
// Make newform 6012.2.a.e in Magma, downloaded from the LMFDB on 13 May 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_e();".
// 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_e();".
// 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, 4, -3, -6, 0, 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], [1, -4, -1, 1, 0], [0, 1, -4, -1, 1], [3, 1, -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_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], [0, 1, 0, -1, 1], [0, -1, 0, 0, -1], [0, -1, 0, 1, -1], [-1, 1, -1, -1, 1], [3, -2, -2, 0, -2], [-1, 2, 1, 1, 1], [-3, 1, 2, 0, -1], [0, -1, 1, 3, 2], [-3, 0, 2, 1, 0], [-4, -1, 4, -1, 2], [2, -1, 4, 2, 0], [2, 1, -3, 2, -1], [0, -4, -1, 1, 1], [-1, 3, -1, 0, 2], [1, 3, -1, 0, -2], [-4, -4, -1, 2, 1], [3, -1, -1, 1, -5], [-5, 4, 3, -2, 4], [-4, 4, -4, -2, -1], [-6, -5, 1, 2, 1], [1, 4, -2, -2, -5], [7, -2, -3, -3, -1], [-4, 0, -2, 3, -3], [5, 2, -1, -3, 0], [-7, 1, 0, -2, 1], [-1, -7, -4, 3, -2], [-7, 0, 3, 3, 2], [8, -5, -5, 1, -5], [-5, -4, 1, -2, -1], [1, -4, 0, 3, 3], [6, 0, -2, -2, -5], [-6, 2, 4, -4, 1], [0, 8, 4, -1, 3], [2, -3, -4, -2, -7], [3, -1, -7, -4, -4], [-2, 9, -1, -7, 5], [-1, 0, 0, 0, 0], [-7, 1, 3, -2, 6], [-9, 4, 1, 0, -3], [-9, -1, -1, -2, 3], [7, -7, 1, 5, -10], [7, -7, 0, 3, -3], [-11, -1, 5, -5, 3], [-4, -2, 0, 4, 3], [5, -4, -5, -3, 4], [-1, 1, 0, 0, -8], [-7, 5, -3, -5, 5], [-9, 5, 2, 0, -3], [-10, 7, -2, -1, 2], [-1, 5, -4, 1, 3], [-7, 5, 8, 5, 2], [-2, -9, 0, 3, 7], [7, 2, 1, -8, 5], [-8, 0, 0, -9, -2], [-9, 7, 1, -6, 13], [-8, -2, -1, 2, -6], [0, 3, 8, 4, -6], [7, 0, 3, 6, -7], [3, 1, -3, 0, 12], [-2, 8, -1, -4, 3], [-4, 1, 2, -9, 0], [2, 15, 0, -1, 10], [6, -2, -1, -1, -4], [-10, 5, 10, -5, 4], [-7, 6, -10, -6, 1], [3, -9, 4, 6, 1], [-3, -1, -9, -6, -3], [12, -11, 3, 7, -11], [-14, -6, 10, 0, 7], [-9, -4, 9, -6, 2], [1, 1, -2, 2, 3], [-7, 7, 7, -6, 5], [5, 3, -1, 8, 0], [1, 12, -10, -1, 1], [-7, -2, 10, 7, 9], [4, -9, -8, 2, 2], [12, -7, -8, -3, 2], [-1, 0, 0, 3, -3], [-20, -2, 2, -2, -3], [-7, 19, 4, 0, 4], [-3, -1, -3, -3, 3], [-4, -3, -4, 2, 7], [-5, 3, 4, -1, -6], [-18, -7, 7, -4, -1], [9, -2, -16, 4, -1], [0, -16, 1, -1, -5], [1, 3, -7, -7, 5], [-4, 9, 8, -8, 12], [-12, -7, 2, 12, 0], [-8, -3, -1, 2, 1], [-5, 1, 8, -1, 9], [-10, 12, 10, 2, 4], [2, 18, 2, -9, 8], [-13, 10, 3, 2, 6], [8, 6, 5, -9, 0], [3, -10, 0, 8, -11], [-7, 1, 6, 5, 3], [2, 8, 5, 2, 0], [6, -2, -12, -7, -1], [1, 13, -7, -1, 9], [3, -2, 1, -14, 4], [11, 3, -9, 4, -1], [10, -4, -4, 11, 3], [26, -4, -11, -4, -18], [17, -1, -5, 3, -20], [4, -1, 12, 10, 3], [11, -1, -3, 5, 6], [-17, -1, 10, 3, 6], [-11, -4, -1, 1, -6], [10, -14, 2, -7, 4], [3, -21, -6, 4, -8], [-2, -11, 7, 8, -9], [-2, -19, 0, 9, -18], [20, -5, -6, 6, 0], [-7, 17, 12, 1, 7], [4, 17, -4, 2, 8], [5, -4, -2, 1, -5], [-6, 9, -5, 0, 0], [-14, -13, 8, 4, 3], [1, 4, 6, -4, -6], [-1, 2, 4, 1, -19], [-28, 1, -1, -9, 0], [5, -9, 11, 7, -8], [-2, -5, -7, -7, -2], [-20, 17, 4, -11, 20], [-17, -2, 6, 5, 12], [-1, -3, -11, 9, -5], [18, -15, -10, -3, -13], [21, -13, -1, 7, -7], [9, -8, -2, -10, 7], [8, 7, -9, -2, -14], [20, -5, 3, 11, 1], [5, 3, 13, 10, -3], [3, 3, 4, 7, -8], [6, -3, -10, 6, -15], [-11, 5, -2, -13, -1], [14, -18, 6, 12, -7], [-4, -14, 9, 2, 0], [16, -10, -11, -6, 8], [7, 6, -2, -18, 7], [-10, -12, -3, 13, -8], [-11, 9, 8, 3, 15], [-4, 5, -2, -5, 3], [11, -13, -2, 3, -12], [11, -8, -12, -9, 0], [11, 4, 1, 8, 0], [0, 10, -9, -6, 13], [17, 4, -13, 6, -9], [0, 9, 1, -7, -3], [-11, -12, 11, 10, 3], [5, 6, 10, -2, -6], [-15, 15, 0, -8, 15], [3, 5, -12, 1, -6], [5, 7, 1, -3, -9], [-14, -5, 7, 8, 19], [8, 12, 11, -11, 6], [5, -8, -14, -4, -12], [16, -3, 6, -6, 2], [2, -7, 6, -7, 13], [-6, 5, -7, -22, -6], [-23, 0, 3, -10, 9], [9, 20, 7, -5, 1], [22, 8, 11, 2, 4], [9, -1, -8, -4, 14], [-4, 8, -5, -13, 15], [7, 6, 1, -2, 16], [-4, 17, -4, -6, 19], [5, 2, -17, 5, -3], [-11, 13, -6, -9, 3], [-27, 4, 17, -7, 9], [-1, 14, 7, -2, -3], [-1, -12, 13, 12, 7], [7, 7, -3, -13, -9], [31, -20, -5, 9, -27], [0, 10, 10, 4, -5], [11, -21, -6, 3, -12], [2, -7, -4, -3, -23], [12, 1, 6, -10, 8], [-22, 4, 16, 3, 17], [-3, 1, -6, 0, 4], [-4, 3, 1, 2, 2], [9, -9, 6, 0, -1], [-8, 22, -2, 2, -4], [4, 1, -4, 3, -2], [3, 9, -4, 3, -6], [20, -4, 0, 9, -2], [14, 8, -12, -3, -5], [-4, -21, 7, 9, -8], [25, -5, -12, -6, -3], [0, -8, 10, 1, 4], [3, -11, -15, 3, -2], [29, -5, 2, 9, -5], [13, 14, -9, -1, 2], [18, -4, 12, 13, -10], [17, -6, 9, 23, -4], [-7, 24, 16, 3, 19], [-46, 11, 16, 2, 22], [-4, 0, 13, 13, 0], [25, 4, 0, 1, 8], [-24, -1, 12, -1, -1], [-25, -1, 8, 15, 7], [36, -10, -8, 9, -8], [-13, -11, 4, 3, 9], [16, -4, -8, 7, -14], [-20, 5, 15, 13, 2], [13, 4, -9, 5, 9], [0, -11, 18, 9, 1], [-14, -6, -1, -3, -13], [-8, 30, 9, -9, 23], [29, -15, -11, 0, -15], [21, 5, 6, -11, 6], [-16, 7, 9, -11, 16], [18, -13, 2, 15, -5], [21, -9, -22, -8, -14], [9, 12, -12, -6, 4], [25, -8, -10, 13, -16], [11, -2, 27, 9, -3], [-5, 6, -1, 4, -3], [-6, -9, -11, -6, -13], [-34, 6, 8, -7, 19], [11, 4, -25, 6, -13], [-7, 9, -15, -9, 8], [-13, -1, -4, -11, 9], [4, 18, 20, 1, 12], [0, 10, -6, 1, 4], [14, -23, 0, 7, -9], [-12, -2, 2, -6, 17], [30, -15, -2, 5, -19], [11, 0, -8, -4, -6], [14, 13, -8, -11, -5], [4, 8, 7, -10, 1], [-3, -15, -2, -1, -22], [-8, -26, -3, 13, -19], [23, -38, 0, 21, -36], [18, -3, -20, 3, -18], [-14, -12, 4, -11, 0], [-9, -10, -2, -9, -7], [11, -8, 4, 3, 8], [-26, -12, -10, -3, 1], [-6, 6, 14, -2, 1], [10, 7, 1, 8, 20], [-20, -5, 11, 13, 6], [14, 5, 5, 16, 18], [30, -5, -6, 14, -9], [-5, -22, 8, 12, 1], [-12, 8, 27, -4, -1], [33, -15, -14, -2, -14], [-27, 5, -22, -18, 2], [-1, -1, -7, 15, -18], [-20, 6, -1, -2, -15], [8, 3, -9, -4, -12], [14, 1, -6, 10, 5], [-13, -4, 3, -8, -3], [-11, -14, -15, -3, -10], [6, 2, -8, -2, -26], [-42, -2, 11, 1, 20], [-16, -12, -7, -2, -7], [3, 9, 13, -16, -4], [31, -3, -22, -8, -21], [8, -1, 2, 8, -11], [40, -6, 3, 7, 11], [4, 16, 21, -6, 12], [-8, 17, 11, -12, 0], [18, 15, 5, 5, -7], [-7, -12, 19, 3, -8], [17, 3, -12, 7, -22], [25, 17, -5, -19, -8], [5, 10, 8, 17, 3], [3, -16, -7, 1, -11], [21, -12, -4, 22, -16], [-2, -18, 11, 1, -11], [-7, 13, 10, 1, 7], [0, 9, 11, 4, 4], [-10, 16, -7, -23, 8], [2, -2, -16, -3, 12], [-15, 13, 4, -16, 16], [-2, -4, -15, 9, -6], [29, 9, 0, -24, 10], [-17, 7, 21, -5, 19], [-5, 7, -7, -10, 21], [-12, -15, 1, 24, 2], [-8, -20, 14, 9, -18], [-16, 11, 19, -6, 15], [-21, 14, -5, -9, 11], [-2, 3, 9, 14, 29], [-29, 4, -6, 6, 11], [-14, -3, 12, 3, -2], [-25, 6, -34, -14, 2], [32, -25, -15, 14, -29], [-2, 13, -4, -14, 1], [3, -30, -11, 13, -18], [-1, -35, 10, 10, -18], [-4, -23, -4, 5, -24], [38, -15, -16, 1, -26], [-38, 21, 21, 11, 24], [-20, -28, 3, 15, 6], [25, -3, -2, 8, -22], [10, -14, 2, -6, -2], [3, 9, 2, 1, 22], [-4, -27, 6, 14, -7], [-3, 32, -5, -6, 21], [-13, -20, 5, 6, -11], [-40, 2, 0, -6, 9], [32, -14, -2, -17, 12], [-28, 28, 20, 4, 7], [12, 8, -6, -23, 9], [45, -3, -18, 10, -22], [29, -17, -32, 2, -14], [35, -18, -24, 7, -26], [-24, 25, -2, -18, 13], [-19, -16, 6, -13, -8], [4, 11, -3, -13, 8], [-35, 19, -4, -6, 8], [13, 14, 5, -5, -26], [-12, 22, 9, 6, 7], [-5, 10, 18, -8, 12], [34, 16, -13, -8, -31], [0, 24, -5, -11, -9], [-4, 13, -6, 6, -2], [-8, 11, -18, -6, 14], [25, -8, -5, 19, -28], [16, -23, -6, 23, -29], [-27, -19, 0, -4, -27], [0, 0, 6, -8, 1], [23, -20, -15, 7, -29], [-20, 2, 21, -3, 22], [1, 18, 17, -11, 0], [-36, 11, 11, 12, -2], [-47, -14, -1, 5, -2], [-34, 4, 28, 5, 12], [-1, 5, 12, 20, 18], [30, -6, -7, -2, -7], [-21, -29, -5, 18, -21], [17, -14, -5, -3, 4], [12, 5, 5, 8, 22], [45, -7, -9, -13, -11], [-24, -6, 10, 9, -7], [-4, 6, -2, -10, 3], [10, -6, 15, 6, -15], [-8, -14, 11, 11, 19], [21, -4, 9, 10, -10], [-33, 14, -2, -19, 39], [-16, 21, -1, -13, 29], [-11, 25, -2, -9, 29], [-35, 6, -10, -22, 9], [-75, 9, 24, -1, 28], [34, -5, -13, 5, 0], [-32, 15, 6, 10, -5], [-12, 33, 3, -19, 20], [-21, 25, 7, -26, 33], [3, -8, 12, 10, 22], [-37, -16, -3, 9, 21], [-16, 0, -12, -2, 1], [20, -14, -35, -7, -21], [13, 12, -5, -14, 10], [-25, -21, 10, 11, 20], [39, 23, 4, -8, 20], [-22, -8, 2, -15, 6], [15, -31, -1, 10, -27], [17, 6, -3, -10, -2], [-19, 19, 2, -12, 0], [-5, 1, 1, -13, 22], [25, -24, -16, 7, -15], [-4, -3, 5, 5, 10], [6, 41, 18, -9, 20], [2, 19, 13, 3, 11], [34, -8, -13, 11, -11], [15, -18, -1, 5, -14], [-10, -19, -22, 18, -1], [-4, 25, 12, -6, 22], [-37, 13, -5, -15, -7], [16, -12, -27, 12, -22], [-16, 30, 3, -19, 18], [-12, 4, 16, -9, 22], [-28, 11, -3, -11, 40], [-29, 11, 7, -10, -5], [20, 20, -18, -20, -6], [-4, 11, -18, 1, -15], [-15, -3, 3, 16, -20], [7, -10, 3, 12, 7], [-21, 13, -18, 2, 4], [-25, 12, -6, -23, 17], [10, 32, 0, -5, 27], [-23, -25, -7, 0, -6], [1, -5, -3, -24, 26], [-38, 21, 22, -10, 24], [-40, 34, 19, 1, 16], [26, -19, -20, 20, -16], [13, -9, 17, -7, 16], [-1, -11, -17, 6, -3], [1, -9, 4, -10, 19], [4, 47, -3, -7, 23], [-30, -13, 9, 18, 11], [-53, 33, 13, -21, 46], [-24, 0, -12, 11, -19], [25, 4, -7, -15, -19], [-29, -4, -12, -3, -5], [-14, 29, 5, 2, 31], [7, 16, -11, -5, 18], [-19, -7, 16, -18, 10], [-17, 7, -17, -22, -5], [40, -15, 18, 16, -11], [35, -21, 11, 3, 6], [-18, 13, 8, 4, 18], [-9, 6, -35, -9, -3], [6, -12, 7, 9, 22], [10, -3, -8, 15, -16], [-11, 35, 15, 12, 29], [-21, 14, 13, -4, 14], [-1, -24, -13, 8, 3], [-21, -25, -4, 0, -25], [7, -15, -2, -13, 3], [-21, 19, 11, -7, 19], [-5, 34, 12, 1, 8], [-24, 8, 8, 7, -16], [-14, -6, -23, -1, -19], [-17, -6, -18, -1, -7], [7, -29, 10, -9, 8], [-27, -12, -3, 8, 9], [-12, 3, -21, -22, -1], [27, 20, 7, 7, 2], [1, -29, -9, 12, -32], [-25, -14, 6, 16, -16], [26, -18, 4, -10, -3], [5, 26, -10, -15, -20], [-20, -23, 3, 11, 13], [19, -23, -13, 0, -24], [70, 2, -19, 0, -18]];
    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_e();".
// 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_e(: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_e();".
// 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_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6012_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-3, 15, 16, -7, -3, 1]>],Snew);
    return Vf;
end function;