FLINT3.7.0-dev
Algorithm

Irreducibility testing over finite fields

Cost
For ff of degree nn over Fq\mathbb{F}_q: Ben-Or and the distinct-degree test O(n C(n)+nM(n)+M(n)log⁡q)O(\sqrt{n}\, C(n) + n M(n) + M(n) \log q) in the worst case, much less on random inputs; Rabin's test with a Frobenius ladder O(log⁡n⋅(1+ω(n)) C(n)+M(n)log⁡q)O(\log n \cdot (1 + \omega(n))\, C(n) + M(n) \log q).

Testing whether f∈Fq[x]f \in \mathbb{F}_q[x] of degree nn is irreducible is cheaper than factoring it, and is the inner loop of the construction of irreducible polynomials, which define the extension fields Fqn\mathbb{F}_{q^n}. All tests are based on Theorem 1 of Factoring polynomials over finite fields: xqd−xx^{q^d} - x is the product of the monic irreducible polynomials whose degree divides dd. As in the factorisation algorithms, the powers hd=xqd mod fh_d = x^{q^d} \bmod f are computed from h1=xq mod fh_1 = x^q \bmod f either by exponentiation by qq or by modular composition, hi+j=hi(hj) mod fh_{i + j} = h_i(h_j) \bmod f (Lemma 3 of Factoring polynomials over finite fields). M(n)M(n) and C(n)C(n) denote the costs of multiplication and of modular composition.

Rabin's test#

Theorem 1 (Rabin [Rab1980b]). Let f∈Fq[x]f \in \mathbb{F}_q[x] have degree n≥1n \ge 1. Then ff is irreducible if and only if

xqn≡x(modf)andgcd⁡(f,xqn/r−x)=1 for every prime r∣n.x^{q^n} \equiv x \pmod f \quad \text{and} \quad \gcd\bigl(f, x^{q^{n/r}} - x\bigr) = 1 \text{ for every prime } r \mid n.

Proof. If ff is irreducible, it divides xqn−xx^{q^n} - x, and it divides xqn/r−xx^{q^{n/r}} - x for no rr because n∤n/rn \nmid n/r. Conversely, the first condition says that ff divides the squarefree polynomial xqn−xx^{q^n} - x, so ff is squarefree and all its irreducible factors have degrees dividing nn. If ff had a factor of degree d<nd < n, d∣nd \mid n, then dd would divide n/rn/r for some prime r∣nr \mid n, and that factor would divide gcd⁡(f,xqn/r−x)\gcd(f, x^{q^{n/r}} - x).

The test needs hnh_n and hn/rh_{n/r} for the ω(n)\omega(n) prime divisors rr of nn. gr_poly_is_irreducible_rabin computes the ladder Li=xq2i mod f=Li−1(Li−1) mod fL_i = x^{q^{2^i}} \bmod f = L_{i-1}(L_{i-1}) \bmod f for 2i≤n2^i \le n, and then each heh_e as a composition of the LiL_i along the binary expansion of ee. This takes O(log⁡n)O(\log n) compositions for the ladder and for each of the 1+ω(n)1 + \omega(n) powers, independently of qq apart from the first step L0=h1L_0 = h_1, which costs O(M(n)log⁡q)O(M(n) \log q). The test does the same amount of work whether or not ff is irreducible.

nmod_poly_is_irreducible_rabin is an older implementation of the same test that computes each heh_e by ee exponentiations by qq, at a cost of O(nM(n)log⁡q)O(n M(n) \log q).

Ben-Or's test and the distinct-degree test#

Theorem 2 (Ben-Or [BenOr1981]). ff of degree n≥1n \ge 1 is irreducible if and only if gcd⁡(f,xqi−x)=1\gcd(f, x^{q^i} - x) = 1 for 1≤i≤n/21 \le i \le n/2.

Proof. A reducible ff has an irreducible factor of degree d≤n/2d \le n/2, which divides xqd−xx^{q^d} - x. Conversely, an irreducible ff of degree nn divides xqi−xx^{q^i} - x only if n∣in \mid i.

Ben-Or's test computes h1,h2,…h_1, h_2, \ldots one after the other and stops at the first nontrivial gcd. Its worst case, reached for irreducible ff, is n/2n/2 steps; but a random polynomial has a factor of small degree with high probability: by an analogue of Mertens' theorem, the probability that a random monic polynomial of degree nn has no irreducible factor of degree at most ii tends to about e−γ/ie^{-\gamma}/i for large nn and ii, so the expected number of steps on random input is small [GaoPan1997]. Since a random polynomial of degree nn is irreducible with probability about 1/n1/n, this early exit is what matters when searching for irreducible polynomials, and Gao and Panario [GaoPan1997] found Ben-Or's test much faster than Rabin's in that setting. gr_poly_is_irreducible_ben_or implements it, with each step a composition with the precomputed matrix of powers of h1h_1 when qq is large, and an exponentiation by qq otherwise.

