
// Make newform 230.6.a.d in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_230_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_230_6_a_d();".
// 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_230_6_a_d();".
// 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 := [-106, -47, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 3, 0], [-31, -4, 1]];
    Rf_basisdens := [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_230_a();"
function MakeCharacter_230_a()
    N := 230;
    order := 1;
    char_gens := [47, 51];
    v := [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_230_a_Hecke(Kf)
    return MakeCharacter_230_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], [-11, 0, -1], [25, 0, 0], [-39, 3, -4], [-173, -19, 17], [10, 37, 46], [-402, 32, 39], [-563, -77, -5], [-529, 0, 0], [-1589, -158, -232], [-3180, -63, -151], [241, 441, 202], [-713, -200, 626], [-9829, -473, -1065], [-429, -602, -783], [-11682, 1438, 123], [-12046, 368, -527], [-14605, -1651, -549], [-28455, -1847, -604], [-34862, 1563, -1231], [-23156, -2879, -1880], [3523, 3201, 1627], [-22438, 1436, 625], [50523, -2405, -1701], [70229, 1809, 4551], [37368, 2968, 1839], [30978, 3786, 1178], [18321, 8853, -1248], [88529, -4743, 2103], [-36777, -6935, 5232], [48611, -11844, -7983], [-168238, -2935, -10100], [-19576, 13920, -10502], [244840, -2153, 9763], [171920, 11542, 11248], [-194020, 5587, 14862], [-77767, 3915, 12696], [165017, 3258, -20259], [90866, -6274, 16762], [38978, 9992, -24002], [103618, 14255, -34636], [-96863, -29425, -24719], [-185946, -33956, -17118], [181580, 15757, -43302], [16878, 5879, 37158], [-50845, 16089, -38343], [-385262, 4248, 6109], [322690, 21714, 68584], [-207419, 11609, -16555], [10775, -54457, -60177], [193914, 13577, -34416], [-480140, -30875, -62791], [-436332, 60734, -14926], [292112, 39588, 48274], [25210, 33129, 32396], [-363879, 9013, 39438], [63143, -67426, 14530], [-212262, -20648, 53579], [587318, 66087, 98466], [-194301, -31489, -60483], [-518620, 85068, -21675], [-1723760, 9618, 59267], [-1386836, 6652, 70774], [-841552, -21957, 81622], [100678, 5736, -58787], [-2054598, -46340, 104190], [-481208, -101313, 156865], [-696721, -33185, -18471], [34446, -10642, 169614], [1106207, 87338, 168432], [-7232, 38789, -132526], [1528733, 90767, 72289], [-991508, -56390, 288265], [476460, 52894, -59758], [1382520, -249288, -109828], [-910043, 85251, 27158], [3284612, -26600, 87382], [204394, 75329, 143008], [2606884, 64194, 89210], [-1171795, -99360, -388104], [2088717, 11841, 265767], [-780227, 673, -220049], [-2983061, -150629, -340177], [1718620, -297852, -275123], [1519834, -16521, -279356], [-302647, 42648, 195751], [3543696, 175852, -153849], [1973830, 97848, -122399], [-821181, -30524, -346617], [-3925160, 24416, 2722], [-2624364, 244704, -26289], [4348592, 86464, -201932], [-2217119, -222230, 358759], [20054, -6179, -73643], [-3274, 139667, 621609], [1971458, -157658, 87655], [3896885, -46806, 400165], [1709800, -235216, 244670], [-2135103, -70891, 272609], [-3546067, -98226, -129303], [-6400985, 421092, 300445], [-748615, 55051, -579794], [3121890, 203732, 34683], [4790676, 154178, 62118], [-7888996, -322040, -421620], [-4543414, -54465, 11856], [4701919, -281314, -150661], [-3401382, -447780, -54678], [5495366, -531086, 101638], [-8650217, -185326, 102232], [-1610788, 693148, 728676], [-3607086, 617578, 217196], [6049401, 259701, 601920], [840290, 80514, 690342], [-6450317, 549799, 399811], [-4993099, -37343, 847891], [2739578, 611266, 464325], [-4081063, -317256, -567935], [5151650, -241943, -85994], [759724, -555928, -874702], [-6962018, -263688, -289880], [-406402, -478859, 881232], [9367142, -85814, -440519], [-649881, -331316, -152415], [4408046, 371858, -528774], [4131613, -1102419, 117185], [5618105, -360747, 121989], [3290938, 293660, 1465625], [-11111234, -475486, -1276985], [-2132418, 632200, 1024151], [-17089104, -276193, 949277], [-11511858, -428202, -425298], [1201697, -38547, 1389075], [-219045, -560557, -49846], [-2359813, -256854, 722974], [-6685292, 201530, -1205804], [-1047111, 310601, 1389111], [17954326, -977916, -236699], [28083689, -366703, -335240], [-6928636, -630468, -1302737], [-14873870, -550201, 350323], [6178644, -223922, -2063910], [-17738605, 436698, 765477], [25875342, 479980, 551931], [6225994, 336646, -1369349], [3392649, 1223037, -1074081], [-9629790, 160268, 1234700], [4055184, 112763, 1534188], [-4935556, 837801, -982599], [-14855021, -144292, 428843], [10355920, 718226, 2255194], [-6231116, 1315280, -756124], [-25550122, -334474, 63906], [2277507, -752498, -1597773], [-3918163, -788687, 1146288], [-5122675, -103365, 1640185], [-1981835, -846867, -1322735], [-5249925, 830440, -1318752], [-8751541, -1146399, 174633], [15947342, 803446, -978362], [2609485, 1318740, -1286233], [-8796664, -437798, 423994], [3086769, 517398, -1063849], [15357982, 68308, -1406974], [-5765463, 2094949, 2485284], [167424, 850468, 826371], [-20015988, -414178, -2098513], [20033732, 55298, 1273968], [-40329649, 144445, -882309], [6674498, -2416499, -1443440], [-20247115, 134219, 2924053], [-2400857, -36942, -651662], [4700836, -2107328, -981838], [-3639796, -1278566, -2733903], [-19242992, -451475, 1544242], [-5828043, -49703, 1569057], [-12061366, 2046411, 2267712], [-25807735, 564710, -1365458], [36199039, -1047137, -570752], [-2995644, 1531488, 3988190], [6101769, 1851726, -98863], [12256983, -935765, -637761], [-23518598, 1040991, 1161778], [-2508868, 1089162, -341858], [-11950712, -1087704, 3945521], [7610410, 351114, -1743316], [-15342958, 692400, 2256564], [20625247, 358407, -2228324], [-32512725, -1714018, 183002], [-8396424, 1415318, 1527597], [425200, -234629, -3096668], [-27855560, 1955980, 1750838], [18398270, 1915804, -3494472], [21212652, -1979408, -2689755], [-13092688, 3321002, 3135292], [-36534773, 465201, -1825774], [36751543, -2895791, -680387], [278644, -43872, -1396130], [-36286714, -2018430, -2769152], [-8318675, -2010738, -2101267], [43424524, 2365976, -3054928], [-32456342, -419090, -335738], [16884258, -307513, -404782], [-21073647, -2363077, 1979087], [38784586, -3591786, -2281498], [-17757696, -1162107, 729228], [25683431, -2191135, -2873961], [31804395, 367922, 4183815], [28498581, 1833886, 473016], [19264022, -7893, 4730868], [-2354614, -4359651, -2363958], [39487671, -1116286, -3132921], [63366143, -92269, -1798437], [5890224, -1937282, -17256], [88188498, 673444, -938571], [53219593, 388589, 1663081], [30781497, -505368, 3841469], [-37272351, 988236, -380448], [63169098, -888534, 3557211], [-6999606, -3828879, -4853574], [13337005, -2216050, -7926620], [33922961, 3725799, 4851483], [-36896781, 4597218, 1933164], [77493589, 299555, 4552750], [69410175, -5161982, -884373], [-78481275, -3197914, -707122], [-45492383, -1235573, 6008891], [-6152640, -6076321, -7515471], [10995564, 3870730, -5749636], [23322108, 5062518, -2901507], [11711998, -2212572, 1041772], [64259535, -2632409, -2807539], [-35236724, -2264866, -6659306], [2010014, 102050, -315683], [82191596, -2018910, -498369], [41765331, -392865, 3177723], [-26560226, -1971178, 3847030], [48795703, -1315695, 5058701], [-63062904, 5667541, 103377], [-83572346, -660355, -2319175], [27705528, -666350, -5005641], [18668210, 2827975, -1729485], [85697455, 460446, -4878701], [27645405, -921672, -6201427], [-85761444, 2639594, 2195916], [-38290022, -283255, 6452444], [-48594305, 2285846, 4114825], [-7980442, 236880, -165272], [-27077608, -5781894, -7534554], [-88189000, 3935144, 598339], [-48712212, 3054564, -180226], [-102270484, -2578034, 6654250], [-19018106, 515998, 5543447], [-64887911, 4004233, 1656835], [-20270982, 4135308, -4041060], [83819532, 998795, 6186393], [43836107, 1232665, -4307697], [7888176, 2503230, 5092124], [-92515120, 838265, 155212], [91162686, -1406681, 158690], [6087256, 3126242, -253979], [-39940761, -5751355, -10148544], [37760842, 2483938, -3910415], [15065175, -756611, 1425266], [-48966266, -6740760, -518482], [-25877431, 5599483, 3942297], [9171631, 393709, -6629377], [19569993, -6077827, 6445539], [74465335, 1539099, 2045860], [38014390, 3010695, -13349980], [-95734801, -1888286, -3962562], [-30824870, 2586278, 124873], [18942055, -1781723, -9282536], [839801, 3798241, 4617711], [27081026, 4891851, 2766888], [-37011603, -6161376, 2112209], [-23473412, 3367560, 4760876], [-99894938, 376306, -4096505], [107332266, 2094628, 8532074], [20658884, -9427796, -1981640], [32550949, -867098, -13548667], [-92068540, 66530, 1198452], [101886581, -1419741, -11573123], [78779556, -73062, -1186600], [158716012, -3112768, -4350662], [-64186380, -10209366, -4351299], [-596938, 5569086, -4501497], [-64407693, -122771, 8623569], [-90944446, -987350, 1421538], [-136828222, -3670400, -10754072], [198164566, -773228, -5538292], [89408172, 2836806, -10954515], [-172541290, 10902544, 4215982], [85806111, 6667137, 9403563], [169082564, 266821, 7108998], [91906436, 1988286, 5383936], [8408794, 5356282, 335908], [-67443120, 1560435, -9789852], [112618992, -8026373, 3695487], [58162505, -2240082, -8101731], [171710903, 1949945, 2431494], [117693, -6028979, 10310022], [108123172, -436008, -15113096], [-75494969, 9748760, -1480783], [-16215240, 5041052, -15279700], [-215620278, -1855119, -6331228], [135354068, -858292, 11513458], [-161499094, -2820870, -7534608], [87002942, 5394108, 13369930], [119324470, 10283296, 2213398], [43433033, 3092504, 10822927], [-19610309, -5519767, 3911765], [132729516, -540988, -1486428], [111837339, -4235052, 7562249], [153369903, -6900357, -8476632], [-219810871, -5989751, -9090903], [-30715668, 2694759, 1801605], [-157542858, -2992365, -14542221], [46863058, -2342712, 5049511], [-58069171, 7084132, -13798931], [190421637, -3151931, 5104289], [-34427587, -3095105, -3293400], [104456283, -14923554, 5532255], [-41457978, -8306570, 9505724], [-110543564, -4685856, -12247459], [145144452, 636524, -9550780], [-148967316, 6188570, 11842844], [-68727267, -13391626, -25429195], [266884523, -553935, 3266467], [63141434, -11946676, -1505435], [104574181, -8965796, -12618842], [155880280, -11047453, 4027412], [-225172990, -526771, -13358355], [71392677, 3197122, 21473973], [-136714019, 1293479, 14180929], [100879685, -11798658, -1457969], [-20464270, 6638280, 14365968], [-54921991, 2908961, 5744491], [-27163311, 7777136, 4648541], [153517021, 189327, -1572584], [-5370482, 4289821, 16667134], [23955027, 6378855, 16692573], [269797026, -3664456, 559176], [7236166, -13292472, 4248610], [-159576086, 4495994, -14543155], [-207834896, 9751746, -2042611], [-26980353, 5860512, -5457610], [99080968, 8601316, 101902], [35985460, -1154182, 10108190], [41431374, 7451402, -17082567], [-85730668, 14535621, 20221011], [-62572372, -11636895, -10217526], [237880878, -912322, 14270097], [-60229282, -10209998, -13527885], [-258422608, -10918728, -15586056], [7347192, 8996854, 8334534], [-52821894, -15932486, -28658004], [-245393856, 11542470, -526518], [-151599912, -1078811, -14414892], [-6771152, 8499876, 7649306], [38149430, 6013530, -5591181], [184268213, 6766900, 10324696], [-32026537, 11364508, -15036881], [-140610298, -4113048, -15516050], [-4641951, 16232302, 12598121], [-121069682, 17581631, 16675366], [-106091862, -2974191, -25162764], [51733109, -13660383, 11148864], [-334661614, -7656644, 141834], [-9899968, -7914873, 20789491], [382291696, -5792370, 4240003], [-203184375, -5741488, 2504457], [230785510, -13477414, 1774106], [-349543292, -1389180, -8921120], [-116197994, -5869387, 19513138], [-842738, 3663565, -21732877], [-56819559, -1441925, 6639027], [51683116, 19985600, 12405433], [-68651760, 5734308, 37331388], [-68008974, 11085113, 20979290], [225154824, 3118262, -14184174], [-112302591, -11810189, -9771237], [-231566852, 2302756, -16971740], [24603458, -13696055, -15270422], [-66290947, 14735193, 5692497], [-135398181, 1647148, -25750149], [-127619886, 3883093, 3009023], [-252020384, -17638482, -3221336], [-97930416, -9141584, -7643905], [-29169732, 20902750, 29781555], [-11527466, 6306334, 44545084], [-57609650, -6756732, -9125308], [-44752886, 6155731, -32742703], [-326019938, -19744834, -30701954], [-335025189, 9892631, 21854049], [-60914582, -14660898, -9067505], [-115244737, -24395073, -47248875], [147976617, 3165249, 20547405], [58371144, 166372, 31736924], [187092006, 13827134, -2566293], [205177241, -40493894, -14563998], [-251831660, 2381517, 1264280], [-115981851, 7752111, 15101678], [-71650982, -11556312, 7391297], [263845091, -15793344, 8573716], [-87373016, 753121, 17089411], [81757091, -28542789, -34546710], [248117491, -21343660, 14802323], [-71771635, -275259, 7566309], [99107360, 18355244, -16258028], [-32246762, 7517117, -27924200], [409474820, -976801, 819784], [205867409, 10451847, 30051901], [221289430, 20177944, 22601038], [-30452267, 21050585, 46753696], [-66084515, 17912886, 65909], [-96767032, -6416600, -29185928], [49460952, -8966344, -32312296], [-526492245, -4290679, -5433120], [1860475, 2905443, 31684667], [328436637, -10150507, -34047225], [388491949, 20837049, -1550213], [-355525314, -17944922, -119220], [42425104, -12233252, 26080100], [-539997968, 17927757, -3703982], [-75650576, 12947107, -16562170], [-568937461, 16145189, 6514951], [-454214794, -3013922, -13336979], [390347032, -16110865, -26801222], [43314638, -1647909, 9635809]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_230_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_230_6_a_d();".
// 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_230_6_a_d(:prec:=3)
    chi := MakeCharacter_230_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_230_6_a_d();".
// 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_230_6_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_230_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![-600, 169, 34, 1]>],Snew);
    return Vf;
end function;