
// Make newform 570.6.a.k in Magma, downloaded from the LMFDB on 19 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_6_a_k();".
// 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_6_a_k();".
// 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 := [128450070, -7203, -26355, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 2, 0, 0], [558600, 16254, -41, -1], [-4697826, 21441, 358, -1]];
    Rf_basisdens := [1, 1, 5586, 11172];
    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 := 6;
    raw_aps := [[-4, 0, 0, 0], [9, 0, 0, 0], [-25, 0, 0, 0], [6, 0, -1, 0], [-117, 0, 2, 1], [-120, -2, -1, 4], [457, -1, 5, 5], [-361, 0, 0, 0], [-107, -2, -7, 1], [-2609, 0, -20, -13], [107, 27, -23, -11], [1424, -18, -57, 12], [2425, -14, 26, -19], [5306, -76, -13, -16], [-4769, 68, -41, 7], [181, 92, 43, -5], [7276, -74, 142, -24], [19429, 15, -1, -79], [20550, -34, -134, 54], [358, -172, 80, 66], [30246, 38, -20, -16], [36174, 52, 258, 218], [-1811, 40, -541, -191], [10937, -224, 20, -11], [-1436, -180, 379, -308], [-62330, -70, -486, 28], [39650, -372, -326, 150], [-6746, 208, 562, 346], [25870, 384, 378, 144], [-10683, -24, -363, 155], [-45874, 324, -30, -350], [67965, 56, 444, 115], [23522, -494, 448, 588], [77962, -598, 964, 550], [167988, 752, 202, 138], [131631, -533, 89, 649], [129952, 1128, -224, -1250], [203500, 110, 2081, 1374], [110479, 1009, 1263, -1499], [164229, 2234, -595, -725], [179642, -172, -820, -934], [215480, 78, -3828, -90], [-39221, -806, -3284, 537], [464654, 232, 1355, 2274], [439125, -1671, -3279, 245], [550850, -596, -704, -34], [160848, 440, -2292, -844], [49110, -2924, 398, 1146], [-19973, 3505, 787, 69], [811583, 1635, 1525, 627], [-130746, 580, 1200, 1220], [207705, -674, -2150, 839], [584570, 4482, 168, -4044], [-189613, -552, 3280, 3541], [400745, -2578, -5227, 2003], [-336159, 1416, -117, -1019], [249593, -1046, -5200, 301], [-190576, -1390, -910, -2672], [704826, -96, -4572, 3148], [-1210265, 3484, 3376, -1873], [-90486, 1762, 11371, -2004], [-634881, -1836, 4931, -2815], [170858, -1126, 4384, 7294], [-904629, 7046, 11214, -2259], [-354104, -708, -4868, 2354], [103783, -2476, 17509, 997], [-412659, 2459, 1887, 3511], [-718146, 924, -13465, -5230], [-465133, -4156, -9967, -4297], [1123980, -1590, -9026, -5790], [-789200, -3352, 7810, -986], [1557311, -10746, 8536, -3987], [-215552, -10018, -14099, 4422], [-669902, 5082, -1535, -14618], [943325, -1529, 5947, 1559], [-2298458, 3680, -2870, 1894], [440668, 7286, -15986, -5282], [840432, 15566, 13906, 5574], [-854983, -2066, -15916, 7553], [1969384, 9280, -10364, -12534], [-1145785, 5980, 146, 5877], [2192192, -16130, -15458, 4282], [394096, -11826, 7390, 13888], [-1844194, -22248, 6003, 9586], [329990, -9120, 3006, 8690], [-2359755, -9514, -3891, 3033], [937331, 13798, -1660, -24881], [2290494, -14986, 13614, -6884], [-775426, 5294, -16232, 9128], [-826384, 3498, 16733, -1506], [1345511, 13402, -14993, -22949], [667401, -4422, -5236, 4795], [572528, -15174, -23234, 9292], [-1417369, -22348, -8976, -14511], [252562, -5398, 32132, -1890], [-6100359, 15180, -19813, 7973], [2408661, -16016, -9508, 7021], [-4441731, -6436, 30002, 5413], [2991868, -8112, 11046, -25172], [1037574, 4938, 15756, -25516], [-587174, 25130, -25944, 12702], [-1865458, -8098, 65876, 23200], [-4397673, 13877, -56921, -8319], [-647173, 7610, 7100, -3945], [4057372, 1118, -31570, -15536], [88288, 5040, -9160, 19954], [2784983, -32610, -53537, 15411], [1475788, -15642, 30594, -21962], [1551884, -13624, -35960, -14892], [3389894, -10184, 950, 42448], [5433418, -1832, 57664, 19490], [-5395630, 602, -24106, 27868], [524217, -20937, 47661, -20315], [9776720, 24216, 27450, 7496], [-1107324, 15156, -47696, -30148], [2730725, -124, 51616, -20271], [-1323094, -25540, 85665, 29468], [-2429183, 20390, -45577, 18561], [-3107105, 44765, 34347, 18791], [6526668, 4676, 15764, 18496], [-1800748, 892, -53896, -6650], [-15346336, -18800, -6995, 692], [1298613, -20788, 77511, 27379], [-1739966, -7412, -20414, -66770], [-864176, -31506, -19410, -41772], [6549932, -11636, 51778, -294], [-5007171, 9463, -90901, -53799], [279687, 986, 18092, 26781], [-6853800, 10256, 98727, -18898], [-6326788, 21996, -2486, 14142], [4691908, 49160, 23336, -65104], [6489618, -33232, 108846, 13474], [858257, 7721, 110407, 27727], [-10020734, -16560, 20826, -24504], [-2910472, -59900, -52714, 2966], [-12759734, 12798, -91528, -5396], [211395, 19244, -64607, 19625], [-6692696, 10696, -26982, -74360], [-3391155, 18334, -201971, -55445], [19087956, 15382, 11538, -24330], [19437844, 5416, 6724, -24024], [7152492, 44712, -153884, -63954], [-9742034, 52746, -34341, -36620], [-3501115, 7805, -116295, 38527], [3165436, -37194, -5856, -7726], [8457306, -16312, -8584, -26882], [-8825614, -123652, -83034, -42720], [-5303865, 40762, 8313, 42933], [4926166, -21890, -157294, 66470], [14430, 68520, 60818, -34442], [-4786380, -88434, 81261, 101020], [-16470764, 2928, -14600, -51882], [-10652800, 43026, 39565, -35758], [21968476, 27244, -64256, -47044], [462774, 49566, 80984, 78378], [6387110, -10174, -133178, 32794], [-6789274, 72082, 69626, 18370], [9534852, 143890, 69804, 21162], [-8430364, 58258, 87880, -39214], [16708777, 21342, 46976, 34853], [10628963, -28204, -79499, -26545], [1203089, -93602, -25791, -68949], [11490210, 29116, 101081, 63904], [32677216, -3848, -14900, -31220], [-5261231, 4960, -168297, -104413], [-10884303, 54755, 57201, -54357], [-10960582, 32768, -81626, -191362], [1289272, 70640, -66936, -174578], [20214208, -97548, 132494, -43578], [-5970610, 36106, -138720, -28504], [-34552, 37974, -7798, -148564], [-21414760, 95484, -33062, 83766], [43057, -61570, 131882, 27087], [-28629430, -35384, -146836, -161976], [4711246, -21676, 42326, -185462], [6473436, -15342, -89388, 184002], [479084, -17080, -95354, -85972], [3069288, 101028, 39072, -89958], [2168778, 136580, -111764, 38354], [-28055948, 87326, 216990, -88598], [19494848, -72818, -18193, 92586], [10586848, -636, 23592, -68388], [-13838286, 156066, 100719, -26942], [13109367, -145516, 25763, -95539], [418963, -178100, -64101, 170747], [-17249914, -150750, 129116, 141384], [7264290, 26994, 237773, 71798], [6053000, 62236, 155878, -118296], [-38763514, -25174, 98906, 113780], [22383789, -3658, -39764, -24361], [16207722, -28, 7033, 118330], [9570115, 11676, -102313, 145755], [-9457868, -89096, 40264, -40152], [-27466373, 98770, 45386, 32479], [12928099, -16948, 208827, -76765], [-11169115, -20584, 259305, 3291], [-50447277, -107553, -34523, 72291], [-52972510, -18290, -13784, -5888], [-13476605, 213163, -149693, -65889], [21110929, -41376, 439449, 179129], [14472323, -97386, 57350, 220215], [-36463994, 39924, 92510, 8770], [12203586, 62386, 281739, -10366], [-41088118, 134018, 73908, 3908], [-5306535, 118536, 156916, -190585], [-9897615, -68465, 172353, 103173], [2665452, 199094, -60384, -56064], [40977877, 104533, -92331, -166401], [2453546, -140770, -400746, -51016], [-6911156, 18996, 585588, -28768], [1148402, 42402, 249234, -55712], [2383586, 49748, 17866, -184764], [-12290324, 54058, -215247, -170046], [-3129677, -148173, -107681, -155031], [18673950, -70248, 415780, 110722], [-50157514, -145348, 351622, 123936], [37651740, 226994, -55507, -8470], [-32336807, -267156, 236378, 151505], [105765327, -15065, -40545, 12401], [10489355, -70745, -547893, 235927], [-38725494, -150056, 189832, 54088], [36335261, -152147, -34573, -56061], [22310273, -4508, -522364, 56429], [20707190, 316534, 334649, 217320], [76751131, -103067, 106027, 33701], [-19926116, 173996, 583178, -39802], [-24569921, 89244, -170325, -344795], [49695656, 307014, -163042, -160968], [16812596, -66074, 898100, 210828], [653885, 176684, 251184, -107901], [-25992880, -164906, 222808, -166574], [55167711, -285559, -284583, 75277], [-17580814, 211260, 246654, -209770], [59087921, 454360, -22364, -315747], [-22610584, -242674, 38823, 176054], [-51069413, -273148, -137561, 356083], [25177125, -230525, -330817, 300653], [10243500, -106546, 253446, 77246], [32336033, -94672, -279276, -298313], [51656538, -93628, 217668, 147174], [21043218, 236164, 277102, 234422], [-51157184, -88470, -445512, -21672], [-20593948, 344508, 383181, -339418], [16817800, 221788, 154532, 82298], [29259915, 114300, -585463, 103501], [9314243, 63278, -172006, -522283], [48291882, 99194, -201375, 177420], [67084878, 97610, 86502, -75170], [71215003, -17271, -339091, 264881], [102081397, -127374, 328695, -39299], [55837690, -118812, 297710, -206072], [-72318810, -115128, -378232, 324460], [-52955249, -202604, 431073, 320131], [48522890, -41438, 29770, -423400], [-23331501, 95719, -73913, 139519], [44993469, -227996, 175218, -380737], [18235475, 45473, 100469, -330525], [15981446, 408634, -341558, -55874], [28429203, -1206, -267999, -52947], [-37333264, -69636, 142706, 447558], [-19700966, 14920, -520042, -512066], [73054332, 39816, 524804, 134296], [-54398164, 485096, 556834, -131178], [10263740, -465746, -203919, 57236], [40091195, 326155, 217019, -613937], [-65688177, -259607, 317553, 475493], [100170859, -172298, -44722, 205951], [-12008632, 136926, 1128092, 7614], [154357028, -53996, 281076, 11064], [-971453, 134127, 175879, -803729], [-17921588, 219516, 371210, 197794], [111990086, -68882, -328430, -250082], [-116240704, 189078, 159156, 45430], [125781678, 415966, -89656, -152914], [78419534, 322536, -716085, -84878], [5872170, -170636, 488541, 500248], [-23241571, -78756, 320003, -692863], [32978170, 243582, -56434, -441432], [18455120, -62754, -949196, -33690], [-27031735, -273008, 960202, 218355], [10146010, 169048, -463678, 14626], [-110523326, -141366, 908106, 226766], [-126097671, 578384, 522353, -38519], [-105050892, 181964, 549562, -424494], [22809494, 673734, 310273, -536956], [-48469833, 267062, -967986, 431361], [-96798070, 40500, 218456, 432160], [-38058219, 385282, -735497, -594633], [-725712, -420348, 195016, -299912], [44938339, -226230, 1329804, 588087], [-144114424, 176160, 142568, -409398], [-82125955, -476168, -619973, -679631], [117408917, -124058, -1317429, 42763], [-121280988, 62738, -371462, 110376], [-31652962, 196578, -203055, 632138], [-55594910, -354440, 758874, 760612], [-39953338, -479616, 709406, 570674], [-73940163, -665879, 808153, 631293], [82744768, -489100, -536396, 181436], [-42245460, 300886, 1327607, -576854], [-105755962, -432886, 182644, 427144], [-63307231, 544016, -364825, 105559], [13086962, 126176, 403910, -145294], [15544325, 586101, 221453, 248647], [-93070242, -101654, 104664, -606462], [42075730, 216824, 91811, -607562], [-61925092, -292608, -489524, -713080], [139147314, 425868, 555884, -112456], [-35718761, 43166, 461914, 520729], [-36414886, -652744, 586674, 658792], [-15223771, 260876, -217127, -174923], [-171296074, -33572, -761496, 11332], [-100257103, -757846, -191568, 215785], [-51211278, -76446, -622556, -899738], [-64608403, 541802, -834217, 368677], [107564738, 213102, 296988, -520228], [-120843291, -525496, 465400, 43283], [-93270740, 383036, -1552488, -566692], [-21651914, -322730, -850410, 164076], [75135200, -239684, 1547434, 338646], [-134956081, 184361, -171623, 362413], [125428362, -632664, -324906, -318292], [21961455, 531150, -1903174, -592013], [185648292, 819358, -180242, -932312], [-1928627, 473867, 1164281, -524935], [26224558, 1134434, -183860, -610664], [195021224, 830792, -831108, -854868], [-240473376, -167136, 439070, 317248], [-122561047, -466195, -935707, 307927], [239143193, 193231, 423053, 14309], [-159056160, -395222, 451890, -103578], [49747557, -847236, 1737619, 176579], [35674076, -846368, -1661782, -332456], [-84095325, 893460, 193461, 587895], [-22740418, -398996, -1294164, -39306], [35478097, -111172, -588189, 287565], [-60047926, -987486, -794692, 258676], [51922645, 941252, 577355, -149169], [57161391, -117853, 1051449, 627039], [-151591448, 352308, 319869, 363450], [59645240, 50694, -1051111, -610696], [-148008492, 583084, 309786, -435078], [-8280445, 420828, -1220506, -496589], [-40580905, 832855, 1130833, -677415], [-151516739, 212136, -906389, -702669], [-30345334, -945714, -1403878, -124726], [86572489, -598903, 17087, -442967], [42752368, 411876, -269776, 589364], [-150451132, 441584, -1682248, 15236], [-40719028, 348564, 1916522, 195394], [169030549, -1057725, -425865, 250815], [-55231164, 449508, 1027493, 89384], [77461590, -591064, 1536258, -153032], [-130227650, 320292, 771576, 239214], [263847456, -517896, 1254236, -81478], [-119961851, -1413036, 695603, 745223], [-325847405, 85850, 44074, 99829], [-61399511, 1062604, 887560, -473401], [79493115, -264851, 1187163, -1198333], [220869574, 216200, 1210538, -196546], [145811016, 51806, 1331238, -270930], [-18136114, -69726, -1751720, -692352], [-92150514, 1265372, 751182, -232922], [-14965474, 792120, 1599716, -932362], [191712, -250342, 420557, -1146894], [-97091864, -780880, 392547, -350824], [-76405678, 784382, -2093564, -429580], [246720536, -497034, 1407930, -518612], [6508990, 1717744, -213274, 308640], [-70273901, 316992, -1616434, 823721], [155106364, 495020, 52028, 725312], [296377433, -71490, -1974169, -139295], [22806039, 23372, -793506, -1304417], [-99315518, 456084, -2616014, -551550], [-48488138, 1569666, 2285342, 112696], [-137912348, -542440, -1025880, 1840376], [-77677335, -620026, 397536, -101021], [-47734094, 919744, -322156, -674072], [165991508, -229218, -1331032, -328102], [355013066, 362500, -1485281, -627994], [-149133849, -151152, 1823602, -645337], [-16055909, 1069267, 952339, 366167], [255588756, -902040, 735187, 310306], [3370386, 10008, -2603508, 107328], [21400139, 11681, -1917143, -1241463], [-35538197, 1158327, -84113, -1123499], [-41156806, 268240, 2055244, 179430], [-158934218, -146684, -2648592, -1426688], [112943708, 9916, -1642797, -260458], [197897159, 612337, 895995, 770749], [361054474, 773362, 352062, -1618728], [141209913, 1582616, -2258321, -1549049], [-48287917, -80888, 487150, 1041369], [30849508, 306120, 879639, -104898], [2354572, -539058, -645602, -921244], [307595762, -670156, 315073, -266478], [145298831, 1045311, 1674217, -640791], [-52022437, -1397136, -1991232, -319773], [227654645, -747265, 305019, 1036391], [-87532332, -618610, 1420766, -542234], [369314334, -932014, -1041904, 583760], [-235017557, 753371, 2752619, 43839], [277516946, 1641436, -1401784, -970910], [226537161, 308534, -2732967, -950109], [129697273, -1063744, 1046934, 1218677], [-207923686, -472952, 510862, -122878], [-118443640, 870184, 3059640, 334014], [80328899, 1101626, -636040, 703903], [379514042, 202378, -2204132, -665506], [-196068321, 1206396, 1299346, 19829], [-338143194, -513956, 1249109, 592494], [369293905, -1095991, -1900655, 1161233], [378946416, -1468624, -2454016, 421668], [203680188, 1440942, -166662, -777368], [-142921210, -1357874, -2178320, -96744], [-88327000, -415572, -2605686, -1045906], [-106351342, -537226, 830086, -1743130], [-349906272, 478342, -2993504, -436120], [262004168, -1673320, -1701610, -651266], [27374094, -139444, -2243758, -1876826], [-36728341, -773222, 1847012, 808275], [46136908, -280722, -2271431, 219172], [36075813, -1018822, -1899911, -1412583], [17353728, -327424, -652232, 655156], [-389594110, -2235680, 890591, 1986238], [207488589, 349226, -1719039, -204213], [-276912094, 1275316, -1166146, 1283750], [-273992382, 385304, -2200728, 40888], [-66861544, 941304, 1733918, 814192], [-33882691, -226166, -3467556, 871]];
    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_6_a_k();".
// 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_6_a_k(:prec:=4)
    chi := MakeCharacter_570_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_6_a_k();".
// 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_6_a_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_570_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<7,R![94224800, 1640180, -34350, -26, 1]>],Snew);
    return Vf;
end function;