
# q-expansion of newform 8470.2.a.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 = 8470
weight = 2
poly_data = [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 = None
aps_data = [[-1], [-2], [1], [1], [0], [2], [3], [-1], [-6], [6], [-4], [2], [0], [-7], [0], [9], [3], [-7], [11], [-3], [11], [11], [-12], [0], [-1], [6], [-1], [-9], [-16], [12], [2], [-12], [12], [5], [0], [8], [8], [5], [9], [12], [24], [-7], [0], [-4], [-9], [2], [-4], [11], [0], [-25], [24], [-24], [8], [-15], [21], [-18], [-15], [2], [-22], [-21], [-16], [12], [-34], [0], [2], [33], [26], [-22], [3], [14], [21], [-3], [29], [23], [8], [21], [12], [-16], [-18], [-4], [9], [8], [3], [2], [-10], [-12], [21], [8], [9], [-22], [12], [36], [-4], [-12], [32], [21], [-21], [30], [-16], [26], [35], [-18], [30], [-9], [-22], [11], [30], [39], [27], [-40], [5], [-1], [-18], [20], [29], [21], [32], [45], [21], [-36], [14], [8], [48], [15], [-43], [48], [26], [18], [-4], [32], [-4], [-6], [-40], [47], [36], [-22], [-12], [50], [-42], [3], [20], [-24], [-22], [-51], [50], [6], [26], [18], [47], [30], [17], [-12], [29], [24], [-1], [-21], [20], [12], [2], [39], [-36], [6], [-22], [21], [42], [-36], [5], [20], [-49], [42], [12], [17], [-48], [-4], [-16], [-36], [62], [-12], [-61], [-1], [-10], [15], [-46], [-54], [-12], [-6], [2], [44], [-10], [12], [29], [-21], [-40], [-45], [21], [39], [59], [-67], [-6], [3], [12], [8], [-16], [50], [51], [6], [-4], [36], [-3], [-28], [-16], [45], [62], [-54], [-24], [-46], [-28], [30], [-60], [69], [-22], [20], [-33], [-46], [-42], [8], [-27], [-9], [-43], [-36], [38], [53], [5], [42], [-34], [72], [-64], [21], [60], [36], [75], [-31], [-43], [20], [18], [6], [-31], [45], [-22], [-12], [53], [6], [-12], [-22], [78], [-6], [-40], [-64], [42], [-46], [-58], [69], [-10], [20], [-18], [20], [36], [36], [47], [9], [-7], [-64], [29], [65], [-22], [47], [-45], [-16], [29], [33], [-27], [-37], [-72], [50], [-82], [-60], [-70], [-69], [-52], [84], [36], [-42], [-30], [81], [-67], [-39], [-82], [12], [-15], [-16], [83], [-3], [5], [-39], [50], [-88], [9], [29], [51], [-85], [-45], [30], [-45], [-40], [18], [20], [12], [-39], [77], [9], [8], [14], [-51], [-34], [-24], [14], [-40], [50], [6], [6], [32], [57], [-28], [-12], [86], [78], [38], [51], [50], [32], [11], [60], [-27], [-37], [-78], [-60], [-25], [80], [42], [60], [5], [8], [18], [35], [-34], [6], [-42], [-60], [-42], [6], [-25], [54], [-30], [18], [2], [44], [42], [38], [-34], [-30], [-88], [-18], [-42], [-58], [65], [15], [45], [-49], [-18], [-67], [78], [96], [-64], [-30], [11], [27], [23], [-76], [20], [-45], [-19], [-30], [84], [62], [-39], [50], [-16], [78], [50], [-66], [50], [36], [-58], [-6], [-87], [-16], [-79], [42], [-52], [0], [-19], [27], [-60], [-52], [-10], [-51], [-48], [104], [-3], [-21], [-36], [-70], [18], [60], [-10], [42], [-69], [-39], [92], [0], [32], [-30], [92], [84], [86], [-24], [-82], [38], [68], [86], [84], [63], [50], [-15], [-46], [-6], [14], [-81], [32]]
