Polynomials

Factoring

x⁶ − 1 = (x − 1)(x + 1)(x² − x + 1)(x² + x + 1). Factoring into irreducible pieces is the engine under every algebraic number here, since each arithmetic result is put on its minimal polynomial by factoring a resultant.

The Zassenhaus method

Factoring over the integers goes through a prime p:

  1. Square-free part. Repeated factors are split off first with gcds of f and f′ (Yun's algorithm), so (x − 1)³ is found as x − 1 with multiplicity 3.
  2. Factor mod p. Choose a small prime that keeps f square-free mod p. Over the finite field F_p, Cantor–Zassenhaus factoring is fast: distinct-degree factoring groups irreducible factors by degree using gcd(f, x^(pᵈ) − x), and equal-degree factoring splits each group with random gcds.
  3. Hensel lifting. The factorisation mod p is lifted to one mod pᵏ, for pᵏ larger than twice a bound on the coefficients of any true factor (a Mignotte-style bound).
  4. Recombination. Each true factor over Z is, mod pᵏ, a product of some of the lifted factors. Products of 1, 2, … lifted factors are tried (with symmetric remainders) until each one either divides f exactly or is ruled out.

The mod p picture already says a lot. x⁴ + 1 is irreducible over the integers, yet it factors modulo every prime; the recombination step is what proves no product of the pieces works over Z.

The same polynomial modulo several primes

The degrees of the factors mod p are the cycle shapes of Frobenius acting on the roots; how often each shape appears as p varies is governed by the Galois group (Chebotarev's density theorem). See Galois groups.

In code

import { factor, isIrreducible, factorModP } from "@ratmath/algebraic";
factor([-1, 0, 0, 0, 0, 0, 1]);
// { content: 1n, factors: [{ factor: [-1n, 1n], multiplicity: 1 }, …] }
isIrreducible([1, 0, 0, 0, 1]);   // true
factorModP([1n, 0n, 0n, 0n, 1n], 17n);  // four linear factors mod 17
Try itEdit the code and run it with @ratmath/algebraic and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs