
# q-expansion of newform 648.4.i.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 = 648
weight = 4
poly_data = [9, -3, -2, -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], [[-9, -2, 2, 1], 6], [[3, 10, 2, -2], 1], [[-33, 10, 2, 7], 2]]

hecke_ring_character_values = [[487, [1, 0, 0, 0]], [325, [1, 0, 0, 0]], [569, [-1, -1, 0, 0]]]
aps_data = [[0, 0, 0, 0], [0, 0, 0, 0], [-4, -4, 0, -1], [0, 12, -1, 1], [0, 1, 0, 0], [-16, -16, 0, 4], [-28, 0, -4, 0], [92, 0, 2, 0], [-46, -46, 0, 4], [0, -168, -2, 2], [-188, -188, 0, 5], [174, 0, -4, 0], [156, 156, 0, -10], [0, 40, 14, -14], [0, -114, 8, -8], [76, 0, -13, 0], [-340, -340, 0, 24], [0, -56, 32, -32], [-176, -176, 0, -34], [908, 0, -12, 0], [-287, 0, 0, 0], [0, -680, -32, 32], [0, -391, -32, 32], [120, 0, 18, 0], [0, -169, -8, 8], [0, -828, 9, -9], [56, 56, 0, 52], [693, 0, -56, 0], [46, 0, 76, 0], [732, 732, 0, 70], [-164, 0, 23, 0], [1003, 1003, 0, 104], [0, -1296, -2, 2], [-1416, -1416, 0, 100], [-2132, -2132, 0, 31], [0, -1468, 113, -113], [764, 764, 0, -72], [1236, 0, 120, 0], [390, 390, 0, -144], [0, 3252, 19, -19], [-1197, 0, 56, 0], [2016, 0, 16, 0], [0, -840, 196, -196], [499, 499, 0, 40], [1092, 0, -245, 0], [1564, 0, -129, 0], [-3028, -3028, 0, -34], [0, -2192, -8, 8], [0, 1740, -24, 24], [1682, 1682, 0, 8], [-3128, 0, -50, 0], [2878, 2878, 0, 164], [0, 1950, -248, 248], [-1168, 0, 336, 0], [3940, 3940, 0, 56], [0, 2158, -132, 132], [560, 0, 226, 0], [68, 0, 185, 0], [0, -3008, 24, -24], [0, 284, 116, -116], [1420, 1420, 0, 178], [624, 624, 0, -134], [-8148, 0, 4, 0], [-1110, -1110, 0, -84], [0, -2427, 96, -96], [0, 36, 449, -449], [0, 1952, 134, -134], [5694, 5694, 0, 56], [-2655, -2655, 0, -304], [0, 1434, 156, -156], [0, -460, -526, 526], [-3462, 0, -24, 0], [0, -8564, 193, -193], [-7628, -7628, 0, -276], [1856, 0, 12, 0], [-10044, -10044, 0, -108], [0, 5668, -409, 409], [-5152, 0, 36, 0], [7104, 7104, 0, -132], [-9279, -9279, 0, -128], [612, 612, 0, -512], [0, 3584, -360, 360], [7346, 0, 224, 0], [5269, 0, -264, 0], [0, 3780, -291, 291], [0, 6884, 224, -224], [9652, 0, -378, 0], [0, -5569, 200, -200], [0, -7868, 255, -255], [-3524, -3524, 0, 3], [1209, 0, 616, 0], [0, -10114, -488, 488], [3448, 0, 248, 0], [-14571, -14571, 0, -328], [-2256, -2256, 0, 926], [7986, 0, 332, 0], [948, 948, 0, -771], [6380, 0, -288, 0], [-6884, 0, 788, 0], [2556, 0, 264, 0], [0, 4652, -428, 428], [14788, 0, -15, 0], [14921, 14921, 0, -272], [0, 7144, 396, -396], [15204, 15204, 0, -488], [-17074, 0, 344, 0], [0, -15959, 456, -456], [2920, 0, -1122, 0], [6594, 6594, 0, -104], [0, -2645, -416, 416], [19528, 19528, 0, -264], [-3514, 0, 880, 0], [996, 996, 0, -38], [0, 21724, 192, -192], [7612, 0, 345, 0], [0, -7172, -978, 978], [8016, 8016, 0, -276], [-13768, 0, 328, 0], [1308, 1308, 0, 123], [0, -12993, 48, -48], [12862, 12862, 0, 572], [0, -3203, 112, -112], [0, -872, -590, 590], [9964, 0, 224, 0], [0, 9872, 1212, -1212], [-15540, 0, 875, 0], [0, 27548, 64, -64], [20212, 0, -272, 0], [0, -7692, -1545, 1545], [-5486, -5486, 0, 1292], [2804, 0, 1596, 0], [-4456, -4456, 0, -1604], [-17172, -17172, 0, 449], [1970, 0, -40, 0], [-22520, -22520, 0, 168], [-23849, -23849, 0, 360], [-14304, 0, -478, 0], [22592, 22592, 0, 992], [14900, 14900, 0, -749], [-14200, 0, -434, 0], [-2588, 0, -726, 0], [0, -4608, -842, 842], [-19916, -19916, 0, 489], [31424, 0, 320, 0], [34, 0, 184, 0], [0, 3492, 268, -268], [0, 13286, 408, -408], [0, 11004, -468, 468], [-8040, -8040, 0, -1088], [16828, 0, 1696, 0], [-2850, -2850, 0, -1952], [-8908, 0, -1696, 0], [7172, 0, -1190, 0], [34576, 34576, 0, -380], [0, -9116, 2094, -2094], [0, 8230, 2208, -2208], [36916, 0, 3, 0], [0, 42344, -468, 468], [-14853, 0, -888, 0], [24660, 24660, 0, 1019], [0, 24999, -880, 880], [-17064, 0, 1404, 0], [11596, 11596, 0, -641], [13929, 0, 992, 0], [6408, 6408, 0, -826], [0, 5934, 3096, -3096], [14428, 0, 1673, 0], [0, -44552, -252, 252]]
