
# q-expansion of newform 336.4.q.m, 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 = 336
weight = 4
poly_data = [746496, 0, 168048, 0, 9457, 0, 173, 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], [[-673920, 869616, 0, 67439, 0, 691, 0, -1], 1347840], [[-208224, 0, -31781, 0, 911, 0, 19, 0], 42120], [[109164672, -19439568, 8185728, 233803, 143232, 29087, 768, 283], 4043520], [[104194944, 14802480, 3526576, 892215, -149776, 19035, -2384, 135], 1347840], [[-9334656, -2960496, -1680944, -178443, -62320, -3807, -560, -27], 269568], [[-624672, 1055052, -95343, 181903, 2733, 5387, 57, 43], 252720], [[-12451968, 78636528, -7751472, 5991727, -417648, 147443, -4272, 1087], 2021760]]

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, -1, 0, 0, 0, 0, 0, 0]]]
aps_data = [[0, 0, 0, 0, 0, 0, 0, 0], [0, -3, 0, 0, 0, 0, 0, 0], [-1, -1, 0, 0, 0, 0, 1, 0], [-2, 0, 0, 0, 0, -1, 0, 0], [-1, -4, -2, -1, 1, 1, 2, -1], [6, 0, -4, 0, -1, -1, 0, 0], [-1, 26, 2, 3, 1, 0, -3, -2], [-5, -5, 1, -1, 1, -3, -4, 0], [26, 26, 1, 0, 1, -3, 2, 1], [-16, 4, 6, 3, -2, -7, -1, -1], [-5, -62, 7, -5, 5, 5, -7, -5], [-143, -143, -2, 3, -2, 6, -12, 1], [110, 8, -14, 6, 2, -8, -2, -2], [71, 12, -15, 9, -1, -16, -3, -3], [-24, -24, -1, -4, -1, 3, 26, -5], [-4, -7, -9, -12, 4, 6, 11, -2], [8, -54, -6, 20, -8, -11, 3, 5], [68, 68, -2, 6, -2, 6, 38, 4], [-2, -21, -12, 26, 2, -5, 5, -9], [209, -4, -31, -3, 2, 7, 1, 1], [1, -49, 2, 9, -1, -3, -4, -1], [444, 444, 4, -9, 4, -12, -29, -5], [-864, -4, -27, -3, -1, 4, 1, 1], [94, 94, 8, -16, 8, -24, -42, -8], [-159, -16, 90, -12, -9, 11, 4, 4], [4, -484, 22, -36, -4, 6, -12, 14], [-611, -611, 7, -7, 7, -21, 18, 0], [798, 798, -3, 3, -3, 9, 18, 0], [13, 519, 10, 21, -13, -15, -12, 11], [771, -4, 47, -3, 22, 27, 1, 1], [-91, -16, -25, -12, 27, 47, 4, 4], [-744, -744, 10, 13, 10, -30, 54, 23], [-18, 1246, -122, -58, 18, 28, 132, -8], [-985, -36, -37, -27, -15, 30, 9, 9], [-714, -714, -6, 24, -6, 18, -14, 18], [17, -365, -11, -83, -17, 8, 36, 42], [-18, -1778, 68, 14, 18, 10, -76, -26], [1350, 1350, -12, 46, -12, 36, 74, 34], [-1693, -44, 93, -33, 20, 75, 11, 11], [-794, -794, -1, 22, -1, 3, 94, 21], [-19, -930, -8, -71, 19, 32, 21, -6], [-786, 16, -158, 12, 1, -19, -4, -4], [-26, -26, 39, -20, 39, -117, 48, 19], [8, 1763, 88, -32, -8, 2, -78, 18], [1325, -52, 121, -39, -20, 45, 13, 13], [2, 1728, -8, 26, -2, -8, 2, -4], [-118, -32, -104, -24, -86, -46, 8, 8], [278, -36, 144, -27, -2, 43, 9, 9], [27, -12, -182, 163, -27, -61, 148, -7], [97, 97, 28, -97, 28, -84, -34, -69], [-1900, -1900, 21, -42, 21, -63, -86, -21], [1238, 104, 140, 78, 36, -94, -26, -26], [17, -2416, -70, -23, -17, -7, 80, 27], [-3276, 108, 61, 81, 21, -114, -27, -27], [-3312, -3312, 41, -44, 41, -123, -110, -3], [-16, 294, -186, -16, 16, 16, 186, -16], [-19, 923, -269, 161, 19, -26, 224, -64], [-4515, -4515, 27, 0, 27, -81, 25, 27], [-105, 823, 30, -33, 105, 87, -48, -123], [2377, 60, -87, 45, -4, -79, -15, -15], [78, -2329, 170, 138, -78, -93, -185, 63], [1932, -108, -90, -81, -90, 45, 27, 27], [1489, -20, -121, -15, -59, -34, 5, 5], [-38, 390, 348, 90, 38, 6, -380, -70], [-67, -67, 0, 82, 0, 0, -212, 82], [2115, 2115, -21, -12, -21, 63, -129, -33], [2255, 2255, 57, -81, 57, -171, 222, -24], [1791, -72, -570, -54, -124, -34, 18, 18], [151, 4648, -244, 339, -151, -198, 197, 104], [-6908, 72, -86, 54, 80, -10, -18, -18], [-35, 2938, 68, 137, 35, -8, -111, -78], [-2424, -2424, 18, 78, 18, -54, 84, 96], [27, -978, 145, -157, -27, 19, -99, 73], [1319, 1319, -12, 141, -12, 36, 94, 129], [1745, 108, 13, 81, 119, -16, -27, -27], [-2912, -2912, -67, 108, -67, 201, -220, 41], [143, 2228, 74, 179, -143, -152, -83, 134], [-1581, -1581, 32, -179, 32, -96, 290, -147], [3180, 3180, 15, 30, 15, -45, 240, 45], [-162, -2423, -4, -162, 162, 162, 4, -162], [-1022, -168, -62, -126, -194, 16, 42, 42], [3178, -472, -2, -354, -75, 515, 118, 118], [-117, 990, -252, -113, 117, 116, 251, -118], [-7448, -480, -306, -360, -63, 537, 120, 120], [-5663, -5663, -1, 12, -1, 3, 557, 11], [-3954, -3954, -63, 217, -63, 189, 670, 154], [2297, 260, -373, 195, 96, -229, -65, -65], [535, 535, 28, 130, 28, -84, -596, 158], [-4068, -248, -652, -186, 132, 442, 62, 62], [-4085, 84, 219, 63, -21, -126, -21, -21], [-2090, -2090, -35, 180, -35, 105, 180, 145], [155, 4070, -54, 615, -155, -270, -61, 40], [185, 12174, -295, 393, -185, -237, 243, 133], [5837, 128, -338, 96, -47, -207, -32, -32], [-2429, -2429, 25, 1, 25, -75, -448, 26], [3594, -344, 460, -258, -128, 302, 86, 86], [-8695, -8695, 86, 36, 86, -258, -249, 122], [152, 1584, 444, 320, -152, -194, -486, 110], [-91, -91, 65, -155, 65, -195, -1124, -90], [6811, 6811, 24, -253, 24, -72, -856, -229], [-398, -472, 164, -354, 14, 604, 118, 118], [61, -1455, -755, 929, -61, -278, 538, -156], [214, -1960, -450, 130, -214, -193, 471, 235], [2504, 2504, 180, -232, 180, -540, 134, -52], [-122, 7967, -694, -638, 122, 251, 823, 7], [84, -9549, -804, 436, -84, -172, 716, -4], [45, 88, -336, 66, 327, 217, -22, -22], [-5368, -5368, -112, 44, -112, 336, -1206, -68], [150, -7676, -128, 518, -150, -242, 36, 58], [-11113, -144, 184, -108, -192, -12, 36, 36], [2138, 2138, -138, 239, -138, 414, 529, 101], [-16, -16752, -542, 224, 16, -44, 482, -76], [3778, 800, 432, 600, 280, -720, -200, -200], [-98, -4171, 658, -590, 98, 221, -535, 25], [-8536, 436, 598, 327, 106, -439, -109, -109], [291, 112, 180, 311, -291, -296, -185, 286], [4639, 172, -1153, 129, 181, -34, -43, -43], [-90, 9636, 846, -218, 90, 122, -814, -58], [13223, 13223, 35, -110, 35, -105, 1253, -75], [10021, 212, -363, 159, 92, -173, -53, -53], [-69, 2903, -408, 555, 69, -87, 252, -225], [-2677, -152, 1502, -114, 146, 336, 38, 38], [-13455, -13455, -189, 332, -189, 567, -1527, 143], [-434, -10690, 430, -1462, 434, 691, -173, -177], [10655, 10655, 17, 291, 17, -51, -614, 308], [-947, -328, 111, -246, -322, 88, 82, 82], [-174, -174, 120, -32, 120, -360, -104, 88], [-10218, -10218, 154, -320, 154, -462, 20, -166], [4397, -776, -777, -582, -339, 631, 194, 194], [8511, 8511, 262, -377, 262, -786, -1296, -115], [292, -4999, -1044, 352, -292, -307, 1029, 277], [1958, 240, 820, 180, 168, -132, -60, -60], [9500, 9500, -148, 113, -148, 444, -431, -35], [-8108, 728, -392, 546, -330, -1240, -182, -182], [-5762, -5762, 305, -152, 305, -915, 662, 153], [4659, 264, -506, 198, 122, -208, -66, -66], [66, 21972, -254, 466, -66, -166, 154, -34], [496, -184, -1920, 1032, -496, -630, 1786, 362], [3291, -152, 881, -114, 210, 400, 38, 38], [-367, -2606, 632, -787, 367, 472, -527, -262], [-7414, 688, -794, 516, 84, -776, -172, -172], [18509, 18509, -48, 588, -48, 144, -853, 540], [-120, 1752, 1288, 744, 120, -96, -1504, -336], [12138, -892, -405, -669, -361, 754, 223, 223], [-329, -991, 336, -473, 329, 365, -300, -293], [-9862, -376, -356, -282, 262, 732, 94, 94], [6064, -1472, -354, -1104, 73, 1913, 368, 368], [-346, 6764, -164, -906, 346, 486, 304, -206], [-876, -876, 2, 262, 2, -6, 612, 264], [20710, 20710, 112, -300, 112, -336, -2048, -188], [1658, 1658, 70, -398, 70, -210, 1284, -328], [28719, -636, -301, -477, -180, 615, 159, 159], [-19607, 492, 501, 369, -161, -776, -123, -123], [3448, 3448, -186, 728, -186, 558, -434, 542], [-214, -10853, -2388, 110, 214, 133, 2307, -295], [-2797, 324, 1195, 243, 112, -293, -81, -81], [11119, 11119, 271, -441, 271, -813, 2330, -170], [7050, 7050, 97, -390, 97, -291, 2160, -293], [33303, 1040, -1108, 780, 124, -1176, -260, -260], [60, 1587, -171, -1596, -60, 354, 585, 474], [14494, 14494, -152, 394, -152, 456, -1468, 242], [14741, 924, -2089, 693, 142, -1013, -231, -231], [-2145, 112, -855, 84, 61, -79, -28, -28], [-22690, -22690, 325, 175, 325, -975, -210, 500], [228, 6346, 356, -108, -228, -144, -272, 312], [-27, 9000, 1704, -1863, 27, 486, -1245, 432], [-349, -15046, 103, -1517, 349, 641, 189, -57], [495, 1753, -1302, 1095, -495, -645, 1152, 345]]
