
// Make newform 112.14.a.d in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_112_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_112_14_a_d();".
// 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_112_14_a_d();".
// 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 := [-25032, -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_112_a();"
function MakeCharacter_112_a()
    N := 112;
    order := 1;
    char_gens := [15, 85, 17];
    v := [1, 1, 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_112_a_Hecke(Kf)
    return MakeCharacter_112_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 := [[0, 0], [-476, -1], [16002, 63], [-117649, 0], [676368, -11088], [1755194, -50895], [108855978, 128286], [-295667876, 114129], [-420367500, 1099350], [-243811770, -2389086], [-1096538072, -3506274], [202530134, -9857106], [4259086314, 51860862], [-13112522648, 36481536], [-77524424880, -23291442], [33003525246, -339839892], [238181148492, -225693891], [98689425002, -401532849], [859366429744, -840313278], [347771739168, 1823602032], [-233042619670, 1429760268], [1216008287920, 2547097812], [871992247308, 1600755741], [1511290120242, -2399150268], [3880031330546, -4519008846], [-10851141824838, -2791682397], [-1200649523360, 97801506], [18263766505560, -1438280298], [24999033513134, -10714462542], [-8712528149802, -25246323144], [-27896471793524, 2550389058], [46555537300524, 45460568673], [51319289284218, -85404831876], [2110569602260, -89891609409], [4582361721654, 255317761188], [26806287008332, 144787643910], [-137860992443398, -210765387663], [75049267039504, 4945547880], [-95928824210856, 44753548554], [342717828824490, -248345491563], [53473980862272, 427246463070], [665440758577658, 190715417757], [637215109508856, 349106383080], [225124797663374, 756796817952], [-236210271199074, 330015388752], [-64387711603712, 880814433222], [776648184528640, 948342500154], [2023530813437896, 1633597583832], [-2454134864619060, -2077085177487], [1392345149875106, -1506591313155], [2038193818987530, 2806767915336], [-1743630343636380, -2035220348574], [4073370312472370, 1953462670290], [3014796493101204, -3212850212721], [-949462895075310, -4003479319968], [4404462673667616, 5872349793744], [3096337819864506, -6882448308723], [-1492331315400632, -3690927197532], [-7670355120154954, 8184170348424], [3611816862375450, -7749603531936], [2768038266171388, 17366625410445], [-2308254886010262, 9964988057943], [17167423571444860, -7757204793183], [-2176187867262696, -41090565440160], [-19629107221681846, 10452903621606], [4963600108292118, -33711603834384], [6324006506518504, -42561083087712], [-1345124883665794, -32863805193240], [-26867387601039864, 8695478342880], [-4944975001020334, 74854052734041], [2312483416805898, 44297610923844], [-25722607671730092, 7497346327506], [20034348836939416, 4194983878992], [-4081962533917450, 881428837716], [-18932968368590456, -43731604374948], [74954672921567376, -570180252330], [-2176617658446234, 32193813352302], [-798691010929630, 50407039106505], [2519162862568614, -44641517901372], [-30935490326556718, 197956718383662], [92613396331519140, -84447075796101], [14927180455655990, -128637020053080], [-103888132473003252, -186858341017362], [156999850378999418, -176389362438174], [-61198632907465760, -5754665112948], [-54083398570807776, -257503302880866], [-16014068485846686, -5786155155816], [182824848433442870, 324142963930800], [109775223654498066, -182249298460179], [106398898543042024, -198643259528532], [-11112867087827988, 628079149825677], [-313470434639865384, -170018455497930], [-83240755529250044, 251228998950678], [811441077652560, -315107963211258], [-122967766467940712, 296900390903886], [119381025757189392, 805028803345368], [-384218671746099582, 29571580165473], [586261384021919634, -59749037812278], [-5975268712800212, -1086715646799831], [-67667323680616930, 582435701701308], [-123858243988466912, 1172317880309940], [-326664714108364122, -140168023551864], [475651009186815588, -36501444204273], [234087709402991310, 570617402930316], [-414684726357075080, -1670783397698772], [-641877326677139686, -505907784877356], [-277662636851200860, 453424683538323], [-273754587332665950, 727934436438156], [-658628031368174088, 1526354318824272], [769445205486987554, -927016273426788], [-932885426878619648, -1128816831861360], [-279813209415665938, 1616622584848866], [2187932444992037526, -59593519779192], [1284200470843184188, -917879451277419], [-1398848326200760664, -475481512508940], [-669988670845326858, 573859094816700], [2363479837224146788, -764493139702089], [474429610944530976, -3929938963126938], [-1439515042420579722, 513091689383574], [1664607582026026368, -2071279243322604], [-2697031095476976454, -17288419032081], [1111860828773629730, 2505891554585244], [-333975697156119270, -589018065237603], [1909266762561161736, 1545050520471402], [46524047993657164, -4460658026351823], [-2327090900937543450, -3854883034695042], [3332155784958315206, -518753718671202], [233167562826620352, 3483697106339946], [2435808879175361032, 2688967390807062], [282820865835477578, 2797243451776647], [-1687590852108682736, 305472853084392], [-704732842837971132, -10270774442160414], [301140868855291708, 469436602012182], [2940828087725556590, 3562548935932098], [397185300408430170, -3726322791663078], [-6246674205534428638, -3425942739482298], [4076012487196456674, 7800271483901787], [2115998989136180428, 6971642310651525], [-5573734713713510022, 7655264839666989], [-2958494446404359850, 3733482820041576], [-3865211548589416340, -4057544316063447], [-9124091089176777834, 1329721275183840], [-11186420943666164576, 7474657669149636], [-853672061078195400, 4398336351174654], [5284765222006803050, 6759950072705991], [-2430485874657065568, 14757049857918906], [-1616905495002471310, -13253158989166419], [-3459747640408248798, -26099325716878314], [7766966676644551012, -4510222183107081], [1975337920208928264, 30042545958569592], [-9939619488258821362, 4235656024654614], [6291699123567521034, -4245121937730528], [-16630412985442400024, -9025667338401126], [3310862649527066760, 20844711269352414], [-15890756529577320512, 9972044840387826], [-14750936118375592764, -16069351225790394], [-5319621480607101920, 29240439255293364], [3808552412638249962, 15824701095188094], [-14117531205015788326, -12453019123786956], [1278702290070952194, -36593515807986573], [16285795902482723040, -33572932105689396], [6875655180383594250, -22811884607480976], [317785210498827508, -26705637745704666], [33250501737256086780, -21989886617796219], [15181573646206911378, -34180163477808012], [19276215445055756880, -52440363722300166], [25543533012186257728, -6119794052115912], [24806913424796038130, 886269431932587], [-13745010492270607570, -2674853362667304], [25939602348469320546, -66772064539218195], [10095385351868144208, -7183312030313874], [-5069589285544935214, 56072689228541925], [51954271119021541536, -7038038683586736], [-42075305871664266406, -25805363155442640], [-11707786548043432448, 26100937469086002], [23344004759182617426, 85853758511323944], [-22747568563873039112, 40752312304109238], [-509174364349918290, -53881731205105230], [18451455565701106312, -57956629016942748], [85813747777568609666, -11883741462659133], [-55703976023398920596, -61828522147381626], [27009142772682600852, 9605760065694423], [-5424847940665642378, 63475138872045810], [-9411808243028346582, 148518088606829448], [44008175968429643412, 76454055088165566], [69145670747533409442, -57777380336227311], [9050409775115146838, 177242672862983196], [64604130101046542188, -14174956221986079], [39439902870896749754, 2851392235258476], [77853840262714819128, -3211535364481926], [8323758714486511226, -34597733826263868], [-14613450796910633160, 162776045506051530], [-113706470308017233576, -44221110912393534], [-78209907456079408422, -26084557588641183], [-163614590229014399400, -20261820349327662], [-105235782964947389454, -66063345293572632], [-86949992774956923346, 38879028284176080], [64557108448667346230, 108059234761308474], [-49622901969243530886, -153003007450271808], [32936904737603059200, 80397201124892556], [-59845233116887623690, -252588465612895860], [-63553365477492787736, -210073463345493846], [128917656250193139602, 99046887868050723], [-40353536940974998678, 200939804835371064], [-117712696986353324772, -252053495482592151], [185900799954064107570, 119621053664817651], [42367255273368653992, -27181340403793902], [123220149069085300008, 28024633840152852], [-72222468906134132178, 145189239166231848], [61517244010856972548, -86827845005726805], [82163116469213123366, -110930809836296772], [145135285524625648434, -220842602147152017], [-88215251270785451828, 262346090705987526], [105562618002723963900, -171039534011961363], [152069966614936157424, 134403219252164340], [73592531820306659258, 234636959192138514], [-55649537611638689912, 66658957775932284], [278667258044115982482, -20367489698582850], [94065095085130878936, -323166627624224160], [11766561726552735030, -276225771124529730], [306115202768945488862, 152419927937034366], [125142528840813178240, -21286263750078060], [276570832105489140594, -267721279216168176], [-21378448690371518060, 400265059231352826], [-138054165983075457780, -292507546751673975], [-126558498872579044546, 551679428252675142], [189463643264267038338, 358008683183825940], [-246871441169365424604, 543315187065028770], [-246928144090622856848, 495521456887264104], [232390891647855326784, 607575711015890064], [-407493481165684488490, -432138561390526410], [-122699079040724851196, -822879821978254917], [-16211529647111773832, 577634289321644100], [299180754111848507130, -276562470587565456], [174178250716050155260, -322140655865309031], [389401729714604219256, 233814058794924804], [12677863874950764266, 386428086652108446], [297619799363687519238, 208088217244255572], [156871702203257044848, -102247421459098986], [-498788456819792431320, -194138701360953300], [554216967727091394840, -141654933224152992], [123846113133194145820, 672375832361272593], [116423640924744652240, -109012187323478808], [-235128367989053665594, 357147141270316740], [490782960173577970122, -39766587102651024], [536496132596100229056, -333260759973690954], [-243467159660309041184, -303730015537303272], [-355026687986977002948, -490177522113167583], [-1063190313421099428560, 124175062101241620], [-348588642598666353072, -408000742324790328], [81153868036427817566, -1299529177808031828], [549105903766915897962, -686613126628298196], [-668707388354993448, -180256062669471684], [-14537365249237022206, 391165589482224012], [-487420517962824353334, -162808045820922249], [168842703515642387088, -1222235103278894418], [-173696057763459450082, 1188962525456360046], [-125156546541960414236, -401012816631680349], [-51139849984181631918, 319994584275726423], [-94189967306584074142, 1769198577465652686], [489258320812049075860, 1801469282168508498], [885633018031751016840, -683520109592879412], [-993557733605972352958, 464144993234325135], [-776112201332296438246, -986265227396716785], [-320025345457490194830, 1464455379255478722], [371499128453052203716, 2469399374170440819], [132552585106573328478, 288404770850598276], [411144717930759782130, 855625058497162404], [-558655134486727602488, -2015964498027126906], [472902763731412188630, -190592561179730934], [-974283544239805335046, 15960292017203565], [1418369308373631379192, 577431780741872784], [179060558431922847890, 1218035980700754336], [-192246626204166698420, -1691222761027582902], [-320610144120925895950, -1699692023279494080], [-653034369939299001416, 3242406226492991340], [-885440145853326379248, 1340399763144238860], [-1515256090293319008778, -288761326428165192], [-489194855838351096370, 852738222197417976], [313980688780500388332, -922440290242376619], [-508291264341306211080, 2504196988290280656], [1826180183734478672224, -850660024847466204], [1851844068186838924632, 1426389686360577630], [1679091369167453705450, 1530023612201479503], [-746050598927389235732, 526050546868266417], [-824929525249361760108, 92492402589728190], [1787823310761775867106, 260413147008230832], [-27344872535902386114, 317285946905988816], [-1178637705736616399624, 3242600941762266750], [1239422727465274923018, -1117406586522839580], [1272058338258154613862, -4420613027947418820], [-865555516278261333924, 559153429887703581], [1871677537500887319222, 1871404527692703024], [-1346939283187412062260, 2463613664433162345], [1860240839006110448222, 923580655432615656], [-3909733937296065344382, -841469113749347559], [817087673105254333720, -2076226760520642636], [-3153405612202946685438, 573291327795798033], [443558995982369390004, -2657618927232405849], [-1122622830404603582012, -6080777442682487145], [-2161454157420347796286, 1864817262512975862], [-1645115467064360329410, -2572314836308471422], [-3859310046520101872648, -1778268911348075076], [3164403257809322592216, 1754506999063890036], [514185512924715721024, 2744641592759760876], [1340523029280781694306, 2921976757892706444], [-345592214658788600088, 2206225772972685576], [3559522048470572711450, -2947044830569153533], [-1045361386820634294852, 3633214702614619122], [-2927137321144167228682, -2925576480566619936], [1826552940804000705576, -1258777716238014912], [2653796111214515884566, 4187383992212829534], [-2916578641570906983006, 6560331603764813028], [1689531099113553030184, 6175700906534137188], [-2542770751515410359944, -7095960626290913916], [3532790203578299061650, 2595936653857722420], [1732666316851646531124, 2729048679152286471], [-4567757825736096488328, -68365961603204580], [-644371098822350073622, -926377236151165224], [1813691445074139209010, -5612054708462577480], [-464589706080569477660, 1380024463597996995], [-6499131619735377672790, -769842826560058860], [5466837773328638323554, 4064294751850980459], [3565914995013446094208, -4284643316386189932], [-3881759986749375935514, -3227529334135042440], [3462467170250151255962, 4379042491312142034], [5276824486106053880752, -2050611291713589444], [-2668765696615244610692, -3873075485296619079], [3083523962099978887860, 3900110789444629662], [-1119124954996069644306, -8068202038101556890], [1154154248202718951766, 3622178402247893544], [5027809537772112135414, -9089198640145790586], [-3045426212080340976608, -1560479592308782194], [29379483098221899636, 12535820792574087483], [5606155686622958777176, -3149584668658676178], [4762251651071458164348, -3284352594574876935], [-389980471979261090338, 6569642313935310330], [-8556128653968973549206, 60854908484690388], [2400539731452406123034, 13197911259590701704], [7518710443256666665144, 427437726137507466], [6491689138897868781710, -269246805283485288], [846605800767358967790, 19979975993243029092], [-6517947676078100516646, 9500764904319150909], [6435637319779303289032, 7414575865926677532], [2516808173511621090246, 7510088976895681974], [9716327691554013662232, 4519622086095594240], [980594101649517697370, -19197845053628457555], [1913496744735553043224, -9518999074804703484], [-1040890170034349154408, 4177888259564156832], [-2044157556977818381806, 15977740956441885675], [2565470051720273658100, -9045410360015865969], [826937062229232157322, 12695858323015012488], [2333398564864224725046, 4564126888578908028], [1357797129043627023976, -15643972908162717174], [2689652849878403797262, 7140782434477438152], [-2445744060059369825070, -19796951384963771328], [6149713604553279389160, 4510660141080180846], [-962505196435117353732, -435776862166483635], [6957726803247128873346, -8669393252980055064], [2761804502338083252, -5650733982813978114], [-2043764285963744088298, -24235342561539034884], [10400956520943862141674, -6760980779821488324], [-2891485710588308419860, -4282019841329268318], [-14523294955633845440784, -6139452897750075246], [11192284393913105816956, -9865322618959843839], [-333616614950593599418, 9366601434840915048], [-6097817570940522133350, -3947937934785748659], [-10987285581508189593260, 6387098306109868494], [2688754559087341092134, 21792138365602778544], [2433658015138785923592, -11651116872747576798], [2130031481035592747284, 30202760969111509335], [2394662512598119910160, -9694954535932947960], [3223551759424420684710, 1142720923505095620], [14186231845911968850616, 5209679442551144184], [10293348452406552301646, -6096051689293474524], [-1159897507648461255828, -26819161137702979119], [-6889207345180246005516, 23650898462749998594], [10998162572237301469610, 21041631187898244840], [-19185341559405087556014, 5790298547952899442], [23976424791844479897362, 10992259717540722270], [-10615934523337794365022, -13985236000925895087], [2285652202732195356534, 20595516280467067800], [-7992225390311229197648, -16089399386637656436], [10298018732055787990674, 3099248369071158528], [-19831588036968819969788, 15495136792715209959], [-9643173977778866031696, 32986041753712438620], [6264007858466913922912, -7607843713995380100], [6270407728737665629298, -24526971948276858825], [322186375266837709552, 40068861727206988998], [25660835094279914843160, -10518905035197438102], [23055112818840845617118, -19725298990526815056], [-3542179717401014758782, 19821944531874002535], [9332346840370737339432, -9680833258761322602], [21689409042404167915396, -14523900358853562381], [-15365514430761468349092, 3056016309472311318], [-7746531469416043799638, -46227112798099529268], [8881120389568995964312, 19462320482044473630], [-18816461043521535384270, 1455696860818473378], [2582019553962660343816, 19078269195997913958], [-27297548134752855430482, 4722191340558116418], [-7613208601873828901374, 19128567579046610859], [13420525525923225807138, 15265140073987837320], [-14062288087986894455144, -39332460066833595564], [-20064582096567719746014, -16027068715075088298], [23005274928031957729938, -16497944336315650203], [-30964572813443264063264, -26299400960109707118], [10473587304412312343150, 27154775745723251808], [-395464731317583762210, 22943367133802871840], [14221677232300336259188, 9393896306985297003], [6343840917498862185492, 18271302026741939079], [28482672317183866093130, -7371715242083079096], [27765014731840875240654, 2891010098246683014], [5989131675307032619752, -37024431838182754812], [29632745278550474362216, 10444906249062347790], [-10449915906943808838166, -24056666009057696112], [9930263785117185018306, -52420465424931941259], [18747920114260066908384, -7486823796307671060], [-8803289802899246368616, -25185129620487270930], [8295579304850601905778, 23869033473027523698], [29175257472761516691456, -20775948428580823296], [15172879532022484538382, 3618257859603375786], [-36150061030461905178526, 19098784707141621195], [20717869453113537583296, 14673663512054684928], [-57263917419489403716828, -2426632907459607333], [12010482989553359420858, 42104437358518324134], [16227379085303401368906, 17339421846397282155], [38178206023057012058808, -37150098046426439424], [-25886133742466992570182, 34846623014369875128], [48892661110387918908196, -39371288699543886549], [-31469022403787016890856, -9618835830603517710]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_112_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_112_14_a_d();".
// 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_112_14_a_d(:prec:=2)
    chi := MakeCharacter_112_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_112_14_a_d();".
// 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_112_14_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_112_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,14,sign)));
    Vf := Kernel([<3,R![-173940, 952, 1]>],Snew);
    return Vf;
end function;