
# q-expansion of newform 405.4.e.f, 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 = 405
weight = 4
poly_data = [1, -1, 1]

# The basis for the coefficient ring is just the power basis
# in the root of the defining polynomial above.
hecke_ring_character_values = [[326, [0, -1]], [82, [1, 0]]]
aps_data = [[-1, 1], [0, 0], [0, -5], [6, -6], [47, -47], [0, 5], [-131, 0], [-56, 0], [0, -3], [157, -157], [0, -225], [-70, 0], [0, -140], [-397, 397], [347, -347], [4, 0], [0, -748], [338, -338], [0, -492], [32, 0], [970, 0], [1257, -1257], [102, -102], [-1488, 0], [-974, 974], [1335, -1335], [0, -686], [-1098, 0], [-700, 0], [0, 1055], [-1646, 0], [0, 1833], [-1098, 1098], [0, 1042], [0, 2941], [-511, 511], [0, 571], [713, 0], [0, -1596], [-4134, 4134], [1828, 0], [-520, 0], [-4826, 4826], [0, -1670], [-1380, 0], [4357, 0], [0, 4162], [5956, -5956], [-4940, 4940], [0, -4344], [-5202, 0], [0, -1546], [3659, -3659], [1221, 0], [0, 6255], [-836, 836], [-2231, 0], [-4832, 0], [-6450, 6450], [1050, -1050], [0, 1584], [0, -6594], [-4343, 0], [0, 2124], [7516, -7516], [6880, -6880], [4986, -4986], [0, -904], [0, -8860], [4454, -4454], [8781, -8781], [2928, 0], [-9102, 9102], [0, 8183], [6136, 0], [0, -5643], [-8991, 8991], [-12449, 0], [0, -8076], [0, 2833], [0, 4777], [6464, -6464], [10680, 0], [11566, 0], [1448, -1448], [2376, -2376], [-14894, 0], [-16204, 16204], [5082, -5082], [0, 10326], [4184, 0], [15576, -15576], [10220, 0], [0, 2692], [0, -5764], [-2437, 0], [0, 5849], [-17032, 0], [4147, 0], [-3942, 0], [13751, -13751], [7944, 0], [0, 6702], [2760, -2760], [0, -8930], [6944, 0], [4206, -4206], [-6571, 0], [0, 9490], [-11861, 11861], [0, 518], [15163, 0], [0, -19011], [7906, -7906], [-3416, 0], [-4830, 4830], [0, -12549], [8164, 0], [0, -23768], [-21472, 21472], [0, -12982], [6006, -6006], [-1164, 1164], [26496, 0], [-17110, 17110], [30251, 0], [-18820, 18820], [31890, 0], [11452, -11452], [0, -7094], [-3200, 0], [0, 20831], [0, 15605], [21349, 0], [0, -3702], [0, 1393], [-6906, 0], [0, -30493], [0, -33488], [-15304, 0], [-40122, 0], [-25098, 25098], [0, 43492], [11206, 0], [-23964, 0], [34606, -34606], [18477, -18477], [41342, -41342], [0, -21898], [-18487, 0], [0, -7593], [-3038, 0], [-16732, 0], [0, 8031], [38487, -38487], [5120, -5120], [28075, 0], [12856, -12856], [-1374, 0], [0, -8543], [-13506, 13506], [21775, 0], [0, -3854], [12933, 0], [0, -17521], [12573, -12573], [8945, 0], [58179, -58179]]
