
# q-expansion of newform 570.4.i.f, downloaded from the LMFDB on 06 June 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 = 570
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 = [[191, [1, 0]], [457, [1, 0]], [211, [0, -1]]]
aps_data = [[2, -2], [3, -3], [5, -5], [-19, 0], [15, 0], [0, -50], [42, -42], [-95, 57], [0, 45], [0, 108], [-196, 0], [-43, 0], [-213, 213], [-338, 338], [0, -240], [0, 453], [180, -180], [0, -98], [0, -110], [-204, 204], [760, -760], [214, -214], [-198, 0], [0, -615], [52, -52], [0, -318], [-1003, 0], [-1122, 0], [-1046, 1046], [1590, 0], [0, 799], [-219, 219], [0, -2508], [0, 364], [-1302, 1302], [-682, 0], [2533, -2533], [3470, 0], [0, -1929], [1437, -1437], [909, 0], [0, -3836], [-2334, 0], [118, -118], [-4299, 0], [0, -1046], [763, -763], [-1901, 1901], [-1176, 0], [518, 0], [1794, -1794], [-3780, 0], [0, -2558], [0, -5292], [0, -6186], [6195, -6195], [5850, -5850], [1762, -1762], [-5722, 0], [0, -2967], [538, -538], [-1215, 0], [1708, -1708], [-1272, 0], [0, 7144], [0, -879], [5951, 0], [8422, -8422], [6546, -6546], [-11194, 0], [-114, 0], [-6072, 6072], [0, 8896], [-529, 0], [-1888, 0], [-7128, 7128], [0, 9564], [-7373, 7373], [1938, -1938], [0, -749], [-10641, 0], [-8030, 8030], [0, -3630], [0, 13468], [1354, -1354], [0, 5154], [12099, 0], [-1126, 0], [6642, -6642], [7985, 0], [10860, 0], [0, 14064], [-6415, 0], [-15993, 15993], [-9581, 9581], [0, 18867], [0, -12630], [-882, 0], [0, 4852], [0, -16388], [0, 23218], [0, -13593], [-16284, 0], [10755, 0], [-3052, 0], [9110, 0], [-21180, 21180], [0, 20424], [0, 13206], [1985, 0], [-20875, 0], [15847, -15847], [0, -672], [-8713, 0], [0, -8420], [-21762, 21762], [7570, -7570], [-21261, 0], [-11535, 0], [0, 19545], [0, -18884], [14792, 0], [14529, 0], [-2778, 0], [-16315, 0], [-3030, 3030], [0, -26378], [-1812, 1812], [25648, -25648], [32393, 0], [10099, -10099], [25845, -25845], [0, 1888], [25615, -25615], [-20505, 0], [0, -19346], [0, 12765], [28484, 0], [33399, 0], [21954, 0], [0, -2279], [0, 6354], [0, -19739], [0, 29940], [1976, 0], [-12750, 12750], [-4430, 4430], [10464, -10464], [0, -37595], [14331, 0], [48133, -48133], [1263, 0], [0, 4798], [0, 588], [25414, -25414], [3138, 0], [-35692, 0], [41037, -41037], [0, -12680], [0, -16212], [24174, -24174], [-45720, 45720], [-14540, 14540], [-29580, 29580], [23820, 0], [17373, -17373], [-47672, 47672], [0, 57529]]
