
# q-expansion of newform 169.4.e.f, downloaded from the LMFDB on 25 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 = 169
weight = 4
poly_data = [256, 0, -144, 0, 65, 0, -9, 0, 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, 0, 0, 0, 0], 1], [[0, 1, 0, 0, 0, 0, 0, 0], 1], [[-1296, 0, 585, 0, -65, 0, 9, 0], 1040], [[0, 181, 0, 0, 0, 0, 0, 1], 130], [[116, 0, 0, 0, 0, 0, 1, 0], 65], [[0, 1296, 0, -585, 0, 65, 0, -9], 1040], [[0, 4176, 0, -1885, 0, 325, 0, -29], 2080], [[4176, 0, -1885, 0, 325, 0, -29, 0], 1040]]

hecke_ring_character_values = [[2, [1, 0, 1, 0, 0, 0, 0, 0]]]
aps_data = [[0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, -3], [0, -1, 0, -1, 0, 1, 1, 0], [0, 0, 0, 0, 0, 11, 5, 0], [0, -12, 0, 17, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [18, 0, 1, 0, 17, 0, 0, -17], [0, 0, 0, 0, 0, 32, -13, 0], [0, 0, -92, 0, 0, 0, 0, 12], [0, 0, 26, 0, 0, 0, 0, 96], [0, 34, 0, -13, 0, -34, 13, 0], [0, -5, 0, 51, 0, 0, 0, 0], [0, 22, 0, 63, 0, 0, 0, 0], [72, 0, 215, 0, -143, 0, 0, 143], [0, -121, 0, -139, 0, 121, 139, 0], [-74, 0, 0, 0, -30, 0, 0, 0], [0, 0, 0, 0, 0, 124, 123, 0], [434, 0, 624, 0, -190, 0, 0, 190], [0, -232, 0, -75, 0, 0, 0, 0], [0, 0, 0, 0, 0, 231, 25, 0], [0, 260, 0, -49, 0, -260, 49, 0], [-524, 0, 0, 0, -40, 0, 0, 0], [0, 182, 0, 535, 0, -182, -535, 0], [0, 388, 0, -83, 0, 0, 0, 0], [0, 0, 0, 0, 0, -508, -359, 0], [0, 0, -700, 0, 0, 0, 0, -142], [152, 0, 0, 0, -304, 0, 0, 0], [0, 0, 1076, 0, 0, 0, 0, -140], [0, 43, 0, 391, 0, -43, -391, 0], [-1246, 0, -1010, 0, -236, 0, 0, 236], [0, 0, 16, 0, 0, 0, 0, 344], [604, 0, 0, 0, -567, 0, 0, 0], [0, 0, 0, 0, 0, 202, 1163, 0], [676, 0, -171, 0, 847, 0, 0, -847], [0, 0, 0, 0, 0, 244, -1067, 0], [0, 441, 0, 1053, 0, -441, -1053, 0], [1802, 0, 0, 0, 924, 0, 0, 0], [0, 0, 0, 0, 0, -430, -1305, 0], [0, -902, 0, -859, 0, 0, 0, 0], [-1642, 0, -2756, 0, 1114, 0, 0, -1114], [0, 0, 109, 0, 0, 0, 0, 29], [358, 0, 0, 0, 558, 0, 0, 0], [-2916, 0, -2042, 0, -874, 0, 0, 874], [0, -206, 0, 397, 0, 0, 0, 0], [0, 1395, 0, 1153, 0, 0, 0, 0], [680, 0, 1350, 0, -670, 0, 0, 670], [0, 0, 747, 0, 0, 0, 0, -537], [0, 1737, 0, 1607, 0, 0, 0, 0], [0, 0, 0, 0, 0, -1018, 347, 0], [0, -101, 0, -235, 0, 101, 235, 0], [-1334, 0, 0, 0, -621, 0, 0, 0], [0, 993, 0, -503, 0, -993, 503, 0], [0, 0, 0, 0, 0, -2536, -733, 0], [-3516, 0, -2424, 0, -1092, 0, 0, 1092], [0, 0, -1045, 0, 0, 0, 0, -151], [0, 0, 4476, 0, 0, 0, 0, 480], [-834, 0, -3024, 0, 2190, 0, 0, -2190], [0, 1193, 0, -437, 0, 0, 0, 0], [2830, 0, -572, 0, 3402, 0, 0, -3402], [0, 484, 0, -1145, 0, -484, 1145, 0], [0, 0, 4260, 0, 0, 0, 0, -1056], [0, 0, 0, 0, 0, -1487, 841, 0], [0, -1748, 0, 1415, 0, 1748, -1415, 0], [-584, 0, 0, 0, 2858, 0, 0, 0], [1434, 0, 0, 0, -3345, 0, 0, 0], [0, 2580, 0, 189, 0, -2580, -189, 0], [0, 0, 0, 0, 0, 122, -2161, 0], [1686, 0, 0, 0, 1841, 0, 0, 0], [-7332, 0, -5579, 0, -1753, 0, 0, 1753], [0, -409, 0, 3259, 0, 0, 0, 0], [0, 1650, 0, 3283, 0, 0, 0, 0], [0, 54, 0, 1335, 0, -54, -1335, 0], [0, 0, 5238, 0, 0, 0, 0, 858], [2246, 0, 236, 0, 2010, 0, 0, -2010], [0, 378, 0, 1417, 0, 0, 0, 0], [0, 0, 0, 0, 0, -2721, 1933, 0], [-1730, 0, 0, 0, -4392, 0, 0, 0], [0, 0, 0, 0, 0, -696, 4163, 0], [0, 530, 0, 1721, 0, 0, 0, 0], [0, 0, 0, 0, 0, 5646, 2373, 0], [0, 0, 2793, 0, 0, 0, 0, 6781], [0, 6139, 0, 3131, 0, -6139, -3131, 0], [0, -1417, 0, -4241, 0, 0, 0, 0], [-13098, 0, -11189, 0, -1909, 0, 0, 1909], [0, 0, -426, 0, 0, 0, 0, 2190], [10028, 0, 0, 0, 111, 0, 0, 0], [0, 0, 0, 0, 0, 1276, 1915, 0], [0, 2216, 0, -4041, 0, 0, 0, 0], [0, 0, 0, 0, 0, -1669, 3867, 0], [0, 1734, 0, -4597, 0, -1734, 4597, 0], [-11404, 0, 0, 0, -1008, 0, 0, 0], [0, 2137, 0, -4573, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1070, -3529, 0], [0, 0, 953, 0, 0, 0, 0, 6329], [0, -178, 0, 1067, 0, 178, -1067, 0], [5812, 0, 10206, 0, -4394, 0, 0, 4394], [0, -112, 0, 363, 0, 0, 0, 0], [-11030, 0, 0, 0, 1303, 0, 0, 0], [0, 0, -9068, 0, 0, 0, 0, -4580], [0, 5763, 0, -1415, 0, -5763, 1415, 0], [7172, 0, 0, 0, -1301, 0, 0, 0], [0, 797, 0, 767, 0, 0, 0, 0], [1744, 0, -281, 0, 2025, 0, 0, -2025], [0, 0, -11347, 0, 0, 0, 0, -8085], [-1648, 0, 0, 0, -3555, 0, 0, 0], [0, -4152, 0, -2483, 0, 4152, 2483, 0], [0, 1566, 0, 1497, 0, 0, 0, 0], [0, 4416, 0, 10755, 0, -4416, -10755, 0], [-1772, 0, 0, 0, -5578, 0, 0, 0], [0, 0, 7193, 0, 0, 0, 0, 1559], [-9572, 0, -8438, 0, -1134, 0, 0, 1134], [0, -9088, 0, -97, 0, 0, 0, 0], [0, 0, 0, 0, 0, 4610, 7429, 0], [0, -1534, 0, -5613, 0, 1534, 5613, 0], [0, 0, 0, 0, 0, -1235, 10333, 0], [23590, 0, 19614, 0, 3976, 0, 0, -3976], [0, 0, 0, 0, 0, -6848, -6145, 0], [0, 0, -3994, 0, 0, 0, 0, -11282], [0, 0, -9600, 0, 0, 0, 0, -7682], [-1360, 0, 5668, 0, -7028, 0, 0, 7028], [0, -9636, 0, 1149, 0, 0, 0, 0], [0, 0, -1769, 0, 0, 0, 0, -6007], [7254, 0, 0, 0, 1538, 0, 0, 0], [0, 0, 0, 0, 0, 1986, -9709, 0], [0, -5846, 0, 3389, 0, 0, 0, 0], [-7954, 0, 0, 0, 10266, 0, 0, 0], [0, 0, 0, 0, 0, 1964, 5279, 0], [8656, 0, 3802, 0, 4854, 0, 0, -4854], [-22248, 0, 0, 0, -1238, 0, 0, 0], [0, -1199, 0, 2463, 0, 1199, -2463, 0], [0, -8978, 0, 2993, 0, 0, 0, 0], [0, -729, 0, 8639, 0, 0, 0, 0], [0, 0, 22856, 0, 0, 0, 0, 1704], [0, 0, -10644, 0, 0, 0, 0, -4218], [0, 0, 0, 0, 0, -7068, -7881, 0], [0, -474, 0, 2943, 0, 0, 0, 0], [0, 0, 0, 0, 0, 131, 6303, 0], [0, 0, 0, 0, 0, -5978, -9369, 0], [14234, 0, 4078, 0, 10156, 0, 0, -10156], [0, 0, 2531, 0, 0, 0, 0, 10489], [0, 1522, 0, 8351, 0, -1522, -8351, 0], [0, 4201, 0, -4287, 0, 0, 0, 0], [-5584, 0, -4234, 0, -1350, 0, 0, 1350], [0, -540, 0, 2803, 0, 540, -2803, 0], [0, 0, 12718, 0, 0, 0, 0, 12764], [0, 0, 0, 0, 0, 6446, 10275, 0], [0, 595, 0, -3295, 0, -595, 3295, 0], [-17242, 0, 0, 0, -15436, 0, 0, 0], [-8920, 0, 0, 0, -16580, 0, 0, 0], [0, 1397, 0, -5271, 0, -1397, 5271, 0], [0, 0, 0, 0, 0, -9371, -12973, 0], [0, 0, -3465, 0, 0, 0, 0, 2725], [2552, 0, 0, 0, -13307, 0, 0, 0], [0, 0, -34184, 0, 0, 0, 0, -4164], [0, 0, 18077, 0, 0, 0, 0, -4875], [-33844, 0, 0, 0, 690, 0, 0, 0], [-13260, 0, -8504, 0, -4756, 0, 0, 4756], [0, 0, 0, 0, 0, -2450, 24729, 0], [-12246, 0, 0, 0, -3532, 0, 0, 0], [0, -13027, 0, -12273, 0, 13027, 12273, 0], [0, -2964, 0, 10349, 0, 0, 0, 0], [-2514, 0, -6373, 0, 3859, 0, 0, -3859], [0, -2509, 0, -16547, 0, 2509, 16547, 0], [-30852, 0, -38101, 0, 7249, 0, 0, -7249], [0, -7136, 0, -9529, 0, 0, 0, 0], [0, 10859, 0, 10909, 0, -10859, -10909, 0], [0, 0, -4926, 0, 0, 0, 0, 8902], [19586, 0, 802, 0, 18784, 0, 0, -18784]]
