
# q-expansion of newform 320.6.c.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 = 6
poly_data = [3, -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], 1], [[-2, 4], 1]]

hecke_ring_character_values = [[191, [1, 0]], [261, [1, 0]], [257, [-1, 0]]]
aps_data = [[0, 0], [0, -3], [45, 5], [0, 9], [-252, 0], [0, -18], [0, 104], [220, 0], [0, -367], [6930, 0], [6752, 0], [0, 2106], [-198, 0], [0, -63], [0, 1589], [0, -878], [24660, 0], [5698, 0], [0, -6579], [53352, 0], [0, -10692], [51920, 0], [0, -9323], [-9990, 0], [0, 15264], [109098, 0], [0, -10647], [0, 14641], [21010, 0], [0, -15832], [0, 13149], [-192852, 0], [0, 21644], [318340, 0], [-84150, 0], [-155848, 0], [0, 53766], [0, -21843], [0, 2729], [0, -74258], [-444420, 0], [-156902, 0], [332352, 0], [0, -118512], [0, 8986], [-395800, 0], [251548, 0], [0, 43533], [0, 175501], [-547670, 0], [0, -7252], [-1005840, 0], [895202, 0], [-558252, 0], [0, 118784], [0, 245993], [1736370, 0], [-1720048, 0], [0, 191826], [1465002, 0], [0, -248823], [0, 359962], [0, 139941], [568152, 0], [0, 259668], [0, 19846], [1580548, 0], [0, -185256], [0, -579239], [1594450, 0], [0, 44528], [1104840, 0], [0, 277029], [0, 442242], [-5093420, 0], [0, -478627], [-1799910, 0], [0, -739314], [-642798, 0], [-2057110, 0], [2937420, 0], [-2717702, 0], [4994352, 0], [0, 313848], [-4704040, 0], [0, -859463], [6203250, 0], [0, 324684], [3851298, 0], [0, 313893], [0, 197221], [-6763680, 0], [0, -1005831], [6875748, 0], [-6940100, 0], [0, -138847], [-4979790, 0], [-147798, 0], [0, 1867617], [9998098, 0], [0, 1787661], [0, 136366], [0, -1309643], [-2270070, 0], [-14380652, 0], [0, -850176], [0, 193681], [0, -1056712], [-8800200, 0], [-10766998, 0], [0, 2279709], [0, -1253718], [0, -1825396], [-9732380, 0], [-8601448, 0], [-6424398, 0], [0, 549837], [0, -569911], [0, -2516978], [1221660, 0], [-16278902, 0], [0, -2169792], [0, 395626], [0, 1553377], [-4502852, 0], [4880898, 0], [9969610, 0], [-11916720, 0], [0, 208449], [0, -919098], [-6169460, 0], [0, 2375513], [-15181648, 0], [0, -98334], [4514202, 0], [-12079870, 0], [0, -1571558], [0, 5206581], [0, -3155114], [24879690, 0], [3954148, 0], [3435498, 0], [0, 595233], [0, -5098199], [-15201470, 0], [28901160, 0], [0, -3046878], [0, -2570716], [-19550540, 0], [0, -4083907], [0, 298926], [-42283998, 0], [0, 20277], [0, -584431], [0, -4332159], [1876752, 0], [-6768520, 0], [11535570, 0], [0, -5919156], [-29491902, 0], [0, 3160261], [0, 2474228], [0, 7114329], [-38477052, 0], [0, -4073176], [0, -4348927], [-52159648, 0], [0, -1474614]]
