
// Make newform 256.8.b.i in Magma, downloaded from the LMFDB on 11 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_256_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_256_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_256_8_b_i();".
// 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_256_8_b_i();".
// 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 := [16, 0, -7, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, -3, 0, 1], [0, 88, 0, -8], [-112, 0, 32, 0]];
    Rf_basisdens := [1, 2, 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_256_b();"
function MakeCharacter_256_b()
    N := 256;
    order := 2;
    char_gens := [255, 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_256_b_Hecke();"
function MakeCharacter_256_b_Hecke(Kf)
    N := 256;
    order := 2;
    char_gens := [255, 5];
    char_values := [[1, 0, 0, 0], [-1, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, 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, 0, 1], [0, 35, 0, 0], [0, 0, 9, 0], [0, 0, 0, 117], [0, -6879, 0, 0], [16994, 0, 0, 0], [0, 0, 0, 549], [0, 0, -261, 0], [0, -17095, 0, 0], [0, 0, 972, 0], [0, 17603, 0, 0], [484550, 0, 0, 0], [0, 0, 0, 10845], [0, 0, 9738, 0], [0, 425851, 0, 0], [0, 0, 0, -11223], [0, -35815, 0, 0], [0, 0, 0, -4959], [0, 0, -6111, 0], [-3912042, 0, 0, 0], [0, 0, -2538, 0], [0, 0, 0, -24795], [2510630, 0, 0, 0], [-50094, 0, 0, 0], [0, 7517699, 0, 0], [0, 0, -161307, 0], [0, 0, 0, -141219], [0, -8903487, 0, 0], [-18849902, 0, 0, 0], [0, 0, -267264, 0], [0, 0, 0, 425169], [18874534, 0, 0, 0], [0, 0, 0, 175653], [0, -17223077, 0, 0], [0, 0, 105291, 0], [0, 10229353, 0, 0], [0, 0, 0, 174249], [0, 0, 450333, 0], [0, 4471249, 0, 0], [0, 0, 0, -1515843], [0, 48113451, 0, 0], [0, 0, -862344, 0], [134692978, 0, 0, 0], [0, 46830563, 0, 0], [0, 0, -433791, 0], [0, 0, 0, 2044773], [0, 0, -1616364, 0], [0, 0, 0, -3980007], [0, -112345005, 0, 0], [249044662, 0, 0, 0], [0, 0, -845118, 0], [80457090, 0, 0, 0], [0, 0, 0, -2583495], [176666114, 0, 0, 0], [0, 0, 2817945, 0], [0, -95677583, 0, 0], [0, 0, 4540014, 0], [0, -262866933, 0, 0], [42410150, 0, 0, 0], [0, 0, 0, 1523457], [0, 200648179, 0, 0], [0, 0, 0, 4374477], [0, 0, -3331665, 0], [181101142, 0, 0, 0], [0, -374424887, 0, 0], [0, 0, 0, 2574405], [-550577934, 0, 0, 0], [0, 0, 0, 19503009], [0, -55223815, 0, 0], [642950242, 0, 0, 0], [0, 0, 1597509, 0], [0, 0, -2164734, 0], [0, 236415931, 0, 0], [0, 0, 0, -20603079], [0, 0, 5885136, 0], [0, 264581587, 0, 0], [0, 795954257, 0, 0], [-1037481118, 0, 0, 0], [508439094, 0, 0, 0], [0, 0, 0, -4790439], [0, 436545555, 0, 0], [0, 0, -23401782, 0], [2461974082, 0, 0, 0], [0, 0, 15247359, 0], [0, 0, 0, -3456423], [-2488240526, 0, 0, 0], [-2187766554, 0, 0, 0], [0, 743122961, 0, 0], [0, 0, 20925414, 0], [0, 0, 0, 29808693], [0, 0, 27880884, 0], [0, 0, 29304549, 0], [0, 0, 0, 21410253], [0, 0, 0, 3744045], [0, 0, 9884151, 0], [0, -327373735, 0, 0], [239014822, 0, 0, 0], [0, 0, 0, 93029013], [0, -2947095159, 0, 0], [0, 0, 0, -18019719], [0, 1471612337, 0, 0], [0, 0, 0, 9433485], [7405306966, 0, 0, 0], [0, 0, 0, -4951431], [-360747646, 0, 0, 0], [0, 0, 0, -102520539], [8895476402, 0, 0, 0], [0, 0, 42540723, 0], [-1963216090, 0, 0, 0], [0, 0, -56349036, 0], [0, 514121779, 0, 0], [-141932554, 0, 0, 0], [0, 0, 0, -113114691], [0, 0, 5403591, 0], [10545534770, 0, 0, 0], [0, 0, 0, 119334897], [0, 0, -62876727, 0], [0, 6163024369, 0, 0], [0, 0, 0, 167056821], [0, -1290716485, 0, 0], [-6531711598, 0, 0, 0], [0, -5661388477, 0, 0], [0, 0, 0, -210338595], [0, 0, 0, -28908099], [0, -5426053735, 0, 0], [0, -3561238605, 0, 0], [0, 0, 43155558, 0], [0, 0, -59806845, 0], [0, 6154272729, 0, 0], [0, 0, 0, -179821287], [0, 0, 44217477, 0], [0, 0, -62641566, 0], [0, 2793088107, 0, 0], [12611746838, 0, 0, 0], [13347463730, 0, 0, 0], [0, -87940781, 0, 0], [0, 0, 0, -206283915], [0, -11131090967, 0, 0], [-23705670970, 0, 0, 0], [0, 0, 0, -326533491], [0, -13217388325, 0, 0], [0, 0, -220416849, 0], [0, 0, 0, -263940327], [0, 3373131897, 0, 0], [0, 0, 111273777, 0], [0, -3548074261, 0, 0], [20950065014, 0, 0, 0], [0, 0, 0, 220953825], [0, 0, -228790620, 0], [0, 13581608033, 0, 0], [13943072210, 0, 0, 0], [0, 0, 0, -533132739], [0, 0, -134416233, 0], [0, 0, 0, 292904901], [0, 0, -143735490, 0], [0, 0, 157258251, 0], [-33663970414, 0, 0, 0], [-45621412234, 0, 0, 0], [0, -25018645471, 0, 0], [0, 0, 0, 515876013], [31099871062, 0, 0, 0], [0, 0, 427783617, 0], [0, 0, 0, -782586315], [-2304889694, 0, 0, 0], [0, 0, -194983101, 0], [0, 0, 421256196, 0], [0, 3915122467, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_256_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_256_8_b_i();".
// 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_256_8_b_i(:prec:=4)
    chi := MakeCharacter_256_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_256_8_b_i();".
// 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_256_8_b_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_256_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<3,R![3840, 0, 1]>,<7,R![-1244160, 0, 1]>],Snew);
    return Vf;
end function;