
# q-expansion of newform 126.4.g.f, downloaded from the LMFDB on 24 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 = 126
weight = 4
poly_data = [2304, 48, 49, -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], [[2304, -49, 49, -1], 2352], [[97, 0, 0, 1], 49]]

hecke_ring_character_values = [[29, [1, 0, 0, 0]], [73, [0, 0, -1, 0]]]
aps_data = [[0, 0, 2, 0], [0, 0, 0, 0], [0, -1, -3, 0], [2, -2, -1, 1], [16, -7, -9, -7], [-27, 0, 0, 5], [-44, -10, 54, -10], [0, 3, 58, 0], [0, -14, -54, 0], [40, 0, 0, -7], [-63, 28, 35, 28], [0, -21, -134, 0], [168, 0, 0, 0], [143, 0, 0, 21], [0, 24, -348, 0], [156, 63, -219, 63], [-412, 61, 351, 61], [0, -34, 220, 0], [503, 35, -538, 35], [812, 0, 0, 28], [143, -97, -46, -97], [0, 98, -311, 0], [188, 0, 0, -89], [0, -54, -1170, 0], [46, 0, 0, -155], [-352, -206, 558, -206], [0, 81, 40, 0], [0, -147, 783, 0], [467, -217, -250, -217], [1540, 0, 0, -28], [-309, 0, 0, -70], [0, -37, -2211, 0], [1424, -182, -1242, -182], [1723, 0, 0, 19], [0, 210, 1374, 0], [-244, 245, -1, 245], [-1910, -198, 2108, -198], [0, 210, -218, 0], [940, 0, 0, 206], [0, 254, -2514, 0], [1716, 336, -2052, 336], [1725, 0, 0, 239], [0, 168, -900, 0], [-1799, -42, 1841, -42], [284, 0, 0, 490], [-2396, 396, 2000, 396], [-2032, 0, 0, 504], [4364, 0, 0, 57], [-1608, -333, 1941, -333], [0, -593, 244, 0], [0, -98, -810, 0], [696, 0, 0, -378], [-2510, 15, 2495, 15], [-2556, 0, 0, 135], [0, -810, 174, 0], [-1080, -336, 1416, -336], [3536, -317, -3219, -317], [0, 59, 121, 0], [3019, -231, -2788, -231], [-4420, 0, 0, -14], [-2539, -529, 3068, -529], [-456, 0, 0, -327], [-911, 0, 0, -299], [8600, -92, -8508, -92], [0, 1030, -977, 0], [0, -651, -2205, 0], [0, -21, -2984, 0], [-1227, 0, 0, -616], [-7188, 504, 6684, 504], [-2618, 0, 0, -56], [804, 996, -1800, 996], [0, 770, -4938, 0], [-9509, -204, 9713, -204], [0, -1211, -5060, 0], [1393, 0, 0, -749], [0, 550, 6606, 0], [20, 658, -678, 658], [0, -79, 12664, 0], [0, 588, 1128, 0], [5263, 1038, -6301, 1038], [-3216, 0, 0, -540], [1569, 0, 0, 287], [-2004, -588, 2592, -588], [-3277, 0, 0, -537], [0, -109, -10463, 0], [0, -161, -6771, 0], [-2972, 0, 0, -1834], [0, 2170, -3131, 0], [3904, 0, 0, 410], [913, 0, 0, 763], [0, -2272, -180, 0], [-8156, 548, 7608, 548], [3127, -1008, -2119, -1008], [-6456, 0, 0, -21], [0, 259, 13126, 0], [5304, 0, 0, -1746], [0, 1293, 3711, 0], [2232, -768, -1464, -768], [0, -1011, -2102, 0], [0, -1897, -1424, 0], [5544, 0, 0, 1778], [-1816, 49, 1767, 49], [11740, 677, -12417, 677], [0, 1974, -1998, 0], [-387, -1253, 1640, -1253], [7709, 1676, -9385, 1676], [4736, 0, 0, 2281], [0, 1278, -11286, 0], [8784, 378, -9162, 378], [7463, 0, 0, -2256], [0, -184, -16337, 0], [-19998, -644, 20642, -644], [27488, 0, 0, -308], [-3373, 1265, 2108, 1265], [10820, 0, 0, -2331], [1324, 1064, -2388, 1064], [803, 0, 0, -129], [-9936, -372, 10308, -372], [0, -273, 15345, 0], [11684, 0, 0, 112], [14885, -1357, -13528, -1357], [-613, 0, 0, -3738], [0, -633, -19959, 0], [-3660, 819, 2841, 819], [0, 531, -19064, 0], [8020, 0, 0, -1603], [0, -924, 16954, 0], [0, 42, -20202, 0], [12385, 0, 0, -158], [0, -3505, 12844, 0], [57, 2401, -2458, 2401], [9336, 0, 0, 1302], [0, 1862, 14731, 0], [-18606, 0, 0, 1610], [0, -686, -3822, 0], [-11873, 0, 0, -2210], [-26056, 298, 25758, 298], [-18168, 2512, 15656, 2512], [-9684, 0, 0, 111], [19748, 280, -20028, 280], [-17912, 0, 0, -2690], [0, 301, -16137, 0], [13868, -1204, -12664, -1204], [11604, 0, 0, 1071], [38027, -13, -38014, -13], [8000, 0, 0, -1874], [-30865, 0, 0, 627], [-42864, 804, 42060, 804], [0, 5016, -2144, 0], [0, 2702, 15738, 0], [0, -350, -4760, 0], [18132, 0, 0, 2250], [29861, 0, 0, 735], [0, 3054, -6966, 0], [24111, 2947, -27058, 2947], [-1092, 0, 0, -1764], [0, 3283, 14476, 0], [0, 2052, -312, 0], [-17557, 0, 0, 744], [32804, 3013, -35817, 3013], [0, 3500, -25428, 0], [-17212, 0, 0, 4984], [-1987, 0, 0, 210], [0, 225, 3195, 0], [1968, -756, -1212, -756], [-18348, -1188, 19536, -1188], [2281, 1512, -3793, 1512], [-1307, -2895, 4202, -2895]]
