Squarefree factorisation
- Cost
- field operations for a polynomial of degree with fast gcds (a constant number of gcds of total degree ), plus -th roots of at most coefficients in characteristic .
A polynomial over a field is squarefree if it is not divisible by the square of a nonconstant polynomial. Every nonzero has a unique squarefree factorisation
with and monic, squarefree, pairwise coprime , where is the product of the irreducible factors of multiplicity exactly . It is the first step of every factorisation algorithm (Factoring polynomials over finite fields, Factoring polynomials over the integers) and of root finding, and it costs only gcds and exact divisions. FLINT returns the nontrivial together with their exponents , made monic over a field and primitive with positive leading coefficient over .
The tool is the derivative. If over the monic irreducible , then
Lemma 1. Suppose that every irreducible is separable (), which holds in characteristic 0 and over finite fields. Then the multiplicity of in is if in , and if in (that is, if the characteristic divides ).
Proof. In the sum, every term except the one for is divisible by . The term for is divisible by exactly if in , since , and vanishes otherwise. Hence in the first case and in the second.
Characteristic zero: Yun's algorithm#
In characteristic 0, Lemma 1 gives , so is the squarefree part of . The multiplicities can be separated by repeating this, but Yun's algorithm [Yun1976] does it with gcds whose degrees add up to .
Input: of degree over a field of characteristic 0, monic (or primitive over a UFD).
Output: the pairs with .
- . If , return .
- , , .
Loop:
- . If , output if and stop.
- ; output if .
- , , .
Proof. For , gives and . Given the invariant,
Every term is divisible by . For with , all terms but the -th are divisible by , and the -th is not, since and . Hence , and , satisfy the invariant for . If , then for all , so .
The degrees of the polynomials in iteration are at most , and . With gcds in for degree (Half-GCD), the whole algorithm therefore costs , the same as one gcd of degree up to a constant factor [Yun1976] [GG2003, §14.6].
Finite fields#
In characteristic the derivative of vanishes when , and if and only if . Over a perfect field, in particular over with , such an is a -th power: if , then , where (and in a prime field). FLINT uses the following algorithm, the classical gcd iteration [Mus1971] [Knu1997, §4.6.2] combined with -th roots [GG2003, §14.6].
Input: of degree over .
Output: the pairs with , the monic.
- If : compute with by taking -th roots of the coefficients, factor recursively, multiply all exponents by and return.
- . If , return (made monic).
, . While :
- ; ; output if .
- , , .
- If : is a -th power; factor recursively and output its factors with exponents multiplied by .
Theorem 3. Algorithm 2 is correct. The exponents output in step 3 are not divisible by , those output in step 4 are, and all are distinct.
Proof. Write . By Lemma 1, after step 2,
By induction on , at the start of iteration we have and . Since is squarefree and contains only factors with , , so is the product of the factors of multiplicity exactly (which is 1 if ), and the updated and satisfy the invariant for . When , the remaining is a -th power. In step 1 and step 4 the recursion is applied to a polynomial of degree at most , whose squarefree factorisation, with exponents multiplied by , gives the factors of with multiplicities divisible by .
As in Yun's algorithm, the degrees of the gcds in step 3 add up to at most , so the cost is , plus at most -th roots of field elements per level of recursion.
The algorithm gives the factorisation with distinct exponents, not necessarily with exponents in order; FLINT returns the factors in the order in which they are found.
Squarefree part and squarefreeness test#
The squarefree part is (up to a unit) in characteristic 0, while in characteristic it is computed from the squarefree factorisation. To test whether is squarefree it suffices, over a perfect field, to test : if and then is a -th power, hence not squarefree.
Use in FLINT#
gr_poly_factor_squarefree implements Algorithm 1 for unique factorisation domains of characteristic 0, after making monic (over a field) or removing its content (otherwise), and Algorithm 2 for finite fields, where the -th roots of the coefficients are computed with gr_fq_pth_root. gr_poly_squarefree_part and gr_poly_is_squarefree use the methods of the previous section. The finite field modules wrap the generic code; fmpz_poly_factor_squarefree has its own implementation of Yun's algorithm with integer gcds, and the squarefreeness tests for nmod_poly compute directly.
int gr_poly_factor_squarefree(gr_ptr c, gr_poly_vec_t fac, fmpz_vec_t exp, const gr_poly_t poly, gr_ctx_t ctx)int gr_poly_squarefree_part(gr_poly_t res, const gr_poly_t poly, gr_ctx_t ctx)truth_t gr_poly_is_squarefree(const gr_poly_t f, gr_ctx_t ctx)void nmod_poly_factor_squarefree(nmod_poly_factor_t res, const nmod_poly_t f)int nmod_poly_is_squarefree(const nmod_poly_t f)void fmpz_mod_poly_factor_squarefree(fmpz_mod_poly_factor_t res, const fmpz_mod_poly_t f, const fmpz_mod_ctx_t ctx)int fmpz_mod_poly_is_squarefree(const fmpz_mod_poly_t f, const fmpz_mod_ctx_t ctx)void fmpz_poly_factor_squarefree(fmpz_poly_factor_t fac, const fmpz_poly_t F)Referenced from#
- Factoring polynomials over finite fields (algorithm)
- Factoring polynomials over the integers (algorithm)
- Polynomial arithmetic over generic rings and its specialisations (overview)
- Roots of polynomials over finite fields (algorithm)
fmpz_mod_poly_factor_squarefreefmpz_poly_factor_squarefreegr_poly_factor_squarefree- Factoring polynomials over a prime field
nmod_poly_factor_squarefree
References#
- [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
- [GG2003] J. von zur Gathen and J. Gerhard, Modern Computer Algebra, second edition, Cambridge University Press (2003)
- [Mus1971] D. R. Musser. Algorithms for polynomial factorization. PhD thesis, University of Wisconsin, 1971.
- [Knu1997] Knuth, D. E. The Art of Computer Programming, volume 2: Seminumerical algorithms, 1997
The FLINT team, “Squarefree factorisation,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/polynomials/squarefree.html (generated 2026-11-02).
@misc{flint-doc-algorithms-polynomials-squarefree,
author = {{The FLINT team}},
title = {{Squarefree factorisation}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/algorithms/polynomials/squarefree.html},
note = {Generated 2026-11-02}
}