Expand description
Sparse multivariate polynomial GCD, cofactors and LCM over the rationals.
gcd() automatically tries Huang–Gao, Huang–Monagan, then Zippel.
gcd_with_algorithm chooses the first algorithm in a documented fallback
chain. cofactors and lcm provide the same choice through their
_with_algorithm variants.
Call an algorithm directly to control recovery:
| Function | Algorithm | Result |
|---|---|---|
zippel() | Zippel modular GCD with LINZIP | Poly |
huang_gao() | Huang–Gao separated Hensel lifting; asymptotic SOTA (2026) | Option<Poly> |
huang_monagan() | Huang–Monagan prime substitution | Option<Poly> |
hu_monagan() | Hu–Monagan GCD/cofactor interpolation | Option<Poly> |
hu_monagan_bivariate() | Hu–Monagan with bivariate images | Option<Poly> |
Named sparse methods return None when bounded recovery fails; they never
switch to another recovery backend. They share integer normalization, CRT,
exact certification and, for Hu–Monagan, Zippel content extraction.
Every successful result has the normalization and zero conventions of gcd().
Huang–Gao’s 2026 paper is the state of the art in asymptotic sparse integer GCD complexity. This bounded, exactly certified implementation does not claim the paper’s full complexity bound or the fastest practical runtime for every input.
use polycore::{Order, Ring};
use zippel_gcd::{gcd, huang_gao, huang_monagan, hu_monagan,
hu_monagan_bivariate, zippel};
let ring = Ring::new(["x", "y"], Order::Lex);
let a = ring.parse("(x + y)*(x + 1)").unwrap();
let b = ring.parse("(x + y)*(y + 2)").unwrap();
let expected = ring.parse("x + y").unwrap();
assert_eq!(gcd(&a, &b), expected); // Automatic recovery and fallback.
assert_eq!(zippel(&a, &b), expected); // Explicit Zippel.
for algorithm in [huang_gao, huang_monagan, hu_monagan, hu_monagan_bivariate] {
assert_eq!(algorithm(&a, &b).unwrap(), expected);
}Structs§
- Frac
num / denwith no common factor anddenmonic in its order. The constantsZeroandOnebuild have no variables and widen to whatever they meet, likeFp’s unbound modulus.- GcdReport
- The top-level recovery chain actually tried, in order.
Enums§
- GcdAlgorithm
- Preferred algorithm for
gcd_with_algorithm,cofactors_with_algorithmandlcm_with_algorithm, including each variant’s documented fallback.
Functions§
- cofactors
- GCD and cofactors
(h, f / h, g / h)using the automatic Huang–Gao-first chain. - cofactors_
with_ algorithm - GCD and cofactors using a chosen first algorithm and its documented fallback chain.
- gcd
- Automatic GCD: Huang–Gao, then Huang–Monagan, then Zippel.
- gcd_
with_ algorithm - GCD using a chosen first algorithm and its documented fallback chain.
- gcd_
with_ report - Compute a GCD with the same fallback chain as
gcd_with_algorithm, recording which attempts ran. This does not add a work limit to the Zippel fallback. - hu_
monagan - Hu–Monagan GCD/cofactor interpolation using univariate images.
- hu_
monagan_ bivariate - Hu–Monagan GCD/cofactor interpolation using bivariate images.
- huang_
gao - Huang–Gao GCD by derivative-aided separated Hensel lifting (asymptotic SOTA, 2026).
- huang_
monagan - Huang–Monagan GCD by integer prime substitution and valuation decoding.
- lcm
- LCM using the automatic Huang–Gao-first GCD chain.
- lcm_
with_ algorithm - LCM using a chosen first algorithm and its documented fallback chain.
- zippel
- Zippel GCD by recursive modular interpolation with LINZIP support reuse.