
// Make newform 2898.2.a.z in Magma, downloaded from the LMFDB on 24 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_z();".
// 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_z();".
// 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
        poly := [-2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
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], [0, 0], [-2, 1], [-1, 0], [0, -3], [-2, -2], [2, 2], [0, 5], [1, 0], [2, 0], [-2, -2], [-6, 3], [-2, 0], [-8, -1], [-6, -2], [-6, -3], [0, -2], [-10, -3], [-8, -3], [10, -2], [-12, 0], [0, 8], [-8, -1], [2, 4], [-6, -2], [-2, 4], [-4, -6], [0, 13], [14, -1], [-2, -8], [0, 12], [-12, -2], [-10, 6], [-12, 6], [10, 9], [10, 2], [6, -1], [-8, -2], [6, 10], [6, 10], [4, 2], [2, -13], [0, -2], [-2, 4], [14, -4], [0, 0], [-4, 4], [14, -10], [8, 3], [2, -13], [0, -16], [16, 4], [-2, -6], [0, -13], [18, -8], [12, 0], [-6, -14], [-16, -4], [2, 2], [2, -12], [0, -1], [-6, 15], [0, -8], [16, 12], [6, 14], [-10, -12], [4, 16], [-18, 4], [4, 14], [-18, 4], [-8, -8], [24, 6], [20, -8], [-18, -3], [0, -23], [20, 0], [-2, 21], [10, 2], [2, -2], [6, 8], [-24, 11], [-18, -7], [-36, 2], [-6, -10], [-8, 4], [20, -6], [-14, 12], [18, -2], [-6, -2], [16, -8], [-8, 1], [8, 12], [0, 0], [4, -10], [12, -10], [8, -26], [2, 22], [-14, -6], [-24, -3], [10, 2], [0, 16], [-14, -9], [-8, -15], [-22, -6], [16, -5], [12, 24], [0, -18], [14, 0], [0, -24], [12, 16], [-30, 2], [-14, 21], [-30, 4], [-8, -19], [28, 2], [-26, -10], [16, 21], [-8, 28], [-6, -22], [0, -9], [-6, 3], [-16, 0], [-30, -1], [-32, -12], [20, -10], [-18, 5], [38, 9], [8, -12], [-8, 20], [-30, -7], [20, 10], [-20, 16], [-8, -22], [-2, -5], [20, -4], [-14, -14], [-2, -5], [24, 7], [-22, -19], [0, 24], [0, 2], [6, 22], [14, 6], [-16, -15], [14, -16], [12, 8], [-26, -6], [24, 8], [-4, -28], [8, 12], [6, -2], [-2, -8], [0, 24], [26, -10], [0, 29], [-28, 10], [32, -16], [10, 0], [-22, 20], [2, 7], [28, 6], [14, 2], [14, -2], [0, 23], [-22, -22], [-24, 10], [26, -10], [2, 12], [6, -6], [26, -16], [-8, 13], [14, -24], [28, 24], [-22, 16], [8, 8], [10, -36], [32, 2], [-22, -6], [-40, 10], [-6, 21], [6, -14], [-32, 7], [-30, 2], [-16, -8], [32, 10], [26, -7], [42, -12], [-8, -27], [60, -4], [38, -18], [8, -24], [-20, -20], [0, 25], [-30, 24], [0, 41], [18, 24], [22, -16], [-22, -17], [-22, -12], [0, -16], [22, -15], [8, -16], [-14, 24], [-42, 4], [-8, 11], [-30, 18], [-12, 16], [40, 0], [14, 16], [24, 12], [-40, -16], [-62, 0], [20, 10], [-16, -7], [10, -42], [38, -18], [-10, -18], [-20, -12], [-4, -16], [-26, 18], [-42, -8], [12, -34], [8, 8], [0, -42], [12, 24], [-18, -12], [-6, -36], [42, -18], [-4, 34], [48, 2], [-14, 10], [0, 3], [0, 10], [-26, 8], [0, -21], [56, 2], [-58, -2], [14, -3], [24, 12], [-2, 18], [-24, -3], [8, 4], [-2, -42], [-58, 4], [28, 24], [-8, 32], [-16, 8], [64, -3], [-48, -1], [24, -24], [10, -15], [2, -12], [16, -16], [-14, 36], [-30, 4], [-28, -18], [10, 17], [16, 7], [38, 2], [-14, -32], [-16, 30], [-40, -19], [30, -4], [-6, -37], [-56, 8], [-24, 23], [-18, -39], [54, -20], [-8, -11], [-10, 12], [-42, 12], [48, 17], [34, -12], [-32, 22], [26, 16], [-8, 36], [-44, -4], [-30, 20], [66, -8], [-64, 9], [56, -8], [28, -6], [-20, -26], [-18, -23], [-52, -4], [-16, -28], [30, 18], [2, 3], [-40, 8], [34, 0], [-6, 1], [16, -27], [-22, 24], [32, 1], [-6, -14], [26, -17], [-16, 32], [-46, 16], [16, 24], [-28, -22], [30, -22], [-54, -13], [8, 8], [8, 0], [40, -11], [10, 32], [-16, 26], [22, -27], [28, 0], [-14, 52], [-16, 20], [14, 23], [-62, 14], [-24, 4], [-20, 2], [-66, 8], [0, -28], [18, 6], [10, -4], [-30, 16], [64, 1], [-18, 14], [-58, -4], [34, -30], [-18, 10], [6, -42], [16, 33], [-28, -30], [-36, -20], [70, 1], [18, 38], [-18, 30], [-32, 12], [-60, 2], [0, -7], [40, -28], [10, 11], [-2, 0], [18, 16], [-52, -22], [-6, 12], [54, -6], [6, -40], [72, 4], [-18, 33], [-28, -6], [6, -14], [-64, -10], [-16, 42], [34, -33], [-24, 24], [-4, -52], [-34, -8], [28, 0], [-34, 11], [-8, 8], [-16, -4], [48, 13], [8, 56], [14, -54], [-6, 49], [34, 0], [-26, -14], [8, -13], [-48, 10], [-16, 8], [42, -12], [-52, 24], [26, 34], [-20, 2], [20, 12], [18, 18], [-22, 19], [12, -38], [10, -52], [-28, -14], [-4, -22], [-54, -12], [70, -14], [-22, -36], [-50, -13], [62, 18], [24, 16], [2, 0], [40, -7], [16, 0], [40, -4], [-46, 20], [-24, -43], [8, 38], [-30, -48], [74, 10], [-32, -12], [-32, -22], [72, 18], [6, -6], [-12, -26], [26, 6], [-40, -21], [66, -6], [42, 34], [54, -24], [-32, -40], [-50, -2], [54, 24], [10, -22], [-10, 15], [-26, 0], [-40, 9], [-16, 40], [-16, 16], [-18, 38], [8, -5], [32, -33], [-34, -44], [42, 2], [58, -14], [46, 6], [10, -14], [-52, -18], [-26, 29], [10, 13], [-16, -4], [-24, -38], [-18, 48], [-26, -12], [32, 5], [32, 0], [0, 14], [6, -2]];
    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_z();".
// 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_z(:prec:=2)
    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_z();".
// 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_z( : 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, 4, 1]>,<11,R![-18, 0, 1]>,<13,R![-4, 4, 1]>],Snew);
    return Vf;
end function;