
# q-expansion of newform 147.5.b.f, downloaded from the LMFDB on 03 May 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 = 147
weight = 5
poly_data = [75096, 0, 38724, 0, 3382, 0, 103, 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, 1, 0, 0, 0, 0, 0, 0], 1], [[13440, -6132, 6552, 812, 332, 69, 4, 1], 1344], [[48384, -6132, 7896, 812, 332, 69, 4, 1], 1344], [[17220, 756, 9660, -4088, 539, -235, 7, -3], 672], [[13440, -63756, 6552, -15260, 332, -733, 4, -9], 1344], [[-44352, -6132, -13776, 812, -664, 69, -8, 1], 672], [[-83664, -6132, -45192, 812, -2488, 69, -32, 1], 1344]]

hecke_ring_character_values = [[50, [-1, 0, 0, 0, 0, 0, 0, 0]], [52, [1, 0, 0, 0, 0, 0, 0, 0]]]
aps_data = [[0, 1, 0, 0, 0, 0, 0, 0], [1, 0, -1, 0, 0, 0, 0, 0], [0, 0, -1, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [1, -6, 1, -1, 2, -3, -1, 1], [32, 0, -4, 3, 0, 0, -2, 5], [-3, -22, -13, -4, -6, -2, -4, -3], [-166, 0, -13, 10, 0, 0, -1, 5], [4, 42, -33, -13, 8, -2, -13, 4], [1, -58, 0, -2, 2, -5, -2, 1], [-294, 0, 16, -23, 0, 0, -13, 33], [-189, 0, 23, 9, 0, 0, 4, -40], [-2, -220, 78, 26, -4, -2, 26, -2], [50, 0, -72, 77, 0, 0, 26, -57], [-26, -46, -25, -7, -52, -22, -7, -26], [18, -236, -35, 6, 36, 71, 6, 18], [5, -584, -83, -13, 10, 49, -13, 5], [1895, 0, -175, -32, 0, 0, 124, -41], [-920, 0, 79, -202, 0, 0, -67, 257], [66, -90, 300, 98, 132, 60, 98, 66], [1545, 0, 103, -163, 0, 0, 88, -116], [5084, 0, -246, 107, 0, 0, -27, 193], [49, 112, 22, -62, 98, -159, -62, 49], [-23, -416, 75, 108, -46, 226, 108, -23], [1782, 0, -305, 185, 0, 0, -2, 124], [39, 468, -233, -70, 78, 62, -70, 39], [1240, 0, -477, 752, 0, 0, -45, -185], [-67, -1300, 219, 171, -134, 227, 171, -67], [-3225, 0, 341, 99, 0, 0, -50, -340], [-162, 1906, 290, 152, -324, 4, 152, -162], [5886, 0, -349, -14, 0, 0, 386, -409], [87, -2274, 311, -37, 174, -335, -37, 87], [11, -1524, -795, -222, 22, 140, -222, 11], [654, 0, -1490, 997, 0, 0, 402, -311], [31, -3036, -657, -278, 62, -146, -278, 31], [-12508, 0, -1488, 8, 0, 0, 865, -250], [-15289, 0, 455, -478, 0, 0, 104, -185], [-2198, 0, -173, 1087, 0, 0, -507, 100], [150, -2890, 1522, 438, 300, -58, 438, 150], [285, -1102, 1323, 250, 570, -288, 250, 285], [-374, 898, -321, 21, -748, 10, 21, -374], [3224, 0, 1130, -1943, 0, 0, 404, 5], [112, 2794, 1805, 167, 224, -1192, 167, 112], [5915, 0, 1506, 750, 0, 0, -362, -1532], [134, -198, -842, 24, 268, 1048, 24, 134], [14844, 0, 1711, -1899, 0, 0, 191, -194], [-4412, 0, -1268, 2478, 0, 0, 146, -1502], [-47296, 0, -937, 1767, 0, 0, 178, -1186], [217, -6426, 1419, 673, 434, 817, 673, 217], [-34271, 0, -519, -977, 0, 0, -178, 1852], [-387, 2798, 1031, 664, -774, 574, 664, -387], [-560, -1568, 10, -256, -1120, -1338, -256, -560], [-47885, 0, -3270, 607, 0, 0, 320, 2023], [-275, -7416, -2716, -570, -550, 731, -570, -275], [-1127, -4746, 313, 608, -2254, 384, 608, -1127], [-74, -13128, 3121, 1155, -148, 270, 1155, -74], [-348, -3742, 3335, 912, -696, -947, 912, -348], [-21178, 0, -1108, -186, 0, 0, 1627, -1960], [9943, 0, 4543, 141, 0, 0, -4472, 4260], [408, 7766, -3302, -772, 816, 1394, -772, 408], [-58942, 0, -1297, 3470, 0, 0, 179, -2531], [553, -13342, -966, -308, 1106, 595, -308, 553], [6170, 0, 2822, -3007, 0, 0, -1698, 3581], [-388, -260, -881, 241, -776, 1216, 241, -388], [973, 0, 690, 2810, 0, 0, -2756, 2012], [662, 5194, -4877, -1448, 1324, 1195, -1448, 662], [35660, 0, 2799, -6326, 0, 0, 533, 2461], [3544, 0, 6223, -1946, 0, 0, -4410, 4543], [1880, 17306, 6349, 769, 3760, -2162, 769, 1880], [-18898, 0, 3128, 1620, 0, 0, 778, -6304], [1421, 12726, 767, -1344, 2842, -3378, -1344, 1421], [-212, -14128, -7463, -3091, -424, -2022, -3091, -212], [-8448, 0, -4238, -3635, 0, 0, 1711, 4451], [3623, 0, 2061, 3047, 0, 0, -1388, -2332], [-102744, 0, 1568, 1267, 0, 0, 2198, -7231], [-742, -3234, -10401, -2399, -1484, 2462, -2399, -742], [-1615, -16038, -12171, -3376, -3230, 428, -3376, -1615], [31737, 0, -14873, 5449, 0, 0, 7518, -5612], [-1007, -15534, -6609, -1200, -2014, 2002, -1200, -1007], [-99023, 0, 3024, -3180, 0, 0, -1198, 2552], [-1342, -15880, -1840, -444, -2684, -834, -444, -1342], [16184, 0, 7416, 1897, 0, 0, -2090, -5133], [-1470, 18994, 7627, 3581, -2940, 1646, 3581, -1470], [-72952, 0, -7624, 12743, 0, 0, -2358, -403], [64920, 0, 11068, -4624, 0, 0, -8037, 9630], [-415, 31120, 10147, 4019, -830, 1495, 4019, -415], [-78, -24666, -13434, -5004, -156, -1656, -5004, -78], [45739, 0, -10454, 1234, 0, 0, 2008, 5204], [2226, 23800, -11506, -4170, 4452, 1222, -4170, 2226], [144634, 0, -14102, 6419, 0, 0, 2698, 2287], [-1980, 23602, 169, -959, -3960, -5026, -959, -1980], [-3954, 12234, 6847, 3159, -7908, -1324, 3159, -3954], [-20576, 0, -17036, 12965, 0, 0, 745, 2581], [-301, -19586, 14028, 5236, -602, 1379, 5236, -301], [14404, 0, -9263, -3288, 0, 0, 5593, 1365], [-2736, -7716, 4008, 2760, -5472, 1536, 2760, -2736], [3778, -6240, 15079, 4864, 7556, 3291, 4864, 3778], [-3927, -6496, -19063, -2848, -7854, 6592, -2848, -3927], [112790, 0, -4471, 1424, 0, 0, -6321, 15689], [293363, 0, 13365, -3729, 0, 0, -1914, -5808], [-39686, 0, -13184, -3080, 0, 0, 7242, 1780], [692, 33178, -4753, -3162, 1384, -4041, -3162, 692], [1179, -19340, -2883, -4433, 2358, -9237, -4433, 1179], [301, 34420, -15151, -7192, 602, -6124, -7192, 301], [-45766, 0, -3093, 11180, 0, 0, -411, -7265], [-58855, 0, 15572, 6732, 0, 0, -7004, -8296], [2699, 26830, 20082, 7460, 5398, 4997, 7460, 2699], [-723, 11680, 17293, 5202, -1446, -2410, 5202, -723], [694, 10760, 13973, -729, 1388, -15466, -729, 694], [136740, 0, -13469, -2972, 0, 0, 7386, 1669], [-104918, 0, 18984, -16111, 0, 0, -4545, 6217], [-9395, 0, -1583, -2274, 0, 0, -3010, 9877], [1486, -39512, 8314, -118, 2972, -7182, -118, 1486], [206072, 0, -6181, 8888, 0, 0, 6187, -15081], [-294220, 0, -33393, -5537, 0, 0, 13486, 11958], [353, -23418, -18429, -5478, 706, 2348, -5478, 353], [-143126, 0, -8868, 17419, 0, 0, 6142, -20835], [3728, 56468, 1851, -2935, 7456, -6928, -2935, 3728], [946, -6630, 22995, 4688, 1892, -7985, 4688, 946], [4418, -13246, -7564, -2554, 8836, 4320, -2554, 4418], [-296971, 0, 17405, -5805, 0, 0, 240, -12080], [168640, 0, 15619, -14574, 0, 0, -8398, 15751], [-2900, 52910, 9119, 10, -5800, -11989, 10, -2900], [3657, 8572, 10045, 6273, 7314, 12431, 6273, 3657], [207316, 0, 2931, 15452, 0, 0, -3077, -12229], [1473, 87312, 11622, 6982, 2946, 10797, 6982, 1473], [-143127, 0, -6133, 20316, 0, 0, -8896, 3609], [3624, 20248, -10235, -6569, 7248, -5848, -6569, 3624], [118462, 0, 15747, -27108, 0, 0, -162, 11685], [-725391, 0, -11291, -10497, 0, 0, 6144, 9500], [180162, 0, -31213, 15604, 0, 0, 617, 14375], [2752, -5000, 45628, 12516, 5504, -5328, 12516, 2752], [-65594, 0, -15140, 7555, 0, 0, 12533, -17481], [142898, 0, 15438, -15106, 0, 0, 7934, -16200], [-8875, -60846, -6327, 4620, -17750, 11312, 4620, -8875], [-477608, 0, 10317, -10994, 0, 0, 6238, -11799], [-493, 64112, -13725, -7262, -986, -8554, -7262, -493], [275222, 0, 6077, -2879, 0, 0, -11165, 19132], [-2961, 32984, 5872, -4096, -5922, -21121, -4096, -2961], [1587, -19922, -14213, -3226, 3174, 6122, -3226, 1587], [236524, 0, 8166, 16320, 0, 0, -5454, -13578], [-6588, 4000, 30261, 10544, -13176, -5217, 10544, -6588], [314466, 0, 15971, -56433, 0, 0, 13613, 13236], [-7659, -9000, -43122, -2338, -15318, 28449, -2338, -7659], [395401, 0, 10899, -7667, 0, 0, -9542, 15852], [-556, -118028, -37812, -15756, -1112, -10012, -15756, -556], [-130760, 0, 18342, -7599, 0, 0, -11658, 12573], [-6649, -49548, -12679, 1560, -13298, 10710, 1560, -6649], [-156884, 0, 31665, -22453, 0, 0, 12063, -33338], [4764, -71932, -9769, 2305, 9528, 21448, 2305, 4764], [-496367, 0, 13987, -25128, 0, 0, -5450, 22041], [-1404, 37458, 27084, 15850, -2808, 19062, 15850, -1404], [-287122, 0, 14466, 10031, 0, 0, -11266, -1965], [1654, 80664, -15377, 2155, 3308, 23496, 2155, 1654], [-78328, 0, 6081, 23332, 0, 0, 9897, -49207], [686, 85526, -3568, -1090, 1372, 984, -1090, 686], [-225814, 0, 17367, 34624, 0, 0, -28355, 4719], [4275, -91738, -50781, -19066, 8550, -2142, -19066, 4275], [446784, 0, -40811, -18414, 0, 0, 44360, -29495], [-3188, -148856, -2629, 2742, -6376, 7667, 2742, -3188], [1152, 88816, -37449, -12047, 2304, 2460, -12047, 1152], [1072, 90270, -7270, 4292, 2144, 21218, 4292, 1072], [381334, 0, 32557, -11928, 0, 0, -5614, -9401], [1881, -182780, -34505, -18239, 3762, -18331, -18239, 1881], [-12425, -103828, -52711, -14862, -24850, -4300, -14862, -12425], [3502, -136854, 16557, 4243, 7004, -326, 4243, 3502], [262808, 0, 3942, -6117, 0, 0, 5301, -8427], [82157, 0, -53419, 61283, 0, 0, 13444, -34752]]
