pub enum EvalTree {
Num(f64),
Var(String),
Fun(String, Vec<EvalTree>),
Add(Vec<EvalTree>),
Mul(Vec<EvalTree>),
Pow(Box<EvalTree>, Box<EvalTree>),
}Expand description
An owned intermediate representation of a symbolic expression.
Unlike Atom, EvalTree owns all its data and
does not depend on an arena. This makes it suitable for multi-pass
compilation and optimization.
Variants§
Num(f64)
A numeric constant.
Var(String)
A variable reference.
Fun(String, Vec<EvalTree>)
A named function applied to arguments.
Add(Vec<EvalTree>)
A sum of terms.
Mul(Vec<EvalTree>)
A product of factors.
Pow(Box<EvalTree>, Box<EvalTree>)
A power expression: base^exponent.
Implementations§
Source§impl EvalTree
impl EvalTree
Sourcepub fn from_atom(atom: Atom<'_>) -> Self
pub fn from_atom(atom: Atom<'_>) -> Self
Convert an Atom into an owned EvalTree.
This dissociates the expression from the arena, allowing the compilation pipeline to work without lifetime constraints.
§Example
ⓘ
use ocas_atom::AtomArena;
use ocas_eval::EvalTree;
let arena = ocas_core::arena::Arena::new();
let ctx = AtomArena::new(&arena);
let atom = ctx.add(&[ctx.var("x"), ctx.num(2)]);
let tree = EvalTree::from_atom(atom);Sourcepub fn fold_constants(&self) -> EvalTree
pub fn fold_constants(&self) -> EvalTree
Fold constant subtrees and apply algebraic identities.
Rules applied:
Add: drop0terms, sum all-constant terms, collapse single termsMul: absorb0, drop1factors, multiply all-constant factors, collapse single factorsPow:x^1 → x,x^0 → 1,Num^NumevaluatedFun: builtin functions of all-constant arguments evaluated (external functions are never folded — they may have side effects)
Trait Implementations§
impl StructuralPartialEq for EvalTree
Auto Trait Implementations§
impl Freeze for EvalTree
impl RefUnwindSafe for EvalTree
impl Send for EvalTree
impl Sync for EvalTree
impl Unpin for EvalTree
impl UnsafeUnpin for EvalTree
impl UnwindSafe for EvalTree
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more