from sage.all import PolynomialRing, ZZ
def segre_component(n):
R = PolynomialRing(ZZ, ["c%s" % i for i in range(1, n + 1)])
c = [R(1)] + list(R.gens())
s = [R(1)]
for m in range(1, n + 1):
s.append(-sum(c[j] * s[m - j] for j in range(1, m + 1)))
return s[n]
print(segre_component(7))The generator computes exact integer coefficients in $\mathbb Z[c_1,\dots,c_6]$ from Formula (1).
Every stored component is checked against the Chern-root identity in Formula (2) and by substituting the Chern classes of $T\mathbb P^m$ for $1\leq n\leq m\leq 6$, which gives $s_n(T\mathbb P^m)=(-1)^n\binom{m+n}{n}h^n$, where $h$ is the hyperplane class.