
# q-expansion of newform 147.6.e.m, 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 = 147
weight = 6
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 = [[50, [1, 0, 0, 0]], [52, [0, 0, -1, 0]]]
aps_data = [[0, 1, 1, 0], [-9, 0, 9, 0], [0, 0, 36, 0], [0, 0, 0, 0], [-244, 8, 236, 8], [-684, 0, 0, 72], [360, 216, -576, 216], [0, -288, 36, 0], [0, 56, 224, 0], [3506, 0, 0, -640], [4680, 576, -5256, 576], [0, 1056, -6090, 0], [-10584, 0, 0, 216], [-4332, 0, 0, 2400], [0, 3456, 2232, 0], [-518, -1184, 1702, -1184], [15300, -864, -14436, -864], [0, 4680, -10980, 0], [7100, 6480, -13580, 6480], [-44864, 0, 0, -2552], [27360, 1872, -29232, 1872], [0, 6480, 24808, 0], [30924, 0, 0, 9504], [0, -3672, 63432, 0], [-27720, 0, 0, 19584], [-64620, 11664, 52956, 11664], [0, -1440, 126648, 0], [0, 2488, -101588, 0], [-8226, 5760, 2466, 5760], [-12526, 0, 0, -1888], [26944, 0, 0, -22032], [0, 16416, 51732, 0], [-393302, -3968, 397270, -3968], [121428, 0, 0, -14976], [0, 41056, -240806, 0], [209544, -2208, -207336, -2208], [369468, -14040, -355428, -14040], [0, -45360, 246692, 0], [-270216, 0, 0, 6912], [0, -16416, 484380, 0], [194060, 3128, -197188, 3128], [-14940, 0, 0, -23256], [0, -568, -177184, 0], [-572418, 61056, 511362, 61056], [-270410, 0, 0, 66496], [566568, 23328, -589896, 23328], [-545772, 0, 0, -21504], [453168, 0, 0, -66528], [948276, -27648, -920628, -27648], [0, -90072, 360612, 0], [0, -118688, -252758, 0], [-6608, 0, 0, -14600], [-710424, -26784, 737208, -26784], [874548, 0, 0, -74304], [0, 110376, 155016, 0], [774928, -72728, -702200, -72728], [-105012, -184464, 289476, -184464], [0, 143136, 1100448, 0], [431194, 106272, -537466, 106272], [694150, 0, 0, -69344], [-179100, -122400, 301500, -122400], [-169380, 0, 0, -50544], [1683756, 0, 0, 215712], [-1639008, 126144, 1512864, 126144], [0, -176976, -517608, 0], [0, -88480, 68882, 0], [0, 88704, -837828, 0], [-2355954, 0, 0, 107328], [1183820, -192328, -991492, -192328], [-2298636, 0, 0, 58680], [312480, 195912, -508392, 195912], [0, -522904, 1104848, 0], [1388880, 239328, -1628208, 239328], [0, 5184, 2345210, 0], [1682772, 0, 0, -305472], [0, 103680, -2929320, 0], [3007094, -102016, -2905078, -102016], [0, 614232, -627228, 0], [0, 430400, -3229870, 0], [-2095128, -195840, 2290968, -195840], [1183716, 0, 0, -429408], [-206186, 0, 0, -764640], [-417728, 567832, -150104, 567832], [-4024296, 0, 0, -345168], [0, 2304, -4535424, 0], [0, 573544, -1418180, 0], [1743938, 0, 0, 565664], [0, -377664, 163830, 0], [-1510668, 0, 0, -403488], [-3920392, 0, 0, -219024], [0, 803520, -2773836, 0], [-4286232, -305856, 4592088, -305856], [321576, -669504, 347928, -669504], [2265884, 0, 0, -427480], [0, -220608, -1735524, 0], [4435920, 0, 0, -93312], [0, -1225584, 2401308, 0], [-5423256, -154440, 5577696, -154440], [0, -1247040, 326628, 0], [0, 142560, 8985202, 0], [-5231092, 0, 0, 1227312], [516002, 1486688, -2002690, 1486688], [6524604, -619488, -5905116, -619488], [0, 60832, -7776038, 0], [7205372, 34992, -7240364, 34992], [-6309648, -77184, 6386832, -77184], [8087364, 0, 0, 110592], [0, -207144, 11007720, 0], [365008, -1265384, 900376, -1265384], [-3089376, 0, 0, -581184], [0, 838368, -373824, 0], [-4980202, -176256, 5156458, -176256], [-1087946, 0, 0, -1168832], [-2545164, -1440000, 3985164, -1440000], [-2854352, 0, 0, 975888], [-3214654, -660160, 3874814, -660160], [6322788, 0, 0, -428832], [7431336, 810432, -8241768, 810432], [0, 2363744, 759998, 0], [3530396, 0, 0, -416008], [8252676, -1112328, -7140348, -1112328], [-15292770, 0, 0, 1152192], [0, 1301184, 3928428, 0], [7058404, 1467256, -8525660, 1467256], [0, -281664, 693684, 0], [1391282, 0, 0, 1114016], [0, 128640, 10356438, 0], [0, -2025216, -12297816, 0], [17656488, 0, 0, 1208736], [0, -1670472, 16317468, 0], [-5921516, -2152656, 8074172, -2152656], [11575256, 0, 0, -779128], [0, -1690464, -2519616, 0], [8627418, 0, 0, 437184], [0, 556632, 21282192, 0], [-6337656, 0, 0, 1404432], [6371892, 848016, -7219908, 848016], [-10727244, 2669184, 8058060, 2669184], [-6616332, 0, 0, 2368224], [1308374, 3991136, -5299510, 3991136], [11268684, 0, 0, 2441088], [0, -1346336, -3445670, 0], [-4406624, -1310256, 5716880, -1310256], [20523740, 0, 0, 1245848], [-17072316, -383832, 17456148, -383832], [13637736, 0, 0, 694656], [-4903884, 0, 0, -2107656], [-5860296, -2537784, 8398080, -2537784], [0, 3465504, -16767108, 0], [0, -1680808, 28501424, 0], [0, -1342656, -16747586, 0], [5316912, 0, 0, -169128], [11004468, 0, 0, 936960], [0, 1729728, -4163688, 0], [22767204, -133152, -22634052, -133152], [-11560496, 0, 0, 833896], [0, 330720, 28917744, 0], [0, -1083240, -6242832, 0], [-15015456, 0, 0, 2032992], [-11982060, 3253824, 8728236, 3253824], [0, -1440296, -5572724, 0], [-27057638, 0, 0, 506560], [2462696, 0, 0, 2694384], [0, -243648, 18375012, 0], [-3611566, 613856, 2997710, 613856], [6428664, 6148224, -12576888, 6148224], [-10471944, 3774048, 6697896, 3774048], [23829444, 2237112, -26066556, 2237112]]
