
# q-expansion of newform 256.5.c.f, downloaded from the LMFDB on 25 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 = 256
weight = 5
poly_data = [6, 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], 1], [[0, 4], 1]]

hecke_ring_character_values = [[255, [-1, 0]], [5, [1, 0]]]
aps_data = [[0, 0], [0, 1], [8, 0], [0, -8], [0, 11], [-216, 0], [-162, 0], [0, 45], [0, 72], [-1304, 0], [0, -64], [1512, 0], [-1890, 0], [0, -297], [0, 144], [-1976, 0], [0, 231], [2376, 0], [0, -171], [0, 792], [-2750, 0], [0, -816], [0, 953], [-2430, 0], [7454, 0], [-1496, 0], [0, -264], [0, -109], [-14904, 0], [-702, 0], [0, -352], [0, -979], [32670, 0], [0, 135], [872, 0], [0, 968], [-28728, 0], [0, 3177], [0, -5544], [25256, 0], [0, 913], [36072, 0], [0, 3168], [41374, 0], [-67640, 0], [0, 2552], [0, 2673], [0, -2112], [0, 7953], [14472, 0], [2754, 0], [0, -9360], [-97570, 0], [0, -6921], [80514, 0], [0, -1512], [44872, 0], [0, 9328], [90504, 0], [-23166, 0], [0, 7227], [37768, 0], [0, 3933], [0, 8712], [-93602, 0], [49192, 0], [0, 1683], [-93758, 0], [0, 22495], [-48600, 0], [108162, 0], [0, 5112], [0, -6256], [-54648, 0], [0, -10593], [0, 12672], [-129112, 0], [232200, 0], [151902, 0], [-28450, 0], [0, -29739], [119880, 0], [0, -17424], [215518, 0], [0, -7672], [0, -18909], [177822, 0], [203294, 0], [-286648, 0], [0, -33968], [0, -5995], [0, -19008], [0, 37080], [0, 10975], [0, -39303], [0, -21528], [-171512, 0], [184734, 0], [0, 42867], [-230904, 0], [0, -4059], [23144, 0], [0, 50125], [127710, 0], [0, 3987], [-270718, 0], [0, 27899], [-62910, 0], [0, -26712], [-203902, 0], [0, -37728], [-222264, 0], [-363582, 0], [0, 32427], [0, 35560], [67230, 0], [0, 7605], [0, 38808], [89288, 0], [0, -22775], [-560088, 0], [-810722, 0], [-655768, 0], [0, 19311], [0, 58113], [-519224, 0], [-919512, 0], [0, 66960], [0, -49880], [706536, 0], [0, -17631], [0, 25560], [0, -54736], [-470232, 0], [691038, 0], [304030, 0], [-533720, 0], [0, 119889], [-552376, 0], [-803682, 0], [0, -7029], [867592, 0], [0, 3080], [0, 88251], [449928, 0], [0, 81720], [121608, 0], [1264734, 0], [0, 98703], [0, 43776], [519048, 0], [434754, 0], [0, -48411], [0, -30456], [0, -70785], [0, 115632], [0, 53768], [-371682, 0], [532418, 0], [614600, 0], [0, -59603], [-604962, 0], [0, -142280], [0, 67583], [-815778, 0], [0, 125928], [0, 42592], [-1802520, 0]]
