
// Make newform 80.20.a.b in Magma, downloaded from the LMFDB on 06 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_80_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_80_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_80_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_80_a();"
function MakeCharacter_80_a()
    N := 80;
    order := 1;
    char_gens := [31, 21, 17];
    v := [1, 1, 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_80_a_Hecke(Kf)
    return MakeCharacter_80_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]];
    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 := [[0], [-24642], [-1953125], [171901114], [11873833248], [35971967642], [-746262181734], [-2682185926820], [-15924407922], [-106190769937650], [158223244950508], [-80246066291254], [1895936900328342], [-3278663887209722], [-1296653846339646], [12483704389153602], [110746676451060300], [-17892488585662918], [-53295728410967486], [-406846488659414172], [-599276103913841518], [183795029900265640], [897306592327000998], [498699120872108010], [-1088346985506567934], [-12478324190566815618], [-4367651796170335082], [-8277140480236855446], [3327018418575082010], [-2246049902740415718], [77701579546097710474], [195142476773093790048], [57774041347821111906], [-278266733243324175620], [99394466254432973250], [229015969858806020548], [-1187243889614179506814], [1018524098077395193078], [-657821966384370752886], [-1666937444180987444238], [-715711554153464989740], [3507453997108433420942], [1138046884037185444548], [-6613681908307268265958], [-9194880195124553237094], [-11229325264826264469080], [-11750848568689143234992], [16987976745871148288398], [29737648044968247124794], [-40903034748273625622170], [-14396696105046285732918], [1338692847627483064200], [445806747877866426062], [-64962579056515087357152], [55045091649893934752826], [150720796113631894392438], [24656737477053846004650], [-119460783398572224626012], [-264148655440183269512734], [129519759558018366346422], [-158388962848931146765442], [-231546928291056597321558], [-627409252856874654469406], [-194000878541973559848612], [-532020852400625252797798], [-353503368008474591984814], [417531771025722826043368], [240223487718233007256226], [-389549181696428831331726], [-1584666714047087482580290], [2445090777280225936296402], [589119279611496915375480], [2110544787259433952109234], [3055109149845281262406562], [-3602757597229836502233500], [-1734442156474441567888482], [-4066491080378315621976030], [-3090958660199425144214374], [3676609385024779019230722], [6365437810453197599302670], [-635539002036146029438140], [-10884006785676800783368318], [-13564935842751287691999372], [3296532019724092164264482], [964911088890695388750760], [-8917962200638879473402762], [11685219294504619657049190], [19863217042719194357689706], [-18347371455582261691296858], [-5054602686070494492474842], [31874013373864775796200514], [-35009837674177440317251320], [15749792189123659958146354], [3701428856392716436663968], [-69298119691629062324572580], [26293171604592851535497238], [27686125373788194237063630], [-113503146894946675075784118], [-38159929672867995926622242], [57486517513150956095061302], [-56546644535978748016568486], [-164938186772943144515017734], [-125673851413748045643007602], [189078782208705369857157390], [-220726151861650206942516632], [217792747564221598617889706], [-118966033139069345182300566], [-159826780680072204914837838], [343040670214751682492002880], [84310011827298180786061862], [296321651741089897882493074], [-249098004059089819590374518], [-281111095130965732735852854], [-354941067078900989634337580], [-445381004889363627109285292], [-795345443430973268510788338], [579550908376828275002209678], [-130893574813189009557126846], [44163823294763902993199202], [-431537137052057390971396860], [281428355633731364208414962], [-1088626403071856073619742638], [672260637664276286284427226], [-1319345819310076501217017242], [530732599702126433100426088], [721166482936488072929681562], [-1986884121140132509597220170], [659752540618149963394986120], [-921607238962128314759134166], [2553172179327596474096856962], [-861253890455346280142965580], [-1778188919994182444574570642], [784063728246937888953453868], [-2378438563087600921555069774], [-210930192555284408795560998], [-4280074786740541476543810430], [2453883721548178419617224362], [-2509188167765863524758888006], [-1619209677871788391163282814], [-7945900274253200592240522870], [-2916730947076244475136800752], [4623331146603066161736797202], [6192388691782883307132802798], [4544950091690115857972264754], [1991461986894323992785878330], [-3768284888078697161414410800], [4424889889572708530387342042], [276061709824840201426322946], [3050080471721024028809643580], [12234603495322124006763869598], [-7558052277185300668232386414], [-9373004737841516480005181778], [13637446117862212155070215598], [11612138688512304787894338474], [1974681681699098606816649154], [20888199117388268808019376508], [-17920702151081382248444412560], [5159509088571535591363790070], [-6097959315257389446144885574], [18559738905024487364888939382], [6335267336505210010131755634], [-17939957598635594387602932438], [19769162640725069609277186754], [23850332950760129249633469768], [33582299496761397358794538866], [-6165416714342282822067215082], [8764515964921562427154449388], [-50541124767952289264503450174], [-40778930618659785737084510830], [-53633050827259579978692840198], [-55461290620579563120623085660], [-55501615731321479803709641738], [-46638400785263671803711395172], [77169871577590447025668663442], [56177688261704783964855939760], [-13605980446053861126016553190], [-33312610216568393521252882712], [-71363948241453211313725605138], [71615635476012956587346483038], [78036389844657165779135863850], [115758910924869409853273445394], [-50497402976537281922848634352], [-115853588119897428167590694638], [-10885798156306427286839900814], [-39872615975698092880647973362], [144263969103398981228881556310], [153505935026566566584785664906], [104631381314627161098184787278], [-190207735607778974359481217970], [191500413715094695545475404348], [187965774581739546552502342442], [-41131901404250096822459260602], [20241377062143007970454015928], [-55611334370395745653425283878], [226419643005469491789792479994], [-84608462989723709720715815478], [301009002541490425642877859662], [226476129329001310450312239602], [307971673698318007580502366306], [-120586932790759507737650092122], [-168817434977600059483282796370], [-235739962506104073733248401612], [239365495845991743045568878386], [51826153430138820285213663890], [412425352526657239405877642940], [423769782539229466735221097746], [-463311068720737745722194744800], [-291378663791652717706161526242], [-34883168274226790028490623030], [517980570372892815748512279448], [-517122031398408839120645902534], [-190137391328225781132358615758], [34779237501017743119869411638], [-428126032669171069152709529526], [-117690133608657031881273032880], [766158566005087860793910247302], [-549028383384613559383098861926], [-880384358329500293420090997198], [-157864546199804646100609586646], [688399191632154626292787605642], [-50632598180875397189009375998], [-1504466798536676331328276338080], [1473685851962901483087000454290], [48535505257439164985047184758], [1594495370891487826285911888234], [-1711367683189798951432161349390], [-185506789486557592917929308398], [1651742118792784110163696243200], [669908979125362587927494166274], [-799278279537551561875851847992], [-454197691174849503708952254358], [750831392734559695560469993900], [-837488611684309735207011245612], [-828238366708459115409423940218], [155824804513328371967662679758], [-300762507319811636176251426486], [857024579902702823928654980870], [435026349317636999265152314482], [1507377169793155082344349034180], [223086486530366600637396813708], [997456177762080023963815392918], [1135649208837186015135292312288], [-1311143603789219052446231678882], [952038257842945740082073364830], [513804503320171559723514135042], [-877052092531684283751309400200], [-3007069615726157476956931939526], [2977682773211529985990515458328], [217676926600034539318041365500], [3202412857991786269309201632678], [-286169782774005183580196095894], [-2288928809255907059911612722798], [2688059080561446451248850347474], [1707485494510422857950502624990], [-4614529007642279506357162955598], [4056938867624120361429089183340], [-2909700450738795741397898250658], [1739806756306200220386621023074], [5176630444690386831626652372306], [-2651027734450160867037370599574], [6226089881911608000545444430718], [6499170651858144744315902458794], [7767713972880105328307946730790], [-409277644147739653832274569878], [-7567345168268214994588308503574], [-6863548126394266334457566249780], [5019560545043572653419822364270], [4317929354832668344734168346842], [2261286348778582528159078069558], [-4635001363536070330764992197638], [477351002176414174695722649542], [-9713020088185797732815255040926], [-2612365892442376061158484568118], [711189558197214751342397360560], [-4115099962468407386949291613174], [1562305915215341882946680364238], [-9918591246992907327848837086686], [-2109916927677360664585603755010], [-7188852464052907105326612611338], [-14882141293270616263439800342992], [7055289859458959134142586188718], [3259225190130585331631127029068], [-3579926170281880794849226495326], [-14213571852020385851962878116098], [-22920189960917114744054700726086], [10675241371067490713150045897868], [-556076700021274995251896783558], [-17012967691582309886179380328374], [-1973275525503411354879887401520], [11356567136646507415675939728630], [931538325637805178722302296042], [7252456144853195922522101009034], [-4964382590740300250943185277438], [17896474727675114599804027491408], [24043961153890338728064334334162], [20551509943267016469018842759370], [33208753241863236038292017841148], [-1842412450300660419070509030438], [17992094247851106449619229739460], [4056125729075208345177680719954], [-5113147051277460392951243715838], [11016146355333059445847392733506], [-14835337200430010546706374091320], [-39724160085565453250174611575282], [22737698425799281878874851548608], [-2042350564047959709887234414974], [32439936369469902007484107822194], [42860704113536663458028106798110], [-25146202363695898489873468991880], [869119097973773709053940733322], [32737280880682494724400586814638], [-51101994183972586807871121107370], [-31902976266403284864496356466398], [-23728322271072752936101393509842], [33127010446449417859678089970074], [40858145495501767440083676456410], [-2954837040701082903925961525700], [-31043908226996148374953020429252], [-14995669243898641858858283183398], [52510880121274204759957628661270], [-44437524721621146252897269228312], [28452147664163468194239866738546], [11480214278253630796065154603482], [-17044630314055916091997275357482], [63196362643153322598037754823282], [-54386583200228013146534109595618], [-2818519894665772642669441921940], [22069757563871225898224389777318], [53846925065962298131556563572594], [-39554490274135203949118670518478], [-41836509051908521488291634492918], [35878785073277476055019708494466], [-18597577008375676470722187817160], [98351703079037525030735438200278], [77489027048084695468539955857808], [128362673758276586218457445805194], [50256484963555365107894838909290], [111784980231635515586312152398042], [-47299654122354132956248048944538], [35641794211756140437622075771754], [20381958750460986111147804392042], [44696589080984155903794420291546], [59848344185308359461050180174770], [88092730031015103022834200695428], [-80135292519586520854480521531318], [-137449512568283417497980759661140], [-56431939450387414606832589032158], [-59146291812427838680203551482046], [-87443239829368233919505418843252], [-143459256492580865468400310291974], [54858047217664470255045141475888], [109643845456745797117916426400026], [17204039682326565246546703915722], [-147529093683195212719444637352362], [-147932054599002662464960527078250], [166684629157945012634345606061282], [6187912693048465736942091627240], [164569702313334072643318201661208], [96402167769133432038063866065746], [-1969179623150635927753732272642], [-23132173391791750663379608269454], [120059774026816928545979422735002], [-114102858434562777616099145279406], [75185491972566973301327079333660], [300998823590392795211121238373434], [-188265884329980070684880361990118], [111125398225628711537807832902586], [-223798773312782964576338919581402], [149777752026487250793969893378342], [54080373788711304093173529304848], [-382825242686100834036696381738620], [229707402036699989559552080272038], [372143382521208006951410111147490], [-357746154060242635307098765957532], [70995142169084852431720914371306], [183281299210795734293076094979820], [-256013229324635770380434078355012], [107790333613132533064021798131602], [-56937581459577269666120825145210], [-205332275210607439585147903926094], [495394205416089990867949087686102], [-342720082920698660522016657029118], [-597290624214363943150826148658046], [-147997542587869050386151263189934], [371299111577491426969502270764060], [115637440972626118203161433721518], [64475642691367084400852790339508], [-433674433154472610403530732032934], [209495821182675535285723458324118], [-67266882995471417371089413136366], [-525228153159502293918299975054890], [-385175430027599052308583420709998], [-210174339162019228981269220934820], [363278752488657388631248782887314], [134715951692333613666486330635028], [-572137730553119584234154608799038], [764808823452129015342308119322920], [261060952817904921081875106212490], [112975761439430173734841497512128], [241241211462191664821741228308242], [-379843635229500780735651654573910], [431482424597666077726680616916442], [842736876644875989564920643429874], [948605546232169696598726130062466], [334767394228464751002969930394050], [-116177460153477487547621798334332], [2195845569240213502279056244466], [433447226441289541584774489040242], [715328605238642603959615045683718], [46107251691199320686037969363300], [383819855276463831423762822161522], [923092445940977926718019925277946], [141288580053446275176002087615838], [-1079449923262475215851108340268672], [-875792609742011421594981478658014], [-149973705964386756149572663271418], [-409281266882369129000852534140320], [-1444235263107025632551887469613446], [378821887907506526408874399171906], [-250241758658937436906247725409202], [-570184084777366147595653802192550], [801745795124347012922195832635786], [1384300299990775403172220775979714], [89834855149592311837417921951740], [1481089093817074613057104162646042], [-1224379370779900588790179889101614], [-597810055797895754975970467421042], [1232816314973586849396146457091950], [1200236883902238287192919293738248], [831271710782203421303783584415880]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_80_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_80_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_80_20_a_b(:prec:=1)
    chi := MakeCharacter_80_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(2999) - 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_80_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_80_20_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_80_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,20,sign)));
    Vf := Kernel([<3,R![24642, 1]>],Snew);
    return Vf;
end function;