
// Make newform 1840.4.a.l in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1840_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_1840_4_a_l();".
// 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_1840_4_a_l();".
// 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 := [1242, -11, -84, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-96, -50, 2, 1], [-534, 50, 13, -1]];
    Rf_basisdens := [1, 1, 15, 15];
    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_1840_a();"
function MakeCharacter_1840_a()
    N := 1840;
    order := 1;
    char_gens := [1151, 1381, 737, 1201];
    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_1840_a_Hecke(Kf)
    return MakeCharacter_1840_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], [-1, 1, 0, 0], [-5, 0, 0, 0], [-6, 1, 2, 0], [-24, -1, -3, 0], [9, 2, 1, -3], [26, 4, -5, -1], [-48, 0, -6, 1], [-23, 0, 0, 0], [69, 23, -11, 7], [55, -13, 11, 2], [2, 17, -4, -7], [-91, -16, 8, 3], [32, 4, 12, -16], [89, -50, -13, -6], [14, -41, 38, 3], [0, -53, -24, 9], [-80, -51, -23, -10], [-194, 35, -52, -1], [319, -56, 18, -1], [129, -102, -3, -10], [-278, -80, 62, -28], [320, 29, -60, 37], [-228, 0, 60, -12], [38, 63, 59, 44], [-966, -23, -28, -1], [-462, -61, 93, 10], [618, -41, 32, 29], [658, -162, 98, -9], [588, 35, -56, 67], [-129, -144, 51, 16], [-511, 40, -135, -86], [174, 66, 30, 63], [-185, 11, 33, 87], [564, -108, -40, -37], [-293, -15, -84, -72], [-24, 27, 158, 73], [-843, -4, 75, -53], [768, -92, 12, -12], [224, 103, -37, -108], [-1493, 186, -239, 6], [-1168, 416, -272, -23], [-1734, 74, 180, 36], [701, 180, 201, -12], [-2141, 117, -34, -74], [-2206, -48, 172, -48], [-3496, 251, -132, 11], [-776, 86, 92, -46], [880, 140, -216, -58], [2980, -74, 190, 146], [-1449, -332, -101, 172], [-1171, -21, 37, 29], [1418, -426, 158, -46], [-1022, -24, -292, 67], [-1997, -180, -429, 80], [-140, -370, 379, 51], [-2359, -75, -87, 205], [742, 735, -56, -56], [-1967, 362, -135, -20], [3868, -62, -324, -16], [710, 1031, -70, 19], [-6524, -451, 4, 33], [-1042, 939, 67, 54], [4049, 438, -157, 48], [1386, -253, 20, 238], [-5908, -538, 38, 87], [723, -111, 53, 225], [2950, 1086, -82, -117], [126, -181, 329, -40], [-131, 697, 227, -93], [297, -402, 635, 188], [1318, -1006, -336, 14], [288, -107, 534, 277], [8262, -64, 240, -154], [-1594, 171, 33, -94], [4432, -567, -390, -331], [-3362, 125, -183, -184], [-283, -237, 612, 336], [-3342, -504, 272, -46], [-2341, -509, -215, -218], [-11360, -226, 104, -38], [-4182, -246, -38, 327], [4644, 340, 392, 158], [2300, -415, 1010, -58], [-119, 1146, -341, 133], [5955, 810, -119, 175], [-3472, -849, 168, 154], [3456, -799, -464, -447], [5069, 282, 429, -182], [-4640, 360, -234, 60], [3854, 441, -714, 403], [-4788, 418, 130, -254], [-7945, -808, 443, -8], [-3833, 33, 627, 473], [-4095, 589, -335, -1], [8796, -369, -732, 114], [-5187, -172, -1165, 20], [4508, -796, -58, 72], [-4892, -782, -1270, 338], [-7715, -932, 183, -554], [4409, -114, 367, -345], [6600, 1473, 34, -323], [15408, -991, 1418, 65], [-4586, -1108, -48, -208], [5602, -995, 411, -102], [4817, 352, 1501, -302], [4231, -1281, -456, 110], [-9830, 1302, 1440, 524], [-7074, 941, 219, 168], [1715, 653, 469, 208], [-1412, -872, 864, 792], [6136, 76, -234, -296], [1348, 1218, -39, -367], [1134, 1086, 496, 569], [-1264, -122, -1582, 436], [6884, 674, 416, 414], [-1618, -1229, 2024, -215], [-1355, -782, 1745, -428], [-1503, -2594, 1741, -287], [-10972, -1862, -32, -274], [6216, -301, -1495, 460], [3691, 700, -1097, 182], [4806, 2341, -406, 89], [8081, 798, -849, -203], [-10024, -912, -324, 302], [5718, 2804, 254, -589], [-14454, -129, 713, -194], [-1238, 1665, 656, -320], [9664, 368, -823, -973], [-9188, -257, 4, 311], [22323, -897, -897, -119], [-7270, -4054, 216, 121], [-2380, 4084, -1070, 282], [-1746, 1431, -268, 487], [9459, -3429, 1113, 330], [6450, 3222, -1152, 38], [-9052, -1970, 1372, 98], [1828, 1, -164, 199], [-2338, 517, 1090, -589], [6756, -994, -2053, 809], [12941, -429, 629, 451], [-2006, 740, -2356, 616], [19345, -2264, 1305, -366], [-10424, 495, -2076, 521], [-14250, -2039, 342, 1025], [-6120, -770, -116, 28], [3972, -1728, -198, 551], [-8381, 242, -2077, 40], [-7475, -1661, -2231, 787], [-153, -458, 403, 1234], [-18276, 935, 2477, -74], [35152, 164, -472, 460], [-26286, 1924, -1634, -565], [-7571, 2088, 2487, 182], [6498, 4495, -1084, -147], [10038, 1940, -826, 1118], [-1300, 1144, 940, -516], [-1469, -6751, 1349, -509], [-5864, 3378, -1052, 599], [24390, 2413, -969, -438], [5699, 1550, -851, 563], [8912, -37, 793, -976], [-1677, 1180, 1247, 960], [-5648, -1157, 1927, 798], [-3280, 4555, 1334, -186], [1032, 970, -563, -455], [16170, 2630, -51, -539], [-11994, -5334, 8, -338], [-4338, 110, -3228, 692], [-20419, 1479, 0, 40], [2574, -1268, 2402, -628], [19897, 2193, -579, 25], [-10072, 5418, -2680, 48], [30446, -114, 837, -789], [11953, -987, -2342, -1904], [928, 2520, -1236, 170], [4943, -116, -741, -1078], [-2229, -1137, -17, -1895], [12116, -872, -887, 951], [-15198, -3446, -2214, 509], [-36177, 1178, -837, 70], [7802, -5, -2735, -1294], [7819, -930, 1239, 781], [-29242, 226, 430, 704], [-7292, 536, -1211, -381], [14646, -822, 1942, 361], [-14864, -20, 1562, -411], [11374, -4467, 3496, 649], [9067, -2476, -1422, -917], [-33034, 190, 1039, -505], [-28753, 226, 2719, -1106], [-11492, 4286, 1304, 1534], [-4358, 5610, 1102, -290], [-6530, -2333, -528, -1657], [-10582, 390, -768, -1250], [-58238, -733, 1552, -24], [5994, -2090, -4874, 120], [20304, -1724, -1930, 664], [1904, 2188, -1546, 528], [22343, -4608, 5577, 76], [-43970, -4531, 1439, -278], [25914, -2020, -490, 909], [-26557, -771, 3354, -270], [9710, 6194, 1238, -1150], [-32604, -3112, -2548, 1136], [-13875, 5554, -3279, 492], [10426, 310, 772, -2282], [-11025, 6397, -1954, -238], [801, 1191, 4423, 256], [-11985, -7102, 1817, 1770], [13807, 3032, 225, 16], [15251, 814, 823, 1196], [-32610, -62, -4524, -107], [19014, 2532, 2318, -322], [-10900, -6763, 1646, -771], [31356, -372, 1388, -350], [3197, -4226, -487, -1838], [-49591, 4883, -5225, -559], [-35800, 1123, 3424, 1100], [-32309, -6678, 4055, -2012], [45227, 6213, -261, -1179], [-22158, 1656, -1996, -1728], [3471, 11664, -4464, 1005], [-914, -4013, 7254, -528], [-29591, -5060, 1871, -578], [7507, 707, -4905, 1915], [5280, -5898, -1772, -515], [-37031, 3347, -523, 1582], [20028, 2662, 1226, 435], [-14752, -3937, -1238, -13], [-8992, 4792, -2442, 87], [24090, -1241, 2183, 1800], [-4442, -1426, -1578, -1422], [14352, -1884, 8225, -859], [-26604, 4959, -1626, 1789], [3500, -7092, -2916, 520], [4748, 1188, -2380, -70], [-39898, 1206, -5478, 460], [-10215, 3219, 3921, -729], [2505, 7030, 146, 2015], [69328, 1139, 1546, 741], [-12203, 4633, -461, 847], [37481, -2194, -4839, -280], [-30425, 3106, 1975, 2066], [-206, -864, 2670, 794], [-1681, 8642, -1115, 83], [16161, 2114, -405, 2362], [11468, -12028, 3014, -1575], [24664, -199, -1269, -1056], [1636, 3144, -4545, 2021], [-20908, -184, -3594, -2538], [11406, 732, 848, 1514], [940, 4207, -4032, 2192], [8796, -4330, -548, 18], [-62878, 3376, 4360, 1196], [-7545, 1205, 1489, 853], [6452, -2021, -7273, -2002], [1194, -5918, 1580, 1512], [12667, 806, 1239, 833], [-44311, 8154, 1661, 1928], [7082, 1866, -3675, -1633], [648, 3691, -688, 131], [18182, 6613, -1204, 3533], [15928, -9265, 2702, 453], [24246, -2858, -2108, -854], [-6056, -963, -5955, 558], [-29200, 3793, 2557, 2342], [-36964, 7076, -4738, 156], [5318, 10147, -4322, 2793], [-12413, -2200, -6061, -467], [53545, -3531, 805, -2539], [-8662, -6833, 6300, -2737], [-17622, -7511, 704, 2656], [-65792, 10082, -1052, 430], [-9615, 11268, -3363, -322], [-28591, -4318, 5841, -802], [-43702, -8451, -3125, 3920], [-35422, 4431, -8896, -2839], [20238, 566, 8092, -2586], [49002, 6262, -2564, 115], [-46561, -4832, 2625, -5198], [-51290, -5644, 2034, 1272], [50544, 8271, 1919, -2866], [-9162, 2954, 856, -330], [-73442, 5750, 1282, -395], [-51746, 9270, 2875, 999], [-54882, -1169, 3046, 327], [-29238, -6204, -5220, -30], [-8090, -1443, -4469, 1204], [37028, 8823, 561, -2798], [-21270, -6460, 20, -268], [10248, 6487, -3440, 2173], [6574, 2730, 1400, -3092], [-3180, 418, 5462, -2755], [-44089, 10413, -3892, -280], [80764, 3897, 929, -134], [-7404, 5090, 1940, -768], [67137, 11195, -222, -894], [10255, -1301, 3101, 1201], [72801, -2541, 7558, 1898], [-3618, 4819, -3332, -3690], [63818, -907, -1856, 2219], [14900, -374, -5262, -2428], [23995, 4218, -7099, 208], [22378, -114, 3688, -443], [16251, 5096, -10093, 2800], [-13646, -3521, 6703, -90], [46898, 506, -3866, 2101], [-63718, -12792, 1134, 514], [17868, 559, -7601, 36], [26453, -12942, 4155, 778], [91592, -4834, -5820, 679], [-24608, 1582, -4714, -1316], [-54779, 12749, -978, 360], [-98236, -3581, 3592, -1432], [56564, -4632, -4212, 750], [-83949, 11037, -2327, 487], [-43957, -313, -2085, 4492], [-45164, -7005, 5632, -3565], [44089, 6707, 202, -3258], [65102, -7569, -5415, -838], [-47790, -6064, -3931, 3505], [23095, -8814, -6069, -1720], [-71596, -7678, 1496, 268], [-45828, 2432, 1613, -217], [-18184, -8748, 4412, -2428], [-11304, -12074, 6582, -461], [89965, -4176, -1409, -3341], [-34144, -12122, 1690, 3401], [48684, -5185, 3830, -2707], [11505, -7815, -2313, -3319], [36101, -6637, 3270, -662], [67779, -9499, 1043, -3177], [-24611, 9368, -5425, 3427], [18582, 5044, 8662, -4816], [-71427, 4538, -2765, -1091], [-43880, -12093, 4653, 508], [58744, 6180, -974, 5160], [-54659, -6063, -10800, 4018], [-57998, 628, -7895, -4235], [9531, -7290, 7731, -1252], [-8122, -2251, 1201, 5504], [68294, -11594, -4678, -3654], [-4718, 3040, -4078, -5890], [-32290, -4819, 1130, -207], [17720, -13417, 12542, -1593], [87131, 17299, 393, -4539], [95574, -1770, 3186, 847], [77302, 2604, 888, 3236], [-42938, 2059, -7624, -6095], [74401, 6009, 2649, -2931], [-87995, -8456, -19, -1938], [16398, 4567, -10014, 1473], [-2888, -5306, -677, -269], [-37644, 2654, -5074, -4790], [-92546, 8614, -12482, -1392], [26500, -6108, 5558, 5698], [-29788, 652, -8438, 1397], [-13123, -4446, -10359, 100], [131156, 3036, -946, 1836], [-11374, -7933, -8746, 1385], [8353, 5051, -2317, 4381], [-18241, 12906, -11401, -3306], [13896, -10661, 35, 2318], [-41479, 3481, -4368, -5722], [33897, -26594, 6393, 32], [-26703, 4735, 4696, 6736], [94026, -1629, -2100, 3283], [139470, 7296, 4314, -4234], [37711, -1617, -7451, 3573], [48860, -5053, -3576, -55], [3561, -12830, 8473, -2252], [-81170, -2833, -14007, 1298], [-4392, 9152, 11180, -3228], [25733, 3826, -11699, -2549], [13763, 2675, -7997, -5377], [-75350, -15476, 4048, -1962], [-98028, 7142, 1831, 4539], [-64856, -3628, -5344, 670], [18279, 6148, -11475, 3470], [7708, -13295, -11209, 1696], [-16516, 8113, -9889, 588], [1768, 21726, -9422, -2372], [-10465, -18322, 2235, -4436], [-109208, -6104, -1360, -1876], [-51665, -9132, 12969, -226], [-31187, -5393, -4079, 2614], [64464, -5482, 5686, -273], [24306, -15967, 2422, 2909], [-38042, 10401, 4566, -1756], [-93344, 12704, 2578, 2144], [44324, -11836, 14330, -573], [-54019, -2687, 1189, 155], [49452, 8312, 10736, -5604], [-49956, 11044, 14158, 4444], [112304, -7323, 12422, 1274], [46548, 18476, -11698, 6432], [-98432, -2724, 4564, -4584], [138894, 874, -11060, 1253], [-122534, -6155, -6726, 869], [30735, -20235, -7563, -391], [-3343, -18870, 9569, 498], [39832, 4013, -2386, -3967], [48938, 13891, -10916, 3122], [8943, -3853, 3763, -4115], [-2393, -7706, -8620, -2545], [-24514, 23247, -7452, 3933], [1503, 25826, -1793, 1909], [4788, 19216, -2320, 2826], [24660, -20792, -11776, -364], [-4085, -500, 2055, -6608], [95325, 16341, 6976, -2486], [-87814, 212, 16154, -888], [90960, -11031, 565, 2], [-27344, 12655, 738, 3916], [23885, 4266, -20591, 7196], [4326, 17100, 5358, 1455], [96128, 272, -11360, -1242], [57066, 21332, 8651, -2281], [-37550, -4774, 17916, -3679], [-191158, 1613, 1017, 2200], [-30148, 13106, 18592, -3236], [31068, 1154, 13596, 2892], [-59224, 4824, 8988, -2606], [-99823, 2586, 8915, 8126], [-22989, 19192, -8645, 2842], [28002, -5640, 8382, -5580], [-27492, -19525, 8968, -4232], [-99695, -6820, 4893, -4656], [-23545, 4130, -17472, -3689]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1840_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1840_4_a_l();".
// 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_1840_4_a_l(:prec:=4)
    chi := MakeCharacter_1840_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_1840_4_a_l();".
// 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_1840_4_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1840_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![1148, -175, -78, 4, 1]>,<7,R![-832, -16655, -648, 26, 1]>],Snew);
    return Vf;
end function;