
// Make newform 6.32.a.a in Magma, downloaded from the LMFDB on 20 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_32_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_32_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 := 32;
    raw_aps := [[-32768], [-14348907], [21436113030], [14604456549536], [10293018436866252], [-73352418613693258], [-14599256484149755614], [47146370538017638100], [-727167447999538420728], [31343797618972430901150], [150548795843298856679192], [360361082662561239603086], [16616080697398882105513002], [33060784909490450111860172], [61933934106405897343697856], [-753991691873135452567642458], [-3106411522013913636622558260], [2446176825940392745671052502], [-22293547991756042337290710444], [-12095165711071522216617287688], [133729768312772750234649038522], [402695267744002369245363823400], [402683556020084541556968405972], [589687228005393315676912352010], [6740800075089364245567129127106], [7126068900528997321895168037942], [7923139139402705913712021087952], [-17928861615687622102389908062884], [72004655748493756995948255647990], [-56360011424726719956617870599758], [451474379948499567129386830021736], [-1048664033835532705903735714877868], [2544939983257343638754402283048426], [2786005009882369161813270079273820], [-1610985155397837728538079013237130], [1106470464073515272914133815238192], [1686088560307080337753897573191446], [15642260876862998959656149425849412], [-28118695679694041430763730040365784], [81560409901886592597458196019935102], [115890537089696969931279468068198340], [-119309922857974004792498166693412498], [-135496173143351532224676616719698688], [-220536705503960199521895378822622078], [-128549481234883210676033479808054154], [-393945768743101033416436727756206000], [2082045090421887016555935837103107812], [-2148832827936809417855127903723122968], [-2384633244191527553281147754202467004], [-1449514152632973546045531612595496290], [-2611513101395228266358832819498696198], [8428362153646722194732521956629992080], [-1598031246957563091847216571713292878], [-612003013710526021321115829701564868], [31475778547126245018017260111593562626], [-13369123331184091383133124065691135928], [72298242193635237976423033383330418350], [-72474858182450230174960529863472784808], [-56341514721901669461534718368687078514], [100632117924234973457981456976172803882], [-88629092364929611297416260813881511188], [57476680876070789028752096344994460342], [-537741731682904354412174356188056909884], [-688917431917541298674144044137333275688], [165434570974222405682514612996045061322], [-974451946464587307727073062207616958114], [902007127314234686091280189949916741692], [712363109612364670038110702437521439346], [657784375949888436712687313508902343516], [3524195974316981628980896703312922763190], [2700317640269700585362934677511746027202], [-5488383862282090885312635408837983668200], [-9590029720807268253351535816805022187864], [-31521588225649729453397621512743921058], [-3743519837585437131002826448246266945220], [-12225998153298705963676459071821803250688], [13706771321331456362639656198883527933830], [13117268647934676593840783381557946463686], [-11552961467348746636479243266314176298878], [7584361274170168535146985945330031241610], [-5545838429956395497621314871421975473340], [49631141645341548902186030764960635034622], [55411783328537333200190787816143473830432], [-29530338579950505430258628512806256487278], [-44573534328849842366813160242078358224800], [105195784891558755289520811153225891489852], [-19380701905847933112251493344384794436430], [-239015518224639687462524053839115625279974], [-61599456646105583084425195377746269939938], [-360809467738719236595959548822358024228008], [171508841473233321429620755064239774345716], [-203257765282878874416975896389894019916720], [143521262534666346426272436488574527274176], [628663545316442892221893481269921198263132], [1053444558796488086776268713629444636354500], [558192399106893376272558545144099346925032], [-1152200199865569436484514798222936117756450], [-1629230565149485233719973575252609443189878], [592403930799145891128718398563569063409612], [533464888574291353072249258968085950400262], [-3588998961543680198171362264590599043811804], [-3392983158825349351017476462593902893075874], [-4164106599466487730236516058768726975756108], [3890284615649159778934937253249626057584410], [3401599409113793536529046281575146189291692], [-8060845775004202810589711974324976626843774], [-8899659688664266201862516545570732842462084], [5707841611620246874339025276255655868261842], [-3029458516089119973094145164413456510831000], [-7317203424198395963744480166765898805198998], [6973554232160609054439796741403863176962696], [23019638480113666575723191750880689191169582], [26363867297648272867672349761008210368383386], [-2050065225940731593966404197731062731206020], [-16264762799075426637158153014945523792931568], [15214329961773663729858079411081225038718002], [165963209633192217708198302127137300139332], [-19689865519804749534122631000397054861555464], [-71408123046255611711045412306621457418967618], [-3001972219837490916897043743065061262275900], [19459046224795813658914359301162770733801502], [61948778468674406619478414548999505691839202], [47846255069282792075661582530443005660156486], [66453950812331561491005420250202983688736972], [-77800755210364748527551306519157602746315308], [-61246328317861696148167673400515375601382818], [-251246553878972248742074601061304357398936130], [10749946814486505504693471815097454834575840], [213555766665910816243270367963871942344750576], [47675938119267646281199518464630463645435302], [179944269355788505379439204571945583357701460], [266378817975013638290830173040224444613637832], [-82132926226246319976407419138866247931640568], [361815551718143473529086500671324110015414286], [-766901219305156529846916813752448737864858118], [485806786621066395341650365777971110201398530], [401574553718351152171987324648641909990034422], [-568436001004852626602505087113846260913134924], [-275946245851739132257277340082110839271679314], [523292178908560927780335303390902724212822730], [285942814493211923255589294255230847643567052], [2463180134547713681195469029496425043169599942], [-2091542099125338773668920749884064094862761808], [-633439791312505379422758168244492047639818004], [-2010048769892895976333155892443045907895918170], [1566695708230504642792820488642344343135287960], [1565485243165410364347525191589365002799276702], [-2786203683171604807342894739251994009478789894], [-1279222748791964858530958432876229902571750820], [-2476230122052289842649004240137051165992577248], [376122941437647748878920469903921915561340646], [-647947670046353505531672589679169110451731118], [-512066719033133801364795497320662284671437868], [8118924779157852250091049685427504211066319416], [-6166925526012276396802991567106529879313336884], [-7155008036919279214736031930025627500649404048], [4729704000368959509450441177344051169906611600], [-4763610798809322855502002082455597710671230030], [-22446873699933025327780048653665522284048235494], [-18382651152476398782167978784630947189584706178], [3458095142173686201493058523773332652882712516], [-19743449878790511221547121932937849284208810278], [-21090274153278304580251094437062642243788967184], [34540970810949820404878978292084368594851017132], [-1520597787506241998034547966406598771710717694], [36600391910344355712814265872060301327932692312], [5914528489696573421219060985693172358352707192], [-45063617534616700915143116162460027070159795474], [-21927355580917343812689454114797575813401333390], [27061956814703818249201005585481117914317295222], [7205832233635947910245850800403107434319684780], [46310556851518724257298191522788277211996395382], [79975444099566395387432053859700396878848563432], [11565691530826357418035201077485513292956426042], [104764924623555467876403402064884321634586069960], [98702509345636224326974542763049409528588726570], [-86956948364201891310588346140854537746488497428], [-109336264724722689163722943039718251326179158938], [-121363941715152691208449017059864851352139696688], [160108523742997991894759315065479981870380203910], [-204719740011141146191675809921702892192155150184], [176877345534504368138188937216570322884412810372], [-49266675827436713451032954475835812762339466498], [-207515535966480123550354640531350570651958083974], [135249729472767498278351622765573032094291989712], [44764038859508977274849349121947036656965373910], [80282912607817923484846876593420044538819490406], [-123933511580955799371587225680053657473121717388], [191402286331881582704213297673150167835448825850], [-512341829651362654143248404228622863373357480448], [187487569324918319284360937454332007765904228802], [-41675220672564004606576968450043964177521675428], [115604724900881441666438844408770765347945102052], [-398050446342647547740753201176076718719474233938], [-595863651994968449483771072525345055754135059084], [356183576643426506045663352265290950727974362842], [-944373772186034260813759757773292071443090987118], [1122538377789934418200247666974507761066237268742], [-1114123179321762794102829993039109533042719259774], [142593173429019648280313341238886683333500691112], [1365579360966244410951037747832575001536527869790], [368422263702362169053710755961863053701191556952], [-833831701105976646243265423055346424450103729074], [-710887653987441713969057882946239453809284929950], [-466232981633917916343574145453184802238858272500], [-1870105088073320320448875623453750700453452400674], [605929258097319690791534032164226673387901295400], [1408397340187396616194233294407970591324697467972], [-986811310227669849993512739502914001320834363750], [538168612635014337224608900559727207040348767692], [-1445408343718974381475044989860981817551706854414], [3501596967402868832514451299208863748048228543062], [907774333544346255465171398728578876372294349952], [-392535011878153569159355008448437604221381892884], [-3283840824111458483077165777109937053591101094280], [2032861526706205413651057035664266458408141788122], [3008197242412272600673877029660716351143271705416], [1609083472886407313140168556913665245441229377122], [413243134244263046206080887200977937209085492056], [5527018771149456336850487665991233623496694237262], [4103739867317002011643571900537056744803071392382], [2254603502381184585443743261461076557924812881760], [6189179258058396311279169772874089224705048011730], [-8522782994773254557095185346500596738527582601128], [-4079396727996072812414581724034691671826898520684], [-672894158914574643279807439382623835400501890530], [-3987961613400231654830104176229454185098957394038], [-13718574195213937204944460837460984852847272621040], [-6306163739811083834782949472529121329704029277904], [-15979643054206085505777889554067297082720685611748], [-4769530040630123982604598398625416364499982968778], [36464318779268162231713451596900295466364586420], [21707353406205764102159386412225130571201929095432], [-22651575849576593334689132997688613820561008930118], [-6448055486622873244985410135528777743337411947508], [8995997688487294393955210454455454920936057460096], [-21800147816313563136776906155470561756498939701230], [25438517647301245082731823128305454103140906244022], [-11503264174103815144969348834681752483555976058820], [-13062683997082870276112863965077369043996542651688], [19846801034364110638783018656107597598937934110452], [28785919281752544404669197238454224339769563805932], [-30441896274423892414361588781941632468718500989088], [-45294771752387568938537577385844499932522079958810], [-42072618966128730986889102247052060160580325903118], [-47444573819414677224307974581888768250211733257560], [28939978547203634377845469365496301185703761274456], [-18471894536837147302587973517017692724352886902508], [7284793476554395467272875530226562449835099322140], [57091431692274490680308304066836849481236422403472], [58493199291978024062396506079087088882962848724006], [-54849422239226262199760858072495863124450151475998], [50175043806985077143471250257884142591342503529976], [-17227153104299183421427808440808118858513234316870], [5024090532451786468315811961520849819347739981422], [26151044683085265029244872680004390327256972276420], [-17823201728127108914393107231928896389785947522738], [-31768702337101738103475496299450314210376643809844], [101892171982921772173200463535867270452070645412246], [115345006658750008201587557710292739434779013881226], [91422011373015771877031498100896900934304332730472], [-101886124324896352524860601516376840525487418266604], [-7522522858613601687189164737229196011254429777570], [60185148624212867175799102806010249001031627724502], [-215573517269705181423620417568956775061820548696974], [11594807461090732612074701661944174632833097062740], [-7513506709543344753414688962653485106246540181090], [-30445754822750438835078656420520782298678214414998], [-151823487674254250286266783032399184512130265339748], [88160683823908545008501889003598836145326016078662], [-61910659183197132934077060648541146312597644326138], [-249623098359863194855735504896141399766587719184124], [-255638117174436696807865591266581185841080477178518], [-32083176317692110921098165212094486722466149250440], [171489038107467140479092680992171986061215645033746], [123581148434441873705016505184157624127327439867552], [120699509089312834205884553902080914937109694758236], [-46823879348715186109232182663664482102473509505130], [573011098181206248205488201116468780822870236355642], [363892721452591668279211762389823479773522805888132], [343100686650035006511660103841765373135956451575952], [-128004549858380575917325392176776249672383361323568], [-570580155511890295070801955034748893882601355009144], [390784046607561552635520087089546281790133509668622], [292475868551237068867598959424841507088427817869036], [474013086576542629270652541140261347903453174761072], [18332065161218209463831112431758858501190747185682], [-629530684899115882022653847897220805138287321848874], [26614516941451146127383916936275179622191065486640], [667261826412779784318185284780991830329715470547650], [-578444508924521340735496845319993966957702240070178], [-879958809806745061250308807739222767799878777741884], [1306616197040819920394145111528770480593100125879722], [469827431409665650174741117647512947880263252422492], [-786248635810028526957361574604078306469185210109018], [-1416390047115793262012555367813787389064463006546610], [-1408974603695437021384489760154364416013632901693048], [1096108814906933339185384501489072541121208310296422], [-1597353942313559939442645569765865242269598619444900], [28191892537909010286821093409542072595124649818916], [2608069265829616995288527684085120469612587183020282], [444634291054611948018339786958251501735604191243006], [-1391437038145790404904979698524317298569561510312760], [1004284913052386063914903957497400659425737839182052], [-221407588886003658917742541063504179358130111864068], [420493910564130116894773099661778674062501458258626], [-1422809267508452482102599506568224571719877317322324], [-1455345501378519281837658675877036858076720853941290], [2772804847209895715074492234811558391203581060309320], [3483670228274632396404760888729684738605100732422542], [-4542078470925296028403949958385118459679054976435248], [-3256262450673160364161966603232235779099554163878650], [2887122789111224010652225481972540821208463814332882], [-754550119755881437040129860706469351988486155112348], [-2590707576473392261462663740712244536702590646586424], [1695918193204264434026686638061484714851610423170010], [1224130986855231531374510745332527659725507374523940], [5076136171614919719572200893225621504809199578546832], [454622783274760348935006394989513147137122091176322], [3846074901663374151421343590653065046463009769181330], [-234511594701759412098741611161361553566160284117788], [1514728635938611671484462499455795494464793661746026], [1489826325137425704990690637846024986486565415923422], [5418953697185621611972819866780839308261295627332952], [2203118704251023802376860908176455282368463775212522], [-8500389480757559564867597724707006130746262204321358], [-1296931092309502477418379718851490489890137527734460], [-783290785818394012901083524309822775294192169074948], [9304103207653797553754065185982456058848305216607776], [7363215422790980678564254377717182476964415927348582], [13722962304575436302430817397011187341715054018005622], [11138775410372968856910395405712580278539036889931566], [-14666463808101892481842743240766987617686712197333560], [-4537490662290983451610995608523941197457581331738508], [9194272306925316427949062471383045942320980840830812], [17602974240177593290432277644569243282513347699998716], [9149541418743537729665897356713006519779083362176150], [327778796446643782604064368700554605068728267656962], [-273358144568230109351826400422890591011548518115238], [-8529660565487525755547359392354914240956785330306664], [-13330308324088265667255111754802066942198251714230658], [8765693705999513082135423486844639600739674662187866], [-3333542206809040925664810721754194621572438208791210], [-17478771453332631952832334437982112666749142157235568], [26283949827060544252846702535661828527502914320494462], [17649815030400501461752572802294774557560936372353380], [-1902065528647089651594202651004162509760640148099618], [-14395946535059442956696812105266252375278503867688164], [9841451795749001582899547941253725622302599486224832], [31344553362663388235980758082508598717339621037449606], [-36018687644127531196626478883566467961663846602254428], [4485384860549675647368762243364509784973682183394586], [-718523245658121129654331893048734844209752553573298], [-3376687928638994124845332157372082777915371785829128], [21335606606581511573710470360192414083863901732501150], [14533520617375928985227350391077268441738809617041322], [-8260300793950987830218941837319753856363969469464000], [-21993477067157162057750039392793016928587956608337508], [-17077764548817159231347206078378454837443060660052094], [-8716219896242162390315425352706201192691090086418728], [24514426826351013730502609036032142871351869142339566], [-19912628635840679168962477553518590287257059575261478], [58380762598115385896901822287903004305092460188291536], [28622120149126253933375344036712886384353902795261500], [49382861867191631982700995653859291791462783906914196], [16500098352293737757002234457748407804711739083871002], [-59897730424222573727915903008920997489066578285610674], [-10103854879291997938955767458958747253005717062666688], [3344963149164695765900019356858152785937060697211242], [5791117123179458293114921754798454125547659068281732], [76846766775017332944696952892972750920364253024913580], [17005847484613037451711051403922353960317062613919152], [-38846037422279400423949441783392770363134527813356250], [-59449896245514989313518314885253961323348301208281328], [-24077163756885393396618554244363348838039546629583354], [16635801053607908145497561995823994253546657639262100], [115236686485680755145149026871939485755442364285220192], [11302361830650774512972019329421385385658404114650082], [129590604910133506134901513316975492756247949106270370], [-8810715054141170701816127991753209940959236285932694], [133067590453791959744688468074093983654293759430294062], [-61322016205473901375007799980205713049958632355829718], [-57336266694995449501314540009223097222483213525818384], [-160716780526302695890734439264756305071943915547172574], [-185408061798910235117052449685730534135066167974205340], [63516289540398777954761794030832235693617219470771752], [-17712044123000930528253389094959246815226612961198328], [96519838757657179613091226469217897037543967195701166], [7599565439063872752721962882265855537696583890673612], [-46289073480001788963069739939872798649464910532716944], [76758931548310178880130779689327806479589447952307650], [-67623376778386553088297016686992468453016739343837658], [-35827319828544566206470730604879835029378687503622820], [169480112411191239255769371412862904003592720540599956], [-54615958953983847344482888445691433843648502600828808], [76385261402486995681664262342378382667901954418201802], [86320501552573505960105928558555594453868455896288840], [258554900606247379712668494753690564866138577322338090], [-63293392946625345280515893553101397289696991062208788], [260773036456686380136710029433623761069874410487039062], [287184536762022529147386964984036814717855463379030550], [-2995353739965275015749520127552380655950689373662638], [-341304449724749099991441596551005152983837464175194184], [196673296111396560573699490352660740923498710524976826], [-248947984339282858636768526800154275221156162434791050], [-196282715800823594766315174209447145310909984275873568], [-355553194028478638902466625837165553288915157362473994], [317166116419612817189799623935273758145648146649069602], [-86346178424273192560302265466685186469285006538723788], [184906609337166317448145961878847644009094031453187140], [42303965213246506234273147205709714182299002179513522], [-522449306820464759201883075926518890821382534566068074], [-496894083258598039195813307537934110518442096953346148], [-433565495155034166837315945923676916214668403233805308], [531092824928135869129310691948006251574104494101396506], [-366013994026474160270518930596362535413562551166184818], [-629299468084567364369936120703370413410983030895919360], [703818174209779508757549046231655006364173524105469696], [-83070550733342480009785193631534216409682473008951294], [-78144371461541236381586606382381801751663416512975448], [-13569781213623586757605535264580408324232169551437810], [-59321046809918937503777232375343337790618362526811954], [785733710947610762489746840640178854191119389362064016], [416889705308381383012784406975288223031868431407813020], [-641829767856384070271417936058251748760690944785743558], [-71323648131392767445379972520855364116544311610465874], [-1097729838292620015791714864513097034032851977515733068], [532338064134197523626007217318626526508052758101393290], [289637957512877744595759175204443360362598339857103452], [254600483974688821162210753469079774591179274811875240]];
    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_32_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_32_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, 32));
    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_32_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_32_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,32,sign)));
    Vf := Kernel([<5,R![-21436113030, 1]>],Snew);
    return Vf;
end function;