
// Make newform 7920.2.a.y 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_y();".
// 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_y();".
// 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], [2], [0], [-2], [0], [0], [-8], [2], [0], [-2], [0], [-6], [-12], [2], [4], [0], [2], [10], [-12], [6], [14], [0], [4], [-12], [-10], [-6], [-2], [-12], [-6], [22], [12], [-14], [14], [-8], [-24], [-12], [-12], [-10], [0], [-10], [12], [16], [22], [-20], [-12], [2], [-12], [12], [-10], [12], [-18], [0], [-30], [-2], [2], [0], [-26], [-24], [10], [24], [-10], [-18], [-8], [26], [-12], [26], [-18], [0], [-20], [-34], [16], [24], [-18], [2], [-6], [-10], [-12], [-10], [12], [-34], [-2], [-12], [-18], [26], [36], [4], [12], [36], [-8], [0], [28], [-24], [18], [-30], [22], [-34], [-26], [0], [24], [-36], [10], [-22], [-36], [36], [24], [26], [22], [-34], [-6], [-32], [16], [30], [40], [24], [-6], [12], [14], [-10], [36], [-12], [-8], [12], [2], [24], [-8], [50], [34], [-36], [-32], [-34], [-12], [26], [18], [-2], [6], [-36], [-2], [24], [4], [-12], [2], [-24], [-10], [-48], [40], [-24], [38], [18], [-44], [-36], [-8], [-24], [-50], [-54], [14], [24], [12], [-24], [22], [36], [18], [0], [-8], [62], [-10], [-54], [-60], [2], [-48], [26], [-20], [-30], [10], [18], [-26], [26], [16], [36], [14], [0], [24], [18], [26], [-56], [-10], [12], [-46], [-36], [28], [-18], [48], [-18], [-22], [62], [48], [-36], [36], [10], [-58], [62], [-12], [-18], [-20], [48], [-12], [52], [14], [42], [40], [-12], [24], [62], [58], [0], [24], [42], [38], [58], [66], [-20], [-72], [50], [-6], [-24], [10], [48], [50], [70], [58], [-12], [-44], [12], [-22], [48], [-36], [0], [12], [-14], [-8], [-10], [-60], [24], [40], [12], [-38], [12], [50], [-48], [72], [-10], [-48], [24], [26], [10], [-18], [38], [34], [48], [14], [-10], [-42], [28], [-6], [-30], [-14], [36], [50], [16], [26], [-26], [-22], [-56], [12], [-22], [2], [60], [-24], [40], [60], [74], [22], [48], [-34], [-12], [-8], [-24], [30], [84], [12], [-84], [-10], [-60], [40], [-6], [0], [10], [14], [0], [-38], [84], [-68], [-10], [60], [62], [0], [38], [24], [78], [0], [-44], [-48], [62], [-12], [-24], [2], [12], [-26], [-46], [-60], [16], [-60], [2], [-20], [-68], [-48], [12], [-10], [54], [-14], [12], [-38], [12], [2], [-60], [74], [70], [-70], [-18], [84], [52], [-30], [0], [-58], [-32], [0], [-78], [94], [-70], [90], [-26], [50], [72], [72], [48], [48], [-48], [-82], [0], [0], [0], [-20], [-46], [48], [-2], [2], [-12], [-80], [-84], [0], [22], [-10], [12], [-60], [-58], [-36], [2], [54], [-42], [-74], [-24], [-14], [-48], [-8], [-22], [-74], [72], [62], [18], [36], [52], [-48], [-70], [-14], [102], [-56], [72], [50], [90], [-2], [78], [36], [-38], [-46], [96], [-44], [-84], [14], [48], [-84], [10], [50], [-90], [84], [-44], [78], [-96], [-30], [-10], [-24], [-24], [74], [-102], [12], [24], [40], [12], [38], [-72], [-20], [-72], [14], [-102], [-10], [74], [-32], [-38], [36], [-30], [50], [96], [-58], [-12], [34], [48], [62], [38], [-38], [24], [-60], [-84], [86], [-90], [-10], [-24], [-22], [90], [-44], [28], [-84], [38], [-38], [-22], [-26], [-60], [-24], [-80], [106], [84], [0], [14], [-36], [2], [-102], [100], [-36], [-18], [-34], [-60]];
    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_y();".
// 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_y(: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_y();".
// 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_y( : 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![-2, 1]>,<17,R![0, 1]>,<19,R![2, 1]>,<23,R![0, 1]>,<29,R![0, 1]>],Snew);
    return Vf;
end function;