pub struct Poly { /* private fields */ }Expand description
A polynomial over ℚ: c[i] is the coefficient of xⁱ. INVARIANT: no trailing zero.
Implementations§
Source§impl Poly
impl Poly
pub fn zero() -> Poly
pub fn one() -> Poly
pub fn x() -> Poly
pub fn constant(c: Rational) -> Poly
Sourcepub fn from_coeffs(c: Vec<Rational>) -> Poly
pub fn from_coeffs(c: Vec<Rational>) -> Poly
From little-endian coefficients (c[i] multiplies xⁱ); trailing zeros are dropped.
pub fn from_i64s(c: &[i64]) -> Poly
pub fn from_bigints(c: &[BigInt]) -> Poly
pub fn coeffs(&self) -> &[Rational]
pub fn is_zero(&self) -> bool
pub fn leading(&self) -> Option<&Rational>
pub fn add(&self, o: &Poly) -> Poly
pub fn sub(&self, o: &Poly) -> Poly
pub fn neg(&self) -> Poly
pub fn mul(&self, o: &Poly) -> Poly
pub fn scale(&self, k: &Rational) -> Poly
pub fn pow(&self, e: u32) -> Poly
Sourcepub fn div_rem(&self, d: &Poly) -> Option<(Poly, Poly)>
pub fn div_rem(&self, d: &Poly) -> Option<(Poly, Poly)>
Euclidean division over ℚ: self = q·d + r with deg r < deg d. None when d is zero.
pub fn derivative(&self) -> Poly
Sourcepub fn reverse(&self) -> Poly
pub fn reverse(&self) -> Poly
x^deg · self(1/x): the polynomial whose roots are the reciprocals of the nonzero roots.
Sourcepub fn squarefree_part(&self) -> Poly
pub fn squarefree_part(&self) -> Poly
The monic polynomial with the same roots, each once: self / gcd(self, self′).
Sourcepub fn primitive_int(&self) -> Vec<BigInt>
pub fn primitive_int(&self) -> Vec<BigInt>
The integer polynomial with the same roots: denominators cleared, content divided out, leading coefficient positive. Empty for the zero polynomial.
Sourcepub fn root_bound(&self) -> Rational
pub fn root_bound(&self) -> Rational
Cauchy’s bound 1 + max |aᵢ/aₙ|: every complex root lies strictly inside it.
Sourcepub fn count_real_roots(&self) -> usize
pub fn count_real_roots(&self) -> usize
The number of distinct real roots.
Sourcepub fn count_real_roots_in(&self, lo: &Rational, hi: &Rational) -> usize
pub fn count_real_roots_in(&self, lo: &Rational, hi: &Rational) -> usize
The number of distinct real roots in the half-open interval (lo, hi].
Sourcepub fn isolate_real_roots(&self) -> Vec<RootInterval>
pub fn isolate_real_roots(&self) -> Vec<RootInterval>
Every distinct real root, isolated, in increasing order.
Sourcepub fn refine(&self, iv: &RootInterval) -> RootInterval
pub fn refine(&self, iv: &RootInterval) -> RootInterval
Halve an isolating interval of one of self’s roots, keeping the root inside. An exact
root stays as it is; a midpoint that is the root becomes the exact interval.
Sourcepub fn resultant(&self, o: &Poly) -> Rational
pub fn resultant(&self, o: &Poly) -> Rational
The resultant lc(self)^{deg o} · ∏ o(α) over the roots α of self; zero exactly when
the two share a root, and zero when either is the zero polynomial.
Sourcepub fn factor_over_q(&self) -> Vec<(Poly, u32)>
pub fn factor_over_q(&self) -> Vec<(Poly, u32)>
The factorization over ℚ into irreducible primitive integer polynomials (positive leading
coefficient) with multiplicities, in Poly::canonical_order. The constant content is
dropped; a constant or zero polynomial has no factors.
Sourcepub fn is_irreducible(&self) -> bool
pub fn is_irreducible(&self) -> bool
Irreducible over ℚ: positive degree and no proper factorization.
Sourcepub fn canonical_order(a: &Poly, b: &Poly) -> Ordering
pub fn canonical_order(a: &Poly, b: &Poly) -> Ordering
The total order factors are listed in: by degree, then by coefficients from the highest power down.