
// Make newform 242.10.a.e in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_242_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_242_10_a_e();".
// 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_242_10_a_e();".
// 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 := [-222, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_242_a();"
function MakeCharacter_242_a()
    N := 242;
    order := 1;
    char_gens := [123];
    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_242_a_Hecke(Kf)
    return MakeCharacter_242_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 := 10;
    raw_aps := [[16, 0], [-6, -9], [-212, -97], [3580, 330], [0, 0], [-75402, 490], [-348442, 6412], [-274012, 36812], [415046, 44659], [1349406, 252246], [-2725746, -367213], [1127664, 403577], [-6599574, -228846], [8349464, 1121834], [26986464, 2071176], [47131774, 2579204], [-55451730, -8232723], [50823782, -11223238], [-150652850, 5360809], [-161279694, -393879], [127189170, 1597174], [10378372, -19867086], [158970976, -40242910], [689154740, -14637263], [719083840, -39733637], [-1422258766, 2378236], [-1714567752, 17013944], [-1011679112, -28043494], [-656947686, -125246444], [417666736, 46621163], [1649493216, 105723280], [95879608, -123730090], [1724694712, -319175005], [4444451176, -234544926], [-4131877414, -305482088], [-3183634156, 599572622], [343284740, -230885601], [-5128193756, 550579168], [-4866269232, -418889652], [-15860736838, 224078020], [-18936006098, 70170113], [8794873672, 1180197613], [-2683681470, -1050535131], [7082615834, 603209894], [-9150387062, 2160431816], [16610491160, -1082572872], [-21644450372, -765776664], [-19359106938, 122044031], [12398841072, 490418898], [-49596868696, -1621049115], [-1254561734, 3224785946], [27032191340, 41517862], [275920322, -3418420030], [-18954072650, 4771199105], [-48293806886, 4250753756], [9126140700, 916991802], [-30200093402, 3791253740], [-101259622568, -2333007996], [-153125500934, -2094776856], [91777208222, -2576620436], [-60948924556, -2780817688], [39154266118, 2985410414], [-156293604556, -7992824092], [-26412523552, 17297687476], [209155929332, -7287906399], [51205547340, -14364559293], [-18883481566, 2817702567], [-96301444530, -9339440], [238688656532, -8834295656], [397321700466, -2424801368], [-220235485980, 10247528373], [119337289056, -445151052], [341936127758, -12331092981], [-326942299270, 9598510424], [343682794106, -7295242005], [313500729982, 2623281755], [631928423532, -13723863297], [-86763315602, -16651455680], [355473327506, 10411705216], [566170510550, -6348179368], [-752075394972, -25860903072], [352347195974, -39076752768], [-389072005020, 7038605682], [225966428840, 55052130231], [137726475848, -70304663776], [453374374670, 62311945021], [468817581172, -9374544211], [214770451298, -4542491890], [-789413220874, 32146807018], [500413765722, 24536811833], [1077433775766, -28933501515], [903781427688, 51760980564], [-927746022202, 74348192715], [-600748801540, 23074276996], [-2035866737932, -6995256192], [-1139233160500, 25409343370], [-636527105840, 64710701549], [-1393657709088, -38696317305], [-70078779044, -77309587740], [-1551097188034, -125804346106], [-1072230528140, 201362100156], [-771128883870, -141211579512], [-1159541857652, 126839317184], [-502129367942, -65968264606], [-857589640588, 74984708504], [80559273872, 112835513043], [1336098528204, 93940327392], [227248711770, 21364744398], [-2558684951784, -206113487856], [1321336541510, -121455054544], [-2668524473044, -69137409826], [-1731376508058, -136730010242], [98612487610, -170813471704], [-842722326046, 264489761943], [-1291780823690, 109474712635], [-5253612326388, 83688183945], [-4866152655754, -160182908403], [-1007372308598, -665690203], [-616119877296, 480235722693], [3592842409440, -352586506302], [975862845060, -263372931373], [7406617140742, -21426310908], [-4782587347478, 302703105608], [-1519326039084, -166763249820], [4607245990830, -137427367135], [-6755339389302, -12242805516], [-4393387828872, -365651495491], [8441862037902, -1634112549], [-2389352644050, 152023244855], [-4524163322522, -141224261622], [4660328146240, -291357361542], [1993638639904, -572081092108], [4416509072930, 85022685405], [10008678140030, -456036426492], [-440306638158, 577980880974], [-13838313363190, -251353390690], [2282343222606, 489983987844], [917744016116, 56525667188], [-1098091936548, 747344913339], [-6767313257126, 444340028138], [-2066167170536, -353969621718], [-10568862616502, 382617976256], [3091013100566, -464137806165], [-4975962985900, 487193565064], [5385551839012, -496496919137], [10619737161390, -207509704161], [-4740390255558, -736034227064], [196754850218, -69105679958], [4526417416198, -1050583130567], [1756430767792, 1210185957176], [23856877179222, 571174667050], [12857889413768, 393234406855], [-1722260122892, -181599859712], [-18329645278524, 104406985302], [-18269847708836, -557026820216], [269329178952, 551776800924], [-9401409037724, 666117215094], [12037136318850, -673939309200], [-8771380457590, 2138853879362], [4945058024058, -2527813532124], [12038885349654, 295107282597], [5902633466310, 1287664471296], [976094526632, -384520384072], [17661977630322, -204602633553], [-20572372562936, 815483641559], [-734871265674, -2092078004181], [19591312995440, -1192226625000], [19790467780298, 840798271160], [-14968433996506, 405530476316], [-3004026159032, 1029812314253], [18743247846608, -2236914555842], [-31564663966258, -1075057105320], [-21064967999880, 2104588337184], [10413910982746, -246727446534], [6605735337786, 3298676681225], [-18966221627608, -1442031652013], [26022953190376, -761234718198], [-12179108114352, 3299807877033], [13948619989392, 1387703082892], [-31316893731530, 899299121658], [17689030890160, -2478504774968], [-18264579812616, 1264321798518], [-8680750537020, -2696703367621], [-7549951365954, 3460035280884], [-38775774472182, -2085759087855], [-62407650985682, -1141537469332], [-57458278059218, -773757563106], [-14044210016340, 5499364704212], [-35034586600842, -2292664045136], [-10681309070468, -2262650239594], [89046288984272, 1288418403411], [-21701331964104, -1906038674646], [35614732024134, -5594883785299], [36058609849950, 1414395653040], [68064499735052, -3126286856], [65920509287644, -351806552755], [-42710851163394, 4789049603512], [-57142885707040, -419681275659], [-32159872232394, -2500484459988], [-3686776186308, -605456463894], [113900808271558, 1601540856434], [122822310357332, 2295778400762], [-52531797090386, -677663912468], [-17356507550190, 8413983050434], [-18748852852734, -1388926781433], [62587794910228, -3259958550313], [-98958603336478, -3072047663979], [-69393977665364, 3739415017976], [-16810495844022, 1666878775698], [-22957196144764, -2493149805972], [-65741372286318, 3496434716890], [127570623780144, -3892117344639], [-25331599932842, 10047109136443], [122216417314236, -4196876360688], [-11490485179116, -7062218683722], [-115200385230652, -3671752123119], [-105455356198120, -3965150885836], [91285529794234, 9532590417374], [155790690611288, 3931019537680], [-56423689611616, 1506698436613], [-169784013857602, -1695068714758], [199845555057680, -1315060980940], [38436822427472, -1443607182509], [87382864652170, -13980347451791], [-123485819436292, -6207810511928], [-48244948348350, -575673851684], [124170830130194, -1492457566964], [189786294009504, 3466128743184], [80436845160032, -1066112342476], [-117667797111468, -7345111379712], [255441085771316, -385096145937], [-150942255322996, 9557384100800], [-88642739146316, 16105215791874], [117179974992970, -11568181820110], [174119247806294, -8804466379671], [20881363924956, 512437786734], [-48970954847776, 16713120069555], [56787374283726, -9465009639942], [54276329498706, 12944906073399], [-95653044124222, 19560796260385], [-10618260513126, -14837979019377], [-41773560480836, -9637089997428], [-16209526757840, -2448268420460], [176459974805060, -13808988779865], [1335055825826, -27742372933406], [-138887592136912, 12867205439668], [-159891360817416, 498446724332], [-140261842145500, 312009447616], [-260992635328280, -2778874793550], [8075341044236, -27215830390442], [-105183774944098, 16238773192934], [241475025797550, -6259924301160], [-7230970494022, -29231547555875], [-279765348138750, 1376295589868], [6285411997514, 20021106169660], [130756211005404, 963374647128], [-34290300964426, 19138908253344], [185102882267504, -6696039768418], [-174717386245620, 3637742554143], [-188824921728786, -10486544559164], [-127490686588264, 279802037180], [450009867360948, -6312875785428], [-481810748366958, -8128924141028], [-408553429902726, 9451311085660], [246952458796650, 4300969304244], [-320739692797492, -8767004152572], [-23506309096504, -13684125799007], [-155562600060624, 9079461094167], [207645314229816, 11519968844866], [74175928758386, -29504120215124], [-591256173852892, 335199959991], [281137455194010, 11006721438815], [-81987684268214, -9031387917512], [219865806972320, 6233838106304], [-149324653812622, 22418337977882], [-285122304895138, 11434437950655], [115105631947538, 14838180813415], [20761308024970, 26136231029652], [378504807289010, 22852599609686], [443077716376076, 1032425706448], [-227034143391072, -27097298357568], [-216336893512670, -19756464692207], [-99133499898960, 15070912558980], [3442877649130, 15006051915576], [93439821363828, 11847200007520], [27070188393642, -20341591844895], [62673155734498, 56294585541736], [136848992364066, 31321849096908], [661978510466658, 7866646574873], [-46774057746746, -41183564900380], [-12717277042340, 48323308689395], [1002700727580036, 299387912904], [282250788117282, 39047803831878], [360315050766624, 8955268594254], [525756842633714, -41603592940192], [-131651748333634, 13617513019942], [209353139962738, 51579969691501], [-23176060193288, -77872078950043], [-763829845953744, 18464980614702], [-485867977732784, -18751166634126], [-195319522204706, -5496553702044], [343758842760142, 18047013101894], [275287655787416, 27845123408996], [-933041882037324, 6069024093360], [966271314600202, -5199493722941], [-228490361488980, -44472858452695], [1147786995437490, 18948881426847], [-140946755216932, -748616252109], [-325909974982656, -10454769198876], [-162157741314770, 58397924114658], [89073439139712, -49496363683320], [-178534022710122, -31719171097104], [-412607674067130, -25152058474716], [-31973152110930, 47709558453353], [302615665610824, -57592135191592], [-700381019103538, -32692116520180], [118504428322354, -20921215153141], [410907292294892, 23475792972910], [-887234061407502, 62695077092408], [569117020126650, 31006203758142], [703620483493356, 13772155656832], [-573403513834904, 70888466650387], [-265062860930078, 50712371953760], [508355740065802, -75600321652439], [-355550463625730, 31252944383108], [-335768574396796, 13709669576925], [-483193959811134, -21060756073237], [94430582315618, -61613722128801], [-152069549938224, 33510568225464], [-1118751960093890, 4020477949178], [-505972460937534, -79174483951496], [-551127152784354, 41436117452736], [-1000425626419940, 12621697525254], [561478339681556, -72729009423908], [347130039668172, -12297973772804], [1423686365203998, 25253226474933], [-676919867507292, 81331618507151], [-474859454551558, -21433462264442], [-84864963856428, -53861738631463], [-1427182746425356, 30909086957114], [758125824042100, -91500214725317], [729690279980388, 43513307255385], [381912287889598, -94409338762390], [810436417161982, 29491146444295], [-23386850242584, -93464755822695], [595030109621584, -71435381439358], [-857103602907824, 2108587104553], [-381405949602262, 61695366085899], [92622194655968, -23348701353944], [-178845409885048, -138771810142067], [-1459963032771284, 24371235403704], [-155266188495412, -6564413400555], [-1860142595770770, 32559054518400], [467176523344152, -87926952994268], [1646570225748522, 63635121767776], [13239172405198, 137706564208388], [-340547708928662, -115665907976167], [-368856692242768, -44595365198426], [-1314283757582082, -44213199984264], [-773373480151126, 41225359480669], [1092982226304874, -54413232011016], [-1491071282282522, -24271081579912], [68698551613622, -93824936556929], [291823898490704, 188751702728398], [385774595457794, 81221447788059], [1234176416455280, -13775176872033], [-247784592677122, 72177750022990], [-26296045214196, -152827038567182], [1635857897429914, 76543148089602], [392309172681870, -147157417178727], [-905814273503628, -56253025036], [-1571667731132484, 102907940595150], [-2048873170229202, -42811186698630], [-1847307573977988, 2202565316290], [-2092474340409940, 12301677746067], [-1119139180058444, 42185546853872], [-1141278310703420, -76624288003462], [624096266679238, 60867896110596], [-1242889604667506, -156168401526016], [1301999667638374, -5735467417584], [2063347235288878, -168484514151832], [239395295151156, 173892052187097], [-1113291061207076, -144132591266526], [1843039986845414, -182444921152652], [1850165717782420, 139239412794060], [-1181873169896634, -5379078211605], [1869121530244192, 103143407430664], [-301080195506420, -73441485343817], [39972135199020, 83954065853284], [3368133031842510, 112570101024291], [2181370850944504, 63000719346679], [350481410412696, -13094523292755], [1568088623326982, -228139329573119], [1724588038612554, 14284511831927], [-3116759758030250, 95149290007259], [931644945002938, -13937080730574], [1696402037665980, -138061679014970], [610605122500658, -75774082459916], [1614785466337260, -220393200119488], [974810829634026, -183051944057232], [-1417140828736534, -50954966165596], [1116169212088848, 116552429026707], [-2173523713646224, 112001995546208], [-970249438961038, -182419963288484], [259906723892686, -96528809813950], [-1107378734713148, -82803331362258], [4270236648244190, 65587179190440], [-1906144222805382, -67760771485554], [-3283083926974748, 92328902915800], [-461008901046454, 283016634944095], [1209486904182334, 182022733424904], [2652585054436354, -34861010768260], [-2171785426344084, -78662350483416], [-652824685506864, -36597037485374], [100067331414014, -368843031457084], [-3732874891119260, 70000135723559], [7254105614147696, 784900212952], [-132924504023354, -231963105646757], [2034853876879738, 59755927118180], [1817614081985868, -11142348925830], [4256654238979104, 150255950125509], [2011441743562806, -375842449620026], [3938540247841600, 170958808466648], [1162564370016528, 107371398857502], [-148943037066166, 36800582552256], [102522232082856, 161761202596449], [927869592076746, 341805396858999], [-352276875670978, 395298925074556], [210875968643962, -329649706802789], [60837501881880, 272873131874280]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_242_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_242_10_a_e();".
// 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_242_10_a_e(:prec:=2)
    chi := MakeCharacter_242_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 10));
    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_242_10_a_e();".
// 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_242_10_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_242_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<3,R![-17892, 21, 1]>,<7,R![-10178000, -7490, 1]>],Snew);
    return Vf;
end function;