
# q-expansion of newform 378.4.g.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 = 378
weight = 4
poly_data = [100, 40, 186, -48, 283, 9, 18, -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, 0, 0, 0, 0, 0, 0], 1], [[2144550, -811706, 3812253, -1314483, 165901, -103443, 17661, -5251], 2252390], [[5541150, -43821428, 9850209, -3396399, 771473, -267279, 45633, -5533], 2252390], [[20095080, -24618118, -26303561, 3388681, -1182462, 400691, -123347, 25642], 2252390], [[-13301880, -34372646, 38379473, -7552513, 2393606, -728363, 179291, -26206], 2252390], [[5873470, 3795232, 3475204, 4902586, 417823, 296256, -3492, 16807], 321770], [[5545466, -7027748, 6404040, -11885520, -84149, -783152, 56798, -42509], 450478], [[-3549092, -394100, -636190, -13230433, -661525, -821980, 35959, -47855], 450478]]

hecke_ring_character_values = [[29, [1, 0, 0, 0, 0, 0, 0, 0]], [325, [0, -1, 0, 0, 0, 0, 0, 0]]]
aps_data = [[0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, -1, -1, 0, 0, 0, 0, 0], [2, -2, 0, 0, -1, 0, 0, 0], [8, -8, 0, 0, 0, -1, 1, 0], [0, 1, 0, -1, -2, -1, 2, 2], [-14, 15, 3, -2, 2, 0, 2, 3], [-3, 20, 2, -1, 2, 3, 3, 0], [0, 23, 3, -1, -1, 0, 0, 0], [-28, -2, 0, -6, -4, -6, 4, -5], [-19, 13, -6, 0, 0, -5, 5, -6], [-5, -29, 10, 6, 11, 5, 5, 0], [-92, -10, 0, -6, 4, -6, -4, 1], [105, 0, 0, -2, -2, -2, 2, -10], [-10, -77, -11, -16, -6, 10, 10, 0], [-36, 9, -7, -20, 20, 11, 9, -7], [32, -42, -6, -4, 4, 9, -5, -6], [4, -101, -16, -7, -11, -4, -4, 0], [-231, 246, 8, 7, -7, 1, -8, 8], [-184, 2, 0, -17, -19, -17, 19, -26], [-32, -5, -52, 15, -15, -15, 0, -52], [9, -29, 64, 2, -7, -9, -9, 0], [-376, 10, 0, -24, -34, -24, 34, 42], [-4, -329, 67, 20, 24, 4, 4, 0], [-501, -10, 0, 24, 34, 24, -34, 74], [66, -128, -40, -22, 22, -11, 33, -40], [-7, -669, 30, 34, 41, 7, 7, 0], [10, 790, -72, 8, -2, -10, -10, 0], [-407, 475, 48, 20, -20, -41, 21, 48], [-848, -26, 0, 23, 49, 23, -49, 68], [37, 6, 0, -25, -31, -25, 31, -12], [66, -651, 43, 29, -37, -66, -66, 0], [972, -953, -1, 20, -20, -65, 45, -1], [-454, 43, 0, -14, -57, -14, 57, 8], [100, 595, 3, 62, -38, -100, -100, 0], [-1209, 1089, -102, -18, 18, -19, 37, -102], [706, -622, 18, 66, -66, -60, -6, 18], [-36, -409, -184, -46, -10, 36, 36, 0], [1304, -6, 0, 104, 110, 104, -110, -18], [-58, 415, 17, 1, 59, 58, 58, 0], [-244, 281, -39, 76, -76, -68, -8, -39], [-527, -9, 0, -22, -13, -22, 13, -222], [-60, 677, -11, 64, 124, 60, 60, 0], [-781, 912, 44, 87, -87, -59, -28, 44], [-1928, 36, 0, 40, 4, 40, -4, -120], [-587, 527, 92, -152, 152, 71, 81, 92], [2211, -54, 0, -20, 34, -20, -34, 50], [-1534, 50, 0, -40, -90, -40, 90, 86], [2820, -2727, 109, -16, 16, -59, 75, 109], [122, -3417, -70, 83, -39, -122, -122, 0], [-50, 3147, 45, -95, -45, 50, 50, 0], [-3240, -20, 0, 118, 138, 118, -138, -77], [1335, -947, 310, 78, -78, -4, -74, 310], [2796, 4, 0, -167, -171, -167, 171, -11], [58, -1888, 146, -50, -108, -58, -58, 0], [740, -940, -32, -168, 168, 131, 37, -32], [4660, -4966, -222, -84, 84, 130, -46, -222], [60, -1829, 64, -181, -241, -60, -60, 0], [-1003, 843, -264, 104, -104, 5, -109, -264], [-4152, -34, 0, -133, -99, -133, 99, -144], [-2465, 2587, 106, 16, -16, 44, -60, 106], [3680, -48, 0, -121, -73, -121, 73, 142], [-3427, -230, 0, -290, -60, -290, 60, -112], [1906, -1840, 288, -222, 222, 25, 197, 288], [-35, 1930, -150, 85, 120, 35, 35, 0], [-4, 344, 0, -167, -163, 4, 4, 0], [13, 674, 288, -205, -218, -13, -13, 0], [2977, -9, 0, 206, 215, 206, -215, 18], [364, -596, -152, -80, 80, -6, 86, -152], [-2517, -26, 0, 77, 103, 77, -103, 166], [4908, -5214, -342, 36, -36, 0, -36, -342], [14, 6490, 80, 64, 50, -14, -14, 0], [2, -243, -56, -185, 185, 57, 128, -56], [169, 4098, 214, 329, 160, -169, -169, 0], [-2758, -207, 0, -276, -69, -276, 69, -92], [-314, -1534, 340, -214, 100, 314, 314, 0], [4226, -3465, 647, 114, -114, 29, -143, 647], [-60, 311, -120, -83, -23, 60, 60, 0], [-324, 3356, 340, -185, 139, 324, 324, 0], [-6139, 6120, -140, 121, -121, -21, -100, -140], [4300, -4, 0, -90, -86, -90, 86, -569], [-7649, -31, 0, 4, 35, 4, -35, -256], [-1812, 1902, 34, 56, -56, 79, -135, 34], [-195, 162, 0, 148, -14, 148, 14, 218], [-30, 6738, 2, -288, -258, 30, 30, 0], [298, 1337, -521, 71, -227, -298, -298, 0], [-2968, 56, 0, 274, 218, 274, -218, -97], [206, 1533, -58, 56, -150, -206, -206, 0], [460, 56, 0, 381, 325, 381, -325, 42], [2337, 309, 0, -176, -485, -176, 485, -372], [262, -4150, -396, 141, -121, -262, -262, 0], [3580, -3099, 337, 144, -144, 340, -484, 337], [3890, -4359, -366, -103, 103, 113, -10, -366], [-9600, 286, 0, -140, -426, -140, 426, 430], [38, 7055, 408, 48, 10, -38, -38, 0], [-4916, 84, 0, 307, 223, 307, -223, -667], [82, -6058, -76, 526, 444, -82, -82, 0], [12462, -12444, 132, -114, 114, -234, 348, 132], [-121, 3903, 90, 193, 314, 121, 121, 0], [209, 8516, 500, 307, 98, -209, -209, 0], [-9495, -372, 0, 28, 400, 28, -400, 52], [1740, -1427, -67, 380, -380, 82, -462, -67], [-6732, 7973, 821, 420, -420, -501, 81, 821], [482, 5840, 690, 697, 215, -482, -482, 0], [9418, -9357, 404, -343, 343, 73, 270, 404], [-1353, 1944, 440, 151, -151, -311, 160, 440], [4180, -116, 0, -94, 22, -94, -22, 121], [190, 3046, 144, 77, -113, -190, -190, 0], [10814, -11485, -725, 54, -54, -313, 259, -725], [-7235, 254, 0, 226, -28, 226, 28, -1170], [-321, -6880, -378, 43, 364, 321, 321, 0], [5563, -5355, -24, 232, -232, -403, 171, -24], [-7248, 128, 0, 461, 333, 461, -333, 330], [-1695, 2010, 56, 259, -259, 355, -614, 56], [-1911, 264, 0, -431, -695, -431, 695, 476], [110, 175, 751, -466, 466, -12, 478, 751], [-3025, 270, 0, 144, -126, 144, 126, -552], [17496, -16896, 324, 276, -276, 306, -582, 324], [-308, -5715, 949, -285, 23, 308, 308, 0], [-8744, -372, 0, 196, 568, 196, -568, 117], [-9948, 10401, 430, 23, -23, 597, -620, 430], [-4767, 671, 0, 84, -587, 84, 587, -212], [184, -2444, -168, -40, -224, -184, -184, 0], [-4194, 3672, 80, -602, 602, 305, 297, 80], [-80, 13979, -654, -328, -248, 80, 80, 0], [7844, 450, 0, 71, -379, 71, 379, -915], [-552, 8657, -1180, 23, 575, 552, 552, 0], [-170, 8580, 766, -321, -151, 170, 170, 0], [-14437, 82, 0, 307, 225, 307, -225, -1384], [-52, -14131, -424, 415, 467, 52, 52, 0], [8883, -9889, -1256, 250, -250, -188, -62, -1256], [-1084, -82, 0, -746, -664, -746, 664, 975], [-677, 12314, -32, -449, 228, 677, 677, 0], [-12453, -88, 0, 645, 733, 645, -733, 156], [-424, -3416, 888, -732, -308, 424, 424, 0], [-4851, -501, 0, -254, 247, -254, -247, -108], [18970, -19021, -89, 38, -38, -337, 299, -89], [-11927, 12819, 1080, -188, 188, -436, 624, 1080], [12540, -692, 0, -497, 195, -497, -195, 520], [-6914, 7718, 554, 250, -250, -498, 248, 554], [770, -622, 0, 482, 1104, 482, -1104, -330], [-894, -9266, -1160, -408, 486, 894, 894, 0], [711, -1743, -888, -144, 144, -493, 637, -888], [23308, -444, 0, 562, 1006, 562, -1006, -754], [-2928, 3051, 162, -39, 39, 545, -506, 162], [8692, 38, 0, 30, -8, 30, 8, 1166], [-17503, 319, 0, -524, -843, -524, 843, 28], [-16494, 15330, -550, -614, 614, -121, 735, -550], [-368, -997, 432, -1252, -884, 368, 368, 0], [442, -663, -1573, 539, 97, -442, -442, 0], [838, 14277, -254, 95, -743, -838, -838, 0], [-20968, 772, 0, -141, -913, -141, 913, 1055], [2223, -405, 0, 628, 1033, 628, -1033, 38], [1474, -1398, -332, 858, -616, -1474, -1474, 0], [7741, -5526, 1326, 889, -889, 389, -1278, 1326], [8580, 290, 0, -1276, -1566, -1276, 1566, -115], [488, 2645, 1506, 867, 379, -488, -488, 0], [60, 6757, 1889, 188, 128, -60, -60, 0], [9200, -439, 0, 74, 513, 74, -513, 284], [-25388, 26846, 550, 908, -908, -529, -379, 550], [34, -11147, 1531, 304, 270, -34, -34, 0], [31304, -656, 0, -897, -241, -897, 241, 639], [8698, 43, 0, -111, -154, -111, 154, -610], [-582, 16075, 77, 875, 1457, 582, 582, 0], [4438, -4388, -220, 270, -270, 1924, -2194, -220], [-26646, 28494, 1498, 350, -350, -569, 219, 1498], [-16439, 18056, 1714, -97, 97, 466, -369, 1714], [12495, -14027, -784, -748, 748, 1125, -377, -784]]
