
# q-expansion of newform 405.3.l.f, downloaded from the LMFDB on 24 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, ZZ
    R = PolynomialRing(QQ, "x")
    f = R(poly_data)
    K = NumberField(f, "a")
    betas = [K([c/ZZ(den) for c in num]) for num, den in basis_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 = 3
poly_data = [1, 0, 0, 0, -1, 0, 0, 0, 1]

# The entries in the following list give a basis for the
# coefficient ring in terms of a root of the defining polynomial above.
# Each line consists of the coefficients of the numerator, and a denominator.
basis_data  = [[[1, 0, 0, 0, 0, 0, 0, 0], 1], [[0, 0, 1, 0, 0, 0, 0, 0], 1], [[0, 0, 0, 0, 1, 0, 0, 0], 1], [[0, 1, 0, 0, 0, 1, 0, 0], 1], [[0, 0, 0, 0, 0, 0, 1, 0], 1], [[0, 0, 0, 1, 0, 0, 0, 1], 1], [[0, 2, 0, 0, 0, -1, 0, 0], 1], [[0, 0, 0, 2, 0, 0, 0, -1], 1]]

hecke_ring_character_values = [[326, [-1, 0, 1, 0, 0, 0, 0, 0]], [82, [0, 0, 0, 0, -1, 0, 0, 0]]]
aps_data = [[0, -1, -1, 0, 1, 0, 0, -1], [0, 0, 0, 0, 0, 0, 0, 0], [-1, -3, 1, 0, 0, -2, 1, 0], [0, -1, -1, 0, 1, 0, 0, 2], [0, 0, 4, -3, 0, 0, 3, -3], [8, 8, -8, 0, 0, 0, 2, 0], [10, 0, 0, 0, -10, 6, 0, -6], [0, 0, 0, 6, 6, 6, 0, -6], [14, 14, -14, 0, 0, 0, 2, 0], [0, 18, 0, 7, -18, 0, -7, -7], [4, 0, -4, 0, 0, -6, 6, 0], [16, 0, 0, 0, -16, -18, 0, 18], [-14, 0, 14, 0, 0, 6, -6, 0], [0, -2, 2, -20, 2, 0, 20, 0], [0, 32, 32, 0, -32, 0, 0, -10], [-14, 0, 0, -12, -14, 0, 0, 0], [0, -36, 0, 0, 0, -31, -31, 0], [0, 0, -50, -18, 0, 0, 18, -18], [50, -50, -50, 0, 0, -4, 0, 0], [68, 0, 0, 0, 0, 0, 0, 0], [19, 0, 0, -48, 19, 0, 0, 0], [0, 0, 0, 10, 0, 0, -10, -10], [0, 4, -4, -14, -4, 0, 14, 0], [0, 0, 0, -36, -6, -36, 0, 36], [0, 5, 5, 0, -5, 0, 0, -16], [0, 0, 34, 57, 0, 0, -57, 57], [77, 77, -77, 0, 0, 0, -10, 0], [-32, 0, 0, 0, 32, -30, 0, 30], [0, 0, 0, 6, -54, 6, 0, -6], [56, 56, -56, 0, 0, 0, -34, 0], [25, 0, 0, 0, -25, 114, 0, -114], [40, 0, -40, 0, 0, 27, -27, 0], [0, -76, -76, 0, 76, 0, 0, 74], [0, -54, 0, 0, 0, 56, 56, 0], [0, -102, 0, 0, 0, -7, -7, 0], [0, 0, -2, 60, 0, 0, -60, 60], [-34, 34, 34, 0, 0, 14, 0, 0], [160, 0, 0, 24, 160, 0, 0, 0], [26, -26, -26, 0, 0, -58, 0, 0], [0, -56, 56, -74, 56, 0, 74, 0], [0, 0, 0, -75, 0, -75, 0, 75], [-154, 0, 0, 54, 0, -54, 0, 54], [0, 0, 4, -18, 0, 0, 18, -18], [89, 89, -89, 0, 0, 0, -136, 0], [82, 0, 0, 0, -82, 12, 0, -12], [0, 0, 0, -12, -222, -12, 0, 12], [-206, 0, 206, 0, 0, 24, -24, 0], [0, 67, -67, 82, -67, 0, -82, 0], [0, 116, 116, 0, -116, 0, 0, -112], [0, -234, 0, 0, 0, -4, -4, 0], [22, 0, 0, -150, 22, 0, 0, 0], [0, 336, 0, 0, 0, -4, -4, 0], [0, 0, 16, 48, 0, 0, -48, 48], [368, 0, 0, 15, 0, -15, 0, 15], [-28, 28, 28, 0, 0, 50, 0, 0], [0, 310, -310, -26, -310, 0, 26, 0], [0, 0, 0, 99, -246, 99, 0, -99], [14, 0, 0, -48, 0, 48, 0, -48], [0, 92, 92, 0, -92, 0, 0, 158], [0, 0, 358, 6, 0, 0, -6, 6], [38, 38, -38, 0, 0, 0, 32, 0], [-70, -70, 70, 0, 0, 0, -136, 0], [22, 0, 0, 0, -22, -120, 0, 120], [-116, 0, 116, 0, 0, -192, 192, 0], [0, 25, -25, -104, -25, 0, 104, 0], [0, -268, -268, 0, 268, 0, 0, -130], [0, 0, -122, -150, 0, 0, 150, -150], [-253, 253, 253, 0, 0, 32, 0, 0], [80, -80, -80, 0, 0, -196, 0, 0], [0, -138, 0, 178, 138, 0, -178, -178], [0, -122, 122, 118, 122, 0, -118, 0], [0, 0, 0, -54, -84, -54, 0, 54], [0, 47, 47, 0, -47, 0, 0, 158], [122, 122, -122, 0, 0, 0, 170, 0], [0, 0, 0, 0, 210, 0, 0, 0], [80, 80, -80, 0, 0, 0, 74, 0], [0, 6, 0, -221, -6, 0, 221, 221], [82, 0, 0, 0, -82, 30, 0, -30], [-50, 0, 50, 0, 0, 192, -192, 0], [0, -84, 0, 0, 0, 176, 176, 0], [0, 336, 0, 0, 0, 101, 101, 0], [0, 0, 22, -96, 0, 0, 96, -96], [-496, 0, 0, 126, 0, -126, 0, 126], [-95, 0, 0, 204, -95, 0, 0, 0], [0, -90, 0, -140, 90, 0, 140, 140], [0, 88, -88, -272, -88, 0, 272, 0], [0, 0, 0, -18, 342, -18, 0, 18], [0, -31, -31, 0, 31, 0, 0, -208], [0, 0, -98, 255, 0, 0, -255, 255], [-103, -103, 103, 0, 0, 0, -190, 0], [-452, 0, 0, 0, 452, 30, 0, -30], [0, 60, 0, 100, -60, 0, -100, -100], [-275, 0, 0, 0, 275, -126, 0, 126], [-260, 0, 260, 0, 0, -63, 63, 0], [0, -186, 0, 0, 0, -226, -226, 0], [208, 0, 0, 162, 208, 0, 0, 0], [0, -486, 0, 0, 0, 119, 119, 0], [134, 0, 0, 186, 0, -186, 0, 186], [-362, 0, 0, 180, -362, 0, 0, 0], [446, 0, 0, -6, 0, 6, 0, -6], [0, 554, 554, 0, -554, 0, 0, -88], [-170, 0, 0, 0, 170, 36, 0, -36], [236, 236, -236, 0, 0, 0, 356, 0], [0, -786, 0, 76, 786, 0, -76, -76], [586, 0, -586, 0, 0, -138, 138, 0], [-395, 0, 0, 0, 395, 84, 0, -84], [0, 452, 452, 0, -452, 0, 0, -130], [-488, 0, 0, 30, -488, 0, 0, 0], [0, 168, 0, 0, 0, -82, -82, 0], [0, 0, -374, 228, 0, 0, -228, 228], [-325, 325, 325, 0, 0, -154, 0, 0], [-314, 0, 0, 246, -314, 0, 0, 0], [74, -74, -74, 0, 0, 386, 0, 0], [0, -486, 0, 136, 486, 0, -136, -136], [32, 0, 0, 30, 0, -30, 0, 30], [0, 0, 106, 24, 0, 0, -24, 24], [152, 152, -152, 0, 0, 0, 500, 0], [-20, 0, 0, 0, 20, 246, 0, -246], [-40, -40, 40, 0, 0, 0, -106, 0], [0, 1020, 0, 25, -1020, 0, -25, -25], [118, 0, -118, 0, 0, 210, -210, 0], [0, 199, -199, 28, -199, 0, -28, 0], [0, 248, 248, 0, -248, 0, 0, 242], [-500, 0, 0, -234, -500, 0, 0, 0], [0, 0, -254, -42, 0, 0, 42, -42], [-70, 0, 0, -333, 0, 333, 0, -333], [0, 6, 0, -296, -6, 0, 296, 296], [0, 0, 0, 252, 12, 252, 0, -252], [0, 131, 131, 0, -131, 0, 0, -94], [332, 332, -332, 0, 0, 0, 50, 0], [0, 0, 0, -66, 354, -66, 0, 66], [188, 188, -188, 0, 0, 0, -190, 0], [316, 0, -316, 0, 0, 222, -222, 0], [-596, 0, 0, 0, 596, -294, 0, 294], [-602, 0, 602, 0, 0, 114, -114, 0], [0, -258, 0, 0, 0, -388, -388, 0], [220, 0, 0, 486, 220, 0, 0, 0], [-862, 862, 862, 0, 0, -40, 0, 0], [152, -152, -152, 0, 0, -130, 0, 0], [0, 0, 0, 0, -150, 0, 0, 0], [602, 0, 0, -300, 0, 300, 0, -300], [0, 0, 238, 111, 0, 0, -111, 111], [-391, -391, 391, 0, 0, 0, 74, 0], [340, 0, 0, 0, -340, -564, 0, 564], [0, 0, 0, -150, 330, -150, 0, 150], [0, -540, 0, 250, 540, 0, -250, -250], [0, 310, -310, -314, -310, 0, 314, 0], [0, 62, 62, 0, -62, 0, 0, 290], [0, -150, 0, 0, 0, 260, 260, 0], [742, 0, 0, -270, 742, 0, 0, 0], [-286, 286, 286, 0, 0, 38, 0, 0], [-298, 0, 0, -96, 0, 96, 0, -96], [-452, 0, 0, -240, -452, 0, 0, 0], [-178, 178, 178, 0, 0, 170, 0, 0], [0, 188, 188, 0, -188, 0, 0, 620], [0, 0, -488, -270, 0, 0, 270, -270], [0, 0, 0, 150, -780, 150, 0, -150], [0, -186, 0, -14, 186, 0, 14, 14], [133, 0, 0, 0, -133, -432, 0, 432], [-674, 0, 674, 0, 0, 351, -351, 0], [0, 164, 164, 0, -164, 0, 0, 824], [388, 0, 0, -198, 388, 0, 0, 0], [-385, 385, 385, 0, 0, 626, 0, 0], [464, 0, 0, -219, 0, 219, 0, -219], [650, -650, -650, 0, 0, -46, 0, 0], [0, 676, -676, 442, -676, 0, -442, 0], [-838, 0, 0, -120, 0, 120, 0, -120], [0, 716, 716, 0, -716, 0, 0, 326]]
