
// Make newform 4998.2.a.bv in Magma, downloaded from the LMFDB on 09 September 2025.
// 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_bv();".
// 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_bv();".
// 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 := [-2, 0, 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_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 := 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]];
    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], [1, 0], [-1, 1], [0, 0], [2, -2], [0, -4], [-1, 0], [3, 0], [3, 1], [-4, -2], [6, 0], [-3, 1], [-4, 4], [7, 2], [10, 0], [-6, 2], [5, -4], [4, -6], [-1, 4], [1, 1], [8, 2], [6, 4], [4, -4], [-5, 8], [-4, -4], [0, 8], [2, 4], [4, 10], [1, 11], [-2, -6], [16, 2], [2, 4], [-13, -2], [0, 10], [-18, 2], [0, 2], [6, 12], [8, -6], [-1, -7], [17, -3], [-1, -6], [3, -11], [4, -12], [-6, -6], [9, 3], [9, -11], [14, -4], [-4, 10], [-2, -4], [12, 6], [2, 2], [-12, -6], [0, -4], [-20, 8], [3, -10], [6, -18], [5, 9], [10, -16], [12, -10], [7, 4], [8, -6], [20, 6], [19, 6], [-17, -3], [10, 14], [-9, 7], [9, -2], [4, 10], [-16, 0], [-8, 14], [-7, -8], [2, 16], [11, 1], [-6, 10], [-12, -16], [26, 4], [-12, -2], [3, -19], [-14, -18], [6, -8], [16, -6], [-16, 0], [3, -3], [-21, -6], [9, 7], [-3, -10], [-28, -10], [-13, 18], [18, 16], [8, -8], [5, 6], [-7, -15], [15, 9], [19, 14], [12, -16], [11, -3], [6, -20], [-4, 14], [16, 16], [-20, 14], [-22, 8], [-16, 0], [-1, 12], [23, -10], [2, 8], [10, -8], [11, 2], [30, 8], [6, 12], [-10, 10], [15, -15], [-14, 16], [-38, -4], [2, 8], [18, -20], [-10, 16], [24, 16], [-10, 8], [21, -3], [-25, -16], [42, 2], [16, 0], [32, -6], [24, 14], [-12, 8], [8, 20], [-3, 19], [-30, 12], [-32, 10], [-36, 10], [27, 4], [-26, -12], [33, -7], [12, -18], [-33, -6], [-13, 8], [26, -12], [-6, 22], [-8, 26], [-2, 14], [-6, 24], [9, -1], [10, 16], [10, -10], [-14, -16], [37, 3], [-12, -14], [-10, -26], [-15, -6], [12, 22], [4, -10], [-8, -20], [0, -8], [18, 8], [-42, 6], [-19, -15], [-12, 2], [-22, 2], [-33, 2], [-37, -9], [-18, 0], [-23, -16], [-32, -6], [-17, -4], [19, -22], [-15, 9], [9, 5], [4, -14], [-16, 24], [-17, 11], [9, 16], [0, 16], [49, 5], [6, -36], [-30, -18], [-40, -14], [0, 26], [-13, -13], [18, 2], [-2, 40], [-16, 4], [-38, -8], [-4, -38], [13, 18], [6, -42], [-16, -18], [3, -35], [5, -10], [22, -20], [-14, -24], [-4, 14], [-14, 10], [-24, 8], [38, -12], [18, 6], [16, -10], [0, 4], [-7, -15], [-18, 22], [-14, -18], [-11, 7], [-5, -27], [24, -8], [19, -4], [4, 8], [-10, 28], [-38, -6], [52, -4], [-2, 18], [-28, 24], [-10, -14], [-18, -34], [-11, 27], [8, -28], [34, 0], [16, -32], [-36, 2], [-22, -20], [38, 16], [0, 10], [30, 14], [43, -7], [-35, -4], [2, -40], [31, -10], [-44, 16], [-18, -14], [50, 8], [-38, 4], [-4, -34], [-12, 40], [6, 34], [56, 2], [-14, -4], [-5, -12], [0, 18], [-52, -8], [4, -14], [-20, -14], [-4, 36], [-2, 24], [20, -4], [-28, -20], [0, -2], [20, -22], [7, 37], [39, -17], [-2, -16], [-3, 2], [-2, 44], [-14, -28], [12, 16], [8, 46], [6, 28], [-48, 4], [-17, 22], [45, 1], [-54, 6], [17, 39], [-27, 36], [-33, 9], [-44, 8], [33, -7], [-35, -17], [38, 16], [49, -16], [22, -30], [-30, 20], [-48, 0], [30, -20], [-28, 26], [52, -8], [53, 0], [0, 16], [-29, -6], [-12, 24], [8, 16], [2, -12], [-38, 8], [7, -32], [28, 14], [6, 4], [-43, 1], [-20, -10], [16, -12], [6, -30], [-40, 2], [39, -25], [-14, 0], [5, -24], [-49, -15], [-24, -10], [7, 42], [-48, -2], [43, 1], [24, -34], [-46, 6], [-10, -8], [-10, -4], [15, -22], [-10, 0], [-10, -34], [-27, -15], [68, 8], [-52, 26], [30, 4], [-24, 0], [5, 41], [12, 6], [-38, -28], [39, 7], [40, -26], [-30, -16], [12, 12], [6, 22], [-9, 10], [27, -6], [54, 0], [34, 28], [25, -4], [6, -26], [-44, -10], [22, 18], [-58, -16], [12, 0], [3, 8], [74, 0], [18, 12], [13, -3], [61, 11], [-1, -13], [27, -13], [-19, 21], [-1, -20], [-28, -34], [10, -30], [48, -20], [34, -18], [-22, 14], [66, 6], [70, 8], [3, 18], [52, -18], [-38, -10], [-16, 36], [26, 2], [21, 1], [-39, -20], [18, -8], [-9, 11], [-31, -34], [10, 14], [-54, 2], [-1, 15], [-64, -10], [25, -18], [2, 44], [18, -12], [-8, 18], [10, -4], [16, -2], [-42, -26], [18, 2], [-6, 26], [4, -8], [-37, 38], [-15, -19], [-2, 24], [8, 50], [-63, -8], [8, 56], [15, 11], [-70, -12], [-54, -10], [-27, 11], [24, 44], [10, -44], [3, 12], [9, -32], [-62, -12], [-20, 2], [66, 8], [-7, 37], [-4, 18], [46, 2], [-15, 31], [-30, -20], [-42, -12], [-12, -6], [-16, 42], [56, 22], [52, 18], [53, -4], [-20, 36], [26, -18], [-36, -18], [-2, -44], [-7, -12], [26, -12], [16, 42], [36, 14], [51, 22], [16, -22], [48, 2], [-12, 30], [3, 19], [94, 6], [-25, 34], [-4, 64], [-42, -10], [-6, -48], [-74, -8], [97, 0], [-76, -4], [-27, -2], [-8, 2], [-5, 45], [19, -39], [-78, 8], [40, 12], [-64, -10], [47, 23], [66, 28], [12, -56], [-28, 22], [58, -18], [24, -24], [40, 46], [-100, 4], [-7, 29]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4998_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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