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§
Required Methods§
Sourcefn constant<T: NumericType>(value: T) -> Self::Repr<T>
fn constant<T: NumericType>(value: T) -> Self::Repr<T>
Create a constant value
Sourcefn var<T: NumericType>(name: &str) -> Self::Repr<T>
fn var<T: NumericType>(name: &str) -> Self::Repr<T>
Create a variable reference by name (registers variable automatically)
Sourcefn var_by_index<T: NumericType>(index: usize) -> Self::Repr<T>
fn var_by_index<T: NumericType>(index: usize) -> Self::Repr<T>
Create a variable reference by index (for performance-critical code)
Sourcefn add<L, R, Output>(
left: Self::Repr<L>,
right: Self::Repr<R>,
) -> Self::Repr<Output>
fn add<L, R, Output>( left: Self::Repr<L>, right: Self::Repr<R>, ) -> Self::Repr<Output>
Addition operation
Sourcefn sub<L, R, Output>(
left: Self::Repr<L>,
right: Self::Repr<R>,
) -> Self::Repr<Output>
fn sub<L, R, Output>( left: Self::Repr<L>, right: Self::Repr<R>, ) -> Self::Repr<Output>
Subtraction operation
Sourcefn mul<L, R, Output>(
left: Self::Repr<L>,
right: Self::Repr<R>,
) -> Self::Repr<Output>
fn mul<L, R, Output>( left: Self::Repr<L>, right: Self::Repr<R>, ) -> Self::Repr<Output>
Multiplication operation
Sourcefn div<L, R, Output>(
left: Self::Repr<L>,
right: Self::Repr<R>,
) -> Self::Repr<Output>
fn div<L, R, Output>( left: Self::Repr<L>, right: Self::Repr<R>, ) -> Self::Repr<Output>
Division operation
Sourcefn pow<T: NumericType + Float>(
base: Self::Repr<T>,
exp: Self::Repr<T>,
) -> Self::Repr<T>
fn pow<T: NumericType + Float>( base: Self::Repr<T>, exp: Self::Repr<T>, ) -> Self::Repr<T>
Power operation
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.