Enum ASTRepr

Source
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>

Source

pub fn count_operations(&self) -> usize

Count the total number of operations in the expression tree

Source

pub fn variable_index(&self) -> Option<usize>

Get the variable index if this is a variable, otherwise None

Source§

impl<T> ASTRepr<T>

Source

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

Source

pub fn pow(self, exp: ASTRepr<T>) -> ASTRepr<T>
where T: Float,

Power operation with natural syntax

Source

pub fn pow_ref(&self, exp: &ASTRepr<T>) -> ASTRepr<T>
where T: Float,

Power operation with reference

Source

pub fn ln(self) -> ASTRepr<T>
where T: Float,

Natural logarithm

Source

pub fn ln_ref(&self) -> ASTRepr<T>
where T: Float,

Natural logarithm with reference

Source

pub fn exp(self) -> ASTRepr<T>
where T: Float,

Exponential function

Source

pub fn exp_ref(&self) -> ASTRepr<T>
where T: Float,

Exponential function with reference

Source

pub fn sqrt(self) -> ASTRepr<T>
where T: Float,

Square root

Source

pub fn sqrt_ref(&self) -> ASTRepr<T>
where T: Float,

Square root with reference

Source

pub fn sin(self) -> ASTRepr<T>
where T: Float,

Sine function

Source

pub fn sin_ref(&self) -> ASTRepr<T>
where T: Float,

Sine function with reference

Source

pub fn cos(self) -> ASTRepr<T>
where T: Float,

Cosine function

Source

pub fn cos_ref(&self) -> ASTRepr<T>
where T: Float,

Cosine function with reference

Trait Implementations§

Source§

impl<T> Add<&ASTRepr<T>> for &ASTRepr<T>
where T: NumericType + Add<Output = T>,

Addition with references

Source§

type Output = ASTRepr<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &ASTRepr<T>) -> Self::Output

Performs the + operation. Read more
Source§

impl<T> Add<&ASTRepr<T>> for ASTRepr<T>
where T: NumericType + Add<Output = T>,

Source§

type Output = ASTRepr<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &ASTRepr<T>) -> Self::Output

Performs the + operation. Read more
Source§

impl<T> Add<ASTRepr<T>> for &ASTRepr<T>
where T: NumericType + Add<Output = T>,

Addition with mixed references

Source§

type Output = ASTRepr<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: ASTRepr<T>) -> Self::Output

Performs the + operation. Read more
Source§

impl<T> Add for ASTRepr<T>
where T: NumericType + Add<Output = T>,

Addition operator overloading for ASTRepr<T>

Source§

type Output = ASTRepr<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: Clone> Clone for ASTRepr<T>

Source§

fn clone(&self) -> ASTRepr<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for ASTRepr<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> Div<&ASTRepr<T>> for &ASTRepr<T>
where T: NumericType + Div<Output = T>,

Division with references

Source§

type Output = ASTRepr<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &ASTRepr<T>) -> Self::Output

Performs the / operation. Read more
Source§

impl<T> Div<&ASTRepr<T>> for ASTRepr<T>
where T: NumericType + Div<Output = T>,

Source§

type Output = ASTRepr<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &ASTRepr<T>) -> Self::Output

Performs the / operation. Read more
Source§

impl<T> Div<ASTRepr<T>> for &ASTRepr<T>
where T: NumericType + Div<Output = T>,

Division with mixed references

Source§

type Output = ASTRepr<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: ASTRepr<T>) -> Self::Output

Performs the / operation. Read more
Source§

impl<T> Div for ASTRepr<T>
where T: NumericType + Div<Output = T>,

Division operator overloading for ASTRepr<T>

Source§

type Output = ASTRepr<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl<T> Mul<&ASTRepr<T>> for &ASTRepr<T>
where T: NumericType + Mul<Output = T>,

Multiplication with references

Source§

type Output = ASTRepr<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &ASTRepr<T>) -> Self::Output

Performs the * operation. Read more
Source§

impl<T> Mul<&ASTRepr<T>> for ASTRepr<T>
where T: NumericType + Mul<Output = T>,

Source§

type Output = ASTRepr<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &ASTRepr<T>) -> Self::Output

Performs the * operation. Read more
Source§

impl<T> Mul<ASTRepr<T>> for &ASTRepr<T>
where T: NumericType + Mul<Output = T>,

Multiplication with mixed references

Source§

type Output = ASTRepr<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: ASTRepr<T>) -> Self::Output

Performs the * operation. Read more
Source§

impl<T> Mul for ASTRepr<T>
where T: NumericType + Mul<Output = T>,

Multiplication operator overloading for ASTRepr<T>

Source§

type Output = ASTRepr<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<T> Neg for &ASTRepr<T>
where T: NumericType + Neg<Output = T>,

Negation with references

Source§

type Output = ASTRepr<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T> Neg for ASTRepr<T>
where T: NumericType + Neg<Output = T>,

Negation operator overloading for ASTRepr<T>

Source§

type Output = ASTRepr<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T: PartialEq> PartialEq for ASTRepr<T>

Source§

fn eq(&self, other: &ASTRepr<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Sub<&ASTRepr<T>> for &ASTRepr<T>
where T: NumericType + Sub<Output = T>,

Subtraction with references

Source§

type Output = ASTRepr<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &ASTRepr<T>) -> Self::Output

Performs the - operation. Read more
Source§

impl<T> Sub<&ASTRepr<T>> for ASTRepr<T>
where T: NumericType + Sub<Output = T>,

Source§

type Output = ASTRepr<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &ASTRepr<T>) -> Self::Output

Performs the - operation. Read more
Source§

impl<T> Sub<ASTRepr<T>> for &ASTRepr<T>
where T: NumericType + Sub<Output = T>,

Subtraction with mixed references

Source§

type Output = ASTRepr<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: ASTRepr<T>) -> Self::Output

Performs the - operation. Read more
Source§

impl<T> Sub for ASTRepr<T>
where T: NumericType + Sub<Output = T>,

Subtraction operator overloading for ASTRepr<T>

Source§

type Output = ASTRepr<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<T> StructuralPartialEq for ASTRepr<T>

Auto Trait Implementations§

§

impl<T> Freeze for ASTRepr<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for ASTRepr<T>
where T: RefUnwindSafe,

§

impl<T> Send for ASTRepr<T>
where T: Send,

§

impl<T> Sync for ASTRepr<T>
where T: Sync,

§

impl<T> Unpin for ASTRepr<T>
where T: Unpin,

§

impl<T> UnwindSafe for ASTRepr<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V