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