
# q-expansion of newform 3150.2.bp.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
    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 = 3150
weight = 2
poly_data = [1, 0, 0, 0, -1, 0, 0, 0, 1]

# The basis for the coefficient ring is just the power basis
# in the root of the defining polynomial above.
hecke_ring_character_values = [[2801, [-1, 0, 0, 0, 0, 0, 0, 0]], [127, [-1, 0, 0, 0, 0, 0, 0, 0]], [451, [1, 0, 0, 0, -1, 0, 0, 0]]]
aps_data = [[1, 0, 0, 0, -1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, -3, 0, 0, 0, 2], [4, 0, 0, -1, -2, 1, 0, 0], [2, 1, 0, 1, 0, 0, 0, -1], [4, -2, 0, -2, -2, 2, 0, 2], [0, -2, 1, 0, 0, 2, 0, -2], [-2, 0, -1, 0, 2, 0, 2, 0], [0, -2, 0, 2, 0, -2, -4, -4], [0, 2, -2, 0, 0, 0, 2, -2], [0, -1, -6, -1, 0, 0, 0, 0], [4, 2, 0, 2, 0, -3, 0, 1], [0, -2, 0, 2, 0, 0, -2, -2], [1, 4, 2, 0, 1, -4, 0, 4], [0, 2, 2, -6, 1, -6, 2, 2], [0, -3, -2, -2, 6, -2, -2, -3], [0, -2, -2, -6, 0, -4, 0, 4], [8, 6, -6, 6, -4, -6, 6, -6], [0, 4, 0, -4, 0, 2, -4, 6], [0, 4, 0, 0, -6, 0, 0, 4], [6, 2, 4, -6, -6, 4, -8, 4], [0, -6, 0, 6, 0, 8, -2, 2], [4, -4, 0, 7, -4, -3, 0, -3], [-6, 2, -12, 2, 0, -6, 6, 4], [0, -4, -6, 0, -2, 0, -6, -4], [4, 6, 0, -5, -4, -1, 0, -1], [-2, -6, -2, 0, 2, 6, 4, 6], [0, 2, 4, -8, -6, -8, 4, 2], [6, -6, -8, -6, 0, -2, 4, 8], [8, -2, 0, 2, -16, 1, 4, -1], [-8, -5, 2, 1, 8, 4, -4, 4], [0, 4, 0, 2, -4, 2, 0, 4], [6, 0, 0, 0, -12, -8, 4, -8], [6, 6, 8, 0, 6, -6, 0, 6], [0, -10, 2, 4, 0, 4, 2, -10], [0, -7, -6, 3, -8, 3, -6, -7], [-6, 4, -6, -6, -6, -10, 0, 10], [-2, 8, 0, -8, 4, -8, -1, 0], [1, 10, -2, 2, 1, -8, 0, 8], [0, -5, 6, 3, 0, -3, -6, 5], [-4, -4, 0, 4, 8, 6, -14, 2], [2, -8, 8, -2, 2, 6, 0, -6], [-4, 0, -6, -6, 2, 6, 6, 0], [-2, -10, 2, -10, 0, 12, -1, -2], [12, 4, 8, 6, -6, -6, -8, -4], [-5, 8, 8, 8, 0, 2, -4, -10], [4, 11, -8, 11, 0, -1, 4, -10], [-4, 0, 0, 10, 2, -10, 0, 0], [0, -14, 4, -2, 0, 12, 0, -12], [-10, 10, 2, -4, 10, -6, -4, -6], [-6, 4, 0, -4, 12, -12, -8, -8], [0, 4, -3, 12, 0, -12, 3, -4], [2, 9, 8, 9, 0, -8, -4, -1], [0, 10, 6, 4, 0, -6, 0, 6], [0, 0, 6, 4, 4, 4, 6, 0], [0, 2, -10, 6, 0, 6, -10, 2], [2, 0, 14, 0, 2, 0, 0, 0], [4, -7, 6, -8, -2, 8, -6, 7], [4, -2, 0, 2, -8, 7, 4, 5], [0, 0, -6, 10, 2, 10, -6, 0], [2, -2, 0, 2, -4, 4, 13, 2], [2, -6, -8, -6, 0, 8, 4, -2], [0, -4, 4, 6, 10, 6, 4, -4], [-2, 14, 4, 2, 2, -16, -8, -16], [4, -8, 4, 8, -4, 0, -8, 0], [-12, 2, -5, 4, 12, -6, 10, -6], [0, 0, 0, 0, 0, -6, 10, -6], [0, 0, -10, 2, -2, 2, -10, 0], [4, 4, 0, -4, -8, -4, 12, 0], [4, 0, -6, 12, -2, -12, 6, 0], [4, 0, 16, -2, 4, -2, 0, 2], [0, 10, 0, 3, 0, 3, 0, 10], [6, 20, 6, 5, 6, -15, 0, 15], [-9, -4, -8, -4, 0, -6, 4, 10], [-7, 0, -2, -4, -7, -4, 0, 4], [-4, -2, -2, 6, 2, -6, 2, 2], [-6, -8, 10, 7, 6, 1, -20, 1], [-8, 1, 4, -6, -8, -7, 0, 7], [0, 16, 0, 20, 0, -20, 0, -16], [4, 0, 4, 0, 0, 15, -2, -15], [16, -2, 8, -2, 0, -4, -4, 6], [-16, 16, 6, 6, 8, -6, -6, -16], [-2, -2, 12, -2, 0, 2, -6, 0], [4, -16, -4, -4, 4, 12, 0, -12], [-4, -2, -2, -4, 4, 6, 4, 6], [0, 13, 0, -13, 0, -10, 0, 3], [6, -14, 6, -8, 6, 6, 0, -6], [-2, -16, -4, -16, 0, 4, 2, 12], [-4, 11, 0, -11, 8, 6, 4, 17], [0, -2, -6, 2, 0, 4, 0, -4], [0, 4, -6, 8, 4, 8, -6, 4], [-24, 11, 4, 6, 12, -6, -4, -11], [-6, -7, 0, 7, 12, 5, -6, -2], [-12, 8, -14, -12, 12, 4, 28, 4], [2, 12, 0, -12, -4, -20, 0, -8], [16, -10, -8, 0, -16, 10, 16, 10], [0, 9, -8, 5, -4, 5, -8, 9], [-12, 16, 6, -2, 12, -14, -12, -14], [2, 10, 2, -22, -2, 12, -4, 12], [-14, -10, 0, 10, 28, 8, 4, -2], [0, -10, 14, -2, 3, -2, 14, -10], [20, -2, 4, 16, -10, -16, -4, 2], [4, -5, 16, 18, 4, 23, 0, -23], [0, -16, 6, 8, -4, 8, 6, -16], [0, -6, 2, -4, 24, -4, 2, -6], [-12, -20, 0, 20, 24, 4, 22, -16], [-6, -10, -12, 6, -6, 16, 0, -16], [8, 18, -6, 4, -4, -4, 6, -18], [8, -4, 0, 4, -16, 12, 22, 8], [-28, -1, 4, -2, 28, 3, -8, 3], [8, 9, -6, 5, -4, -5, 6, -9], [-4, 6, 28, 6, 0, 0, -14, -6], [-22, 6, -8, 18, 11, -18, 8, -6], [0, 4, -28, 4, 0, 12, 14, -16], [16, -5, -16, -7, -8, 7, 16, 5], [-8, 0, 16, 0, 0, 6, -8, -6], [-6, 20, 14, 16, 3, -16, -14, -20], [-18, -18, 5, 8, 18, 10, -10, 10], [-6, 9, 0, -9, 12, 5, -6, 14], [4, -2, 10, -4, -2, 4, -10, 2], [6, -6, 0, 6, -12, 10, -6, 4], [-2, 14, 15, 16, -2, 2, 0, -2], [0, -24, -2, 0, -6, 0, -2, -24], [-4, -12, -12, 4, -4, 16, 0, -16], [6, 8, 0, -8, -12, -18, -6, -10], [-2, -12, -2, -14, 2, 26, 4, 26], [-6, -2, -10, -10, 6, 12, 20, 12], [0, -11, -8, -11, 0, 22, 4, -11], [12, 21, -2, -13, -12, -8, 4, -8], [0, 8, 11, -6, 12, -6, 11, 8], [-3, 12, 20, 12, 0, -8, -10, -4], [8, 6, 12, -6, -8, 0, -24, 0], [-6, 15, 0, -15, 12, -11, 14, 4], [12, -19, -8, 10, -12, 9, 16, 9], [-8, -4, 0, 4, 16, -4, -27, -8], [20, 24, -9, 6, -10, -6, 9, -24], [0, 16, -4, -14, 8, -14, -4, 16], [16, -16, 0, 16, -32, 8, -16, -8], [-8, -10, -16, -21, 4, 21, 16, 10], [-5, 8, 0, -8, 10, -22, -20, -14], [0, -2, -16, -4, 0, -2, 0, 2], [-16, 11, -8, 6, 8, -6, 8, -11], [6, -14, -16, -14, 0, 10, 8, 4], [-12, -4, -16, 2, 6, -2, 16, 4], [-2, 28, -8, 28, 0, -18, 4, -10], [-4, -12, -4, -12, 0, 15, 2, -3], [32, 12, -12, 2, -16, -2, 12, -12], [-2, -28, 16, -12, -2, 16, 0, -16], [-14, 16, -3, -12, 14, -4, 6, -4], [-18, -1, 8, -12, -18, -11, 0, 11], [16, 5, -32, 5, 0, 2, 16, -7], [8, -16, 0, 16, -16, 12, 10, -4], [12, 0, -8, 8, 12, 8, 0, -8], [-20, 8, 16, 12, 10, -12, -16, -8], [0, -26, 0, 26, 0, 0, -8, -26], [-18, -4, 2, -26, 18, 30, -4, 30], [-8, 5, -16, 1, 8, -6, 32, -6], [22, 14, 16, 14, 0, -20, -8, 6], [0, -10, 0, 20, -26, 20, 0, -10], [-4, -2, 16, -6, 4, 8, -32, 8], [-12, -6, -16, -6, 0, 30, 8, -24], [-4, 9, 0, -9, 8, -11, -12, -2], [-4, 19, -10, -11, 4, -8, 20, -8], [0, 6, 2, -12, 0, -12, 2, 6], [6, 8, 2, 16, -3, -16, -2, -8], [0, 0, -8, 2, -4, 2, -8, 0], [0, -29, 2, 0, -2, 0, 2, -29], [-4, 20, 14, 20, 0, -4, -7, -16], [-9, 18, 2, 26, -9, 8, 0, -8], [-20, -21, 2, -22, 10, 22, -2, 21], [-6, 6, 0, -6, 12, -10, 28, -4], [4, 2, 28, -10, 4, -12, 0, 12], [0, -8, 4, -4, 0, 4, -4, 8], [20, 10, -20, 10, -10, -10, 20, -10], [-32, 13, -16, 13, 0, -13, 8, 0], [7, 16, 8, 16, 0, -6, -4, -10], [8, 28, -2, 4, -4, -4, 2, -28], [12, 3, 16, 3, 0, 2, -8, -5], [-2, -10, -30, -12, -2, -2, 0, 2], [-4, 9, 8, 23, -4, 14, 0, -14], [-24, -16, 20, -16, 0, 13, -10, 3], [0, -12, 0, 12, 0, -9, -6, -21], [-8, 6, 8, 0, -8, -6, 0, 6], [0, -4, -2, 0, -19, 0, -2, -4], [0, -4, -20, -6, -6, -6, -20, -4], [-4, -20, 0, -3, 2, 3, 0, 20], [0, 8, -10, 4, -6, 4, -10, 8], [16, -8, -1, -12, -16, 20, 2, 20], [0, 18, 10, -14, 22, -14, 10, 18], [-16, 12, 22, 2, 16, -14, -44, -14], [10, 8, 12, 8, 0, -6, -6, -2], [23, -26, -12, 6, -23, 20, 24, 20], [16, -16, -2, 16, -16, 0, 4, 0], [0, -6, -8, 2, 18, 2, -8, -6], [-8, -6, 26, 2, 4, -2, -26, 6], [0, 12, 20, -4, -5, -4, 20, 12], [-2, 8, 2, -25, -2, -33, 0, 33], [-4, 14, 0, -14, 8, 18, 6, 32], [2, -24, 4, -16, 2, 8, 0, -8], [20, -24, -2, -12, -10, 12, 2, 24], [-12, -18, 0, 18, 24, -2, 10, -20], [6, 8, 2, 3, -6, -11, -4, -11], [24, 4, 5, 28, -12, -28, -5, -4], [2, -1, -20, -1, 0, -9, 10, 10], [-36, -12, 19, -6, 18, 6, -19, 12], [-26, 6, -4, -8, -26, -14, 0, 14], [-2, -6, 4, 0, 2, 6, -8, 6], [12, 10, 0, -10, -24, -17, 24, -7], [8, 16, 1, -2, -4, 2, -1, -16], [10, -14, -24, -8, 10, 6, 0, -6], [-2, 6, -44, 6, 0, -8, 22, 2], [12, 3, 0, -3, -24, 11, -12, 14], [6, -6, -6, -32, 6, -26, 0, 26], [0, -22, 6, 20, 2, 20, 6, -22], [-3, 16, 12, 36, -3, 20, 0, -20], [24, -9, -20, -3, -12, 3, 20, 9], [0, -26, -8, 29, -20, 29, -8, -26], [-15, 0, -2, -24, 15, 24, 4, 24], [23, 4, -28, 4, 0, -6, 14, 2], [-20, -12, 20, 4, 20, 8, -40, 8], [-2, -22, 0, 22, 4, 12, 30, -10], [-12, -7, 32, -13, -12, -6, 0, 6], [-4, -19, -4, -22, -4, -3, 0, 3], [-4, -10, 0, 10, 8, 26, -16, 16], [-10, 8, 4, 8, 0, -14, -2, 6], [-18, 20, -12, -4, -18, -24, 0, 24], [12, 4, 0, 18, -6, -18, 0, -4], [20, -15, -16, 5, -20, 10, 32, 10], [18, -10, 26, -5, 18, 5, 0, -5], [-20, 0, -32, 9, 10, -9, 32, 0], [14, -14, 32, 18, -7, -18, -32, 14], [30, 10, 20, 10, 0, 4, -10, -14], [-40, 14, -4, 7, 20, -7, 4, -14], [-8, 2, -8, 2, 0, -20, 4, 18], [0, -20, -12, -4, 0, 4, 12, 20], [4, 4, 44, 12, 4, 8, 0, -8], [10, 22, 17, -8, -10, -14, -34, -14], [-4, -12, 0, 12, 8, 1, -2, -11], [-38, -10, -4, -10, 0, -8, 2, 18], [0, -2, 8, 6, 14, 6, 8, -2], [20, -14, 21, 4, 20, 18, 0, -18], [0, -27, -4, 10, 0, 10, -4, -27], [34, 10, 2, -26, -34, 16, -4, 16], [-6, 6, 0, -6, 12, 18, -16, 24], [-30, 2, -2, 6, 30, -8, 4, -8], [0, -14, -8, -14, 0, 21, 4, -7], [0, -8, 16, 3, -6, 3, 16, -8], [0, 4, -22, 0, -24, 0, -22, 4], [-10, 0, 42, 0, 0, -4, -21, 4], [22, 3, 0, -3, -44, 1, -30, 4], [4, 11, -8, 6, -4, -17, 16, -17], [0, -8, 1, 16, 46, 16, 1, -8], [3, -16, 0, 16, -6, 12, 16, -4], [32, -28, 8, 4, -16, -4, -8, 28], [-14, -11, 0, 4, -14, 15, 0, -15], [0, 20, 2, -30, 2, -30, 2, 20], [0, -4, -16, 12, -26, 12, -16, -4], [1, 24, 0, -24, -2, 6, -10, 30], [18, -10, 0, 24, -18, -14, 0, -14], [16, 17, -36, 15, -8, -15, 36, -17], [-8, 22, -32, 22, 0, -28, 16, 6], [-36, -6, 24, -8, 18, 8, -24, 6], [18, 15, 12, 15, 0, 1, -6, -16], [4, -12, 30, -8, -2, 8, -30, 12], [8, -22, 33, -12, 8, 10, 0, -10], [8, -22, 0, 22, -16, 4, -6, -18], [8, -18, 24, -18, 0, -19, -12, 37], [-6, 0, 0, 0, 12, 10, -14, 10], [0, -8, 9, 2, -10, 2, 9, -8], [-2, 4, -34, -14, -2, -18, 0, 18], [8, -2, -38, 0, -4, 0, 38, 2], [0, 6, -2, 16, -28, 16, -2, 6], [0, 16, -4, -26, 0, 10, 8, 10], [0, 2, 16, 2, 0, -8, -8, 6], [-8, -15, 12, -2, 8, 17, -24, 17], [4, 6, -6, -30, -4, 24, 12, 24], [0, -12, 8, 20, 0, 20, 8, -12], [31, 16, -24, 0, -31, -16, 48, -16], [-2, -31, 0, 4, 2, 27, 0, 27], [-12, 0, -21, 24, 6, -24, 21, 0], [0, 12, 2, -40, -22, -40, 2, 12], [-1, 32, 0, -32, 2, -12, 6, 20], [-4, -2, 0, 2, 8, 6, -36, 4], [-18, 4, -24, 2, 18, -6, 48, -6], [6, 24, 2, 18, 6, -6, 0, 6], [12, 18, -10, 0, -6, 0, 10, -18], [-2, 14, 6, 14, 0, -12, -3, -2], [-20, 28, 34, 8, 10, -8, -34, -28], [-24, -30, -8, -30, 0, 15, 4, 15], [12, -2, -36, 10, -6, -10, 36, 2], [32, 16, 14, -12, -16, 12, -14, -16], [-18, 28, -14, -20, 18, -8, 28, -8], [30, 7, 16, 7, 0, -4, -8, -3], [-8, -16, 0, 16, 16, -23, 10, -39], [0, 36, -2, -28, 18, -28, -2, 36], [0, 10, 36, 24, 0, 14, 0, -14], [-4, 8, 0, -8, 8, 4, 32, 12], [-16, 41, -2, -17, 16, -24, 4, -24], [-22, -10, -4, -10, 0, 8, 2, 2], [30, -32, -2, 10, -30, 22, 4, 22], [34, -14, 1, 16, -34, -2, -2, -2], [0, -18, 10, 38, -14, 38, 10, -18]]
