
// Make newform 2898.2.a.j in Magma, downloaded from the LMFDB on 19 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_j();".
// 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_j();".
// 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], [3], [1], [0], [5], [0], [8], [1], [-3], [2], [-7], [-9], [-1], [3], [12], [6], [14], [-4], [-6], [-4], [-16], [12], [-6], [-1], [6], [-1], [-12], [-19], [-15], [-13], [18], [9], [5], [0], [11], [-4], [20], [12], [-6], [-15], [2], [12], [-1], [-9], [17], [8], [14], [15], [-4], [6], [-12], [-19], [15], [-6], [9], [18], [-28], [-4], [15], [14], [30], [11], [-12], [-10], [27], [-16], [-4], [-3], [-10], [-27], [-21], [29], [-22], [29], [-36], [30], [-22], [-18], [32], [-36], [-19], [-15], [17], [26], [27], [-18], [-28], [30], [-31], [33], [6], [-31], [-12], [14], [-18], [0], [-30], [26], [20], [-10], [-24], [3], [-45], [-4], [26], [12], [27], [24], [-16], [14], [-1], [-6], [-10], [20], [15], [14], [0], [9], [0], [-10], [35], [-18], [12], [-49], [-36], [-22], [-45], [-28], [8], [50], [-24], [-40], [-34], [-30], [-37], [51], [-4], [-33], [12], [5], [30], [-13], [-6], [-10], [-6], [-49], [15], [-31], [-12], [-40], [-30], [26], [0], [41], [-21], [-16], [-33], [-25], [51], [3], [18], [44], [0], [21], [-30], [-28], [26], [-22], [-24], [42], [-31], [-51], [26], [-16], [-42], [-10], [-6], [-19], [-22], [-28], [-3], [-40], [21], [-9], [-33], [-34], [8], [47], [3], [50], [39], [-52], [-30], [-30], [-60], [50], [14], [54], [-27], [18], [-52], [-7], [-22], [-15], [-48], [53], [12], [-30], [-4], [-25], [54], [44], [-24], [-3], [-58], [44], [-9], [21], [-27], [8], [-40], [18], [-16], [24], [26], [60], [-72], [71], [-48], [14], [-46], [44], [-36], [8], [48], [41], [30], [15], [60], [6], [20], [20], [50], [21], [-15], [74], [51], [-25], [-51], [-13], [-54], [9], [65], [-24], [33], [77], [2], [30], [-64], [56], [-54], [41], [74], [42], [14], [-66], [0], [-1], [66], [41], [20], [23], [74], [-58], [74], [-39], [2], [-58], [-69], [27], [-22], [30], [80], [-67], [-30], [8], [18], [-82], [-33], [-60], [-39], [0], [-51], [-46], [66], [17], [12], [-42], [-7], [77], [48], [-10], [51], [-49], [-7], [9], [20], [27], [38], [-27], [-30], [66], [-64], [84], [86], [0], [60], [-13], [-12], [-82], [-10], [-42], [-85], [33], [-34], [56], [53], [-21], [36], [56], [-27], [62], [-12], [-25], [-12], [77], [6], [-70], [83], [-10], [-57], [-66], [80], [-48], [69], [29], [62], [36], [69], [68], [-91], [-33], [80], [41], [-39], [-30], [60], [-72], [54], [-22], [-33], [12], [-60], [-7], [71], [24], [-4], [-64], [-84], [47], [-6], [24], [-40], [-40], [-90], [-33], [59], [54], [56], [-66], [54], [-16], [66], [44], [-75], [53], [5], [-31], [-54], [-82], [90], [9], [53], [-60], [26], [-25], [60], [-13], [-3], [-55], [-102], [50], [-48], [-42], [50], [-37], [-96], [-28], [96], [-22], [33], [12], [-76], [50], [-24], [-54], [-82], [-54], [78], [78], [32], [36], [-84], [-76], [-12], [-96], [48], [-25], [51]];
    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_j();".
// 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_j(: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_j();".
// 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_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2898_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-3, 1]>,<11,R![0, 1]>,<13,R![-5, 1]>],Snew);
    return Vf;
end function;