
// Make newform 252.4.b.f in Magma, downloaded from the LMFDB on 24 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_f();".
// 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_f();".
// 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 := [262144, -32768, -8192, -3072, 0, 448, -448, 56, 0, -6, -2, -1, 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, 0, 0], [0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [32768, 8192, 3072, 0, -448, 448, -56, 0, 6, 2, 1, -1], [98304, 32768, 3072, -3584, 3136, 0, -56, 48, 22, 10, -7, -1], [294912, 49152, -19456, 25088, -1344, 896, 216, 176, 98, -50, -5, -3], [-1310720, -925696, 138240, -15360, 33600, 3136, 360, 1568, -610, 26, 69, 11], [-3440640, -770048, -158720, -17920, -6464, -12928, 2264, -80, 34, 142, 91, 29], [-3244032, -507904, -136192, 5632, 10304, -6272, 3784, -688, 182, 122, 41, 31], [-4685824, -901120, -171008, -33280, -17216, -10496, 5336, 464, 98, 158, 91, 45], [-5046272, -1712128, -224256, 52224, -19008, -12608, 1080, 1760, 26, 206, 111, 65], [-3031040, -823296, -109568, -18688, -5696, -9312, 1304, 456, 186, 66, 79, 37], [-5128192, -1130496, -375808, -23552, -6592, -10560, 4648, 384, 318, 138, 101, 59]];
    Rf_basisdens := [1, 1, 32768, 32768, 32768, 98304, 98304, 98304, 98304, 98304, 49152, 49152];
    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, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 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, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 0, 0], [1, 0, -1, 0, 0, 0, -1, 0, 0, 0, 0, 0], [0, 1, -2, 0, 0, 0, 0, 0, 0, 0, -1, -1], [-1, 1, -3, 1, 1, 0, 1, 0, -1, -1, 0, 0], [0, 1, -2, 2, -2, 0, 1, 1, 0, 2, -1, 1], [-7, 1, 3, -1, 1, -2, 0, 1, -1, 1, 0, 0], [-3, -3, 8, 7, -1, 0, 2, -1, 2, 1, -2, 2], [-21, 1, 1, 11, 5, 2, 3, 0, 3, 1, 2, -4], [-37, -3, -3, 13, -5, -2, -1, -2, 3, -1, 4, -2], [-25, 3, 19, 5, -5, -2, -4, 1, 1, -1, 2, 0], [10, 9, -26, -20, 0, 0, -3, 7, 4, 0, 5, -5], [-2, 4, 8, 0, 4, 0, 5, 3, -12, -4, -2, -4], [-18, -12, -36, 2, -10, -4, -6, 0, 0, -2, 2, 2], [-9, 7, 35, 11, -3, -6, -1, 0, 1, 1, 4, -2], [-90, -8, -48, -6, 14, -4, 16, -6, -4, 6, -2, -2], [-1, 21, -57, 5, -3, 0, 9, 8, -23, 3, 4, 8], [-2, -22, 72, -4, 8, 0, -1, -3, 16, -8, 0, -6], [-3, 17, -22, -1, 7, 0, 10, 7, -32, -7, 2, -2], [22, 4, -42, -42, -2, 0, -20, 2, 6, 2, 22, 2], [-26, 6, -66, 34, 18, 0, 9, -17, 8, -18, -4, 4], [42, 20, 96, 70, 2, -4, -10, 12, 16, 2, 18, -18], [10, -43, 232, -28, 8, 0, 5, 15, -30, -8, 9, -9], [-26, -36, 114, 58, -6, 0, 0, -26, -34, 6, -10, 22], [-28, -30, -23, 56, 0, 0, -6, -34, 27, 0, 10, 38], [113, 55, 243, -29, -27, -6, -3, -14, -7, -7, -4, 14], [-28, 1, -32, 32, 24, 0, 12, -16, -14, -24, 3, 7], [-178, -12, -20, 20, -20, -8, -34, 22, 4, -4, 8, 0], [150, 26, 98, -24, 0, 0, -36, 36, -6, 0, -6, 6], [18, 46, -222, -22, -14, 0, 1, 19, 64, 14, 8, 4], [540, -78, -330, -44, 4, 16, -24, 24, -6, -4, -14, 10], [-234, -40, -140, 120, 8, 8, -38, 42, 32, 0, 28, -32], [-280, -72, -300, 16, 16, -8, 8, 4, 0, 8, 4, -8], [-417, 39, 139, -121, -15, 18, 53, -66, -23, -11, -32, 34], [44, 20, -14, -96, 8, 0, -29, 15, -48, -8, 32, -20], [-5, 53, -153, 17, -7, 0, 41, 36, 49, 7, -24, -12], [-6, -50, 120, -4, 16, 0, -29, -35, -44, -16, 32, 22], [-198, 98, 378, -22, 6, 12, 20, -18, -2, -2, -8, 4], [6, -108, 451, 6, -18, 0, -36, -30, -7, 18, -42, -30], [70, -69, 500, -142, 2, 0, 2, 72, -86, -2, 39, -33], [19, -127, 537, -43, 5, 0, 29, 48, 67, -5, 12, -12], [-71, 27, -194, 155, -13, 0, -16, -87, -68, 13, -52, 32], [761, -47, -173, 165, 19, 34, 54, -47, 51, -5, 34, -46], [-75, 15, 55, 109, 35, -34, 83, -54, 13, 23, 30, -36], [-268, 54, 210, -78, -18, 36, 17, -35, -6, -18, -24, 24], [42, 148, -272, -40, -44, 0, -15, 27, -176, 44, -46, -44], [158, -60, -228, 104, 8, 32, -43, 43, 36, -8, 20, -28], [-150, 26, 90, 50, 30, -36, -118, 144, -2, 22, 16, -20], [15, 153, -411, 45, -75, 0, 93, 108, 51, 75, -48, 12], [828, -12, -64, -126, -10, -28, 16, -18, -40, 6, -26, 34], [83, 19, -86, -127, -39, 0, -144, -61, -152, 39, 42, -2], [-104, -46, 12, 200, 8, 0, -46, -150, -92, -8, -66, 30], [-240, 84, 264, -316, -4, -16, -6, 6, -84, 4, -76, 80], [-94, -133, 340, 144, 44, 0, 119, 25, 170, -44, 11, 61], [181, -13, -4, -321, -41, 0, -128, 53, 174, 41, 64, -76], [102, 94, -23, -238, 34, 0, -38, 64, -81, -34, -4, -140], [581, 95, 291, 159, 121, -14, 49, 34, 25, 45, 32, -70], [-949, -173, -681, 25, -9, 30, -122, 111, 17, -13, 2, -4], [-54, 150, 614, -4, -20, 40, -44, 24, 14, -20, -6, 6], [-619, 45, 255, -297, -135, -18, -94, 7, -69, -39, -60, 108], [-70, -54, 13, 182, -42, 0, -78, -148, 27, 42, -116, -4], [1655, 31, 189, 117, -37, 26, -114, 85, 41, -21, 28, -20], [906, 68, 300, -54, -50, 76, -52, 6, 16, -42, -22, 26], [-12, -152, 180, -28, 52, 0, -20, -32, 172, -52, 116, 76], [-963, 9, -19, -295, -17, -2, 7, -18, -73, -5, -72, 78], [-58, 236, -736, 120, -4, 0, 213, 155, -132, 4, 86, 148], [-460, 254, 1102, 250, -26, 28, 88, -110, 74, -18, 60, -56], [158, -67, 266, -302, -14, 0, -44, 114, 140, 14, 117, -27], [85, 11, -15, -217, 47, 0, -157, -72, -89, -47, 24, -108], [2, -139, 772, 12, -16, 0, 41, 43, -274, 16, 65, 79], [-161, 81, -278, 221, 101, 0, 50, -111, -104, -101, -112, -52], [2204, -90, -462, 142, 130, -20, 119, -29, 18, 50, 28, -68], [2306, 208, 632, 36, 204, -72, 8, 140, -32, 92, 4, -60], [-110, 488, -1604, 116, 104, 0, 169, 59, -248, -104, 6, 12], [-1872, 278, 822, -16, 264, 0, 224, -48, -26, 88, -26, -62], [3339, -19, -211, 87, 153, -54, 45, 66, -9, 69, 18, -60], [-11, -253, 1041, 35, -13, 0, -133, -144, -389, 13, 24, 48], [2694, 120, 124, -360, 232, 88, 74, 66, -80, 48, -124, 32], [206, 144, 750, -382, -30, 0, 72, 278, -614, 30, 10, -166], [-3024, -166, -534, 344, -48, 48, -286, 246, 106, -32, 82, -74], [-2377, 415, 1871, -143, -209, -122, -118, -1, -59, -29, 2, 88], [-21, -215, 376, -111, 153, 0, -174, -195, 282, -153, -28, -160], [-134, 298, -942, 318, -50, 0, 118, -16, -426, 50, -20, 164], [5060, -442, -1662, -230, -154, 20, 85, -191, -38, -58, -48, 96], [-6, 67, 74, -78, 90, 0, 114, 108, -240, -90, 99, 15], [-1416, 88, 488, 702, 58, -140, 38, 24, 124, 66, 194, -190], [-3112, 250, 754, 142, 242, 116, -204, 346, 54, 42, -4, -96], [272, -372, 1693, -496, -48, 0, 48, 320, 267, 48, 196, -28], [-274, 426, -1914, 422, 126, 0, 69, -205, -140, -126, -104, 44], [4608, 292, 1416, 236, -140, -224, -278, 222, -4, 28, 108, -24], [-5928, 18, 42, 4, 52, -152, 354, -294, -54, 68, 22, -14], [-300, -292, 518, 676, -76, 0, 147, -153, 464, 76, -248, 128], [-2, 157, -920, 190, -186, 0, 96, 94, 362, 186, -35, 153], [-110, -268, 1252, 308, -88, 0, 193, 83, -56, 88, -78, 120], [3426, -524, -1716, 654, -166, -220, 82, -156, 104, 18, 214, -122], [-16, 638, -1475, -84, 116, 0, 338, 322, -145, -116, -94, -194], [100, 339, -1610, -134, -66, 0, -369, -269, -332, 66, 41, 7], [-3646, -514, -1974, -418, -174, 12, -98, -20, -86, -62, -92, 148], [83, -49, -177, 37, 11, -130, 386, -357, -35, 47, 30, -12], [178, 690, -2568, -356, 0, 0, -105, 73, 380, 0, -124, -302], [4251, -465, -1973, 227, 165, -54, -163, 282, 25, 73, 52, -98], [450, 200, 252, -106, 450, 204, 14, 252, 4, 82, -98, -86], [4602, 430, 2162, 372, -332, 64, 50, -282, 142, -132, 110, -10], [170, -102, 1524, -388, 48, 0, -93, 77, -896, -48, 76, -142], [150, -330, 1386, -294, -6, 0, -198, -48, -282, 6, 132, -12], [-6054, -286, -1386, 194, 270, -12, -196, 378, 22, 94, 28, -116], [80, 499, -1724, -194, 34, 0, 55, 135, -362, -34, 237, 123], [-419, -543, 1390, 1007, -169, 0, -118, -537, -596, 169, -142, 446], [-330, 206, 318, 310, 350, 0, 446, 116, -610, -350, -140, -160], [6650, -236, -1260, -204, 236, 56, 201, -53, -52, 60, -80, -8], [-1240, -210, -714, -1158, -378, -36, -156, -90, -270, -114, -252, 384], [1260, 350, 1274, -886, -106, 116, 492, -582, -174, -74, -232, 248], [-7144, -160, -540, 952, 104, 152, 112, -68, 280, -16, 204, -264], [434, 610, -2454, -590, -278, 0, -263, 171, -136, 278, 324, 168], [-4332, -2, -826, -1102, 462, 252, 278, -12, -230, 70, -356, 160], [4259, 31, -219, 965, 523, 106, 252, 79, 233, 139, 180, -372], [-366, 82, -54, -170, 330, -108, 526, -288, -106, 146, -52, -40], [4305, -35, -167, -175, -25, 62, -555, 528, -21, -29, -52, 50], [280, 169, 1208, -500, -60, 0, 72, 352, -814, 60, -73, -293], [-429, -151, -297, 601, 257, 0, 185, -244, 857, -257, -308, -136], [353, 517, 1519, -683, 371, -142, 390, -119, -249, 171, -178, 78], [-30, -152, 553, -70, 130, 0, -176, -206, -141, -130, -58, -158], [-606, -53, -794, 978, 234, 0, 570, -36, 876, -234, -157, 215], [-12034, 222, 498, 274, 430, -44, -406, 700, 18, 158, 40, -176], [-4479, 801, 2989, -595, 75, -90, -493, 558, -185, 55, -140, 130], [5432, -62, 322, 678, -422, 340, -306, -32, 318, -254, 148, -64], [-12624, -230, -654, 316, -132, -264, 346, -390, 2, 44, 134, -46], [-4189, 449, 2205, -183, -449, 190, -557, 226, 55, -213, -40, 158], [-217, -459, 669, 149, 285, 0, -411, -628, -749, -285, 364, 296], [-406, -782, 2820, 1024, -212, 0, 367, -39, 68, 212, -228, 390], [149, 607, -3386, -193, -105, 0, -216, -67, 460, 105, 204, 160], [220, 320, -2890, -388, -52, 0, -453, -233, 664, 52, 324, 156], [-1804, 362, 1090, 794, 470, 284, -98, 364, 254, 62, 112, -316], [-476, -751, 910, 1190, -238, 0, -115, -591, 1008, 238, -405, 309], [596, -860, 1356, -800, -392, 0, -764, -168, 1376, 392, 288, 84], [408, -234, -233, -1140, 324, 0, -582, -174, 365, -324, 594, -138], [6878, 286, 534, -1330, 226, 196, -366, 484, -286, 10, -384, 276], [-874, -32, -131, 1534, 214, 0, 820, -54, 367, -214, -438, 222], [-5946, -38, -482, -608, 232, -440, 834, -606, -318, 224, -98, 94], [11642, -174, -378, 854, -118, 140, -502, 400, 270, -86, 200, -184], [-6261, -53, 631, 639, -663, 210, -81, -396, 285, -291, 180, 6], [-6, -334, -594, -170, 182, 0, -55, -61, 1880, -182, 52, -124], [-378, 363, -568, 562, 194, 0, 446, 68, -1138, -194, 103, 287], [-23, 427, -2841, 435, -389, 0, -209, -232, 1113, 389, -428, -16], [4020, 840, 3240, -1512, -216, -144, 78, -198, -408, -24, -336, 432], [569, -1, 3585, -885, -253, 0, 419, 988, -1065, 253, -112, -428], [-456, 421, -518, 362, 550, 0, 313, -143, -1140, -550, -109, -203], [-17167, 473, 1923, 711, 121, 94, 328, -263, 199, 9, 152, -208], [209, -825, 3038, -1077, 659, 0, -580, -371, -588, -659, 488, -380], [-9088, 522, 2234, -542, -274, 92, 28, -226, -82, -122, -128, 204], [160, 637, -1256, 66, -386, 0, 241, 401, -562, 386, -77, 149], [450, 400, -88, -1072, 172, 0, 437, 887, 712, -172, 86, -536], [-25218, -938, -3690, 1086, 146, 308, 136, -90, 362, -54, 208, -308], [-414, -88, 2216, 868, -40, 0, 201, -213, -1732, 40, -506, -52], [-367, 47, -2068, 1267, -533, 0, 208, -159, 1670, 533, -504, 396], [-28, -1044, 3986, 8, 48, 0, -173, -201, -656, -48, 232, 212], [122, -443, 2266, -68, -176, 0, 709, 831, 904, 176, 105, 159], [408, -408, 3276, -1164, 348, 0, 12, 420, -960, -348, 456, -300], [798, -532, 2797, -1250, -346, 0, -424, 374, 775, 346, -122, -574], [250, 247, -596, -818, 318, 0, -210, 40, 146, -318, 55, -513], [1194, 964, 3592, 36, 252, 0, -318, 486, -12, 84, -12, -72], [-674, 174, 642, 970, 378, 0, 717, 43, -1348, -378, -100, 196], [19314, -1602, -6162, -654, -402, 156, 690, -984, -78, -186, -156, 264], [-4728, -248, 296, -2, -1222, 212, -706, -144, 172, -478, 66, 306], [5010, -258, -690, -1134, -594, 108, -528, 114, -198, -234, -252, 432], [-320, 284, -1118, 308, 332, 0, -377, -697, -1664, -332, 132, 120], [717, 331, -1719, -1681, 247, 0, 151, 868, 1879, -247, 608, -356]];
    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_f();".
// 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_f(:prec:=12)
    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_f();".
// 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_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_252_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![224760987648, 0, 30453516288, 0, 1456436096, 0, 29440120, 0, 249644, 0, 858, 0, 1]>,<11,R![584217371305280000, 0, 12525766859191168, 0, 45887475687456, 0, 64285126792, 0, 39015876, 0, 10414, 0, 1]>,<19,R![111463534080, 8618904192, 99824480, -1835880, -27084, 42, 1]>],Snew);
    return Vf;
end function;