
# q-expansion of newform 441.3.m.f, downloaded from the LMFDB on 28 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 = 441
weight = 3
poly_data = [1, -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 = [[344, [1, 0]], [199, [0, 1]]]
aps_data = [[0, 1], [0, 0], [8, -4], [0, 0], [10, -10], [-4, 8], [0, 0], [-24, 12], [0, -14], [38, 0], [-16, -16], [0, -26], [-40, 80], [26, 0], [-32, 16], [10, -10], [44, 44], [40, -20], [-74, 74], [62, 0], [24, 24], [0, 46], [52, -104], [48, -24], [-32, 64], [-68, -68], [-112, 56], [0, 10], [-74, 74], [-178, 0], [-190, 0], [56, -28], [-206, 206], [68, -136], [0, 106], [46, -46], [140, 140], [0, -170], [56, -112], [-200, 100], [-38, 38], [-108, 216], [0, 82], [-50, 50], [278, 0], [-168, -168], [74, 0], [-176, 352], [4, 4], [-328, 164], [0, 178], [-34, 0], [112, 112], [108, -216], [-160, 80], [-62, 62], [132, 132], [-384, 192], [-26, 26], [494, 0], [116, 116], [284, -568], [12, -24], [8, 8], [304, -152], [0, 250], [0, 646], [146, 0], [106, -106], [364, -728], [-176, -176], [0, -494], [-320, -320], [0, -218], [-550, 0], [-64, 32], [394, -394], [-120, 60], [0, 178], [-376, -376], [-412, 824], [602, 0], [34, -34], [240, -480], [112, -56], [0, -470], [-514, 0], [0, 478], [388, -776], [-430, 0], [984, -492], [-224, -224], [-818, 818], [-490, 0], [0, -554], [168, -336], [1112, -556], [-72, -72], [-72, 36], [0, 118], [-406, 0], [-998, 998], [212, 212], [0, -62], [-410, 410], [-480, -480], [316, -632], [-1152, 576], [1186, -1186], [232, -464], [-160, 80], [-26, 26], [734, 0], [484, 484], [-286, 0], [658, -658], [188, -376], [-264, -264], [0, -614], [-442, 0], [20, 20], [386, 0], [904, -452], [298, -298], [1000, -500], [-154, 0], [0, -890], [-96, 48], [136, -272], [-88, 44], [982, -982], [686, 0], [0, -290], [-358, 0], [752, -376], [-448, 896], [-132, -132], [44, 44], [500, -1000], [802, -802], [516, -1032], [0, 1450], [1246, -1246], [-586, 0], [-468, -468], [-8, 16], [-140, 280], [808, 808], [344, -172], [0, -1070], [0, 502], [-576, 1152], [-118, 0], [-592, 296], [-1466, 1466], [542, 0], [0, 1630], [-224, 112], [696, -1392], [-508, -508], [0, 1402], [110, 0], [1202, 0], [-312, 156], [-1310, 1310], [904, 904], [-818, 818], [100, 100]]
