
// Make newform 6012.2.a.a in Magma, downloaded from the LMFDB on 18 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_a();".
// 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_a();".
// 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, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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], [3, 0], [2, -1], [0, 0], [5, -1], [0, -1], [2, 0], [0, 1], [-3, -2], [2, 2], [5, -2], [-3, 4], [5, 2], [3, -2], [0, 2], [6, -6], [-7, 6], [-1, 4], [3, -3], [-10, 3], [11, -2], [-3, 2], [0, 6], [-7, 5], [-3, 6], [-1, -1], [-3, -2], [2, 0], [9, -8], [5, 4], [-3, 10], [12, -4], [-1, 3], [-6, -5], [8, 5], [-13, 6], [-10, 2], [1, 0], [-15, 4], [6, -3], [2, -4], [9, 1], [-1, 3], [-6, 1], [-13, 1], [2, 5], [11, -5], [-15, 6], [11, -1], [0, -3], [-18, 3], [5, -1], [15, -2], [-3, -7], [-3, -4], [-3, -1], [-4, 8], [14, 5], [-3, 8], [8, -8], [-18, 0], [-4, 13], [3, -4], [-1, 5], [6, -15], [23, -6], [23, 2], [-15, -3], [5, -18], [18, -6], [-15, 6], [5, 6], [-28, 5], [23, -10], [-9, 16], [-9, 6], [-13, 7], [24, -1], [26, -3], [3, 4], [8, 2], [6, -10], [-4, -11], [-13, -4], [-21, 9], [-27, 10], [23, -7], [24, -1], [11, -4], [-3, 7], [24, -12], [17, 6], [27, -12], [26, -11], [12, -5], [-18, -3], [30, 6], [5, -6], [-31, -2], [14, -21], [3, -6], [-12, -5], [-27, -4], [20, -15], [-13, -5], [36, 3], [33, -2], [33, -3], [-10, 15], [-7, 9], [-13, -11], [-3, 18], [2, 10], [-4, -13], [9, 1], [-1, -5], [6, 13], [-3, 7], [6, 6], [-22, -7], [14, 12], [0, 6], [15, 15], [-1, -18], [15, -10], [11, 17], [39, -7], [8, 9], [14, 0], [26, -13], [-36, -7], [-19, -2], [2, 9], [6, -1], [-1, -6], [-6, -2], [2, 18], [-9, -12], [-3, -9], [-1, -16], [6, -9], [-19, -1], [-36, 15], [-22, 26], [-45, 2], [20, 9], [9, -15], [-46, 2], [0, 5], [8, 5], [24, -4], [2, -13], [3, -6], [23, -12], [-21, 6], [-7, 3], [-27, 5], [-10, -18], [-27, -14], [-21, 3], [6, -21], [-37, 5], [15, -28], [-15, 25], [-24, 24], [8, -12], [-34, 4], [2, 8], [9, -21], [-48, -4], [-43, -4], [-39, 3], [-43, 10], [5, 20], [-6, 24], [-40, 8], [-30, 6], [11, -18], [-16, 1], [29, -19], [-27, 3], [-1, -20], [-21, 3], [-42, 0], [-30, -5], [38, -13], [-25, 14], [-1, -14], [-3, -8], [-7, -10], [-27, -10], [26, 15], [-12, 7], [-3, -24], [-9, -18], [8, -11], [2, -22], [-3, 22], [0, 6], [27, -14], [38, 4], [26, -8], [11, -8], [60, 1], [-3, 15], [2, 5], [21, -4], [15, -29], [-40, 14], [-49, -5], [-12, 25], [20, -1], [-6, 8], [-60, 4], [-7, -11], [-40, 0], [21, -14], [-15, -15], [39, -14], [35, -10], [5, -24], [-15, -25], [-7, -27], [-15, 15], [2, -14], [15, -1], [63, 4], [-25, 10], [6, -4], [17, 16], [-1, 20], [-34, 20], [-27, 24], [50, 9], [-33, -9], [-10, 31], [18, 21], [33, 3], [6, 27], [-3, -28], [-13, 13], [-1, -9], [-40, 16], [12, -30], [-18, 12], [-4, 18], [-51, 0], [2, -28], [-51, 10], [47, -22], [-15, 4], [-18, -8], [11, -7], [-21, 30], [18, -15], [14, -14], [-55, 6], [33, -6], [-4, 16], [29, -21], [-24, -4], [-10, 5], [11, 9], [-6, -12], [11, -20], [-6, 4], [33, -34], [17, 4], [-33, 31], [2, -15], [11, -4], [-22, 32], [-55, -8], [-31, 24], [50, -17], [-6, 6], [44, -18], [2, -33], [-42, -5], [-6, 27], [44, 4], [54, -21], [2, 22], [-10, -20], [-3, 21], [2, -25], [-21, 24], [-1, -22], [-33, 15], [45, 14], [18, 23], [-24, 7], [3, -3], [2, -11], [-27, 9], [-61, -4], [63, -13], [-12, -6], [-37, 35], [-16, 9], [-21, -3], [77, -8], [-30, 7], [5, 29], [2, 18], [3, 27], [8, 8], [-9, 14], [-1, 12], [-33, -9], [36, 18], [15, -14], [44, 14], [9, -10], [11, -30], [-9, -10], [-24, -18], [-4, -28], [-3, -28], [38, -23], [32, 8], [12, -13], [65, -18], [-18, 30], [38, -18], [20, -27], [2, -29], [9, 13], [-24, 11], [29, -23], [-21, 20], [-34, 7], [33, -18], [47, -9], [45, -24], [-22, 10], [-60, 14], [26, 25], [-34, 0], [2, -34], [-12, -30], [-27, -1], [47, -8], [60, 6], [27, 7], [8, -16], [-10, 15], [39, 5], [3, -29], [-19, 0], [-16, 8], [-45, -10], [32, -40], [-46, 1], [36, 9], [-48, 18], [21, 1], [-12, 17], [57, 0], [38, -10], [-48, 5], [-9, 12], [-3, 7], [-43, 26], [47, -8], [-3, 14], [50, 6], [32, 2], [-18, 30], [-28, 2], [42, -24], [-15, 18], [44, -15], [23, 22], [-18, 0], [-27, -14], [-22, 3], [9, -21], [29, -31], [-15, -7], [-36, 31], [-1, 39], [12, 3], [17, 28], [63, -2], [-25, 16], [35, 6], [53, 18], [36, -9], [-46, 15], [51, 9], [24, -6], [-7, 15], [-27, -6], [23, -7], [-25, -16], [-42, 34], [-13, -18], [-15, -30], [-61, -13], [-60, 10], [2, -4], [-42, -4], [18, -33], [32, 28], [2, -41], [-69, 5], [-64, -14], [-87, 11], [5, 20], [30, 12], [-15, -13], [-49, -6], [-46, 2], [0, 11], [51, -12], [-25, 6], [93, 0], [-36, 39], [-57, 17], [-19, 17], [-18, -36], [12, 24], [-43, 0], [-6, 8], [27, -3], [45, 1], [62, -16], [27, -12]];
    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_a();".
// 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_a(:prec:=2)
    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_a();".
// 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_a( : 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, 1]>],Snew);
    return Vf;
end function;