
// Make newform 128.8.b.e in Magma, downloaded from the LMFDB on 10 March 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_128_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_128_b_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_128_8_b_e();".
// 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_128_8_b_e();".
// 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 := [529, 0, 0, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 0, 4, 0], [0, 184, 0, 8], [0, 736, 0, -32]];
    Rf_basisdens := [1, 23, 23, 23];
    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_128_b();"
function MakeCharacter_128_b()
    N := 128;
    order := 2;
    char_gens := [127, 5];
    v := [2, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_128_b_Hecke();"
function MakeCharacter_128_b_Hecke( : Kf := false)
    N := 128;
    order := 2;
    char_gens := [127, 5];
    char_values := [[1, 0, 0, 0], [-1, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 8;
    raw_aps := [[0, 0, 0, 0], [0, 0, -1, 0], [0, 45, 0, 0], [0, 0, 0, 1], [0, 0, -49, 0], [0, 955, 0, 0], [-15842, 0, 0, 0], [0, 0, -661, 0], [0, 0, 0, 479], [0, -24437, 0, 0], [0, 0, 0, -568], [0, -59687, 0, 0], [-455622, 0, 0, 0], [0, 0, 7403, 0], [0, 0, 0, -6230], [0, -321091, 0, 0], [0, 0, 2019, 0], [0, -400641, 0, 0], [0, 0, -43269, 0], [0, 0, 0, 7117], [-2742762, 0, 0, 0], [0, 0, 0, 28898], [0, 0, -10129, 0], [-346458, 0, 0, 0], [-6841298, 0, 0, 0], [0, -4548607, 0, 0], [0, 0, 0, -55711], [0, 0, 13127, 0], [0, 5213575, 0, 0], [18626962, 0, 0, 0], [0, 0, 0, 13492], [0, 0, -729501, 0], [10320474, 0, 0, 0], [0, 0, -702389, 0], [0, -609327, 0, 0], [0, 0, 0, 303855], [0, 18877535, 0, 0], [0, 0, -1715321, 0], [0, 0, 0, 235269], [0, 3566043, 0, 0], [0, 0, 1777127, 0], [0, -13398607, 0, 0], [0, 0, 0, 129676], [-76586994, 0, 0, 0], [0, -4097019, 0, 0], [0, 0, 0, -493183], [0, 0, 1043735, 0], [0, 0, 0, 1012712], [0, 0, -5129761, 0], [0, 27891917, 0, 0], [-370240970, 0, 0, 0], [0, 0, 0, 1265382], [-4140290, 0, 0, 0], [0, 0, -1771629, 0], [-134765566, 0, 0, 0], [0, 0, 0, 177709], [0, -41975769, 0, 0], [0, 0, 0, -256458], [0, 104387701, 0, 0], [71984166, 0, 0, 0], [0, 0, 1324679, 0], [0, 169523085, 0, 0], [0, 0, -1798197, 0], [0, 0, 0, -639449], [977284778, 0, 0, 0], [0, 2130131, 0, 0], [0, 0, 8659319, 0], [1013777138, 0, 0, 0], [0, 0, -20797845, 0], [0, 162105379, 0, 0], [346139746, 0, 0, 0], [0, 0, 0, -5071359], [0, 0, 0, 7648938], [0, 297212005, 0, 0], [0, 0, 7196027, 0], [0, 0, 0, 1436144], [0, -451952927, 0, 0], [0, 476730319, 0, 0], [-773205730, 0, 0, 0], [1381564106, 0, 0, 0], [0, 0, 52023787, 0], [0, -13997147, 0, 0], [0, 0, 0, -3359274], [751243838, 0, 0, 0], [0, 0, 0, -14467929], [0, 0, 34935039, 0], [-2276891122, 0, 0, 0], [-2291817446, 0, 0, 0], [0, 53516007, 0, 0], [0, 0, 0, -4765198], [0, 0, -54059325, 0], [0, 0, 0, -2289944], [0, 0, 0, 16935413], [0, 0, -55349997, 0], [0, 0, 72903551, 0], [0, 0, 0, 3782427], [0, 313234023, 0, 0], [-4465012902, 0, 0, 0], [0, 0, 58360183, 0], [0, 982865207, 0, 0], [0, 0, -117395109, 0], [0, -104782973, 0, 0], [0, 0, 146488539, 0], [3463818922, 0, 0, 0], [0, 0, 80625839, 0], [6149458818, 0, 0, 0], [0, 0, 20249375, 0], [428953266, 0, 0, 0], [0, 0, 0, -33401757], [9222336166, 0, 0, 0], [0, 0, 0, 26535908], [0, 2688482997, 0, 0], [-5820771466, 0, 0, 0], [0, 0, -110274785, 0], [0, 0, 0, 30803515], [-5463654066, 0, 0, 0], [0, 0, -63091269, 0], [0, 0, 0, 48069309], [0, -302655497, 0, 0], [0, 0, -146004993, 0], [0, 1156236265, 0, 0], [7571115758, 0, 0, 0], [0, -2090167511, 0, 0], [0, 0, -139627837, 0], [0, 0, 215004023, 0], [0, -2154359761, 0, 0], [0, 1409517265, 0, 0], [0, 0, 0, -36644550], [0, 0, 0, 28125875], [0, -2338817461, 0, 0], [0, 0, 19907407, 0], [0, 0, 0, 75913493], [0, 0, 0, -72650050], [0, 3858787929, 0, 0], [-7002893078, 0, 0, 0], [-7662677426, 0, 0, 0], [0, -4810953071, 0, 0], [0, 0, -438484713, 0], [0, 2015110031, 0, 0], [11969623610, 0, 0, 0], [0, 0, -32519521, 0], [0, -5730285099, 0, 0], [0, 0, 0, 62881831], [0, 0, -354875881, 0], [0, 2025619543, 0, 0], [0, 0, 0, -62933127], [0, -959600891, 0, 0], [6182697866, 0, 0, 0], [0, 0, -144092645, 0], [0, 0, 0, -80467376], [0, 9204470959, 0, 0], [11501293522, 0, 0, 0], [0, 0, -284595965, 0], [0, 0, 0, -91212729], [0, 0, 596974595, 0], [0, 0, 0, -42387426], [0, 0, 0, -80107065], [24111226094, 0, 0, 0], [15810460150, 0, 0, 0], [0, 3768772807, 0, 0], [0, 0, 647698683, 0], [-16152847446, 0, 0, 0], [0, 0, 0, 104865177], [0, 0, 626759395, 0], [-8649350178, 0, 0, 0], [0, 0, 0, 184579259], [0, 0, 0, -95306468], [0, -2546226407, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_128_b_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_128_8_b_e();".
// 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_128_8_b_e(:prec:=4)
    chi := MakeCharacter_128_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 8));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_128_8_b_e();".
// 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_128_8_b_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_128_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<3,R![2944, 0, 1]>],Snew);
    return Vf;
end function;