Engineering/Mathematics/Algorithm engineering
Factoring Polynomials over Finite Fields
Unlike integer factorization, polynomial factorization over a finite field is solved: randomised algorithms run in polynomial time and are fast in practice. The whole approach rests on one structural gift — the Frobenius map — that the integers do not provide.
- Core algorithm
- Computing
- Polynomial time
- ≈16 min read
- Builds finite fields
01
Executive summary
Factorization proceeds in three stages, and separating them is what makes the problem tractable. Squarefree decomposition removes repeated factors using the derivative. Distinct-degree factorization separates the remaining factors by degree using gcds with Xqd − X. Equal-degree factorization splits a product of same-degree irreducibles, and this is the only stage that requires randomness.
Berlekamp's algorithm is an alternative that solves the whole problem with linear algebra: the factors correspond to the kernel of the Frobenius map minus the identity. It is preferable for small fields and low degrees; Cantor–Zassenhaus scales better for large q.
Squarefree decomposition
Compute gcd(f, f′) to strip repeated factors, handling the characteristic-p case where the derivative vanishes.
Distinct-degree factorization
For d = 1, 2, … compute gcd(f, Xqd − X), which collects precisely the irreducible factors of degree d.
Equal-degree factorization
Split each same-degree product with random probes; each trial succeeds with probability at least one half.
Verify
Multiply the factors back together. Verification is cheap and turns a randomised procedure into a certain answer.
02
Squarefree decomposition
A repeated irreducible factor of f divides gcd(f, f′), so a single gcd separates the squarefree part from the rest — no factoring required.
Squarefree decomposition over F_q, characteristic p
- if f′ = 0:
- // every exponent is a multiple of p
- write f = g(X^p); take p-th roots of coefficients (Frobenius is invertible)
- recurse on g₁ with f = g₁^p
- d ← gcd(f, f′); w ← f/d
- // w holds each distinct irreducible factor exactly once
- peel multiplicities: repeatedly gcd w with d, dividing out as multiplicities are identified
- output list of (squarefree factor, multiplicity)
O(k²) field operations for degree k. Always the first stage — the later algorithms assume a squarefree input.
The vanishing-derivative branch is not optional
Over Fq with characteristic p, the polynomial Xp − a has zero derivative even though it is non-constant. An implementation that assumes f′ ≠ 0 for non-constant f will loop or return wrong results on such inputs. Take p-th roots of the coefficients using the inverse Frobenius, which exists because Frobenius is bijective on a finite field.
03
Distinct-degree factorization
The degree-separating identity
Hence for a squarefree f, the gcd of f with Xqd − X is exactly the product of the irreducible factors of f whose degree divides d. Processing d in increasing order and dividing out at each step isolates the factors of each degree.
Distinct-degree factorization
- input: squarefree monic f
- h ← X mod f; d ← 0
- while deg f > 0:
- d ← d+1; h ← h^q mod f // one Frobenius application
- g ← gcd(h − X, f) // product of the degree-d factors
- if g ≠ 1: record (g, d); f ← f/g; h ← h mod f
- if deg f < 2d+2: record (f, deg f); break
- output list of (product of degree-d factors, d)
O(k) Frobenius applications, each O(k² log q) classically, plus one gcd per step. The early-exit test avoids a full sweep when the remaining factor must be irreducible.
- Frobenius dominates the cost. Computing hq mod f is a modular exponentiation with exponent q. Precomputing the matrix of the Frobenius map on Fq[X]/(f) turns each subsequent application into a matrix–vector product.
- Irreducibility test for free. A degree-k polynomial is irreducible exactly when Xqk ≡ X (mod f) and gcd(f, Xqk/ℓ − X) = 1 for every prime ℓ ∣ k. This is the standard test used when constructing finite fields.
- Root finding is the case d = 1. The roots of f in Fq are the linear factors, extracted by gcd(f, Xq − X) followed by an equal-degree split.
04
Equal-degree factorization: Cantor–Zassenhaus
After the previous stage, each remaining polynomial is a product of r distinct irreducibles all of the same degree d. By the Chinese remainder theorem, Fq[X]/(f) ≅ (Fqd)r, and a random element has an independent coordinate in each copy. Raising to the power (qd−1)/2 sends each coordinate to ±1 at random, so a gcd separates the components.
Cantor–Zassenhaus equal-degree split (odd q)
- input: f, a product of r ≥ 2 distinct irreducibles each of degree d
- repeat:
- pick a random a ∈ F_q[X] with deg a < deg f
- g ← gcd(a, f); if g ≠ 1: return g // lucky hit
- b ← a^{(q^d − 1)/2} mod f
- g ← gcd(b − 1, f)
- if 1 < deg g < deg f: return g // non-trivial split found
- recurse on g and f/g until all factors are irreducible
Each trial costs one modular exponentiation, O(d log q) squarings in F_q[X]/(f). The probability of a non-trivial split is at least 1/2, so the expected number of trials is at most 2.
Characteristic two needs a different probe
The exponent (qd−1)/2 is meaningless when q is even. The standard substitute is the trace map a + a2 + a4 + ⋯ + a2d−1, whose value in each component is 0 or 1 with equal probability, giving the same splitting behaviour.
05
Berlekamp's algorithm
The Berlekamp subalgebra
For squarefree f with r irreducible factors, the set B = {a ∈ Fq[X]/(f) : aq = a} is an Fq-vector space of dimension exactly r — it is the kernel of the linear map Q − I, where Q is the matrix of the Frobenius map. Any non-constant a ∈ B yields a non-trivial factor, because f = ∏c ∈ Fq gcd(f, a − c).
Build the Frobenius matrix
Compute Xiq mod f for i = 0,…,k−1; these are the columns of Q. Cost O(k2 log q + k3) or better.
Compute the kernel of Q − I
Gaussian elimination gives a basis; its dimension is the number of irreducible factors, known before any factor is found.
Split using basis elements
For a non-constant basis element a, the gcds gcd(f, a − c) over c ∈ Fq split f. Small q means few values of c to try.
| Criterion | Berlekamp | Cantor–Zassenhaus |
|---|---|---|
| Cost dependence on q | Splitting step scales with q if done deterministically | Only logarithmic in q |
| Cost dependence on degree | O(k3) for the linear algebra | Õ(k2) with the standard stages |
| Randomness | Needed only to pick useful kernel elements | Essential to the splitting step |
| Extra information | Reveals the number of factors immediately | Discovers factors one at a time |
| Best for | Small q, moderate degree | Large q, high degree |
Production computer algebra systems implement both and select on the parameters, often after a cheap distinct-degree pass that may finish the job on its own.
06
Constructing irreducible polynomials
Building a finite field Fqk requires an irreducible polynomial of degree k over Fq. Random search is the method of choice.
Random irreducible polynomial of degree k over F_q
- repeat:
- pick a random monic f of degree k
- if f passes the irreducibility test: return f
- // test: X^{q^k} ≡ X (mod f) and gcd(f, X^{q^{k/ℓ}} − X) = 1 for each prime ℓ ∣ k
Success probability ≈ 1/k by the Möbius count I_q(k) ≈ q^k/k, so about k trials are expected. Each test costs O(k² log q) field operations.
- Prefer sparse moduli. Reduction modulo f costs one shifted subtraction per non-zero term, so trinomials and pentanomials give the fastest field arithmetic. Standards for binary fields specify particular low-weight polynomials.
- Primitive polynomials — those whose roots generate F*qk — are needed for maximal-length shift register sequences. Verifying primitivity requires the factorization of qk−1, which is a much harder precondition than irreducibility.
- Deterministic construction is possible in polynomial time only under the extended Riemann hypothesis, or in special characteristics. Unconditional deterministic construction for arbitrary q and k remains open — a striking gap given how easy the randomised version is.
07
Quick reference and FAQ
| Fact | Statement |
|---|---|
| Squarefree test | gcd(f, f′) = 1 |
| Degree separation | gcd(f, Xqd − X) collects degree-d factors |
| Irreducibility | Xqk ≡ X and coprimality at each k/ℓ |
| Split probability | ≥ 1/2 per Cantor–Zassenhaus trial |
| Factor count | dim ker(Q − I) in Berlekamp's method |
| Irreducible density | ≈ 1/k among monic degree-k polynomials |
| Overall cost | Expected Õ(k2 + k log q) operations |
| Characteristic 2 | Use the trace map instead of the (qd−1)/2 power |
Why is randomness needed at all?
Does this help with factoring polynomials over ℚ?
How is the number of irreducible factors known before finding them?
Can these algorithms find roots of a polynomial over a finite field?
09
References and further reading
- V. Shoup, A Computational Introduction to Number Theory and Algebra, Cambridge University Press, 2005 — Chapter 21.
- E. R. Berlekamp, 'Factoring polynomials over finite fields', Bell System Technical Journal 46 (1967) 1853–1859.
- D. G. Cantor and H. Zassenhaus, 'A new algorithm for factoring polynomials over finite fields', Math. Comp. 36 (1981) 587–592.
- J. von zur Gathen and J. Gerhard, Modern Computer Algebra, 3rd ed., Cambridge, 2013 — Chapter 14.
- V. Shoup, 'A new polynomial factorization algorithm and its implementation', J. Symbolic Computation 20 (1995) 363–397.
KEVOS® Knowledge LibraryEngineering → MathematicsTaxonomy ID: ENG-MATHPage ID: factoring-polynomials-over-finite-fieldsReview cycle: annual
