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