
// Make newform 1232.4.a.s in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1232_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_1232_4_a_s();".
// 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_1232_4_a_s();".
// 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 := [1, 5, -12, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 2, 0, 0], [-3, -12, 0, 1], [-7, 24, 2, -2]];
    Rf_basisdens := [1, 1, 1, 1];
    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_1232_a();"
function MakeCharacter_1232_a()
    N := 1232;
    order := 1;
    char_gens := [463, 309, 353, 673];
    v := [1, 1, 1, 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;

function MakeCharacter_1232_a_Hecke(Kf)
    return MakeCharacter_1232_a();
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], [-4, 0, -1, 0], [4, -1, 2, 0], [7, 0, 0, 0], [11, 0, 0, 0], [18, -10, -3, 0], [-6, 11, -5, -2], [-66, 11, 4, -4], [-14, 4, -18, 2], [-88, -2, 14, -6], [6, 9, 9, 16], [29, -9, -16, -23], [-10, 37, -23, -14], [-103, 37, -2, -37], [18, 7, 39, -8], [147, 3, -8, 7], [46, -50, -3, 74], [-86, 72, 29, 48], [-242, -122, 62, -2], [-386, -94, 26, -2], [310, 139, -47, -78], [277, 43, 6, 71], [-96, 9, 76, 34], [-740, -30, -48, -74], [-102, -72, 154, 104], [54, -36, 201, 136], [-724, 11, 9, -82], [44, -62, 36, -164], [-938, 70, -94, -104], [-46, -134, 124, 32], [-6, 86, -156, -78], [-962, 149, 18, -256], [-939, -5, -36, 69], [-222, -259, 72, 44], [-1686, 202, -240, 60], [-589, -295, 294, 173], [-8, 81, -210, -208], [-1684, 296, -130, 192], [2314, 92, -176, -126], [-1406, -64, -357, 320], [-884, -12, 80, 144], [-2078, 109, 68, 202], [-2118, 268, 336, 22], [-896, -630, 168, 78], [-546, -272, -80, 260], [-1060, 371, -79, 326], [-292, 242, 356, 44], [-272, -7, -211, 278], [-2450, 29, -350, 216], [230, 357, -40, -50], [-706, -50, -390, -200], [1114, 58, -408, -462], [2454, -211, 241, -230], [-810, -326, 231, 114], [1928, -650, 20, 482], [-60, 280, -432, 124], [542, -83, -72, 78], [-2600, 98, -62, -100], [-3984, 112, -432, 382], [52, 380, -406, 322], [-1802, -687, 414, 296], [4050, 208, 21, -328], [-2954, 313, -190, -920], [-1344, -131, 261, -682], [1434, -390, -100, -732], [2922, 624, -448, 292], [-914, 638, 296, 182], [406, 830, 830, -820], [-1481, 471, -466, -179], [-66, -1118, 17, -152], [2304, 578, -784, -30], [-1291, 315, -46, 83], [2194, -487, 1107, 12], [3412, -22, 612, -50], [-1282, -318, -322, -610], [2520, 1385, -981, 150], [-2322, -974, 44, -1028], [3316, 129, -898, -700], [1022, -514, 1024, 1364], [1070, -111, 413, 262], [-7548, -840, -369, 152], [-6115, -339, 640, -355], [2255, -931, -1190, -287], [4930, -72, -1382, -80], [34, -1424, 406, -1246], [5090, 1618, 440, -734], [3841, -1121, -1688, -127], [-2078, 1344, -1940, -1132], [502, -2212, 1539, -472], [1112, -1160, 258, 1484], [-4696, -1456, -1051, 1292], [1114, -1038, 726, -234], [2200, -286, 250, -340], [3751, 1589, 46, -431], [4504, -600, -1522, -28], [8220, -978, 1110, -416], [-2346, 345, -2232, -762], [5098, 1184, -762, -496], [-5760, -1533, -1262, 1038], [-8638, 16, -680, 1144], [-14164, -756, -184, -96], [1032, 2106, -580, 1306], [-8454, 1725, -804, -188], [-5478, -2894, 442, -192], [-10884, 1700, -156, 1176], [3838, 354, -1266, 472], [14328, -774, 501, 64], [-1954, 89, 583, -742], [-18580, -120, -570, 144], [15178, 483, 269, 1282], [3210, -422, -600, -962], [60, 610, 454, -722], [2795, 187, 184, -913], [2272, -1780, -503, 1748], [-3236, 2274, 288, -2092], [185, 1293, 1964, 1465], [-9914, 1230, 1235, 1538], [11150, 1041, -1411, -168], [-196, 1280, -408, -418], [9019, 567, 194, 1201], [7302, 345, 1466, 1678], [-7628, 1520, -2230, 74], [4974, -1446, 153, -420], [-19940, 1816, 124, -864], [3432, -438, 1027, 504], [8702, 522, -2158, -1864], [-8112, -2964, 1568, 1194], [14356, -2163, 1239, 106], [-6646, 1821, 849, -2308], [5362, 2136, 861, -656], [-1772, -2740, -924, 184], [1726, -1882, -2064, 1542], [-1348, 2778, -2538, -1344], [8144, -736, 972, -2942], [5518, -3511, 1921, -1050], [-18794, 287, -2013, -2706], [-440, 1485, -260, 1304], [-8900, 2221, -2028, -2042], [16044, -275, -1710, -1932], [-9140, 3158, 2312, -2318], [14916, -2657, 2982, 2658], [-9950, -3418, 1632, 100], [-7160, -5482, 2500, -840], [-9791, -3233, 1614, -313], [3676, -373, 2986, 1136], [-5636, 4029, -409, -3374], [-9370, 4202, 2221, 1100], [-3754, 513, -1259, 2374], [-3486, 2066, 307, -1090], [-5382, 3892, -3348, -658], [-20492, 3980, 318, -1414], [-7110, 1690, -270, 2964], [-7540, 3352, -3916, -1184], [5714, -3634, -1490, -3378], [-17546, 2818, -2222, 406], [12778, -3352, -774, 26], [-6156, 1716, 2696, 3276], [17008, -3422, -1554, 2226], [4274, -4003, 3035, 1590], [-2174, 1504, 865, 232], [-20840, 200, 4016, 2620], [11372, -2726, 660, 894], [12693, 179, -2178, -2245], [25220, -3528, 1057, -2176], [23260, -374, 436, 190], [30590, 4575, -1325, -2244], [15870, -1030, 2694, -2122], [2054, -3962, -921, -2152], [-18058, 6148, -2284, 2992], [-13272, 7515, 1192, 2068], [7860, -1154, 8748, 3148], [5462, 3035, 2786, 3490], [11157, -1473, 854, -1697], [-3780, -2888, -526, 1946], [560, 2723, 1613, 4210], [23684, -2428, 3618, 5482], [28445, -237, 4798, 395], [-18999, 3291, 2512, -3883], [-18290, 2268, -2326, 4358], [6982, -2212, -3503, 2456], [17264, -6092, -896, 4552], [1954, -779, 792, -2020], [-14480, 320, -3364, -4694], [-10170, -5793, 1049, -4378], [-16158, -462, 4052, 2798], [7970, -4639, 3424, 4162], [39668, -2438, 5332, 1166], [-11382, -5800, -873, 3058], [-15382, 686, -1446, 1828], [4556, -1518, -4312, -2064], [1908, 9160, 1778, -4534], [-5096, 3334, 4436, 2616], [3378, -5386, 594, 2218], [28526, -1117, 1314, -4350], [-6769, 2689, -4234, -3231], [-15172, -158, -2568, 6622], [-30100, -2888, 3718, 222], [-2671, -2917, -5488, 2245], [6082, -3103, -353, -5850], [-27080, 3710, 574, 812], [16486, -2078, 6412, 6928], [-24156, 2282, -5712, 88], [-10048, -443, -1944, 760], [13670, 567, -251, 434], [21794, -9088, -2801, -4830], [33598, -4399, 1946, 3270], [37518, -2549, 115, -2748], [23056, 740, 5164, -6468], [25824, -8306, 4992, -6226], [-15782, 4456, 289, -1630], [502, -5414, -1378, 8084], [-4900, 8681, -4560, -4572], [-4862, 3510, 68, -6738], [38266, -2838, -1051, 5470], [19236, 6554, 2486, 600], [-1034, -9782, 1484, 1368], [4599, -8319, 422, -1019], [9186, -785, 711, 7418], [-11980, -5212, 3882, 7800], [48388, 2860, 56, 1022], [-50354, 1028, -4954, 180], [-1734, -4480, 422, -3942], [11967, -915, 3800, 947], [28216, -4260, -1424, 4840], [4684, 7463, -2134, 6802], [9516, -5508, 2134, 7250], [28052, 3904, -346, 2970], [31544, 3760, 5704, -7360], [-6242, 1320, 46, -9378], [27917, 2033, 6770, -4377], [-22477, -3683, -972, 1323], [-28532, -5479, -1522, 1142], [-24916, 2364, 1468, 4492], [14398, -4076, -8112, -5084], [-11074, 2656, -8417, -8802], [-94, -3888, 2382, 498], [17094, 8140, -5678, -5772], [-38912, -2992, -2772, 3374], [55066, 1978, 8638, -2998], [45848, -2437, -4469, 506], [2900, -4708, 4398, -3632], [7178, 4527, 2328, 11080], [-5858, -2141, 9769, -2780], [-6443, -4391, 5128, -5459], [23406, 2083, 2673, 4750], [-28566, -92, 584, -878], [-5658, -2825, -2559, 5452], [-4872, -1014, 1551, -520], [3116, -6216, 4792, -360], [-26892, -1396, 4244, -2636], [37300, 9806, -232, -1338], [82082, 827, -1831, -3450], [25544, -7784, 2570, 3108], [19520, -14702, 328, -54], [-14106, -2672, 2445, -10372], [45724, -1802, 7968, 9820], [-1565, 3105, 7220, 9371], [-46256, -2825, 452, -6010], [8118, 3573, 2798, 3950], [22974, 1517, -2839, -6670], [-44343, -2201, -4074, 1527], [34636, -688, 11476, -1704], [-11586, 1354, -4597, 956], [7022, 14890, 1155, -248], [36456, -8912, -4756, -5450], [54412, -3706, 11341, -1388], [39855, -16641, 3152, -7477], [-16412, 7100, -10442, -10038], [8301, 9287, -3022, -5701], [6758, 13144, -1738, 1668], [6308, -2255, -1426, -1844], [-30384, 4512, 8406, 2196], [29506, -2830, 2310, 4252], [-68714, 4710, -14832, 534], [3666, -13737, 11609, 8238], [-19848, -13515, 5389, 1062], [30798, -9610, 7740, -7970], [-676, 9114, 6920, 3822], [-44354, -4568, -6628, -512], [45704, -3819, -5048, -5958], [-30712, 7888, -8620, -3608], [5210, 4102, -322, 9506], [-26140, -9824, 1542, 228], [40122, -16242, 643, -124], [-53140, 10493, -7192, 1086], [-71288, 14230, 12626, 6164], [40239, 317, 1160, 1971], [22014, 6682, 5204, 5632], [26748, 7563, -6755, 8246], [-56138, 8885, 5851, 3878], [32429, 11305, 560, -9995], [-30980, 4860, 1257, -3384], [470, 9494, -4270, -1972], [28178, 3055, 1892, 12240], [-24530, 9002, -6256, -2528], [39582, -14108, -2893, 1184], [19802, 12223, 6505, -8184], [40838, 8449, -14692, -7162], [35116, 8851, -5920, 9146], [8784, 6307, 14564, 3846], [-42798, 9527, -10405, -2934], [-48302, 3586, -3250, -1756], [-14219, -6001, 7162, -5249], [-19372, -17320, 438, -1376], [18922, -16078, 454, 5906], [-52645, 1797, -11728, -465], [25748, -2184, -5888, 7584], [123162, -1399, 6634, -3646], [-5840, 4992, -14028, 1816], [15950, -11338, 11812, 10216], [-55630, 2510, -5568, 1326], [-51008, 15428, -7724, -2974], [4834, -10990, 15914, 1924], [-24190, 478, -17328, 258], [-38809, 13213, 3134, 1989], [47478, 2553, -7717, -8070], [9340, 10674, -16511, -9188], [3248, -3584, -3060, 16640], [-9718, -3106, -2850, 11636], [15582, 9970, -13134, -12096], [-59310, -15525, 7914, 4384], [-9532, -3094, -10396, -15698], [590, 15868, 7585, -5412], [41080, -7894, 10632, 2416], [-106734, 4, 9764, 3204], [22396, -15464, 15280, 3098], [-7494, 1774, -2238, -5854], [48132, 16932, -12759, -8248], [-5505, 8177, -4618, -1695], [-45782, -7566, -1634, 3124], [-59484, -1578, 2540, -13682], [-3421, -2095, -9980, -6989], [-18816, -498, 368, 4396], [31190, 3973, -6972, 5768], [11545, 13819, -18514, -4417], [83126, 7980, 4411, -6546], [-48721, 24825, 8508, -425], [-21654, -29833, 7501, 6010], [-15872, -13686, -6952, 1850], [36340, 6220, -9878, -8868], [41144, 6634, 3448, 366], [75965, 249, 2796, -6067], [123426, -1240, 6451, 248], [-38840, 15746, 6192, -14024], [28414, 10342, 824, 5868], [112328, -1280, 16988, -2228], [72580, 22003, -18620, -10968], [-53408, -16456, -11026, 9876], [23988, 11344, 14656, 3444], [-142984, 14869, 6360, 1960], [-3406, -24187, -3596, -3444], [43305, 5183, 3592, 23057], [94520, -6078, 12912, 15230], [-21496, -8164, -10506, 3744], [-61740, 21536, 5104, 4546], [-134446, 2959, 1725, -7862], [27116, -18417, 12345, 3326], [-15428, 18887, -910, 3834], [-38270, -7208, -5256, -12608], [39056, 17736, -13424, -7552], [-32124, 3220, 19240, 6682], [-7022, -7597, -8147, 20802], [147808, -7256, -476, 2848], [21261, -13649, 3646, -9845], [-762, -5156, 591, -14554], [135439, 11359, 704, -8597], [33190, -19680, 11947, 3716], [-68226, 14158, 11080, 5006], [8446, 328, 10412, -8128], [-76762, -994, 794, 14006], [-41818, 344, -1043, 1870], [57980, -14380, -2740, 12516], [63954, -22488, -6440, 8328], [15356, -23992, -1332, 21124], [69245, 2765, 18128, 9109], [85884, 27356, -10951, -6184], [-57273, -22443, 13442, 8785], [-37590, 4465, 5015, 7274], [-93750, -713, -10557, -13210], [-19170, -16301, 2675, 11482], [10842, 18991, -6974, 974], [151555, 2679, 1292, 4623], [-133649, 11957, 934, -5467], [-152896, 6642, -13796, 58], [-127442, 3137, -20608, 9848], [-16764, 29521, 17945, -16790], [-29614, -7440, -6104, 1062], [111676, -11193, -14386, -11744], [-132660, 2054, 1044, -3252], [85016, 6571, -4043, -7694], [107359, -7265, 5376, -11261], [6898, -2485, -12436, 5934], [48266, 15746, -14794, -11054], [-52176, 18034, 5653, 13264], [-60800, -25500, 14220, -4328], [49900, 30164, -11602, -11430], [-17296, 27664, 8998, -23048], [3384, -17172, 4448, -12682], [-70840, -18852, 7970, 6836], [-105708, 552, -16070, 4514], [-74290, 9138, -30093, 5388], [-100494, -14640, 10144, 6336], [-47144, 5580, -23752, -7560], [7776, 13580, -32944, -16362], [-163606, 8826, 3373, -40], [5398, -14888, 10124, 14486], [72022, 18780, 5936, -18240], [-9156, -882, 12084, 16682], [-28112, 11844, -10057, 17132], [60072, -29532, -773, -828], [-128098, 17053, -5033, 12626], [50524, -30442, 622, -11410], [42942, 17882, -4772, 16710], [2677, 5147, -21998, -18781], [-12918, 3046, -6098, -12644], [-1052, -24379, 22770, 22292], [106620, -3264, -2744, -8316], [-76352, -26159, 1507, -10058], [-197376, 6728, -1040, 3270], [-75864, 9780, -19072, -23848], [-73910, 894, -24240, -3472], [-37378, -22896, 10317, 16084], [53912, -3148, 16098, 27876], [-40960, 2981, -12098, -18382], [-27816, -18812, 26504, 14022], [29138, 3115, -6624, 5998], [-78906, -10510, -17210, 8582], [77776, -1932, 26382, -6162], [7390, 8160, -24871, 6646], [17076, -2312, -2294, 1588]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1232_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1232_4_a_s();".
// 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_1232_4_a_s(:prec:=4)
    chi := MakeCharacter_1232_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_1232_4_a_s();".
// 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_1232_4_a_s( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1232_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-1016, -436, 6, 14, 1]>,<5,R![-4016, 2648, -240, -10, 1]>],Snew);
    return Vf;
end function;