
// Make newform 200.6.a.h in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_200_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_200_6_a_h();".
// 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_200_6_a_h();".
// 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 := [-24, -38, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [25, 3, -1], [-87, 31, 3]];
    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_200_a();"
function MakeCharacter_200_a()
    N := 200;
    order := 1;
    char_gens := [151, 101, 177];
    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_200_a_Hecke(Kf)
    return MakeCharacter_200_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 := [[0, 0, 0], [0, -1, 0], [0, 0, 0], [24, -1, -1], [-4, -8, 1], [76, -31, -1], [-393, -49, 5], [376, 87, 6], [896, -204, 6], [3968, 13, -5], [2408, 220, -2], [-4842, -201, -39], [1157, -292, 44], [13620, 241, -41], [-9984, 733, 31], [3778, 1468, 76], [21676, -151, 35], [7538, 19, -155], [-8852, 162, -105], [29280, -1299, 135], [-1895, -2363, -257], [6896, 1181, 113], [71540, -1310, 43], [60427, 1141, -41], [-27090, 4846, 82], [-53194, 3605, -325], [71792, 2007, -171], [63844, 526, 457], [10238, 7221, 507], [-161583, -1308, 372], [132536, 6314, -436], [-37900, 1439, 929], [56275, 11786, -730], [-229836, 312, -399], [-113648, 15179, -739], [128560, 5285, -427], [91430, -9486, 1446], [-61500, -13592, 1777], [14344, 13735, 1021], [-172240, 11392, -632], [-140560, 21057, 1440], [-49558, -21588, 2556], [-13888, -10170, 1752], [-132569, -13249, 1685], [-76198, -15018, -1470], [113536, 10400, -3916], [85324, -13702, -331], [-385336, 25342, 2254], [14460, 26985, -153], [442436, 37378, 766], [747146, 17672, 776], [433560, -18387, 3555], [859013, 37161, 1083], [-667264, -25249, -1396], [-553374, 34614, 3498], [-346056, 21348, 1278], [207832, 11462, -5326], [936976, -27302, 1576], [569688, 20453, -4021], [219630, 2246, 7370], [-403608, -3907, -3328], [1227290, -52053, 3453], [1506968, 7011, -4332], [-299184, -52385, -4553], [131526, -12526, -3970], [-390628, -41020, 1460], [-231028, -66304, -3043], [1534997, -132840, 5088], [1886012, 27838, 9409], [-975178, -94363, 5171], [162074, 141814, 2266], [-2229848, -139979, -6647], [-639048, 12368, -2764], [-1969338, 45886, -4670], [512320, -65415, -3090], [-980800, 49193, 5753], [-2195010, -58536, -10248], [3148044, -6404, -6572], [-1509231, 207675, 153], [582397, -9234, -14694], [-391064, -164333, 11110], [1067940, 174870, 3642], [297768, -263591, -5771], [-3086433, 54341, 11015], [-2830808, 133773, -2805], [4825896, 16863, -6174], [-1412867, 174661, 14695], [2108903, -231606, 6174], [-2191292, -75956, 18268], [-2840384, -16730, 13582], [3838908, -75217, -2095], [-1667248, 57616, -21122], [-3031112, 22166, -5536], [-2966036, -288083, -13781], [4711364, -115269, -13539], [3897336, -308622, -2526], [2591666, -132536, -8936], [-2171939, 355164, 5748], [2681812, 211376, 19835], [4121832, 285836, 812], [4723080, 253559, 26576], [-6476340, 62075, 17573], [7144732, 94253, 18983], [2087217, -577676, 22492], [6340732, 186699, 6789], [4685253, 331724, 21308], [5303208, -3159, -31392], [3731497, 12718, 8962], [-1321064, 230863, 35215], [4800039, 68447, 24677], [-1526328, 90240, -23688], [-8163646, 248048, 4928], [-10739534, 193024, 2176], [4440668, -19431, 12471], [9678448, 290976, -9774], [2586, -506826, 34314], [-2569716, -421005, -34899], [-437976, 783558, 3606], [813962, 244399, 27913], [3159004, 105526, -62267], [2529608, -784783, 14255], [694358, -552988, -42100], [300256, 93458, -30898], [2128380, -37710, 9873], [3054144, 106189, -73340], [4027644, 36169, -35441], [-4120188, -72266, 41002], [-1752184, 93223, -28181], [8550304, -7887, -48585], [10155548, 624029, -41581], [-665836, 724889, -22561], [-2770992, 577776, 30426], [-321432, -246951, -18009], [14312312, 211852, 18076], [844885, -52220, -21932], [-6018271, -643847, -71165], [-3833912, 560239, -42695], [-5770132, 1216405, -62765], [-5622362, -372416, 109888], [-7897758, -218718, 10830], [9274684, -439933, -68659], [2788218, 494114, 46958], [-12247488, 473710, 35014], [14050312, -688439, -17408], [-5715372, 266129, 83255], [19908584, 403134, -918], [-5219082, 111650, 28430], [-6851341, 1039136, -118720], [-795932, 972668, 35261], [-5475272, -56939, -11597], [14942132, -689520, 39768], [23439934, 93466, 28582], [9734568, -1373797, 13172], [1994176, 1290620, 56408], [-17118092, -307007, 10015], [-8214200, 94536, -83940], [13298760, 311314, -108884], [-7287106, 523396, 75004], [-11686527, -1769945, -78947], [18171028, -2008191, 56031], [2954348, -485715, -200337], [-18833433, 1007016, -79896], [-19298968, -810256, -38296], [8764788, -572120, -89351], [-7130301, 714533, 205751], [35176128, -301287, 42921], [4940888, 531303, 43839], [-8481372, 424590, 81690], [5875337, 646947, 76929], [-47844280, -185675, -44189], [1833480, 941761, -55322], [2059410, -612253, -171019], [-15277072, 2696205, -117543], [2834817, 1666877, -99457], [-9285616, -1045755, 149835], [17705907, 405627, 30009], [-3138928, 26863, 72964], [-5044370, -274279, -769], [4238416, 1226486, -203470], [-9198342, -1056346, -86254], [-8819136, -2210602, 76406], [33312832, -228353, 113770], [258522, -1553923, -109309], [-21016907, 57197, 54695], [-1164616, -798743, 91459], [5052332, 1267458, 28326], [-3348290, 1950975, -239511], [-5612144, -502863, -139134], [-10132959, -725546, 88690], [-27422536, -2104931, -39389], [4623585, -705628, -41716], [-25601280, -591849, -94218], [-8561820, -2003210, -246239], [31271542, 370760, -37792], [9081936, -297449, 47932], [-36875114, -2460396, -85620], [-11091901, -275044, -76588], [12558502, -1831082, -178070], [-23205451, -432674, 117826], [-6018456, 1111619, -45049], [-41110310, -2233706, -206], [-26730648, 2876648, -10060], [-48738216, -1862212, 151436], [-18959765, 1141336, -74240], [-16688420, 33601, -112001], [52498310, -512330, -117926], [13279704, 731468, -19570], [44772764, 357465, -128001], [2950254, -2981736, -307464], [12445500, 2294581, -196985], [10725150, -1608968, -359192], [65306090, -232311, 94575], [12416856, -2557321, 45737], [16946516, 2668418, 210953], [78618936, -358528, -60118], [-53578495, -2190538, -45862], [24706352, 964590, -86256], [78713793, 1134253, -264953], [-29140016, -2525825, 309115], [61195846, 3483233, 250415], [-62615578, -116808, 184752], [34413480, -4181329, -9547], [13834661, 486145, -344189], [35746640, -2506591, -176167], [66135352, -237587, -176942], [-2843594, 1545177, 47487], [31204061, -3388841, 194989], [89016520, 3528881, 165647], [-41641032, -1380001, -147139], [-34498880, 2183495, 170600], [90191862, -568307, -112133], [25184452, -171668, -642737], [-68580256, -148497, 88203], [67735411, 54585, -277221], [1250004, -4719189, 377001], [-18118488, 4394841, -140007], [-40075759, -1366531, -370417], [3413016, -607497, 265185], [33086152, 953433, 166386], [33754208, -2436802, 309470], [-35931824, 1475117, 307130], [-78192792, 338063, 55688], [35104744, 3957074, 301820], [-26628828, 2165906, -234034], [29642133, -313204, -599476], [-13728512, -4307926, 556646], [-58827616, 2337483, 377991], [12148228, -5636683, 208811], [20174096, 2458369, 326518], [13363288, 1993917, -252885], [8019400, -115598, 269974], [64402619, 2131348, 106348], [45731728, -5266085, -128897], [54217367, 3837759, 125541], [-23274336, 5873951, 148625], [-62416884, -1447422, -130455], [-29959176, 352561, -255233], [74231296, 5208271, 103354], [15824358, -973671, -133689], [1224563, 2536226, -249898], [-99096928, 2106735, -150549], [2016628, 1667148, 244845], [12648872, 1113221, -232717], [8155684, 7224249, 573039], [57390055, -1014219, -436545], [-43089896, 4089909, -581316], [-94000122, -2230834, 437546], [13957022, 366794, 148214], [19031020, -3246446, -46127], [-71280162, -4176869, 144517], [-38824300, -7114527, -510537], [80755036, -3514054, 577811], [-161102963, 4216465, -209405], [-176389848, 3593329, 42055], [144634046, -3357872, 185008], [93219368, -7369586, 139294], [1240996, 318356, -405769], [-58328144, -5841652, 44060], [-81771362, -2412436, -298636], [23732568, -3730683, -875388], [-62744784, -3711438, 755082], [113651384, -1308916, 495266], [-33063000, 4342712, 303608], [6599668, -7466940, -197076], [57966080, 373479, -418458], [-37899976, 2829250, -96578], [-2817022, -6542996, -196652], [-71060776, 344747, -602491], [9450920, -6480466, 909962], [-56078814, 9123312, -284208], [109074034, -1719111, 415287], [134658780, 2606745, -533673], [-90362415, 8855481, 66627], [103331576, -4462969, 743660], [142113452, 2986584, -496704], [120628846, -6132626, 89986], [17127768, 12049705, 243721], [-130093824, 10878429, -341469], [38814668, -1897385, -56351], [123865964, 258224, 541973], [-82866233, 4656094, 497938], [1395890, 10232141, 455819], [-37055832, -2210312, -690992], [219720032, 1048747, 62848], [8873112, -9922389, 93312], [-137935845, -4491911, 173299], [43298756, -9360067, 946187], [-12628330, 4222957, 674635], [78619664, -5398636, 33470], [-117771350, -6350367, 1064751], [-49453536, -4906427, 141469], [58272546, -14570532, 36564], [-43140563, -767399, -362669], [-23780692, 10799313, 507195], [-223730456, -6512580, -253872], [98871046, 5480322, 366558], [47084896, -3645357, 299346], [219808296, 4511784, -613224], [-71921231, -4587658, 267770], [-84132013, 13174966, -393446], [-73038508, -2398593, 1503609], [-75851989, 12201034, -70850], [69056148, -1937811, 142419], [61960216, -3017812, -165598], [-54594970, -14059326, -600450], [105360450, -8188170, 622842], [126238924, 14055240, 577959], [-136740284, -3850701, 740373], [-305318824, 3632485, -268799], [-54833140, 5269475, -428539], [146877828, 2869291, -837683], [81346950, -7316879, 546391], [122810824, 12028509, 15417], [-61320, -2460161, 313396], [-30691916, 13121370, -392565], [194860916, 9144359, 692189], [-212098040, 3569333, -12061], [274289694, -6661152, 46272], [360069643, 4472385, 286443], [92598360, -2960133, 460611], [-223435584, -5378290, 1133258], [-12262233, 10636794, -328866], [254783158, -10198776, -105168], [32297024, 6164835, -410511], [266730770, -3530628, 466716], [-191087228, 4932021, -508197], [-22593348, 13213265, -416641], [47312936, 12563457, 206676], [-72173392, -174913, 636281], [17419962, -10404747, -494757], [-167635284, 21340016, -677677], [181529662, -4994678, 776230], [-15817738, -2240627, -1022429], [-184217696, 3614631, -217131], [-244723414, 7677936, 570120], [-233319703, 7592757, 683031], [-102972504, 13896399, 826629], [68150868, 2217902, 909863], [131209682, 10188696, -1058136], [-116782752, -17450590, -1357726], [31417582, -14063625, -665439], [-330836233, -1061063, -66149], [-79494280, -20120747, -532115], [-354216404, 4594321, -342569], [142155652, 8087302, -1326401], [6467313, -10862597, -1371647], [336719952, 6674427, -598971], [-67754984, 7863936, -146352], [38703125, -6105078, -2020554], [246445140, 178239, -1423071], [271148732, 2566932, 469773], [-80580192, -7508860, 2159312], [103909508, 9138992, -651640], [109952032, 4792342, -1381670], [-103251270, 11654639, -27559], [128575056, 9474681, 712548], [-159502544, -22839163, -242947], [-59382499, 1283734, -1630190], [-54035979, -6029163, -287265], [5007694, 8677476, 1133004], [28967986, 11246402, 682262], [154426871, 12428430, 1134186], [129813264, 13445949, -934701], [202664817, 6126612, -2330844], [34592116, 3048871, -215099], [-154110528, -5625533, -1796525], [269061432, -13235884, 149972], [-353141760, 795612, -148764], [33891556, 31004743, 211429], [-65711088, 4384948, -531470], [-106192477, 403450, -1922], [95340316, -8995778, -2168942], [-442494568, -8870485, -73792], [-53497180, 55734, 1050183], [-1261392, -17368988, 1445014], [-144457093, 1637896, 1406848], [23899176, -9423464, 2132596], [202783105, 6891874, 226414], [-126489724, -2516136, -868911], [-79518454, 4669430, -545134], [29235968, -16818121, 2493209], [166317423, 4257909, 679095], [65959144, 20131253, 1837871], [-417473929, -15359644, -243172], [139923144, 4716168, 100752], [15080432, 17082371, -1225747], [104272190, 18614448, -64224], [7482426, -2667930, 1603962], [89915564, 2379933, -687501], [-89859276, 13237782, -1280151], [-55960031, 4447310, -316846], [-49603632, 20252364, 787572], [46309344, -14704819, 1535948], [-354342668, -3457017, -884079], [-348675771, 14941591, -1032059], [-493943770, 1833677, -350389], [-182511232, -1591034, -781688], [324996840, -30572276, 1746922], [375125067, -14699535, 934371], [204081024, -4220037, 1342935], [414503872, 14836441, -724529], [-84991174, -6398589, 502317], [165520, -5945032, -2908474], [-75050400, -19839997, 1721276], [-407251421, -12009032, -1156016], [95340216, -26644821, 1088037], [534107500, -6926687, -1396085], [-393754761, 10103451, 1067889], [-45562164, -28854482, 1366207], [95301568, -129538, -1584784]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_200_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_200_6_a_h();".
// 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_200_6_a_h(:prec:=3)
    chi := MakeCharacter_200_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_200_6_a_h();".
// 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_200_6_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_200_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![1095, -441, 1, 1]>],Snew);
    return Vf;
end function;