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