
// Make newform 256.8.b.n in Magma, downloaded from the LMFDB on 10 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_n();".
// 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_n();".
// 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 := [5625, 13680, 13084, 5760, 841, -180, -62, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [188115840, 359208784, 252995400, 65902336, -3744360, -3938672, -156960, 69616], [-303230100, -535399516, -346767690, -80513624, 6972810, 4925668, 131520, -82684], [841862160, 1606405948, 1118319702, 278830336, -20996622, -16809620, -437784, 276532], [-1667684480, -3450593536, -2491103840, -658256704, 34591520, 39185408, 1634560, -697024], [-4696677600, -8492948608, -5094786840, -858811792, 178701000, 54409664, -1455360, -709552], [471234624, 1018216256, 802095648, 243431552, -4187616, -14288832, -836544, 270912], [-51441020280, -112085889272, -87823832580, -25249804688, 980463780, 1479963976, 65463840, -26266328]];
    Rf_basisdens := [1, 377985, 125995, 75597, 125995, 125995, 25199, 377985];
    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, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 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, 0], [0, -1, -1, 0, 0, 0, 0, 0], [0, 8, 2, 1, 0, 0, 0, 0], [340, 0, 0, 0, 0, 1, 0, 0], [0, -110, 17, -8, 0, 0, 0, -1], [0, 107, 34, -13, 0, 0, 0, 2], [-498, 0, 0, 0, -26, -14, -7, 0], [0, -786, -335, 56, 0, 0, 0, -5], [10156, 0, 0, 0, 55, -5, -88, 0], [0, -2252, -266, 203, 0, 0, 0, 16], [-77888, 0, 0, 0, -67, -60, -8, 0], [0, 4693, -3210, -135, 0, 0, 0, -98], [-207434, 0, 0, 0, 338, 220, 154, 0], [0, 35077, -8089, -944, 0, 0, 0, 18], [-540072, 0, 0, 0, 859, 266, -280, 0], [0, 118043, -1218, 1113, 0, 0, 0, 154], [0, 151927, -7569, -2592, 0, 0, 0, -336], [0, -54953, 2690, 4339, 0, 0, 0, 914], [0, -31122, -24635, -3592, 0, 0, 0, 1287], [-41020, 0, 0, 0, 6097, -623, 728, 0], [-2268878, 0, 0, 0, 132, -1114, -2841, 0], [-4532712, 0, 0, 0, -2252, -578, -832, 0], [0, -31585, 12843, 14016, 0, 0, 0, -2252], [-1152478, 0, 0, 0, -4980, 3622, 9975, 0], [563310, 0, 0, 0, 3934, 3818, 12629, 0], [0, -21049, 222014, 11257, 0, 0, 0, -2182], [-5837420, 0, 0, 0, -2607, 5429, -8616, 0], [0, 545860, -171347, -6712, 0, 0, 0, -951], [0, 876876, -26842, 27739, 0, 0, 0, 3784], [-2185438, 0, 0, 0, 1212, 2112, -23496, 0], [-10326640, 0, 0, 0, 11081, -232, 34456, 0], [0, 3849000, 71529, 8328, 0, 0, 0, -3807], [11469414, 0, 0, 0, 48014, 1020, 18178, 0], [0, -35631, -59657, -72016, 0, 0, 0, -3642], [0, -3214934, -460294, 56737, 0, 0, 0, -13788], [-30935380, 0, 0, 0, -90429, 15979, 15432, 0], [0, 593961, -567958, -17261, 0, 0, 0, -2690], [0, 1369929, -175957, -106352, 0, 0, 0, -27774], [-26602460, 0, 0, 0, 55900, 30421, -71008, 0], [0, -2001919, -865894, -19805, 0, 0, 0, -29770], [0, 5394389, 842367, 82224, 0, 0, 0, 14962], [0, 4318592, 460594, -109999, 0, 0, 0, 13048], [-32998416, 0, 0, 0, 50009, -17264, -26216, 0], [-1239890, 0, 0, 0, 120126, -83238, -30099, 0], [0, -430322, 1737946, -60655, 0, 0, 0, -19740], [-1313580, 0, 0, 0, 195622, -63815, 114512, 0], [0, -10492923, 581623, -105424, 0, 0, 0, 11914], [-51002816, 0, 0, 0, -38245, 27932, 120520, 0], [0, -15443969, -569881, -202496, 0, 0, 0, 25848], [0, 5131562, -137622, -7071, 0, 0, 0, 2028], [-9840494, 0, 0, 0, -81028, 133558, -86465, 0], [67432520, 0, 0, 0, -71912, 133674, 134816, 0], [75660494, 0, 0, 0, 42590, -17902, 284665, 0], [0, -7740481, 1338863, 605344, 0, 0, 0, -17368], [-11460334, 0, 0, 0, 404212, 27664, 176624, 0], [160708420, 0, 0, 0, -112585, -163255, -408536, 0], [0, 16009394, -635042, 868043, 0, 0, 0, 4828], [-72501464, 0, 0, 0, 382435, -364914, 279464, 0], [0, 23428695, 684814, 379241, 0, 0, 0, -104638], [-11520398, 0, 0, 0, 386300, -230242, -28733, 0], [0, -23140620, -83335, -102392, 0, 0, 0, -23219], [0, -42014010, -2749350, 89937, 0, 0, 0, 136676], [0, -8546750, 6061233, 348888, 0, 0, 0, 21335], [-160691316, 0, 0, 0, 470884, -274329, -265312, 0], [40427846, 0, 0, 0, 577026, 73020, 33642, 0], [0, 13911648, -8529914, 825755, 0, 0, 0, -40], [0, -26352204, 5273893, -75064, 0, 0, 0, -59871], [115724050, 0, 0, 0, 112932, 353608, -279396, 0], [0, -48644135, 6776187, 411696, 0, 0, 0, 13466], [0, -45173302, 6652558, -638245, 0, 0, 0, -128876], [-361597294, 0, 0, 0, -803288, 46584, 1054652, 0], [-225077612, 0, 0, 0, 205389, 345573, 471096, 0], [-301903912, 0, 0, 0, -551755, 297874, 775384, 0], [0, 101027797, -11365402, -2175287, 0, 0, 0, -201610], [0, 119230501, 8617595, 314896, 0, 0, 0, 295358], [175505408, 0, 0, 0, -409280, 231680, -497728, 0], [0, -131798795, -8972522, 1662809, 0, 0, 0, 83502], [0, -85657336, -7315978, 797035, 0, 0, 0, -500752], [-116662098, 0, 0, 0, -949770, -1019966, -1755999, 0], [-950291066, 0, 0, 0, 1524418, 448908, -117454, 0], [0, -7771850, -18333987, 1488312, 0, 0, 0, -334841], [0, -11914048, -9320062, -1493423, 0, 0, 0, 527248], [-436217592, 0, 0, 0, -1320926, 289026, -638704, 0], [1152960238, 0, 0, 0, 988046, -103934, 715057, 0], [1000780620, 0, 0, 0, 259368, 180775, -4032960, 0], [0, -4029950, -17820003, -2301768, 0, 0, 0, -899101], [560383118, 0, 0, 0, -913818, 567034, -618675, 0], [-1005715082, 0, 0, 0, -730510, 1412940, -1279886, 0], [0, 132300214, -6008338, 1995739, 0, 0, 0, 274084], [-2080386536, 0, 0, 0, -4971180, 347454, -1645440, 0], [0, 41139088, 17055813, -1094520, 0, 0, 0, -207555], [-156972736, 0, 0, 0, -4527953, 245932, 886376, 0], [249387684, 0, 0, 0, 571166, -1038531, -82928, 0], [0, 98007675, 7422755, -2830784, 0, 0, 0, 1355240], [0, -137621929, -29865197, 6066176, 0, 0, 0, -762508], [-1187452452, 0, 0, 0, 2387407, 491447, 2892392, 0], [0, -137661703, 4703178, 2323011, 0, 0, 0, -1097218], [1655469830, 0, 0, 0, 2994734, 528620, -205286, 0], [0, 229785240, 39820317, 1507560, 0, 0, 0, -592043], [0, -256100845, -34620078, -9046413, 0, 0, 0, 810410], [0, -7735610, -13648419, 3527352, 0, 0, 0, 796311], [0, 394374783, -31900206, 4778595, 0, 0, 0, -612070], [0, -41231646, -30990927, -9552552, 0, 0, 0, -648105], [3121253814, 0, 0, 0, -1135058, 1034028, -2113606, 0], [0, 72753590, -49436955, 12708312, 0, 0, 0, 733271], [1332511426, 0, 0, 0, 1349308, 456136, -3970996, 0], [0, -435976078, -33556511, 7366520, 0, 0, 0, 1664623], [-1927729806, 0, 0, 0, -3197400, 1263440, 3001560, 0], [-47100868, 0, 0, 0, -6090626, -3947637, -3069616, 0], [-1241147902, 0, 0, 0, -4979420, -1637978, 6422951, 0], [-613982288, 0, 0, 0, 5115454, -218380, -6347632, 0], [0, -277175568, 64325250, 8414673, 0, 0, 0, -447088], [3369520962, 0, 0, 0, -6312316, 5118606, 1887211, 0], [0, -1589370, 15644529, 4161048, 0, 0, 0, -1232581], [2977116700, 0, 0, 0, 100699, 1078583, 4426952, 0], [-1478543922, 0, 0, 0, -7627362, 3641514, 2818869, 0], [0, -379836074, 118300997, 13232440, 0, 0, 0, 269055], [5115196740, 0, 0, 0, 4920183, 2911433, -3434904, 0], [0, 40200726, 23095150, -12997813, 0, 0, 0, -2691628], [0, -361645613, -80570173, 1956832, 0, 0, 0, 3383064], [0, 928838692, -28374430, -2500655, 0, 0, 0, 502496], [5447756910, 0, 0, 0, -10056506, -627110, 5135741, 0], [0, -466545975, 69510470, -11106887, 0, 0, 0, -1070218], [0, -369931341, -16983741, 14185344, 0, 0, 0, 2427600], [0, -938978763, -25680001, -23277392, 0, 0, 0, -602894], [0, 9158323, 17621554, -713437, 0, 0, 0, 1382634], [0, 548122677, -78293098, 4811977, 0, 0, 0, 1718750], [5637026104, 0, 0, 0, 1618238, 5137614, -5983376, 0], [6478420284, 0, 0, 0, -15347310, -5235045, 7882800, 0], [0, -1019052088, -36312890, 8309531, 0, 0, 0, -43656], [0, -638787521, -68830553, 21510272, 0, 0, 0, 1555480], [1939998564, 0, 0, 0, 11388838, -8858419, 11972240, 0], [-6468195736, 0, 0, 0, 1559094, -4938550, -12926544, 0], [0, 1246835714, 68570362, 22916033, 0, 0, 0, -2172860], [3170425030, 0, 0, 0, -24188942, -386052, 2400170, 0], [4467624462, 0, 0, 0, 16977830, 1780698, -2326787, 0], [0, 319921649, 166915782, 15148137, 0, 0, 0, 671590], [0, -807697831, -19785585, -19177008, 0, 0, 0, -4829586], [0, -418019147, 33103962, -7177341, 0, 0, 0, -2184202], [-3950202186, 0, 0, 0, 17473698, -131780, 8314794, 0], [0, 108850706, -184886215, -22131848, 0, 0, 0, -1781737], [0, -798958147, 227072198, 42316969, 0, 0, 0, -2607386], [-11268740468, 0, 0, 0, 31650936, -6141449, -8501568, 0], [0, -925376720, 25866137, -8945048, 0, 0, 0, -6486559], [0, -420474903, 172791114, -11895357, 0, 0, 0, -4694594], [3304610804, 0, 0, 0, -22505564, 7892761, 2060960, 0], [0, -1063984705, 182963758, -51971431, 0, 0, 0, -563102], [-4595706858, 0, 0, 0, -3988242, -16677492, -6427350, 0], [0, 688766845, 69928067, -23245616, 0, 0, 0, -3117922], [7819439904, 0, 0, 0, 10756729, -298836, -18566440, 0], [0, 237538314, 77731806, -7905381, 0, 0, 0, 5461868], [-12959920206, 0, 0, 0, -23132332, 4068104, -9558308, 0], [0, 2064812048, -172164739, 8275336, 0, 0, 0, -204123], [-1082540852, 0, 0, 0, 14437166, 3539935, 2261008, 0], [0, 1686443499, 280194251, 9615424, 0, 0, 0, -1835248], [14663575304, 0, 0, 0, -40698179, -14933682, 154136, 0], [-15072775540, 0, 0, 0, 3959545, 9757467, 25898840, 0], [-1202134386, 0, 0, 0, 48729534, -4290822, -14726211, 0], [-5789115950, 0, 0, 0, -13614644, -2072938, -1095025, 0], [0, 109048632, 246619670, 33542491, 0, 0, 0, -9518896], [0, -944574522, -41992999, 19019896, 0, 0, 0, 2221787], [11650215958, 0, 0, 0, -14262818, 10457628, -37832590, 0], [-12024783692, 0, 0, 0, 42277204, 5698889, -13080544, 0], [0, -2066047849, -26994893, 57548192, 0, 0, 0, -2597012], [15034795182, 0, 0, 0, -21039906, -3020750, 33347145, 0], [25359609884, 0, 0, 0, 5177612, 6730907, -42509984, 0], [9487919312, 0, 0, 0, -38296888, -5155452, -45483584, 0], [0, 2154223017, -566688186, -31775319, 0, 0, 0, -7428762]];
    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_n();".
// 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_n(:prec:=8)
    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_n();".
// 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_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_256_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<3,R![7467583705344, 0, 46303554816, 0, 52321120, 0, 13904, 0, 1]>,<7,R![-566184154880, 2269384448, -1696800, -1360, 1]>],Snew);
    return Vf;
end function;