Factoring over finite fields
- Cost
- Polynomial in the degrees and the number of terms in practice (randomised); the extension degree is of the number of terms, and the Frobenius recombination costs coefficient powerings per factor for an extension of degree .
FLINT factors a polynomial , with a word-size prime , in the same stages as over the integers (see Factorisation): content removal, squarefree (separable) decomposition, reduction to a bivariate problem by evaluation, bivariate factorisation, and lifting of the bivariate factors to all variables by Hensel lifting [Wan1978] [MonTun2020] or recombination [Zas1969]. Two things differ in positive characteristic. A polynomial can have zero derivative without being constant, which the squarefree decomposition must handle; and the field can be too small to provide the evaluation points that the reduction to two variables needs. The second problem is solved by factoring over an extension field and recombining the factors found there along the orbits of the Frobenius automorphism, an idea that goes back to von zur Gathen and Kaltofen's analysis of factoring over finite fields. The implementation follows the notes of its author [Sch-mpoly].
The pipeline#
nmod_mpoly_factor_algo (and fq_nmod_mpoly_factor_algo) proceeds as follows. Throughout, factors are made monic and the leading coefficient of is kept as the constant of the factorisation.
- Content.
nmod_mpoly_factor_contentremoves the monomial content (powers of variables dividing ) and splits into factors that are primitive with respect to every variable, by repeatedly computing the content with respect to one variable. - Compression. Each factor is compressed by an invertible affine change of the exponent lattice (
mpoly_compression_set) so that it uses as few variables and as small exponents as possible. A randomised test on projections of its Newton polytope may prove the factor irreducible at this point (an indecomposable Newton polytope implies irreducibility [Gao2001]). - Separable decomposition (
nmod_mpoly_factor_separablewithsep= 1): see Separable factorisation in characteristic . Each resulting factor is squarefree and satisfies, for every variable, or , with at least one nonzero derivative. - Deflation by powers of (Deflation by powers of ) and a permutation that puts a variable with first.
- Irreducible factorisation of each factor: univariate factorisation (
nmod_poly_factor) for one variable; bivariate factorisation (n_bpoly_mod_factor_smprime, elsen_bpoly_mod_factor_lgprime) for two; for more variables, polynomials of degree 1 in are irreducible, those of degree 2 are split by solving a quadratic equation withnmod_mpoly_quadratic_root(Quadratics), and the others are factored by the lifting algorithms of Evaluation points and extension fields. - The factors are inflated, uncompressed, and multiplied by the multiplicities of the separable decomposition.
Separable factorisation in characteristic #
In characteristic zero, Yun's algorithm [Yun1976] computes the squarefree decomposition from GCDs of with its derivatives. In characteristic the derivative vanishes on the terms whose exponent in is a multiple of , so factors of multiplicity divisible by , and factors that are polynomials in , are invisible to it [GT1996] [Lec2008]. The following lemma deals with what remains.
Lemma 1 (-th roots). Let be a perfect field of characteristic , and with for all . Then , where is obtained from by dividing every exponent by and replacing every coefficient by . For , , and over , .
Proof. The coefficient of in is , so means that whenever . Thus with all exponents divisible by . As the Frobenius map is a ring endomorphism in characteristic , . In , , so .
_nmod_mpoly_factor_separable works as follows on a monic primitive . For each variable in turn (choosing first the variable whose derivative has the fewest terms), it runs Yun's algorithm with respect to that variable on the current cofactor : with , , , , and while and the multiplicity is less than , the factor of multiplicity is . The factors found are split further against the derivatives with respect to the remaining variables, to obtain the property of step 3. When all variables have been processed, the remaining has zero derivative in every variable; with the largest power of dividing all its exponents, by Lemma 1, is computed by deflation (and, over , by the coefficient map with ), its separable decomposition is computed recursively and raised to the power , and the two decompositions are merged into one with pairwise coprime bases by GCDs.
Deflation by powers of #
After the separable decomposition, a factor may still have all its exponents in some variables divisible by a power of , for example . FLINT divides the exponents of each variable by the largest power of dividing all of them, factors the deflated polynomial (so that ) and inflates the factors. This is correct because of the following lemma.
Lemma 2. Let be a perfect field of characteristic , and irreducible with for some . Then is irreducible.
Proof. Write and let be the automorphism of that maps each coefficient to and fixes the variables. In with , the Frobenius gives , and is irreducible. Suppose in . Then , so by unique factorisation for a unit and some . The left side has zero derivative with respect to , while the derivative of the right side is , where . Hence , that is , and or is a unit.
Corollary 3. Let be squarefree, and obtained by dividing the exponents of some variables by powers of as above, with at least one variable undeflated. If is the irreducible factorisation, so is .
Proof. Each has nonzero derivative with respect to some undeflated variable: otherwise is a polynomial in the -th powers of the undeflated variables, and its inflation is a polynomial in -th powers of all variables, hence a -th power by Lemma 1, contradicting squarefreeness of . Deflating one variable and one power of at a time, Lemma 2 shows that each inflated stays irreducible.
Quadratics#
Let with be squarefree and primitive in . It is reducible if and only if it has a factor of degree 1 in . Since with , and the roots of this monic polynomial, a root of , are integral over the unique factorisation domain , the polynomial is reducible if and only if has a root ; then is the product of and with . In odd characteristic , and the square root is computed by the heap algorithm of Square roots. In characteristic 2 there is no such formula, and FLINT solves the equation (signs do not matter) directly, term by term, by an algorithm from Schultz's notes [Sch-mpoly] that simplifies §§4–5 of Cherly, Gallardo, Vaserstein and Wheland [CGVW1998], whose method divides by polynomials and does not preserve sparsity.
Let with (if the root is , if it is 0), and write with and a monomial. If is a root, so is , and the coefficients of in and differ by , so at most one of them equals : we may look for a root in which the coefficient of is not .
Lemma 4 (Leading term of a root). Let be a root of in which the coefficient of is not , and let be its leading term. Then exactly one of the following holds:
- : then and , which requires to be a square;
- : then and with ;
- : then and , which requires this quotient to be a monomial smaller than .
Moreover is a root of , the leading monomial of is smaller than that of , and the coefficient of in is not (in case 2 it is zero).
Proof. In characteristic 2, is the sum of the squares of the terms of , so its leading term is , while the leading term of is . If , the first dominates and ; if , the second does and . If , the two have the same monomial and their sum is , which is nonzero because ; it equals , and satisfies . In the three cases is , , or , so the case is determined by , and is determined by (in case 2 up to the two roots , ). Finally , and has leading term by the above.
Input: nonzero . Output: with , or "no root".
- Set and .
- While : determine from by the case of Lemma 4 that applies, using case 1 only while all terms of are larger than , and case 3 once a term has been chosen; if the required square root, quadratic root or monomial quotient does not exist, return "no root". Set and .
- Return .
By Lemma 4 and induction, if a root exists the algorithm finds one, term by term; if it returns , then and is a root. The leading monomial of decreases strictly, so the terms of form a strictly decreasing sequence of monomials, which is finite because a monomial ordering is a well-ordering; so the algorithm terminates also when there is no root. The terms of are produced in decreasing order by a heap, as in Heap division, merging , the products and the squares (no cross terms appear in characteristic 2), so the heap has at most entries and the cost is that of a heap division with products.
Case 2 needs a root of in .
Lemma 5 (Artin–Schreier equations in characteristic 2). Let be the absolute trace of . The equation has a root if and only if , and then, for any with ,
is a root. If with , then has trace 1.
Proof. The map is -linear with kernel , so its image has elements; it lies in the kernel of the trace, because , and the trace is onto, so the image is the kernel of the trace [LN1997, Ch. 2]. For the formula, let , so that , and . Then , and in the terms with cancel, leaving . For : the partial fraction decomposition over the roots of , multiplied by and compared at , gives , and the left side is the trace of .
fq_nmod_mpoly_quadratic_root and nmod_mpoly_quadratic_root (to which fmpz_mod_mpoly_quadratic_root reduces for a word-size modulus) implement this: in odd characteristic by a square root, in characteristic 2 by Algorithm 1 with the static heap function _fq_nmod_mpoly_quadratic_root_heap and the trace formula of Lemma 5. Over itself case 2 never applies, since . The factoring code uses them for squarefree factors of degree 2 in the main variable (_apply_quadratic).
Evaluation points and extension fields#
To factor a squarefree in variables, the lifting algorithms choose a point and factor the bivariate image . The point must keep the leading coefficient in nonzero and the image separable in , and Wang's method needs in addition that the factors of the leading coefficient stay distinguishable. These conditions fail on the zero set of nonzero polynomials, so over a large field random points work with high probability (Lemma 1 of GCDs over small finite fields). Over a small field they may all fail, and the bivariate factorisation itself needs a value for which the univariate image is separable.
FLINT therefore tries, in order: points in (smprime), points in an extension with , where field arithmetic uses Zech logarithms (medprime, via fq_zech_mpoly), and points in extensions of any degree (lgprime, via fq_nmod_mpoly). The extension degree starts at about for terms (half that for Wang's and Zassenhaus's methods) and is increased each time the algorithm runs out of points. In the bivariate algorithm, n_bpoly_mod_factor_lgprime reduces modulo irreducible polynomials of increasing degree and lifts -adically instead of -adically.
A factorisation over is turned into one over as follows.
Theorem 6 (Frobenius orbits). Let be irreducible and separable, that is, for some with , and let be the automorphism of over , acting on through the coefficients. Then the monic irreducible factors of in are pairwise distinct and form a single orbit under , with , and .
Proof. remains separable over , because over by Lemma 2 of GCDs over small finite fields; so is squarefree over and its monic irreducible factors are distinct. Since fixes and is a ring automorphism preserving monicity, it permutes the . Let be the orbit of and the product of the polynomials in . Then , so has coefficients in (the fixed field of ), and divides in (division by a monic polynomial is the same over and over ). As is irreducible over , , so all factors lie in . The orbit length divides the order of .
Hence, for a squarefree factored over via its factors over , the irreducible factors over are the products over the orbits. FLINT computes them by taking a factor , applying to its coefficients times, removing each conjugate from the list of remaining factors, and multiplying the orbit together; the product has coefficients in and is mapped back.
Bivariate factorisation#
Over , an irreducible bivariate polynomial stays irreducible under a generic specialisation , so a univariate image usually has as many factors as the polynomial itself and recombination is cheap (Dense bivariate factorisation). Over a finite field this fails: a univariate image of an irreducible polynomial typically splits into several factors, and recombination needs a better method than trying subsets [BHKS2009]. n_bpoly_mod_factor_smprime factors , separable in , as follows:
- Remove the content in .
- For with , factor with
nmod_poly_factor, record the degrees of the factors for the degree pruning of Lemma 5 of Factorisation (which may prove irreducible), and skip if the image is not squarefree. Of the first two good points, keep the one with fewer factors. - Shift , make monic in as a power series in , and lift the monic local factors to modulo .
- Find the true factors as products of the by linear algebra over , increasing until this succeeds.
The linear algebra is the function field version of van Hoeij's method [vHo2002; BHKS2009], with the logarithmic derivative bounds used by Lecerf [Lec2006]. For of degree in , let be the smallest concave function on with whenever , the upper boundary of the Newton polygon of with respect to (mpoly_bivar_cld_bounds).
Lemma 7 (Logarithmic derivative bounds). If divides , then for .
Proof. Write , so that . Newton polygons with respect to the valuation are additive under multiplication (Dumas' theorem, the one-variable case of Ostrowski's theorem of Irreducibility from the Newton polytope), so is the sup-convolution of the corresponding functions for and . Since , the coefficient of in has degree in at most .
Let . If is a true factor with , the logarithmic derivative of the product gives , so by Lemma 7 the coefficients of in vanish for when is the indicator vector of . These coefficients are linear forms in over , and the indicator vectors of the irreducible factors of lie in their common kernel. FLINT keeps a basis of this kernel in reduced row echelon form, starting from the identity matrix and intersecting with the kernel of the new equations (nmod_mat_init_nullspace_tr, tested with nmod_mat_is_reduced) as the precision grows:
- if the kernel has dimension 1, is irreducible, since the indicator vectors of its irreducible factors are linearly independent and lie in the kernel;
- if the reduced basis consists of 0-1 vectors with exactly one 1 in each column, its rows partition the local factors, and the candidate factors are the products over the rows, multiplied by , reduced modulo and made primitive; they are tested by division, and if a test fails, products of two candidates are tried as well;
- otherwise the precision is increased.
When groups of local factors are known to belong together, they are multiplied together and the lifting continues with fewer factors. Each returned factor is verified by division, so the result is correct whatever the precision. n_bpoly_mod_factor_lgprime does the same with replaced by an irreducible polynomial of increasing degree, for fields without good points: is factored over and the factors are lifted -adically. The fq_nmod versions n_fq_bpoly_factor_smprime and n_fq_bpoly_factor_lgprime are analogous.
Leading coefficients over a finite field#
Wang's method (Wang's method) assigns the factors of to the factors of by looking at prime numbers that divide the values of the factors of . Over a finite field the values are field elements and there are no primes; moreover a univariate image of an irreducible polynomial is usually reducible, so lifting from a univariate factorisation would require recombination. FLINT therefore replaces the evaluation point by a curve: each variable , , is replaced by a random polynomial in a new variable , and is factored as a bivariate polynomial in [Sch-mpoly]. Irreducible polynomials in play the role of the primes, and the proof of Lemma 5 of Multivariate Hensel lifting applies with replaced by : if an irreducible divides but neither the content of the bivariate image nor the other , the exponent of in the leading coefficient of the -th factor is the multiplicity of in the leading coefficient of the -th bivariate factor times the content, divided by the multiplicity of in .
nmod_mpoly_factor_lcc_wang checks the sequential form of the condition (each monic must keep a factor of positive degree after removing its common factors with the content and with ) and computes the exponents with n_poly_mod_remove. The lifting itself starts from the factors at , which are the images of the bivariate factors at the point ; since they come from a bivariate factorisation, they correspond to the factors of much more often than the factors of an arbitrary univariate image would. If the bivariate image is irreducible, so is , because the substitution preserves the degree in . nmod_mpoly_factor_irred_smprime_wang tries a few random curves through each random point (one at which the degrees are preserved and the univariate image is squarefree), raising the degree of the curves in from 1 up to 9 as attempts fail, before giving up.
Choosing among the methods#
For a factor with at least three variables after deflation, nmod_mpoly_factor_algo with all methods enabled first factors the leading coefficient in (needed by Wang's and Zippel's methods). It then computes the density of the factor ( terms, total degree , variables) and tries in order:
- density above 0.005: Wang over , Wang over (
medprime), sparse lifting over , sparse liftingmedprime; otherwise the same with sparse lifting first; - density above 0.001: Wang
lgprime, then sparse liftinglgprime; otherwise the other order; - Zassenhaus's method over ,
medprimeandlgprime, as a last resort (and first if the leading coefficient cannot be factored).
The first method that succeeds determines the factorisation. Over , fq_nmod_mpoly_factor_algo has the same structure with only the smprime and lgprime levels, the extensions being presented through the embeddings of fq_nmod_mpoly.h and the orbits taken under . fmpz_mod_mpoly_factor_algo calls nmod_mpoly_factor_algo for a word-size modulus and uses only the smprime level otherwise.
Use in FLINT#
- Public functions:
nmod_mpoly_factor,nmod_mpoly_factor_squarefree,nmod_mpoly_factor_separable,nmod_mpoly_factor_algoand its variants; the same forfq_nmod_mpoly,fmpz_mod_mpolyandfq_zech_mpoly(which converts tofq_nmod_mpoly). - Separable decomposition:
_nmod_mpoly_factor_separable,_fq_nmod_mpoly_factor_separable(Separable factorisation in characteristic ). - Bivariate:
n_bpoly_mod_factor_smprimeandn_bpoly_mod_factor_lgprime,n_fq_bpoly_factor_smprimeandn_fq_bpoly_factor_lgprime, with Hensel lifting and linear-algebra recombination (Lemma 7), usingmpoly_bivar_cld_bounds. - Quadratics:
nmod_mpoly_quadratic_root,fq_nmod_mpoly_quadratic_root(Algorithm 1, Lemma 5). - Leading coefficients:
nmod_mpoly_factor_lcc_wang(Leading coefficients over a finite field), used bynmod_mpoly_factor_irred_smprime_wang. - Lifting:
nmod_mpoly_factor_irred_{sm,med,lg}prime_{zassenhaus,wang,zippel}and thefq_nmod_mpolyandfq_zech_mpolyanalogues; Frobenius recombination (Theorem 6) in themedprimeandlgprimeversions.
int nmod_mpoly_factor(nmod_mpoly_factor_t f, const nmod_mpoly_t A, const nmod_mpoly_ctx_t ctx)int nmod_mpoly_factor_squarefree(nmod_mpoly_factor_t f, const nmod_mpoly_t A, const nmod_mpoly_ctx_t ctx)int nmod_mpoly_factor_separable(nmod_mpoly_factor_t f, const nmod_mpoly_t A, const nmod_mpoly_ctx_t ctx, int sep)int fq_nmod_mpoly_factor(fq_nmod_mpoly_factor_t f, const fq_nmod_mpoly_t A, const fq_nmod_mpoly_ctx_t ctx)int fmpz_mod_mpoly_factor(fmpz_mod_mpoly_factor_t f, const fmpz_mod_mpoly_t A, const fmpz_mod_mpoly_ctx_t ctx)Referenced from#
- Factorisation (algorithm)
- Multivariate Hensel lifting (algorithm)
- Multivariate polynomials: representations and algorithms (overview)
- Factoring polynomials over finite fields (algorithm)
- fmpz_mod_mpoly_factor.h (module)
- Factoring multivariate polynomials over the integers
- Getting started with fq_nmod_mpoly
fq_nmod_mpoly_quadratic_root- fq_nmod_mpoly_factor.h (module)
- fq_zech_mpoly.h (module)
- fq_zech_mpoly_factor.h (module)
nmod_mpoly_quadratic_root- Factorisation
- nmod_mpoly_factor.h (module)
n_bpoly_mod_factor_smprimenmod_mpoly_factor_lcc_wang
References#
- [Wan1978] P. S. Wang. An improved multivariate polynomial factoring algorithm. Mathematics of Computation 32 (1978), 1215–1231. https://doi.org/10.1090/S0025-5718-1978-0568284-3
- [MonTun2020] M. Monagan and B. Tuncer. The complexity of sparse Hensel lifting and sparse polynomial factorization. Journal of Symbolic Computation 99 (2020), 189–230. https://doi.org/10.1016/j.jsc.2019.05.001
- [Zas1969] H. Zassenhaus. On Hensel factorization, I. Journal of Number Theory 1 (1969), 291–311. https://doi.org/10.1016/0022-314X(69)90047-X
- [Sch-mpoly] D. Schultz. Algorithms for multivariate polynomials. Notes in the FLINT source tree, src/mpoly/doc/MPolyAlgorithms.tex.
- [Gao2001] S. Gao. Absolute irreducibility of polynomials via Newton polytopes. Journal of Algebra 237 (2001), 501–520. https://doi.org/10.1006/jabr.2000.8586
- [Yun1976] D. Y. Y. Yun. On square-free decomposition algorithms. Proceedings of the 1976 ACM Symposium on Symbolic and Algebraic Computation (SYMSAC '76), 26–35. https://doi.org/10.1145/800205.806320
- [GT1996] P. Gianni and B. Trager. Square-free algorithms in positive characteristic. Applicable Algebra in Engineering, Communication and Computing 7 (1996), 1–14.
- [Lec2008] G. Lecerf. Fast separable factorization and applications. Applicable Algebra in Engineering, Communication and Computing 19:2 (2008), 135–160.
- [CGVW1998] J. Cherly, L. Gallardo, L. Vaserstein and E. Wheland. Solving quadratic equations over polynomial rings of characteristic two. Publicacions Matemàtiques 42:1 (1998), 131–142.
- [LN1997] R. Lidl and H. Niederreiter. Finite Fields. Second edition, Encyclopedia of Mathematics and its Applications 20, Cambridge University Press, 1997.
- [BHKS2009] K. Belabas, M. van Hoeij, J. Klüners and A. Steel. Factoring polynomials over global fields. Journal de Théorie des Nombres de Bordeaux 21 (2009), 15–39. https://doi.org/10.5802/jtnb.655
- [vHo2002] M. van Hoeij. Factoring polynomials and the knapsack problem. Journal of Number Theory 95 (2002), 167–189. https://doi.org/10.1006/jnth.2001.2763
- [Lec2006] G. Lecerf. Sharp precision in Hensel lifting for bivariate polynomial factorization. Mathematics of Computation 75 (2006), 921–933.
The FLINT team, “Factoring over finite fields,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/multivariate/modp-factoring.html (generated 2026-11-02).
@misc{flint-doc-algorithms-multivariate-modp-factoring,
author = {{The FLINT team}},
title = {{Factoring over finite fields}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/algorithms/multivariate/modp-factoring.html},
note = {Generated 2026-11-02}
}