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