
# q-expansion of newform 100.3.b.f, downloaded from the LMFDB on 18 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 = 100
weight = 3
poly_data = [1, -1, 1, -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, 0, 0], 1], [[0, 2, 0, 0], 1], [[0, 0, 2, 2], 1], [[1, -2, 2, -2], 1]]

hecke_ring_character_values = [[51, [-1, 0, 0, 0]], [77, [1, 0, 0, 0]]]
aps_data = [[0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 0], [2, -2, -1, 2], [4, -4, 2, 4], [4, -2, 0, -2], [6, 8, 0, 8], [-4, 4, 0, -4], [2, -2, -3, 2], [-2, 4, 0, 4], [4, -4, -10, 4], [-4, -10, 0, -10], [-28, -6, 0, -6], [-4, 4, -3, -4], [-6, 6, -13, -6], [44, -10, 0, -10], [12, -12, -12, 12], [32, -26, 0, -26], [-20, 20, 11, -20], [-20, 20, -2, -20], [-66, -32, 0, -32], [-16, 16, 20, -16], [12, -12, 13, 12], [-22, 40, 0, 40], [66, -12, 0, -12], [82, 8, 0, 8], [-22, 22, -23, -22], [24, -24, -17, 24], [-32, -74, 0, -74], [-126, 20, 0, 20], [38, -38, 23, 38], [28, -28, -42, 28], [26, 12, 0, 12], [-60, 60, -4, -60], [48, 38, 0, 38], [36, -36, 62, 36], [-84, 54, 0, 54], [-56, 56, 45, -56], [-18, 18, 15, -18], [204, -10, 0, -10], [12, -12, 76, 12], [122, 16, 0, 16], [-44, 44, 58, -44], [-146, -16, 0, -16], [16, -70, 0, -70], [-32, 32, -64, -32], [-28, 28, -42, -28], [-70, 70, 13, -70], [16, -16, -1, 16], [118, -20, 0, -20], [-6, 140, 0, 140], [40, -40, 36, 40], [-68, -30, 0, -30], [-52, 52, 26, -52], [266, -4, 0, -4], [-58, 58, -79, -58], [-192, 70, 0, 70], [-12, 12, -86, -12], [256, 90, 0, 90], [-28, 10, 0, 10], [48, -48, -15, 48], [-76, 46, 0, 46], [68, -68, 11, 68], [68, -68, 10, 68], [174, -176, 0, -176], [-264, -46, 0, -46], [44, -44, 70, 44], [126, -64, 0, -64], [76, -76, 91, 76], [-242, -108, 0, -108], [14, -144, 0, -144], [16, -16, 16, 16], [-34, 34, -157, -34], [-256, 154, 0, 154], [60, -60, 32, 60], [114, -114, -43, 114], [48, -154, 0, -154], [-124, 94, 0, 94], [282, 72, 0, 72], [-272, 150, 0, 150], [-140, 140, 28, -140], [-328, -114, 0, -114], [-44, 44, -126, -44], [234, 60, 0, 60], [128, -128, -48, 128], [88, -88, -19, 88], [528, 102, 0, 102], [-554, 120, 0, 120], [-278, 80, 0, 80], [-2, 2, -167, -2], [-232, 232, -13, -232], [-32, 32, -172, -32], [-158, 158, 67, -158], [-52, 52, -38, -52], [228, -228, -24, 228], [-214, 214, 73, -214], [-602, 140, 0, 140], [202, -360, 0, -360], [104, -104, 161, 104], [-438, -80, 0, -80], [40, -40, -1, 40], [-704, -86, 0, -86], [-184, 184, 89, -184], [-112, 54, 0, 54], [20, -20, -122, 20], [186, 236, 0, 236], [-68, 68, -153, -68], [94, 96, 0, 96], [-216, 216, -12, -216], [172, 82, 0, 82], [138, -138, 251, 138], [-656, -70, 0, -70], [-54, 220, 0, 220], [-4, 4, 200, -4], [-52, 52, 198, -52], [212, 282, 0, 282], [52, -52, -271, 52], [-38, 38, -117, -38], [464, 42, 0, 42], [-28, 28, -92, -28], [-48, 342, 0, 342], [114, 260, 0, 260], [136, 306, 0, 306], [-44, 44, 61, -44], [4, -4, -86, 4], [-568, 62, 0, 62], [518, 316, 0, 316], [88, -88, -76, 88], [154, -154, 55, 154], [-236, 446, 0, 446], [-20, 20, 36, -20], [134, -134, 213, 134], [-116, 116, -282, -116], [576, -134, 0, -134], [122, 344, 0, 344], [-102, -328, 0, -328], [104, -142, 0, -142], [-116, 116, -169, -116], [-744, 210, 0, 210], [218, 200, 0, 200], [44, -44, 122, 44], [232, -402, 0, -402], [-134, 134, -115, -134], [-220, 220, 267, -220], [-352, 70, 0, 70], [-208, 208, 220, -208], [264, -590, 0, -590], [426, -260, 0, -260], [12, -12, -52, 12], [158, -158, -147, 158], [-284, 142, 0, 142], [-348, -262, 0, -262], [64, -64, -103, 64], [18, -18, 199, 18], [-104, 104, 27, -104], [-108, 108, -442, -108], [88, -88, 204, 88], [968, 254, 0, 254], [-294, -20, 0, -20], [1082, 160, 0, 160], [140, -140, 259, 140], [-866, 192, 0, 192], [182, -182, -125, 182], [-396, 396, 246, -396], [1226, -68, 0, -68], [-122, 122, 65, -122], [244, -244, 14, 244], [316, -346, 0, -346]]
