
// Make newform 819.4.a.h in Magma, downloaded from the LMFDB on 17 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_819_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_819_4_a_h();".
// 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_819_4_a_h();".
// 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 := [76, -24, -27, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [10, -19, -2, 1], [-14, -1, 1, 0]];
    Rf_basisdens := [1, 1, 4, 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_819_a();"
function MakeCharacter_819_a()
    N := 819;
    order := 1;
    char_gens := [92, 703, 379];
    v := [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_819_a_Hecke(Kf)
    return MakeCharacter_819_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 := [[1, -1, 0, 0], [0, 0, 0, 0], [10, 1, -2, 1], [7, 0, 0, 0], [23, 5, -1, -2], [-13, 0, 0, 0], [36, -20, 2, 0], [-16, 9, 10, -3], [29, 18, 7, 1], [110, -29, 18, 9], [-75, 30, -1, -9], [-63, -39, 7, -18], [3, 37, 77, -2], [134, 21, 8, 9], [207, 4, -31, 7], [58, 59, 54, -27], [194, 26, 50, -48], [-35, -9, -13, -6], [-127, 11, -31, -8], [-368, -32, -32, -18], [27, -78, -5, 75], [237, 64, 3, -37], [286, -13, -48, -47], [720, -7, 16, -33], [693, -224, -83, -13], [945, 59, -221, 16], [-206, -106, 106, 4], [-1180, -56, -168, -20], [-374, 28, 284, 38], [-163, 64, -135, 1], [1293, 241, 37, -82], [776, 104, 344, 8], [-782, 42, -160, -116], [-120, 350, -180, -116], [899, 17, -223, 232], [528, 40, 72, -130], [669, 249, -137, 18], [364, 120, -376, 288], [954, -311, -184, 15], [114, -522, 264, 48], [-644, 197, -246, 19], [-1189, 133, 153, 164], [40, 32, 432, -220], [-1756, -202, -166, -92], [143, 481, -291, -86], [524, -704, -548, -118], [-720, 139, 42, -391], [-1441, -94, 901, -35], [232, -884, 328, 232], [-1248, -294, 406, 48], [1639, 1080, 503, -265], [242, 486, -350, 48], [-740, 895, 164, -235], [773, 967, -543, 58], [-1704, 166, 26, 250], [-622, -247, 104, 445], [415, 211, -707, -312], [-271, 593, 961, -182], [-192, -1039, 344, -299], [1680, 426, 882, -94], [439, -73, -705, -386], [1256, 399, 748, -347], [1622, -775, -172, 175], [-2090, -148, -1038, -372], [-1514, 344, -28, 478], [2179, -329, -1571, 72], [-3447, -505, -623, 160], [3107, 1212, 319, -549], [424, -672, 284, -100], [-2060, 1027, -180, 377], [1303, -1659, 617, 438], [-1532, 216, 164, -178], [1748, -246, 664, 108], [-1800, 1130, -614, 856], [-2724, -1506, 1252, 108], [2255, 411, -785, 462], [-1668, -6, 2178, 76], [-438, 65, -206, -455], [2632, 516, -178, 878], [4652, -293, 836, 233], [-767, -1013, 997, -746], [7075, -189, 1025, 246], [-1262, -548, 1198, 582], [7654, -1162, 352, 34], [5614, 800, -518, 178], [2, -3305, 144, 211], [-4490, 1974, -364, 202], [970, 702, -1004, 276], [7316, 1366, 894, -272], [4852, 14, -1872, 400], [-2008, -1090, -1060, 888], [1682, -2695, 536, 307], [-5078, -2232, 454, 6], [-2376, -1020, -1140, 904], [1031, 855, 203, -492], [-208, 1294, -2220, -542], [14076, -885, -528, 97], [678, 2578, -1204, 858], [-6837, 2805, 695, 744], [-3702, 1310, -2184, -248], [-4046, 2731, -752, 587], [-5097, -969, 2169, -252], [4801, -763, 417, -1366], [-1051, 3046, -1995, -177], [4496, 431, 2962, 457], [-3634, -452, -2924, -1000], [10576, -1075, -222, -271], [4672, -2313, -3484, -455], [-3853, 2432, 485, 53], [-26, 2336, -748, -812], [-2870, -4244, -2842, 404], [2023, 1051, -147, 308], [1338, -2540, -796, 532], [-410, 386, 1166, 184], [7538, 576, -3978, -90], [-2409, -82, 763, -1935], [-896, -48, -3440, -900], [7996, -2862, -400, -664], [-12892, -3594, 106, 560], [14212, -2189, 118, 261], [15586, -2683, 114, -395], [4969, -454, 2533, -1673], [2173, 1411, 367, -188], [5691, -3377, -1, 1978], [-10486, -4567, -1136, 1459], [4414, 585, 3614, -509], [-7345, 2105, 3689, -212], [3394, 1968, 3854, -156], [-16910, -2848, 4110, -302], [-2614, -2871, 1082, -15], [180, -3534, -1572, -840], [10608, -5692, -920, 396], [-10721, 4630, 1157, -397], [-1696, -3631, 3408, 517], [8329, 1108, 1813, -1297], [12719, -3872, -797, 1385], [11386, -2096, -1604, -456], [9446, -81, 32, 2217], [5989, -1593, -3361, -1682], [-8536, -2833, -2860, 1375], [-23516, 2856, 1052, 972], [8990, -4072, -292, 288], [9365, -3331, -2699, -1874], [5996, 5720, 2288, -2480], [-4798, -292, 16, -26], [-1809, 5455, 2591, -374], [-18974, -2765, -1706, -541], [8098, 1364, 2004, -160], [11845, 563, -6703, 340], [-13780, 1620, -260, -2332], [-5549, -5529, 3545, 1518], [-14186, -4728, 4712, -188], [8490, 2406, 5198, -828], [-27698, 2170, -698, -780], [2860, -10093, 582, 1237], [-9898, -1083, -1268, 741], [-8877, -1125, -3357, 1206], [-10571, 844, -2063, 3375], [13040, 4916, -2422, 388], [10236, -6647, -3580, -1205], [-3332, 190, -7028, -786], [-9408, -9593, -1492, 1167], [-18698, 1612, -326, -1156], [4815, -3231, -5877, 2592], [-4370, 4472, 168, 1494], [-21638, 1349, 4944, 359], [16415, -2709, -881, -1470], [-403, 7941, 2711, -540], [11920, 2730, -2674, 3978], [-9770, -46, 132, 1272], [-9272, -3302, 3232, 780], [-29706, -5768, -60, 1160], [141, 3196, -349, -637], [-18172, -6244, -5466, 988], [-37882, -2138, 4702, -520], [-12560, 1476, -3442, 1994], [-28757, -461, -4065, 578], [29342, 2788, 4572, -1260], [16400, -7602, -2308, 1836], [1351, 3085, -931, 4532], [-3786, 402, -7418, -1944], [-25737, 965, 5107, -3758], [3950, -1816, 1176, -92], [-6005, -4602, 383, -569], [-12608, 3510, -964, 3188], [10190, -9408, -1016, -1550], [-40962, -5171, 202, 1343], [-23514, -3113, 7920, -1495], [29140, 6326, -2590, -1400], [8415, 8586, -5139, 2681], [17896, -5248, -3358, 1876], [-34597, 1141, 363, 696], [20444, -10221, 4478, -99], [29388, 5643, 384, -1339], [-13396, 2303, 14, 1709], [-10550, 7482, 3176, 1200], [-5280, 3394, -4226, -130], [-18844, 329, 2756, -2243], [27400, 1753, -3296, -673], [-54220, 2202, 3688, -374], [35837, -3779, -9, 2082], [-1008, 6028, -4088, 1394], [-43550, 4869, -942, 1341], [-13554, -12346, -8496, 1978], [10576, 8565, 3962, 1901], [-1366, 474, -1160, -78], [-13390, 5983, -988, -859], [-48156, 85, 4682, -317], [3642, -13358, -10408, -944], [-37493, -735, -1865, -5028], [-38981, -4434, 1227, 1761], [-32501, 6103, 1441, 2362], [15051, -1477, -2973, 4726], [19592, 4212, 928, 4248], [-5651, 170, 3663, -7653], [-23561, 2508, 2043, 921], [-13649, -10414, -8299, 607], [21032, -1220, -7050, 1774], [-22958, 5622, 3314, 4652], [4137, 1253, 7507, -1430], [-33560, -8315, 6704, -943], [-6573, -1973, -10165, -2974], [-37868, -3924, 8834, -1762], [-6530, 6892, 10210, 3446], [13123, 57, 7439, 4916], [-44674, 6101, -4774, -7025], [61360, -2876, -9650, 406], [20095, 9578, 909, 491], [-5160, -4126, 1324, 4024], [-10859, 9211, -6803, 534], [-41968, -4650, -374, -2832], [-11436, 8996, -3452, -134], [46376, -2260, -1712, 3184], [8037, -15573, -9033, -1174], [-30835, 8127, -7607, 996], [-28117, 7616, -1675, -1849], [33915, 4605, -2895, 4674], [-2157, -4101, -8403, 304], [21742, 9365, -2208, -4663], [-34008, 9558, -9732, -6970], [-73943, -395, 5533, -1954], [-21087, 3759, 4805, -5088], [27720, -11732, -360, 2948], [-8306, 5132, 7880, -584], [2577, 10142, 6289, -4819], [-51910, -11078, -894, 2046], [-20183, 10804, 1631, -3439], [-4752, -13661, -3250, -1185], [3341, -3043, -4799, 2536], [671, -5750, -5451, 9903], [1855, 4991, -4483, -5204], [28230, 6756, 12264, 152], [-61170, -12596, -7342, 3174], [23078, 9176, 3652, 1900], [-43027, -2425, -3409, 3774], [-22992, -5512, -9260, 6136], [372, 1267, -11552, 755], [-9906, -13550, -13282, 2096], [-25061, -15737, -3959, -328], [23149, 9788, -9611, -2825], [-27902, 8485, -400, 221], [11536, 1947, 7802, 2641], [37496, 3319, 9808, -3151], [26805, -15793, -6349, 4024], [587, -4919, 12405, 3918], [-14348, 12034, 5912, -934], [-9119, 4207, 12175, -5510], [9953, 10886, -6583, 3841], [67751, -10343, 3335, 410], [28124, 10950, -2966, -4700], [11061, 8651, -525, -4736], [-26201, 7147, 19595, -3760], [59621, -18637, -6541, -2906], [-36026, 16491, 3112, 147], [51598, -1846, 5344, -4880], [-21608, -5816, -3616, -256], [78964, -16880, 1672, -3418], [-21031, 11877, 3047, 1374], [9108, -11804, 5534, 1862], [38636, 2288, 6596, -5216], [39542, -14880, -7958, 2826], [58818, 3620, -14018, 634], [44066, 990, -7526, -636], [50412, 14587, 11364, -1843], [40380, 1240, 6100, 7712], [-39699, -1962, -12825, -4727], [-3201, 5106, 14927, -2943], [-55834, -4782, 15112, 294], [19205, -11299, 2677, -7226], [-1412, 26296, 10, -4520], [15700, 17601, 9440, -371], [23789, 5069, -15907, 2442], [-37682, -796, -4848, -5140], [-52144, 13575, -8690, -9665], [61432, 4341, -4368, -3279], [-27894, 9398, -10232, -1074], [-20628, -8814, -904, -5358], [19493, 11201, -5989, 9104], [-8669, 2703, 10115, -9740], [68204, 9577, 310, 2309], [-14478, 4168, -16936, -2806], [-75553, -1321, 16817, -5302], [-60390, -3903, 6504, -1155], [-19610, -9601, 15324, 5131], [-22510, 9267, -3752, 9495], [-35972, -7578, -8598, 3438], [70298, -8162, 5238, 5544], [4410, 26518, -14020, -316], [29066, 5452, -930, -5966], [-6874, -1139, 2410, 3503], [-36622, 1754, 1658, -6602], [57602, -5360, 7896, 986], [-16317, -4975, 20653, -858], [-16140, 5949, -1182, -7425], [-20566, -18814, 6890, 2298], [17288, 11476, -7238, 3974], [-55914, 17553, -9348, 175], [66138, -4300, 10486, -1164], [-68136, 14861, 1740, -6077], [10565, 1616, -5359, -7195], [-85227, -18355, 10493, 1546], [3364, -19396, -6850, 1642], [-61713, 16577, 14761, -1804], [-86830, -19242, 8202, -828], [100746, 10830, 9096, -842], [-36502, 510, -11020, 960], [60793, 18325, 3813, 1934], [13850, 4649, -56, 6643], [-81688, -6460, 2288, 2124], [-2138, -28660, 11916, 1800], [-14129, 2713, -9991, 1520], [11526, -13833, -2238, 10177], [-90774, 16428, 1358, 2700], [-17310, 5247, -9204, -2543], [17975, 16261, -19937, -298], [70288, -9773, 3574, 10523], [-51662, -8626, 29576, -3368], [6149, -10537, 3263, -11422], [10430, -29340, -2244, 6696], [-108186, -20784, -13534, 4398], [87494, -26666, -1852, -1672], [-74381, 6985, 5701, 9306], [-8930, -7568, 15184, -6208], [51419, -6709, 5035, 2782], [-66447, -18731, 8795, 878], [-82680, 5072, 9172, -8540], [61918, -18880, -8612, -2606], [52876, -19836, -400, -1266], [14213, -30936, 13915, 101], [-15469, 309, 6853, -7656], [5864, -26755, 3474, 2041], [23672, 33662, 21590, -1574], [-51595, -20239, 2615, -2158], [-36646, -9852, 15494, -5634], [-79858, 12360, -8304, -5988], [-87096, 4402, 13034, 1526], [-7411, -21350, -6465, 2971], [105352, -2139, 674, 13045], [-39739, 10271, -18025, 9794], [-12652, 7466, -8008, 9412], [104538, -21308, -3068, -4660], [89102, -40064, -9384, -8568], [75617, 22802, -23125, -1403], [-98321, -24525, -15781, 8032], [-58309, 8457, 6335, -10398], [-16787, 23964, -13331, -3015], [72570, 7053, -37242, 5657], [82134, -11892, -23606, 1764], [28719, -15898, 3503, 2365], [4502, -28630, -35470, -3280], [53373, -33057, -5799, -9810], [-46206, 21434, 11434, -4366], [79382, 8619, -6902, 2253], [-51128, 14164, -3232, -12190], [39574, -18391, -18582, -4325], [-39444, -17832, 20556, -11488], [75377, 21521, 977, 846], [22337, 13635, -20929, 5682], [-59980, 23588, -5638, 8830], [74068, 12082, -1006, 6596], [32882, -19395, -6530, -3911], [64916, -31938, 21022, 9032], [-7824, 7952, -16016, 4402], [101412, -31272, -8526, -2788], [114670, -311, -14236, -3745], [11470, 19099, -4496, 7649], [141794, 12250, 6170, -5902], [122887, 15539, -6743, -1448], [16812, 15760, 16704, 2654], [-66672, -10644, 1464, -6050], [-153818, -1896, 25260, -3468], [26084, 38805, 892, 1867], [13709, 5001, 15841, -4090], [140060, 25040, 19756, -8672], [5082, 23598, 19362, -5184], [-34459, 30062, 18969, -497], [-50299, -44347, -12883, 9034], [51396, -27438, -17010, -4644], [-28632, -4819, -4418, 2575], [-5582, 19926, 17804, -14766], [-128598, 1475, 18814, -2369], [49300, 26329, -10316, -5399], [-170344, -3646, 2436, 2296], [85575, 11560, 19343, -7371], [25302, 26265, -25062, -7183], [-6748, 8260, 17340, -3130], [116165, 18585, 2059, 1824], [46536, 30104, 20398, 812], [-96042, -23239, -22260, -4769], [38922, 23043, 27036, 2857], [-13138, 9882, 19160, -5118], [146338, 16329, -1918, -1325], [-146132, 10699, -22202, -17651], [-70124, 2904, 56, -6852], [-95503, 22904, 6241, -3899], [-21222, -27110, -26008, 10648], [11050, 19686, -27118, 12936], [114704, 8208, 23184, 864], [-27549, 30797, 1621, 7626], [-30494, 19746, 7202, 2166], [61512, -10383, 23364, 9933], [67202, 39220, 10592, -12028], [-3188, 33672, 12860, -15526], [-90924, -15852, -25236, -2266], [-23082, 7548, -27748, -1776], [93758, -28719, -2174, -1451], [-101244, -23359, 6226, 5423], [-60448, 6216, -12026, -21138], [-6804, -9777, 30218, 2715], [21530, -39588, -13442, 9034]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_819_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_819_4_a_h();".
// 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_819_4_a_h(:prec:=4)
    chi := MakeCharacter_819_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_819_4_a_h();".
// 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_819_4_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_819_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![26, 74, -21, -4, 1]>,<5,R![-27288, 4806, 145, -36, 1]>],Snew);
    return Vf;
end function;