
// Make newform 2800.2.a.r in Magma, downloaded from the LMFDB on 25 April 2024.
// 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_r();".
// 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_r();".
// 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)
    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+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 := [[0], [0], [0], [1], [-1], [2], [4], [2], [-5], [1], [2], [3], [12], [-11], [-2], [6], [10], [4], [-1], [3], [0], [9], [2], [-6], [14], [12], [-14], [12], [5], [-3], [3], [12], [14], [-12], [11], [-5], [8], [-8], [-6], [-2], [4], [20], [16], [-19], [-19], [-20], [28], [20], [18], [10], [3], [12], [-10], [-24], [-18], [21], [26], [30], [22], [-11], [14], [-22], [-32], [-8], [-14], [-15], [9], [2], [-7], [30], [-14], [15], [-16], [29], [-31], [-6], [33], [-34], [-27], [-14], [6], [-21], [-32], [-20], [-34], [24], [-21], [17], [30], [-24], [-22], [14], [1], [27], [4], [30], [-26], [-2], [-8], [-41], [-1], [-11], [-2], [-19], [-43], [46], [-36], [24], [9], [16], [-42], [27], [-33], [22], [-19], [-15], [-36], [-18], [34], [12], [-18], [6], [-46], [9], [28], [38], [-10], [32], [-16], [36], [3], [-12], [-12], [-17], [0], [-32], [30], [20], [0], [-9], [-26], [10], [31], [-27], [16], [-32], [16], [-12], [-50], [-51], [26], [18], [-25], [-44], [-12], [41], [25], [-20], [20], [-14], [28], [9], [-24], [22], [7], [30], [61], [6], [-13], [-56], [25], [-14], [-59], [-2], [-20], [12], [-19], [26], [34], [-2], [41], [48], [-41], [-46], [35], [26], [37], [-22], [17], [20], [10], [51], [55], [38], [61], [4], [-3], [-69], [-38], [14], [18], [62], [-14], [0], [48], [28], [-34], [28], [39], [16], [35], [8], [-31], [-48], [44], [24], [37], [-46], [-21], [-13], [17], [-52], [43], [3], [6], [22], [-56], [-11], [8], [7], [-37], [30], [4], [-5], [-66], [54], [36], [-27], [-25], [72], [-17], [-34], [34], [-29], [58], [28], [58], [46], [44], [-40], [-30], [28], [0], [8], [-74], [36], [-55], [0], [42], [-42], [-32], [29], [-66], [10], [-32], [-64], [-29], [-60], [69], [59], [-4], [-20], [24], [73], [-32], [-16], [-11], [-22], [83], [48], [-60], [0], [14], [-56], [-8], [-25], [-11], [57], [36], [-18], [-5], [-66], [15], [-48], [41], [24], [-56], [6], [20], [54], [36], [66], [61], [77], [-51], [-34], [3], [-62], [-3], [-2], [-8], [-54], [9], [-44], [-61], [-20], [86], [60], [-16], [-35], [28], [-26], [-42], [-29], [77], [54], [-67], [38], [-37], [-9], [14], [47], [-10], [-92], [-52], [-30], [-55], [42], [-38], [72], [-50], [39], [-56], [-59], [-73], [-61], [-8], [13], [66], [48], [-64], [-3], [34], [74], [-85], [74], [30], [-88], [-22], [92], [49], [-62], [-40], [-69], [-18], [-10], [-42], [29], [-13], [51], [-50], [-73], [18], [-18], [-11], [48], [-29], [16], [-18], [-44], [-64], [29], [-9], [-75], [12], [4], [59], [-78], [81], [52], [49], [-78], [-33], [58], [-53], [-29], [28], [6], [-56], [21], [18], [45], [-77], [42], [-42], [-66], [-103], [-90], [52], [-42], [14], [3], [-4], [-7], [-61], [-42], [32], [52], [12], [18], [-30], [-28], [64], [-40], [30], [36], [33], [-30], [64], [-74]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2800_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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