
# q-expansion of newform 588.4.i.f, downloaded from the LMFDB on 19 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 = 588
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 = [[295, [1, 0]], [197, [1, 0]], [493, [0, -1]]]
aps_data = [[0, 0], [3, -3], [0, -6], [0, 0], [-36, 36], [62, 0], [-114, 114], [0, 76], [0, 24], [54, 0], [112, -112], [0, 178], [378, 0], [-172, 0], [0, 192], [402, -402], [-396, 396], [0, -254], [1012, -1012], [840, 0], [-890, 890], [0, -80], [-108, 0], [0, 1638], [1010, 0], [-6, 6], [0, 472], [0, 972], [1786, -1786], [-2286, 0], [1328, 0], [0, 1212], [1254, -1254], [-340, 0], [0, -1038], [-2936, 2936], [1330, -1330], [0, 3364], [3048, 0], [0, 2706], [-4716, 4716], [1910, 0], [0, -4080], [2686, -2686], [510, 0], [-1352, 1352], [-3364, 0], [-4768, 0], [-420, 420], [0, 1882], [0, -5082], [-5424, 0], [2590, -2590], [-4932, 0], [0, 3438], [-6120, 6120], [18, -18], [0, -6896], [-6254, 6254], [1194, 0], [7156, -7156], [-3738, 0], [-844, 0], [-6312, 6312], [0, -8282], [0, -9318], [0, -1652], [-1294, 0], [-3636, 3636], [10478, 0], [7566, -7566], [0, 8040], [-7568, 7568], [0, 13522], [2468, 0], [0, 12336], [3762, -3762], [0, 8770], [0, -6642], [1510, -1510], [-1260, 0], [3998, 0], [2736, -2736], [2690, 0], [0, 1240], [0, 3900], [-10878, 0], [0, -2330], [15150, 0], [-2992, 0], [0, -8724], [-9744, 9744], [-4136, 4136], [16212, 0], [0, -2396], [13128, 0], [0, -12798], [-7386, 7386], [0, -5180], [0, -4070], [14780, 0], [6858, -6858], [-6660, 6660], [0, 150], [8188, -8188], [5854, -5854], [17580, 0], [0, -17154], [18120, -18120], [17546, 0], [0, 14560], [4498, -4498], [-5478, 0], [-6044, 6044], [-15352, 0], [22398, -22398], [3764, 0], [17688, -17688], [0, -19878], [-20004, 0], [1306, -1306], [-13054, 0], [0, -5046], [-12468, 12468], [0, 23212], [35958, 0], [0, -6446], [0, 4704], [-10600, 0], [0, -12542], [-23324, 23324], [-6312, 0], [0, -35840], [-34594, 0], [0, -23946], [18770, 0], [-30342, 30342], [26188, -26188], [-34818, 0], [21702, -21702], [-20356, 0], [0, 19890], [-4232, 4232], [9636, 0], [-35294, 35294], [-3768, 0], [-39466, 0], [34038, -34038], [0, 3364], [0, -13104], [0, 40858], [-37374, 0], [9788, 0], [0, -50424], [12412, -12412], [6576, 0], [0, -8264], [0, -39426], [-4678, 0], [17346, -17346], [0, -19452], [4458, 0], [52520, 0], [0, 10404], [7566, -7566], [-44376, 44376], [27328, -27328], [-2774, 2774]]
