pub trait Differentiate<T: Clone> where
    Self: Sized + Express<T> + Display + Debug
{ fn to_deepex<'a>(
        &'a self,
        ops: &[Operator<'a, T>]
    ) -> ExResult<DeepEx<'a, T>>
    where
        Self: Sized,
        T: DataType + Float,
        <T as FromStr>::Err: Debug
; fn from_deepex(
        deepex: DeepEx<'_, T>,
        ops: &[Operator<'_, T>]
    ) -> ExResult<Self>
    where
        Self: Sized,
        T: DataType + Float,
        <T as FromStr>::Err: Debug
; fn partial(&self, var_idx: usize) -> ExResult<Self>
    where
        T: DataType + Float,
        <T as FromStr>::Err: Debug
, { ... } fn partial_nth(&self, var_idx: usize, n: usize) -> ExResult<Self>
    where
        T: DataType + Float,
        <T as FromStr>::Err: Debug
, { ... } fn partial_iter<'a, I>(&self, var_idxs: I) -> ExResult<Self>
    where
        T: DataType + Float,
        <T as FromStr>::Err: Debug,
        I: Iterator<Item = &'a usize> + Clone
, { ... } }
Expand description

feature = "partial" - Trait for partial differentiation.

Required Methods

feature = "partial" - Every trait implementation needs to implement the conversion to a deep expression to be able to use the default implementation of partial.

feature = "partial" - Every trait implementation needs to implement the conversion from a deep expression to be able to use the default implementation of partial.

Provided Methods

feature = "partial" - This method computes a new expression that is the partial derivative of self with default operators.

Example
use exmex::prelude::*;

let mut expr = FlatEx::<f64>::from_str("sin(1+y^2)*x")?;
let dexpr_dx = expr.partial(0)?;
let dexpr_dy = expr.partial(1)?;

assert!((dexpr_dx.eval(&[9e5, 2.0])? - (5.0 as f64).sin()).abs() < 1e-12);
//             |    
//           The partial derivative dexpr_dx does depend on x. Still, it
//           expects the same number of parameters as the corresponding
//           antiderivative. Hence, you can pass any number for x.  

assert!((dexpr_dy.eval(&[2.5, 2.0])? - 10.0 * (5.0 as f64).cos()).abs() < 1e-12);
Arguments
  • var_idx - variable with respect to which the partial derivative is computed
Errors
  • If you use custom operators this might not work as expected. It could return an ExError if an operator is not found or compute a wrong result if an operator is defined in an un-expected way.

feature = "partial" - Computes the nth partial derivative with respect to one variable

Example
use exmex::prelude::*;

let mut expr = FlatEx::<f64>::from_str("x^4+y^4")?;

let dexpr_dxx_nth = expr.partial_nth(0, 2)?;

let dexpr_dx = expr.partial(0)?;
let dexpr_dxx_2step = dexpr_dx.partial(0)?;

assert!((dexpr_dxx_2step.eval(&[4.3, 2.1])? - dexpr_dxx_nth.eval(&[4.3, 2.1])?).abs() < 1e-12);
Arguments
  • var_idx - variable with respect to which the partial derivative is computed
  • n - order of derivation
Errors
  • If you use custom operators this might not work as expected. It could return an ExError if an operator is not found or compute a wrong result if an operator is defined in an un-expected way.

feature = "partial" - Computes a chain of partial derivatives with respect to the variables passed as iterator

Example
use exmex::prelude::*;

let mut expr = FlatEx::<f64>::from_str("x^4+y^4")?;

let dexpr_dxy_iter = expr.partial_iter([0, 1].iter())?;

let dexpr_dx = expr.partial(0)?;
let dexpr_dxy_2step = dexpr_dx.partial(1)?;

assert!((dexpr_dxy_2step.eval(&[4.3, 2.1])? - dexpr_dxy_iter.eval(&[4.3, 2.1])?).abs() < 1e-12);
Arguments
  • var_idxs - variables with respect to which the partial derivative is computed
  • n - order of derivation
Errors
  • If you use custom operators this might not work as expected. It could return an ExError if an operator is not found or compute a wrong result if an operator is defined in an un-expected way.

Implementors