
// Make newform 84.12.a.b in Magma, downloaded from the LMFDB on 17 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_84_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_84_12_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_84_12_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 := [-250116, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    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_84_a();"
function MakeCharacter_84_a()
    N := 84;
    order := 1;
    char_gens := [43, 29, 73];
    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_84_a_Hecke(Kf)
    return MakeCharacter_84_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 := 12;
    raw_aps := [[0, 0], [-243, 0], [-4455, -5], [-16807, 0], [166617, -115], [110592, 1458], [4120227, -2503], [4857644, 1944], [8556111, 10367], [32975262, -117800], [39729240, -34344], [147033644, -483570], [-208747935, 690591], [-149459212, 1626480], [241447554, -2289774], [-2134755648, 3111378], [-2615799582, -4074170], [-924873594, 8181000], [-3727394846, -6436746], [-15767760591, 5015153], [-4864591556, -1198638], [-25478178222, 13426722], [-12122072172, -86080], [5742574785, 53744511], [-55400331584, -23050818], [-78889817889, 18880849], [-61736760868, 12682980], [-89173240119, -102252627], [-254796557978, -33568992], [-97882555410, 3356092], [277156752834, 160845426], [227125770984, 347365540], [-118255418964, -98651582], [1005169576156, 151280784], [-148644530784, -1238343630], [803851703032, 151628112], [510399859058, -615729276], [544041391742, 833177826], [911444540778, -1085919086], [78997155363, 1732767277], [270007407423, 387048123], [1003675988964, 1149139710], [-2104839244323, 309867285], [2848931945420, -3945073734], [-1134618935904, -606517534], [348935324756, 3727837404], [-284380542184, -451229940], [4163204492804, -6341852556], [-1603594032390, -8261661306], [-9468008108060, -3833984178], [-9884750224428, 4856334218], [-19841164239249, 306757815], [2303009732384, 261471726], [-6504711364494, 14421799014], [-27999421987023, -2881816713], [-13249961055801, -10040583369], [-35288247690495, 3252142939], [-1893464624196, -17421469956], [-14298007725664, 17610214050], [-30855038594400, -17872834330], [26847410860852, 16707296520], [-7172232054345, -20875908471], [54173703092968, -11272145004], [11544453849114, 10103375842], [-10859242197830, 17883921312], [-25776901821744, 81675420714], [21988281283952, -83717959860], [84019373527638, 40368477060], [-5760375396273, 19781422563], [-63160598800682, -26840307096], [-49581874981269, -93256960479], [-19589138533503, -157594190255], [64385279978648, -98871578856], [-30580008421874, 84630054528], [186051954341896, 62508300372], [56900256896484, 168648241940], [-198718996522482, 34817518096], [38160803330154, -276746133492], [84823399155672, -196900912842], [-40985389810528, 299027149686], [278071080615090, -45587463378], [38345812470864, 369378942498], [-268532954744715, -109965745971], [-331690469506402, -234367427268], [-495907467714936, -163646574480], [-41485460998041, 335416498187], [-198289866110886, -448300606664], [-331518370937030, 36305617824], [134579200897215, -271859169047], [79710892822342, -290555471466], [-278507125852506, -598486484126], [469869019192638, 281170782878], [-335616243378172, 529931663820], [283937855500503, 367982749707], [-305485368871280, -887021538876], [654959347175808, 196402344120], [627310076182641, 272841415035], [784410618299967, -788356100787], [-654987839320684, -509050273032], [-540686612645520, 916004139642], [695054306426058, -267847076754], [-222801289831476, -1684089900650], [1455123002463414, -1008195769054], [485932228156980, 195899406906], [-1093173427833114, 28697291874], [750222490722094, 551545296876], [2151794571636654, -619277195854], [-1175963884963389, 969142630953], [-1748124529217811, 1265879002269], [1611605100015734, -1348968815028], [-650573561683080, 1730308387464], [-3628417416223242, -545658785496], [1050279656019696, 1767023341766], [120556420502080, -938446248636], [-1589485845689110, -934213072158], [-3713924390631660, -1465134237886], [694999203887252, 4527445858272], [-1514854276736346, 1354582517646], [81976838912298, 915812973108], [886609159193853, 113954046617], [570851432066122, -3817448025084], [-70924620179392, -169378217586], [-1421455312245213, 4392564862053], [-4542836211882765, 2572771658055], [-2337684756304288, 3323388334572], [2552250148425270, -3755721716432], [880435497486182, 4903607273400], [-8690477966063280, 284157074928], [4162816369614292, -4304585585844], [2627515089555552, -6704135523630], [-1941929564691450, -4940167352886], [-5532937776414495, 3190717412625], [-1201205550793560, 4521442878936], [3139598644108806, -2948794426584], [-3158944427852343, -8832487918345], [6150549773271478, 8293815919044], [10718452088297811, 2218284111397], [6293231778608376, -1924107148764], [3242807912753955, -4059182806179], [574746192979290, 8773956088768], [6054737532467608, 881597833308], [4564120491014292, 1273245767078], [-7568483374021730, 8518208838966], [12084384825370161, 3989747811813], [-2054389268808356, 1484208239310], [-3369003020311914, 3933400825310], [-3253828889750818, -15866123722488], [6981942931846209, -8123675447313], [6620616940333736, -12003409117620], [4686720196744323, 6625871986219], [-10790466325350578, -10138458197304], [-2677866204953889, 25056124401381], [8554255697833232, 19800478372356], [-8051544087696774, 10242477490194], [947184063152484, 958684192272], [-2354479621099443, -633555545691], [-7869888252883676, -1901443581396], [2943809085654477, -10757255998941], [-472730661325306, 18476897572332], [-9818641967479407, 26658518933179], [-5077878559324695, 16559135399749], [8522930045442834, -14192577651448], [15594892508435690, 3307561441794], [6553787714999316, 9294900099864], [10840080933328320, -15299847358626], [-10083389891459004, -18706444548468], [17308426505107436, -25150675180644], [-17119213629534214, -14574089581308], [-14368331071938544, 790748084430], [25748322340246695, 17429029485369], [36994744046386413, 18799795364737], [-32999105258182430, -24904527601644], [12663361321900173, -24874164171123], [4730715840948648, 68346678591774], [-7055010212280324, 57002552826156], [52494488608279131, -25519208716055], [12524135138821818, 23713965018630], [78100350248769318, 5942109229352], [-5956105603789600, -10044113483592], [-22452419988395686, -63092210325012], [888958780837782, 10374541601958], [-7339252285272600, 16854741994004], [-34903298581952984, 1276223852106], [-8068329639636345, 27542372031397], [60518348564692059, 1740476694595], [34871942928282291, -17547738379803], [20563879199118282, -25753923623484], [34455928144349732, -65414254720896], [-653765920573488, 38290525870086], [-61395525226158444, 44701682289636], [16808206815959968, -48012871758066], [-24918520512742551, -73193450335731], [47528586308909212, -11106593869392], [1621512345156903, -71160536680735], [65328981881054445, -74277593745015], [-32061851678648349, 112889876884481], [47980494747561176, -34846142510250], [16104742793953144, -14364717109902], [-108461074474355715, -53012500256925], [-92027521069504218, -11956128402306], [51309018996673680, -34345256019462], [-94455270228607404, -32200794449820], [75351657459475424, 110116258764426], [-149080065167970672, -25337144946114], [-165996804592762920, -36793918083588], [-51659881452500805, -150270191421819], [28486198862995052, -161946889512084], [-8121179277321039, 127831843750077], [16488916071174306, 139467770759304], [-53134909307420752, -6753157823772], [-37242559885293286, -24300894970296], [-30307774906616715, 77848842388999], [-83684001752997684, -86056606452636], [-57439102748889492, 179645174432512], [-54812560663706526, -149204346367206], [149683623948452630, 73225238326380], [-59434070102526956, -198281385356940], [-33331355803701585, 53631074899301], [-82590590690913321, -151030948009513], [106603999370766342, 51332514837824], [203880730386846862, 111580642193472], [15789920920398364, 111210839503524], [109493950387177638, 134581642472292], [-95939028237210992, 66039117219936], [32171979141240192, -111964605645300], [94344137954810300, -343718719093746], [-115007559895033119, -104979331490209], [-11396580526023273, 208642551002287], [-154522566150818124, 281941952974092], [101240102617236459, -40221591386673], [191197761724069830, 46723828153248], [169488064346075704, 270670030112916], [-104267002061665508, -67637004141204], [335072210775334434, -93630323530872], [288238628350242368, 81852553089828], [81899293747007160, 352297387208328], [-29934067804889528, 14221719570582], [253834721073838548, 84474938801478], [-115193858987722797, 214847048218743], [-159372625190776200, -116581395531392], [546126475634855955, -73584208181857], [163720500421779464, -429164449434468], [295937930950633292, -209757999595356], [-143791130477085480, -74493276198606], [427993698914182053, -113998175988517], [-446392347187312206, -68096885949750], [-24421505737295256, 118840418023896], [448495416669221802, -305821324807306], [-423680248416826978, 297060622572042], [-237358994927587461, 145935334095219], [-195196798877162630, 97557870246228], [-530054212505296941, 125534359484457], [-70182509578242579, 127827595556973], [-151550064116631740, -362787842218086], [168787779062260347, 386481065449301], [359329408339662765, -186339448594663], [-581037690950007904, -229595325742350], [39474474411750048, -210228000962652], [132840347004667035, 404223741854125], [-469961407487470930, 303917788484532], [-447959764894375502, -218634650537310], [401689803780617787, -49455454906793], [-176672809395509540, 552845749765302], [265523617642628926, -50972518680480], [199247737117332015, -668295826561323], [151499154880923304, 483694693089012], [-147899645201027052, -275057736619074], [136873579835573703, 255674546262133], [1146399488880683602, 52988875715934], [-400250904926837058, -197488260224928], [407472615438755358, -6915764683872], [-277590447965544196, -861294542723712], [-643162831164651444, 230972956474770], [110450706909103052, -560207975565204], [776856361747371988, -463258230419790], [631052498626360956, 385449167200068], [408294973144416141, 171332477077745], [-685662519952753776, 807385088515770], [-234196354960771124, -1000834710225822], [94977364109036202, 942592417125510], [784534600038834612, -203510968280364], [-806619307133487510, 186138488183922], [-605102303376207756, 325468782424860], [-393923518153310350, -179228879903268], [675095238535888932, -1146945832124760], [422124807009057957, 670598438328317], [-92979637974649806, 660454499834496], [-836455146635154636, -914440607285818], [45811434803871476, -1489579407482580], [-171389930149710999, 813160235309295], [-1306283057570299752, -84796398641502], [609542383721785848, 622193189522436], [752159265917388192, -1353566519280954], [-1558356709441717242, -753912847308710], [436535775106526558, -497058907254552], [210023703378287235, 1289167357534653], [-1173508047335339932, -347918762684556], [-881555285404002843, -920274306021561], [-1090765245812120694, -556986312503490], [-175595229502770972, -2155185074953008], [1416803747263527730, -356544573000984], [1230689194841492334, 522020091194424], [-761896995384945266, 1197170261697726], [217386418456173213, -2001979493151879], [-457795721722561162, 606600484903026], [625174429990092590, 111125831777100], [512382936971751795, 2273756466296503], [1554454815498193316, 160936342510374], [-1391691652803677511, 789122387658905], [1110360995820701384, 658411539980058], [-707574248298251028, 1991335848346140], [-245499545665029150, -2605588775556044], [-629729025400622160, -1928739682222946], [1583642199269936408, -812956382125236], [-2341351081894483089, 266614613784223], [-946130101285612996, -1672757982936270], [-1283183484483784536, 353364266968548], [1057185313661473335, -2743406494506593], [786950990078321780, 2782779367402530], [304112086986127356, 1696071793640250], [-1978288192332067324, 651802865760000], [1691556082317756184, -634725132354882], [-596902737572158761, -2010096244225503], [822153825248983732, -1893594063538044], [1665500703841160694, 1828057494331900], [1333693827522388028, -466729777917270], [-1285253074371425110, 538411582905966], [3803616201389407012, 493771826630520], [548379167600088729, -2676001117528159], [288550226602552158, 1404180619776320], [-874213298276574382, -353443787619012], [2580436502424594810, -32623104897100], [-1555216638810785052, 1309894252341444], [2766668292341887986, -1631586496154866], [-372609641489573702, -927742602402378], [-1857834982869343326, 2131911728511526], [-927979674345621810, -826062706822824], [1853313748165767825, -147063491206121], [-125659336848237544, -1443718907507826], [1713312822898318588, -436525205299668], [250932092689285070, -5367613782705120], [130234875500166336, -2973006386354202], [-432499205209185387, 157778765470983], [-3690087741872079012, -1596981765929292], [4218779175672936294, 180739166546304], [-693802660023592875, -3196711637030271], [-2895860035698163576, 1588604344149042], [-5747310775135535764, -753714524715480], [-2743288643279432988, -842664403177836], [-3516703230473362521, -572168889040503], [3114851299023016544, 2153836615174380], [-1347799343353781464, 4780060156029726], [-1316532440551278312, 4213978971977634], [-898879814816416548, 1881622410788268], [5219264401725200734, -1376452012966704], [-2261733949508286069, -70729397152807], [-1245553631927894016, 2781057739663600], [-3307631794285736052, -4015646909620080], [5015429922560648310, -288280585579036], [-197201006522485371, 7690419029971589], [-1912110467045599946, -3818909748619656], [-3494091875626717515, -3657961774016893], [5635642841092116477, -1887802597660811], [-2790642322700701731, -1447016928630319], [-5042843873968582496, -721035405673380], [1659041534503893920, 4975129554894198], [-6262591417036351227, -1268217273443745], [5566643647796583618, 1508470082973882], [-1554043756140102836, 184238153285490], [4121904048323563467, 4664441476820375], [273152342947520464, 1817226357315876], [6823200092581414665, -2827911390408495], [-3047419130762901708, -2050951954019738], [4212133652946107260, -3756623189043708], [4113811470058596448, 3669378553715274], [202016944801681920, 5534494261492620], [2948216078607410223, -5343319558170073], [916854601726226926, -5938079423483988], [-2167479519288309909, 7754501019060161], [-6041469091192670812, 2483199461462202], [-3083828084800739217, 5515862285351145], [-79935738305668974, -1184062670067368], [2682647780418491116, 2840031161951796], [2221205796152926398, -8794390890352452], [-94202744040511628, -9274322329340832], [6629723335796193612, 1563370784867092], [4806445503079999640, -387268748543592], [2345235588077035864, 6574249923694146], [-2234163407385609806, 1115176929949854], [-2399694372389870946, -92741959196866], [2746956916653225728, 7508545233638094], [1065353071907769993, 6983508471685419], [-5227553269773376767, -3277817351827003], [5836515460901594096, -8274394630157076], [-6613349699391770871, -7101015567438839], [3637285983931884798, 3957167368403316], [4995488008485468868, 4375929879017604], [2888051358981859155, -4737203769120799], [9061680383906604738, -2886563264899842], [-9932721212886874038, 632535843412412], [1359624338005561718, -2474496835182792], [7760100286061858142, 6627629679527004], [2982313939795405546, 10234339120618650], [-1530604651734323343, 8290748028866335], [-1806237761049663399, -11072334355195221], [2185961993953546568, 13241775546190800], [-7229543143602237968, -5182666807728150], [1248294555927455922, -476727674982528], [14204115731046388004, -1990497201817248], [2156829687300434346, 2106206730323846], [-10431685848740823206, 1935103959063720], [-11015273063833342866, 7412968330851776], [-163953457293935493, 8751637969717391], [-15010577867486114316, 3466695720747096], [4955198679144487544, 5388162946675470], [-4836556508601487275, -2648231159392945], [-6371354717904307149, 12853309125851099], [2707605818708031064, -7634991788572896], [11045257347612453975, -3908445325866963], [-3993966729572613606, -15340795152652766], [-6370895310531465906, 8196546687456488], [-14785375229322508270, -3836821132075428], [-10599103760614747731, 52035087006485], [-5865933319688176416, -2128787613147708], [6724004248200826778, -13121925650090928], [-16820971671036751893, -4060841762490779], [-14295174627220830189, -4473569648072897], [13914024080721932016, -1038844422044874], [6705056720586923724, -4836458027581200], [11842294416545291706, 5604159066199826]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_84_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_84_12_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_84_12_a_b(:prec:=2)
    chi := MakeCharacter_84_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 12));
    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_84_12_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_84_12_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_84_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,12,sign)));
    Vf := Kernel([<5,R![-5164600, 8910, 1]>],Snew);
    return Vf;
end function;