
// Make newform 126.10.a.d in Magma, downloaded from the LMFDB on 28 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_126_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_126_10_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_126_10_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_126_a();"
function MakeCharacter_126_a()
    N := 126;
    order := 1;
    char_gens := [29, 73];
    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_126_a_Hecke(Kf)
    return MakeCharacter_126_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 := 10;
    raw_aps := [[16], [0], [-1590], [2401], [22668], [-64186], [-29946], [301484], [-1237488], [-391806], [6802688], [19279766], [10487358], [38420876], [2928], [68190666], [-79636692], [-37203370], [58234052], [49349376], [345747674], [455981888], [-446212188], [571901790], [244250210], [-1313905350], [-153761848], [211407132], [2685025406], [-952202034], [-928822624], [4752013332], [6967872294], [-6390555964], [10011424170], [4952576072], [-4307885818], [-12455437516], [-16708331592], [-20789349342], [-13013476860], [2557979822], [9940106568], [-10711917502], [11476697562], [12078457976], [-53922880060], [15475222208], [-68412172188], [6070171934], [21186168870], [30666840984], [-58707666286], [81356054940], [3389687670], [-71854174704], [-13926429678], [131656040480], [-36367423018], [116968980150], [157634683220], [134540487450], [281460116972], [-184532511144], [-16163234998], [8958846018], [-37710920788], [202981432178], [188559397356], [-140280459226], [-74430645690], [231256044624], [-294257416048], [270035471414], [188183183420], [282828654480], [758057983098], [558142365782], [-713586662466], [-671416522054], [-785557262700], [841170350054], [991534868808], [-209921891614], [-1050609034888], [171164264988], [892199053566], [193570786442], [-1202643251262], [-1285201050496], [1376191467156], [1155988393152], [-672883357192], [790635527820], [273133992548], [-1570833681912], [1241424242850], [-688836714834], [-493203256972], [3709832062142], [3354881109140], [-4396686297582], [-2188356924], [693421630806], [-1714945930036], [618396050306], [4543658025228], [-4236217661418], [3374029421520], [-3093335382022], [437822773472], [-2168582899498], [-1320982468506], [3979035318548], [3793182780296], [-7025894188914], [-6148861862452], [-2171489853864], [5475839082834], [4674900876516], [334777478798], [-2470289937982], [4489334649930], [-8329622827476], [10635248704988], [-5022836185086], [-10300504456906], [503659827264], [-10486307305384], [12929511398726], [-5318223771724], [250527069072], [14388164497280], [-4390874451898], [4310459507406], [-12753053153710], [-12612079263270], [2631645080732], [-21138395598], [-6739012256970], [-1434653924524], [13855309367178], [3121547580488], [9345752707500], [-11148143181082], [24431493844440], [16737914088542], [17935460482254], [17841721263140], [-13267611939048], [25171702047038], [-21206944992330], [27975283870916], [7691553409800], [-8031875885764], [37076416211304], [-23238729605320], [14738602614150], [-38639644996246], [-41264287974750], [-32525471308092], [-23078809836090], [-15335798630776], [-19897138640436], [-11688716512578], [36875780297304], [-41034682149856], [-499823152738], [23247078906674], [-25901886553350], [11248260813996], [-45844774357786], [-31561534209120], [-4392335551318], [-58150630737664], [39994223396238], [22109075156828], [-26779745629830], [-2741437818376], [40647063240326], [-14515235086912], [-34098297836796], [-66916116479050], [-41745918078978], [-56016633491400], [-92892634716198], [74165397928094], [40788935361164], [-11721635148886], [-80023181991600], [15035859669746], [61538326727292], [-30338358369244], [-2361575967630], [12736915188612], [41865241788798], [44198544036530], [-81870782115922], [-6236329023594], [77622179161800], [117957031808658], [33529208464352], [119114253074558], [80527199091410], [85471304979276], [-163697355646014], [40765529492048], [-45429248715468], [-11914121487978], [29666728645940], [-138289840792846], [125640829276506], [-89456235431704], [56762787050940], [57464763776808], [138333151233434], [-166024788975088], [-41444995011546], [23082324385728], [203974833639330], [-172750191780778], [211432423026440], [271136945016606], [-108842752785472], [-69348428386812], [-61821716797114], [198429265915230], [-39474481169784], [-104515075381768], [-326089680837828], [-226570407821602], [202162934726012], [-275826477474016], [-220505672092170], [54824584735748], [71333826583056], [-16894270697038], [256045901743434], [-286121521718820], [67447566027000], [-153373652210316], [-350482756616188], [-321888138722296], [107384953605230], [144610671226950], [29004163056840], [155980126872560], [68763124966020], [-250215839882692], [135943091200872], [-378946910038786], [390475628254758], [383993889449568], [418692022960538], [116937520820466], [-384691452906156], [194016551924198], [-373084875252700], [139977933580314], [247385313683786], [95515322572928], [111944866580388], [471112860516302], [-107235461769802], [92597775778806], [255712139320988], [503634825652914], [-535073761613970], [-354947926605892], [182039841890394], [395489055541430], [-352060748960812], [-544022762552566], [-101815269697744], [-149367935455198], [49671512743304], [-258005834195460], [615609580571390], [-549582019196470], [190319310838452], [-417056038073184], [638885368580024], [-658480891350312], [-203027521646914], [-392633519651116], [-337845439898520], [-173088244226158], [-232363366171830], [-185270183622664], [26704397632950], [-835619552201550], [-18112121179644], [858493026147990], [-122641416189828], [677003567026286], [-244147904843214], [244821353194496], [933834526435818], [902250818084604], [-1033711416744100], [-548634890122630], [1187984107013682], [-336010612525504], [1277539621964676], [-324315432937492], [39526636802402], [-850454472308772], [-211048521043498], [1501472261437248], [-358174213678330], [104401402964976], [581253832927914], [-478680096623730], [1235250561214532], [-158663587234032], [623058731213690], [-50869294526988], [609417404376], [-1751169284801710], [-174022971977250], [787547971059644], [-1254085641755206], [814085130240450], [-136367748402496], [-1108138465433226], [694261777319282], [1812835146062036], [1856357516146772], [-1425865917130152], [-1253186803136070], [1244800622306126], [184592426410338], [336274002399296], [1820935466584404], [1668529452442988], [-1192271993462772], [-1636032330470770], [-1885731582376842], [-1711450724011846], [1249868952825104], [-918586656985066], [-1089528381757962], [-1071390485552166], [2102676612248072], [1489961760662658], [-1774987368228972], [-1911407576711362], [-826230161616532], [-1270408611972240], [-121616082919158], [-1486854462573556], [-2363213720996854], [747147472104978], [-970347702666976], [-2048084231064010], [-2637885681140850], [1856555108464080], [-72419396591316], [-1807993698773874], [-2738950843978656], [-326602057168762], [2299858773152142], [-2041239705147768], [-565367708352660], [-1263137112239380], [1369923920613290], [-3111756357025134], [2602246550183336], [-2252018893039846], [1933221901280244], [-2215580698633804], [206704213659768], [380497747804074], [152065421625224], [-2987905185493666], [2718233730083940], [-821754864596664], [4197445987910978], [-2566536908267130], [-3272208774871462], [4104964725177138], [-1077180482623338], [-2530099315951720], [774412327921470], [1177873746426236], [1747833528608664], [-2347635271684624], [3642700864318238], [-1880796616314820], [3516642769776768], [762964019604578], [2173045987676874], [1920788606287356], [-1139879267736100], [-1427843277993120], [5178988122070106], [1149775480105904], [1072828143177966], [915498228999980], [-865195574386998], [449224382375606], [481167575701374], [-3614920048769632], [-4057698991013106], [587037107404986], [1634521664971928], [-1502218016091538], [-245986834573458], [3051285418443116], [1524056475315828], [-698642275946830], [3040555799307306], [-1940340240781812], [-2658278292022924], [-4436361920572918], [-1371982403635854], [4975522299322680], [-2453120204446744], [-692269284183930], [-4841117624749992], [7271409092446050], [-1408681400309314], [4518037693938168], [-3439986762949812], [-6849159782028550], [3801725409705234], [-5705222609302764], [1788087787783830], [2836294001506100], [-1891331012883864]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_126_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_126_10_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_126_10_a_d(:prec:=1)
    chi := MakeCharacter_126_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 10));
    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_126_10_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_126_10_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_126_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<5,R![1590, 1]>],Snew);
    return Vf;
end function;