
# q-expansion of newform 4140.2.a.m, 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 = 4140
weight = 2
poly_data = [-4, -1, 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, 0], [0, 0], [-1, 0], [0, 1], [-2, 0], [-1, -1], [0, -1], [6, 0], [-1, 0], [-1, -2], [-3, 4], [-2, -1], [1, -2], [0, 0], [3, -3], [2, 1], [-4, 3], [-2, -2], [-6, -1], [-5, -2], [-7, 1], [10, -2], [-4, 7], [-4, -4], [-8, -2], [10, 3], [-16, 0], [-6, 1], [0, 6], [0, -5], [-5, 5], [-13, 5], [-12, 2], [-1, -4], [-6, 6], [9, -9], [-12, 3], [-1, 7], [8, 0], [10, -6], [-11, 7], [10, -6], [-2, -6], [5, -1], [11, 3], [-10, 0], [8, -3], [8, -10], [-16, -4], [4, -12], [-7, 3], [-13, 4], [6, 0], [-8, 6], [-19, -5], [-18, 7], [-13, -4], [4, 7], [1, -3], [12, -2], [2, 5], [4, 5], [-16, -2], [-1, -3], [12, -5], [-10, -2], [3, 10], [-12, 10], [4, -8], [-11, -6], [-21, 9], [10, -10], [-20, -1], [-10, -4], [-16, -8], [-16, 5], [16, -2], [-9, 17], [-2, 0], [5, -16], [24, -2], [20, 2], [0, 4], [22, 7], [7, 5], [-1, 5], [14, 3], [12, -1], [23, 7], [-16, -6], [30, -3], [-8, 20], [-5, 5], [9, -8], [-3, 10], [-14, 7], [-1, 11], [-12, 10], [16, -12], [5, -3], [7, -11], [8, 3], [16, -19], [14, -12], [36, 0], [-27, -1], [-25, 7], [10, -10], [-8, 16], [21, 6], [-12, 8], [20, -10], [2, -1], [-8, 8], [20, 4], [-12, 2], [-18, 15], [-13, 3], [9, -19], [0, -6], [14, -8], [-9, 17], [-14, -5], [-19, -9], [-4, 8], [12, -4], [40, -4], [4, -9], [-34, 5], [8, -3], [-25, 10], [-24, 8], [-8, -2], [10, 1], [3, 16], [-26, 6], [36, 2], [-32, -3], [14, 15], [26, 11], [37, 4], [14, 8], [-15, -9], [-12, -3], [14, -17], [48, -2], [-10, -4], [41, -3], [-35, 8], [5, 1], [22, -16], [20, -24], [-20, 12], [11, -21], [14, 3], [-2, 2], [16, 12], [-15, 28], [-6, -4], [48, -4], [-49, -3], [18, 8], [-49, -3], [38, -6], [-6, -21], [14, 9], [20, 13], [30, 10], [-30, -10], [9, 11], [-34, -10], [-43, 4], [24, -2], [44, -7], [7, -11], [16, -12], [27, -11], [21, 12], [30, -7], [0, 10], [43, -9], [28, -12], [-23, -7], [-34, 20], [-26, 15], [-12, 2], [14, -20], [-2, 9], [-35, 4], [4, -3], [-25, 11], [-36, 10], [6, -12], [-22, 1], [-22, 6], [24, 13], [34, -4], [48, 2], [48, 6], [21, 1], [-4, -12], [-16, 20], [-3, 21], [-6, 8], [-12, -12], [-37, 3], [30, 10], [11, 3], [9, -26], [7, -15], [-1, -21], [21, -23], [-16, 0], [30, 6], [20, 11], [24, -20], [-15, 1], [3, -20], [-10, 15], [-3, 25], [31, 2], [62, 4], [-21, 2], [32, -5], [-53, 7], [-1, -20], [-38, -12], [-31, 14], [10, 18], [24, -15], [-46, 16], [4, 6], [-22, -8], [-22, -9], [-24, 1], [0, -12], [-8, 24], [-22, 0], [55, 0], [5, 20], [-28, 7], [25, -8], [-63, 1], [-37, 15], [10, -14], [7, 17], [29, 7], [22, 12], [-14, -16], [2, -11], [12, -26], [2, 0], [-10, -1], [-40, 2], [-50, 8], [-63, -2], [42, -14], [-30, 6], [-17, 11], [5, -11], [-40, 19], [-32, -7], [-2, -11], [-16, 11], [-6, -14], [14, -10], [-26, -14], [-52, 14], [-22, 13], [11, -23], [-27, -16], [-6, -17], [36, 17], [-44, -6], [-11, 3], [13, 5], [-12, -4], [-2, 31], [-22, 22], [16, -28], [9, -11], [-6, -6], [42, -2], [46, 14], [16, 14], [36, 1], [-10, -17], [-46, 0], [-32, 0], [18, -20], [-18, 12], [0, -19], [22, -6], [-46, -10], [53, -5], [-26, 6], [4, -22], [1, -15], [-27, -20], [-21, -13], [20, 23], [42, 1], [12, 12], [-55, 7], [-20, 24], [-53, -11], [-4, -10], [12, 14], [-58, 10], [10, -14], [-25, 13], [-14, -4], [-8, 28], [71, 1], [-50, 3], [-44, 16], [17, -22], [3, 4], [-36, 9], [-11, 17], [-24, 0], [28, -13], [-31, -7], [-24, -10], [-42, 5], [-16, 12], [26, 2], [23, -25], [-38, 22], [-20, -3], [37, 18], [-3, -3], [-13, -4], [1, 13], [-10, 14], [25, -5], [-54, -4], [-4, 30], [-5, 19], [80, 1], [27, 15], [-56, -6], [-22, -4], [-42, -6], [70, -1], [-24, 21], [19, -26], [60, 6], [-54, 8], [-14, -13], [-39, 10], [1, 3], [38, -21], [70, -7], [-56, 12], [-50, 12], [44, -6], [42, -24], [47, 3], [-28, -18], [-38, 35], [-13, -16], [-59, 21], [82, -6], [47, 15], [-11, 13], [69, -5], [38, -1], [-14, 10], [-51, 16], [56, 5], [-1, -33], [-36, 4], [56, -8], [-25, -5], [37, -14], [-2, 0], [74, -1], [28, 28], [27, -25], [-34, 28], [-54, -12], [-60, -12], [-3, -15], [20, -16], [25, 5], [51, -30], [-58, 6], [22, 3], [68, 11], [4, -18], [26, -4], [7, 30], [20, -20], [-16, 18], [-14, -1], [60, 2], [36, -20], [-4, 0], [14, 25], [-29, 16], [-1, -33], [-28, 15], [32, -7], [33, -4], [-71, 2], [-30, 9], [-73, 19], [-36, 8], [12, -8], [11, -19], [-39, -7], [34, -38], [-58, -14], [-26, -3], [27, -25], [-16, -8], [44, -28], [4, -21], [20, -48], [24, -6], [-16, -22], [0, -30], [44, 0], [-23, -1], [5, -1], [-42, -10], [-90, -5], [-23, -1], [39, -10]]
