
# q-expansion of newform 847.2.e.f, downloaded from the LMFDB on 16 June 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 = 847
weight = 2
poly_data = [81, 243, 738, 567, 901, 186, 791, 46, 310, -10, 88, -2, 11, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 1], [[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 1], [[-2769021545193, -419787716481, -1227775483773, -127463103666, -1107227074832, 66266320224, -363336135912, 62824878659, -125448127626, 22306355388, -15976163615, 2434085922, -1552789332, 264377324], 909375762219], [[891314822619, -162577235322, -476390118258, 1957024671128, -480514963920, -108041907152, -258146335705, -93182289202, -51773044484, -85356499939, -4273053430, -12002255852, -793131972, -1514602168], 2728127286657], [[-38669157038421, -26360911887678, -77105494677402, -1523156075858, -69896336375010, 3211892530202, -28117199167805, 3110755985902, -7900259971876, 693079476709, -989644306820, 60937104272, -87439272219, 5120621638], 8184381859971], [[42036246745902, 32577659865837, 95301325805229, -18500664198097, 87069104507298, -2187660804938, 35259419426588, -2278445555803, 9805888787770, 386510823884, 1197525580805, 97189960210, 113311355787, 15219014966], 8184381859971], [[-108394416522, -8597258502120, -4282179087205, -10395016879719, -2154764833166, -8962220714614, -599361077356, -3462977921174, 24682367051, -972615082942, 10005517546, -121835885661, -1514602168, -11003886699], 2728127286657], [[-31356178550721, -26953282477782, -37232124903144, 25544683415771, -48517362837210, 31227868587523, -21513827374075, 15826188091859, -7107292181864, 4213902389729, -908095812328, 516218986960, -73110782037, 43887916724], 8184381859971], [[-9689220683829, -3848169457905, -25127954651643, -5272038683065, -18050526645160, -9355603596675, -7113485935828, -4209195252812, -1488941406670, -1429266020771, -171764293659, -191773032494, -17909964458, -18302830254], 2728127286657], [[-29545999845552, -79304637167811, -81788641622955, -140371605946657, -13058826240585, -127582161736640, 773286812261, -51960605308615, 4538810784463, -14373255223111, 689127290837, -1779899351258, 39995780802, -157825292764], 8184381859971], [[573975068229, -28827257812917, -12208387943444, -46993807091301, 12643557407888, -45253815216011, 6863777133868, -18601132187350, 3493334991514, -5317596779882, 487669814708, -656430346233, 34411700773, -60247680609], 2728127286657], [[2599860888081, -72802702704366, -62792916566616, -119559044837828, 2883052397772, -131731282481665, 5802580587031, -55678242835400, 6407350926317, -16793253087734, 981284443237, -2119933619446, 51679398804, -199685537987], 8184381859971], [[-303224946210, 7440621603079, 3724853327087, 16856283416757, -5933738435297, 16665583346082, -3337838853308, 7031004131898, -1562423497633, 1991601922618, -216874387178, 245120458775, -16117932056, 22354218198], 909375762219], [[544112700525, -30806361389625, -17972852408413, -63268419260298, 12752710183822, -59907851834623, 7183631816072, -24589070187227, 3976440383837, -6961332948772, 558485888017, -861062148420, 37463058359, -78390217983], 2728127286657]]

