pub struct Polynomial {
pub coeffs: Vec<RnsRational>,
pub channels: Channels,
}Expand description
A univariate polynomial with exact rational coefficients.
coeffs[i] is the coefficient of xⁱ. Trailing zero coefficients are
trimmed so the last entry (if any) is the nonzero leading coefficient.
Fields§
§coeffs: Vec<RnsRational>§channels: ChannelsImplementations§
Source§impl Polynomial
impl Polynomial
Sourcepub fn new(coeffs: Vec<RnsRational>, channels: Channels) -> Self
pub fn new(coeffs: Vec<RnsRational>, channels: Channels) -> Self
Build from coefficients (ascending powers), trimming trailing zeros.
Sourcepub fn from_int_coeffs(coeffs: &[i64], channels: Channels) -> Self
pub fn from_int_coeffs(coeffs: &[i64], channels: Channels) -> Self
Build from integer coefficients (ascending powers).
Sourcepub fn constant(c: RnsRational) -> Self
pub fn constant(c: RnsRational) -> Self
A constant polynomial.
Sourcepub fn degree(&self) -> usize
pub fn degree(&self) -> usize
Degree; the zero polynomial has degree 0 by convention here (callers
should also check Polynomial::is_zero).
Sourcepub fn leading(&self) -> RnsRational
pub fn leading(&self) -> RnsRational
The leading (highest-power) coefficient, or zero for the zero polynomial.
Sourcepub fn eval(&self, x: &RnsRational) -> RnsRational
pub fn eval(&self, x: &RnsRational) -> RnsRational
Evaluate at a rational point via Horner’s scheme.
Sourcepub fn sign_at(&self, x: &RnsRational) -> i32
pub fn sign_at(&self, x: &RnsRational) -> i32
Sign of p(x): -1, 0, or +1.
Sourcepub fn derivative(&self) -> Self
pub fn derivative(&self) -> Self
Formal derivative.
Sourcepub fn scalar_mul(&self, s: &RnsRational) -> Self
pub fn scalar_mul(&self, s: &RnsRational) -> Self
Multiply by a rational scalar.
Sourcepub fn divmod(&self, divisor: &Self) -> (Self, Self)
pub fn divmod(&self, divisor: &Self) -> (Self, Self)
Long division returning (quotient, remainder) over the rational field.
Panics if divisor is zero.
Sourcepub fn div_exact(&self, divisor: &Self) -> Self
pub fn div_exact(&self, divisor: &Self) -> Self
Exact division (asserts the remainder is zero).
Sourcepub fn monic(&self) -> Self
pub fn monic(&self) -> Self
Make monic (leading coefficient 1). The zero polynomial is returned as-is.
Sourcepub fn gcd(a: &Self, b: &Self) -> Self
pub fn gcd(a: &Self, b: &Self) -> Self
Monic GCD of two polynomials (Euclidean algorithm over ℚ).
Sourcepub fn squarefree(&self) -> Self
pub fn squarefree(&self) -> Self
Square-free part: p / gcd(p, p'), made monic.
Sourcepub fn sturm_sequence(&self) -> Vec<Self>
pub fn sturm_sequence(&self) -> Vec<Self>
The Sturm sequence s0 = p, s1 = p', s_{i+1} = -rem(s_{i-1}, s_i).
Sourcepub fn sign_changes(seq: &[Self], x: &RnsRational) -> usize
pub fn sign_changes(seq: &[Self], x: &RnsRational) -> usize
Count sign changes of a Sturm sequence evaluated at x (zeros ignored).
Sourcepub fn sturm_root_count(&self, a: &RnsRational, b: &RnsRational) -> usize
pub fn sturm_root_count(&self, a: &RnsRational, b: &RnsRational) -> usize
Number of distinct real roots in the half-open interval (a, b].
Sourcepub fn root_bound(&self) -> RnsRational
pub fn root_bound(&self) -> RnsRational
A Cauchy bound B such that every real root lies in (-B, B).
Sourcepub fn isolate_real_roots(&self) -> Vec<(RnsRational, RnsRational)>
pub fn isolate_real_roots(&self) -> Vec<(RnsRational, RnsRational)>
Isolate every real root into its own interval (lo, hi], sorted ascending.
self should be square-free for clean isolation.
Sourcepub fn find_rational_root(&self) -> Option<RnsRational>
pub fn find_rational_root(&self) -> Option<RnsRational>
Find one rational root via the rational-root theorem, or None.
Sourcepub fn factor_over_q(&self) -> Vec<Self>
pub fn factor_over_q(&self) -> Vec<Self>
Factor into monic irreducible-over-ℚ factors (for the low degrees that arise from resultants of quadratics/cubics, this is exact; higher-degree factors that resist rational-root splitting are returned whole).
Trait Implementations§
Source§impl Clone for Polynomial
impl Clone for Polynomial
Source§fn clone(&self) -> Polynomial
fn clone(&self) -> Polynomial
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Polynomial
impl Debug for Polynomial
impl Eq for Polynomial
Source§impl PartialEq for Polynomial
impl PartialEq for Polynomial
Auto Trait Implementations§
impl Freeze for Polynomial
impl RefUnwindSafe for Polynomial
impl Send for Polynomial
impl Sync for Polynomial
impl Unpin for Polynomial
impl UnsafeUnpin for Polynomial
impl UnwindSafe for Polynomial
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more