
// Make newform 48.22.a.d in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_48_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_48_22_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_48_22_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_48_a();"
function MakeCharacter_48_a()
    N := 48;
    order := 1;
    char_gens := [31, 37, 17];
    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_48_a_Hecke(Kf)
    return MakeCharacter_48_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 := 22;
    raw_aps := [[0], [59049], [-41512770], [-538429808], [64113040188], [-130980107986], [8242029723618], [-13492101753020], [233184825844776], [-2024562031123770], [6869194988701768], [3443998107027638], [-21842403084625158], [71792816814133756], [-283544719418655648], [-2172285419049898146], [-1534831476719068260], [4311589520797626062], [-9243910904037307868], [20387361256404760728], [16617754439328636074], [-67940304745507627880], [-39503732340682314684], [41611676186839694490], [57181473208903260098], [432416578714693391502], [-1841230728243859903904], [2438048811123644563692], [-4136763140673116371090], [3479095556570215495314], [-1371405749859518373128], [24527587051125818716068], [10283520533032563572538], [-8706918353900791504340], [-90399709129464927774450], [47520563656407300511648], [-150900576147493727782642], [48350335374711020165236], [-478731485374094089368], [-161803993969566450913626], [87637680509256519942420], [93662447300352255276182], [-1208580981805990844664192], [-1788217916583857384827006], [1909630515897793391963598], [-1442538876933641026892000], [-3988478392887968177566412], [4629626578313893879963576], [3430098205885493413670772], [811791906818476248715430], [822187598619057903533034], [8855253952606095597124560], [7469344340829098486839442], [-946473559538403124733652], [-19182506017473142619308542], [-888428809984623005756664], [-21384718554950095318593930], [15643479490160130993151528], [-80497264624577589245286922], [83317074784526942300709882], [4461298032280050280147516], [96712751143741545341697294], [-168162634712174621426825708], [-230370278508655140986598312], [-279658012890075318179426086], [29850054914544090073341318], [-255594372567753724557710132], [-49193138827587979264454062], [-298135622906180040035184948], [772833867655104735300080750], [-730755372621841067508909246], [15893602757390155346042040], [1407343785560265038429603032], [-930077343271275426161288026], [-2185411856031617611297700180], [-2103465083057236572720758784], [-297815385557395111182342210], [636504104722696090640240798], [2438882440496984272834412802], [548031897832771423780109210], [6082457119525760382578664180], [-4059899006382585766987893178], [7872143954524713451926787968], [-1737846393016211840301407566], [-8374160974880011143129735440], [33028603328353290846781356], [5217125093706720166578623250], [215210558017639442950349258], [16869898307433872652613078662], [19035227842165678427020442536], [12102676306000085248450327332], [-6952525728812972594026278480], [10641234482349713256321163312], [-16806365263681913359700438292], [5122854140903403310788759700], [-19960644690841785148663200504], [-2579664650258787739906039290], [-26122970874931690364392143078], [-67074997929127124737576966724], [-21519598091080486239700559458], [74678884283499733151361698452], [-79516621655794595287122128442], [-54630475811968490797645382364], [94347753608621322683348816970], [-80502688557192538676776533572], [-16713209748295217317456180222], [-31573049710064303705244124788], [-5484927888673329085387681806], [-125620658203688600381134975800], [39932519503450424280802227002], [246989744233417277472610442392], [26391063094884762318035752214], [309820221453069471259829935818], [250758346984346089623219775180], [43277014217764274599149635968], [-87338129147951304875869051758], [472012662281044842887803317556], [-12679914419730103032806825448], [-276226226695286755683440965146], [-64651093109860756023840399660], [-227730096181644030821366698138], [-379242654490524454184795452126], [-339716792517518435143954664322], [-454742470684348761035562212484], [371838197284336465451891877508], [-937969255282051004951082021498], [-754577664218910736843279357690], [-1227539546566558647195430005120], [-904406856558230986053248052128], [-1388738978923466104527919576066], [-2115060316123808116356693853340], [-2268054880656676218135285273144], [698349419132254736961327622648], [-379778380441320730765832293642], [-750370717124167632447554710038], [216884139434996536569961306370], [-3081282447850977846794412827826], [-1464598484722136200982480076188], [1277306969066927295682331257398], [-4249750098490156189571483076390], [-2058625527118300100510988644612], [-180716557632132154265970525378], [6235322116210406836119407601376], [-3371788293111801720481171466628], [-270711354830692318697687485570], [7454572359051331000890150282360], [-6106526280775814816359806859546], [-4083071917280672721162578328342], [-5271894671353956817046416571060], [-10553714420150581769951975175264], [7160688934406921976169683124478], [-10594251736792060470882179557518], [-6607441444291509214872541529084], [2744668494079234486872150014712], [-5455677369963674243381962583108], [8757394753617937276889426384688], [-12429537373114329172261211808320], [22431000732773336043087939443730], [-11005150343244776250473713211062], [-23803608375613899065906027348058], [-8097622045727514838197167514348], [-3422323218848039624719247798646], [-13312057600912052006631125850368], [-9717740684720670610640105819172], [-14063736808615603541092676695422], [48729100520256050266625407838616], [-1178465528769504227219631008792], [50543774300846828901005197734998], [-18243950410467762485019054774190], [19073460097874438491555820041614], [-49243768619886760647534617230020], [-2611950066420602323643862170578], [-44383856269074743181272649028632], [-38224900869165413825019201274966], [-51204687972602047610186021279240], [68020773707146330400033993773050], [-52225220319599668884938349466052], [16902768636996298517959316308062], [-13884101672496897414969937208864], [102733593172823950765464388063070], [98062623462427464532929931723912], [76734234799693018358461856901108], [-8445422328222705579823452699706], [-91344053245300546878773971767702], [81351476687361348634250690022096], [-117422120990638959640301973252690], [-94461326070842127476044718559682], [-146015145147428600034698408833724], [141609131754783717414388365169130], [442205171463639717613758382848], [-120274609081123863312029902381246], [-94575727517410395627436558135764], [178835844600979426402990042133428], [251213668438489776373571798992182], [243170160626303641351901291983812], [-209105120798228697051057909740406], [-81411307823179038610371699089998], [-399064155884369114383668765269986], [69135607506090123644349952249218], [178150944273020515630872073003176], [-9475456464139520171744180246970], [417289753572594517103189171564968], [262781689330671132136990608061238], [236412084783232866286771492095650], [143079683911901309123079921943740], [682503706427335981917694012054278], [182166477242907277920120783102520], [-38556684838469163114945423627084], [248657575697345738261127882726090], [698118604690317170497987352837308], [817423503694027795605035297276498], [-174540281646238131732722036441298], [-271788851665327473007499210555504], [-104895465363415690129432877031108], [775473927515277426805517477230680], [277130909937224582002818903872522], [235015330037471949176378514300472], [-356790269447429084466118317158238], [441432884180308574622512126068632], [27752968880212868444235604295574], [-1316060083738793723334972204725818], [1438047816222001825659069737407600], [304481446232269019364589502493810], [-2294374940204978982409977083691224], [817683137919869246693637522061572], [-387983669180168073395164149033370], [-1035427586448352534261928628526566], [1595844365905619026709227152251760], [-1481899767886946475244197187413248], [-2888596340332190497326637097012052], [-269669765044181983447395173825746], [-1095168996132197183772865185927260], [-1795259260966018673107027115400872], [254944614411747683640857531101482], [3621385959869165742445053211627516], [2372004888047432235105722692271712], [-1609337744734950097272733668015310], [594348122682489757316149014220494], [873251272653297154712177368862700], [1556982296645222720752849747287288], [-297935239264916109832489320999324], [1700855424920368864077517135350268], [-5075316639615962611104724601328944], [-318712998720577586222684002782850], [2789280759263772014023471500303954], [-1044296868735111855022516967360760], [1040488814843273465187918364173832], [2130510058802467868932954732737828], [-5488797500059441442190648062794580], [-5043205334479215592368095300036784], [-8202651653330716931246587879961602], [-3645068597471084429684394291202398], [3500646210349730048808531191031192], [-3094868270814286774377608759563990], [4180548335032743238736488875116214], [5592901795917281240130935067146580], [-689885926218645891551184052978378], [-7363704579431851105239226056891428], [937874509373150314501254622433838], [2060379698989193066810963645576858], [9110374072332934716837828290137336], [-3994571858602707869582334241629468], [9069721685679549392540551322586470], [8261076410081590776567244708015694], [-8740179356068957474303145414320302], [-4337670123667462073982853511222300], [-3532418886013139176350775417850490], [7139363820754762010215802999444922], [8197791554555879918113310569737676], [-7271147214627361042539388823678466], [-2307674307212620571166708992010658], [11158462389763237431435550565119252], [-5979088612660217676148555288344646], [2803883731471638273189577381579240], [23761297007137065971921803333888178], [-12087307276472428533227081546315984], [4063624787886979785708292221292812], [-4207449071409581256986109556429810], [-24739231934072013620612444763888598], [14618507095338517383677951904602388], [-14842818023335433281731303952260624], [3070411319912050102492393977331168], [24613065541413293330469304781966952], [12033690120190981029970055105326262], [-2725623577811532773624089430896868], [-15515378801532558382479878621320272], [20062493666265108789551973850756274], [4773626518017797264397297733442478], [16377284593182876330368646273029920], [44187641366629274924864757168148290], [24224398549369605537236015520012102], [-38203444377543489289915085968838508], [-20571706133014329497807267132887686], [-29405703604802713370284820489778132], [-31802698418009630575186792525216066], [-17458203516362248122081826879315050], [-15723615070724394332885732515678952], [-13543946300940437816425832906614626], [21872133863248690701312184814817420], [-58308942779314502508375239097375788], [27938585913578304045096494848885994], [56757591378319499856239041794693798], [-54660640106080436435012900010341000], [38117856682101492033786652169414196], [59596107533160776286578952979958188], [-24003110222282642663041880521915582], [-15223817347578310856251860252096228], [75240032498485215931452055463558030], [63322886349726508725797643482981160], [11211417792402088883706139069798454], [113352459698296806547743461958662736], [27816199350444529089072222148268670], [-46752458105331023248833250146335118], [89165874091615049165325512527743316], [62467438588052803366243902513719112], [52304944167981865002438613946788490], [-30559246547346321273876432183309900], [106952757643933847829485883470912688], [52408903672625501890911530548691714], [172819971174400398655948331447630130], [40372698554073840032287341944553268], [-118309984568769627157570659913646662], [-13711223825163091753756020244500858], [96475461457016822802432280033874056], [30793585403072356094312168978564154], [30608363051466967592281442667033362], [48370245984093409731764163933562420], [146460640645175865092125050091933996], [574294491321399620966130827272992], [75633592397910717991928450393650014], [242494084260474739418515379932720622], [-237663470834998350866632526522927562], [-86386918059500576464626409045787240], [-47187810356978450181291678870043644], [-286639382891960854373474537700301652], [-120164399852760292047457554703238868], [270007236014899989639487866783363470], [-151317566101880593384722606516470526], [148651978785728786841687224848607882], [229526373426998684880702624871107112], [-88012659402944173326110053414467706], [-206858137441133827088257055956659702], [186831123000048343277945306672041710], [-283186281730270812919507062663665312], [228275876484707098137633108258133734], [391843943227755214801662692684559060], [133149800373165628358031354853341542], [-164458286699276276782208086618744148], [212096616902759095530376522858321248], [108102764256412937795260287538021758], [157681397909071655885586022236627028], [-90922341953734015210284951280077622], [-282131433884443972052982957793349418], [-456744283762311368762913746470225784], [-145455332222472105530095105207146010], [-421197152220888635729671339207497606], [-279828180391660244142028215938496000], [-482329007908291181858635439683197012], [463337328529748081201658971084636418], [-91450859684955538036170676196413224], [80390439697324254641899906626817238], [-643823793190315475895509522263888758], [-232858074766480873396424984686070448], [294568403653719476393060009095045740], [19020191755821755436201367823802532], [638889302362716195030956445725347274], [-448565601235667100778569858421975722], [274244336239700646319086835776960496], [767209120906605357037283479172356922], [-191436836287588030411472717663248332], [1069794529424667858891458340446428060], [-131307166360097112785008500069825744], [-293841375794445531681649461132310050], [-441642513064230427524984066540628352], [-129868389706729293656938454707631842], [-523692638980537982969918256650915580], [-280129158878035852506747917333551392], [-1053209254469175527550602341693562206], [-1213916476743821638261711051753004190], [-111874899332572063074655536525530182], [1036700130513884677626122797891028022], [-403074408978255085531722747576341766], [339162681297173641068303484118592352], [859262474150831304498205794750722658], [-405356956859546561665718660201039660], [-884059638007758822046121252850013464], [-1133235032337118553080026461423902472], [-986839929620608295351542340581137322], [-1198123227075767758233731464709978084], [-950889378838107490567252179636733488], [-295632969181357641365957611991378110], [1641696709053888238840256033063326494], [-234500851730462222428399872631948500], [-691671226326285029556140548779645308], [-727549736449777829383474125036613512], [-455683595689123975448085002460626086], [-34801891408868696597354238344510120], [-793436571630329662599828635550468870], [998926965164068975930495778419266268], [-1772580867165552076604146163207960658], [947871975591234541077991459193867150], [-284182294767880372462764125055980046], [1544898835608199234003074200375052232], [422842433340427776885359448478811178], [-1620604577675364969510060406602482610], [95797435596136874006292191427979408], [-746479230657856176931382398046061202], [2933542186804436614575186699007986402], [391055527571780183010298269702213796], [2233733234338984439406650230857254580], [1692530502022866848446714426321558034], [2704423708299118343687722321006381038], [653168799746059268174883897072562956], [2243351867351799114652191162412980148], [-689740087805013400500760931521535542], [701706863260975897839903572127050262], [-3287818780766068763471173654408318080], [2155809511502439734917661307952440112], [-201084144318919223905083636040114302], [2751311050252102096286661057665634696], [1065681294875042458548267522051217110], [2653271133536655996331434793469459318], [1168867189538968261209647439207774672], [-1603804912074470961015776098532127540], [2380105479909526263396707305974806954], [1078289159934714523688521791717194358], [3955902681912590777019844245072465636], [-2450457449483806702607614251574547430], [-3602667626126621871696423314810475572], [-761120409873791831521563916395219000]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_48_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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