
# q-expansion of newform 1617.4.a.m, downloaded from the LMFDB on 17 June 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
    R = PolynomialRing(QQ, "x")
    f = R(poly_data)
    K = NumberField(f, "a")
    betas = [K.gens()[0]**i for i in range(len(poly_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 = 1617
weight = 4
poly_data = [-4, -1, 1]

# The basis for the coefficient ring is just the power basis
# in the root of the defining polynomial above.
hecke_ring_character_values = None
aps_data = [[1, 1], [3, 0], [-2, 3], [0, 0], [-11, 0], [6, 13], [54, 4], [24, 23], [-32, 8], [-38, 65], [168, -26], [-86, 107], [22, -86], [-76, 120], [-132, 163], [54, 58], [32, -53], [178, 80], [-16, -95], [496, -56], [322, -317], [-176, 124], [116, 30], [-130, 216], [1142, -18], [562, 476], [128, -54], [712, 315], [-778, -340], [-158, -12], [-488, -746], [-772, -308], [1754, -364], [308, 332], [-110, 525], [992, -838], [2282, 214], [-416, 1497], [1816, -1324], [578, -1630], [1700, 44], [-318, -750], [256, -1646], [-278, -1742], [-226, -1920], [4312, -812], [-204, -1138], [-24, 454], [-3404, 2014], [1330, -638], [-3878, -12], [-2356, 853], [3650, 1173], [-520, -195], [-366, 2775], [5148, -1509], [1914, -384], [-7124, -473], [1398, 818], [-1874, 329], [416, 767], [-4070, -1218], [-6100, 2696], [3576, -1992], [-6170, 184], [2926, -2718], [4644, -772], [6858, -1874], [9100, -212], [1078, 3209], [1674, -3119], [8496, -1612], [4632, -1986], [-642, -1836], [2992, 2647], [3072, -1520], [3094, -2626], [-2414, -1004], [506, -2378], [6998, -660], [2432, -5731], [-4174, -1087], [-3660, 3867], [5894, -5438], [-3580, -2809], [4236, -328], [-8438, -854], [4066, -342], [-8894, -1150], [612, -6035], [1992, 1439], [1400, -634], [-12856, 2560], [13560, -2181], [-17176, 647], [-2888, -2160], [13258, 3640], [4570, -2593], [-2648, 5145], [-3618, 8334], [-3236, -5796], [-1798, 8021], [-4276, 5196], [9562, -1448], [-13756, 7916], [-11362, 320], [-8072, -4935], [7998, -5934], [-7568, -4812], [-5806, -1785], [-180, -5873], [-20322, -2204], [5146, -11964], [-324, 7854], [360, 7644], [-14126, -3280], [-7812, 7608], [-12180, 8561], [10750, -2854], [24928, -3329], [6050, 594], [3514, -3666], [11346, -576], [-5612, -1538], [-5916, 6342], [-21050, -4888], [-7118, 11533], [1684, 4213], [-25896, -3796], [11394, 4760], [-11124, 12704], [3708, 8651], [-6780, -8419], [13562, -3317], [28630, -1690], [-3454, 1965], [14334, -8465], [17136, -9375], [14686, -7619], [-19714, -9691], [-8056, -12759], [15258, 5679], [-20740, 9445], [-4200, -2365], [-1462, -12546], [11732, 4931], [-17590, 1820], [-1890, 16640], [-7468, -9888], [-28616, 10828], [21742, -1614], [13714, 4335], [-248, 7231], [8464, 5254], [-16508, 2656], [6432, 13322], [3640, -5396], [19914, -21615], [-30090, -2224], [44882, 3286], [10652, -5094], [-10066, 23341], [8256, -16678], [28440, 441], [16394, 13066], [-23272, -8632], [11396, -25851], [-438, -11404], [-25438, -14572], [-4722, 5539], [-18408, 10891], [-40110, 9728], [36784, 1792], [-3782, 16088], [-5752, 3182], [21630, 2076], [55764, -6404], [-24738, -13704], [16124, -3627], [-30338, 8299], [31972, 11237], [3580, 1088], [16606, 2644], [16166, -25530], [-19400, 18020], [-61298, 2987], [49470, -5762], [-14476, -8650], [18874, -3960], [30904, -6230], [-38242, 12372], [24880, -9387], [-49424, -8255], [-25314, 27741], [24880, -7573], [22450, -8607], [38066, -18736], [38950, 604], [-21842, 32318], [-26264, -12140], [-9722, 14244], [28644, -851], [-50190, -1854], [-5430, -16673], [63108, -160], [14570, 16936], [37312, -8224], [22168, 1593], [-20838, -4496], [16692, -23444], [-26302, 26404], [41222, -567], [-45084, -12633], [-35356, 8188], [18512, 2286], [-4010, -18224], [-672, 1372], [77142, 2716], [-1512, 4898], [12438, 18052], [59534, -12976], [36012, -8323], [-53846, 8026], [-42964, 11063], [-19076, -8008], [-5602, 5792], [2770, 27977], [15152, -21866], [17052, 9293], [5312, -25367], [33318, -12792], [12960, 21333], [-11016, 13526], [36926, 645], [37716, -1816], [-22456, -650], [44622, 24536], [95810, -6879], [14788, 16118], [2660, 37111], [29828, 13312], [-10364, 25696], [37936, 8534], [21222, -35756], [4574, -38770], [42328, -16472], [58192, -27684], [45736, -11669], [-30892, 49100], [28596, 28435], [-42698, 24748], [31422, -18186], [-55272, 40242], [-46490, -900], [-37254, -31220], [-62076, 32840], [85834, -3145], [40760, -10479], [-89146, 11297], [51346, -21413], [97112, -2666], [47764, -9024], [25082, 32828], [-53298, 8163], [76426, 7893], [18420, 41954], [49702, -13796], [37242, -17793], [-44, 44372], [-6002, 10204], [-5286, -17146], [-57760, -29719], [-79394, 11886], [-7592, -4478], [-36294, -37209], [13664, -32846], [-96148, -2800], [84214, -18964], [60602, -4200], [15692, 51624], [52768, 30656], [36136, -56368], [51376, -40118], [39142, -67537], [110960, 387], [-17832, 54544], [-56730, 54865], [49950, -57068], [40720, -27070], [4150, 23576], [-11082, 12768], [22876, 19052], [55646, -32403], [59204, -32448], [27534, -48106], [10402, -1914], [77000, -17498], [62018, 5984], [-78300, -696], [45384, 22895], [13034, 7029], [55314, -13189], [-39296, -2008], [51396, -66716], [-77480, -8675], [-56810, -239], [-124948, 6912], [-38214, 55422], [-132832, 7708], [119206, -13622], [47176, -61338], [-57914, 48686], [-156298, 2813], [-38148, 4880], [-13088, -61080], [-133770, -12708], [93660, -34712], [-26168, 12656], [-32522, 12522], [15298, -56280], [63432, -57049], [-24530, -55339], [-113110, 8940], [81312, -34728], [-110394, 4895], [25798, 614], [-82740, -16296], [101332, -4012], [-37668, -35207], [-50654, 10653], [89038, 28702], [-129714, 32778], [-93508, 45995], [-107340, 46338], [63332, -67228], [-52752, 23199], [-33654, 68529], [-58162, 19398], [9622, 76464], [44144, -99712], [12254, 5060], [-40166, 208], [-83230, 8600], [-72252, 20151], [14918, -90744], [139072, 17587], [-34086, 30812], [-188380, 13876], [-34368, -52532], [-65230, 27100], [90252, -25248], [-41930, -30381], [62510, -27938], [-18628, -47357], [-208802, 1884], [-125714, 26004], [-49172, 85743], [-135836, 25620], [-25674, -29291], [18784, 3028], [-86650, -28222], [43814, -69062], [206680, -8400], [152632, -38789], [92252, 24928], [-32578, 41493], [56474, 8492], [18864, -22666], [-115702, 48272], [-97684, 35410], [54972, -16026], [-66212, 8009], [-14070, 65891], [-131800, 4208], [-117414, 51185], [-212320, 14009], [183740, 5037], [176266, -45525], [-7418, 85400], [74662, -5984], [59838, -68363], [-63726, 33166], [-96992, -36626], [-101690, -24931], [-27908, 22456], [-178956, -5269], [120692, -26643], [-51398, 27436], [-28244, 49210], [-115036, 793], [-156738, -40637], [-77198, -38884], [29868, 33944], [176812, 8576], [-76904, 43066], [-25654, -42376], [-171540, 31419], [89586, -13227], [47524, -79460], [-93902, -12211], [-148250, 47417], [70498, 69352], [5992, 35722], [-191778, 39268], [-72838, -13042], [64348, -102667], [-71574, 9801], [-165582, -1336], [-47660, -25506], [-40756, 42964], [182206, -4056], [-88258, 49444], [-676, 12144], [-36980, -47568], [-168918, -33972], [-118714, 26079], [110740, -17689], [-15888, -67546], [203478, -46536], [45296, -5958], [134742, -2636], [9854, -65515], [-25360, -77014], [61340, 37474], [58310, -77788], [225942, -23973], [135324, 41158], [-24370, 4777], [-85444, -84658], [-83304, 110040]]
