
# q-expansion of newform 1008.2.r.m, downloaded from the LMFDB on 24 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 = 1008
weight = 2
poly_data = [19, 3, -22, 3, 21, -15, 5, -3, 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, 0, 0, 0, 0], 1], [[0, 1, 0, 0, 0, 0, 0, 0], 1], [[-478, -752, 1011, -1008, 459, -177, 79, -4], 933], [[-2193, 1604, 2894, -2687, 260, -395, 164, 35], 1866], [[-2525, 1610, 6498, -4095, -876, 39, 146, 217], 5598], [[343, 6122, -5166, 1953, -3630, 1101, -328, 241], 5598], [[1799, 730, -438, -2019, 1944, -585, 298, -145], 1866], [[-6265, -6296, 10122, 2181, -6966, 1863, -1016, 701], 5598]]

hecke_ring_character_values = [[127, [1, 0, 0, 0, 0, 0, 0, 0]], [757, [1, 0, 0, 0, 0, 0, 0, 0]], [785, [0, 0, 0, 0, 0, 0, -1, 0]], [577, [1, 0, 0, 0, 0, 0, 0, 0]]]
aps_data = [[0, 0, 0, 0, 0, 0, 0, 0], [1, 0, -1, 0, 0, 0, 0, 0], [0, 0, 1, -1, 1, 2, 0, -1], [1, 0, 0, 0, 0, 0, -1, 0], [0, -1, 2, -2, 3, 1, -2, -2], [0, -2, 0, -1, 3, 2, 0, -2], [-5, 3, 2, -1, 1, -1, -2, -3], [2, -1, 0, 1, -1, 1, 0, 1], [0, 1, 1, 1, -2, -2, 1, 3], [1, -1, -1, 2, -2, -1, 0, -1], [0, 0, 1, 0, 0, 0, -3, 1], [6, 1, 0, 0, 1, 0, 0, -1], [0, 4, -3, 1, -5, -2, -1, -1], [2, -1, 1, -4, 3, 2, -3, 0], [-1, 4, -1, 4, -3, -2, 2, 3], [-1, 0, 3, 0, -3, 0, -3, 0], [0, -1, -3, 1, 0, -2, 0, -1], [-4, 3, 3, 2, 2, -1, 1, -1], [0, 1, 2, -1, 0, 2, 1, 0], [0, 6, 3, 2, 3, 2, -3, -6], [1, 5, 3, 2, 2, 2, -3, -5], [10, -4, -6, 2, -7, -1, -4, 1], [3, -6, -2, -6, 1, 3, -1, -1], [-2, 1, 1, 3, 0, 3, -1, -1], [5, 1, -7, 2, -8, -1, 2, 7], [6, 2, -2, 6, -5, -3, -4, 1], [0, 3, 1, 2, -5, -4, 2, 5], [0, -4, -1, -1, -3, -1, 1, 4], [7, -7, -7, 2, 0, 2, 7, 7], [0, 0, -4, 1, -1, -2, 1, -2], [-5, 5, 6, 2, -1, 2, -6, -5], [0, -1, 3, -4, 5, 8, -1, -5], [4, -3, -7, -4, -5, 2, 3, 6], [0, 9, -2, 3, -12, -6, -4, 4], [0, -4, -5, 1, 3, -2, 7, -3], [-8, 1, 8, -8, 12, 4, 0, -3], [0, -3, 4, -5, 8, 10, -10, -6], [-7, -3, -2, 1, -1, 1, 2, 3], [0, 0, -4, 1, -1, -2, 4, -2], [10, 1, -1, -4, 1, 2, -9, 4], [-5, -5, -1, -4, -4, -4, 1, 5], [-1, -11, -7, -5, -4, -5, 7, 11], [19, -1, -2, 2, -3, -1, -17, 0], [0, 3, -7, 2, -5, -4, -5, -3], [-9, -2, -4, 1, 2, 1, 4, 2], [1, -10, -5, -2, -5, -2, 5, 10], [0, 0, 0, 3, -3, -6, 8, 6], [6, -6, -9, 2, -10, -1, 3, 2], [-4, -7, -4, 0, -4, 0, 8, -3], [0, 6, 0, 2, -8, -4, -11, 4], [-7, 11, 9, 1, 2, 1, -9, -11], [0, 0, 0, 0, 0, 0, 5, 0], [-1, -7, -8, -4, -6, 2, 9, 3], [-10, 1, 3, 2, -2, 2, -3, -1], [0, 6, 0, 4, -10, -8, 0, 8], [6, 2, -2, 10, -7, -5, -4, -1], [0, -2, 1, -4, -3, -4, -1, 2], [-8, -1, -5, -5, 4, -5, 5, 1], [5, -4, -6, 2, -7, -1, 1, 1], [6, 2, 3, 0, 3, 0, -9, -1], [0, -8, 5, -1, 9, 2, 6, 3], [0, -1, -3, 0, 1, 0, 21, -3], [-4, -7, -7, -6, 0, -6, 7, 7], [0, -4, -7, 3, 1, -6, 19, -1], [-11, -1, 1, 6, -2, -3, 10, -5], [6, 3, 6, 2, 5, -1, -12, -4], [-13, 4, 16, -2, 17, 1, -3, -11], [0, -5, 1, -3, 8, 6, -18, -5], [0, 5, 4, -2, -3, 4, -13, 0], [16, -6, -2, -4, 0, 2, -14, -2], [-9, 1, 8, -8, 12, 4, 1, -3], [12, -11, -7, 2, -4, 2, 7, 11], [-4, -1, -9, 0, -9, 0, 13, 8], [0, -10, 11, -10, 20, 20, -7, -9], [-3, 4, 6, 5, -2, 5, -6, -4], [0, -6, -9, 2, 4, -4, 21, -5], [11, -2, -1, -8, 3, 4, -10, 3], [-14, -1, -6, -6, 5, -6, 6, 1], [0, 0, -1, 2, -2, -4, 10, 3], [0, 6, -8, 6, -12, -12, 2, 4], [0, 17, -5, 7, -24, -14, 1, 9], [-1, 8, -5, 16, -13, -8, 6, 5], [-3, 2, -2, -5, 4, -5, 2, -2], [-14, 2, 7, -1, -5, -1, -7, -2], [-9, 7, 9, 6, 6, -3, 0, -5], [-4, 0, 8, -12, 14, 6, -4, -2], [-20, 13, 7, -2, 6, -2, -7, -13], [-4, 6, 8, -6, 11, 3, -4, 1], [0, -2, 7, -4, 9, 2, -7, -7], [0, 9, -3, 1, -10, -2, 5, -1], [-18, 3, 0, -2, 3, -2, 0, -3], [-17, -6, 7, -12, 13, 6, 10, -7], [2, 12, 1, 4, 11, 4, -1, -12], [0, -6, 3, -2, 8, 4, 9, -1], [0, 4, -2, -4, 0, 8, 6, -10], [2, 5, -1, 1, 6, 1, 1, -5], [0, -1, 7, -4, 5, 8, 8, -1], [24, -18, -13, 3, -5, 3, 13, 18], [4, -2, -7, -6, 5, -6, 7, 2], [4, 4, -7, -1, 11, -1, 7, -4], [1, -5, -2, -8, 2, 4, 1, 1], [13, -8, 0, 5, -8, 5, 0, 8], [0, -6, -5, -6, 12, 12, 0, -17], [-24, 6, -1, 10, -6, -5, 25, 2], [0, -17, 9, -5, 22, 10, 20, -1], [-21, 2, 5, 4, -3, 4, -5, -2], [25, 5, -13, 16, -21, -8, -12, 10], [15, -5, 1, -8, -6, -8, -1, 5], [0, -2, 10, -2, 4, 4, 0, 6], [8, 13, 6, 10, 1, -5, -14, 2], [0, -4, -4, -1, 5, 2, 2, -6], [-20, 22, 15, -5, 7, -5, -15, -22], [0, 0, -1, -1, 1, 2, 7, -3], [-12, -3, 19, -14, 26, 7, -7, -15], [-5, 5, 4, 8, 1, 8, -4, -5], [8, 1, -3, -6, 0, 3, -5, 7], [0, 1, -3, 1, -2, -2, -38, -1], [-9, 5, -7, 0, 12, 0, 7, -5], [0, -9, 6, -7, 16, 14, 7, -8], [23, 0, -15, 4, -17, -2, -8, 13], [0, 7, -11, 6, -13, -12, -3, 1], [-7, -7, 1, -16, 9, 8, 6, 0], [15, -13, -9, -10, -4, 5, -6, 1], [12, -18, -10, -4, -8, -4, 10, 18], [5, 11, -5, 16, -13, -8, 0, 8], [4, 2, 4, 2, -2, 2, -4, -2], [-22, 14, 2, 12, -4, -6, 20, 6], [27, -12, -4, -1, -8, -1, 4, 12], [-16, -3, -7, 8, -11, -4, 23, 0], [0, 0, -2, -6, 6, 12, 19, -14], [-7, -6, -6, -15, 0, -15, 6, 6], [0, -3, 0, 3, 0, -6, 23, 6], [0, -3, 2, -1, 4, 2, 6, 0], [-17, 9, 4, 1, 5, 1, -4, -9], [0, -2, 14, 4, -2, -8, -2, 22], [0, 5, 7, -2, -3, 4, 10, 3], [-35, 6, 4, 2, 2, 2, -4, -6], [0, 8, 3, -2, -6, 4, -11, -1], [0, 13, -2, 6, -19, -12, 8, 10], [21, -1, -2, 1, 1, 1, 2, 1], [39, -10, -1, 6, -9, 6, 1, 10], [-3, -4, 5, -20, 15, 10, -2, 1], [0, 4, 0, 8, -12, -16, -4, 16], [9, -12, -6, -9, -6, -9, 6, 12], [23, -19, -11, 6, -8, 6, 11, 19], [12, 0, 15, -6, 18, 3, -27, -12], [14, -24, 6, -26, 19, 13, -20, -17], [3, 1, -12, 0, -12, 0, 9, 13], [0, -10, 2, -7, 17, 14, 8, -12], [-8, -5, -5, -12, 0, -12, 5, 5], [0, 1, -20, 13, -14, -26, 21, 6], [4, 7, 8, 16, -1, 16, -8, -7], [2, -23, -16, -4, -7, -4, 16, 23], [0, -5, 11, -4, 9, 8, 10, 3], [-16, 10, -1, 6, -4, -3, 17, 8], [-8, 11, 6, 16, -2, -8, 2, -3], [-43, 5, 4, -4, 1, -4, -4, -5], [-1, -7, 5, -6, 8, 3, -4, -9], [-3, -11, -6, 1, -5, 1, 6, 11], [0, 8, 1, 3, -11, -6, 8, 7], [19, 1, -18, 8, -22, -4, -1, 15], [22, -4, 0, 4, -4, 4, 0, 4], [0, -13, 8, -10, 23, 20, -2, -12], [-22, -5, -3, 2, -2, 2, 3, 5], [0, 2, 10, -1, -1, 2, -22, 8], [-3, 5, -10, 24, -22, -12, 13, 3], [33, 11, 7, 4, 4, 4, -7, -11], [23, 0, -11, -6, -8, 3, -12, 14], [-3, -7, -6, -11, -1, -11, 6, 7], [0, -3, 2, -1, 4, 2, 12, 0], [13, -13, -9, -14, -2, 7, -4, 3], [0, -16, -9, -2, 18, 4, 24, -13], [0, 14, 0, 6, -20, -12, 3, 12], [11, 12, -4, 16, -12, -8, -7, 8], [0, 10, -8, 7, -17, -14, -22, 6], [0, -6, -3, 1, 5, -2, 13, -1], [14, 9, -21, 12, -27, -6, 7, 24], [-6, -3, -2, -4, -1, -4, 2, 3], [17, -2, 1, -12, -3, -12, -1, 2], [-7, 3, 2, -14, 9, 7, 5, 8], [-20, -13, -3, -22, 8, 11, 23, 1], [-13, -10, 5, -12, 11, 6, 8, -9], [0, 18, 10, -2, -16, 4, -38, 6], [-5, -23, -9, -4, -14, -4, 9, 23], [0, 9, -7, 3, -12, -6, -35, -1], [-39, -6, 9, -4, 11, 2, 30, -13], [-10, -5, -8, -8, 3, -8, 8, 5], [-28, 8, 9, -8, 13, 4, 19, 3], [0, 4, 15, -2, -2, 4, -18, 11], [21, -11, -11, 6, 0, 6, 11, 11], [-19, 6, 4, -7, 2, -7, -4, -6], [-6, -1, -5, 8, -9, -4, 11, 0], [13, -6, -14, 3, 8, 3, 14, 6], [45, 1, 7, 0, 7, 0, -52, -6], [20, -3, 6, 16, -9, 16, -6, 3], [0, 1, 3, 4, -5, -8, -12, 11], [0, 3, 12, -3, 0, 6, 8, 6], [-17, -2, -5, 16, -13, -8, 22, -5], [-43, 0, 14, -10, 19, 5, 29, -9], [-40, 10, 5, -3, 5, -3, -5, -10], [0, 0, 14, -9, 9, 18, -40, -4], [-18, 14, 25, 10, 20, -5, -7, -16], [0, 13, -3, 8, -21, -16, -17, 13], [-4, 3, 10, -6, 13, 3, -6, -4], [15, -7, -2, 10, -5, 10, 2, 7], [-9, 17, 14, 2, 3, 2, -14, -17], [4, -4, -6, 8, 2, 8, 6, 4], [0, -5, -23, 0, 5, 0, 8, -23], [-8, -18, 10, -20, 20, 10, -2, -18], [0, 8, 3, 6, -14, -12, -8, 15], [-3, -17, -2, -4, -15, -4, 2, 17], [0, -11, 8, 2, 9, -4, 13, 12], [4, 22, -4, 20, -14, -10, 0, 16], [15, -9, 5, -16, 13, 8, -20, -6], [0, 13, 14, -3, -10, 6, -51, 8], [-3, 15, 15, 10, 10, -5, -12, -5], [0, -19, -5, -3, 22, 6, 5, -11], [-2, 17, -1, 24, -13, -12, 3, 6], [-3, -1, 2, -1, -3, -1, -2, 1], [0, 3, -7, 3, -6, -6, 24, -1], [0, 21, -9, 1, -22, -2, 0, -7], [0, -16, 20, -16, 32, 32, -10, -12], [0, -2, 10, -13, 15, 26, -21, -16], [36, -23, -20, 4, -3, 4, 20, 23], [0, -6, -6, 2, 4, -4, 4, -2], [19, -20, -20, -14, -13, 7, 1, 7], [6, -1, -2, -10, 3, 5, -4, 6], [16, 14, 14, -5, 0, -5, -14, -14], [-2, 13, 6, 18, -3, -9, -4, -2], [0, -9, -1, 8, -5, -4, 1, -12], [0, -6, 5, 0, 6, 0, -15, 5], [-23, -2, 1, 5, -3, 5, -1, 2], [0, -10, 4, -1, 11, 2, 3, 2], [0, -1, 10, -8, 9, 16, -23, -6], [1, 12, 5, -10, 10, 5, -6, 12], [12, -19, -19, -4, -17, 2, 7, 2], [0, -4, 18, -16, 20, 32, -2, -14], [21, 2, 3, -6, -1, -6, -3, -2], [0, -30, 9, -12, 42, 24, 13, -15], [-9, 11, 15, 0, -4, 0, -15, -11], [-28, 13, -16, 26, -29, -13, 44, 16], [-11, 6, 2, -9, 4, -9, -2, -6], [0, -12, 21, -9, 21, 18, -1, 3], [-11, 24, 10, 1, 14, 1, -10, -24], [0, 7, -21, 10, -17, -20, -24, -1], [13, 12, -22, 18, -31, -9, 9, 25], [23, -2, -6, -5, 4, -5, 6, 2], [0, -26, 21, -16, 42, 32, 2, -11], [0, 11, -18, 2, -13, -4, -9, -14], [-17, 36, 26, 4, 10, 4, -26, -36], [0, 4, -15, 7, -11, -14, 7, -1], [-10, 18, -10, 4, 28, 4, 10, -18], [0, 7, 13, -1, -6, 2, -15, 11], [-3, 4, 6, -14, 13, 7, -3, 5], [-25, -10, 29, -24, 41, 12, -4, -27], [33, -19, -12, -3, -7, -3, 12, 19], [5, -15, -13, 2, -2, 2, 13, 15], [-10, -24, 6, -22, 17, 11, 4, -19], [-9, -11, -15, 1, 4, 1, 15, 11], [0, -4, -17, -13, 13, -13, 17, 4], [-13, -13, 24, -32, 40, 16, -11, -21], [-45, 2, 10, -6, 13, 3, 35, -5], [0, -4, 7, 1, 3, -2, -37, 9], [-29, 14, 20, -8, -6, -8, -20, -14], [0, -4, 0, -4, 8, 8, 12, -8], [2, -12, 10, -8, 14, 4, -12, -18], [13, -25, -23, 12, -2, 12, 23, 25], [38, -11, 1, -12, 7, 6, -39, -6], [0, 6, 3, -7, 1, 14, 3, -11], [0, -7, 1, -2, 9, 4, 2, -3], [0, 11, 18, 3, -14, -6, -7, 24], [11, -29, -27, -12, -2, -12, 27, 29], [-2, 20, -1, 30, -16, -15, 3, 6], [0, 1, 2, 7, -8, -14, 37, 16], [0, 5, 21, -5, 0, 10, -12, 11], [-14, -16, 1, -1, -17, -1, -1, 16], [0, 13, -11, 0, -13, 0, 10, -11], [-19, 30, 11, 16, 3, -8, 8, 11], [44, -14, -16, 6, 2, 6, 16, 14], [27, 1, -36, 10, -41, -5, 9, 32], [0, -10, -6, 1, 9, -2, -12, -4], [0, -12, 23, -19, 31, 38, -3, -15], [-15, 17, 2, 24, -10, -12, 13, 3], [12, 23, 18, 28, 4, -14, -30, -9], [0, 5, -14, 14, -19, -28, 10, 14], [12, -7, 0, 13, -7, 13, 0, 7], [12, -25, -4, -5, -21, -5, 4, 25], [0, -9, 17, -1, 10, 2, 0, 15], [51, -21, -23, 2, -24, -1, -28, 1], [27, 7, 8, -3, -1, -3, -8, -7], [9, -3, -12, 0, -12, 0, 3, 9], [5, -18, -15, -21, -3, -21, 15, 18], [0, 13, 2, 3, -16, -6, -28, 8], [0, 29, -10, 10, -39, -20, 5, 10], [7, 9, -12, 32, -28, -16, 5, 5], [0, 4, -25, 17, -21, -34, -12, 9], [-9, -13, -17, -18, -8, 9, 26, 13], [31, -6, -9, 6, -12, -3, -22, 0], [24, -15, -10, 6, -5, 6, 10, 15], [2, -12, -7, 2, -8, -1, 5, -6], [0, 0, -6, 3, -3, -6, -14, 0], [45, -20, -19, 6, -1, 6, 19, 20], [6, 0, 5, 10, -5, 10, -5, 0]]
