
// Make newform 2.42.a.b in Magma, downloaded from the LMFDB on 21 August 2025.
// 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_42_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_42_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 := [-1139917559892, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-2880, 5760]];
    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 := 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]];
    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 := 42;
    raw_aps := [[1048576, 0], [4431673764, -1], [48799592162790, 49284], [108553401186544328, -30482802], [55297240742469782892, 187241620797], [86646553419224348447534, 929010448548], [-5143983130370838539214702, 30456449636472], [103127441069929895350728500, 22472953406377947], [7462710689442564152180957784, 125759442615183594], [-687571505970942194307444947010, 154199068865837137044], [-1813248461355580234899563331808, -746833205024396213256], [60178339794689457605433497299718, 2217415765316982141492], [635088569953420053430569673439082, 246963196406049498826416], [-3022716710580308049385234395426676, -431472849607631162642283], [-12708239483165271434441140445930832, 1016892781558884965056788], [-150688242142370159078418346116024426, 8255896635822744346003188], [-1641005125348969042997736934227394020, -275093893095838968867375087], [-2242578872920230008838760420795939618, 703715266558744012106590788], [27527868038041190763220815153656518628, -4116172738939952725411426161], [-24428942369265740051276665549998569208, 13063800228304183362206661438], [-242808479422581409082906786174924844406, 6609177664578421711725869208], [-452883427170995414485468510351223445040, 33589637229048492154067704332], [635877603283629124003291615645297984884, -109248674020774775779594916565], [1346207279152236910049345195914378718490, -133660930626358490209980545640], [-15994734157750589004845528531334660345502, -1234876169506125918223025559720], [14442978400687664312160860940061185135942, -5480276855838933773515327439724], [-88492523217522802881133444943310519259096, -28815441922789764716402218021770], [153963308735878797273555517580076569931468, -65322577946868517839318167833371], [-267372391041059184725379561559069367240050, 34149103636610527219641831607476], [1239105362004535760748426644323356436018674, 44125719431188253516372253559104], [9531632564086923393579260077638927736949888, -330786606262009053563206967988576], [-8453066401246354906294101600951266849124828, -5323341279146711032975937845715649], [-26065074332502702420819576185185221040505142, -1726089733778617289673415134292752], [25961140672586807124714739913539248929620460, -18668117616038249951204593177329027], [256101514867872203148135514680767620181128950, 16037805175303383346317991842454020], [71950406771211581223280174891050530919988952, 57686825322136244081296903965536970], [89228459101550402007905128557403881942153278, -27916118472758883653206793467450332], [-716852873977899668572519061482053081731983036, 145670958551907752671732371562965015], [1977731559243370965067393858821172766140378728, 323588816979537183666166068192290214], [-19496878910990234420065764919647507820562226, 1130689686466576036786051164959825220], [4734467772706489024289920238863349734736670420, -3410657034781857689445585800332057389], [19694611374904409208208916325460183349747077142, 406014556968066998886136046322107364], [-35665264387674951746735489131299557106915079488, -2293298587639750363545055636986673392], [30293927427191906902628845836785853955058073794, 1619253516212376093649682114961743640], [-109181922665901916277666426902185779577448618842, 6366402090592445782601895252228697764], [-95995399170596898863604317705500147339787922040, -3446901858666119473768095239811853986], [683628208712047956196576718501914424646307725812, -21344028575877095497810189542888568245], [603159001415001156957830466926473827305146948064, 98557270254432812090158467111812813256], [105086254820766657450812559058025761151716421508, -184482007838393481549193232974492415673], [2278418160025678629127100745300535059966608106950, -38108185936373238155802251727255376092], [2020109953565816636615413322934433235592125494314, 384453946723837317401654674512716497752], [1545900691718324583665240467427806344590516503920, 453263418645497966498214989965247721252], [2280230261832107214555136813017687882014008829042, -1017366719391897775661163068489784685320], [15911237335401111644185398773671825097146844767452, -380679260001286760330574108378620228895], [-40732039392829865050561927336068869915119588792062, -372877482464956135443979177064194894848], [21722335641033159481438677490655810251721764828104, -6038649618193665304434101775534295751154], [-20251107669640960076554719787060742032282825179090, 6829611919145027978572944638984025722196], [-18658978848018981375788568901855470798797408914288, 11368361238319427840565339798323325738396], [-125797042002771885609839744893500129076852875096202, 11138026064393782583454421866412033651188], [117225601205521840701894662501836729372394029061082, -15854664665686968511050120781393924495560], [-40388127522333726862774142735773647486724623439876, 4305243129506977035012432670753836062841], [45571372689949079043023098779680131797426535077894, 55142089822731493665202060039596214624740], [-884508793648872506401039911705893802315278288133292, -72942061865869282649625019761160835315565], [-290507709264401433736451359672609141272925275790728, -8408395363860311668408002705146909382366], [-601321508370675077829276405163455356552522636473606, 232659421122788642668420033699018329130032], [-128908708250607849455216008859438785124631960524322, -457198910613822316908716961746342363198316], [-465681479703679081641264839186982557411378631234388, -1302426362963926985475685320480281505354963], [-1436997596561485756439073769852396462716803819490862, 638647506009213576273952450636022281121760], [-1316034168854510916160829100640199281931047823657412, 47448393685297485720697737075104210086281], [11257240725828161805730807075939264883143663213103870, -627609698233854024651109305844371410002572], [1243473458663204666677316124896258135271495052005474, -1255644465273134280276169803532012374701472], [-553348075885008440462076488230285762429612251109080, 4090529754620610331211765096709547130561334], [-2765555069446458769090207107127169310917134792551952, -7568670980658637511918314012616433619646268], [1201253105884455355064811431052852495445422466869974, 5828357080901978224703309026953443315723220], [71805039062843291048277155721964548101132616905941340, 5204118481358302439940454635428384474423169], [14850677277313112996913186638054866190037153658107264, -4485955151743988818424241241557676081535328], [-164341703173217395915233830790436845792046834439592090, 403138483753041205795050049887184022672628], [-34708770363265985307991305229285402282401074595828562, 41551122306133317237133109090727392759402676], [46275389074130034424728565976627172592810397077753362, -9457358271182963284769106578633124024528456], [59636227926243235695041518398410048861151250183201370, -24923743570413001200116493450090646153610256], [-641123904852035738140087294558853862412064074825737660, 31797800787762193822862217281161773408948663], [288604936434534976683614901538282251061258616288191622, -140042201235390077452947227142011241903665340], [262176117641417679973952172417356431689904256893354032, -172647830213766375647487887779573762948720140], [165050470467324549306700132538841220046646060144440114, 202464918952305570408459866781421135769911992], [531387043943617190023969873953789125586122125697367800, 67792014675636698214903411020628745571421954], [-1061515735531705312871890514308209131177561171186241636, -14591097940241092221567821863560330068107887], [-2349095944122782545022163725025544635693043051398788670, 171953430065798613424499651838906639816859032], [-2058831796158003372267361345029429518753849132856868342, -592315615340373687115786651533391000883899920], [-2830699597540489627387600186644735259075444564369086738, -412528754978666928130157201169908398528924140], [6908236987402090555065285757686888339015124089799106384, -107923660466881538071731421023194673552599892], [-1780902695557134666008803081868749994722158101955759372, 150930163657437022970802616647584162288308779], [-3635843834810399115642852162478566081329300920261881120, -473464343916348729003659519896415940257406840], [-784533769272067387528484911511994119897129998038649432, -670415715895308159584790946244055592104502698], [-8084277713367541017438979531130286981328792112150938548, 1746081726974201058778428897201847434725446629], [-3167239763763405325393480551067987763051272917033116140, 613065251025352701225941255854244128733395779], [35379945135639949018284745213178206911132995338068483384, 892307725995042780549271497582870453296334642], [30381455385172210449523884608559979935072347518520261790, -4260764914919765982712630513234778189839354908], [29354561015836155759204772244408014458613882027903618122, -618339438705552419787771457444320571467952080], [6631202657330807492553078638922466761356721073461399404, -11567424159885122224508326842499341658317164163], [-12703690976293983622576319212379738816856663003025449538, -16565965407060851358941790827029001361921979452], [-11037215671394306888920602192232719233145475030887930172, 12798660274544133318480679138765277321335156887], [-78116584067720190393672367199619701977369321041104417202, -18358534415485605706096666124046508298421580764], [134949474358795016874060509085648282571111221365971369044, 18204686148073405016556007544047037156677014867], [-58677435733039484027875251412317239091476284453404232710, -61379130681507797646918394955800515004356925392], [194203638993078207866177866399813526074290225101655276572, 31390109297976210361595411806608981804548574705], [517013428390380637476641710125278334772746232952380040258, -20949276969838019130201820224717038961704784288], [173606896883001880639835843718600093964980176120630072748, 53218687985502846866358728346409959161952188589], [871837545135095556749108338406066532225666731079250543314, 14972280371400894023137686643156672327972483008], [-528805034842861545236772614742098962238165002521510989160, 63357663236292893785282345279552216988822354586], [585454521420181880660251030768200445443228176837806784282, -123206401546256813089178019988507301050697043048], [546243062092293265999623695371503773849710558297525813088, 111141078618855160029850757613442486536059023272], [1036857383522802434201944674152743325010572000861081922374, 243234783766571378699987606233657020104964754884], [-371794866454759798231069141424490311953481130097609463382, 15887676786960285477703292622861801914177545080], [-1352660037350474676267099089648329806845481253372251664180, -89702703809349517801938189415854982937222299995], [325293797042624295203228153587257651920017816753684887992, 257780507097320079769046831940551265287364262674], [5157007250179874826894412516978935520591075276660028045442, 140438444272120152947602856879696037273576085080], [872248008972966892070321323786004414218657699612130521124, 738033364103189076269582206885939509473776296447], [-2865047907421160387530890808788083822705120207390621071032, -582901726706683022432691935778442389138662163282], [3011432477590526249251921976197103082774425322021574483374, 460791091172098221050856646044596251283417957268], [1128038294855128445345945854551269198727539563970897829300, -782620638394345444302832788782355189966802726629], [1090272884172862427796469174761317133261578211997797503222, -1160539790509233183220826571991008288880280286876], [4985774202235405681184144146974637036175191257290131987874, 256809825723119903357137244324277510672267131160], [3822209804823654655367624017068270686028702545327004930438, 1178888357968960644254465045608421338428754177524], [13970056642145895881625986526506799462490972142455935827724, 933405925927082167569325372281909438488209341621], [16971962131453216729775641520290337099089291893557957959892, 148000804859683987283749270665385559527018853715], [-32221001125481907013334573986972032527743412339339262637218, 634469123834756366801076157745595666965065035012], [1463551329289671835838714547321719777356439197801392730790, 4658236112398147075445701908290323075820499114612], [-28826952197337808650489691597636906101027066278405097359280, -1515761733739671758386248796516167241854323015700], [48723273900667942407670494541969314032377299643559665274648, -2511451206666283651166947177889222168090385088902], [-3735570154038559254837283781197295306524745005261800005506, -3835114780887443275692089651059974403728849300396], [31533459241847859487232735931116470502498283808304560955780, -9663086392675327740693453556376085737283121984569], [-87571773982338427337127209068033263029775963155204188967256, 5635462472957501984017036778222151510717062409750], [-84433999918106175280627880394696888916094832244787104344208, -13212550708187833202102132994080859349109731841244], [36684394595101018508776283527373032304623141466028091518038, 15302641110049553275378967845808744347011456653892], [-33137935757820878377594945135308100334554984920756985388358, 18564034206099956882469101241055232984630758535472], [-96141150549733466212087884234720028461091711230435024298750, 6085253543400387353500276442338115585103103419672], [-3422104492529533257870447356277711661205874675161660742426, -37273390985014641616486259299521145945062626340300], [300890409014709435585652513452997832780494471815441730771508, -12495213828944778905595015324503724167260358356677], [99847220084573199503857612644876394119375946763882142514878, 37760741240723150660648354580312249406876053871332], [410157050245879507630216474377409071943294896074072244867690, 52844891237600872734095147088143765444224158269232], [-96787963206082371309263828231797914720131369082492814625908, 3799887168625325746705966907712677812185731207157], [-418334402411370124718251750291323539442735802873010961581418, -45943198091510340394574467781637635344671500288556], [-647181343340091358226522312024535617114850290904285221088136, 38437530188681328700562716027122324860746406241186], [36866310516805370817137092704968834922881074716763891139868, 42482355172916313447327504946284645456414664467441], [149905591644441187684783853341178887115813661747260289398750, 38025156475665209756676512398306942050412450623588], [862674049184475866052609895909309493356730854864049801331720, 22013873460754003889268344851210146887158568753982], [-473989843632317169007797474076344915296382100838375264525386, -92253962322176653100769013166501221188947804523276], [-663870673604832742361806757882927823176516161656092086711782, 71832348779866251161130794605762985202003493827504], [579790588528336507505401963967543475076877512077687237724220, 204119666893619342468467009492343202592209710478729], [-960525891175021352262443751806104323954906717285337876273056, -252173547977614141755754363021359247628297345204568], [-738940123815283392596194994277472690731213135350687289246322, 308154431967034245546626996997160897376140081836180], [-615701400804112895392487372791584810615444945257963719055118, -373717513776770856088769918332471967075192183189280], [2140065333244822731428685900154344964422348123193645897812884, -48130685030544692955773522498359382024987507018685], [-1570429443858444794090098031862126476248401214954059276483912, 188867092390660488653527844844821911019300163015570], [120778471863919999679706547124573079580888480213615204089068, 176739935322459820656743131766287225284166297757949], [-1383336889394543476417032537022026419733008725697634408987888, 307831592779471322761395922653061035351354253604220], [-1363597579801726142270425468787762431147449814732706095265320, -594226067108098720593267678091358391050909208647286], [1736690432060108373815152558399500015949809982493972637869730, -795679916092566549061055221133401634326748612287080], [-4142019378022336352225445456762850174553114791641174216887062, -244262900493230925109900434856179688868017362437160], [-826852086594376749515200451864029295441095967816997185947698, -2420985307696173440407874020896586281055755527994636], [4169603810175368206645630174198735925855178554881320216084948, -1253776663550964792189217251295327461829215424817805], [-7547558151776991717433926966076763070899580143976907155308166, 605487933501490556128337702423972393486153932954992], [1961641930779270491040333285639398459858776153532005159493768, 1448666746452212210396604025092843576304090372984350], [-1273133482577584786595029306705096512037193500210917098147028, 3247156915925436306860108886787085854291525807633005], [-28312633688471289830039238778629062180777798013818350173136302, -173769708224717071236078779607647640032975889591432], [9344173734492742258276779406098775624772852737084376657111064, 2638743578309308577617532071133483747865447375561402], [6860084056615470874076758464563283853991627027161611778004192, 1384533266792765862785826452758759039993417650538440], [23921396012421672912495182364557195363142719981405422034263238, 3299750273954327905702632981668164732306018600272756]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2_42_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_42_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, 42));
    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_42_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_42_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,42,sign)));
    Vf := Kernel([<3,R![-18179996484555185904, -8863347528, 1]>],Snew);
    return Vf;
end function;