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


// To make the character of type GrpDrchElt, type "MakeCharacter_6_a();"
function MakeCharacter_6_a()
    N := 6;
    order := 1;
    char_gens := [5];
    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_6_a_Hecke(Kf)
    return MakeCharacter_6_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 := 30;
    raw_aps := [[-16384], [-4782969], [1951578750], [-1589770990192], [303770786679492], [17487095945024654], [-52864751324813022], [3266460704183826620], [44207920862534261784], [-467030861037198187770], [-3337262440659652380328], [-90314696764630914610282], [-390996859326592822952838], [-73184822005294487519356], [1475814532343495313710688], [13646064995749116887665374], [18891434886233883283962660], [-40408385429659622944023058], [-211050027668634892874076772], [-1378914175432505856792154968], [-1811141459575459484455628566], [2211618860354579859314086280], [2341343955035171656621355964], [-10829752565330692931623286310], [-95479799628312306401982166462], [73447485453942821168845391502], [-20413034527376620893828866176], [492199785449323004025203841108], [-244128442164562254304071482290], [704845576035893337219065271954], [-4791659400632906720545226019352], [-9037409999389541739176066457828], [14638433585365734942809222428218], [6743714046288302158597377064340], [-15313989251897718523420909225650], [-8312998827431321478977457394048], [108862250941404340298989641008558], [128062843538921847421812286664204], [-161235847063384256961895210720872], [-115743405564036458014016590075866], [335178490244788155112163857092780], [312311916232400771394837570570422], [-126032925800024553587326908233088], [-1715864026667272889737566617217406], [-2748972163117077430345108516726962], [-3844899161884919570688445743908800], [1606447954446150335468449891095692], [14473814055405441003681703222294184], [-16805045994705057510103266582238452], [-402178946005685509840978594662970], [-11035543619602942125503217675865686], [-5087331762966336251107352249082960], [-7270846887929251457020490914896238], [-71340921617425325662733001754741548], [-163584409750418313309857243275718142], [184807735608619942179986420653229304], [-250673742805165765315409990192477130], [-58959205097366727659188282696544968], [-342788160067765953374024914113453802], [-25319254703391851227111020161585478], [63726002464100439599210259803493764], [653338107809880283831725350828500494], [87799563453779645974657102793518508], [1291710363476278827245857642114007592], [-1498472206649134740199540369422867046], [-1927287579614184190392827277350420922], [4514722074146812101626062527940064372], [1976450708079970406450493427041848018], [6487229491759790219956133023595879988], [560390428669462994154679775949188750], [9086398901038761335979452428253755074], [17916947956090358454788482387647463560], [8364220663633471519125538907081065928], [-22081267307141859034657970162522611066], [-32912690952782942431555698460870856620], [-10529976258486404112518454924712743936], [198840782509017708696356886335672190], [76477166564692157193646552402932370238], [-913090360907072188362908434154177598], [-35190302962705373115710709285458154790], [-41904814927658088194370124588278571380], [68725044766413056642289632507955140582], [-256470485508215504730645316535615128128], [200904656306738205086513629468596478514], [334933186260847737994030406069427219440], [-134814183219198278146000713581529411756], [340722620925311239266934885179446269650], [303761223455775289055425619250209189258], [-196156343300884835839723697045799320058], [-746168796913363122354662718063142407496], [-224999665821797846117724528801869540772], [979436584036890410851526186910547182480], [-1076501060574545795724746372114999490832], [52057721497159338169557889967372195412], [33079271241589692418028214561529875500], [1745783173886522095450493564498828378424], [-77561228335099048821347470617366175290], [-513660196538783063904503534677799260518], [1205421888922681487908279336460883868484], [-1777976551986440008412999666959615175938], [8455877590752101246855379908722940410988], [1907087276902271411489433107508147317958], [5981097623881164079646569762560038211804], [-2047227393886248888532619036828655010230], [-5081282114722405148376076679998436550268], [3228582166038932449023981095883235140098], [2234437845054246874259332546767152575668], [-576366235553468445748898341223319054606], [-22983053376620005075549541825085798299400], [-14017463001153919107599933834636695758598], [-19381024837548014928134017220797686724792], [18242417090708685828245230031284614689654], [7804391190021584312469435448110166631178], [30890328825145333507741356304664107884020], [14887224599994313840201059205684514240672], [41910957609184588028087482379573493044562], [-79254049884995074403963362170207914344756], [-43753342841379545009252836398816902743512], [-34062502029907837561113187241154789049626], [-117067403109735681362832023636370539893140], [78211805355520606494880232504351849126342], [-43709517491008425561911580714759283270366], [202731378272171263974204109549643621623998], [9172671948064193967878611049042781781764], [-11571065310032983561031277999879810576388], [209529027804015341612207380043983358930502], [-280232352946483087509045645739044282140890], [123754970124737379192427563333639302982720], [-48181834451753457870531924268018224780352], [-350306875460468477620340224709950541713186], [-65704147248072343341660290924505835450660], [-126871019323446261778755692845445078544456], [933645375620509078555113704886928412038952], [256063416174662388950690069188412821457558], [-963947061685054743306973737947017579761558], [369673026891374321755419429346276285479170], [730644552421518097835394548729388403587534], [1270720982331348053707579407652891782154268], [1052362387073880305737131139907111496730038], [1564587641537124473719538225044769974446810], [-587444628585222898905508528009806036797308], [52269464107042775767408507818222353585982], [422097851950547749998389083852449234190784], [4013679975560270704971977460703005223223748], [-1833055689178656040689427580857781959931170], [-3315429234452042498242931118086966811589560], [-1642309302310582429942859594495278996138426], [5552353734021492020802624687878144775623658], [-5819181203013521304097211575377275250296140], [-3337059824534407032429639472364455718414496], [-1134380505475951710414917267622167678146402], [7805488348942336947393660998475772169063922], [7289828899712692401898114864928685296631164], [-1461339392089658699650940035653131620586232], [12349334701535361809449229388261031505552708], [-5973152718593424659830710677341419130335408], [-4320382111504485455371610284672043597512480], [-358888475443802221370185271721492198218670], [-815292932359101440996132583629779854622582], [-18152578908600889469334538977348252458782938], [-18774256515818723071157249042026157100073812], [28363578848176855997473836621149590061934474], [33029998325097378065122215203609798642805728], [15491759304364182850886944917019250007424932], [37160572689471437405830335159172093917906498], [-3563565411898522154916832738296520981802136], [29551664069140399319552856174947129160704312], [-4408352609116409296369810307628158923378762], [-49236008173633376141002682760175556106294190], [-65082797197159503720891865511859856140992946], [-44793895966486039471938584116466434542371580], [-6343794275612170930582925785994374362061618], [-24382012261093980780400635412545643628890728], [67352473817486185200025361358252404844711914], [59408029066678593872177823856237220660521640], [-100154510714158989722113144845674028092007750], [39074032634346563976473871015696673378085252], [74366048862833636982617649893624473423917342], [-33131581486470954516051031931941638374308096], [-154034705369412822461516179759876835048889730], [-42594871886098234155709418160027138825225832], [96067266993392411392849999803054995034182412], [-174147324065862936210773446597115390614081306], [201182116594136782306330529182663170280864938], [-234970739970384047166322448046577114003847376], [54376027291824381809789691789048087116492910], [54372095473865758571955884984687920857026078], [-33247589189699513104514988583107199873571716], [179807130321724824063796076100833701514108330], [371588993225511446487693021732232072845380352], [407190490660876907172197884315523152198289474], [-376491515966804368607947254202726660778853996], [-416929063241526441133297533973258641231796468], [-641138689888667296529044422362092574826191178], [-192307469550477003956326237596631850871504132], [-424456758233301255544519817468183879938858806], [385678496384446494922293558726555806108958002], [541845859826374192928504285382722467486656254], [636049594669782311053138333873561198079042178], [265911609775011251795310024450735337591930584], [-638433714856556824766184816907527983257978170], [-338723887352867955336426015655281585122957128], [-1162636512029087508285790729701676014159111082], [1260537952439262322472784389571501054628729250], [1601628656266183843368182140408550484232811460], [-2017605614509605694840731001372421705618995002], [127837389074198696779668591950320984786349480], [947656102774836837383463082884473684374719564], [-118434824709030085597934448181078241943502710], [-976038059753674629122239658375834704850796988], [-778542022250162650627190192410256338839004462], [691797221262838286956409887346974625456613102], [-69325317124542424068804401477290948783174576], [1703078276413036694432970259046553249734885508], [1395777065758559921899151303271731377710678120], [1779421764229174260735717210127754407452772682], [-63865235068957649405916641013116930117379352], [226516633371014889408677050098460033151465442], [-3762540273548827273370880640038175603378731672], [-2573374247084848932051522255757738922437871466], [110898228958142962819522905799733548255032422], [690271409951469216596800623764284310757446000], [7377692536677267491232446317924849601009791410], [-1865935433036937614472786821351363809626051016], [-6832787172113275814674804866708731324199419652], [-5167147691558411851284259296526929528903290170], [-2066365528795195279785933115511599867818725286], [-4919198934554489757951107443745528878847334960], [-9347471068706367083584825800738070185020535712], [-9465228576168358366131085276783118187260931948], [1902660568850293541881369821359854068577704974], [2589678240676919373467417080070351610007872860], [-3849449624814939579269353942661317399071768568], [6410083967978118735975995057809168278926537322], [7944122347108483753090471763996345613429141764], [1738076084689136144058957933535323567852185568], [15461104994028328111296530889763355807181296690], [-18365286301522917397935939569517382083915403506], [15938414989830488436301582151282207996164497300], [-6491867388629600787325585021326912478757671608], [4360923772099720047232879959311310421367478684], [-7290124614751011715093591168709889829495063228], [19131357963377928247256361968601926179889355344], [-21716671613609168011557751377238736281601438050], [-33574615349504144443162124900220825946767322926], [3923026517039407839560733749539937708890175160], [-9171732974013133898494120787353111980552743272], [25692183213459258496122916466256372514002408732], [4667110921145181108930086325466748080182572180], [-23744893406228506790705278258983799205767267536], [26152314269853349554649339243957571135272371038], [11783825092075681714751253888380330870282970402], [5024657513741533624776042649501974573306512808], [-48350495346262577347611873361910907188037034390], [36441253505479146896792357830379380162670836854], [-48914571184326803993482338969111894151699874580], [-5783972794374443091608500234721861198749423018], [69583243831963058967448457861155740012672840548], [13002250681309060302363188551328536417678451118], [15050028180975173083022404878201461129918893658], [63384321366263232639041133708876599497398038504], [12406795286762074102259105841320113423473387228], [74368016041680768551581613439608833390857400070], [27163942148647413774373135135677682808690112494], [56152590992120061635255468321590670595473493138], [91425874060905725503764839646673132521347851100], [74748145919857575208921036034875579988765829510], [-114708533480894965446207742991580224471731552518], [-128647624293775446343432767366500972857045136716], [-14704386676744296349773092546795898320789752386], [61394131374289935162003375014089890271023940862], [-5555667008605419590624849495999207031309229012], [-121132469941187173703694952236244327026881576326], [-113631524890094116825282317405858436034776586440], [-91569626506949816181591803359697746636209841102], [-130631328908543821209185052959946258206547731536], [-144919256397708252099889864097023121264774939532], [190822014095265160965127577666851330610793074990], [-248900237522617087435658838699806325108911554198], [115393807626744715201833112141834154057341934892], [-132518749194734715331360390370963491958091658416], [79534661966315140031887356011279519771295433472], [-370195975263632879887426236856400906083634828712], [-8121836950822787875895688460560433079653518058], [306439491040053740487065299668813859904856291428], [29491098038974588827377184066394803026455111632], [-114715180271272620982270071397511639089410796366], [-301635177439195781658112129966417734816409958802], [510229106695374325796535209745035823814364372480], [35585942287646121697537594126593820798761181890], [-318342804329566067868860898874337281525376551098], [551049266198716603627927141591675823847455985708], [-526747229130199114759094129747514951389363538246], [75277939048479308196309668197928772835570298772], [125972707726535149255781802851966482096902382814], [58502824129201555542855410823199796660358931350], [-48411810775629310715601492914538247457996091448], [-236705890833098469271564348143631432185563824866], [1033951344653280855109480574248138629583955592180], [-908007656721767713189472525517673224986908584532], [752645503751445600471118150382773898670303978794], [309614430522916404930286025775274251231036476838], [-218025608371146182320554961178929138499306416600], [-227368029087877066517855418134437815738925903476], [-377658986942056766074594057140221318201212427308], [-780163214688055050794985717674923581820889020222], [-1422041923884323197582920774833877266129433876252], [571778115888474972041371802841884175999568590830], [194882540373504930665061391247366974300901049240], [-1333052336764350382970855184442430891134461995626], [1768783653323245380570062950110096335822006845104], [172901382722408397637608764296629305212171484670], [-1649116544034821951017705469240141724141146947278], [-2201798232262944367994718003139399584105030967636], [-1057889757168994416622163242409568515482961746632], [1917480674847350150299722074606244058509830399690], [1952931797253371213321633622477377430700920463500], [2096999690724457582802537748699689396909896184592], [1270346189623973293362495637232661531513360068354], [2772683789346950218277474733605669481904444238130], [2825374913693994829903431279846651002533364255372], [-1703993909531324143540016025650201145040693307782], [-3099890044623966014229927926691889161677434830138], [-2953443743217742482730491367975861535712814247656], [2644274324373033074076126648979358889154183942074], [-437153546603676948818774156439791988267469528558], [-4498529127590055024511211523683603776008231687220], [1868603099165217860933799064360999957718030263124], [-2667743230643801679083189737331811093476525128992], [-5004571558332170581547429744351266208250605016546], [2267190389816282997168764727861808048558150584782], [-3177290272337888533207538853338636539825081902282], [4828069845703963633284352426823609721885909949640], [2230649787647171294333848427501319192040489046844], [7118147228090163810304227494489275218376727365652], [-5852317247674677936224439019054316829691846208172], [-2225531478957332135100422838349335483363822354130], [59788554180912142391193440440754699488851663234], [-1003514870550236136742525211834825968366279700278], [-4681745645307799845977515511775203641626355049032], [554479167046074458352787478781258753105770091494], [7569764890763558572007663489270796536729914800138], [1653643328355398206093545446146933910394941660910], [-80660469256237587718049256394620145426007684608], [-1573177350306280624925245234299469003121114762586], [-1243868084596928568005282250899990555753191099860], [-3455264927499819861675344040508467745034192642938], [-3298105447809908478209044015044310177064800693612], [-2874312826678387790053931435416403193908077503648], [9613601768573912142416714351017252129409828524158], [-6745155051315428287209202578303407893384385670868], [-3077618827711280499686400588222280071646662346102], [16371085293969278593507591373319624357089695731222], [-7064614575187712197968999031196756319913325268136], [-1825755181598745372333999174669099736348495719610], [9097465600131425931905752905072501169321845787194], [-9992550735162305995229950634983498883832023049600], [-8276421108902562171761954532240581582650771795308], [14478710513335255530436736735613894672985973018178], [-10158119964880408538628053158385080511117735453016], [22905694275500190736118003344271698700104056904118], [2418657170902710070462118333075776259763432479562], [10218472015090856973241399466416544743672425671088], [12345275974525711789397534227990253133520929840660], [7155464071540108692538958674070939101122061820828], [-2144301376909186667562502089424370958630390718966], [29319802010886436782040898172012842700087958213398], [7665346279909930497792922583242305224750711259824], [-2531533730039831248389102955185835104699835155718], [-21851649608621083214569658244235046969032072194228], [-26623902747011889703090228982752313939438767189660], [5531997940767502285105987919287047057013535726544], [-16567733968491532305193060447548271127122686444450], [1413326773816864600065066741212942975531580558752], [20999057747494310424867197171583544421599196719358], [13750100468782560143224205339556920045387623830780], [37809502997313303446706238815784103167001427335712], [-10750643530682372113956725610916054233376874253406], [12056270927838685132175436571167150044782214399010], [-25653715771481221764535164225861939319924336604422], [22881310331574539364338218244633732671685024540982], [-2941326392398012725243779612590841891282098798086], [-49706257176264740884269305635328712133984826350912], [-79485291283672714413866280568251800179242920925342], [-37152293065156733697481666704514038181341917443540], [-33596447450814690831400770010408152220128493797096], [41322380431718739454407411876590477741842174561832], [-45805175985264994039579440275305901532292001131402], [88929551942065869357656140755743481065339919148964], [-44723571717533521962597690225501078193846125938832], [-96841208695256977206138881073415964087850282213310], [-9182050823169231330953684332608056569085708550306], [29850359076652194668042836367438172430427748772500], [-59250538815356891510365878209509352242555666773892], [45895917833355220927637927494430128926305526256392], [4033778645209490874184924951710464076475790406554], [-105667727320373326069384754539672034202227519676280], [-15472419572701019904872350648484213292564074465670], [96527575919076651291963308985031425153103313524772], [-44004786893531232671403680721393129461470054245138], [23289949823838224610048741955733444408514948152750], [91413694187991717412202549247564892725156948481074], [-109550046734593644067606205356862679971940074173672], [-65313547428748231324969172057131849515354969068502], [37270974824742703532726619157753686068472314963790], [-3560315395092713648306690452526387227851931771888], [-127336609468113655716347671672047742104031277232562], [28174097100889274244308835951343955371261399127202], [-63506193776950376353688253414681661030929910042276], [86652064192403478420407578824244948036305581663820], [97934097801761458259175325602914008740105062189714], [146265635332716043187116953968337149890166603411118], [-57882460833208805675452193693313190089279926444556], [-27975952477776222884565526152177145847537753565748], [18821374971900215351143337772733044813722217307658], [-143785890732096930527445483896667022459602452879658], [-105127529624026058062492211441648435604234791483520], [-158896756276942292908029086451314044424420503775632], [-16686258166357023961183778967104186133827776988862], [116078804426845549526116462448051369709899075623224], [-244839344995388057227430662298985045698650405832490], [-260079709572467373040868766542640555575561170372522], [-253738270267766903659490587689769277838662806723152], [326434733306698192787280811107997810498800094729140], [-120923646036516111693060188266844304082926428795926], [241695212396008088915234905406058982685808021448758], [200383136840809665169746176205714808445156509122204], [-123734376359697519261157213588358268283157804229030], [294138988319593702810929656856414329370586775015732], [260205603385570485869952599415012073014816399329400]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6_30_a_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_6_30_a_a(:prec:=1)
    chi := MakeCharacter_6_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 30));
    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_6_30_a_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_6_30_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,30,sign)));
    Vf := Kernel([<5,R![-1951578750, 1]>],Snew);
    return Vf;
end function;