
# q-expansion of newform 320.3.h.f, downloaded from the LMFDB on 23 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 = 320
weight = 3
poly_data = [1, 0, 14, 0, 9, 0, 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, 0, 0, 0], 1], [[23, 0, 20, 0, 2, 0], 5], [[0, 76, 0, 40, 0, 4], 5], [[7, -92, -10, -70, -2, -8], 5], [[21, -92, 30, -70, 4, -8], 5], [[0, 224, 0, 140, 0, 16], 5]]

hecke_ring_character_values = [[191, [-1, 0, 0, 0, 0, 0]], [261, [1, 0, 0, 0, 0, 0]], [257, [-1, 0, 0, 0, 0, 0]]]
aps_data = [[0, 0, 0, 0, 0, 0], [-1, -1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0], [2, 0, 0, 1, -1, 0], [-2, -2, 1, 2, 2, 0], [0, 0, 0, 0, 0, 1], [1, 1, -4, -1, -1, -1], [0, 0, -1, 0, 0, 2], [-12, -2, 0, 3, -3, 0], [-10, -8, 0, 0, 0, 0], [-2, -2, 4, 2, 2, 2], [1, 1, 8, -1, -1, -2], [-13, -5, 0, -1, 1, 0], [13, 1, 0, 6, -6, 0], [42, -8, 0, 1, -1, 0], [8, 8, -8, -8, -8, 3], [0, 0, -15, 0, 0, -2], [17, 1, 0, -7, 7, 0], [-47, 13, 0, 2, -2, 0], [6, 6, 2, -6, -6, -2], [-1, -1, 4, 1, 1, 3], [6, 6, -24, -6, -6, 2], [33, -3, 0, -14, 14, 0], [10, -8, 0, -16, 16, 0], [5, 5, -12, -5, -5, -1], [-58, -8, 0, 16, -16, 0], [20, -2, 0, 3, -3, 0], [-61, -21, 0, -20, 20, 0], [-39, -7, 0, -7, 7, 0], [12, 12, 0, -12, -12, -8], [-20, -26, 0, 3, -3, 0], [-12, -12, 3, 12, 12, -10], [2, 2, -8, -2, -2, -4], [6, 6, -31, -6, -6, 8], [-7, -23, 0, 17, -17, 0], [-12, -12, 26, 12, 12, 8], [3, 3, -32, -3, -3, -6], [-141, -21, 0, 20, -20, 0], [-16, 34, 0, -1, 1, 0], [-13, -13, -8, 13, 13, -10], [14, 14, -29, -14, -14, 12], [-10, 72, 0, -16, 16, 0], [20, 20, -8, -20, -20, 12], [-13, -13, -20, 13, 13, 1], [6, 6, -32, -6, -6, 1], [-34, -34, -14, 34, 34, 6], [-12, -12, 39, 12, 12, 14], [72, -54, 0, 31, -31, 0], [123, 35, 0, -4, 4, 0], [54, -24, 0, 0, 0, 0], [31, 31, -28, -31, -31, -5], [6, 6, 0, -6, -6, 2], [139, -29, 0, 7, -7, 0], [-6, -6, -27, 6, 6, -4], [-28, -28, 56, 28, 28, -12], [-18, 20, 0, -3, 3, 0], [-111, 65, 0, -7, 7, 0], [-6, -6, 32, 6, 6, 14], [-35, -35, -24, 35, 35, -2], [-213, -13, 0, -33, 33, 0], [-389, -13, 0, -12, 12, 0], [19, 19, -32, -19, -19, 20], [253, 1, 0, -2, 2, 0], [-12, -12, -46, 12, 12, -24], [10, 10, -72, -10, -10, 8], [-14, -14, 0, 14, 14, -5], [-44, -44, 13, 44, 44, -14], [-26, -26, 16, 26, 26, -26], [165, 41, 0, 14, -14, 0], [118, 56, 0, 48, -48, 0], [-18, -18, 24, 18, 18, 34], [-20, -20, 54, 20, 20, -24], [-108, -34, 0, -21, 21, 0], [-31, -31, 72, 31, 31, 18], [34, 34, 21, -34, -34, 4], [-116, -122, 0, -45, 45, 0], [281, 9, 0, -47, 47, 0], [54, 54, -64, -54, -54, -21], [266, -24, 0, 16, -16, 0], [179, 91, 0, -17, 17, 0], [26, 26, 103, -26, -26, -8], [-439, -71, 0, -15, 15, 0], [-6, -6, -104, 6, 6, 14], [3, 3, -92, -3, -3, 13], [-52, -52, 98, 52, 52, -16], [351, -17, 0, -8, 8, 0], [-293, -77, 0, -9, 9, 0], [80, 80, -16, -80, -80, -26], [470, -8, 0, 16, -16, 0], [306, 112, 0, 25, -25, 0], [-361, -25, 0, 56, -56, 0], [-40, -40, 88, 40, 40, -24], [62, -124, 0, 45, -45, 0], [16, 16, -131, -16, -16, 6], [-86, -86, 75, 86, 86, 0], [-252, -18, 0, 35, -35, 0], [-42, -136, 0, 0, 0, 0], [-350, 80, 0, 48, -48, 0], [-281, -89, 0, 48, -48, 0], [230, 40, 0, 80, -80, 0], [-225, -161, 0, -16, 16, 0], [-25, -25, 48, 25, 25, -22], [99, 59, 0, 4, -4, 0], [131, -117, 0, -65, 65, 0], [-26, -26, 61, 26, 26, 32], [-78, -78, -24, 78, 78, 22], [-523, 89, 0, -34, 34, 0], [12, 12, 152, -12, -12, 24], [-26, -26, 126, 26, 26, 54], [-229, 67, 0, -33, 33, 0], [-54, 184, 0, 17, -17, 0], [-14, -14, 24, 14, 14, -59], [13, 13, -44, -13, -13, 13], [-40, -40, 61, 40, 40, -50], [-52, -52, 18, 52, 52, -32], [347, -13, 0, 39, -39, 0], [53, 73, 0, -58, 58, 0], [-366, -208, 0, -63, 63, 0], [-78, -78, 56, 78, 78, -9], [26, 26, 51, -26, -26, -16], [-463, -207, 0, -31, 31, 0], [-87, -87, 4, 87, 87, -37], [72, 72, 96, -72, -72, -9], [-111, -99, 0, 106, -106, 0], [64, 64, -9, -64, -64, -14], [-119, -311, 0, -55, 55, 0], [118, -120, 0, -16, 16, 0], [-34, -34, 120, 34, 34, 42], [214, 12, 0, -75, 75, 0], [65, 65, 200, -65, -65, 4], [22, 22, 31, -22, -22, -20], [-342, 216, 0, -7, 7, 0], [76, 76, 60, -76, -76, -36], [35, 35, -216, -35, -35, -48], [-438, 40, 0, -112, 112, 0], [2, -16, 0, -48, 48, 0], [-32, -32, 40, 32, 32, 15], [569, 37, 0, -118, 118, 0], [48, 48, -216, -48, -48, 45], [418, 144, 0, -80, 80, 0], [98, 98, 49, -98, -98, -36], [-399, -47, 0, 177, -177, 0], [184, 58, 0, -41, 41, 0], [-343, -59, 0, -126, 126, 0], [769, 17, 0, -87, 87, 0], [100, 100, 14, -100, -100, -48], [-24, -24, 208, 24, 24, 51], [-108, -108, 144, 108, 108, -66], [72, 72, -183, -72, -72, 22], [-114, -268, 0, 133, -133, 0], [-27, -27, 48, 27, 27, 92], [547, -37, 0, 55, -55, 0], [-441, 183, 0, -56, 56, 0], [-502, -40, 0, 41, -41, 0], [1195, 67, 0, 68, -68, 0], [-58, -58, -8, 58, 58, -78], [-26, -26, -50, 26, 26, -10], [75, 323, 0, 7, -7, 0], [-45, -45, 92, 45, 45, -17], [390, -120, 0, -48, 48, 0], [401, -243, 0, -14, 14, 0], [-24, -24, -16, 24, 24, 18], [-88, -22, 0, -25, 25, 0], [-184, -184, 69, 184, 184, 30], [27, 27, 4, -27, -27, 13], [846, -44, 0, -3, 3, 0], [-200, -200, 56, 200, 200, -8], [72, 72, -280, -72, -72, -1]]
