
// Make newform 252.4.b.d in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_252_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_252_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_252_4_b_d();".
// 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_4_b_d();".
// 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 := [8978, 1072, -3172, -464, 493, 84, -30, -4, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [26653239984, 31061346042, -7812762598, -1820971716, 856630098, 12013496, -28020178, 2107780], [-38413062497, -7541701016, 7812762598, 1820971716, -856630098, -12013496, 28020178, -2107780], [-204544903, 78029576, 48793686, -9022980, -3328540, 648572, 27552, -5280], [158760439399, -34928966104, -33992527302, 10555104876, 4456400722, -946363840, -178195062, 37410820], [-65434616690, 42141065120, 32020502452, -14881408792, -6385173864, 1067149048, 411792664, -71287048], [390648894103, -191858039266, -121788747936, 29088392180, 14797753670, -2515029448, -485124166, 85892144], [-15131816, -1479810, 4834142, 374248, -509450, -17704, 28790, -2876]];
    Rf_basisdens := [1, 11759822513, 11759822513, 7201361, 11759822513, 11759822513, 11759822513, 379019];
    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_b();"
function MakeCharacter_252_b()
    N := 252;
    order := 2;
    char_gens := [127, 29, 73];
    v := [1, 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_b_Hecke();"
function MakeCharacter_252_b_Hecke(Kf)
    N := 252;
    order := 2;
    char_gens := [127, 29, 73];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 0], [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+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 := [[1, 0, -1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 3, 0, 1, 0, 1, 0], [0, 0, 3, 0, 1, -5, 0, 0], [0, -2, 0, 4, 0, 1, 2, 1], [0, -2, 0, 4, 0, 1, 2, 0], [0, 1, 0, 0, 0, 1, -2, 0], [0, 0, -21, 0, -7, -19, 0, 0], [74, 0, 18, 0, -18, 0, 0, 0], [0, 6, 0, 0, 0, -3, 6, 0], [174, 0, 14, 0, -14, 0, 0, 0], [0, -4, 0, 8, 0, 2, 4, 10], [0, 0, 3, 0, 1, 25, 0, 0], [0, 6, 0, 0, 0, 7, -14, 0], [146, 0, -76, 0, 76, 0, 0, 0], [0, 29, 0, 0, 0, -15, 30, 0], [0, 8, 0, -16, 0, -4, -8, -39], [0, 0, -141, 0, -47, -11, 0, 0], [0, 0, 126, 0, 42, 7, 0, 0], [0, -6, 0, 12, 0, 3, 6, 10], [0, 0, 24, 0, 8, -159, 0, 0], [0, -119, 0, 0, 0, -10, 20, 0], [0, -2, 0, 4, 0, 1, 2, -70], [0, -26, 0, 52, 0, 13, 26, -60], [0, -26, 0, 52, 0, 13, 26, 37], [0, -62, 0, 0, 0, -18, 36, 0], [0, 0, -63, 0, -21, 79, 0, 0], [630, 0, -88, 0, 88, 0, 0, 0], [-154, 0, -29, 0, 29, 0, 0, 0], [0, 0, 93, 0, 31, 215, 0, 0], [0, -99, 0, 0, 0, 26, -52, 0], [-250, 0, -88, 0, 88, 0, 0, 0], [0, 315, 0, 0, 0, 9, -18, 0], [1522, 0, -120, 0, 120, 0, 0, 0], [0, 0, 717, 0, 239, -253, 0, 0], [0, -10, 0, 20, 0, 5, 10, 29], [0, 0, -843, 0, -281, 113, 0, 0], [0, 322, 0, 0, 0, 16, -32, 0], [0, -66, 0, 132, 0, 33, 66, 31], [0, 0, -369, 0, -123, -529, 0, 0], [0, 44, 0, -88, 0, -22, -44, 59], [0, 0, -36, 0, -12, -81, 0, 0], [-1014, 0, -519, 0, 519, 0, 0, 0], [-2158, 0, -98, 0, 98, 0, 0, 0], [0, 426, 0, 0, 0, 14, -28, 0], [0, 0, -1161, 0, -387, -267, 0, 0], [0, -336, 0, 0, 0, 124, -248, 0], [0, 463, 0, 0, 0, 97, -194, 0], [0, 18, 0, -36, 0, -9, -18, 267], [-1242, 0, 688, 0, -688, 0, 0, 0], [0, 0, -1017, 0, -339, -215, 0, 0], [0, 98, 0, -196, 0, -49, -98, 104], [0, -273, 0, 0, 0, -92, 184, 0], [0, -12, 0, 24, 0, 6, 12, 296], [0, 0, 1290, 0, 430, -305, 0, 0], [0, -86, 0, 172, 0, 43, 86, -273], [0, 344, 0, 0, 0, 98, -196, 0], [2462, 0, -626, 0, 626, 0, 0, 0], [694, 0, -208, 0, 208, 0, 0, 0], [0, 489, 0, 0, 0, 44, -88, 0], [0, 142, 0, -284, 0, -71, -142, -155], [0, -329, 0, 0, 0, -34, 68, 0], [0, -356, 0, 0, 0, 225, -450, 0], [0, 104, 0, -208, 0, -52, -104, -278], [490, 0, 662, 0, -662, 0, 0, 0], [0, 0, 1929, 0, 643, 1149, 0, 0], [-1350, 0, 1453, 0, -1453, 0, 0, 0], [0, 0, 717, 0, 239, -1265, 0, 0], [0, 188, 0, -376, 0, -94, -188, -583], [0, 336, 0, -672, 0, -168, -336, -328], [0, 0, 963, 0, 321, 789, 0, 0], [0, -1296, 0, 0, 0, 42, -84, 0], [-3106, 0, 618, 0, -618, 0, 0, 0], [0, 0, -2007, 0, -669, -2347, 0, 0], [0, -1058, 0, 0, 0, 181, -362, 0], [-4270, 0, -1466, 0, 1466, 0, 0, 0], [0, -160, 0, 320, 0, 80, 160, 101], [-4698, 0, -13, 0, 13, 0, 0, 0], [0, -52, 0, 104, 0, 26, 52, -6], [0, 1141, 0, 0, 0, -62, 124, 0], [-1122, 0, 772, 0, -772, 0, 0, 0], [0, 0, 1875, 0, 625, 1105, 0, 0], [0, -18, 0, 36, 0, 9, 18, -560], [0, -496, 0, 0, 0, -15, 30, 0], [0, 0, -1941, 0, -647, 291, 0, 0], [1150, 0, 2476, 0, -2476, 0, 0, 0], [9202, 0, 1303, 0, -1303, 0, 0, 0], [0, 124, 0, -248, 0, -62, -124, 67], [0, 0, -3552, 0, -1184, 129, 0, 0], [0, -337, 0, 0, 0, -353, 706, 0], [0, 2178, 0, 0, 0, 215, -430, 0], [0, 0, 4437, 0, 1479, -837, 0, 0], [0, 0, -3639, 0, -1213, -1457, 0, 0], [0, 0, -4707, 0, -1569, -55, 0, 0], [0, -1624, 0, 0, 0, 75, -150, 0], [0, 228, 0, -456, 0, -114, -228, 815], [0, -508, 0, 1016, 0, 254, 508, 370], [0, -1693, 0, 0, 0, -155, 310, 0], [-9914, 0, -1508, 0, 1508, 0, 0, 0], [0, 0, -5187, 0, -1729, 1281, 0, 0], [-1526, 0, 4176, 0, -4176, 0, 0, 0], [0, 1303, 0, 0, 0, -473, 946, 0], [-4610, 0, -1247, 0, 1247, 0, 0, 0], [0, 0, 3279, 0, 1093, -183, 0, 0], [0, 12, 0, -24, 0, -6, -12, 1608], [0, -287, 0, 0, 0, 121, -242, 0], [0, 80, 0, -160, 0, -40, -80, -1212], [0, 0, -1134, 0, -378, -3033, 0, 0], [0, 598, 0, -1196, 0, -299, -598, 14], [0, 2416, 0, 0, 0, 332, -664, 0], [14942, 0, -804, 0, 804, 0, 0, 0], [-2034, 0, -2575, 0, 2575, 0, 0, 0], [0, 2057, 0, 0, 0, -366, 732, 0], [0, 0, -1614, 0, -538, -31, 0, 0], [6134, 0, 647, 0, -647, 0, 0, 0], [0, -35, 0, 0, 0, -563, 1126, 0], [0, -2554, 0, 0, 0, -334, 668, 0], [-16918, 0, -1428, 0, 1428, 0, 0, 0], [0, 0, -5403, 0, -1801, 2211, 0, 0], [0, 358, 0, -716, 0, -179, -358, -1033], [-7358, 0, -380, 0, 380, 0, 0, 0], [0, 436, 0, -872, 0, -218, -436, 177], [0, 0, 4053, 0, 1351, 2791, 0, 0], [0, 855, 0, 0, 0, 558, -1116, 0], [4954, 0, 588, 0, -588, 0, 0, 0], [-11682, 0, 2820, 0, -2820, 0, 0, 0], [0, -1786, 0, 0, 0, 395, -790, 0], [0, -322, 0, 0, 0, 602, -1204, 0], [0, 428, 0, -856, 0, -214, -428, 1305], [0, 0, -3135, 0, -1045, 2969, 0, 0], [0, 0, 2907, 0, 969, 2917, 0, 0], [0, 0, 2841, 0, 947, -1737, 0, 0], [-11762, 0, 212, 0, -212, 0, 0, 0], [0, 412, 0, -824, 0, -206, -412, -178], [0, -206, 0, 412, 0, 103, 206, 1684], [0, -144, 0, 288, 0, 72, 144, -1247], [0, -3599, 0, 0, 0, 505, -1010, 0], [0, 158, 0, -316, 0, -79, -158, -21], [7086, 0, -767, 0, 767, 0, 0, 0], [0, 3717, 0, 0, 0, 388, -776, 0], [-1406, 0, 434, 0, -434, 0, 0, 0], [0, 0, 582, 0, 194, 841, 0, 0], [0, 0, 51, 0, 17, 131, 0, 0], [0, 96, 0, -192, 0, -48, -96, -1367], [0, 4494, 0, 0, 0, -42, 84, 0], [0, -426, 0, 852, 0, 213, 426, -1849], [0, -464, 0, 928, 0, 232, 464, 1134], [0, -2407, 0, 0, 0, -388, 776, 0], [0, 0, -564, 0, -188, -1, 0, 0], [22726, 0, -3674, 0, 3674, 0, 0, 0], [0, 648, 0, -1296, 0, -324, -648, -1764], [0, 0, 1203, 0, 401, 925, 0, 0], [0, 2834, 0, 0, 0, -174, 348, 0], [0, 0, -2475, 0, -825, -4635, 0, 0], [0, 0, 10455, 0, 3485, -2279, 0, 0], [0, 0, -8742, 0, -2914, -3055, 0, 0], [0, -1138, 0, 2276, 0, 569, 1138, 1812], [0, 582, 0, -1164, 0, -291, -582, 426], [0, 986, 0, -1972, 0, -493, -986, -745], [0, 0, -11487, 0, -3829, -2693, 0, 0], [39574, 0, 1688, 0, -1688, 0, 0, 0], [0, 0, 4317, 0, 1439, 4251, 0, 0], [0, 1161, 0, 0, 0, -747, 1494, 0], [-1362, 0, 5760, 0, -5760, 0, 0, 0], [0, -3366, 0, 0, 0, -198, 396, 0], [0, 0, -1332, 0, -444, 7361, 0, 0], [0, -292, 0, 584, 0, 146, 292, -161]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_252_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_252_4_b_d();".
// 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_4_b_d(:prec:=8)
    chi := MakeCharacter_252_b();
    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_252_4_b_d();".
// 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_4_b_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_252_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![22304, 0, 368, 0, 1]>,<11,R![272, 0, 1720, 0, 1]>,<19,R![694048, 0, -2128, 0, 1]>],Snew);
    return Vf;
end function;