from sage.all import PolynomialRing, QQ, factorial
def chern_character_component(n):
R = PolynomialRing(QQ, ["c%s" % i for i in range(1, n + 1)])
c = R.gens()
power_sums = {}
for m in range(1, n + 1):
total = R(0)
for j in range(1, m):
total += (1 if j % 2 else -1) * c[j - 1] * power_sums[m - j]
total += (1 if (m + 1) % 2 == 0 else -1) * QQ(m) * c[m - 1]
power_sums[m] = total
return power_sums[n] / factorial(n)
print(chern_character_component(6))The generator computes exact rational coefficients from Formula (2) and Formula (3).
Every stored component was checked against the Chern-root definition in Formula (1) and against $\mathrm{ch}_n(T\mathbb{P}^m)=(m+1)h^n/n!$ for $1\leq n\leq m\leq 6$.