
# q-expansion of newform 336.3.bh.f, downloaded from the LMFDB on 27 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 = 336
weight = 3
poly_data = [256, 16, 17, -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], [[256, -17, 17, -1], 272], [[16, 33, -1, 1], 16], [[33, -17, 0, 1], 17]]

hecke_ring_character_values = [[127, [1, 0, 0, 0]], [85, [1, 0, 0, 0]], [113, [1, 0, 0, 0]], [241, [1, -1, 0, 0]]]
aps_data = [[0, 0, 0, 0], [2, -1, 0, 0], [-1, -2, 0, -1], [0, 0, -1, 0], [0, -7, -1, 1], [0, 1, -1, 0], [-4, 2, -2, -2], [14, 13, 0, -1], [-24, 24, 0, 0], [3, -1, -1, -2], [-10, 5, -6, -6], [38, -37, -2, -1], [10, -24, 4, 0], [-22, 3, 3, 6], [16, 14, 0, -2], [0, 49, 1, -1], [-82, 41, 1, 1], [-28, -36, 0, -8], [0, 6, -5, 5], [60, -6, -6, -12], [-8, 4, -7, -7], [-31, 29, 4, 2], [-19, 21, 17, 0], [30, 36, 0, 6], [-5, 17, -7, 0], [-24, 12, 18, 18], [48, 35, 0, -13], [-51, 46, 10, 5], [0, -22, 3, -3], [-102, -4, -4, -8], [25, 0, 0, 0], [-99, -90, 0, 9], [0, 96, 12, -12], [18, -17, -19, 0], [-150, 152, -4, -2], [0, 125, -5, 5], [-120, 60, 24, 24], [8, -18, 20, 10], [-8, 30, -14, 0], [132, 120, 0, -12], [0, 138, 0, 0], [2, 9, -13, 0], [24, -10, -28, -14], [0, -99, -14, 14], [-6, 14, 14, 28], [104, -52, -16, -16], [200, -14, -14, -28], [99, -231, 33, 0], [-138, 69, -9, -9], [-26, -35, 0, -9], [-198, 214, -32, -16], [108, -14, -14, -28], [242, -121, -1, -1], [91, -147, -35, 0], [42, 66, 0, 24], [0, 246, -18, 18], [-206, 103, 5, 5], [-25, -12, 0, 13], [0, 10, -3, 3], [-108, -16, -16, -32], [-140, 70, -27, -27], [175, -363, 13, 0], [-28, 53, 3, 0], [-164, 82, -28, -28], [-115, -107, 0, 8], [231, -254, 46, 23], [-344, 329, 30, 15], [67, 18, 18, 36], [0, -50, -14, 14], [104, -212, 4, 0], [-88, 44, -2, -2], [36, -68, 64, 32], [226, -113, 32, 32], [94, -91, -6, -3], [-34, -49, -49, -98], [242, 268, 0, 26], [0, 166, -20, 20], [236, 227, 0, -9], [252, -232, -40, -20], [510, -255, -4, -4], [172, -378, 34, 0], [-64, 33, 33, 66], [0, 322, -20, 20], [-196, 377, 15, 0], [171, 204, 0, 33], [63, -30, -66, -33], [300, -30, -30, -60], [11, -11, 0, 0], [-440, 864, 16, 0], [-302, 9, 9, 18], [-108, -90, 0, 18], [-604, 302, 46, 46], [0, -317, 30, -30], [-123, 37, 37, 74], [730, -715, -30, -15], [122, -144, -100, 0], [-155, -106, 0, 49], [172, -86, 2, 2], [-132, -167, 0, -35], [766, -751, -30, -15], [-146, -4, -4, -8], [0, -425, 1, -1], [390, -195, -57, -57], [-150, 178, -56, -28], [0, -286, 51, -51], [198, -99, 56, 56], [81, -189, 27, 0], [-128, -142, 0, -14], [0, 284, 56, -56], [-215, 478, -48, 0], [-5, 131, 0, 136], [0, -520, -26, 26], [-120, 50, 50, 100], [48, -24, -73, -73], [937, 11, 11, 22], [0, -232, 20, -20], [-596, 1195, -3, 0], [312, -156, 66, 66], [105, -172, 134, 67], [-738, -38, -38, -76], [140, -70, -95, -95], [-611, 48, 48, 96], [267, 300, 0, 33], [0, 341, -43, 43], [-182, -71, 0, 111], [-519, -35, -35, -70], [-34, -30, 128, 64], [122, 34, 0, -88], [-521, 1048, -6, 0], [-82, -121, 0, -39], [0, -232, -15, 15], [-348, 54, 54, 108], [61, -97, 72, 36], [352, 2, 2, 4], [-44, -100, 0, -56], [217, -456, 22, 0], [-664, 332, 58, 58], [-208, 104, 152, 152], [195, -483, 93, 0], [0, 596, -22, 22], [156, -324, 12, 0], [759, -700, -118, -59], [0, 478, -16, 16], [-525, 89, 89, 178], [-580, 290, -95, -95], [-518, 1086, -50, 0], [-376, 687, 65, 0], [152, -76, 4, 4], [566, 480, 0, -86], [-6, 42, -72, -36], [-752, 690, 124, 62], [-756, 1524, -12, 0], [-658, -69, -69, -138], [-416, -298, 0, 118], [0, -366, -67, 67], [396, -88, -88, -176], [-902, 941, -78, -39], [-394, -350, 0, 44], [87, -148, -26, 0], [118, -59, -175, -175], [-174, 122, 104, 52], [-714, -70, -70, -140], [-1301, -2, -2, -4], [-307, -212, 0, 95], [0, 738, -24, 24], [-28, 14, -50, -50], [0, -945, 26, -26], [-1336, 668, 57, 57]]
