Elimination

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.

Where two curves meet
= 0
= 0

The resultant

Take two polynomials in xx, with coefficients that may involve other variables:

f=amxm+⋯+a0,g=bnxn+⋯+b0. f = a_m x^m + \dots + a_0, \qquad g = b_n x^n + \dots + b_0 .

They share a root (or a common factor) exactly when there are nonzero u,vu, v with deg⁡u<n\deg u < n, deg⁡v<m\deg v < m and uf+vg=0u f + v g = 0. Written out coefficient by coefficient, that is a square system of m+nm + n linear equations whose matrix is the Sylvester matrix: nn shifted rows of the coefficients of ff above mm shifted rows of those of gg. Its determinant is the resultant:

Res⁡x(f,g)=det⁡Syl⁡(f,g)=am n bn m∏i,j(αi−βj), \operatorname{Res}_x(f, g) = \det \operatorname{Syl}(f, g) = a_m^{\,n}\, b_n^{\,m} \prod_{i,j} (\alpha_i - \beta_j),

where the αi\alpha_i and βj\beta_j are the roots of ff and gg. So the resultant vanishes exactly when ff and gg have a common root in xx.

When ff and gg also involve yy, the resultant with respect to yy is a polynomial in xx alone. Its roots are the xx-coordinates of the common points of the two curves (together with any xx where both leading coefficients vanish). The variable yy 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 ff and f′f', normalised:

Disc⁡(f)=(−1)n(n−1)/2anRes⁡x(f,f′)=an2n−2∏i<j(αi−αj)2. \operatorname{Disc}(f) = \frac{(-1)^{n(n-1)/2}}{a_n} \operatorname{Res}_x(f, f') = a_n^{2n-2} \prod_{i < j} (\alpha_i - \alpha_j)^2 .

For a quadratic it is the familiar b2−4acb^2 - 4ac, and for x3+px+qx^3 + px + q it is −4p3−27q2-4p^3 - 27q^2. For a curve f(x,y)=0f(x, y) = 0, the discriminant with respect to yy vanishes at the xx 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

mij←mij mkk−mik mkjprevious pivot m_{ij} \leftarrow \frac{m_{ij}\, m_{kk} - m_{ik}\, m_{kj}}{\text{previous pivot}}

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
Try itEdit the code and run it with @ratmath/structures and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs