
# q-expansion of newform 3969.2.a.m, downloaded from the LMFDB on 19 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 = 3969
weight = 2
poly_data = [1, -4, -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], [[-3, -1, 1], 1]]

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