
# q-expansion of newform 336.4.q.f, downloaded from the LMFDB on 14 December 2025.

# 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 = 336
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 = [[127, [1, 0]], [85, [1, 0]], [113, [1, 0]], [241, [0, -1]]]
aps_data = [[0, 0], [3, -3], [0, 6], [14, -21], [-30, 30], [53, 0], [84, -84], [0, -97], [0, 84], [-180, 0], [179, -179], [0, 145], [126, 0], [325, 0], [0, -366], [768, -768], [-264, 264], [0, -818], [-523, 523], [342, 0], [43, -43], [0, -1171], [810, 0], [0, 600], [386, 0], [-618, 618], [0, 1475], [0, 1884], [-413, 413], [-882, 0], [-2483, 0], [0, 2118], [-3012, 3012], [37, 0], [0, 1644], [1088, -1088], [-506, 506], [0, 1844], [-162, 0], [0, 2724], [-1254, 1254], [-1807, 0], [0, 714], [3709, -3709], [-1044, 0], [-136, 136], [-1484, 0], [2032, 0], [6198, -6198], [0, 4591], [0, -4530], [-1530, 0], [-5534, 5534], [468, 0], [0, 2490], [1572, -1572], [-1806, 1806], [0, -6112], [4231, -4231], [-3816, 0], [-3997, 3997], [4608, 0], [631, 0], [3894, -3894], [0, 2185], [0, -3504], [0, 2945], [4277, 0], [7188, -7188], [-9406, 0], [-3390, 3390], [0, -4812], [-7099, 7099], [0, -2963], [11899, 0], [0, 2568], [10146, -10146], [0, 6229], [0, 2472], [7075, -7075], [4158, 0], [-6595, 0], [1518, -1518], [8567, 0], [0, 10640], [0, 7032], [-14814, 0], [0, 11251], [-3852, 0], [475, 0], [0, 5934], [-13368, 13368], [6653, -6653], [-15444, 0], [0, 683], [-9882, 0], [0, -4206], [-9060, 9060], [0, -15679], [0, 7711], [-4292, 0], [9858, -9858], [-13890, 13890], [0, -19038], [-8053, 8053], [17137, -17137], [-18144, 0], [0, 24702], [-2172, 2172], [4175, 0], [0, 2261], [16318, -16318], [-26550, 0], [19925, -19925], [6832, 0], [-10212, 10212], [-3779, 0], [16998, -16998], [0, 21750], [10944, 0], [-10955, 10955], [25103, 0], [0, 5604], [10968, -10968], [0, 8405], [468, 0], [0, 25066], [0, 11082], [-13481, 0], [0, -24317], [-18217, 18217], [-19782, 0], [0, -4921], [18098, 0], [0, 24468], [21719, 0], [30306, -30306], [27296, -27296], [-35100, 0], [-44394, 44394], [8584, 0], [0, 9834], [43856, -43856], [-13266, 0], [-17453, 17453], [35172, 0], [3503, 0], [-22848, 22848], [0, -13456], [0, 40710], [0, -2906], [-19188, 0], [17251, 0], [0, -2094], [-40267, 40267], [-17604, 0], [0, 3509], [0, 34638], [-17353, 0], [46920, -46920], [0, 18354], [35568, 0], [27343, 0], [0, 51024], [2226, -2226], [35304, -35304], [-2341, 2341], [-29015, 29015]]
