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