Trait MathExpr

Source
pub trait MathExpr {
    type Repr<T>;

Show 14 methods // Required methods fn constant<T: NumericType>(value: T) -> Self::Repr<T>; fn var<T: NumericType>(name: &str) -> Self::Repr<T>; fn var_by_index<T: NumericType>(index: usize) -> Self::Repr<T>; fn add<L, R, Output>( left: Self::Repr<L>, right: Self::Repr<R>, ) -> Self::Repr<Output> where L: NumericType + Add<R, Output = Output>, R: NumericType, Output: NumericType; fn sub<L, R, Output>( left: Self::Repr<L>, right: Self::Repr<R>, ) -> Self::Repr<Output> where L: NumericType + Sub<R, Output = Output>, R: NumericType, Output: NumericType; fn mul<L, R, Output>( left: Self::Repr<L>, right: Self::Repr<R>, ) -> Self::Repr<Output> where L: NumericType + Mul<R, Output = Output>, R: NumericType, Output: NumericType; fn div<L, R, Output>( left: Self::Repr<L>, right: Self::Repr<R>, ) -> Self::Repr<Output> where L: NumericType + Div<R, Output = Output>, R: NumericType, Output: NumericType; fn pow<T: NumericType + Float>( base: Self::Repr<T>, exp: Self::Repr<T>, ) -> Self::Repr<T>; fn neg<T: NumericType + Neg<Output = T>>( expr: Self::Repr<T>, ) -> Self::Repr<T>; fn ln<T: NumericType + Float>(expr: Self::Repr<T>) -> Self::Repr<T>; fn exp<T: NumericType + Float>(expr: Self::Repr<T>) -> Self::Repr<T>; fn sqrt<T: NumericType + Float>(expr: Self::Repr<T>) -> Self::Repr<T>; fn sin<T: NumericType + Float>(expr: Self::Repr<T>) -> Self::Repr<T>; fn cos<T: NumericType + Float>(expr: Self::Repr<T>) -> Self::Repr<T>;
}
Expand description

Core trait for mathematical expressions using Generic Associated Types (GATs) This follows the final tagless approach where the representation type is parameterized and works with generic numeric types including AD types

Required Associated Types§

Source

type Repr<T>

The representation type parameterized by the value type

Required Methods§

Source

fn constant<T: NumericType>(value: T) -> Self::Repr<T>

Create a constant value

Source

fn var<T: NumericType>(name: &str) -> Self::Repr<T>

Create a variable reference by name (registers variable automatically)

Source

fn var_by_index<T: NumericType>(index: usize) -> Self::Repr<T>

Create a variable reference by index (for performance-critical code)

Source

fn add<L, R, Output>( left: Self::Repr<L>, right: Self::Repr<R>, ) -> Self::Repr<Output>
where L: NumericType + Add<R, Output = Output>, R: NumericType, Output: NumericType,

Addition operation

Source

fn sub<L, R, Output>( left: Self::Repr<L>, right: Self::Repr<R>, ) -> Self::Repr<Output>
where L: NumericType + Sub<R, Output = Output>, R: NumericType, Output: NumericType,

Subtraction operation

Source

fn mul<L, R, Output>( left: Self::Repr<L>, right: Self::Repr<R>, ) -> Self::Repr<Output>
where L: NumericType + Mul<R, Output = Output>, R: NumericType, Output: NumericType,

Multiplication operation

Source

fn div<L, R, Output>( left: Self::Repr<L>, right: Self::Repr<R>, ) -> Self::Repr<Output>
where L: NumericType + Div<R, Output = Output>, R: NumericType, Output: NumericType,

Division operation

Source

fn pow<T: NumericType + Float>( base: Self::Repr<T>, exp: Self::Repr<T>, ) -> Self::Repr<T>

Power operation

Source

fn neg<T: NumericType + Neg<Output = T>>(expr: Self::Repr<T>) -> Self::Repr<T>

Negation operation

Source

fn ln<T: NumericType + Float>(expr: Self::Repr<T>) -> Self::Repr<T>

Natural logarithm

Source

fn exp<T: NumericType + Float>(expr: Self::Repr<T>) -> Self::Repr<T>

Exponential function

Source

fn sqrt<T: NumericType + Float>(expr: Self::Repr<T>) -> Self::Repr<T>

Square root

Source

fn sin<T: NumericType + Float>(expr: Self::Repr<T>) -> Self::Repr<T>

Sine function

Source

fn cos<T: NumericType + Float>(expr: Self::Repr<T>) -> Self::Repr<T>

Cosine function

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl MathExpr for ASTEval

For compatibility with the main MathExpr trait, we provide a limited implementation that works only with f64 types

Source§

type Repr<T> = ASTRepr<T>

Source§

impl MathExpr for DirectEval

Source§

type Repr<T> = T

Source§

impl MathExpr for PrettyPrint