
// Make newform 128.4.e.b in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_128_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_128_e_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_4_e_b();".
// 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_4_e_b();".
// 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 := [1024, -512, -64, 96, 56, -80, 14, 6, -1, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-3072, 2752, -384, -536, 120, 170, -82, -7, 14, -1], [7424, -3264, 3008, -8, 120, -210, 114, -101, 2, -3], [-2304, 16064, -9728, 3848, 120, 130, -634, 341, -122, 3], [31744, -15424, -5632, 2152, 1240, -870, 174, 49, -18, 7], [-4864, -1856, 2752, -792, 520, 90, 86, -39, 38, -17], [256, -6976, 11392, -7992, 1560, 50, 166, -419, 198, -37], [416, 320, -96, -56, 80, -14, -6, 1, 2, -1], [1728, -896, -128, -56, 184, -90, -6, 3, 10, -3], [11264, -11072, 2944, 1704, -1288, -294, 414, -47, -66, 39]];
    Rf_basisdens := [1, 1280, 1280, 1280, 1280, 1280, 1280, 32, 64, 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_128_e();"
function MakeCharacter_128_e()
    N := 128;
    order := 4;
    char_gens := [127, 5];
    v := [4, 3];
    // 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_e_Hecke();"
function MakeCharacter_128_e_Hecke(Kf)
    N := 128;
    order := 4;
    char_gens := [127, 5];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, -1, 0, 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+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 := 4;
    raw_aps := [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, -1, 0, 0, 0, 0, 0, 0], [0, -3, 0, 0, 1, 0, 0, 0, 0, 0], [-1, 1, -1, 2, 0, 0, 0, -1, 0, 1], [0, 0, 0, 0, 1, -2, 1, 1, -1, 1], [-4, 0, 5, -2, 0, 5, 2, 1, -3, 0], [1, 1, 0, 0, 2, 1, 6, -1, -2, -1], [0, 23, -4, 6, 1, 4, 6, 0, 0, 2], [16, 16, 0, 0, -2, 20, 1, 2, 2, 2], [38, 0, 4, 6, 0, 4, -6, -2, 0, 0], [8, -8, -30, 3, 1, 0, 0, -1, 1, 1], [0, -8, -24, -2, 0, 24, -2, 0, 0, -4], [84, -84, 3, 8, 0, 0, 0, 4, 0, -4], [-98, 0, 0, -6, 0, 0, 6, 10, 4, 0], [32, -32, 42, 7, 13, 0, 0, 7, 13, -7], [-174, 174, -1, 0, -14, 0, 0, 4, -14, -4], [-96, -96, 0, 0, 9, 30, -3, -11, -9, -11], [-189, -189, 0, 0, -12, -11, -2, -1, 12, -1], [0, -337, 28, 6, -7, -28, 6, 0, 0, 2], [0, -50, -31, 12, 17, 31, 12, 0, 0, -1], [-428, 0, 4, 32, 0, 4, -32, -8, 4, 0], [260, 260, 0, 0, 22, -11, -28, -2, -22, -2], [0, 18, 15, -52, -1, -15, -52, 0, 0, 1], [-36, 0, 25, -58, 0, 25, 58, -3, -15, 0], [136, -136, 70, -21, -13, 0, 0, -3, -13, 3], [0, -749, -76, 50, 25, 76, 50, 0, 0, -10], [405, -405, -33, -34, -12, 0, 0, -23, -12, 23], [0, 0, 0, 0, 32, 96, 29, 8, -32, 8], [-58, 0, -34, 20, 0, -34, -20, 14, -50, 0], [850, 0, -188, -6, 0, -188, 6, -30, 8, 0], [-609, -609, 0, 0, -4, 53, 22, 3, 4, 3], [0, 212, 86, -6, -66, -86, -6, 0, 0, -2], [850, -850, -29, 100, 20, 0, 0, 6, 20, -6], [416, -416, -176, -13, 16, 0, 0, 28, 16, -28], [0, 875, -172, -14, 17, 172, -14, 0, 0, -74], [528, 528, 0, 0, 7, -190, 29, -37, -7, -37], [-960, -960, 0, 0, -20, -87, -184, -28, 20, -28], [0, -1099, -144, -104, -79, 144, -104, 0, 0, 40], [296, 296, 0, 0, -75, 182, -39, -11, 75, -11], [768, 768, 0, 0, -6, -99, 20, 38, 6, 38], [-632, 632, -320, 155, 24, 0, 0, -60, 24, 60], [1422, 0, -340, 102, 0, -340, -102, 14, -24, 0], [-556, 0, -51, 62, 0, -51, -62, -79, -59, 0], [-1048, 1048, 72, 63, -60, 0, 0, 36, -60, -36], [0, -983, 200, 4, -47, -200, 4, 0, 0, -52], [698, 698, 0, 0, -50, -131, 64, -68, 50, -68], [750, 0, 356, -50, 0, 356, 50, -10, 112, 0], [92, 92, 0, 0, -44, 169, 160, 72, 44, 72], [1328, -1328, -4, -65, 14, 0, 0, -22, 14, 22], [0, 302, -191, -28, -111, 191, -28, 0, 0, 47], [-1540, 0, -84, -64, 0, -84, 64, -56, -148, 0], [4, 0, 321, -58, 0, 321, 58, -99, -39, 0], [520, -520, 183, 260, 130, 0, 0, -38, 130, 38], [1014, 0, -154, -124, 0, -154, 124, 134, 86, 0], [0, -709, 164, 74, 137, -164, 74, 0, 0, 46], [-376, -376, 0, 0, 20, -232, -203, 28, -20, 28], [258, 0, 16, 262, 0, 16, -262, -122, 76, 0], [1256, -1256, 326, -153, -85, 0, 0, 9, -85, -9], [0, -658, 469, 176, 149, -469, 176, 0, 0, 107], [-381, 381, -317, 30, -70, 0, 0, -19, -70, 19], [2392, -2392, -128, 71, -48, 0, 0, -16, -48, 16], [-729, -729, 0, 0, 102, -335, 106, 49, -102, 49], [0, -39, 152, -68, -119, -152, -68, 0, 0, -156], [0, -272, 436, -270, 156, -436, -270, 0, 0, -120], [-3256, -3256, 0, 0, -52, 88, -335, -32, 52, -32], [-585, 585, 79, 146, 72, 0, 0, 111, 72, -111], [-94, 0, 256, 176, 0, 256, -176, 144, 96, 0], [2606, -2606, 471, 32, -106, 0, 0, 20, -106, -20], [4392, 4392, 0, 0, -138, -156, -303, -14, 138, -14], [142, 0, -406, 396, 0, -406, -396, -118, 154, 0], [0, 763, 132, -278, 25, -132, -278, 0, 0, -66], [3614, 0, 48, -102, 0, 48, 102, 282, -204, 0], [-1752, 1752, -262, -297, 213, 0, 0, 167, 213, -167], [1434, -1434, 591, -368, -134, 0, 0, -28, -134, 28], [-948, 0, 152, 204, 0, 152, -204, 172, 208, 0], [-4168, 4168, 418, -325, 81, 0, 0, 71, 81, -71], [-536, -536, 0, 0, -242, 228, -691, 22, 242, 22], [340, 0, 169, 214, 0, 169, -214, -315, 65, 0], [0, -976, -4, 202, -316, 4, 202, 0, 0, -160], [4237, 4237, 0, 0, 64, -283, -134, -19, -64, -19], [4040, -4040, 964, 255, -174, 0, 0, -98, -174, 98], [1124, 0, -180, -56, 0, -180, 56, -288, 284, 0], [-860, 0, -119, -234, 0, -119, 234, 245, -31, 0], [0, -3219, -752, 136, -391, 752, 136, 0, 0, 376], [3883, -3883, -949, -90, -66, 0, 0, -23, -66, 23], [-3236, 0, 233, -442, 0, 233, 442, 77, -511, 0], [0, -2152, 752, -442, -216, -752, -442, 0, 0, -108], [-816, -816, 0, 0, 114, 2012, 941, 98, -114, 98], [5216, 0, 92, -276, 0, 92, 276, -220, -364, 0], [-6393, -6393, 0, 0, 434, -615, 178, -43, -434, -43], [222, 0, -540, 30, 0, -540, -30, 70, 272, 0], [0, 6517, 272, 72, 145, -272, 72, 0, 0, 488], [-5402, 5402, -1685, 292, 288, 0, 0, -10, 288, 10], [-398, -398, 0, 0, -86, 1637, 248, 264, 86, 264], [0, -1921, -1140, 334, 337, 1140, 334, 0, 0, 122], [-6200, -6200, 0, 0, -311, -674, 525, 61, 311, 61], [0, 3380, -786, 330, 150, 786, 330, 0, 0, 118], [-99, 99, 327, -618, 56, 0, 0, -11, 56, 11], [7632, 7632, 0, 0, 117, -1754, 293, -151, -117, -151], [1147, 1147, 0, 0, 248, -211, 790, 275, -248, 275], [776, 776, 0, 0, 163, -230, 161, 163, -163, 163], [-1859, -1859, 0, 0, -594, -1415, -906, 111, 594, 111], [0, 2348, -158, 358, -262, 158, 358, 0, 0, -230], [-353, 353, -1509, 894, -290, 0, 0, -131, -290, 131], [-1734, 0, -228, 952, 0, -228, -952, 236, 668, 0], [-5603, 5603, 247, -522, -256, 0, 0, 13, -256, -13], [-3478, 0, 140, -184, 0, 140, 184, -68, 44, 0], [0, 4309, 1504, -384, -119, -1504, -384, 0, 0, -48], [0, 2410, 1035, -108, 411, -1035, -108, 0, 0, -155], [-1376, 0, -824, -264, 0, -824, 264, 408, -200, 0], [6920, -6920, -468, -289, -218, 0, 0, 154, -218, -154], [0, -2862, -221, -352, 227, 221, -352, 0, 0, -307], [2595, -2595, -1177, -1486, -308, 0, 0, 335, -308, -335], [0, -941, -1532, 282, -191, 1532, 282, 0, 0, 78], [2804, 0, -1755, 174, 0, -1755, -174, -391, -419, 0], [-3793, -3793, 0, 0, -68, 1877, 582, 195, 68, 195], [0, -8585, -436, -82, -359, 436, -82, 0, 0, 42], [-1464, -1464, 0, 0, -112, -864, -1115, -392, 112, -392], [-4624, -4624, 0, 0, 318, 533, -20, -30, -318, -30], [7160, -7160, -440, 355, 652, 0, 0, 72, 652, -72], [-204, 0, -1051, -1202, 0, -1051, 1202, 345, 93, 0], [9160, -9160, -1598, 739, -79, 0, 0, -17, -79, 17], [-948, 948, 2467, 488, 368, 0, 0, -292, 368, 292], [1986, 1986, 0, 0, 402, -3019, -872, -320, -402, -320], [-7672, -7672, 0, 0, 215, 834, 293, 443, -215, 443], [-6816, 6816, -906, 547, -5, 0, 0, 101, -5, -101], [-15580, 0, 100, -224, 0, 100, 224, -440, -476, 0], [0, 2601, 1016, 1196, 217, -1016, 1196, 0, 0, 324], [8008, 8008, 0, 0, 580, 264, -615, -64, -580, -64], [-6722, -6722, 0, 0, 172, 1601, 740, -190, -172, -190], [0, -11367, -24, -252, 385, 24, -252, 0, 0, -52], [-4460, 0, -260, -1368, 0, -260, 1368, 192, 524, 0], [-5184, 5184, 3232, -1141, -88, 0, 0, -148, -88, 148], [0, -3864, 1400, 826, 64, -1400, 826, 0, 0, -76], [7396, 0, 365, 894, 0, 365, -894, -63, -859, 0], [-9872, 9872, -1002, -973, -213, 0, 0, 149, -213, -149], [11008, 11008, 0, 0, -626, 1877, -1124, -78, 626, -78], [7832, 7832, 0, 0, -39, 862, -203, 69, 39, 69], [0, 4624, 236, -394, -348, -236, -394, 0, 0, 936], [6421, -6421, 1775, 286, 172, 0, 0, -143, 172, 143], [-3752, 3752, -2190, 599, 113, 0, 0, 107, 113, -107], [0, -4311, -680, 908, 1129, 680, 908, 0, 0, -492], [3487, -3487, -1861, -402, 702, 0, 0, -499, 702, 499], [-8344, -8344, 0, 0, -335, 846, -579, -363, 335, -363], [0, -18279, -280, -60, -143, 280, -60, 0, 0, 444], [2304, -2304, -1374, 1023, -295, 0, 0, -653, -295, 653], [0, 5604, -1146, -586, 414, 1146, -586, 0, 0, -970], [-10470, 10470, 2023, 1192, -90, 0, 0, 336, -90, -336], [13822, 0, 388, 526, 0, 388, -526, -186, -1072, 0], [560, 560, 0, 0, 170, -1012, 405, -478, -170, -478], [8186, 0, 428, -296, 0, 428, 296, 556, -404, 0], [10683, 10683, 0, 0, 526, 1681, -1038, -243, -526, -243], [0, 26625, 8, -1116, -1431, -8, -1116, 0, 0, -148], [9876, -9876, -1253, -1328, 348, 0, 0, 176, 348, -176], [-24910, 0, 1104, 294, 0, 1104, -294, 150, -244, 0], [0, 2159, 524, 350, -639, -524, 350, 0, 0, -934], [-1252, 0, 2049, 1110, 0, 2049, -1110, 149, 793, 0], [0, 4958, 2681, 1348, 457, -2681, 1348, 0, 0, 87], [-4096, -4096, 0, 0, -400, 1664, -1107, -1048, 400, -1048], [-2201, -2201, 0, 0, -650, -4079, -950, 161, 650, 161], [0, 7460, -946, 78, -314, 946, 78, 0, 0, 910], [0, -8467, 1472, -144, 1409, -1472, -144, 0, 0, -784], [-11354, 11354, -125, -1092, -1012, 0, 0, -542, -1012, 542], [-9908, 0, -3147, 606, 0, -3147, -606, -447, -147, 0], [0, 17217, 296, -2108, -711, -296, -2108, 0, 0, -324], [1216, 0, 2120, -120, 0, 2120, 120, -200, 24, 0], [-592, 592, -3314, 1307, 471, 0, 0, -431, 471, 431]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_128_e_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_128_4_e_b();".
// 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_4_e_b(:prec:=10)
    chi := MakeCharacter_128_e();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_4_e_b();".
// 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_4_e_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_128_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![829472, 1272544, 976144, 166272, 4624, -4432, 4424, 96, 2, -2, 1]>],Snew);
    return Vf;
end function;