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