Resultants and discriminants
Two equations in x and y can be turned into one equation in x alone. The resultant does it with a determinant, and tells you exactly where two curves meet.
The resultant
Take two polynomials in , with coefficients that may involve other variables:
They share a root (or a common factor) exactly when there are nonzero with , and . Written out coefficient by coefficient, that is a square system of linear equations whose matrix is the Sylvester matrix: shifted rows of the coefficients of above shifted rows of those of . Its determinant is the resultant:
where the and are the roots of and . So the resultant vanishes exactly when and have a common root in .
When and also involve , the resultant with respect to is a polynomial in alone. Its roots are the -coordinates of the common points of the two curves (together with any where both leading coefficients vanish). The variable has been eliminated.
import { ring, resultant, sylvester, discriminant } from "@ratmath/structures";
const R = ring("x, y");
const circle = R.poly("x^2 + y^2 - 1");
const parabola = R.poly("y - x^2");
String(resultant(circle, parabola, "y")); // "x⁴ + x² − 1"
sylvester(circle, parabola, "y"); // [[1, 0, x² − 1], [1, −x², 0], [0, 1, −x²]]
The discriminant
A polynomial has a repeated root exactly when it shares a root with its derivative. The discriminant is the resultant of and , normalised:
For a quadratic it is the familiar , and for it is . For a curve , the discriminant with respect to vanishes at the where the curve has a vertical tangent or a singular point.
Determinants without fractions
Gaussian elimination on a matrix of polynomials would fill it with fractions. Bareiss elimination avoids them: the update
always divides exactly, because every entry it produces is itself a minor of the original matrix (Sylvester's identity). The entries stay polynomials and stay as small as possible, and the last pivot is the determinant.
import { det, jacobian, hessian } from "@ratmath/structures";
const S = ring("x, y, z");
const [x, y, z] = S.gens;
String(det([[1, x, x.pow(2)], [1, y, y.pow(2)], [1, z, z.pow(2)]]));
// the Vandermonde determinant (y − x)(z − x)(z − y), expanded
const T = ring("u, v");
const J = jacobian([T.poly("u^2 - v^2"), T.poly("2 u v")]); // rows are gradients
String(det(J)); // "4u² + 4v²"
hessian(T.poly("u^3 - 3 u v^2")); // second partial derivatives
@ratmath/structures and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.