Struct doctor_syn::expression::Expression [−][src]
pub struct Expression { /* fields omitted */ }
Implementations
impl Expression
[src]
impl Expression
[src]pub fn span(&self) -> Span
[src]
pub fn into_inner(self) -> Expr
[src]
pub fn is_lit(&self) -> bool
[src]
pub fn is_lit(&self) -> bool
[src]Generate a number from a literal expression.
use doctor_syn::{Expression, expr}; assert!(expr!("hello").is_lit());
pub fn subst(&self, variables: VariableList) -> Result<Expression>
[src]
pub fn subst(&self, variables: VariableList) -> Result<Expression>
[src]Substitute the occurance of certain variables with an expression.
use doctor_syn::{expr, vars}; assert_eq!(expr!(x + 1).subst(vars!(x=1)).unwrap(), expr!(1 + 1));
pub fn eval<T: Evaluateable>(&self) -> Result<T>
[src]
pub fn eval<T: Evaluateable>(&self) -> Result<T>
[src]Eval constant expressions into a single expression using a particular floating point type.
use doctor_syn::{expr}; assert_eq!(expr!(1 + 1).eval::<f64>().unwrap(), 2.0);
pub fn approx<T: Evaluateable>(
&self,
num_terms: usize,
xmin: T,
xmax: T,
variable: Name,
parity: Parity
) -> Result<Expression>
[src]
pub fn approx<T: Evaluateable>(
&self,
num_terms: usize,
xmin: T,
xmax: T,
variable: Name,
parity: Parity
) -> Result<Expression>
[src]Return a polynomial approximation of a single variable expression. The polynomial is in a canonical form t[k] . mul_add( x, t[k-1]) … . mul_add( x, t[0]) This is the most accurate and highest throughput form on most processors.
use doctor_syn::{expr, name, Parity}; assert_eq!(expr!(x).approx(2, 0.0, 1.0, name!(x)).unwrap(), expr!(1f64 . mul_add (x , 0f64), Parity::Neither));
pub fn expand(&self) -> Result<Expression>
[src]
pub fn expand(&self) -> Result<Expression>
[src]Expand an expression.
use doctor_syn::{expr, Result}; || -> Result<()> { // Unary assert_eq!(expr!(- - x).expand()?, expr!(x)); assert_eq!(expr!(-(x+1)).expand()?, expr!(-x-1)); // Binary add/sub assert_eq!(expr!((x+1)+(x+1)).expand()?, expr!(x + 1 + x + 1)); assert_eq!(expr!((x+1)+((x+1)+(x+1))).expand()?, expr!(x + 1 + x + 1 + x + 1)); assert_eq!(expr!((x+1)-(x+1)).expand()?, expr!(x + 1 - x - 1)); assert_eq!(expr!((x+1)-((x+1)-(x+1))).expand()?, expr!(x + 1 - x - 1 + x + 1)); assert_eq!(expr!((x+1)-((x+1)-(-x+1))).expand()?, expr!(x + 1 - x - 1 - x + 1)); // Binary mul assert_eq!(expr!(x*x).expand()?, expr!(x * x)); assert_eq!(expr!(x*(x+1)).expand()?, expr!(x * x + x * 1)); assert_eq!(expr!((x+1)*x).expand()?, expr!(x * x + 1 * x)); assert_eq!(expr!((x+1)*(x+1)).expand()?, expr!(x * x + x * 1 + 1 * x + 1 * 1)); assert_eq!(expr!((x+1)*(x+1)*(x+1)).expand()?, expr!(x * x * x + x * x * 1 + x * 1 * x + x * 1 * 1 + 1 * x * x + 1 * x * 1 + 1 * 1 * x + 1 * 1 * 1)); Ok(()) }();
pub fn collect_terms(&self, variable: Name) -> Result<Expression>
[src]
pub fn collect_terms(&self, variable: Name) -> Result<Expression>
[src]Collect terms assuming commutativity.
use doctor_syn::{expr, Result}; || -> Result<()> { Ok(()) }();
pub fn paren(&self) -> Result<Expression>
[src]
pub fn paren(&self) -> Result<Expression>
[src]Parenthesise operators of operators.
use doctor_syn::{expr}; assert_eq!(expr!(-x).paren().unwrap(), expr!(-x)); assert_eq!(expr!(x+1).paren().unwrap(), expr!(x+1)); assert_eq!(expr!(x+1+1).paren().unwrap(), expr!((x+1)+1)); assert_eq!(expr!(x+1+1+1).paren().unwrap(), expr!(((x+1)+1)+1)); assert_eq!(expr!(2*x+y).paren().unwrap(), expr!((2*x)+y));
pub fn use_suffix(&self, float_suffix: Option<String>) -> Result<Expression>
[src]
pub fn use_suffix(&self, float_suffix: Option<String>) -> Result<Expression>
[src]Change the suffix of floatng point numbers.
use doctor_syn::{expr}; assert_eq!(expr!(1.0f64).use_suffix(Some("f32".to_string())).unwrap(), expr!(1.0_f32));
Trait Implementations
impl Clone for Expression
[src]
impl Clone for Expression
[src]fn clone(&self) -> Expression
[src]
fn clone(&self) -> Expression
[src]Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]Performs copy-assignment from source
. Read more
impl Debug for Expression
[src]
impl Debug for Expression
[src]impl Display for Expression
[src]
impl Display for Expression
[src]impl FromStr for Expression
[src]
impl FromStr for Expression
[src]impl PartialEq<Expression> for Expression
[src]
impl PartialEq<Expression> for Expression
[src]fn eq(&self, other: &Expression) -> bool
[src]
fn eq(&self, other: &Expression) -> bool
[src]This method tests for self
and other
values to be equal, and is used
by ==
. Read more
fn ne(&self, other: &Expression) -> bool
[src]
fn ne(&self, other: &Expression) -> bool
[src]This method tests for !=
.
impl TryFrom<&'_ Expression> for f64
[src]
impl TryFrom<&'_ Expression> for f64
[src]impl TryFrom<&'_ Expression> for f32
[src]
impl TryFrom<&'_ Expression> for f32
[src]impl TryFrom<Expression> for f64
[src]
impl TryFrom<Expression> for f64
[src]impl TryFrom<Expression> for f32
[src]
impl TryFrom<Expression> for f32
[src]impl TryFrom<f32> for Expression
[src]
impl TryFrom<f32> for Expression
[src]impl TryFrom<f64> for Expression
[src]
impl TryFrom<f64> for Expression
[src]impl StructuralPartialEq for Expression
[src]
Auto Trait Implementations
impl RefUnwindSafe for Expression
impl !Send for Expression
impl !Sync for Expression
impl Unpin for Expression
impl UnwindSafe for Expression
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more