pub struct SparsePolynomial {
pub terms: HashMap<Monomial, BigRational>,
pub num_vars: usize,
}Expand description
Sparse polynomial: HashMap<Monomial, Coefficient>
Efficient representation for polynomial computation:
- Addition: O(n) - merge hashmaps
- Multiplication: O(n²) - compute all monomial products
- No expression tree growth - coefficients are BigRational
Fields§
§terms: HashMap<Monomial, BigRational>Terms: monomial → coefficient Only non-zero coefficients are stored
num_vars: usizeNumber of variables
Implementations§
Source§impl SparsePolynomial
impl SparsePolynomial
Sourcepub fn from_term(
monomial: Monomial,
coeff: BigRational,
num_vars: usize,
) -> Self
pub fn from_term( monomial: Monomial, coeff: BigRational, num_vars: usize, ) -> Self
Create polynomial from single term
Sourcepub fn constant(value: BigRational, num_vars: usize) -> Self
pub fn constant(value: BigRational, num_vars: usize) -> Self
Create constant polynomial
Sourcepub fn leading_monomial(&self, order: &MonomialOrder) -> Option<&Monomial>
pub fn leading_monomial(&self, order: &MonomialOrder) -> Option<&Monomial>
Get leading monomial (w.r.t. given ordering)
Sourcepub fn leading_coefficient(&self, order: &MonomialOrder) -> Option<&BigRational>
pub fn leading_coefficient(&self, order: &MonomialOrder) -> Option<&BigRational>
Get leading coefficient
Sourcepub fn leading_term(
&self,
order: &MonomialOrder,
) -> Option<(Monomial, BigRational)>
pub fn leading_term( &self, order: &MonomialOrder, ) -> Option<(Monomial, BigRational)>
Get leading term (monomial + coefficient)
Sourcepub fn scalar_mul(&self, scalar: &BigRational) -> Self
pub fn scalar_mul(&self, scalar: &BigRational) -> Self
Multiply by scalar
Sourcepub fn mul_monomial(&self, monomial: &Monomial) -> Self
pub fn mul_monomial(&self, monomial: &Monomial) -> Self
Multiply polynomial by a monomial
Trait Implementations§
Source§impl Clone for SparsePolynomial
impl Clone for SparsePolynomial
Source§fn clone(&self) -> SparsePolynomial
fn clone(&self) -> SparsePolynomial
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SparsePolynomial
impl RefUnwindSafe for SparsePolynomial
impl Send for SparsePolynomial
impl Sync for SparsePolynomial
impl Unpin for SparsePolynomial
impl UnwindSafe for SparsePolynomial
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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