
# q-expansion of newform 4704.2.a.f, downloaded from the LMFDB on 25 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 = 4704
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], [-1], [0], [-1], [0], [8], [-4], [-4], [-5], [7], [8], [-4], [-10], [6], [-1], [9], [2], [-2], [-6], [-2], [9], [-3], [6], [1], [-2], [-16], [-15], [10], [4], [-13], [-19], [18], [10], [6], [-7], [-20], [-20], [-18], [18], [-20], [-20], [0], [-11], [18], [20], [-22], [-19], [7], [-24], [-8], [-12], [-15], [1], [-18], [30], [17], [11], [-24], [6], [-6], [-3], [-4], [28], [-1], [-5], [-20], [1], [-28], [-6], [24], [-6], [-3], [-4], [28], [-34], [-34], [-4], [-32], [-23], [24], [2], [0], [-30], [19], [-29], [-24], [15], [14], [40], [-12], [-18], [31], [27], [-34], [-12], [9], [-14], [8], [22], [-8], [9], [29], [-12], [-14], [-23], [15], [36], [-30], [-19], [25], [44], [6], [-10], [-33], [38], [2], [10], [-31], [-16], [-18], [-19], [27], [37], [-12], [27], [14], [10], [19], [14], [-34], [38], [7], [-26], [0], [19], [-18], [-38], [51], [-32], [-2], [-1], [-16], [43], [20], [-8], [-42], [6], [-18], [46], [32], [-18], [28], [4], [12], [6], [32], [-34], [29], [51], [-40], [-6], [-7], [59], [50], [-24], [5], [-10], [-1], [3], [57], [-42], [4], [-35], [-23], [-52], [10], [-51], [40], [-42], [41], [15], [50], [-22], [-14], [-9], [-46], [46], [51], [-4], [-41], [57], [12], [18], [19], [10], [46], [-26], [26], [-34], [-15], [0], [38], [-10], [-24], [69], [-16], [9], [-48], [-18], [-38], [-61], [1], [39], [-20], [22], [-13], [-28], [-58], [2], [0], [-56], [-42], [-19], [-61], [-8], [-18], [36], [-13], [36], [2], [44], [33], [42], [14], [-24], [29], [13], [-12], [44], [-4], [60], [69], [-50], [-24], [0], [63], [20], [32], [12], [-26], [10], [-14], [38], [-39], [39], [-26], [-64], [57], [-13], [8], [-69], [38], [64], [-30], [46], [53], [-72], [40], [5], [-64], [18], [83], [-49], [-53], [-8], [33], [-44], [-66], [40], [-18], [-59], [-56], [16], [-2], [-32], [-65], [-27], [17], [20], [6], [87], [52], [-12], [16], [-37], [-48], [10], [-76], [-42], [10], [45], [-25], [51], [22], [34], [-69], [-30], [-58], [10], [-42], [-78], [-24], [56], [-32], [42], [-15], [-40], [3], [16], [24], [-22], [77], [0], [-12], [-43], [-50], [-14], [-18], [-79], [-10], [-19], [-40], [48], [-22], [4], [-28], [-42], [15], [5], [30], [-72], [-75], [-37], [-45], [-75], [74], [2], [-38], [69], [36], [19], [-62], [81], [-14], [62], [66], [1], [-60], [-86], [62], [32], [-74], [84], [84], [-21], [14], [88], [-31], [33], [8], [-66], [-5], [16], [20], [32], [-24], [-43], [-14], [90], [50], [-46], [-72], [-48], [-2], [90], [-80], [76], [-32], [36], [9], [-38], [-21], [-58], [-30], [23], [33], [-54], [-20], [45], [76], [84], [4], [-42], [-79], [-27], [2], [-86], [-14], [-19], [-55], [65], [-11], [70], [-14], [33], [-48], [-80], [40], [18], [49], [18], [54], [93], [-34], [-10], [-47], [24], [30], [28]]
