import numberdb.sage as numberdb
from sage.rings.integer_ring import ZZ
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
n = 5
R = PolynomialRing(ZZ, ["a%s" % i for i in range(n - 1)])
a = R.gens()
S = PolynomialRing(R, "x")
x = S.gen()
f = x**n + sum(a[i] * x**i for i in range(n - 1))
sign = -1 if (n * (n - 1) // 2) % 2 else 1
sign * f.resultant(f.derivative())The generator computes exact integer coefficients in $\mathbb Z[a_0,\dots,a_{n-2}]$ from the resultant identity in Formula (1), and all arithmetic is exact.
It checks Formula (2) by substituting the elementary symmetric polynomials of roots satisfying $\alpha_1+\cdots+\alpha_n=0$, compares the quadratic and cubic rows from Formula (3) and Formula (4) against the stored values, compares degrees $2$ through $5$ with the specialization of the general-polynomial discriminant, and compares integer specializations with Sage's exact univariate discriminant over $\mathbb Z[x]$.