
# q-expansion of newform 336.4.b.f, downloaded from the LMFDB on 24 September 2025.

# 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 = 336
weight = 4
poly_data = [1232100, 0, 180672, 0, 8461, 0, 158, 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, 0, 0], 1], [[0, -185964, 0, -14702, 0, -316, 0, -2], 11655], [[21107760, -5860488, 2786840, -690094, 88060, -20597, 740, -169], 93240], [[-21107760, -5860488, -2786840, -690094, -88060, -20597, -740, -169], 93240], [[0, 11580252, 0, 1117496, 0, 31333, 0, 251], 93240], [[0, -8481804, 0, -1027292, 0, -31171, 0, -257], 93240], [[33438, 0, 3892, 0, 119, 0, 1, 0], 21], [[177216, 0, 20630, 0, 613, 0, 5, 0], 63]]

hecke_ring_character_values = [[127, [-1, 0, 0, 0, 0, 0, 0, 0]], [85, [1, 0, 0, 0, 0, 0, 0, 0]], [113, [1, 0, 0, 0, 0, 0, 0, 0]], [241, [-1, 0, 0, 0, 0, 0, 0, 0]]]
aps_data = [[0, 0, 0, 0, 0, 0, 0, 0], [3, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 1, 1, 1, 0, -1, 0, 0], [0, -2, -1, -1, -1, 1, 0, 0], [0, 2, 2, 2, 0, -3, 0, 0], [8, 0, -1, 1, 0, 0, 0, 1], [0, -2, -2, -2, -3, -2, 0, 0], [32, 0, -2, 2, 0, 0, 1, 1], [-40, 0, 0, 0, 0, 0, -2, 1], [52, 0, -3, 3, 0, 0, -1, -3], [0, 2, 8, 8, 6, -1, 0, 0], [0, 7, 1, 1, -6, 6, 0, 0], [90, 0, 12, -12, 0, 0, -1, 0], [38, 0, -2, 2, 0, 0, 2, -5], [218, 0, 10, -10, 0, 0, 1, 4], [0, -4, 3, 3, -1, 7, 0, 0], [0, -13, 9, 9, -6, 0, 0, 0], [0, 30, -6, -6, -3, 32, 0, 0], [0, 28, 18, 18, -2, -16, 0, 0], [0, 4, -1, -1, -6, -24, 0, 0], [-210, 0, 0, 0, 0, 0, -5, 0], [0, -38, 4, 4, 6, -19, 0, 0], [0, 22, 14, 14, -10, 40, 0, 0], [0, 28, -32, -32, 12, 27, 0, 0], [-432, 0, -16, 16, 0, 0, 2, 3], [0, 23, -7, -7, 12, -51, 0, 0], [-362, 0, 34, -34, 0, 0, -8, 4], [592, 0, -4, 4, 0, 0, 9, -10], [0, 70, 19, 19, 30, 36, 0, 0], [-514, 0, 40, -40, 0, 0, 7, -14], [-946, 0, -38, 38, 0, 0, 6, -8], [304, 0, 4, -4, 0, 0, 18, 8], [-86, 0, 68, -68, 0, 0, 16, -13], [0, 10, 45, 45, 36, -96, 0, 0], [0, 116, -73, -73, -21, -69, 0, 0], [0, 21, 5, 5, 30, 60, 0, 0], [824, 0, -2, 2, 0, 0, 4, -26], [0, -100, -58, -58, 42, -43, 0, 0], [0, -23, -41, -41, 30, 93, 0, 0], [0, -18, -89, -89, -13, 217, 0, 0], [0, -88, -34, -34, 9, 142, 0, 0], [-472, 0, -19, 19, 0, 0, 3, 11], [132, 0, 12, -12, 0, 0, -9, -33], [2112, 0, -47, 47, 0, 0, -4, -18], [0, -23, 41, 41, -18, -282, 0, 0], [20, 0, 11, -11, 0, 0, 18, 52], [2188, 0, 44, -44, 0, 0, 4, 38], [0, -148, 11, 11, -33, -3, 0, 0], [-940, 0, -134, 134, 0, 0, 15, 40], [0, 62, 68, 68, 3, 132, 0, 0], [0, 282, 20, 20, -32, 74, 0, 0], [1584, 0, 114, -114, 0, 0, -14, -12], [0, -158, 124, 124, 30, -5, 0, 0], [0, 132, 138, 138, -27, -308, 0, 0], [0, 308, -106, -106, -54, 161, 0, 0], [276, 0, 152, -152, 0, 0, 4, 3], [3908, 0, -25, 25, 0, 0, 23, 5], [136, 0, -136, 136, 0, 0, 1, 2], [3996, 0, 37, -37, 0, 0, -22, -27], [0, 192, 102, 102, 54, -3, 0, 0], [1012, 0, 15, -15, 0, 0, -18, 71], [4090, 0, -106, 106, 0, 0, -13, 32], [0, -408, 56, 56, 28, 80, 0, 0], [-3662, 0, 8, -8, 0, 0, -20, -19], [0, -17, -31, -31, -78, -186, 0, 0], [-3258, 0, -22, 22, 0, 0, 26, 2], [0, -1, -85, -85, -66, 325, 0, 0], [0, 96, -107, -107, -91, -83, 0, 0], [0, 450, -120, -120, -66, 41, 0, 0], [0, -332, 232, 232, 63, -126, 0, 0], [3780, 0, 79, -79, 0, 0, -26, 6], [-902, 0, -116, 116, 0, 0, -22, -80], [0, -45, 221, 221, 150, -270, 0, 0], [966, 0, -96, 96, 0, 0, 37, -18], [1432, 0, -88, 88, 0, 0, -63, 77], [0, -530, -131, -131, 69, 201, 0, 0], [1374, 0, 306, -306, 0, 0, -38, -72], [0, 330, -238, -238, -50, 536, 0, 0], [6038, 0, -110, 110, 0, 0, 75, -38], [-4428, 0, -185, 185, 0, 0, -17, 97], [0, -240, 84, 84, 75, 208, 0, 0], [0, 116, -274, -274, 138, -18, 0, 0], [-1192, 0, -43, 43, 0, 0, 8, -74], [0, -465, 27, 27, 138, -505, 0, 0], [816, 0, 444, -444, 0, 0, -51, 60], [3414, 0, -70, 70, 0, 0, -42, -34], [0, 388, 52, 52, -48, -79, 0, 0], [0, -214, -161, -161, 162, 216, 0, 0], [-3840, 0, 138, -138, 0, 0, -2, -108], [6214, 0, -322, 322, 0, 0, 53, -94], [0, -68, -331, -331, -84, -240, 0, 0], [0, 493, -185, -185, 102, 91, 0, 0], [0, 207, -183, -183, 150, 246, 0, 0], [-7226, 0, -448, 448, 0, 0, 45, 104], [0, -340, -232, -232, -144, 375, 0, 0], [0, 446, 62, 62, 12, -545, 0, 0], [-6312, 0, 152, -152, 0, 0, 10, -138], [3448, 0, 99, -99, 0, 0, 105, -87], [0, -323, 21, 21, -186, -48, 0, 0], [6526, 0, 56, -56, 0, 0, 66, -13], [-5238, 0, 240, -240, 0, 0, -83, -108], [-4892, 0, 230, -230, 0, 0, 19, 74], [0, -183, 73, 73, 30, 612, 0, 0], [0, 584, 42, 42, 350, 742, 0, 0], [488, 0, 370, -370, 0, 0, -86, 118], [0, 50, -238, -238, 0, -47, 0, 0], [0, -330, 474, 474, 141, -212, 0, 0], [0, 14, -34, -34, -258, -330, 0, 0], [5672, 0, -157, 157, 0, 0, -96, 172], [-558, 0, -586, 586, 0, 0, 34, 74], [8218, 0, -514, 514, 0, 0, -92, 14], [4568, 0, -180, 180, 0, 0, 126, 64], [0, 126, -233, -233, -162, -1056, 0, 0], [-12642, 0, 312, -312, 0, 0, 6, 30], [8268, 0, -23, 23, 0, 0, -94, -153], [2860, 0, -460, 460, 0, 0, -118, 110], [-17858, 0, -70, 70, 0, 0, 22, 89], [0, 1115, -439, -439, -48, 233, 0, 0], [0, -800, 195, 195, -221, -361, 0, 0], [-5100, 0, 325, -325, 0, 0, -179, -17], [0, 572, 986, 986, 126, -845, 0, 0], [0, -637, -541, -541, -126, 467, 0, 0], [-9076, 0, -288, 288, 0, 0, -92, -2], [3782, 0, -320, 320, 0, 0, -102, -83], [9826, 0, -284, 284, 0, 0, -38, 262], [10790, 0, -242, 242, 0, 0, -163, -182], [-12116, 0, -356, 356, 0, 0, -152, 125], [0, -16, -409, -409, -153, 537, 0, 0], [0, 31, 61, 61, 30, -1128, 0, 0], [0, 1408, 142, 142, -123, -1210, 0, 0], [0, 720, -127, -127, -252, -756, 0, 0], [-1586, 0, -848, 848, 0, 0, 36, -122], [0, 322, -38, -38, 396, 1161, 0, 0], [0, -830, -892, -892, -100, 952, 0, 0], [0, -440, 592, 592, 456, -215, 0, 0], [-8972, 0, 592, -592, 0, 0, -32, 86], [0, -1316, -638, -638, -6, 763, 0, 0], [-8732, 0, -310, 310, 0, 0, 99, -58], [7316, 0, -420, 420, 0, 0, 44, 34], [-2106, 0, -102, 102, 0, 0, 202, -273], [0, 472, -265, -265, 198, -120, 0, 0], [0, 1433, -445, -445, -258, 1153, 0, 0], [0, -1028, -403, -403, 425, -1085, 0, 0], [-9288, 0, 198, -198, 0, 0, 120, -312], [0, -476, -219, -219, -599, 29, 0, 0], [0, -922, 590, 590, 216, -1411, 0, 0], [-12008, 0, -537, 537, 0, 0, 100, -103], [0, -1488, 270, 270, 417, -1854, 0, 0], [-5114, 0, -50, 50, 0, 0, -188, 22], [0, 438, 102, 102, 528, -469, 0, 0], [0, -1451, -751, -751, 150, 1386, 0, 0], [21216, 0, -162, 162, 0, 0, 32, 354], [0, -589, 61, 61, -330, 750, 0, 0], [0, 348, -966, -966, 81, 420, 0, 0], [0, 810, -723, -723, 492, 216, 0, 0], [0, 1894, -428, -428, 342, 855, 0, 0], [0, -186, 1108, 1108, 344, -800, 0, 0], [0, -1948, -790, -790, 114, 391, 0, 0], [0, -2583, -405, -405, -222, -227, 0, 0], [14902, 0, -130, 130, 0, 0, -30, 68], [0, -1036, 171, 171, -126, -1212, 0, 0], [-7272, 0, 324, -324, 0, 0, -54, -486], [-4016, 0, -316, 316, 0, 0, -43, -52], [-2812, 0, 58, -58, 0, 0, 134, -254], [0, 578, -171, -171, 528, 1956, 0, 0], [0, -1992, 81, 81, -771, -1131, 0, 0]]
