
# q-expansion of newform 98.4.c.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
    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 = 98
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 = [[3, [0, -1]]]
aps_data = [[0, 2], [8, -8], [0, -14], [0, 0], [28, -28], [-18, 0], [74, -74], [0, 80], [0, 112], [190, 0], [72, -72], [0, 346], [-162, 0], [-412, 0], [0, 24], [-318, 318], [-200, 200], [0, -198], [716, -716], [392, 0], [538, -538], [0, -240], [1072, 0], [0, 810], [-1354, 0], [-1358, 1358], [0, -832], [0, -444], [-1870, 1870], [1378, 0], [1944, 0], [0, -848], [2966, -2966], [-2800, 0], [0, -510], [-592, 592], [-2686, 2686], [0, 1012], [-544, 0], [0, 1858], [300, -300], [2358, 0], [0, -1392], [-1778, 1778], [1214, 0], [1040, -1040], [-3868, 0], [-3968, 0], [-3936, 3936], [0, 4810], [0, 2182], [-3000, 0], [2042, -2042], [528, 0], [0, 5634], [-168, 168], [-1310, 1310], [0, -2208], [-5294, 5294], [3242, 0], [-1592, 1592], [5022, 0], [9536, 0], [-968, 968], [0, 3058], [0, 4986], [0, -8612], [-10206, 0], [-2004, 2004], [-1330, 0], [978, -978], [0, 9680], [-8656, 8656], [0, -5278], [6340, 0], [0, -6232], [14810, -14810], [0, 5154], [0, -3282], [5810, -5810], [-13560, 0], [-738, 0], [-1272, 1272], [5062, 0], [0, 5640], [0, -13388], [-3230, 0], [0, 10646], [-7282, 0], [12688, 0], [0, -2816], [-3160, 3160], [14176, -14176], [-11268, 0], [0, 4460], [1512, 0], [0, -11790], [1362, -1362], [0, 6968], [0, -7062], [-8196, 0], [7466, -7466], [24968, -24968], [0, -14250], [-6372, 6372], [-8366, 8366], [-20384, 0], [0, 9378], [9000, -9000], [-7562, 0], [0, -2976], [-4278, 4278], [18794, 0], [18040, -18040], [-21688, 0], [10558, -10558], [26152, 0], [25584, -25584], [0, -15198], [-6100, 0], [-2318, 2318], [-10222, 0], [0, 25434], [8532, -8532], [0, 20672], [-21458, 0], [0, 9850], [0, -18840], [-37504, 0], [0, 13338], [-17100, 17100], [-19632, 0], [0, -33912], [-31386, 0], [0, -34558], [-39130, 0], [-25982, 25982], [35424, -35424], [30606, 0], [-16810, 16810], [9368, 0], [0, -34382], [4472, -4472], [-1716, 0], [-7910, 7910], [19360, 0], [-698, 0], [-23406, 23406], [0, 7280], [0, -9808], [0, 8066], [-25842, 0], [-5692, 0], [0, -13536], [-17004, 17004], [-14568, 0], [0, 1400], [0, -13830], [24166, 0], [-10838, 10838], [0, 40916], [56618, 0], [17504, 0], [0, 23112], [-23874, 23874], [-15312, 15312], [16528, -16528], [-28606, 28606]]
