
// Make newform 32.8.b.a in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_32_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_32_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_32_8_b_a();".
// 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_32_8_b_a();".
// 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 := [32768, -3072, -320, -24, -10, -3, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [106, -72, 42, 3, -1, 0], [15872, 1088, 104, -50, -7, -3], [60928, 3136, -1112, 222, -47, -11], [2260, 1200, 108, 16, 1, -1], [-205312, 101952, -3352, -1458, -487, 93]];
    Rf_basisdens := [1, 2, 256, 256, 4, 256];
    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_32_b();"
function MakeCharacter_32_b()
    N := 32;
    order := 2;
    char_gens := [31, 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_32_b_Hecke();"
function MakeCharacter_32_b_Hecke(Kf)
    N := 32;
    order := 2;
    char_gens := [31, 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+1)]];
    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, 1, 0, 0, 0], [0, 0, 1, 1, 0, 0], [115, 1, 0, 0, 0, 0], [0, 0, -3, -7, 0, -1], [0, 0, -21, -3, 0, -2], [248, 25, 0, 0, -7, 0], [0, 0, 105, 93, 0, -5], [217, 11, 0, 0, -8, 0], [0, 0, -2337, 79, 0, 16], [14908, 12, 0, 0, 72, 0], [0, 0, 6633, -33, 0, 58], [87022, 302, 0, 0, 142, 0], [0, 0, -579, 522, 0, 38], [-261198, -210, 0, 0, -168, 0], [0, 0, 17949, 535, 0, -170], [0, 0, 10933, 3680, 0, -224], [0, 0, -7353, 3993, 0, -66], [0, 0, 4017, -1443, 0, 123], [1264923, -3279, 0, 0, -504, 0], [348404, -809, 0, 0, 1239, 0], [-2669330, -2054, 0, 0, 2016, 0], [0, 0, -13319, 9992, 0, 568], [362020, 1079, 0, 0, 439, 0], [-183496, -7183, 0, 0, 849, 0], [0, 0, -155207, -19253, 0, -1794], [11078791, -3211, 0, 0, 936, 0], [0, 0, -180243, 239, 0, -2599], [0, 0, 80931, -42069, 0, -328], [-768198, 14172, 0, 0, -4068, 0], [-20085248, 760, 0, 0, 10632, 0], [0, 0, 138673, -74953, 0, -1199], [-7063818, -33942, 0, 0, -5238, 0], [0, 0, -632499, 9882, 0, 7702], [0, 0, 476373, 6409, 0, -404], [36400393, -49573, 0, 0, 17592, 0], [0, 0, -523137, 3021, 0, 9634], [0, 0, 609681, 201498, 0, 12182], [41412239, 61909, 0, 0, -6496, 0], [0, 0, -21261, 105361, 0, -6446], [0, 0, -423191, 25214, 0, -18542], [0, 0, -275523, -25347, 0, 704], [-13037672, 55712, 0, 0, -7448, 0], [31527032, 97, 0, 0, 19137, 0], [0, 0, -1094287, 222781, 0, -3436], [-8476325, -31031, 0, 0, -11856, 0], [0, 0, -1009191, 228666, 0, 23798], [72062692, -112524, 0, 0, 44952, 0], [0, 0, 93137, -547432, 0, 13992], [0, 0, -3011751, -140427, 0, -5692], [-6513884, -38065, 0, 0, 74191, 0], [88470090, -109362, 0, 0, -46272, 0], [-120608728, -179727, 0, 0, -31407, 0], [0, 0, 2041749, 512636, 0, 4388], [115521210, -33036, 0, 0, -20940, 0], [-250127485, -283463, 0, 0, -29320, 0], [0, 0, 107307, -372065, 0, -67796], [222320998, 34058, 0, 0, -100872, 0], [0, 0, 1145973, -193425, 0, -66730], [153112212, 240639, 0, 0, 119679, 0], [0, 0, -3764619, -1214097, 0, -35623], [0, 0, 1531689, -852731, 0, 56836], [0, 0, 6096537, 888309, 0, -20829], [-108534347, 238199, 0, 0, 305344, 0], [141121886, -380370, 0, 0, 76686, 0], [0, 0, 1013383, 1813399, 0, 145776], [0, 0, 12658557, 305523, 0, 36149], [-448179334, 471116, 0, 0, 31116, 0], [0, 0, -13200763, 1483874, 0, 11406], [0, 0, 12691695, -63333, 0, -281420], [577236450, -794592, 0, 0, 82080, 0], [161754535, 975989, 0, 0, -212216, 0], [-113349686, 449414, 0, 0, -255096, 0], [0, 0, -12961491, 2246715, 0, 51170], [0, 0, -7110027, 1527870, 0, -252974], [-233255088, 747216, 0, 0, 461472, 0], [0, 0, -21443359, 2384791, 0, -218758], [0, 0, 16437963, -3949005, 0, 23000], [-1240708008, -1274775, 0, 0, 138825, 0], [156828830, -1042402, 0, 0, -553602, 0], [0, 0, -8498559, 1385657, 0, -261313], [0, 0, -17927991, -4963839, 0, 297608], [-1462543182, -1117290, 0, 0, 13680, 0], [-1292916760, 514353, 0, 0, 800145, 0], [1122525925, 592967, 0, 0, 152832, 0], [0, 0, -2379579, -2236219, 0, 404819], [1808301960, 518457, 0, 0, -475623, 0], [-749276626, -1035138, 0, 0, 560094, 0], [0, 0, -12470373, -3070577, 0, -227156], [-646790210, 43402, 0, 0, 1189440, 0], [0, 0, -23323543, 559571, 0, -180651], [-1876177660, 2714356, 0, 0, -922504, 0], [508602151, -1901907, 0, 0, -500784, 0], [0, 0, -34049411, 3726476, 0, -113132], [0, 0, 26767017, -10541604, 0, -105276], [1293912813, -16857, 0, 0, -1239432, 0], [0, 0, 13118199, -1658627, 0, -481622], [-1296585258, 1113594, 0, 0, -246246, 0], [0, 0, 19868061, 11411235, 0, 908805], [0, 0, -11542689, -10486311, 0, 934102], [0, 0, -12335103, -8321115, 0, 869875], [0, 0, 37598163, 7251349, 0, -190514], [0, 0, 48508761, 230921, 0, 230639], [1744773990, -3715494, 0, 0, 531066, 0], [0, 0, 92014917, -742527, 0, 269239], [4459883354, 365572, 0, 0, 386244, 0], [0, 0, -6689123, -4192243, 0, -484277], [-3607467294, 1757640, 0, 0, 86856, 0], [-972290975, 1113227, 0, 0, -1907888, 0], [1096214612, 4582335, 0, 0, -1711425, 0], [4012604452, 936700, 0, 0, 105552, 0], [0, 0, -14320071, -16996431, 0, -971704], [-1845680668, -996497, 0, 0, -54673, 0], [0, 0, -143727027, 5339685, 0, -814989], [-5991515747, -5840201, 0, 0, -1360776, 0], [4244315672, -2668175, 0, 0, -1192495, 0], [0, 0, 22242321, -15657459, 0, -2004661], [-86612781, 9765129, 0, 0, 397464, 0], [0, 0, -104932341, -6923177, 0, 503572], [0, 0, -134012007, -12303700, 0, 1413236], [0, 0, 76584789, 17005101, 0, -386072], [3455146856, -1040295, 0, 0, 543801, 0], [0, 0, 78925833, 14087671, 0, 2181634], [0, 0, -161468579, 6613736, 0, -541736], [0, 0, 127485993, -5118078, 0, 594286], [0, 0, -153241241, 11245081, 0, 1078878], [0, 0, 9129969, -33492417, 0, 659618], [-2825383490, -10334086, 0, 0, 1785424, 0], [-6344461295, 7597211, 0, 0, -4661040, 0], [0, 0, -196140081, 12787647, 0, -1507952], [0, 0, -39494511, 29542164, 0, -654772], [4520784839, -846995, 0, 0, 38384, 0], [4623245098, 9288606, 0, 0, -520944, 0], [0, 0, 166960653, 38555073, 0, -187668], [3961069982, 5817646, 0, 0, 446606, 0], [1073446760, 802409, 0, 0, -6797751, 0], [0, 0, 167183809, -18796793, 0, -3228822], [0, 0, -38833863, 16321146, 0, -2662986], [0, 0, -27628897, 17590285, 0, -3292030], [2787663150, 13949070, 0, 0, 1525230, 0], [0, 0, -42595731, -12910539, 0, -3788317], [0, 0, 65246173, -34631093, 0, 2521986], [3384790069, 17214615, 0, 0, -1983456, 0], [0, 0, -44835483, 26970251, 0, 1371869], [0, 0, 257312007, -55279155, 0, 1383914], [19217720555, -13017815, 0, 0, 3374720, 0], [0, 0, 232656069, 46098087, 0, -2489682], [-1398777498, 12155658, 0, 0, 7948842, 0], [0, 0, -320192955, -10155282, 0, 5178530], [-22732300428, 4678356, 0, 0, -3106968, 0], [0, 0, -88711197, 36467487, 0, 3542948], [189033562, 5526092, 0, 0, -11899508, 0], [0, 0, 358421721, -23045853, 0, 605573], [21701908653, -2029713, 0, 0, -2064912, 0], [0, 0, 342726957, -41605968, 0, -3140912], [-22205899722, 4378506, 0, 0, 9444456, 0], [3862875145, -21905749, 0, 0, 4821096, 0], [-17198699560, -15174719, 0, 0, 6541601, 0], [11031163844, 32639967, 0, 0, 795999, 0], [0, 0, -291923277, -37718333, 0, -6306704], [0, 0, 385490457, 46029233, 0, 4049927], [-1491584058, 16235562, 0, 0, -16066998, 0], [-6822867749, -15692967, 0, 0, 1681056, 0], [0, 0, 107870733, -66578728, 0, -6605464], [16879167368, -22397615, 0, 0, -9182287, 0], [27352331345, -4523093, 0, 0, 4016000, 0], [5117439508, -20331108, 0, 0, 1573632, 0], [0, 0, 199132953, -65317953, 0, -854262]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_32_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_32_8_b_a();".
// 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_32_8_b_a(:prec:=6)
    chi := MakeCharacter_32_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_32_8_b_a();".
// 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_32_8_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_32_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;