← LibraryFactoring Polynomials over Finite FieldsEngineering · MathematicsLesson 31/32← PrevNext →
ArticlePublished 6 Aug 2026Updated 5 Aug 20268 min readBy Kevin Jogin
KEVOS® Knowledge Library · Engineering → Mathematics

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
Polynomial timeSolved problemRandomised algorithms factor degree-k polynomials over Fq in expected Õ(k2 + k log q) operations.
gcd(f, Xqd−X)Degree separationExtracts exactly the factors of degree d — the distinct-degree stage.
≥ 1/2Splitting probabilityEach Cantor–Zassenhaus trial separates a given pair of factors with probability at least one half.
dim kerBerlekampThe number of irreducible factors equals the kernel dimension of Frobenius − I.

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.

  1. Squarefree decomposition

    Compute gcd(f, f′) to strip repeated factors, handling the characteristic-p case where the derivative vanishes.

  2. Distinct-degree factorization

    For d = 1, 2, … compute gcd(f, Xqd − X), which collects precisely the irreducible factors of degree d.

  3. Equal-degree factorization

    Split each same-degree product with random probes; each trial succeeds with probability at least one half.

  4. Verify

    Multiply the factors back together. Verification is cheap and turns a randomised procedure into a certain answer.

Contents

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

  1. if f′ = 0:
  2. // every exponent is a multiple of p
  3. write f = g(X^p); take p-th roots of coefficients (Frobenius is invertible)
  4. recurse on g₁ with f = g₁^p
  5. d ← gcd(f, f′); w ← f/d
  6. // w holds each distinct irreducible factor exactly once
  7. peel multiplicities: repeatedly gcd w with d, dividing out as multiplicities are identified
  8. 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.

Contents

03

Distinct-degree factorization

Theorem T1

The degree-separating identity

Xqd − X = ∏ { g : g monic irreducible over Fq, deg g ∣ d }

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

  1. input: squarefree monic f
  2. h ← X mod f; d ← 0
  3. while deg f > 0:
  4. d ← d+1; h ← h^q mod f // one Frobenius application
  5. g ← gcd(h − X, f) // product of the degree-d factors
  6. if g ≠ 1: record (g, d); f ← f/g; h ← h mod f
  7. if deg f < 2d+2: record (f, deg f); break
  8. 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.
Contents

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)

  1. input: f, a product of r ≥ 2 distinct irreducibles each of degree d
  2. repeat:
  3. pick a random a ∈ F_q[X] with deg a < deg f
  4. g ← gcd(a, f); if g ≠ 1: return g // lucky hit
  5. b ← a^{(q^d − 1)/2} mod f
  6. g ← gcd(b − 1, f)
  7. if 1 < deg g < deg f: return g // non-trivial split found
  8. 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.

Contents

05

Berlekamp's algorithm

Theorem T2

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).

  1. 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.

  2. 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.

  3. 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.

Choosing between the two approaches
CriterionBerlekampCantor–Zassenhaus
Cost dependence on qSplitting step scales with q if done deterministicallyOnly logarithmic in q
Cost dependence on degreeO(k3) for the linear algebraÕ(k2) with the standard stages
RandomnessNeeded only to pick useful kernel elementsEssential to the splitting step
Extra informationReveals the number of factors immediatelyDiscovers factors one at a time
Best forSmall q, moderate degreeLarge 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.

Contents

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

  1. repeat:
  2. pick a random monic f of degree k
  3. if f passes the irreducibility test: return f
  4. // 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.
Contents

07

Quick reference and FAQ

Facts
FactStatement
Squarefree testgcd(f, f′) = 1
Degree separationgcd(f, Xqd − X) collects degree-d factors
IrreducibilityXqk ≡ X and coprimality at each k/ℓ
Split probability≥ 1/2 per Cantor–Zassenhaus trial
Factor countdim ker(Q − I) in Berlekamp's method
Irreducible density≈ 1/k among monic degree-k polynomials
Overall costExpected Õ(k2 + k log q) operations
Characteristic 2Use the trace map instead of the (qd−1)/2 power
Why is randomness needed at all?
The equal-degree stage must break a symmetry: the factors are indistinguishable by any polynomial-time deterministic criterion currently known, and a random probe breaks the tie. Deterministic alternatives exist under the extended Riemann hypothesis or for small characteristic.
Does this help with factoring polynomials over ℚ?
It is the first step. Factor modulo a well-chosen prime, lift the factorization to a prime power by Hensel's lemma, then recombine factors — with lattice reduction (LLL) used to make the recombination step polynomial time rather than exponential.
How is the number of irreducible factors known before finding them?
Berlekamp's method computes it as the kernel dimension of Q − I, which is a single Gaussian elimination. The distinct-degree stage also reveals the degree profile before any equal-degree splitting is attempted.
Can these algorithms find roots of a polynomial over a finite field?
Yes — root finding is the degree-one case. Compute gcd(f, Xq − X) to isolate the linear factors, then apply equal-degree splitting with d = 1. This is the standard method behind modular square and cube root extraction for general exponents.
Contents

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


Continue learning

Polynomial Arithmetic and ApplicationsArticle · MathematicsNEXT LESSON →The RSA CryptosystemArticle · MathematicsSubexponential Factoring and Index CalculusArticle · MathematicsComputing Modular Square RootsArticle · Mathematics