
# q-expansion of newform 216.3.h.f, downloaded from the LMFDB on 25 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 = 216
weight = 3
poly_data = [256, 0, -32, 0, 2, 0, -2, 0, 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], [[0, 0, 1, 0, 0, 0, 0, 0], 1], [[0, -96, 0, 66, 0, 14, 0, 1], 160], [[-16, 0, -14, 0, 14, 0, 1, 0], 80], [[0, -56, 0, 26, 0, -6, 0, 1], 80], [[0, 48, 0, 42, 0, -2, 0, -3], 160], [[16, 0, -2, 0, 2, 0, -1, 0], 16]]

hecke_ring_character_values = [[55, [1, 0, 0, 0, 0, 0, 0, 0]], [109, [-1, 0, 0, 0, 0, 0, 0, 0]], [137, [-1, 0, 0, 0, 0, 0, 0, 0]]]
aps_data = [[0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, -1, 0, 0], [6, 0, -1, 0, 0, 0, 0, -1], [0, 1, 0, 0, 0, 0, 1, 0], [1, 0, -1, 0, 1, 0, 0, 1], [0, 7, 0, 2, 0, 3, -4, 0], [2, 0, -2, 0, -5, 0, 0, 2], [0, 7, 0, -2, 0, 4, -3, 0], [0, 4, 0, 0, 0, 6, 10, 0], [-10, 0, -6, 0, 0, 0, 0, -6], [7, 0, -7, 0, -7, 0, 0, 7], [0, -10, 0, 12, 0, -8, 2, 0], [10, 0, -10, 0, 6, 0, 0, 10], [0, -3, 0, -14, 0, 2, 5, 0], [0, -14, 0, 0, 0, 12, -2, 0], [0, -11, 0, 0, 0, -8, -19, 0], [3, 0, -3, 0, -5, 0, 0, 3], [-12, 0, 12, 0, -7, 0, 0, -12], [0, -30, 0, -12, 0, -12, 18, 0], [31, 0, 4, 0, 0, 0, 0, 4], [24, 0, 5, 0, 0, 0, 0, 5], [0, -20, 0, 0, 0, 10, -10, 0], [0, 5, 0, 22, 0, -3, -8, 0], [-9, 0, 14, 0, 0, 0, 0, 14], [0, 22, 0, 0, 0, 2, 24, 0], [-14, 0, -11, 0, 0, 0, 0, -11], [0, 31, 0, 0, 0, -18, 13, 0], [2, 0, -2, 0, 40, 0, 0, 2], [0, 27, 0, 2, 0, 13, -14, 0], [0, 0, 20, 0, 0, 0, 0, 20], [0, 4, 0, 0, 0, -14, -10, 0], [0, -39, 0, 22, 0, -25, 14, 0], [-22, 0, 22, 0, 15, 0, 0, -22], [0, 34, 0, 0, 0, 6, 40, 0], [-80, 0, 19, 0, 0, 0, 0, 19], [-38, 0, 38, 0, 16, 0, 0, -38], [-2, 0, 2, 0, 11, 0, 0, -2], [0, 11, 0, 6, 0, 4, -7, 0], [0, 46, 0, 0, 0, -48, -2, 0], [0, 82, 0, 0, 0, -32, 50, 0], [-1, 0, 1, 0, -65, 0, 0, -1], [0, 25, 0, 42, 0, 2, -23, 0], [121, 0, -26, 0, 0, 0, 0, -26], [0, -71, 0, 0, 0, 13, -58, 0], [102, 0, 17, 0, 0, 0, 0, 17], [10, 0, -10, 0, 25, 0, 0, 10], [-34, 0, -6, 0, 0, 0, 0, -6], [0, -110, 0, 0, 0, 80, -30, 0], [8, 0, -8, 0, -60, 0, 0, 8], [0, 86, 0, -44, 0, 54, -32, 0], [0, 60, 0, 8, 0, 28, -32, 0], [-103, 0, -18, 0, 0, 0, 0, -18], [0, 34, 0, 0, 0, 6, 40, 0], [0, -138, 0, -52, 0, -56, 82, 0], [0, -4, 0, 56, 0, -16, -12, 0], [0, -83, 0, 0, 0, 57, -26, 0], [-206, 0, -47, 0, 0, 0, 0, -47], [14, 0, -14, 0, -112, 0, 0, 14], [0, -60, 0, -32, 0, -22, 38, 0], [22, 0, -22, 0, -62, 0, 0, 22], [0, 19, 0, 0, 0, -57, -38, 0], [30, 0, -30, 0, 6, 0, 0, 30], [0, 55, 0, -2, 0, 28, -27, 0], [-25, 0, -30, 0, 0, 0, 0, -30], [0, 40, 0, 0, 0, -10, 30, 0], [-2, 0, 2, 0, -105, 0, 0, -2], [375, 0, -10, 0, 0, 0, 0, -10], [0, -44, 0, 0, 0, 32, -12, 0], [-77, 0, 77, 0, 45, 0, 0, -77], [0, 12, 0, -8, 0, 8, -4, 0], [0, 145, 0, 50, 0, 60, -85, 0], [340, 0, -5, 0, 0, 0, 0, -5], [35, 0, -35, 0, -159, 0, 0, 35], [-100, 0, 100, 0, 85, 0, 0, -100], [0, -18, 0, 92, 0, -32, -14, 0], [0, 97, 0, 0, 0, 7, 104, 0], [2, 0, -2, 0, 136, 0, 0, 2], [0, 120, 0, 80, 0, 40, -80, 0], [57, 0, 122, 0, 0, 0, 0, 122], [0, 91, 0, 0, 0, -60, 31, 0], [-13, 0, 13, 0, -175, 0, 0, -13], [0, 15, 0, -90, 0, 30, 15, 0], [-76, 0, -54, 0, 0, 0, 0, -54], [-506, 0, 58, 0, 0, 0, 0, 58], [0, 94, 0, 0, 0, 18, 112, 0], [0, 15, 0, 90, 0, -15, -30, 0], [-160, 0, -30, 0, 0, 0, 0, -30], [0, -35, 0, 0, 0, 39, 4, 0], [24, 0, 101, 0, 0, 0, 0, 101], [0, -119, 0, 0, 0, -58, -177, 0], [0, -70, 0, -52, 0, -22, 48, 0], [80, 0, -15, 0, 0, 0, 0, -15], [0, -95, 0, 0, 0, -86, -181, 0], [-48, 0, 48, 0, -10, 0, 0, -48], [0, 87, 0, -18, 0, 48, -39, 0], [0, -101, 0, 0, 0, 81, -20, 0], [0, -165, 0, 90, 0, -105, 60, 0], [42, 0, -42, 0, -99, 0, 0, 42], [-77, 0, 77, 0, 125, 0, 0, -77], [-88, 0, 88, 0, 11, 0, 0, -88], [0, -95, 0, 0, 0, 135, 40, 0], [0, 70, 0, 0, 0, -90, -20, 0], [0, 255, 0, 82, 0, 107, -148, 0], [98, 0, -98, 0, 135, 0, 0, 98], [-71, 0, 76, 0, 0, 0, 0, 76], [0, 25, 0, 0, 0, -110, -85, 0], [0, -168, 0, -24, 0, -78, 90, 0], [0, 100, 0, -80, 0, 70, -30, 0], [320, 0, -6, 0, 0, 0, 0, -6], [246, 0, -61, 0, 0, 0, 0, -61], [77, 0, -77, 0, -269, 0, 0, 77], [0, 7, 0, 82, 0, -17, -24, 0], [-72, 0, 72, 0, -65, 0, 0, -72], [936, 0, 11, 0, 0, 0, 0, 11], [0, 130, 0, 108, 0, 38, -92, 0], [-14, 0, 14, 0, -14, 0, 0, -14], [0, -174, 0, -84, 0, -66, 108, 0], [0, 160, 0, 0, 0, -90, 70, 0], [0, 82, 0, 0, 0, -102, -20, 0], [-23, 0, 23, 0, -125, 0, 0, -23], [251, 0, -126, 0, 0, 0, 0, -126], [0, -239, 0, 0, 0, -3, -242, 0], [0, -230, 0, 0, 0, 100, -130, 0], [110, 0, -110, 0, -190, 0, 0, 110], [0, 277, 0, 0, 0, -13, 264, 0], [53, 0, -53, 0, -115, 0, 0, 53], [0, 280, 0, -40, 0, 150, -130, 0], [-866, 0, -14, 0, 0, 0, 0, -14], [118, 0, -118, 0, -32, 0, 0, 118], [70, 0, -70, 0, 110, 0, 0, 70], [0, 47, 0, -18, 0, 28, -19, 0], [14, 0, -165, 0, 0, 0, 0, -165], [45, 0, -45, 0, -219, 0, 0, 45], [0, -185, 0, 82, 0, -113, 72, 0], [-333, 0, -28, 0, 0, 0, 0, -28], [0, 100, 0, 0, 0, -70, 30, 0], [-30, 0, 30, 0, -229, 0, 0, -30], [0, -50, 0, 0, 0, 190, 140, 0], [0, -330, 0, -12, 0, -162, 168, 0], [22, 0, -22, 0, -130, 0, 0, 22], [0, -65, 0, 0, 0, 119, 54, 0], [-130, 0, -255, 0, 0, 0, 0, -255], [0, -101, 0, 0, 0, -42, -143, 0], [17, 0, -17, 0, 415, 0, 0, 17], [0, -190, 0, 188, 0, -142, 48, 0], [129, 0, -129, 0, -179, 0, 0, 129], [0, -294, 0, 76, 0, -166, 128, 0], [-188, 0, 188, 0, 85, 0, 0, -188], [0, 477, 0, 162, 0, 198, -279, 0], [-43, 0, 43, 0, 201, 0, 0, -43], [0, -145, 0, -110, 0, -45, 100, 0], [112, 0, -112, 0, -37, 0, 0, 112], [0, -408, 0, 8, 0, -206, 202, 0], [182, 0, -182, 0, -259, 0, 0, 182], [0, -90, 0, -140, 0, -10, 80, 0], [994, 0, -50, 0, 0, 0, 0, -50], [0, 40, 0, -192, 0, 68, 28, 0], [-421, 0, 246, 0, 0, 0, 0, 246], [0, -299, 0, 0, 0, 15, -284, 0], [0, 325, 0, 0, 0, -90, 235, 0], [0, -453, 0, -54, 0, -213, 240, 0], [-1336, 0, -39, 0, 0, 0, 0, -39], [0, -131, 0, 0, 0, 186, 55, 0], [0, -248, 0, -104, 0, -98, 150, 0], [0, -283, 0, 146, 0, -178, 105, 0], [-856, 0, 15, 0, 0, 0, 0, 15], [-246, 0, 246, 0, -104, 0, 0, -246]]
