
# q-expansion of newform 966.4.a.f, 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 = 966
weight = 4
poly_data = [-4, -15, -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], 1], [[0, 1, 0], 1], [[-10, -2, 1], 1]]

hecke_ring_character_values = None
aps_data = [[2, 0, 0], [-3, 0, 0], [4, -3, 0], [7, 0, 0], [21, -12, -2], [20, -2, -3], [2, -5, 3], [23, -10, -4], [-23, 0, 0], [92, 45, 9], [64, 43, 15], [12, -59, 21], [27, 42, -48], [-214, -34, -49], [137, 11, 69], [-185, -14, -65], [131, 138, -7], [129, -111, 20], [340, 43, -50], [-22, 194, 75], [62, 121, -53], [104, -151, 27], [520, -41, 13], [724, 186, -23], [0, -59, 29], [953, 108, 21], [443, -7, -19], [422, -288, 57], [604, 113, 80], [-162, 295, 82], [167, 415, 168], [159, 168, -258], [-367, 168, -46], [-40, -359, -280], [425, 23, 37], [1333, 355, 269], [295, -529, 209], [433, -40, -233], [887, -294, 76], [-396, -17, 113], [-124, -363, -150], [2828, 153, 209], [2341, -193, 69], [-1709, -397, -447], [-856, 406, 121], [493, -22, -291], [-705, 56, 210], [-870, -769, 206], [2586, -1195, -272], [-893, 516, -181], [-3492, -753, 72], [-4664, 197, -184], [-757, 1076, 500], [438, -1232, -78], [-3283, 1351, 249], [-1143, 1392, 40], [188, -1004, -411], [-3910, 1701, 171], [-565, 847, -534], [230, -1740, -442], [1224, 1133, 24], [100, 820, 104], [-1266, 151, 243], [1601, -991, 64], [-1173, -75, 677], [-5974, 1823, 118], [1521, -131, 717], [-5024, 926, -203], [5484, 1303, 21], [-3966, 1103, 410], [-3200, -219, -541], [-1688, 1611, -194], [-3413, -189, 370], [-6036, -851, 489], [-930, 1794, -634], [5036, 1701, 623], [-3036, -1211, 773], [1746, 1942, -528], [-8945, 336, -416], [568, 865, 761], [6678, -501, -276], [2706, 822, 35], [2441, -2075, -356], [-7623, -1755, -685], [410, -3383, -655], [-5264, -2184, -1852], [7470, 783, 706], [-2338, 261, -426], [8722, 867, -404], [-2641, 3292, 900], [1860, -1199, -293], [8074, 1339, 1655], [-1482, 2319, -13], [9080, 746, 1167], [-7540, -2177, 1038], [8972, 1379, 858], [-4499, -3525, -1715], [4642, -564, -1144], [4901, -3779, -991], [-11107, -93, 797], [-12568, -729, -1102], [-3774, -2440, 906], [4042, -2216, 479], [1725, 2795, 2303], [-7326, 4781, 1499], [5062, -88, 548], [2163, 4585, -1800], [-5842, 1392, 2294], [376, 4294, -397], [-18736, -1779, -890], [-62, -2902, -429], [-14584, 5247, 909], [6796, -1434, -1799], [5666, 3772, 423], [-3276, 2563, 1947], [9911, 309, 1716], [-8791, 3049, -636], [16676, 779, -1430], [-10236, -4149, 672], [1078, 2535, -1235], [-2043, -3576, -2160], [-11679, 3744, 512], [-5358, 5434, 2207], [-2830, 2507, -855], [-706, -2606, 2105], [9423, -8292, -477], [-8124, -986, 1257], [-6, -3965, -841], [7033, 3050, 1772], [298, -3448, 3430], [-11690, -5755, 2743], [19799, 2652, 2951], [-1148, 7859, 1400], [16986, -943, -1283], [-7573, 4513, -407], [-4634, 3964, -3118], [18618, -2369, 633], [8779, 4668, -689], [10238, -5850, -1392], [16484, -9800, -2735], [-5988, 1477, 567], [-460, 8100, -1210], [-9889, 538, -3497], [3499, 3874, 513], [21156, -2181, -1197], [18444, -2556, -297], [-17512, 3734, 272], [29281, -1711, -469], [24200, 3970, 774], [8110, 176, 4498], [8037, -4013, -1381], [11386, -2008, -598], [-3126, 126, -627], [-15234, -4616, -445], [-18712, 3475, 288], [11732, 1904, -986], [-7176, 347, -3349], [-7722, 12999, 1710], [12387, 4392, 6218], [-6936, -1140, 1428], [9648, -3442, 1726], [-10895, -3271, -3548], [33920, 306, -1026], [-28532, 2070, 2607], [18945, -10677, -882], [-1440, 8689, -1501], [10767, 31, 2038], [9226, 5933, 3517], [14674, 3617, -14], [-34725, 6229, 786], [18001, 8727, 1542], [-12702, -11076, 1076], [4005, 3017, -6376], [-39022, -1463, -3591], [33726, -7862, -1518], [-22188, 8925, -1593], [36513, -5963, -1980], [-14390, 1475, -6046], [6397, -6516, 3341], [21046, 4905, -2128], [-1277, -9092, -377], [17808, -2364, 4639], [18843, 4480, -905], [-23813, 385, 3960], [-10147, -1750, 4804], [-22724, 326, 4319], [-29505, -7929, -965], [-17958, 53, -3935], [53159, -780, 231], [-23630, -4671, 1407], [11570, 1151, 1270], [-1172, 10745, -2112], [-24540, -4234, 4952], [-43181, -1324, -2834], [-14235, -2731, 1320], [-45902, 756, 967], [-30984, -670, 2423], [16438, 11116, 2650], [-24608, -1726, 5802], [-24655, 3106, -5283], [-43153, -1097, 1195], [7620, 3036, -2244], [-18766, -14323, -722], [36201, 5037, 5500], [-29964, -5851, -7079], [13035, 12299, -4701], [19170, -537, -1853], [-19978, 7323, 5518], [-5316, 2795, 568], [-18656, 3707, -2391], [12543, -2543, -5317], [-29001, 240, 2177], [-3576, -10993, 2901], [-43066, -8498, -1990], [-13062, 15184, -1967], [-51370, 18573, 3200], [-9675, -3546, -5572], [21200, -6890, 4501], [19154, -11417, 3007], [-23708, 5073, 1183], [17235, -17263, -2840], [3573, 7017, 8381], [-19538, 1404, 4021], [-17976, 11864, -392], [-29781, 19384, 6608], [-21625, 2226, -8611], [-29852, -5169, -5731], [32656, -10816, -1576], [-54874, 15072, 3711], [12778, -14989, -9555], [-1007, -8164, 6240], [-3818, 19772, 8421], [28716, 6883, 6106], [740, 1184, 3172], [27853, 12087, -180], [21818, 7516, -5375], [-25511, -9873, -3711], [-38960, -663, 1287], [11182, -14817, 3261], [15594, -5739, -5525], [16355, 13338, -4064], [26744, -8679, 2280], [-3660, -11630, 1984], [54987, 6824, -1074], [27651, -2300, 7526], [-1187, -23995, 1364], [-63630, 10770, -2558], [25898, -20518, -6046], [17936, -11655, -1907], [8263, 1368, 1000], [-11106, -861, -11001], [-17772, 6322, 5338], [-7645, 11280, 3002], [24617, 14308, 13326], [-2480, -17351, 7389], [7498, 9556, -13018], [-44838, 15185, 3041], [-18083, -138, 6876], [-43523, -3139, 4626], [-2888, -4059, -9019], [-72410, -7680, 4115], [43555, 12707, 6683], [40190, -14341, -1250], [-38855, -10814, -4820], [-34259, -8887, -15826], [-3933, 1406, 1774], [18855, -16665, 3619], [-3464, 5217, -1357], [25778, -33275, -3129], [12532, 16951, 7312], [32910, -3607, 969], [-63984, 11805, -5687], [-37892, 10902, -5561], [14602, 19094, 5972], [-46154, 9977, -6379], [-17190, -296, -5188], [43890, 5253, 14175], [9427, -16956, -9094], [3318, 6723, 3543], [-8962, -21101, 2785], [-54351, -8505, -7371], [101050, 8584, -227], [81240, -10407, 2799], [-37868, -7393, -6017], [2006, 4223, 8940], [15864, -10885, 3877], [-82660, 9033, 5265], [-18565, -13349, -8557], [-1290, -28950, -8687], [1050, -21874, 4690], [54435, -3249, -3284], [-32036, 3896, 11531], [7704, -4578, 459], [-1234, 3029, -6639], [79166, 12126, 11958], [2114, 34399, -2531], [12132, 14860, -4736], [-30763, -2025, -8632], [-33823, 16096, 7660], [-27728, -7979, -6951], [85200, 3084, 5841], [-50390, -18556, -8488], [-18220, -11857, 5273], [13588, -27069, -5044], [-75162, -838, -5218], [-10085, 3238, 9248], [64512, 19109, -10388], [51395, 25370, -7232], [54315, -28789, 733], [-37520, 362, 10027], [83993, 19978, -5610], [54032, 15551, -1423], [73731, 1778, 6601], [26858, -1009, -8285], [11341, 20600, 12924], [-16519, -29585, -241], [57113, 25998, 406], [37550, 15061, 13347], [70383, 11316, 5630], [72964, -1304, 10214], [82979, -20353, -4597], [41924, -28890, -4163], [58589, -458, -3249], [16809, -27750, -16570], [37329, -36758, -1774], [59597, -6680, 1597], [-39674, 3407, -17699], [-22196, -12333, -12486], [56307, -4799, 3535], [-82335, 39205, 9855], [23350, -26510, -7514], [-15142, 17105, 4671], [30994, -9664, -6717], [68781, 7666, 9077], [13312, 5448, -16210], [-4785, 27551, 6815], [45470, 11940, 2814], [7314, -2198, 21528], [-44690, -23719, 3162], [-71004, 419, 6032], [-11192, 20177, 14641], [10517, 9761, 3221], [-50227, 20403, 1086], [-15224, 4833, -12759], [14179, -35273, -3025], [-57192, -12294, -10883], [-17368, -21137, 3716], [21091, 340, 12117], [39430, -4267, 13778], [-33056, -34333, -24057], [18376, 20208, -14153], [30967, 13082, -8822], [-35734, -15539, 3979], [34527, -12864, -5845], [78884, 12605, -3305], [54345, -45145, -10313], [108082, 4368, 15606], [-38048, 10383, 3679], [118808, -1581, -5237], [48476, -25997, 2265], [70918, 9295, 5777], [37337, -4104, -650], [8986, -13045, -7587], [-15635, 10703, -14545], [-29992, 10056, 5242], [-28191, 1635, 3231], [-22459, 15897, -13602], [-108718, 41854, 2608], [-67676, 16862, 15381], [148006, -26130, -4929], [16582, 4119, 13891], [73838, 7614, -2562], [-39215, -15671, -1869], [-104577, 8049, 10649], [21316, 25077, 7561], [69912, 17439, -12436], [-4099, 27068, -14709], [-103383, 16851, -9911], [-116016, -2322, -8538], [-123974, -25411, 5729], [74854, -35047, -13843], [189020, 2330, -2403], [-101885, 30309, -9465], [97206, -53260, -10343], [-31300, 32137, 5282], [80009, 12597, 18366], [17481, -38355, 8246], [73500, -49038, 2614], [-21950, -44223, 2837], [-131584, 26822, 13504], [-23622, -17711, -12873], [59341, 24110, 5943], [62582, 13212, 8540], [54340, -1592, 12518], [-43441, -10381, 17916], [77134, 19287, -9354], [-70969, -2890, 7336], [25636, -35215, -4819], [-35356, -39734, -18415], [-5576, -14675, 5903], [22426, -17061, -9729], [121666, 25996, -10987], [-98138, -27948, 16798], [-75344, 48218, -2301], [-69487, -25071, 13624], [-69820, 130, -22835], [-2240, 36200, 3984], [-5506, -28756, -24334], [63096, 752, -13396], [15016, 6423, -7100], [111952, 11278, -3163], [5358, 15102, -24336], [-174533, 40953, 11197], [212566, -10808, -665], [39852, 7440, -10827], [15006, 22376, 31204], [-80940, -41925, 24927], [62386, 8589, -4495], [142598, -299, 18547], [42316, -43324, -10818], [96420, -23555, 5887], [-28985, -20056, -6124], [-123438, 17627, 9850], [-103702, -6576, -3325], [98446, 46336, -15067], [42317, -52001, -14635], [65763, 34485, 18054], [191398, 16104, 20882], [-22350, -8273, -10642], [155885, -14215, -2060]]
