pub enum Term<T> {
Value(T),
Scalar(u128),
Var(VarValue),
Add(Box<Self>, Box<Self>),
Mul(Box<Self>, Box<Self>),
}
Expand description
A symbolic term that can be used to express simple arithmetic.
Can only be evaluated to a concrete value within a crate::scope::Scope
.
Variants§
Implementations§
Source§impl Term<u128>
impl Term<u128>
Sourcepub fn eval(&self, ctx: &SimpleScope) -> Result<u128, String>
pub fn eval(&self, ctx: &SimpleScope) -> Result<u128, String>
Evaluates the term within the given scope to a concrete value.
pub fn into_chromatic(self, unit: Dimension) -> ChromaticTerm
Source§impl<T> Term<T>
impl<T> Term<T>
pub fn is_const_zero(&self) -> bool
pub fn is_const_one(&self) -> bool
Sourcepub fn free_vars(&self, scope: &Scope<Term<T>>) -> Set<String>
pub fn free_vars(&self, scope: &Scope<Term<T>>) -> Set<String>
Returns the variables of the term that are not part of crate::scope::Scope
.
Lambda calculus calls such a variable free.
This is the inverse of Self::bound_vars
.
Sourcepub fn bound_vars(&self, scope: &Scope<Term<T>>) -> Set<String>
pub fn bound_vars(&self, scope: &Scope<Term<T>>) -> Set<String>
Returns the variables of the term that are part of crate::scope::Scope
.
Lambda calculus calls such a variable bound.
This is the inverse of Self::free_vars
.
pub fn fmt_equation(&self, scope: &Scope<Term<T>>) -> String
pub fn into_substituted(self, var: &str, term: &Term<T>) -> Self
pub fn substitute(&mut self, var: &str, term: &Term<T>)
pub fn visit<F, R>(&self, f: &mut F) -> Result<Vec<R>, String>
Sourcepub fn find_largest_factor(&self, var: &str) -> Option<u128>
pub fn find_largest_factor(&self, var: &str) -> Option<u128>
Returns the largest pre-factor of the variable in the term.
pub fn as_scalar(&self) -> Option<u128>
pub fn as_var(&self) -> Option<&str>
Source§impl Term<Weight>
impl Term<Weight>
Sourcepub fn eval(&self, ctx: &ChromaticScope) -> Result<Weight, String>
pub fn eval(&self, ctx: &ChromaticScope) -> Result<Weight, String>
Evaluates the term within the given scope to a concrete value.
pub fn simplify(&self, unit: Dimension) -> Result<SimpleTerm, String>
pub fn for_values<F>(&self, f: F) -> Result<SimpleTerm, String>
Sourcepub fn splice_add(self, other: Self) -> Self
pub fn splice_add(self, other: Self) -> Self
Splice orthogonal weight terms together so that they produce a sum.
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Term<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Term<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T: Ord> Ord for Term<T>
impl<T: Ord> Ord for Term<T>
Source§impl<T: PartialOrd> PartialOrd for Term<T>
impl<T: PartialOrd> PartialOrd for Term<T>
impl<T: Eq> Eq for Term<T>
impl<T> StructuralPartialEq for Term<T>
Auto Trait Implementations§
impl<T> Freeze for Term<T>where
T: Freeze,
impl<T> RefUnwindSafe for Term<T>where
T: RefUnwindSafe,
impl<T> Send for Term<T>where
T: Send,
impl<T> Sync for Term<T>where
T: Sync,
impl<T> Unpin for Term<T>where
T: Unpin,
impl<T> UnwindSafe for Term<T>where
T: UnwindSafe,
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