
# q-expansion of newform 354.4.a.f, 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 = 354
weight = 4
poly_data = [14, -17, -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], [[-1, 3, 0], 1], [[-12, 0, 1], 1]]

hecke_ring_character_values = None
aps_data = [[-2, 0, 0], [3, 0, 0], [-9, 1, 1], [8, 1, -2], [-3, 2, -4], [-5, 0, 4], [9, 4, 7], [41, -1, 2], [1, -7, 10], [-46, -12, -17], [214, 2, -9], [205, 14, -3], [98, 9, -20], [-79, -14, 28], [48, 28, -35], [93, -33, 27], [59, 0, 0], [324, 6, -25], [137, 47, -49], [409, -2, -36], [548, -16, 101], [607, 8, 102], [-78, 5, -10], [452, -16, 9], [401, 39, 3], [-142, -79, -63], [552, -116, -54], [-511, 5, 24], [109, 73, 62], [-361, -5, -49], [-443, 103, -85], [-854, -14, 12], [-745, -16, 102], [-703, -93, 9], [431, -132, -149], [-654, 208, 123], [-1097, -69, 139], [744, -42, 143], [-918, -210, -117], [354, 91, -248], [-605, 198, 194], [1004, -30, -249], [1955, -187, -93], [408, -111, -73], [-2490, 42, -96], [1702, -314, -325], [-849, -330, 335], [900, -259, -29], [-715, 166, -511], [-1630, 183, 186], [2786, 26, -72], [529, -237, 503], [-4764, -161, 33], [2019, 181, 451], [660, 255, -171], [-1972, 245, 240], [-397, -86, 644], [1755, 40, -12], [-3279, 89, 115], [2216, -479, -55], [-1233, 256, 255], [-239, -517, -284], [-1524, -66, 326], [1963, -298, 169], [-2117, 51, -218], [1853, -381, 79], [-2598, 500, -410], [3767, -217, 818], [-1056, -532, -175], [295, -44, -334], [1013, -165, -614], [4980, -315, 627], [1175, -271, -937], [-6399, -189, -706], [773, -819, -663], [1545, -124, 1184], [2926, -96, 272], [-8043, 285, 329], [2715, -759, -720], [394, -44, -1276], [4598, 407, 741], [4691, -352, -70], [2424, 66, 165], [1929, -24, -1285], [6141, 1066, -351], [-4855, 20, 891], [-2385, -442, 290], [-5850, -218, 51], [6969, -489, 312], [2299, -51, 1726], [8688, -179, -161], [1881, -41, 796], [243, -360, 797], [6340, 566, -863], [2291, 661, 637], [3996, -1110, -1311], [-2496, -318, 663], [-6054, -188, -851], [-3175, 287, 1199], [6341, -366, 750], [-2615, 1009, 926], [9466, 1402, -570], [-10531, -1257, 331], [2784, -1158, -1563], [-2007, -345, -55], [-7517, 38, 522], [10167, 282, -1194], [-3182, 1100, -1355], [700, 2041, 669], [-9221, -71, 446], [9915, -580, -1304], [-9364, 567, -597], [2495, 880, 305], [-4547, 1811, 849], [10209, 142, 888], [-13217, 1495, 1449], [-8113, -1183, 752], [1556, 340, 1568], [-9750, 198, -1137], [9617, -1217, 452], [2006, -888, 141], [-9674, -516, 652], [-468, 1272, 234], [1961, -1812, -1448], [9230, -1609, -781], [3900, -177, -42], [-3918, 924, 2846], [2337, -2177, 1066], [19838, -73, 209], [-1957, -1725, 1413], [-6409, 366, -477], [5237, -289, -690], [-3970, 2344, -566], [-889, -603, -234], [2731, -189, -1297], [18859, -165, 658], [-2954, 1684, -66], [2590, -1728, 2062], [5298, 2789, -19], [30603, -51, 2094], [2272, -1569, 3379], [726, 499, 820], [30469, 943, -973], [-26927, 625, 1431], [8224, 2224, -1321], [-18631, 689, -1767], [129, 2003, -68], [-23645, -249, -181], [26114, -1350, 978], [-16551, 847, -1490], [-15414, 898, -1338], [21270, 56, 4334], [-25792, -1524, 1344], [-17631, -2475, 591], [-7293, -1031, -1755], [16178, -1103, 4172], [4822, 1640, 126], [-2439, 2411, -3211], [-7379, 1325, -639], [-24233, 1307, -1985], [12988, 656, -1943], [-7084, -1791, -4205], [-583, 2767, -1406], [4049, 77, -2352], [-1043, -3269, -429], [-8155, 485, -1311], [42371, 889, 580], [-38054, 926, -1281], [-5676, -1464, 920], [-21738, 231, -4143], [-40753, -1319, 365], [31158, 511, 753], [-21403, -2446, 2193], [12953, 3235, -3035], [10864, -2485, 2433], [-307, 506, -1500], [-22331, 65, -693], [40130, 349, 17], [1375, -1543, -4434], [-3850, -800, -2648], [-1682, 2066, -150], [-20020, -2494, 3162], [3911, 1164, 558], [-4862, -620, 3246], [-27039, 1656, 2994], [-3595, -1711, -834], [-3138, 1604, -3158], [-15268, 427, -4649], [27485, 29, 2285], [-10345, -1153, 2142], [-26319, -627, 953], [-7037, 2462, -5456], [28188, -2495, 1863], [1544, 1922, 4131], [-50768, 2794, 1878], [-17781, 1935, 4350], [30333, -4403, -3732], [-18250, 123, -1482], [13256, -2560, 1335], [-35571, 3367, 4510], [-20128, 2786, -4338], [-8591, -4949, 4127], [19835, -5741, -5024], [38627, -1481, 2278], [8954, 3766, -760], [28238, -2303, 6206], [11375, 433, -4655], [3949, -1300, 145], [21597, 2623, 3904], [-35356, 1595, 1535], [-31355, -1533, -284], [37845, -1761, 1605], [56479, 1212, -1403], [19466, -3238, -4554], [-26543, 756, 3728], [543, -2373, 722], [28615, 5554, -3028], [22810, 3211, -1740], [57003, -225, -330], [30647, 3761, -2571], [-869, -4692, -1502], [22437, 2405, 5803], [36836, -3074, 3026], [-6040, 1692, 3261], [-31668, -1743, -3399], [-38154, -1247, 312], [36903, -1953, 9570], [13650, -502, 1964], [43328, -3962, 406], [-50689, -1891, -5886], [49422, -303, -1942], [-40857, -3202, -2300], [61333, 367, -1864], [1647, 141, -2271], [36918, -3826, -1142], [41325, 7023, -2901], [26307, 6699, -895], [-62, -1188, -2059], [16391, 2501, 5997], [10508, 2041, 7712], [9985, -3149, 1857], [-29736, 889, -4845], [-24569, -1084, 1638], [-21980, -7026, -680], [1989, -1710, -4191], [13982, -3027, -536], [-4703, -2269, -5055], [-20749, -4734, -4220], [32280, 4370, 1093], [-70883, -1964, -1164], [-77573, 2175, -3878], [27829, 2425, -1608], [2236, -5948, -1935], [-39571, -5004, 354], [-89569, -1893, -911], [-19637, 3685, -3369], [1831, 1739, 8439], [-73544, 560, -3894], [-12447, -1331, 4873], [13973, 3612, 9621], [-19447, 1383, -5109], [-34219, 7295, 1635], [19666, 5626, -5248], [15954, 7440, -8518], [6149, 1209, 8659], [-66128, -275, 3563], [-37963, 7739, 1008], [43024, 3736, -3342], [26113, -6411, -1211], [16117, 4345, 639], [71082, -5528, -2604], [-11074, -1700, -2771], [23363, -399, 9972], [-33035, 3478, -5896], [6773, 6682, 2212], [-375, -4259, 11550], [1042, 2680, -6777], [-51243, 4713, 707], [-35719, 2775, -8205], [-50699, -1985, 8499], [10013, 2052, 5986], [35102, 5714, 1820], [138060, -492, 2994], [-21778, -7317, 8373], [34817, 1135, -2609], [15238, 9022, -549], [65359, -6231, -2093], [-10699, -3227, -754], [46075, -1741, -6993], [3286, 7540, -3516], [-27373, -4248, -11360], [-38110, -592, 2154], [-64505, 2923, 1770], [62569, 5092, 2268], [-45963, -4269, 6173], [-53717, 7846, -1086], [-64092, -7603, 6550], [-29391, -2695, 683], [22722, -1701, 4452], [-27603, 11435, 7711], [124, -5910, 6853], [20063, -2252, 10988], [-39579, -1961, -12909], [-60894, 7981, 2191], [85248, 2872, 7992], [39015, -5603, 1101], [10107, 5739, -2649], [64574, -2959, 8984], [-70720, -2458, -12939], [32982, 9808, 4998], [40487, -156, -9278], [-69265, 7637, 300], [-1455, 4304, 2624], [57074, 8169, -3234], [-341, 6328, -141], [-26043, 8311, 11943], [-3726, 5210, 2801], [-45961, 8672, 8172], [-81256, -5030, -5432], [101823, -768, 11802], [-73130, 2044, -19792], [5002, 7248, -4694], [-12206, 6838, 11199], [-16470, 8350, 6306], [-73617, -425, 6301], [-24578, -3922, 2130], [26245, -1880, -190], [17198, -7960, 2162], [90640, -5008, 7024], [14162, -13164, -3329], [36313, -618, 7951], [-13972, 1478, 5256], [32112, -414, 4946], [-25755, -5185, -10273], [-13321, 2809, -3842], [50244, -7256, 7813], [53464, 3592, 13805], [-37698, -1146, 10662], [88950, -166, 9691], [90405, -1433, 609], [20282, 11570, -2344], [28255, 11651, 5983], [-36514, 9093, 25], [26608, -792, -4604], [-23070, -4179, -6843], [2239, 3014, 2512], [-38481, -3174, -14020], [7160, -6102, 978], [26691, 461, 2615], [60341, -8515, 1137], [17891, 6333, -5400], [-5212, -11565, 7140], [-109648, 6278, -6165], [69022, -6238, 16923], [-138274, -538, -7843], [-42028, -14008, 11904], [17070, -4300, 4940], [-91946, -11294, 4107], [-57649, 8343, 13822], [-20767, -8998, 11730], [55725, 2658, -82], [-77947, -10776, -3269], [105564, 2443, -347], [-56195, -6088, 8230], [-76470, -12154, 2641], [3464, -1546, -20071], [106588, 2293, 10263], [8944, -9053, -12481], [-17626, -10160, -116], [-20080, 10220, 267], [-6285, -570, -2938], [-214951, 1923, -1697], [85649, -1333, 10380], [-14308, 14040, 5430], [-16792, 7828, 9487], [90991, -5723, 13986], [-103869, -5317, -5980], [79362, 3388, 4845], [-92402, 1330, -18882], [36889, -4967, -17347], [-4232, -4102, -11576], [-12316, 11348, -3897], [-149159, 3140, -5637], [-39885, -7303, 11939], [-45993, 1143, -631], [235189, 229, -1947], [92025, 2056, 21000], [-17040, 2444, -6173], [166431, 861, 9980], [129171, 697, 553], [-100133, -5753, 10913], [107803, 3946, 17235], [16713, -3220, -10375], [-112702, -5913, -2145], [-44210, -4122, -1963], [-105428, -9898, -4020], [145320, -1696, 7363], [-76434, 4176, 18144], [97297, -5521, -8664], [-5427, -2753, -3425], [-32755, -13429, -16363], [-40790, 13714, -1938], [72622, 6647, -16029], [-121668, -119, -2840], [148723, -10717, -2348], [42397, -1915, -14931], [11066, 17204, 8294], [-54262, -10871, 3737], [62709, 2286, 12902], [-9293, 12109, -7803], [17773, 8474, 6861], [-44696, -5406, 10697], [83207, -7591, -18012], [88081, 9131, -13143], [-60083, 18346, 18800], [3960, 9580, 4864], [-7144, -3504, 10144], [10346, 12670, 10555], [190165, 1777, -3651], [205490, -3503, 4754], [154621, 917, 9046], [-153305, -4343, 1397], [-49043, -809, 9864], [174612, -6652, 7034], [67272, 11073, 3599], [60744, -6636, 3108], [-40071, 10535, -27190], [101566, -7525, 6658], [-132200, -20858, 12305], [14565, 503, 18941]]
