
# q-expansion of newform 4002.2.a.m, downloaded from the LMFDB on 18 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 = 4002
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], [1], [-3], [-4], [3], [5], [-6], [2], [-1], [-1], [5], [-7], [-9], [-10], [-12], [6], [-3], [5], [-13], [-3], [2], [8], [-6], [-12], [-10], [3], [-1], [6], [-10], [-6], [-7], [6], [-6], [20], [15], [-16], [14], [-13], [-9], [0], [-12], [14], [-3], [-22], [-18], [-25], [5], [26], [-18], [17], [-24], [9], [-22], [15], [0], [12], [-3], [11], [17], [-6], [11], [12], [29], [-12], [20], [3], [8], [-13], [12], [35], [-24], [24], [-22], [-4], [20], [12], [6], [14], [21], [32], [-30], [23], [-12], [2], [-10], [24], [3], [8], [15], [-22], [3], [-21], [38], [-24], [-22], [0], [-36], [-42], [23], [-22], [-4], [-9], [21], [-6], [-7], [-10], [-12], [24], [-6], [20], [-40], [14], [-18], [-16], [-43], [0], [-4], [-3], [-27], [36], [8], [26], [0], [9], [50], [-33], [26], [15], [-46], [-7], [5], [-15], [38], [-19], [-42], [23], [36], [53], [-24], [-39], [-22], [-6], [-31], [21], [-34], [3], [-22], [-54], [-28], [-33], [-46], [36], [2], [-36], [-10], [-15], [-25], [24], [32], [-27], [42], [-6], [-4], [21], [-3], [33], [44], [8], [-40], [42], [6], [50], [24], [-46], [32], [9], [50], [42], [38], [-16], [23], [-39], [23], [-36], [-12], [-63], [-40], [14], [-40], [36], [-61], [24], [32], [-42], [3], [54], [-13], [44], [54], [21], [-12], [44], [68], [14], [-12], [-12], [-16], [-63], [-18], [35], [-10], [30], [44], [12], [-54], [-70], [50], [27], [60], [-63], [50], [5], [45], [2], [72], [-28], [-12], [54], [-4], [-57], [-22], [-16], [-52], [-42], [41], [-12], [-31], [-66], [39], [48], [-60], [8], [26], [-70], [-24], [72], [-70], [-66], [-1], [-27], [50], [-63], [48], [65], [18], [-69], [-58], [-22], [-24], [-73], [-10], [12], [-1], [-13], [78], [8], [18], [0], [-4], [-42], [-25], [68], [-34], [32], [-82], [-28], [-18], [-46], [11], [-54], [75], [8], [-54], [56], [8], [0], [-70], [18], [-4], [66], [42], [12], [48], [-36], [-10], [-57], [80], [42], [-3], [44], [77], [-45], [-40], [-30], [74], [-58], [72], [-70], [36], [38], [-3], [12], [81], [-58], [-72], [8], [-12], [63], [-4], [-3], [44], [68], [-78], [-64], [42], [-13], [-79], [8], [87], [51], [2], [54], [-34], [78], [-16], [-12], [-16], [-78], [44], [29], [-64], [63], [27], [-19], [66], [30], [20], [-43], [-27], [-36], [62], [-97], [-27], [-1], [-10], [27], [27], [-60], [9], [33], [62], [24], [-42], [-6], [-7], [-40], [18], [65], [-34], [42], [74], [-24], [72], [-31], [11], [-24], [-69], [65], [3], [-10], [36], [-27], [89], [57], [68], [3], [80], [26], [20], [-3], [-91], [18], [-84], [-7], [45], [-88], [-100], [12], [5], [-6], [-7], [-33], [-28], [39], [-42], [8], [-100], [-69], [98], [-51], [-91], [18], [84], [44], [41], [-90], [-66], [44], [-60], [63], [-9], [-22], [-36], [-72], [-7], [-6], [60], [-6], [-16], [-30]]
