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