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