
// Make newform 2352.4.a.cn in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2352_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_2352_4_a_cn();".
// 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_2352_4_a_cn();".
// 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 := [382, 0, -40, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [20, 40, -1, -2], [40, 12, -2, 0], [-140, 0, 7, 0]];
    Rf_basisdens := [1, 3, 3, 3];
    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_2352_a();"
function MakeCharacter_2352_a()
    N := 2352;
    order := 1;
    char_gens := [1471, 1765, 785, 2257];
    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_2352_a_Hecke(Kf)
    return MakeCharacter_2352_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], [-3, 0, 0, 0], [2, 1, 0, 0], [0, 0, 0, 0], [-10, 1, 1, 1], [12, 0, 1, 1], [18, -3, -1, -2], [-8, 2, 5, 2], [-2, -3, -1, -3], [36, 12, 5, 0], [-12, -6, -9, 2], [12, 14, -2, -10], [18, -3, 11, 20], [-128, -2, 10, 10], [-40, -2, 11, -6], [134, 12, -6, 24], [-60, 30, -7, 26], [224, 10, 1, -29], [-272, 22, 2, -38], [-322, 13, -33, 25], [372, 18, -26, 1], [-104, 36, -20, 24], [28, 32, 26, 4], [790, -25, 39, -28], [596, 22, -24, 25], [650, -71, -26, 14], [-876, 18, -21, -10], [-158, 63, 55, 51], [-208, 18, 32, 66], [-186, -76, 24, -28], [420, 50, 66, 158], [-1316, 8, -18, -76], [-232, -58, -67, 74], [164, 16, -12, 4], [206, 4, 2, -152], [892, -30, 26, -222], [1768, 86, 93, 113], [-16, -106, -110, 38], [408, -54, -53, 146], [1086, -45, -152, 18], [170, -57, 3, -261], [804, 168, 95, 63], [-66, -151, 11, 29], [-1158, 4, 96, 220], [346, 224, 2, 164], [432, 120, 56, -132], [1532, -140, -8, 184], [968, 328, 24, 84], [620, -38, 45, 162], [1692, 60, -209, -201], [1520, -142, 91, -178], [134, -27, 119, 357], [3956, -146, -60, -25], [340, -178, -129, -218], [2866, 29, 125, 164], [730, -5, -131, -281], [3374, 79, 6, -156], [-452, 170, -13, 462], [682, -212, -176, -332], [2624, -414, -245, 174], [3768, -198, -31, -258], [1794, 141, 86, -82], [2872, 14, 23, -626], [1472, -158, 93, 270], [1592, -8, 306, -293], [3922, 108, 198, 48], [1596, 212, -208, -244], [-2696, -324, 238, 468], [-2386, 257, -63, -103], [2376, -330, 37, 429], [2510, 235, -205, 42], [2298, 235, -59, -125], [4696, 404, -82, -504], [-1934, 136, -260, 136], [3988, 472, 340, 520], [3208, 68, 56, -368], [3716, -56, -35, -980], [-4584, -246, -113, -521], [6160, -46, -125, -418], [3148, -190, -300, -115], [1724, 322, 103, -346], [-5758, 316, -76, 868], [4422, 189, 199, 501], [-560, 140, 298, 661], [5016, 360, 412, 792], [-262, 187, 7, -689], [3622, 172, 92, 484], [-5410, 424, 592, 40], [2254, -61, 144, -722], [8380, -534, -602, 210], [7948, -106, 215, -490], [8776, -298, -385, 258], [3732, 498, 306, 786], [-4274, -243, -235, 129], [4536, -206, 438, -542], [2288, 208, -270, 860], [-6858, 171, -134, 308], [1726, -397, 37, 750], [5868, -108, 326, 1052], [-7954, -244, 360, 548], [5148, -152, 612, -476], [-62, -28, 58, -1264], [5348, 1078, 157, 778], [7824, -230, -335, -50], [-4852, 620, -712, 656], [872, 172, 132, 157], [6004, 242, -667, -358], [3538, -787, -495, -398], [11102, -131, -201, 337], [-2728, -1076, -112, 351], [6152, -1088, -596, 476], [-3536, -946, -370, -1354], [776, 330, 873, 270], [2860, -724, 694, -124], [6956, 546, -570, -750], [3904, -166, -161, 518], [-3168, -1926, 81, -74], [752, 154, 847, 1642], [5508, -652, -47, 920], [-3066, -327, -843, -711], [-7152, 630, 163, 773], [-12340, -688, -820, -856], [-14306, 659, 696, -586], [3770, 827, 983, 479], [-3820, 580, -202, 1256], [772, -1536, 167, 300], [-9720, -842, 1220, 1318], [-6472, -632, -642, -2220], [1788, 810, -593, -234], [-6868, 400, 593, -785], [-6848, -1102, -714, -46], [-8866, 985, 719, -167], [-920, -136, 1388, -172], [-8176, -606, -216, -126], [7694, 1411, -191, -672], [6784, 1100, 566, 1637], [-16250, 71, -154, 1482], [-13916, -1204, -330, -432], [-11654, 1001, 348, 162], [7618, -332, 332, 1948], [-16876, -68, -786, -300], [23234, -1292, -358, 88], [-5848, 1656, 24, -252], [530, 219, -385, -633], [-11548, -1448, -1153, -2555], [-12376, -1166, -1321, -1294], [-10296, -858, 461, 1209], [9934, 923, 241, 2400], [-12536, -922, 1079, 142], [2326, -1079, -937, 397], [-11872, 146, -1798, -310], [186, 249, 725, -474], [-2000, -2070, 166, -1398], [-8632, 958, 1509, -490], [4240, 574, -158, -1082], [-514, -1847, 747, -503], [8772, 506, 86, 1502], [31662, 435, -375, -32], [176, -1016, 236, -881], [-13010, 2135, -352, 1600], [14818, 1055, 623, 3287], [5682, 704, -996, -3016], [1276, 602, -1790, -1762], [-13420, -2192, 368, -432], [768, 330, -179, 4830], [-26088, -1200, -112, -224], [-5452, -798, 590, -882], [-13344, -1026, -1061, -747], [878, 924, 872, -3180], [202, 209, 400, -1806], [27018, 2511, -189, -573], [-14568, 3090, 691, -177], [7534, 3165, 951, 2025], [8764, 96, -122, 4560], [-18752, 1496, -260, 464], [9110, 583, 307, -1162], [4844, 1876, 2032, 388], [7076, -740, 1579, 1000], [-7260, 1938, -545, 1530], [-12192, -618, 1063, 3617], [-6456, -476, -1264, 2068], [-3788, -1144, 740, 16], [16908, -3162, 888, -1722], [30686, -1205, 215, -1006], [15550, -895, -1189, 785], [-16122, 615, -760, 2966], [-20494, 64, 1432, 616], [-18764, -496, -708, -3020], [-2476, -1508, -2738, -308], [-28712, -1024, 530, 3148], [26236, 1598, 1062, 2823], [40054, 1601, -915, -859], [-20396, -1460, -1560, 832], [-14998, 1777, 1464, 182], [37514, -2489, 847, -1925], [17538, 357, -335, 3110], [-17220, -2100, -108, 3156], [-292, -2514, -536, 1950], [-20346, -57, 35, -876], [-2808, -4170, -581, -1910], [-12578, -1480, -3002, -4132], [-17728, 3244, 506, -20], [-22548, 1932, -105, 2693], [5508, 1530, 290, -3889], [-23052, 12, -1678, -2684], [-30050, -1573, 906, 214], [-20152, 1504, 60, -1544], [29830, -2407, 813, 689], [-2618, -2864, 1072, -1616], [-5096, 26, 2521, 1050], [5120, -3292, -1228, -3820], [-20266, -269, 520, -896], [-9332, -2970, 390, -1698], [3892, 1652, 1722, 3996], [752, 1246, 1239, 5066], [19496, -2432, -1350, 1081], [-40820, -2994, -206, 786], [870, -1713, 1085, 3642], [15358, -2843, -513, 2377], [14276, 3208, 2197, 1900], [14800, 3030, 572, 4422], [-580, -2570, -3071, -3322], [-37598, -2700, 816, 1212], [-53584, 452, -456, -2848], [29172, 924, 216, -2264], [33356, 2838, 290, 1998], [25998, 387, -5, -6308], [-3422, -1341, 2989, 2379], [53604, 522, 619, -1054], [-9270, -4477, 467, -3229], [26520, -2242, 1992, -5122], [27976, -3154, -1533, 1626], [-69356, -870, 1822, 1782], [-2930, 3068, -2288, 1820], [-9240, 774, -1277, 5650], [32504, -20, -1494, -332], [15468, 3042, 2376, 5103], [20758, -3568, -2578, 2852], [43198, -2639, -1155, 589], [9272, 1972, -948, -2352], [-12554, -2527, 465, 2369], [35164, -1984, 512, -4984], [24416, -1712, 232, 504], [-23490, 2988, 388, 6348], [26698, -3055, -2163, 1688], [16232, 1054, 1533, -754], [30388, -946, 1005, 834], [24108, 3750, 515, -266], [-7132, 260, 264, 4664], [-22062, -637, -3179, -1009], [7762, 352, -1212, 4696], [406, -3049, 2891, -910], [-5194, 4413, -445, 249], [18876, -1338, -1558, -745], [-7918, 2149, -434, 5006], [50130, 4887, -917, -2997], [11828, 1218, -1196, -6462], [32152, 998, -1025, 1486], [-12230, -271, 590, 1274], [-152, -3736, 3102, 1465], [-6480, -1020, -1632, 4092], [23582, -3055, -843, -2023], [-8132, -124, -85, -1015], [4976, -842, 535, -203], [4834, 3461, -1765, 442], [19180, -160, -404, -6904], [-41618, -1576, -322, 4172], [28018, 1541, -1327, -3694], [-50060, 2928, -676, 1680], [42964, 964, -1417, -6800], [-67472, -3958, 705, 3709], [3588, 1044, -880, -2436], [24588, -4650, -4294, -553], [-448, 396, 960, -4560], [-40908, -2142, -858, -2933], [29020, 746, 971, -1078], [20722, 3739, -997, -509], [-31286, 132, 840, -8364], [11922, -5812, -1056, -2524], [34596, -4830, -1891, 4906], [32784, -1608, -3516, -1288], [-31756, -2062, -3722, -3646], [83184, 3036, 790, 4372], [6752, -1574, 237, -3101], [24380, -1532, 1170, -5676], [20366, -35, -3741, -4883], [-2150, 5304, -1472, -312], [-29838, -1680, 34, 6780], [29436, -1974, -449, -314], [20214, 1887, -1721, 1648], [-41874, 2864, -338, -5164], [32140, -7156, -1408, 1248], [27680, 538, 2977, -866], [-27916, -338, -1227, -3814], [25686, 4592, 204, 3728], [15050, 4177, 1204, -4806], [-31840, -1820, 666, 776], [15698, 6769, 2654, -456], [-52412, -4054, 4181, 4450], [73580, -2168, -1680, 3040], [20816, -5660, -1046, 155], [-111732, 1128, 991, -3948], [32604, 5958, 730, 2334], [58206, 145, 4553, 3313], [-49364, 3444, 2384, -3120], [45088, 1408, 914, 3688], [-62362, -3575, -891, -1703], [45548, -7292, -877, -2995], [-17270, -7769, 261, -1001], [64642, 3212, 1072, -676], [-12416, 1568, 3012, 2000], [-36972, 4192, 6195, -1988], [43568, -5202, -1513, -3846], [26456, -4998, 1726, -2058], [-14274, -5871, -1897, -1203], [52228, -7222, 1122, -999], [-29916, 1356, -374, -2372], [-42698, -4779, -2681, -4335], [68180, -446, -1374, 3973], [-4968, 4134, -1133, -2814], [7256, 2890, -2351, 1862], [46060, 1128, 2712, -7104], [32822, -3641, -2494, -1438], [73684, 1286, 3002, 8210], [75418, -3828, -2320, 2628], [87140, 3742, -764, 2069], [7520, -2434, 3834, 2990], [-59784, 942, -321, -2598], [-146394, 1677, -937, 2901], [59004, -1644, -2947, -1464], [-38050, -4640, -3416, -3224], [-2220, -1980, -3919, 5304], [-79036, -7214, -1689, -2870], [47908, -514, 2233, -12494], [-82416, -5414, -2090, -4802], [30612, -3018, 2769, -9958], [18128, -8946, -1110, 630], [82838, 4087, 931, 3104], [14068, -7174, -2658, -5533], [23756, -6638, -2953, 2746], [57614, -112, 276, 6032], [38768, 1918, 2431, 4714], [59858, 2905, -1622, 3536], [27920, 2368, 2216, 1144], [67300, -9980, 71, -3824], [59490, 2151, -1033, 6567], [50468, 940, -1739, 2797], [27816, -8530, 2202, 2378], [1400, 4648, 1908, 9512], [-7570, -653, 6122, 7918], [23632, 8330, -463, 7942], [-12070, -2172, 3372, 8076], [-31018, -7096, 542, -4300], [14648, -7832, 2520, -5216], [-19186, -8176, 3368, 944], [40902, -1305, -585, 9542], [-162688, -1436, -1432, -6192], [23196, -9732, -618, 188], [-77834, -2164, -316, -11788], [-77386, 2461, -1541, 2941], [-64126, -1720, 4684, 3368], [93602, 37, -1547, -2796], [-19898, 2409, 8455, -1599], [-57410, 9413, 4433, -4495], [29148, 7272, 6724, 7476], [19564, 1324, -5688, -1004], [-91998, 1593, -498, 1396], [22576, -3044, -224, -812], [-43630, 9684, 1984, 3084], [-118634, 6233, 2285, -3523], [-155536, 2290, -3331, 3050], [-32630, -1417, 5113, -6901], [68694, -2560, 3742, -1060], [-89252, -5326, -2537, 690], [-1626, -36, -5564, -11868], [-67476, 792, -3270, -3372], [-57238, 767, -7383, 2255], [81400, -2836, 832, -1125], [7754, -6551, -4017, 9534], [-35076, 2538, -2536, -2751], [50374, -2473, -2776, 3030], [17786, 4348, 5316, -2780], [104272, -10576, 3456, -7840], [-37066, 13440, 1756, 7056], [-4436, 12716, 1226, -3140], [6336, 2976, -7510, 3396], [103036, -4082, -4998, 3658], [-22596, 4584, -3123, 14827], [55148, 5744, 1340, -9568], [-38376, 2766, -3613, 10682], [-44052, 3656, 1378, -7336], [111910, 1091, 2924, -4540], [-24258, -15755, -591, -3551], [35392, -2374, 8329, -138], [-190922, 245, 195, 7469], [27928, 11000, 5562, 3920], [-120856, -4232, -2708, -4008], [5822, -7109, -703, -6582], [-45132, -3084, 1600, -1548], [-86044, -4408, -4789, 596], [83192, -8966, 1471, -3443], [-85874, 8084, -3984, 1628], [66780, -4630, -10570, 1514], [-133534, 1645, -4777, 7508], [-8502, 405, -3410, -13596], [19448, 9040, 8584, 9700], [9034, 2788, 8260, 8668], [-7378, 7808, 184, -2872], [51804, 2832, -5512, -408], [-15988, -7934, -13, 9054], [15640, 8012, -2588, -12367], [39556, 8248, 4433, -5924], [14542, -8747, -3455, 805], [57736, 7786, 5846, 10930], [-160372, 4608, -2254, 5904], [24310, 2579, 26, 11480], [-8314, 5913, 103, -11259], [4044, -6090, -5363, -7086], [-84350, 341, 2851, 3546], [50672, -206, -2679, -18050], [46204, -744, -4489, -2172], [-66776, 3842, 671, -10147], [-174854, 11371, 4081, -3161], [-62676, 1656, 8718, 380], [-60256, 52, 1466, 8093], [-26342, -4351, -6882, -8978], [-149042, -1087, 6109, 6977], [-11048, -3994, -4287, -7846], [-33668, 620, -8526, 7624], [6680, -4274, -2731, -13778]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2352_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2352_4_a_cn();".
// 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_2352_4_a_cn(:prec:=4)
    chi := MakeCharacter_2352_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_2352_4_a_cn();".
// 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_2352_4_a_cn( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2352_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![22148, 1456, -300, -8, 1]>,<11,R![7056, -4704, -232, 40, 1]>],Snew);
    return Vf;
end function;