pub struct NatPolyForm { /* private fields */ }Expand description
A normalized polynomial form for Nat expressions.
This is the canonical representation for Nat arithmetic (Level 1 addition +
Level 2 multiplication). Each term is a monomial mapped to its coefficient.
Two NatPolyForms are equal iff their normalized terms match.
Implementations§
Source§impl NatPolyForm
impl NatPolyForm
Sourcepub fn from_constant(c: u64) -> Self
pub fn from_constant(c: u64) -> Self
Create a polynomial from a constant.
Sourcepub fn from_var(name: GenericParamName) -> Self
pub fn from_var(name: GenericParamName) -> Self
Create a polynomial from a single variable with coefficient 1.
Sourcepub fn add(&self, other: &Self) -> Result<Self, NatOverflowError>
pub fn add(&self, other: &Self) -> Result<Self, NatOverflowError>
Add two polynomials.
Returns an error if a coefficient overflows.
Sourcepub fn mul(&self, other: &Self) -> Result<Self, NatOverflowError>
pub fn mul(&self, other: &Self) -> Result<Self, NatOverflowError>
Multiply two polynomials (distributive law).
Returns an error if a coefficient or exponent overflows.
Sourcepub fn is_constant(&self) -> bool
pub fn is_constant(&self) -> bool
Returns true if this form has no variables (is a constant).
Sourcepub fn evaluate(&self, bindings: &HashMap<GenericParamName, u64>) -> Option<u64>
pub fn evaluate(&self, bindings: &HashMap<GenericParamName, u64>) -> Option<u64>
Evaluate to a concrete value given variable bindings.
Returns None if any variable is unbound or arithmetic overflows.
Sourcepub fn format(&self) -> String
pub fn format(&self) -> String
Format as a human-readable string.
Examples: "3", "N", "N + 1", "M * N", "2 * N^2 + N + 1".
Sourcepub fn is_leq(&self, other: &Self) -> bool
pub fn is_leq(&self, other: &Self) -> bool
Check if self <= other for all non-negative variable assignments.
Returns true iff for every monomial, the coefficient in self is <=
the coefficient in other. This is sound because all Nat variables
are non-negative, so each monomial evaluates to a non-negative value.
Sourcepub fn variables(&self) -> BTreeSet<GenericParamName>
pub fn variables(&self) -> BTreeSet<GenericParamName>
Collect all variable names that appear in any monomial of this polynomial.
Source§impl NatPolyForm
impl NatPolyForm
Sourcepub fn to_nat_range_identity(
&self,
) -> Result<NatRangeIndexIdentity, NatRangeIndexError>
pub fn to_nat_range_identity( &self, ) -> Result<NatRangeIndexIdentity, NatRangeIndexError>
Wrap this normalized Nat form as a typed Nat-range index identity.
§Errors
Returns an error when the form is a concrete invalid Nat range size.
Trait Implementations§
Source§impl Clone for NatPolyForm
impl Clone for NatPolyForm
Source§fn clone(&self) -> NatPolyForm
fn clone(&self) -> NatPolyForm
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 NatPolyForm
impl Debug for NatPolyForm
Source§impl Display for NatPolyForm
impl Display for NatPolyForm
impl Eq for NatPolyForm
Source§impl Hash for NatPolyForm
impl Hash for NatPolyForm
Source§impl PartialEq for NatPolyForm
impl PartialEq for NatPolyForm
Source§fn eq(&self, other: &NatPolyForm) -> bool
fn eq(&self, other: &NatPolyForm) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for NatPolyForm
Auto Trait Implementations§
impl Freeze for NatPolyForm
impl RefUnwindSafe for NatPolyForm
impl Send for NatPolyForm
impl Sync for NatPolyForm
impl Unpin for NatPolyForm
impl UnsafeUnpin for NatPolyForm
impl UnwindSafe for NatPolyForm
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.