pub struct Polynomial { /* private fields */ }Expand description
Dense univariate polynomial with f64 coefficients, little-endian.
Implementations§
Source§impl Polynomial
impl Polynomial
Sourcepub fn new(coeffs: Vec<f64>) -> Self
pub fn new(coeffs: Vec<f64>) -> Self
Build from coefficients (index i = coefficient of x^i), trimming any
near-zero high-order terms.
Sourcepub fn degree(&self) -> Option<usize>
pub fn degree(&self) -> Option<usize>
Degree of the polynomial, or None for the zero polynomial.
Sourcepub fn add(&self, other: &Polynomial) -> Polynomial
pub fn add(&self, other: &Polynomial) -> Polynomial
Sum self + other.
Sourcepub fn sub(&self, other: &Polynomial) -> Polynomial
pub fn sub(&self, other: &Polynomial) -> Polynomial
Difference self - other.
Sourcepub fn scale(&self, s: f64) -> Polynomial
pub fn scale(&self, s: f64) -> Polynomial
Scale every coefficient by s.
Sourcepub fn mul(&self, other: &Polynomial) -> Polynomial
pub fn mul(&self, other: &Polynomial) -> Polynomial
Product self * other (schoolbook convolution).
Sourcepub fn div_rem(&self, divisor: &Polynomial) -> Option<(Polynomial, Polynomial)>
pub fn div_rem(&self, divisor: &Polynomial) -> Option<(Polynomial, Polynomial)>
Polynomial long division: returns (quotient, remainder) with
self == quotient * divisor + remainder and deg(remainder) < deg(divisor). Fails closed (None) when dividing by the zero polynomial.
Sourcepub fn derivative(&self) -> Polynomial
pub fn derivative(&self) -> Polynomial
First derivative.
Sourcepub fn monic(&self) -> Polynomial
pub fn monic(&self) -> Polynomial
Make the polynomial monic (leading coefficient 1). Zero polynomial maps to itself.
Sourcepub fn gcd(&self, other: &Polynomial) -> Polynomial
pub fn gcd(&self, other: &Polynomial) -> Polynomial
Greatest common divisor via the Euclidean algorithm, returned monic
(so it is unique up to the normalisation gcd of the zero polynomial
with p is monic(p)).
Sourcepub fn resultant(&self, other: &Polynomial) -> f64
pub fn resultant(&self, other: &Polynomial) -> f64
Resultant of self and other via the Euclidean remainder sequence.
The resultant is zero iff the two polynomials share a common root
(over the complex numbers / have a non-constant gcd). It is computed by
running the Euclidean algorithm and accumulating the standard
degree/leading-coefficient factors that relate res(a, b) to
res(b, a mod b):
res(a, b) = (-1)^(deg a · deg b) · lc(b)^(deg a − deg r) · res(b, r)
with base cases res(a, const c) = c^(deg a) and a zero result whenever
a remainder vanishes with positive remaining degree (a common factor).
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
Source§impl PartialEq for Polynomial
impl PartialEq for Polynomial
Source§fn eq(&self, other: &Polynomial) -> bool
fn eq(&self, other: &Polynomial) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq 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§
§impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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