Skip to main content

SparsePolynomial

Struct SparsePolynomial 

Source
pub struct SparsePolynomial { /* private fields */ }
Available on crate feature exact only.
Expand description

An exact polynomial Σ coefficient[e] * t^e with nonnegative u128 exponents.

Terms are stored in increasing exponent order. Coefficients are reduced rational numbers with positive denominators; zero coefficients are absent. Duplicate input exponents are summed exactly, including cancellation. Self::leading_term means the least exponent with a nonzero coefficient, appropriate to an infinitesimal t → 0+, rather than the highest degree.

Storage and arbitrary-precision coefficients allocate on the heap. Construction consumes owned terms; queries borrow them; cloning makes a deep copy. The determinant budget does not cover construction. Multivariate encodings, perturbation-variable assignment and interpretation of coefficient signs belong to callers, who must prove their encoding preserves the desired order and exponent addition. No multivariate ordering is inferred here.

Implementations§

Source§

impl SparsePolynomial

Source

pub const fn zero() -> Self

Construct the zero polynomial without allocating.

Source

pub fn try_from_terms( terms: impl IntoIterator<Item = (u128, BigRational)>, ) -> Result<Self, LaError>

Consume terms, normalize rational coefficients and combine equal exponents.

Input order is immaterial to a successful result. Raw unreduced or negative-denominator rationals are accepted. Validation precedes zero removal, so even 0/0 is rejected. The iterator is consumed only up to the first invalid coefficient; this constructor has no work budget.

§Errors

Returns LaError::NonFinite with input origin and a NonFiniteLocation::PolynomialTerm for a zero denominator.

Source

pub const fn terms(&self) -> &BTreeMap<u128, BigRational>

Borrow all nonzero terms in increasing exponent order.

Source

pub fn is_zero(&self) -> bool

Whether every coefficient is exactly zero.

Source

pub fn leading_term(&self) -> Option<(u128, &BigRational)>

Borrow the first nonzero coefficient in increasing exponent order.

None proves this is the zero polynomial. A failed determinant evaluation never returns a polynomial, so it cannot be confused with this result.

Trait Implementations§

Source§

impl Clone for SparsePolynomial

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SparsePolynomial

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SparsePolynomial

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for SparsePolynomial

Source§

impl PartialEq for SparsePolynomial

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SparsePolynomial

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.