
// Make newform 289.4.a.c in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_289_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_289_4_a_c();".
// 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_289_4_a_c();".
// 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 := [36, -4, -21, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [18, -15, -3, 1], [-26, -19, 1, 1]];
    Rf_basisdens := [1, 1, 4, 4];
    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_289_a();"
function MakeCharacter_289_a()
    N := 289;
    order := 1;
    char_gens := [3];
    v := [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_289_a_Hecke(Kf)
    return MakeCharacter_289_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, 1, 0, 0], [-1, 1, 1, 0], [4, -1, 1, 2], [10, 1, -5, 0], [1, 0, 2, -4], [-5, -9, 5, -2], [0, 0, 0, 0], [7, -13, 11, 4], [100, -25, 1, -4], [-15, -11, -1, 6], [93, -2, -16, -8], [108, 38, 46, 4], [210, -8, -4, -12], [-43, 50, 32, 24], [-17, 32, 42, -4], [5, 93, -65, -2], [222, 56, 64, 12], [139, -2, -46, 60], [-176, -158, 10, 16], [298, -36, -44, -4], [83, 130, 62, -16], [294, -212, 52, 76], [183, 37, -3, -84], [218, -20, -112, -44], [-224, 67, 149, -162], [-329, -158, -58, -52], [682, -136, -136, -68], [215, -372, -90, 40], [211, 228, -68, -60], [132, 61, -273, 66], [-517, 242, -104, 192], [1576, -14, -46, 104], [1004, 138, -38, -20], [-820, 75, -11, 8], [-126, 114, -122, -144], [689, -312, -342, -96], [-1236, 15, -267, -190], [121, 850, 120, -96], [1171, -135, -107, -4], [195, -102, 394, -24], [884, -257, -459, 136], [-275, -332, -116, -84], [583, -937, -29, 116], [-353, 116, 76, 48], [508, -757, 189, -142], [701, 206, 92, 284], [-108, 101, 203, -320], [1268, 219, -283, -276], [129, 138, 372, -444], [1968, -784, 248, -88], [2502, 718, -286, -144], [-2713, -180, 326, -308], [426, -683, 247, 142], [359, 181, -579, -32], [-1062, -1071, -729, 486], [1073, 173, 561, -512], [2739, 537, -737, 42], [-652, -583, -1061, 84], [2348, 88, -704, -208], [-3738, 215, -383, 210], [5900, -272, -440, 200], [2580, 50, 394, -132], [1808, 519, 101, 624], [-1691, 261, 633, 68], [-1548, 754, -270, -356], [-3079, -606, 126, 4], [-3882, -49, 733, 620], [-3399, -141, 177, -182], [-3305, 409, -855, -748], [-2021, 334, 1538, 244], [-357, 712, -400, 744], [-4158, 1075, -499, -1152], [3180, -202, 1102, 496], [991, -1132, 1108, 508], [-1439, -1178, -212, 144], [-883, 2835, -353, -320], [-2647, -1868, -528, -176], [-5269, -966, -582, -352], [2734, -1265, -835, -910], [2927, 1494, 582, -660], [2751, -1284, -82, 120], [2638, 315, 1601, -386], [4626, 171, 153, 1368], [3588, -1304, -752, 80], [614, -126, -1910, -1012], [4193, -2126, 1124, 724], [-263, -1731, 1827, 422], [-5690, -1069, -1463, 538], [-3034, 1088, -1460, 724], [5274, -1122, 494, 572], [-7866, 2139, -447, -180], [8603, -20, 774, 652], [-3413, -1587, 609, -1032], [-2618, 1185, 1815, 1220], [6972, -2413, 425, -128], [2251, 1724, -1254, -472], [9713, 566, 1282, -764], [-1392, 440, -2136, -120], [-5599, -2336, -1886, 1236], [-3897, 277, 3115, -962], [5627, 2090, -760, -796], [8696, 1204, 996, 856], [-4844, 1274, 4186, 1448], [8487, 2430, -910, 72], [-3149, -821, -533, 1008], [13541, 254, -2650, 588], [4291, 511, -1281, -676], [3447, 428, -428, -1512], [3171, 772, -1594, 60], [1989, -4823, -25, -338], [-4303, 796, -170, 1592], [-16484, 2950, -290, -668], [2637, 904, -2812, 540], [-4351, -4452, -1146, -316], [11107, 193, 517, -764], [-3007, -2187, -1973, 346], [7552, -2170, -1970, 3312], [-4103, 1308, -882, -2200], [-5747, 4970, -66, -628], [109, -1818, 2620, 680], [-15152, -505, -1843, -614], [-7960, 3004, 2476, 1280], [-663, 2853, 1023, -678], [-4021, -1445, 683, 928], [7472, 5016, -2516, -796], [-7863, -756, 3264, 1536], [-1011, -1351, 1523, -1010], [3925, 3938, 2068, -2056], [-9914, 2044, -1364, 1636], [-14195, -1801, -663, -1598], [-2289, -4680, -1854, 1880], [14565, 5050, 3596, -624], [7873, 216, 3090, -960], [-4455, 3468, -276, -2740], [19309, -4076, 1016, -268], [-5681, 2955, -1387, -3206], [-3151, 5952, 2280, -2372], [-4030, 3426, -206, -1084], [13317, 0, -3652, 2496], [6770, -1398, 1590, 1576], [-5324, 5218, 2002, 2184], [21485, -4934, 1554, -1736], [-10181, 2006, -428, 2424], [4167, 4758, -96, 288], [6822, 3626, -618, -1264], [10814, -390, -5406, 484], [-12029, -576, -1956, 2472], [-425, 2622, -1014, -1288], [1844, 5762, 1154, 432], [-20812, 2437, 1199, 52], [7280, 1713, -4785, -634], [607, 5311, -3927, -1798], [-15405, -1303, -4279, -400], [-7724, 6335, 1545, 1124], [-15099, -1961, -105, 928], [23986, 7231, 1689, -904], [5343, 113, -379, -1096], [4549, 4895, -387, -1762], [-16224, -2163, 1455, -2806], [10026, -1755, 3087, -486], [-8695, -5040, 4362, 1948], [-22712, 7093, -2269, -142], [31976, -1227, -3085, 1812], [-12832, 5095, 777, -2456], [-4167, -5327, -6697, -2394], [-28746, 5996, -1676, 1620], [5973, -923, -7607, -536], [1677, -10305, 2745, 3358], [-18521, 5410, 1354, -5292], [-12660, -7843, -6821, 2310], [-12969, 2308, 3578, 108], [8004, 5365, -6293, -1834], [14513, 4806, 2800, -56], [-21869, 794, -2298, 1216], [11232, 4992, -2196, 1940], [14239, -6215, -1533, 2138], [30583, -4083, 717, -2412], [5837, 3256, 7068, 736], [-23578, 5674, 514, -5148], [-13161, -1206, 1242, -2512], [-13044, 4685, -2485, -4588], [12652, -6078, -4654, 1664], [-33894, -1378, -2566, 2416], [16178, -7878, -3866, 1240], [2005, 252, 9546, -4852], [-20970, -5380, 4624, 2556], [-18189, 7726, 386, -932], [18137, -1454, 1072, -216], [5557, 11806, -410, -4116], [18767, 301, -7119, -224], [-8072, -1233, -2331, 2646], [-25039, -2584, -3386, 112], [-1380, -4742, -1342, 2384], [8770, -1910, -1546, 6752], [24039, -11276, -10, -3888], [-39131, 11536, -2040, -328], [5759, -4546, 2702, 5948], [2006, 3082, -5618, -4792], [-15657, 3506, 1234, -2244], [-650, -7217, 5169, 2096], [4459, 4111, 6669, -862], [17894, -5184, 5520, -6460], [24547, -9877, -6439, -3458], [1700, -5110, -4462, -1980], [12610, 12558, -5906, -868], [33049, -7566, -3294, 1040], [7915, -4619, 7369, -6788], [-34050, 4816, 200, -7332], [564, 6383, -8927, -1842], [-35052, -2860, 2796, -1456], [3230, 8626, 478, -2152], [29723, 5560, 7032, -3260], [-43377, 2011, 1063, 1204], [-16830, 216, 1152, -684], [-4778, 1638, 10614, -1516], [-9513, -13162, 1294, 2452], [-3437, -2557, 3159, 2620], [30153, -15031, 5191, -2622], [-92, 14706, -6142, -3808], [-16546, 5856, 3252, 5812], [16154, 6630, -2022, -5616], [-25513, 12375, 4251, -304], [-24711, 11014, -1234, 1428], [20583, -7462, 9512, 328], [50451, -3084, -2978, -3840], [4740, -12757, -8231, -1630], [26967, -10152, -3072, 9168], [-43494, 5713, 2771, 2400], [51174, 554, -5934, 2732], [23978, 6721, -7473, 4276], [18076, -7789, 437, 5362], [-35630, -10309, -10835, 348], [-20047, 12178, -4300, -5928], [14354, 6568, 2268, 868], [16365, 10288, 5078, -4048], [-8453, 10674, 1608, 5624], [-20730, -1648, -6580, -140], [-27612, -1474, 3030, 5940], [-13875, -2715, 8085, 3156], [-17238, -11310, -3574, 5844], [-58016, -5514, 4926, 440], [34145, 6055, 4295, 3744], [-7581, 14735, 3395, 1172], [26062, -11901, 3285, -5114], [33576, 8265, 2223, -726], [63376, 1812, -9852, 1088], [-29825, 1526, -4460, -4608], [-9517, -20742, 9980, 3328], [20979, 5518, -11560, -5152], [-11832, 7566, 13158, 3264], [4424, 14153, 9587, 318], [7379, 3125, -8049, -4550], [-10061, -6366, 6880, -1912], [-23198, 22938, -6570, 1680], [-13935, 13228, 5864, 5808], [-27350, 13381, 10299, -2236], [14141, 13254, 4366, -3424], [-7619, -2942, 676, -5772], [-66763, 1817, 4491, -4442], [31418, -15212, 5168, 7308], [-4416, -7916, -2276, 3040], [-53826, -13537, -8507, -3180], [35012, 14244, 9748, -5512], [-146, -24116, 8504, 7212], [31798, 1885, -7309, -3442], [35293, 13700, -4178, -1340], [-9598, -13225, 5485, -1730], [533, 12984, 10464, 2584], [-3967, -85, -8413, 8348], [23329, 5226, -1102, -4864], [-40134, -3419, 3367, -4118], [34861, 5807, 12207, 1780], [74247, -8073, 1953, -3682], [38051, -3607, 11045, 5940], [14772, -13668, 5436, -7024], [-39327, -7286, 652, -736], [-79748, 16782, -2146, -904], [-16575, -2967, 1107, 6986], [-20130, -17438, -12826, 2000], [-62089, 22533, 1221, 9964], [54762, -5578, -10178, 660], [4580, -17888, -1528, 11768], [-39578, -25460, -13780, -268], [-4348, -8161, -17723, -5742], [-37853, 16730, 2900, -3720], [-15693, 1776, 14502, 3048], [47578, -2167, -11677, 1110], [10709, -6590, -8838, 12496], [-44229, 12024, -1102, -1396], [-60823, -5258, 19358, 1012], [43473, 14966, 7414, -3216], [10485, 7708, 19454, 756], [2707, 2421, -17409, 4058], [-22471, 2293, -9787, -15308], [-18282, -5501, -2723, -12074], [87756, 14737, 10835, -5730], [-51176, -9952, -8312, 9736], [44163, -12723, 915, 7686], [37237, 8524, -15130, -1420], [2467, 24029, 14981, -1664], [21117, -1987, 14243, 2966], [-39405, -11096, 13664, 6132], [21678, -17818, 12806, 2644], [28622, -26919, -13145, -8108], [-24348, -17597, -915, -56], [17052, -2448, -10640, 13936], [25761, -38424, -2422, 204], [2879, 13695, 6493, 6650], [64706, -3221, -1395, 6064], [-51495, -5149, 13005, -5110], [-32017, -23307, 16577, 52], [39165, -10966, -12414, -4344], [-40977, -5422, 12082, 9180], [24451, -11776, 18482, 1528], [-14279, 2614, -5836, 4844], [-100680, -384, 8064, 4160], [-65701, -15930, 5856, 5512], [-26297, -8250, -14760, 2372], [-5355, -14511, -4809, -3614], [29949, -3705, 8397, -6918], [-45525, 16697, 14633, 2572], [-44684, 10498, -12774, -2676], [-42539, -32188, -13280, 2144], [-102845, 4448, 12150, -3272], [-26209, 8118, 20554, -7880], [48663, 10472, -6016, 5552], [32651, 31512, -19518, -2344], [-27723, -2894, 11144, -7808], [3011, 9904, -8166, 6604], [25956, 19861, -8269, -12042], [-17675, 10107, 10269, -1998], [23154, -11998, 10822, -4488], [124356, 4309, 3463, -1748], [-28688, 7923, 7529, -7864], [-4620, 4671, 14761, 2464], [-109236, -20696, -9028, 2604], [3689, 27122, 12878, 4140], [74852, -60, 148, 9472], [-19219, 39168, -10724, -9340], [27021, -33100, -13194, 1112], [-10509, 34307, -17407, -1390], [-106577, 7013, 8127, -2902], [-41684, 9381, 19859, -12850], [-56083, -8296, 19210, -6528], [30783, -7974, -5862, 15576], [-36788, 2282, 23538, 272], [46530, -23061, -2487, -4706], [-14851, -7354, 28036, 11592], [85933, -21052, -618, 8960], [84672, -10562, -10426, 14292], [40753, 14398, 2660, 7960], [1073, 22858, 18558, 15512], [-103860, -2243, -7873, 126], [-8361, 7745, 7157, -5360], [-40107, -742, -1206, -352], [-14845, 15918, 9274, 5560], [32070, 18991, 933, -6096], [18778, 3003, -5091, 11252], [6682, -30892, -25440, -13084], [-53724, 12042, 18786, 5088], [-11959, -16639, 7219, -7774], [35936, -3766, -19718, 2884], [81306, 16262, 15382, 3708], [72792, -34589, 8813, -6048], [-95502, 809, 5711, -14812], [-41765, 7462, 21734, 14284], [-1285, -37200, -8056, 3268], [-99328, -6611, -2621, -4548], [-6332, 1196, -3260, 3264], [80267, 10107, 9947, -6536], [48002, -4029, -4571, -4300], [89397, 28253, 241, -324], [-36111, 6959, 22105, 2694], [-2960, -16686, -5694, -13136], [24516, 2686, 21774, -1724], [57389, -4557, 7051, -5024], [108017, -6964, 4558, 14944], [-25618, 40796, -8632, 1380], [104559, 22327, -14439, -4146], [48561, 37093, -18341, 350], [52698, 12974, 18442, 16368], [46125, -18628, -12296, -10260], [-57755, 51226, 460, -528], [-28706, -27513, -18891, 12098], [-99598, 8460, -14900, 13772], [-86802, 7159, -16135, -8184], [61132, 15182, 7310, -10064], [-86593, 6185, -6601, -15990], [-17696, -1518, 24130, 13248], [-90975, -12696, -890, 5988], [-46299, 5285, 12995, 4858], [86717, 21679, -3343, -7442], [104776, 32560, -2080, 368], [56792, -19039, -18837, -2736], [54191, -19635, -16127, 11656], [-69091, -1027, -26029, -21514], [-20983, 35540, -8758, -17916], [55763, -21751, -957, 25186], [119611, 15049, 20105, -1404], [39472, -8420, -8676, -3016], [7650, -13998, -1794, -4352], [19601, -16745, 16949, 13090], [20667, -25288, -15754, -9760], [-31052, -18216, -14736, 3032], [46019, 39019, 24353, -8234], [13613, 12995, -22009, 17552], [79504, -26410, 13070, 4252], [-99488, 21222, 2678, 9980], [-31964, -40253, -15439, 12088], [-3387, 5428, -18934, 6960], [-28848, -29087, 6751, 13018], [-36065, 30968, 21588, 3032], [-34067, 2913, -32175, 4796], [84462, -818, -21762, -8516], [13580, -18435, 13971, -2718], [-107781, 4616, 18052, 13128], [74600, 7698, 6026, 16096], [-55217, 41632, -7838, -12156], [-75459, 17455, 2861, 11406], [28479, 8898, -22212, -19236], [-35611, 22348, -2500, -2708], [86950, 11761, -20189, -8838], [-20322, 574, -8098, -1548], [3020, 11788, -3904, 1780], [-11480, 35227, 6193, -13530], [57661, -39808, -1712, 25100], [35289, -12958, 10564, -8604], [-85913, -30676, 15964, 3272], [-155607, 20546, -6476, -12364], [97068, -58897, 14533, 11796]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_289_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_289_4_a_c();".
// 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_289_4_a_c(:prec:=4)
    chi := MakeCharacter_289_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_289_4_a_c();".
// 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_289_4_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_289_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![36, -4, -21, -1, 1]>,<3,R![63, 88, -55, 2, 1]>],Snew);
    return Vf;
end function;