
# q-expansion of newform 324.3.f.m, downloaded from the LMFDB on 25 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 = 324
weight = 3
poly_data = [9, 3, 4, -1, 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], 1], [[0, 1, 0, 0], 1], [[-3, -4, 4, -1], 12], [[7, 0, 0, 1], 4]]

hecke_ring_character_values = [[163, [-1, 0, 0, 0]], [245, [0, 0, 1, 0]]]
aps_data = [[1, -1, 0, 0], [0, 0, 0, 0], [-2, 2, -1, 2], [-3, 2, -1, 4], [7, 0, -7, 0], [0, 0, -16, 0], [4, 0, 0, -8], [18, -24, 12, -12], [20, 0, 10, 0], [-14, 28, -14, 0], [0, -2, 1, 2], [26, 0, 0, 0], [4, -4, 2, -4], [6, -4, 2, -8], [-2, 0, 2, 0], [19, 0, 0, -38], [-88, 0, -44, 0], [-8, 0, -8, 0], [0, -20, 10, 20], [-36, 0, -72, 0], [-19, 0, 0, 0], [24, -16, 8, -32], [67, 0, -67, 0], [22, 0, 0, -44], [-119, 0, -119, 0], [-17, 34, -17, 0], [0, 40, -20, -40], [75, 0, 150, 0], [-46, 0, 0, 0], [52, -52, 26, -52], [9, -12, 6, -6], [50, 0, 25, 0], [22, -44, 22, 0], [0, 40, -20, -40], [-2, 2, -1, 2], [-93, 62, -31, 124], [0, 0, 92, 0], [72, -96, 48, -48], [-196, 0, -98, 0], [49, -98, 49, 0], [153, 0, 306, 0], [272, 0, 0, 0], [-152, 0, 152, 0], [0, 0, -187, 0], [-5, 0, 0, 10], [45, -60, 30, -30], [0, -20, 10, 20], [96, -64, 32, -128], [-44, 0, 44, 0], [0, 0, -214, 0], [-86, 0, 0, 172], [476, 0, 238, 0], [-206, 0, -206, 0], [48, 0, 96, 0], [16, -16, 8, -16], [-26, 0, 26, 0], [-14, 0, 0, 28], [-9, 12, -6, 6], [160, 0, 160, 0], [-140, 280, -140, 0], [0, 4, -2, -4], [-92, 92, -46, 92], [-252, 336, -168, 168], [-28, 0, -14, 0], [-233, 0, -233, 0], [139, -278, 139, 0], [-66, 44, -22, 88], [0, 0, 50, 0], [-226, 0, -113, 0], [538, 0, 538, 0], [-62, 124, -62, 0], [258, 0, 516, 0], [-129, 86, -43, 172], [0, 0, 212, 0], [108, -144, 72, -72], [-280, 0, -140, 0], [-143, 286, -143, 0], [80, 0, 0, 0], [-344, 344, -172, 344], [0, 0, -349, 0], [344, 0, 172, 0], [208, 0, 208, 0], [-318, 0, -636, 0], [125, 0, 0, 0], [-273, 182, -91, 364], [220, 0, -220, 0], [-134, 0, 0, 268], [-827, 0, -827, 0], [-179, 358, -179, 0], [0, 34, -17, -34], [-429, 0, -858, 0], [-194, 0, 194, 0], [-288, 384, -192, 192], [566, 0, 283, 0], [0, -212, 106, 212], [186, 0, 372, 0], [-302, 302, -151, 302], [64, 0, 0, -128], [324, -432, 216, -216], [260, 0, 0, 0], [420, -280, 140, -560], [-131, 0, 0, 262], [806, 0, 403, 0], [76, -152, 76, 0], [0, -80, 40, 80], [494, 0, 0, 0], [-137, 0, 137, 0], [130, 0, 0, -260], [-652, 0, -326, 0], [-647, 0, -647, 0], [0, -128, 64, 128], [866, 0, 0, 0], [124, -124, 62, -124], [-480, 320, -160, 640], [-45, 60, -30, 30], [238, -476, 238, 0], [0, -8, 4, 8], [312, 0, 624, 0], [238, -238, 119, -238], [-563, 0, 563, 0], [0, 0, -970, 0], [595, 0, 595, 0], [118, -236, 118, 0], [36, 0, 72, 0], [-516, 344, -172, 688], [-257, 0, 0, 514], [28, 0, 28, 0], [-156, 0, -312, 0], [-3, 2, -1, 4], [0, 0, 338, 0], [396, -528, 264, -264], [-688, 0, -344, 0], [0, -170, 85, 170], [-250, 0, 0, 0], [-272, 272, -136, 272], [0, 0, 65, 0], [-230, 0, 0, 460], [0, 256, -128, -256], [430, -430, 215, -430], [58, 0, 0, -116], [-702, 936, -468, 468], [-14, 28, -14, 0], [0, 430, -215, -430], [336, 0, 672, 0], [-1186, 0, 0, 0], [484, 0, -484, 0], [1294, 0, 1294, 0], [364, -728, 364, 0], [0, -128, 64, 128], [492, 0, 984, 0], [0, 0, 1118, 0], [208, 0, 0, -416], [-630, 840, -420, 420], [1280, 0, 640, 0], [294, -196, 98, -392], [454, 0, -454, 0], [-423, 564, -282, 282], [-68, 136, -68, 0], [-649, 0, 0, 0], [-866, 866, -433, 866], [-59, 0, 59, 0], [-140, 0, 0, 280], [0, -302, 151, 302], [303, 0, 606, 0], [724, -724, 362, -724], [-986, 0, 986, 0], [-153, 204, -102, 102], [-1304, 0, -1304, 0]]
