
# q-expansion of newform 162.4.a.f, downloaded from the LMFDB on 19 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 = 162
weight = 4
poly_data = [-26, -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], 1], [[-2, 3], 1]]

hecke_ring_character_values = None
aps_data = [[-2, 0], [0, 0], [-5, -1], [9, -1], [-11, 2], [31, 1], [2, 1], [64, -5], [35, 1], [115, -7], [107, 3], [138, 14], [235, 2], [-55, -24], [249, 15], [82, 14], [83, -2], [-517, 15], [-577, 12], [-172, -32], [-166, -21], [181, 13], [621, 21], [-226, 40], [-53, 22], [-649, 43], [767, 81], [1456, -1], [-358, 18], [-357, -87], [1016, 66], [-1001, 59], [619, -34], [915, -88], [-649, 145], [797, 159], [1331, 3], [780, -16], [1479, 111], [-3009, 33], [-3164, 56], [-990, 116], [4049, -29], [683, 246], [134, -230], [-1244, 106], [-2813, -197], [-1615, -57], [1461, 90], [-1933, 225], [-2234, 287], [-477, -3], [711, 350], [1528, -55], [4695, 108], [149, -341], [226, -382], [4760, -132], [-673, -99], [-2729, -187], [3071, 63], [-6181, 25], [1952, 453], [3499, -139], [5871, 50], [2123, -47], [2809, 49], [3831, -376], [-3033, 96], [-1809, -325], [-677, -160], [1704, -282], [4541, -147], [-809, -131], [1332, -73], [487, 11], [-625, -647], [-5974, -234], [5059, -322], [-6441, -346], [-14037, -141], [-525, 371], [-1600, 658], [7994, 45], [-9931, -399], [-7359, 468], [3114, 189], [-1021, -462], [-8333, 341], [9475, -389], [-8840, -91], [-2595, 231], [-6728, 226], [-11077, -524], [-12157, -162], [-4692, -852], [9487, 299], [1262, 253], [16544, -36], [3438, -910], [-9451, 228], [11666, 136], [1647, 1392], [5471, 178], [4455, 170], [3578, 699], [-3175, 112], [-2818, -1256], [9287, 55], [7907, -1272], [8271, 431], [7106, -462], [21763, -232], [1853, 336], [16992, 368], [9223, 650], [18839, -810], [-3912, 618], [-2125, -971], [-2959, -23], [-973, 939], [19927, -95], [-12985, 463], [-24816, 147], [22853, 9], [4234, 1532], [-23921, 319], [20400, 372], [5429, 27], [-3481, -1323], [-23740, -225], [-1137, 2241], [-17529, 995], [9566, -1068], [13503, 1209], [-14285, -875], [8322, 1056], [2423, -873], [-11409, -1041], [-15982, -179], [-21328, -171], [2027, 841], [9835, -65], [6620, 1240], [-21902, -44], [3945, 1161], [11387, 1125], [-3009, -435], [-2961, 2186], [27896, -1208], [-17553, -637], [-13274, 32], [19864, 481], [-11213, -601], [13057, -254], [18765, -159], [-11080, -42], [5127, 753], [16038, -1576], [5003, 163], [-13059, -672], [-36606, 885], [3467, -1359], [1752, -3012], [-26257, 562], [-7771, -2591], [13544, -600], [-16681, 2463]]
