
// Make newform 22.14.a.b in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_22_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_22_14_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_22_14_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 := [-13860, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-2, 4]];
    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_22_a();"
function MakeCharacter_22_a()
    N := 22;
    order := 1;
    char_gens := [13];
    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_22_a_Hecke(Kf)
    return MakeCharacter_22_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 := 14;
    raw_aps := [[-64, 0], [813, -3], [3833, 76], [318524, 33], [1771561, 0], [-1894334, -8279], [18568652, -68063], [-51230298, 227621], [676373521, -644389], [3712659060, -4578810], [4081741297, 6082615], [-6036597797, 43794100], [36896129790, -9606171], [10225459842, -101899756], [35653077300, -171862494], [154788983702, 234108394], [-201901034541, -292525083], [-40609788504, 787404242], [114577816551, -605238211], [-580939457289, 2199410247], [228018658690, 4969469113], [2520544453526, 1096805448], [2805453122470, 3486617858], [-1619665313021, 8358406502], [-10270683060087, -2002648840], [-7312982031088, 19766495905], [-10882252970300, -13676145602], [-7746814884680, -2764376899], [3205793708866, -43574498492], [-5532542757787, 76127835082], [-60947673182078, -46592036693], [24945814026232, -23237172805], [-22866755238907, 206557104130], [51482677446464, 18725255637], [-3339799899472, -147630406181], [-25930828185810, -242600041486], [357132236921, -117507609696], [-172171832210556, 585840679280], [172762652422194, 365117373273], [77290591629338, -391243725008], [-78557114673373, -787244136869], [-146685176259477, -1458087260482], [-616933669608921, 201756312321], [-3774605687268, 187810139204], [219214707521470, 2133747036176], [-299421306646384, -1189610361552], [261776832868220, 14577500664], [151968180231529, -1724768805335], [69143861256576, -4828855310391], [-1646407029065173, -1305222385974], [50161400413492, 3830284526594], [437660049588686, 893991208018], [-259460028173940, 4792636644614], [-4466635784625049, -995815088603], [1657054261234970, -1194262704254], [5779479619321836, 9753531625521], [7682352665827034, 711296255632], [-1155728029328518, -15199847954115], [2299659770296250, -3934889934174], [9549660311506802, 8391220229230], [5565980941052328, 9371330564222], [-4646191851453326, 27832594529435], [-16224541047437898, -9655664876143], [-725234290603568, -42374509877050], [1613298083480819, -38633477838690], [17734294912759485, -14558286938304], [25736876175065897, 165067805115], [-35719572235839896, 10585768772953], [-973023664426402, -43337796723545], [-2365741814104772, 50370612091129], [38019893570961471, 43339954526166], [-20456821355974614, -87814168224327], [18592700304297017, 28545959812647], [-14436073308394980, 63203715280733], [1659550931522873, 99091866465909], [-38385961785618259, -136010697853859], [-99063536238282123, -31932169348674], [47129666698354650, -35719768257334], [-76503289880737874, 22622492889722], [-15227726794286094, -48198702395032], [29419001255123280, -215805616994190], [-101639451966157918, -94719911844990], [86394797850414312, -33367787269965], [-102086341585784035, -277794502315452], [63306484665017988, -206589050790046], [-11505379631201765, -29418388514047], [-51989009571144961, 473586357338482], [160845958608537888, 208574260193210], [-7327577171360848, 314488694462110], [119440900356226135, 308813040082843], [22675020302286771, 108431160096669], [-274739857825562562, -12707129896221], [34229910154783325, 103622182028121], [-289473286752915376, 53704522078756], [495482438183574380, 125612704823220], [-326007694934888458, 357795507871984], [-354591478326297037, -356638591285706], [-353676670018451043, 689248465211760], [285552278949121610, 304797589290843], [117102505803150330, 1320407901058199], [141556478812990916, -1928981721903246], [645585364116557040, -1543303800617169], [34837463858216704, -1483243532098990], [-923291152948859012, 661814434801154], [-689809096918210788, 91570589852900], [1116008172371768357, -329871737315538], [554848148730913128, 2814006092957850], [52228375628309148, 2570512240310712], [-105013817997466224, -2516711890986012], [469204539679046964, 1256399918072111], [-1550295352790371830, -60249670219384], [-1188933503557956056, -1652571317413100], [154644275558600642, -4253652753852488], [-1326961810644249667, -386152730349111], [-455480529519966399, 3072830302935527], [95260846743483687, -4858486121557980], [363962267760628295, 2224366979309943], [166829821831065119, -1962620100675647], [1647655396360985019, 3806576087686230], [-747128356982714646, 2100309752851272], [671756604296582665, -3620438337902426], [1863480023928660062, 3327292387359144], [-735317371242443744, -4021691255746141], [1166655960327569484, -3615829879605390], [2502934498985668771, 2695446797069347], [4551067609707356064, 3240798624440361], [2870766670194772867, 6542857976376346], [3397620957105035133, -2895043892230251], [-2304017277257700311, -5012873128468487], [1574599081137080312, 5593565195077314], [4067793541248109574, -5550050281028898], [481824574838273788, 2415282344437172], [-4002781088751428989, 7704863315187327], [4327245229428135098, -2872315208089200], [8379167240763426342, -2701751913563445], [779471163586809210, -17269940635898875], [1319885258600729346, -6498763342701084], [-3374431926772016052, 19623014652477770], [-103971647869530015, -3108152263221534], [-4051638688607211578, -4268833507198939], [-4298247663404562550, 12356417847905904], [-768266391684734810, -3254949851814616], [-977654943841897891, 16932946764674985], [5288863616620218782, 11574343523198047], [-13654321864240406343, 7906673529004856], [-13483078347610292727, 2305423128415029], [496670078123912350, -23745678860637032], [-346749666805668208, -35756315493973748], [-5165603177795360685, 21081999847543355], [10563417156641810504, 5746777109475040], [7609861563468499870, 26322549975735571], [14157374642163694705, -11949910759983886], [1925235933670403352, 10113582330457094], [-4052879464972189734, 14306632370384064], [5054843330184996324, 15248303196574568], [-2513833111355622840, -27611926906305366], [-13882715266628443726, -35855969780556348], [706504695792427350, 302178831863190], [-15438179617566060402, 8363931999126005], [5378008254084269190, 30864599756394354], [12663341247148267743, 52786092591895695], [-22870619110104960576, 328057726434345], [23800238801868905316, -37021462089581266], [-8493927920408406879, 54948146675590227], [-20711560070974014031, -12708680732862542], [88627933407589101, -92664224149844919], [-7130587164622024744, -38662632341644248], [21391994572139365488, -69670446875249485], [-42109197453066870174, -10502514329971942], [17962196183364248867, 55239341368316914], [-11229315060650624710, -102849315488059130], [31317538976289348422, 20753470585338480], [17585319298608627378, -86485803919775217], [-25978720186084038178, -61987535805420351], [-20689428509900280737, 13634973181361839], [-34233474936273362255, -52236407371610260], [-40857710267462359876, -3081876469047309], [20211875373994929771, -4085881293576108], [-41558355045571571588, 98870273124277144], [-37652595628981390756, 75254928867204792], [12284798122200186360, 65825211281275616], [25220648807248970418, -21065604042482862], [56005881272133510589, 52212255210405280], [74648621968888384770, 12851792961022266], [-8685859265231341377, 147771800886645627], [71313779690922935870, -61089984625504790], [65994893896748023238, 11382669500992845], [-42817334107866557372, -54742752977297318], [-27903454896096034772, 49100027266251019], [75900858387912874318, 66063928813948898], [-1619048428801082491, 19413904182479190], [-74060700551164265112, 36622727330912157], [16638583608454937755, -250840642914114371], [19378501870198211046, 309549991588814412], [21853827018664765898, -212371872877665875], [-47193421021484450545, -182122323561597002], [-139128463083104089376, 112782185633094841], [-47076435567067199965, 8103699400425498], [122396309914753590186, 75794991483458454], [49545983062112463360, -25028236271891337], [-48563477179062346862, -80924980401903811], [-118413199563560507994, 93652922529561692], [-201546595413865417782, 68621699694248780], [21135112817976683212, -74251219779111554], [83878715739487880457, 250695352151313291], [50011642451260855121, 176441831456884384], [73915773389151277043, 123740702525391579], [67147981648392208432, -349738856921070826], [27795538060725178740, 440953006512879750], [32540872512457168820, 349226091151211394], [-132705981470607417680, -207915603964117424], [-26869601547543084885, 196774767785138064], [-146825814358695074583, -40376778164478181], [137986374702954000312, -105777418786225758], [-168275063667143470488, 255299284874497581], [-50741765915352727273, 144556098640462020], [30199557104170485582, -395824154679965773], [86216629751883309616, -846557130766498], [-201071572245758234060, -82992368230296454], [-296817995974049459741, -251809590126214990], [-216176614334305904082, -183248831661175297], [197455034134504802250, 608064841900677665], [-189157721406812790167, 222869042173967084], [-418183482923364342501, -95114002331016235], [119924089568619265202, 511074255123885817], [346923926341550730358, 572778100055172754], [-170633508771081327962, -359279811454927048], [142978046921604349260, -822704588710367790], [381199125643658779278, -12139069127755105], [-147594750302406393726, 264379276935485841], [305114415859826241593, -51274769470607568], [-42469059944198994882, 192586919983246319], [473865781108642856246, 126300892368985752], [99835878352819475236, -503979575993424418], [476070560659736975147, -707340887297049441], [-259851256975981217970, -817178037442097874], [75833092549355938517, -858090178506984954], [-194897625361745394894, -388656650137802259], [-478917095639674295379, -603234841747492767], [-95719637847842003045, -55616943249590431], [-187722872897896265871, -962742128452911825], [672341190437997338120, -401417229326352516], [-170124160540418922408, -1260769035994373926], [426704571858520275305, 1300055165529754380], [367457429166437641448, 888924952645872832], [71470880958688773080, 534838351945269670], [33838165067528722288, -1413993763791723530], [-427254546189352649852, -121158960273024592], [-218198642870697299050, -886954217156077410], [-297753329608758195214, 48639731151123616], [734967920805342407088, -47437832045260840], [357395804129915404476, 1271908854066484347], [-315233082890423608325, 596049682434113951], [605020984296991630666, 237135935410445878], [346262429164355961764, -1271515876983116525], [939919581700039709112, 2990189398073946], [-48948710704671634114, -704520231099627228], [221818784258899347660, -1199052528128682799], [198157080433032717993, 262787123723953140], [1105530826468776966688, -981626303521302425], [-703914279905830009560, 346471629174802718], [232888612214369628702, -1412891876680705263], [-549438213391680361580, -1291191380324077625], [640795558639909752064, -710905533287756315], [357705109062014275506, -889348840718469726], [219698086621669959500, 2694645061897073310], [745434519129403631899, 880304087874920012], [-410586992160220647147, 1654681362765582348], [-1043725249892695217078, -1103279526610394516], [-896989923294599076898, 1015372124903288254], [-259198366336397314243, -923608700493735870], [-466747114194624345671, 2674950428894021683], [130242249693955088718, 1832205623288699402], [-1438728683515639018278, 114683726977565351], [2155459590636606970722, 139378264202776907], [-1487676116637580562659, 1817868566633510931], [2055476113234354498525, -726689866635236599], [-761577892659499788634, -2763804820099174782], [-337529312463547452786, -3009708885859130389], [1694945870854688754122, -1523140108590236855], [664105689770074412190, 368318708608654173], [47982814543222640427, -1281426430147428295], [1452353791195896406194, -930923358959470827], [-685642263032359272286, -2596059622192921554], [-1793398516631247638192, 890161927882177750], [-741884949131552531913, 1273349088757380375], [213578551149995883066, 1866012316156323776], [148164040018661678628, 162397030073361615], [-988862100029324861465, 866494338311541175], [-1135717463147453853272, -2909292709187059081], [306279827715962183741, -4537089059643663008], [527186556271867935648, 1366217279987076630], [-702069155897092154796, 3641947887319174500], [-668790167955183386604, -4162433725690262163], [-2595295865947796577180, 1506623684662449473], [37723968919168758458, -5692416676062689561], [-1258684090419311548053, 5497321684161597035], [1160418518240026048247, -204740676045534116], [-2245431184383969390132, 880992426096819609], [-2035343557426827403390, -653678505455919204], [2294035896546070961756, 69194222918459721], [-2977834230506035526762, -4986032869388389975], [1266999516665016151080, 3078273503200343810], [-116962154534121135756, 1862248033741020360], [1908678662088417289785, 6039639886879252409], [95244413392502727979, 6906828710979688258], [-3959032235115507401775, -498619324777306389], [-1349322878709319656619, -4968043792513062492], [-4385866038213753853920, -369955605295676490], [4006809914589634001798, 69769482759574767], [-1387280591700427023972, 9367690778175587262], [-925795854174782981874, 7945604654920853748], [2218077786021836255358, -194495683338061752], [191541336035573507071, -9516278316487818959], [861608109625181952592, -1587348443894483728], [1761601512478020382764, 7195583757788845757], [-247936489930375708915, 2255013036828645295], [-184329145286586370030, -7245525812124950036], [-1041224722032763136258, 7841196579354747814], [-2362368388331411445114, 11191915792526811423], [-888363543775686765566, -10735083284572748699], [-280159235504681408823, -5728301554336784848], [-2618778849956180128460, -78405287805377071], [1497652381501114112379, -8102931022387234135], [2377260545330489442898, 9317383554604150202], [2119378245753234993443, -1637515349063044392], [-1071642955145498240291, 3383528612287230607], [-8754230953264560221515, -1180146942950443287], [-920574304976092307610, -11214326903411934819], [-1745254037656692100772, 7708161176703938132], [1172897452706463014830, 16966904763918421204], [418499562099199176354, -3319483063769829522], [2020192939492143159932, 13302462446963631471], [-4538441120429075888236, 5539452712236573610], [3001930962959172793348, -11848342461993822362], [-94616838797349371121, -6064407479928781677], [5297567190311653283821, -5631332900476978922], [-5015400045099143058916, 737623550795211220], [-1634012294461143746309, 20850351353856890422], [4497273867540649841064, -15796651676582502577], [-4279123812352964743059, 6566471883374667056], [-6315281001041340049905, 3847593985853353956], [2496068164130662353466, -11616919938890160967], [-6546841753648516754523, -8315321408663393965], [5686010853949718374659, -18209437223868537540], [-9725085482318511743186, -9670807152529154938], [1933937701372135851735, 8331921887523476414], [-7006966141979433314683, 4845483006789347127], [9451202005682138576390, 12314497824417757789], [-3037273738669002503933, -4811992262254413358], [-3421750446551753880730, -20234370119435876601], [8254399715137447337555, -13146924150956827464], [-4733363350263060759234, -20668179472966735728], [5460307929177437783452, -15005106911751804416], [11850495913054006873912, 7102377080254589491], [-3102429186856625156918, -949847743434600346], [3086462659093026739715, 23019265638699374845], [-3510719718243529215478, -15094094891786132030], [-11126412263390938030170, 1710707873938510866], [-3281901150729229726793, 14547191651529887849], [-533228113698699446266, 23541902799264126228], [14367583124297639077156, -224367169307232373], [5861259516471283061281, -11058010969891034971], [8722529012195801666912, 12498687738237973831], [-1508896999654046878891, 8394758901738544803], [12201984864181675191293, -5210550665613578388], [9130326990347610090878, 6441482009126235985], [3841035074722437123910, 13826460198725625148], [-2566210333896938625190, 2536144373499890319], [6667354572958242845307, -36019952155140272805], [17913048154607989437124, -6509192731731212498], [-14334762916188600263940, 7938454356115544883], [-4924829454979972121754, -14055196522053034917], [-14621655268945877894630, 10248236579276594554], [2650260308523481411505, 9111101717921188686], [22861592091459537922472, 13226203992841949206], [-18398112682823316733220, -3480189912320709451], [2200304291879536601918, -31758187298670033048], [-18745898551605584748890, 5794327612742890430], [-16239190628348054324512, -7397311206227130975], [6599178694186984336826, 23232411668462633542], [106376868143567252835, 5232484130154543858], [9282360208304646586304, 1186063921537109763], [-6080054265982974527908, -21846732240516800003], [-16774803883946274416200, 3923327782048809480], [-7197032589484983857271, -48941857681076810925], [5362821369360664183620, -21247384561155347926], [13311819786134654079693, 22765812620812731110], [6502981549732428513190, -10485500616905832947], [28964038690029701461497, -190781148074244813], [-10634818263438980993115, -10867309935042223720], [-19094621998240340715381, -30643118911792604490], [-3739484122094970572837, 23048854191806575619], [-12253650877513905892667, -40274311161133447775], [11044527424946865758909, -17752376298932535119], [-3938650450871631246562, 7888527103560857997], [21126188635068099338500, -13274057673324550565], [-4988017647956272767638, 1575146109661683866], [-32987055101654093163080, 780859545684568834], [3634346354402057470302, 19630218217919438340], [10116050925271865620584, -37612384469918908723], [14007018066083170714089, -53325053879232803700], [26009702295309448017408, 43690610320162015880], [-13114351352995005009854, -55768888473856475446], [13094933363712928793632, 47928108184377400646], [-3452020785027122252344, 22326654402598263777], [-26052843533657583897826, -3632077778284276572], [-35250399789706491039150, 17786973419872738569], [42064833575376948354876, -1524930873563526184], [-5664197969009720939627, -74729317189978437691], [24743795360768070253382, 6760126844343674394], [3955343728277800032316, 35080072315458035579], [7204544611259931683916, 11028679978825352556], [-30528653944061396912984, -24050119232043757283], [-10024810870925452998432, -43526376985792162705], [-7891514678461067962531, -70361251199346672614], [-13810578738827809460092, 50207990310336029674], [-27446998368369843243435, -13711910059748617579], [-395882155698429958690, 16912720884527749156], [-24737253165982601098674, -5782982438432843844], [29504657194765872512115, 49238507920947060690], [18398866145852273338300, -12040559354604019634], [-1039452777189945987532, -35325590657628683750], [5733104618396746905732, -7302886210256778699], [33323633250886349034458, 38752333644314832792], [-27406438302381828332577, -50373967487404242150], [-8477800327161461939499, -18948898255782882039], [59946074714927834966072, 7098180836642240911], [32282023032522418874049, -43922152850806920439], [21476551489168131897120, 43469345514960003240]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_22_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_22_14_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_22_14_a_b(:prec:=2)
    chi := MakeCharacter_22_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 14));
    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_22_14_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_22_14_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_22_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,14,sign)));
    Vf := Kernel([<3,R![-1334907, -1626, 1]>],Snew);
    return Vf;
end function;