
# q-expansion of newform 245.4.a.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 = 245
weight = 4
poly_data = [64, 288, 21, -37, -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], 1], [[0, 1, 0, 0, 0], 1], [[-4, -21, 0, 1, 0], 4], [[-15, 0, 1, 0, 0], 1], [[112, 21, -29, -1, 1], 4]]

hecke_ring_character_values = None
aps_data = [[0, 1, 0, 0, 0], [-2, 0, 1, 0, 0], [-5, 0, 0, 0, 0], [0, 0, 0, 0, 0], [8, 7, -1, 1, 1], [2, -1, -1, -1, -3], [-2, 4, 2, -6, 0], [-6, 9, 3, 1, -3], [40, 7, 0, -9, -3], [31, 31, -1, -13, 3], [82, 10, -12, -8, -4], [-24, -37, 1, -11, 5], [-67, 2, 26, 14, 0], [134, -56, -15, -4, -8], [-88, -33, 9, -15, -9], [64, 7, 15, -13, -3], [138, 46, -10, 8, -4], [379, 41, 1, 1, 3], [218, -66, 59, 26, -12], [158, 62, 10, -32, -4], [-362, 74, 44, 8, -2], [86, -8, -96, -22, -6], [-318, 22, -3, 22, 36], [453, -115, 63, 3, 23], [134, -40, -8, -24, -8], [-139, 163, -73, -17, 11], [12, 264, -95, 42, -14], [198, -110, -73, 86, -12], [937, -77, -49, 11, -35], [-636, 156, -14, 62, -16], [344, -15, 95, 39, 69], [1264, -81, -47, -47, 33], [20, -24, -56, 72, 72], [388, -168, -226, -52, 48], [-871, 249, -147, -119, -53], [102, -136, 182, 26, 38], [718, -217, 125, 97, -27], [1044, 244, 20, -252, -38], [-340, -123, -114, 53, -31], [-648, -621, -19, 113, 5], [1246, 155, -137, -5, 43], [-411, 417, 85, 1, 69], [-716, 560, 74, 44, 136], [1534, -50, 86, -142, -2], [2034, 187, -267, -3, 49], [52, -504, -176, 24, -16], [2218, -207, 263, -119, 37], [2072, -300, 304, 204, 26], [-1024, -404, -168, -272, 122], [-942, 818, -118, -158, 86], [550, 456, 210, 206, -72], [542, 184, -282, -126, -146], [1202, 65, 335, 59, 159], [1406, 71, 423, 175, 23], [1428, -712, 204, 288, 68], [-1116, 108, 617, -186, 74], [1161, 171, 467, 79, -7], [-1122, -438, -202, -140, 52], [-2950, 452, 406, -6, 164], [-606, 71, -415, -139, 25], [1148, -302, -386, 258, -176], [-2952, -955, 311, -201, -33], [330, -116, 589, -264, 34], [-954, 526, -74, 172, -196], [912, 96, 696, 68, -72], [-5306, -744, 474, -94, -92], [3118, 1423, -161, -189, -85], [-2184, 746, 276, -44, -262], [-1622, -1382, -253, 214, -64], [2843, -41, -257, -133, 87], [-396, 796, 6, -222, 172], [506, -1700, 114, 298, -194], [-2500, 847, -706, -253, -179], [-2356, -94, 614, -198, -94], [402, -135, -769, 437, 105], [-2264, 259, -520, -681, 253], [-2626, -1110, 314, 90, -154], [-638, -656, -1596, 380, -136], [-5513, -1226, -246, 158, 346], [-1989, -793, 121, 33, 63], [3308, -697, -387, -363, 133], [47, -289, -669, -169, -187], [1472, -1384, -102, 312, 60], [-1252, -112, -574, -626, -116], [-576, 622, -90, 538, 22], [94, -1262, 163, -294, -70], [-2945, -942, 1478, 578, 24], [4832, -1670, 118, 154, -26], [2226, 932, -916, 736, -124], [7600, 1381, -412, -263, 225], [-10922, -556, 173, 272, 118], [1994, -1778, 684, -40, 324], [-792, 1124, -364, -152, 226], [-4654, -1710, 668, 20, 4], [4740, 664, 1626, -48, 152], [572, 2920, 819, -586, 376], [3159, -157, -1677, -789, 43], [3582, 1295, -1471, -387, 25], [240, -208, -508, -292, -70], [4777, 1147, -813, 491, 115], [10338, 2726, -1133, 438, 428], [-4030, -509, 633, 161, -507], [1058, 1024, 203, -568, -86], [-5634, 291, -1115, -671, -611], [1590, 1542, 266, -936, -420], [1258, 2714, 126, -142, 526], [-3392, 1952, 988, -276, -354], [9720, -2368, 730, -414, 272], [6324, -2610, 1778, 134, 282], [-10282, 844, -880, -452, -356], [-4812, 4437, -1380, -471, -257], [-3846, 2153, 657, 209, 439], [2688, -2278, 2346, 822, 218], [4092, 1479, -281, -811, -859], [-1224, -2088, 1810, 792, -600], [-171, -1438, 94, 94, 564], [4568, -4078, -438, 330, -696], [-16580, -2013, 34, 1207, 101], [-1766, 1863, -1949, 39, 77], [-13882, -1318, -830, -516, 712], [1727, -1259, -3643, -39, -149], [-2396, 2306, -574, -898, -546], [3154, 295, -2065, -933, -587], [2966, 206, -757, -534, -794], [-4472, -2320, 1510, -1588, 92], [2831, 1707, -1733, 1659, 133], [-13057, 1627, 2351, 1111, 123], [484, -3896, 198, 36, 612], [-8652, 1737, 1474, 565, 45], [3726, 1105, -689, 375, 371], [5344, 4631, 455, -299, 329], [1480, 601, -1764, 285, -883], [-3300, -1378, 914, 1082, 1082], [-2566, 3204, -38, -34, 428], [6150, 1563, 1649, -403, -619], [-7858, 2701, -257, 1099, -13], [10794, 3065, -1467, -135, 131], [14670, 2708, -2255, 308, 294], [-19536, -2782, -1458, 626, 394], [5553, -786, 654, 1562, 254], [-3690, -1403, 1261, 865, 1061], [-7586, -1248, 368, -212, 560], [7260, -4324, 1175, -830, 436], [22850, -3616, -1689, -52, -768], [6346, 2148, -1292, 120, 1060], [6824, 1618, 84, -894, -510], [-2748, 4255, -2917, -1297, 57], [-12662, 4820, 2808, 1080, -192], [-9136, 5744, 472, -580, 1168], [9408, 1127, -2422, -1157, 3], [9880, -3963, 3625, 1825, -501], [-1371, -4632, 492, -932, 406], [11416, 2668, 1128, -160, 966], [11736, -6628, 2293, 606, -56], [-5782, -2388, 1179, 276, -140], [-5880, 2170, 1820, -1086, 274], [-1486, -5212, -1908, -90, -326], [6471, 430, 486, -290, -476], [-9924, -866, -2422, 2098, -182], [-14874, 2018, -3134, -1638, 302], [13206, 1420, -1671, 652, -210], [-2824, -1292, 2792, 2724, 272], [13016, 332, -3731, -1426, -916], [-8516, 667, 161, -1819, 1157], [1510, 140, -4128, -2180, -700], [-21236, 2117, -1748, -191, -55], [5590, 2838, 1432, 2800, -352], [-1712, 282, 2832, -1956, -718]]
