
// Make newform 7920.2.a.br in Magma, downloaded from the LMFDB on 20 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_br();".
// 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_br();".
// 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;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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, -4], [0, 2], [2, 2], [2, 6], [-2, 4], [2, -6], [-4, -1], [0, -2], [10, 2], [-2, 6], [-6, -2], [0, -6], [-6, -2], [6, -1], [4, 4], [-4, -3], [10, 4], [-2, -2], [-2, 4], [-12, -4], [-4, -7], [-2, -12], [6, 4], [-8, -3], [-8, -6], [14, 0], [0, 2], [-6, 0], [-16, -4], [-6, -2], [-12, 4], [0, 3], [6, -9], [-4, 8], [-8, 4], [-16, -4], [2, 13], [-2, -13], [0, 8], [-8, 0], [-8, 10], [-12, 9], [-14, 8], [-2, -9], [-8, -14], [14, 6], [-10, 14], [2, 14], [-16, -1], [12, 4], [0, -12], [-6, -3], [2, 10], [-4, 13], [2, 11], [-20, 9], [18, 2], [-10, -16], [6, 16], [-6, 2], [-6, 5], [-4, 7], [-18, 6], [6, -14], [4, -2], [-20, -6], [10, 3], [20, -8], [4, -8], [0, -20], [-14, 2], [-10, -16], [-10, 8], [-4, 4], [-16, -8], [-16, -4], [14, -10], [4, -10], [4, -12], [2, 0], [-18, -15], [-14, 8], [-16, 2], [8, -6], [0, 18], [8, 2], [-8, -20], [-20, 12], [32, 5], [-8, 0], [-10, 8], [4, 3], [2, 20], [-12, -5], [-6, 1], [36, -1], [14, 16], [-20, 2], [10, 26], [0, -2], [-2, 13], [8, -12], [26, -14], [0, -3], [22, 17], [-14, -4], [26, -6], [-24, 4], [-18, -12], [-12, -24], [12, -12], [-2, -22], [-24, -4], [-22, -4], [30, -1], [-22, 7], [-4, 2], [-12, -4], [6, 2], [-44, -4], [-8, 0], [24, 4], [2, -9], [16, 6], [8, 19], [-16, -16], [2, -34], [-22, 12], [22, 14], [10, 2], [-20, 11], [-18, 0], [-34, -6], [8, -14], [10, -14], [0, -12], [-4, 23], [4, 28], [-14, -18], [-6, -9], [-18, -15], [42, -6], [36, 12], [-10, -23], [-24, 8], [20, 12], [16, -3], [12, 26], [16, 20], [24, -14], [12, -16], [10, -9], [-14, 8], [0, 6], [-6, -7], [-24, -3], [-12, -8], [6, -12], [20, -8], [30, -2], [-2, 17], [6, -18], [2, 34], [0, -16], [-4, 20], [12, 14], [50, -1], [30, -10], [-8, 16], [12, -6], [-4, 28], [0, 17], [-18, -4], [0, -16], [-12, -12], [6, -2], [30, 3], [48, -10], [6, 20], [-14, 31], [-16, 18], [2, -16], [-24, 8], [26, 14], [36, -1], [4, 0], [-20, -12], [-28, -1], [-6, -6], [30, -22], [-30, 12], [34, 13], [-32, -15], [38, -10], [-40, 10], [-50, 0], [-10, 18], [-12, 8], [-26, 20], [40, 20], [28, 13], [-42, 18], [-38, -14], [54, -7], [-26, -20], [56, -4], [4, 46], [36, -2], [30, 16], [-32, 13], [-6, 16], [20, 28], [38, -6], [-6, 26], [24, -4], [-32, -16], [-24, 0], [36, -13], [-18, -4], [10, -24], [10, -34], [40, -17], [-44, -2], [-42, 6], [8, -18], [-44, 10], [-30, 22], [16, -2], [-40, -9], [24, -8], [42, 15], [-46, 2], [-24, 16], [-12, -12], [52, 16], [-28, -28], [24, 24], [14, 39], [-32, 26], [32, -2], [10, -42], [12, 10], [-8, -27], [10, 13], [-14, -28], [-32, 0], [6, 24], [34, -15], [-40, -12], [4, -44], [-4, 3], [14, -28], [42, 3], [0, 9], [-20, 27], [30, -2], [66, -7], [22, 26], [36, 24], [50, 4], [12, -16], [-28, -1], [42, -17], [2, -8], [-12, -22], [54, -10], [-24, -10], [-2, -43], [40, 22], [-20, -26], [-6, -26], [30, 22], [-20, 14], [32, -23], [38, -14], [0, 1], [-2, 0], [-12, 5], [-32, -12], [10, -22], [-42, -19], [14, 6], [2, -40], [44, 20], [0, -20], [-6, 17], [-48, -6], [-14, 33], [10, -4], [-24, 0], [2, 46], [-64, -16], [44, 15], [-10, 49], [22, 35], [-28, -22], [12, -6], [22, 14], [46, -12], [-40, -2], [-18, 12], [-24, -24], [-2, -11], [-64, -11], [52, -12], [26, -20], [-36, -14], [8, 49], [66, 6], [68, -8], [-40, 26], [-34, 14], [-46, 12], [-32, 12], [-2, -2], [-30, -14], [-4, 22], [38, 7], [-32, -8], [38, 22], [20, -40], [-32, 21], [18, -39], [6, -6], [-50, 24], [-8, 24], [-12, 17], [60, -12], [-8, -20], [-42, 24], [62, -9], [-24, 8], [-16, 15], [-2, 50], [54, -10], [-22, 16], [30, -14], [10, 18], [44, 10], [-2, 24], [20, 20], [28, -32], [-2, -14], [20, -10], [34, -20], [-18, 28], [-24, -43], [-6, -10], [50, -9], [-22, -30], [-28, 22], [18, -15], [68, 0], [-82, -5], [18, -20], [0, 66], [-12, -2], [8, 8], [22, -10], [-38, -39], [48, -5], [-42, 22], [-26, 6], [-18, -10], [-8, -17], [54, 16], [-12, 18], [14, -38], [20, 12], [-4, 30], [6, -51], [-34, 0], [-14, -41], [0, -12], [-6, -26], [-16, 7], [18, 31], [-24, -48], [-40, 0], [-24, -12], [14, 26], [-4, -29], [4, -4], [-8, 0], [58, -2], [-6, 58], [20, 2], [-10, -42], [-66, 1], [44, 10], [-60, -12], [28, 32], [2, -10], [30, -40], [-30, 48], [-32, -23], [66, -6], [-66, -12], [-4, 36], [-18, -18], [30, 16], [-20, -6], [-66, 18], [6, 53], [2, 19], [76, 0], [-68, -22], [-14, 25], [-18, -16], [-32, -40], [52, -32], [-18, -46], [8, -25], [70, 24], [-2, -1], [-8, -52], [32, 22], [22, -8], [-38, -18], [4, -32], [-74, 12], [36, 24], [20, 2], [-44, -24], [40, 44], [-12, -24], [44, 22], [18, 2], [-10, 48], [6, -18], [-16, -24], [0, 42], [-36, 26], [32, 8], [-16, -8], [-34, 40], [52, 12], [-2, 36], [-10, 43], [84, -11], [8, 5], [68, 12], [-30, -22], [28, 45], [30, 18], [-44, -13], [50, 24], [-54, 40], [6, -24], [34, 8], [-8, 12], [14, 11], [14, 8], [-30, 38], [-8, -56], [-60, 22], [-32, 28], [-20, -63], [-10, 11], [0, -26], [4, 24], [-66, -26], [-26, -14], [24, 17], [-32, -32], [-40, 40], [-46, -22], [10, 26], [-46, -19], [-46, 36], [-74, -26], [-16, 41], [-22, -16], [-110, -4], [-90, 4]];
    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_br();".
// 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_br(: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_br();".
// 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_br( : 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, 0, 1]>,<13,R![2, 4, 1]>,<17,R![2, -4, 1]>,<19,R![-32, 0, 1]>,<23,R![-8, 0, 1]>,<29,R![-4, -4, 1]>],Snew);
    return Vf;
end function;