pub struct SparsePolynomial { /* private fields */ }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
impl SparsePolynomial
Sourcepub fn try_from_terms(
terms: impl IntoIterator<Item = (u128, BigRational)>,
) -> Result<Self, LaError>
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.
Sourcepub const fn terms(&self) -> &BTreeMap<u128, BigRational>
pub const fn terms(&self) -> &BTreeMap<u128, BigRational>
Borrow all nonzero terms in increasing exponent order.
Sourcepub fn leading_term(&self) -> Option<(u128, &BigRational)>
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.