
# q-expansion of newform 8040.2.a.m, 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
    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 = 8040
weight = 2
poly_data = [-4, -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], [1, 0], [1, 0], [0, 1], [4, -1], [0, 2], [-4, 2], [4, -2], [-4, 0], [2, 2], [2, 2], [2, -3], [6, 0], [8, -2], [0, -2], [-2, 2], [-2, -4], [-2, 3], [1, 0], [10, -1], [-6, -2], [-2, 0], [-12, 1], [10, -5], [12, 1], [6, -5], [8, -2], [8, -4], [10, 1], [2, -1], [0, 2], [10, -2], [-2, -1], [-6, 6], [-10, 2], [-8, -1], [-6, 8], [-16, 1], [0, 0], [-16, 3], [8, -4], [2, -10], [0, -2], [22, -2], [-6, -4], [4, -7], [-8, 4], [8, 2], [-4, -4], [-2, -9], [-2, -1], [-20, 6], [10, -5], [0, 5], [16, -6], [-8, 8], [-2, 6], [14, 0], [18, -5], [2, 0], [0, 3], [24, -3], [8, 5], [12, -8], [0, 5], [-20, 2], [-6, -1], [-4, 6], [4, -12], [2, 8], [6, -4], [-2, 9], [-16, 8], [20, 2], [-2, -10], [28, -1], [-10, 6], [22, -5], [-10, 14], [10, 8], [-6, -2], [18, 6], [-14, 1], [0, -2], [-20, -1], [-20, -4], [-18, 11], [-14, 2], [6, 10], [0, -12], [0, -9], [-6, 5], [8, -17], [-2, 6], [6, -3], [-4, -7], [-14, 0], [-14, 2], [0, 3], [22, 4], [28, 0], [12, -6], [-28, 2], [-26, -3], [8, 8], [0, 2], [-20, -2], [-30, 7], [36, -2], [34, -9], [0, 6], [14, -20], [28, -4], [16, -6], [2, 14], [14, -4], [-12, -4], [-12, -5], [-14, 10], [18, 6], [2, 4], [20, 6], [-30, 4], [4, 10], [24, -2], [10, 1], [2, 2], [-30, -6], [-40, 0], [-16, 10], [-14, 6], [0, 2], [16, -16], [16, 6], [6, -9], [14, 10], [16, -19], [20, 6], [-24, 15], [-14, 0], [-14, 19], [-6, 22], [-40, 6], [-24, -9], [-14, -14], [-6, 6], [34, 4], [26, -1], [28, -4], [4, 2], [2, -16], [42, -5], [-12, -4], [16, 0], [-32, 11], [22, -5], [10, -16], [10, -14], [16, 3], [18, -24], [-28, 13], [-20, 22], [0, -14], [14, -14], [4, 10], [-24, 0], [-10, 8], [38, -11], [-2, 1], [-6, -12], [14, -8], [6, 14], [-30, -6], [-16, 9], [-14, -6], [18, -18], [-42, 5], [-34, 12], [4, -1], [-58, -2], [-40, 10], [-14, 4], [18, 0], [12, 14], [-20, -15], [-38, -2], [12, 4], [-44, 6], [-38, 18], [-20, -10], [6, 4], [12, 1], [6, 11], [2, -11], [-4, 6], [-8, -14], [-18, 1], [-24, 2], [-26, -8], [-8, -16], [-22, -10], [16, 11], [8, -4], [30, -4], [-36, 0], [16, -14], [-20, 9], [52, -9], [-6, 5], [42, -9], [22, 12], [-42, 7], [-16, 8], [-4, -4], [-48, 12], [30, -16], [-32, -10], [22, -13], [36, -11], [-8, 23], [2, 20], [-32, -8], [-38, 0], [0, -20], [-20, 12], [-38, -6], [12, -10], [-16, 22], [40, -22], [0, 24], [-12, 22], [-6, -11], [-40, 15], [34, 4], [-48, -1], [-24, 12], [-10, 9], [40, -9], [-34, 26], [6, -22], [-8, 7], [42, -1], [20, -13], [22, -17], [2, -27], [24, 4], [16, 0], [28, -3], [-18, 14], [-12, -17], [14, -11], [-10, 27], [-52, -5], [-22, 31], [-6, -6], [-48, 15], [26, -1], [-24, 11], [-48, 1], [-14, -6], [16, 4], [-12, 11], [-18, 9], [48, -14], [-48, 0], [16, -24], [-42, 13], [-2, -8], [8, 4], [-46, 18], [-6, 23], [-56, -6], [-4, -9], [28, 12], [42, -10], [-16, -23], [-60, 12], [6, -6], [2, 3], [-40, -4], [44, -20], [4, 17], [-36, -9], [-6, 1], [32, -12], [10, -13], [34, 16], [-4, -11], [-58, 12], [-54, 14], [-22, 18], [-44, 20], [12, -8], [-26, 24], [40, -14], [-42, 4], [18, 18], [38, 8], [46, -10], [-24, -12], [20, -21], [-12, 21], [4, -1], [-4, 11], [4, 4], [48, 10], [12, -36], [-10, -28], [26, -18], [20, -6], [52, -13], [-38, -2], [-10, 9], [24, -29], [-40, 0], [-42, 16], [-2, 8], [-36, 12], [18, -24], [-38, 18], [-16, 26], [18, -14], [-22, 2], [-16, -25], [-12, 20], [62, -11], [44, 6], [-8, 25], [4, 15], [-58, 22], [-14, -16], [12, -11], [-6, -20], [20, 14], [48, 0], [-52, 15], [-66, 4], [-44, 16], [38, -6], [-8, 18], [-10, -24], [-8, -16], [-78, 7], [-12, -19], [-40, -3], [52, 16], [66, 0], [-36, -10], [-58, -14], [-42, -14], [16, -28], [-52, -15], [58, -4], [-52, 20], [18, 24], [-14, -3], [-2, 5], [64, -11], [10, -39], [68, -9], [26, -25], [-2, -3], [4, 8], [18, 14], [-24, -9], [-56, 7], [20, -5], [-8, 26], [22, -16], [44, -19], [48, -6], [28, 16], [-6, -20], [-34, 8], [-44, 16], [26, 14], [-24, -18], [6, -14], [2, 32], [-6, 24], [-22, 31], [-30, -15], [-68, 12], [14, -21], [70, -7], [-12, 3], [46, -24], [-10, -3], [-32, 28], [-36, -13], [-66, 4], [-30, 20], [-46, 10], [-12, 22], [-4, -2], [-10, -28], [-8, 1], [6, 12], [22, -7], [-38, -4], [14, 4], [-44, -2], [-4, 11], [-34, 43], [58, 17], [-30, 16], [60, -10], [-6, 36], [-16, 9], [20, 3], [50, -30], [12, 9], [32, -15], [-8, 20], [-36, -5], [-2, -18], [10, -34], [24, -12], [36, 6], [12, 36], [-10, -17], [10, 7], [-48, 0], [-20, 9], [0, 25], [0, -10], [-16, 7], [-14, 0], [16, 4], [8, -30], [-14, -28], [64, -20], [56, 14], [40, -8], [-2, -17], [14, 4], [22, -26], [30, 3], [16, -32], [12, 5], [20, 1], [-14, 8], [18, 19], [-6, 21], [2, -24], [8, -10], [-4, -32], [4, 33], [62, -24], [-54, 24], [24, 2], [-8, 36], [-40, 43], [-6, -4], [82, -2], [42, -27], [90, 7], [14, 26], [-22, 5], [18, -20], [50, -10]]
