Irreducibility testing over finite fields
- Cost
- For of degree over : Ben-Or and the distinct-degree test in the worst case, much less on random inputs; Rabin's test with a Frobenius ladder .
Testing whether of degree is irreducible is cheaper than factoring it, and is the inner loop of the construction of irreducible polynomials, which define the extension fields . All tests are based on Theorem 1 of Factoring polynomials over finite fields: is the product of the monic irreducible polynomials whose degree divides . As in the factorisation algorithms, the powers are computed from either by exponentiation by or by modular composition, (Lemma 3 of Factoring polynomials over finite fields). and denote the costs of multiplication and of modular composition.
Rabin's test#
Theorem 1 (Rabin [Rab1980b]). Let have degree . Then is irreducible if and only if
Proof. If is irreducible, it divides , and it divides for no because . Conversely, the first condition says that divides the squarefree polynomial , so is squarefree and all its irreducible factors have degrees dividing . If had a factor of degree , , then would divide for some prime , and that factor would divide .
The test needs and for the prime divisors of . gr_poly_is_irreducible_rabin computes the ladder for , and then each as a composition of the along the binary expansion of . This takes compositions for the ladder and for each of the powers, independently of apart from the first step , which costs . The test does the same amount of work whether or not is irreducible.
nmod_poly_is_irreducible_rabin is an older implementation of the same test that computes each by exponentiations by , at a cost of .
Ben-Or's test and the distinct-degree test#
Theorem 2 (Ben-Or [BenOr1981]). of degree is irreducible if and only if for .
Proof. A reducible has an irreducible factor of degree , which divides . Conversely, an irreducible of degree divides only if .
Ben-Or's test computes one after the other and stops at the first nontrivial gcd. Its worst case, reached for irreducible , is 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 has no irreducible factor of degree at most tends to about for large and , so the expected number of steps on random input is small [GaoPan1997]. Since a random polynomial of degree is irreducible with probability about , 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 when is large, and an exponentiation by 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 baby steps and then, for each interval of degrees, one giant step and the gcd of 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 for irreducible inputs and also exits early for most reducible ones, though only after the baby steps.
Both tests first check squarefreeness with one gcd (), 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 of degree :
- Over a prime field with , evaluate at all elements and return false if there is a root. For small this rejects a large fraction of random inputs at a cost of .
- If , return the result of the distinct-degree test.
- Otherwise check squarefreeness, then compute for (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 compositions against 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 over is found by testing random monic polynomials: there are about of them among the monic polynomials, so about 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.
truth_t gr_poly_is_irreducible(const gr_poly_t f, gr_ctx_t ctx)truth_t gr_poly_is_irreducible_ddf(const gr_poly_t f, gr_ctx_t ctx)truth_t gr_poly_is_irreducible_rabin(const gr_poly_t f, gr_ctx_t ctx)truth_t gr_poly_is_irreducible_ben_or(const gr_poly_t f, gr_ctx_t ctx)int nmod_poly_is_irreducible(const nmod_poly_t f)int nmod_poly_is_irreducible_ddf(const nmod_poly_t f)int nmod_poly_is_irreducible_rabin(const nmod_poly_t f)int fmpz_mod_poly_is_irreducible(const fmpz_mod_poly_t f, const fmpz_mod_ctx_t ctx)int fmpz_mod_poly_is_irreducible_ddf(const fmpz_mod_poly_t f, const fmpz_mod_ctx_t ctx)int fmpz_mod_poly_is_irreducible_rabin(const fmpz_mod_poly_t f, const fmpz_mod_ctx_t ctx)Referenced from#
- Defining polynomials (algorithm)
- Factoring polynomials over finite fields (algorithm)
fmpz_mod_poly_is_irreducible- gr_poly.h (module)
nmod_poly_is_irreducible
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)
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).
@misc{flint-doc-algorithms-polynomials-irreducibility,
author = {{The FLINT team}},
title = {{Irreducibility testing over finite fields}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/algorithms/polynomials/irreducibility.html},
note = {Generated 2026-11-02}
}