
// Make newform 252.9.d.b in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_252_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_252_d_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_252_9_d_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_252_9_d_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 := [85162752, 0, 976392, 0, 2160, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [0, 5640984, 0, -828, 0, -1], [0, -494136, 0, 828, 0, 1], [-251332416, 63046152, -2021976, 212796, -1332, 109], [1507994496, 531380376, 12131856, 1691604, 7992, 859], [8574584832, 131733288, 31983984, 424764, 15984, 217]];
    Rf_basisdens := [1, 183816, 20424, 183816, 183816, 183816];
    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_252_d();"
function MakeCharacter_252_d()
    N := 252;
    order := 2;
    char_gens := [127, 29, 73];
    v := [2, 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_252_d_Hecke();"
function MakeCharacter_252_d_Hecke(Kf)
    N := 252;
    order := 2;
    char_gens := [127, 29, 73];
    char_values := [[1, 0, 0, 0, 0, 0], [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 := 9;
    raw_aps := [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, -1, 0, 0, 0, 0], [361, 0, 0, -1, 0, 0], [-4082, -1, 0, -2, 0, 1], [0, -29, -3, -6, -1, 0], [0, -100, 45, 18, 3, 0], [0, -64, 50, -30, -5, 0], [1934, -29, 6, -58, 6, 5], [-210722, 98, -30, 196, -30, 22], [0, 996, -1515, 90, 15, 0], [530722, -342, 78, -684, 78, 30], [0, -2078, 1290, -540, -90, 0], [-1297230, 175, -70, 350, -70, 105], [0, -364, -4809, 486, 81, 0], [1390110, -420, 180, -840, 180, -300], [0, -1784, 5130, 2610, 435, 0], [0, 10019, 3300, -120, -20, 0], [2763250, 2395, -490, 4790, -490, -435], [10348142, 316, -219, 632, -219, 560], [0, -3346, 33803, 5118, 853, 0], [31019090, 1050, -471, 2100, -471, 834], [0, 43240, -29163, -4428, -738, 0], [0, -25554, 21285, -14670, -2445, 0], [0, -28328, -22843, -3822, -637, 0], [0, 169203, -65055, 1170, 195, 0], [0, -7408, -98512, -20028, -3338, 0], [-167282546, -919, 666, -1838, 666, -1745], [35259810, 23872, -5032, 47744, -5032, -3744], [98572734, 12321, -4839, 24642, -4839, 7035], [-288728334, -5131, -746, -10262, -746, 8115], [0, 193056, 3225, -86220, -14370, 0], [-175551362, 76412, -18528, 152824, -18528, -2300], [0, -556144, 110840, 39930, 6655, 0], [-466073634, 24996, -3264, 49992, -3264, -11940], [208204786, -14979, 5634, -29958, 5634, -7557], [0, 724263, 118797, -116118, -19353, 0], [236785586, 81669, -24756, 163338, -24756, 17355], [0, -136840, -467058, -103176, -17196, 0], [0, 905925, -280671, 71154, 11859, 0], [-243253234, 78091, -20544, 156182, -20544, 4085], [0, -59459, -625430, -283020, -47170, 0], [145172462, 68878, -17373, 137756, -17373, 614], [-349909118, -72897, 7083, -145794, 7083, 44565], [-244849826, 90986, -2754, 181972, -2754, -79970], [0, -1973192, 1371540, -41460, -6910, 0], [765744626, 43271, 4714, 86542, 4714, -62127], [0, -3004824, -579640, -142992, -23832, 0], [0, 632016, 595908, -109998, -18333, 0], [0, 2627541, 1411735, 14670, 2445, 0], [1670857342, 511268, -137832, 1022536, -137832, 40060], [-864244978, -279473, 74742, -558946, 74742, -19495], [0, 4094444, -1404125, 171150, 28525, 0], [0, 3474896, 3304785, 972360, 162060, 0], [0, 2736744, -1524942, -281052, -46842, 0], [1311525998, -539768, 153057, -1079536, 153057, -72460], [0, 3173221, 2937075, 1041750, 173625, 0], [0, 708688, 3209370, -472020, -78670, 0], [-552251166, -440074, 174166, -880148, 174166, -256590], [-4888885570, -406040, 100224, -812080, 100224, 5144], [0, 1859832, 2887811, 922176, 153696, 0], [0, -6762413, -342939, 1250010, 208335, 0], [0, -2651712, -7152853, 2226348, 371058, 0], [0, 2394524, -12802545, 791730, 131955, 0], [0, 10072522, -12920636, 1596360, 266060, 0], [-1350386274, -1458726, 275214, -2917452, 275214, 357870], [-2664993614, 1393401, -426084, 2786802, -426084, 310935], [1510416706, -902241, 56679, -1804482, 56679, 675525], [-9464971058, 830153, -323202, 1660306, -323202, 462655], [0, -9462997, 6766430, -1365780, -227630, 0], [0, -2237104, -14019252, 2349576, 391596, 0], [-4041973618, -1080005, 489270, -2160010, 489270, -877075], [0, -297464, 7417294, 2086644, 347774, 0], [18677595746, -854646, 226194, -1709292, 226194, -50130], [-19032560462, -2459895, 708180, -4919790, 708180, -372825], [0, 9935140, -19743963, -1057878, -176313, 0], [11816337118, 158714, 125142, 317428, 125142, -659282], [0, -17469729, 9545320, 6019632, 1003272, 0], [-23878914946, -2300603, 668097, -4601206, 668097, -371785], [0, -29784646, -1540650, 6151020, 1025170, 0], [0, 9847376, 15856665, -1905660, -317610, 0], [10777619362, 1090360, 5468, 2180720, 5468, -1112232], [-9669074546, -4994365, 1153938, -9988730, 1153938, 378613], [0, 52598244, -52858247, 1499418, 249903, 0], [0, -49131516, -17156705, -5169510, -861585, 0], [-23853629106, 1962531, -723384, 3925062, -723384, 931005], [-10828725442, -663728, 316908, -1327456, 316908, -603904], [2607853186, 975009, -802791, 1950018, -802791, 2236155], [0, 48048193, -6041250, 6550380, 1091730, 0], [-40768785262, 6018702, -1341543, 12037404, -1341543, -652530], [0, -101173296, 34149870, -8542242, -1423707, 0], [0, 20885956, -42460365, -8581050, -1430175, 0], [13912547954, -712339, -588254, -1424678, -588254, 3065355], [27658422222, 5559069, -1341126, 11118138, -1341126, -194565], [-17704564302, -5626163, 2124716, -11252326, 2124716, -2872701], [0, 12588652, -8878995, -19852578, -3308763, 0], [0, -12113771, 13829430, -14122260, -2353710, 0], [0, 41437594, -93967530, 11575260, 1929210, 0], [0, -2294552, -29843432, 4662858, 777143, 0], [-64228308382, 6076944, -1371228, 12153888, -1371228, -592032], [-67968718, 1313253, -188172, 2626506, -188172, -560565], [67199795806, 6986744, -2650656, 13973488, -2650656, 3615880], [0, 98326608, 59705622, -9932418, -1655403, 0], [36701589758, -15539201, 2969559, -31078402, 2969559, 3660965], [48507045554, 8419683, -1644522, 16839366, -1644522, -1841595], [0, -155589016, 4163134, -16934916, -2822486, 0], [0, -20769360, -10387782, -22410342, -3735057, 0], [0, -42217940, -141233508, 26002728, 4333788, 0], [51304084270, 12262604, -1864671, 24525208, -1864671, -4803920], [0, 25366962, -169529015, -22417830, -3736305, 0], [0, -32657192, 48175488, 5091456, 848576, 0], [21806319394, -21707144, 6352676, -43414288, 6352676, -3703560], [-129992281026, -4503189, -917289, -9006378, -917289, 8172345], [0, 120620032, -131068575, 6478500, 1079750, 0], [-66202994734, 1237560, -2123853, 2475120, -2123853, 7257852], [149310454270, -14529367, 3422853, -29058734, 3422853, 837955], [0, -219209952, -41379038, 3320154, 553359, 0], [0, -8789304, -2891412, -20513772, -3418962, 0], [-2237678690, -11569600, 5819220, -23139200, 5819220, -11707280], [126488993486, -12889295, 4151922, -25778590, 4151922, -3718393], [0, -197270807, -24924855, 39523170, 6587195, 0], [20102523266, -3350716, 172684, -6701432, 172684, 2659980], [0, 51529023, 119210934, 16811820, 2801970, 0], [72925732110, -10462035, 2967270, -20924070, 2967270, -1407045], [0, 76768536, 112123255, -39271500, -6545250, 0], [132337529118, -29768400, 7857012, -59536800, 7857012, -1659648], [155546006626, -12822852, 5374596, -25645704, 5374596, -8675532], [0, -214596404, 185502975, 55071990, 9178665, 0], [0, -435499296, -8402128, -39013668, -6502278, 0], [0, 359859459, 121611138, 38103012, 6350502, 0], [110848955186, 42650577, -12340656, 85301154, -12340656, 6712047], [123829110670, 24557795, -8937330, 49115590, -8937330, 11191525], [158826689138, -24378535, 3651994, -48757070, 3651994, 9770559], [-88281482462, -8473608, 3734892, -16947216, 3734892, -6465960], [0, -16417874, -25902930, -8593380, -1432230, 0], [0, 101045624, 277151675, 75538590, 12589765, 0], [0, -320318593, 368194896, 31842720, 5307120, 0], [0, 254806792, -413727706, 20492634, 3415439, 0], [0, 99672225, -450097599, 80388306, 13398051, 0], [226851589758, -23185065, 5501439, -46370130, 5501439, 1179309], [0, -584081016, -58196625, 88917120, 14819520, 0], [-399050395362, -20317446, 2538090, -40634892, 2538090, 10165086], [128913234194, -68456184, 16306431, -136912368, 16306431, 3230460], [61786243086, 12170559, 1944, 24341118, 1944, -12178335], [0, 166881451, -666516540, -73102920, -12183820, 0], [0, -139447288, -366377880, -32754420, -5459070, 0], [0, -42531599, 173788773, -146995062, -24499177, 0], [0, 316082462, -227281632, 102295008, 17049168, 0], [0, 12502288, -393162225, 6421800, 1070300, 0], [-338776236562, -29335058, 8951667, -58670116, 8951667, -6471610], [-421697500318, 84953418, -20392242, 169906836, -20392242, -3384450], [0, 541865556, 344029920, -36998640, -6166440, 0], [378315566386, 50436759, -12027066, 100873518, -12027066, -2328495], [0, -337304848, -140111292, -37254852, -6209142, 0], [226500811570, 33188325, -1924080, 66376650, -1924080, -25492005], [-354506043506, 80723159, -16662906, 161446318, -16662906, -14071535], [-410179534062, -14401460, 2804867, -28802920, 2804867, 3181992], [0, -254415832, 1068704505, -131481990, -21913665, 0], [0, 1651891214, -345900159, 59442090, 9907015, 0], [0, 347837101, -886586325, -166540410, -27756735, 0], [-221967624370, -6540515, -10623690, -13081030, -10623690, 49035275], [127067092926, 114531744, -26751816, 229063488, -26751816, -7524480], [912528226930, -26147435, 2239610, -52294870, 2239610, 17188995], [0, -96065000, 292516650, -254277270, -42379545, 0], [636805173566, 66998884, -17124696, 133997768, -17124696, 1499900], [0, -2085525944, 195492840, -127728828, -21288138, 0], [-286124925614, 112082406, -20173779, 224164812, -20173779, -31387290], [0, -748514319, -39295774, -263026620, -43837770, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_252_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_252_9_d_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_252_9_d_b(:prec:=6)
    chi := MakeCharacter_252_d();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 9));
    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_252_9_d_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_252_9_d_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_252_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,9,sign)));
    Vf := Kernel([<5,R![48680661813120000, 0, 593123565600, 0, 1511232, 0, 1]>],Snew);
    return Vf;
end function;