
// Make newform 7920.2.a.m in Magma, downloaded from the LMFDB on 25 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_m();".
// 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_m();".
// 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], [0], [1], [6], [-2], [4], [0], [10], [0], [6], [-2], [-4], [-8], [10], [-4], [-2], [4], [-8], [2], [8], [-12], [6], [18], [-14], [-16], [-4], [14], [-2], [-8], [20], [6], [-4], [18], [16], [-18], [20], [24], [-14], [-12], [-10], [0], [10], [-6], [-8], [20], [-24], [4], [-26], [6], [16], [18], [-4], [14], [24], [2], [8], [-18], [-18], [12], [-6], [20], [24], [-6], [34], [4], [10], [12], [30], [14], [-8], [8], [-18], [-12], [-8], [-6], [-2], [-2], [10], [36], [38], [16], [2], [-32], [4], [30], [18], [-6], [-40], [-4], [0], [0], [-36], [-20], [24], [-14], [38], [-20], [-2], [4], [-30], [-12], [-18], [12], [-46], [-12], [46], [24], [42], [-40], [-2], [-26], [-44], [24], [30], [20], [48], [-14], [36], [-10], [-22], [-22], [20], [44], [26], [38], [-32], [-32], [6], [20], [-24], [-32], [38], [-18], [-46], [26], [-28], [-30], [-18], [44], [18], [-32], [44], [-2], [24], [-50], [22], [36], [24], [-58], [-2], [-12], [56], [12], [-48], [32], [-50], [2], [10], [12], [6], [-48], [12], [30], [-48], [32], [-2], [50], [-54], [-20], [30], [-24], [-14], [48], [-10], [-20], [42], [0], [30], [-8], [-60], [-10], [-42], [40], [26], [38], [-28], [-38], [0], [18], [-20], [-4], [-62], [-12], [6], [2], [-2], [-2], [-56], [10], [-24], [-42], [2], [44], [2], [16], [-60], [-18], [52], [-22], [26], [-16], [36], [-8], [-22], [72], [6], [-48], [-30], [-42], [32], [14], [8], [-44], [-26], [-74], [-16], [64], [-20], [62], [20], [-40], [-18], [44], [-32], [-14], [-54], [76], [24], [-4], [60], [-64], [46], [30], [8], [40], [36], [-20], [16], [-10], [-10], [-32], [10], [-30], [-44], [-10], [-36], [26], [-14], [-56], [20], [-10], [-26], [-18], [28], [-62], [54], [-68], [42], [-50], [-60], [10], [-40], [26], [0], [-44], [-2], [58], [-60], [-16], [56], [40], [-42], [28], [32], [-62], [-70], [56], [54], [-46], [12], [-10], [28], [22], [42], [-48], [42], [60], [68], [-30], [2], [56], [-84], [68], [34], [-28], [-82], [-72], [-2], [-16], [10], [-10], [-76], [-8], [10], [68], [-32], [-78], [22], [-44], [74], [-70], [-8], [6], [50], [-20], [12], [0], [-6], [-34], [-62], [-8], [-44], [-52], [-12], [-66], [-50], [-22], [-8], [-26], [86], [-62], [72], [-30], [20], [-26], [-68], [32], [-54], [-76], [74], [2], [-8], [-74], [-42], [-64], [44], [46], [-64], [-50], [-18], [40], [44], [-12], [-38], [-30], [-80], [10], [20], [20], [-48], [2], [-80], [-18], [-12], [-48], [-38], [54], [34], [-30], [38], [32], [-50], [36], [16], [64], [38], [-68], [-40], [98], [-6], [-36], [-44], [88], [2], [-88], [54], [52], [18], [-50], [-18], [56], [-42], [-30], [96], [62], [70], [36], [-12], [10], [74], [-12], [68], [98], [50], [-48], [-32], [-2], [24], [18], [46], [8], [12], [10], [18], [-52], [-2], [-28], [-40], [-70], [-44], [-76], [-24], [14], [78], [10], [22], [92], [64], [84], [-2], [22], [80], [-30], [78], [-52], [-48], [2], [30], [52], [88], [84], [-2], [-14], [10], [-2], [68], [14], [22], [52], [-8], [36], [-58], [-36], [-22], [0], [-108], [-58], [44], [40], [12], [0], [66], [-68], [-58], [-110], [-80], [0], [-54], [-22], [-82]];
    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_m();".
// 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_m(: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_m();".
// 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_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7920_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![0, 1]>,<13,R![-6, 1]>,<17,R![2, 1]>,<19,R![-4, 1]>,<23,R![0, 1]>,<29,R![-10, 1]>],Snew);
    return Vf;
end function;