
# q-expansion of newform 6027.2.a.m, 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 = 6027
weight = 2
poly_data = [-2, 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, 1], [-1, 0], [-2, 1], [0, 0], [1, -1], [-2, 3], [-1, -1], [4, -1], [0, 1], [1, 5], [3, 0], [-1, 6], [1, 0], [-5, 0], [-9, 1], [4, -2], [0, -6], [-1, -4], [2, -6], [3, -5], [-1, -8], [-2, 4], [6, 5], [6, -4], [-12, -3], [-1, -1], [5, 8], [-6, -4], [-2, -7], [-6, -9], [-2, -8], [12, 1], [11, 5], [2, 4], [6, -8], [-16, 0], [-18, 0], [-1, 6], [-2, -4], [2, -5], [5, 7], [-4, -8], [16, -2], [2, 1], [18, -3], [12, -3], [-16, 6], [-16, -4], [-11, -7], [-4, -3], [-18, 0], [4, -10], [-1, 6], [-6, 2], [15, 7], [1, -1], [0, -6], [1, 14], [1, 20], [-1, -13], [-19, -2], [-11, -1], [-11, -8], [-24, 2], [2, -19], [-5, 5], [12, -3], [3, -12], [-9, -7], [5, 10], [18, -12], [12, -3], [1, -4], [19, -10], [10, -12], [-27, -7], [-18, 3], [2, 23], [-12, -16], [-19, -2], [-8, 5], [8, 12], [32, 5], [3, 6], [14, 12], [-8, 20], [12, 6], [-4, 0], [-6, 16], [-10, 11], [-10, -8], [3, 7], [-15, -12], [-6, 5], [-28, -6], [17, 13], [7, 19], [-27, 3], [-34, 0], [2, 12], [-16, 6], [27, 9], [3, 7], [-20, -11], [20, 16], [28, -6], [11, -13], [-3, -1], [0, 25], [18, -6], [26, -6], [8, -8], [6, 15], [-1, -8], [-3, 18], [7, 11], [-12, 18], [8, -11], [3, 7], [-32, 2], [12, 18], [2, -14], [-18, 11], [22, 20], [2, 9], [-26, 14], [-22, 6], [-25, 11], [20, -9], [17, -10], [17, -4], [-6, -16], [18, -12], [4, -3], [-12, 2], [25, -6], [-49, 1], [-3, -12], [30, -10], [-6, -22], [1, -12], [-12, 19], [-10, -30], [15, 5], [-9, -24], [20, -2], [0, 0], [-32, 14], [-11, 4], [18, -5], [-13, 10], [20, -16], [-8, 1], [5, 29], [10, -4], [44, 7], [-14, 1], [-19, -19], [-36, 12], [30, -16], [-18, -28], [-12, 21], [-18, -12], [-25, 11], [9, 1], [30, 5], [-20, 6], [-14, 1], [3, -12], [-6, -14], [6, -12], [-12, 18], [10, 28], [-29, -12], [20, 20], [21, -7], [-20, -9], [-30, -14], [44, -3], [38, 4], [7, 22], [2, 32], [24, -12], [-6, 0], [14, 32], [-6, 3], [-16, 0], [-34, -4], [-6, 3], [23, -23], [19, -6], [-24, -10], [-2, 18], [-46, -10], [-12, 1], [-12, 12], [-18, -18], [2, -37], [-10, -20], [39, -15], [0, 4], [15, 30], [-32, -3], [-30, -24], [9, -3], [-21, 1], [-26, 2], [39, 23], [12, -29], [-45, -12], [2, -9], [39, 15], [-14, 10], [12, 22], [-23, -17], [-23, -6], [22, 27], [24, 21], [-39, 21], [-6, -2], [-12, 33], [-31, -20], [49, 1], [20, 13], [22, 37], [24, 9], [-30, 8], [-2, -49], [-16, -6], [16, -23], [-34, 20], [10, 35], [-27, 12], [-32, -25], [24, -15], [-6, -32], [14, -9], [6, 6], [-16, 20], [45, 13], [0, -10], [-28, -16], [-10, -26], [-61, -2], [8, -40], [34, -25], [-22, 26], [3, -7], [29, 34], [-30, 34], [41, -6], [-8, 17], [42, -10], [1, -12], [-30, 18], [2, -16], [-52, 5], [0, -27], [-15, 33], [-24, 27], [-11, -4], [15, 19], [6, 6], [40, 10], [30, 5], [-33, -12], [27, 29], [6, -2], [-14, -32], [-13, -43], [-16, -20], [-51, 0], [13, 6], [3, -42], [6, 12], [-16, 36], [15, 45], [16, -34], [-36, 27], [33, 15], [9, 19], [6, 51], [6, 12], [-8, -2], [-40, 30], [11, -19], [0, -45], [-62, -2], [50, 3], [-23, 17], [-15, 9], [6, 20], [-27, -25], [20, -37], [-40, 21], [27, 13], [12, -6], [2, -38], [36, 0], [30, -3], [-28, -30], [-42, 8], [-1, 44], [1, 47], [-19, -2], [-10, 32], [-36, -19], [41, 12], [30, 12], [-4, -49], [-9, 15], [-6, 6], [8, 38], [43, -22], [22, -23], [-24, -12], [-6, -40], [24, 45], [-2, 10], [1, 47], [2, -30], [12, 18], [6, 19], [-46, -19], [-48, -15], [-62, 0], [46, -5], [-14, 5], [27, 27], [18, -10], [-28, -34], [-6, -36], [0, 0], [24, 42], [11, -16], [-67, -1], [46, -3], [-58, 1], [26, -11], [-29, 38], [-16, 0], [84, -4], [-28, -14], [-78, -6], [16, -16], [24, -12], [-56, -6], [11, -12], [-36, -16], [56, -2], [-18, -45], [53, 26], [3, 51], [-81, 0], [0, -6], [-24, 50], [18, -29], [-72, 4], [6, -1], [-28, 17], [23, -14], [66, 4], [-35, 25], [0, -34], [14, 22], [-30, -3], [-62, -26], [-23, -28], [71, -16], [32, -16], [32, -36], [0, -62], [-55, -23], [66, 0], [36, 3], [8, 17], [66, 9], [84, -6], [-75, 9], [-20, -33], [-15, 41], [-56, -25], [-31, 32], [-24, 12], [-2, 38], [66, 0], [-18, 3], [48, 6], [-63, -6], [-12, 32], [18, 18], [-33, 37], [0, 18], [36, 0], [24, 28], [8, 48], [20, 27], [-30, -18], [-31, 18], [30, -6], [-39, 18], [42, -6], [53, -26], [42, -2], [-12, -9], [-48, 21], [-15, -12], [3, 37], [40, 25], [52, -31], [-1, 38], [24, -28], [4, -10], [20, -22], [44, -21], [36, 35], [-30, 39], [-24, -33], [21, 35], [66, -24], [16, -41], [-90, 0], [-18, -19], [-51, 3], [-7, 0], [12, 39], [-37, -31], [33, 27], [44, 19], [3, 21]]
