
// Make newform 7920.2.a.bi in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7920_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_7920_2_a_bi();".
// 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_7920_2_a_bi();".
// 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_7920_a();"
function MakeCharacter_7920_a()
    N := 7920;
    order := 1;
    char_gens := [991, 5941, 3521, 6337, 6481];
    v := [1, 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_7920_a_Hecke(Kf)
    return MakeCharacter_7920_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], [1], [2], [1], [-4], [4], [0], [0], [6], [0], [-2], [-6], [-2], [0], [10], [12], [-6], [12], [16], [4], [4], [2], [-6], [-2], [-6], [-4], [-6], [-10], [-14], [22], [8], [-6], [12], [18], [-20], [18], [24], [-6], [24], [20], [2], [-24], [-12], [8], [16], [8], [8], [-26], [-10], [0], [12], [-10], [-20], [-18], [6], [-14], [20], [-12], [26], [-18], [12], [-2], [0], [10], [6], [-4], [28], [34], [-14], [-10], [20], [-32], [-16], [4], [12], [-6], [2], [18], [2], [12], [-6], [8], [30], [-32], [8], [-6], [0], [18], [24], [36], [20], [-16], [-28], [-4], [-6], [-30], [42], [-6], [14], [42], [-24], [-34], [38], [-44], [-42], [28], [12], [16], [-42], [-42], [16], [10], [4], [32], [34], [8], [28], [42], [-28], [46], [20], [-20], [-4], [28], [-2], [10], [-40], [28], [24], [44], [22], [16], [34], [-34], [-18], [34], [-26], [22], [-22], [-20], [6], [4], [2], [50], [0], [24], [20], [-28], [-44], [-24], [-58], [-8], [42], [-44], [8], [-32], [-34], [-16], [-54], [-36], [0], [-34], [-36], [10], [-36], [-40], [16], [-58], [18], [12], [18], [28], [8], [56], [-34], [-52], [-6], [-2], [6], [-44], [-12], [50], [48], [16], [-10], [-8], [20], [-46], [0], [14], [-38], [12], [42], [-42], [-66], [-50], [-58], [0], [6], [46], [-8], [-58], [38], [-52], [30], [24], [30], [-46], [-12], [-32], [22], [4], [4], [12], [-54], [-54], [-18], [-44], [18], [-38], [4], [-26], [44], [-38], [-2], [18], [24], [70], [-64], [-14], [-52], [-48], [-14], [52], [30], [-34], [36], [20], [-64], [24], [-56], [-4], [50], [-56], [36], [-8], [-36], [-28], [38], [-68], [-50], [-4], [-54], [24], [20], [-38], [-54], [-18], [8], [-22], [-2], [26], [60], [-58], [20], [-18], [-58], [22], [-52], [-34], [76], [46], [-8], [16], [-40], [68], [-70], [46], [-40], [-58], [8], [-82], [-50], [42], [-32], [70], [-20], [-56], [-26], [42], [48], [-24], [-32], [-4], [-62], [16], [26], [-20], [22], [-56], [-8], [48], [68], [68], [58], [-20], [54], [-40], [-40], [-14], [50], [-18], [-44], [-70], [-10], [-52], [-28], [-18], [6], [80], [14], [46], [64], [16], [-2], [-28], [-8], [6], [8], [-62], [-42], [-36], [-82], [8], [48], [-34], [88], [22], [2], [58], [-2], [10], [32], [26], [24], [-10], [-8], [72], [-78], [-28], [-86], [-50], [14], [-22], [-36], [24], [-24], [-88], [76], [-12], [-18], [72], [0], [32], [-58], [-40], [42], [62], [60], [84], [54], [50], [-40], [10], [76], [-36], [24], [70], [72], [34], [-50], [46], [-12], [-32], [-44], [-8], [-54], [-6], [100], [14], [-54], [-60], [-44], [-48], [-64], [-56], [54], [-68], [-18], [30], [18], [58], [70], [-62], [-60], [-46], [-18], [-44], [36], [-104], [-52], [40], [44], [28], [-82], [80], [-60], [78], [-6], [6], [-52], [-28], [-56], [82], [82], [48], [46], [-4], [-60], [-50], [-60], [44], [-64], [-14], [66], [54], [74], [-28], [48], [-40], [6], [94], [-48], [50], [80], [74], [10], [-34], [-14], [22], [-72], [-66], [54], [-78], [-42], [14], [100], [76], [-46], [20], [-80], [-8], [-46], [22], [-12], [40], [-32], [58], [28], [-66], [-16], [-96], [86], [52], [-4], [62], [64], [70], [6], [-78], [38]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7920_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_7920_2_a_bi();".
// 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_7920_2_a_bi(:prec:=1)
    chi := MakeCharacter_7920_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(3449) - 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_7920_2_a_bi();".
// 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_7920_2_a_bi( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7920_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-2, 1]>,<13,R![4, 1]>,<17,R![-4, 1]>,<19,R![0, 1]>,<23,R![0, 1]>,<29,R![-6, 1]>],Snew);
    return Vf;
end function;