pub trait Calculate<'a, T>: Express<'a, T>{
// Provided methods
fn operate_unary(self, repr: &'a str) -> ExResult<Self> { ... }
fn operate_binary(self, other: Self, repr: &'a str) -> ExResult<Self> { ... }
fn subs<F>(self, sub: &mut F) -> ExResult<Self>
where F: FnMut(&str) -> Option<Self> { ... }
fn from_num(x: T) -> Self { ... }
}
Expand description
Calculation with expression such as application of operators or substitution
Provided Methods§
sourcefn operate_unary(self, repr: &'a str) -> ExResult<Self>
fn operate_unary(self, repr: &'a str) -> ExResult<Self>
sourcefn operate_binary(self, other: Self, repr: &'a str) -> ExResult<Self>
fn operate_binary(self, other: Self, repr: &'a str) -> ExResult<Self>
sourcefn subs<F>(self, sub: &mut F) -> ExResult<Self>
fn subs<F>(self, sub: &mut F) -> ExResult<Self>
Substitutes a variable with another expression.
Arguments
sub
- function that assigns to each variable name optionally a new expression
Example
use exmex::{DeepEx, prelude::*};
use std::f64;
let expr = DeepEx::<f64>::parse("-z/x + 2^7 + E")?;
let mut sub = |var: &str| match var {
"z" => Some(DeepEx::<f64>::parse("2*y").unwrap()),
_ => None,
};
let substituted = expr.subs(&mut sub)?;
assert_eq!(substituted.var_names(), ["x", "y"]);
let reference = 2.0f64.powi(7) + f64::consts::E + 1.0;
assert_eq!(substituted.eval(&[-4.0, 2.0])?, reference);
Object Safety§
This trait is not object safe.