
// Make newform 64.20.a.b in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_64_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_64_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_64_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_64_a();"
function MakeCharacter_64_a()
    N := 64;
    order := 1;
    char_gens := [63, 5];
    v := [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_64_a_Hecke(Kf)
    return MakeCharacter_64_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 := [[0], [-50652], [2377410], [-16917544], [16212108], [-50421615062], [225070099506], [1710278572660], [14036534788872], [-1137835269510], [-104626880141728], [169392327370594], [-3309984750560838], [-1127913532193492], [3498693987674256], [-29956294112980302], [-58391397642732420], [-23373685132672742], [205102524257382244], [-177902341950417768], [299853775038660122], [-92227090144007440], [-1208542823470585932], [4371201192290304330], [-635013222218448094], [14225184990751604898], [4907294374153596152], [-26462522729977956756], [18417779076742725130], [25742101939950990162], [88072027398734416256], [-71928888557627226972], [-295426173292082995494], [-138478242598622657780], [266021193813555196050], [575578481645706044552], [1072375480931336531194], [580764662999007691588], [243392417169880585656], [1193502882659918351178], [4146639259449756929940], [-3323637583685998127822], [6193795096341916302912], [-5206971294736770240958], [-2423836313237712027006], [-1059072621521283111400], [13242387429757990150708], [20092136783007908058272], [20349408367227979917444], [39990035937447287206690], [24217033172511669439482], [26241066116230112579280], [73644506169104941694162], [-72930920304932253837252], [-63812030516904649354494], [-135819824783556684808488], [133672004682359243213610], [200547574021219881238832], [-200222747174096559828206], [-119239496202616376591478], [3461084772055526965468], [213235512531799832489058], [-191887086781507035813356], [-154521700942476731981208], [287407616111100408566762], [-26353269327755584850406], [1053375627397004455028428], [676159899744517170641906], [-1063246225907504447440356], [714666649174805721201850], [-507320765589089335531998], [3320064150855122758012920], [-2244298570574857699866544], [-5106064897996372955121422], [4289751162168739890186940], [-1868030627574609716765568], [6474481839876985824443970], [-1227597115000120170846806], [-517895245995397565310798], [2818767450506973223394570], [-8655708588109946594551740], [5216517712913512492334818], [10436381488383884270310672], [14510951301856278108779282], [17985690752159857937736680], [-8736849476979332061375492], [-16057594567447141671042750], [-2675866234039257366875494], [-6968065181802302254603542], [-24984337558293435796179088], [-19453069178829687522404556], [33415333454065222785017760], [-48618082719633037051166344], [-9867302508639730608865812], [35415047001126952989663700], [14720352635696539116278952], [48829005109648323366368730], [71444530606997803992245082], [-89989490933798334932096372], [93360210082563133894716538], [27467041603607834560578244], [-142588699490134503664158006], [172252275378180515000704788], [52489258032363872534509290], [3216737162983851125343868], [117452828132996543064218306], [-1868862009035096102933556], [-150165073713894823114150158], [165804217294620955662035400], [-254795398167551616303036598], [314191293450732569600135456], [391477672780633338462808738], [486066221227871859201962106], [451098253696556017748426860], [203805071384693884419692072], [577926950333012117394136962], [-772049268275202746206982492], [-1392256800135635419647144], [619470222760661832598870698], [79662660304446879314894580], [185436309592288012497255058], [591531975816112122825354722], [297418062223597907916800994], [1259426577099632388995338668], [-31996453716239418771490412], [-2064629078554311470359104102], [1440955677319441783081036930], [-1263930301200965104242038160], [554467748906702914995440456], [-806563014637524944378250182], [-663849768850552007374925180], [-3640947602991580851653680008], [-1554577041827633477827398448], [-1334060519009086810602782606], [-68982915656223958871596758], [-809673088318519394490554110], [-1009238467990545727481244222], [4883074190805508431608093044], [-1183457735592477326828764806], [-5084951459230685387890761030], [27213304830712131339736108], [516380791107383402431504818], [-1976238814126263760979269528], [1167945368430261889372056444], [-4208089612099645624896372710], [8492535037153362379496144280], [9333449430453710848291401298], [-11103739699848511536058131894], [-11147795036950497002528898020], [11544545264508987293598868512], [-15591174053274879720999887606], [335920487479087202598947922], [134374308692347566243606868], [9238872428845976272837826856], [18058501386448135781249208844], [-19930387918681950794667229008], [10431956843245634836995714440], [-5177357237229028065304968990], [9332015844322152887347483706], [-4501145845350783495352219062], [-17612552500617257594061934956], [5937301978653944117499620202], [-25848879904223060783499866344], [-20573213660753757730929994932], [-23452372740546363458648241294], [42552577586447649578248834632], [52147222626560601969944350112], [1615412567054620685341032994], [-312773894468333088734390830], [-5723497971079247212868549262], [22887827695208653210295289660], [1855595513941838113387462618], [-50467130676688800945071986728], [-14186978613279342467663857318], [-45594637605856378647327712720], [23879871229691523389684032650], [-42446219738863429212672905252], [75311822192431378008906300258], [67076395564757481129932845112], [65416333646743380094596523210], [52381721094430759979295064256], [141921673037325868974334853988], [69267694446834929166679417858], [53671023776016143615558126106], [45846795161384724438136960752], [-46179182250097402741761617070], [-31308108692158065457458881606], [-13923271899354876114312408572], [13349426678786056133344716410], [152776189414922661830275028352], [10514537823293805337451222402], [7505746617718193750816069388], [180729796717718241685169178868], [29442522798570935937781833978], [177976638792304490311354898244], [259865707416073018977496995642], [177913994182498248346605968402], [125771488901174454914604605338], [318195697699726759979687447106], [-104275151568407760831334436328], [298980536164515595305996493290], [-112016200834303778215946301328], [49755860943065668305126602194], [-448647352693024741325741504350], [35971090084416797876367084780], [-121033050223189979650841652006], [-20488014967775844922669277440], [-5563617210824038457707584732], [-647030747966853215461931074470], [-230109791205633058498872362612], [-418174895968837524654653478094], [166246571526527235131746010898], [-144353803040894448587334790648], [371656454653829675908905473244], [651911113976597505235856675640], [805741933389267941581781559482], [-493359229488998098871242463344], [681573826660316617379068000242], [1113505456633686594955600032456], [671300071603428041306285985978], [1048999787592311704089149430178], [-946939577165960693393024426200], [539300289020756556474578032770], [468669224443689204015424759472], [762205901062110774214370950644], [-1083254377430855342384275084910], [-859994468504656926199402563318], [-351297496803764300828107641120], [311342953550466430302713808056], [-65403803809878420317480525652], [-1055296005928439758195554405302], [1954245441899044300530676242580], [-361014132942461896884631691968], [-506469259964279085419455263078], [-1875105209481657765906917745332], [2282382955415701069320678835056], [-988467692584065944147573411470], [-1883385945584979049804572452142], [1003411115724635631262357561500], [-1286984675751490781395830928008], [1856298882523803117387682575828], [-1363414110581808435956661055172], [1554244019159454855148255391192], [768246273769005888455823275050], [-1678338938688227142372564750798], [234378115695445136612890285320], [-2709722818851147143690923632544], [1018630054075357757992376080068], [-1070158760758746804004686978260], [3788434237733431718048466098832], [-4154021741574715172383664972006], [5048895501990622867789776414402], [-672271149364905587318970538344], [-2846760609945219909226587795430], [-4216382311332096653618319847062], [3784109930183241324661193729460], [1807436473408418273324837166418], [-3092605701973934131392422448356], [-841634894104527651344137363806], [-6065534357258048730525087147094], [-4990801929365969551255963305088], [2396118984893499596462557627044], [-3557576874136080023548104755390], [1960794785392226705108510673658], [-4595418804541848335747047294494], [264450144537780795237327487300], [-2405659204231917659405966284470], [8298801198470859847633551205482], [8930470316073266218504577944828], [-6469393003028944519281481203582], [9998066696497261540074010741738], [-9218960000495394995115337310156], [8374151860989043838533829248202], [5078872722186197083643307804320], [3060305935160178873382107332306], [-10499096329985079043971145620568], [6367615866472415726383428662844], [-5297803181711584500231084302630], [13262511689522832412691672679002], [14485671744464805509697494363508], [11244001782228471384241831570272], [-12116272485433780325268468950728], [10423505864949507726579068695656], [3521740208245788374424637657858], [-19564431324820078724126718786356], [10733234639416377367419346997232], [-8409951603200185447865331966478], [1816219190019059124118993306194], [-6844950998819795014072584406840], [10135208005948828339605110429730], [4689732328855381479984233132298], [2941951322229165090263614997844], [-1564220551773834209548763345238], [-8524849709789212385780658461172], [29240093783451150490064905135018], [11486747857318284432869452333050], [-10591054547393992470183007644448], [-24845411155572256537597025257422], [-9430298652700184568499861638660], [41237471747076426814221281545444], [38528097828828445133088404620442], [26431481065503508981011643023594], [-37331813301073663762367410771600], [6753091775998298537749603210548], [4265534413346145858299125361308], [13904243907479304942502893580706], [158034580606487056589146840044], [-25636750069489669519425561736310], [-23612139961755562541757209368920], [-27737983457956870100586547933502], [-39359275062859335387053280385488], [-31553055577504988569762638801390], [14419541176989396357366082369122], [-5083658883115173207125736111932], [-11122487652814921120312576639944], [-35304308786595303931575608409670], [41517530884759177491348065639700], [56805304067408412955132571520192], [-18468289009979173942728060613438], [41598210104404627451558960570610], [6868983150158816849549975343028], [-12724336262148389154546496435894], [-74685351090827182784695482478662], [24387228972971055572790460220192], [-17841580906179580877045974699398], [-8766464486372159660389793219758], [-68152101247183515184079518618460], [-47927387472677864260276623583652], [935885059665127958389615781856], [-79412669165993264183850789944862], [-25329035299110856761876026035382], [-92755883352514951715815279586406], [54973588021042272742593742460480], [-6797885040323621638794078232092], [28408906831431823291866066742348], [-63006185170425643436921959264356], [12970826615254588787106396682810], [-14566941807375875418182979824478], [-146294922971090343592491015887878], [94954798527411963000177410549456], [-53838595605911053848345859744142], [73374007784332272778606263300906], [75457991430163573865281845588930], [-144359437305038733544135104653608], [-50433151828299579103529805365382], [69995469424290444559892873172420], [-84394369122519529547030532828062], [-148551053328859292397155410316756], [-106323557247020427527319236136048], [183647515950807664609831247388594], [-49883233578302912963483266962332], [100315353787061799968317812967706], [-57810471951354029712161277718422], [178571029799867412654171275048432], [150782861745416876552610711333970], [159098121794608163266460799597642], [182008356775657511887057523988000], [-119197235002766588703228115180692], [-11777077810508719126887791858094], [-66967232213940497706060913677528], [54955495578756529146295708476994], [-176886875261937261044759559616038], [-78899043310923289541675155934544], [-195386171877213876507602661754020], [211812232125507873371531617304644], [-12340084869432362552690181249478], [236717110647380866001536908421194], [70779109433088274688979435446552], [-86177491670968827358885912420918], [61484137627811933514281495537028], [327183847328043471658336359114220], [423571029945578801629035119024592], [-18605361044925986763579500100750], [46464442086214200410750376848552], [-212625229701818397573775651373606], [-374660479047204833792988874290060], [-496889701824129690157079753923488], [-144681034408701179151691645817758], [85243292925282372602864319898770], [380524868650283748069534347382506], [311808100135620770820460674741018], [-147363207962510350801647615570918], [159165295038493390881432305254856], [-127568424163669221961485696118494], [78362655814966997484947110219780], [-356363253735491059900150205543688], [535151444443471036356012249207632], [591698068568229593862493084804594], [100290265235979108924298740750268], [-540302793466701709117239816534144], [445115100730963279201962795616130], [-481981250123971052785111340414142], [-685101150190242094454273061587700], [36158972217380428461547891853044], [-396763170577022706593631032671608], [-485906045845305237072289665640438], [-392902398329799157862278114800160], [356031851735268423284761485777210], [36010752663542792327618880666028], [-853362592925516197892002702022862], [-257860365481932292008102716277350], [159412439668834807613711355227202], [361176026980172862793481865593456], [-447725418525469633083698636701494], [-858511126353087851029954934020830], [-181234439948550327137016967594888], [-373638847164456592385216573740406], [230142327561186075527397774408402], [2928450798229016684884392705748], [530159803303142893006345160941860], [-869223307695554807421950205235918], [175118713140216137550966078571794], [-361433997506059111033617393536292], [749667243378611918786307218833348], [-207727677446739257650699694241094], [-258982704639426069669726290700342], [824709308694068279585804928730560], [-48892504406540805258620228119144], [11362430946294399417719408683506], [-569030171365243761746653934517048], [-1081414893414918785629102887276870], [-521984319414978949600414734887006], [-136267351925080074780420654938544], [846309521139048841779276807519420], [434000394331499716769892822384602], [1354627118585024975547955102177194], [-77019196707596468932481803699212], [-935449930112229532293571551704310], [1018803751926289329784007175685468], [1471362658286743739265775056781800]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_64_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_64_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_64_20_a_b(:prec:=1)
    chi := MakeCharacter_64_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_64_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_64_20_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_64_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,20,sign)));
    Vf := Kernel([<3,R![50652, 1]>],Snew);
    return Vf;
end function;