
// Make newform 7920.2.a.bs 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_bs();".
// 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_bs();".
// 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
        poly := [-2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 2]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
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], [0, 0], [-1, 0], [0, 1], [-1, 0], [2, 1], [-2, 1], [0, 2], [0, 2], [-2, 0], [0, -2], [6, 0], [2, 0], [-4, 1], [0, 2], [-6, 2], [4, 2], [6, -2], [-4, -2], [-8, -2], [6, 3], [-4, -2], [8, 1], [-2, 0], [10, -2], [-2, 2], [-8, 4], [0, -3], [6, -4], [-2, -4], [0, -1], [-12, 2], [6, 4], [0, -4], [6, -2], [4, -6], [6, 6], [-20, 0], [-4, -5], [10, -3], [4, 0], [-2, 4], [-16, 0], [6, -1], [18, 1], [8, 0], [0, 6], [8, 6], [0, 3], [6, 0], [6, 3], [0, 2], [2, -2], [-4, 6], [14, 6], [-12, 1], [18, -4], [20, 2], [10, 1], [2, -8], [-20, -3], [18, 3], [12, -3], [-16, -2], [-6, -4], [2, -8], [12, 6], [-18, -5], [16, -3], [-10, -6], [-18, 6], [0, -10], [-8, -6], [10, 3], [12, -4], [0, 0], [2, 0], [6, -2], [14, 0], [-14, 4], [20, -4], [14, 8], [24, 4], [10, 6], [4, -8], [-4, 12], [-26, -4], [-18, 5], [14, -2], [-8, -2], [12, 6], [32, -2], [8, 10], [-20, 0], [-20, 0], [-4, 3], [-14, 8], [6, 8], [-12, -9], [22, 0], [-20, 7], [34, -3], [8, -9], [2, 10], [8, -4], [-22, 6], [36, -2], [-10, -11], [16, 8], [-30, -2], [0, 7], [-6, 11], [22, -8], [12, -2], [24, 4], [-26, 0], [-20, 8], [8, 0], [34, -6], [-4, -4], [38, 4], [-10, -9], [10, 3], [28, -2], [4, -4], [6, -4], [-34, 4], [32, -4], [0, -12], [-22, 3], [0, -8], [-36, 1], [16, -12], [-2, -14], [-14, -2], [10, 14], [-6, 6], [-12, -11], [2, 8], [-22, 0], [-32, 4], [6, 0], [-40, 4], [16, 5], [6, -12], [16, 2], [-22, -9], [6, 13], [28, 6], [0, 4], [-30, 3], [-26, -4], [36, -8], [-12, 7], [-4, 2], [-16, -12], [36, 4], [-42, -4], [6, -11], [22, 2], [20, -14], [30, 3], [8, 7], [4, -12], [-34, 0], [-24, 4], [32, 6], [10, -5], [18, 10], [-22, -10], [-12, -12], [-10, 12], [-16, 2], [14, 1], [-8, 10], [14, -4], [40, 8], [-6, -4], [8, -5], [-18, 12], [-8, -12], [44, 0], [-18, -10], [-2, 3], [-48, -2], [-30, 0], [10, 11], [-28, -2], [-46, 0], [8, 16], [10, 10], [-32, -3], [28, -4], [10, 0], [-40, -1], [-26, -6], [10, -14], [-50, 4], [-10, -1], [-52, -3], [6, 8], [36, -4], [-10, 4], [2, -22], [12, -12], [2, 4], [-8, 4], [-40, -5], [-6, 12], [4, -6], [46, 9], [-46, -8], [0, -20], [-28, -10], [-16, 2], [-6, 16], [-16, 17], [-46, -6], [0, -4], [18, 6], [38, 2], [-28, 14], [22, 12], [0, -4], [-16, 5], [38, -4], [-26, 12], [-8, -14], [0, 7], [-28, 6], [22, -14], [24, 0], [-12, -12], [42, 4], [-28, 2], [20, 5], [10, -16], [18, -1], [-36, -14], [-16, 0], [36, 0], [-48, 6], [48, -4], [-26, 0], [46, -5], [-16, 18], [16, 10], [4, 6], [8, -12], [-44, 1], [50, -7], [-46, 10], [-32, -4], [26, 0], [-14, -11], [-28, -4], [62, 4], [12, 3], [-38, 0], [-26, -7], [0, -11], [24, 3], [-10, 18], [26, 9], [-34, -10], [-20, 0], [42, -8], [-50, -4], [-60, 5], [10, -21], [14, -8], [36, 2], [-14, 18], [-4, -4], [22, 1], [8, 10], [-20, -2], [22, -6], [18, -10], [20, -2], [-20, -15], [-24, -6], [-4, 13], [38, 16], [-28, -9], [24, -8], [10, -18], [-22, 11], [-56, 6], [2, -22], [42, -8], [4, -12], [6, 7], [28, -14], [-54, -7], [14, -6], [16, 0], [-6, 26], [-52, -4], [-36, 5], [-74, 1], [18, 21], [-44, -4], [76, -2], [-28, 6], [-14, 16], [28, 14], [-18, -20], [-32, -16], [10, -17], [-12, -13], [-14, 16], [34, -14], [-20, 2], [-4, -9], [26, 2], [-20, 4], [24, -2], [10, -10], [-38, 2], [-32, 10], [-62, 10], [22, 8], [-32, -10], [-10, -21], [26, 0], [44, -10], [44, 4], [44, -11], [18, -15], [-34, 6], [50, 8], [28, -2], [48, 3], [-80, -2], [-4, 0], [30, 0], [-2, 3], [-14, -16], [72, 1], [-18, 18], [-10, -10], [38, 10], [48, -10], [-30, -10], [-20, -2], [-26, -8], [-44, 8], [32, 0], [10, -6], [-8, 8], [-54, 0], [26, -24], [-32, 7], [-34, -10], [-26, 25], [0, -6], [68, 2], [-26, 11], [-16, -20], [-14, 9], [42, -18], [8, 6], [-12, -2], [36, 12], [2, 6], [-14, 21], [-16, 13], [50, 6], [-52, -6], [76, 2], [-60, -11], [-18, 26], [-44, 12], [6, -26], [36, -16], [16, 22], [-18, -19], [-22, 14], [30, -23], [10, -24], [38, 2], [40, 3], [-18, -7], [-24, -22], [80, -4], [0, 12], [-34, -6], [-12, -1], [24, -8], [42, -8], [-22, -14], [-52, -14], [44, -18], [16, -6], [14, 5], [36, 16], [38, -20], [44, -4], [38, 4], [30, -16], [30, -24], [-24, -15], [-42, -2], [22, 2], [36, 2], [22, -14], [50, 6], [-52, 18], [-44, 2], [62, 13], [34, -21], [4, -12], [16, -20], [-42, 15], [34, 8], [8, -8], [24, 12], [-18, -6], [12, 7], [10, 12], [50, 5], [40, 20], [-28, 14], [-6, 32], [34, -14], [44, 12], [26, 6], [60, -12], [24, -2], [-62, 0], [-12, 12], [-12, 24], [0, 26], [38, 14], [14, 32], [74, -10], [14, 0], [12, 30], [-20, -8], [28, -8], [22, 4], [38, 12], [48, -20], [-6, 4], [-50, -9], [-36, 3], [4, -21], [-38, 4], [-66, 10], [-4, -23], [-80, -2], [32, -9], [50, 14], [18, -8], [58, 16], [-58, 12], [52, 4], [-54, -3], [22, -16], [4, -34], [16, -4], [-12, 30], [-50, -4], [-12, -35], [-2, -9], [-28, 8], [20, -8], [-22, 12], [20, 6], [-40, -17], [36, 12], [8, -8], [82, 10], [52, -2], [66, 9], [10, -24], [40, 10], [-12, -3], [-6, 16], [26, 28], [-30, -22]];
    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_bs();".
// 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_bs(:prec:=2)
    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_bs();".
// 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_bs( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7920_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-8, 0, 1]>,<13,R![-4, -4, 1]>,<17,R![-4, 4, 1]>,<19,R![-32, 0, 1]>,<23,R![-32, 0, 1]>,<29,R![2, 1]>],Snew);
    return Vf;
end function;