
# q-expansion of newform 1078.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 = 1078
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 = [[-1], [3], [4], [0], [-1], [1], [-2], [-6], [-2], [1], [-4], [-2], [2], [4], [-2], [-12], [-9], [5], [-9], [4], [2], [-15], [6], [-6], [5], [15], [-12], [8], [10], [17], [5], [18], [-9], [-8], [-10], [9], [-4], [13], [17], [5], [13], [22], [14], [-22], [-3], [-10], [-14], [26], [-10], [16], [6], [19], [-30], [-12], [21], [3], [-12], [-25], [-3], [-10], [6], [6], [-32], [28], [-1], [-12], [7], [-30], [-28], [-2], [18], [-31], [14], [-7], [-29], [-8], [0], [30], [15], [32], [20], [-20], [1], [10], [5], [-12], [30], [2], [3], [-14], [12], [37], [-4], [18], [-16], [21], [-2], [26], [-20], [-25], [0], [38], [-26], [36], [-20], [7], [3], [0], [-24], [-26], [16], [22], [-27], [-20], [0], [9], [-1], [-24], [22], [-32], [10], [16], [-38], [-33], [-15], [39], [6], [26], [34], [1], [18], [36], [-44], [26], [-54], [38], [24], [22], [-38], [-48], [28], [-15], [38], [-22], [-16], [-54], [-50], [4], [17], [10], [25], [-9], [1], [17], [44], [-54], [-24], [33], [12], [-55], [-16], [56], [56], [13], [14], [-18], [-20], [42], [-20], [46], [6], [10], [-23], [10], [10], [-49], [44], [38], [24], [14], [36], [10], [64], [-4], [4], [18], [13], [-21], [-52], [-31], [14], [4], [-25], [8], [-32], [57], [8], [50], [-30], [57], [1], [41], [32], [70], [-21], [0], [-32], [-30], [0], [-11], [-22], [14], [-16], [-20], [-3], [-25], [5], [36], [36], [-10], [57], [-13], [-33], [-38], [66], [-71], [-1], [0], [-37], [-10], [-64], [-26], [-29], [30], [-9], [-39], [30], [21], [21], [16], [24], [32], [36], [-46], [-66], [48], [26], [35], [18], [45], [-75], [-20], [22], [26], [-47], [-6], [14], [-4], [46], [40], [-8], [-20], [-42], [31], [-45], [-15], [-24], [-49], [10], [2], [-10], [-44], [51], [-28], [-28], [-20], [63], [-73], [82], [-6], [69], [-58], [15], [23], [-46], [-54], [-53], [-14], [30], [-12], [-42], [43], [24], [-62], [1], [-17], [-18], [-4], [10], [-42], [-56], [-23], [-1], [69], [-67], [-19], [73], [32], [66], [54], [27], [-10], [8], [84], [9], [-84], [-43], [-12], [30], [-60], [-20], [23], [-43], [-20], [48], [-21], [56], [24], [81], [-33], [18], [-46], [85], [-38], [22], [15], [40], [0], [21], [-24], [26], [-30], [37], [-38], [-18], [30], [16], [-83], [0], [84], [12], [-70], [-62], [-35], [-6], [-18], [-40], [-34], [10], [-12], [23], [26], [40], [60], [67], [21], [62], [4], [86], [75], [16], [-41], [-34], [79], [0], [-15], [-16], [-74], [70], [12], [-32], [10], [-13], [-46], [-40], [38], [-10], [18], [-8], [10], [37], [-16], [25], [-41], [-60], [-12], [49], [-65], [-55], [35], [-75], [-57], [-75], [51], [45], [-40], [-2], [-84], [-20], [65], [-72], [42], [39], [94], [4], [-42], [-1], [-80], [-85], [37], [-86], [-63], [-62], [44], [-41], [-12], [9], [-18], [-101], [-85]]
