
// Make newform 31.3.f.a in Magma, downloaded from the LMFDB on 07 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_31_f();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_31_f_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_31_3_f_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_31_3_f_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 := [731025, -3116475, 6454710, -6139950, 7116556, -2156427, 3401146, -636120, 688988, -173039, 199542, -79034, 39842, -6447, 2908, -510, 250, -33, 20, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [797323745369524087634135964519219299894681863793078604606635, -101130153122855773648945164172680595627673762901979449226950, 179343703661103228371560796494950003273341157244822899172655, -88772130477608769086702487450258488997614093101962344772485, 65387657434403791736446036878681237419270187341847569645728, -32025655970570696707457639781414521666207951802867779540744, 13301664137167686135318618571836894356806080230040471329889, -7624808981467503778560348033044445762716404432919894218403, 4435643020859600351639118027898731145437816715899969036158, -2354829888108541429329433475939912364050835853062120585702, 832638087173642074130972483408967727403035125626741244626, -287486427367305390838812936845768706914515941182532154747, 65982912875820342051136428643809638868932185160188589588, -21995016566432090286542546463013830096230350652415795776, 5181762404953963572765680211495247369721161449535573255, -1796678985364041299522515379808058017306413708223309101, 359239090099569663424828256069177611510652831982544730, -129194067955475472812887089523148378204356003176769030, 16691574571835862193759770136204144261722688877132317, -4495526646960638036160404011135654784110926912842591], [84582940300688492595176711336053308071154430169563053370050, -145071822745847572320872191513646922303995694123425989362215, 56171496951761137610086884246558887931457336827517643710685, -27601643847620166972287105507431045126993497661078657193744, 20575906973878047679008913754371252644751878795329939106116, 4757035740502745774740136364905275101862929611375582096855, 4247270891016898263058639141288423282044145570665354158723, -777397385030854528658404631191822988308001132382659335726, 1436063281755208209501570486377297803853000536980778453106, 226848653763122570549656950783920780800297386936918807862, -132151919863835205765856088732809990088331488421041572029, 145561878358118262219471452990698704957616481113384612100, -12235927389323197644098711829684209476325225158681198132, 10258533084938447983354186255879640031704558181094186057, -911213277306223450691078808074057723658894755195252539, 968159077876050312170070855637741869354694454006946270, -46022490217306363965639593222164993269869838573843782, 89500278866213735853832158800349414207505094002026963, -6123658696844321768598788882519701062811851375073337, 5309592671902479902379596446827677923461389143957964], [433726357055530295481204380910317917759379073839882835935250, -1247944828571836361716391517286925815836042554619638351722500, 654437695514349774312610103374849674815684534873817828686880, -2946829806598178399175832221273939380467887638655476504928866, -133970169249284506486820569137118227559480595717208518829936, -1218722103786123048726218727807246258612301025489248792027016, 43823693482452084323334692390076413318685155564189070050478, -249282877540116032061495458548728385359425003148011866100992, 18818530840173540908809381234667693532392204592914398684282, -59246826310854204531746320750358190611736506073942581618856, 18575442185211600394562671572852766333778807022686770266682, -13859822946633185865125368800028545320063929617189931283356, 1631703807757643310901421666530200184615820513530381396656, -1005491898390269376096313550671564903050467907600478494455, 120690918314951844883838985167745432034766319980474781816, -89973641484588039676338908546294582141672216084193922136, 6494139023192226949586307948731467009552796493380915670, -7287026737490860685850368954060667431679831205357530316, 432191907703258599715481571076029111043064477430061966, -386755498948761717556750091397281147942782341360446828], [5836360317944547899347090758544961536158253366781447035710150, -38219882616711223297318372919876790724883238272710104454503975, 41490221383070687259777840664004132777721352770257528403915120, 60797975455957508481397443532165161764806525382435651603018900, 41952290553092804274237655391760929927398997595944761319658798, 28970039167168743311838982795628515452926907253355356007469426, 6851716781865137846584229025394645303017467820268972124271952, 5976175926913450143825465943337970982039328556242378725356263, 1488271684453005668341709940779779912527588629502674752056851, 764415651141733156240401725873595942786362628284948345635382, -16520014245961272212670332089899008902418716299116673647351, 322076809874116600693351751182330129781251500961855961140714, -10354219554661557698313439111971058742629813028042423196763, 22673390942798537382284268833073851553247197576610683562107, -296009894544996502818580661524071688481176955696176319563, 2198604842753015085535871250975790866009015351207194578403, 76335433453656673775319000249314061730753183908621456957, 185134628114247650092221803195299745091394035289479853874, 2166284325077616873090776503867711065372267163700647526, 11202238400067685588872272063814966283643133481767254983], [-583322310858571328877807945471802797965296883669968678961332050, 1720361707458279880613687217584389825056828293789398668948272025, -3157074550926090815121687268097466231756331983359237421112215045, 900571096096858039796398349858978628993121707026217230096681825, -1519137420378577417101271202789289397040391099639335203437127974, 959240231291682103915950172010945475207545788509232100497732712, -410164408888208957015573683877371334966930885304457203255391761, 173413678377326016345090594640545132904431012619039344299291926, -74414747621052121072955533280632242524154950688836044851288448, 66106435508736453890827209400011178516257436468109662996936029, -36213269984118600391870450340939864189596604834447999819607622, 13194134962388300586172890823864080604712810252623406522201698, -2810338545606827180505667183191945628142694165419140952797731, 952744492933417277598366094633971991040718908040887275444874, -236206261799798566820817671833535690435509084391078289261096, 77776089586379109069606013182460847131436099678303386607081, -16840067241198525909749802613577898874143544561080556118481, 6332583942850075658378981266413610207872048999944232218713, -1041348458991754127686870306115601464887966459605405923218, 317085382876416945224633997270556530835700720026960963166], [34262649535899189184098348075852482512874689329772143084083250, -180987722244563306805349624069086836912943930962876995066182540, 39676560361377767912850533256415201835490213128660343585576138, -248309820790419856829868688557276436010891618455659539403483272, 3460655052314653161681331307446545047800949778170676495578478, -112524791334579267634483478503793258063886883713677257931865974, 7303703290167688828362496155874250755377976883021512294631856, -22228104388891839725547108466086952893308542531326155716739086, 2474905566833505803660995769341902992531814129081918933292438, -5689474628938036338594565893883973835196207933598308351968066, 1882826653720409877271597217452257229598053144129047215508088, -1254402280057731526800033775473968568375079989787529426030548, 160716889584113617489786902951199912868791312818096284745855, -91465744074564867590887637080308257340433473501961224914048, 12119100259808926237116458763680868705432155625371725878948, -8084538891575319778906804246343708286096408218588454199310, 700660511661461467290914511142167007938850746964494735798, -651741446532696397018875454402378493121818734283379779338, 45592575087098795819531035185726189812388747492143861944, -33818819263589106860132895197685607622563670474844665570], [32329548481400980387223336291672372943651673058596079654926980, 62719837352528497902641105482025273458540317273024197970293910, 18783186160997980644382110461198231260849596645527150722885209, 208066704370873497185393270905459181711948728541881727138006984, 57203488637930345608105303652132849384278511464720038925942686, 107362437043771650011495715352377945968828717156261675265441014, 1762408842269015982699825275258976195557565035542717495167471, 21207290397393364474840703257234965138093831077592620414771200, 1097271796913542119872539558881509044721269216440709287382088, 4386069160790184803434296684199205717012184522480473786627358, -1277396565072682694875730337707488262995053746885074647102343, 1234066577882140032230107471410857939635904352768677327806606, -119488837551724489075520084854131814822822092424987362894216, 88612348098273582208575802160269515354249556356634694779556, -8500053119632616405190659260928036759009238780021130679265, 8074025708847563401850157320060151314633268568494373690442, -371859043181744660463676758362940679024810056716151650379, 666033728953991800686127424684840326254025353598820687452, -30020137663815618971835074789514165305942324821553458087, 37324057985298745221773935791071731277547943967605336982], [-17880407867017392105131657446768342379764554906879524045455725, 44920491766673109230410287283801676804960821215027193463141100, 7869384986007831452451984729343168526230371059577234014788170, -56974706984058697751229032354682556678312798124480089944848900, -16296657647017059260673462739860487631708625608643654362098977, -38439833127849061429702807859303594314226857366429547484578609, -947625719756486577793202124197244410116680123817470903441723, -7651559420114507096196456522415891598373937247486066270774652, -513849794550357761920618726944244188259221532342068950148364, -1594032761286992460558980402198837983007222675577673542432098, 548059100193928674534623798581844867413927913565967410907129, -497228139293549512950842822102098434168004790857785404729211, 50815291001139291642534214617190040092409786250011714076952, -35319709513862674052613549544293805365730604411231892416493, 3738831857963878479464284672336641042471675152300572710257, -3218250436996263024252800534542641522093065310349234979292, 176442794548202530865183137266284722479226646267440523767, -269179555867085760009880691612032265723693642465350564981, 13776017927087554275153175425959844737632126969774125126, -15466893103678676487014324642295993623772839464387837777], [-478681043661456407469250726520494953634552381384538446794150, 2607877931423419077232478295371099064506103539211209161857990, -3126247946767704664347286589613391949753704774282765731592830, 4350018175225140550330052412659458030147896407182904202202037, -1009684989978108770440234429686089367397767673481470866548544, 2415615702227967769657186082250285783296971782999145841018000, -343546201345530457974733671362851027699620390831286775255094, 447455940489074627950432654573254840277743213196768850108023, -79097152031256971895068021326034471076515293697541149154088, 132557709940906170075492625161978427250120840221950336726498, -53713123117759603782612596691628590974952408994797023954998, 29341632170831900613718436905334648189380183450011325542685, -4438570883651448682382625936438982068844926855941307161934, 2125252004903447743320289108612414679360166707616916572434, -349579167069739805198996545967843494751927450897572371300, 184828358822276204524807859517869231448073906025571775115, -22052434868019700063040818029961079030766972340472992194, 15084822286545858453594089872674148300601264810786394211, -1411358434245317609637741949764812268367254837776948284, 782946987838278446872154329695250828932518651116793261], [-102116833080014101153175912788449336806948676224346054513961890, 236044804251190338057010292550900497661292956349055449026632025, -291826241270961639196338631695881815414203503834176466508648681, 371614938948121918464024866517704809496841492369330185000419220, -69774065612206793336542163835105732371636105428278534678107073, 194538745968013319768845534655961526433516067855000599925470897, -28292907559269809910222800933479564579025791128216412995363555, 39138366858568656015830244914095894696902417540035261502693304, -6815176631907704881598286373759846955104129875106552315197334, 10608493079710705181135686075006215476299218575701774354490181, -4160420771598839643152333346680608346300341530564559604302279, 2350820982933047742296605481106244318210554506516134635273586, -346705604295299180847582832423100386858528629394615557052944, 170222611097705148628084882589375544272310697922396956663703, -27149407627020511854385954061197881994863942733398587337687, 14852208688207843295583465015925958945725431677017644047798, -1675875002594594878711975670362376896959038332164577982538, 1204562706009106261368602255450118061828719347064720945715, -105864282285035767405630683228102936473418294759646773247, 62861688055526124393343995916932304757548785892454042198], [-279796782564263320094095373664590290331241471431974753310001150, -74098852342638451892751718487197599698198421913118007641942400, 272035772876215451383500674767790888843005185786531996612713780, -242249984481832042887416637923874237412695179359276757640435995, 108533911579861529384240084430232383711867711406811672169098537, -215285613847576483645753801280018428535633910106688616440495861, 36392534943469004485790535145547360186548385202550591500285688, -36505642303437761842973768975709113967095733621315126649566443, 5672469495263677961878056139580029337438461705191208921696924, -11918136134874329184532834624416255682274638571119159554633037, 5688583288976315309243953624071708037597951961680203858854351, -2900982231699943019255721152144425056709724573714909913102319, 464531255417194844232161311516043209203895751683459021357913, -207649449273839407508325638232491999992190418633925718288762, 37655390920320337503575815374703688315481195427408023107408, -17911477508458691096784483668475499202064333106074792192968, 2455588213478116193495301937478816283343614237473797761973, -1492251733285405995456913212780727102217027186945221384994, 161912276273644181307584168827263522894354133130688834399, -80066816683185614017035340853494166284799559599907343748], [673953736890930501238252455791147697428858151575623186049775, 51392541341051174991733777915409357968106305693123970437212750, -121154975492421826310190167725293059246222356765885071521806905, 152471806398283947640278621088110076769109347077821037158729740, -32609199928461903898663998241561319715504097901963995823189542, 91828678771759299458009294715407079251164811068173231294615116, -12559901479899347687799344087463037035906671404023226961687598, 17857609048403920849115888871615925878706549930340814822518963, -2516929027375470990241638183485930131217001793920631970462514, 4934436529229081521537012575068677618038732554014562586211697, -2054614845707668251383603017563457041300630870818847888718006, 1176643962977866687691971108179718328883892336308326660715884, -171879002268507935133269203760300372514915436165421511678128, 84663042836614362531348439155960889744747387501267294217322, -13508448851701087846177656620426572814641628740430648406263, 7420682853782303864476937224131018503416483068723062071238, -830291355522203215482138843654576740947270027727841022053, 609774129308528994907737038954647909173644689622684602489, -54056877024345564560826319706024819186149432127244942759, 32580980675266865569077704525542050140235332825362841483], [-1223222419672873184870867721345364408051023107122538976604358475, 6229408336952873826295076058517574291878120333663498985962127550, 1694416231760980845738921209074003066133697783116541536251605870, 8806908678707144912822578033698083544050968757638635748344289820, 2007456383162023162467182778688081766383524813295727860267228698, 3263595722760154361477046480515341542812169814726057772131246316, 222597108000231430802808001002022906228826611388944945465433007, 691283616918587319314637089279386913647498049335321277618567608, 5161337474430563317238445517809555943906036373211086387109911, 137838285976580219368528187019578331421236058852083093361273842, -27162404945030710615257013759835396978142334093981159776453691, 33065918879321304440662890003099664003222056027422003784420799, -2682520452904107009267290116196234039810410505280738640715508, 2416972326600950840481934802775189120266886439712341686097727, -172394922235104269450769847197679203396843870855098039943198, 221488420300916134894427973271084872622165103887023231945923, -5675905500050608079958065194555618715879665424866474449513, 17731281971804773904001217200845050460136591288927962148259, -457091384607244745061824961381088611725159172646720537069, 948890025970452570505038077424467557590135157484727395513], [-3765570602617612765330242901065627324488591220693356275495627200, 13025890268246337080313443337185164275548990860089518498541833475, -14797272337125731326668614631107481453158975536853473153805135565, 13487191521778451485500212272291287691654190476366600780672996405, -5957910405762769335685049192722954936780433568028669252407212892, 7253381621079319111154601789635391554960488105229485288842176641, -1609155494589618080109566425119755794536469966245557583951417108, 1407557626527275197062684516759945344571676558411268040571877213, -394403524522953443490797108079580540010341293647581153228709939, 439599143461945926419886786805497851491970464363365521933601087, -188492527667998514520345492355935541136405326800299418578756111, 88274765415024094979345259848199384659639271688054032459052904, -15180849992558533473331924412145594012785643287236509506949588, 6428515028151898106152985657452914728728773049072205991540262, -1218723475260070906054826663461345772654224341896209926487833, 547779231376139716360749187286898353837504715445976235544318, -81092825188998377167421029958670278309240586111677680479933, 44101769464152305073275583631806219782068962247531344234254, -4962437735426924773772509523567507329854472979562700204964, 2206349329907541137041304897114878973834752519749650070658], [239838546751294324288688436530967377590122825308405001588582750, -1266914055711943147637447368483607858390607516740138965463277780, 335883908257972717409407296505432891502241582817819817174522031, -1738168745532938997809080819900935052076241329189616775824382904, 24224585366202572131769319152125815334606648447194735469049346, -787673539342054873441384349526552806447208185995740805523061818, 51125923031173821798537473091119755287645838181150586062422992, -155596730722242878078829759262608670253159797719283090017173602, 17324338967834540625626970385393320947722698903573432533047066, -39826322402566254370161961257187816846373455535188158463776462, 13179786576042869140901180522165800607186372008903330508556616, -8780815960404120687600236428317779978625559928512705982213836, 1125018227088795322428508320658399390081539189726673993220985, -640260208521954073136213459562157801383034314513728574398336, 84833701818662483659815211345766080938025089377602081152636, -56591772241027238452347629724405958002674857530119179395170, 4904623581630230271036401577995169055571955228751463150586, -4562190125728874779132128180816649451852731139983658455366, 319148025609691570736717246300083328686721232445007033608, -236731734845123748020930266383799253357945693323912658990], [211789345305643164408975935018179683570268117922780907601791135, 454975765388343214045874019596142586116962544571439414257344195, 97087657820090699341121169684463957889422706600805274018684833, 1408691611475469682827424586978079037195595009325598695666130883, 353237447448977860858059285697031766017056835369451466941277377, 718617961074795937731405568602527163574729473245255916547180853, 10575760142209700806264685239617788929658199198868073273795016, 141820766631072019352924274270012757258527884156481672271412269, 5692894688006819704207045719703452850754505349695677093375609, 29966299990659182168045804268507374067152826720102644403080997, -8842152248207279434567484502053111475210788037432412386307771, 8272955788355278082520274069973483164995829190944953626213173, -819857996896608002561509856831459853178571188555719532283517, 594603622009019225140701079487059545639748972467283222455365, -58686918084806499576143358998689020604879615795572154578585, 54067140045436528209530871092295914491048139809484486471003, -2657733477478521382290580603543409582107551581575415156610, 4454372873262798687625249193476900250491828820929501578379, -208762136929271734155615500745443457935110211969695019593, 248315538447707952816254504860497431703937791039400082927], [86545688062215095051748506719526862027472232526721639844154540, -207489794906601727773583298411810857626832514565143352432181895, 274323275773746343863953922805737947172950199851363361872714186, -354317980774360557330293190660183914223497268197594731162577352, 74627149446958730489121308227867953864111542557945672239731609, -186925135267405941966549182691801043995859009971183603440896544, 27343218258300665237729841121763520821256794628760574875577276, -36679749300683569672063918264786325945147872966111018533827079, 6405513582502522003914064475557832813730104571274581735023514, -10116063071366956334640067650578228542748889171011082374122379, 4005901584036753280918254628559750277356170593505975341135522, -2243633991782131583714913219802128709984766827411539153513001, 333135613245088433204608955886113273116537265710938165936938, -162401797480320971206759632767088519633663979114219024000512, 26120542574713642878347327053520901973314997712808285507731, -14154535291723561316044978633750169541415775652986929679372, 1620830000067421280592644435898654009611727092604857493056, -1150109960653876262594200708022801635583077120690008603725, 102764286465294587998100357613406879804350434713092265840, -59989793038472306167511726053755859810369966038771381049], [698702339058814651601346765092014602931673003288120204978727330, -1608333143026076089339308351326213124305841293606657448722129325, 1971622052688011127474153106557279637291126825876201336134610107, -2503251934012255744444376481266840124036641138173462607648106500, 499502829766665900170836256862624107674613899699455949448085897, -1306596352109983882606742224178445752804877894155248910403067235, 192539033491725331273541664277106649123624560166645129738986181, -262443212782977041602226399380946224859208302577191783646770854, 46726576273687110018101808231213539868364436276055204843724234, -71517452083256925705626695948697801309585232218408330762228697, 28101098451950239953627459185491687624071847144461106368082513, -15772237541165158704199640004157232968448211550582439739679312, 2338629720445541692244151731500652687962173353406608398814868, -1142440870727929701911938246281268741464410942707214796348701, 183251847113637990162854882667016639479520440092475161125776, -99601860806966655098088352109124239275363019314662381608138, 11348356722763827937351458677264173102603936277564732140518, -8074617772863079974982388419310234213065171245476758329727, 715509231230641072918190708785278090264906572871997256821, -420576628247609775135720910550569741766818989545600889056]];
    Rf_basisdens := [1, 1, 113348900055220939609071274289525299520097643113445247710505, 113348900055220939609071274289525299520097643113445247710505, 1020140100496988456481641468605727695680878788021007229394545, 21536291010491978525723542115009806908818552191554597064995950, 581479857283283420194535637105264786538100909171974120754890650, 58147985728328342019453563710526478653810090917197412075489065, 58147985728328342019453563710526478653810090917197412075489065, 21536291010491978525723542115009806908818552191554597064995950, 1020140100496988456481641468605727695680878788021007229394545, 58147985728328342019453563710526478653810090917197412075489065, 64608873031475935577170626345029420726455656574663791194987850, 21536291010491978525723542115009806908818552191554597064995950, 581479857283283420194535637105264786538100909171974120754890650, 581479857283283420194535637105264786538100909171974120754890650, 58147985728328342019453563710526478653810090917197412075489065, 58147985728328342019453563710526478653810090917197412075489065, 12921774606295187115434125269005884145291131314932758238997570, 58147985728328342019453563710526478653810090917197412075489065];
    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_31_f();"
