
// Make newform 5.20.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_20_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_20_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 := [10870990650, -26738538, -323561, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-1034892417, 10576678, 12712, -50], [-2087927994, 57439676, 25424, -100], [43256659674, 120441404, -224584, -340]];
    Rf_basisdens := [1, 1360737, 453579, 194391];
    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 := 20;
    raw_aps := [[-105, -1, 0, 0], [770, 14, -1, 0], [-1953125, 0, 0, 0], [53505350, -49970, -81, -720], [2896428192, 1619940, -77230, 40240], [3703083290, 11351688, 1026500, -19040], [212258435610, -121164168, -7550788, 1498720], [494541927140, 1219060368, 13782296, -6204944], [-6642476738190, 4000888282, -123482299, -14097200], [29066793584910, 37650049232, 1412036264, -102722816], [62762418097172, 143885209220, 1856329010, 396745120], [13367914429130, -243628254544, -12933056552, -2445430720], [1401555474487062, 712181442920, -23031632140, -4324587680], [981048278190650, -2731979985890, 21833437543, -766535200], [2493111081747390, -1921361759922, 43968973391, -14751076400], [-1865569067700030, -15326779667656, -31983718116, 67159889760], [46538735490709620, 12678949138904, 1608356028, 42781997328], [62129398277661242, 36325386740800, -360031877600, -98525459200], [-20994236520169090, -100961063907158, -4551579249123, 520771602720], [-81713627050007268, -165342580099100, 12014191896450, 563398838400], [176517759515566610, 114653489212472, -8035911594084, 533085805920], [325058972626185560, -916151083256168, 25529181697644, 518296355904], [-223679067331191270, -302602901639754, 35028167349747, -3909329328000], [-1098182629867912470, 2022193747562256, -37763877572088, 19031306062272], [359467624487945090, 2690599733940328, -33285019698124, -217413745760], [-3908636674219559298, -1423690425647120, 62125785178040, -9092016427520], [-5699025745487188630, -2119158272121406, 40910223760729, 62338447292240], [6982565477341953750, 8478111779008730, 127196694400789, 48025404776960], [12672660606068569370, -20525100772966736, -11027975916712, -53221955945792], [-9751396812196737510, 7888532671694928, -149772687294040, -5884458904640], [51376471521891886070, 33258343158886054, 969350709369115, 156286074110480], [38813006979159682272, 13336325678174940, -824575165631730, -648391222067760], [-25639607830104800670, 45483924153082336, 2912140277245808, -269247939234560], [100420623163598435780, -89565893152448184, 7500647813035572, 678328161441552], [56530608320153491650, -453458060598003280, 765825983408600, -1711806200429120], [-3003130071728449348, 207915871465399780, 996254447583490, -2447646703429120], [-103244225596860385150, -411125175799076080, -9217458208804856, -1582053174621760], [162724207982379321290, -184647650806279082, 27934615675071875, 3348862477708480], [-202182079350189150090, 373814277126601102, 42426281443445327, -2695165658535440], [-340269369236640376590, 1412126506593044272, 2261178290412056, -1322265990941120], [1280733875863913924460, 768514851050792, -59879023434339516, 6760207164872304], [-2561722897562589144178, 455453238758314400, 4115223972845200, -54301413217600], [2537248692931292862012, -4214869180971682820, 58506705699098190, -1579167046986720], [-1083028623463365826150, -4429005567086116040, -97984912502719972, 753645029753440], [3433230707185949419290, -2494765530404421992, 156302859083407436, 7273537254210400], [214642779655364682200, 2283973063759408960, -107457945434211200, 9192575673623840], [3262732980177809073392, 11162436913537180, -201302315111353810, 23018983880475280], [-5881740980843197112590, -15721683243770889918, -324999641241422919, 65254466281471920], [15010590323553069454470, 8844674290747429554, -403201547056214015, -16882432571028640], [3428368663930653751910, 18324704424671507072, 506629748205778304, 54661756531770304], [-25683810315859684934070, 10486103623470190696, 105083694331002932, 25777220804263840], [17020845711290809858680, 28061844742579323576, 1058504936209334012, -103250586254080448], [-2364263708227082876338, -40759260823767473400, -874692713299584700, -101753033861866400], [24631074085402053454752, 1496232195202564500, -923670755098449750, 190444354795494000], [20339242147002183502650, 59893261322593866960, -944299442553537816, 217922162089671360], [29021932678450191908490, 39027734244992413458, -987784696466342015, 183019989086289680], [-19816725117044658317910, 6617806052079768288, 2217027456056211056, -491381981567345024], [100309776464920287152732, 36733390899747944220, 397538609364476510, 422645409408025120], [43707398456310439251170, -51810785365339639696, 3230770767784644920, 448993106240324800], [32742045926717974426422, 189766402675728444920, -3086919298948035140, 197326792632108320], [-172881220771972642673470, 24708231876144493366, 2825827599777397587, 44083779030217440], [-273714118729061076408150, 56755726696497568480, 1893718773141241328, -437959117432090880], [-27591811065428255356450, 132552038897330847930, -3971345262209412571, 999615490522657120], [98634127270292065702692, 74157638651765286220, 9330732889599983510, -291340758102178880], [-89400933827337476420710, 224861611170238261648, -8544276926931187000, -1440283626670040000], [-58257525598405083974190, 58586720474254950632, -5379159100186988428, -1250281808144889440], [201168228418494871917272, -438729380555148253140, 8730140589635860630, -1897197641825951440], [423461114775500076992930, 57547597518217621616, -29068655040601184712, -4505111326618105920], [-270645357970878953340210, 124010024811175212898, 30803328208849299961, -1962582636858701440], [847139649020089732706750, -520916145592592901280, 2744891547687348720, 3140238913785802560], [936614884209995589173970, -272880210221632336496, -43393237411560508216, 6049258044508763200], [-1170853574476571285074680, -249364215178953241216, -18806122018500021152, -4481104804865882272], [-518789251393272993175090, -38664729346636692178, -13025559086516220673, 15811315765010231440], [-1002724735028144521341790, -2376602698171273157808, -14863383346323100504, -3305591050851654080], [-1228215047772918287960740, 3215316391028578960912, -23593008562804513736, 6549473392390972304], [-2415392653523515700893470, -1684077506149445457614, 59044889974962090737, 950025378530601520], [-292246513352318649301470, -1310322029423754973984, 95975514919117417072, 677966917041940352], [1402221291561697383915290, 3620995838287433102728, 68470345238923655236, 6339866354906360480], [-1937529303153885112447998, -3104135178529744506560, -16716125224667872480, 10784987388311578240], [-2637136732708171244022130, 703920343032096402424, 211720759398271484348, 6778648123919507488], [-252909788919140937894660, -4092698264538957788632, -199943275346205498364, 6381108871466848816], [2307807540540095159614082, -3512117633971607587280, -89773565866273451240, 30924730556297213120], [-6857041617043982771879028, 1498781091380338048940, 377974404590396215270, 24942208759758206240], [10193355155421749929760930, 4041612255541391989736, 147496568422829055732, 26595255211831332000], [14252730452651923444869080, -969486636153222210944, 88859428928995639072, -40524738957427864288], [2188094024816379411439050, -4914532788039612488770, 49559947970059766263, 56070930751291168160], [-1439412306400276228071450, -4744499268807246595480, 171714572279716152180, 24159232734665359200], [-4541325743572966499008150, 17671464744595367840000, -37546295061649904256, -39889356401133047040], [-9767227248755895522528858, 15694452268803100258480, -302251891590523197160, -50834402560666449920], [24423466350978761147072090, 8031298258303949287658, 77621930256551510765, -19789360082125418000], [5806233025840901117098110, 17632221590693610190202, 95813019550918376837, -81766507418156016800], [-14015987023653106211852040, -13064053037959233272648, 51085631369613800444, -11244085642793633216], [32518572286854904011162830, -23529013135881713183754, 431850532202253528483, 60548029366396487280], [-2758873661637898747819488, -335712787445350268940, 147070349375691264730, 132235972538063083760], [6864761607139273322473700, -37339309659371787009280, -524005360060668955440, -99449611871948233680], [-16216873918742117249201430, 14359419849676676342194, -1360527399090098289711, -74125716708021502320], [-10887045596635558012698930, 18589160074347637603264, 608548023833820855328, -321819254635889703232], [-13425908060054011653166518, -17522645600106398343680, 826480710355106146560, -102925206217682465280], [31925298487567708353299810, 23348079230897387194182, -899862094987567562149, 353482369498908052000], [45801855331349749340542262, -3739463595880117595760, 142011894795282038920, 421433949434955175040], [33342303510899012753420390, 5901622381647529468178, -1653418375163814202959, -446207918784796586400], [-23431791586368080094284550, -8272398035720328668080, -2120846863325584578776, 417572787319681924160], [-79500664049085003296898510, -72124570785816413524882, -3618391523530009851665, -204233643451468982080], [-112107820242525050666610, 145945521130961302867928, -1014727255847975759444, 601661789866556344736], [87282776449670210822431832, -57697777633797335053140, 2488534612819968156630, 44405729763968512560], [74257493549773986014918570, -43864646625858519095776, -1427346815136472795760, -140464997804930659840], [-11916032868534757954288170, 74769850910598846385306, 2097121608639216962933, -391265624128864887680], [-128339108842070110198639950, 89897653310260175412160, -1431197461260302471712, -912874491159142129920], [-173149757694035637307992000, 66140565295967346634520, 4461573605354316963020, -718439319995425315040], [135775603829869167810996902, -63954288652279781580200, -733788455309501070100, -111415382363244783200], [-84893365296464095013996050, 27934564874265911788750, 1488169776931610920399, 1294036177461803697680], [89160920325634133240942090, 81151062978801649298088, 11348594373229657350740, 95490049527857314720], [-6179064949576544598059190, -26964299716687761151288, -2233112316090617142428, 2175345346148128942880], [-89192356690456500324650260, 16795015488130842607648, -2188027277160403976704, 10992915170281954576], [-130871530139940874065487828, 233417043554610167680980, -7067375541970730067910, 4350306577457822080], [620415941648552713662802062, -103416193155599293918520, 4531701786808603234340, 519547316993901098080], [-12204230179703799901420750, -10587363884673635620610, -8967329090936954117577, 352349285935854781440], [117693532057516707805990590, -196118115563834418978042, 1286641055117183660651, -1293480498214281322640], [-304541747777625537607910430, -93197508423212705061576, -162417069820670542436, 4074766817228526072800], [338922537802441931784169020, -488749622280966358382536, -1473153094325204194932, -222646012951178925072], [-65625142207043676974246158, 58260135467119812074720, -4840659802646418276240, -2122859094752380298880], [-98023528379554972149318190, -210075326739001847974888, 10108416742738715953676, -4376220376815924286880], [-27509010124512519693726630, -449787280360571069591736, 17265553665897193993380, -488390979674317732320], [683762547318094062240704730, 595320935337347468727966, 11547252046411716561447, -2146390926024886741920], [89115143696383558868823512, -160730320737265808074620, -16264456416753963635710, 3258912364670800582480], [-604454675077466493514576998, 90348861121668772508720, 45013915283388428596760, 87987762513281149120], [289191732086635733630758070, 25203754742190906711504, -11179130106080980470232, -2908244128339786982912], [713245038528056138799256440, -614295928846180331233512, -19289940320948893933524, 4763439645300399166656], [-1473338844776474354457465130, 75722207293620688569294, -1503904872529201414545, -4504664597871769232400], [-679711972597398854598751870, 245930789182128088761216, 20151601635185668003392, 2572079710479310488960], [677672141930956247594768780, 1853368880448498830670936, -894552585920301494308, -230238940510969012688], [-98902585145617555894359150, -1416509484609655737886630, -32975750384549051975547, 4537347077451148662480], [-396806918835957007708277548, -458529435217595442425180, 52032731458247548735810, -12965986898237303949280], [-176572208214180783767356750, -354043973070959857266080, 18125869440823289257264, 3527698458371537141120], [-360515281791647605199365158, 290739357814101337647680, 61110055795458492113440, 4784156459002754401280], [-2341590906876879841107702910, 1026295082425784914031888, 1631391692037603419656, 14788409778419939907776], [-83530983110944064141701590, -159848485341722697772808, -54169714185978292775044, -6201448656392337969440], [889275069648968078185351430, 1607076791027696146361186, -43080512156896281061287, 9490735105282574038560], [-426258774465697041557837310, -1187771048725074227936392, -28920815884081408453444, -15869025869214891756320], [1616935800285213792766386570, -2224445398325173287589376, 136299714255294949663488, 15008776294345793653248], [539456704814909343282652592, -3068467276642425774169740, -13360232943775367077670, -8273197121531700777040], [417254225800597005773355282, 1155226502459626019318480, 48947066013050070868840, -7309467592915782665920], [233064705158362655461448210, -1115314730515888791414118, 121126268631685532304421, 12473918795087253561680], [-349312849078046386329810930, -1755728914751936645571326, -19614814964783725991735, 6208628533079048514560], [-2426657230113911542728827590, -1466055327324644741646208, 99490530418551121769024, -9890041243573641307136], [-3403707154534065500005699920, 2183113505551414668618536, -59430089147991535143148, -4565294742573310862048], [-2181744610573390721591633830, 1894352619389386303912024, -98394388868462713260756, 3767366302375348468320], [4291500178525484867155118850, 2628536314212359715205040, -179137355408077405087656, 6348204486310899539520], [575365997973530922352153220, -3331390573072112224187576, -265720106486281193942732, -257657785535029499632], [-6298848667953498109140602910, 851627628748892513875138, 222178701009489266759865, -45548173821810990472080], [2706026533654951138478721170, 5755238713676727779872864, -255423405057715961632080, 42456438096314698679040], [7299229502553125891216811822, 3080491518157783393721720, 87961672475036199115260, -47431682164244336534880], [-5869499455192511131038988270, 1781811417265377876868206, -43706353462718235243153, 42373204832885747173440], [-4850934830992315774640934570, 6087634517648563212171246, 158518612126769560257663, -16158729730525559744400], [8949005548337009127504525950, 3739005918072049671503330, 42377207518956648752249, -3288639576795539633600], [-4965107493457062161318019708, -4909413183077804898444860, -176076044806034248811630, 9386765656845490665440], [-7951922900018394738795973360, -5790666006159256078392152, -256240226494543076887724, 8039313866371268360096], [-1686744921993970675508036490, -2615528385563036954293528, -560286227612605374892876, -7934360879816425459616], [12425091105004877262103286330, 2277985465303830279841816, -219623587799817077743092, 56017509468844088945760], [-1344667289504348090340384138, -10665852153292274014999360, 56439226448975956409120, 19013395532727018725440], [-9625380861007745368509401010, -6466092560791659311277622, -490079742463465970920979, -22012591315110326834080], [-268144908622595386642582230, 7282573077429726621272704, 561674587767895155145024, 69512661980051404060160], [-13696340894704551990611684290, 17472875182956350902103862, 159447964963329722043267, 38275135073519633402160], [14704840644751448219346362232, 3155331497306026320914540, -716717373802666308137930, 20640081673688975921840], [-4501407811963679893430991630, -16806601755135339878940456, -78489460480228140521620, -53559333398804219511200], [-20754857565003669537128123670, -5053888999343809875065214, -308115168795390234017223, 93686510138911625814480], [-14877624068582193015179351788, -24306558469342691426708620, 120245911801074049301290, -19259951464438053375520], [23926410535215267528066113090, -14886980524995151927943832, -93693221834178462091724, -173846907873705367160800]];
    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_20_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_20_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, 20));
    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_20_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_20_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,20,sign)));
    Vf := Kernel([<2,R![237314973696, -746347520, -2002872, 420, 1]>],Snew);
    return Vf;
end function;