
// Make newform 6.30.a.c in Magma, downloaded from the LMFDB on 25 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_c();".
// 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_c();".
// 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], [-21003872250], [1540629019832], [-1765121303482548], [-2817533925589474], [-1217344130484395598], [2696824417300672340], [-83091607940596084104], [-373821742435215352290], [-2503240865137999551088], [-55452778541712818086858], [-397795591315092632336598], [210619358285038091878316], [2594313197853807893435472], [5777440175609105519260566], [64902007109801538344613660], [-112174996267136890127951698], [-248737931110802576032407388], [612934098996643793966308392], [1455538645154676278929109546], [2435982470924032282819775360], [5283721488999468732467326356], [6175849698987958280301400890], [-62517784184796470636199850078], [-115780470773319106087221174138], [110577493624360325980688177336], [412693059398707874676921077772], [71561603352044516832722408510], [-956048779187564290626140200974], [-342698197496553619798419777328], [531150010412299303545094767972], [6390762257590838929514508364362], [395472344404959894120763582700], [21177008075821374956249414838870], [15001953650877001564248786602312], [-112788002463690832922679565215538], [-180626042682019586718363737691484], [-298723558758602482860525541397208], [321201335901323380634590683885006], [-18237306571934121336146393054700], [-718952762015744733943294500035098], [-1760804942797279338157204820726208], [-1305665098286489735154709074879934], [-1593535568941013911459631535610458], [1691876919374193926104501921146200], [-979887081678670260970799923612108], [13081426272912957234078703540904816], [-24878827474212828995093235507595548], [14163927025138826697251641187362070], [-14993059353392526481253224801558134], [-12172740138141851238385860816396240], [-18487758685100178928455685826751118], [102151902849385189121509087373786172], [-71207314157224988030261533067398398], [-1386475812764323944298846239299064], [155345334443462267822657166964730190], [-657202217685785375768804038379488], [383138363180665139025730829730036422], [-250821612700981073402138997455287878], [-140451772427899494141738597583148164], [603242253792951823947023649846993606], [1208343199000403013850046842244641172], [138359268555769034361048112611238392], [-1628513623636888798342275630032216614], [-885592225431701802726047139608807298], [-1666717287311495335902806915188813588], [-4329876557750675614199592052214884078], [-189620737064640460546304067006635748], [10271968544908564830940848672995251790], [15062537092077971387403798915964804386], [-7192680116893556235501208510143044280], [9845907702413420371015204947163033952], [-13936881724783445795634470860849985914], [-12099272062177959800502560893986680260], [-23299712782078259894744884919894696064], [7764440679834428505400513083036184710], [56962706538685373507456421641262854462], [-66034105773372165509883948839025589518], [-50936592232878590824507047153821390470], [-8637698301767537995534441898494580700], [-116342081575535915340904018515987261418], [165299567382440189910155625670108931472], [-45660755276992828534031608680487930894], [134813807595254188091787076282436345480], [197852674961368284176865564359352983676], [-106383566671029656986388479436605214430], [-403701730565976523922581558829179886998], [635425719539053791558914319669756706542], [57348055800220388509711394943330356576], [-634997897433282425311323158379031828908], [-105569272213043976402101134287183159360], [-400602491051527674300655159087155642088], [1169003850990734266286575645728405298572], [-974754936566992067090906757060028269100], [-618102501116450983009209632176179995304], [-1703926449685830690717419169253190571330], [329159435110183173924545048516603670282], [-3314879502642468261268831211225627791924], [-2488092274692104616907331096801034514258], [-2534569144126674352940375142404613588508], [7120402903180653539313362293872627109902], [2528335012234603713777083986195279529076], [4038567893832405828357493549748395981050], [6405619147569240095742215288816799842012], [2989009232899830220268659716085800824642], [-15681878379406519158152833416989455646868], [-28607388711282767674412328351860550309294], [-1929689327715451877831189619402861659400], [-31188812881227305468704735593794227153798], [2577776063308181540378935248984162347312], [18375630783587425123785395586713563415606], [22526136635745108038697756012779074179402], [13877694359063902051384105135890530873420], [-26962385162575650965397890118790561779928], [39155099473777252645300458790042907183202], [57915506039995431188328969449938308125636], [53871421624036271955889701194192009185512], [-39289931905435695881261933598967059198354], [-45199154155981292495773004090919015979980], [-54953366427357611512280110026168247254298], [-37078541297844804310897711571357669875294], [46379292775059497848535830732065958216422], [55134885421112021905591819300854700784556], [120625695390075244214474207972893100997812], [-175259856496835798020809660558863149374978], [37035198261748891543698008775469490409590], [-85441369772721419471642696595675099778320], [-115556323826790459956167897859977449772408], [-220123982326839779716601774400325893082834], [490699612263565354875782231761265224001540], [-252883981894672529288932565702045635823064], [810589459270808056652950187087678817114272], [397651975104461123622042758278151371422182], [-186466926823549883987981923392854914159878], [-1026756536622701774570351295756439776114430], [-359602042885991165281131702504834639891354], [899339219172399849241935920833630170062612], [899287339347867508728234855548663681987262], [-1966672000121457182846573001894819919910550], [105713622776278524072640248301088888462252], [1267444967676488878410740521465825809487062], [-1143533729396828082643725785046601311768664], [-2262033003152817338835146034841120216144548], [288043034337991280953361197890465781718990], [-1521716328661682744811026165718532564119960], [2955281679555592641025530425871497521179686], [-2320703248116155338999827658497984896326758], [-332441989560047957923578592069959169612900], [-5164881937572119516358351381387696346166304], [-2414487949305764469409273593874626849440098], [4817714830661755567603260684200472521827122], [-2913492531953100116716037918333569531328524], [6407099809148338188992856252673167168141432], [1891880847068961895929259772632357873252172], [-564196592630572556887559385149732402448048], [-5198290625444625432464577444888954048653560], [-19811537645212215523778375367602887724833470], [16620238760087535268925095910832573695291402], [16008190769457924866021575854627991155218382], [19089439810528163189681514096454596954648852], [-20910769359629906239818158073229992045447174], [5081244724245802809162693424781816685469592], [-38776091877798830412753630373489681478063028], [32022037993377618607578467882438689779509682], [-11145434463307201717119288115075979498109864], [30022471051548273894793694727501370861511312], [6733572121122359874270775519155272472086582], [-52294665409271521580904228026801886940720270], [68194860466965246518005346718806950346826486], [-74835378419768123016878020592833529868298980], [10517680247120731310352620504597984443077422], [-61004134111190216816624726863684759824940728], [-36878914917655734429641265399811010365996054], [1139314826617137590441204612338701503863040], [96793418041748343556096404578803839238800570], [-82672970399870331419070515971531317947182468], [-9744362458332352481240946666302852800436058], [-131316714235350914823957104381507047808005384], [87980121280587244039096841297953266700593950], [172318071999074389623489173379672876829995632], [173147666214235076160746251780161104287689732], [11677929582451421988312194613039870436119926], [-84114483159194716934856823395403463519228118], [-253636209898209978727489919474629818797421744], [-77844088880915157389996577963179124711424170], [128884585435757942996808316432933564277103662], [48700116984263515354114466355463004543553476], [-71553735587241907475771626622470172877939190], [70540681996357313790350247968342137474081152], [-49817403372364173997876671251292152861020414], [-59611958105509076837869255367040746803711764], [5195464138647906361152578173225043248072052], [-33612213350923807641785517797095630798065858], [-337117131646103434545330456867641468588025468], [353171886521245063298274936533158524812199306], [292065091583038409478550621328300283037563122], [511712187016951558938671056986295037717037326], [44885288538010205918741740850639053010470722], [-696763113294668174744693792275814487301221624], [41200966915681617720539234969925438379863150], [662869618813297161999409122717329908139757152], [716220319280097246364108562631701889714985862], [688984503341063123479834898060818402486033250], [960646710560697019817886810047498555254941420], [1776102567093156124367127586209305620811774142], [-1905609393684812696914929765836882403510126640], [414300869417154222276459375557208664509897156], [181887617869557242626055274129698866507471530], [-31377839865733303700100359253166794477582388], [-85505177128150778765802425523151947835061038], [1936265790552673080069393256004366567623329942], [2554512962514680357745307415286576404734847336], [-2484123507831836199268620287652597583675274628], [2747975389777571309638472146092963555772197960], [330983047357995774267631677098800267845676682], [-2638928703126525614282781974809286013714227488], [3976197699302403072988118919980511525898167282], [3699991988603654783698174550514566133957233112], [-4881802304639026511341994169463873651462430274], [-1501366595965568528833739068019375063806846378], [2570219532209107288678252935647004589729282760], [-3645001061461340783204191770204364573311232350], [-1444526438736559357330353306443984225884945504], [-6721469565130073753908701993650303459361554988], [8859875682435804328618536118741596108128601830], [2522077423987050025986095441160470703215016186], [8784834485278281363235246853263828847793171840], [-285301348656233338618025998179391180580235208], [-2671423603142318993261547820780300792691616948], [10140604304414415784147869472670969111898809726], [-5799771338778843073113203729914659761494795660], [-4988913111386329029327123426623529830165274928], [9098977645910187166617429546077947365561262122], [9629189907663677020673563116454877470355993996], [-4800473599768526569287825738713805230089426128], [-1811609407096089748725770154264465518714843950], [7645996775388209643317250006490030820562114966], [1428892547648620720121119769249378973184549980], [12323995334353422243212305390257501914012939592], [-16783034182115961735373298981493922079075389644], [-9345831989146964323259738199045122523638185828], [17663337246966399136577996573782860865233392696], [-29876632923342230991921787801539884232663089410], [21388642584518035719238926579758342560009076946], [-25093984910320023302134864275326122505351463240], [27901364023301785474678642875572629524815466512], [14670273621814011568188148095007800751378227012], [-27144975408519684767251499107589735318797275700], [-32696842436851954715087461317999006894094089744], [44156856492405657469645623795822897369345071822], [47159962244270076487366327024610403113789929602], [14245155259045438619894100322786033422841018152], [50027354351713564099343614852631028914707207850], [-28672362860119352340616627383270653956802937714], [-7562641203916511638333351162356452703452339340], [8600373569319103891870226283107399425589486342], [-36153975641131054934799260093128447625487032068], [-57845563181991749722788580031866216906863393978], [17519036552820134954129013256617122833508712602], [42168585947899894628191909511199595434077283536], [-72513394613445877085862117528305750001183280668], [-44650952370125505015860144117199664362805009930], [-44098251392348366026710011034831921261188061874], [110097559135799891699817653800365857774466239682], [60822278044845263586873115228341694674286371140], [-114367367052634933316450668800746360027412541170], [300785808798902193274921677540716486454722202], [28436272861079754549568166502806742834660653756], [-52388343488071477147238557526760153403780768314], [-87333798126449251045198449528787173952878851458], [114883816950022819547890769648307091868951394932], [95748086862377051982328363617949369838602708346], [11859082007475973769785699537427018551482120080], [-78617274786727535137116211256148952787539438798], [205016247922691783126191050018573656951650819016], [122978858940928288346306198302984267393085639292], [-127035812037579518699940911306821547063441602450], [-142877902157734158333773780172911385149975500438], [-128549194691227996980453249193043259181190702028], [168158947647040166164002164518607298712658432256], [-121116814068067643826026429479238795650875384328], [-129214225868883922395258449406833052894860962728], [-385032621845257279231528413732948075059901021418], [-143409107779937286569240842468504961654312810548], [106763233043402664411655295063455682835435506832], [435981618921433383360647395775863100046611162066], [77262749645534575524523361301261465270589728342], [-96747470502549995187331406125035430923280103800], [-58420758710267515027402686975691238327413506270], [-280913990592582158785479165779838413503507860018], [51012410949231756050361787491048240295338540372], [398509719954455554046439136747962883912413424986], [624089820520214085434327914678843141549100575212], [314312027024644752325034747013502176792866537726], [-113886217709648738167558310014848963838011169410], [-771740554344209590341673909724353908013641772048], [179563809318773073143797494855549269797472791446], [34784008040924635296931389482658126580407216060], [1018004187336730752161235034276965056589082251332], [182800565894016242145273204475413196304235868586], [-1271825810758964441541202809486692045634578928978], [958540256777998062658109953629345058159295455040], [1016763137636266447429120211353794082258190902836], [-926583628945019335867137050295130584738569982628], [-1512193386303592577013062485746108509336809699678], [1269144558719946336412985452744385684436773640492], [-561422542140223965268343447625796474946864947330], [824172984682521827559382239736344236041293835800], [-997773883329576600641235162452011438332191185834], [1184733524219775548116214728960357692951053214096], [-723237902637436674984001776972306723323333590410], [-2308582636275470778950207864921335024601695815678], [-106934728087094329641728252908613714065201789084], [-1501502581145017607365811432595901194590845592088], [-1148579999841179861006727532432910341757761560310], [-766001416498264075515119028437908371175392447660], [-2304001207344310834585396924768556956898729591328], [-3025081941899719624920943891627222104091657262014], [-2039505668051298100529845190266589532202712209710], [-929858373168938680696368478732507686978030008908], [-971488777260256386629469321877091834609711506438], [3265808693878038598757393928696201795785161138782], [2732112368706671936928802715735996636715171981776], [-1717307716264845094974910198121831295598134945174], [866267468426529775820379820446604805998119266162], [-697031856682551556806408389423299996726673808700], [4005818714816731320855241425949611086135419527836], [-2527032631748152416383342136136873161178400804448], [4986120123965623467616415606721002008911037831206], [-1759215877754475111823239904170436261684315414018], [6652627178958022846903833776252505082202520740382], [5092238012525272124594930919701287103581814864720], [1465304503157286407648813822744714802599248345956], [-4371095070320975077490834302887748517810754874708], [-1229635344186748384881430671088164768430067254308], [-7685874280979326943995262865738038129928086730610], [-854428442984046994920309598418743312168995812574], [-8279292734774417302722202053005308263921734543158], [-4206549031794455098632667002303229623384011468608], [-2216892197006535516336279606551211824271574340794], [-3381255523661498251903613316930721141724690582598], [5767210525050760113841051530694914515689778620710], [4463928138641599353686877299810415314672729675672], [4153040014334561069917987169966708673164795941086], [-1562338350232634639142912397984421208566838566940], [5101061470148626780778908780612926099853059380822], [8813430747955502205340737205666922467155069828812], [4945527298642344366160503494867588523197815777872], [10204866193081288988481682451134389279812852025942], [-3791096208341152791454538534939512053643573508668], [6169935637713025186796251802430803436081037004522], [-11650250357189246686855092770997300590905746283698], [3430492959252535846753715472954548151461959789856], [17563242684840172572625634804231973837821607681830], [-4118062621877949733678817799780125442120951692934], [6707888531695910044149435484600952738348164384800], [-11788437681875735979639800333513879899379911727988], [16766755120300538100753761549890382374481146604562], [-12975798267342293920179891326130729794089270751304], [14894138627417717450828948408031706616636241496982], [20085094437539649954403045406176593211762363309482], [-167062004949906178492763961309881317318917397488], [5410998860862040529032000429241875767764902405020], [23244678932540326130639369001150467180293895700932], [-22267079761162098971769843835105358224881470175094], [-22679698835793496573654508601057558081822934467858], [683544023581449823309095090456547411015184755256], [13895206802918832999750162919985170812442102247162], [-3919387838229393247888991360915835509740720860828], [-39732881347202923965932391805091108604156434169940], [-6710079022434564204293271346544169657807031207824], [-19427935620189130649171193542762869631240852913450], [-45338416756805957711141720497537751465698420385368], [18637563682451653645081024655361416889269419616462], [-10683224900303869581948476952878298193995772852140], [-21366092391816355974206063997233826655616181307488], [14544869788689828277677956913720803476042345735586], [-37981742818547198922364607778997081587710053964910], [20661680583771122869505649190892781374706037383962], [-1168416831170357735223293989158776501820750069858], [-11403397245297631203482730890963265899685791901174], [-5165151415104377969792226583312991846132079488248], [-57069620075257902248427710299515009096166597344798], [53712644663679574186422802596107621630941339526180], [-55027713300006331512715057858095771975137960407704], [-85962948114951853023949271209318812499100071238368], [-45548119448446693869681299148660532371702005045338], [-59745259852533695487343101851877555089826708368164], [21208511333557205437035805236323199414932443347552], [72586771512570218911425593711379199775507250640130], [-57949569320750148791928613665778976611285775745594], [112302861441029774328183992019507075165622216063980], [-96442624599749507796584451255946648836185988424108], [-4625209978017159217347479937503499695812106939688], [60114249676989403289659836536092041486420066820346], [93893979988737899426212969868076624703523986490480], [4103062496945327259727680667626594464736836865450], [-59793831823396851591460812982091236996877009026708], [-67312827070632529526657349998276535152821327259658], [7601688401298641830927441787185455786226447563950], [-93060306659817749791905117707734968736234107579294], [104396225631530032901304792621305916172856858645792], [-76105834876680176914581868267856583239294854381158], [-59604850524756346273992142836517807281638387227770], [5867187387562613944512019281097832581742871645272], [-127051349053761160989545351828853070536002602707778], [146226916253576337268530548645545826806373668718802], [-168999078322369291510458057307268985379084050788044], [-140458282359834563555500621291371272618862896847420], [199748865203583164017309961886210705780569966314706], [-102988838206255360225037138636001010055140004968938], [7587140455380456784450420613540733487337828934876], [5576789876934626578219873576364626125083867989412], [94547318851453852980197591278779789026850155410442], [93903763484978045004631077015238251858205031639022], [96854588136407492992630059835905131361856803518400], [49783409584518684223850842252333692330197610671672], [-36917003973858852375079887196680771518740309526478], [233688745984190148177980854765296624248900159337336], [-68992648675964343296710765084659199237518752356290], [72051344265495942949563317100965834130598491825782], [-274667572539280416892761134381130093803450410724688], [-23701969358959683049444964110971023361677241466500], [-120996359959610981781404717896183882908317931990934], [53804525959846534587811801378708781811519360791502], [334695543979006507112233258960097687933511305614356], [303440012580905942295640278319525440507155582075130], [-201385043780051397334191279987181051232636638544548], [-54072607447937258310620187449014965602519830992360]];
    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_c();".
// 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_c(: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_c();".
// 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_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,30,sign)));
    Vf := Kernel([<5,R![21003872250, 1]>],Snew);
    return Vf;
end function;