
# q-expansion of newform 507.4.a.m, downloaded from the LMFDB on 20 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 = 507
weight = 4
poly_data = [78, 24, -25, -2, 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], [[-13, -1, 1, 0], 1], [[15, -19, -2, 1], 1]]

hecke_ring_character_values = None
aps_data = [[0, 1, 0, 0], [-3, 0, 0, 0], [-1, -1, -1, 0], [-4, 1, 0, 1], [8, 4, -1, 1], [0, 0, 0, 0], [15, 19, 0, -1], [28, 6, -7, 1], [28, -4, 1, 3], [43, 11, 1, -6], [-20, 53, -7, 0], [15, 21, -2, -1], [-285, 43, 0, 3], [84, 57, -14, -1], [-20, -8, -47, 3], [47, 37, 23, 2], [72, 10, 24, 14], [-245, 26, -31, -3], [-348, 129, -14, -1], [304, -76, 49, 11], [335, -194, -24, -2], [-176, -21, -7, -2], [-32, -138, 1, 5], [478, -146, -50, -28], [506, 71, -63, -22], [675, 151, -99, 6], [-236, 41, -34, -45], [152, -208, 23, -7], [-310, -101, 33, -2], [407, -31, 2, -53], [-416, 219, 89, -26], [200, 406, -46, 20], [-161, -189, 70, 9], [-220, 149, 21, -4], [-725, -287, -71, 40], [-1164, -442, -17, 43], [443, -270, -45, -21], [-348, -369, 31, 20], [1652, -60, 26, 42], [718, 508, -92, 4], [-280, 350, 167, 119], [-85, 489, 84, 69], [384, 38, -144, 78], [323, -296, 66, -74], [-670, 286, -190, 16], [-3136, 515, 102, -19], [396, -97, -11, -146], [1328, 0, -336, 0], [-1684, 686, 263, -17], [-1030, 44, 0, -100], [2758, -544, -188, 16], [1420, 446, -29, 31], [131, -557, -135, 70], [-1548, -132, -234, -134], [15, -401, -186, -183], [3564, 66, 51, 95], [3570, 690, 42, -56], [-2656, -667, -291, 68], [247, 1129, 170, -97], [-1873, 521, 2, -9], [-1272, 77, 76, 145], [-2473, 335, -115, -2], [-1252, -1291, 174, -1], [-1256, 34, -287, 57], [-30, 437, -773, -50], [3279, -375, -189, -126], [3940, -687, 89, 100], [2787, 510, 220, -70], [2256, 374, -399, -27], [6650, -19, 519, 50], [-7741, 25, -262, -77], [-2664, 1134, -603, -99], [-552, 1415, -572, 139], [2071, -1430, -751, -19], [1984, -1625, 161, 74], [5236, -604, -128, -184], [2143, 41, 265, -188], [-4246, 1089, -177, 78], [-1753, 827, -574, 233], [5223, 422, 10, 52], [4960, -252, 256, 76], [-1229, 992, 521, 171], [3308, 474, 95, -189], [5631, 100, 370, -150], [792, -1795, -164, -311], [4612, -2308, -290, -110], [-1390, 1244, 308, 184], [-9549, -486, -134, -256], [-2289, -251, -147, -316], [2936, 123, -198, -231], [-688, 1492, -1, 113], [-10468, 972, 50, -198], [-1580, 1614, 185, -95], [2268, 784, -363, 279], [-9980, 288, -802, -182], [1636, 648, 403, 165], [-2385, -853, 405, 106], [-3733, -1389, 92, 379], [660, -14, -101, -333], [-1013, 88, 1121, 59], [-1432, -473, 126, 505], [-2053, 905, 1121, 332], [-12640, -2798, 812, -174], [2810, 820, 1748, -140], [-11396, 310, -1423, -343], [8927, 1347, 609, 150], [4284, 606, -282, -4], [-7161, 3213, 282, -21], [-9748, 2246, -1594, -588], [-10785, -33, 745, -22], [-7204, -2496, 690, 102], [347, 3814, 45, 61], [-9173, -783, -692, 453], [-5520, -1023, -995, -16], [1396, 243, 155, 148], [-4561, 3393, -820, -115], [6088, 3803, -493, 516], [-7256, 538, 694, -52], [10990, -3990, -626, 136], [-6280, 1148, 68, -440], [3603, -1786, 343, 43], [2479, 3396, 734, 358], [-3930, 718, 1290, 208], [4540, 1406, -1754, -124], [-2560, -2317, -1356, -193], [-8830, -4814, 866, -544], [9155, 1732, 1149, -461], [-13492, 2338, 1676, 414], [-6684, 5605, 670, -465], [4887, -1260, 277, 11], [-5912, 4820, -1108, 96], [21832, -4906, -452, 162], [-2540, 598, -745, -733], [-18258, -1792, 352, -440], [3894, -618, -1602, 4], [414, 512, 1420, -548], [-7086, -668, 1584, 68], [-4380, -2537, -965, 792], [13234, -1550, 2206, 496], [-4405, -4921, 1226, 17], [-5348, -547, -1735, 120], [5610, 976, 48, -864], [-604, -1032, -2178, -750], [9596, -4172, 698, 1058], [-18545, 3708, -607, -665], [9168, -7486, 342, -120], [-8101, -2362, 147, -889], [1187, 4797, -1102, -461], [-24892, 1705, -384, -359], [4308, 3820, -333, 13], [-20033, 1037, 746, 219], [7343, -477, 2060, -225], [-7016, -3711, 929, 340], [1016, -3758, 824, 118], [6016, -3512, 1574, 1034], [-7232, -7300, 34, 334], [-22884, 2856, -518, 950], [-6933, 1943, -1422, 237], [-669, -233, -1739, 750], [29970, -5648, -1416, -872], [-27724, -932, -1714, 22], [18318, 1520, -2520, 384], [-32248, -970, -69, -337], [-4416, -2912, 492, -256], [-12569, -633, 1042, 637], [22808, 2898, -1144, -86], [-7696, 2630, -1479, -895], [20611, -4662, 659, -125], [3586, 4711, -1111, -742], [-17553, -1201, -2721, 596], [-19924, 7162, 947, -109], [-3185, -5259, 866, 691], [24244, -1634, 1588, 238], [-4025, -3570, -172, -470], [-14228, -7672, 86, 786], [-1469, 6957, -782, -1149], [-11948, -1799, 1466, 695], [1311, -5, 1215, -1220], [-6328, 8241, 729, 828], [-23222, 453, 1619, -122], [42624, 550, 973, 621], [12192, 3974, 882, 308], [7643, -1076, 381, -821], [21050, 340, 164, 596], [-47904, -184, -573, -371], [26215, -4425, 1219, -732], [11690, -2513, 1341, 1366], [-5920, 6024, -54, 1278], [19355, 5354, -2778, 164], [26032, 366, 1399, 579], [-22377, 1650, 2068, -394], [-4992, 1098, 45, -707], [348, 597, -1796, -583], [24402, 4624, -1032, -60], [7052, 1180, -2395, 663], [-8766, 4294, -2550, -612], [9291, -4928, 4432, 264], [22703, -428, 2871, 1345], [-28445, -4955, 2632, 369], [-13532, 7146, -3434, -316], [-833, 14133, -623, -396], [-8900, 10993, 2039, -994], [-10565, 2488, -1723, 1463], [-3321, 134, -1904, 670], [7028, -84, -199, 1167], [7363, 3949, -1949, -190], [-17352, 4277, 4720, 565], [-7968, -4968, -4752, -692], [13075, 4111, -2918, 893], [2764, -7204, 2654, 1734], [-13529, -5412, 5102, 214], [10210, 3514, 1198, 108], [22288, 2473, 206, 179], [35800, 9524, -323, 755], [20028, 2192, 4530, -618], [-25937, 11371, 155, 140], [-25216, 9049, -2463, 196], [20755, -6763, -1724, 413], [6204, 650, 6624, -194], [-45622, 5326, -526, 1316], [7607, -5668, -1773, -835], [31532, 8883, -2229, -780], [17911, -7125, -248, 1463], [-32592, 11251, 4177, 102], [33572, 1150, 2105, -1871], [20219, 5838, -2391, -1287], [-16957, 14773, 2996, 505], [-4112, -2800, 2680, -1132], [-28372, 4063, 2691, -896], [-57408, 12508, 2568, -8], [19835, -4652, -2895, 607], [-16940, 307, 191, 752], [-18132, 1828, -1964, -768], [10143, -2955, 8256, -75], [38684, -4745, 6357, 598], [-18316, 4986, -6610, -1604], [-27638, 15803, -415, -42], [2247, -7133, 603, -3180], [-30856, 1876, -466, 1746], [19256, 6144, 1049, 531], [12880, 2990, -5837, 459], [-50664, 2074, 3763, -453], [-132, -122, -4241, -1005], [1435, 8646, -3127, 1297], [17987, 3461, 6764, 961], [8664, -4480, -4320, -892], [11520, 10721, -569, -458], [924, -2986, -1218, 784], [68028, 6485, 436, -479], [-6056, 4982, 1753, -159], [6178, 12879, 1085, 2734], [-48722, 524, -260, 240], [-12748, 3290, -5764, -1530], [-5569, 4954, -3864, 658], [39958, -7904, -2864, 1152], [-9312, -4304, 3975, -991], [20878, 14168, -4720, 1272], [18908, 17170, 1605, -1079], [2522, 1218, -2266, 52], [-14201, 8691, -997, -716], [1588, -2592, 6968, 1576], [16552, 892, -1376, -664], [-26205, 8844, 3727, 1841], [54739, -1426, 2249, 1113], [-21057, -19845, 2832, -869], [-43352, 1305, 2324, -1115], [8838, -13908, -3636, 112], [-857, 1609, 2320, 3573], [-22972, -4330, 453, -2779], [42531, 3501, 2133, -2204], [43619, 4270, -1371, 349], [25992, -15887, 847, -498], [-17601, -7493, 5623, 1464], [12368, -1152, -2562, 1962], [-15222, 14259, -1019, 1514], [10380, 3294, 1615, 1907], [22584, -8002, -1788, 186], [-16093, -4655, -4626, 1843], [25063, -6484, 572, 2688], [-42924, -74, -993, 239], [34596, -20072, -4305, -399], [1656, 8240, 7360, -1304], [-41948, -8590, -608, 1846], [-27101, -8998, 6791, 855], [19136, -5834, -3237, -4121], [20548, -7876, -3269, -959], [19755, 29310, -146, -2032], [15619, -3965, 3583, -864], [-89004, -3225, 2644, -1333], [4035, -727, 9108, 909], [86402, 6150, -5194, 432], [4404, 20040, 3081, 703], [-23785, 13319, 1874, 737], [-12176, -9394, -3968, 50], [116698, -5255, -1477, -94], [-14193, 709, 1473, -2516], [9648, -6784, 4900, 916], [-20421, 13695, -471, 2150], [-2044, -2750, 3422, 604], [54576, -411, -4742, -1693], [62307, 15268, -6098, 846], [-7697, -6001, 7915, -764], [-52728, -12878, 979, 2979], [50456, -6066, 6620, -230], [76356, -3807, 2998, 1691], [74103, -2230, -4550, 568], [35660, 1704, 4463, -695], [-19281, 8553, 12046, 1763], [-48048, -15242, -738, -2700], [-14985, -7515, 2482, 1235], [-19940, -4402, 2869, -1711], [18670, 16988, 460, -2700], [23323, 7931, 2410, -2543], [13592, -16349, -9660, -833], [38316, -21372, 1929, 2275], [-28977, -25358, 8404, -1458], [63016, -8062, -3221, -2737], [-64820, 3184, -7187, 2367], [47154, -10169, 4561, 210], [-73113, -939, -102, -49], [-14368, -7905, -1770, -1311], [-24642, 781, 4015, 882], [-9721, 3921, -5761, -3490], [-44192, -6737, 2072, 503], [72294, 12404, -792, 728], [-26717, 29086, -3826, -112], [-88848, -1461, -2576, 3563], [-23028, 19302, -1643, -715], [27420, 18524, -8397, 2557], [42567, -39189, -2685, 884], [-17809, -22611, -7782, 2211], [-36681, -9969, 1527, 3996], [-50020, 21431, 3564, 179], [34336, 18810, 133, -351], [32436, -4121, 5854, -1647], [-35576, -476, -6305, -5211], [65943, -10294, -1757, 547], [52774, 5804, 3940, -684], [-33841, -18285, 3879, -1152], [29640, -9427, 4939, -2810], [18862, -2732, -1504, -964], [-92369, 16519, -11306, -5099], [20931, -13389, 2961, -5682], [-96344, -8655, -6568, 3457], [-13966, 31468, 1388, -2616], [77660, 2996, -787, -1053], [56899, -40556, -1861, 701], [25928, -3232, -13764, -1564], [-1968, 3584, 3129, -653], [-40842, 20690, 4614, -504], [47252, -12195, -11070, -885], [-29426, 23504, -1276, -4500], [86003, -2167, -7381, -310], [-41132, -1575, -10054, 1111], [101675, 7477, 168, 3373], [-97081, 3903, 6086, -791], [68024, -13590, 4055, -3769], [16100, -13616, -1492, -2292], [1423, 9531, 5368, 3503], [-16444, -3038, 2285, 3509], [-54509, -8879, 4184, 2177], [-31749, -13801, 2562, -2423], [-81948, -9422, -1512, -2742], [50176, -28534, 2848, -366], [-81272, 20897, 9401, 2556], [-32222, -16331, -5101, -4234], [3258, -2706, -8814, 3196], [30168, -13571, -10571, 1044], [-68749, 22683, -1845, 540], [-42896, 18220, 5470, 4414], [-48316, 8851, 16776, -653], [-21596, -5464, 2065, 3871], [-47037, 10117, -7689, -242], [-33680, 6866, 12263, 87], [76051, 8865, 3908, -6323], [-112136, 20766, -3323, -2635], [44800, 8830, -4355, 721], [-18642, 34077, 6775, 98], [-29801, 1533, -5816, 4857], [-22857, -33030, 2182, 2636], [9098, 16766, 7274, 324], [-99321, 17205, 6090, 4087], [-42380, 21298, 5249, 581], [-13418, 5408, -2912, 4180], [28140, 17925, -7643, 2348], [756, 4890, -2835, 3389], [34132, 23230, 863, 1475], [-2662, 663, 20277, 318], [113956, -16901, 1925, -2206], [-133500, 18290, 7134, 1356], [10099, -18113, 7547, -6280], [-26149, -16145, 6827, -440], [135776, -5650, -1117, 243], [36264, 19730, -7289, -4241], [-21068, 43008, -3188, -4656], [-102694, -33025, 57, 266], [60832, 4030, -1183, 665], [-112262, 18200, -10136, -3596], [-4868, -32552, -628, 3596], [-99837, 13253, -11043, -2456], [-68738, 26261, -12085, -2298], [-90826, 26204, -11656, -2488], [-4892, 22349, 6671, -2670], [31611, 31349, 120, -1051], [-62545, -32107, 10811, -2162], [-15520, 24335, 3234, 797], [-51322, 23915, -9915, 410], [43271, 13203, 896, 2507], [53852, -15391, -7704, 1745], [21692, -15964, -8680, -5344], [-12093, 40380, -7532, -2560], [-3209, 45993, -3455, -1256], [29380, -30016, -5381, -1495], [-37652, -18588, -7420, -3200], [65367, -23594, -6620, 3258], [-173305, 149, -733, -966], [-104668, -8924, -4522, -3102], [-1892, -6573, -8176, 4363], [125786, 6190, 3650, -2168], [55932, 39460, -1608, -3508], [4467, -14609, 13827, -816], [-73857, -182, -4475, 2025], [95820, -27402, -4659, -4375], [11100, -21786, -9417, 495], [46410, -11043, 3103, -7294], [18751, 17231, -12407, 4190], [138436, -15806, -3476, -558], [-195221, 12163, -1376, -2073], [-27028, 6431, -7194, 1169], [63736, -21298, -7766, -5848]]
