
// Make newform 570.4.a.s in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_570_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_570_4_a_s();".
// 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_570_4_a_s();".
// 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 := [-12540, 4362, -410, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 2, 0, 0], [1824, -367, 6, 1], [-3857, 749, -11, -2]];
    Rf_basisdens := [1, 1, 1, 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_570_a();"
function MakeCharacter_570_a()
    N := 570;
    order := 1;
    char_gens := [191, 457, 211];
    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_570_a_Hecke(Kf)
    return MakeCharacter_570_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], [5, 0, 0, 0], [9, 0, 0, 1], [13, 1, 0, -1], [12, -1, -1, 0], [4, -1, 2, 0], [19, 0, 0, 0], [25, 2, -1, -3], [3, 1, 4, -5], [10, -5, -2, 0], [10, -5, 1, 6], [-6, -6, -3, -12], [22, 7, 3, -12], [95, 14, -7, -5], [-43, -2, 1, -21], [19, -5, 3, 17], [17, -4, 7, 23], [-40, 4, 16, 4], [40, 6, 2, 4], [70, 2, -16, -8], [135, 7, 1, 17], [-94, -9, -4, 8], [2, -34, -13, 52], [-230, -1, -11, -62], [16, 40, 20, -22], [-100, -12, 28, 36], [8, 30, -32, 8], [45, 11, -5, -63], [-355, -4, 19, -5], [-314, -32, -10, 6], [-451, -43, -12, 7], [-647, 1, 21, 29], [118, -54, 16, 86], [48, 26, -38, 14], [-384, 17, 16, 90], [-467, 29, -25, -83], [336, 73, -15, -46], [-1551, -74, 1, 1], [-675, 16, -25, -17], [-285, -19, -41, 29], [-1025, -45, -3, -13], [-931, 53, -22, 19], [586, 19, -13, 42], [-2083, 38, 101, 31], [220, -20, 10, -180], [-1658, 26, -54, -170], [642, -74, 22, 158], [-2591, -34, -23, 69], [877, -6, 19, 119], [-1281, -93, -37, 87], [-563, 141, 46, -101], [-1038, 36, -28, 208], [-2791, -55, -38, 115], [-3677, 58, 1, -67], [-1383, 24, -35, 153], [-229, -133, 34, -17], [-2742, -20, 92, -22], [-847, -133, -59, -139], [-2286, 158, -19, -172], [2060, -93, -39, 18], [-403, 194, -13, -101], [1110, 10, 68, 62], [-5513, 19, -22, 17], [4100, 64, 116, -158], [-3619, 124, -3, -81], [-3953, -52, 81, -41], [1388, -25, 93, 188], [-5010, 25, -112, -8], [2536, 68, -114, -14], [883, -259, -41, 351], [601, 25, 118, -49], [4507, 202, -66, -57], [7580, 53, -41, -196], [2053, -106, -81, -119], [-798, -180, 10, -270], [5146, -62, -28, -16], [5525, -3, 77, -27], [-4976, 58, 77, 146], [1232, -170, -76, 106], [2159, 147, -30, -43], [1687, 133, -181, -57], [-7904, -50, -114, -244], [10290, 19, 51, 2], [-825, -41, -15, -7], [4644, -149, 140, -14], [6684, -90, 19, 390], [6796, 154, 68, -18], [-1944, -132, 98, 258], [6645, 72, 236, -347], [-976, 201, 80, 458], [3489, -45, -24, 51], [10560, -126, 66, 364], [-9983, -121, -70, -57], [-2414, 58, -132, 282], [11175, 106, -137, 67], [9293, 243, 104, -271], [-2398, 128, 145, -224], [6842, -238, 40, 554], [9262, 36, 120, 272], [6806, -434, 124, 454], [6450, 320, -100, -172], [9963, 72, -153, -213], [13508, -86, -149, -18], [-6692, -510, 126, 140], [7918, 78, 102, 56], [6654, 311, 154, -460], [12747, 201, -37, -9], [-4848, -6, 288, 516], [3842, 2, -22, -892], [7994, -38, 36, 118], [5157, -341, -25, -487], [8858, -423, -204, -214], [-19880, -62, -58, -48], [5808, 384, -32, 664], [5104, -108, 317, 574], [-8390, -43, 181, -92], [215, -342, -193, -85], [10301, -52, 45, 859], [3649, 163, -253, -145], [5419, -289, -47, -65], [-2620, 465, 169, -672], [14683, -32, -133, -19], [8966, 392, 254, -686], [-10416, 162, -282, -488], [7174, -196, -36, -696], [-13225, -194, 53, 1], [-10425, 41, -136, 29], [-6191, 468, 302, 353], [-3669, -227, -121, -229], [-17672, 452, 112, -524], [-4958, -384, 122, 658], [-10424, 523, 184, -834], [-5681, -185, -523, 27], [3808, 714, -474, -542], [-324, 806, -214, -18], [-10085, -858, 59, 97], [-12998, 418, 368, -558], [9559, -26, -15, 749], [4834, 578, -28, 780], [-13258, 494, 466, -274], [4078, -552, -82, 112], [-4305, 496, -406, 455], [-21159, -152, -171, 193], [747, -153, 325, 703], [-804, -234, 82, -360], [-2891, -511, 483, 541], [-2899, 656, 193, -269], [-10922, -700, -306, 178], [-10270, 156, 454, -190], [3400, 507, 189, -1156], [-10736, -122, -348, -334], [2278, -457, -509, -164], [-9940, 420, -120, -652], [-24980, 474, -414, -1036], [3260, -930, -152, -520], [-8034, -640, -282, 1086], [21282, -370, 70, 284], [-6232, -486, 900, 642], [-20279, 349, -212, -775], [-7556, 203, -18, 1098], [-21801, 378, 381, 1113], [20093, -54, -374, 609], [-15571, -397, 3, 1219], [-13033, -1324, -125, -11], [3275, 134, -157, -77], [1973, -675, 639, -261], [10153, -247, 763, 649], [23716, 228, 78, 362], [-18982, -28, 200, 1036], [18699, 245, 335, -427], [9291, 601, -177, -61], [7003, 121, 44, 401], [11912, -506, -634, 226], [2133, 177, 671, 1843], [10672, -624, -200, -1874], [-10100, 1238, -450, -1508], [-28632, 738, 516, 246], [18432, -208, 314, 456], [6868, -148, 162, -1634], [14889, -346, -374, -1443], [10191, 1373, -203, -1495], [14372, 313, -443, 52], [-6559, 230, 391, 1603], [5627, 458, 141, -1841], [38454, 1098, 96, 12], [32898, 289, -907, -214], [-5502, -1110, 340, 1162], [14962, 338, -398, -644], [-1209, -989, -614, 1873], [2442, 1255, 653, 794], [27688, -527, 352, 914], [13226, -1058, -490, 1162], [8259, -879, 1010, 411], [12484, 1073, 560, -1338], [-31199, 4, -485, -889], [37951, -320, 413, 57], [-23153, 343, -369, 1779], [22340, -779, 318, 1524], [22305, -1110, 515, 2061], [16103, -119, 18, 207], [6573, 557, 367, 1107], [32064, 333, 509, -2456], [-36420, 618, -106, -722], [2325, -651, 424, 855], [11821, 790, -851, -913], [-14850, 54, -6, 2170], [-35879, -804, 33, -671], [-7326, -166, 14, 1148], [6746, -210, -266, -1470], [5134, -388, 722, 1396], [3216, 910, -1328, -506], [4895, 118, -902, 1531], [4721, -262, 41, -371], [7116, 32, 942, 1892], [-8828, -400, 572, -134], [18441, 1004, 460, 753], [-10354, 1864, -1199, -1836], [17793, 510, 325, -2151], [-18067, -264, -339, 587], [8131, -1689, -897, 839], [11088, -2497, -624, 2790], [14268, -432, -31, 1794], [20287, 1762, 584, -309], [-16915, -526, 429, 1513], [-3688, 1196, 1350, -934], [-40243, -106, -1045, -17], [-34580, -106, -1094, -24], [15588, -424, -1352, -60], [21381, 1049, -368, -433], [22871, -415, 217, 959], [-13859, 1576, 767, -915], [36891, -1429, -959, 933], [-19170, -2030, 623, 760], [-50900, 35, -17, 850], [-2565, -1570, 405, -457], [47681, -528, 439, 1203], [-22088, 1132, -86, -1654], [31171, 283, -1790, -1207], [-39442, 706, 120, -1086], [5902, 836, -874, 570], [-9576, 2040, 204, -4004], [50505, -446, 560, -691], [-32275, 301, 1303, -179], [-56921, 50, 91, -183], [38617, -1349, -856, 1883], [9677, -192, -426, -3075], [-30435, 275, 479, 2963], [35219, 638, -447, 143], [8853, 1860, -1495, -963], [18859, 383, -683, 703], [-16470, 2088, 292, -2952], [16525, -2074, 117, 1521], [-7136, 308, -1400, -506], [11051, 418, 1083, -987], [331, -1175, -360, 4157], [-21049, 912, -1371, -171], [-2058, -56, 1562, 2906], [-1415, -264, 1033, 1219], [-2972, -1306, 610, 982], [5350, -446, -1138, -1110], [-31178, -550, 962, 438], [-12010, 710, -208, -4444], [7104, -893, -823, -316], [-6530, 3067, -396, -2206], [-45679, -1276, -737, 3329], [40519, -839, 770, 2015], [3814, -14, 86, 3824], [4896, -1504, 88, 444], [35081, 844, 541, -2601], [26007, 1489, 671, -1249], [-32156, -44, -124, 2736], [17730, -680, -934, -16], [5764, 1184, 838, -4580], [-5604, -781, 1049, 420], [22471, -1552, 76, 847], [49556, 2821, -174, -2250], [5687, -739, 1637, -433], [-2356, 694, 576, 670], [-20745, -1077, -1028, -1587], [59126, -484, 1582, -1754], [91410, -1328, -94, 338], [21615, 436, -1459, -3017], [-43389, 1049, -1341, -3597], [27658, 3055, 797, -120], [27671, -125, -682, -2103], [15018, -1260, 2072, 1648], [-8619, 750, 2413, 1059], [-66080, -2424, 176, 1880], [-50238, 1340, 1429, -1264], [62644, 1506, 664, -1622], [-31414, -1997, -148, 1272], [-50703, -1554, -883, 1803], [2279, -1839, 535, 3881], [-39572, 1477, 1323, 1380], [36600, -642, -2704, 54], [-21053, -1229, -67, 1221], [20621, 446, -1387, -641], [26547, -1689, -1903, 897], [-68930, 1849, -375, 576], [36070, -1602, 48, 3536], [-32051, 14, -1663, -1845], [-12806, 3592, 1218, -1014], [28037, -276, -787, -1123], [-39522, 206, -100, -426], [-1218, -1163, -1877, 1010], [-97454, -1782, -378, 2122], [8507, -2409, 87, 3687], [-18913, 895, 1578, -1647], [-30393, 2107, -1347, -3157], [48063, -1316, 73, -1841], [-3862, 2984, 1440, -2276], [19992, 2114, 993, 2762], [63118, 3510, 48, -2194], [81677, -292, 209, -995], [-34516, -4122, 870, 1134], [-92069, 1291, 850, -391], [19662, 366, -1090, 3762], [12162, 564, -1402, -1448], [94152, -1890, 442, 2250], [32179, 354, 1949, -121], [80124, 1564, -1412, -1222], [-105567, -857, -800, 253], [78778, -2530, 1956, 4030], [3796, -2261, 690, 2336], [-19774, -2536, -1888, 4232], [-41306, 1802, -958, -962], [-16182, -206, -2604, 2858], [48887, -2326, -33, 5911], [53591, -100, 1607, -1211], [-9778, 342, -32, -6492], [1853, 1406, -3215, 331], [-47432, 1618, -514, 3540], [86872, 1183, 1918, -3250], [80362, -1018, -1184, 2122], [-9010, -577, 988, -212], [-15041, -485, 3791, -309], [29143, 2896, -2405, -1651], [56709, 2310, 199, 571], [43655, -1000, -1610, -4297], [9288, 655, 2549, -196], [10477, 583, 1505, 7853], [6503, -2181, -366, 6131], [56928, 1653, 444, -3830], [-39961, -2348, 2335, 1593], [-17603, -103, -1237, 6087], [-82463, 128, -677, -425], [-79042, 124, -214, 490], [178, -1020, 2582, -3302], [75850, -2978, -980, 4112], [17651, 312, -567, 4131], [32852, -117, 2485, -1092], [-45730, 200, -674, -3896], [-11270, -3218, -1816, -3138], [-51945, -3141, -1515, 4243], [24615, -1744, -897, -2443], [53257, 291, -976, 2323], [-15073, 729, 1054, -415], [48356, -1423, 2514, 1876], [84634, 3184, -626, -1366], [43251, 211, 275, -433], [-26202, -3870, 960, 3792], [5114, 3528, 866, 1010], [-34331, -1855, 53, 1167], [22810, 2331, -3537, -1336], [-80196, 3523, 743, -3076], [-57804, -3214, 326, 2450], [12456, -1178, -450, -9028], [7040, 5512, 1032, -3674], [2507, 621, -3334, -4555], [-3940, 4268, 2080, -4024], [70103, -1794, 371, 1067], [50839, 4387, -130, -1213], [59964, -2382, -16, 1072], [-128177, 1061, -1295, 5671], [-118759, -1295, -1821, 939], [61687, 3267, 314, 5041], [106318, -2008, -1304, -4196], [11654, 4190, 1526, -4544], [-47322, 1297, 1415, 3338], [-39215, 3373, 712, 2993], [-22430, -881, -2032, -202], [22817, -1552, -1250, 3833], [54527, -897, -1957, -73], [-80469, -3678, 2305, 991], [40645, 442, 1989, -43], [-43868, -3212, -774, -4596], [-18803, 1411, -1807, -3807], [-11054, 1227, 2061, 2360], [-47279, 3442, 1397, 4625], [33312, 244, -1232, 3086], [38263, 1916, -4877, -1407], [80343, -413, 3306, -2027], [23038, 1759, 549, -636], [-106590, -1484, -776, -4070], [-12312, 1877, -2081, -3372], [-6424, -2431, 452, -2734], [-53652, 3516, 2639, 1410], [78445, 5734, 1123, -6087], [-19582, 3582, -3804, 224], [90405, 169, 2945, -7387], [-62542, -241, -856, -3218], [71794, 412, -3028, -654], [-8481, -2986, 2473, 3353], [-82191, -1427, 382, 1945], [-48252, 2234, -2300, 840], [-48179, 5353, 2495, -459], [60700, -2358, -2281, -1058], [-18606, -1518, -420, 1018], [-117683, -3559, -300, -1689], [-13992, 1239, -1753, 6256], [28647, -2264, 31, -4043], [120792, -1540, 608, -4996], [-43488, 2094, 1570, -4112], [124042, 1946, 1144, -5444], [-77048, -522, -906, 3958], [-33422, -1114, -2686, -4290], [-23302, -1534, 3418, 1430], [20531, -615, -45, -4105], [7262, 344, 390, -3602], [24171, 295, -1480, -2153], [-62044, 1563, -2867, -9840], [139513, 4426, -17, 725], [-59229, 2275, -4699, -455], [-50964, 445, 4409, 80], [-78205, 2534, 1393, -4055], [81024, 4362, 112, 3264], [-18270, -372, -3064, -9456], [99144, -834, -1378, -4808], [-73669, -2109, 2638, -307]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_570_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_570_4_a_s();".
// 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_570_4_a_s(:prec:=4)
    chi := MakeCharacter_570_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_570_4_a_s();".
// 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_570_4_a_s( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_570_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![14032, 9516, -278, -36, 1]>,<11,R![34560, 36648, -570, -54, 1]>],Snew);
    return Vf;
end function;