
// Make newform 200.6.a.f in Magma, downloaded from the LMFDB on 24 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_f();".
// 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_f();".
// 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 := [-60, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [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], [4, 1], [0, 0], [-4, -2], [-100, -21], [-296, -52], [139, -16], [-420, 59], [-976, -98], [-2340, 148], [-2504, -354], [6250, 484], [-2667, 936], [112, 1076], [13036, 0], [-23406, 360], [-40888, -416], [-23466, 44], [34404, 323], [3724, -344], [-54411, 72], [-54052, 3062], [13612, -3841], [35495, 5024], [-48426, -3800], [-75534, -7860], [100276, -1240], [57260, 5165], [70714, -8980], [-32127, 11064], [-54896, 7738], [133880, -988], [-148469, 4104], [122708, 2939], [268884, -12964], [122748, -12134], [-122882, 27104], [386276, 5643], [-166580, -6512], [-174096, -34088], [298028, 21727], [-224134, -20856], [149864, -14846], [76475, -3216], [188770, 33168], [-212480, 18428], [-659420, -22459], [-384176, 15660], [796568, 22316], [-879396, -26920], [-24790, 41936], [-368508, 41148], [-463215, -14888], [-453436, 84869], [767530, 15400], [-1315224, 24726], [-1305376, -42320], [-413976, 98910], [209556, -6676], [337334, -89544], [-577676, -23997], [4254, -24868], [-251700, -87527], [17268, -140026], [1263198, -104824], [214028, -80680], [-2532212, -19145], [-341835, 73864], [1551172, -50971], [230386, 22564], [426594, -133256], [276084, -203418], [-4253640, 27020], [2615534, 37224], [2631580, 54225], [-240900, 116226], [2611998, 153168], [-2094756, 46528], [3088757, 151616], [25317, -390592], [3215004, -157473], [-2173268, 268984], [4301028, 81542], [638459, -184736], [-2772716, 213588], [749996, -340345], [292377, -237504], [-3955233, -282512], [309652, -225080], [1784552, -376444], [8519040, -34268], [-1620336, 444202], [-5713696, -196854], [1389816, 414900], [-4347816, -141572], [141488, 124724], [-2776494, -223808], [524845, 107840], [4661844, -164831], [-7154632, 342520], [2135468, -415751], [443152, 246404], [5566248, 455336], [-3397855, -339872], [-5837488, 587812], [-1959467, 133800], [13406660, -154057], [-4227951, 616248], [-3995972, -204962], [-8185221, 475136], [-8455544, 506536], [4697026, -44144], [-1202638, -453376], [-696520, 171756], [-5065872, -848362], [7369506, 18312], [1625920, -264332], [-1308912, -224580], [-1253826, -995780], [9343556, -390343], [-10216044, -623028], [13850374, 9088], [-9060680, 382008], [-2730188, -400031], [-9371700, -931841], [16653224, -59948], [5239820, -534552], [17202892, 284186], [-24254916, -199948], [13885432, 102028], [8002864, -157148], [-9570928, -382498], [2143780, 1280476], [-4823736, 197576], [8837893, -709064], [-3656659, -486752], [5999676, 537036], [-6642408, 557060], [-6074522, 420160], [747450, 779112], [-614992, 1190724], [14295122, 839880], [-1948856, 322532], [1674852, 690615], [-7901216, 483204], [7754992, -633792], [-377138, -1356120], [-12555853, 583904], [-8787084, 529435], [-1631740, -2012092], [-762700, -1837896], [7282870, -283400], [-27319812, -40447], [34264016, -341876], [-13389200, 938812], [-15082136, 234956], [-11333248, -229134], [-29542418, 598064], [18576949, 67424], [1666080, 384076], [2501624, -2696576], [-28357625, -1458224], [40914408, 699528], [-8974828, -1799837], [-28000417, -222000], [9014204, 2742050], [3733404, -1081514], [18597132, 2007840], [3247629, -1596080], [-11028476, 1482788], [-22541948, -1032783], [1250614, 1053324], [-11748580, 2160574], [-41546243, 1174992], [3882844, 83420], [-10347881, -2900000], [40715668, 334941], [-13868390, 1940628], [41131320, -1063136], [29125570, 2583216], [32089768, -2435700], [10049860, 1518847], [-49402506, 1751996], [-49602511, 1061848], [52581044, -403680], [33175940, 2256400], [25033266, -2713588], [-1120820, -1484139], [38712617, -2972256], [-46202524, -1574004], [15904593, -582400], [58061604, -1632885], [74770636, 546317], [37806550, 1914456], [-3917452, 1383325], [-48817402, -804144], [30184915, -2057120], [36283886, -1853368], [-26906979, -2799608], [33804604, -2745646], [-35109790, 535712], [11581704, 2351348], [36269928, 1314920], [14200779, -1034904], [-8342952, 2052444], [-59786034, 3105592], [29822056, -2753442], [-34145608, 1169092], [-28318194, -3540144], [53076264, -1120064], [64047614, 788352], [-21770794, 1753204], [-6626084, 2314692], [-11822516, 1123321], [7037176, -2133634], [24401481, -1011912], [-13701576, -1215998], [3107517, -40648], [73507956, -2812110], [17830802, -3851108], [39360902, 3271896], [2086732, 6023472], [-61295343, 3975832], [-57301844, 2555050], [-51645052, 633161], [-40879774, -4108844], [-96496751, -858592], [13998116, -3317060], [68905500, 4396184], [-46714780, -2039375], [63290514, -4098092], [-20034092, 6043873], [21223364, -1965966], [-50016705, -1578392], [-104823064, 958832], [26009316, -3756942], [-67792115, 1456960], [-71762068, 557372], [-19501660, 4618365], [-76376920, 3893468], [-10894244, -7616127], [4050028, -2531511], [-92364000, -3950174], [-3640068, -1793992], [129148389, 381016], [43711640, 4823176], [24150548, 206730], [-20755408, 7161964], [39798220, -2720415], [-26291196, 10907908], [45918048, 2477040], [117431659, -1652176], [-50082876, 7851234], [62158059, -2582624], [145080852, -2130716], [85324548, 1532313], [-13991740, 3760380], [-88706044, -1365409], [-45556910, 5254444], [-93515189, -3994880], [101206532, -349422], [112506820, 1908827], [95201444, -5497468], [88149776, 4383748], [11286211, 5082584], [82432324, 3712767], [71680558, -4140592], [-133431018, -5052168], [63591716, 5696705], [-126379294, -585020], [46309600, 2273204], [3492404, 5007327], [-36150407, -211640], [-81863292, -7317596], [-97612866, 9149696], [-4189328, -4731252], [135405524, -2907023], [-8820352, 9315528], [-1104402, -4024208], [63403908, -6145209], [6450984, 1186284], [-44032184, -10018214], [-145137656, -7865488], [-254244828, 409088], [164553572, -5162613], [139089456, -4596296], [59229458, -1914800], [-46811556, 1934580], [-13260432, 15997488], [-49465694, -4326464], [25564382, 7225308], [49749688, 426316], [-123957411, 9891360], [-159200100, -8186499], [24155916, 13716904], [-73259562, 80376], [-2927916, 9540082], [-94593828, 9011964], [44680432, -8595412], [109672492, 6047215], [-248160401, -3448520], [128406222, -9548604], [-254103032, -4313416], [-21699788, -7513003], [-46500052, -3325675], [118836455, 773808], [51605840, -672892], [-269618382, 2536292], [-108361920, 8366694], [-86115338, 14673180], [-164441620, -4049966], [151974962, 9335456], [161550137, -4105552], [-21844120, -7546368], [-5210952, 17696884], [-99793378, -4539272], [-177625196, 2024675], [49344328, -1053344], [293248313, -6197352], [-163600485, 8629624], [-242852456, 4838540], [-19293277, -4290224], [-127002832, -6004228], [-68705880, -6453062], [20994494, 7269976], [-48421558, -13912936], [257042988, 4596173], [-71515080, -21815380], [-107281692, 14528158], [1791984, -14434692], [200212424, 14143500], [183582290, -9060668], [17460852, 7143758], [106417148, 21584029], [-375251636, 5242215], [-228007656, -10027632], [-120976444, -708444], [146843742, 7607328], [-160392649, 17267536], [-34362804, 1648206], [133293736, -2901456], [182285023, 11855488], [96415126, -20284792], [-19609772, -27340432], [192404066, 406936], [289458224, -8461188], [-236429304, 10903388], [75035620, 29002811], [-195589548, 14579244], [-70509962, 2300236], [-282308692, -6558743], [-286945930, -4686712], [273723090, -4573940], [92035108, 3677016], [46122090, 6944296], [110283589, -24406944], [79748556, -738048], [276907804, 9308903], [357904690, 9635616], [-269070952, 8972292], [-90521598, -1203652], [61667011, 18176744], [-437507132, 1159922], [-195089944, -3169132], [-102583444, -5775145], [46356757, 16943096], [145056916, 20258020], [105202392, -26629072], [108919309, 6356984], [4553240, -19151548], [184778348, 5360883], [-429421680, 1998316], [164856196, -20871128], [-363091960, -1569928], [143307118, 16930284], [-265979412, 17079987], [259358972, -8620622], [108872293, -9164544], [361499409, 16990872], [-213380162, 22352256], [-116533814, -9068064], [-315760737, 18740048], [413053436, -656452], [207203809, -16754024], [-272639144, 15706888], [-132232620, -11899402], [-161529432, 31489640], [-84470704, -3468784], [48856328, 24187784], [127473216, 37786082], [-332271909, -1740064], [-194760572, 18648472], [-539198420, -5449259], [130344716, -6128385], [227348640, -14448610], [-190371429, 30536888], [-293088504, -19767932], [-95762535, 20065992], [183571876, 35206907], [-533379438, 14107872], [-164351212, -10273948], [-91165429, 6053696], [325609268, -363240], [338484327, -647952], [333960168, -1060248], [181165444, -9544508], [-57400258, -27100560], [201552258, 5961384], [-113809800, -5048036], [-449480804, -6105275], [-173677303, -9689208], [204704224, 31346512], [343399404, -6022697], [-66720680, -47444340], [-40919879, 17773352], [176939074, 27665284], [705091624, -1528750], [52629752, -20747598], [-118842953, 37504648], [-156807116, 30036682], [376236332, 32656388], [-213350882, 10326740], [88844592, -37571110], [-476297132, -2059855], [-138051965, -27619976], [205587516, -22342188], [-148403672, 2312032], [561082907, -8218456], [45233300, -32629713], [96327432, 36142994]];
    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_f();".
// 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_f(:prec:=2)
    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_f();".
// 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_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_200_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![-225, -8, 1]>],Snew);
    return Vf;
end function;