
# q-expansion of newform 882.4.g.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 = 882
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 = [[785, [1, 0]], [199, [0, -1]]]
aps_data = [[0, -2], [0, 0], [0, -6], [0, 0], [12, -12], [-38, 0], [126, -126], [0, 20], [0, 168], [-30, 0], [-88, 88], [0, -254], [42, 0], [-52, 0], [0, 96], [198, -198], [660, -660], [0, -538], [-884, 884], [-792, 0], [218, -218], [0, 520], [-492, 0], [0, -810], [-1154, 0], [618, -618], [0, 128], [0, -1476], [-1190, 1190], [462, 0], [-2536, 0], [0, -2292], [-726, 726], [-380, 0], [0, 1590], [-2432, 2432], [614, -614], [0, 1852], [-2136, 0], [0, -1758], [-540, 540], [-1982, 0], [0, -2688], [2302, -2302], [-4374, 0], [-1600, 1600], [3332, 0], [-2648, 0], [-2244, 2244], [0, -5650], [0, 4698], [1200, 0], [-718, 718], [6012, 0], [0, 2046], [-6072, 6072], [6930, -6930], [0, 1352], [1186, -1186], [-2442, 0], [2828, -2828], [4758, 0], [8476, 0], [-4632, 4632], [0, -4822], [0, -3426], [0, 2788], [434, 0], [6684, -6684], [-2630, 0], [7422, -7422], [0, -10440], [10424, -10424], [0, -3278], [6140, 0], [0, 3072], [6150, -6150], [0, -106], [0, -1758], [-3670, 3670], [-9660, 0], [8462, 0], [9792, -9792], [7342, 0], [0, 10640], [0, -17412], [1710, 0], [0, 646], [-6018, 0], [-6712, 0], [0, -5364], [-9840, 9840], [-1424, 1424], [4548, 0], [0, -6500], [12168, 0], [0, 21090], [5238, -5238], [0, 8588], [0, -3062], [-8476, 0], [-12546, 12546], [12, -12], [0, 19290], [12148, -12148], [-10366, 10366], [7644, 0], [0, -8658], [25800, -25800], [-16202, 0], [0, -24136], [4642, -4642], [6726, 0], [-21220, 21220], [29792, 0], [-10158, 10158], [-29828, 0], [-1944, 1944], [0, 26718], [-4260, 0], [22862, -22862], [-32542, 0], [0, -14214], [-7092, 7092], [0, -13228], [-28062, 0], [0, 27250], [0, 14400], [-17984, 0], [0, 16598], [-1460, 1460], [30072, 0], [0, 18088], [24734, 0], [0, 22278], [-16130, 0], [-29718, 29718], [9524, -9524], [-33906, 0], [-630, 630], [20788, 0], [0, -43098], [14272, -14272], [-13644, 0], [-2410, 2410], [23160, 0], [-32078, 0], [14406, -14406], [0, 30620], [0, 17568], [0, 21706], [-14958, 0], [-32812, 0], [0, 38856], [28276, -28276], [-8112, 0], [0, 26080], [0, -49170], [-48314, 0], [-34782, 34782], [0, -25116], [15462, 0], [-736, 0], [0, 29268], [16674, -16674], [31272, -31272], [15928, -15928], [42014, -42014]]
