
# q-expansion of newform 576.3.q.f, 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, 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 = 576
weight = 3
poly_data = [4, 0, -2, 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], 1], [[0, 0, 1, 0], 2], [[0, 2, 0, 1], 2], [[0, 4, 0, -1], 2]]

hecke_ring_character_values = [[127, [1, 0, 0, 0]], [325, [1, 0, 0, 0]], [65, [1, -1, 0, 0]]]
aps_data = [[0, 0, 0, 0], [1, -2, 0, 1], [3, 3, 0, 0], [0, 1, 3, 0], [-6, 3, -1, 2], [5, -5, 6, -6], [-6, 12, 4, -2], [10, 0, 0, 6], [3, 3, -1, -1], [-6, 3, 2, -4], [19, -19, 9, -9], [-32, 0, 0, -6], [-21, -21, 6, 6], [0, 23, 9, 0], [18, -9, -7, 14], [30, -60, -20, 10], [-21, -21, 13, 13], [0, -31, 18, 0], [53, -53, -9, 9], [30, -60, 16, -8], [-52, 0, 0, 18], [0, 7, 15, 0], [126, -63, -5, 10], [30, -60, -44, 22], [0, 7, 42, 0], [6, -3, 36, -72], [37, -37, -27, 27], [-60, 120, -32, 16], [16, 0, 0, 54], [9, 9, -44, -44], [-34, 0, 0, -18], [-69, -69, -27, -27], [222, -111, 10, -20], [11, -11, 39, -39], [-3, -3, -26, -26], [0, 175, -45, 0], [-109, 109, -36, 36], [58, 0, 0, -78], [-99, -99, -29, -29], [-18, 9, -20, 40], [-96, 192, -56, 28], [-140, 0, 0, -42], [-6, 3, -3, 6], [-125, 125, 90, -90], [24, -48, 56, -28], [80, 0, 0, 30], [-103, 103, -21, 21], [0, -203, -45, 0], [-54, 27, -29, 58], [143, -143, 108, -108], [-48, 96, 32, -16], [-9, -9, -17, -17], [0, -143, -24, 0], [48, -96, 64, -32], [-27, -27, -8, -8], [462, -231, -15, 30], [30, -60, 4, -2], [-34, 0, 0, -126], [0, -49, 0, 0], [-210, 105, -38, 76], [-145, 145, -81, 81], [87, 87, -32, -32], [-110, 0, 0, 18], [-93, -93, -21, -21], [0, 397, 12, 0], [330, -165, -42, 84], [0, 245, 93, 0], [-335, 335, -12, 12], [-207, -207, 53, 53], [0, 107, -84, 0], [-210, 105, 34, -68], [-36, 72, 168, -84], [0, -77, -45, 0], [113, -113, -138, 138], [328, 0, 0, 66], [-183, -183, 99, 99], [78, -39, 24, -48], [124, 0, 0, -54], [195, 195, 18, 18], [385, -385, 24, -24], [153, 153, 65, 65], [0, 269, 6, 0], [-276, 552, -104, 52], [344, 0, 0, 54], [0, 139, 171, 0], [-162, 81, 163, -326], [54, -108, -300, 150], [0, -401, -126, 0], [138, -69, 26, -52], [283, -283, 93, -93], [-60, 120, -344, 172], [558, -279, 41, -82], [-190, 0, 0, 66], [-345, -345, -83, -83], [35, -35, 243, -243], [-342, 684, 144, -72], [-195, -195, 126, 126], [-168, 336, 40, -20], [-488, 0, 0, 162], [274, 0, 0, -96], [0, 41, -207, 0], [-318, 636, 68, -34], [333, 333, -7, -7], [-6, 3, -60, 120], [-7, 7, -33, 33], [-88, 0, 0, 18], [582, -291, 15, -30], [-78, 156, 100, -50], [-483, -483, 11, 11], [0, 751, -18, 0], [745, -745, -183, 183], [-56, 0, 0, -234], [-21, -21, 54, 54], [0, -175, 9, 0], [-58, 0, 0, 42], [-318, 159, -8, 16], [593, -593, -81, 81], [-36, 72, -168, 84], [375, 375, 28, 28], [42, -21, -93, 186], [395, -395, -252, 252], [0, -137, -174, 0], [-66, 33, -96, 192], [180, -360, 384, -192], [0, 707, -135, 0], [-366, 732, -68, 34], [0, -349, 336, 0], [-180, 360, -96, 48], [0, 643, -81, 0], [-55, 55, 270, -270], [-272, 0, 0, -270], [297, 297, -125, -125], [241, -241, 429, -429], [-866, 0, 0, 72], [-369, -369, -74, -74], [157, -157, -204, 204], [234, -468, 60, -30], [359, -359, -189, 189], [-63, -63, -286, -286], [-6, 12, -116, 58], [-74, 0, 0, 270], [-174, 87, -258, 516], [1579, -1579, -15, 15], [-444, 888, -88, 44], [-980, 0, 0, 42], [-54, 27, 257, -514], [0, 77, -162, 0], [990, -495, 14, -28], [245, -245, 291, -291], [-528, 1056, 184, -92], [317, -317, 282, -282], [510, -1020, 308, -154], [838, 0, 0, 222], [87, 87, 171, 171], [0, 335, 345, 0], [198, -99, -259, 518], [38, 0, 0, 522], [558, -279, -34, 68], [896, 0, 0, -174], [-165, -165, -152, -152], [450, -225, 91, -182], [-342, 684, 60, -30], [-629, 629, -243, 243], [-90, 180, 384, -192], [-15, -15, -364, -364], [30, -15, 189, -378], [650, 0, 0, 90], [0, 275, 396, 0]]
