
// Make newform 4998.2.a.cl in Magma, downloaded from the LMFDB on 17 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4998_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_4998_2_a_cl();".
// 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_4998_2_a_cl();".
// 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 := [28, 12, -11, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-6, -1, 1, 0], [0, -8, -1, 1]];
    Rf_basisdens := [1, 1, 2, 2];
    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_4998_a();"
function MakeCharacter_4998_a()
    N := 4998;
    order := 1;
    char_gens := [1667, 2551, 4117];
    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_4998_a_Hecke(Kf)
    return MakeCharacter_4998_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 := [[-1, 0, 0, 0], [-1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1], [-2, 1, 0, 0], [1, 0, 0, 0], [-2, 1, -2, 1], [-2, 1, -1, 1], [0, -1, 0, -1], [-4, 1, 0, 1], [4, 0, 1, 1], [0, 1, 2, -1], [-2, 0, -4, 1], [4, 1, -4, 1], [6, -1, 0, 0], [0, -1, 3, -1], [0, 0, -2, -2], [2, 2, 2, -1], [-2, 2, -5, 0], [-4, 1, 4, 0], [-2, 2, -2, 1], [-2, 1, 1, 0], [0, 3, -6, 0], [0, 1, 0, 2], [2, 0, 5, 0], [-4, -1, -5, -2], [6, -2, 2, -2], [2, 5, 1, -1], [-2, 2, -1, -1], [2, 0, -2, 0], [4, 0, -8, 2], [10, -1, -4, -1], [-8, 4, 0, 1], [0, 3, 2, 0], [12, -1, 6, 3], [-4, 2, 0, -2], [4, -4, -3, -2], [4, -6, -2, -1], [2, 2, -4, 4], [-2, 1, -6, 5], [-14, 1, -2, 1], [2, -2, 0, -3], [2, 3, -4, 3], [8, -1, 2, -3], [-4, -3, 4, -3], [-4, 4, 3, -2], [-6, -7, 5, -3], [4, -4, -4, 0], [-2, -7, 4, -4], [14, -4, 3, 3], [2, 6, 0, 1], [-6, -4, 4, -2], [10, -3, 5, -4], [4, 3, -2, 6], [6, 6, -2, 1], [10, 0, 2, 6], [-4, 1, -9, 4], [6, -3, 1, 3], [-2, -2, -6, 2], [-10, 0, -4, 3], [14, -3, -1, -1], [14, -4, 2, 2], [10, -2, 0, -1], [-2, 2, -10, 0], [8, 2, 8, 0], [-2, 0, -12, -3], [18, 0, 4, 0], [4, 10, -4, 1], [-2, -3, -6, -2], [4, 7, 0, 0], [0, 2, 0, 2], [0, 4, -8, 0], [14, 3, -2, 7], [12, -8, -3, 2], [4, 3, 2, -1], [8, -2, -6, -2], [8, 2, 2, 2], [4, 5, -9, 1], [20, -2, 3, -2], [-4, 1, -4, -1], [-2, -3, -12, -1], [2, -4, -1, -6], [-12, 8, 3, 2], [8, 3, 2, 7], [4, 3, 18, -1], [-2, 2, 9, -3], [16, -1, -10, 0], [6, -3, 5, -7], [-2, 4, 2, -2], [0, -5, -3, -7], [-20, 2, -14, -5], [10, -6, 2, 3], [14, 3, -2, -1], [-12, -2, 11, -2], [-2, 6, 2, 8], [10, 1, -1, 7], [-12, -1, -2, 5], [14, 0, 2, -2], [20, 0, -9, 1], [12, -3, -15, -1], [10, -2, 8, 0], [2, -1, -15, 0], [-2, 6, 6, 6], [-8, 10, 7, 2], [-4, 1, 11, 3], [18, -5, 9, -2], [-6, 0, -10, 2], [0, 4, -14, 10], [-6, 8, 0, 0], [4, 1, 12, 1], [14, 11, -12, 7], [-2, 0, 5, 3], [4, -6, -8, 3], [-6, -5, 4, 1], [6, 6, -15, -1], [0, -6, 8, -11], [4, 3, -10, -1], [0, 6, 8, -4], [2, -2, -16, 0], [12, -10, 6, 2], [10, -5, 10, 3], [16, 3, 6, 2], [-2, 10, -6, 4], [-18, 4, 0, 3], [-2, -11, 4, -4], [8, -8, -11, -3], [-8, -6, 4, 2], [8, -7, 3, -4], [-12, -6, 0, 4], [4, -4, 26, -2], [2, 5, 3, -7], [-8, 4, 6, 0], [6, -3, -24, -3], [28, 1, -4, 2], [-12, 2, 5, -2], [-22, -5, -7, 1], [8, 4, -24, 1], [14, -3, -19, 1], [-12, -5, 1, -1], [-16, -6, -16, 5], [-12, -5, 22, -1], [2, 4, -16, -1], [-4, -2, -8, -1], [-2, 1, -18, 4], [30, 0, 4, 7], [4, -7, 20, -3], [6, -2, 4, -8], [2, 2, -4, 6], [-10, -10, 18, -9], [4, -6, -23, -3], [0, -2, -4, -4], [-4, 2, -22, 2], [-10, 2, 28, 1], [-40, 3, 7, 3], [-14, -1, 5, 1], [-26, 4, 6, 2], [-14, -6, 8, 0], [-8, -11, 1, -3], [4, -3, -4, 2], [-18, 12, 0, -6], [6, -9, -16, 5], [4, -1, -2, -1], [-2, 3, 15, -8], [-10, 7, 2, -9], [-4, -2, -4, -4], [-26, 0, -14, -1], [-18, 5, -22, -3], [-38, 9, -2, -3], [0, -13, 6, 0], [-6, -2, -4, -6], [26, 3, 6, 6], [-38, -4, 3, 2], [6, -3, 22, -2], [6, 5, -7, -1], [-2, 3, -10, -3], [-8, 2, 15, -4], [-4, 10, -12, 12], [-14, 9, -5, -5], [12, 12, -10, 8], [-10, 4, 10, 6], [4, -2, -2, -4], [-6, 5, 13, 1], [-6, 6, -6, -8], [-6, -4, 8, -3], [10, 6, 3, 10], [-12, 12, 17, 7], [34, -11, -12, -3], [-2, 10, -22, -2], [-16, 2, 14, -1], [-8, 13, -14, 2], [0, 0, 2, -1], [-30, 2, -4, -7], [-22, 2, -21, -4], [-24, -2, 22, 1], [-14, 7, 14, 3], [-2, 3, 0, -1], [-40, 2, 1, -3], [-22, 7, -2, -7], [-8, -6, 2, 0], [0, 6, -30, 6], [0, 9, -8, 3], [6, -1, 22, -4], [12, 1, 19, -13], [10, 11, -7, 8], [2, 3, -5, 11], [-4, -13, 11, -6], [10, 10, -12, 8], [-20, 7, 1, 3], [6, -9, 16, -9], [10, -1, -6, -5], [6, -12, 3, -2], [6, -10, 8, -5], [18, -7, 1, 6], [2, -8, -24, 5], [14, -8, -8, 0], [-4, 0, -20, -6], [16, 9, 10, 6], [-14, -9, -11, 3], [32, -13, -10, -8], [-6, 8, -22, 14], [44, -3, 0, -5], [6, 4, 8, 8], [2, 4, 4, 1], [22, -3, 13, 2], [14, -10, 12, -4], [14, -8, -16, 0], [-38, -3, -1, -5], [24, 5, 15, -4], [-14, 14, 10, 12], [-10, 12, -14, -2], [16, -2, -16, -4], [14, -11, 4, 5], [-6, -9, 10, 3], [14, 18, -20, 6], [-8, -12, 8, 2], [-20, 1, -30, -6], [8, 11, -20, 5], [-34, 16, -2, -2], [-4, 5, -4, 3], [-8, 10, 12, -9], [46, -12, -6, 2], [16, -17, -5, 0], [6, -1, -20, 1], [8, -7, -2, -11], [2, 0, 0, -3], [-16, 16, 4, 4], [4, 15, -26, 3], [10, 2, -12, 9], [6, -6, 2, -3], [-14, 1, 10, -13], [-50, 2, -16, 0], [-24, 8, -6, -8], [-8, 5, 10, 8], [-2, -11, 31, -1], [-4, 0, -28, -2], [-4, 4, -3, -3], [22, 4, -8, 2], [24, -1, -12, 4], [-4, 12, 5, 6], [22, -12, -4, -1], [12, 0, 0, -10], [-38, -2, -12, 0], [-38, -16, 16, -4], [10, -12, 8, -4], [38, 1, 8, 5], [4, -12, -18, 0], [40, -13, -8, 0], [-16, 6, 9, -6], [26, -5, -8, 10], [-38, -6, 0, 0], [-30, -10, 6, -5], [4, -4, 13, -10], [-2, -11, -4, 3], [-16, 9, -17, 7], [16, -3, 5, -12], [6, 3, -30, -3], [-26, -1, -2, -17], [-18, 5, 18, -6], [18, -17, -9, 2], [-4, 9, 14, 3], [-34, 2, -16, 5], [-46, 4, -4, -3], [-26, -1, -28, 6], [-22, 4, 8, 7], [18, -8, -2, 11], [2, 7, -2, -7], [32, -1, 24, -7], [18, -1, 11, 9], [-4, -21, 2, -2], [-4, -12, -14, 6], [-20, 6, 6, 0], [10, -12, 22, -14], [-32, 5, 12, -3], [24, -4, 13, -7], [-8, -19, 22, -10], [36, -11, 5, 8], [34, -5, -11, 5], [-24, 9, 20, 3], [30, 0, -2, 14], [-40, -6, -21, 4], [18, 9, -40, 4], [34, 4, 26, -5], [0, 6, 34, 9], [-8, -1, 31, -1], [-2, 12, -22, 10], [-20, 20, 0, 14], [34, -7, -34, -3], [-4, -2, 18, -6], [22, 5, -4, 9], [-2, -8, 14, 2], [0, 4, 14, -10], [-10, -6, -15, -1], [12, -8, 6, -8], [-2, -2, -8, 9], [-12, 0, -5, 10], [-28, 3, -9, -9], [-18, -2, -1, 6], [18, 6, -2, 14], [18, -5, 38, -5], [-20, 10, 8, -9], [2, 1, -18, -1], [-38, 7, -15, -11], [16, 7, -14, 9], [20, -1, 17, 1], [12, -13, -17, 7], [-12, 15, 3, 17], [24, -8, -8, 1], [-10, -3, -37, 1], [-8, 2, -28, 0], [28, -12, -31, -3], [-32, -18, 36, -8], [36, -12, -12, -10], [-2, -19, -13, 2], [-24, -11, 1, -1], [8, -14, -10, -8], [50, 4, -2, 6], [20, -9, -14, 5], [-36, -15, 20, -12], [8, -5, 11, -6], [-2, 17, 10, -1], [26, 3, -20, -1], [-4, -1, -24, 2], [-50, 7, -8, 3], [46, -7, 16, -8], [8, 6, 12, 15], [-6, -11, 26, 3], [6, -12, 36, -3], [30, -6, -20, 5], [-48, -1, 18, -2], [-14, 7, 22, 3], [34, 1, 38, -9], [-18, -13, -8, -8], [16, -24, -12, 8], [18, 4, 16, -4], [-36, 17, 4, 10], [-32, 1, 10, 9], [8, 3, 20, -1], [44, -1, -19, -3], [30, -2, -34, -3], [-4, -12, -43, 7], [-24, 4, 20, -4], [-10, 8, -8, -7], [52, -10, 2, -11], [34, -13, -20, 1], [18, -17, -14, 4], [-20, 1, -44, 8], [44, -5, -22, 3], [-18, 13, 4, -13], [-12, -11, 6, -15], [30, 8, 12, -8], [-6, 5, -37, 9], [68, -7, 2, 4], [-10, 23, 5, -3], [46, 7, -5, 7], [32, -1, 20, -1], [2, -14, 23, -6], [0, -7, 43, -5], [16, -15, -10, 4], [32, -13, -25, -5], [-40, 11, 34, 4], [-22, 13, -28, 5], [26, -22, -12, -13], [-26, 4, -3, -11], [8, -14, -20, -9], [-46, -4, -4, -7], [-38, 8, 26, 0], [-24, 4, 8, 4], [-24, -5, -21, -13], [20, -3, -4, -1], [-10, -2, -4, -8], [-8, 19, -4, 2], [12, 24, -24, 8], [-14, -1, 0, -1], [26, -20, -18, -1], [22, -26, 2, 10], [-28, 21, 1, 0], [6, 10, -8, 12], [-20, -11, -3, -5], [12, 19, -2, 4], [-26, 3, 38, -3], [18, 11, 26, -1], [-10, 7, 40, -7], [2, 13, 14, 9], [22, -8, 19, -8], [-12, 4, -32, 6], [30, -12, 26, 2], [-18, 25, -12, -5], [-30, 18, -16, -8], [-16, 11, 6, 15], [-4, 3, -16, 0], [28, 11, 2, -2], [4, 16, 8, -2], [4, 1, 5, 11], [38, -4, -8, 2], [8, -23, 6, -4], [38, -2, 25, -14], [32, -2, -10, -4], [-44, -14, 12, -16], [-16, 19, 0, -1], [16, 21, 6, 2], [4, 7, 24, -19], [18, -5, 45, -11], [22, -11, -35, -4], [-20, 1, -30, 4], [18, 14, -15, 20], [-12, 8, 18, 15], [-8, -3, 27, -5], [2, 6, 16, -4], [8, 12, -24, 12]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4998_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4998_2_a_cl();".
// 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_4998_2_a_cl(:prec:=4)
    chi := MakeCharacter_4998_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_4998_2_a_cl();".
// 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_4998_2_a_cl( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4998_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![28, 12, -11, -2, 1]>,<11,R![28, 4, -21, 2, 1]>,<13,R![8, -24, 1, 6, 1]>,<23,R![56, -56, -2, 8, 1]>],Snew);
    return Vf;
end function;