
# q-expansion of newform 720.3.bh.f, downloaded from the LMFDB on 25 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 = 720
weight = 3
poly_data = [9, 0, 0, 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], 1], [[0, 1, 0, 0], 1], [[0, 0, 1, 0], 3], [[0, 0, 0, 1], 3]]

hecke_ring_character_values = [[271, [1, 0, 0, 0]], [181, [1, 0, 0, 0]], [641, [1, 0, 0, 0]], [577, [0, 0, -1, 0]]]
aps_data = [[0, 0, 0, 0], [0, 0, 0, 0], [-3, 1, -1, 2], [-5, 0, 5, 2], [-4, -5, 0, 5], [0, 10, 0, 0], [10, 0, -10, 2], [0, -10, 10, -10], [-10, 6, -10, 0], [0, -5, -22, -5], [-4, 10, 0, -10], [0, 0, 0, -6], [-50, 10, 0, -10], [-30, 4, -30, 0], [0, 0, 0, -18], [50, -12, 50, 0], [0, 15, 52, 15], [-78, -10, 0, 10], [10, 0, -10, -12], [-20, 40, 0, -40], [-5, -32, -5, 0], [0, -10, -24, -10], [-60, -34, -60, 0], [0, 60, 10, 60], [75, 0, -75, 16], [-58, 5, 0, -5], [-55, 26, -55, 0], [-40, 0, 40, -46], [0, -30, -86, -30], [-40, 22, -40, 0], [-5, 0, 5, 2], [32, -5, 0, 5], [60, 0, -60, -34], [0, -40, 122, -40], [0, -35, -114, -35], [110, 20, 0, -20], [-30, 0, 30, 6], [40, -40, 40, 0], [130, 0, -130, 34], [-80, -74, -80, 0], [0, 5, -88, 5], [-10, -110, 0, 110], [4, -30, 0, 30], [15, -56, 15, 0], [-30, 0, 30, 188], [0, 20, -114, 20], [-110, 40, 0, -40], [105, 110, 105, 0], [100, 0, -100, 80], [0, 60, 138, 60], [-90, -50, -90, 0], [0, 60, -96, 60], [-32, 0, 0, 0], [-312, -25, 0, 25], [140, 0, -140, -54], [130, 66, 130, 0], [0, -15, 242, -15], [66, 0, 0, 0], [180, 0, -180, 26], [-6, -130, 0, 130], [-50, -208, -50, 0], [-90, 192, -90, 0], [-150, 0, 150, -24], [-116, 40, 0, -40], [-255, -56, -255, 0], [-60, 0, 60, 2], [-202, -170, 0, 170], [-75, 0, 75, -16], [320, 0, -320, -76], [0, 90, 38, 90], [-90, 142, -90, 0], [0, -30, 212, -30], [-5, 0, 5, -338], [70, -174, 70, 0], [0, 0, -194, 0], [-240, 238, -240, 0], [0, -105, 222, -105], [10, 0, -10, -326], [114, -200, 0, 200], [0, -80, -12, -80], [0, -125, -504, -125], [-310, -80, 0, 80], [128, -90, 0, 90], [65, 4, 65, 0], [0, 140, -214, 140], [-120, -176, -120, 0], [0, -150, -154, -150], [255, 0, -255, -240], [-326, 75, 0, -75], [-515, -18, -515, 0], [140, 0, -140, 414], [0, -60, 52, -60], [-105, 0, 105, 114], [4, 65, 0, -65], [0, -110, 278, -110], [-240, 234, -240, 0], [0, -45, -226, -45], [-522, 110, 0, -110], [-30, 52, -30, 0], [-482, -50, 0, 50], [-390, 0, 390, 184], [150, 0, -150, -236], [-420, 300, -420, 0], [0, -140, -338, -140], [-230, -10, 0, 10], [205, 0, -205, 396], [-180, 0, 180, -402], [40, 314, 40, 0], [0, -70, 568, -70], [-202, 180, 0, -180], [135, 0, -135, 186], [-210, 418, -210, 0], [150, 0, -150, -182], [0, -120, -522, -120], [-232, -130, 0, 130], [-634, -120, 0, 120], [-480, 236, -480, 0], [-620, 0, 620, 14], [240, 134, 240, 0], [0, -105, -196, -105], [938, -90, 0, 90], [295, -340, 295, 0], [160, 0, -160, -418], [540, 214, 540, 0], [1122, 10, 0, -10], [514, 65, 0, -65], [0, 120, 662, 120], [0, 60, -236, 60], [-585, 0, 585, -206], [100, 106, 100, 0], [0, 430, -130, 430], [-260, -266, -260, 0], [-252, -450, 0, 450], [-420, 0, 420, 462], [-182, -10, 0, 10], [0, 60, 706, 60], [420, 58, 420, 0], [890, 0, -890, -56], [240, 0, -240, 334], [0, 160, -518, 160], [310, -140, 0, 140], [-86, -365, 0, 365], [85, 342, 85, 0], [780, 0, -780, -244], [0, -290, 586, -290], [0, 30, 1052, 30], [670, 302, 670, 0], [-750, 0, 750, -106], [0, 220, 410, 220], [-430, -518, -430, 0], [-450, 0, 450, -98], [550, -280, 0, 280], [380, -272, 380, 0], [150, 0, -150, 158], [140, 0, -140, 636], [568, -90, 0, 90], [0, -330, 836, -330], [0, 10, 1046, 10], [-155, 0, 155, -176], [-630, 365, 0, -365], [-380, 0, 380, -216], [420, -34, 420, 0], [-205, 0, 205, -210], [-872, -275, 0, 275], [150, 0, -150, -566], [460, 638, 460, 0], [662, -360, 0, 360], [700, 0, -700, 82]]
