
# q-expansion of newform 121.4.c.f, downloaded from the LMFDB on 19 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 = 121
weight = 4
poly_data = [81, 0, 27, 0, 9, 0, 3, 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], [[0, 0, 1, 0, 0, 0, 0, 0], 3], [[0, 0, 0, 1, 0, 0, 0, 0], 3], [[0, 0, 0, 0, 1, 0, 0, 0], 9], [[0, 0, 0, 0, 0, 1, 0, 0], 9], [[0, 0, 0, 0, 0, 0, 1, 0], 27], [[0, 0, 0, 0, 0, 0, 0, 1], 27]]

hecke_ring_character_values = [[2, [0, 0, 0, 0, 1, 0, 0, 0]]]
aps_data = [[0, 0, -1, 0, 0, 0, 0, 1], [0, 4, 0, 0, 0, 0, -1, 0], [-1, 0, -1, -8, -1, 0, -1, 0], [0, 4, 0, 4, -10, 4, 0, 4], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, -40, 0, 0, 0, 0, -20], [-62, 0, -62, 12, -62, 0, -62, 0], [0, 60, 0, 0, 0, 0, -36, 0], [-49, 0, 0, 0, 0, 36, 0, 0], [0, 56, 0, 56, -72, 56, 0, 56], [0, 0, -17, 0, 0, 0, 0, -28], [0, -8, 0, -8, 27, -8, 0, -8], [0, -4, 0, 0, 0, 0, -268, 0], [30, 0, 0, 0, 0, -16, 0, 0], [0, 120, 0, 0, 0, 0, -136, 0], [0, 0, -246, 0, 0, 0, 0, 56], [0, -132, 0, -132, 317, -132, 0, -132], [420, 0, 420, 184, 420, 0, 420, 0], [377, 0, 0, 0, 0, 20, 0, 0], [339, 0, 339, -76, 339, 0, 339, 0], [0, 468, 0, 468, 200, 468, 0, 468], [0, 0, -158, 0, 0, 0, 0, 656], [234, 0, 234, 120, 234, 0, 234, 0], [-921, 0, 0, 0, 0, 328, 0, 0], [0, 0, 1097, 0, 0, 0, 0, -144], [0, 0, -566, 0, 0, 0, 0, -420], [0, 488, 0, 488, -880, 488, 0, 488], [0, 380, 0, 0, 0, 0, -174, 0], [-490, 0, 0, 0, 0, 320, 0, 0], [0, -664, 0, 0, 0, 0, -855, 0], [-604, 0, -604, -412, -604, 0, -604, 0], [222, 0, 0, 0, 0, -796, 0, 0], [-905, 0, -905, -408, -905, 0, -905, 0], [0, -828, 0, -828, 1466, -828, 0, -828], [530, 0, 530, -1708, 530, 0, 530, 0], [0, -408, 0, 0, 0, 0, 1870, 0], [0, -616, 0, 0, 0, 0, 1409, 0], [0, 0, -2060, 0, 0, 0, 0, 384], [0, 0, -1608, 0, 0, 0, 0, 652], [0, 144, 0, 0, 0, 0, -2058, 0], [0, -900, 0, 0, 0, 0, -2871, 0], [-1303, 0, -1303, 1216, -1303, 0, -1303, 0], [0, -348, 0, -348, 2321, -348, 0, -348], [-572, 0, -572, 1104, -572, 0, -572, 0], [4322, 0, 0, 0, 0, 464, 0, 0], [408, 0, 0, 0, 0, -240, 0, 0], [0, 0, -1500, 0, 0, 0, 0, -928], [0, 1132, 0, 0, 0, 0, -1973, 0], [0, 1844, 0, 1844, -1422, 1844, 0, 1844], [0, 0, 3495, 0, 0, 0, 0, 912], [0, 0, -2304, 0, 0, 0, 0, 1208], [0, -2424, 0, 0, 0, 0, -114, 0], [-1456, 0, 0, 0, 0, 1416, 0, 0], [0, 0, 409, 0, 0, 0, 0, -396], [0, 1160, 0, 1160, -1226, 1160, 0, 1160], [-3194, 0, 0, 0, 0, 1724, 0, 0], [-3010, 0, -3010, 1168, -3010, 0, -3010, 0], [0, -892, 0, -892, -3032, -892, 0, -892], [0, 0, -166, 0, 0, 0, 0, 232], [198, 0, 198, 2952, 198, 0, 198, 0], [0, 136, 0, 0, 0, 0, 4964, 0], [0, -3236, 0, -3236, 3276, -3236, 0, -3236], [1588, 0, 0, 0, 0, -52, 0, 0], [0, -3192, 0, 0, 0, 0, -1956, 0], [-3263, 0, -3263, -2264, -3263, 0, -3263, 0], [0, 0, 109, 0, 0, 0, 0, 72], [3607, 0, 0, 0, 0, 2844, 0, 0], [0, 3444, 0, 3444, -5726, 3444, 0, 3444], [-632, 0, -632, -3020, -632, 0, -632, 0], [0, -932, 0, 0, 0, 0, -5106, 0], [-2589, 0, 0, 0, 0, 4808, 0, 0], [0, 2132, 0, 2132, 7808, 2132, 0, 2132], [0, -836, 0, -836, 8215, -836, 0, -836], [2726, 0, 0, 0, 0, -1492, 0, 0], [1829, 0, 1829, -572, 1829, 0, 1829, 0], [0, 0, -4585, 0, 0, 0, 0, -1012], [0, 3440, 0, 3440, -2847, 3440, 0, 3440], [9262, 0, 0, 0, 0, -2856, 0, 0], [2950, 0, 2950, 1912, 2950, 0, 2950, 0], [0, 0, -2514, 0, 0, 0, 0, -3872], [-12100, 0, 0, 0, 0, -1624, 0, 0], [0, -7688, 0, 0, 0, 0, -170, 0], [0, 0, -2658, 0, 0, 0, 0, 1300], [0, -2880, 0, -2880, -6755, -2880, 0, -2880], [2000, 0, 0, 0, 0, -5672, 0, 0], [0, 452, 0, 0, 0, 0, 10885, 0], [0, 0, 8315, 0, 0, 0, 0, 5000], [-13380, 0, -13380, 1624, -13380, 0, -13380, 0], [-6660, 0, 0, 0, 0, -1112, 0, 0], [-2243, 0, 0, 0, 0, -3276, 0, 0], [5019, 0, 5019, -5852, 5019, 0, 5019, 0], [10784, 0, 10784, 452, 10784, 0, 10784, 0], [0, 7324, 0, 0, 0, 0, -5641, 0], [0, -1648, 0, -1648, 10472, -1648, 0, -1648], [0, 9520, 0, 9520, -3580, 9520, 0, 9520], [0, 688, 0, 0, 0, 0, -8974, 0], [0, -2288, 0, 0, 0, 0, 2487, 0], [0, -7776, 0, -7776, -5859, -7776, 0, -7776], [9356, 0, 9356, -1788, 9356, 0, 9356, 0], [0, 0, 2348, 0, 0, 0, 0, -6732], [0, 1752, 0, 0, 0, 0, 7984, 0], [0, -2372, 0, -2372, 7910, -2372, 0, -2372], [0, 0, 9332, 0, 0, 0, 0, -328], [0, 4504, 0, 0, 0, 0, 2472, 0], [7180, 0, 0, 0, 0, -5648, 0, 0], [17607, 0, 17607, -1224, 17607, 0, 17607, 0], [0, 6120, 0, 6120, 484, 6120, 0, 6120], [-3740, 0, 0, 0, 0, 352, 0, 0], [-11632, 0, -11632, -896, -11632, 0, -11632, 0], [0, 6796, 0, 6796, 6994, 6796, 0, 6796], [0, 0, -9650, 0, 0, 0, 0, 7056], [0, -4688, 0, 0, 0, 0, -4592, 0], [-3246, 0, 0, 0, 0, 11248, 0, 0], [0, 9844, 0, 0, 0, 0, -4393, 0], [0, 7356, 0, 7356, 8791, 7356, 0, 7356], [0, -7952, 0, 0, 0, 0, 6375, 0], [-8189, 0, -8189, -11940, -8189, 0, -8189, 0], [0, 0, -6031, 0, 0, 0, 0, -2564], [0, 3952, 0, 3952, 13183, 3952, 0, 3952], [-2338, 0, 0, 0, 0, -7424, 0, 0], [2797, 0, 0, 0, 0, -288, 0, 0], [0, 0, -11006, 0, 0, 0, 0, -7040], [5538, 0, 5538, 4436, 5538, 0, 5538, 0], [-21688, 0, 0, 0, 0, -4536, 0, 0], [0, 0, 8993, 0, 0, 0, 0, 10860], [0, 14332, 0, 0, 0, 0, -5126, 0], [-15215, 0, -15215, 2256, -15215, 0, -15215, 0], [0, -9948, 0, -9948, -15393, -9948, 0, -9948], [-4029, 0, 0, 0, 0, -2036, 0, 0], [0, 968, 0, 968, -10308, 968, 0, 968], [0, 0, 22750, 0, 0, 0, 0, 2536], [-9020, 0, -9020, 11664, -9020, 0, -9020, 0], [0, -7388, 0, 0, 0, 0, 3937, 0], [0, 0, 5666, 0, 0, 0, 0, 17360], [0, 0, -21432, 0, 0, 0, 0, -7484], [-10616, 0, 0, 0, 0, 12828, 0, 0], [0, 6608, 0, 0, 0, 0, -24126, 0], [5656, 0, 5656, 5816, 5656, 0, 5656, 0], [9571, 0, 9571, -10080, 9571, 0, 9571, 0], [14772, 0, 14772, -5124, 14772, 0, 14772, 0], [0, -5568, 0, 0, 0, 0, -23842, 0], [0, 6480, 0, 6480, 8618, 6480, 0, 6480], [0, 0, 1887, 0, 0, 0, 0, 17372], [0, 0, 1864, 0, 0, 0, 0, 20724], [0, 1752, 0, 1752, 1897, 1752, 0, 1752], [0, 236, 0, 0, 0, 0, -37781, 0], [10238, 0, 10238, 18896, 10238, 0, 10238, 0], [-13064, 0, 0, 0, 0, -17520, 0, 0], [19425, 0, 0, 0, 0, 5836, 0, 0], [-2352, 0, -2352, 6928, -2352, 0, -2352, 0], [0, 18180, 0, 0, 0, 0, 11760, 0], [11645, 0, 0, 0, 0, -4520, 0, 0], [0, -88, 0, 0, 0, 0, 48940, 0], [0, 9296, 0, 9296, -25394, 9296, 0, 9296], [-29652, 0, -29652, -4640, -29652, 0, -29652, 0], [0, 0, 18348, 0, 0, 0, 0, -8488], [4066, 0, 4066, -15712, 4066, 0, 4066, 0], [8310, 0, 8310, 8584, 8310, 0, 8310, 0], [0, 0, 29524, 0, 0, 0, 0, -2916], [28626, 0, 28626, 7624, 28626, 0, 28626, 0], [-2955, 0, 0, 0, 0, -17428, 0, 0], [0, -17804, 0, -17804, -10102, -17804, 0, -17804], [27176, 0, 0, 0, 0, -10968, 0, 0], [0, -4452, 0, 0, 0, 0, -12865, 0], [0, 0, 12117, 0, 0, 0, 0, 1400], [0, 17956, 0, 17956, 1815, 17956, 0, 17956], [-4304, 0, 0, 0, 0, -19504, 0, 0], [0, 1484, 0, 1484, 29374, 1484, 0, 1484]]
