
// Make newform 1.40.a.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1_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_1_40_a_a();".
// 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_1_40_a_a();".
// 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 := [-142249227846, -175630027, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 72, 0], [-25290723888, -262224, 216]];
    Rf_basisdens := [1, 1, 7];
    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_1_a();"
function MakeCharacter_1_a()
    N := 1;
    order := 1;
    char_gens := [];
    v := [];
    // 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_1_a_Hecke(Kf)
    return MakeCharacter_1_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 := 40;
    raw_aps := [[182952, -1, 0], [369814284, -729, 1], [5808972166830, -47874308, -12636], [-5998765906211848, 32827389462, -7335174], [222604989421917178692, 134509309731005, -11834988165], [1052026900482655751654, 160821112991868, 1115908456740], [296675263669597913964402, 1013853378421933608, 94395618447768], [3075870728335899191172860, -433737587411141229, -2625847472007243], [101769530490306523580062824, 43986670167470841250, 80143699389496974], [-830894073086216092432148010, -1665289738570523343796, -3905238531403525932], [102035890582607568136518248672, -113124810261416041339560, -22561852423742474520], [2533024470767859724962863695502, 3548266288697377802355660, -253850901376045677228], [797308068745923168744159996762, -2545947972354765178738160, 6638614109175980519280], [54288641223849113219022378768164, -77002579364347414648530891, 1442367830821908189507], [67561077291801947255214347894352, 639828997104890671770399716, -44165399640338944810116], [1956359996254839226617982210814334, 1766607032736967185626005836, 610703512513770240281556], [-18694227128540426772369762889879020, 13517224095259016024793030913, -8314230064262395045799529], [13192558560708809443966229992277942, -2636818484998994823827340900, 28068966366170106300029700], [-46886643218706630959245466909143348, 25409683021912091455120745463, -11899425955266726344653647], [1283017736958022715566765080472072632, -725564675919087019127570019450, 231046501681727568871331850], [-60251378830757689033653328012265926, 59725651859909015738082507720, -338106253777574933581827336], [4602590733738743096631891285564853040, -12151810974889138295217792512196, -693064765726610157709560732], [-6966466715968516267892589449395602756, 357322601374254602609750744867, 9545885939955802643598214053], [68350013303369952378853951074025408170, 107750969168313875361828067484232, -40078838436299927371083749256], [57830296105909597812604069832410442402, 142512307242368470481214491238216, 78255615566048161017261368184], [1427822718258463503924421754315725684302, -35642759376393110552536156046740, 37679133249354383139782442420], [-1254601823043055974689576313255172282216, 669444376327533517707754269910686, 394227426102219403925592998706], [1701607206593287314679769901144869697252, -572012470257949681221332966197563, 11949525017803063972060723251], [-1065100384764785296323500418975115394170, -2324227369355313647771829880051092, -725628529772121047915425100364], [-1289841813188330097044555186580913457646, -1475318120794025166668414505998912, -4988954237584671057781682781120], [1002391389578735913323266316786823623552, 23468593693508298676535436771135264, -28433091316627264688454720345120], [-78115394489058495258641673703892394003828, 72015955343668612670258757616033255, -32592841608068183133195929972415], [-579558435087950370797673919023003365409798, -265797318688586173200130645912375600, -10206302895630624220463907636048], [-86393317046908271545114979617328220017980, -502492012924744500838077049644405123, -196783529235015875580013422377541], [-81498799445154145122897390140762689217250, -2207050447106428842468002652808257860, -301937517622474897396271905486620], [-57625237030119800685765807171273192884248, 4350776729358253382137837773982935810, 921020654919934577794361817588270], [-2014081022059375483362496238499845101833898, 1324607386004746998839764867705423932, 5770547119815853614566660047716], [-4889381562775475704789565963621311613077396, 15031898949155941642408803703487583, 234154059513908556326492562356745], [13541894929369292797771308117939238157540952, -1764108967195626145824077004963085682, -5572233324647579823506176734323262], [-4367923168839905761562788232569154395300026, -10730865444019616139350223862801174180, 8533671964571780861421285803197764], [47170250394216079056334649188397722904270940, 19517081405586123229199995710935209899, 53397936375095715945837127780871133], [-30414270727022488640434510405975343132024578, 40854344330535187290263872108575486300, -20108908861336901997207038148147900], [-100135959027278934175181632848446782417937088, -347368171681864729936492324650591966640, 25928743504876571156711022231459120], [-255433048716018875485431563939668517977975486, 33806593317028923278378394918580360584, 104875750448074797815747670129861432], [-484822756283201420421276988417403991171002898, 351379396483253647516197347375014075356, 140522404551487395281406093952276164], [280798459466782718263259557755297379207667000, 822647037279650823763970334562242783270, -268144249374140315740212788708885910], [336125298297311754524311526457623862308229692, 1970524421435362793180039044579245527235, 70471460302709654063917379411626245], [-5043184278063902349130176897384324734348241376, 368086275811752840693930894818032189800, 438636041088945606298820746313409624], [-1803909731292198867512112974771454501184443348, -11329072325845630026929181119660096685361, 1110763599919660285774021239777390105], [9137579456174670696870239901381855027709181390, -1562425288432490590321698259309175892516, 4020062074087845955623668933146053828], [2886948961305868589667519741156320006212029594, 7757063737703615345557364969111581552392, -5944913749604081982820462633275609672], [-12089539214212574843218839121403744390554324080, 20051404338555669286077110712211144907572, 1011795532629591241003508739543364524], [27289155626820496282027287779473348039333314962, 5901679100734619937210792853222264108200, -1213909196662886222660900704637370600], [-34667420745080634146694136896931836212247512748, -87291054981412981434016574462620949355375, 10503329185241715306353906265489642375], [-93108852319399924422483931034439904040866207998, 39869834195934444278430183891775741668352, -15918004828060139783873831609759468544], [47749382843979324377051363937648705768006509304, 40605563152184233349322551841203162525078, 14393427498582431709067450347943890810], [95331694366479837791005594534502562741958036710, 21514726676979533666206271646722430844236, 1150954996472505514646011898478227412], [22155070146059277727032640309517294923684434032, -320639498226566703372178900316379837891060, -42820018164740524790237251773592375020], [-222435285317470133024456361241832953888083219298, -490342597602048953820028940108562162205236, 97007220028793569092257733300052605780], [220671549086204355237049243412619954216529106922, 137035418951379895934140426952485587116840, -36529366060561602418166787700785615720], [388446953845552663646982340589955532214886107444, -518988692674651190269554697796723506583223, -124337612899422321617571086620415112177], [171117686108403302407681545433788453358560572814, -1298718276928121258704901105298287430518756, -473815047523071702251051588173303725948], [195729691883100680739843934214920142619403071452, -4856074633809309230783559628357558978920213, 560249724122451141673302662682520223901], [508964157900193194285673462830964754228683998792, 3806355475149171465914572564430371933717690, -254148654337459219313569499975539933770], [3660610464650799547589767243891546936622833188554, 1654593560739526462165514234815957175964048, 1125253926801702765975440693338512342000], [-443236968269319337480508026807321184645201492298, 228186878516056513042758316636837775458508, 162046528003619079215463585245023862868], [-7200796071470516225555529179329633983113008850428, -2437809428455383931718713644764575732507155, -3816444102980136659661769088864666328885], [-6528997380853679531179819416199172477814784769998, 22472913619937571680538296743927760044935840, 5537954438949029859045376551018164929632], [31277327737387097596892944094146173266139423224052, 16409026643479471948995669541385464591234201, 8064438219280400395324758839013809903679], [5413423452899269312792788135215958029867027532950, 22426718748518564022919913637759559625317740, 13246267393073555755033426889791231910580], [22447510689468151690661992217993403806231124003234, 46074407682948480796123441473962673942211616, -6571143373151732860682473197808349853984], [-21327290475704165958499478253967162889171882377320, -69550588758938770773436397672772467679440802, 3033229162495351372816297556535257310066], [90810580842708966327962491499957571204516329633552, 26083872344003360303559510578770768035596628, 2420281099173476137701316585464815085708], [-71244450066169135635678944618661303123922826661826, -106548669686044103257840904065418168781289620, 40494801850733394303605796038813336316084], [-129320201444024551340734331070122231294091850217260, -33220076147125617690127124975484514971218511, -45534227476234220387165922116507892509337], [139884400544656353462662514522579117964905278511744, -193127957999573404638360607422096578533822688, 24825063458831576006427503233671205145568], [2471149755821280345819896250181878448455729108270, 183051546379892764225623590520158302806784652, 64459947737215556419682514450337088884884], [-45531288498676937684552237226048177263173716966298, -422119261781857794017749639274866230050040084, 41827025113196685948634418745629887384884], [117184608164610028040954814361965089587059516770802, 301679083907976593282740401965175364188411880, -272044614038854240619816379670420256192040], [-319405828382397844792636102576433070311399424210070, -58099785575386755291075634021612971209965872, -133202702846835944872543805810400428364624], [262063973997018165760640941398447135978315615889260, -1073411106205203491093044908996437785681174529, 151096634625033213781665660768632827575657], [-664770806163830941991403082669777679152691975461618, 1309626986686729967149849162671435540028490940, 93760243722322795505536621045055317258980], [373077898198841693362193676847923410981631569905872, -3611129913810482567167239153412161204700210620, -816900053684809870513399738214065999149540], [2000727863447513725734053318978970758000743262058194, 251706969480097786359182007234291892468532712, -99929883581378687257884488351804586939432], [1222049095882455140117717345801883937815333441880520, 325835127009758711834601576858506180466873882, -95027191955843244334856062154983300481706], [-2113703849415412917302898831281713939175143719337836, 3993670023834919552858159695918757123304263169, 1032821083973559322997668018589758877951127], [6530061243593421264779784559563354878215466233642050, -2235707571268687795423103339063703627358362360, -463076057326369645427538114215340901890120], [-7664726150778893739165104990521567670908720324316998, 1680899363652811193740990106058605770166776272, -136033337333187090191660046876236222938704], [-1828850950475465630745367784127778921613040232964058, 8166647814385858890368954565138464333815000460, -339468300432366176804208631904428907715180], [-2875173813671029487763951549535039808018352420194896, 6866856494124640516289364580283416503912756828, 1457480051458316056632835709781621897889860], [5252148701740231813827888795034655258932621957800252, -10044937846104989031865074877054372710731153757, -3127326378625816864675790508468238491264987], [9146883953168790111674432214370694925293349795659040, 9590671570809138793864395230097615502183669544, 1570799021853806430184116766697701871005848], [5318390736150127285129777682234367687982453014825752, -14719324917980410108903888434654177189979207170, 5833943338553039725642968906152473660465362], [27441020984347974314488836669051123820163595424839012, -3271483326818992603392724411632803578149741755, 12054335770155512879562309059304444221652915], [428320207542709286192591466391024015733474696803100, -46801557650518825396520779251229568500238987685, 2098683458295539451079353131832927388978605], [-21804439126239886582642572956824240956227314095722616, 3517933315096691471865123731920043299442859786, 15225757705594485204588596584588452407436006], [-40673341887843174099024356027336366219179908620725770, -25047642034365127189588551338138779677459685892, -12232678443236210975625640398495124592207964], [-59729818269256761039868949193287391412051639757795718, -44651264054867603412457102795422430661870229360, -15268833935575448900081393407391568827151120], [59607266446506202956184656565086245750856772455680324, 61861255277575536536027339509524290718307907325, 6007705616839450804838955373213703561693499], [50479966340637878689868618883041163736916821245691862, -23774897887364021805126436826134292409522322020, 45578741968343547779953601913274225343526660], [-11889545682152372871595646894754568406446116491088148, 12210039984029824858381048449184285463383895391, 1455377411349047148180727714218837178425609], [-117115871650744316235333329290289660831478843248253498, 41384722657688094249384930436079694864986071932, -142802729853071217337206383035436354932369884], [-320996759392531951722221664107199984214076388990869796, 409833165409802356746875106193881872479774669483, 16338543911273480035367603816069805286887645], [-10114826862217419541152997096751650663293067952564790, -956193818515162374455150857571120344325864489584, 30747147940652763137840489949400434944831472], [-371333841803655495361099736186842009935981780450521068, 22117197822240015261117485159814524666755653345, 74055928883639655478614103001444540699154615], [-176452989382455133570300265018863172705149853115201598, -235806228719734610012218851272763196050214212576, 215309506478727736228762321820805416115160800], [-48637267865233996762052098943720343884677241432925948, -1201357915716316782594678660457253239039528960915, -10853200904442186257927728467377515692630453], [43754622708462131628123021542874615493317256353720114, 1367729754214481825540179333483106748773367153984, 386380250326743339895345649426197444922480832], [396960926987691515610172739011069890497429230392412200, -727409488117876220157829400013777255965208124910, 453556724395038697723348616417143099589328030], [-283010504580378480077785346425152944852831421708192598, -2474609131869101272156734135073735298044478825400, 11279032696745596849799315759561925621358200], [900675698168730397931321744640423367205176127378133152, 279088819548906531377605579685721605275330435272, 761337908626647859712696156169744802830216696], [-946322190451796169964731340038766138649792642901504946, 1029290597076808205291093261962765834297805438268, -639279724984843733865015165006813052893084060], [-342917000288681350321054532375372396306806689684103398, 1459541481005359250022411595528873862621365247848, -616288392012667038335888000038390588946352552], [-605949933793571321721005409861778981822007419294010140, 1141621570638223050614483786000150577836703093381, 406714426481221471956762151963772080104576627], [1375608199446007907774363709662739641941486646077188872, 2237357265179043972900353095752896811796659951210, -882812547140941643591509048344493156528599930], [3872946165700025394647411025323657348144723050187032962, 1812529230824770806339916491431751946175339141960, -1269103650371018567878398380135805787327084680], [-4961333475765363545071036467104690716520033438584958836, -3667187986064363454184516710036133221660718919001, -780924741537633054653207765880101141162414463], [1827694091099707420025122535670945572279300655674418552, 63719646183827132699256990086015772291038017206, -1767931553798141074602173386854677169985195686], [1421805498791341271720079244270698980981436980634047334, -1267455087213370415999697298162880148225062011124, 4103990658168631864215364234526135706110703636], [-8256569648552515923753771189229265590275421038389791620, -10417755274527309851821790088830695564140089279917, 985475354561460745698775011604544950463343861], [3731757185710948473580924773041453327234374033218566942, -3448542242066446934266046711875522085505834129060, 2122476386327925644425304054650535182234438980], [-2111338626077160391287803988402213310404948800728333726, 11495178384170648715198625275655097267057699861640, -256999332204768800216758785353424724232164296], [1117456432351835086598960652474425547870855763154572302, -7860918295310412280898262182402348277946286407156, -3738790321500783795682191642266585901542900460], [-4682701840054980651021735456301389302215008487514884956, -23541906675505276072183514820212983340353124814123, -3617354339533837612788242075106056498579126877], [-13570326069048263404522528426655275210858843440192391588, -6811051068204421780178465018864979050459283793365, -4043243761550025957514575053911577569933793955], [-7439564201584195911266495055790433259324662046591505098, -36163628222659616898888279931838766987836069025060, 11444438924271627416956608600110195118473686980], [-9141445913466668690919016962566230629095611534159332370, -12898192172347193291789533828301296762203714829812, -1113460424209978711708745466892147375146746604], [19585713864216310861115129720609429942756581655101226160, 11658243187864116940823474136587481049462664686236, -8159721225658704550600229903642122738449966588], [59532420880918776805883897749587486483591377910510166952, -45325803173572532461373724008203837980814104333966, -11407889275165503343972736438700954307370004930], [-76672488615929899778003250432565200040652944777600310506, -25125456351168330332271064587259266034223207276148, -4913147807198517549086332592992585809124191852], [34526292376349329225491933801327466284409759725041650220, 95715065440521866904061368143627159528779614265167, -31198436421452392943278333905608972750758251111], [40609901837403424262813285164423385132705349222323888664, 28226877646425479671866857939408450139828845927614, 8701303639608808564594827663391278547025178642], [91639595378843705666554876126174174413898212643079422352, 15650290718841552616311681662461941894938229817140, 50146042499157561587493298042598937338375614380], [-51683817090513102310891119739758295989952301650843263298, -109195863811246384477502751644377839650814023320068, -11015055229785547321322048689589292027447150684], [-181057556191615694518151778597270198316348304905360730358, 111673089466544529294550381259466121931750194441360, 22424385864928444902175414497913194548643195120], [92701016334045650640226614811051743665510962596499070210, -186770617790086182213923647149719756214957449747064, 20452637279394495029155593209166850987609920312], [56523793250893248873958627306896569197757276872269177774, 3489337790334101909327654495565100983447485967180, -4954441595144195007063273405216593334164188716], [-462899868193714559519833349804163988658718885159727494148, -13707853285857268595784040631919145127856458438925, -18771581904725154827449340158743328266174922923], [273831478585715880003150154109540770886329286418608895702, -89082626405132347117650836070879321220823585587844, 116562208661813224635945952376089816378827107364], [-76887757063771977314025813081597574688451607712909045670, 387743026639117743130823168086908373938147764515728, -180338429508571133942276226132870787118373713424], [-132738863614366242771427272574865076726600289902188268508, -205757281796715674491528878491272221083916054869355, 205943041554820677506226910459248581205780383715], [-54624665709391752589594813954279367667111609624899449218, -532795286404819161206578365497149482656866483483540, 73034280400644796171976139965784504667462736820], [-629829528385268688730027349908463018077722480481798785976, 754052897649684181272988373734400091867418837774650, 29488161879024959347669001152905879023452273974], [383687988939256142660122345734401627410966186778945957652, 162451723154985285005506917934975218089620088711649, 36382523072009297459374227369484482696569640375], [-250949155613586413510834207519583685196939458523889134410, 123283015642642066846895261098691282245314732377724, -36964280266576696078535174465241365565269968092], [-137458717158120754433138590709929854607875737452351588680, -933932267656063712532034985102075364874845334862458, -318423167463222966378979943607875476467974058486], [523401131135222244503956917877295071234850394919091223134, 760044760954918328345690969560566258487248516656076, -467412192749725967007437462709281093116639765164], [1039976883141459874338068665891466107374067150090289804202, -1398403955297472109599692548290857512121107585677808, -180921972989617091053463155181615971179739499664], [181415485459374239634334530778344479333464019964557979380, 507450932336682201847530347612147943235873638259353, 439018409416503921714621795055585731041362149951], [-480038953145697017448807415029385346942868051705835161696, 1388887646387392096907822601426426503395377340212168, 618657301317303264903784446549236317178441493240], [-2926458295348134379482437498320446116902173925462313029498, -627693964671967790736396187938680267095048832842356, -602827576361346170458136479911682742324533719660], [1027926301569956870471185404696960766996513091788054850322, 4108824882816416141700242526694393206950810696065440, 48788568494991854256053472119130700613920560480], [946774257550085672886251934881860106753594617829640927644, -4046683045654049170295127158816765671996489121532453, -362170596014512817302527215145910344969919391187], [2128478556401682261136804775379850089899355183920577094152, 3238460110476847915460841905063458538379112107460330, -591400100726364734206897342645904853136044447738], [796155463974942335105177598772938555346233974905150810052, 2205887334497119653928930111840020619450130126346237, -349247754999659418260880021866938487980828049349], [1498989444002377529970063204375977823157492221887758647792, 189937106109264184733141297830400750525751473660780, 2110470226224052297997476631093994161349942574260], [-2100175365606222824564703762811580326272478450909286146840, 4215879069921183608926326366156191061157062776922306, -2409633298767701817273757857241079678529733994898], [540606412049801568266969634327899662831126217302324341090, 8503083598556785114585621285415414583731286547877384, -1182652560464679718676279095211576698987390060872], [-1051462995439198394450411868094971114039159514047699983398, -1601022606652941133039229367048627642754286957149560, -3471703134462604184358190789269957783562288730568], [-2095181160528213512186943426763963514916977267352472388538, -6706890932577777884933710001237242821033225277099220, 178099762527232547990351401241326911515753494260], [-4523855640074612713877752426510603656122722392487035779748, 14174529868842115255771427944397582688576858808956491, -1364175518216061182199508821548048768909260260291], [-8573152810786468893534478297382159022047902117554394941366, 8934400148013124954652515008368680966802989971886416, -2595150920008611624371049422331227878676011755984], [-14542855778113561971865338329606577325458958817916791791048, -10971735891422380023408153246499716594117263457842202, -2053730678340659595809735323063723088352601321302], [17010935959502220145539763681389701069906708267244780844932, 2044257545040263857504986411775169464743763575308205, 3508633562672100161872678330769267894800916564235], [6994514433406493176774125169484028675859832496427530017202, -7226467482595159438192067959343613914843119199168216, -4697903823709610597667024261459165888411023800680], [-7511591739460032720233195790588026271931994190140246336856, 24909672460965945443379528409989268888535728483254962, -4688857848080239125478697336815612528122022708482], [-982349389185067007866455881756154589076261548079305585888, 29983542123216456646936006749006413428135392546086760, 6599040909915045068803786895050528518834041656920], [10463589650792377489304223480299111538438295254680831249102, 22391393448807425127135979663916154423384358280817036, 8679049099302230679958084249494568969818071173524]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1_40_a_a();".
// 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_1_40_a_a(:prec:=3)
    chi := MakeCharacter_1_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 40));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_1_40_a_a();".
// 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_1_40_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,40,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;