
# q-expansion of newform 6422.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 = 6422
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 = [[-1, 0, 0], [-1, 1, 0], [0, -1, 1], [0, 1, 0], [2, 1, -1], [0, 0, 0], [0, -2, 0], [-1, 0, 0], [1, 1, 2], [-6, 1, -3], [4, -4, 3], [-2, 2, -4], [-4, -1, 2], [-1, -2, 0], [3, 3, 1], [4, -4, 3], [0, -1, -5], [1, -2, -1], [0, -2, 4], [3, 0, 0], [-9, 4, -8], [1, -5, 0], [-6, 4, -9], [10, 0, 3], [6, 2, 0], [-3, -2, -4], [-2, 4, 5], [-2, -1, 2], [3, -6, 0], [7, 6, -2], [-4, -4, 5], [-13, 1, 1], [-3, -1, -6], [-6, -2, -3], [15, 1, 2], [11, -3, 0], [-6, 3, -3], [1, -1, 1], [7, -5, 3], [3, 7, 2], [4, 6, -7], [-3, -7, -3], [2, 1, -4], [3, -2, 9], [-10, -3, 6], [17, -3, 11], [-13, 9, -3], [7, 2, 2], [5, 1, -5], [2, -9, 8], [-4, -4, -1], [10, -11, 14], [-5, -1, -1], [-2, 1, 2], [-3, 8, -5], [-15, -6, 1], [10, -3, 10], [2, -3, -7], [-16, 5, -4], [-16, 5, 3], [-3, -11, 6], [4, -9, 15], [-5, -6, 2], [5, 5, -2], [-15, 7, -2], [-9, 3, -16], [4, -7, 5], [-1, 3, -2], [-14, 8, -11], [-8, 17, -11], [-10, -9, 6], [11, 1, -3], [-16, 4, 2], [3, 15, -13], [-1, -5, -13], [-17, 14, -1], [20, 2, 7], [-11, 9, 9], [-9, 2, 2], [-10, 11, -16], [-7, -12, 8], [-16, -1, -4], [3, -2, 9], [-18, 7, 3], [-11, -9, -1], [-24, 10, -1], [-4, 15, -10], [16, -16, 7], [-22, 4, -17], [12, -9, 8], [3, -9, -7], [10, 4, -2], [5, 4, 6], [11, -11, 16], [-1, -2, 0], [-12, 20, -6], [14, -12, -5], [-7, 2, -3], [-14, 17, -6], [-21, 11, 0], [-15, -13, 12], [-13, -3, 6], [-10, 19, -19], [-16, 10, 3], [1, 5, -7], [9, 6, 13], [-17, 17, -2], [-20, 4, 6], [-21, 14, -16], [-8, 20, -19], [-25, 2, -1], [-7, 19, -14], [20, -13, 6], [34, -1, 9], [-23, 2, 2], [-17, -1, -4], [-30, -6, 1], [8, -14, 17], [16, -11, 16], [-2, 14, -7], [-5, -16, 15], [23, -6, 12], [5, -8, 12], [30, -5, 2], [-4, -3, 6], [22, -14, 1], [9, -3, 11], [-14, -1, -24], [-17, -6, -7], [-33, 12, -4], [-1, 4, 13], [-14, 4, 4], [-19, 3, 10], [-26, 0, 1], [14, 15, -8], [10, -25, 25], [-11, 12, -2], [-15, -1, -15], [12, -21, 12], [11, -3, 3], [-18, 4, 1], [3, -1, 15], [-31, 6, -4], [24, -3, 8], [-3, 7, -1], [-14, -3, -14], [-14, 20, -24], [14, -18, -4], [-11, 14, -14], [-16, -11, 5], [-26, 11, 5], [5, -11, -9], [-3, 2, -9], [24, 0, -7], [-19, 10, -10], [18, -25, 10], [-29, -2, -16], [8, -2, -15], [-11, 5, -20], [-25, -4, 9], [5, 20, -2], [-28, 5, 8], [-15, 0, 5], [20, -5, 0], [-8, -3, -22], [-2, 15, -8], [-16, 7, -15], [-23, 6, -4], [19, -10, 12], [4, -31, 13], [6, 15, -19], [5, -8, 13], [15, -22, 6], [-27, 4, 7], [21, 2, 14], [40, 1, 2], [-35, 17, -6], [-11, 14, -1], [-35, 15, -17], [5, -22, 19], [0, -13, 2], [13, -1, 11], [7, 3, 25], [39, -3, 3], [6, -14, 7], [-4, 4, -7], [-24, 11, 8], [5, 6, -3], [-15, -14, -8], [39, -8, 0], [42, 7, -6], [-9, 23, 1], [5, 20, -11], [12, 12, 5], [-1, 3, -23], [19, 9, 7], [4, 13, 18], [-22, -1, 13], [-30, 8, 13], [38, 0, 7], [18, -21, 11], [-16, 31, -3], [8, 3, -14], [-29, 9, -11], [26, -10, 14], [-13, 15, -7], [47, 1, -5], [24, -30, 11], [1, -31, 19], [15, -10, 0], [45, -1, 15], [-15, 12, -2], [14, 20, -7], [31, -6, 23], [24, 4, -6], [13, 9, -6], [25, -22, -4], [46, 3, -5], [32, -27, -9], [-5, 18, 1], [34, 1, 3], [28, 14, 3], [-6, -3, 13], [-8, -12, 10], [29, -9, 9], [-11, 7, -21], [34, 5, -6], [-18, 2, 14], [17, -6, 11], [5, 6, -3], [-19, -17, 17], [-1, -17, -19], [8, -22, -2], [-17, 14, -24], [24, -23, -12], [-34, 4, -11], [-3, 27, 5], [-18, -10, -2], [27, -24, 5], [20, -4, 19], [10, 4, 13], [26, -2, -2], [-6, -12, 6], [27, 24, -18], [-18, 8, 6], [-30, 23, -7], [-2, 14, -31], [-18, 36, -38], [13, 5, 34], [-34, 19, -8], [38, -4, 17], [-19, -8, -4], [11, -23, -7], [6, -8, 0], [-20, -2, -21], [9, 7, 20], [12, -5, 11], [-13, 7, -3], [28, -13, 29], [-3, 13, -26], [-19, 22, -6], [3, 14, 6], [-57, 15, -10], [26, -16, 35], [3, 31, -21], [-33, 19, 14], [18, -27, -18], [-45, 7, -1], [-4, 27, -18], [-32, 24, 12], [-11, -17, -1], [45, -1, -5], [5, 4, 1], [32, -3, 10], [-47, 13, -2], [44, -5, 10], [-43, -3, -6], [-12, -3, -28], [14, -40, 34], [-23, 21, 16], [1, -3, -26], [-23, 36, -14], [3, 5, 9], [48, -7, -9], [38, -3, 1], [-18, 29, 3], [24, -13, 41], [-21, -16, 12], [-9, -15, 19], [16, 5, 11], [2, 21, -7], [-64, 9, -7], [22, -2, -9], [-21, 16, 15], [-23, 4, -33], [-33, 14, -26], [-17, -17, 9], [42, 14, -12], [-15, 40, -35], [14, 3, 22], [9, 32, -25], [-35, -3, -16], [35, -30, 10], [-16, -13, -18], [-65, -7, 1], [12, -6, 22], [-21, 10, -24], [12, -20, 6], [-18, 13, -26], [-53, 16, 5], [26, 4, 20], [-30, -2, -19], [2, 22, 12], [10, 14, 5], [26, 9, 0], [14, 27, -6], [31, -9, 20], [-18, 40, -23], [-12, 4, -12], [-19, -13, 3], [12, -30, 25], [24, 29, -24], [39, 0, -4], [-19, 1, -29], [10, 14, 15], [-13, -41, 21], [-21, 1, -34], [61, 11, -9], [-2, -9, -6], [-26, -8, -18], [-32, 10, 10], [24, -2, 25], [-2, 4, 6], [67, -8, 11], [19, -6, 5], [-23, -31, 21], [-64, 18, 4], [40, -31, 8], [58, -16, 21], [11, -6, -20], [20, -21, 36], [41, -29, 23], [-6, -27, 18], [-25, 16, 3], [-44, 6, -24], [33, -24, -9], [29, 11, 19], [-44, -3, -18], [22, -14, 27], [31, -17, 42], [45, -15, -11], [-41, 22, -24], [-9, -6, 24], [-29, 10, 17], [7, 9, 4], [-21, -30, 10], [-67, 2, 5], [22, 11, 16], [19, -35, 32], [-58, 1, -3], [-19, 27, 6], [7, -25, 12], [32, -37, 51], [10, -25, 20], [9, 13, -30], [-15, -33, 29], [-13, -28, 33], [24, 19, 3], [-37, 7, 6], [14, 12, -27], [-50, -5, -11], [-3, -29, 28], [6, -16, -2], [33, -35, 51], [-2, -6, -26], [13, 20, -17], [34, 14, -12], [68, -10, 4], [22, -17, 0], [7, -29, -1], [-49, -5, 15], [16, 20, -5], [-5, 0, -11], [8, 3, 6], [-36, 21, 17], [54, -31, 14], [18, -34, -20], [0, -42, 6], [-51, 1, -23], [-30, 24, 8], [-10, 28, -18], [-6, 13, -3], [4, -17, 16], [-23, -17, -6], [-8, 1, -10], [-28, 14, -11], [14, 20, -20], [20, 21, -3], [-24, 3, -28], [35, 4, -12], [66, -15, 11], [28, -33, 47], [37, -17, 26], [-12, -3, 0], [-29, -4, -23], [14, -12, -5], [-47, -3, -3], [49, -36, 15], [-19, 8, -32], [32, -7, 44], [-31, -14, -15], [-22, 37, -41], [-12, -12, -6], [-22, 7, -8], [32, -8, 22], [-6, -35, 34], [-26, -5, 20], [15, -17, 21], [-66, 7, -23], [61, -11, 8], [-36, 40, -49], [-35, -6, -5], [-5, -5, 31], [30, -29, 37], [-28, 18, -33], [34, 0, 27], [43, -20, 41], [13, 4, 21], [-61, -17, 13], [-15, -46, 27]]
