
// Make newform 256.8.b.l 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_l();".
// 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_l();".
// 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 := [36, 0, 2512, 0, 101, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [0, -1854, 0, -95, 0, -1], [0, -2206, 0, -95, 0, -1], [31, 0, -204, 0, -4, 0], [0, 197118, 0, 7639, 0, 73], [-23517, 0, -1724, 0, -20, 0]];
    Rf_basisdens := [1, 44, 33, 11, 66, 33];
    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], [-1, 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, -1, 1, 0, 0, 0], [0, -1, 0, 0, 1, 0], [3, 0, 0, -2, 0, 1], [0, -21, 32, 0, -20, 0], [0, 85, -147, 0, 27, 0], [104, 0, 0, -211, 0, 15], [0, 531, -36, 0, -68, 0], [14261, 0, 0, -482, 0, 51], [0, 2805, -7196, 0, -245, 0], [-52424, 0, 0, 20, 0, 364], [0, 6847, 11059, 0, -47, 0], [301658, 0, 0, -5382, 0, -658], [0, 6227, -34921, 0, -344, 0], [-284718, 0, 0, -2736, 0, -1534], [0, 21455, 76845, 0, -1183, 0], [0, -849, -92551, 0, 3552, 0], [0, 13077, -175039, 0, -3749, 0], [0, 17935, 325076, 0, -3124, 0], [3312591, 0, 0, -2966, 0, 729], [1938872, 0, 0, 22363, 0, 217], [-328726, 0, 0, 21140, 0, 2814], [0, 18499, 617001, 0, 6256, 0], [1625288, 0, 0, 38731, 0, -5783], [-1733280, 0, 0, 69369, 0, 18515], [0, 28719, -9535, 0, -21631, 0], [5939899, 0, 0, 144290, 0, -7939], [0, 171011, 1303098, 0, -21452, 0], [0, -194875, 555532, 0, -39429, 0], [4318354, 0, 0, 123720, 0, -25224], [29601668, 0, 0, -125828, 0, -20064], [0, -76593, 576294, 0, 80148, 0], [-14640550, 0, 0, -94798, 0, -53834], [0, -139301, 4738883, 0, 80120, 0], [0, 354287, -3354082, 0, -67727, 0], [13636949, 0, 0, -476594, 0, -38525], [0, 507557, 1774831, 0, -53397, 0], [0, -165001, 2010643, 0, -13400, 0], [2960783, 0, 0, 783526, 0, 64437], [0, -56331, 633431, 0, -146725, 0], [0, -463541, 3156375, 0, -361784, 0], [0, 1044495, -1873976, 0, 34481, 0], [62892, 0, 0, -1088820, 0, 145432], [-38430320, 0, 0, 826161, 0, -145605], [0, 1045759, 5643258, 0, 128225, 0], [36065747, 0, 0, 1535894, 0, -73431], [0, -1176813, 7305879, 0, 606568, 0], [-133737720, 0, 0, -97844, 0, -399948], [0, -735113, 2045425, 0, -268000, 0], [0, -1222449, 22859614, 0, -126255, 0], [57003272, 0, 0, 444723, 0, 298337], [-172607714, 0, 0, 865772, 0, 288778], [-111864152, 0, 0, -529651, 0, 168303], [0, -1907457, -20150975, 0, 632896, 0], [-18258126, 0, 0, 345344, 0, -745056], [-157622625, 0, 0, 102146, 0, -231423], [0, 4090917, -9336538, 0, -411653, 0], [-226762434, 0, 0, -668504, 0, -30778], [0, 6800479, -25012879, 0, 1061265, 0], [-69819504, 0, 0, -3043673, 0, 77469], [0, 3102151, -30505678, 0, -69660, 0], [0, 7761343, 3792578, 0, -247007, 0], [0, -6915845, -23580240, 0, 435244, 0], [-549144283, 0, 0, 3287714, 0, 111175], [-42947830, 0, 0, -3397302, 0, 577374], [0, -255931, 55838008, 0, 1650555, 0], [0, -1296053, -6687622, 0, 1219028, 0], [75921258, 0, 0, -873028, 0, -1385740], [0, 3016055, 25481187, 0, 1579304, 0], [0, 16933749, 14451790, 0, -3525781, 0], [403040234, 0, 0, -5678228, 0, 604580], [-256706213, 0, 0, -13253934, 0, 44109], [-96119870, 0, 0, -3230472, 0, 730586], [0, -10138545, -52755853, 0, -4404479, 0], [0, -23609841, 5136175, 0, -1047496, 0], [253296128, 0, 0, 7806528, 0, -601024], [0, -11779553, 127819539, 0, -914191, 0], [0, -15456939, -138815792, 0, 1519147, 0], [53918104, 0, 0, -33419, 0, 1082407], [916647450, 0, 0, 1433330, 0, 2156566], [0, -10675097, 91332652, 0, 648460, 0], [0, -189457, 316721864, 0, 1036689, 0], [392737598, 0, 0, -4801228, 0, 1943986], [-1407935240, 0, 0, -3192795, 0, -195977], [2415984853, 0, 0, 774418, 0, -390425], [0, -20376529, 63958488, 0, -4869220, 0], [-100842832, 0, 0, -24178895, 0, -629381], [2014686602, 0, 0, -17467406, 0, -1111402], [0, 23292469, -142385886, 0, 5491371, 0], [-743219734, 0, 0, 10123092, 0, 2311614], [0, -9335757, 115874102, 0, -1044060, 0], [329016552, 0, 0, 22736092, 0, -727260], [2743241855, 0, 0, 3192494, 0, 3720685], [0, -54567789, 174094005, 0, -37088, 0], [0, 26976875, 287721297, 0, 6005040, 0], [-265229943, 0, 0, -19126458, 0, -505297], [0, 63680245, 178924447, 0, 3436315, 0], [-1412428054, 0, 0, 414442, 0, 6018462], [0, 23390075, -73012946, 0, -5927068, 0], [0, -21461515, 124765445, 0, 5215931, 0], [0, -86686137, 267400252, 0, -11173428, 0], [0, -66437819, 150036953, 0, -14190485, 0], [0, -7196805, -467890224, 0, -14149716, 0], [-2224098854, 0, 0, -3236342, 0, -4402690], [0, -31911377, -10454852, 0, -12879572, 0], [-1756105606, 0, 0, 50336524, 0, -3005148], [0, 134712411, -133897376, 0, -3190612, 0], [2800086626, 0, 0, 46094360, 0, -4573240], [-5250730007, 0, 0, -52114606, 0, 3955195], [214518024, 0, 0, 4647835, 0, 2487705], [-2501548252, 0, 0, -55626432, 0, 3543844], [0, -78823825, 812232088, 0, -9554671, 0], [-2591763856, 0, 0, 11550287, 0, -1224299], [0, -102609677, -350931628, 0, -4184228, 0], [142319705, 0, 0, -74884458, 0, 10234831], [2093357952, 0, 0, 2024025, 0, 4057971], [0, 98428127, 21889724, 0, 23401900, 0], [-5466719969, 0, 0, 46582210, 0, -4643519], [0, -20854651, -110393918, 0, 3994587, 0], [0, 141501619, -865263251, 0, 188480, 0], [0, -75166161, -85856860, 0, 3312721, 0], [-3931918736, 0, 0, -22604255, 0, -1169973], [0, 98158815, 559129791, 0, 7249649, 0], [0, -107582685, -645268179, 0, -1437888, 0], [0, -68355125, 454934135, 0, -25604280, 0], [0, 36264517, 249929445, 0, 4532843, 0], [0, 173896815, 1193587923, 0, -9370079, 0], [-7719566158, 0, 0, -60911060, 0, 8038814], [7959827529, 0, 0, 83952930, 0, -5016405], [0, -192546235, -557316016, 0, 12210043, 0], [0, -191715465, 1168880689, 0, 4266784, 0], [-3583658481, 0, 0, -37632210, 0, 18900221], [-1716204090, 0, 0, -67609900, 0, -18938278], [0, -12897969, 745173574, 0, -19416559, 0], [-365077494, 0, 0, -16641974, 0, -13582882], [-7538914544, 0, 0, -12253919, 0, 1761227], [0, -164745745, 502790679, 0, -24577951, 0], [0, 83448579, 1437272699, 0, 4952760, 0], [0, -193149035, -10493853, 0, 56871355, 0], [-4905943814, 0, 0, 44037898, 0, 8939422], [0, -111556125, 1230043280, 0, 8336396, 0], [0, -222495185, -418293365, 0, 33153441, 0], [7974310149, 0, 0, 3891250, 0, -887753], [0, -408696801, 389487662, 0, -18318668, 0], [0, 162208885, -497803345, 0, -22900325, 0], [-4889277381, 0, 0, -84784322, 0, 11685369], [0, -250825041, 405441289, 0, -24863935, 0], [-3503851878, 0, 0, 217018554, 0, -11261298], [0, 193877655, 1279106359, 0, 12053240, 0], [2939783552, 0, 0, 94603988, 0, -18059276], [0, -143831659, 523145038, 0, 40095755, 0], [7030969738, 0, 0, 94202812, 0, 39261300], [0, 59695643, 570422406, 0, 119321860, 0], [-3372257243, 0, 0, 127426986, 0, 2356879], [0, 24852075, 2073997845, 0, -9997696, 0], [10440017878, 0, 0, 10165088, 0, -7635626], [6034169549, 0, 0, 179441014, 0, 34834403], [4891760784, 0, 0, 36710721, 0, -6630165], [-6511811480, 0, 0, -38848125, 0, -54634927], [0, -118818075, 1782863136, 0, 44704667, 0], [0, 34027323, 115478436, 0, -58690820, 0], [-1840949910, 0, 0, 185806498, 0, -352378], [18098188811, 0, 0, -269787618, 0, -26637143], [0, 231915003, -498115535, 0, -23410384, 0], [156653992, 0, 0, -179791331, 0, -28110305], [-3203187167, 0, 0, -66920422, 0, -40905285], [21130088556, 0, 0, 196416344, 0, 26923204], [0, -601757265, -807910689, 0, 122292129, 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_l();".
// 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_l(:prec:=6)
    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_l();".
// 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_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_256_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<3,R![88962624, 0, 10224432, 0, 6508, 0, 1]>,<7,R![73585600, -416976, -12, 1]>],Snew);
    return Vf;
end function;