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