
// Make newform 5.22.a.b in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_5_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_5_22_a_b();".
// 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_5_22_a_b();".
// 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 := [239341586400, -743130000, -1929606, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 2, 0, 0], [187959204, -6622602, -3089, 5], [287631324, -1174314, -877, 1]];
    Rf_basisdens := [1, 1, 324, 324];
    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_5_a();"
function MakeCharacter_5_a()
    N := 5;
    order := 1;
    char_gens := [2];
    v := [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_5_a_Hecke(Kf)
    return MakeCharacter_5_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 := [[728, -1, 0, 0], [20803, 14, 0, 1], [9765625, 0, 0, 0], [128229189, -151718, -240, -3741], [8426594482, 10314300, -34960, -498310], [215800602474, 164888472, 10880, -2463340], [4424319060766, -1294061352, -1490560, 56964212], [16304015379096, 763721112, -3945616, 93015260], [76520469215315, 24630667030, 76636400, -418790491], [-296443394191386, 952540949168, -306462784, 78166280], [2031846005744342, 133752737900, 1773573920, -862528630], [12678019030524750, 8600426719280, 7046988160, -190415090072], [-37800336566436498, -20801622292600, -18359135680, 580236129020], [48792380862265727, 35817392485846, 50846202400, -186104750483], [-115510891753802843, 61133418909546, -16982582800, 1761380347691], [253393522035018698, -160292367443896, -37579912320, -4654113643524], [2499469711860952868, -1816200651268864, -78619775088, -10107368119560], [-2704962433906538338, 1208712183964000, 1085335436800, 36191725358800], [5490782175513793701, 1878089789248978, -3277891990560, 13649810007327], [12820470449883872422, 6658993564529500, -2368785369600, 122110301527650], [18680267051247552550, 8041828828308920, -7145920103040, 99802721989764], [-15242079871567732836, 16637645067077848, 23120794903296, -591598647271500], [-69659091046984109349, -46943043913465122, 20433394056000, 42495668251833], [-80868888287293415358, -88135702035718896, 34085851966848, 1609362983646840], [77141812121329572982, 287086760138387176, -276035270648320, 1333589101939436], [-182336878023443824258, 303324567468835600, 237730946377280, 8530185975789080], [-731634721067279947377, -129549488691498706, -198544578705680, -2418651913220039], [-620098036432681826111, -592776825777825958, 323641692728320, -2829852386722901], [-1397826007655287364762, -369173710012598384, 454293234117632, 5807934049182200], [-1247947958023965935366, 778087310952321552, 420076688286080, -18546639595438600], [-1637225844753112224067, -463597203135024326, 3093631175091760, 27940882680632035], [2508420848872650019902, -2836106412971360700, 1459754182773840, 146478625191237990], [-4515461559920586289270, 2012348730140520640, 7674041769687680, -239202765993549472], [21232340689004043260612, 7757545350653647584, -4012090955981232, -105128636450314200], [-12622608913115667839010, 18956859546767686640, -10670173617614080, -196045255036546360], [11711431261914799087742, 43925878166973213100, -16156202786736320, -47239962485903270], [54023592756755353717254, -33172973567012128528, -11868568817121920, -85425064826377976], [15709452660330079591519, -79034340554550472058, 3714477751509440, -293224137289420795], [155389754464115956982561, -55824455880899910062, 14323248214823120, -22160763955217113], [-165397989879283513950250, -37468645558132125200, -118248983195474560, -1589752072191997816], [-471003941903972312375116, 134029681252639893008, 57242335992219696, -433591279975381920], [130460343604121513336982, -288514883223692092000, -131918633894321600, -2023545947358047600], [-571149583939918648435118, 54868302685051464100, 64720461759053280, -1914410767744633170], [-272384648664385117660898, -56140919710523064584, 126199274570875520, 5604874560566275172], [413230127403368606720762, 142989536060720726536, 697962048347340800, 4293360199859228636], [1003090434687050586321320, 125630101275648471520, 65116095335150560, -2050856378039264480], [1617861953486587304230102, -12479574600293009900, 918069770194036880, -7341145729393081570], [2333824957779819797387015, 157593395017686731790, -51074746502381040, 15151417177682491449], [1879120002114128613166133, -783235308779563471566, 1263357011977748320, -8843631765885340625], [-3110174033296696423768906, -1735844813564402758912, 1587341452754204096, 4119358413180444320], [-1132818665415854427639874, -245530999353415022552, -354819590343239680, -31124297280535589812], [3815118546863178259334932, 2344950088217393556744, -1665310165355621632, -3406296912608944420], [-6608962467000327729749658, 902729599011715017000, 590612856879953600, 6667658530744117100], [1861366922465114769304002, -1825268488481801218500, 897464019228654000, 59193574689606332250], [-12842931005939104336730406, 903047422623547402032, -6393334945022186880, 37954832276374704744], [15545184833103858215569379, 9111706838817004064022, 2248469138436981040, -86699786790368748155], [-17308158679165223650283714, -2046366027096742101888, 4079393959247569664, -92250760234737472960], [-5287443367906965586904718, 6199513005209254368900, 3611002151207810720, -255395673718312711330], [29001239264558033961655358, -11800715933036445145936, -9589961312700678400, -90001404627195581080], [-18162368963898182434552058, 10070697070164499981400, 12855056555111005120, 20164727855792796820], [34450861473906949569049431, 12800178693681125979238, -4189132322124206880, 380740289427137024133], [-23543843708077203519339418, 35044059919589310044896, 1780419683486168960, 23875568126397910352], [30228603809081946216413589, 14185018063842709916562, -5005768881127444960, 392182034270709038879], [-73931684299117126762716478, -3501625497197567497100, -39385305427506820480, 261615283633120764470], [96870982834962494439443314, 49975316875157049028912, -38469935124141760000, -456434549607925543000], [-151578061134137070646174134, -39658463763058181416072, 31893233637794405120, 97382040241205045732], [42811318265504669826449662, 18257686176965213807700, 36545135917092790960, 2277339197750523315310], [-90578193371886634043823590, -135770964729867973744240, -5615783118214986240, -33784196355194881032], [-319595627549524757360503023, 91485165767052703275226, -19545242999873190080, 639974028210865125451], [-28824296673616071597791810, -67469712682022714004640, -30482843712283229760, -3621767636123474910480], [198808242597851256972360938, -13135561251512064281456, 196442540848426265600, 2413758284316113866616], [-228627879487672696839586472, 251141271204107767615616, 43464419966800758112, -4206438070251327102320], [-96246391692452738776672519, 151431737036534112371858, -74699566446732823120, -2430889824423947759593], [349669596035737513558657230, -101905452639013285017840, -142697957498073015040, -5595425710479549036616], [-247278428912900936831165776, -624371978000112407021672, 213914582784681689296, -6640306983484635973460], [-55275491983945082643330889, 420090216705425174892718, -603995928682749021040, -2575312007795188451287], [-305105494313049191652761738, 440623561463499307505984, 268328158337483987968, 8723827646349889583200], [-612117917430653667857068918, -326931081626603016661544, 115039066545729919360, 2433922305247628435956], [-767122461420708262900595278, 146280428309075940692800, -1225885212037271647360, 916464866385919771040], [3445635322182593575686321958, -384501837914840137334504, -228019094035105450048, 6157304500263372414260], [-2199977579202403788022996404, -777445423815761531892448, -899714800496375861776, -10630907746650554238280], [-21869769423117647285516818, 757882680680938765740400, 543793763785587166720, -26980128586329531657080], [163230777634843592304594202, -1534901405180166407550700, 852327828195328039840, 5056139680275221083990], [-2523041505576716625831061514, 2248457868120980954558408, -216300246686546016000, 12473844362561854548348], [-1692256766771832580336673608, -1308237059045079500719136, -249235799590870253792, -31608469772720083656320], [-102979915238768184082175693, -1769705319053867764272034, 222878598374145477280, 50446331483136842880457], [1117511527247622902604176390, -984660448784254435332280, -416057240241042014400, 4340034687339220149660], [9165971717310499744419077434, -2514229322247193324471648, 186685628183189656320, 2155562533447578377904], [-553867443371702296822705498, -3923188900676647978516400, -1381693762057007792320, -37810228962654731136520], [2912935903121344034352869279, 360630329988267636810782, 883398717846683714000, 42754567014182365095185], [-4727109573449448273150141039, 192086072935600193622218, -2651503188212923213600, 56192329513597516925507], [-2330353883966513778041211796, 1877106143440469957332888, 4800652135255561697216, -83955129100812639451660], [18168213055911122690453274665, 1402955000506530261473250, 265081094723242766160, 11864185642094201546463], [9251577516848109729280405922, 3434573861250795160052700, 2003400230225638731760, 14582648142146375493610], [810514634236799758590238840, -5602145442803206887802600, -4228253025645357365520, -108097998007588809734820], [15851281480074130166472562423, -4782243415400158004585186, 2195928999539518440240, -55769159413090867123359], [21124951102301499053392611438, 3295968339270186617405056, 10328319136122513383872, -46623595014737022705440], [-9821988844395319501475144918, -13734380496465860663225600, -3659900157624349831680, -48917399455400321508480], [-4031608694731685608116606585, -3478853823163039972212570, 2762162483137606580000, -81141188039030114901691], [16189278725371468988519061862, -6716714136435048585829200, 16572714609440655999040, 93748674725346531626440], [10234204872415131275606787757, 11324337372305412489181346, -795709941414532096800, 260571589003473219801591], [7287614656192245069254171254, -6752103741567153749441488, 9016826705331242878720, 472762491669637626063784], [42310865335532050892328015019, 13547744929143560918342462, -12131138972448736754240, 241716580230904016291785], [-55173323793830425711648328234, -9921288430997136483281608, -22907512894893070354496, -350641113172661389433180], [36710967296185621049129346902, -9565909847138912297046300, -5706756891370786346640, 533071093662311279320710], [-27380682660486052572074939022, -2140610623530445689540256, -18886394109241964766080, 221601679262552011131280], [45459961405238453594548860125, 56985460131242272140304210, -16204216317563320720960, 443452930807539854506223], [-84362613283520738733355239998, 28498658082212531872963936, 4146535791172263344640, -750971768077689520262448], [-44012861821005267986503493460, 1473385473833857198090760, -58299149750789292960160, 301981667674079425675820], [76429871675643118039296456502, -58571605685638973674637000, -22803880959307869755200, 127274426454479537291300], [167000108258444854917493610309, -73605664380568301520576758, -24839792691087483903440, -73979456647750816789061], [112524113997781812349510727874, 5221741395120721980961752, -22061926795975491043840, 137053416737291974054580], [-17394581974757152250598814754, 33235507668699968771944808, 69620606710165221237760, -939787463986392005851988], [71015719917514372747108082056, -32289382009969563207898328, 26415723219495776050064, -330030965206047039541180], [51006631986884099968472048622, 102646486661527498555457100, -16432474267904557030720, -1635641635608841344495670], [-100559170614376403410428031018, 40083999382295625749866600, 78506483018062939014080, 133639282825156100706380], [104351565117473716326221084247, -122269815313206036210038474, 45290962025643556547520, -831802077500847780917523], [-312762588089896153142887587863, -104159537727665415568083294, 33549183969437985037520, -1465697334000147657811009], [-14961196057773858683554005982, 182383396962191837777819784, -148459802596686870617600, 725315075617957148443036], [74721113313192997047220800788, -109211940817852721099265904, 82818242522562857614512, -1591155360504952204334880], [318627035773926556176035661622, -17393497837026551909701600, -51182721379500884628480, -1374589685451971574683280], [167142074383889696776444581710, 32971382664741190126933400, -13737862411344281021440, 3294588848889861103771604], [-64850113656081672362201475582, -72840185022593288287206696, -68311133060228804259840, -2021556331837765579428300], [669607090753041112232240438631, -161327644091264222307025242, -63027775662497240216160, -264503037920820030363387], [53743505028142329372799645482, -281896937279466544939872900, -131871180157797672297520, 1078439964465014377407530], [-351275590699810585310749332138, -162948555162438676247527600, 46345773137838614712320, -1327657270703106869365480], [138878407165476426011052181518, 78633509771780594688836976, 75795999518688228661952, -6506128748055235240106200], [-260788165022937025179763071564, 469217205989643003175412232, 216419970665936275622784, 5205436312890870591483420], [370471848656784665566172582573, -121994036528919052830054966, 274618585295014864069200, 6611991249969552347268555], [878844730453893724581681224606, -204952062645886215033795552, -305296894612198436257920, 1117877926580452925846448], [178021861496153831817554909052, 211607547654799202314105344, 177319707104315036903408, 12504609674023459755774920], [-324865732187278803885033147433, -348605325783793585332080194, -391154662692710576438160, 10394224288665782990045937], [-935023877031361987235668071538, 101285220154162882184683900, -9890490887613412914080, -2442715975734811704593630], [-739506097139369069565469634746, -70247096712851353352931968, 40024007427477839319040, -9217341562637603012102336], [-696049943761388027315103082598, -87234117667492851448086400, 472666706309170240986880, 5588276205428356600367680], [-230486802148919281503971221014, -970394598868039387267287088, 61669276695975319924864, -4924710414283097876672360], [677802787420997851208869960730, -939501275639610219565035320, 245861598288860019169280, 6264897464970470269507964], [270930758575527938856131999905, 21033318854130698300852330, -732480557315546609947680, -8724204352501294206986637], [77034514240728678000665991762, -67946461863481244366142904, 1167572804757693309301760, -15715380629572394162598724], [-450740460096400958750943245942, 254913681672886331072119936, -1716633032836442115307008, -8287553959658104822006080], [2137981087557752413268344355842, 1045826362583819436730172700, 487304652136247326770160, 21184909542220293011112010], [-683583100618027750390478773538, -1259818607801029295178072400, -519474777098721471211520, -661417597693804193693720], [412965496483715552336674772715, 1344491591629223782932520070, 1261268410044189862297840, -9451132198267510196984531], [2633596508525205981318376988553, -535676775592091166836351606, 1551832158356066857030720, -7073641856382637361472845], [-496751162707464900554038828066, 184890530442204835931514848, 75674439312378326913536, 6109235381741366911076240], [-3196875383262114246828063513348, -758607872392907569520786296, -658231327926168171982432, 18986577423567008236086860], [-2333420708392792221976030679382, -1200437076188231539359494456, -19334153152153382730240, -24516126081254537695214724], [-728773331238575962623416929726, -919412399195764394577021808, 685506470231494516275840, -31547075802423820353562056], [2939831823761224319345750733308, -2649504412492634090754650384, -2376665721800187101756528, 30633532781474987799231040], [1267251036132368365303268362699, -52349103192021486676264298, -1059565929809952045000240, 34053190500557478004956405], [-99308565470487840636015932082, -286638013230121135252998176, -2805470634526504276091520, -9476762515471735134031920], [-4842345333600465196976403033058, -652285883702712901562794600, -386731801561772026534080, -60976840184343211389490380], [-4119570268241029626320051049709, -943555489847071174667559282, 80630651126968748397120, 73989357748917172051251873], [4779893708292736632740984257365, 1332432333585719138311603290, 1518029651180200979749200, 77617032994352607222717123], [9068798192768634698170326729989, -1919247346828565384288390878, -1895205867502043166827200, 5598567550230558372589319], [-3837525963635574759276536775018, -2304777042684506960495419700, -275585321183329621369760, 13080968229259836018584890], [-2701188790189322546396974334044, -1861317923238040942910778248, 2471812055347917499915744, -71140892212646278303979660], [5115857561015725893048495384294, 2642528901167188434679809608, -5982629558595671053326784, -43653530281469672368032100], [-1537221085689620262694219968090, -8728227321892615434777084680, 3523491220125742903902720, -23872217250634982389580892], [2898263129440664307622551582462, -570134371061969177388059200, 3412405104847014501765440, 98780998305701504160947840], [-7734796034434766994054314922443, -359878038017074819357421614, 2309148984152819606993440, 98793847054338652980157951], [8870353294244779504761859423338, -4946393466064333841769390176, 788962218036455504442880, -88725886087840983960624464], [-15835136266531685085086421207379, -503555492057442367176637782, 1566417699307802963602320, -24407969225351274622149573], [16186719188839201872523183767142, 1027828624300462945192139300, -2951321986926426962090960, 64197137500966725081933190], [-6399440952981403747077579694802, 6670456404893360126963288184, -7450467126075722299206400, -93505460898315307035768220], [-1092037007211776537430363473589, 4552720177254276094049092998, 623695280188832118269040, 110330563694353284265629933], [-2453119457175651109288601221218, -10084694804116036686390880900, -3533737655005724570311520, -63212212992710583458985470], [-24280481610369522383779334872478, 5918567498698238974535361816, 6927069041539008625878400, 71239934829465894366261076]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5_22_a_b();".
// 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_5_22_a_b(:prec:=4)
    chi := MakeCharacter_5_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(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_5_22_a_b();".
// 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_5_22_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,22,sign)));
    Vf := Kernel([<2,R![-4309053579264, 15642931840, -4542888, -2910, 1]>],Snew);
    return Vf;
end function;