
// Make newform 1.34.a.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1_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_1_34_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_1_34_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
        poly := [-589050, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-72, 144]];
    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_1_a();"
function MakeCharacter_1_a()
    N := 1;
    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_1_a_Hecke(Kf)
    return MakeCharacter_1_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 := [[-60840, -1], [18959940, 312], [-90530768250, -1004000], [-33576540033400, 801594864], [66935907720957132, -1346611783000], [-1490805239129721970, -3738595861728], [-39680574630587762670, -2662090686805056], [-680348221520848585900, 4884703150768920], [13081927026837315789720, 164629195362887632], [-837259985815199964554850, -6085145360184173920], [-3119150612861816168547808, 32916497064471576000], [-52401370758379090049086810, 201328064188470297504], [138783306511001091366094122, -3236263342715375504000], [783830594683536056884145900, 8895966303666004296552], [2710530730715625630238486320, 4940382341410102637984], [-13433707392771451546487585610, 204581426965700223902112], [-152893204817649216513331997700, 313307989464802929484360], [-2872946991706632429533681218, -63847143944628190380000], [799453168612247670875104782980, 2836410062756385218812344], [-1334880968978052357868405042488, 18940614610767754331910000], [473157160595999435482583268170, -59188764472986488593013568], [-4267599986382818234865053095600, -11864921072398352723625120], [14536302901873972722201991661460, 242837964943800314244215192], [66359733827802158132469298863450, -38025461074666269866468160], [-183893665465267863575419938928030, 5319399073608078217805640384], [340126539554326484284435470019302, -13987446288359738287625116000], [-1049548346669976180437693243835160, -5829124730760176311484795088], [-215966578526803593993330894374100, 8352268618133224626364082664], [2487966392024688857661784523629550, 17555076080357801085343712160], [10353227985537869455296087868386930, 29825884460290943093542799872], [-45020651605667368323805305666643840, -237043214665017190242816197376], [-77950002990996603542948277456392508, 438187781312233875659921587000], [192421246079050587134962951955972490, -935019467763736362925073389696], [-221978591569820301049713867971269300, -1264291719406221350380505238360], [351272726084513428370471609181033750, -1608519073506829404215089925600], [-938083463547871541099982625997059048, -3794408019373755273470503326000], [-734871582379755784334963298157396450, -18509113610828446500788408307936], [2214498028574842754672973770889777380, 5422728801970526061984505671672], [3066622344866198940679557131841962280, 33589604166942793751856009940144], [-10418722947658352858172821585935998930, -34728998318951105614878766079968], [-6751456946251614125495540626726169100, 127858018256495135183433090699480], [-10936347132839848508090783468526214858, 120607512800314320392047237620000], [19999401746418853264927419405135867072, -187274094836819332208821819696000], [-22826619723453406685401932589854226750, 266899672179525232301337727733952], [23024917193639182519251864383014419270, -1013226747506436795808330928238816], [2974870165371742335918148220367965000, 924100855633614444326881573849200], [-131557645284599234463366585520587276268, 683776838896585323502021342479000], [7170683698009413887864793904470775520, 4148636977175103093020090176544832], [-252509572456898559206258845013555448540, -84080393616690669915829833853576], [631190439610210095447029915062934114150, 2621912789603318717305390673429280], [707392190993609680756625246348664810, 639418260447900696668134136486592], [-1733503598612941644978685574408129782800, -889224234491503324504209961825760], [-1708845425865624574971093413733067115278, -12163336187979758108361802724520000], [2490501263091794955136270766641836888252, 4918329773825900393100628453965000], [-4278248148758125214685813985147107729150, 12363328410246633299975428727332864], [2065113497983696764347697484413277286280, -69618408416595121109638924138931728], [-10292510137757593577409701367379811233650, 4720561723950324795487264246261920], [8843351839429231633571516877447304132112, 136035445614217754829942728576556000], [-9570057607049088762230618892758725430890, -39933603789444117300214410339694176], [-20915659915861791959743063662210500739558, -73082505545099775056590162749544000], [11643035968639816528828328480743919895260, -241925970540535221538681420149823608], [2501940082061685758272338672043341834150, -149588544564215771137982724918388448], [-89087174660941801253198045113636689455500, 541694125822272931429011446213058264], [-116152900659148309463160961539842117488968, -984203568761146350138231191085734000], [45751864911267391632110430031747523356730, 652231336244609827342041367715955072], [44478034998097447797004596503701782679230, -1219228072392771949757123191146722656], [162393835324816047907372086068399615214092, -4105953138318932807331819451723287000], [-59058848546157047490976118935882196724910, -4618332397755556580622331899329700096], [651460345845005147287346315140791456104220, -1505979730874198541086017990232218616], [-345578251419079578630919907857052987049250, 7999598576953357555567106316797661600], [-407503963055623202294688735469866663434910, -5158133817731697793970687481821433088], [772732672039102635109360884210681769741800, 3697964843655836782718624593901690160], [1036340034621910939366527076225930936480880, -2890579113125914515357164968026284256], [626941245334429087896354074927444906042870, -11831697402846235361445410702047356768], [-157945971917340313961034520633047993276100, 47954891831466786714421923311327668680], [-5947189312965792093469039302701118926259840, -7942260306604651729602562644392715008], [5273146222171315079801992186528556333266950, -20241951246662411965664670413791819360], [-2072474762687116200149131447802223443814130, 96092461124465645872134003977058554784], [4970952251449394255517025986620479680461202, -2936795067677028775828258452223208000], [17719198331854924395586068037450566911313050, -3361493446314607614829573260445991040], [12774139245551747014196090329215499432688100, 28783002483339409555006742248104707320], [-20127999655491574982411470511430482275454938, -5314812522208749869904998975042604000], [9306340665962342638785357605543327673481392, -278972483909029251979996953206164188000], [-19327837649404040838324226244114973957325390, -62552317377866149082885030920930886208], [-22847671822592890952669566499071855528601800, 342534596898080926498748015371824631440], [38249007549986812984965053346735092496901500, -252267318096191824371975044010919621048], [-9250259562977458917513608409944533568370750, 56100432707993389283047215611548075200], [-5139626404659951653727710597039963898762550, -691034362076272294426645485114809233536], [-19536367537299775801168882419830539808868018, 1035722331614942974129865577404326244000], [-61890149114699943155590394714935034939759920, -59562687514975496005296169072639002528], [39343848492037283142699660702633935742204180, 674303243094127376825685550490636507544], [-267114889314041860189437929162241487043565600, 211775155977972651623775704997202249280], [-150759012133883233698443441560483789009303960, -45723822805794520026355292641995538896], [58767498555430526231691462986798957723724972, -771056538561681763148577493698424127000], [253870167652338261530868027144677401791048500, 702995345262078294581857537537705767000], [-341656732723509187278325096724395441586791560, -885165745334497327403589216648684872688], [-193771973031362282034646413312736391130936450, -4918209215660048012744026481602890441440], [-157630562223813270638902983098702099684539638, 1577556951212343822607518615490496496000], [1044526090460978431214592280497091284540694220, 163592702574408322609040323248174910632], [-661164534341128271001334252845137918007265378, -9680741777729968433433384358212561708000], [1321418493861095702717830803705413139138142820, 5127340496219607673530799515189472596984], [-973960789451352132230865840545248190527559250, 25303262092766729729906656019308346943264], [2772442306738629311646601496161049904458884980, 7032398979684655697423230751922806650072], [-424609051461789478547902170743371107877566150, -25457616221472111631297344146481590001280], [1339043540203870527076436672641625147739926012, 3738426391962150384296102392361307933000], [-2982129911637555870095377018665998028360940990, 6820982384018445841791435439865215636224], [4131508443593561793174425577721629500339651340, -20094082913424346830931758143830553755096], [8038978068953797837441460015628365740494752850, 7544101065842671031664399948530384420352], [-4171148144946610161604023953545820513470953000, 19921912622544956684531414921665591435600], [-822051316182665517888879312523144487190700198, 66170990480902250091548187156710173560000], [-1276744252518008565604861685002290515141533600, -86761665680766852490413195851768567814336], [4202932098322070359435614822092303383840819430, 40739361571656641971073788639618344355872], [-1116732507484374151697209248580738742707422870, -91855024569122672515833744769068661384256], [-11169515865756351088879696980497714259785650900, 3628646224985693071659081011187298412520], [5191976508387901244882114518045036507318911992, 177038265569943229531606331931573747594000], [3376442096948916821096876511042424045225889922, -90887941843884141947170278622941583816000], [17424143999943697764548246899089744236927279300, -157737244507895561834628820913506706779848], [10552900866160280081869230040831686603626490120, -219372672339475326518110445878389050067216], [-616253877627341221552165878601229707075956210, -113986603410750719233442260662240098600288], [5699080127841251492479638793278337315472121300, 232572460675622305438312149269169189575960], [-9088890040115185531465805151988060903836381418, -426601029361179922702057810785913176204000], [-25982953084815467253042330401644232024279022430, 251990272424828138057905464315180148900032], [-62905964622257980033206808147532570275611177690, 280063884009819373843003083103850766533024], [-42252592933103763703080030881756623756628629140, -492834643383043533892829638000006574093208], [-71768688110267179638722691269180032812818876428, 268070238705757314170170665523774879479000], [77561410032170808631610270152262835951447102, 970908348322059157065888864453728225556000], [48207561727074827071669745954840860621284532550, 468306292628792231232299291466483462329760], [-4935053439620440127794283939019115531116260400, -673408260459477546665346996057127878974880], [-19937169887203972911717051479367640661987184040, 1388192308996707597730416070718904993593424], [65054644319011966544611778191817883916143625310, 173042061639312407621401808803369943570592], [-42397113254152044956963861064421845144875182300, 2552648512732538824048840786940471005989240], [407680640676013680096880501821671375610444388200, 397714086587581147778101298093838806600752], [102592119503312427530142847242019008541925088752, -1137980715010292161112668774105747355244000], [-92537638267265990047442240384563081834940480650, 281470450941971204193053141931065655288864], [-291599550341422501535821300647574277491901210118, -1144831669004877269835302051499283275536000], [-211651358033600122360267989096019372623465361150, 37626747574766499283162781231931411529920], [-161471951168352689905325343575405260523732305530, -2001318054168514925035161759240175499062368], [-192518631418978151079810504795975050100569926060, -3922548058564706003449643307672900885035496], [343355732863640648944584048494152036534608167070, -1691687401479025770640534288281076979170016], [526883422266622126009652706386449729511230507050, -1137713815375564695532803827298486422144640], [-110023260989739191161930775587117330168299304468, 3114676722306729976982690928189457661073000], [7421978939262112514308120118794631169410318262, 3583818136024142315871531132341144106404000], [-168782329568150021932415960095084840448516747080, 18040589532418579172171593980001567498476432], [91207013621553434636043876950215397149539307260, 5985360114395745315664818956860544417233224], [-190500939201810227087671429750610061484725078850, -18123870382952865748311451286774641992081120], [-1526213040425095635434271817472863278467435743800, -12104022162323454634949577464768734127190160], [3968284333786413812379118692871353061518485445590, 2879865274218714507133350257606033122410912], [-1225131914869431794073523712190857439063464317350, 3262863621503473950677809943221805119585664], [2623943149211381350123114565229132862780946006300, -2398821318638468168189275981087429305678840], [-14436778706883386282250716246971091217523228320, -436980231088280228434410569526257239720128], [-3125171080943855917840211531757850699443867427090, 10109944521583335948627445392611276417790624], [-3188505227858588772450465389529223544451791791758, -9178961174008299132112333021855329477024000], [6363505674884515243996795110315627075694788500660, 14354576175110321689690733386468129037563992], [-6280989559973347763428451485588952496201385130760, -10479924662894908123729542074382073259411696], [8344160941732267024273526502125542358204280500300, 5657643944152243230049518654786879465425064], [-4186615956348459091789854405845287969653996429168, 58277794862809959643385990117706200428172000], [923865656299249242896838304913063346523215224600, -72083613397831821497203805703778382067493680], [4157169008312431590284060012257551259502924383650, 104198901777071361902611140711942741983372480], [-1878146216589476608792234308989426858948888225110, 54751413983522926427302096893152741349760704], [4602885924608802750326743029468214668796449963822, -88853853095177541821608686762420129348668000], [-377800115979948981505653884424081894047148211980, -92418565807887589095457908890066421694603816], [3383572252650180226839377731555194190574525090490, 104744605767658072644358846496762276562160512], [-20231697798532742212587531731218538014124386427320, -33751835207121241780632484246874559622701456], [-16497693855051730962439351112358380712202031356788, 148051260893523724784435635304084358301737000], [6781135518073410979879329363099712571469671904210, -44666652433046894378157328995520067998784576], [14729541369957322261168852883636262081863813833560, -193881083294987373233719292954174761813759408], [17239525132037310843194787022253366360317856725472, -49970766548428796425163608824499973151576000], [-12857634902027470869980780806179239691404365138330, 337120202620519704711346381050522209078791584]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1_34_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_1_34_a_a(:prec:=2)
    chi := MakeCharacter_1_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_1_34_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_1_34_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,34,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;