
// Make newform 2.34.a.b in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2_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_2_34_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_2_34_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
        poly := [-19957422, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-10560, 21120]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_2_a();"
function MakeCharacter_2_a()
    N := 2;
    order := 1;
    char_gens := [];
    v := [];
    // 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_2_a_Hecke(Kf)
    return MakeCharacter_2_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 := 34;
    raw_aps := [[65536, 0], [4178244, -1], [-2666238330, -3996], [66359547937928, 896238], [-79052735711361588, 2213453277], [2491699257749546894, -13597194492], [151232816263289425938, -833438065608], [1117795600232964348500, 13790479962267], [-35712280882563558595176, 63128735356554], [-126441981860200427111010, -10405860886172556], [-2160042970558103946554848, 2188390162942584], [58013142203621116497628838, 704679249787856532], [-83388663305157338803342038, 5060866057679897136], [-18363088423559382158483476, 795637191126404277], [1434766475737112352467546928, -18059171324272980012], [-2198873621387531314157385546, 12899519303831752788], [93793426483775442692922544380, 1543364398971116671473], [232232889084698791178008083902, -421048866702681721692], [-374729143498873764286559851132, -983584506180951735921], [1303726542788652627509725714632, -32010300149461480209762], [-2602485858174583231758577962166, -7053718121455510850472], [-13279759580524671270656464485040, -55615602681639381593268], [-18531253092530988693232792389996, 351831567447465296653035], [151487323039834721088374855865690, -501873494660051370396840], [34050157158299135610743930012258, -2406517813207010596844520], [-833637892812995006419142596325658, -4507472531842742669471244], [378290232870295209170780114033384, -11084829662854801398419370], [-367161024724573666831709655090132, -8546529438153053124717051], [4136133199371603646266179769018350, -9028672346538851238257004], [-858507591511932267206901895303566, 8922163395720920895998784], [-46013311413387048946583345727375232, -178356275913339935200946016], [-65561733407410376324598188107243068, -910853131013489421021226689], [105206252348809108885576118423466378, -1437838083361274863143253392], [266831015216251900095804641789699660, -895363828256047288456545507], [-851106883984804100433457010829743850, -2751429767571716883211895580], [702297119810457355215348553574870552, -2230198076303977921292340630], [1572776020781908336991594037989339678, 13449974828703773356729963908], [1913386584999565608092857611999869924, -24148288016101140595407137385], [1585402357025169206746094402461814568, -33187558366857500534030957946], [-175012404549855251298371107050130386, 54804433749060077850223661220], [15622560453241767856800286745358028020, 53052674090935524758731918611], [-17543293423311438146524263721473501898, 85870491949313403188616881604], [43344451361313259157083828905459072192, 228901977945166196321201649168], [27398192884001446484794090863652339394, -465529778413640239863904862760], [-24884516781522251235632504801508151482, 492855643232609732900186495364], [-6998686760105940408956307220276563640, -106017499096133831441722809666], [-122572485184694480737688213362623967468, -975019483967550047926080697845], [-101312136322753469378811645915848900896, 9819263375344482072349531002696], [-659199153741446637295521281139115880412, -3237621509967349739301833934393], [475708341885946077430742140003165307750, -4650461145501786286555076893692], [155534422555814402996667607476878841834, 19206968799661180211029679010072], [-586071511398031618907158256362095448080, -18586704294992568551250317085468], [1545292936292662031761360377016457825522, -8734981859292769487669673877320], [-2957942449010046576847435731592081646148, -11016971701342289580417196626495], [7261915877400282837556972382236385538, 77938936921386216784234300787712], [-2327152487132771679647273828576487062136, 6793124715124071292815711686766], [-19355791847540994831364574706850121976690, -9935409036040327509998726173644], [2985348070471971621377329617294969627152, 54347932072862739504414194130396], [-5882594336713028837326255344626719689322, 280991436928612709808430887431508], [2030960845344149530141407259993400137242, -342386647199094774397402413425160], [-1264027502871310989421066407418262763556, -354733664746010008653288654178599], [-1779944591233743956873403175072782345306, -61809294093022418738463560467260], [24159034744357589303057239018401273384308, 245829497673955976600338639514835], [-113886465039057112063541966458783114196808, -1348686200952624996166520901027006], [115210974841861450801230816687982407325754, 841218105629882077706523058122672], [-168005273579455513158705980618035094850882, 1462119402031768163610164508779124], [311757630639992590609217065851219044821772, -204821451576896994374743783541043], [153642656460410857440189825556948362539858, -599569169660429250621924366999840], [-828208410601970248461514262368123720084452, 4202835051616024506354104448360681], [-691225887963209142795086654115880831140130, -11071860062818666585482197524425132], [-599260673586360908846516835530223363455646, -3412924463147532973881164030669472], [-244761067590947014988563788951977916896280, 2202300845808736198002000747752214], [207217617780972116708344735109028547864688, -4086402977192901730910545923041148], [-597248253892128129991418563261424685528586, -36926791180546373862811618776888780], [-3403977855297504480655838340895414443665860, 34272225397850385704622854967299169], [5810445067201969543132992080783432131123584, -1269052309956437400154713426746208], [-2342103885338566555079515472947849669149690, -36626910277542656425846559252564652], [4567640997811548598371253687478977453104398, -28000369825865738184549300740073324], [9986867078486253200422556510796431124418962, -68653158317235036444449555949363336], [-22768959987181044409845248616363273996176230, -17272807618994783010662538791250576], [601086048514993989571808806242263117939940, -31263572598112250517845968028192457], [18141353922044155084239291153588366229914662, -87547326573674351586283862196715740], [-39126696809337732766028506145441349022966608, -75448865890754203037019478488414540], [2320577150546629177643523904121732199552434, -46672334168590290370569378963575688], [7737380363821698972657822367821138837721400, 221562370438488259959750639856014114], [62012805006605606546091005698248530083504764, 268954293272667628136268896335287153], [-30664830271650712545798672482003214978039870, -252107233166548971734617365246877608], [-15632894941329685622807440652206511181407542, 1298549183551210833468130939549722480], [-3716303172734402012701120871045244812157618, 845595501792895056652660273605065460], [-7258721233415250860231198345757222997451056, -665955013310471837444134036611392532], [24848491167940523621352190135978718843496468, -119659962983052898514303270313308181], [-74428472267793176760748987812672866971660320, 671030885494559025365512159076465160], [-260200653330093760258233213660999208843017112, -603067385173919284998143017190618058], [-48397429388224571596594874285779803561398868, -403702231195537910640234726814052091], [65939492373676464977977318825203365752427060, 1969606756917855149486856776427463299], [-449792475219935230407773263002861300253145736, 729678894062008611694578788958940242], [192298567799868685068692715611906588416491390, -195279359778440900282044913467068], [-456950955700879723940794935317516158566485238, -869496998949108547272900031880857680], [-466808307077256604207673501494688198407317556, -8008453093404635791085958842255002083], [288560171311294935969884237330489579207510942, 7481484729732466664003126543109737508], [2782317858140626660392645765982878792127122788, -1810317043432083453246377580190286313], [-285097920572373580248394129727535147332395602, 8006401441270896773809284567695760516], [-882102939859094859718513381032737801489817996, -32928930037925697547126066086624541293], [638315477202911462122526107136993297871026490, 36371094478459835814631533143218899888], [383526320962931873749698165288438555767606012, 34357561304366571633530226606611620305], [4417381235657573735908264505506162279784079938, 10002169740018021654706332428493117792], [-762132847529539093101464969210944079177094132, 60850214500228920755971496692125832269], [203644616799263918580845789642591337916255314, 69643564032925195064710667265276186048], [2424864455461489014393766834830845267390970840, -58757705186506155800044052793577422534], [71522635755414076079793932743442798367233882, -8377772192508025907352465167250808488], [-14466008458806062107977564092672980178857105312, 14076160138511176543467975788430209832], [-3887611223953370832334873728463190959542199066, 17852358952404395747915199346767904164], [-855609032892668031683733758505547410423393942, -74159433890275101137483211355414462920], [2547997401840580636427387368326594032875531820, 3519744477868726972088730810926756805], [-6863642220562511962625205114092679451714941448, -190806475646320031952424066931518516686], [-13131890709889893497762733393468254836884010878, -267335076473736059089482451101458905320], [4924863990554675151881297009290717741727273924, -185937418471367340727716803886800225793], [21231500806170382160825589461673234826472677128, -29290294323535379070381835310364644082], [8023635013100255977433959987674765883879421454, 215609898560877745964176530212513431668], [-44069025202484039146450968129682297859201549100, 156842268832484143510168517766959830491], [-15829910968754128668552199789012216053267610858, -310462780225664508591320035929221897916], [54502078886224681713070640486388317538604055714, -219754205441987483289280842664757427240], [21829501663736464736069496806090916021904871718, 394042978407012337298881424953898880084], [-20176465043598648889798939935427023732048151956, -115304306871433304191988413787758904619], [62159212189386597691290209885202466679885475572, -339468545351614326179941131035135883885], [-9832140079954282798457601581947182144157614018, 1069720968841649082761174597368797270372], [-12601718155139686750415683587245210083044596410, -1695151146781483470327280120993740162348], [-44138068343622803408484022640560050584560300080, 1749704602419283499021514083345658125100], [36705947444010636686600518060161903970615690328, -2443029939396764562234689136805787134182], [87773157027598124444361588029181777324813445214, -1012222923046077777865093146306935684556], [-287445779030517057086461454533246555689212448220, -480767494730191163839983153161903897529], [18036100444252492424213666705483165655132509544, -812149715288291023763422290352074890250], [70146662958116536979946132958723612883761770992, -2739694642104229568264856278484499924764], [-260556214744539319208753738070292722355332327562, -1616364360833268057989024206610198256348], [170648300027924048750595476353644578626152288762, 3016219899827210279158432695215849829552], [-234967253914591674574756880495322911843433821950, 1819243965766402828149539934634312133592], [407952594893589611162128239839814820807106510214, 1723558364686482236610902111604518039700], [280722698238124336996500698482241841676916774228, -107478026894445048115337713125371533317], [-264598574129815858383883530007841994890812574562, 6098376434847386572493567545305993240132], [376624589375481970096269386980029874921850370090, -4739870159790214291171597798532144443728], [-396705549296804674806630155595607704313114535188, -5145488389683067538939284463229604176363], [91805122708740654119785337706679559163674141622, 1781484396923310767167389100064470433844], [-580063270983401042364268524889441934328651322696, -12595245663591420089181073209840187597374], [-1804606466309971628451379252846310010296583246852, -2270242311286108187291869331373700943919], [1095435196430240875754595117763300423613217679550, -2613003177499864871367972609791296522812], [-1058833024128740113533648078495818527487227085880, 13249876206327642574457492414759437756062], [-2659877780542176856443623972168598841099291992106, 17060982256517923053025611415704533898324], [2940090393157109686193125511195064053345995120218, 3028605816417157391328216847489971653424], [408525336360853342649847030997545123384445998620, 29928957283584146669332777662698265189609], [-1013168735837223380541521408851637293656186369696, 12945011843171329772315881688511419397672], [1507168002130960044190870419509123378861357662958, -20553627312930392529075190416775759790220], [-1902896774678928410074627414803479681084332361358, 34977368281010827489791449280526238922720], [2752943806868265596681817102716492925182486676404, 45729653730716489221551446581831648086915], [635430572443922272391927765630625323460053225208, -59076074225579840510842148682443504593230], [-1040841878666040353213275311694231922083482506932, 6763589337459723406317932149717570810269], [-5314007412096571010437553871239853206090977907568, 81723938717527462450050670929146682841020], [-1776402463703425928475284025420399326322955058920, 105529029453024148502266912109533331219754], [5456548606844046234025424217313745468919137549730, -109307682161337811423061927109803899706280], [9979155080895730415652538480726854180456279986858, -1041830640030390849966537456916416825960], [-912335453112377993350674099116982878615677713618, 31743792246779381392281396857463804217044], [-18569122745061144710016392693825712458455570606092, 33648797897162652090937423314043236226995], [11584620954393943795837616755930225934083640867514, 62293812097052560993994546362493476926192], [11118483296193607983509556321964718124306744820808, -164507515555087786031905840074608913720450], [11273153390152531607171867902183623089269505904012, -82649170371793807826389290571015325905395], [31573864745232702999317892528614726688496300493778, 6240980262878891750638117953732706162488], [-10555079955342166655331886326066879574225555573416, 163452408315258303237541672817674377023322], [-5647329961123292612116224875408744596788883037728, -387551261224259863386929698837330828760760], [-12257359183150897643822581784505931466739583419802, -135530120777469467661076029578660400832044]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2_34_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_2_34_a_b(:prec:=2)
    chi := MakeCharacter_2_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 34));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_2_34_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_2_34_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,34,sign)));
    Vf := Kernel([<3,R![-8884638284346864, -8356488, 1]>],Snew);
    return Vf;
end function;