pub struct ExactNumPoly { /* private fields */ }Expand description
Dense univariate polynomial c₀ + c₁ x + ⋯ + cₙ xⁿ.
Coefficients are stored lowest degree first. Leading zeros are stripped.
The zero polynomial has an empty coefficient vector. Arithmetic methods
take an explicit precision p and rounding mode; stored (p, rm) are the
values used when the polynomial was constructed.
Implementations§
Source§impl ExactNumPoly
impl ExactNumPoly
Sourcepub fn zero(p: usize, rm: RoundingMode) -> Self
pub fn zero(p: usize, rm: RoundingMode) -> Self
Zero polynomial at (p, rm).
Sourcepub fn one(p: usize, rm: RoundingMode) -> Self
pub fn one(p: usize, rm: RoundingMode) -> Self
Constant 1 at (p, rm).
Sourcepub fn from_coeffs(p: usize, rm: RoundingMode, coeffs: &[ExactNum]) -> Self
pub fn from_coeffs(p: usize, rm: RoundingMode, coeffs: &[ExactNum]) -> Self
Build from coefficients, lowest degree first. Each coefficient is
rounded to (p, rm). Leading zeros are stripped.
Sourcepub fn from_i64_coeffs(p: usize, rm: RoundingMode, coeffs: &[i64]) -> Self
pub fn from_i64_coeffs(p: usize, rm: RoundingMode, coeffs: &[i64]) -> Self
Coefficients from i64 values, lowest degree first.
Sourcepub fn rounding(&self) -> RoundingMode
pub fn rounding(&self) -> RoundingMode
Stored construction rounding mode.
Sourcepub fn coeffs(&self) -> &[ExactNum]
pub fn coeffs(&self) -> &[ExactNum]
Coefficients, lowest degree first. Empty if this is the zero polynomial.
Sourcepub fn eval(
&self,
x: &ExactNum,
p: usize,
rm: RoundingMode,
_cc: &mut Consts,
) -> ExactNum
pub fn eval( &self, x: &ExactNum, p: usize, rm: RoundingMode, _cc: &mut Consts, ) -> ExactNum
Horner evaluation c₀ + x(c₁ + x(c₂ + ⋯)) at (p, rm).
cc is accepted for signature uniformity with other numeric methods;
Horner uses only add and fused multiply-add.
Sourcepub fn add(&self, rhs: &Self, p: usize, rm: RoundingMode) -> Self
pub fn add(&self, rhs: &Self, p: usize, rm: RoundingMode) -> Self
Coefficient-wise sum at precision p.
Sourcepub fn sub(&self, rhs: &Self, p: usize, rm: RoundingMode) -> Self
pub fn sub(&self, rhs: &Self, p: usize, rm: RoundingMode) -> Self
Coefficient-wise difference at precision p.
Sourcepub fn mul(&self, rhs: &Self, p: usize, rm: RoundingMode) -> Self
pub fn mul(&self, rhs: &Self, p: usize, rm: RoundingMode) -> Self
Schoolbook product at precision p.
Sourcepub fn div_rem(
&self,
g: &Self,
p: usize,
rm: RoundingMode,
) -> Option<(Self, Self)>
pub fn div_rem( &self, g: &Self, p: usize, rm: RoundingMode, ) -> Option<(Self, Self)>
Polynomial division: self = q·g + r with deg r < deg g.
None if g is the zero polynomial or a coefficient is non-finite.
Sourcepub fn gcd(&self, other: &Self, p: usize, rm: RoundingMode) -> Self
pub fn gcd(&self, other: &Self, p: usize, rm: RoundingMode) -> Self
Euclidean GCD with integer content removal, returned monic.
Both zero → zero. One zero → monic of the other.
Sourcepub fn compose(
&self,
g: &Self,
p: usize,
rm: RoundingMode,
_cc: &mut Consts,
) -> Self
pub fn compose( &self, g: &Self, p: usize, rm: RoundingMode, _cc: &mut Consts, ) -> Self
Composition self(g(x)) by Horner at precision p.
Sourcepub fn derivative(&self, p: usize, rm: RoundingMode) -> Self
pub fn derivative(&self, p: usize, rm: RoundingMode) -> Self
Formal derivative. The derivative of a constant is zero.
Sourcepub fn integral(&self, p: usize, rm: RoundingMode) -> Self
pub fn integral(&self, p: usize, rm: RoundingMode) -> Self
Indefinite integral with constant term zero.
Sourcepub fn companion_matrix(
&self,
p: usize,
rm: RoundingMode,
) -> Option<ExactNumArray>
pub fn companion_matrix( &self, p: usize, rm: RoundingMode, ) -> Option<ExactNumArray>
Monic companion matrix of this polynomial, or None if the degree is
zero or the polynomial is zero / non-finite.
Last column is (-c₀/cₙ, …, -cₙ₋₁/cₙ). Subdiagonal is ones.
Sourcepub fn roots_real(
&self,
p: usize,
rm: RoundingMode,
_cc: &mut Consts,
) -> Option<Vec<ExactNum>>
pub fn roots_real( &self, p: usize, rm: RoundingMode, _cc: &mut Consts, ) -> Option<Vec<ExactNum>>
Real roots via the companion characteristic equation.
Degree 1 and 2 use the closed-form eigenvalues of the companion
(linear solve / quadratic formula) at extra working precision, then
one round to p. Degree greater than POLY_COMPANION_CLOSED_DEG
returns None — those companions are not symmetric, so
ExactNumArray::eigen_decomp does not apply.
The zero polynomial returns None. A nonzero constant returns an
empty vector. A negative discriminant returns an empty vector.
Trait Implementations§
Source§impl Clone for ExactNumPoly
impl Clone for ExactNumPoly
Source§fn clone(&self) -> ExactNumPoly
fn clone(&self) -> ExactNumPoly
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 ExactNumPoly
impl Debug for ExactNumPoly
Auto Trait Implementations§
impl Freeze for ExactNumPoly
impl RefUnwindSafe for ExactNumPoly
impl Send for ExactNumPoly
impl Sync for ExactNumPoly
impl Unpin for ExactNumPoly
impl UnsafeUnpin for ExactNumPoly
impl UnwindSafe for ExactNumPoly
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<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