
// Make newform 2898.2.a.h in Magma, downloaded from the LMFDB on 11 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_2898_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_2898_2_a_h();".
// 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_2898_2_a_h();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_2898_a();"
function MakeCharacter_2898_a()
    N := 2898;
    order := 1;
    char_gens := [1289, 829, 1891];
    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_2898_a_Hecke( : Kf := Kf)
    return MakeCharacter_2898_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], [2], [1], [-6], [-4], [2], [4], [-1], [10], [-8], [-8], [2], [6], [-12], [-12], [6], [-6], [-2], [-16], [2], [0], [-4], [6], [2], [-8], [-8], [-6], [4], [14], [8], [-10], [-6], [-10], [4], [-8], [-6], [20], [12], [-24], [0], [-2], [-16], [-2], [-2], [-16], [-12], [4], [-24], [22], [6], [24], [-6], [0], [-2], [-28], [24], [0], [-14], [-2], [24], [26], [-2], [-28], [2], [22], [-8], [-6], [12], [-8], [14], [12], [-8], [-4], [26], [-8], [4], [28], [26], [22], [0], [-12], [-12], [-34], [8], [-16], [18], [-26], [-8], [-32], [-28], [32], [-24], [-16], [24], [-32], [16], [-6], [36], [-14], [-32], [-24], [-36], [-6], [26], [-6], [42], [30], [24], [2], [36], [36], [30], [-40], [4], [18], [4], [-32], [-26], [-10], [26], [-50], [14], [44], [-22], [4], [32], [48], [32], [14], [28], [-24], [8], [-28], [42], [30], [-34], [40], [18], [-38], [-14], [-14], [-32], [10], [-20], [32], [-12], [-22], [-14], [0], [-10], [42], [44], [-12], [10], [20], [-40], [10], [26], [42], [-36], [26], [8], [8], [-6], [-40], [0], [12], [-10], [-20], [34], [16], [-36], [-62], [-4], [-10], [0], [22], [-56], [62], [-32], [0], [14], [6], [12], [-46], [14], [8], [-26], [52], [-6], [4], [-30], [52], [-46], [-22], [-46], [8], [-2], [-36], [40], [36], [20], [66], [56], [52], [-8], [48], [-10], [10], [42], [-24], [-56], [32], [-40], [18], [40], [-30], [-52], [6], [50], [16], [-10], [-16], [2], [26], [38], [32], [32], [4], [-58], [4], [-44], [-70], [-48], [-48], [-70], [24], [-68], [-24], [34], [-26], [4], [22], [-18], [32], [40], [36], [46], [-28], [16], [34], [28], [-2], [48], [-24], [-4], [-8], [20], [-2], [-24], [-18], [-52], [10], [-30], [-20], [-56], [-38], [-22], [-54], [40], [-26], [70], [-24], [-30], [32], [8], [22], [-70], [-24], [-76], [-60], [-8], [-62], [22], [40], [-26], [8], [44], [-34], [60], [20], [-42], [-32], [-6], [62], [-40], [-76], [-66], [-82], [-10], [12], [88], [48], [-6], [-54], [-52], [66], [48], [-10], [28], [0], [50], [24], [-80], [26], [62], [-64], [-2], [18], [76], [-18], [40], [8], [-30], [-2], [6], [58], [-24], [-36], [74], [-66], [-84], [-54], [-86], [-14], [-56], [-66], [-22], [16], [-2], [66], [-12], [48], [-20], [-68], [-76], [28], [24], [90], [74], [70], [-58], [56], [-88], [86], [0], [52], [22], [0], [80], [6], [-24], [22], [10], [-38], [-36], [84], [22], [0], [-78], [16], [24], [-56], [-66], [6], [4], [-42], [-34], [-2], [10], [42], [32], [-54], [72], [-4], [-32], [-76], [-18], [-96], [66], [76], [52], [-82], [-100], [-34], [56], [54], [18], [38], [64], [-78], [0], [6], [-44], [-80], [80], [22], [4], [-90], [-94], [-66], [78], [78], [-6], [24], [-88], [-16], [94], [-24], [36], [-58], [-72], [90], [14], [-48], [42], [-90], [-42], [60]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2898_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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