
// Make newform 80.10.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_10_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_10_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 := [-79, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 16]];
    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 := 10;
    raw_aps := [[0, 0], [130, 1], [-625, 0], [190, 69], [-51360, 30], [89570, -564], [158010, -348], [-68636, 5160], [332730, -6393], [-3446874, 5880], [-145916, -26250], [5630690, 59976], [14886726, -72180], [5854090, -99615], [-31246650, 42573], [4708890, 212532], [46465428, -373980], [97836962, -721440], [109883710, 203139], [-155603508, -1397610], [-49612030, 2047716], [-271130888, 70020], [628457850, 192957], [-231145926, -5421960], [835858370, 2902956], [-593410074, 3512040], [221674930, 960723], [249042630, 5435043], [-726810718, -1177080], [-763442310, 13181592], [-4425461570, -7684191], [-438215520, -29723790], [-4562549550, -16951536], [-3276221276, -21103380], [-3893692326, 15977160], [-4241962580, -52919370], [-1802716150, 631704], [-5200327670, -33654435], [3622830, -109829019], [6033752730, -39181368], [20120817132, -31184580], [1868195030, -9437520], [-4045319028, 211723530], [14961338330, -71205372], [10284296370, 4522884], [9530496952, 90525120], [-7052087504, -173409870], [17392057930, -229646085], [8107988550, -4030497], [-21212864146, 58986240], [-26817249030, 333620172], [-11554367976, -197678220], [16175404814, -140156580], [-50380749600, -190455450], [-6281712390, 277620312], [-100072707630, -4792821], [41240171058, -817339440], [15073810540, 302388570], [-11884468870, 1099932648], [44344622406, 910845060], [101670486130, -712207707], [97046310210, -242777520], [102274523710, -608327541], [45587739828, -179012910], [137326658090, -1390226376], [-161227146150, 259723932], [137606920792, -161514630], [-126530990590, -1506593784], [74126232030, 1857192975], [360018204950, -883612080], [203891824530, 1071014904], [-79341904344, -1817532960], [-54375776810, -576658179], [372062485370, 962419128], [107446254268, -1438135800], [380822692410, 2341372227], [183838550874, 452220240], [387667343330, 2227520076], [140179190370, -2969575200], [569175787166, 2431842180], [-772137282756, -2939060100], [636913820666, 756762120], [-459921283236, 5679437490], [-242441264830, -4017285204], [413950061752, 4805148960], [-243183984390, 1246459137], [167496460806, 335582700], [1042843024730, -2155836672], [-513733206210, -5087981880], [698658521650, 269391303], [1026679377630, 1390279275], [-235494243816, -6217550220], [992561459110, -5394966303], [-70709287200, 1627339350], [-658472549276, -1031668560], [-3599220270, 11873375979], [1106148875046, 2784123360], [17965062714, 6376147200], [-486139326350, 3686895693], [1170694100654, -15672561000], [2077320826150, -7212961233], [-442620804990, 351145080], [-2020367856750, -2408422911], [450217464030, -20787710700], [3522141156952, -3728230950], [-381299545750, 525114864], [2823403235910, -106720317], [-2718204624750, 9624184224], [-3930607558080, 3829718340], [2072229737270, 17974239060], [88903639510, -34295369859], [-1731049021150, 4947253596], [-1352323390470, -22350324708], [2279799676300, 8081101440], [778435665628, 19319414430], [-2156581307538, -34090131780], [3295186212850, 7139276073], [3859099092630, -7099379751], [2119116417930, -1314857004], [-7993719098436, -4170063180], [-446412433462, 10977961680], [-1269128866030, 62205321492], [-6998619399630, 13452098124], [4723454537130, -31960769439], [381560883352, 3410779230], [4976157968130, 1440325320], [-2322921561154, -69700159560], [4840236023064, 44637103620], [-9620591428370, 11798915733], [5985918236810, 34563357504], [6468463294540, -56373978780], [-9198204807750, 22752569367], [-9355741693436, -3971363130], [10156025871050, 15591317904], [1377068364522, -69609472800], [3401690820482, -2853109320], [-1624023880830, 15951738900], [-2674204206170, -37808296713], [-6362802246390, -33579090444], [6207288287034, 75692678400], [7264217059696, 31601446230], [3896141278506, 112998109560], [-9044140698470, 59709310791], [12427495861470, 23036954655], [2412995306402, 57518556480], [-106883870352, 5360973660], [5840557301330, 105758149860], [-14242078014510, -53900734296], [1639572880804, -115064028180], [-14062835400390, 118210764507], [4729044128570, 13737984528], [-1099248393618, 107851512420], [14995451074930, 67606481793], [-3496414089810, 88760050341], [-24130089529490, -64091125377], [8197545214068, 42672479670], [-2028548491184, -212982755940], [-1832576801322, -11657513940], [-4383092796310, -73293953676], [30239177319822, 62261948640], [-34401042140370, 80160703491], [-24533966036550, -61531654848], [-5188274037290, 77116045761], [24836809734264, 139111339290], [3398550777810, 250832562804], [9610292513490, -81369589341], [32636549761924, 75535414110], [-22163381320390, 136204402428], [30625281169970, 89867580840], [21207743820210, 163400851884], [-26128491235716, -66125203320], [17490276011054, 106710632640], [-3455053091532, -25077782310], [-12231852028030, 170686481196], [-8243616827504, -302057325120], [50053220385642, -98731851000], [-41422813207208, -165272122950], [-31901388853866, -182183386560], [-42677406707510, 137900907735], [-14835089699086, -98239727040], [30395016451030, -335996999259], [-31157451124368, 123651451770], [-24855820340470, -202142883636], [-4581422810910, 294044126340], [-27839512604310, 266968724091], [-1005676329090, -70738374840], [11630702700530, -96868562328], [-5673550323470, -94310609847], [29084714057342, -151762398060], [87321039934068, 73915658310], [31579182655850, -397079072976], [47432124374730, 402974073393], [-24063191084600, 295995050070], [16099571947650, 628623196560], [14970403410630, -29361950577], [77614766653050, -44566827708], [48852038463374, 101247236820], [-10931243918470, 353660104908], [45896240317410, -102612865920], [729068940450, 592964602635], [20579015868966, -653801070840], [1997989751068, -683973265590], [17796474190730, 465083454204], [-39195900384046, 278613000000], [82542615397860, -2683088460], [-9394884465510, -925179794448], [-117611314892192, 260932128600], [41301335089890, -376486985535], [-35116225312326, 236645927640], [-106132065670616, 506116985250], [-55930798491430, 132835190748], [109241977642122, 478642200360], [-76999323418190, 347087554083], [-51406932378810, -104196950037], [24549745160688, 164841880260], [103816960564790, 152304626700], [-35297591146610, 47733283905], [137819331580818, -84483759840], [56556293869230, -1072671078819], [-113816898489870, -450544722156], [-188267108457094, -62630680080], [97346488255648, 738165302460], [-63128176740462, -161268404520], [8704364855650, -361745981433], [-118033586938890, -632092710753], [106657462813898, 413339813760], [-97408201996830, -423762495300], [183759942268800, 91019658600], [147767945231830, 618602486961], [3423858545784, 1229691479370], [7396455279410, -814147391148], [-22423375458668, 1242541046520], [116221954043452, -1441091469630], [104966750977014, -1738185238140], [189427783759810, 563893105509], [-128260333162530, 1557998751705], [82077748886342, -831808367460], [-50986312375350, -1463403424644], [-55874230126500, -1716039753120], [54105184956420, -1206416856990], [-239981169987510, 473223071253], [52017142756384, -283532392170], [-61301154143030, 924079597695], [-175091409917290, -702843244560], [-398865434910, 1869355362840], [-50841275906904, 2122883516520], [-132215010193010, -1872973253895], [-16348208949528, -1484252627370], [-117071843823836, -1239011519820], [350371599486450, -7857834009], [67086932857490, 583506696780], [-60006170380782, -2607209220000], [-182096437816890, -1625202216447], [24005150921294, 1775364440580], [-63631508565990, -2205459743568], [278369461482708, -641917854480], [-30483397775578, -176866131960], [37404789607150, -694350226377], [-88308757930230, -2374428913944], [270508924946810, 148490400960], [122051903646490, 2721999031131], [-61641301261290, 2785250957319], [413529073726574, -260330531040], [-75372762311470, 2367317591760], [93047539499370, 28001344476], [77291305835956, -1553039402400], [171523792440486, -2778054488160], [-295473981199638, -586967780880], [274896732778810, -764149025151], [-323613311895150, -2602889715384], [359581550793182, -2099564725200], [172930174633150, 3174899972859], [109955603351450, -3404339625492], [16325187738256, -1126453771440], [121811344972010, 494099035584], [-55635635089670, -1850725705041], [203467924949550, 3643917738711], [178477808107670, 4178256515160], [446498098998758, -384619549260], [-195664609569072, 768352115370], [-30079824952470, 751975145331], [-19638203035196, -3715695377910], [339582611577750, -3949039230711], [86535176193062, -2204219121120], [-37306970483210, 3392726608683], [299340594320676, 708805955670], [400802098292570, 2378880677028], [456814151175810, 900928037580], [-457766674622480, 469011217500], [339873415215318, 4834698581580], [42528166907058, 4040656989480], [-32188344529770, -3557144918721], [-186327360830190, -496309684116], [-47876568483408, -1693193214450], [-100590726049990, -3682807863552], [368171391643698, 2014597247160], [-780491819871308, 2631054313830], [380726511261330, -904595852304], [-416661329887140, 2635715142000], [7349263836910, -2196684848997], [-701112066876430, 149374326240], [-238893029629590, 4599714978888], [386288447971288, 3824113533900], [-882555941265390, -1412483031711], [621033446281408, -1976608048410], [515857465282370, -5365357981404], [520112172223230, -5694203848473], [421951843560470, 1637216629560], [-649691971583064, 4075849922040], [407362936697570, -3256817959944], [-54439422012150, -2797002004317], [451173837896190, 697631835120], [654843515781090, -6917169556560], [308890864629970, -3391461534039], [67408224511710, 10488528887085], [-1329470658070006, -866318410680], [-29201143379964, -2741276902200], [378775882225908, -774550644450], [296826780559130, -1399746738792], [-149036036522922, -8671392752340], [149565551794072, 1507154337630], [62788652474690, 1959162784176], [1525332536652930, 311574071520], [1005048172393570, 2816572104327], [-766950714544350, 6806532625560], [-1012044564737314, 886884949260], [-179269860506348, 7898681346480], [1805942567523850, 689022652905], [744346603628790, 8267249112477], [742896818889450, 5104681674108], [-431449912306990, -1100304721080], [350280571628490, -2413228747104], [-1546976099669720, 2216885388780], [-262988570143830, 6467781262221], [-1247310223518224, -1206412577730], [-681728326825530, 5301357861483], [-820723803775150, 8115715848600], [-250742001939750, -10434736414080], [-970985206773994, 3243308988900], [-1721276859002690, -4439986434351], [1444853424312290, 1965575373216], [397622413395690, -2965062021984], [82119172589226, 9016922692440], [-1732096151148500, -1662024146610], [-1363147435600590, -6284657411976], [-943177855879212, 1522444101360], [-1335734125921510, -4253802648480], [-1092283307117330, 5474278158783], [-782523574079964, 8088418456950], [-1497440496903630, 1750400059764], [976090550937040, -10435772947710], [81892989660170, -14027949907848], [-2183548462733358, 734212188960], [-139801706367230, -11551136100921], [334715545793726, 326363718240], [202374405982770, 10470665182836], [-369239295212232, -5428273511220], [2517102221762472, -1361898042510], [-2181581328424590, -5859294578364], [1294437458706570, 4170023595063], [777326273204330, -2332035301188], [172111628404746, -2753421599520], [-144513887425290, -6626093147523], [-1459770384829884, 347062733940], [1243309860296710, -13895497232145], [61585695528650, -10386823994988], [1808272543125570, 12255702617700], [-193884904286750, -5538604040253], [2026524768887990, -3155004708900], [1351798800156912, -2992658078910], [312116624674012, -15447370746000], [1102466517215730, -5144610118569], [625067654878650, 3283906644120], [-325471865858804, -13542208546410], [-2862554615859310, -4055093858820], [170430012518868, 15234754165680], [1761133432298868, 1915442534550], [831320674277330, -2791101447168], [1695035299589766, 10216228691100], [-1409079711423550, 14497109933256], [2178292895008782, 6877769153280], [-1364042338226190, -24332521964664], [-594813385728650, -777422768967], [1844399948374290, -7479654469296], [-1489273495648796, -8582956280280], [-866082302278470, -16920554781153], [792200121216028, 12809671591770], [-1839785442552430, -5538655742760], [-546648175809830, 13117029228801], [-823772000812650, 24174582210909], [323151838018550, -19555440398580], [-1707874464148470, 13991359739016], [583662189720516, -4833738395940], [2177626565649550, 7792319421075], [300925886276124, 16848861639750], [1259157358522130, 6071036199552], [-978795127265288, -12807643873740], [1256504544694074, 1120797313920], [783996472856128, 4093026089550], [-292569155849814, -3018552725040], [1557080101278290, 16016379081480], [1581452033064090, 16354867980300], [-466963446430250, 6105915535341], [839381798344530, -3735954502656], [1500180722191290, -20075528968800], [-1461304239900500, 21364799471190], [-223774169047270, 16968972401700], [-182426884897902, 30424977366960], [-1604763617096870, 22566800335581], [-63673446304740, 41149405534500], [858782628596690, 19161118500792], [-2395431078199950, 3592748928264], [-891102660459630, -35689948517211], [4750221121337728, -12127336371630], [-1122749614001710, -7891704486348], [1106706556407774, -22827888062040], [3958372435543584, 13174285327320], [170171322581950, -31004988700371], [1243470965966370, 36919745654700], [-3681549141324870, -13323140830113], [-1518610923189630, 12698994644400], [30448516420130, -14337867050484], [-2081173281374010, 3792618680733], [-820769795764380, -14629051112340], [6089386263091850, -8565602469408], [-1282813163150790, 23231253228984], [-1361812662056430, 22307506209729], [-1912290711562626, -11257885831980], [399596421114808, 7473293176410], [1832641575950424, 20765223781800]];
    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_10_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_10_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, 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_80_10_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_10_a_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_80_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<3,R![-3324, -260, 1]>],Snew);
    return Vf;
end function;