
# q-expansion of newform 245.4.e.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
    R = PolynomialRing(QQ, "x")
    f = R(poly_data)
    K = NumberField(f, "a")
    betas = [K.gens()[0]**i for i in range(len(poly_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 = 245
weight = 4
poly_data = [1, -1, 1]

# The basis for the coefficient ring is just the power basis
# in the root of the defining polynomial above.
hecke_ring_character_values = [[197, [1, 0]], [101, [0, -1]]]
aps_data = [[0, 4], [-2, 2], [0, 5], [0, 0], [-32, 32], [-38, 0], [-26, 26], [0, -100], [0, 78], [-50, 0], [108, -108], [0, -266], [22, 0], [442, 0], [0, 514], [-2, 2], [-500, 500], [0, 518], [-126, 126], [412, 0], [878, -878], [0, -600], [282, 0], [0, 150], [386, 0], [-702, 702], [0, 598], [0, 1194], [550, -550], [1562, 0], [1846, 0], [0, 2208], [2334, -2334], [-700, 0], [0, -2050], [-1852, 1852], [2494, -2494], [0, -2762], [3126, 0], [0, 78], [1300, -1300], [1742, 0], [0, -3772], [358, -358], [-2214, 0], [2600, -2600], [-1168, 0], [-6478, 0], [-646, 646], [0, -3750], [0, -1482], [1400, 0], [-3022, 3022], [-1248, 0], [0, -2106], [3638, -3638], [6550, -6550], [0, 4388], [-546, 546], [-6858, 0], [-9282, 9282], [4842, 0], [-2594, 0], [-7332, 7332], [0, -1562], [0, -1426], [0, 4008], [8866, 0], [1714, -1714], [1150, 0], [4398, -4398], [0, -1800], [5874, -5874], [0, 2078], [7900, 0], [0, 7518], [1950, -1950], [0, -13786], [0, -6402], [-11150, 11150], [-13700, 0], [-5438, 0], [-7692, 7692], [-1118, 0], [0, 2600], [0, 11958], [-17050, 0], [0, 9494], [-11418, 0], [7962, 0], [0, -6526], [-17400, 17400], [-1166, 1166], [7072, 0], [0, -100], [2602, 0], [0, -11150], [3638, -3638], [0, 2078], [0, -5622], [16486, 0], [-11706, 11706], [25038, -25038], [0, -17550], [-10712, 10712], [13654, -13654], [14166, 0], [0, -17842], [17600, -17600], [27302, 0], [0, 3794], [13238, -13238], [-11574, 0], [-8300, 8300], [-7508, 0], [27378, -27378], [1842, 0], [10114, -10114], [0, -10402], [7100, 0], [7118, -7118], [-31278, 0], [0, 30054], [4518, -4518], [0, -29272], [-5798, 0], [0, -8950], [0, -7800], [-8554, 0], [0, -2882], [-18700, 18700], [12242, 0], [0, 31148], [-7694, 0], [0, 4518], [-39550, 0], [-22122, 22122], [16634, -16634], [27586, 0], [-3850, 3850], [10032, 0], [0, -20562], [-10322, 10322], [8846, 0], [25350, -25350], [46000, 0], [-16998, 0], [26494, -26494], [0, 21500], [0, -25762], [0, -30546], [32942, 0], [-27118, 0], [0, 38634], [1794, -1794], [41732, 0], [0, -29200], [0, 48650], [-11334, 0], [31178, -31178], [0, -4686], [-598, 0], [41726, 0], [0, -24312], [-40946, 40946], [-42282, 42282], [-1172, 1172], [31614, -31614]]
