Expand description
Univariate factorization over ℤ via Berlekamp–Zassenhaus. Univariate factorization over ℤ via Berlekamp–Zassenhaus (mod-p factoring, Hensel lifting, recombination).
This module implements the classical Zassenhaus algorithm for factoring a
square-free primitive polynomial f ∈ ℤ[x] into irreducibles:
- Choose primes. Small odd primes
pwithp ∤ lc(f)andf mod psquare-free are tried; the one producing the fewest modular factors is kept. The sets of achievable factor degrees are intersected across all tried primes, which often proves irreducibility outright. - Factor mod p with Cantor–Zassenhaus (distinct-degree splitting
followed by equal-degree splitting). Arithmetic in
GF(p)[x]usesu64coefficients withp < 2³¹. - Hensel lift the modular factorization to
p^kwherep^k > 2 · 2ⁿ · ‖f‖₂ · |lc(f)|(the Mignotte bound) using linear multifactor lifting. - Recombine by trying subsets of the lifted factors of increasing
size. Each candidate is
lc · ∏ gᵢreduced to symmetric residues, made primitive, and tested by exact trial division. Cheap filters (achievable degree, constant-term divisibility) reject almost all spurious subsets without a division. - Verify the final factorization by multiplying back. If anything is inconsistent the input is returned unfactored — the result is never wrong, at worst incomplete.
The subset search is exponential in the number of modular factors, so
it is bounded by MAX_RECOMBINATION_SUBSETS. When the budget is
exhausted the remaining (possibly reducible) cofactor is returned as a
single factor and a tracing::warn! is emitted. Callers inside the
crate that need to know whether every returned factor is certified
irreducible use factor_zassenhaus_checked, which reports that as a
flag; the public functions keep their signatures.
§Examples
use symplex::factor_zassenhaus::{factor_zassenhaus, Poly};
use num_bigint::BigInt;
use num_rational::Ratio;
let c = |n: i64| Ratio::from_integer(BigInt::from(n));
// x^4 + 4 = (x^2 - 2x + 2)(x^2 + 2x + 2) (Sophie Germain identity)
let f = Poly::from_coeffs(vec![c(4), c(0), c(0), c(0), c(1)]);
let factors = factor_zassenhaus(&f);
assert_eq!(factors.len(), 2);
assert!(factors.iter().all(|(g, m)| g.degree() == Some(2) && *m == 1));Modules§
- traits
- Coefficient-ring traits used by
GenPoly(re-exported so that the polynomial types above are fully documented and usable generically).
Structs§
- GenPoly
- A dense univariate polynomial with coefficients in
C.
Constants§
- MAX_
KRONECKER_ SUBSTITUTION_ DEGREE - Largest univariate degree the Kronecker substitution in
factor_multivariateis allowed to produce. - MAX_
PRIME - Largest prime allowed for the
u64finite-field arithmetic (products of two residues must fit inu64).factor_mod_paccepts odd primes strictly below this bound. - MAX_
RECOMBINATION_ SUBSETS - Upper bound on the number of factor subsets examined during recombination. Beyond this the remaining cofactor is returned as-is.
- PRIMES_
TO_ TRY - Number of usable primes whose modular factorizations are compared; the one with the fewest factors is used for lifting.
Functions§
- factor_
mod_ p - Factor a polynomial over the prime field
GF(p). - factor_
multivariate - Factor a multivariate polynomial over ℤ by Kronecker substitution.
- factor_
squarefree_ z - Factor a square-free primitive polynomial
f ∈ ℤ[x](coefficients in ascending degree order) into irreducible integer factors. - factor_
zassenhaus - Factor a polynomial over ℤ into primitive irreducible factors with multiplicities.
- factor_
zassenhaus_ with_ content - Factor a polynomial over ℤ, returning
(content, factors). - is_
irreducible_ z - Decide whether a non-constant polynomial with rational coefficients is irreducible over ℚ.
Type Aliases§
- ModP
Factorization - A factorization over
GF(p): the leading coefficient and the monic irreducible factors (ascending coefficients in[0, p)) with multiplicities. Returned byfactor_mod_p. - Multi
Factorization - A factorization over ℤ of a multivariate polynomial: rational content
and
(factor, multiplicity)pairs. Returned byfactor_multivariate. - Poly
- A dense univariate polynomial over ℚ.