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