The distinct-degree test gr_poly_is_irreducible_ddf runs the coarse phase of the baby-step giant-step distinct-degree factorisation (Algorithm 2 of Factoring polynomials over finite fields): it computes ℓ≈n/2\ell \approx \sqrt{n/2} baby steps and then, for each interval (ℓj,ℓ(j+1)](\ell j, \ell(j+1)] of degrees, one giant step and the gcd of ff with the interval polynomial, stopping at the first nontrivial gcd. It is Ben-Or's test with the degrees grouped into intervals, so it costs O(n C(n)+nM(n))O(\sqrt{n}\, C(n) + n M(n)) for irreducible inputs and also exits early for most reducible ones, though only after the ℓ\ell baby steps.

Both tests first check squarefreeness with one gcd (gcd⁡(f,f′)=1\gcd(f, f') = 1), which is cheap and rejects some inputs immediately.

FLINT's strategy#

gr_poly_is_irreducible, which nmod_poly_is_irreducible, fmpz_mod_poly_is_irreducible and the fq_*_poly_is_irreducible functions wrap, proceeds as follows for ff of degree n≥2n \ge 2:

  1. Over a prime field Fp\mathbb{F}_p with p≤max⁡(200,2(n+1))p \le \max(200, 2(n + 1)), evaluate ff at all pp elements and return false if there is a root. For small pp this rejects a large fraction of random inputs at a cost of O(np)O(np).
  2. If n<600n < 600, return the result of the distinct-degree test.
  3. Otherwise check squarefreeness, then compute gcd⁡(f,xqi−x)\gcd(f, x^{q^i} - x) for i≤4i \le 4 (with exponentiations) and return false if one is nontrivial, and finally return the result of Rabin's test.

For large irreducible inputs Rabin's test with the Frobenius ladder needs O(log⁡n)O(\log n) compositions against O(n)O(\sqrt{n}) for the distinct-degree test, so the crossover is at a moderate degree; the filter in step 3 keeps the early exit for random inputs, whose smallest factor usually has small degree. The generic functions return T_UNKNOWN when they cannot decide (for example over a context that is not known to be a finite field); the type-specific wrappers throw an exception in that case, and, unlike the generic functions, consider constants irreducible.

Constructing irreducible polynomials#

An irreducible polynomial of degree nn over Fq\mathbb{F}_q is found by testing random monic polynomials: there are about qn/nq^n / n of them among the qnq^n monic polynomials, so about nn trials are needed on average (nmod_poly_randtest_irreducible, fmpz_mod_poly_randtest_irreducible). For finite field arithmetic sparse polynomials are preferable, because reduction modulo a trinomial or pentanomial is cheap; nmod_poly_minimal_irreducible searches binomials, trinomials, tetranomials and pentanomials in a fixed order with nmod_poly_is_irreducible_ddf. Conway polynomials, which make the embeddings between different extension fields compatible, cannot be computed efficiently in general and are taken from a table ([Lüb2004]; _nmod_poly_conway). The finite field contexts such as fq_nmod_ctx_init_ui use the Conway polynomial when the table contains it and the sparse polynomial of nmod_poly_minimal_irreducible otherwise. The choice of defining polynomials for the finite field types is discussed in Defining polynomials.

Referenced from#

References#

  • [Rab1980b] M. O. Rabin. Probabilistic algorithms in finite fields. SIAM Journal on Computing 9 (1980), 273–280.
  • [BenOr1981] M. Ben-Or. Probabilistic algorithms in finite fields. 22nd Annual Symposium on Foundations of Computer Science (FOCS 1981), IEEE, 394–398.
  • [GaoPan1997] S. Gao and D. Panario. Tests and constructions of irreducible polynomials over finite fields. In Foundations of Computational Mathematics (F. Cucker, M. Shub, eds.), Springer, 1997, 346–361.
  • [Lüb2004] F. Lübeck, "Conway polynomials for finite fields", RTWH Aachen, https://www.math.rwth-aachen.de/~Frank.Luebeck/data/ConwayPol/index.html, (accessed 2024-01-12)
Cite this page

The FLINT team, “Irreducibility testing over finite fields,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/polynomials/irreducibility.html (generated 2026-11-02).