hecke_ring_character_values = [[122, [0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0]], [365, [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]]
aps_data = [[0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, -1, 1, -1, 1, -1, 1, 0, 0, -1, -1, -1, -1], [0, 1, 0, 0, 0, 0, 0, 0, 1, -1, 1, -1, -2, -1], [0, -1, 0, 0, 0, 0, 1, -1, 1, 0, 0, -1, -1, 0], [2, 0, -1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0], [-3, 1, 0, 1, -1, -2, 3, 0, 0, 0, -1, 0, 0, 2], [0, 0, 0, 0, 0, 0, 2, 1, 0, -1, -3, 0, -1, 1], [-2, 0, 1, 0, -1, 1, 0, -1, -1, 0, 0, 0, 0, 0], [1, 0, 2, -1, 0, -1, 0, -1, -1, -1, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, -5, 1, 0, -1, -1, 0, -2, 0], [2, -2, 1, -2, 1, 0, -2, 0, -2, 1, 1, 0, 1, 0], [-2, -2, -1, -2, 1, 1, 2, 0, 1, -1, 1, -1, -1, -1], [0, -1, 0, 0, 0, 0, 0, 0, -2, 2, 1, 2, 4, 1], [-3, -3, 4, -3, 0, -1, 3, -3, -3, 1, 0, 2, 4, 1], [-1, 0, -1, -1, 1, 2, 0, 0, 0, -1, 0, 1, 0, 0], [2, 3, -1, 3, 1, 0, -2, 2, 1, 1, 1, 1, -1, 0], [0, -4, 0, 0, 0, 0, 2, 0, -2, 2, 0, 2, 2, -1], [3, 0, -2, 1, -2, 2, 0, 2, 2, 0, 0, 0, 0, 0], [0, -1, 0, 0, 0, 0, -6, -1, -1, 2, 2, 1, 2, -1], [-4, 0, 1, -4, 1, 0, 0, 0, 0, -2, 0, 2, 0, 0], [1, 5, -2, 5, -1, 0, -1, 0, 0, -2, -1, -4, -2, 0], [0, 1, 0, 0, 0, 0, -4, 0, 2, -2, 1, -2, 0, 1], [0, -4, 0, 0, 0, 0, -1, 0, 1, -1, -2, -1, 2, 0], [1, -1, -1, -1, -4, -3, -1, -1, 0, -2, -4, -3, -1, 3], [1, 0, -2, 0, -3, 0, 0, -1, -1, 1, 0, -1, 0, 0], [-2, 0, 0, 2, 4, -1, 0, 2, 2, -3, 0, 3, 0, 0], [0, 4, 0, 0, 0, 0, 1, 2, -4, 2, 2, 4, 3, -2], [-3, -2, 0, -2, 0, -3, 3, 2, -1, 2, 0, 1, 0, 3], [7, 0, -1, -3, 2, 1, 0, 3, 3, -1, 0, 1, 0, 0], [0, -2, 0, 0, 0, 0, -5, 0, 4, -4, 1, -4, -5, -2], [9, 2, -3, 2, 0, 1, -9, 5, 1, 2, 0, 0, -3, -1], [1, -6, 0, -6, -1, -3, -1, -1, 1, -1, -1, 0, 0, 3], [0, -2, 0, 0, 0, 0, 1, -1, 0, 1, -3, 0, -1, 2], [5, 0, 5, -3, 5, 0, 0, -3, -3, 0, 0, 0, 0, 0], [0, 4, 0, 0, 0, 0, -4, 3, -3, 0, -4, 3, 1, -1], [-1, 2, -3, 2, -1, 0, 1, 0, 6, -3, -1, 0, -3, 0], [8, 0, -1, 3, 0, 0, 0, -1, -1, 2, 0, -2, 0, 0], [0, 1, 0, 0, 0, 0, -2, 1, -4, 3, 1, 4, 1, -1], [-1, 0, 1, 0, -5, -1, 1, -2, -2, -1, -5, -2, 1, 1], [8, 0, -6, 6, 2, 5, 0, 4, 4, 1, 0, -1, 0, 0], [-3, 3, 3, 3, 1, -1, 3, -2, -3, 1, 1, 1, 3, 1], [6, 0, -1, 2, -3, 0, 0, 4, 4, -1, 0, 1, 0, 0], [6, 0, -3, 5, 1, 2, 0, 2, 2, -1, 0, 1, 0, 0], [2, 2, 6, 2, 0, 0, -2, -2, -7, 4, 0, 3, 6, 0], [0, -5, 0, 0, 0, 0, 5, 2, -2, 0, 2, 2, 1, -2], [0, -1, 0, 0, 0, 0, -1, -1, 0, 1, 0, 0, 4, -2], [5, 0, 5, 6, 2, 3, 0, -6, -6, 3, 0, -3, 0, 0], [8, -2, 4, -2, 5, 0, -8, 0, -5, 4, 5, 3, 4, 0], [11, 0, 1, 2, 1, 3, 0, 2, 2, 4, 0, -4, 0, 0], [0, 6, 0, 0, 0, 0, -5, 1, -1, 0, 2, 1, -4, 1], [1, 0, 1, 0, 1, -2, -1, -1, 1, 0, 1, 2, 1, 2], [-9, 2, -2, 2, 5, 1, 9, 2, 3, 0, 5, 1, -2, -1], [0, -7, 0, 0, 0, 0, 2, 0, -1, 1, 1, 1, 2, 2], [-8, 0, 2, 0, -1, 1, 8, -1, -3, 1, -1, 0, 2, -1], [-2, 0, -2, 0, 4, 0, 0, 0, 0, 3, 0, -3, 0, 0], [-10, -3, -1, -3, -1, 0, 10, 0, 0, -1, -1, -2, -1, 0], [2, 0, -4, 1, -3, -2, 0, 0, 0, 1, 0, -1, 0, 0], [-3, 0, -6, -2, -7, 2, 0, 3, 3, 3, 0, -3, 0, 0], [-8, 1, 4, 1, 3, 1, 8, -1, -3, 3, 3, 4, 4, -1], [0, -9, 0, 0, 0, 0, 2, -2, 4, -2, -6, -4, 1, 4], [0, -1, 0, 0, 0, 0, -14, 2, -3, 1, -2, 3, 4, 0], [0, -5, 0, 0, 0, 0, -5, -3, -1, 4, 5, 1, 0, 4], [-6, 0, 6, -1, -4, 0, 0, -8, -8, 1, 0, -1, 0, 0], [-12, 1, 2, 1, -1, -1, 12, -5, 1, -3, -1, 0, 2, 1], [6, 0, 6, -1, 3, 1, 0, -2, -2, 2, 0, -2, 0, 0], [4, -4, 2, -4, -1, 0, -4, 2, -2, 4, -1, 4, 2, 0], [0, 1, 0, 0, 0, 0, 8, 1, 4, -5, -4, -4, -8, -2], [-11, 0, 8, 0, 4, -2, 11, -5, -9, 3, 4, 2, 8, 2], [0, 1, 0, 0, 0, 0, -2, 1, -2, 1, -7, 2, -2, -3], [7, 0, -9, 2, 1, 4, 0, 7, 7, 0, 0, 0, 0, 0], [0, -5, 0, 0, 0, 0, -6, -2, 7, -5, 4, -7, -2, 0], [-1, -2, 0, -2, -4, 2, 1, 2, 2, 2, -4, 4, 0, -2], [0, 3, 0, 0, 0, 0, 10, -2, 3, -1, 0, -3, -2, 4], [0, -1, 0, 0, 0, 0, -7, -1, -4, 5, 11, 4, 7, -3], [3, -8, 3, -8, 10, 2, -3, -2, 1, 1, 10, 5, 3, -2], [11, 0, -3, 1, 0, 3, 0, -1, -1, 3, 0, -3, 0, 0], [-9, 0, 5, 4, -3, 0, 0, 0, 0, 2, 0, -2, 0, 0], [9, 6, 1, 6, 7, 4, -9, 4, -2, 5, 7, 4, 1, -4], [8, 0, -1, -4, 7, 2, 0, 5, 5, -3, 0, 3, 0, 0], [0, 2, 0, 0, 0, 0, -6, -1, -2, 3, 1, 2, -6, 1], [0, 1, 0, 0, 0, 0, 2, 5, -8, 3, -3, 8, 3, -2], [-4, 0, -4, -5, -1, 5, 0, 2, 2, 2, 0, -2, 0, 0], [0, 4, 0, 0, 0, 0, -14, 0, -1, 1, 8, 1, -1, 0], [-5, 0, 6, 2, 1, 1, 0, -3, -3, -3, 0, 3, 0, 0], [-4, 0, -4, -4, 8, -1, 0, 4, 4, -3, 0, 3, 0, 0], [0, -6, 0, 0, 0, 0, -2, -3, 0, 3, 4, 0, -1, 3], [3, -4, 7, -4, 6, 1, -3, -2, -3, 5, 6, 9, 7, -1], [-5, -2, 11, -2, -3, 0, 5, -3, -11, 8, -3, 8, 11, 0], [12, 0, -5, -7, 8, -2, 0, 3, 3, -1, 0, 1, 0, 0], [0, -7, 0, 0, 0, 0, 9, -8, 9, -1, 2, -9, -1, 6], [6, 0, 0, 7, 7, -1, 0, 0, 0, -2, 0, 2, 0, 0], [0, 8, 0, 0, 0, 0, -8, -5, 2, 3, 4, -2, 1, 2], [0, -2, -10, -2, -2, 0, 0, 6, 11, -4, -2, -3, -10, 0], [0, 0, 0, 0, 0, 0, -4, 4, -5, 1, -3, 5, 3, -6], [0, 4, 0, 0, 0, 0, 16, -1, 2, -1, 2, -2, 4, 6], [-15, 0, -3, 0, 1, -8, 0, 4, 4, -3, 0, 3, 0, 0], [6, -5, 6, -5, 4, 0, -6, -4, -9, 2, 4, -1, 6, 0], [1, -2, 0, -2, 1, 8, -1, -2, -2, -2, 1, -4, 0, -8], [0, 0, 0, 0, 0, 0, -3, -6, -1, 7, -2, 1, -1, 4], [1, 6, -2, 6, 3, -1, -1, 1, 4, -1, 3, 1, -2, 1], [-3, 6, -2, 6, -5, 0, 3, 1, -4, -1, -5, -7, -2, 0], [-5, 0, 6, -6, -2, -8, 0, -6, -6, 0, 0, 0, 0, 0], [0, -1, 0, 0, 0, 0, 11, 0, -6, 6, 3, 6, 11, 4], [10, 1, -4, 1, -4, 3, -10, 6, 2, 2, -4, 0, -4, -3], [-2, 0, 1, -2, 10, 8, 0, -1, -1, 0, 0, 0, 0, 0], [0, 4, 0, 0, 0, 0, -4, 4, -3, -1, -10, 3, 3, 2], [-10, 6, 7, 6, 6, -5, 10, -3, -7, 4, 6, 4, 7, 5], [3, 0, 11, -7, 2, -5, 0, 0, 0, -4, 0, 4, 0, 0], [13, -7, -7, -7, 5, 4, -13, 2, 8, -5, 5, -4, -7, -4], [17, 0, -3, 12, 7, 1, 0, 5, 5, 3, 0, -3, 0, 0], [-8, -3, 0, -3, 0, -7, 8, -6, 2, -6, 0, -4, 0, 7], [5, 0, 9, 1, 6, 4, 0, -5, -5, -2, 0, 2, 0, 0], [-14, 1, -9, 1, 0, 8, 14, 3, 5, -6, 0, -10, -9, -8], [0, -5, 0, 0, 0, 0, 1, -1, -10, 11, 2, 10, 12, -1], [-6, 0, 11, 2, 5, -4, 0, -8, -8, -3, 0, 3, 0, 0], [-7, 0, 0, 0, 1, 7, 7, 8, -4, 8, 1, 4, 0, -7], [1, 0, 2, -8, 2, 3, 0, -4, -4, 1, 0, -1, 0, 0], [0, 2, 0, 0, 0, 0, -8, -6, -4, 10, 11, 4, 10, 2], [-9, 10, 4, 10, -7, -2, 9, -4, -6, 0, -7, -2, 4, 2], [0, -6, 0, 0, 0, 0, -19, -3, -4, 7, 6, 4, -1, -3], [2, 0, -7, 2, -9, -2, 0, 3, 3, -2, 0, 2, 0, 0], [0, -2, 0, 0, 0, 0, -17, -1, -2, 3, 0, 2, 4, 1], [0, -3, 0, 0, 0, 0, -3, -4, -2, 6, -1, 2, 3, 0], [2, 0, -5, 13, -10, 1, 0, 0, 0, 5, 0, -5, 0, 0], [0, -11, 0, 0, 0, 0, 9, -6, 1, 5, -4, -1, 5, 1], [5, 2, -2, 2, 8, 0, -5, -2, 2, -4, 8, -4, -2, 0], [-4, 0, 6, -4, 0, 4, 0, -2, -2, -1, 0, 1, 0, 0], [0, -1, 0, 0, 0, 0, 3, 2, -1, -1, 7, 1, -3, -2], [-13, 0, 1, -7, -3, -6, 0, 2, 2, -1, 0, 1, 0, 0], [0, -2, 0, 0, 0, 0, 27, 3, -7, 4, -10, 7, 3, 2], [-10, 0, 5, -1, 1, 0, 0, -10, -10, 5, 0, -5, 0, 0], [-6, 4, -4, 4, -6, 0, 6, -1, 6, -5, -6, -3, -4, 0], [-10, 0, -4, 0, -3, 6, 10, 1, 5, -3, -3, -2, -4, -6], [0, 0, 2, -4, 5, 2, 0, -1, -1, 1, 0, -1, 0, 0], [6, 0, 5, 0, -11, -1, -6, -4, -5, 1, -11, 1, 5, 1], [-1, 0, 0, -3, -2, -2, 0, 2, 2, -1, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 11, 0, -4, 4, 10, 4, 4, -1], [-2, 0, -6, 0, -10, -8, 2, -5, 9, -11, -10, -8, -6, 8], [-7, 0, -10, -5, -12, -3, 0, 3, 3, -2, 0, 2, 0, 0], [3, 10, -5, 10, 4, -1, -3, 2, 9, -3, 4, 1, -5, 1], [9, 0, 12, -5, -6, 0, 0, -7, -7, -1, 0, 1, 0, 0], [3, 0, 3, -5, -7, -1, 0, 1, 1, 1, 0, -1, 0, 0], [-16, -1, 5, -1, -4, -6, 16, -9, -5, -4, -4, -4, 5, 6], [0, 2, 0, 0, 0, 0, -1, 5, -9, 4, 12, 9, 9, -2], [0, -7, 0, 0, 0, 0, -5, -2, 4, -2, -8, -4, 2, 4], [0, -4, 0, 0, 0, 0, -6, 1, 4, -5, -7, -4, -6, 5], [11, 0, -1, -1, 13, 3, 0, 2, 2, -8, 0, 8, 0, 0], [7, 0, 3, -4, 13, 4, 0, 3, 3, -4, 0, 4, 0, 0], [0, 5, 0, 0, 0, 0, -1, 3, 10, -13, -2, -10, -13, -5], [6, -3, 16, -3, 10, -3, -6, -7, -12, 9, 10, 13, 16, 3], [-17, 0, 13, -6, -7, -9, 0, -9, -9, 1, 0, -1, 0, 0], [0, 5, 0, 0, 0, 0, 6, -8, 3, 5, 2, -3, 7, 3], [0, 3, 0, 0, 0, 0, -6, 9, 0, -9, -9, 0, 0, 0], [-1, 0, 15, 4, 0, 0, 0, -4, -4, 4, 0, -4, 0, 0], [-10, 3, 1, 3, -2, 2, 10, 3, -5, 4, -2, 0, 1, -2], [0, 3, 0, 0, 0, 0, 7, -5, 0, 5, 1, 0, 12, 5], [21, 0, 5, -6, -7, -3, 0, -6, -6, 2, 0, -2, 0, 0], [13, 0, 8, -4, 12, 0, 0, -2, -2, 1, 0, -1, 0, 0], [0, -3, 0, 0, 0, 0, -16, 2, 4, -6, 3, -4, 0, -3], [4, -13, -5, -13, 5, -1, -4, 0, 9, -5, 5, -1, -5, 1], [-13, -10, 8, -10, 2, -4, 13, -14, -4, -6, 2, -2, 8, 4], [23, -1, -12, -1, -2, 9, -23, 10, 10, -2, -2, -4, -12, -9], [15, 4, 0, 4, 10, 0, -15, -2, 1, -2, 10, -1, 0, 0]]
