
# q-expansion of newform 78.8.a.f, downloaded from the LMFDB on 26 May 2024.

# We generate the q-expansion using the Hecke eigenvalues a_p at the primes.
# Each a_p is given as a linear combination
# of the following basis for the coefficient ring.

def make_data():

    from sage.all import prod, floor, prime_powers, gcd, QQ, primes_first_n, next_prime, RR

    def discrete_log(elts, gens, mod):
        # algorithm 2.2, page 16 of https://arxiv.org/abs/0903.2785
        def table_gens(gens, mod):
            T = [1]
            n = len(gens)
            r = [None]*n
            s = [None]*n
            for i in range(n):
                beta = gens[i]
                r[i] = 1
                N = len(T)
                while beta not in T:
                    for Tj in T[:N]:
                        T.append((beta*Tj) % mod)
                    beta = (beta*gens[i]) % mod
                    r[i] += 1
                s[i] = T.index(beta)
            return T, r, s
        T, r, s = table_gens(gens, mod)
        n = len(gens)
        N = [ prod(r[:j]) for j in range(n) ]
        Z = lambda s: [ (floor(s/N[j]) % r[j]) for j in range(n)]
        return [Z(T.index(elt % mod)) for elt in elts]
    def extend_multiplicatively(an):
        for pp in prime_powers(len(an)-1):
            for k in range(1, (len(an) - 1)//pp + 1):
                if gcd(k, pp) == 1:
                    an[pp*k] = an[pp]*an[k]
    from sage.all import PolynomialRing, NumberField, ZZ
    R = PolynomialRing(QQ, "x")
    f = R(poly_data)
    K = NumberField(f, "a")
    betas = [K([c/ZZ(den) for c in num]) for num, den in basis_data]
    convert_elt_to_field = lambda elt: sum(c*beta for c, beta in zip(elt, betas))
    # convert aps to K elements
    primes = primes_first_n(len(aps_data))
    good_primes = [p for p in primes if not p.divides(level)]
    aps = map(convert_elt_to_field, aps_data)
    if not hecke_ring_character_values:
        # trivial character
        char_values = dict(zip(good_primes, [1]*len(good_primes)))
    else:
        gens = [elt[0] for elt in hecke_ring_character_values]
        gens_values = [convert_elt_to_field(elt[1]) for elt in hecke_ring_character_values]
        char_values = dict([(
            p,prod(g**k for g, k in zip(gens_values, elt)))
            for p, elt in zip(good_primes, discrete_log(good_primes, gens, level))
            ])
    an_list_bound = next_prime(primes[-1])
    an = [0]*an_list_bound
    an[1] = 1
    
    from sage.all import PowerSeriesRing
    PS = PowerSeriesRing(K, "q")
    for p, ap in zip(primes, aps):
        if p.divides(level):
            euler_factor = [1, -ap]
        else:
            euler_factor = [1, -ap, p**(weight - 1) * char_values[p]]
        k = RR(an_list_bound).log(p).floor() + 1
        foo = (1/PS(euler_factor)).padded_list(k)
        for i in range(1, k):
            an[p**i] = foo[i]
    extend_multiplicatively(an)
    return PS(an)
level = 78
weight = 8
poly_data = [-147, -1, 1]

# The entries in the following list give a basis for the
# coefficient ring in terms of a root of the defining polynomial above.
# Each line consists of the coefficients of the numerator, and a denominator.
basis_data  = [[[1, 0], 1], [[-4, 8], 1]]

hecke_ring_character_values = None
aps_data = [[8, 0], [-27, 0], [-38, -4], [456, -7], [-3272, 47], [2197, 0], [9826, 128], [37836, 11], [38400, -696], [40710, -834], [180920, -537], [30726, 4088], [-348386, 4670], [-48444, -670], [17764, 3365], [1169494, -2662], [132752, 1351], [2161782, 3824], [-90508, -13005], [201020, -9221], [-576334, 35112], [-264424, -6864], [-883104, -56031], [-9490586, -11758], [-2611638, -88552], [-10006738, 69502], [-826584, 210458], [-10291548, 126552], [11408022, 49808], [-616614, 244440], [13368376, 183970], [10384556, 155752], [-31552034, -156130], [50603428, -57272], [-13965870, -108300], [15769600, 583489], [-20078698, 120204], [25852028, 607137], [-5816628, 506109], [19300678, 577106], [6067716, -933018], [70449662, 730512], [-18375184, 558142], [-46384734, -1003132], [18606186, 398556], [-52349040, 754238], [-71148812, -1543868], [122599928, -61545], [86850088, -525331], [-60185202, -1004596], [-226084782, -377628], [-39238140, -1422489], [-95107926, -876472], [-192406972, 2546050], [192394026, 2336124], [-13594976, -4644922], [119446310, 321622], [207490640, -532047], [-241733778, -272308], [-255071314, -3520082], [619595132, -62010], [92001442, -2020240], [211274820, 4334717], [200090304, -4370568], [-465485558, -4558928], [-649363278, 2069424], [168019916, -1928049], [266239474, -2352080], [638184732, 8755008], [-584419730, 3267364], [-232855946, -10695478], [-806458404, 3915417], [1321146192, -5611288], [530789278, 1793404], [-518891084, -12486761], [-1221270612, 1975419], [-199743850, -9759602], [1075226542, -10498532], [210814398, 8821542], [-441498814, 7668588], [1357748588, 2929528], [-940440690, -1810036], [-56270308, 8550715], [480006754, -10704632], [544035576, 2862806], [-1538892044, 3877160], [2849785374, 7597590], [-692653502, 8311132], [-185597454, 24391080], [-465611472, -28642675], [3526438876, -1657762], [726908476, -10196467], [-394344528, -14694481], [-1221433452, -12395130], [-408885932, 12824071], [-2906159968, 16744942], [-4025427774, 7193880], [-1365840046, -20432708], [-1867903452, 2731664], [-394233802, -31145688], [-6990859876, 350724], [59431578, -42609228], [2404186340, 3853834], [472759890, 23032656], [-1317332916, 49485110], [-4080008654, 5477896], [5031757976, 45606421], [1421079630, 41527974], [-4017846480, -23987142], [846789770, 4821000], [629660720, 20431272], [359603718, -82448968], [-766884498, 96334398], [1230449180, 8355189], [682377040, 1390249], [8584125058, 27280400], [-3119782876, -97160217], [1687337112, -738300], [-2107783610, 36204914], [6492822036, -57614328], [-4331157162, 12663308], [5680978866, -44660656], [4766216950, -5834362], [6618512680, 74767367], [-672893628, -140715085], [9715127966, 22198042], [1221256318, -69760868], [-5426233704, -88028280], [8354362688, 80411562], [-3413235738, -170984188], [4430584212, 48027245], [-1029166932, 38869107], [-3999137920, 157004994], [13790172622, 29859676], [-6329371858, -101219714], [-2751092782, 81349932], [16171953186, -22448244], [-4343722380, -137938747], [14316305534, 73723774], [-6218256830, -41127772], [6149160580, -32970701], [-8807113374, 140933676], [3429003992, 179999910], [-21236156728, 60975331], [-1024754874, 51993116], [-10434940700, 133313897], [24650536662, 56572172], [14066696322, -108042096], [11098682556, -199720576], [8598946844, -102252881], [4896585822, 124829444], [-17570341910, -22666228], [5831773332, 231848942], [-12536279928, -230067690], [11321472972, 32155466], [6760761296, 257013946], [5814537824, -92647980], [15892752854, 41383930], [7856056778, 4084800], [-2300757302, -210818344], [32558116504, 95505671], [29161927026, 14703624], [-18945828144, 132280295], [-31236964964, 137041028], [42970817118, 50728734], [-8219583564, -338113419], [-25868605520, -348124784], [-4413841842, -309029632], [-5731551366, -129720592], [396356446, -129235966], [-14019023856, 153418329], [-39292534898, 155786944], [-22229122336, -491050484], [-12694470974, 91619512], [42333100512, 103989086], [-41323452678, 168045744], [-39340839220, 194286885], [8432998882, 31016864], [-57186712568, -50786762], [-13764631098, 231669956], [31485970416, 513194945], [-506179244, -104522986], [2798673854, 154084788], [-14436937722, -134200086], [31386672708, 492143577], [1278320342, -379464650], [14676359670, -152034928], [-1721796, 74114195], [-67549744206, 114404900], [-44634159324, -587574063], [-4946054238, 61976576], [74856189672, 54247353], [54945767852, -522264876], [-10705595942, 26140580], [47195825780, 67869466], [-70681099230, 236997228], [-103494735134, -147614792], [26755625302, -488263544], [41635635726, -646431522], [35749340632, -8064478], [23014100466, -575272932], [-7734539696, 1070766112], [49954473054, -111572320], [17044244162, 144997056], [42795464768, 196184359], [71617119166, -129631150], [-85346225128, -189048885], [-81944319332, 12677972], [28535169318, -685527102], [-51717761284, 634638906], [-76444052094, 626051720], [-26661012714, -338609922], [-88480675200, -4363036], [104853071880, -223929129], [-9227357612, -41180029], [-16073461382, 548211640], [125145668104, -347714660], [-9701060382, -1000257852], [-114972586948, 325985419], [-43277861030, -76310164], [-24268501730, -1470265580], [-79376726520, -910283899], [-88388715394, -1203882098], [-105016585960, 1137452907], [10581139980, -434487750], [112647735342, -58275280], [107017680122, 917475784], [73165246440, -1146496902], [105795203040, 770270570], [-7658723328, -572518149], [25310747206, -1310217584], [-26120691572, -83704124], [-8227704784, 65306871], [-1266757110, 1406179164], [-4425557148, 1245144212], [87198158820, -861632277], [39872714202, 1279226984], [31856506962, 1396045344], [-37612751956, 583741666], [168929144808, -481752690], [-64181202896, 590554565], [-2324260260, 1001721170], [-179065078496, -254173892], [163730667150, -453238468], [-4662645218, -899732554], [146921270448, 553949400], [189747714304, -923078735], [52647261048, -5235657], [-193664274092, 490139923], [136300817880, -236880936], [16463842790, 1498801068], [11242570006, -2014526926], [90643321220, 1455818425], [-90478852390, 1287733896], [-98436834474, -454429338], [-174972913056, -1107556317], [115100508574, 1030591864], [94654934084, -1915777353], [-72483383850, 1538668482], [-131952403126, -405113640], [-290088236664, 280837214], [-98022566700, 1451952312], [-223679967810, 435011384], [-156816311146, 767593656], [-97980522114, -2414450226], [58038853060, 872323396], [-218644721502, 1074259104], [58533733422, -485168538], [114988254908, -1243165707], [-252155709618, 702134946], [266639400438, -1066579768], [5051184244, 283683595], [-148071171582, 1129654088], [165046692592, -1151577878], [-118296482718, -1898428744], [-191612340056, -274217117], [165346812624, 2991550689], [64786749294, 1150056536], [108335534042, 2230628004], [-142966985508, 2291489754], [13215048336, 2489857194], [-49496583640, 2314569681], [-332927648296, -1559551766], [107294687094, -949980136], [22048310588, -1790859699], [126246728832, -3436928844], [-230627262302, -1731170744], [168775838642, 2769654124], [-170849845024, -2163996867], [-165174505446, -1428590868], [283341920126, -614547386], [123342151172, -301199000], [-228236235802, -1344937742], [307758685776, -1822195173], [-61757857306, 5296952052], [-418984294434, 702714510], [199059977280, -1343590240], [-323982560010, 891281754], [-83151993828, -4386109812], [-8418262396, 3206801721], [193813575386, -1366258464], [-382576064958, -3034086732], [-235711507024, -696408198], [362915966964, -307804680], [283619755124, -4298211912], [125778452186, -1651988016], [-272236530564, -3284306850], [168759171158, -2980312236], [-12998382396, 2653785585], [-128742557602, -3718655508], [319721754040, 673850402], [-554015956646, 1086040964], [-131565091398, 6512178900], [-388766728252, 145570632], [99635816652, 6479269473], [261451906794, -5280241336], [-25144178808, -76473999], [400418386284, -2409365997], [240358613066, -5169109572], [285342050306, -2018602916], [180830995020, 5615809010], [-271317605702, -4077658016], [198544185678, 2143497858], [-286733873752, 1004603049], [263096516166, -5849361918], [340942547682, 5377853144], [280882736700, 5937998261], [-106553936980, -3229309881], [240955270912, -2043879664], [324644699982, -5884389030], [-644762062154, -3535223516], [-207669972730, -170633486], [-209179258056, 7015988240], [600867802304, -2467019801], [-278125599372, -118611289], [429946302472, -6554030047], [-121633878082, 5487936612], [-47437905242, 7260572930], [174216810258, 1485582800], [-45958065024, 4984541150], [-792977369706, 227203532], [365987903874, 6642474516], [-130247238366, 5553009336], [175075846280, 2023731270], [-104041318926, 3188638512], [237620085220, -2811629818], [779001866222, -3290922120], [-1669559388, -6690628615], [161015508884, 86650933], [425521887622, -7497705166], [-419733746636, -3438616013], [482753652642, 5051047772], [87158654970, -4129483008], [-244295999848, -8172603702], [-1045359517970, -269669864], [312968308530, -4620007344], [1019244880500, -2649016515], [335911295520, 914804973], [98645401002, 4012976376], [-340228436268, -789153957], [-301779717594, -3725604148], [-264483292694, -5359073812], [519242866440, -4224069474], [-636983661376, -2242325747], [-163799890596, -10442577130], [933101989002, -3520389520], [-725600040222, -4609614564], [342233417120, -237163503], [629500063098, -4237556536], [-1041558949108, -2947327580], [-320092764284, -8625356330], [968898869588, 2222417665], [-329800458586, -2183861510], [-417377215312, -9410171676], [-101090630650, 988978092], [-1372109237136, 1448653917], [-491063368416, -10802603532], [715143198354, -7714097104], [-89784735342, -16078390356], [-207719919174, -4191751672], [-678494208630, -4665410604], [237552963566, -3405134306], [12644533272, -14320142659], [-9671811874, -8405180690], [691381305004, 6284616229], [-1074726584428, 3354286333], [781628469472, -2311393961], [-1180057515218, -8217625748], [353256750868, 7561342195], [-273363844984, -8677060586], [828818685018, 9752109668], [-333849785982, 14764119276], [-1106299010200, -1195938437], [1535431863252, -2965858348], [-492430434772, 11206605853], [470112426170, -9969052008], [-253771730464, 13158966183], [974986624042, 6777729512], [1197963192284, -7944797568], [171553421578, -12833913592], [249544910782, 11319504448], [936306196802, 630356680], [-261129636272, 19626998173], [889278580934, -213102590], [-831547049958, -8875844640], [351660795760, 5777134444], [707466856630, 6931324156], [195713553918, 7562824302], [-754811590972, -15949005615], [920214165968, -3185516873], [-165710622254, -3983451152], [-863384266458, -2393479290], [-379184778116, -8883383752], [-84954993956, -10014067622], [-693879639638, 14536259056], [-148324650082, 1288413394], [1503555216740, -506575349], [-367587650960, 3844643596], [-851301623986, -8166264194], [-178513318560, -3402985296], [193122402278, -2735058950], [854361116342, -1065074640], [-173980649804, -25457039989], [-1298184484604, -5235906340], [-768573032822, 2061304840], [125412708922, 19220785304], [1063088144716, -8823406354], [130648264422, -4780034430], [-373571014588, -175250619], [-1318473636168, 3225107466]]
