
// Make newform 25.38.b.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_25_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_25_b_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_25_38_b_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_25_38_b_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 := [253904465984400, 0, 31868761, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 191212564, 0, 4], [0, 79671905, 0, 5], [76485026400, 0, 4800, 0]];
    Rf_basisdens := [1, 1327865, 1593438, 1];
    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_25_b();"
function MakeCharacter_25_b()
    N := 25;
    order := 2;
    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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_25_b_Hecke();"
function MakeCharacter_25_b_Hecke(Kf)
    N := 25;
    order := 2;
    char_gens := [2];
    char_values := [[-1, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, 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+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 := 38;
    raw_aps := [[0, 1, -1944, 0], [0, 72, -139914, 0], [0, 0, 0, 0], [0, 9650004336, -34484439534860, 0], [-13367018177424269028, 0, 0, -643726129420], [0, -724443400725408, -5305817416539331783, 0], [0, 24633489938571456, -894390738819317673327, 0], [-186638233286256856853060, 0, 0, -25859523645743148], [0, -34024622863285905488, 262411801499338819454628, 0], [635336913562941208975814610, 0, 0, 46166393183925012208], [130710409895709447740772512, 0, 0, 129282893368575510240], [0, -251014973543177117121504, -680253637938207865887332381, 0], [-630241647733186566987342420918, 0, 0, 11646939679707049762240], [0, 4277308746306872497542552, 25702410231579188311695816050, 0], [0, 3802403479056906286688416, 42522068755689340251584075832, 0], [0, 115415105640300817180680672, -1597997362585908100715056788939, 0], [118981229803045064379449684850420, 0, 0, 9638769640809562154925116], [50899420686519350100053127599822, 0, 0, 57996147933406932600891600], [0, 7835678640912228686313856056, -108919232809813581086438093525462, 0], [-373066544896916246344981079434008, 0, 0, 348387247960267224822367800], [0, -1181005639005244198519101888, -196398516764964260239093825074877, 0], [-136200819017047919517823972572337040, 0, 0, 816971035001524657242324048], [0, 238689899875563369340619699432, 4704602753909099293087462176010734, 0], [666434460855619058957171989397471430, 0, 0, 46695731045296421710420559904], [0, -10627502949105201678203260881984, 60020618884732299730391300906612377, 0], [-91707626645345800863644808706568298, 0, 0, 680760978509120684301578143760], [0, 34855177292978739353526575464272, -199224601231822440084972117490017124, 0], [0, -24630885537760682931284731165464, -128438350618495756799687924728700370, 0], [-14742270277170567272447122138170903230, 0, 0, 825175608358809891564211864176], [0, 33638501497340241518252258401792, -586153392016082696636464970881494273, 0], [0, -3289457630565276475754186411514624, -3279934291241602052805214097700949184, 0], [-124420461956238631186326717911276635788, 0, 0, 117160184403357881339392382897980], [0, -4972831159552869876416994180466304, 12941865119149456801424435121493234269, 0], [4759621368973495193091217082436338119780, 0, 0, -85068552080015147916046706562036], [249841683235389768135250916187744061050, 0, 0, -169123392645947919949083249042640], [-10728911655260345880462030843215974701448, 0, 0, 190968394872421001732744565763560], [0, 42122105812184531133039114724703136, 1086517494836912898324172207713999612655, 0], [0, 8749675600328076043746913999168392, 1566337225992669930781583016406734264422, 0], [0, 193697247188398911418946617384606256, -2272603640074578041922956027345504141052, 0], [0, 48101375114138767438848143664233312, -5599980589301281845943118214815056114647, 0], [37810903209132004035276423138418913685660, 0, 0, 20044718602563651551504091380079348], [155270915925568798266431818187464446465062, 0, 0, -13068332219880162882463916527009200], [-839093341221447109534687693809308265442368, 0, 0, 30148051927143667499580699843728960], [0, -860248229006850253624081353087027648, 19134579923161631244774537687661111656695, 0], [0, -2842998218230359975951074475127730784, -14426697350498063287009942513453068988173, 0], [-1371266102267262206151889179938110610378600, 0, 0, 91301448644344764839379315221169480], [4548965279634817580411184864932522934266372, 0, 0, 633035887366261778195130030100321260], [0, 99220018078677348789303246474159294912, -40278732200819271028156031313615177902512, 0], [0, 37444620854825526912141989750639107576, 1065628821484183327504550789122268499630906, 0], [42070960264233534237660149427725297543532010, 0, 0, 462366168041742235708313883736924848], [0, -127220432406495965832058295015287416768, 616297192608628478649553418826981541302579, 0], [85468140709266816414188944322109576470790480, 0, 0, -2963017081587548375064485699810353936], [18192999400938027932597492880260557299810482, 0, 0, -6808155239433570502404051974132272800], [-108939635554992345163876152182187829415165748, 0, 0, -15309446256700372688536905409261429500], [0, 1089945608651225293053025340361565454336, 2505776200894323550913136778893021465760425, 0], [0, 509983553329824807139775248804498600592, 12054977650403918133983383840083836536571532, 0], [814129787359426984131324047703842969484870690, 0, 0, 10843081457004479148256449314598174192], [-1044912111029848919348102104838755291947026608, 0, 0, 40803096275549272214088715621718342640], [0, -946184079597928885992880901062475833824, 39428218846824185622928004207140267820067451, 0], [930494707912263029825086293557596574332416762, 0, 0, 100824996381234555233852944377556588640], [0, -4611698165134634212898942105492618124168, 19395535180584980825842574252132255773775834, 0], [0, 727174556182904462978289624176302483552, -15917187900479927536241578784484102879668835, 0], [0, 30946134082429563977624493122675898894936, -45355000648612121941801112526425117174377790, 0], [3528365581751252566153684843366461346824306072, 0, 0, -448155916364531923831827247325181419960], [0, 4637147526657978442323321860570017752192, -138032543988225762029673066715149833773116373, 0], [0, 2596769169935028400888684619724904865056, -448931098598737648657261595404158738927443457, 0], [34823141392177444385510184742601101647451595612, 0, 0, -850474237427943693905795152475795650380], [0, -150408530451038299821871579770962048027904, -693128578804119556398806328455936291920698191, 0], [0, 40555525250542114081543897046784591019016, -1365324533679337876495187128529954405882931258, 0], [-115486318943554292273239717792808744909220733550, 0, 0, 958145492591164901058619297788101527920], [0, -207408174535694531123968820218918288553728, -1877878360182507327422151104460015624131496729, 0], [23672250349918773626108648128927624129750790520, 0, 0, 4665958195229064638622427546097269251816], [0, -396913847325049763430251049533447114533344, 1293905273865490978698832536733561965681838168, 0], [0, -29479819110552147614675847315895623168288, -5176508442152835123574528822034227495145863147, 0], [155385596592869841837558799306786991575677691060, 0, 0, 13471525995099568989767376389282363700348], [0, -727726931495180416209180310743868361331968, 18860099854251888847880172043095536633363863104, 0], [558373926767190320082359062565474571054900451530, 0, 0, -31616313809399143766201705872403124737936], [0, 2527153640103141298488044040605389332995616, -7356825725418832021601929996770541058654386553, 0], [-338080762430626629596588831991139095213992241198, 0, 0, -30901337845871056660964736249972311177120], [799160624867255553525605557596674934981249844870, 0, 0, -28116275832281871641966131698113948278464], [920080641223971375439095453567657730603270741740, 0, 0, 156700462177315879931728417073741228735972], [-4145805779264492786427386086008332152383987990058, 0, 0, 14403428488942032656295139211360942066640], [3175832997215056446498667861332567481681230963312, 0, 0, -10224761597636708353333653203269546649520], [0, 5981823448328076295627124341822973627917632, -1669360328068687822106309267758480045224110881, 0], [6871110685274422640899826023441749309755804667880, 0, 0, 237537289902781315233891370752972507708984], [0, -31318250385633154498804450440960115101976648, 64316821751326351665823702780885368768030353610, 0], [-5164413354345105790263549798611982087363343430850, 0, 0, 736602247960556394639981280031936168416800], [0, -10682585905706579608216395851833141356699264, 157417207223344383281374776703708456376024476285, 0], [-9478318108785424245714626333802602601688981089378, 0, 0, 959084536077049292200151791368169595609360], [0, 29161823015282167281256254695473185958072992, 447342805966776713835978393862137683970294011192, 0], [0, -26652624059239287958985532567818678138535144, -530768116306520708977406436086795347508650689582, 0], [-36851915907522432911475410352652170442810944678240, 0, 0, -547297004070734316252286426782382952098592], [0, 111971597779345138569531913462648777841278896, -698717087670494879389491015986248269858928523996, 0], [67256677951400028937737458855014395394112653380732, 0, 0, -1632077818324487803599481700083644909539180], [-102587478702326392004154227298396222448526930094500, 0, 0, 1187345341905867454796657419408921208684340], [0, -227332989822443591701052777458060792541366928, 478059874269257058189125918868640107798089236596, 0], [140645117596974772260107687472668073447703109139570, 0, 0, 95594208549005390037425414417693871813296], [-57568072300716044765517915192865681067298815222358, 0, 0, 9201340810674852511439904313700160584571840], [0, -256964032974894551946090013877537675043544488, 636260443987313972610008044648570101444960576578, 0], [100189239957738074903442812767570951588865358209582, 0, 0, 32956325965849665009901645770723891121859280], [0, 346337716380048213705224723752116644223799416, 1158948897566671028965508484870020887679749211482, 0], [0, 415072444286416743427961253295732269726123936, 10391125604110325879165604418878666117967491525015, 0], [0, -1355732703079566778330145263908651505774366808, -2509554281405851290163520272119579547776300302658, 0], [-76741102467515438078900489321815149536886417069210, 0, 0, -9990667901910841777980838400051668083889088], [568447727128469159474768635384134436770496343540492, 0, 0, -47670463543875259934689980479122078645461180], [0, -1644542621102756377732177772589284189993044224, 17657115241233776874212719513972855642906930101961, 0], [0, 344107647344760973591098195353437156606861096, 20093260233374675311430734405242121235867596286814, 0], [0, 1672710914050629190633369513949054153649265152, 11902692207430032973800063992781328208835476241615, 0], [3351729963147473396944773645506741442866617731328200, 0, 0, 64848649033774963535967356022890580598421720], [-1240388252780259577144015090370377902575677538137798, 0, 0, 63961928260071214214638244135726941037637600], [0, 9048645605802788718876137367087683030546953536, -17357282392042791175954306918579249401540147240080, 0], [0, -1971156758985521309182509980529593921365058208, 12119883434586773169409461777454321547378900220797, 0], [0, -13152793578315023497255332570479074441513409344, -25210043030286636101300912152486336043166983712627, 0], [-3317392268540954573001294287429713301729735431812860, 0, 0, -138885669632734038627315793609669437557154708], [12127864978005105477371057117944951898572243786712, 0, 0, -166082349148103814991153358473133681704782840], [-1641051088740564695715733791954026420327047673294718, 0, 0, 687106047467751360020434120720856898006030560], [0, -12869087353445438593247468307163621890396856248, -235032286565813782428254496642317768467626947870410, 0], [0, -18684386058808804946349920745089140113737514384, -191860755898152129502073097008430604435002833777868, 0], [0, 19485887473833376760801467649595423307043675872, 30874700296272094454963597874529899697576233227001, 0], [-10996304677107299759552101063889074492597897850269380, 0, 0, -429109192094310924229480300733748011583939884], [7130502367829663388777669511380754340901181966726022, 0, 0, -430789878750411869621290627687918346381142960], [0, -9040890955008358348325766239421816836137994688, -52196161062902665793445175770204783494511377609017, 0], [0, 94939609962175208132681690399480301746695698976, 60380757501105745883989424168854327161896939600931, 0], [0, 71294476941591413394625340635105587836504212632, -136336298197560980646095555318327828759483363530446, 0], [31951340751563027408719274956067182775272142594636132, 0, 0, -1425856629454459071296531834818419438013393140], [17282239553228651670167345115551418513297129440557902, 0, 0, -1233023677524659410328905452319080590526400560], [80752727796686265215911814552809997087318737689144970, 0, 0, -190955606309590487708325385409338116635454864], [-12024070257638893062348301009443393433180424025350160, 0, 0, -2099033663802582129287805291720855556458489648], [0, -253563732627312824902769008720284949873091525424, -546518944715372976946424459802969575240859238279364, 0], [0, 60950617137841374827332411894215804957806507232, -241886551254548511823890444711538397534876569119631, 0], [-61240940827831838092522396379929002059663346885000020, 0, 0, 4720505482991087488302055506026931780732440484], [0, 154105085815191722049532783656488928892833423952, -1876931358987056363825406139769844984955034481523620, 0], [148890569120252021008471107909519478599219426996504752, 0, 0, 329956741474076521374291690530038506952442640], [0, 367660389467756071102949778012632559882967794336, -2837839170523545245294661935527976968093128799198805, 0], [-178097573169665893347639962230751846923484620566202278, 0, 0, -11232765585879596692630218854541094562297522240], [-184903100394764391806643174414677409665342427759575810, 0, 0, -12860719661581110248244944680628324261096714208], [0, -551118707731260709147211998709542120449005587488, 349226137596221710704020120248576688742431191499373, 0], [0, -112109069786192571251640896588983099990570470504, 552351804392726571154120454916288548583528242093554, 0], [0, 1919040195170162454822162319664368210082905344416, -3063365116783927365478760718207124727313071297972433, 0], [-550957227288081151543562412378942063933515446938432330, 0, 0, -9327765818857668392530913930563852214809642944], [-700413436876002860502886440564583396102032639992111428, 0, 0, -5411932208891307686706885236333838485833083180], [38391234551943421167537816948702058321373612529176742, 0, 0, -2561430169273245345328876469159941048585216240], [0, -656347956550118524366425905799894516403795983888, -26057478903355781835695869092701851812455259909385132, 0], [0, -1792966031163262534581624881805212472242320471224, -16831363981709498615790767650666767602018436912859914, 0], [-359246268835988321133365376537721526980144533247075790, 0, 0, -4661258870553133024113920814321460679628074832], [-362517442034535131140152793963326000533257248116665320, 0, 0, 108054089985650305854397798242549450692854571464], [0, 2586167572461521071959741148732006575597795490272, 634583320801433795007823659693454323035353267551461, 0], [0, 48828594424874112128009721732959109692552177536, 1092937596747028297000837181647240142543191852796325, 0], [-1159433532395461463053594106965249755758618589462711980, 0, 0, -15858231654648467014133538801923129421335703204], [0, -1218708939505098163662977283352326383478281510208, -40551923792151110072633919359610607346710719015852528, 0], [0, 9659669477128281186910114430090384789538497753376, 6580076381355585580325078031139029516490620420752311, 0], [-327110530419209426630739473007267599215027820985145038, 0, 0, -104497663052991641935695650485942601759944709760], [0, 5756311402103173163338057445685075485144449237032, 15717387099805406897153368595197860368990911110030494, 0], [0, 4382653538707950081404639582311651246843447991696, 73364546983890113417435051145401186031056825978540364, 0], [0, -111429626755782840738246907233358158692829963864, -128154712971584636805352034543975226771279137932664450, 0], [2875914911321145211167266417148476982657908697887032272, 0, 0, -3303925130088900349822707044759201153974245520], [1034903723119349727312713848245429985388313468013423240, 0, 0, -341499474427018284138517343393018010159997300968], [-5180364872660200697365372046203975860915442901710701090, 0, 0, -236178441315007423663934537669481098769794343392], [0, -233929610116362360292555253252110741765044208704, -79312188651073316842927573381933148648770564897767251, 0], [-4648326435949025984098579342749034761191383031998863618, 0, 0, 480868095333312004336018949656195927993317608080], [0, -21346127408689521414616572223584598723700940463784, -181333690370282868923260705902212008607294211705493758, 0], [0, 25285493768492767280238852878235506344384300409472, -195055177911991847116439062481565444008761422475926549, 0], [0, -31324028165912261021498555477372214500096106480144, -106598797933735869459167379094436035610271974963876012, 0], [5209870028254085897075129472832062004851058576822499292, 0, 0, 273943403830395234957022693285278460848542956980], [0, -13057287149035028044055740391795130097301613807424, -230056277822025424461726470927739737898952169446074639, 0], [0, -31726026381006904867871027143593537162328540546768, -521308576158905019894208464934334579860150310782160316, 0], [45112689871561262570484702316789753502609976878011232, 0, 0, -2233062187617236791623463156354601849657688860640], [0, -1949256049744784270980808617691663203344419273184, -664560599564725755842426071263299655737121921993331133, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_25_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_25_38_b_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_25_38_b_a(:prec:=4)
    chi := MakeCharacter_25_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 38));
    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_25_38_b_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_25_38_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_25_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,38,sign)));
    Vf := Kernel([<2,R![18879696635540281491456, 0, 312598176768, 0, 1]>],Snew);
    return Vf;
end function;