
// Make newform 2800.2.a.z in Magma, downloaded from the LMFDB on 13 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_2800_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_2800_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_2800_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_2800_a();"
function MakeCharacter_2800_a()
    N := 2800;
    order := 1;
    char_gens := [351, 2101, 2577, 801];
    v := [1, 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_2800_a_Hecke( : Kf := Kf)
    return MakeCharacter_2800_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]];
    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 := [[0], [1], [0], [1], [3], [-5], [-3], [-2], [-6], [3], [4], [-2], [-12], [-10], [9], [-12], [0], [8], [-4], [0], [-2], [1], [12], [-12], [1], [6], [5], [6], [-7], [-6], [-16], [6], [12], [-14], [-6], [1], [-14], [2], [-3], [9], [-12], [20], [-9], [4], [0], [16], [13], [-19], [-3], [-4], [-24], [21], [-10], [-18], [-30], [6], [-6], [16], [10], [3], [-13], [21], [11], [-18], [19], [18], [28], [-14], [-18], [26], [-15], [-24], [17], [4], [-20], [12], [-3], [25], [-15], [14], [12], [17], [-21], [-2], [-26], [-18], [-9], [-8], [-24], [32], [15], [30], [38], [-15], [31], [27], [-6], [-42], [20], [11], [8], [24], [36], [18], [4], [7], [-24], [39], [-45], [-10], [-13], [-2], [-42], [-26], [-29], [-30], [41], [-24], [6], [15], [32], [28], [-45], [-24], [28], [-9], [35], [30], [8], [31], [43], [-12], [-23], [16], [30], [14], [-21], [5], [-15], [-15], [-2], [-27], [-4], [54], [-52], [42], [10], [30], [4], [24], [-50], [0], [20], [-24], [26], [24], [-11], [36], [-47], [0], [0], [0], [-22], [48], [-54], [-21], [-56], [37], [-43], [6], [-24], [50], [15], [46], [-50], [-12], [55], [-51], [-52], [8], [-28], [-12], [-14], [-6], [-36], [42], [16], [17], [-31], [-48], [-2], [30], [25], [0], [-60], [-9], [-49], [-44], [-3], [-3], [-18], [-26], [-50], [-46], [-54], [-3], [-2], [-60], [-42], [-32], [52], [-30], [-28], [-27], [-18], [-28], [50], [60], [42], [-6], [-22], [22], [-51], [2], [-75], [-10], [9], [51], [-19], [-36], [-68], [-38], [40], [9], [-19], [-3], [32], [48], [-15], [54], [24], [-56], [-31], [38], [-33], [-54], [56], [-18], [-59], [-18], [-50], [42], [-36], [8], [-6], [39], [38], [-28], [27], [7], [-10], [-78], [-4], [7], [-18], [46], [-27], [-6], [-4], [-18], [-40], [-52], [-71], [4], [58], [-7], [12], [-46], [65], [-18], [-27], [49], [48], [-10], [77], [-69], [-38], [-42], [28], [-36], [-75], [39], [24], [12], [-26], [0], [-26], [-21], [-60], [-55], [85], [-78], [-65], [-48], [-23], [-2], [6], [32], [-48], [16], [72], [39], [-18], [86], [-90], [20], [-66], [27], [37], [69], [82], [-32], [-54], [20], [66], [20], [25], [44], [72], [36], [-10], [-36], [82], [-21], [-20], [-63], [65], [-66], [14], [-7], [-26], [-48], [42], [-17], [18], [-36], [38], [44], [-66], [57], [-32], [16], [-3], [89], [5], [18], [42], [42], [6], [-6], [64], [0], [48], [63], [-52], [-98], [-39], [-70], [29], [-33], [16], [48], [39], [-86], [-2], [72], [-9], [79], [6], [-53], [6], [-78], [-52], [66], [40], [21], [19], [-77], [20], [15], [-55], [-27], [-75], [44], [27], [40], [-20], [-24], [67], [18], [-4], [84], [-94], [33], [12], [70], [-26], [-33], [-76], [36], [-71], [18], [-18], [28], [58], [24], [75], [-28], [54], [-51], [33], [-38], [-78], [12], [43], [9], [72], [-54], [16], [48]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2800_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2800_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_2800_2_a_z(:prec:=1)
    chi := MakeCharacter_2800_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_2800_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_2800_2_a_z( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2800_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-1, 1]>,<11,R![-3, 1]>,<13,R![5, 1]>],Snew);
    return Vf;
end function;