
# q-expansion of newform 169.4.c.f, downloaded from the LMFDB on 23 April 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 = 169
weight = 4
poly_data = [16, 4, 5, -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, 0, 0], 1], [[0, 1, 0, 0], 1], [[16, -5, 5, -1], 20], [[4, 0, 0, 1], 5]]

hecke_ring_character_values = [[2, [0, 0, -1, 0]]]
aps_data = [[-2, 1, 2, 1], [-1, 3, 1, 3], [10, 0, 0, 5], [0, 1, 7, 0], [1, -15, -1, -15], [0, 0, 0, 0], [0, 16, -43, 0], [0, 5, -73, 0], [-89, -33, 89, -33], [13, 60, -13, 60], [120, 0, 0, 100], [-73, 44, 73, 44], [259, -20, -259, -20], [0, -97, -179, 0], [-100, 0, 0, -140], [190, 0, 0, -165], [0, -55, -377, 0], [0, 200, -351, 0], [-283, -91, 283, -91], [0, 105, 11, 0], [-250, 0, 0, 85], [140, 0, 0, 40], [-180, 0, 0, -100], [523, 125, -523, 125], [0, -469, 27, 0], [-151, 320, 151, 320], [-1080, 0, 0, 320], [367, -601, -367, -601], [230, 0, 0, -260], [0, 388, -659, 0], [-1853, -481, 1853, -481], [820, 0, 0, 840], [0, -16, 663, 0], [0, -245, 297, 0], [0, 40, -1913, 0], [-960, 0, 0, -540], [254, 0, 0, -417], [0, -1103, -781, 0], [993, 1721, -993, 1721], [0, -223, -1771, 0], [-473, -445, 473, -445], [-970, 0, 0, -105], [0, 335, -2159, 0], [-1421, -352, 1421, -352], [-1313, -1731, 1313, -1731], [0, -1325, 2157, 0], [111, -945, -111, -945], [-1111, 33, 1111, 33], [0, -1051, 1823, 0], [-330, 0, 0, 1700], [-4162, 0, 0, 276], [-5576, 0, 0, -300], [0, 2680, -989, 0], [0, -45, -5691, 0], [1493, 116, -1493, 116], [3831, 1587, -3831, 1587], [0, 45, 2553, 0], [3921, -695, -3921, -695], [0, 804, 5093, 0], [7990, 0, 0, 725], [-2601, 303, 2601, 303], [0, -3148, 3359, 0], [300, 0, 0, 2120], [5080, 0, 0, -1120], [-3450, 0, 0, 1980], [630, 0, 0, -2355], [0, -2815, 3299, 0], [2690, 0, 0, 1295], [0, -349, 4717, 0], [1323, -815, -1323, -815], [3511, 3552, -3511, 3552], [-5304, 0, 0, -1200], [807, -3081, -807, -3081], [0, -5088, 2069, 0], [193, -5355, -193, -5355], [0, 1653, -4729, 0], [3890, 0, 0, 3135], [0, -3189, 6287, 0], [1139, 280, -1139, 280], [0, -1020, 5163, 0], [-11373, 395, 11373, 395], [-8862, 0, 0, 625], [-10251, -2455, 10251, -2455], [0, 2488, 2021, 0], [-7677, 975, 7677, 975], [-11260, 0, 0, -2100], [0, 4295, -337, 0], [3143, 7016, -3143, 7016], [0, -5860, 5299, 0], [-14120, 0, 0, -1080], [-6920, 0, 0, -5220], [-3867, 2225, 3867, 2225], [0, -1111, 7763, 0], [59, 1175, -59, 1175], [3220, 0, 0, 6500], [0, 1027, -3951, 0], [9287, -4540, -9287, -4540], [6738, 0, 0, 6575], [6299, 5243, -6299, 5243], [3110, 0, 0, 7785], [5860, 0, 0, 6020], [-15133, 3004, 15133, 3004], [0, -3513, -12631, 0], [1253, -3645, -1253, -3645], [5620, 0, 0, 2880], [3214, 0, 0, -4047], [11853, 5001, -11853, 5001], [-6522, 0, 0, 81], [6380, 0, 0, 1600], [-14291, -3080, 14291, -3080], [0, 3351, -11363, 0], [18799, -1492, -18799, -1492], [0, 2876, 14607, 0], [-14420, 0, 0, -2840], [0, -9175, 4619, 0], [0, -4840, 16029, 0], [0, 3973, -20949, 0], [-9997, 2011, 9997, 2011], [2229, 3743, -2229, 3743], [0, -5585, -14027, 0], [16479, 6000, -16479, 6000], [1081, 8612, -1081, 8612], [19210, 0, 0, -4580], [0, -5967, 20711, 0], [-12519, 8305, 12519, 8305], [-14150, 0, 0, -8220], [0, 1720, -6413, 0], [0, 1575, 8753, 0], [8920, 0, 0, 5860], [-6890, 0, 0, -17855], [20157, 2225, -20157, 2225], [19709, 8193, -19709, 8193], [3671, -3645, -3671, -3645], [-3747, -5649, 3747, -5649], [0, 5415, -249, 0], [-16833, -3255, 16833, -3255], [0, 13907, -1361, 0], [0, 941, -15053, 0], [0, -7471, 53, 0], [10573, 8660, -10573, 8660], [-13968, 0, 0, -1700], [-33641, -2795, 33641, -2795], [0, -7197, 4621, 0], [9236, 0, 0, -13728], [-5843, 7220, 5843, 7220], [0, -4055, -14293, 0], [-4590, 0, 0, -5755], [-18630, 0, 0, -8065], [-4820, 0, 0, -4480], [-16192, 0, 0, 11516], [0, -3176, 38583, 0], [-11691, 8140, 11691, 8140], [-11140, 0, 0, -15140], [-46117, -2349, 46117, -2349], [3143, -13149, -3143, -13149], [25760, 0, 0, -3420], [0, -13765, 11737, 0], [0, 160, -24973, 0], [-21350, 0, 0, -3605], [-10390, 0, 0, 1760], [1033, -2499, -1033, -2499], [0, 8693, 1261, 0], [2160, 0, 0, 10040], [0, 10135, -25699, 0], [-7113, -15716, 7113, -15716], [26640, 0, 0, 8500], [-3069, 3695, 3069, 3695], [0, -1496, 7393, 0]]
