
// Make newform 16.22.a.c in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_16_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_16_22_a_c();".
// 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_16_22_a_c();".
// 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_16_a();"
function MakeCharacter_16_a()
    N := 16;
    order := 1;
    char_gens := [15, 5];
    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_16_a_Hecke(Kf)
    return MakeCharacter_16_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], [128844], [21640950], [768078808], [94724929188], [-80621789794], [3052282930002], [7920788351740], [73845437470344], [-4253031736469010], [-1900541176310432], [22191429912035222], [-20622803144546358], [193605854685795844], [-146960504315611632], [2038267110310687206], [5975882742742352820], [6190617154478149262], [-16961315295446680052], [5632758963952293528], [-43284759511102937494], [51264938664949064560], [-48911854702961049156], [-504303489899844009030], [808275058155029184482], [-1002018079349702950698], [589747054476306481144], [-1122100836768400472892], [1723939397379244815230], [495809929052605094706], [-1636093498211141405312], [13864963308265839166668], [-40078919621811128507478], [-44758479808291059117020], [49328908894524903236550], [-57041480281980994831352], [63562335234693291666542], [-86848360806012005785556], [189411168573448801125048], [-418507989542345072272194], [-476751571771182829691940], [-28862734509184028216218], [-886377892508974169952192], [86350861419370594951106], [-699007897302572286502218], [1245423293022700543384600], [-3508414568865110558396612], [4723499876938725919843744], [5443168797133335298442988], [6906769890393014065423190], [4536502138132360491188106], [2734929976785810304038480], [-8089068534967740784314958], [-6639265576003324440330252], [1572784572582880285431042], [34007704831734243878665944], [-35797484585908924151848290], [-24610355301559536092347472], [-61167930197964617291422138], [17371006954434479553698682], [-75723743460270764544477356], [48868444165733855376762006], [217987303913841181562767708], [40464448729200819848147688], [-8741736495920098775109094], [-31975828554853721823734898], [252214821588073220443373668], [-153126867676011786188538478], [-323436088129753442457201132], [-677854422495976101280925650], [684291443640449529403335906], [68550020504461629496003320], [-1135754326884411482171208752], [382975272769427563667540006], [-71476681765193129726476940], [1384251778002467070147567744], [1632131566081847956928241270], [1210289951770833802578359582], [-651358092672234306844957998], [-4452509308640009615484926470], [-4929117920066309934786331860], [1501451475964271757135865622], [7192208408787252836263540368], [4231039979486647937142977906], [-4532345507950689721889204120], [4611861758580901269978709044], [-125691710634107392937298750], [11592375120690064099596363242], [10251364377141043522143968862], [5728005750190077010592015344], [-11265794999774759881781786052], [11737295436000615389604761760], [-4752717872642987025249185672], [25983670171031766454922026308], [-38450776510836865272391897700], [32744550835279659331248859944], [-20247200613982617886769365170], [4752074954635301477500711722], [128180197215053244081351844], [34274656328077303421562536942], [73032853601376943572884637868], [-33259714798117503240689822658], [82833166386840180402048689244], [73541432034222675440706774810], [-109130626920792725089300727372], [13072697119255384430631063362], [171459462862893571896113347428], [235277286506353728692049564306], [133384412823451582627272515400], [-36447416902986319326209315398], [-271227627181215540047395469792], [-202698916028143257089926173994], [304169265740427497878453505802], [-121487484873224131263384454460], [179118323410746278123102310568], [-341742425780992412389179071358], [-75758164069647994355240322356], [299088493885343953698667892568], [54050657891124307079175461406], [-22660638043214718006135714180], [-187482826359076091819735585338], [753000691407057420241379913506], [-812051875824678056735287260138], [-469972897548632796837487826556], [-358805596844034670680933510692], [-733109594156634430617996768498], [1209091792279360098319100495030], [525189439062659479431490752240], [-723318091782840375543685184312], [-2114087495493409671682372595794], [742068891536737542377897606380], [-1699679357057511219743864530056], [-590225070899380377343532741552], [1333076245417286181881105272742], [-786217296234752404551865196838], [-1650825843831149027017656897790], [3779302894002331949030614345206], [3582189155895850005156403346428], [-4459013991509129674821903456018], [3091556302581578909161041725130], [985710954571375834730784163588], [-5819295509980003569677765623578], [-1828477660915060538310548748056], [3809967436089866256476934878388], [924246936816516492950713531790], [-2180574840713560389663470012520], [-4277540661459166671682864143994], [-176321978256569215028208889158], [-4740092804763513487964459545580], [-810823601157008814082791788256], [1552548727521538775021916955262], [-5757216249646820376137356256718], [12913360687045683307151349167644], [4227522565906801827046787439528], [-13478618410502600169967727606492], [12888619206142565685594630762288], [-1250178927398570334618210919160], [-14124505231588636986777423084510], [-7128507429613373822931851972278], [-107253668033184700395005678658], [-29293479178428793583046597808932], [30432047879175387280562346071706], [37848488080891056648372326612248], [16233440423927458231915611821028], [2988581693960192100230788268562], [24137102462439152330833908223944], [22943625633260040059279850383008], [35503639024038538087336360874582], [-9886530659889415849756626357070], [52029727380438803505902365168806], [21553515070692885206349009514740], [4343842413377632099482423667022], [56411873956285982542431364292568], [33698823951263404614826193579306], [91864594077561487150928988898480], [46610085394164370039109280905850], [34756510480755293437811903064148], [90071789832567015628508055098262], [-33168837159984038490904833824456], [79992279072052298297493066997310], [-98884759850983763576872032049472], [-71397239429991729725571892975092], [-51178751448827718992323226702794], [-126289322441239916879594385524118], [79597595156853068354952906559344], [-21773644743930240285492473198970], [-134918678425680828212069697599698], [-130821511110391591679769380919956], [109255237459428564915525135182090], [-185364418475901560285818078273152], [-152083060460021991085766741287294], [35793829494375499674590551031844], [177577527060535064021055654626428], [-33619940506614086172316341936018], [-354692745810343450502514565231572], [-354598515074084592665133419207094], [54233361986275265598489797362802], [293419392014232517363218187867406], [40212187336943302131558939198402], [505848286331891598430683401963544], [-184643430422926074275102108226210], [327445753304307658025038813078768], [-103977348259400255120675030742778], [322689446814234700438482496138850], [-467982187323292035214931197096380], [-411483604016555200035350901551538], [22100603968546122435370588706560], [321669774244586260256454467092044], [563487442808117753372511542665770], [-160972211169355142802226837824092], [249378331933890372965237332249682], [-259026528840101358629215450490298], [-384003265593154713254106033844856], [449426792426933701938041837101908], [719195599497295109140133806634040], [1005919321929843935538069694443722], [345241269377584358174935084092688], [370305287110999329123464016937362], [-1100967092889575392028352227917752], [1322002890629453146192757708917806], [-1426196729225883751438645853963818], [258793967128560174172099430117800], [-497148127692854562796703508716670], [4359234019533940462926693565744], [-739318057263048397347771888967812], [-1188249360474885762418912847684410], [892688461032519468291817736858106], [-517992182338910091540844204645920], [448372149158565811057734148733368], [2558148004728160280853962921826948], [22974088143628712247645947459006], [481232820338286210411238884057820], [532999064775222420227822592132928], [1817507031581438813208169694677482], [579716999392010333534385244047844], [3050535978180174376242463164780528], [780069970199126403013146799434770], [2590649151976524775228750596288006], [-408825039393768045074149244731500], [1987765111030915559058228898004088], [-1664895502244119498165079829587556], [-3881141236584828897581067118680332], [-2059263347803112160976221762505256], [4705611857527555264718589944347550], [5418304375916275483281822264045906], [6085733733279289448878524334659720], [-3734592104339949839549101790881952], [3171891119018489628076005745734828], [3388191923945904303581804675168260], [-2185080695095774181420960031311856], [5722138925174191856450873998167182], [436926670176848170088189185057602], [-685124224236923410847048920377192], [-3009824202140180337202305379736470], [-1427304462322991407549310785698594], [2296940082116315063870040698282940], [-1624534569315672382909315261427578], [449908145551028964554296765299988], [6967084073945108383782854337617622], [5019618507129398716843262683953242], [-6726008842531337605921401023613056], [-560302933437263520945935161760052], [3891516887543724326315743527630710], [-6020903821724922469071766423278994], [-13637038327267041819757502568938718], [4844244783695722307548531325190700], [8383747045521538475559662339709630], [4123847241367982789849765873370522], [16265159819208945086841063181493044], [8115754610810954889210412074932406], [-6693182579199929195798712290461858], [2176506518195946819053581076631868], [12629878075962696043184619545525306], [12251747002641716235182255115298720], [-12976519028295505466199735758863438], [-6126957408267382808651028516036056], [-8602760121742032494761324370664972], [4768480879416977638665671271790670], [17892786416171908562540793015618602], [-3802146003722602611488242290219012], [32727340146904272188284396779176544], [-6254922778988924752410127525017032], [-17412352206099513798155513804606232], [-15658305219425346642585792551617738], [23458109011124671744873660789006948], [16742178091220632282348350065954928], [-17055722384143508687502780202947694], [27109564344433337134435712822326662], [8732974563194295451933312118937160], [-26940072948184301793675701205638430], [-39596218841281150417791881584986498], [305692382716761698211406866260508], [-3967205325195654472853931135369894], [-20976427669296626941750154034663132], [48344898422033946198853732832351006], [7382180387179384352149115925917550], [66199711691953071065171134595758048], [-12680864420118030432860207144560794], [-80757567211183359351826274429051340], [23734967755084461726296484915366028], [11270148948820378247791692344828906], [30451948579263226003344304006028382], [-58748824710458089024403227076483600], [23362715704198354283088544402320444], [-79221365623238248487918169902549612], [6726064158847645172647297500290402], [-6807871998328019491551878517735612], [-51382744401589483993151210997847810], [38303079351457690544807778086186280], [-55684545354008497461680822929277194], [65420019507357290029405840479367344], [-90588232019827343944755471001327290], [105231431488644376825520451960414882], [85751668812304968669658448244828844], [59445593400761480061451733236847928], [29227791457776835948634553610624970], [-73354036670443517435161622564321700], [-16394300346369866413329947681877312], [-4565642435658809667802718870844094], [4819901424422359212014457810079890], [100624276030322961099172410881972668], [-150327367799321239553961484028126278], [102054626998195680842287567332375342], [-129623897047049861343819278673983456], [-38518699110142025562560900503208694], [113121436414976151374398172409606962], [109388804134834108658531731476192460], [-208029326502391131229807964642176556], [153719683167715979426757314018435808], [-208633145556257273865620068834325994], [17290076861561343582819961457247422], [-6998893918644877016674082237134578], [-134516255785512120265890518620944320], [-222123022645333900437894720249994356], [-20277648690903995478973567417402652], [-99762881736166293220629653642137452], [-147184973657419614915526527698539090], [154547691764164673680652046910571106], [259870522010041542957376350228326282], [165564563055942216051279841006734928], [-174693208526266242912875687262114394], [-83977404871033142592628563803841318], [-264318274771823275054034333206952970], [-312779680489385819803308366631151912], [201380959801913928143949406191585006], [-112715919731492465897983295902235220], [-240689837270712301718535135682474858], [137979265585698266837655787349240068], [324346608908118576057789994901272848], [-225470495051748724861600375377740058], [352203999006598397711968243669954828], [-39269716158640785799910420349734038], [-300262264320116050061900592640093218], [262620730869689750433414149106181744], [415694164133948331422501628341051270], [94445567847480774144590118426501306], [-452001057947200468372375709990604000], [-285390960727567025043518824907876412], [-59122001367577625682638722187982798], [-516564742649541673758998884370375256], [38857253400063770127489016792712822], [-417187147288403010238331291719036758], [-200348478329316357557220916430196432], [-54374740220617399093108198247969580], [115709670966215952348237983265346348], [-194887795019767765847537027522957494], [181776514951589895179529691567139262], [123903506297746768131861575098597144], [92116455208402960278396776861649722], [541854681029979546780409752605669868], [-120733636353715717403043245456313020], [138341152362178762499425097536862544], [-151743645674641023274912591863164250], [335519438725691568709866233500631848], [-1004708830226934690016648187248097458], [1061361505148160019290360587943672060], [-229045272765793782832714902147218592], [1369244831694833549003284997029305506], [-579161692552103372145274463819462670], [-578452388997119403151338294815879398], [142123473061678321532150463464775822], [-641764933099823562576288874235238294], [-863036644923332229044992661379893432], [-1429373001790942160880250248972246558], [-1237274416409563129059702894361311380], [1057503677627166461676259038687882744], [-579300586065440776811314219435553072], [-1509306169331906737978440788919749338], [-1125728386692061261099910410492751756], [-1548075863018367171397082526567046272], [465214074128853656313264970861911170], [-84017562760164466932466495664403594], [225179918460118867037858164151345700], [-115462355980999486496087087370901892], [-210950805990643830022773838255838712], [1222559040892118767973571763998778106], [1653588548980632374334651291824470240], [979473763670982982158891024623113290], [613430675015523257639947475290030468], [2114715300263073706456954052832560742], [-2070683045170390690917490685621316850], [470669374874630382038751350918394306], [-2403208483044558286935066958277499152], [786073289235359155822497959342587962], [1090600191455965387100570517806896470], [-1999881423042846041781085475758099592], [-1061394243244398579347585192000546818], [-264447364145572603700255067155281998], [-948708483068707648256314480269811556], [1590913532397561310569791134682046540], [-1885746860377769863951835637673534894], [1162378186171509412833395689688471622], [551909370896187647476613078136341844], [1113464806563376413797370649642335148], [458987686809573962562710330059210442], [2467784187029588619262018181375238462], [1108455859695958915591739596229530560], [3298017266408187821363017469808709528], [1816539977101214065947261735660142482], [-2557037921144485686328929934277180856], [-1584940850798624658361780609935586770], [-1896315696984313822618953370582829098], [-3890651850059803513188556895393662512], [4961304247641563573823996769722321780], [2738011287527334134762824193683892906], [-2798364132839604496058683885772306658], [4754925839945112381189954306181464444], [2278926948987721825347216048274876410], [-719144766983987515524803025299766572], [4352211977872383227080050903050077800]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_16_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_16_22_a_c();".
// 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_16_22_a_c(:prec:=1)
    chi := MakeCharacter_16_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_16_22_a_c();".
// 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_16_22_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_16_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,22,sign)));
    Vf := Kernel([<3,R![-128844, 1]>],Snew);
    return Vf;
end function;