
// Make newform 966.4.a.h in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_966_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_966_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_966_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 := [16751, 245, -356, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-1885, 1864, 12, -7], [6467, 305, -37, -1]];
    Rf_basisdens := [1, 1, 542, 271];
    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_966_a();"
function MakeCharacter_966_a()
    N := 966;
    order := 1;
    char_gens := [323, 829, 925];
    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_966_a_Hecke(Kf)
    return MakeCharacter_966_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 := [[-2, 0, 0, 0], [-3, 0, 0, 0], [-1, -1, 0, 0], [-7, 0, 0, 0], [-10, -2, 1, 0], [5, 3, -2, -1], [6, -2, 2, 3], [4, 0, -1, 0], [23, 0, 0, 0], [-12, 8, -4, 1], [36, 10, -2, 5], [-40, 16, 8, 3], [-154, 4, -1, 4], [53, 9, -14, 11], [152, 6, 17, -19], [109, -29, -11, -13], [63, 3, -15, -15], [71, -1, 13, 12], [13, -25, -22, 36], [131, 19, 38, -15], [-64, -16, 46, 5], [148, 10, -10, 17], [118, 28, -46, -7], [-377, 33, -50, -3], [166, -50, 32, 23], [-857, 21, 1, 17], [642, -8, 33, -53], [-385, -49, -2, 31], [-357, 23, -4, -46], [-347, 61, -30, -36], [-381, -19, -45, 64], [-1004, 44, 25, -42], [-424, -30, 91, -40], [-29, -87, 14, 32], [-1470, 22, -3, 31], [-1308, 18, 9, 57], [-70, -26, -9, -97], [231, 3, -29, -79], [-276, 20, 1, -48], [-1076, 120, 80, -3], [-1883, 31, -34, 0], [-966, -50, 8, 123], [484, -42, 59, -153], [-1014, -154, -27, 45], [-2937, 73, 54, 27], [-1203, 53, -15, 7], [-2062, -126, 169, 12], [1395, 89, -180, 6], [-1783, -13, 148, -140], [-1285, 201, -239, -31], [-837, 83, -84, -10], [-1201, -83, -82, -126], [-1560, -54, -275, 180], [-478, 38, 278, 66], [-3294, -90, 119, 41], [52, -64, -119, -2], [-2859, 183, -6, -231], [1094, -8, 64, -43], [-53, -65, 197, -202], [44, -270, 104, 162], [-153, -83, 154, 144], [2126, 368, -162, 120], [7932, -66, -60, -107], [1799, 57, -187, -80], [2352, 100, 59, 135], [757, -47, -170, 76], [1722, -456, -235, 17], [-2399, 63, 14, 129], [-4372, 110, -74, 281], [329, 113, -350, 142], [4988, 408, 300, -73], [2747, 37, 546, -228], [1905, 243, 397, -150], [3532, -92, -116, -393], [3608, -56, -2, -358], [202, 304, 234, -213], [-2332, -168, -404, -143], [36, -358, -72, 220], [-3026, 264, 105, 230], [-842, 302, -220, 427], [7555, -103, 356, 140], [-429, 445, 76, -273], [-1117, 389, 159, -240], [7166, 130, 289, -355], [2252, 422, 476, -153], [-372, 552, -52, 260], [-43, -91, -66, 292], [3889, -367, 214, 44], [2273, -827, -246, 124], [3780, -192, 37, 494], [-818, -528, -74, 555], [-136, -926, -424, 259], [-3254, 892, -260, -339], [8739, -121, 68, 57], [-4439, 51, 102, -60], [2865, 371, -550, 10], [-2062, -494, 75, -751], [-5074, 220, 8, -148], [186, -412, -505, 207], [-2586, -538, 319, 209], [3909, 1103, -246, 40], [-6196, -666, -344, -22], [385, -475, 370, -569], [-7980, -620, 365, 65], [-10036, -34, 460, 309], [9762, 744, -216, 156], [10311, -299, -137, -236], [-2808, -266, -124, -598], [-10889, 223, -476, -287], [4995, -549, 8, -442], [-819, -1175, -674, 481], [-15038, 222, 768, 407], [3615, -787, -10, -605], [7931, 767, -322, -291], [-8446, -340, -482, -115], [-7451, -507, -73, 396], [205, 151, -1109, 440], [-3487, 243, 82, 770], [-7973, -673, -1032, 978], [-4248, -822, 312, 289], [-1556, -14, 283, -1524], [6846, 280, -187, -158], [-10235, -629, 272, -769], [-804, 774, 424, 77], [-2201, 191, 1130, -81], [-7353, -1127, -743, -17], [-9223, -245, -326, 253], [-8784, 754, 740, 735], [14152, 280, 157, -440], [-9208, -1190, 112, -430], [-12648, -1006, -620, 221], [15577, 273, -581, -525], [-14181, 833, -26, 450], [-4172, -236, 758, 1235], [-4360, -560, -955, 645], [-7476, -1918, 400, -406], [-1944, 1284, -886, -815], [-3087, -503, 1119, 525], [-5232, -386, -436, 36], [-3279, -901, 1614, -969], [-502, -776, 866, -51], [-1480, 138, -134, -150], [-5091, 1025, -1179, -883], [10057, 1209, 887, 17], [-14202, 94, -456, -415], [-14315, -875, 648, 7], [7908, -302, -706, 2212], [942, -906, -441, -1161], [-9272, -2168, 88, -650], [8854, 990, -674, 1222], [-15556, -652, 1527, 431], [2052, 1770, 468, -482], [5387, -745, 2130, -15], [-9547, 1461, 994, 287], [-24573, -1323, -74, 78], [14298, -2078, 764, 202], [2898, -460, -406, -1615], [-793, -769, 570, -514], [962, 1116, -1123, -598], [-4130, -1120, 1762, -60], [20752, -248, -428, 942], [3185, -439, -1159, -96], [-7760, 244, -1988, 806], [18203, 443, -1176, 739], [-10951, 1197, 45, -346], [7094, -964, -1662, 291], [-3611, -9, 179, -494], [-2494, -986, -1298, 811], [3065, -551, -2174, 224], [-21381, 239, 697, 1634], [-2081, -583, -425, 2414], [23826, -260, 728, 268], [10415, 641, 1179, -1032], [20840, 916, 822, -1257], [8620, 176, 510, -50], [5564, -1776, -144, 1627], [-17391, 3091, 113, -544], [-2331, 1249, -1118, -184], [42695, 627, -291, 43], [-4403, -287, 514, -884], [947, -3389, -1851, -395], [14233, -2099, 468, 167], [3389, -1769, 1539, -7], [15041, -215, -1379, -2164], [6802, 418, -1479, -726], [-459, -3005, -1570, 1379], [-19580, 1292, 117, -1897], [36, -1254, 956, -1177], [-3231, 111, 587, 2561], [22318, 132, 1616, -1145], [5261, 313, -2, 2390], [-5701, 1141, 130, 718], [3970, -158, -2048, 1188], [7702, -2300, 447, 606], [-3921, -571, -289, -1940], [31071, -987, 384, -793], [12787, 729, 586, -1677], [-41504, -638, 1100, -670], [9422, 1376, -1974, 1302], [-4661, 107, -233, 1781], [-8352, -796, 499, -1203], [3920, -1448, -408, 3288], [-1293, -1809, -226, 1142], [13707, 1807, -7, -472], [15488, 1874, 790, 437], [21240, -3672, 613, 795], [15384, -1378, 916, 1061], [-11449, -1547, 1176, -2260], [-17101, 2515, 1564, 202], [15518, -896, -2966, -961], [16054, 3214, -1435, -437], [-45473, 533, -1541, 317], [-5144, 898, -1258, -2305], [-10176, 3264, -494, 198], [19867, 2483, -2082, -731], [-33427, 2005, 1934, 1604], [-8574, -1710, -741, -1098], [21059, -379, 1030, -1099], [23802, 1528, -2656, 731], [-35014, 790, 156, 1879], [-18709, -1509, -1279, 816], [7270, 636, 1619, -961], [-66271, 51, 1468, 143], [-20460, -1284, 1436, -640], [-19182, 130, -1331, 668], [16361, 1319, 2123, -1653], [1848, -1928, -1536, -1567], [-23788, -2500, -660, -1736], [17787, 27, 1990, -79], [20796, 14, -1072, 1953], [-15822, -456, -1479, 3626], [-30991, 885, -1278, 227], [-12599, -2345, 2018, 768], [-2406, 2352, -2994, 392], [21867, -1575, -2149, -2492], [41407, -4529, -422, 873], [11670, -2618, -963, -2393], [1318, -406, 56, 2079], [-31176, 314, 1080, 2653], [-60906, 164, 1280, 1263], [-17722, -1014, 3395, 1046], [7687, 2125, 2430, -788], [310, -566, -2096, 1472], [-45572, 1346, 759, -1168], [-33034, -1592, 2307, -370], [-10905, -3471, -1783, -652], [47872, 1404, -466, 182], [4352, 3824, -1486, 1170], [-6154, -1080, 2214, 219], [-70204, 0, 471, -2134], [-53212, -4256, 2286, -3007], [5054, -3656, 686, 866], [25086, -2094, 747, 3568], [67846, -1816, 75, -670], [23498, 2946, 3128, -343], [51154, 198, 1670, -1586], [34348, -844, -3030, -2233], [-56892, 1480, 453, 2728], [5679, -1757, -1809, -466], [37710, -1130, -144, 3819], [-3117, 2687, 3154, -969], [-6074, -1844, -2067, -2739], [-17387, -123, -1874, 898], [32670, 2992, 1611, -1424], [31663, -3897, 1643, 578], [-9506, 1754, -4405, 462], [-33604, 3256, 75, -3227], [-33196, 3736, -1336, -3397], [-50912, -1814, -3160, 1581], [3719, 5339, 2420, -1350], [-28030, 2230, -630, -2081], [94338, -4324, 654, 2327], [15947, 1405, 154, -2071], [-39154, 4210, 942, -2536], [18430, -3282, 4234, -285], [26564, 4012, 1306, 1000], [19828, 5018, 4944, -1593], [-43660, -2246, 2751, 2848], [9400, 752, -798, 2169], [-35726, -1944, 2384, -491], [-77096, 982, 2025, 3405], [19789, 1817, 362, -3023], [-11310, -3080, 3426, 3447], [-20226, 2454, -916, -3699], [35393, 1259, 1156, -2760], [63472, -1250, -2514, 329], [38120, -2492, -1064, -2541], [-45428, -1072, 999, -2963], [-12141, 519, 2326, 1203], [-35110, -1476, -4436, 5470], [66839, -2273, -3997, -3548], [31641, -3395, -200, -3001], [-21651, -1309, -5746, 453], [18920, -4830, -2348, 1153], [-19082, -148, 3204, -2310], [-14560, 2516, -1474, -2663], [-36320, -9112, -1916, -1196], [-20097, -2641, 1835, 1296], [-76794, -3546, 2247, -164], [77064, 686, 970, -1129], [-53589, -167, 1122, 1019], [-8382, 5324, -40, 2396], [-30324, 70, 2454, 799], [-93467, -221, 506, -2514], [-61284, 3804, -2782, -930], [11404, -3622, 1175, -2302], [50355, 1917, 4234, -4698], [30558, -2656, -531, 5640], [35500, -1074, -3343, 2963], [-63929, -4055, 3326, -2233], [16306, 3642, -2761, 782], [48790, 5286, 2732, 465], [22023, 9105, -547, -115], [-57694, -6144, -2988, 249], [-9916, -768, 917, -98], [-21932, 92, 3821, -7807], [-20666, 5026, -2509, 722], [-38108, 358, 1648, -2509], [-498, 528, -2567, 422], [-50720, -4602, 746, -1538], [-58734, 3160, 25, -3387], [17317, 5323, 4790, -1715], [-35505, -3895, 121, -905], [69372, 4588, -3817, -284], [21418, 768, -2761, 5880], [108869, -377, 159, 1399], [-54448, 5814, 2084, 75], [-71433, -3047, -1174, -2034], [57964, 5482, -4011, 3241], [-90630, 2938, -3271, 833], [-26742, 2440, -412, 4058], [-81734, -3434, 854, 639], [22855, 2391, -3574, -1635], [-19945, -3141, -1577, -499], [-19190, -2130, 2840, 3150], [-94838, -4772, 5751, -1329], [-3296, -574, -5264, 3794], [-48664, 154, -1228, -2084], [34731, -6349, 2950, 4102], [34265, 6351, 5046, -2516], [47196, -1140, 1596, 2283], [14276, -168, 6377, 311], [73137, -1143, -93, -3966], [3286, 2636, -1654, 4299], [-67472, 3308, 1735, 4985], [17649, 9005, -7616, -197], [24411, 4539, -1464, -1172], [34545, 3797, -3951, 1399], [51927, 4213, -1508, -5030], [-87246, -298, -164, 315], [-8421, 2815, 3020, 2781], [79770, 392, 1539, -2512], [-140306, -1726, 154, 2183], [-55019, 5857, 4367, 937], [-101126, -710, -5524, 837], [-86856, 2580, 147, -605], [-6322, -5618, 6022, -2366], [-106248, -458, -5450, 3079], [109084, -3592, 4884, 1079], [39880, 4606, 1778, 3185], [78522, 1462, -8050, -1945], [-64626, -2104, -515, 1702], [56508, -9270, 1600, 5709], [100162, 352, 943, -4935], [47806, -3262, -2072, -134], [-54136, -236, 599, -3461], [28615, -6805, -4993, -2254], [-2826, -3038, -4050, -4856], [120189, -5045, -1150, 4913], [-74025, -741, 4758, 4881], [104000, 4090, -4484, 4649], [18060, 1776, -3162, 1330], [-39410, 9662, 4345, -3027], [-97374, 3832, 2045, -37], [114992, -7928, 2616, 2791], [-305, -2667, -3758, 1872], [6309, -6907, 7137, 1743], [-97686, 2730, -3939, 1883], [-68798, -10356, 7310, -3778], [94098, -6646, 6, -1209], [88398, 11206, 2858, 1569], [-31537, -3403, 2526, -2465], [101252, 6158, -2441, 971], [29641, -4725, -528, -497], [44761, -1585, -9410, -870], [35913, -2053, -4947, -594], [57139, 5585, -5171, -2866], [-2022, -120, -4454, 3350], [12602, 2604, -1768, 2487], [-11198, 4534, -2228, -2932], [17230, 3706, 5202, 4773], [38283, 2277, 1185, -4665], [58736, -3012, 1030, -2200], [68578, -5170, 3584, 6202], [63405, -1277, 7817, -5648], [131927, -8685, -1386, 2768], [28980, -9252, 1339, 36], [38462, -4758, 560, 5189], [-28681, 2979, 896, -4507], [58842, -4810, 2744, 5547], [2122, -1470, -3286, 1005], [126937, 379, -2044, -2881], [48918, -5626, -5210, 2402], [46429, 2495, -4190, -2525], [-101707, 6977, 3003, 1108], [69583, -7957, 2856, 3123], [87210, -7476, 218, 1656], [-836, 5554, -6848, -174], [-39164, -4584, 3900, -9432], [-60081, 5117, 5650, 1580], [154365, 6447, -838, -925], [35264, 8654, -4540, 3092], [-79810, -9200, -2231, 1107], [91591, -9537, 894, 2523], [102451, -2315, -3754, -5247], [37202, 5980, -4000, 6088], [129366, -4220, 3130, 315], [37932, -410, 4020, -1217], [58108, 10768, -1518, 1623], [-74838, 8802, -4048, -2986], [27110, -5494, 2652, 4427], [160152, 4102, 725, 828], [-50941, -1035, -5016, -2020], [47165, 5033, -1382, -3437], [125879, -731, -2092, 3671], [-15386, 16182, 2387, 1589], [3989, 9803, -1491, 2518], [-72280, 6790, -11976, -1330], [-5509, -5379, -7796, 4650], [2999, -4247, 5577, -360]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_966_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_966_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_966_4_a_h(:prec:=4)
    chi := MakeCharacter_966_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_966_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_966_4_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_966_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![16152, -950, -347, 5, 1]>],Snew);
    return Vf;
end function;