
// Make newform 2898.2.a.c in Magma, downloaded from the LMFDB on 20 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_c();".
// 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_c();".
// 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], [-1], [6], [-6], [-1], [5], [-8], [3], [9], [3], [-9], [-6], [-8], [2], [4], [10], [2], [-4], [4], [0], [-5], [-10], [-15], [-18], [-17], [-9], [1], [-10], [-1], [13], [12], [9], [-18], [14], [-8], [6], [11], [-2], [-8], [3], [-9], [-21], [-20], [-16], [-3], [-30], [-22], [-14], [29], [-3], [6], [9], [6], [14], [8], [13], [-24], [10], [-17], [-24], [-22], [-17], [10], [-34], [3], [-6], [11], [7], [3], [22], [29], [-6], [16], [-26], [18], [2], [-16], [31], [-19], [13], [-10], [-23], [-36], [-30], [40], [-29], [19], [-16], [35], [12], [24], [14], [-12], [-10], [-26], [30], [-22], [34], [-3], [33], [-20], [28], [12], [21], [-40], [-10], [-10], [-7], [18], [26], [34], [21], [30], [36], [-47], [48], [24], [19], [-2], [12], [-17], [10], [30], [-49], [-32], [-16], [50], [0], [24], [-10], [6], [35], [-25], [-4], [-5], [-30], [13], [54], [-31], [-2], [-6], [48], [-23], [1], [-39], [-16], [28], [54], [-12], [32], [17], [-9], [26], [25], [3], [19], [45], [-34], [-48], [36], [39], [-48], [52], [-18], [-54], [-62], [46], [-37], [5], [-30], [-24], [28], [-60], [54], [39], [8], [20], [-45], [4], [19], [-41], [-5], [-8], [30], [-57], [-61], [20], [-39], [40], [0], [38], [-6], [2], [-10], [-26], [-43], [2], [-40], [-33], [26], [3], [-24], [15], [44], [36], [4], [31], [-8], [-34], [-12], [25], [-2], [-8], [-63], [17], [21], [-38], [-20], [-32], [-42], [42], [-40], [72], [-30], [-35], [-40], [-26], [-26], [2], [30], [-14], [8], [-71], [-26], [-11], [-24], [-2], [-64], [26], [52], [-9], [17], [50], [1], [-37], [69], [-7], [-50], [-59], [-39], [32], [-65], [47], [-68], [-44], [58], [-38], [34], [-17], [-26], [46], [10], [44], [48], [43], [2], [43], [36], [19], [62], [4], [-40], [-21], [2], [-70], [37], [-53], [24], [-42], [-10], [-71], [44], [70], [66], [40], [-55], [52], [23], [-8], [7], [64], [46], [59], [40], [-4], [-31], [13], [2], [-52], [13], [35], [-27], [-13], [-38], [-21], [58], [-51], [36], [62], [16], [0], [14], [-70], [48], [-37], [66], [4], [-32], [-28], [49], [-33], [34], [-60], [29], [-37], [60], [90], [33], [-10], [-58], [7], [2], [15], [-12], [-32], [-27], [-26], [-71], [-54], [14], [-32], [39], [-1], [18], [58], [93], [76], [-27], [23], [-56], [-29], [-37], [42], [-80], [-78], [-6], [-62], [1], [-2], [66], [17], [-13], [92], [-64], [30], [84], [35], [-16], [-42], [-32], [22], [14], [7], [43], [-98], [-18], [-30], [-46], [16], [-72], [26], [5], [-77], [-49], [29], [46], [78], [-48], [-65], [49], [-84], [72], [1], [-58], [23], [-27], [11], [74], [-12], [-56], [-56], [14], [-7], [12], [36], [36], [46], [37], [-14], [52], [58], [-48], [82], [-34], [-94], [-62], [-54], [-28], [-42], [96], [70], [62], [16], [-60], [63], [-105]];
    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_c();".
// 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_c(: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_c();".
// 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_c( : 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![1, 1]>],Snew);
    return Vf;
end function;