Factoring
x³ + y³ + z³ − 3xyz = (x + y + z)(x² + y² + z² − xy − xz − yz). Factoring finds the irreducible pieces of any polynomial with rational coefficients, in any number of variables.
What the answer means
A polynomial is irreducible over Q when it is not a product of two polynomials of lower degree with rational coefficients. Every nonzero polynomial is a product
of irreducible ones, uniquely up to order and sign. The library returns each with whole-number coefficients having no common factor, and puts the leftover rational number in unit.
The field matters. is irreducible over Q but equals once is allowed; is irreducible over Q but splits over Q(√2). Curiously , the circle, stays irreducible over every field of characteristic other than 2.
How it is done: Kronecker's substitution
Factoring in one variable is a solved problem (the Zassenhaus method in @ratmath/algebraic). Kronecker's idea reduces several variables to one.
- Remove repeated factors with the square-free decomposition, and make the coefficients whole numbers.
- Substitute. Choose larger than the degree of in every variable and replace A monomial becomes : its exponents are the digits of one number in base . Distinct monomials with all exponents below therefore stay distinct, and the substitution can be undone.
- Factor the image in the single variable .
- Recombine. Any true factor of has exponents below as well, so its image is a product of some of the one-variable factors. Try each product of 1, 2, … of them: read its exponents back in base and test whether the result divides . Whatever divides is a factor; if nothing does, is irreducible.
For take : the image is . The product reads back as , which divides .
The method is simple and always right, but the image has degree about , so it suits the polynomials of a course or a calculator rather than very large ones. The library refuses (with a clear error) when the image would pass degree 60,000.
import { ring, factor, isIrreducible } from "@ratmath/structures";
const R = ring("x, y");
const { unit, factors } = factor(R.poly("2/3 x^4 y - 2/3 y^5"));
String(unit); // "2/3"
factors.map((t) => [String(t.factor), t.multiplicity]);
// [["y", 1], ["x + y", 1], ["x − y", 1], ["x² + y²", 1]]
isIrreducible(R.poly("x^2 + y^2 - 1")); // true
@ratmath/structures and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.