function MakeCharacter_31_f()
    N := 31;
    order := 10;
    char_gens := [3];
    v := [7];
    // 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_31_f_Hecke();"
function MakeCharacter_31_f_Hecke( : Kf := false)
    N := 31;
    order := 10;
    char_gens := [3];
    char_values := [[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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]];
    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 := 3;
    raw_aps := [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0], [-2, 0, 0, 0, 1, -1, -1, 0, 1, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, -1, 0, -1, 0, -1, 1, 0, 0, 1, 0, 0, 0, -1], [-2, 2, 0, 1, -2, 0, 0, 1, 0, 2, 0, 0, -1, 1, 0, 1, -1, 1, 0, 0], [3, 2, 0, -1, -3, 3, 2, -3, 0, 0, -2, -3, 2, 1, -1, 1, 1, 0, 1, -1], [4, -2, 2, -1, -1, 4, 5, 1, -4, 4, 4, -2, 0, 5, 0, -1, 0, -1, 1, -2], [3, 1, 0, -1, 1, -1, -2, 2, 3, -1, -4, 4, 1, -4, 0, 0, -2, 0, 1, 0], [0, 1, 1, 4, 6, -5, -3, 3, 3, -5, -2, 0, 0, -3, 0, -1, 1, 0, 1, 0], [-2, -3, -2, -6, 1, 2, 2, 2, 6, 1, 3, -2, 2, -1, -1, 2, 3, 6, 0, 4], [7, 6, -2, 12, -4, 2, -4, -3, -10, -1, -7, 5, -1, 1, -2, 0, 3, 1, 0, 1], [-12, 4, 1, 6, 3, -9, -5, 10, 5, -2, 2, 0, -5, 6, 4, -6, -2, -3, -10, 1], [-7, 0, -2, 1, 5, 0, -5, -3, 4, -2, 2, -1, -1, -6, -8, 0, -6, 0, -1, 2], [14, -9, 2, -6, -8, 0, 5, 2, -5, 6, 3, -11, -2, 1, 1, -2, -1, -2, 0, 0], [-15, 0, -1, 4, 5, -8, -7, -9, 9, -9, 2, 9, 0, -3, 6, 3, 0, 1, -6, 0], [-20, -3, 6, -11, -9, 4, 7, 29, 21, 4, 6, -56, 3, 7, 3, -3, 4, -1, 3, -2], [16, 0, 6, -5, 0, 0, 1, -39, -14, -1, 3, 39, 0, 0, -2, -3, 0, -6, 2, 0], [-1, 7, -1, -11, 2, 8, 2, 4, 9, 16, -4, 3, 2, 2, 2, 6, 2, 1, 4, 1], [8, 6, -16, 6, 2, 2, -4, -4, -4, 1, -2, 12, -6, -6, -4, 4, 0, 4, 0, 4], [-36, 15, -5, 1, 5, -6, -1, 35, 4, -4, 0, 0, -3, 1, 3, -5, 5, 2, -5, 0], [-2, 0, -8, 1, 4, -2, -4, -38, 36, -5, 0, 4, -4, -7, 2, 2, 2, 6, -1, 4], [46, -8, 8, -6, 5, 13, 6, 0, -26, 13, 16, 40, 7, 6, 7, -1, 0, -4, 1, -8], [6, -5, -1, 6, -10, -2, -1, -6, -7, -2, -3, 3, 2, -1, -1, 2, -4, -8, 0, -9], [-18, 8, 8, 9, 6, -10, -14, 18, -3, 7, 0, -4, -3, 14, 10, -7, -13, 5, -5, -4], [-10, 20, 0, -4, 10, -20, -10, -15, -11, -6, -20, 42, -6, -8, 0, -6, -1, -1, -2, 4], [4, 2, 7, -4, 13, -21, -1, -5, 23, 5, 0, 0, 1, 1, -1, -8, -7, -20, -8, 0], [1, -11, 3, -7, 10, -3, 1, -38, 6, -10, -11, -7, 7, -16, 4, 0, 1, 0, 7, -3], [5, 6, -11, -2, -13, 13, 5, 0, -23, 7, 0, 0, -4, -5, 4, 10, 11, 17, 10, 0], [18, 0, -14, -14, 5, 23, 0, 11, 5, 0, -9, -11, 0, -19, -23, 15, 4, 14, 23, 4], [10, -14, 0, -14, -10, 20, 10, -49, -54, -2, 14, -17, 5, 17, 0, 5, 12, 12, -4, 13], [20, -46, -4, -13, 2, 19, 21, 3, -28, -4, 27, 11, -4, 12, -2, -2, 0, -4, -6, 0], [-8, -19, 0, -13, 8, -16, -8, -10, 4, -17, 19, -27, 6, -5, 0, 6, 6, 6, -1, -15], [-4, 8, 4, 23, -15, 9, 11, -4, -21, 7, 20, -18, -4, 14, 9, -2, -3, 4, 5, 3], [-48, -24, 8, -22, 8, 3, 4, 25, -37, 20, 21, -15, -2, 27, 21, -1, 3, 8, 19, -3], [32, -7, -12, -7, 13, -20, -15, 5, -45, 0, -2, 55, -15, 5, 5, -5, 0, 19, 0, 19], [26, 3, -14, -8, -8, 36, -12, -44, 36, -11, -17, 19, 18, -29, -36, 18, 10, 4, 18, 7], [-30, 10, -1, -11, 9, 13, -19, 35, 30, 20, -12, -22, 11, -10, -14, 0, 0, 0, 11, 1], [10, -33, 10, -6, 28, -13, -5, -15, -78, -21, 0, 0, -6, 5, 6, -17, -10, 8, -17, 0], [17, 34, 11, 13, 1, -14, 21, 37, 26, 27, -6, -57, -13, 7, 7, -14, -4, -8, -1, 3], [70, 0, 1, 22, -32, -5, -6, -60, -69, -12, -23, 60, 0, -7, -1, 1, 9, -1, 1, 9], [9, 4, 6, -14, -13, -4, 45, -34, 35, 15, 36, -30, 10, 29, 4, -14, 9, -15, -2, -3], [-12, 33, 14, -41, -13, 26, 4, 20, 3, 44, 9, -21, 4, 14, 12, 20, -28, -8, 8, -20], [-32, 38, 12, 38, -6, -25, -3, 5, 83, 2, -9, -85, -7, 22, 5, -5, 0, -13, 0, -13], [10, -4, 0, 23, -10, 20, 10, -20, -35, -1, 4, -8, -5, 26, 0, -5, -5, -5, -3, -6], [-138, -36, 28, -23, -4, 14, 36, 93, 57, -2, -4, -92, 12, -4, -14, 2, -7, -21, 7, -14], [-46, 18, -13, 32, -4, -25, -5, -18, -67, -11, -17, 4, -40, -4, 9, -20, 2, -13, -31, -2], [-80, 7, -8, 7, 56, 0, -36, -17, 85, -25, 20, -32, 14, -36, -17, 17, 0, -4, 0, -4], [23, -6, -29, -32, -51, 60, 19, 1, 77, 29, 32, 57, 19, 3, -9, 29, 58, 26, 38, 32], [92, -1, 16, 9, 10, -23, -9, 40, 0, 2, -28, 110, -9, 2, 30, 0, -4, 0, -9, -16], [-12, -14, 1, -17, 17, 5, 5, -48, -46, -23, 18, 76, 37, -9, -9, 18, 1, 2, -19, 3], [43, 0, -1, -4, 44, 4, -38, 33, -49, -28, 10, -33, 0, 8, 6, -38, -6, 1, -6, -6], [32, 25, 19, -4, -55, 14, 11, 69, 13, 14, -50, -48, -6, 11, -6, -10, -23, -21, 10, -42], [36, -8, -40, -35, 32, 34, 4, -9, -26, -5, 28, 32, 1, -38, -34, 33, 25, 15, 17, 20], [-41, 36, 10, 28, 5, -40, -23, 163, -16, -4, -29, 171, -34, -20, 13, -17, -21, 10, -21, 21], [149, 12, 30, -7, -5, -9, 7, -142, -150, 19, 0, 0, 9, -7, -9, 5, -30, 6, 5, 0], [27, 14, 13, 33, 14, -17, -21, 22, 66, -7, 16, 36, 8, 5, -11, 4, -15, 13, -3, 15], [24, -69, -42, -76, -35, 130, 12, 7, 84, 14, 23, -52, 26, -28, -28, 56, 22, 44, 30, 2], [-74, 3, 0, 4, 6, -3, 13, -111, -25, -3, -6, 24, 14, 13, 14, -21, -14, -7, 21, -14], [1, -9, 55, -3, 14, -45, 21, 12, -16, -5, 22, -15, 11, 15, 15, -30, -35, -70, -41, -15], [62, -6, -21, -22, -1, 19, 7, -24, 15, 8, 8, 33, 22, -7, -1, 0, 27, 0, 22, 21], [-16, 9, 0, 7, 16, -32, -16, 52, 82, -27, -9, -19, 14, -19, 0, 14, 0, 0, -7, 17], [9, -57, -16, -25, 75, -20, -24, -33, -219, -32, 0, 0, -18, 24, 18, -26, 16, -13, -26, 0], [-175, 0, -16, 27, -25, -85, -12, 151, 149, -71, -1, -151, 0, -4, 26, -37, 45, 16, -26, 45], [43, 49, -24, 49, -96, 60, 22, -37, -95, 12, -74, 110, -2, -38, -37, 37, 0, 8, 0, 8], [51, -60, -16, -29, 59, -29, -29, -11, 96, -13, 18, 15, 0, -30, -13, 0, 12, -16, -13, -12], [77, -40, 0, -89, -77, 154, 77, 95, 25, 95, 40, -118, 7, 52, 0, 7, 31, 31, 45, 26], [108, 39, -32, -7, 14, -16, -3, -40, -104, 30, -14, 0, -31, -2, -2, 4, 28, 56, 35, 24], [92, 56, 22, 73, -84, -82, 20, -9, -117, -7, -8, 29, -34, 41, 82, -48, 4, -26, -41, -11], [-28, 35, 25, -53, 8, -25, 9, 107, 125, 30, -17, 9, 9, -52, -33, -15, -50, -32, 18, -18], [-8, -75, -14, -44, 2, -6, 21, 29, -22, 48, 0, 0, 13, -21, -13, 21, 14, 18, 21, 0], [-36, -26, 32, 4, 49, -31, -43, 97, 141, -46, 16, -171, -30, 33, 33, -66, -22, -44, -36, -12], [201, 0, 25, -8, 77, -50, -9, -267, -229, -31, 36, 267, 0, -7, 28, 11, -3, -25, -28, -3], [66, 32, 11, -54, -16, 29, 11, -90, -37, -25, 5, 42, 11, -4, -20, 2, -22, -13, 22, -9], [162, -10, -65, -10, 44, 10, -21, -37, -30, -16, 23, 88, 11, -31, -37, 37, 0, 30, 0, 30], [-78, 127, 0, 124, 78, -156, -78, 21, 30, -27, -127, 21, -69, -60, 0, -69, -59, -59, -69, 4], [-147, 14, -32, 31, -5, -16, -41, 215, -94, -11, -32, -35, -26, -21, 16, 10, 12, 20, -8, 16], [-112, -2, -12, 23, 52, -85, -23, -87, 24, -85, 4, -2, 11, -23, 11, -2, 22, 17, 2, 34], [-12, 93, -80, 93, 6, 13, -24, -29, -64, 6, -18, 117, -36, -37, -29, 29, 0, 32, 0, 32], [-68, 12, -8, 64, -79, 39, 31, 29, -37, 44, -30, 71, -30, 17, 17, -34, 23, 46, -4, 38], [-84, 28, 0, -26, -49, -49, -1, 157, 91, 32, 50, -65, -1, -46, 9, 7, 0, 17, -2, -17], [-42, 0, 45, 4, -130, 39, 86, 149, 73, 94, -35, -149, 0, 26, -31, 11, -29, -45, 31, -29], [-188, 0, 50, 51, 82, -131, -30, 58, 136, -109, 1, -58, 0, -4, 52, -49, -25, -50, -52, -25], [17, 0, 11, -11, 111, -30, -39, -10, -8, -78, 2, 10, 0, -61, -9, 35, -11, -11, 9, -11], [29, 34, -19, -54, 8, 25, 10, -23, 169, 45, -18, 182, 10, -5, -15, 5, 38, -8, 20, 46], [-78, -65, 73, -65, -17, -39, 40, 54, 113, 22, 23, -207, -4, 79, 54, -54, 0, -10, 0, -10], [6, -80, 4, -50, -16, 56, 64, 58, 48, -52, 0, 0, 26, -64, -26, 2, -4, -30, 2, 0], [37, 16, 25, -44, -13, 26, 5, 32, 63, 15, -24, 2, 42, -84, -6, 21, 4, 25, 36, -4], [58, -16, 4, -38, -84, 69, 56, -58, -86, 69, 32, 60, 31, 56, 31, 22, -14, -9, -22, -18], [266, -170, 22, -119, 76, 10, 152, -67, -165, -24, 58, 28, 34, 0, -10, -24, 17, -39, 5, -11], [272, -7, -38, 57, -65, 79, -32, -94, -89, -24, -45, -133, 17, -25, -25, 50, 13, 26, 33, -12], [94, 43, -65, 34, -10, -20, -33, -136, -1, -40, 35, 161, -34, -39, -67, 0, 23, 0, -34, 65], [10, 107, -25, -61, -29, 40, 37, 27, 0, 66, 0, 0, -2, -37, 2, 53, 25, 0, 53, 0], [-86, -31, -33, 85, 127, -62, -23, -33, 38, -62, 62, -30, -9, -23, -9, 43, 55, 44, -43, 88], [-12, -1, 40, 23, 58, -26, -11, 3, 1, -23, -47, 9, -11, 7, -1, -23, -80, 10, -22, -90], [-48, 12, -22, -42, 18, -37, -24, 83, -21, -8, -75, 99, -26, -3, 5, -13, -23, -22, -21, 23], [-45, 27, 0, 83, 45, -90, -45, 98, 124, -47, -27, 43, -19, -24, 0, -19, 6, 6, -64, 19], [57, -86, 2, 57, 29, -19, 14, -135, -24, -20, 90, -95, -66, 57, 13, -33, -13, 2, -53, 13], [115, 92, 80, 92, -186, -18, 74, 24, 28, 20, -112, -126, 34, 92, 24, -24, 0, -84, 0, -84], [-224, -102, 46, -82, 48, 28, 88, 106, 146, 49, 34, -170, 28, 49, -28, 0, -56, 10, 14, -23], [-122, 153, -12, 157, -128, -27, -26, 96, -48, 21, 0, 0, -56, 26, 56, -3, 12, 29, -3, 0], [20, -112, 0, -63, -20, 40, 20, -101, -110, 87, 112, -222, 11, -58, 0, 11, -60, -60, -46, -28], [-100, -59, 62, 191, 103, -166, -66, 12, 235, -114, -37, 289, -66, 32, 56, -76, -124, -95, -132, -29], [168, -15, -15, -15, -78, 10, 14, -7, -315, -33, -64, 308, 80, 4, -7, 7, 0, -1, 0, -1], [190, -52, -80, -21, 24, 82, -64, -231, 94, -37, -92, 115, 53, -66, -82, 29, 49, 31, 41, 40], [-191, -220, 36, -132, 97, 22, 13, 11, -186, 22, 119, -33, 18, -26, 13, 9, 0, 36, 31, 0], [267, -2, 34, -60, 21, 69, -19, -22, 79, 6, 78, 226, 60, -73, -91, 0, 15, 0, 60, -34], [-301, -18, -28, -127, 113, -33, -9, 270, 572, -11, 61, -257, 9, -7, -7, 14, 22, 44, 5, 16], [62, -54, 0, -136, -62, 124, 62, -115, -140, 120, 54, 142, 37, -33, 0, 37, -31, -31, 70, -65], [43, 9, 73, -45, -113, 49, 104, 29, -59, -13, 42, -106, 45, 46, 38, 0, -6, 0, 45, -73], [-128, 38, 59, -1, 87, -94, -65, -98, -260, -20, -8, 332, -73, 28, 28, -56, 8, 16, 17, 75], [97, 0, -29, -35, -39, 8, 11, 106, -144, 66, 82, -106, 0, 103, 47, -93, 69, 29, -47, 69], [92, -2, 114, -11, 44, -48, 26, 93, -195, -24, 68, 19, -10, 14, 48, -38, -85, -29, -24, -57], [362, 0, 34, 27, -70, 39, -10, -324, -369, 36, -20, 324, 0, -8, 7, 59, -51, -34, -7, -51], [-60, -68, -21, 68, -16, 51, 0, 114, -126, -23, 16, -240, 0, 51, 6, 6, 42, 37, 0, 5], [-51, 32, 36, -45, -153, 126, 117, -46, 128, 44, -4, -52, 31, -51, -126, 95, -28, -8, 63, -18], [-3, 70, -91, 9, 50, 53, -40, -58, 29, -28, -30, 52, 27, -39, -39, 78, 25, 50, 51, -41], [198, 65, -42, 62, 8, -44, -113, -103, -94, -44, -130, 414, -34, -113, -34, 37, 18, 30, -37, 60], [-363, 15, 12, -7, 177, -114, -49, 181, 106, 58, 143, -138, -76, 96, 114, -38, 26, -38, -57, -6], [-392, -5, -41, 16, 53, -42, -48, -100, 32, 29, 53, -328, -16, -3, 49, 0, 61, 0, -16, 41], [-3, 158, -13, 192, -65, -47, -88, -85, -124, -31, 0, 0, 3, 88, -3, -39, 13, -16, -39, 0], [-337, -16, -6, 63, 171, -63, -155, -95, 92, 123, 119, -119, -63, 31, 31, 0, -87, 0, -63, 6], [92, 48, -36, 135, 1, 20, -11, 173, 46, 20, -96, -70, -60, -11, -60, 49, -50, -7, -49, -14], [-128, -36, 40, 72, -25, -39, -18, 189, 9, -20, 43, -162, -18, 15, 31, -5, -80, 1, -36, -81], [-264, 39, 93, 39, 84, -95, 37, 77, -155, -31, 121, 41, 99, 132, 77, -77, 0, -31, 0, -31], [-344, 132, -46, 38, -102, 207, -47, 297, -105, 15, 0, 0, 49, 47, -49, 111, 46, 104, 111, 0], [-211, 24, 30, -5, -129, 67, 105, 346, -100, 32, -33, -321, 5, 132, 8, 0, -60, 0, 5, -30], [428, 72, -86, 38, -156, 88, -8, -428, 42, -10, -92, 220, 42, -56, -88, 46, 36, 50, 44, 43], [35, 23, 2, 41, -92, -86, -32, -232, -167, 49, 124, 97, -32, 10, 98, 34, -4, -20, -64, 16], [26, -19, -11, 26, 104, -103, -59, -85, 133, -39, 0, 0, -84, 59, 84, -71, 11, 88, -71, 0], [56, -49, 0, 36, -56, 112, 56, 50, -12, 10, 49, 13, -6, 108, 0, -6, 97, 97, 84, 60], [-68, -8, -6, -54, -22, 2, 31, 220, 342, -94, -9, 91, 31, -91, -22, 40, 12, 0, 62, 12], [192, 89, -55, -229, -111, 167, 70, -161, -229, 11, 41, -138, 70, -43, -83, 57, 110, 104, 140, 6], [86, 37, 0, -140, -86, 172, 86, -184, -192, 143, -37, -111, 78, -49, 0, 78, 6, 6, 173, -85], [294, -8, 0, -22, -18, 18, 22, 284, 304, 58, 40, 168, -8, -16, 62, -4, 38, 0, 54, -38], [-58, 12, -76, 18, -16, -4, -14, -162, -45, -4, -24, 118, -24, -14, -24, 24, 18, 47, -24, 94], [-235, -88, 47, -88, 115, -69, 59, -1, 63, -18, 174, -121, 95, 128, -1, 1, 0, -74, 0, -74], [-358, -37, -73, -47, 114, -137, -77, 179, 298, -63, 37, -22, -55, 41, 41, -82, 27, 54, -27, -19], [291, -218, -21, -256, -13, 154, 75, -228, -323, 5, 140, 124, 116, -46, -46, 92, -4, -8, -24, -29], [-173, 18, -62, -72, 38, 20, -93, -274, -4, 20, -36, 194, -27, -93, -27, -53, 102, 82, 53, 164], [-125, 88, -20, 142, -66, -70, 22, 56, -273, -12, -50, 80, -184, 234, 80, -92, 10, -20, -104, -10], [548, 13, -33, 13, 58, 171, 57, -81, -249, 1, 115, 273, 55, -114, -81, 81, 0, 3, 0, 3], [96, -170, 8, 30, 139, -40, -54, -73, 170, -48, 166, 23, 28, 86, -62, 14, 13, 8, -34, -13], [216, 41, 16, -48, -9, -10, -51, 255, 45, -10, -82, 12, -20, -51, -20, -70, -42, -29, 70, -58], [159, -137, -66, -203, -165, 277, 144, -30, -83, 179, 58, 28, 17, -52, -52, 104, 77, 154, 87, 88], [109, 18, -32, 122, -2, 10, 81, 466, 138, 10, -36, -438, 23, 81, 23, 7, 16, 24, -7, 48], [-115, -102, 47, -53, 94, 52, 8, 20, 45, 78, 103, -176, 53, 33, 35, 0, -109, 0, 53, -47], [-11, 0, 61, 11, -168, 25, 42, 176, 18, 60, -18, -176, 0, 19, -7, 15, -70, -61, 7, -70], [28, 160, 0, -45, -28, 56, 28, 409, 381, 61, -160, -217, 0, -5, 0, 0, 2, 2, 105, 26], [100, 89, -41, 188, 154, -138, -183, -3, 40, -138, -178, 286, 72, -183, 72, 39, -47, -3, -39, -6], [-13, -68, 24, 126, 77, -18, -29, -129, -101, -67, -48, 57, -29, 69, 97, 39, -48, -24, -58, -24], [326, -147, 39, -15, 87, 2, -25, -351, -149, -96, 0, 0, -35, 25, 35, -47, -39, -95, -47, 0], [143, -84, 80, -134, -66, 112, 108, -17, 51, 120, 74, -257, 8, 134, 116, 4, 38, 80, 124, -38], [-266, 150, 8, 163, 150, -268, -225, 45, 182, 41, 11, -37, -86, 126, 84, -43, 40, 8, -2, -40], [0, -172, -59, 20, 268, -70, -96, 110, 76, -192, -134, 116, -20, -268, -168, 0, -52, 0, -20, 59], [202, 69, 11, 174, 82, -344, -62, -264, -9, -44, 0, 0, -161, 62, 161, -194, -11, -113, -194, 0], [-134, 17, -34, 278, -229, 79, -4, 201, 430, -31, -125, -298, 26, 1, 1, -2, 48, 96, -28, 62], [-3, 142, 0, 95, 3, -6, -3, -252, -214, 14, -142, 526, 35, -55, 0, 35, 37, 37, 17, -60], [73, 66, -44, -70, -20, 111, 2, -191, 288, 165, 18, 477, 2, 105, 49, 53, 88, 100, 4, -12], [-112, 136, 0, 38, 112, -224, -112, 177, 325, -86, -136, -103, 36, -174, 0, 36, -34, -34, -68, 11], [303, 124, -56, -9, -61, -88, 167, -129, -235, 183, 230, 85, -61, 210, 88, -27, 122, -66, -44, 28], [-350, 13, -44, 52, -2, 58, 92, -360, -51, 58, -26, -82, -31, 92, -31, -64, 60, 52, 64, 104], [-344, 102, -22, 64, -216, -96, 12, 236, 284, -96, -204, -592, -14, 12, -14, 64, 28, 25, -64, 50], [-291, 21, -4, 23, 24, -2, -22, 443, 213, 24, -2, -208, -22, 64, 95, 51, 8, 25, -44, -17], [34, 60, 35, 106, 74, -162, -134, 360, 28, 52, 14, 274, -106, 24, 136, 0, -6, 0, -106, -35], [193, 0, -76, 249, 44, 171, -110, -457, -110, -22, -332, 457, 0, -146, -83, 187, -83, 76, 83, -83], [88, -63, 22, -149, 49, -28, -49, -409, -224, -28, 126, 546, -104, -49, -104, -23, -32, -27, 23, -54], [-61, -58, -21, 78, -99, -65, -10, 140, -212, -153, 109, -342, -10, -35, -38, -58, 42, -53, -20, 95], [137, -30, -18, -30, 115, -130, -25, 47, -448, 42, 90, 426, -109, 105, 47, -47, 0, 88, 0, 88]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_31_f_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_31_3_f_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_31_3_f_a(:prec:=20)
    chi := MakeCharacter_31_f();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    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_31_3_f_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_31_3_f_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_31_f();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;