FLINT3.7.0-dev
Module · 40 functions

fmpz_poly_factor.h

#include <flint/fmpz_poly_factor.h>

This module factors polynomials in Z[x]\mathbb{Z}[x] into irreducible factors. A factorisation is stored as an fmpz_poly_factor_t: a signed content cc together with distinct primitive irreducible factors fif_i of positive degree and positive leading coefficient, and multiplicities eie_i, so that f=c∏ifieif = c \prod_i f_i^{e_i}. The main function is fmpz_poly_factor, which lifts a factorisation modulo a small prime pp-adically and recombines the modular factors by the Zassenhaus algorithm when there are few and by van Hoeij's lattice reduction algorithm when there are many. The guide Factoring polynomials over the integers shows how to use it, and Factoring polynomials over the integers describes the algorithms.

AlgorithmFactoring polynomials over the integersThe Zassenhaus algorithm (factor modulo a prime, Hensel lift, recombine subsets of the modular factors) and van Hoeij's knapsack method with CLD data and gradual feeding to LLL, as implemented in fmpz_poly_factor, with the reductions that come first (content, powers of x, deflation with Capelli certificates, squarefree factorisation), the choice of the prime and the bounds that make the result provable.

Types and memory management#

A factorisation c∏i<numpieic \prod_{i < \mathit{num}} p_i^{e_i}, with fields c (an fmpz, the constant factor), p (an array of alloc polynomials, of which the first num are used), exp (the multiplicities) and num, alloc. An fmpz_poly_factor_t is an array of one structure. A freshly initialised structure represents the empty product, with c=1c = 1.

Initialise fac as the empty factorisation with c=1c = 1, allocating nothing, respectively room for alloc factors.

Changes the allocated space to exactly alloc factors; for alloc = 0 the structure is cleared and reinitialised. The number of factors is not adjusted, so alloc should be at least fac->num.

Ensures that fac has room for at least len factors, growing the allocation to at least twice its old size if it has to grow.

Frees the memory used by fac.

Manipulating factorisations#

Sets res to a copy of fac.

Multiplies the factorisation by pep^e: if pp is equal to one of the stored factors, its multiplicity is increased by ee, otherwise pp is appended with multiplicity ee. The content is not changed. Meant for primitive pp of positive degree and e≠0e \ne 0, which is not checked.

Multiplies res by the factorisation fac: the contents are multiplied and the factors of fac are inserted with fmpz_poly_factor_insert. res and fac must be distinct.

Set zz to the constant factor cc of F, respectively to the factor with index ii, which must satisfy 0≤i<0 \le i < F->num.

Prints the content on one line, then each factor in the plain format of fmpz_poly_print followed by ^ and its multiplicity, one per line.

Factoring#

Sets fac to the factorisation of GG into its signed content and irreducible primitive factors with positive leading coefficient and their multiplicities. The zero polynomial gives content 0 and no factors, a constant cc gives content cc and no factors. fac must be initialised; its previous factors are discarded. The factors are not sorted.

Full documentation

Factors GG like fmpz_poly_factor, but without deflation and using only the Zassenhaus recombination. Its running time is exponential in the number of modular factors, so it is meant for comparison and testing. fac should be freshly initialised, since the factors are appended to those already present.

Full documentation

