pub struct Polynomial { /* private fields */ }Expand description
A polynomial is a sum of monomials with integer coefficients.
Example: 2x^2 + 3xy - 5 is {x^2: 2, xy: 3, 1: -5}
Uses BTreeMap for deterministic ordering (canonical form).
Implementations§
Source§impl Polynomial
impl Polynomial
Sourcepub fn zero() -> Self
pub fn zero() -> Self
The additive identity (zero polynomial).
Represented as an empty map of terms.
Sourcepub fn constant(c: i64) -> Self
pub fn constant(c: i64) -> Self
Create a constant polynomial from an integer.
Returns the zero polynomial if c is 0.
Sourcepub fn add(&self, other: &Polynomial) -> Polynomial
pub fn add(&self, other: &Polynomial) -> Polynomial
Add two polynomials
Sourcepub fn neg(&self) -> Polynomial
pub fn neg(&self) -> Polynomial
Negate a polynomial
Sourcepub fn sub(&self, other: &Polynomial) -> Polynomial
pub fn sub(&self, other: &Polynomial) -> Polynomial
Subtract two polynomials
Sourcepub fn mul(&self, other: &Polynomial) -> Polynomial
pub fn mul(&self, other: &Polynomial) -> Polynomial
Multiply two polynomials
Sourcepub fn canonical_eq(&self, other: &Polynomial) -> bool
pub fn canonical_eq(&self, other: &Polynomial) -> bool
Check equality in canonical form. Since BTreeMap maintains sorted order and we remove zeros, structural equality is semantic equality.
Trait Implementations§
Source§impl Clone for Polynomial
impl Clone for Polynomial
Source§fn clone(&self) -> Polynomial
fn clone(&self) -> Polynomial
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 moreSource§impl Debug for Polynomial
impl Debug for Polynomial
Source§impl PartialEq for Polynomial
impl PartialEq for Polynomial
impl Eq for Polynomial
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 UnwindSafe for Polynomial
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