
# q-expansion of newform 504.4.s.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 = 504
weight = 4
poly_data = [15876, 126, 127, -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], 1], [[0, 1, 0, 0], 1], [[15876, -127, 127, -1], 16002], [[253, 0, 0, 1], 127]]

hecke_ring_character_values = [[127, [1, 0, 0, 0]], [253, [1, 0, 0, 0]], [281, [1, 0, 0, 0]], [73, [0, 0, -1, 0]]]
aps_data = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 1, 4, 0], [9, 0, -17, -1], [5, -5, 0, -5], [-10, 0, 0, 1], [0, -4, 4, -4], [0, -7, -55, 0], [0, -4, 76, 0], [45, 0, 0, 5], [181, -2, -179, -2], [0, -1, 27, 0], [76, 0, 0, 18], [188, 0, 0, 27], [0, 36, 166, 0], [351, -5, -346, -5], [-279, -27, 306, -27], [0, 28, 566, 0], [-80, -73, 153, -73], [-346, 0, 0, 76], [440, -63, -377, -63], [0, -48, 425, 0], [175, 0, 0, -67], [0, 22, -940, 0], [837, 0, 0, 55], [-274, 76, 198, 76], [0, -35, 441, 0], [0, 9, 1782, 0], [460, -47, -413, -47], [-356, 0, 0, -22], [469, 0, 0, -20], [0, -107, 1516, 0], [-882, -14, 896, -14], [1504, 0, 0, -73], [0, 94, 2336, 0], [-3249, -37, 3286, -37], [72, 234, -306, 234], [0, 172, -2260, 0], [-670, 0, 0, -32], [0, 14, -1760, 0], [1616, -118, -1498, -118], [2170, 0, 0, 97], [0, 18, 1994, 0], [-1369, 226, 1143, 226], [-1962, 0, 0, 162], [36, -332, 296, -332], [-1926, 0, 0, 206], [2619, 0, 0, -153], [-2597, -99, 2696, -99], [0, -83, 1549, 0], [0, -98, -3002, 0], [-3668, 0, 0, 82], [-3949, 285, 3664, 285], [423, 0, 0, 103], [0, 392, -2898, 0], [1134, 378, -1512, 378], [2587, 113, -2700, 113], [0, 305, -2798, 0], [-1810, -369, 2179, -369], [1422, 0, 0, -90], [2060, -115, -1945, -115], [2133, 0, 0, -207], [-170, 0, 0, 747], [-4396, -518, 4914, -518], [0, 502, -107, 0], [0, -495, 1242, 0], [0, -153, -1745, 0], [-4159, 0, 0, 468], [-3636, 216, 3420, 216], [5994, 0, 0, 296], [-1004, -58, 1062, -58], [0, 162, -4896, 0], [5831, 110, -5941, 110], [0, -821, 4807, 0], [5318, 0, 0, -737], [0, -342, -396, 0], [-6854, -692, 7546, -692], [0, -801, 2159, 0], [0, 216, -288, 0], [-2107, -350, 2457, -350], [7924, 0, 0, 442], [568, 0, 0, -765], [8464, -58, -8406, -58], [8272, 0, 0, 477], [0, -207, -7902, 0], [0, -265, -5162, 0], [-9832, 0, 0, 26], [0, 54, 17207, 0], [13662, 0, 0, -198], [1286, 0, 0, 675], [0, 274, -14274, 0], [-1278, 986, 292, 986], [-2213, -758, 2971, -758], [7947, 0, 0, -117], [0, -313, 13481, 0], [3344, 0, 0, 1286], [0, -689, 13428, 0], [12906, 126, -13032, 126], [0, 55, -5897, 0], [0, 1559, 2321, 0], [3240, 0, 0, -692], [-4315, 99, 4216, 99], [1409, 459, -1868, 459], [0, 590, -4374, 0], [-10252, 317, 9935, 317], [377, -1520, 1143, -1520], [4113, 0, 0, -1139], [0, 1822, -1458, 0], [-5166, -1858, 7024, -1858], [-23365, 0, 0, -268], [0, 974, -18955, 0], [1116, 422, -1538, 422], [-12514, 0, 0, 904], [-11224, 991, 10233, 991], [-15705, 0, 0, 35], [-17154, 122, 17032, 122], [7228, 0, 0, 963], [-17042, 716, 16326, 716], [0, -927, 17932, 0], [-1368, 0, 0, 608], [4888, -765, -4123, -765], [-15119, 0, 0, -558], [0, 1395, -342, 0], [-6813, 1431, 5382, 1431], [0, 1087, -11573, 0], [-10827, 0, 0, 1885], [0, 280, -3862, 0], [0, 1616, -14130, 0], [3043, 0, 0, 1960], [0, -385, -595, 0], [-11800, 117, 11683, 117], [13630, 0, 0, -1376], [0, 2140, 8155, 0], [13822, 0, 0, -420], [0, -792, 14292, 0], [-11359, 0, 0, -142], [5342, 1800, -7142, 1800], [466, -2870, 2404, -2870], [-8613, 0, 0, 2043], [-2668, 2506, 162, 2506], [12238, 0, 0, -3058], [0, -337, 13356, 0], [3960, -2240, -1720, -2240], [7447, 0, 0, -1975], [20386, 1503, -21889, 1503], [-12744, 0, 0, -324], [25424, 0, 0, -1015], [-4158, 1818, 2340, 1818], [0, -2818, 5660, 0], [0, -972, -11318, 0], [0, 242, -14822, 0], [-6246, 0, 0, -2714], [12430, 0, 0, -2241], [0, 1850, 2394, 0], [1954, 2265, -4219, 2265], [35190, 0, 0, 1282], [0, 1595, 11807, 0], [0, -928, 15530, 0], [2035, 0, 0, 908], [-11259, -351, 11610, -351], [0, -1126, 38354, 0], [-13878, 0, 0, -1526], [-4393, 0, 0, 460], [0, -2183, -16366, 0], [-9454, -140, 9594, -140], [-2988, -1260, 4248, -1260], [73, -406, 333, -406], [24632, -1377, -23255, -1377]]
