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