
// Make newform 3969.2.a.z in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3969_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_3969_2_a_z();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_3969_2_a_z();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function ConvertToHeckeField(input: pass_field := false, Kf := [])
    if not pass_field then
        poly := [-3, 3, 9, -5, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [-3, 0, 1, 0, 0], [-1, -4, 0, 1, 0], [2, 4, -5, -1, 1]];
    Rf_basisdens := [1, 1, 1, 1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_3969_a();"
function MakeCharacter_3969_a()
    N := 3969;
    order := 1;
    char_gens := [2108, 3727];
    v := [1, 1];
    // chi(gens[i]) = zeta^v[i]
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    F := CyclotomicField(order);
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),[F|F.1^e:e in v]);
    return MinimalBaseRingCharacter(chi);
end function;

function MakeCharacter_3969_a_Hecke(Kf)
    return MakeCharacter_3969_a();
end function;


function ExtendMultiplicatively(weight, aps, character)
    prec := NextPrime(NthPrime(#aps)) - 1; // we will able to figure out a_0 ... a_prec
    primes := PrimesUpTo(prec);
    prime_powers := primes;
    assert #primes eq #aps;
    log_prec := Floor(Log(prec)/Log(2)); // prec < 2^(log_prec+1)
    F := Universe(aps);
    FXY<X, Y> := PolynomialRing(F, 2);
    // 1/(1 - a_p T + p^(weight - 1) * char(p) T^2) = 1 + a_p T + a_{p^2} T^2 + ...
    R<T> := PowerSeriesRing(FXY : Precision := log_prec + 1);
    recursion := Coefficients(1/(1 - X*T + Y*T^2));
    coeffs := [F!0: i in [1..(prec+1)]];
    coeffs[1] := 1; //a_1
    for i := 1 to #primes do
        p := primes[i];
        coeffs[p] := aps[i];
        b := p^(weight - 1) * F!character(p);
        r := 2;
        p_power := p * p;
        //deals with powers of p
        while p_power le prec do
            Append(~prime_powers, p_power);
            coeffs[p_power] := Evaluate(recursion[r + 1], [aps[i], b]);
            p_power *:= p;
            r +:= 1;
        end while;    
    end for;
    Sort(~prime_powers);
    for pp in prime_powers do
        for k := 1 to Floor(prec/pp) do
            if GCD(k, pp) eq 1 then
                coeffs[pp*k] := coeffs[pp]*coeffs[k];
            end if;
        end for;
    end for;
    return coeffs;
end function;


function qexpCoeffs()
    // To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
    weight := 2;
    raw_aps := [[0, -1, 0, 0, 0], [0, 0, 0, 0, 0], [-1, 0, 0, 0, -1], [0, 0, 0, 0, 0], [-1, 0, 1, -1, 0], [1, 1, 0, 0, -1], [-3, 1, -1, 0, 0], [-1, 2, -1, 1, -1], [0, 0, -2, 2, 1], [-1, -1, 2, -1, 0], [1, 0, -1, 1, 1], [0, -2, 0, -2, 0], [0, -1, -1, 1, 2], [3, -2, -1, 1, 3], [-4, -1, 2, 1, 1], [5, -1, 0, 0, 2], [-6, -1, -1, -1, 1], [2, 1, -1, -1, 1], [-1, 4, 2, -1, 1], [2, -2, 1, 3, 2], [-4, 0, 1, -3, 0], [3, -4, 2, 0, 1], [-1, 0, -2, 4, -2], [-7, 2, 0, -2, 1], [2, 1, 4, -1, -2], [-1, -4, 2, -3, -1], [-2, 1, 1, -3, 2], [2, 2, 0, 1, 4], [3, 4, 0, 1, 0], [-3, -3, 1, 3, 0], [5, -2, 1, -1, -2], [-12, 5, 2, 0, 0], [-1, 1, -3, 1, -2], [-5, 2, -4, -1, 0], [8, -2, 2, -4, 3], [3, 2, 5, -3, 1], [0, -5, 1, 4, 0], [3, -3, -2, 2, 2], [-2, -4, 3, 0, -2], [-10, 6, 1, -3, -1], [-8, 1, 0, -1, -1], [-4, -2, -7, 2, 1], [1, 5, 1, 2, -7], [-4, 3, -6, 0, -3], [-8, 7, 0, 1, -3], [6, -5, 0, 1, -6], [-2, 7, -3, 3, -1], [-5, -1, 0, -1, 3], [-5, 5, 7, -2, 0], [12, -4, 2, 6, 1], [8, 0, 5, 0, -4], [-4, 2, -2, -4, 3], [3, -1, -4, -3, -2], [-5, -2, 3, -2, 0], [1, -3, 5, 1, 0], [-6, 8, -6, -4, -2], [2, -4, 0, 6, -1], [7, -7, 6, 2, 3], [-2, -1, 0, 5, -3], [1, 8, -2, -3, -2], [0, 0, 4, -7, -1], [-2, 4, -2, 1, 0], [9, -7, 4, 0, 1], [-17, 7, 1, -7, -7], [1, -4, 7, -1, -3], [5, -1, -4, -5, 1], [4, -4, 4, -1, 9], [3, 0, -5, -1, 2], [-7, -2, -1, 1, 7], [4, -11, -6, 6, 2], [6, -4, -3, 5, 7], [5, -8, 4, 2, -3], [-5, -8, 5, -3, 5], [-9, 3, 2, -7, -4], [2, 7, -5, -1, 4], [-6, -12, 1, -1, 4], [4, -10, 1, 7, 0], [-11, 0, -7, 1, -2], [10, -4, -3, -1, 2], [8, -12, 0, -3, 6], [-18, 1, -3, -4, 7], [1, 4, -2, -6, -4], [-2, 3, 4, -3, 7], [3, -7, 4, -3, -5], [-10, -6, -2, 0, -3], [-15, 1, -5, 1, 2], [-18, 12, -6, -6, -3], [0, 9, -2, -4, -7], [-19, 4, -3, 3, -7], [-10, 1, 8, -10, -5], [6, 11, 1, 0, 0], [-20, 0, -9, 6, -2], [2, 2, 2, 4, -1], [12, -7, -4, -2, -7], [4, -7, -3, 2, 3], [-9, 0, -6, 6, -3], [-7, 14, -11, -5, -5], [-3, 10, -10, 3, -6], [-6, 0, 7, -7, -13], [2, 4, -3, 8, -5], [6, -4, 4, -3, 4], [-6, -9, -6, 4, -1], [-4, 11, -11, 0, 5], [10, -1, -5, 5, 5], [-15, -3, 2, -1, -1], [16, -4, -3, 5, 9], [-1, -1, -4, 5, 9], [7, -11, -6, 0, 4], [-4, 6, 6, -1, -12], [-5, -4, 2, -7, 3], [13, -1, 7, 2, -6], [-8, 2, -9, 8, -9], [8, 8, 10, -4, 0], [24, -12, -2, 5, 5], [-14, 6, -8, 7, -11], [-25, 10, 3, 1, 1], [3, -2, -1, 7, 12], [-1, -15, 8, -1, 9], [-3, 12, 7, -4, -5], [5, 18, -2, -2, 1], [22, 3, -9, 7, 4], [4, 5, 0, 11, -9], [-6, -5, 10, -11, -7], [2, -4, -3, -3, 5], [-2, 7, -5, 3, -4], [13, -10, -10, 6, 4], [-3, -8, -3, 4, -12], [0, -4, -11, 6, 0], [2, 14, -9, -2, -4], [-9, 7, 0, 4, -3], [-10, 14, 1, 1, -7], [-3, 7, -15, 5, -5], [-27, 10, 7, 1, -3], [0, -5, 5, 1, -9], [10, -19, -3, 11, 2], [6, 2, 2, -6, 1], [9, -1, 4, -13, -8], [2, 7, -1, 8, -5], [-1, 1, 8, 3, 2], [-14, 15, 1, 6, -2], [-4, 9, 0, -15, 0], [17, -6, 13, 0, 2], [-6, -2, 6, 1, 0], [29, -5, 1, 3, 8], [6, -15, 8, 5, 5], [-2, -12, 6, -10, 8], [-10, 12, 3, 3, -3], [24, 5, 6, 2, -11], [-20, 7, -5, 3, 2], [-10, 3, 5, -3, -1], [25, -16, -3, 5, 9], [5, -14, 4, -9, 5], [9, -7, -10, 9, 1], [5, 14, 4, 4, -2], [4, 4, -8, 12, -4], [8, -6, 4, -2, -11], [-5, -11, 4, -3, -4], [1, 13, -13, 6, -5], [-30, 21, 6, -10, -7], [22, -4, 9, -11, 9], [1, -8, 8, -9, 10], [-14, 9, -5, -4, -16], [1, 1, -3, 6, -4], [-12, -1, 1, 0, -9], [-13, -3, 3, 2, 15], [-17, 5, 7, -11, -6], [14, -3, -3, 0, -3], [27, 0, -5, -7, -7], [2, -15, 14, 0, 9], [-8, 9, -7, -11, 3], [14, 1, 3, 1, -2], [-31, 14, 7, -2, -7], [-6, 18, -14, 2, -2], [-15, 24, -4, -1, -10], [6, 2, -7, 9, -11], [-8, 19, -5, 1, -6], [-20, -8, 3, -6, 14], [-27, -6, 0, -8, 2], [8, 13, -8, 2, 7], [10, -7, 9, -4, 6], [14, -5, -3, 14, -2], [-15, -16, 9, 4, 2], [10, -3, 7, -5, 7], [0, -9, 21, -7, -2], [22, -2, 10, -4, -1], [18, -17, -2, -3, 0], [-15, 3, 10, -19, -1], [3, 7, 4, 4, 12], [3, -6, 1, 5, 11], [-14, 2, -1, 7, 9], [25, 0, 12, -11, 7], [22, -5, 2, 7, -3], [17, 9, -12, 0, -3], [-8, 6, -6, 7, 18], [-10, 7, 1, 1, -17], [-9, 5, -4, -1, -11], [4, -7, -8, 14, -3], [6, 16, -12, -5, -3], [7, -8, 5, -2, 9], [-30, 20, -2, -6, 0], [-13, -8, 11, -8, -11], [-19, 14, -9, -11, 8], [-17, 3, 11, -8, -5], [-20, -4, 3, 2, 12], [-24, -11, -4, -1, 1], [28, 10, -6, 11, -4], [-16, 5, -11, 13, 11], [-37, 13, -1, -7, -12], [6, -7, -12, -2, -7], [-12, 6, 13, -1, 8], [-1, -4, 16, 1, 2], [14, -16, -8, 8, 3], [10, -26, 6, 6, 2], [11, -2, 12, -16, 3], [-14, -4, -15, 7, 6], [-11, 17, 12, -4, -3], [27, 3, 5, 2, 2], [-9, 14, -9, -7, 7], [-5, 12, -14, -2, -3], [-18, 1, -6, 2, 4], [1, 7, -8, 12, 5], [14, -15, 5, 12, -3], [22, -9, 17, -8, 3], [-27, 24, -1, -4, -10], [-39, 14, 11, -14, -10], [2, 5, 3, 4, -7], [9, -3, -13, 23, 1], [28, -2, -3, 14, -1], [-4, 1, -9, -1, 13], [-39, 1, -2, 1, -13], [24, -26, 4, 7, 12], [0, -11, -5, 10, 12], [6, -5, 5, 10, -9], [-9, 10, 9, -9, 6], [27, 6, 0, 5, -7], [-25, -2, 6, 1, 4], [-19, 14, -7, -8, -16], [-23, -4, -13, 2, 2], [15, 1, 6, -1, -2], [-26, 6, -5, 8, 2], [20, -11, 0, 16, 1], [-6, 11, 3, 0, 7], [5, 27, -2, 9, -12], [29, -2, 2, 2, 1], [14, -4, -8, -16, -6], [-30, 6, -1, -7, -2], [-18, -1, 4, 9, -2], [-26, -10, -3, 4, -3], [-32, 6, -15, 1, 10], [-15, 9, 0, -9, 9], [-4, -7, 6, 4, 5], [3, 5, -5, 24, -9], [9, -2, -3, 15, -3], [-8, -17, -9, 6, 2], [-6, -7, -6, -1, 1], [-12, -12, -9, 8, -8], [-3, 17, -13, 3, -11], [-23, 0, 11, -14, 1], [10, -7, 14, -6, -11], [8, -20, 6, -7, 7], [-16, -8, -12, 2, 1], [-8, 2, 7, -18, -11], [-31, -6, -3, 12, -6], [11, -16, 21, -5, 8], [4, 26, 6, -8, 0], [29, -15, -12, -3, -3], [-17, -4, -4, 3, -8], [-2, 3, 15, -16, -4], [17, -20, 11, 14, 7], [5, 11, -20, 0, -10], [27, -5, 7, 1, 15], [5, -15, 12, -12, -12], [25, 17, -6, -1, 0], [1, -8, -11, -3, -13], [-6, -3, 7, -4, 14], [6, -4, -19, 6, 4], [-21, 5, -4, -6, 6], [39, -17, -3, 7, 12], [-27, 9, -11, -7, -1], [-18, 2, 3, 0, -15], [-15, -18, 4, 7, 5], [2, -13, 13, -2, -10], [-28, 13, -12, 3, -1], [26, 6, 2, 9, 0], [0, -22, 20, -9, 7], [28, -11, 12, -12, 7], [-2, -13, -3, 11, 9], [-34, 14, -5, 5, -18], [-14, -2, 7, 0, -16], [8, 10, 13, 3, -10], [-10, -9, 28, -13, -12], [13, -25, 14, 10, 3], [38, -14, -4, 14, 3], [-10, 5, -5, 5, 3], [31, -26, -3, 9, 11], [17, -1, 13, -6, -1], [-30, 15, -2, -13, 8], [31, -1, -5, -9, 1], [-2, -10, 5, -16, 17], [-46, -4, -3, 4, -7], [-34, -4, -8, 1, 8], [45, -1, 19, 0, -12], [-18, -2, -5, 10, 3], [-39, 27, 1, -3, -12], [-10, 23, 7, -5, -16], [9, -3, -15, -1, 5], [4, -19, -14, 1, 12], [12, -14, 6, 4, -21], [-45, 5, -1, -6, 0], [-29, 21, -6, -8, 4], [2, -25, 8, -8, 19], [39, -28, 1, 5, 13], [4, -9, 0, 10, 0], [-1, -25, 10, 13, -1], [-12, -8, 11, -4, -5], [-13, -12, -9, -9, 3], [7, 7, 14, -8, -3], [17, -24, -9, 11, -3], [14, 15, -7, 3, 9], [-6, -23, 12, -10, 16], [32, 7, 9, -7, 13], [-11, 21, -9, -5, 13], [-1, -17, 25, 3, 11], [-21, 25, 5, -2, -12], [27, 18, -16, 7, 5], [-11, -1, 0, 14, 3], [-18, -12, 4, 11, 11], [11, -3, 9, 3, -12], [7, -11, -16, 0, 1], [-28, -8, -8, 0, 20], [30, 0, 13, -13, 17], [-29, 16, -14, 8, -13], [11, -12, 18, -15, 0], [21, -15, 2, 25, -1], [34, 5, -6, 2, -6], [-8, 13, 0, 16, 3], [-2, 18, -8, 13, 7], [46, -13, -6, 11, 26], [-12, 19, -16, 16, -15], [12, 0, 22, -4, -16], [-26, -1, 12, -28, -3], [-41, 11, -5, -6, -5], [25, -15, 8, 11, -4], [9, 12, -11, -4, -10], [-6, 20, 6, 3, 0], [10, 19, -3, 1, -15], [-12, 21, -8, -1, 20], [2, -16, 5, 1, -10], [-25, 15, 10, -2, -2], [3, -6, 0, -10, -5], [-9, 27, 4, 5, -19], [15, -29, 0, -14, 18], [9, 30, -5, 3, -12], [-15, 5, -21, 3, -5], [-4, -14, -7, 11, -2], [27, -17, -10, -7, 1], [-12, -12, 1, -10, -2], [-34, 14, 6, -21, -7], [27, 4, 6, -2, 5], [-22, 3, 7, 16, 4], [-38, 11, -1, 2, 15], [17, -35, -9, 5, -3], [41, -28, 9, 12, 5], [-13, 21, -8, 9, -13], [12, 8, 2, 12, -8], [9, -12, 28, -19, -1], [11, 31, -12, 3, -16], [-16, 25, 8, -19, 1], [-12, 0, 0, 11, 17], [-24, 6, -10, 22, -4], [-3, 4, 15, -20, -3], [1, -28, 9, -1, -7], [-1, 6, -20, 22, -2], [23, 1, 9, -16, 4], [8, -26, -4, 20, 4], [-2, 3, 2, 18, 1], [-31, 9, 14, -11, -8], [-22, 24, -24, -6, -12], [-9, 2, -8, 12, -3], [26, -16, 7, 7, 2], [4, 21, 3, -15, -5], [1, 0, 17, -37, -4], [-23, -23, 0, 0, -4], [-15, 10, -8, -3, -30], [16, -4, -7, 5, 15], [-16, -3, -37, 8, 3], [-5, -5, 13, 0, -16], [-6, -6, 4, -13, 8], [32, -5, -6, 2, 4], [-14, -6, -7, -16, 8], [4, 7, 27, -9, -10], [48, 10, 1, 1, -10], [-21, 1, 11, -18, 0], [-61, -3, -3, -3, 6], [-4, 6, -5, 15, -4], [-16, 25, -28, -4, -2], [16, -7, 6, -10, 12], [0, -4, -3, 10, -19], [-1, 16, 13, -31, 1], [-20, 16, -8, -16, -4], [1, -31, 13, -13, 15], [36, -39, -3, 20, 10], [-7, 5, -16, 13, -16], [32, -23, 8, 14, 9], [-8, -21, 7, -21, 4], [6, 9, 13, -7, 14], [1, 21, 5, 1, 10], [-3, -3, -13, -15, 6], [-40, 12, -18, 9, 6], [43, -18, 3, 22, -3], [-26, 14, -14, 5, -18], [13, 19, -7, -3, -14], [36, -11, -1, 8, -2], [-12, -24, -5, 14, -7], [2, 10, -2, -4, -23], [-2, 16, 3, -3, 16], [-42, 5, 7, 3, -3], [16, -10, 7, 8, 6], [18, 24, -21, 6, 3], [-17, -1, -9, -10, -1], [27, 15, -7, 10, 5], [-25, 22, -10, -25, -2], [11, -11, 3, -3, 23], [-3, 2, -19, 25, -7], [-20, 19, 7, -9, -7], [30, -16, -1, 2, -17], [-49, -5, 3, -13, 3], [7, 2, 26, 6, -2], [-27, 17, 15, 3, -8], [-41, 17, -14, -11, -3]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3969_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3969_2_a_z();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
function MakeNewformModFrm_3969_2_a_z(:prec:=5)
    chi := MakeCharacter_3969_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 2));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 1;
    while true do
        trunc_vec := Vector(Kf, [0] cat [f_vec[i]: i in [1..prec]]);
        B := Basis(S, prec + 1);
        S_basismat := Matrix([AbsEltseq(g): g in B]);
        if Rank(S_basismat) eq Min(NumberOfRows(S_basismat), NumberOfColumns(S_basismat)) then
            S_basismat := ChangeRing(S_basismat,Kf);
            f_lincom := Solution(S_basismat,trunc_vec);
            f := &+[f_lincom[i]*Basis(S)[i] : i in [1..#Basis(S)]];
            return f;
        end if;
        error if prec eq maxprec, "Unable to distinguish newform within newspace";
        prec := Min(Ceiling(1.25 * prec), maxprec);
    end while;
end function;


// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_3969_2_a_z();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function MakeNewformModSym_3969_2_a_z( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3969_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![3, 3, -9, -5, 2, 1]>,<5,R![3, 18, -18, -5, 4, 1]>,<11,R![15, 12, -15, -8, 4, 1]>,<13,R![-5, -23, 13, 13, -8, 1]>],Snew);
    return Vf;
end function;