
# q-expansion of newform 3192.2.a.f, downloaded from the LMFDB on 18 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 = 3192
weight = 2
poly_data = [0, 1]

# The basis for the coefficient ring is just the power basis
# in the root of the defining polynomial above.
hecke_ring_character_values = None
aps_data = [[0], [-1], [0], [1], [-4], [2], [0], [1], [0], [8], [-8], [-10], [2], [4], [-2], [12], [-4], [-10], [-8], [6], [6], [-16], [6], [-6], [2], [-8], [-16], [-6], [2], [-4], [-12], [10], [-6], [0], [-6], [12], [6], [12], [-12], [6], [-18], [-2], [-24], [-14], [-2], [-12], [-12], [0], [16], [18], [-18], [-20], [10], [-6], [6], [-12], [26], [-24], [-22], [12], [-32], [-2], [-28], [14], [-6], [-8], [-8], [22], [-24], [30], [-16], [-8], [4], [-26], [16], [36], [18], [22], [-16], [22], [30], [18], [6], [-14], [32], [16], [-8], [6], [-24], [24], [18], [2], [16], [-8], [-20], [30], [-22], [38], [36], [-2], [28], [2], [-16], [20], [-4], [2], [10], [20], [10], [10], [-16], [2], [-46], [0], [-48], [-24], [-8], [-10], [30], [14], [2], [34], [42], [46], [-20], [-18], [26], [42], [-8], [-22], [20], [6], [20], [46], [-20], [-54], [-26], [-20], [-50], [-6], [28], [-30], [-16], [2], [46], [40], [6], [-30], [-12], [34], [6], [8], [36], [20], [28], [50], [-40], [32], [-38], [42], [-44], [-56], [32], [-28], [-24], [-56], [48], [6], [-26], [48], [26], [10], [28], [-58], [8], [-12], [-20], [-26], [-56], [-18], [-48], [20], [-22], [18], [-40], [24], [-30], [4], [-42], [-38], [-2], [12], [0], [-54], [44], [-18], [-26], [6], [-32], [66], [20], [-48], [-2], [14], [-22], [-32], [20], [10], [-26], [60], [-50], [16], [40], [-24], [24], [14], [8], [22], [-6], [-46], [50], [32], [60], [-40], [-36], [-26], [30], [42], [48], [32], [-26], [-20], [8], [-52], [-52], [-54], [46], [6], [-16], [68], [-34], [52], [28], [-26], [-42], [26], [-36], [-64], [36], [0], [30], [44], [-12], [-74], [-12], [36], [22], [-52], [-30], [-14], [-16], [-78], [74], [-30], [-28], [-20], [52], [4], [36], [-78], [46], [28], [-26], [-56], [2], [52], [0], [46], [-54], [58], [-12], [72], [46], [38], [-36], [60], [2], [-48], [36], [-26], [-38], [22], [-76], [-28], [-58], [60], [-48], [-80], [48], [-40], [-22], [48], [-72], [-78], [12], [-10], [-54], [-14], [-4], [34], [30], [-54], [64], [-48], [48], [58], [-54], [-2], [-26], [18], [-4], [-2], [42], [68], [22], [-6], [-36], [-4], [-2], [54], [46], [40], [60], [-58], [28], [42], [-10], [10], [-74], [-8], [-90], [18], [30], [-24], [-48], [-2], [10], [76], [40], [56], [-68], [-2], [-42], [8], [-50], [70], [-42], [-2], [-90], [-82], [-26], [44], [86], [2], [0], [-62], [-92], [4], [2], [-20], [-60], [28], [-44], [-48], [38], [-44], [-24], [-38], [52], [82], [-30], [-54], [16], [18], [60], [-4], [-16], [50], [44], [-12], [94], [86], [44], [-28], [54], [54], [0], [74], [-40], [50], [50], [50], [32], [78], [74], [28], [-10], [8], [-4], [70], [66], [10], [82], [-4], [106], [-84], [38], [56], [-48], [24], [-16], [-58], [12], [-36], [-58], [78], [-66], [54], [32], [46]]
