
// Make newform 78.8.a.e in Magma, downloaded from the LMFDB on 05 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_78_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_78_8_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_78_8_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 := [-2454, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 6]];
    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_78_a();"
function MakeCharacter_78_a()
    N := 78;
    order := 1;
    char_gens := [53, 67];
    v := [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_78_a_Hecke(Kf)
    return MakeCharacter_78_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 := 8;
    raw_aps := [[-8, 0], [27, 0], [-52, 1], [124, -3], [-4262, -8], [-2197, 0], [-5526, 22], [6996, -89], [24260, 216], [-107830, -424], [-97760, 213], [-263586, 802], [-644316, -475], [-137996, 2750], [-839474, -1050], [-18714, -5768], [-495778, 5866], [778042, -1676], [386008, 10585], [-2883890, 3104], [783374, -7622], [5460656, 1276], [-2019966, -6294], [3598224, 15547], [-4228282, -9498], [-10418078, -10698], [4856224, -26698], [7755248, -25372], [6517522, -3812], [289814, -19100], [-6575336, -18710], [6442376, -30888], [10291284, 73125], [-1035812, -49332], [37161240, 86175], [-31226400, 140679], [8489198, 194616], [3540572, -10807], [1213398, 114326], [-9250918, 82634], [-362964, 51652], [87944022, -183928], [44184856, 389212], [-33992566, -40148], [-68806476, -437651], [122179400, 120698], [112642748, 432752], [-124339728, 597185], [46841262, -820764], [-128642862, 763844], [-69974498, 509378], [75041790, -831664], [43017054, -836262], [122012928, -104000], [46860414, 1267846], [173576916, 299072], [-226271430, 582392], [-238391420, -731747], [-178867482, -351472], [-167142284, -1040667], [-633828692, -99370], [432254248, -616325], [-193674760, -686377], [121861524, -2603408], [-670396042, 135008], [1540668, -1924299], [512074016, 1157701], [362546606, 1954700], [1215204468, -302988], [726670750, 586734], [-145472684, 4613], [-79755354, -2951298], [588962168, -3794832], [881934722, -2706544], [-244594484, 142019], [-1493490438, 1471486], [87130470, -6775602], [344441438, 3625562], [-1260096672, 1977167], [-1282452794, -966162], [-1552058712, 3909088], [2372257090, 1981724], [493435962, 865350], [1006300006, 3869852], [534775496, -1230274], [-2699055576, -1895220], [528799384, -3646565], [-1713353978, -4799542], [348258516, -1304935], [27636412, -9667855], [-538039576, 4575312], [615137346, 6732068], [-1766822992, 8849781], [1340373688, -5955480], [477270688, -1711539], [2161935148, -742292], [-3320037404, 989745], [-1694950866, -5492788], [-3359574588, -4480644], [-1005229582, 11599472], [-4652528204, -8859964], [3679770672, -13482497], [495130700, 9075656], [3737061310, -140834], [-1004972796, -1608150], [-1190095086, 3141004], [-264200086, -28152446], [-4705276120, 13876391], [-1722405380, -13759172], [4851734950, -15999000], [-5379279960, 125148], [-7323029098, -1886702], [-8072507012, 1600437], [2375720800, 2581639], [-1145537240, 24290959], [4423192618, 12754670], [-7134282424, -14041703], [6789803248, -2133820], [-9983808630, -9172164], [-4738835004, -20056708], [2833352798, -28737962], [8310318394, -13467664], [-408183810, 33294092], [1244269210, 26708948], [-3174826688, 17649005], [-2550723594, 18487582], [12239392298, 1024552], [11333179916, -11842580], [-5615237528, 9505258], [15471687578, -8958072], [-4809491208, -8483805], [-11510543858, 5560608], [5216660520, 4939714], [10972054458, -30383796], [10582450692, -37562399], [2900249898, 38081952], [7584550664, 34155259], [-7349025640, 51074347], [6718701486, -13130774], [-10355989410, 28363668], [19403855060, -26581141], [11034803936, -23218089], [-20011749672, -2814670], [-5348968782, -12586936], [-2243815694, -13458644], [19372729970, -7261168], [905857678, 15677438], [-20766264722, -196954], [15531139916, -53474876], [2034434746, -45656774], [-12254038482, -62956954], [-31401290250, -3751898], [-9264795932, 60210638], [-26246793752, 18085800], [-20206426812, -36814406], [23061381576, 10128456], [-9966155496, -52423340], [39132564, 35051365], [18285309462, -5156500], [-31114556792, -16326989], [4382850726, 118413774], [-13465686826, -30957494], [8109537224, 89521905], [-2038481724, -1073572], [-15845235408, -104834769], [32203497074, 14281444], [24315594720, 19554876], [-5479138258, -8647888], [-52324554466, -25840642], [-15238503286, -127519154], [22324316814, 47644204], [40949734302, 39461594], [-9622803116, -165838644], [-2719651706, 144418838], [-25438704528, -38808654], [-52097662958, -45163096], [-3013198240, -34597945], [23245534552, -168148181], [19821608128, 185267502], [1778780522, 93677736], [17714468004, -14895215], [61358035276, 61291884], [10078874506, -198515948], [-45851365528, -16469309], [13739142742, 146346998], [-11566898858, 162267270], [6911568670, 69140208], [72995980956, -45176965], [29323025774, -107523290], [29127002646, 114321902], [-36757055822, -67386016], [23309249178, -252399418], [16746075172, 63539904], [-2238501352, 252624335], [-15013737500, 149025204], [-43956903690, 166971842], [21575151506, -57633292], [-71796528902, -119333496], [38166759584, -32235293], [-25260309872, -2147932], [-104595267324, -40894247], [-57521901856, -217144948], [8635424186, 201192080], [-67652328398, 59941816], [19234037518, -369746826], [-26086883586, 230156580], [-6557994248, -149673215], [742087872, 355957648], [-62465248152, -101420117], [31080765156, 125342286], [41023858694, 92709340], [58774950246, 231448948], [-4039534960, 84615296], [-91385339030, -211799436], [-45766584462, 179331106], [-30661233902, -21630720], [10470140176, -33565720], [-16520982022, -403024172], [-14764470602, 438824376], [-40198243800, 175670059], [172424520430, -39964280], [-20939543500, 438013181], [5517890856, 204518847], [155453135680, -120999267], [-46973995800, 82190180], [-74242537618, 277858900], [-163109456782, -24008944], [140815112700, 272943568], [-86730210920, -37978970], [-34306764018, 647859626], [26554019134, -68492496], [-121270417172, 63197216], [46118931276, -258141969], [75673073650, 107721574], [-114279429172, 416295688], [15118646270, 147559072], [-16559643218, 294932494], [-6472655672, 152576431], [-107475252036, -301124844], [-99525163792, -185289880], [-14139164214, -597292270], [-112912824260, 93176850], [-97864163544, -568834228], [-81214070410, 182407082], [-108694603072, 108761239], [106676410308, 136884880], [65116124756, -73360095], [-3076803242, -2704902], [-104979062932, -115801697], [95715378540, 347063756], [-1522367230, 399989352], [-64879877404, 722104709], [229153982050, 264204700], [-159633664570, -279028284], [68261113474, -482986892], [23073290794, -284338412], [98611434114, 401975304], [64219432076, 388680903], [160241943270, 413833678], [-21077020334, -436406280], [-45392174216, -729130674], [54063163380, -287679772], [101037082490, 913527964], [-56542449674, -623896376], [157146499224, -106571989], [19417116580, -864003544], [87041058988, -191207051], [-214161281548, 231037557], [-13036460928, 281925147], [228455100498, 180895214], [-62538602702, -122047408], [19931547496, -87759795], [-247982777898, 342329602], [28490637992, 342802542], [-62184854242, -605786576], [-392107971924, -82163653], [-60349556434, 704810576], [-131332496826, 568479506], [231614771362, 137215604], [4383697752, -185216016], [-67298222296, 777243876], [227795936700, -544381559], [-195168063904, -28720964], [-29518296346, -905390586], [-215967089688, -514896601], [-117544724768, -1209549604], [-276477477658, 814722964], [-18377314552, -75189249], [192371023736, -1053321857], [307397482334, -333374518], [-196852541754, -277833916], [75241868588, -552071420], [-113688656928, -1031434393], [-264069260074, -62608878], [-153087837314, 1047304888], [250012005606, -515044150], [-225265532880, -964643360], [79605983510, 552706366], [84431050492, 700751108], [477311649896, 112565199], [-144537622486, 260201464], [34730402108, 1074385537], [6240257736, 697523882], [263761138316, 513892400], [550058559724, -260165672], [471798445574, -465607614], [430748266324, -319319480], [-90942056682, 75202144], [222749498194, -242249380], [-258183754518, 714109228], [-348292471380, 504309488], [-95731783276, 357693309], [-530465986578, 636554060], [601030067452, 174979508], [-155609075602, -1411743438], [-149324693866, -1131173576], [-108472973658, -1255371884], [-231138500206, 1238854918], [-107630071426, 358548802], [287493074306, 1982673374], [480261211700, 603612710], [345612115642, -881019484], [-131085203082, 1548373808], [18718227272, -712869089], [-129109119736, -1786859877], [-321460478138, -163187476], [175911892060, 273410441], [-272271932880, -1949620199], [-35136528512, 145614924], [-634033091782, -567704900], [349094223226, -538897056], [56388116930, 2004408156], [-416382742456, 140776440], [167882523066, 313807036], [7244751068, 425692411], [37737544538, -416862498], [-686640318922, -575419838], [-90761763028, 1195654285], [101944470918, 342041330], [211350943304, -1976195330], [-270434460834, 1421723798], [-27592348674, -1996720936], [-337449553256, 1836828771], [18073807000, 2666368410], [548998654076, 255450953], [-54380108660, 2651482112], [-665434071758, 1772478720], [-599998399372, -726048075], [-429619406386, 1099806838], [-362213710602, 1953601706], [-124403794376, 1061290377], [488023457758, 1334903778], [577898256720, 288558947], [-418463427832, 1665193022], [209043135210, -2035630544], [466632718950, -468914196], [-627155733450, 615909670], [727784995950, 1342674728], [544783794438, -1936509806], [-283002328062, -459191218], [670585894534, -1161204762], [87827754666, 1356628778], [395988336860, -1819401036], [791033999774, 343199088], [-342377543524, -190790090], [-159961813022, 456992560], [94708280412, 3895369469], [-100087768880, -604760637], [-445209756942, -2226964776], [-452292894168, 2255332580], [49464893716, -93340850], [-452179542058, -1028348750], [155719632894, -993711880], [215375448, -4038497356], [-594482763210, 3290914568], [79336683594, 4650444142], [-196190647176, 3248220388], [170052681026, 249935724], [-888186780262, -1252255996], [34537228114, 254052572], [-1419090023520, -936635409], [946584812444, 1296929521], [595814514588, 1046987249], [178328263384, 2973899955], [21340046764, 4209006369], [-352491185862, -1865407828], [-22808261628, -1611840881], [973686478538, -2619227532], [-1368257141788, -1611068405], [-124493258116, -201434684], [607733662398, -1003743682], [-431323267448, 1528764519], [344014607010, 4813646728], [349187476868, 1835217348], [-186390318162, -4133486442], [218575874590, -1499194092], [264727078356, 5124148063], [989022414842, -1898385838], [405025442844, -2087662388], [-287358530532, -4697385867], [920790028102, 3525085638], [747924666818, 4402879590], [359196227212, -1456075443], [-1901484684464, 969876335], [-421848493188, -5222899675], [653988781520, 222552444], [1009358505370, 2157724704], [465270825648, 175125607], [881814217072, -2397589865], [-1167778812222, -2796978708], [385599442354, 5831765832], [-332700175362, -2556175860], [-406438878604, -345579908], [385714084924, -3616867302], [209522605058, -1519151636], [-1009112659722, -4722511716], [-627790378410, 1821334896], [540220361440, 4903630524], [-312010502424, 235005879], [-232090867380, 3028731996], [-327664169662, 2525136230], [-677029543802, 870930510], [-453723350586, 3996358404], [678430673736, 173509920], [-213715234558, -6612617820], [1094766378448, 4905942051], [455173965104, 651411184], [201605101872, -1057454665], [-548697064988, 4116291941], [-834141663368, 713889936]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_78_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_78_8_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_78_8_a_e(:prec:=2)
    chi := MakeCharacter_78_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 8));
    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_78_8_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_78_8_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_78_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<5,R![-85640, 104, 1]>],Snew);
    return Vf;
end function;