
# q-expansion of newform 5934.2.a.f, downloaded from the LMFDB on 03 June 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 = 5934
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], [-1], [-1], [3], [-3], [1], [-4], [1], [-1], [1], [4], [-10], [-8], [1], [-7], [2], [-4], [-4], [2], [6], [6], [-4], [5], [6], [7], [-12], [-4], [-1], [11], [-15], [-2], [-18], [-17], [-14], [-10], [4], [-4], [-1], [21], [-4], [6], [13], [0], [22], [-8], [-8], [3], [3], [-20], [6], [-19], [-15], [26], [-13], [3], [2], [-32], [-16], [-32], [26], [0], [18], [-22], [31], [-10], [20], [-7], [-3], [-24], [-18], [16], [12], [18], [24], [2], [-8], [-19], [27], [-26], [14], [6], [12], [-9], [-22], [-2], [-41], [3], [12], [0], [15], [-36], [27], [-8], [-20], [19], [-8], [18], [-19], [-15], [-46], [-26], [44], [24], [34], [7], [42], [-36], [-14], [-15], [-12], [-21], [-14], [-12], [-40], [0], [6], [10], [36], [-1], [-4], [9], [-24], [26], [44], [44], [6], [19], [36], [15], [6], [25], [24], [1], [34], [42], [-55], [31], [22], [8], [28], [44], [-32], [34], [3], [46], [16], [31], [48], [-39], [2], [-14], [-28], [-50], [36], [-18], [22], [34], [13], [8], [52], [41], [-7], [22], [-36], [22], [-36], [25], [-22], [-10], [-52], [-10], [2], [-6], [17], [24], [60], [16], [10], [2], [-14], [-8], [-36], [6], [9], [-26], [29], [18], [56], [21], [8], [14], [-56], [32], [-33], [-18], [6], [39], [-47], [0], [6], [12], [17], [-16], [40], [4], [-51], [-37], [-44], [-43], [-6], [62], [-2], [-28], [-12], [50], [-3], [-23], [-33], [0], [-36], [-64], [-46], [17], [-38], [6], [25], [20], [6], [-35], [-10], [24], [-60], [-62], [-57], [2], [24], [-6], [-72], [-50], [-33], [0], [-23], [20], [-35], [31], [-13], [-23], [-3], [-4], [47], [21], [0], [-33], [8], [-30], [-56], [28], [0], [38], [-27], [80], [-66], [29], [51], [54], [35], [61], [6], [7], [0], [70], [-57], [4], [0], [35], [39], [-13], [6], [79], [-48], [-39], [-38], [8], [-50], [-57], [-56], [-47], [26], [31], [2], [32], [23], [50], [72], [79], [-44], [-56], [-22], [32], [28], [11], [-17], [78], [-69], [-20], [34], [-77], [16], [-64], [-36], [-10], [-15], [-62], [-59], [33], [34], [1], [-67], [-74], [-45], [-56], [-34], [69], [-76], [11], [13], [-31], [-32], [-9], [41], [-50], [52], [-21], [-28], [-34], [-21], [-38], [9], [-52], [37], [19], [-18], [-22], [9], [24], [-27], [34], [-56], [-54], [10], [-16], [16], [50], [41], [17], [15], [58], [-18], [26], [-69], [62], [58], [-58], [16], [-4], [20], [-21], [-58], [64], [92], [4], [-24], [15], [-68], [2], [48], [-60], [18], [77], [-78], [-20], [34], [42], [-95], [-18], [51], [-7], [-13], [76], [-48], [-6], [90], [-56], [-30], [-48], [29], [64], [42], [-103], [-41], [41], [38], [-92], [48], [-27], [47], [28], [58], [28], [56], [6], [5], [-8], [80], [-22], [-96], [-71], [-28], [30], [78], [-25], [-74], [-8], [60], [40], [11], [20], [3], [70], [-70]]
