
# q-expansion of newform 1014.2.a.m, 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, ZZ
    R = PolynomialRing(QQ, "x")
    f = R(poly_data)
    K = NumberField(f, "a")
    betas = [K([c/ZZ(den) for c in num]) for num, den in basis_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 = 1014
weight = 2
poly_data = [1, -2, -1, 1]

# The entries in the following list give a basis for the
# coefficient ring in terms of a root of the defining polynomial above.
# Each line consists of the coefficients of the numerator, and a denominator.
basis_data  = [[[1, 0, 0], 1], [[0, 1, 0], 1], [[-2, 0, 1], 1]]

hecke_ring_character_values = None
aps_data = [[-1, 0, 0], [1, 0, 0], [1, 1, 1], [0, -1, 2], [0, -2, -1], [0, 0, 0], [6, -2, 4], [-4, 4, -4], [4, 2, -2], [4, -2, -3], [0, 4, -5], [6, -4, 2], [4, 0, -2], [0, -6, 2], [0, -4, 0], [1, 9, -3], [2, 1, -2], [-4, 2, 0], [8, -8, 10], [2, -6, 6], [-1, -3, -1], [4, -11, 6], [-2, 11, -2], [2, 2, -2], [-3, -1, -3], [2, -5, -4], [-9, 3, -7], [-2, 3, 2], [8, -4, 0], [4, 4, -4], [-11, 9, -9], [3, -3, 9], [-8, 4, -12], [0, -2, -2], [12, -6, -3], [-4, 0, -11], [2, -6, 2], [-6, -2, -4], [-6, 10, 6], [0, -10, 7], [7, -3, 17], [-10, 10, -6], [6, -6, -4], [2, 4, 4], [-6, 5, 0], [0, 12, -7], [-8, 6, 4], [0, 4, 4], [-17, 5, 1], [14, 6, -4], [-22, 8, -18], [-16, -2, -2], [-19, 7, -3], [-14, 15, -6], [2, -6, -4], [-10, 0, -10], [-3, -19, 9], [1, -7, 7], [-12, 10, -6], [-14, 6, -2], [-18, -4, 0], [12, -2, -1], [-10, 10, 8], [0, 6, -6], [-19, 11, -15], [6, -3, -4], [6, 4, 10], [-4, -8, -5], [10, 1, 2], [10, -2, -14], [18, -18, 20], [-4, -2, 2], [0, 5, -14], [-12, 22, -16], [-8, 8, 4], [-24, 6, -6], [24, -14, 15], [8, -2, 12], [2, 18, -16], [16, -15, 24], [0, -10, -3], [-12, -2, -4], [-14, -10, -2], [8, -16, 15], [12, -7, 18], [12, -6, -7], [-12, 4, -12], [4, -12, -5], [-10, 7, 12], [0, -16, 4], [5, 11, -13], [12, -20, 14], [-5, 15, 1], [4, -6, -7], [-4, 8, -16], [-18, 12, -14], [26, 0, 12], [2, 8, 16], [2, 8, -18], [-4, 8, -2], [4, 8, 0], [14, 0, 8], [-7, -5, 11], [0, -8, -24], [18, -24, 8], [-20, 9, -4], [20, -10, 29], [18, 0, 16], [10, -2, -8], [8, 0, -11], [32, -15, 14], [-8, 28, -2], [-4, -18, 4], [-10, 26, -6], [-16, 1, -6], [24, -18, 18], [-10, -6, -8], [-18, 16, -22], [14, -3, 16], [-14, 19, 6], [10, -24, 18], [4, -7, 20], [18, 13, 0], [-11, -5, -9], [-10, 0, -12], [-14, 4, 12], [26, -12, 26], [-18, 24, 8], [12, 9, 10], [-18, 6, -16], [-4, -4, 6], [-36, 12, -6], [28, 12, 3], [12, -12, 4], [-16, 8, -8], [-2, 4, -16], [34, -7, -12], [-16, 0, -22], [12, 14, -13], [-28, 4, 10], [-20, -8, 16], [-1, -9, -17], [-12, -23, 10], [-8, 14, -11], [-16, 14, -18], [14, 8, 22], [16, -12, 22], [12, -10, 28], [-12, -14, 16], [24, -12, 34], [40, -4, 6], [18, -2, -4], [-26, -14, 0], [-28, -8, 2], [-6, -16, 0], [34, -6, -8], [31, -9, 5], [-6, 28, -14], [-8, 0, 25], [12, -6, -7], [9, -13, -5], [-12, -6, -6], [12, 0, 7], [4, -26, 3], [-2, -14, 16], [10, -38, 4], [-15, 29, -17], [18, -10, 18], [-12, 8, -1], [-10, -8, 0], [36, 16, -8], [-18, -10, -8], [6, 28, 2], [-10, 20, 12], [0, 24, 12], [20, -34, 26], [16, 2, 14], [34, 15, -8], [-20, -12, 12], [-6, 2, 22], [5, 21, 3], [32, 26, -11], [-22, -10, -12], [-12, -18, 6], [-10, 20, -2], [22, 5, -4], [-6, 2, 4], [16, 10, 14], [-8, 41, -16], [-32, 34, -22], [4, 12, 27], [6, 1, 18], [34, -22, 8], [41, -31, 33], [-37, 29, -27], [8, 20, 4], [-40, 20, -29], [10, 14, -14], [-28, 22, 8], [6, -14, 0], [10, -28, -4], [-4, 20, 15], [48, -4, 4], [21, -9, 21], [-2, 7, -6], [-12, 46, -23], [41, -15, 7], [-14, 33, -18], [12, -10, 32], [30, -12, 38], [17, 3, -11], [0, -30, -9], [4, -20, 28], [4, -20, 24], [14, 6, 32], [-20, -1, -8], [-12, 16, 7], [16, -16, -8], [-28, 26, -14], [-35, 9, 1], [18, -40, 12], [-17, 19, -11], [-6, 20, 18], [-32, 12, -19], [0, -4, -4], [8, -2, 16], [2, 0, -40], [6, 2, 26], [7, 15, 25], [-23, 3, -1], [-52, 20, -18], [34, 8, 0], [24, -21, 22], [22, -22, -6], [-34, 46, -42], [-32, 18, -10], [-16, 33, -4], [22, 15, -8], [8, 16, 20], [48, -32, 42], [4, -6, -7], [-16, -14, -10], [-16, 12, 36], [-28, -24, 20], [-32, 32, -36], [20, -40, 30], [48, -20, 33], [8, -42, 29], [14, -16, -22], [-4, -16, 22], [30, -16, 38], [-34, -2, -16], [-28, 6, -42], [8, -7, -32], [-2, 3, -36], [50, -31, 30], [4, 10, 14], [0, -20, 34], [34, -13, 12], [-44, 4, 9], [16, -16, 3], [37, -5, 23], [-6, -14, 8], [-14, 8, 8], [-44, 10, -40], [-20, 20, 12], [-7, 33, -31], [-18, 0, -12], [-26, 34, -38], [-33, 15, -29], [32, 8, -12], [-8, -12, -14], [-37, -19, 15], [1, -31, -9], [24, -3, -8], [36, 8, 15], [59, 1, 5], [-66, 12, -24], [-8, 17, 16], [-10, 33, 6], [-16, 26, 36], [-15, -19, 7], [12, 0, -20], [-34, -8, -12], [38, 20, -16], [-12, 24, -28], [-33, -15, 11], [13, -31, 21], [-20, -4, 11], [-28, 4, -10], [26, -19, 16], [-8, -46, 23], [24, -26, -8], [23, 9, 1], [-38, -22, -2], [-30, -15, -12], [-11, 33, -25], [2, 27, 12], [-36, 10, -39], [-14, -2, -44], [-20, 32, 3], [-3, 29, 1], [20, -39, 34], [5, -5, 11], [34, -24, 20], [33, -21, 21], [-16, -28, 0], [46, -44, 52], [-8, 18, -18], [10, -28, 0], [-22, 24, -4], [-2, -23, 0], [48, -16, 42], [-62, -4, -2], [-46, 22, 16], [-40, 20, -21], [-39, 23, -17], [0, -50, 28], [18, -64, 32], [-22, -2, -4], [-30, -34, 4], [8, 8, 13], [46, -21, 40], [-60, 0, 1], [50, 6, -4], [-36, 16, 9], [-62, 2, 0], [38, -12, 8], [20, 0, -26], [2, -8, 48], [-14, 28, 30], [-9, 15, 15], [24, 28, -12], [19, 25, -11], [50, 20, -4], [29, -33, 47], [12, 16, 2], [-24, 12, 14], [12, 4, -23], [0, -16, -13], [-14, -10, -44], [-2, -4, 26], [20, 6, 3], [40, -12, 25], [28, -14, -33], [-14, 51, -46], [-34, 26, -32], [12, 4, -42], [-22, -34, -2], [5, -7, -3], [-20, 24, -4], [60, 17, -12], [-44, 26, -9], [-20, 32, -12], [10, 32, -24], [4, -18, -6], [-28, 4, -34], [-34, 19, -50], [-38, 46, 0], [-4, -24, 26], [-4, -8, -14], [4, -12, -4], [4, 32, -6], [62, -15, -2], [-6, -8, 32], [43, -15, 7], [-6, -15, 16], [-17, -1, -23], [44, -16, -9], [19, 17, 17], [28, -24, -28], [-26, 42, -48], [4, 22, 21], [11, -5, -19], [20, 16, -38], [-1, 29, -11], [42, -20, -26], [8, 25, 12], [-14, -2, 8], [-12, -37, 4], [40, -22, 33], [36, 2, 4], [-8, -20, 11], [22, -4, -14], [24, -60, 40], [12, -4, 30], [8, -11, 42], [-2, -34, 18], [-30, 10, -22], [50, -10, 28], [-36, 52, -15], [29, -31, 25], [66, -25, 34], [24, -22, 32], [-30, 14, 38], [8, -28, 9], [24, -7, 14], [-48, 18, -14], [42, 2, 10], [-28, 6, -63], [-14, -28, -10], [-16, 28, -36], [27, 23, -27], [-36, 16, -18], [-4, 38, -25], [-75, 29, -53], [66, -34, 18], [-26, 24, 8], [4, -28, 38], [-44, -12, 0], [68, -37, 44], [-48, -10, 19], [52, 6, -19], [6, 30, -10], [-11, -5, -51], [-6, -12, 36], [10, 0, -10], [-48, 36, -43], [-16, -6, 2], [28, -32, 20], [34, 13, 16], [46, -12, -10], [34, -34, 46], [-40, 20, 12], [24, 12, -35], [-42, 8, -36], [-37, 17, -47], [-26, 44, -56], [54, -26, -6], [50, -14, 26]]
