
// Make newform 4800.2.a.cb in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4800_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_4800_2_a_cb();".
// 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_4800_2_a_cb();".
// 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_4800_a();"
function MakeCharacter_4800_a()
    N := 4800;
    order := 1;
    char_gens := [4351, 901, 1601, 577];
    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_4800_a_Hecke(Kf)
    return MakeCharacter_4800_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], [0], [0], [2], [-6], [-4], [8], [2], [-4], [10], [2], [4], [8], [-2], [8], [2], [12], [-8], [14], [12], [4], [-14], [-2], [10], [8], [-12], [10], [10], [-16], [-8], [-22], [20], [10], [-20], [10], [20], [0], [-2], [16], [-14], [24], [-10], [-2], [20], [28], [0], [12], [-6], [-6], [24], [2], [-24], [-6], [0], [-30], [-4], [18], [2], [-12], [14], [20], [0], [-2], [-26], [12], [22], [-12], [2], [2], [16], [8], [-14], [-20], [16], [-6], [-30], [-14], [10], [-32], [10], [8], [-26], [4], [20], [-30], [38], [-14], [24], [4], [-32], [-40], [-16], [4], [0], [-30], [-22], [28], [42], [28], [-18], [-36], [10], [-4], [-2], [-12], [26], [0], [26], [40], [26], [-6], [4], [4], [26], [4], [0], [30], [24], [-38], [-26], [-42], [-36], [28], [-30], [10], [-40], [-40], [-22], [-28], [-8], [28], [2], [-6], [50], [46], [-44], [30], [-30], [-36], [42], [-40], [-4], [-6], [-16], [-6], [-30], [-20], [-24], [-6], [26], [-44], [-32], [-28], [0], [4], [-14], [6], [18], [-28], [26], [8], [8], [-38], [-56], [52], [18], [-46], [-10], [8], [26], [-24], [30], [-20], [-30], [-28], [-6], [-32], [26], [16], [0], [-14], [2], [48], [42], [34], [-4], [-38], [56], [38], [12], [12], [-30], [44], [-30], [-30], [18], [-54], [24], [-46], [-12], [58], [-62], [-48], [54], [-44], [-36], [34], [-44], [-10], [-22], [24], [28], [56], [-38], [8], [66], [-8], [-50], [-22], [-44], [-54], [40], [36], [-62], [-46], [-56], [32], [-24], [18], [20], [28], [66], [-20], [-32], [-30], [54], [-64], [-24], [44], [-36], [56], [34], [-14], [-72], [40], [0], [12], [-24], [-6], [18], [24], [-6], [-74], [24], [2], [-28], [30], [-34], [-80], [52], [-38], [66], [18], [-28], [18], [-70], [44], [6], [-6], [4], [-2], [-36], [54], [-8], [-44], [18], [-6], [-24], [32], [52], [-16], [-30], [36], [-8], [46], [-58], [-20], [82], [-14], [12], [-54], [40], [34], [34], [52], [46], [48], [-84], [14], [-66], [68], [-36], [4], [14], [-52], [-62], [24], [66], [56], [-54], [50], [-4], [-24], [26], [32], [0], [-42], [50], [-76], [-34], [34], [48], [-46], [50], [52], [20], [0], [86], [66], [78], [20], [60], [68], [12], [-86], [50], [58], [48], [-46], [34], [42], [-60], [22], [40], [74], [44], [0], [62], [-60], [6], [-78], [32], [-6], [-6], [0], [-24], [18], [0], [-62], [-6], [16], [48], [-36], [-42], [-42], [96], [58], [72], [-36], [96], [26], [-4], [-86], [-88], [-80], [14], [34], [-58], [-30], [-54], [-32], [66], [36], [-16], [-20], [50], [-36], [-96], [-30], [-26], [24], [52], [72], [-10], [-100], [50], [4], [74], [10], [-30], [32], [42], [42], [-28], [58], [-14], [68], [64], [62], [-26], [92], [60], [-18], [-30], [-64], [16], [18], [24], [66], [-62], [-16], [-56], [-2], [22], [20], [-54], [68], [-16]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4800_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4800_2_a_cb();".
// 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_4800_2_a_cb(:prec:=1)
    chi := MakeCharacter_4800_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_4800_2_a_cb();".
// 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_4800_2_a_cb( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4800_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![0, 1]>,<11,R![0, 1]>,<13,R![-2, 1]>,<19,R![4, 1]>,<23,R![-8, 1]>],Snew);
    return Vf;
end function;