
// Make newform 2420.2.a.l in Magma, downloaded from the LMFDB on 06 February 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_2420_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_2420_2_a_l();".
// 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_2420_2_a_l();".
// 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 := [5, 5, -4, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-3, -1, 1, 0], [0, -3, -1, 1]];
    Rf_basisdens := [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_2420_a();"
function MakeCharacter_2420_a()
    N := 2420;
    order := 1;
    char_gens := [1211, 1937, 2301];
    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_2420_a_Hecke(Kf)
    return MakeCharacter_2420_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]];
    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, -1, -1, 0], [1, 0, 0, 0], [1, -1, -1, 1], [0, 0, 0, 0], [4, -1, 0, 1], [2, 2, -1, 1], [-1, -1, 0, -2], [0, 0, 2, 1], [1, 1, 0, -2], [0, -1, 4, -1], [0, -2, 1, -3], [4, -2, 5, -1], [4, -1, 4, -5], [-3, 6, 2, -1], [-3, 4, 1, -3], [5, 1, -1, 1], [-1, 0, -3, -2], [3, -1, 6, -1], [-5, -1, -6, 1], [5, 1, -2, 1], [5, 1, 6, 0], [3, 0, -4, -1], [5, -2, 8, -4], [-1, 0, 0, 6], [1, -6, 1, -3], [1, 0, -6, -2], [3, 1, 7, 2], [7, 3, 4, -1], [-11, 0, -4, -1], [-2, 5, -1, 2], [0, 1, -6, 3], [-3, 3, -3, -1], [-3, 4, 1, 1], [0, 7, -1, 2], [1, 3, -7, 8], [10, -5, 0, 3], [12, -3, 6, 0], [-2, 5, 11, 1], [14, 1, 3, -1], [5, 0, 0, 0], [-4, 7, -14, 3], [1, -3, 0, 1], [19, 0, 4, -3], [5, 2, 5, -7], [-10, -3, -6, 2], [11, -3, 12, 5], [0, 8, -14, 6], [-13, 9, -1, -4], [-3, -2, 6, -7], [-5, 9, -9, -1], [-4, 4, -8, 5], [-5, -2, -15, -2], [-16, -3, 5, -4], [7, 0, 8, -1], [5, -5, 12, -1], [16, -1, 2, 1], [-8, -3, 7, -5], [11, -6, -3, -4], [-12, -1, -10, 8], [-2, 1, -13, -3], [11, -11, 1, -1], [-19, 4, -11, 3], [17, -6, 8, 3], [14, -9, 6, 6], [-10, 2, -2, 1], [-2, 4, -8, 0], [16, 2, 15, 2], [-8, -7, -7, 7], [10, -1, 2, 11], [-9, -1, -9, 1], [1, -4, -8, 14], [-23, -1, -6, -2], [8, -5, -1, 0], [-15, 8, -5, -8], [21, -2, -7, 1], [-7, 0, 10, -10], [-14, 4, -13, -6], [8, 2, 1, -3], [-2, 6, -5, 8], [6, 8, -5, 1], [16, 3, 17, -9], [-15, 2, -13, 9], [-1, -5, 5, 2], [4, 5, -8, 4], [-4, 5, 13, -3], [-13, 7, -17, 0], [0, 8, 9, 4], [-12, -8, -14, 13], [-18, -1, -7, 10], [-13, 0, -15, 8], [-6, -6, 18, -7], [-5, -5, -7, 2], [-23, 3, -12, 9], [-5, -1, 5, 6], [-16, 10, -10, -7], [-2, -5, -11, 17], [4, -9, -9, 11], [24, -5, 10, 4], [1, 14, -7, 6], [-16, 11, 4, 8], [5, -9, -2, 0], [-7, -1, 4, -2], [-11, 12, 12, 1], [-26, 9, -12, -3], [6, -4, -6, -11], [5, 5, 14, -14], [12, -5, 26, -8], [21, -4, 16, 11], [16, -3, -2, 5], [-6, 8, 8, -13], [3, -6, -26, -5], [-1, 6, 9, 1], [16, -11, 1, -16], [-1, 6, 8, -4], [-1, 2, 8, 8], [1, -5, -6, 0], [-12, 0, -5, -6], [-11, 10, -8, -1], [-23, 9, -13, -1], [-12, 3, -10, -14], [21, -1, 3, -4], [7, 0, -10, -2], [-9, 12, 2, -1], [3, 11, 25, 4], [-4, 4, 17, 1], [-7, 13, 4, 6], [-7, 14, -6, 17], [1, 10, -10, 10], [25, -6, -1, 2], [4, 1, 8, -4], [8, 6, 14, -4], [4, 8, 11, -14], [10, -6, 30, -8], [-7, 4, 20, 1], [11, 0, -8, -2], [-12, 3, -7, 7], [-23, 4, 1, 2], [-12, 5, -15, 8], [-1, -8, 8, 2], [-23, -4, -7, 13], [-5, 3, -5, 7], [29, -2, 21, -8], [-3, -6, 15, 3], [24, -4, 1, 3], [-4, -11, -8, -4], [5, 3, 12, -14], [16, 15, -5, 2], [-1, -8, -6, 9], [12, -12, 7, 8], [17, -4, -10, 0], [9, -17, -1, 2], [9, 5, -17, 17], [-30, 3, -31, -4], [28, 3, -4, 15], [-12, 18, -12, 4], [10, -10, -14, -12], [-1, 7, 19, -14], [24, -10, 2, 3], [-20, -1, -6, -8], [22, -1, 27, -1], [-10, -7, -29, 8], [19, -13, 17, -9], [-14, 3, 9, -13], [5, 2, 21, -9], [0, 16, 13, -2], [-11, -10, 0, 3], [17, -15, 5, -9], [8, 15, 18, -12], [20, -21, 10, 0], [10, -10, 7, -14], [-7, -9, -6, 0], [-4, -3, 4, -22], [15, -29, -7, 0], [-14, -3, -20, 1], [-4, -5, -3, -7], [-30, 9, -18, 0], [5, -17, 3, 6], [13, -20, 12, 6], [24, -4, 25, -9], [-2, 20, 0, 9], [14, 1, -9, 16], [-25, 1, -13, -2], [9, -12, -12, 8], [-28, 10, -21, -6], [-12, -12, -6, -2], [28, -19, -3, 5], [4, 2, -8, -2], [1, -4, -27, 13], [8, -12, -19, -11], [6, 5, 7, 15], [9, -13, 16, -6], [-5, 1, -14, 0], [27, -6, -11, 4], [16, 13, 20, -3], [-11, -5, -17, 20], [29, -22, -14, -5], [-17, -5, 14, -21], [15, -10, -7, -10], [18, 0, -6, 9], [-10, 3, -8, 6], [36, 0, -2, 4], [-8, 13, -21, 17], [5, 23, 0, -2], [-27, 13, -11, -9], [4, 3, 34, -11], [-16, 8, -31, -1], [-9, -3, -10, -11], [-32, 10, -7, 12], [10, -11, 26, -15], [-7, 10, -11, -15], [9, -20, -17, -11], [-16, 1, -20, -10], [-16, 0, -16, 10], [2, 4, -3, -2], [7, -1, 19, -2], [18, 4, 10, -9], [-8, -15, -7, 3], [-44, 1, -10, 11], [3, 18, 3, 13], [41, 0, 31, -3], [53, -15, 0, 3], [-28, -5, 7, -17], [33, -1, 24, -6], [18, -1, 18, 5], [2, 7, -11, -4], [10, 13, 20, 5], [16, -13, -5, -22], [14, -13, 4, -24], [23, -3, 10, 7], [0, 10, 12, -4], [0, -12, 16, 5], [22, 6, 5, -8], [-28, -10, -17, 14], [-10, 0, -2, 10], [17, 4, 10, -10], [-11, 20, -27, 3], [-39, 15, 2, -12], [20, 3, 31, 3], [-15, 11, -7, 3], [14, -2, 1, -14], [-18, -2, -11, -10], [4, -5, -7, -8], [-14, 15, -1, -5], [-17, -17, -8, 9], [34, 3, -15, 1], [-9, -15, 5, -2], [-7, -9, 18, -2], [1, 0, 10, -28], [-24, -8, 18, -22], [-7, 16, 12, -4], [16, -12, -9, -8], [47, -22, 15, 14], [-12, -17, -31, 12], [-5, 19, -14, 22], [-10, -2, 5, -34], [-19, 11, -17, 1], [-37, -3, -8, 6], [-10, -4, 29, 3], [4, 18, 14, 12], [3, 0, -7, -4], [-12, 0, -33, -3], [11, 5, 3, 19], [-29, 3, -21, -9], [5, 10, -6, -4], [7, -14, 10, -31], [13, 17, -20, 17], [18, 12, 14, 17], [-2, -6, -10, -8], [-8, -7, 18, -2], [-35, 8, 2, 14], [13, -14, -35, -6], [-36, 8, -3, -15], [19, 5, 18, -10], [18, -2, 47, -8], [-24, -14, -10, -4], [-8, -14, 20, -33], [-4, 17, -15, 15], [0, -10, -21, -8], [30, 7, 30, -5], [-29, -2, -22, 12], [6, 0, 37, 7], [34, -18, 9, 1], [11, -1, -13, 16], [-21, -10, -15, 19], [14, 16, 8, 1], [21, -22, -18, 0], [12, 10, -6, 33], [-5, -18, -19, 20], [-25, -8, -7, -3], [5, -14, -35, -9], [34, -11, 4, 6], [-51, 23, 1, 0], [1, -28, -8, 6], [7, -17, 17, 6], [-73, 11, -6, -6], [-16, -9, -8, 6], [21, 3, 40, 8], [-29, 27, 1, -18], [-47, 19, 4, -7], [-33, 5, 16, -12], [12, 10, -14, 7], [8, 17, -9, 2], [20, 0, -23, -10], [-4, 26, -6, -5], [-14, -14, 0, 3], [-29, 3, -12, 7], [33, -2, 0, 19], [-27, -5, -34, 10], [-15, 18, 9, 1], [4, 13, 0, 11], [-35, 4, -43, 11], [3, -14, -28, -6], [-1, 8, 12, -5], [40, -3, 37, -1], [-23, 7, 9, 20], [-44, 20, 7, 3], [43, -15, 17, -1], [42, 7, -8, 5], [-21, -20, 10, 0], [-42, -7, -25, -7], [3, 9, 36, -8], [-1, -15, 21, -27], [10, 9, 43, 11], [-25, -15, 28, -16], [11, -10, 23, 9], [-28, 16, -4, -19], [0, -2, 43, -13], [47, -4, 4, 6], [-8, 34, 18, -9], [-9, 1, 31, -24], [-34, -2, -44, -10], [3, -9, -6, 13], [-32, 0, -53, 9], [32, -24, 24, 3], [44, -14, 3, 6], [3, -1, 34, -15], [-28, -18, 5, -11], [-19, -3, -8, -9], [10, -8, 36, 6], [-25, -23, 0, -4], [-8, -12, -10, 21], [-55, -3, -33, 15], [-4, 5, -8, 15], [4, 3, -17, -19], [12, 7, 41, -2], [-1, 19, -4, 1], [-4, 1, 11, 17], [26, 12, 13, -2], [15, -16, -34, -3], [-20, -2, -4, -9], [-13, 13, -15, 31], [3, -11, 24, -8], [-6, -23, -24, 28], [-21, -5, 30, -21], [-40, -6, -5, 10], [-35, 1, -56, 22], [2, -5, -29, 11], [-40, 17, -35, -16], [-19, 4, -1, 5], [51, -9, 27, 6], [10, -29, 17, -17], [-1, -33, 34, -19], [23, -15, 11, 9], [-44, 17, 8, -10], [-6, -10, -26, 6], [39, -23, 10, -7], [-13, 24, -14, -15], [-20, -23, -4, 13], [-30, 16, -7, 9], [-10, 2, 20, -9], [-26, -9, -19, 21], [12, -12, 21, -4], [32, -23, -17, 5], [23, 9, 12, 19], [3, -15, -38, 16], [43, 8, 32, -1], [8, 3, -8, 33], [-18, -5, -28, 23], [-6, 9, -11, -13], [-5, 27, 20, 1], [-17, -8, -18, 10], [-29, 21, 4, -19], [30, 1, -4, -8], [-35, 43, 16, 5], [-24, -18, -46, 1], [53, 12, 43, -19], [-22, 3, -1, -16], [-28, 14, -2, -12], [0, -28, 6, -6], [-56, -13, -2, -1], [0, 3, -7, -10], [24, -16, 33, 11], [-61, 4, -1, -7], [31, -17, 35, -8], [-5, -9, -34, -3], [8, 32, 22, -22], [-8, -8, -16, 6], [-25, 3, -13, -15], [10, 12, -11, 7], [5, 3, 34, -8], [24, -42, -12, 5], [-15, -25, -44, 15], [-53, 10, 2, 13], [-1, 14, 30, 1], [35, 12, 23, -6], [-22, 21, 5, 28], [28, -3, 1, 0], [-65, 0, 8, -2], [-28, -11, -8, -7], [10, -1, -21, 39], [39, 6, -5, -4], [-2, 29, 3, -12], [-38, 36, 0, -11], [-27, -10, -4, 0], [3, -28, 24, -13], [20, 8, -4, 15], [-9, 21, 28, -13], [7, 25, 8, 18], [-21, 22, -27, 25], [5, 7, 42, -2], [-14, -7, -10, -27], [13, 4, 37, -27], [-24, -2, 48, -2], [12, -11, -36, -7], [2, 13, 39, -15], [-37, 4, -10, -1], [-37, -10, -25, 1], [15, 12, 45, -21], [57, -8, 30, -17]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2420_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2420_2_a_l();".
// 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_2420_2_a_l(:prec:=4)
    chi := MakeCharacter_2420_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_2420_2_a_l();".
// 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_2420_2_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2420_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![1, 5, -8, 0, 1]>,<7,R![5, 5, -9, -3, 1]>],Snew);
    return Vf;
end function;