
# q-expansion of newform 3240.2.a.m, downloaded from the LMFDB on 19 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 = 3240
weight = 2
poly_data = [-8, -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 = [[0, 0], [0, 0], [1, 0], [0, 1], [-1, 1], [0, -1], [0, -2], [1, 0], [2, 1], [-1, 1], [1, 3], [6, 0], [7, -2], [2, -2], [-6, -1], [0, 3], [5, 0], [6, 2], [6, -2], [-1, -1], [8, 2], [4, -2], [-10, 0], [-1, -1], [2, -2], [1, -5], [10, -3], [-6, 0], [11, -3], [8, 2], [4, -5], [13, -2], [-12, 2], [15, 0], [6, 4], [21, 1], [6, 5], [-4, 4], [-12, 0], [-2, 5], [-11, 2], [3, -5], [-9, 1], [-6, 2], [-4, 1], [0, 4], [17, 0], [12, 4], [-4, -4], [-10, -2], [6, -6], [0, -6], [13, -7], [4, -5], [14, -4], [-6, 3], [5, -3], [-16, 2], [-10, 3], [14, 1], [10, 2], [2, -5], [-6, 2], [1, 5], [-4, 0], [-14, 1], [17, -1], [-4, -2], [-16, 6], [-23, 1], [6, -8], [-13, -1], [-10, -6], [-4, -2], [4, -9], [-16, -1], [14, 2], [34, 0], [6, 9], [-18, -1], [8, 8], [25, 1], [13, -1], [6, -14], [5, -11], [-2, -8], [1, 10], [-26, 6], [21, 3], [-10, 5], [-4, 6], [-17, 3], [-4, 7], [1, -8], [13, 2], [-16, 8], [-38, 0], [10, -3], [-20, -6], [-17, 9], [-40, 0], [-8, -7], [10, -6], [29, -6], [7, -3], [4, -4], [30, 0], [-2, -8], [-15, 9], [13, 0], [-38, -2], [-12, 9], [-20, 10], [-36, 1], [-39, -1], [19, 7], [26, 2], [2, -10], [-20, 2], [-12, 15], [-19, 11], [-10, -4], [-14, 3], [24, -6], [20, -9], [-1, 3], [-10, -12], [-27, -7], [-40, 3], [-10, 8], [-1, 5], [-20, 4], [-24, 6], [20, -3], [-3, 6], [-11, 9], [18, 0], [-8, -10], [0, -6], [-1, 14], [-7, -9], [39, -1], [-30, 2], [8, -16], [7, -15], [-5, -7], [4, 2], [-40, 2], [29, -9], [-28, -7], [16, 3], [23, -1], [20, 6], [-30, 5], [-26, 4], [9, -19], [35, -3], [9, 5], [38, -2], [-2, -12], [42, 2], [-12, 0], [-28, -4], [15, 10], [32, 6], [4, 4], [1, -1], [-12, -9], [-39, -2], [-24, 7], [3, -14], [27, -7], [7, -13], [-22, -6], [-32, 2], [-53, 4], [4, -3], [13, -7], [20, 4], [-9, -13], [-6, -2], [32, -7], [-4, -3], [2, 10], [38, -3], [27, 7], [-2, -7], [0, -2], [19, 2], [12, -10], [-18, 4], [-26, 4], [12, -8], [-33, 7], [2, -2], [-4, 0], [9, 0], [-10, 5], [-24, -2], [-20, -7], [-13, 11], [31, -15], [32, 3], [1, 16], [-20, -8], [-24, 1], [5, -11], [20, 10], [-34, -4], [44, 0], [-6, -4], [15, 1], [44, -9], [8, 8], [31, -3], [-23, 10], [-34, 10], [-11, 5], [-30, 3], [-10, -8], [9, 13], [11, 7], [15, -10], [64, 1], [24, -12], [-5, 21], [-46, 0], [0, -2], [2, 21], [52, 5], [48, -1], [31, 4], [-40, 0], [-10, -11], [-32, 4], [-30, 15], [7, -2], [-28, 14], [60, -1], [13, -5], [-56, 0], [24, -7], [-2, -9], [6, -4], [0, 10], [-47, 5], [18, -7], [12, 19], [21, 8], [-42, -2], [18, -12], [5, 4], [-14, -2], [-5, -16], [-34, -3], [16, -5], [-25, -9], [-22, 2], [16, -5], [0, 12], [30, -19], [54, -8], [1, 19], [28, -19], [50, -6], [7, -18], [-14, 12], [-23, 4], [-4, 20], [30, -13], [15, -5], [4, -12], [-32, -2], [-9, -11], [50, -12], [22, 14], [-26, 6], [-11, 5], [50, -9], [-12, -15], [-18, -15], [-24, -12], [14, -27], [-10, -2], [-20, 0], [-1, 13], [-22, 12], [38, 11], [21, 3], [30, -12], [3, -1], [20, -4], [-4, 14], [19, -23], [16, 9], [9, 9], [-27, 13], [-4, 26], [13, 0], [18, 0], [10, 10], [-44, 1], [11, -3], [6, -8], [25, -14], [20, -2], [20, 2], [17, 1], [25, 13], [8, -18], [22, 6], [-5, -5], [13, -14], [-58, 10], [20, -12], [1, 0], [27, 8], [-17, 1], [26, -2], [-63, -7], [-28, 9], [-4, 12], [-41, 13], [4, 12], [12, -10], [-7, -10], [21, -25], [-30, 10], [16, 11], [2, -7], [-27, 13], [2, 7], [7, -9], [-72, 2], [11, 10], [-26, 10], [-9, 19], [-2, -2], [-3, 8], [-40, 5], [-2, -19], [10, 10], [25, 3], [-52, 6], [44, 7], [-60, 8], [9, 17], [38, -8], [-39, 9], [60, -3], [-5, 24], [8, 2], [-38, 6], [46, 11], [-15, -5], [18, -4], [-19, 11], [-31, 10], [22, -12], [48, -11], [84, -2], [5, -8], [12, -5], [53, 2], [-58, -4], [-12, 8], [8, 23], [38, -18], [41, -6], [55, 4], [-20, 5], [-50, 11], [29, -1], [5, 17], [12, 1], [43, 4], [35, -9], [-30, -2], [49, -11], [12, 4], [-58, 0], [-50, -6], [-54, -3], [50, 8], [23, -7], [-32, 3], [-16, 4], [-2, -5], [-32, 22], [-38, -15], [54, -16], [36, -27], [28, -8], [14, -8], [1, 29], [-14, -4], [-35, 17], [78, -9], [20, 9], [11, -7], [-17, 1], [0, 18], [-22, 7], [-20, -8], [33, 21], [-24, -6], [-68, -3], [10, 1], [22, 0], [-55, -13], [48, -10], [58, -8], [20, 24], [7, 0], [-36, 8], [-10, -10], [-77, 9], [18, 14], [-4, 14], [-54, 6], [-18, -6], [-58, -11], [48, 17], [-57, 20], [34, 10], [2, 23], [42, -18], [-2, 7], [47, -3], [40, 8]]
