
# q-expansion of newform 1665.2.a.f, downloaded from the LMFDB on 22 September 2025.

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