Sets the content of fac to the signed content cc of FF (with the sign of the leading coefficient) and appends squarefree, pairwise coprime, primitive factors gig_i of positive degree with distinct multiplicities eie_i, so that F=c∏igieiF = c \prod_i g_i^{e_i} with gcd⁡(gi,gi′)=1\gcd(g_i, g_i') = 1. Each gig_i is the product of all irreducible factors of FF of multiplicity eie_i. Uses Yun's algorithm [Yun1976] (Squarefree factorisation). fac should be freshly initialised.

Full documentation
void _fmpz_poly_factor_zassenhaus(fmpz_poly_factor_t final_fac, slong exp, const fmpz_poly_t f, slong cutoff, int use_van_hoeij)

Appends the irreducible factors of the squarefree, primitive polynomial ff of length at least 2 with nonzero constant coefficient and positive leading coefficient, each with multiplicity exp, to final_fac; none of the conditions is checked.

More

Appends the irreducible factors of the squarefree primitive ff, each with multiplicity exp, to final_fac, given its factorisation fac into r≥2r \ge 2 monic irreducible factors modulo the prime pp, by van Hoeij's knapsack algorithm with gradual feeding of CLD data [vHo2002], [HvHN2011]. The modular factors are lifted to an initial precision, a lattice is reduced with LLL after each new column of CLD data, and the precision is doubled until a 0-1 basis of the recombination lattice is found and verified.

Insert the factorisation of the primitive quadratic (respectively cubic) polynomial ff into fac, with multiplicity exp, without changing the content of fac. A quadratic splits if and only if its discriminant is a square; a cubic is reducible if and only if it has a rational root, which is located from real and 2-adic approximations of the roots and tested over Z\mathbb{Z} (Cubics). The content of ff must be 1, which is not checked.

Sets BB to a bound for the absolute values of the coefficients of all factors in Z[x]\mathbb{Z}[x] of ff of degree m≥2m \ge 2: the maximum of ∣f(0)∣|f(0)|, ∣lc⁡(f)∣|\operatorname{lc}(f)| and of (m−1j)N+(m−1j−1)∣lc⁡(f)∣\binom{m-1}{j} N + \binom{m-1}{j-1} |\operatorname{lc}(f)| for 1≤j<m1 \le j < m, where N≥∥f∥2N \ge \|f\|_2 is an integer [Coh1996, Theorem 3.5.1]. The Zassenhaus algorithm lifts to pa>2∣lc⁡(f)∣Bp^a > 2 |\operatorname{lc}(f)| B.

Irreducibility of inflations#

Given TT irreducible over Q\mathbb{Q} of degree at least 1 and a prime pp, attempts to prove that T(xp)T(x^p) is irreducible over Q\mathbb{Q}. Returns 1 if a proof was found and 0 if the search was inconclusive, in which case T(xp)T(x^p) may still be irreducible. The behaviour is undefined if TT is reducible. TT need not be primitive and may have negative leading coefficient.

More

Given TT irreducible over Q\mathbb{Q} of degree at least 1 and d≥1d \ge 1, returns 1 if T(xd)T(x^d) is proved irreducible over Q\mathbb{Q} and 0 if the attempt was inconclusive. The prime-step certificate is chained over the prime factorisation of dd, using T(xd)=U(xd/p)T(x^d) = U(x^{d/p}) with U=T(xp)U = T(x^p). The behaviour is undefined if TT is reducible. fmpz_poly_factor uses this to avoid refactoring inflations of irreducible factors of deflated polynomials.

Recombination#

Find the irreducible factors of the squarefree primitive FF from its monic factors lifted_fac modulo P=paP = p^a, where P>2∣lc⁡(F)∣BP > 2 |\operatorname{lc}(F)| B for the Mignotte bound BB, by trying subsets of the modular factors in order of increasing size: for each subset SS, the product lc⁡(F)∏i∈Sgi\operatorname{lc}(F) \prod_{i \in S} g_i is reduced into the symmetric range modulo PP, its primitive part is tested as a divisor of FF, and true factors are removed together with their modular factors. Each factor is appended to final_fac with multiplicity exp. The with_prune version skips subsets whose total degree is impossible according to Z.

Fills the (r+1)×2k(r + 1) \times 2k matrix res with the CLD data of van Hoeij's algorithm for the rr lifted factors gig_i of ff modulo PP: row ii holds low and high coefficients of fgi′/gif g_i' / g_i modulo PP in the symmetric range, and row rr the corresponding bounds from fmpz_poly_CLD_bound. Of the low kk and high kk coefficients, only those whose bound times deg⁡f\sqrt{\deg f} is small enough compared to PP are used; the function returns the number of columns filled, low ones first.

Checks whether the reduced lattice basis MM of van Hoeij's algorithm determines the factorisation: if the first rr columns of MM define a partition of the rr lifted factors (a 0-1 basis), the products of the factors in each part (times lc, reduced modulo PP, made primitive) are tested as divisors of ff, first modulo 2 and then over Z\mathbb{Z}. If all of them divide, the factors are appended to final_fac with multiplicity exp and 1 is returned; otherwise 0 is returned and final_fac is unchanged.

Internal functions#

These functions support the Zassenhaus recombination. A subset of the rr modular factors is encoded in an array s of length rr whose entries are factor indices i≥0i \ge 0 for the factors in the subset and −i−1-i - 1 for the others.

Sets s to the first subset of size mm of its rr entries, the first mm entries.

Advances s to the next subset of the same size in a fixed order and returns 1, or returns 0 if it was the last.

Removes the entries of the current subset from s, moving the remaining entries to the front, and sets it to the next subset of the same size mm of the remaining entries, returning 1, or returns 0 if there is none.

Records the degrees dd for which a factor of degree dd is still possible, given the degrees of the modular factors modulo several primes: a true factor of degree dd is a product of modular factors of total degree dd modulo every prime.

Sets the degree of the polynomial to be factored to d≥1d \ge 1 and marks all degrees 0,…,d0, \ldots, d as possible.

Add the degrees of the modular factors for one prime: after zassenhaus_prune_start_add_factors, each call to zassenhaus_prune_add_factor records exp factors of degree deg, and zassenhaus_prune_end_add_factors intersects the set of possible degrees with the set of subset sums of the recorded degrees. The degrees must add up to the degree given to zassenhaus_prune_set_degree; otherwise an exception is raised.

Returns whether a factor of degree dd is still possible.

Returns whether no degree strictly between 0 and the degree of the polynomial is possible, which proves the polynomial irreducible.

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
  • [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
  • [HvHN2011] W. Hart, M. van Hoeij and A. Novocin. Practical polynomial factoring in polynomial time. ISSAC 2011, 163–170. https://doi.org/10.1145/1993886.1993915
  • [Coh1996] Cohen, Henri : A course in computational algebraic number theory, Springer, 1996
Cite this page

The FLINT team, “fmpz_poly_factor.h (module overview),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/fmpz_poly_factor/index.html (generated 2026-11-02).