Struct doctor_syn::expression::Expression[][src]

pub struct Expression { /* fields omitted */ }

Implementations

impl Expression[src]

pub fn span(&self) -> Span[src]

pub fn into_inner(self) -> Expr[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]

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]

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]

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]

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]

Collect terms assuming commutativity.

use doctor_syn::{expr, Result};
|| -> Result<()> {
    
   Ok(())
}();

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]

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 AsRef<Expr> for Expression[src]

fn as_ref(&self) -> &Expr[src]

Performs the conversion.

impl Clone for 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]

Performs copy-assignment from source. Read more

impl Debug for Expression[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl Display for Expression[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl From<Expr> for Expression[src]

fn from(expr: Expr) -> Self[src]

Performs the conversion.

impl FromStr for Expression[src]

type Err = Error

The associated error which can be returned from parsing.

fn from_str(s: &str) -> Result<Self>[src]

Parses a string s to return a value of this type. Read more

impl PartialEq<Expression> for Expression[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]

This method tests for !=.

impl TryFrom<&'_ Expression> for f64[src]

type Error = Error

The type returned in the event of a conversion error.

fn try_from(expr: &Expression) -> Result<Self>[src]

Performs the conversion.

impl TryFrom<&'_ Expression> for f32[src]

type Error = Error

The type returned in the event of a conversion error.

fn try_from(expr: &Expression) -> Result<Self>[src]

Performs the conversion.

impl TryFrom<Expression> for f64[src]

type Error = Error

The type returned in the event of a conversion error.

fn try_from(expr: Expression) -> Result<Self>[src]

Performs the conversion.

impl TryFrom<Expression> for f32[src]

type Error = Error

The type returned in the event of a conversion error.

fn try_from(expr: Expression) -> Result<Self>[src]

Performs the conversion.

impl TryFrom<f32> for Expression[src]

type Error = Error

The type returned in the event of a conversion error.

fn try_from(val: f32) -> Result<Self>[src]

Performs the conversion.

impl TryFrom<f64> for Expression[src]

type Error = Error

The type returned in the event of a conversion error.

fn try_from(val: f64) -> Result<Self>[src]

Performs the conversion.

impl StructuralPartialEq for Expression[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.