
// Make newform 2352.4.a.cq in Magma, downloaded from the LMFDB on 18 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_cq();".
// 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_cq();".
// 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 := [119, 18, -23, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [2, 25, -3, 1], [-140, 77, 21, -7], [-68, 7, 7, -1]];
    Rf_basisdens := [1, 9, 9, 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_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], [0, -1, 0, 0], [0, 0, 0, 0], [0, -3, 0, 1], [0, 0, 0, 3], [-12, -1, -3, -3], [48, -6, -5, 3], [-48, -3, -6, -1], [24, 0, -9, 1], [12, -6, 9, -3], [64, -6, 24, -6], [-252, -1, 15, -3], [28, 6, 12, 6], [216, 10, -3, -3], [-162, -24, -18, -10], [84, 10, 15, -21], [-240, 30, -14, 15], [-180, 6, 48, -30], [336, -3, 30, -9], [-168, 30, 49, -18], [496, -36, -96, 24], [780, 8, -18, -18], [-540, -11, -69, -15], [-504, 18, -49, 48], [-48, -9, 12, -42], [636, 42, -31, 9], [456, -21, -84, -1], [172, 42, -6, -48], [-258, -12, -108, 0], [-280, 18, -12, -78], [540, -72, -6, -6], [-912, -42, -3, 81], [780, 96, 112, 12], [-186, 72, 78, -82], [-656, 90, 36, 54], [1200, -78, -40, 27], [-820, 102, 108, 18], [528, -82, -315, 45], [1272, -27, -162, 72], [1344, 123, 48, 27], [1392, 96, -36, -111], [-840, 177, 270, -109], [1178, 0, 228, -84], [-1494, 60, -54, 118], [1584, 0, -108, 72], [-1116, -84, -288, 0], [-1704, 96, 180, -144], [2292, 126, 171, 135], [2928, 84, 72, 45], [-2328, -30, -213, -81], [2088, -27, -438, -9], [2328, 114, 153, -24], [-2148, -190, -327, -75], [492, -9, -111, -165], [4248, 99, 6, -99], [2568, 217, 78, -138], [-1404, -126, 193, 33], [2314, -96, 132, 156], [-4008, -174, -189, -217], [2640, -78, -445, 15], [3936, 19, 360, -126], [-768, 222, 401, 9], [1104, 134, 411, -93], [480, 336, 243, -54], [-3222, -96, -78, 242], [260, 108, 228, 96], [-2296, -444, -282, 30], [552, 213, 240, 225], [1728, 90, -72, -129], [2436, -559, -159, 21], [-4392, 195, 210, 109], [4008, -204, 86, -30], [946, 120, 444, -84], [-6652, 192, -348, 204], [1920, 44, 192, 48], [-768, -324, -333, 289], [1728, -162, 284, 201], [-1992, -150, 435, -81], [-1176, 30, -261, -336], [5916, -98, -255, -291], [450, 312, -768, 120], [1704, -651, 210, -9], [-432, -324, 81, 498], [3144, 408, 396, -36], [-6456, -201, -432, -73], [2142, -36, -936, 396], [2142, -576, 456, -24], [-408, -395, -378, 252], [2528, -534, 108, -306], [7380, -614, -951, 165], [4632, 874, 393, 33], [7848, 282, 444, 510], [-6288, 537, 708, -243], [-260, 42, -336, -438], [8280, -280, -330, 174], [2280, 253, -810, 54], [2412, 737, 1131, 15], [4500, 324, 954, -102], [1630, 360, 1500, -276], [9980, 24, -444, 264], [-3942, -504, -906, -450], [4788, -542, -213, 399], [-3504, 618, 69, 269], [3284, 1452, 204, -276], [-6720, -60, -9, 204], [9564, 342, 1299, 327], [-4260, -89, -813, 339], [-8496, 669, 318, -1], [576, -684, 657, -336], [1416, -672, -864, -204], [2700, 390, -1080, 126], [-696, 618, 261, -19], [-300, 708, -374, -6], [-800, 1506, 972, -594], [6024, 786, 1239, 19], [-5784, 210, 571, -705], [5352, -306, 633, 273], [3432, -912, -93, 405], [-6432, -1299, -540, 333], [13920, -102, -1530, 33], [1764, 684, 180, -72], [4248, 261, 954, -792], [-20472, 663, -384, 279], [-8868, -372, 54, 42], [13992, 588, 201, 315], [8092, 150, -390, -996], [-2400, -152, -1086, 786], [-9036, -1134, -203, 165], [13872, -24, 558, -345], [-5292, -750, -324, -738], [-13272, 849, -186, -233], [9160, 648, 288, 612], [3212, 570, 2898, 216], [-3444, 145, -51, 795], [1488, -564, 1053, -618], [6192, -503, 1104, 150], [2364, 852, 1094, -78], [10680, 63, -2694, 204], [8778, 660, 1752, -1052], [-15540, 228, -1782, 810], [-10614, -528, -618, 414], [21896, -528, -1248, 276], [3120, 975, -744, -513], [-3360, 600, 274, 645], [-9360, 190, -159, 1065], [8448, -534, 1188, 327], [-22788, 217, 2157, -165], [-4896, 198, 401, -183], [-15072, -927, 546, -145], [-18460, -1254, -1200, 138], [3900, 27, -2445, -753], [-20636, 882, 168, 426], [-12672, 314, -1077, -357], [7244, 294, -72, -90], [-10344, -831, 2322, 539], [5912, 258, 660, 546], [-17076, 1457, -1239, 471], [-17472, 384, 1697, -480], [10176, 809, 3708, -36], [-6888, 3, 936, 783], [-3054, 2760, 1428, -676], [15120, 330, 132, -1806], [-36, -2168, -1128, 816], [-5712, -246, -255, 1233], [-1704, -1432, 24, -768], [15544, -2502, -2604, 1074], [-17952, -222, -1634, -663], [21790, 1608, 1140, 516], [13128, 1351, 90, -684], [288, -1557, -168, 819], [9120, 678, -1544, 117], [-24192, -1683, -1842, -1017], [-2564, 1932, 1314, -918], [4560, -192, -436, -36], [-24396, -235, -1095, 921], [-3132, 276, 4848, -276], [-4512, 120, -2535, -297], [-5460, 2082, -135, 885], [8640, -1062, 806, 837], [7568, -2100, -2496, 1668], [-17844, -2728, -1644, 300], [-15048, 18, 1686, 132], [-19164, -2735, -63, 837], [-27816, -2319, -6, 1027], [-3048, 2449, 438, -732], [4194, -360, -5136, 384], [-612, 576, -1008, -468], [11180, 1440, -810, -486], [-43920, 1448, 1638, -162], [-40680, 810, -2889, 450], [-11568, 1965, 3600, -2043], [-19124, 996, -4008, 1200], [15528, 791, -882, -1332], [15120, -1413, 1188, -1449], [-18564, -1441, -2553, 1515], [20700, 1320, 2952, -144], [-19880, 2154, 3966, -348], [-37404, -315, -213, -807], [18168, -2654, -315, -891], [-8994, -276, -5514, 522], [10320, -588, 1566, 78], [-2304, 756, 5738, 765], [-23256, 342, -1273, 1770], [19836, 244, -3498, 462], [-30672, -2699, 1380, 1758], [-2280, 888, 4028, -108], [-30288, -1275, -540, -819], [8934, 720, -1176, 2296], [-34944, -1446, 855, -249], [22600, 2100, -1536, -588], [-21840, 1485, 2748, -1716], [-6616, 1758, 1476, -1278], [-852, 748, 342, -1386], [13056, 3122, 1713, -303], [-47664, 1440, 2921, -2250], [-27800, -426, 3444, -1194], [19836, 2869, 3171, 147], [-8112, 1389, 2046, -81], [-20544, 4236, 3003, -855], [5588, 1038, 4242, -372], [11028, 462, 6759, -333], [-56118, 1164, -2892, 576], [1864, 324, -768, 1200], [3540, 1324, -2400, -1392], [-20384, 3282, 3324, 78], [-38508, -935, -2397, -327], [19728, -1461, 2826, -1763], [27804, -2670, -3875, 2769], [52920, -1953, -2256, 171], [12620, -1170, -3330, 2448], [4992, -354, -5319, 309], [27080, 450, 4668, -510], [-29610, -612, 5676, 1008], [-3120, 678, 2129, 2661], [41880, -1836, -282, 222], [-18264, 1014, 6489, -2496], [26502, 324, -738, 2746], [67656, 549, -3096, -595], [-64848, 1684, -2964, 1068], [12528, 1845, -1416, 1377], [2100, 984, 6552, -3192], [-21072, 1896, 2376, -1224], [23166, 2328, -552, -744], [32220, 947, 4389, -525], [-23664, -1934, 1203, 627], [41964, 2382, -481, -441], [-31596, 1106, 5589, -63], [32284, -876, 564, 2172], [-3984, 1971, -3282, 1925], [-14446, 4392, 6516, -468], [6612, -459, -3363, -1959], [30600, 21, -30, 107], [27240, 1482, 1831, -2142], [14112, 2971, -2724, -1338], [16728, -2205, 5568, 595], [61192, -378, 2166, -3048], [68976, 1062, 1129, -1071], [-1008, -1105, 5460, -2838], [-1200, -4584, -7115, 1386], [-25288, -180, -1152, 1116], [14232, 1677, -7884, -683], [-3648, -4908, -3978, 765], [-13728, 2130, 6782, -2535], [-15132, 4455, 1233, -747], [-32556, 456, -4212, 2244], [-46866, 1308, 3894, -1350], [72684, 783, 663, 951], [58276, -1632, -2808, -144], [528, 816, -1803, 2915], [38880, 1710, 7128, 1503], [-19636, -2772, 1692, 2664], [21912, -534, -2889, -510], [53864, -3540, 2760, -1608], [48168, -4410, -6125, 2466], [-26364, -2046, 3605, 2145], [-7536, 2775, 4944, -4293], [8522, 2976, -660, 1740], [51074, -168, 2316, -2244], [-13236, 406, -2301, 39], [66048, -368, 516, 444], [40040, -6270, -5052, 966], [23520, -6148, -6294, 1986], [44112, -6954, -1350, -633], [468, 900, -3218, 4686], [17472, -795, -2778, 171], [-28934, -2448, 3288, 600], [39666, 2820, 4866, -1250], [30228, -2622, 1301, 837], [-17868, -1315, -4257, 3969], [-38178, -2940, 822, -1630], [88812, 1828, -1368, -2088], [37488, -2670, -795, -107], [19380, 2474, 3891, -681], [-41050, -3696, -828, 1692], [-6024, 2791, 5466, -2076], [35232, -516, -5630, 1326], [46440, -1081, -798, -2274], [-5796, -1394, -3405, -1281], [72708, -3864, -104, -504], [-1008, 3276, 7263, 2622], [-27072, -540, 585, 4275], [-5256, 4758, 9804, -1686], [28008, 3789, -2040, 585], [38404, 84, -8100, 684], [86472, -4944, -810, 522], [48144, -651, 7020, -963], [-50832, -972, -7222, -2523], [3600, 7983, 3126, 1197], [-26318, 4824, 8172, -1980], [44352, -2824, -84, 2220], [16104, -7572, -555, -1377], [-31392, 5262, 9243, -2357], [-3124, 8994, 3468, -750], [-70824, 2649, -7374, 207], [10536, -1002, -859, -1374], [-4548, 7660, 9246, -474], [39384, 3813, -4050, 2143], [-64536, 1614, 2209, -1350], [-23160, -5514, -4545, 63], [-74064, -7086, -869, 1311], [-48572, -1308, 3744, -3276], [40848, 5833, -7488, -2538], [-42048, -6498, -2484, 4302], [59058, 5076, -1572, -2448], [41160, -6270, -11309, 1200], [-73844, 4782, 1452, 474], [52176, 4134, 3429, -4239], [-50760, 3693, -1950, -2305], [53664, -2232, -5433, 3097], [-23058, 6120, 10608, -5136], [58584, 2304, -6381, -91], [78876, 2538, -319, -939], [25188, 10162, 3231, -405], [-59084, 138, -240, 438], [39492, -2150, 9951, -5277], [30204, 1782, -2052, -3798], [48756, 4213, 9843, 429], [-20280, 1302, -7857, 3678], [38484, -1206, 14481, -2091], [-105922, -144, -4500, -2700], [32160, 7806, 4467, -1853], [-32088, -4337, -6786, 5274], [80496, 2496, 6048, 3672], [69168, -1320, 2637, 4339], [22920, -6213, -6144, -2665], [128352, -2580, -4716, -333], [-31996, -5370, -6012, 1998], [52776, 3016, 3660, -6132], [6384, 5229, 5712, -2766], [-39672, -5238, -6885, 4263], [15290, 2808, -2808, 3312], [-7866, -60, -7986, -2062], [-14424, 12000, 2480, 1176], [-36370, 2016, -2952, 2088], [17172, -4987, -675, -27], [71496, 524, 4848, 2688], [31764, -8884, -12486, 618], [9102, 4668, 2568, -4932], [-48552, -3795, -6306, 3835], [18370, -5544, 2316, 3804], [45420, 719, 2589, 7431], [-24816, 6177, 9990, -4545], [77424, 4377, -2400, 2169], [14004, -2448, 1512, -4596], [-78308, 4872, 4836, 2436], [-115608, -5057, -6042, -354], [51848, 2052, -6696, -324], [70802, 1296, -6828, -2388], [816, -1059, -7992, -3987], [-24408, 7794, 13995, 291], [-69024, -6993, -330, -2015], [-570, -2652, 5862, -8262], [612, 8154, 15273, -1995], [76374, -9024, -7392, 2640], [-98916, 504, -8106, 30], [-47760, 375, 12690, -135], [-15744, -444, 15309, -3240], [-51564, -2061, 3033, 7641], [-21912, 1614, 7263, 3576], [112248, -5471, 9666, -2736], [52194, -2124, 4080, 3212], [-46224, -6000, -14016, 2496], [57078, -4584, -3876, 5500], [-149772, 204, 2542, 2166], [-18456, -6840, -2970, 1926], [56376, 7734, -1284, 1014], [-480, -8976, 1062, 147], [-45604, 4416, 4488, 2496], [-17400, 4770, -3243, 3165], [-44308, 7332, 9054, -234], [56400, 1773, 4608, 1548], [-4464, -5559, 2640, 377], [52920, 2250, 819, -4305], [42120, 933, 7662, -11285], [-21888, -768, -5226, 1338], [-68376, 3552, 356, -1764], [66156, -8855, -5313, 519], [72972, -5484, 11832, -2940], [80760, 9612, 9693, 2951], [17904, 390, 2610, -3], [41046, -7044, -6516, -1656], [57376, 1146, 6084, 3870], [103332, -3761, -2493, -2583], [-135048, 2403, -162, -90], [-69336, 7776, 1580, 2928], [-66662, -5232, -1800, 6120], [55950, 5568, 2712, -5248], [38916, -3744, -2376, 3072], [-28068, 3294, -10347, 7905], [78912, -2916, -11025, 1824], [57456, -1044, -10593, -4779], [29328, -5631, 1644, 2169], [-79588, -3678, 6456, 3714], [-42308, 5004, 19254, -4890], [62712, -5643, 2598, 618], [94368, -5367, -8526, 6831], [32292, -5850, 8879, 1575], [71364, -809, -3759, 11397], [108000, 5038, 2991, 327], [45168, -1644, 3057, -837], [-92256, 6150, -14738, 3009], [61752, 2139, -3006, 4329], [98796, -3032, 10914, -2550], [134112, 5628, 12285, 222], [-70416, -6065, -3072, -1254], [-68616, 11925, 15252, -4923], [13872, 9390, 7113, 3565], [-160188, 2028, -238, 1590], [43248, 2106, -7197, -933]];
    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_cq();".
// 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_cq(: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_cq();".
// 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_cq( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2352_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![27748, 576, -412, 0, 1]>,<11,R![733072, -82944, -4136, 0, 1]>],Snew);
    return Vf;
end function;