
// Make newform 80.12.a.j in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_80_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_80_12_a_j();".
// 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_80_12_a_j();".
// 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 := [-151, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 32]];
    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_80_a();"
function MakeCharacter_80_a()
    N := 80;
    order := 1;
    char_gens := [31, 21, 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_80_a_Hecke(Kf)
    return MakeCharacter_80_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], [110, 1], [-3125, 0], [-28950, 33], [309088, -1650], [1707130, 804], [658970, -7908], [-2662660, 17160], [-29471970, 2091], [47070190, -143640], [-122271732, -450450], [10501610, -1189608], [-372871658, 1415700], [-314975050, -869319], [701030770, -1281567], [569160290, 11672124], [-3658757780, 10988580], [-758212838, 3348000], [-7867145070, -5730717], [-16469235772, -3425250], [-14991424430, -21226116], [1651411560, -35977260], [-6649551210, -68801139], [-6337385430, 90955080], [-1540351870, -284116908], [43118460702, 194407800], [4872759910, 228406551], [-148271607750, -11438517], [-8108731270, 745600920], [-229226954470, -16111896], [152862492410, -68858667], [431249652768, -340527150], [-30837648990, -81589008], [21666125980, 1245477420], [924273719650, -330906600], [-868794124252, -959998050], [795446852450, 452853192], [-779038591130, -1225272579], [1633753407930, 3510045633], [749035993170, -2686818216], [142249751860, 4507493340], [-2024990248018, 5430234000], [3737955510308, 1785138450], [3465547847450, -784333956], [-2308525846470, -3249388308], [-2645579186200, -3821371200], [-4053832556912, 7403142450], [-5176459851170, 4139056791], [-5954557006390, 5211102783], [3605577513990, -21506480640], [-113554278390, 26602769364], [1480945470280, -8474449980], [-5118617279858, 19960198500], [-8499532462752, -8641586250], [-6031088410950, 15427588392], [11466739254470, 1331645871], [-12876374355190, -64183698960], [-1058656645372, 31558834050], [26175460828290, 10370383992], [27178583660982, 50928188700], [9299004926190, -1553705139], [-22935790250550, 113733708144], [3547753353650, -61252086117], [42944218312188, 78254431050], [26762254375130, -139780411896], [50932617480370, -64184558508], [-9539232167832, 180483256650], [28249674994210, 272915686392], [-55676928860030, 214837508583], [-30880259434850, 172814262000], [-41944029649710, -36922179576], [19505926968120, 451048022880], [147988652664930, -120911521167], [6304516136770, -196553976216], [-174951505636540, 271993280040], [-107087900001810, -208327251489], [-217099562743230, -185806075920], [-6813364590470, -113671292508], [-49300384860798, -156937893600], [-315044811955570, 310494555420], [-371786087869660, 363752594460], [-395507050960478, -12270277800], [99646338864468, -583394262150], [-434573403047390, 318443724564], [-32093314391320, 238182009120], [-154460651669850, 454577299881], [278766447290150, 984078849300], [259329563665450, 1119942091392], [-15644846809338, 912880771800], [-200520869270730, -450601662429], [619557688080530, -299637680517], [-308612783574840, -1648013961660], [72805954563490, -647627349267], [-300174480066592, -1597978073850], [-695424367984900, -1044222817200], [547411997009510, 1340858169951], [-1096427185874770, -1029266102880], [208453684250122, -741462316800], [615747463502030, 830256622341], [1195136775326742, -32662284600], [84926225889770, -4226453432817], [633793458946650, -459594595608], [425917167217470, -1190832389679], [-207058311595890, -1946826444660], [439184274871528, 4164159472650], [462730429250090, 5511543800592], [1007598778754490, 4794107671083], [1002412880460850, -5492435405856], [-1054192307502400, 2065335880500], [-1113459935079898, -5012906344500], [-2810806823305150, 250687920033], [-2879403210701270, 2733173601204], [-508630992912630, 2382401506692], [940111201298740, -8471558401440], [-2729136620643532, -1350749329050], [-1495393658151858, -2099700896700], [-438447096269250, 7609970873481], [1914550262232370, -535253528667], [1277925799623490, -8855849108676], [-757551780381980, 1423603164180], [-2944713244585838, -1244665174800], [575896550741970, 3653405640684], [440497844973690, -3711717795708], [-259006655391210, -6637071775239], [4202996166280808, -6112788406050], [1096032534452602, 4825086298200], [3424880494195030, -1736945801880], [1125729986746440, 8276422099860], [-998777606209190, -14249630198367], [-6088126720024990, -5441760063936], [4530310531234580, 16648874388420], [5508934195095550, -4189319672469], [-402106419657652, -1671733260450], [-6358661705048750, -1742253085008], [6114091486087962, -6302049151200], [3509957552231810, -22527309483960], [8346713263588170, -712124374116], [-1666188982550710, 26007834942183], [-10515532289392670, -10641633881508], [7928743033849930, -6919287578880], [-13175778647288112, -16228306217850], [15276928441267122, -12799254730200], [7962692451983230, 15447943266891], [5070125214041410, -15132104810217], [-3998578876123110, 11324935575360], [-9269145734351920, -10084568623380], [-3519205024610310, 2335743410124], [-19084895335263550, 5583067699992], [-2183194093990180, -17291000968020], [2758517311676270, 22530062611671], [2832260906338290, 4831257337392], [-4892535016086418, 19613209076700], [-20498884353986210, 3368979492561], [12516801470275290, -37130851769967], [-28106562176703150, -10013896779417], [14622622353980188, -15715775473650], [11794170715568240, -2457826832340], [6785946428311990, -50403366810540], [-17099516572041990, -9074600284308], [-3647871907970858, -79398722325600], [-21935476044890430, 62219915910483], [-5784594199913110, -28117619914176], [-1548045950206670, 75845437949133], [7358602534659528, -83584866984150], [17777563250648690, 86181159228492], [16416451484239590, -44468975522889], [10650329825322508, -79302731911050], [11650817390732130, -70809532147308], [1344895397702930, -3431358410280], [22920738243797530, 45732898364004], [28752190619486340, 25439049701160], [-11438057504327978, -101485795281600], [-20296052760225732, 60164169988050], [-37990719042441390, 12455472274164], [2538151313061680, 141506467384320], [37020906381385050, 93619820383800], [-12817358597804952, 58280927635050], [-6996142125460338, -155882023080000], [17520165162066670, -115229472515829], [-11669452202102390, 101472799899840], [-29095667890462910, -36520291505367], [-38438888110716592, -96346803512550], [-8058478351657550, -120428855906556], [21057085197620530, -185784340524708], [24214553161567710, 103437365310951], [49998599374803830, 15632535165720], [30659507731307370, 66145074411192], [45925865994226430, -34773079397559], [-42611539065023410, -80103469993140], [-50231175769039652, 6482451882750], [-9644740362868310, -2309308230576], [-55933324200027530, -108031935876279], [89933320469635128, -93068792846250], [-96655890250318918, 21264320794800], [61764022917562890, 245044472866383], [-47287286680815350, 88656021871644], [33679025948127502, 29576562849900], [-19205895886020270, 280617756360804], [52489396432617570, -109919621783808], [33946326136055030, 44803029557391], [-8276988032589810, -42908929256040], [-20095526561610732, 52660466497650], [99080277055113810, -29571959745708], [60368688067714450, 62697160977600], [30115936138467420, 67743978374580], [-59649621733540110, 239844425091792], [16739386851120160, -262055956567560], [-142515502102412210, 87459711880161], [-99840713298221430, 350388012664680], [135968123042214808, 82726537667250], [133409406148953530, 23885575957092], [67856426287010002, -58002527507400], [13982233441711110, 603539159064951], [173765920558221850, 74378587152483], [-69591948923786160, -308616467785740], [-148909192587529978, -271365123499500], [100716240845075210, -172477322315067], [-58163009184226638, 487167167167200], [-55567480766220070, 230454171409833], [3589561608212970, -553145184706116], [218474046198997282, -130543571233200], [72970807079000800, 85832851634700], [136490964856432530, 118933683111720], [111400836492017030, -278913965421309], [-228371136362752390, -384373058572017], [267141858512108690, 213371923186560], [-34862746842268590, -26746171971036], [26795440232814080, 264972255373320], [52139426695456370, -40815815472867], [138291347136562248, -505981183866150], [-77672393840105910, 511323170820924], [65352575670953420, 422054599995480], [-60454935385117772, -410635559606550], [-223053678752641018, -634761849684900], [-170701960145663810, -908579360958339], [-391825819668986310, 341021215290333], [407547549393862470, -246647329213020], [-183110645415536750, -178212028707756], [85119735200206500, 368171955720000], [55908646113487788, -207138084380550], [-162780423053112570, 1208093579873541], [-17699737690974432, -485632459297050], [334415348904157550, -391451510380269], [-218234434829482050, 452053861890000], [4182777083145090, 155054083890024], [-333397860442817480, -69691211390520], [-300583547508288470, 114252232548333], [-312783258208896872, 297175011136950], [-97043550314525540, -664103483202060], [613212721968247990, -148515241125789], [-77976262311727670, -745170242785308], [-69218103885260398, -1490326460604000], [-211185564602543550, 1121894417052333], [234505729881124830, -688000133919780], [445934066973997330, -838542552800496], [230872226174118540, 59255085786960], [-79775444247950978, 1504719227040600], [-62336167038283790, 1417381991779983], [-391484274378837390, 925978632540792], [-520500312081419350, -56370697718208], [505454841502337870, -649347729448329], [35192083894886330, -1656101382495417], [240823639458279110, 94635104780640], [-305319598587328950, 1034605819807344], [862345678698583530, -709142805577308], [332708942000523500, -352236976473600], [426373783329230, 329303866506720], [80127450075428122, -826109894540400], [-483431825816098970, 1136497920073641], [411057339539030810, 1870062581101464], [-381751855934532058, 1774808141504400], [638339305357403570, 1232753627126283], [534484638805636490, -1025790719000076], [-18833092065212880, 1627986758737680], [-363169810935531510, 1782052211078592], [617152002071431390, 592025569028211], [-782576990205628110, 1231666837159983], [463141251504123870, -1627789624540920], [310539286668291702, 1875896955446700], [149119069937567088, 1862488640606250], [735615475045829630, 1348970986128591], [-198412238619254932, -1706480812449150], [-485400963335371630, -702597919777467], [319791131827228062, -387538061527200], [-527968694598090870, -919437678190317], [-1040649858146469972, 943194120005550], [-335518278875657030, -2440875780598116], [634289589504195690, -932260893502908], [-714676533796865840, -868823919211860], [-778936800433613130, -349618043164620], [206897838177168202, -3323128262718600], [229531184465437850, 1270950164069583], [-916380909535892670, -2657822689757196], [841545484328221968, -715312197667650], [-1881080532414646990, -314524833476736], [734956994417102250, 2424379279986600], [-1809890937983844452, 764918086254750], [252169142383598970, 2276583744075984], [737280274291895460, 3811184436324240], [584154484042678690, -2032775010802917], [60069462432566850, -218751676287456], [-169178638678623070, 2695854260885592], [-1107722414409614200, 3187461341715900], [24412959824520510, 3858397425345201], [958059587789554688, -604622833499850], [199825050945946370, -3789289916556708], [2201571029485902210, -454859803537617], [-273268032838337410, 924071733355560], [171534726023444280, 921858172308120], [321351739581867690, 3418943459014824], [687241859454735870, -5673109603743729], [-2049678183927870090, -476880737315760], [139577903146024482, 5064586304062800], [-1802598835445282210, 4042158046556361], [-1212514985005411510, 1194180057505833], [27848321994076570, -1517966458582920], [1057716538742439900, -6302811212712600], [-32107373415442212, -7743785646674250], [-1431750738705557670, 125020038102504], [1117533563058863190, -1414970236751340], [-424049569747390232, 445115634832350], [-1594005617920035790, -4791220619823408], [1074049365894093242, 858039378765600], [-1630056487571546650, 3435625853532531], [81806714162727090, -619223594252376], [-625092194049819938, -6540696922433100], [-415670631278356340, -8228451038507760], [-3573546006571493290, 180886391519601], [-711206699048733150, -6431760636506367], [-595135672254637870, -3116928436869996], [-2698250448700758678, 1382025184618200], [828457166184103010, -3132933939688608], [605579117017346680, -690264403455780], [1818875232578001350, 1708658424659181], [-1433307232109131952, -2828915079680850], [1975301409173306330, 6848834912023683], [-2727512961772356790, 2908503974583240], [796735166746535770, 5569955196749184], [-1937652943154696218, 279992444543100], [1514681182030051290, -10369832734349067], [-2763775602955676150, -1281475025530656], [-2266999281303306470, -4708270893621408], [-1136618748906996270, -5516176620183480], [-1583259782979171612, 7159959781476150], [26707694969005610, -10272570160536], [-1514285423033408820, -9313252037572080], [-1816301078129933758, -137106358620000], [-3144188545774790830, -7721707469273817], [-5997097014506631252, -901223309718450], [-3079160961738942950, 5772560002679292], [711163932013231728, 9383893424767650], [3307264445915030490, -5501045708782008], [1460789939971191082, -1603527638512800], [-124780734978598810, -17257029694156989], [-368594772024326730, -15814491064957920], [4404510544396246050, -5566372019599956], [1114892133801996200, 14619202488843900], [-2338609405084935912, -6519766235413950], [431111478222111570, -10939006411397508], [-636482875072825970, -1795981387806309], [-2775907010522705390, 12163789980945492], [-422044408225397158, -6399912312876000], [-4434835616530994430, -2835777982438767], [-136887175947885380, 10626005942606580], [-3860153851383814070, 11672375389251183], [1258430406018350170, -482935802996916], [1003270794200980890, -2509553631445908], [5439580038205304310, 2839758559329351], [4716851334276067622, -9722851889010300], [1294607561861721168, -1562746331430750], [1998057868357518180, 5933826224554320], [3408918332917165750, -12497484890418669], [-309054451409985150, 22099265263672200], [6889231132136414148, 3067991615548350], [2536708340061003850, 2239747603749492], [-6910743972292285940, 1294474174860240], [3758397013725730908, -9696211224448050], [188907277494837650, -19336849636851456], [6798280713519743430, 984442634698020], [414490082431949170, -2271132203190408], [-2801423871618856778, 13850700471283200], [7694549809821932610, 3991779294846264], [-6375045893470975630, -4555716953450667], [-6049029058437983150, 5454219473497392], [-4365995659167181380, -4714136004998520], [1127801008940763070, -6437990745593229], [8182286395345044628, -9345144208890750], [-7639591770973813510, -3349009405274808], [421243770480225990, -6879528436887639], [5718322548308106690, -12509173432559967], [455695918725227670, 14409794613288180], [-1502982776259830350, -10424165245106856], [5170730652236021500, 15856498838679900], [-5984113436923656350, -8327199301674717], [-6359639390666547212, -95835055530450], [1757149480745382530, 115418600152704], [11274957442794398440, -4058508380110140], [9401045041244559690, 1670714092056960], [-5200597409395109632, 9201084921061950], [-5437195010267239758, 6419187841522800], [-1987743517353624950, -16107464682474600], [-518496947981673510, 25995422382855924], [1378586812718164130, 36921390412000833], [-3627109988650674110, 29803579826625792], [-1606649866946336030, -30032319889161120], [6358758112295886308, 14559123757038750], [-889599889295111470, -18484178893741908], [-8840267608241443598, -10458948508129200], [2541143366423384310, 9826782308972301], [3301659897448118340, -30953267590951740], [-2918222542217694990, 28807700375246664], [-4079713136545913190, -33022736389136808], [4473838910357452750, -21707399858727219], [-10281229969358876352, 1305428069771250], [13737872931119598050, 2492667421349292], [9668464697300802662, -10817659388747400], [-15692502154944219040, -5404808293149960], [12855301346147733290, -17224815635078967], [3290364350093604930, 25344935132284692], [8481165300134895710, 28032525623307651], [-2955374294859337670, -6847387866224880], [384755773992905770, 198432422305092], [-9846428385721768590, 14534605438971633], [2371552422927629980, -18790096505584980], [-2193317332320246310, 5211060312760224], [-5051786386468031950, -25504301840126808], [3550678569224692670, 24002003017357521], [2664164089948816110, -29999616758273460], [6797016619519406728, -30474828863018550], [-8992226965380601400, -22655616358534200]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_80_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_80_12_a_j();".
// 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_80_12_a_j(:prec:=2)
    chi := MakeCharacter_80_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_80_12_a_j();".
// 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_80_12_a_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_80_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,12,sign)));
    Vf := Kernel([<3,R![-142524, -220, 1]>],Snew);
    return Vf;
end function;