pub enum ASTRepr<T> {
Show 13 variants
Constant(T),
Variable(usize),
Add(Box<ASTRepr<T>>, Box<ASTRepr<T>>),
Sub(Box<ASTRepr<T>>, Box<ASTRepr<T>>),
Mul(Box<ASTRepr<T>>, Box<ASTRepr<T>>),
Div(Box<ASTRepr<T>>, Box<ASTRepr<T>>),
Pow(Box<ASTRepr<T>>, Box<ASTRepr<T>>),
Neg(Box<ASTRepr<T>>),
Ln(Box<ASTRepr<T>>),
Exp(Box<ASTRepr<T>>),
Sqrt(Box<ASTRepr<T>>),
Sin(Box<ASTRepr<T>>),
Cos(Box<ASTRepr<T>>),
}Expand description
JIT compilation representation for mathematical expressions
This enum represents mathematical expressions in a form suitable for JIT compilation using Cranelift. Each variant corresponds to a mathematical operation that can be compiled to native machine code.
§Performance Note
Variables are referenced by index for optimal performance with DirectEval,
using vector indexing instead of string lookups:
use mathcompile::final_tagless::{ASTRepr, DirectEval};
// Efficient: uses vector indexing
let expr = ASTRepr::Add(
Box::new(ASTRepr::Variable(0)), // x
Box::new(ASTRepr::Variable(1)), // y
);
let result = DirectEval::eval_with_vars(&expr, &[2.0, 3.0]);
assert_eq!(result, 5.0);Variants§
Constant(T)
Constant value
Variable(usize)
Variable reference by index (efficient for evaluation)
Add(Box<ASTRepr<T>>, Box<ASTRepr<T>>)
Addition of two expressions
Sub(Box<ASTRepr<T>>, Box<ASTRepr<T>>)
Subtraction of two expressions
Mul(Box<ASTRepr<T>>, Box<ASTRepr<T>>)
Multiplication of two expressions
Div(Box<ASTRepr<T>>, Box<ASTRepr<T>>)
Division of two expressions
Pow(Box<ASTRepr<T>>, Box<ASTRepr<T>>)
Power operation
Neg(Box<ASTRepr<T>>)
Negation
Ln(Box<ASTRepr<T>>)
Natural logarithm
Exp(Box<ASTRepr<T>>)
Exponential function
Sqrt(Box<ASTRepr<T>>)
Square root
Sin(Box<ASTRepr<T>>)
Sine function
Cos(Box<ASTRepr<T>>)
Cosine function
Implementations§
Source§impl<T> ASTRepr<T>
impl<T> ASTRepr<T>
Sourcepub fn count_operations(&self) -> usize
pub fn count_operations(&self) -> usize
Count the total number of operations in the expression tree
Sourcepub fn variable_index(&self) -> Option<usize>
pub fn variable_index(&self) -> Option<usize>
Get the variable index if this is a variable, otherwise None
Source§impl<T> ASTRepr<T>
impl<T> ASTRepr<T>
Sourcepub fn count_summation_operations(&self) -> usize
pub fn count_summation_operations(&self) -> usize
Add summation support to the AST representation
These variants would be added to the enum in a complete implementation:
- SumFinite(Box<
ASTRepr>, Box< ASTRepr<ASTFunction>>) - SumInfinite(Box<
ASTRepr>, Box< ASTRepr<ASTFunction>>) - SumTelescoping(Box<
ASTRepr>, Box< ASTRepr<ASTFunction>>) - Range(i64, i64)
- Function(String, Box<
ASTRepr>) Placeholder for future summation operation counting
Source§impl<T> ASTRepr<T>where
T: NumericType,
Additional convenience methods for ASTRepr<T> with generic types
impl<T> ASTRepr<T>where
T: NumericType,
Additional convenience methods for ASTRepr<T> with generic types
Trait Implementations§
Source§impl<T> Add<&ASTRepr<T>> for &ASTRepr<T>where
T: NumericType + Add<Output = T>,
Addition with references
impl<T> Add<&ASTRepr<T>> for &ASTRepr<T>where
T: NumericType + Add<Output = T>,
Addition with references
Source§impl<T> Add<ASTRepr<T>> for &ASTRepr<T>where
T: NumericType + Add<Output = T>,
Addition with mixed references
impl<T> Add<ASTRepr<T>> for &ASTRepr<T>where
T: NumericType + Add<Output = T>,
Addition with mixed references
Source§impl<T> Add for ASTRepr<T>where
T: NumericType + Add<Output = T>,
Addition operator overloading for ASTRepr<T>
impl<T> Add for ASTRepr<T>where
T: NumericType + Add<Output = T>,
Addition operator overloading for ASTRepr<T>
Source§impl<T> Div<&ASTRepr<T>> for &ASTRepr<T>where
T: NumericType + Div<Output = T>,
Division with references
impl<T> Div<&ASTRepr<T>> for &ASTRepr<T>where
T: NumericType + Div<Output = T>,
Division with references
Source§impl<T> Div<ASTRepr<T>> for &ASTRepr<T>where
T: NumericType + Div<Output = T>,
Division with mixed references
impl<T> Div<ASTRepr<T>> for &ASTRepr<T>where
T: NumericType + Div<Output = T>,
Division with mixed references
Source§impl<T> Div for ASTRepr<T>where
T: NumericType + Div<Output = T>,
Division operator overloading for ASTRepr<T>
impl<T> Div for ASTRepr<T>where
T: NumericType + Div<Output = T>,
Division operator overloading for ASTRepr<T>
Source§impl<T> Mul<&ASTRepr<T>> for &ASTRepr<T>where
T: NumericType + Mul<Output = T>,
Multiplication with references
impl<T> Mul<&ASTRepr<T>> for &ASTRepr<T>where
T: NumericType + Mul<Output = T>,
Multiplication with references
Source§impl<T> Mul<ASTRepr<T>> for &ASTRepr<T>where
T: NumericType + Mul<Output = T>,
Multiplication with mixed references
impl<T> Mul<ASTRepr<T>> for &ASTRepr<T>where
T: NumericType + Mul<Output = T>,
Multiplication with mixed references
Source§impl<T> Mul for ASTRepr<T>where
T: NumericType + Mul<Output = T>,
Multiplication operator overloading for ASTRepr<T>
impl<T> Mul for ASTRepr<T>where
T: NumericType + Mul<Output = T>,
Multiplication operator overloading for ASTRepr<T>
Source§impl<T> Neg for ASTRepr<T>where
T: NumericType + Neg<Output = T>,
Negation operator overloading for ASTRepr<T>
impl<T> Neg for ASTRepr<T>where
T: NumericType + Neg<Output = T>,
Negation operator overloading for ASTRepr<T>
Source§impl<T> Sub<&ASTRepr<T>> for &ASTRepr<T>where
T: NumericType + Sub<Output = T>,
Subtraction with references
impl<T> Sub<&ASTRepr<T>> for &ASTRepr<T>where
T: NumericType + Sub<Output = T>,
Subtraction with references
Source§impl<T> Sub<ASTRepr<T>> for &ASTRepr<T>where
T: NumericType + Sub<Output = T>,
Subtraction with mixed references
impl<T> Sub<ASTRepr<T>> for &ASTRepr<T>where
T: NumericType + Sub<Output = T>,
Subtraction with mixed references
Source§impl<T> Sub for ASTRepr<T>where
T: NumericType + Sub<Output = T>,
Subtraction operator overloading for ASTRepr<T>
impl<T> Sub for ASTRepr<T>where
T: NumericType + Sub<Output = T>,
Subtraction operator overloading for ASTRepr<T>