
// Make newform 966.4.a.j 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_j();".
// 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_j();".
// 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 := [1050, 17, -171, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [42, 471, 2, -3], [-910, -189, 10, 1]];
    Rf_basisdens := [1, 1, 64, 64];
    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, 0, -1, 0], [-7, 0, 0, 0], [6, -3, 1, -1], [-18, -2, 0, 1], [-5, 10, 5, 1], [-14, 5, 1, 1], [-23, 0, 0, 0], [-57, -4, 11, 11], [19, 6, 11, 9], [-39, 12, 9, 3], [-118, -13, -7, -13], [-116, -6, 0, -11], [-59, -19, 26, -8], [-50, 5, 9, 28], [44, 37, -11, -12], [-509, -29, 6, 5], [-93, -2, -27, -22], [-406, 50, -6, 3], [-121, -38, -55, -15], [-545, 2, -33, -1], [245, 2, 5, 63], [524, -90, -18, -61], [-199, -56, -75, -41], [632, -7, -37, -80], [251, -57, 46, 38], [348, -78, -28, 27], [-885, 32, -27, 26], [79, -18, -77, -140], [-51, -63, -116, -73], [310, 161, -39, 3], [216, 47, 95, 17], [-2097, 90, 37, 8], [-63, -155, 56, 30], [-269, 147, -90, -44], [-1297, -35, 106, -124], [98, 101, -57, 42], [84, 105, -17, -23], [-751, -80, 17, 119], [-1459, -82, -281, -152], [-435, 260, 69, 47], [887, 67, -230, -12], [-1835, 255, 82, 112], [172, -122, 14, 181], [-928, -341, -189, -28], [-2456, -233, 157, 201], [1093, -188, -143, -232], [91, -152, 115, -8], [-2672, -161, 89, 22], [-519, 48, -169, -88], [-2163, 334, 183, 10], [-2670, -125, 217, -17], [2956, 74, -50, 280], [2219, -41, 116, -70], [-454, -191, -171, -295], [242, 178, 8, 221], [-2515, 252, 31, -201], [-2169, -25, -74, -245], [-826, 84, -60, -114], [1729, -490, -41, -272], [2430, 270, 86, -38], [-1041, -216, 57, -25], [-2509, 461, 26, 29], [-2107, 277, 96, 420], [-439, 18, 93, 324], [2085, 247, 608, 296], [1066, 362, -440, -337], [675, 22, -153, 513], [-2657, 182, -85, 118], [3691, -276, 47, -171], [4629, 234, -409, 112], [-1737, 191, 444, 639], [1021, -220, 181, -93], [4682, 286, -128, -276], [-457, 930, -173, 101], [-2067, 148, 625, 73], [1348, -276, -254, -348], [3940, 109, 249, 733], [4839, -300, 267, -299], [-1827, -1176, -403, -160], [2306, -464, -250, 271], [-7451, -217, 122, -417], [9089, 463, 254, 76], [-2867, 408, -177, -115], [5076, -748, 420, 112], [7741, 438, -55, 112], [2359, 194, 803, 586], [-907, -1058, -455, -210], [1984, -237, -127, 339], [431, 902, -441, -231], [3381, -88, 707, 323], [1775, -1016, -571, -249], [-2178, -356, 648, 765], [11897, -578, 31, -418], [4961, -294, -341, 580], [-4509, -565, -84, 342], [-7486, 992, -240, 292], [-4441, -467, 460, 772], [2385, -659, 180, -654], [-663, 1242, -461, 46], [2382, 1600, 1144, 394], [7720, -1050, -136, -299], [3965, 177, 724, 152], [471, 796, -91, -151], [1490, 256, 544, 592], [1019, 463, -156, -529], [-2682, -712, -296, 390], [134, -980, -308, 229], [-10671, 300, -293, -560], [-6264, -54, 1032, 607], [-14917, 1148, 235, 975], [-2396, 578, -286, 355], [-1730, 1026, -406, 1061], [10085, 866, -131, -101], [-10485, -869, -6, -729], [11033, -1435, 20, -817], [-5757, -302, 325, -984], [-4663, -56, -45, -1200], [5913, -1284, -369, -699], [-6070, 1609, 531, 797], [1742, -1197, 101, 667], [-3512, 1868, 504, 995], [-6525, -1004, 401, 1083], [72, -670, -168, 221], [-184, 241, 183, -240], [7666, -938, 772, -317], [-5973, -400, -19, -175], [11314, 435, 67, -885], [-10562, 812, 372, 26], [-4863, 1112, -157, -245], [70, 75, 1069, 166], [-5977, 1682, 1089, -4], [8493, 1714, 879, 1093], [-12335, 61, -1372, -368], [-1686, -1112, 1332, 1150], [11471, 554, -499, -221], [5686, -79, 127, -904], [7816, -2456, -842, -184], [-7990, 214, -1248, -1399], [6317, -74, 425, 1705], [-11038, -1082, -1894, -1768], [7932, 419, -345, -644], [-216, 2243, 939, -152], [4825, 556, 1109, 1879], [15472, 800, 1390, 967], [-14004, -266, -600, 122], [3113, 1087, 2142, 696], [15354, 1100, 1406, 1422], [-14732, 2410, -1498, 156], [-10827, 165, -708, 536], [-9422, -312, -1748, -1154], [13656, -3354, 444, -867], [7520, 414, -324, 1195], [-16873, -2246, 1521, 960], [-1628, -620, 276, 1114], [18185, 834, -455, 291], [-21135, 310, -2003, -536], [2334, -1429, -727, -75], [-16126, -2910, -58, 882], [-2162, 1632, -2242, 118], [-17273, 3997, 372, 537], [10950, -772, -450, 570], [-3874, -4028, -1448, -217], [1273, -671, -1018, -749], [18559, 1250, 1715, 481], [5229, 377, 1824, 833], [13771, 2302, -2543, -1697], [-14365, 2542, 411, -130], [3789, -139, -1406, -1733], [-361, 1475, -2724, -711], [-4346, 1504, -528, 20], [-10939, -3301, 822, 1315], [-37775, 1714, 363, 385], [7142, 894, -604, 1796], [40149, -380, 661, 583], [-513, 2531, 1856, 1029], [-34983, 446, 769, 1872], [-4610, -2033, 1341, 1324], [7063, -658, -229, -340], [32438, 2683, -1823, -756], [31844, 2180, 1174, -205], [-14084, 2165, -1657, 1098], [8709, 1673, 2150, 229], [-15888, -1495, -421, -2555], [-17628, -490, -1526, 517], [-8599, -2081, 862, 1654], [32887, -744, -1723, 1387], [-6132, -3795, -1229, 582], [11241, 4484, -49, -1171], [-11701, 2946, -1785, -30], [-25711, 1334, 631, 1466], [-14098, -2936, -1050, -416], [-7484, 2003, 2499, -695], [-4655, -349, -1102, 1131], [-4778, 1184, 3186, 43], [-22930, 3470, -1060, 765], [-218, -368, 272, -2974], [4940, 1518, -2208, 672], [27832, -3733, 47, -2922], [-2491, -1885, -1470, -1886], [-10612, 264, 2548, 3588], [4925, -4066, -847, -742], [1407, 627, -1214, -3611], [49075, 2418, -1365, -1277], [-31277, -1555, 486, -86], [31033, -5548, -625, -2951], [-27397, 1292, -3081, -74], [-9543, -3316, 291, -1656], [-21025, -290, 7, 391], [-15205, 999, 2940, -1610], [-1044, -3581, -3107, -4790], [2025, -646, -2491, 1513], [27970, 4738, 1004, -1004], [432, -2342, 4132, 1345], [2123, 4542, 3023, 1240], [-26794, -3651, -4411, -2423], [-38768, -4410, -1234, -407], [-7075, -5496, -2781, -2261], [16311, 3352, 1811, -867], [23813, 3019, 708, 3037], [-7585, 4669, 1412, -980], [2098, 5104, 4222, 1883], [-23188, 1552, -2676, -1036], [53606, 517, 1593, 3317], [-16794, 1221, 101, 472], [6323, 3796, 3351, 4097], [-4224, 2988, 2868, 1128], [-5034, 3182, -338, 3473], [-34637, 764, 3569, 1035], [-2670, -1097, 2537, -2017], [-786, -3930, -1286, 1343], [-33317, 386, 4729, -322], [-21590, 2274, -786, -2210], [48347, -1211, -962, -3617], [17424, 6482, -408, 59], [33799, -3557, 1492, 1398], [24073, -3704, -1107, -5593], [-34857, 4920, 617, 2659], [-27439, -3388, -2953, -1735], [-1224, 4431, -3139, 439], [2895, -6394, -2047, -2516], [-36114, -2396, 3202, 172], [-12334, -1143, 4123, -437], [19164, -5105, -1981, -411], [-15333, 2953, 4294, -1639], [30702, -1786, -524, 3724], [2738, -2830, -2372, 2940], [-19709, 3158, 4587, 629], [29382, 831, -1677, 975], [-22833, -1766, 1693, -3893], [21936, 878, 1452, 28], [34638, -3917, 1595, -311], [-9014, -2739, -2389, -1817], [-55745, -1528, -1713, -3489], [-93984, -1834, -462, -284], [-33667, -4018, 683, 861], [13694, -3481, 5531, 667], [3581, -1413, -5948, -435], [21107, 740, -2113, 3793], [-20750, 634, -394, -891], [24863, -5199, -1640, 1140], [10399, -2830, 1967, 1662], [-58476, 2097, -2131, 1205], [2433, -2369, 2672, -443], [-27898, -599, -5035, -293], [43557, -4581, -1910, -2374], [25173, -1344, 4601, 3075], [-12117, -2180, 4313, -3091], [-37159, 984, 2987, -500], [-6105, 5490, -2831, 3395], [-28725, -2850, 2659, -171], [-10078, 6290, -1404, 2617], [45318, 490, -2724, -1814], [-20697, -7990, -5699, -4369], [39904, -558, 4918, 2906], [29137, 1548, 1563, 3493], [18226, -8191, -837, -2953], [-19881, -666, -5063, -1013], [12933, -2464, 2319, -2735], [-29563, -4491, 4202, -432], [3874, -702, 2426, 2359], [1239, 3562, -1181, -3687], [-17641, 472, -929, -4419], [57869, 408, 1317, -2570], [-11549, -6854, 4527, 1425], [32213, 3532, 5773, 4219], [18885, -4777, -4010, 654], [10120, 1786, -3468, -1827], [-53832, 5008, -1494, 2306], [-5783, -7285, -752, -1837], [9008, 8408, 342, -3989], [55152, 3362, 2886, 763], [-277, -1236, -3031, -2415], [2688, -7692, -6510, -1522], [9463, 7114, -1267, -1657], [30276, -2044, -1400, 352], [-69481, -4977, 1286, 2091], [16902, -7217, 663, -349], [-45923, 3730, -1175, 503], [-6920, 7538, 734, -2169], [-3518, -8296, 4952, 972], [-33503, -38, -1835, -1795], [-22497, 2834, 4713, 6322], [31882, -10446, -3060, -4240], [-59764, 2489, 2181, -5671], [-3787, 4650, -2073, -4958], [-114924, 1687, 159, 2315], [-36621, -7151, -3712, -1326], [63742, 162, 512, 4179], [17080, -7697, -823, 1369], [-67989, 2036, 5711, -4443], [-37766, 1137, -7355, -1182], [7039, 8144, 1449, 975], [51010, -3315, 2337, 2473], [10031, -1349, 2160, -552], [9004, 5939, -499, 6405], [15241, -3292, -5913, -3671], [-37678, 4223, -2839, 621], [35910, 714, 230, 1716], [-38579, -5373, 5192, 1140], [64154, -4142, 5360, 2335], [-30194, 2929, 2397, 2886], [-47966, 1353, 873, -1449], [14534, 5899, 905, -223], [-47008, -1643, -8969, -5990], [-24551, 9732, 827, 4591], [24421, 4402, 6879, 2102], [-29563, 133, 3138, -4940], [77671, 6993, 4702, -932], [32412, 1500, -2090, -2322], [-37289, -3826, 2301, 1807], [-59234, -2130, -758, -4681], [43684, -14293, -3337, -4326], [-13828, -10496, -1624, 34], [27037, -6237, 8068, 324], [-68942, -5532, 3432, 4582], [137844, 2128, 554, 744], [-37007, -2566, 261, 3102], [-19045, -2466, -8503, -5272], [-20917, -5432, -449, -779], [19803, 2973, -4510, -1094], [-52225, -7961, 5098, -499], [-87965, -190, 5599, -1159], [-47799, -5529, 2426, 3514], [-13014, 17972, 8080, 2739], [-83001, -4560, 4909, -1058], [152606, 3063, 6293, 2966], [-31721, -7628, -4977, -7990], [81047, -1480, -373, -5677], [-41102, 1148, 10612, 957], [-21720, -1099, 401, 7383], [53479, 6382, 1981, 8331], [25462, 1557, -357, 4308], [78073, -3896, 1521, -1275], [24499, 4851, -6236, -3684], [8332, -7934, 2894, -5216], [-65011, 634, 7777, 4689], [-29595, -1288, 4781, -1479], [-31457, 3322, 3811, -2363], [-66237, -6042, 4233, 5909], [11688, -4127, 5413, 4939], [-8845, 968, -5079, -2517], [11931, 803, -2302, 5514], [44428, -3208, 3580, 5558], [35765, -459, 6832, 5064], [101669, -6677, 1228, 949], [-39102, -4714, -10020, -8786], [-97046, -350, 5736, -3461], [-44150, 7122, -1578, 3463], [-142805, -3080, -1011, 1535], [46494, 6630, 4612, 7916], [162111, 5057, -3738, -6372], [57627, 14235, 2442, -142], [12911, 9404, 871, -5327], [-155721, -6502, 4057, 2546], [55862, 6681, 343, -3444], [4031, 9811, 4636, -4802], [90072, -8390, -8952, 1132], [9415, -1526, -9275, -113], [-92567, -1578, -525, 4711], [-30984, -3406, -2122, 4631], [-10151, 7421, -7818, -7248], [34266, -4972, -6854, -2661], [-9603, -2390, -2053, -4478], [101719, -1011, 5010, 1023], [12291, 9991, 3064, 3959], [-2864, 12274, 3340, 6776], [-84757, -2000, -5895, -4113], [136870, -5912, 3982, 428], [817, -706, 3123, 8059], [8438, -10383, 2637, -1654], [796, 3642, -13202, -4294], [-18228, 2980, 3256, -9874], [134515, 8633, -2082, -4571], [-25899, 13878, 621, 4278], [85178, 1837, -7311, 889], [72089, -3084, -8107, 3241], [11900, -5688, 4926, -1107], [120699, 2472, -1209, -1287], [-1563, -9378, -3665, -4175], [69330, 2292, -2438, -6145], [49752, -5630, -7662, -1836], [205152, 1174, 4854, 1129], [-60431, -1633, -7504, -8893], [-92476, 2864, 4514, -5049], [-9570, -4906, 8070, -950], [98366, 6044, -2596, 4154], [-64300, 11088, 4516, 5960], [77479, -7286, 3633, -158], [58634, -9054, -2324, -2243], [90256, 2636, -3402, -4468], [3737, -10587, -3694, -9378], [-20518, -3054, -10954, -9107], [66204, -2794, -6962, -6073], [68058, 2196, 1336, -8916], [-135393, -8858, 2091, 5671], [36029, -256, 4159, -6123], [104301, 8674, -4273, -1471], [34344, 13088, -4740, -3422], [33953, -5428, -3975, -6157], [16230, -16217, -7551, 1099], [111403, -1460, 3851, 9814], [151708, -4978, -6796, 367], [-10136, -3076, -1592, -5157], [31263, 7531, -2184, 7658], [35397, 21185, 4372, -1193], [58998, -19000, -9440, -7842], [15325, 2252, 3805, -2036], [-87229, -1535, 566, -13939]];
    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_j();".
// 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_j(: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_j();".
// 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_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_966_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![5152, 1634, -335, -5, 1]>],Snew);
    return Vf;
end function;