
// Make newform 8820.2.a.t in Magma, downloaded from the LMFDB on 20 June 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_8820_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_8820_2_a_t();".
// 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_8820_2_a_t();".
// 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_8820_a();"
function MakeCharacter_8820_a()
    N := 8820;
    order := 1;
    char_gens := [4411, 7841, 7057, 1081];
    v := [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_8820_a_Hecke( : Kf := Kf)
    return MakeCharacter_8820_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]];
    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], [-2], [4], [2], [0], [-2], [-6], [-4], [-10], [-2], [4], [-8], [-10], [4], [-8], [8], [-6], [-4], [4], [4], [-10], [12], [-14], [-4], [6], [10], [-10], [12], [12], [2], [4], [-2], [24], [-8], [8], [0], [-6], [-22], [-20], [-6], [6], [-18], [-16], [-4], [8], [12], [-28], [26], [14], [-4], [28], [-18], [-18], [-10], [-28], [-22], [10], [-16], [-6], [32], [-32], [-16], [6], [-4], [-2], [10], [32], [18], [-22], [-32], [6], [-4], [-16], [18], [-8], [2], [-4], [-12], [26], [18], [-8], [32], [-22], [6], [-6], [42], [-20], [-28], [16], [16], [42], [28], [0], [-18], [18], [-20], [2], [-32], [30], [-36], [26], [0], [-16], [-28], [-14], [34], [-40], [40], [-38], [42], [-36], [-20], [42], [48], [-32], [10], [-2], [8], [-38], [-22], [-30], [-44], [2], [18], [0], [28], [12], [-24], [-54], [16], [34], [30], [-16], [18], [-12], [-46], [22], [4], [-18], [-28], [22], [4], [24], [-56], [30], [-8], [6], [18], [26], [-20], [16], [28], [50], [-40], [-18], [-24], [-10], [-42], [-2], [20], [28], [-30], [-16], [0], [0], [-2], [34], [-42], [-32], [18], [-6], [-16], [-54], [32], [58], [28], [8], [4], [60], [-26], [-30], [-50], [18], [-10], [44], [-54], [-24], [12], [-66], [-12], [-30], [38], [18], [58], [-2], [22], [0], [6], [-8], [4], [44], [36], [42], [56], [30], [14], [8], [-2], [-18], [16], [20], [8], [8], [32], [26], [54], [-62], [18], [-68], [54], [16], [-44], [70], [-66], [6], [28], [18], [-6], [16], [32], [-2], [16], [64], [-28], [-18], [-30], [-64], [-54], [68], [-24], [50], [-26], [8], [12], [-52], [16], [-18], [6], [42], [-22], [20], [58], [14], [54], [48], [34], [48], [-36], [26], [76], [-48], [-62], [36], [-34], [-30], [48], [-78], [40], [-20], [28], [8], [-28], [36], [22], [34], [-50], [28], [-72], [12], [64], [-56], [-20], [-46], [-14], [38], [-52], [-10], [38], [60], [26], [-44], [46], [-78], [24], [54], [-44], [-68], [56], [-38], [-52], [6], [-64], [14], [66], [-36], [-6], [26], [88], [2], [-14], [-60], [-42], [52], [84], [70], [-68], [26], [32], [-46], [-30], [-64], [-58], [-28], [-64], [8], [50], [-70], [86], [58], [-20], [84], [80], [60], [-78], [6], [44], [20], [-26], [18], [-26], [-24], [10], [54], [52], [-76], [-48], [58], [72], [-26], [54], [-16], [22], [42], [32], [12], [-90], [2], [6], [-66], [90], [-50], [76], [98], [6], [-44], [-2], [90], [0], [50], [6], [-28], [66], [-20], [-26], [-64], [58], [-44], [50], [14], [8], [22], [-20], [-48], [-40], [-52], [-16], [0], [-14], [-98], [-26], [8], [-30], [54], [-64], [34], [-16], [82], [0], [6], [20], [62], [46], [48], [18], [70], [76], [-60], [-32], [-86], [-78], [52], [-22], [-98], [-50], [-84], [2], [56], [66], [-88], [10], [-60], [-24], [2], [-38], [34], [-4], [0], [20], [6], [-48], [-48], [-80], [70], [-26], [-6], [-72], [-32], [-84], [10], [26], [74], [84], [86], [20], [-88], [-24], [28], [80], [-96], [-42], [-86], [-50], [6], [30], [60], [20], [22], [76], [-28], [-54], [10], [12], [14], [104], [4], [-54], [76], [-76], [62], [40], [2], [10], [52], [-86], [-28], [96], [-26], [-68], [-30], [-108], [-62], [28], [62], [-6], [-60], [-8], [12], [0], [8], [-114], [-58], [94], [24], [-88], [30], [-60], [64], [-38], [-44], [-2], [-32], [34], [-46], [-58], [-76], [-10], [0], [-52], [24], [0], [-42], [88], [-26], [-106], [-40], [78], [56], [22], [92], [46], [-86], [48], [100], [-76], [-74], [6], [-30], [24], [34], [112], [90], [-28], [-40], [56], [94], [106], [48], [-16], [-106], [-8], [-60], [86], [-8], [-16], [-4], [-28], [46], [30], [96], [72], [58], [38], [-68], [100]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8820_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8820_2_a_t();".
// 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_8820_2_a_t(:prec:=1)
    chi := MakeCharacter_8820_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(4027) - 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_8820_2_a_t();".
// 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_8820_2_a_t( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8820_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![2, 1]>,<13,R![-4, 1]>,<17,R![-2, 1]>,<31,R![4, 1]>],Snew);
    return Vf;
end function;