
// Make newform 2898.2.a.u in Magma, downloaded from the LMFDB on 25 April 2024.
// 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_u();".
// 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_u();".
// 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)
    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+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], [4], [1], [-2], [2], [-2], [-2], [-1], [6], [0], [4], [10], [-10], [8], [0], [0], [-4], [2], [-8], [-2], [-8], [6], [-6], [-2], [14], [-12], [2], [-16], [-6], [8], [0], [-18], [-16], [24], [16], [-8], [24], [0], [2], [-16], [-20], [20], [-6], [-10], [0], [-20], [16], [-14], [12], [6], [-8], [-18], [-26], [-14], [8], [18], [16], [2], [10], [-6], [12], [-12], [-24], [22], [30], [20], [26], [-16], [14], [-34], [20], [-32], [-36], [2], [16], [36], [-38], [38], [-6], [-2], [4], [28], [-34], [-8], [-8], [10], [6], [-30], [-32], [-34], [-40], [40], [-8], [-8], [12], [-6], [30], [-10], [18], [-28], [28], [34], [-26], [2], [38], [-16], [-30], [-24], [-2], [16], [-8], [-6], [10], [-20], [-42], [-14], [-8], [-14], [26], [28], [-18], [-36], [-28], [-40], [-36], [-12], [48], [8], [-32], [16], [-16], [12], [48], [22], [14], [0], [18], [0], [6], [16], [50], [-32], [-54], [14], [0], [42], [22], [-28], [40], [58], [-38], [44], [48], [38], [-36], [48], [-14], [34], [20], [56], [30], [48], [-30], [-2], [-36], [16], [38], [30], [6], [-30], [-2], [48], [-30], [56], [-30], [40], [58], [12], [8], [32], [6], [-38], [-42], [20], [0], [38], [-46], [-26], [0], [-2], [-36], [-42], [-42], [2], [34], [-30], [-44], [34], [0], [36], [-24], [6], [-62], [-38], [42], [0], [-44], [26], [20], [-50], [-50], [-12], [42], [32], [14], [40], [-18], [24], [2], [14], [-60], [-2], [44], [-28], [-26], [42], [0], [28], [32], [-14], [10], [20], [10], [50], [-28], [6], [20], [-60], [-16], [22], [44], [24], [22], [6], [-64], [-40], [-10], [38], [56], [40], [-6], [32], [18], [30], [40], [0], [22], [-30], [26], [-76], [-6], [-50], [36], [-66], [18], [20], [-14], [-42], [14], [-50], [38], [-54], [-44], [50], [72], [76], [62], [10], [2], [72], [28], [68], [28], [-4], [-72], [38], [12], [-16], [66], [0], [6], [-6], [-38], [2], [-60], [-56], [-2], [60], [64], [-34], [36], [16], [52], [26], [-62], [32], [-84], [-72], [-18], [16], [-16], [6], [-28], [36], [10], [-36], [-32], [26], [18], [-38], [14], [-18], [-8], [-18], [62], [22], [-64], [48], [60], [-6], [26], [-16], [-16], [30], [-12], [-20], [50], [10], [28], [-26], [78], [22], [-88], [52], [40], [42], [-56], [76], [12], [28], [54], [-58], [-64], [-32], [-74], [-56], [-50], [-66], [-8], [48], [42], [32], [6], [-32], [22], [78], [-48], [-90], [0], [-20], [-72], [28], [-60], [78], [40], [-12], [58], [-74], [2], [24], [-34], [-8], [50], [70], [-96], [8], [14], [58], [84], [10], [-70], [-44], [0], [60], [-34], [20], [30], [-2], [-38], [50], [-14], [-88], [46], [-66], [-56], [16], [-62], [-6], [-36], [14], [18], [26], [34], [-86], [90], [40], [-72], [94], [-44], [28], [-32], [8], [48], [-70], [78], [22], [54], [-72], [-8]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2898_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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