
// Make newform 2366.4.a.r in Magma, downloaded from the LMFDB on 14 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_2366_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_2366_4_a_r();".
// 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_2366_4_a_r();".
// 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 := [162, -12, -33, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-16, -2, 1, 0], [36, -18, -4, 1]];
    Rf_basisdens := [1, 1, 1, 3];
    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_2366_a();"
function MakeCharacter_2366_a()
    N := 2366;
    order := 1;
    char_gens := [339, 2199];
    v := [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_2366_a_Hecke( : Kf := Kf)
    return MakeCharacter_2366_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]];
    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 := [[2, 0, 0, 0], [-2, 1, 0, 0], [1, 1, 0, 3], [-7, 0, 0, 0], [-6, 1, 0, -4], [0, 0, 0, 0], [-5, 1, -7, -1], [12, -6, -7, 7], [-46, 13, -1, 5], [19, 2, 11, -22], [-60, -37, -1, 2], [193, -30, 6, 9], [-61, -33, 7, -44], [6, -13, -14, -43], [-146, 42, -4, 7], [-39, 38, 12, 0], [-178, -3, -7, 30], [-105, -69, -31, 94], [-186, 45, -17, -94], [-58, -14, 24, -70], [109, 51, 49, -12], [-548, 149, 7, -19], [-134, -117, -33, -164], [644, -68, -53, 35], [-344, 154, 39, -14], [-363, -161, 28, 115], [-122, -132, 66, -111], [148, -218, 49, 21], [-44, 130, 140, -231], [549, 94, 150, -44], [-764, -40, 37, 238], [156, -344, 67, 124], [-1207, -100, 35, -242], [88, 185, -58, -253], [-475, 104, 111, 4], [-890, 522, 138, 211], [-1485, 75, -162, 88], [140, -95, -119, 467], [914, 5, 161, 204], [1110, -14, -60, 491], [-1864, 68, -102, -203], [-843, 45, 21, 184], [616, 125, -172, -464], [617, 140, -332, 421], [-1290, -552, 21, -165], [-1302, -118, 98, 105], [-222, -17, -107, -298], [-1724, 438, 107, -434], [-616, 545, 147, -502], [330, 938, 24, -56], [-2170, -116, 225, -321], [1260, 693, -33, 276], [-927, -333, 176, -794], [1130, 380, -118, 350], [-3199, -703, 104, -636], [1508, -103, 137, 208], [418, 680, 223, 966], [1506, 515, -47, -182], [1021, 162, 190, 448], [-1075, 610, -152, -675], [-6046, 381, 79, 145], [-1801, -93, 47, -70], [1438, -1321, 280, -147], [-5010, 75, 154, -455], [376, -272, 198, 1424], [1951, -60, -50, 560], [1022, -1163, -536, 320], [-3399, -204, 347, -202], [1154, 399, -213, 1019], [-1320, 1616, -12, 587], [753, -765, -74, 143], [106, -284, 547, -822], [-1760, 263, 569, -1691], [3079, -196, -249, -1581], [4764, -1847, -484, -78], [356, 209, -284, -1315], [-3109, -676, 20, 983], [-5906, 708, -284, -580], [4485, 992, 417, 1466], [4505, -1131, 434, 563], [-6048, -399, -685, -320], [5073, -484, -536, 377], [-5466, 1110, 341, 964], [-413, -215, -571, -1505], [-2248, -101, 574, -15], [2776, -1902, -644, -1716], [-784, -2404, 520, 1058], [-2253, 0, -44, -2243], [5103, 523, 358, -2245], [7000, 1493, -241, -1040], [-3606, -117, -69, 676], [-134, -837, -1520, 798], [3662, 1832, 501, -2004], [-2534, 338, -1443, 588], [3568, 2525, -70, 461], [-12212, -539, 262, 956], [-3341, 697, 191, 691], [4191, 1711, 939, 12], [-10720, -2466, 776, -1626], [4355, -1468, -561, -1936], [-3630, 3313, -427, 190], [2003, 426, 317, 1729], [2494, -1499, 307, 1841], [1228, -2160, -300, 1354], [-3002, -1940, -791, 119], [3447, -2379, -167, -503], [-2934, 286, -691, 8], [13987, -1827, 596, 726], [9832, -1382, -705, -1030], [-2087, 2915, 218, -1005], [-3230, 476, -272, 797], [12857, -256, 1137, 2067], [11605, -1498, -834, 1686], [-3638, 1043, 161, 2427], [11670, 1660, -345, 1879], [5533, 1916, -1481, 2075], [-1232, 3248, -604, 375], [-11862, 360, -166, -2890], [5218, -132, 1741, -348], [-5764, -4018, -70, 1296], [9447, -1747, 1361, -534], [10577, -1398, 1698, -464], [12808, -4220, -1061, -1529], [3834, 588, -930, -3929], [-4182, 4310, 1445, 1017], [-1380, -4724, 2, 944], [15671, 80, -807, -122], [6614, -533, 1079, 2666], [10676, -998, 1244, 1587], [-8719, -3507, 750, 2314], [1092, -5716, 722, 300], [842, -5226, -319, -782], [-7456, 3863, 977, 250], [-19892, 3464, 968, -436], [6636, -1402, -291, -3572], [12878, 1214, -1076, 57], [-14670, -1888, 142, -1281], [12636, 1203, 473, 2893], [-642, 3010, 244, -836], [16465, 4596, -768, 758], [-13642, -1685, 1590, -1986], [2218, 188, -536, -3461], [6764, 3458, 1028, 1429], [254, 4135, 1606, 1041], [-16059, -671, 556, 6019], [20356, -1638, 1531, 1551], [14053, -4239, -1945, 1697], [23799, -4125, -786, -1152], [-10544, 3315, -955, -187], [-12856, 879, 457, 353], [-13453, -3910, 256, -926], [-9373, 3155, -1199, 2199], [-110, -3467, -3639, 4042], [-9164, -2862, -444, 538], [11752, -175, -1809, 6113], [13222, 1640, 839, -929], [10902, 3766, 566, -362], [-20007, 1987, 721, -317], [3185, -965, -1055, 5153], [-14562, -1652, -3624, 2417], [-9672, 8121, -440, 1808], [-4712, 4122, -882, -4451], [-26526, 547, 55, -2600], [-12230, -402, -1626, -79], [13569, -300, -2912, 898], [-2568, -172, 137, -3980], [464, 5135, -526, -1230], [6575, 7615, -1865, 3897], [-7622, 3846, -1761, 2160], [15493, 6935, -467, 3917], [-292, -3809, 928, -749], [6691, 3313, -1040, -444], [-9564, 6298, -1289, 220], [4741, -4028, -559, 3121], [28986, -2081, -292, -2884], [-33231, 10545, 2747, 77], [-23346, 1136, 1670, 86], [9937, -2484, 1117, 2349], [6786, 7082, 895, 2664], [-16412, -746, -1579, 918], [-7994, -3593, 2191, -3376], [10094, 1976, 1487, -2015], [2651, 486, -3848, 6658], [-31284, 740, 2231, -3173], [-7906, 6080, 2009, -327], [31387, 2543, 69, -4093], [32, 6192, 2390, -1176], [-50640, -1990, 435, 10], [-25067, 64, -1742, -6745], [8454, -3310, -4713, 2897], [-20767, -6131, 855, 3737], [24080, -4091, -318, 129], [266, 4750, -521, 6947], [33974, 5596, -35, 5843], [-3454, -295, -1024, 2366], [-21500, -2672, 1676, -491], [10507, 7914, 1897, 209], [3623, 6140, 1717, 7805], [-2993, 1077, -875, 7220], [570, -4606, 2274, 891], [23641, -5780, -3085, 1843], [-21452, -3792, 1043, 1455], [15741, 4381, -4093, 2915], [-20665, -6301, 1422, -8017], [33594, -1644, 1284, 2393], [16201, 7265, 1567, -4261], [-44738, -1529, 897, 5301], [24960, 7067, 1497, 3000], [9563, 4802, 909, 5227], [-34476, -3320, -908, -1734], [-43733, 3240, -3097, -3406], [37632, -4550, -2833, 6036], [-15338, -10692, -40, 8993], [-19542, 3742, 1026, 3793], [-63120, -3296, -1455, 5528], [6893, 4325, 6237, -347], [6034, 9899, -205, -6748], [14861, -175, 1166, -10110], [-29530, -1710, 1223, 7992], [24344, -1744, -2273, -975], [38637, -1820, -3493, 2346], [11454, 6894, 938, 259], [29187, -3074, -162, 2157], [-4038, 3682, -2733, 4502], [59806, -2294, -1017, 3071], [-12771, 4140, 2965, 5208], [-3677, 1835, -2343, -5179], [-24726, 3436, -6675, -3002], [-19188, -2028, -4045, 94], [-984, 3610, 2372, 10317], [39819, 3790, -4364, 4421], [-3492, 1474, -1094, -11497], [132, -2207, -3954, 983], [-13319, -9676, 650, -8887], [19464, -1993, 6189, -1697], [7374, -7896, 6196, 1969], [-15426, -12408, 93, 10148], [-22753, 5154, 2708, 4660], [6682, -4994, -3238, -3696], [-29382, 4511, -1387, 3208], [-26420, -8371, 1812, -476], [-27004, 5935, 4825, -6180], [64778, -2690, 1941, -4650], [29425, 6898, 1468, 12050], [1585, 14213, 3077, -9756], [-12982, -10261, -5033, 1199], [-952, -6795, -4853, 3747], [8882, -9484, -5533, 8295], [43268, 12541, -99, -9057], [40432, 11274, -2259, 8800], [-414, -7514, -175, 2488], [3852, -6886, 4237, 82], [-51440, 2524, -5262, 2047], [5429, 8487, 751, -9557], [-33618, -7964, 4470, -12317], [-62488, 10104, -2610, -2455], [-22400, 11752, 223, 9537], [-43336, -1384, -696, -3397], [-16786, -13610, -590, -3059], [62759, -1475, -5730, 7174], [-16536, -6370, -5552, 4259], [-39148, -1870, -1484, 4871], [-23747, -7419, 2163, -13941], [-17679, -1569, -1479, -12353], [-33569, 17661, 4281, 4900], [-12084, 7081, 1815, -155], [10900, -806, -6652, -485], [91247, -769, 366, -4466], [-31238, -1218, 6192, -10015], [28171, -1362, 3070, -3886], [-12985, -11323, -1826, 5368], [61922, -9932, -6523, 4574], [-18127, -15557, -1719, 344], [-79702, -5578, 452, -3573], [858, -10464, -4118, 2598], [3750, -4445, -3416, -154], [1052, -1687, -367, 18372], [28205, 6710, 1648, 7645], [-56735, -7530, -4872, -9157], [-15602, 2390, 7602, -6825], [53294, -14682, -7147, 6970], [-7148, -16352, 5453, 4184], [36128, 12765, -432, 3970], [23113, -339, -5667, -1830], [-35028, -8574, -1670, -2419], [-44778, 8998, 4720, -6232], [-19491, 308, -4309, -2999], [74993, 9270, -5605, 14679], [672, -28608, 2966, 4086], [25289, 5345, -1786, -3351], [-19926, -17452, -276, -16169], [100138, 860, -3717, 7718], [-22901, -24868, 2440, 153], [72138, -9755, 4574, 5139], [-44660, 11378, 9152, -9300], [-39067, 2647, -1484, 3652], [-18620, -20962, -13, 1819], [66619, 11197, 2434, 4398], [-15178, -3066, 1871, -5255], [-35186, 16057, -2228, 646], [3947, -7477, 2689, -19356], [-2881, -18880, -587, 3248], [45304, 1368, 4944, 2702], [30928, 10456, 2930, 2743], [48154, -15160, -7664, -2587], [7467, 13634, 3560, 15368], [-71768, 11460, -4394, 2351], [-25027, 7485, 3673, -10097], [27680, -8551, 2215, 9788], [-3393, -144, 1846, 16055], [67820, -21254, -4486, -153], [1232, 30058, -520, -12993], [-57991, -13314, 40, -6966], [39922, -28481, 2324, 842], [-35060, -12170, 335, 5314], [31059, 23209, -2198, 8740], [-32020, -10091, 1799, -4462], [25046, 2535, 3601, -20421], [-46738, -9222, -3704, -16229], [42353, 4056, 7762, -4297], [18984, 6963, -8087, -1212], [-4488, -13780, 193, -2652], [30605, -19669, -5341, 2115], [-29862, -7314, -761, 29285], [42942, 10828, -506, 10514], [66663, 4487, 7568, -8436], [-36424, -1942, 3697, -8171], [16084, -24185, -1860, -8460], [-26258, -11589, -1024, 15010], [8501, -5956, -502, -5517], [-46003, 26936, -7072, -7038], [23067, 2056, 9225, -900], [-89466, 22640, 6790, -4198], [-108058, -8066, -3498, 12755], [23370, -1456, 8551, 7724], [57042, -1946, 10570, 18750], [-63689, -3722, 4148, -5506], [6494, 2552, -6160, -12548], [53225, 3389, -8398, 908], [-51846, -7763, -1665, 4050], [32614, 23496, 5169, -14142], [-35681, 7758, 1170, -14249], [-29995, -6041, -7644, -4326], [-4384, -15981, -11531, 1423], [-44932, -11824, 1454, -7704], [-81336, 14321, 8169, -2877], [-162585, -6715, -1426, 1247], [-81496, -11526, -890, 23000], [-33508, -4151, -319, -1778], [17924, 2780, -4438, 7249], [-31520, -7152, -4892, 21185], [-48416, -4830, -3524, -9758], [-69285, -1338, -7852, 12350], [-43026, -13691, 1916, 11305], [-113485, -5626, -748, 10716], [-30725, -14425, -9330, 4914], [-33310, -18568, -6301, -7863], [-155376, -5244, 4806, -11262], [16907, -16050, -8515, -14030], [17034, 11730, -7854, 6648], [133447, 12408, 871, 8959], [-44063, -7059, -4093, -620], [-63430, -7748, -10036, -29260], [-81744, 667, 3621, -10554], [-48288, -31590, 4074, 7574], [99784, -18628, -1446, 4631], [-41384, 17304, -4276, -2058], [10, 22313, 1690, 15068], [-88545, 7784, -11775, -3443], [45658, -23362, 11188, -414], [-128384, 827, 3027, -11826], [25444, -11440, -11025, 17915], [59, 5684, -1581, 7221], [115772, -7147, 2721, 779], [65525, -25448, 3895, 2066], [-110026, -7320, -9834, 13277], [-82136, -7223, -2243, 3183], [-86872, 26308, 11401, 3624], [84571, -8267, 3085, 129], [45055, -18695, 8673, -8303], [-65926, -424, -7681, 17592], [16179, 19078, 8322, -13176], [-52112, -10599, -4419, -3036], [23676, -944, -5736, -37179], [110328, 13225, -5642, 21035], [-35446, 21968, -6542, -19040], [111420, -15989, -6949, -9504], [20606, 3238, -352, -6817], [-82178, -2299, 6249, 10062], [-14728, 21895, 5955, -7429], [-77061, -6706, -1899, -10136], [26433, -5755, -11355, 19553], [-2974, 4097, 9738, -8241], [-33506, 10901, -6655, -17240], [47158, -10279, 13510, 18579], [-97460, -10124, -6258, 25782], [-72840, 33313, 13640, -515], [43146, -10896, -10568, -14350], [84106, -23675, -1326, -3687], [23509, -2418, -963, 26882], [-55290, 11884, 2182, -22279], [-27214, 936, 16455, -5192], [24360, 6572, -8908, 8176], [-50485, 16821, 1406, -9054], [15945, -10257, -5918, 1726], [86508, 18435, -3565, 24836], [87056, 12860, -4352, -18298], [5123, 41164, 5398, -24881], [4570, -9329, -7659, 4179], [-18196, -32572, 7776, -9222], [-51181, -8025, 3528, -17410], [-56337, -24728, -5124, -33575], [85212, 7844, -11840, 19921], [-168458, -11344, -6246, -14454], [-46839, 39262, -1462, -246], [25901, 5661, 8361, -7796], [-136602, 5468, 3788, -13122], [59526, -889, -1308, 92], [19554, -5474, 8958, -25101], [58238, -34637, -4507, -1432], [123297, -19346, -14140, 11924], [18347, -13263, -5621, 5011], [-92168, 25986, 8286, -11611], [47048, 8209, -13703, 15296], [112978, 15618, -666, -2492], [-204825, -4855, 4758, -4632], [34420, -44103, -1313, -303], [166073, -3580, 3701, 6408], [33450, 26202, 2018, -27699], [30300, 35927, -679, -4820]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2366_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2366_4_a_r();".
// 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_2366_4_a_r(:prec:=4)
    chi := MakeCharacter_2366_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_2366_4_a_r();".
// 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_2366_4_a_r( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2366_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![14, -124, -15, 7, 1]>,<5,R![24191, 485, -432, 1, 1]>],Snew);
    return Vf;
end function;