
# q-expansion of newform 8880.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 = 8880
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 = [[0], [-1], [-1], [1], [-3], [-7], [-3], [1], [3], [6], [10], [1], [0], [4], [12], [9], [-6], [-10], [10], [6], [11], [-8], [-9], [-9], [-16], [-6], [4], [-3], [-7], [18], [7], [12], [-18], [-14], [-6], [-23], [-4], [1], [-3], [-9], [0], [-22], [-3], [-10], [3], [-20], [-2], [-8], [-24], [-10], [18], [-12], [26], [-6], [9], [0], [9], [-20], [23], [27], [13], [-15], [22], [24], [8], [-18], [28], [-13], [-36], [8], [18], [12], [-23], [14], [-26], [9], [18], [-4], [15], [-4], [27], [-10], [3], [-31], [-20], [12], [-30], [8], [18], [4], [0], [39], [22], [9], [-41], [-36], [-33], [-12], [-44], [-25], [37], [-24], [18], [-39], [-14], [2], [36], [-36], [12], [-37], [-14], [-34], [42], [-20], [4], [24], [31], [-45], [-36], [-12], [-13], [-1], [3], [36], [10], [-48], [-25], [-6], [-2], [14], [34], [-6], [4], [-13], [6], [-22], [15], [-2], [30], [-21], [28], [-9], [7], [12], [29], [-30], [-19], [-9], [-5], [0], [32], [-12], [-35], [18], [37], [-48], [4], [-18], [-10], [18], [24], [6], [22], [-36], [9], [-42], [52], [-1], [14], [36], [6], [-46], [48], [-61], [37], [42], [-8], [15], [-32], [38], [4], [42], [5], [18], [-24], [-15], [-16], [-29], [-52], [0], [62], [60], [-11], [-15], [-12], [36], [-40], [26], [36], [-3], [-6], [-35], [-40], [-46], [12], [-6], [25], [-39], [-9], [-32], [-22], [-24], [40], [-3], [-27], [-19], [22], [-42], [-57], [-21], [2], [25], [6], [-38], [12], [11], [24], [-24], [4], [0], [-70], [-56], [43], [72], [28], [18], [5], [-66], [18], [24], [-60], [1], [-17], [-49], [72], [-75], [70], [-30], [-38], [33], [-67], [72], [6], [-4], [66], [-48], [-58], [-62], [-51], [-34], [-2], [-48], [-4], [-10], [9], [28], [-27], [-30], [58], [-66], [59], [-47], [-64], [-32], [41], [-29], [-21], [26], [35], [42], [-6], [-50], [6], [-28], [52], [-30], [2], [42], [10], [-9], [30], [-18], [18], [27], [32], [-54], [1], [33], [0], [-80], [-22], [-18], [-32], [30], [31], [56], [60], [50], [66], [-79], [-48], [-57], [18], [52], [45], [-22], [-45], [15], [-70], [81], [-89], [-73], [-12], [-35], [-24], [-16], [64], [40], [9], [-66], [-16], [48], [-74], [-30], [19], [-24], [-22], [30], [-34], [-56], [-76], [-6], [0], [-32], [84], [-30], [56], [22], [0], [54], [34], [65], [60], [-74], [2], [-72], [-39], [78], [72], [-72], [-46], [-42], [-51], [-36], [-38], [62], [48], [-2], [50], [72], [64], [54], [-39], [22], [38], [45], [42], [-97], [-27], [59], [-54], [9], [-38], [-18], [-68], [-12], [97], [86], [-20], [57], [-19], [-66], [-48], [-23], [-96], [-73], [22], [72], [22], [75], [-40], [57], [28], [-18], [-18], [-47], [-61], [-84], [-80], [36], [-67], [-63], [78], [43], [-28], [-81], [-12], [-65], [-90], [0], [-18], [77], [-18], [57], [47], [-78], [-51], [-18], [94], [-108], [-97], [-84], [1], [60], [-4], [-60], [-10], [74], [88], [34], [-51], [3], [-22], [60], [8], [-93], [4], [-72], [68], [80], [97], [78], [-27], [-24], [14], [-12], [44], [-84], [-58], [-48], [40], [76], [72], [71], [-11], [98], [1], [81], [60], [-20], [-32], [42], [39], [20], [12], [-31], [72], [52], [96], [51], [20], [-54], [29], [-90], [16], [15], [-58], [-102], [76], [-23], [-19], [54], [-100], [-6], [114], [86], [40], [54], [-77], [-20], [60], [-20], [78], [10], [-49], [48], [-30], [-38], [-4], [103]]
