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