
// Make newform 6012.2.a.d in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6012_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_6012_2_a_d();".
// 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_6012_2_a_d();".
// 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 := [-1, 6, 6, -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], [-2, -1, 1, 0, 0], [3, -3, -2, 1, 0], [2, 5, -4, -2, 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_6012_a();"
function MakeCharacter_6012_a()
    N := 6012;
    order := 1;
    char_gens := [3007, 3341, 4681];
    v := [1, 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_6012_a_Hecke(Kf)
    return MakeCharacter_6012_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, 0, 0, 0, 0], [0, 0, 0, 0, 0], [-2, 0, 0, 0, 0], [2, 0, 0, -1, 0], [0, -1, -1, -1, 0], [0, -2, 0, 0, 0], [2, -2, 0, 0, 2], [1, -2, 1, 0, -1], [0, 0, -2, -2, 0], [2, -2, 0, -1, 0], [3, -3, 1, 0, 1], [0, 2, 2, 0, 0], [0, 2, -2, 0, -2], [0, 4, 0, 0, 0], [-1, -2, -1, 0, 1], [-2, 4, 0, 0, -2], [-2, 4, 0, 2, 2], [3, 2, -3, -2, 0], [6, 2, 0, -2, 2], [-4, 2, 4, 2, -2], [2, -2, 2, 2, 2], [-6, 4, 2, 4, -2], [2, -6, 0, 0, 0], [5, -2, -1, -2, 0], [-6, -1, -1, -1, -4], [4, -2, 0, 2, 2], [4, 0, -6, 0, 0], [-2, 4, 0, 1, -4], [6, 2, -4, -2, 4], [2, 0, 4, -2, -2], [0, -1, -1, 3, 0], [6, 0, 0, 0, 4], [-2, 1, -3, 1, -4], [2, -2, -2, -4, -2], [8, 0, 0, 0, 4], [0, 0, -8, -2, 2], [1, -5, 7, 4, -1], [14, -6, 0, 0, 4], [1, 0, 0, 0, 0], [10, -1, -1, 3, 0], [7, 2, -5, -4, 1], [3, 4, -1, 0, 1], [-9, -3, 1, 4, -3], [-10, 0, -2, 0, -4], [4, 4, -6, 0, 0], [8, 1, -3, 1, -4], [-1, 1, -3, 0, -3], [-3, 4, -1, 4, -4], [-2, 0, -6, 2, -2], [6, -2, -4, -1, 0], [13, -5, 3, 4, 3], [-7, 4, 7, 4, -4], [-4, 4, 0, 2, 6], [10, -8, 0, -3, 0], [-4, 2, 8, 4, -6], [1, 4, -1, 0, 4], [-2, -6, 0, 2, 6], [6, -4, 0, 0, 0], [2, 2, -4, -2, -2], [7, 6, -3, -2, 0], [12, 3, -1, -1, 4], [3, -3, -7, -4, 1], [4, 2, -8, 0, -2], [12, -4, -4, -8, 4], [2, -6, -4, 2, -2], [1, -6, -1, -6, 0], [0, 8, 2, -2, 2], [-3, 0, -7, 4, -1], [-6, 8, 6, 2, -6], [8, 0, 0, 2, -2], [-2, 2, 0, -7, 0], [11, -3, 5, 0, 1], [3, 2, -1, -4, -7], [22, -2, -2, -2, 0], [10, 6, -2, 4, 2], [-14, 4, 8, 1, 0], [-4, -4, 2, -4, 0], [9, 2, 3, -2, -8], [6, 6, -10, -4, 2], [6, 1, 1, -7, 0], [-3, -1, 7, 0, -1], [2, 2, -4, 5, 4], [7, 0, 1, 4, -4], [7, -4, -1, -8, 1], [-2, 2, 2, 8, 6], [6, 4, 6, 6, 2], [-1, 12, -1, 0, 1], [-10, -10, 0, -2, 2], [-5, 4, 3, 4, 1], [20, 6, 0, -2, 4], [2, 0, -8, 5, 0], [-8, -2, 2, 2, -2], [-8, 2, 12, -2, 0], [20, -8, -4, -4, 8], [-4, -8, 4, 4, 0], [7, -4, -7, 4, 0], [2, 1, 13, 1, 0], [-14, 0, 6, 10, -4], [-7, 3, 7, 8, 3], [-2, -2, -4, -2, -6], [18, -8, -4, 2, 4], [-10, -3, 1, -3, -8], [-9, 10, -5, 0, -7], [2, -6, -4, -2, -6], [-4, -2, 0, -4, 6], [5, -1, -1, 4, 3], [-16, 10, 10, 8, -2], [6, 10, -2, 0, 8], [2, -12, 0, 3, 4], [-18, 6, 0, -3, -8], [0, -8, -4, 2, 2], [-1, 1, 9, 12, -3], [-10, -10, 4, -1, 8], [-10, -2, 2, 4, 8], [5, -8, -1, -8, 4], [6, -4, -2, -10, 2], [20, 0, -4, -6, -4], [8, -12, -4, -2, 12], [7, 1, -11, 0, 5], [-4, 0, 4, 2, 0], [18, -6, -10, -4, 0], [-20, 20, 2, 0, -4], [-14, 0, 0, -4, -4], [0, -4, 8, 4, 0], [-8, 8, -2, 0, -12], [-5, 14, 1, 2, 0], [-14, 6, 0, -6, 0], [6, 14, -10, -4, 2], [4, 4, 2, 0, 6], [-23, 8, 1, 0, 3], [-10, -8, 0, 6, -6], [0, 4, 4, -8, -4], [8, -2, 6, -2, 12], [6, -3, -7, 5, 4], [-11, 10, 3, 6, -12], [-16, 6, 8, 8, 0], [2, 4, 4, -8, -2], [12, -10, 10, 8, 0], [-18, 12, 0, 2, -4], [-2, 1, -15, -7, -4], [-14, 6, 0, 6, 2], [14, 0, -10, 6, -2], [4, 2, 6, 2, -2], [-2, -8, 2, 2, 4], [-12, 10, 10, 6, -10], [11, 12, -7, 8, -4], [-6, -5, -5, -1, 4], [-11, 0, -3, 8, -5], [26, -4, 4, -5, -8], [4, 11, -13, -5, 4], [9, 0, 1, 4, -9], [-4, -6, 6, -2, 12], [18, -4, -4, -7, -4], [-2, 0, 6, 8, 10], [-11, -4, 15, 0, -4], [-3, -14, 9, 4, 3], [7, -6, 11, 0, 9], [-1, 5, -3, -12, 1], [-2, -6, 4, 6, -2], [-18, 10, 4, 12, -6], [-21, 16, 5, 0, 0], [8, 8, -12, 2, 2], [21, 3, -1, 12, 3], [18, -14, 2, 2, -2], [-32, 4, -4, 2, 8], [-4, -20, 4, 0, 0], [8, 4, 4, 2, -10], [-2, -6, 12, 5, -8], [14, -7, 1, -7, 12], [6, -10, 0, -11, -8], [10, -6, -4, 8, 8], [-2, 11, -13, -9, -4], [36, -11, -11, -3, 0], [5, 3, -9, 0, 3], [-10, 22, 6, -2, -10], [-17, -7, 1, 4, 9], [27, -7, -15, 4, -3], [2, -8, -6, 6, 2], [-4, -5, 15, 7, 0], [-6, -6, 8, -4, 10], [-3, 6, -7, 0, 3], [13, 3, 3, -4, -5], [-14, 26, 0, 2, -8], [-20, 6, 18, 12, -4], [-14, 10, -10, 0, 8], [-2, 8, 0, -4, 8], [3, 9, -15, 0, 5], [-2, 4, 8, -1, -12], [-26, 10, 12, 9, 0], [20, -6, -2, 2, -2], [6, -10, -12, 2, 8], [-14, 6, 12, 0, 8], [-17, -8, 21, 8, -8], [30, 2, 4, -3, -8], [-7, 2, 13, 12, -9], [-1, 8, 3, 0, 13], [-7, 0, -11, 0, -5], [-11, 3, 7, -8, 7], [1, 4, 5, 0, -1], [1, -5, 7, 4, -9], [-8, -16, 10, 4, 0], [-27, 16, 11, 0, 0], [-10, -2, 6, 2, -6], [22, -14, -14, -12, 6], [24, -4, -10, -2, -6], [10, -5, -9, -1, 8], [10, 10, 10, -10, -2], [23, -18, -1, -4, -3], [-8, 6, 10, -2, 12], [2, -8, 8, -5, 12], [-6, 1, -11, -7, 8], [-6, 5, 1, -11, -4], [16, -8, 4, 4, -4], [12, 0, -8, -14, 8], [26, 12, -8, 11, -4], [-14, -14, 0, 1, 8], [0, 12, 6, 8, 0], [6, 5, 13, -7, 0], [24, -5, -1, 11, 4], [2, -18, -4, -6, -2], [-2, -8, 6, 8, -2], [-7, -25, 11, 0, 3], [-28, -2, 12, 4, 2], [15, -6, -17, -12, -3], [8, -2, 4, -8, -2], [-23, -13, 3, -8, -5], [27, 0, -21, 0, -3], [-26, 8, 12, -2, -4], [-16, 0, 24, 6, 4], [11, -12, -3, 0, 0], [14, -12, -10, 2, 12], [-16, 2, -8, 2, 10], [-4, 18, 10, 6, -20], [12, 8, 0, -10, 4], [-4, 1, -15, 1, -4], [-8, -4, 14, 4, 10], [-40, 0, -6, 2, 10], [-11, 4, 17, 12, -9], [-20, 6, -18, -2, -8], [16, 7, -1, 7, 0], [10, 14, 0, 0, 8], [19, -18, -9, -4, 17], [-16, 12, 2, 8, 0], [20, -6, -6, -10, 0], [-27, 6, 15, 2, -4], [6, 8, 4, -1, 4], [28, -20, -4, -8, 12], [-30, 12, 8, 6, -4], [-2, -4, -16, -5, -4], [2, 8, 6, 0, 8], [7, -10, -7, -10, -20], [17, -20, -7, -4, -13], [-22, 0, -6, -2, -4], [-24, 20, 6, 12, -20], [16, -24, -2, -6, -8], [-1, -3, 9, 0, 1], [-4, 4, 20, -6, 12], [-3, 4, -1, 0, 12], [2, 2, 22, 6, 4], [-21, 4, -5, -16, -7], [12, 4, 4, 8, -12], [-18, 12, -8, 8, 6], [2, -14, -16, -2, 12], [6, -6, -8, -10, 0], [-11, -1, -25, -4, 15], [-20, -20, 8, -8, 4], [-8, 10, 14, 0, 8], [-44, 2, 4, 6, -12], [-18, -8, 4, 14, -10], [-7, -6, -13, -18, -4], [-8, 12, 14, 0, 10], [-7, 11, -5, 8, 7], [-26, 8, 12, 6, -4], [-20, 8, -8, -4, -20], [41, -18, -13, -14, 12], [12, -6, -10, -4, 12], [-24, 6, 2, 6, 12], [2, 10, -2, 4, -2], [-14, 6, -2, 6, -16], [3, 33, -15, -4, 5], [-18, -14, -2, 6, -2], [48, 10, -6, 0, 4], [14, 22, -4, 2, -10], [7, 16, -9, 8, 5], [-36, 6, 4, -2, 4], [2, 14, -10, 4, 0], [-31, 6, 11, 6, -8], [-34, 6, 14, 22, -8], [24, 15, -9, 7, 0], [-14, -8, 4, 0, -16], [-23, -1, 11, -4, 7], [14, 16, -10, 0, -4], [34, -2, -8, -9, 8], [-16, 8, 8, 0, -4], [18, -2, 24, 11, -4], [-25, -8, -1, 4, 17], [-24, 11, 3, 15, -8], [30, -24, 2, 2, 2], [-10, 0, 18, 6, -18], [24, -4, 8, 4, 16], [24, -6, -10, 2, 10], [12, 12, -2, -12, -2], [-9, -8, -15, -4, 4], [-14, 12, 18, -2, -4], [-33, 22, 11, 12, -23], [30, -22, -10, -6, 18], [-24, 4, 14, 6, -12], [14, 2, -16, 3, -4], [4, 6, 12, -6, -12], [18, -3, -15, 1, 4], [4, 16, -10, -12, 2], [31, 9, 1, 0, 5], [10, 2, 0, 5, 0], [8, -26, 16, 6, -6], [58, 10, -6, -4, 4], [-23, 4, -11, 4, -9], [-36, -10, -4, -16, -2], [-23, 10, -19, -4, 11], [-2, 0, 18, 14, -8], [-30, -2, 16, 12, -12], [-17, -16, 9, -4, 0], [-14, -6, 12, 9, 4], [13, -5, -1, 8, -9], [24, -2, -2, 0, 14], [0, 8, 2, -6, -2], [26, -10, 28, 9, 8], [4, -8, -12, -16, 4], [34, 12, 8, 7, -8], [26, -12, 16, 13, 12], [-38, 1, 5, 13, -4], [33, -4, 17, 12, -1], [-2, 17, 1, 13, -16], [8, 10, 2, 0, -18], [-16, -7, -11, 9, -4], [38, -34, -2, 10, 6], [-1, -18, -13, -12, 9], [-15, -12, 25, 16, -13], [38, 0, 6, -12, 8], [4, -10, -12, 2, -12], [-36, -4, -4, -4, -12], [-1, -14, 25, 18, -8], [-27, -10, -9, 14, 0], [14, -10, 18, -4, 26], [30, 8, -4, 2, 8], [-17, 1, 25, 8, -7], [4, 3, 15, 3, 12], [-2, 2, 8, 5, -20], [-4, -5, -1, 11, -4], [14, -22, 2, -6, 20], [33, -1, 3, -4, -5], [12, 13, -11, -3, -4], [8, 22, -14, 6, -6], [-10, -6, 24, 4, -10], [50, -24, -16, -12, 8], [6, -12, -4, 16, 12], [-4, 24, -8, 0, 10], [13, -25, 3, 0, -9], [10, 0, -30, -14, 14], [0, -16, -14, -6, 2], [13, 6, 13, 4, -9], [23, 10, 1, -6, 20], [12, 6, -2, 14, -10], [32, -14, -2, -4, -4], [15, -22, -9, 12, 13], [12, -8, 16, 4, 0], [32, 12, 0, 6, 0], [32, -24, -8, -6, 10], [38, 12, 0, 0, 18], [-15, 18, -1, 14, 8], [-12, -24, 6, 6, 6], [-70, 14, 2, -2, -2], [-18, 32, -4, -1, -20], [39, 4, -9, 0, 9], [2, -32, 0, 6, 8], [-2, -18, 14, -8, 0], [-12, -16, -6, -6, -14], [36, -10, -2, -2, 8], [50, -14, -8, -7, -8], [-4, -4, -24, 10, -8], [31, 9, -11, -12, 17], [27, -12, 15, 4, -3], [35, -4, -17, -20, 1], [-14, -10, 6, -2, -18], [43, -4, -1, -4, 1], [-48, 0, -16, -16, 0], [16, -2, 2, 2, 8], [-6, 20, 10, 16, 4], [-10, 0, -2, -22, 0], [-2, 0, 0, -7, -20], [50, -16, -14, -2, 4], [42, -24, 14, 18, 8], [30, 8, 12, 8, 4], [22, -12, 0, -15, -12], [10, -20, -2, 12, 12], [-2, 30, -2, -4, 0], [-30, -4, -10, -10, 2], [-24, 11, 23, 23, -4], [-33, 22, -3, 6, 4], [46, 4, -8, -2, 4], [-10, -22, -10, 6, 20], [7, 2, 13, -2, 8], [18, -16, 8, 0, -12], [20, 0, 16, 0, -2], [20, 22, -14, 4, 2], [-34, -6, 2, 8, -12], [-24, 30, -2, -10, -16], [44, -4, -12, -22, 22], [38, 4, -14, -8, 12], [44, 4, 8, 6, -2], [13, 3, -21, -12, 15], [4, -14, 40, 12, -6], [-14, 14, -6, -4, -14], [32, 21, -11, -15, 12], [19, -19, 9, 12, 13], [-34, -2, 8, 25, -8], [27, 30, -19, 10, -8], [-12, 30, 8, 20, -18], [-35, -2, 9, 8, 15], [-14, 16, 4, 8, 8], [48, -15, -23, -23, 4], [40, -34, -10, 4, 12], [18, 8, 22, 6, -8], [-6, -32, 12, -7, -8], [-16, -7, 29, 1, 12], [27, 18, 5, -14, 0], [6, 2, -28, -10, 2], [-17, -3, 25, 16, -19], [10, 14, -12, 11, 0], [-5, 20, 17, 12, -12], [-32, 20, 10, -2, -4]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6012_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6012_2_a_d();".
// 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_6012_2_a_d(:prec:=5)
    chi := MakeCharacter_6012_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_6012_2_a_d();".
// 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_6012_2_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6012_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![2, 1]>],Snew);
    return Vf;
end function;