
# q-expansion of newform 147.6.a.m, downloaded from the LMFDB on 17 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 = [294, 7, -97, -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], [[-49, -1, 1, 0], 1], [[52, -89, -2, 1], 2]]

hecke_ring_character_values = None
aps_data = [[1, -1, 0, 0], [9, 0, 0, 0], [1, -2, 1, 1], [0, 0, 0, 0], [107, -8, 9, 3], [96, 76, -1, 9], [92, -108, -8, 4], [72, 220, -1, -15], [1804, -300, 8, 20], [147, -254, -103, 5], [-1523, -130, 94, 24], [3508, 1028, -95, -9], [1128, -328, -62, 142], [7142, 816, 93, -33], [-3818, 324, 56, -28], [3095, 1338, 13, -239], [9011, -888, 163, -71], [-1566, 796, -52, 240], [-2286, 2764, -193, 465], [21390, 3660, -24, -180], [14074, 3056, -143, -93], [-11635, 2286, -96, -786], [-50001, -6432, 1005, -129], [-20966, 9508, 1582, 622], [-47705, 464, -863, -669], [42794, -11428, -340, -1264], [36272, 1320, -765, -1527], [-7979, -3008, 1057, 475], [16246, 11408, -575, -1917], [38784, 5704, 518, 2594], [15991, 8210, -572, -2658], [-162257, 10216, -2711, -989], [-111034, 3972, 2326, 502], [132886, -6028, 1921, 1551], [216046, 9708, 1142, 926], [97781, 17286, -1485, 855], [134124, -34880, 3314, 1206], [158772, 3460, 44, 3624], [-33474, 11392, 716, -4900], [-300818, -38476, 3978, -2550], [216140, -46552, 2810, -82], [-31272, -25304, -10369, -3291], [160096, -24536, -11306, -3230], [201845, -45720, -3030, 822], [604506, -6500, 2966, -442], [237412, -53824, -3644, -5796], [65622, -65960, -13246, 126], [94047, 35890, -3271, 5733], [455117, -18216, -1937, -11387], [75572, -92208, -8829, -8775], [270940, -10980, -5806, -11878], [71532, -56892, 17418, 15666], [259031, 78384, -13875, 2007], [14259, -91808, -18313, -7843], [546658, 61220, -4572, -5736], [576686, -44348, 9006, -7026], [-481465, 70506, -19925, -2861], [444633, -143186, 10367, -1341], [-484176, 83968, 30143, 12237], [392274, 215252, -18470, -15926], [689502, 83584, 21317, -8073], [-610941, 91658, -5171, -4919], [146604, -43244, 40853, 8907], [164408, -15456, 20806, 23410], [-14959, -42576, -1062, 2718], [-780725, -60774, 19637, -15151], [-775012, 67032, -47463, -1413], [-109623, -110720, -1732, 14244], [936764, 337640, -15196, -33172], [351162, -86192, -19960, -31752], [-1661632, -49232, -29850, -21510], [-950450, 163424, 18498, 21462], [-452945, -175102, -60866, 12492], [2346248, -18072, 43341, 42543], [-2114336, 59960, -7151, -23133], [-838166, 89616, 68798, -1390], [2321654, -273804, -13640, -6620], [-406460, 276704, -46559, -37725], [-650864, -32784, -45196, -36316], [-1286857, -229584, 76362, -690], [950592, 340992, -3942, -20802], [-81850, 288516, -36003, 1131], [-1897420, 9456, -54626, 58258], [-395586, 85624, -45661, 18033], [551833, -290938, -45833, -7965], [-2806793, 35808, -24025, 34061], [575784, -23004, -21762, -52362], [-764433, 43120, -3982, 32454], [-1762494, 474644, -7502, -44582], [-3914808, 128464, -7339, -6009], [-3266660, -126192, -58930, 7010], [-3533566, 66620, 3962, 38594], [-5022309, 152146, 13970, 26472], [2096679, -426424, -22409, -59267], [-2370786, -418724, 809, -15249], [-1741608, -575052, 137094, 28374], [4323007, 159554, 19359, 9423], [-2536738, -554064, -38198, 86014], [-3617664, 208660, 38537, 39687], [-1830754, -217620, 91881, 52551], [1325796, 207964, -77812, -83568], [1396145, -335258, -70359, -101847], [-1552393, -202328, -45651, -52521], [-6342656, -255836, 48382, 59518], [-3182434, -957504, 22605, -50673], [-1381425, 335512, 110360, 55872], [-7669203, -8792, -64807, -45709], [2821492, -1332180, 76022, 75662], [-8134426, -314376, -43478, -81866], [4762675, -53896, 228916, 70068], [-2711413, 1515666, -21174, -98304], [10308588, -889556, -91018, -23346], [7952346, 116112, -25104, -148896], [4437510, 1078984, 39311, -69747], [-3778741, 14994, -67779, -62175], [7776890, 597120, 97858, 143662], [-2532814, -170748, -103923, 149475], [1109978, 321788, 24332, 40928], [5232289, 407526, -237547, 4349], [-4725312, -1464528, 182172, 72444], [-4494822, -49052, -292933, -3723], [13360509, 423712, -80530, -1638], [2271853, -480234, 236831, 85451], [1529153, -1336968, 21529, -84725], [-7285096, 201936, -212823, -27261], [11127675, 476826, 70941, 41793], [3276694, -1909552, 104440, 24024], [-9237818, 669960, -185248, -121576], [6476633, 432678, -26832, -134298], [-5954630, 1349468, -144671, -188625], [-1705562, 801188, -39251, 165363], [467850, -479760, -344640, 72624], [9535683, -904694, -85108, 58926], [2746562, 721260, 158076, -73104], [-2747792, 931500, -381676, 38576], [-11680915, -54816, -117354, 228882], [6354650, -1946620, -72568, -110212], [1406826, 95320, -149134, 63006], [-3788955, 629686, -266245, -21865], [13440416, 564552, 136162, 17062], [-1872586, -2241084, 358122, 47394], [6718903, 651098, 465855, 170391], [-9846008, -1086640, 134152, -112632], [-2814321, 1916712, 61497, -104421], [-12283192, 700836, 19047, -78279], [10392660, -1924724, -165676, -171304], [-13283626, -897048, 228663, 46701], [15138038, 1614784, -115122, 34986], [5808770, -916224, -216366, -334554], [-1222538, 379920, -12100, -148636], [2996016, 3087184, -176530, -1974], [-2498970, 349668, -216126, -75198], [3318440, 1958760, -109719, 88059], [-3368564, -479356, -285678, -174006], [-19072660, 416820, -135591, -243177], [-6525006, 1737828, 461070, -10746], [-8668696, 276048, -58995, 74031], [18437026, 680048, 181044, 331572], [-24843437, -623392, 216580, 117612], [2572421, 1080638, 21791, -19093], [3527248, -1605760, -209550, -428490], [24928266, -1662712, -220946, -290918], [388221, -3875090, 318860, 254322], [-14480759, -1377000, 139121, -291037], [-5314078, -2196936, 171148, 136252], [16747196, 2788848, -396632, -86960], [8391761, 1007118, 396954, 531612], [-17801970, 2693752, -590209, -581595], [-34034265, -692504, 332282, 126390], [12206221, 2922182, 24267, -689841], [2446829, -18504, -200567, 190387], [-1556366, 2736812, -320936, -531228], [16812544, 3570204, -357928, 380372], [2000045, -440376, 4368, 213480], [-9175885, 3492762, 588300, -20658], [7074204, 1074704, -362132, -674972], [17190426, -4058888, -122149, 262737], [-10828987, 149062, -877743, -585879], [18883480, -2557000, -482024, -443280], [13124358, -5062124, -607105, 131889], [-3602083, 359214, 208554, 231996], [8032173, 449328, -677343, 100899], [-4771330, -1236504, -773007, -273621], [710818, -1287796, -863766, -110910], [18738914, -1951224, 807328, -98024], [-13015951, -5389786, 39587, -128617], [29123394, -3264716, -391936, 128148], [3084654, 632212, -578113, 80121], [-18670173, 2019136, 820850, 62022], [18236480, 772036, -3702, -771630], [-7253343, -4699280, 466016, -565344], [-15517179, 3635328, -775785, 67053], [-22073272, 2154468, -446772, -488088], [16664134, 1453284, 1229006, 207302], [-4168009, -366224, 381807, -69579], [-819754, 6260940, -126950, 614506], [-13433482, 5104872, -856617, -507699], [-23403902, -4553740, 59392, 383844], [-17558154, 468024, 632748, -434628], [-30226970, 7528116, 848750, 113654], [-22620439, -2416810, 715073, 19361], [-17605576, -997008, -1097859, -156753], [-22952282, -929992, -121304, 907920], [-1313886, -5941352, -765736, 582288], [-20237328, -4564720, 911122, -62714], [48164027, 2360114, -341389, 544595], [17128600, 5340920, -478952, -239088], [6586957, -718152, -349765, 66377], [171276, -2614956, 1689180, -16488], [-8792502, -7655372, -164326, -37998], [-22072814, -1180072, 371599, 522069], [18224325, 3876150, 305547, 1248399], [37975221, 4729654, -714337, 607131], [-28271315, -911216, 172141, -10481], [640328, -1354012, 1351016, -1852], [7082610, 212584, -1230433, -69099], [-3129601, -3379158, 1019289, 1302765], [51245804, -5652164, 125796, 108216], [51927706, -9060128, -310634, -66662], [43998474, 8049972, 50964, -290904], [21761792, 2861040, 48855, 69141], [27984048, -626840, -394801, 184413], [-60184190, 10931912, 371784, -158760], [47079977, -3916050, -620769, 34995], [-21994287, -2774608, -973013, -790703], [-8683672, 8966952, 1003662, 872514], [33544054, -6830612, -1095350, -920534], [39137324, 11561168, -284350, -868282], [80843681, -1266450, 301140, -190374], [39872980, 3645024, 1219154, 832046], [33263166, 8798572, -565663, 261135], [-63187080, 1328152, 1407212, -270084], [74887493, -3719130, -331104, 92982], [-39761710, 712780, -1595160, 248292], [-26327894, -5287804, -425615, 1293615], [-22540384, -13029252, 374602, 691522], [3466971, 12150184, -207778, -1106334], [93544165, 1213310, 502077, -908835], [1169868, 922176, 75240, -471000], [17430924, 1769660, 1324798, 784270], [67518404, -5374272, 539902, 1184818], [14783368, -6634432, 232675, 822465], [20186239, 7862282, 1499752, 1962018], [43653066, -9481904, -786868, 119892], [47954088, -10661076, 319572, 1104312], [-58907204, -2786240, -1487504, -132536], [-32230971, 11071870, -279076, -1203726], [33878588, 13517576, -1288294, -28210], [19271904, -4709744, -1148872, -1386744], [35410032, -6875256, 2036496, 498360], [31767650, 6204600, 234657, -778149], [31733098, 4963800, 478706, -378394], [8471990, -4937384, -1685484, 384228], [-23701038, 6404728, -1750231, -1511037], [45887807, -11969198, 359865, 307509], [-15763709, -2494144, 608199, 1916805], [28979462, -6623100, 515133, -1984965], [23227804, 1754096, 1611169, 652491], [-257865, 7661610, -456417, 254199], [-134719315, 2806536, -223581, -125487], [14910224, -18632160, 42513, -52293], [9502335, 2473304, 2028187, 1476025], [682526, 106344, -1051179, 499863], [87918212, -1735632, 701397, -412929], [189628250, 2395808, 13340, -650524], [30329150, 13094916, 847149, 960915], [17289453, -15499098, -890199, -1548807], [-25566624, 1649764, 2227034, -252550], [86083500, -6314960, 190472, -2035176], [-7930747, -12191786, -2518347, 15213], [-107782896, -1759016, -2201335, 891795], [34487066, 1118460, -1165926, 70794], [-27131859, 16789240, -384544, 500712], [-22583005, -4901214, -2008566, -1893120], [-83708739, 5449168, -3067297, -1000803], [112177520, 2657328, 1633260, 2044740], [59313181, 19809832, -932441, -787835], [-42765236, -498844, -93299, 2683995], [-100461690, 18034408, 477839, 103605], [-51899912, -4863280, 188544, -481704], [-141933994, 5008796, -1485862, -1502854], [-35102903, 10527614, 1496476, -472302], [-92078736, -5644204, -325886, 2586586], [140864364, 9157120, -981895, 308811], [65117822, 5539260, -151818, -174690], [9534844, 22687716, -1287238, -1997950], [-17452569, -27988016, 805526, 18738], [54560061, -23265786, 1125597, 1860189], [26923811, -7949526, 1660116, -993354], [-54621012, 3054720, -1709598, -1250754], [-103649770, -7617764, 2532414, 266262], [-34443283, -16281056, -2445771, -2371713], [-107871524, -1425384, -1249114, -474574], [-47741292, 23549136, 2656200, 365928], [-1230600, 2748580, 2454485, 239859], [-89092171, 20711206, 1785741, -278331], [50651856, -6910208, 4495739, 1895625], [143199486, -19995892, -2006474, -976922], [-3918284, -17058136, 951318, 2888370], [41770418, -11864448, -1180089, 1663101], [-127944890, 2932208, -969944, 621624], [28953637, 6044934, -3080767, -141343], [82236219, 14713810, 687209, 2028741], [-36290841, -1856936, 1347215, 2001269], [-150710, 2108360, 531649, 2945235], [-94746734, 854984, -557447, 1431171], [22366607, 28584336, -2741927, -387869], [97320862, -4388656, 1374625, -606717], [-84898850, 6568312, 2336206, 3442354], [109985070, 4642552, 226991, -142443], [-17842538, 13357320, -2801038, -2776426], [33978890, 10720772, -2124532, -4336], [-169637360, -2975292, -2876758, -3087742], [46233808, -15591040, 1956832, 46800], [-2359908, 11105708, 1555192, 57124], [116569094, -7052520, -1790007, 1191987], [-93232125, -26220480, 1070925, -699297], [53936540, 6261492, 1578664, 520612], [-31047723, 17825920, 3636140, -83004], [161235624, 8922624, 32790, 2444562], [121921040, 2483232, -663849, -3501075], [-143737830, -18201440, -345841, 2236317], [58661187, -5725542, 734583, -3191193], [33350744, 9842712, 3890397, 1249959], [-200598928, 21304320, -2498174, -2108378], [31004259, -5104904, -444142, 1655982], [-23421834, 28722808, -1392037, -1282863], [32492246, 12643980, -1278111, 1165287], [120128530, 4749872, -2788530, -2128566], [-75297855, 35654838, 1904745, 1908369], [28906518, 33653164, 1828037, -559413], [-14957707, 10377126, 3643357, -1904915], [-89418568, -4549032, -1339533, -1242999], [-233065816, -4055088, -1389122, -1392662], [-115259382, -629948, -4204849, 678249], [181695180, 11417872, 3826970, 3692486], [840704, -11338212, -586158, 4353666], [332335726, 15010104, -191230, -156034], [-107431495, -16492896, -522180, 619284], [140474703, -15045710, -3665800, -3328950], [-9772974, -11666132, -1724077, -2453403], [-39961512, -6764980, -1382948, -2136656], [-178832469, 30937362, 2773893, -1274271], [-155115993, -37162214, 2848952, 1301010], [-54225629, -18504070, 6322335, 926151], [-59081199, -2617784, -3072913, 1378949], [-111522906, -3265928, 2238473, -1416621], [-8216346, -7244684, 1146614, -1576218], [-75929694, 7092984, -2212788, -3942084], [-5822957, 7516394, -2994717, 3727227], [105078000, -40937756, -4297648, -4288524], [129385675, 22160408, 2530909, -2406753], [77505546, -38367884, 3740180, 2039456], [-45859877, -11831518, 309829, -2658999], [334802730, 11059324, 820523, -1270323], [-197680878, -6799456, -6203216, 2187592], [-297495626, -556596, -1000804, 1851128], [-50553541, -24709152, -556349, 1437169], [-63155084, 39192608, 1875204, 5564100], [24608838, -24665568, -3613584, -3548064], [39659974, 7532660, 1619608, -2691348], [49033312, -24229040, 3056626, -2154818], [94755770, -23850408, 6707524, 1985620], [-28083548, -18460600, -1569774, -1549410], [-82396828, -7927140, 2809587, 6550365], [-21089349, -20004848, -4477783, -1331397], [409901754, 6977060, -3133226, -346394], [51917040, 15865528, 5353595, 3496737], [-158459039, 20696384, -3261137, -4125267], [-12570307, -455448, -5409899, -4494305], [32849944, -26669608, 3315199, -844371], [-190969706, 11179824, -249076, -1345684], [460731027, 17471058, -2179761, 298695], [199514456, -28438680, 8724669, 5976327], [211851780, -18420020, 1914563, 4607589], [99261968, 35839936, -2280504, -5879520], [-142190256, 27458044, -453316, -114424], [268985723, 1778712, 475401, -2358333], [427478110, -5869332, 3085046, -208786], [-201576578, -23563336, 2227969, -3499941], [-64602058, 9436244, 6066026, 3302954], [13285374, -46639152, 684378, 3502926], [322125168, -16377104, -3678520, 287928], [91133264, 39028700, -3067576, 2621132], [-101466710, 58025000, 2900254, 1283538], [-198263674, 27392012, 10085534, 598598], [-206412808, -25207512, -2140971, 161535], [-68195196, -5006936, 3577814, -985446], [-40737496, -38093412, 5870973, 4480299], [-95617992, -1012980, -1708242, 292638], [178028817, -17746328, 657680, -7214184], [188862382, 47300340, 513188, -4035376], [255018935, -25578144, -528497, 3274429], [-32960290, -7605624, 2654403, -2642343], [-44335010, -12630352, -1895676, 1319436], [-93134601, -18001448, 2632649, -576669], [271071363, 12645442, -8539927, 373653], [-332028210, 33826452, 3923256, 1725324], [32563780, 23386676, 2808973, 8680803], [-37213339, 54222198, 3564853, 5263813], [37035872, 40036476, -6106002, -5910090], [-180572852, -10225612, 3819084, -4491312], [-22001316, 20919040, 13400588, -1129500], [254600542, -28200732, 565040, -4160284], [-143238505, -55456326, 761887, 4612687], [-12278553, 16043818, -3274372, 2675022], [533931190, 21913400, 89344, 1483704], [-102526374, 30184640, 5636158, 6529258], [153690842, -36381600, 194529, 653547], [-222440297, 35255880, 2122319, 3864533], [-40124233, -7435536, -412839, -2541861], [107867353, -12185098, -4466469, 501759], [-105157719, -53162992, 934045, -3892889], [190757706, 10656016, 800990, 2988090], [195508162, 19273184, -1193915, -1281873], [233173567, -64838046, -4318585, -2914369], [-70684436, 25286592, 882338, 7462118], [30665864, -13510512, 7615275, -1650039], [-144503676, -12490692, -4797156, -6902112], [-323296706, -37151220, -3321622, 5870498], [96952457, -22889658, -1557521, 992995], [206440494, 55014976, -3539437, 967017], [-217519314, 13042172, 3281314, 5252530], [-20037129, 33427232, 2151529, -3658397], [-70029478, -8374896, -12656700, -3920916], [32320802, 33351468, -10559900, 1331296], [-102667763, -62435792, 1442959, 1486165], [163762860, -18656148, -5470440, -979788], [322879666, 8361404, 4470874, 8056314], [85883540, -60682608, 8416924, 9312820]]
