
# q-expansion of newform 2016.2.a.m, downloaded from the LMFDB on 15 November 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 = 2016
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], [4], [-1], [-2], [-2], [0], [4], [-6], [10], [8], [10], [4], [8], [-4], [-10], [8], [-6], [-4], [14], [6], [-4], [-12], [-4], [-2], [0], [0], [-10], [14], [-2], [20], [-20], [-6], [-4], [6], [0], [-22], [-20], [20], [-24], [-6], [14], [6], [6], [-2], [8], [-8], [16], [0], [14], [18], [-6], [-2], [-24], [4], [-30], [-12], [24], [10], [-6], [20], [0], [12], [-12], [-14], [-18], [32], [-22], [2], [-14], [8], [22], [-24], [14], [-32], [8], [-30], [-38], [-22], [22], [16], [-22], [-18], [-14], [-8], [-6], [-10], [-22], [0], [20], [-8], [-12], [40], [10], [-24], [24], [36], [0], [36], [-14], [-12], [22], [-24], [-14], [-20], [-6], [48], [24], [-10], [34], [8], [6], [18], [-36], [-4], [2], [12], [12], [26], [6], [-22], [-34], [-16], [18], [28], [18], [-26], [32], [0], [38], [-20], [6], [-16], [-42], [-12], [34], [-24], [-36], [-24], [14], [-20], [-2], [4], [-26], [14], [44], [42], [-28], [20], [-22], [-50], [-48], [8], [-12], [-32], [-18], [0], [36], [2], [-4], [-18], [6], [-12], [-20], [-14], [0], [-16], [-6], [-2], [8], [30], [42], [-26], [-26], [-8], [-16], [44], [42], [16], [34], [44], [28], [-14], [-8], [18], [-16], [30], [-28], [38], [-24], [-26], [-26], [-64], [32], [-34], [48], [-2], [-38], [-20], [-52], [54], [56], [-34], [6], [4], [0], [-8], [-34], [-10], [20], [50], [12], [24], [12], [20], [-54], [-16], [-40], [-14], [-6], [38], [-40], [30], [-32], [-36], [-22], [-36], [-54], [-8], [-38], [46], [20], [-32], [-66], [-4], [64], [14], [6], [66], [-8], [-54], [12], [0], [18], [44], [-44], [16], [-48], [-68], [26], [-66], [40], [-42], [54], [-32], [-18], [-30], [52], [-72], [-38], [52], [-6], [-58], [10], [24], [-44], [62], [-56], [-4], [42], [-46], [-8], [38], [24], [-2], [24], [22], [2], [46], [-64], [24], [-4], [-16], [-54], [4], [-18], [82], [-26], [-80], [20], [6], [12], [66], [80], [6], [-24], [-80], [84], [-24], [-4], [34], [10], [68], [-26], [28], [58], [-6], [30], [-42], [-70], [72], [2], [-14], [64], [-30], [70], [-36], [82], [-2], [66], [-36], [-10], [40], [16], [54], [70], [36], [-60], [22], [-22], [46], [58], [-16], [32], [-20], [-8], [30], [-76], [-34], [0], [62], [-22], [20], [-80], [-38], [-42], [-42], [8], [56], [-32], [20], [-10], [-10], [-72], [78], [0], [0], [60], [-98], [46], [-2], [84], [-50], [94], [-20], [-74], [60], [-44], [-50], [18], [-44], [-66], [-42], [40], [2], [-36], [10], [74], [96], [-66], [96], [46], [-32], [-90], [44], [64], [-72], [62], [-52], [52], [62], [-76], [-42], [-28], [-26], [66], [56], [24], [-68], [10], [-38], [-18], [44], [36], [92], [-32], [-94], [46], [60], [32], [-14], [34], [-102], [-48], [-26], [92], [58], [88], [56], [68], [-38], [-22], [38], [-12], [-46], [-80], [90], [106], [-52], [-60]]
