
# q-expansion of newform 99.6.a.f, downloaded from the LMFDB on 23 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 = 99
weight = 6
poly_data = [-44, -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 = None
aps_data = [[3, -1], [0, 0], [-34, 10], [-148, 10], [121, 0], [-102, 38], [430, -60], [-732, -12], [1868, -366], [-3094, -412], [-3936, 344], [-14890, -136], [2534, 712], [-7580, -1496], [-5188, 2526], [-5986, -2206], [-9388, 1476], [-2638, 2330], [14068, 3200], [15356, 3098], [26554, 7536], [5676, -9482], [30444, -2592], [-38666, -15056], [14210, -21300], [24578, -8556], [-36192, 11380], [-5156, 4648], [-36070, 310], [-206722, 5336], [-108036, -31994], [-140564, 31384], [293918, -13620], [-74660, 47244], [-3942, 47728], [98132, -35754], [-16058, 2996], [-257300, -34368], [113888, 65804], [100602, -6300], [222828, -61236], [385646, 41452], [-140356, 32166], [126922, 74124], [-611278, -15260], [-220560, 50532], [168604, -39224], [-274240, -88448], [1176692, 25232], [-68514, -38652], [557398, 87280], [836472, -15780], [-517910, 127548], [-192668, -182628], [250430, 36592], [838872, -138872], [-1302490, -135422], [-1032764, 187034], [-454278, -60142], [-1288026, -103788], [1444740, -16936], [1196794, 183112], [1173444, -42260], [-460500, -111894], [-237894, 78976], [-229490, 167646], [1186900, 122472], [721586, -501288], [-487020, 393896], [-1784038, 382142], [681902, 192104], [2110656, -138652], [2034960, 288920], [-2328718, -170114], [3179972, 7408], [1251124, 345722], [1516414, -70934], [-1087418, 100740], [-2987802, 248452], [-242062, 77852], [-4865876, -157156], [-3304858, 14920], [5194976, 6992], [779650, 652488], [440436, -954178], [-2592252, 45980], [569302, -646012], [-850750, -590956], [2840546, 135824], [263752, 802620], [2288500, 141256], [-778272, -711800], [-2543472, 492796], [-1775844, -582784], [-145316, 942728], [-38304, 1062188], [-3113450, -218942], [-5494866, 690300], [5178548, -182400], [-8555462, 437022], [-361948, -68700], [-1732078, 90328], [91412, -859544], [1872902, -826060], [-1441844, 285116], [3261666, 115692], [335524, -265284], [8628046, 34772], [8708108, -214838], [-9862518, 708400], [4229996, -1778538], [-5202278, 1639466], [-4580618, -1040384], [13736940, -37520], [-13887176, 424536], [-1867562, 1563316], [3143348, 1458696], [12317772, -63614], [-1365810, -1524202], [-10136124, 772664], [-11035106, 78900], [-11516486, 865100], [2718466, -625748], [12031988, 305508], [-16560412, -1044336], [-2593262, 1067552], [3837758, 2082948], [-8815260, -144486], [1407328, -2667380], [1778762, -2665930], [-9866900, 644048], [1301152, -938076], [-7291168, -1078904], [17250550, -1621312], [-5908570, -1841068], [25347146, -697908], [-5796466, 2109698], [-2333332, 2125768], [-15403402, 919410], [-10814442, 1422528], [13023460, 4704], [4937842, -4900692], [16477496, 427184], [-15581980, 1222536], [2707870, 648384], [7283748, 4407782], [-19421094, 1152226], [21259718, 256272], [-15306908, 344656], [17034268, 1789222], [-20886582, -2466066], [4933806, 3672856], [9488436, -2848360], [-27104000, -2290276], [1120108, -1417592], [-890044, 1060994], [1521260, -1636574], [-9560618, 350212], [5688602, -567984], [10906010, 2300852], [-38670796, -581944], [4625318, -4570208], [-36060092, 557358], [-30517516, -2620332], [30309062, -2470996], [14940236, -3001030], [33372288, -1465672], [9795250, -3919834]]
