pub enum Expr {
Show 147 variants
Constant(f64),
BigInt(BigInt),
Rational(BigRational),
Boolean(bool),
Variable(String),
Pattern(String),
Add(Arc<Expr>, Arc<Expr>),
Sub(Arc<Expr>, Arc<Expr>),
Mul(Arc<Expr>, Arc<Expr>),
Div(Arc<Expr>, Arc<Expr>),
Power(Arc<Expr>, Arc<Expr>),
Neg(Arc<Expr>),
AddList(Vec<Expr>),
MulList(Vec<Expr>),
Sin(Arc<Expr>),
Cos(Arc<Expr>),
Tan(Arc<Expr>),
Exp(Arc<Expr>),
Log(Arc<Expr>),
Abs(Arc<Expr>),
Sqrt(Arc<Expr>),
Eq(Arc<Expr>, Arc<Expr>),
Lt(Arc<Expr>, Arc<Expr>),
Gt(Arc<Expr>, Arc<Expr>),
Le(Arc<Expr>, Arc<Expr>),
Ge(Arc<Expr>, Arc<Expr>),
Matrix(Vec<Vec<Expr>>),
Vector(Vec<Expr>),
Complex(Arc<Expr>, Arc<Expr>),
Transpose(Arc<Expr>),
MatrixMul(Arc<Expr>, Arc<Expr>),
MatrixVecMul(Arc<Expr>, Arc<Expr>),
Inverse(Arc<Expr>),
Derivative(Arc<Expr>, String),
DerivativeN(Arc<Expr>, String, Arc<Expr>),
Integral {
integrand: Arc<Expr>,
var: Arc<Expr>,
lower_bound: Arc<Expr>,
upper_bound: Arc<Expr>,
},
VolumeIntegral {
scalar_field: Arc<Expr>,
volume: Arc<Expr>,
},
SurfaceIntegral {
vector_field: Arc<Expr>,
surface: Arc<Expr>,
},
Limit(Arc<Expr>, String, Arc<Expr>),
Sum {
body: Arc<Expr>,
var: Arc<Expr>,
from: Arc<Expr>,
to: Arc<Expr>,
},
Series(Arc<Expr>, String, Arc<Expr>, Arc<Expr>),
Summation(Arc<Expr>, String, Arc<Expr>, Arc<Expr>),
Product(Arc<Expr>, String, Arc<Expr>, Arc<Expr>),
ConvergenceAnalysis(Arc<Expr>, String),
AsymptoticExpansion(Arc<Expr>, String, Arc<Expr>, Arc<Expr>),
Sec(Arc<Expr>),
Csc(Arc<Expr>),
Cot(Arc<Expr>),
ArcSin(Arc<Expr>),
ArcCos(Arc<Expr>),
ArcTan(Arc<Expr>),
ArcSec(Arc<Expr>),
ArcCsc(Arc<Expr>),
ArcCot(Arc<Expr>),
Sinh(Arc<Expr>),
Cosh(Arc<Expr>),
Tanh(Arc<Expr>),
Sech(Arc<Expr>),
Csch(Arc<Expr>),
Coth(Arc<Expr>),
ArcSinh(Arc<Expr>),
ArcCosh(Arc<Expr>),
ArcTanh(Arc<Expr>),
ArcSech(Arc<Expr>),
ArcCsch(Arc<Expr>),
ArcCoth(Arc<Expr>),
LogBase(Arc<Expr>, Arc<Expr>),
Atan2(Arc<Expr>, Arc<Expr>),
Binomial(Arc<Expr>, Arc<Expr>),
Factorial(Arc<Expr>),
Permutation(Arc<Expr>, Arc<Expr>),
Combination(Arc<Expr>, Arc<Expr>),
FallingFactorial(Arc<Expr>, Arc<Expr>),
RisingFactorial(Arc<Expr>, Arc<Expr>),
Path(PathType, Arc<Expr>, Arc<Expr>),
Boundary(Arc<Expr>),
Domain(String),
Pi,
E,
Infinity,
NegativeInfinity,
Gamma(Arc<Expr>),
Beta(Arc<Expr>, Arc<Expr>),
Erf(Arc<Expr>),
Erfc(Arc<Expr>),
Erfi(Arc<Expr>),
Zeta(Arc<Expr>),
BesselJ(Arc<Expr>, Arc<Expr>),
BesselY(Arc<Expr>, Arc<Expr>),
LegendreP(Arc<Expr>, Arc<Expr>),
LaguerreL(Arc<Expr>, Arc<Expr>),
HermiteH(Arc<Expr>, Arc<Expr>),
Digamma(Arc<Expr>),
KroneckerDelta(Arc<Expr>, Arc<Expr>),
And(Vec<Expr>),
Or(Vec<Expr>),
Not(Arc<Expr>),
Xor(Arc<Expr>, Arc<Expr>),
Implies(Arc<Expr>, Arc<Expr>),
Equivalent(Arc<Expr>, Arc<Expr>),
Predicate {
name: String,
args: Vec<Expr>,
},
ForAll(String, Arc<Expr>),
Exists(String, Arc<Expr>),
Union(Vec<Expr>),
Interval(Arc<Expr>, Arc<Expr>, bool, bool),
Polynomial(Vec<Expr>),
SparsePolynomial(SparsePolynomial),
Floor(Arc<Expr>),
IsPrime(Arc<Expr>),
Gcd(Arc<Expr>, Arc<Expr>),
Mod(Arc<Expr>, Arc<Expr>),
Solve(Arc<Expr>, String),
Substitute(Arc<Expr>, String, Arc<Expr>),
System(Vec<Expr>),
Solutions(Vec<Expr>),
ParametricSolution {
x: Arc<Expr>,
y: Arc<Expr>,
},
RootOf {
poly: Arc<Expr>,
index: u32,
},
InfiniteSolutions,
NoSolution,
Ode {
equation: Arc<Expr>,
func: String,
var: String,
},
Pde {
equation: Arc<Expr>,
func: String,
vars: Vec<String>,
},
GeneralSolution(Arc<Expr>),
ParticularSolution(Arc<Expr>),
Fredholm(Arc<Expr>, Arc<Expr>, Arc<Expr>, Arc<Expr>),
Volterra(Arc<Expr>, Arc<Expr>, Arc<Expr>, Arc<Expr>),
Apply(Arc<Expr>, Arc<Expr>),
Tuple(Vec<Expr>),
Dag(Arc<DagNode>),
Distribution(Arc<dyn Distribution>),
Max(Arc<Expr>, Arc<Expr>),
Quantity(Arc<UnitQuantity>),
QuantityWithValue(Arc<Expr>, String),
CustomZero,
CustomString(String),
CustomArcOne(Arc<Expr>),
CustomArcTwo(Arc<Expr>, Arc<Expr>),
CustomArcThree(Arc<Expr>, Arc<Expr>, Arc<Expr>),
CustomArcFour(Arc<Expr>, Arc<Expr>, Arc<Expr>, Arc<Expr>),
CustomArcFive(Arc<Expr>, Arc<Expr>, Arc<Expr>, Arc<Expr>, Arc<Expr>),
CustomVecOne(Vec<Expr>),
CustomVecTwo(Vec<Expr>, Vec<Expr>),
CustomVecThree(Vec<Expr>, Vec<Expr>, Vec<Expr>),
CustomVecFour(Vec<Expr>, Vec<Expr>, Vec<Expr>, Vec<Expr>),
CustomVecFive(Vec<Expr>, Vec<Expr>, Vec<Expr>, Vec<Expr>, Vec<Expr>),
UnaryList(String, Arc<Expr>),
BinaryList(String, Arc<Expr>, Arc<Expr>),
NaryList(String, Vec<Expr>),
}Expand description
The central enum representing a mathematical expression in the symbolic system.
Expr is an Abstract Syntax Tree (AST) that can represent a wide variety of
mathematical objects and operations. Manual implementations for Debug, Clone,
PartialEq, Eq, and Hash are provided to handle variants containing types
that do not derive these traits automatically (e.g., f64, Arc<dyn Distribution>).
Variants§
Constant(f64)
A floating-point constant (64-bit).
BigInt(BigInt)
An arbitrary-precision integer.
Rational(BigRational)
An arbitrary-precision rational number.
Boolean(bool)
A boolean value (true or false).
Variable(String)
A symbolic variable, represented by a string name.
Pattern(String)
A pattern variable, used for rule-matching systems.
Add(Arc<Expr>, Arc<Expr>)
Addition of two expressions.
Sub(Arc<Expr>, Arc<Expr>)
Subtraction of two expressions.
Mul(Arc<Expr>, Arc<Expr>)
Multiplication of two expressions.
Div(Arc<Expr>, Arc<Expr>)
Division of two expressions.
Power(Arc<Expr>, Arc<Expr>)
Exponentiation (base raised to the power of exponent).
Neg(Arc<Expr>)
Negation of an expression.
AddList(Vec<Expr>)
N-ary Addition (Sum of a list of expressions).
This variant represents the sum of multiple expressions in a single operation,
which is more efficient than nested binary Add operations for associative operations.
It’s part of the AST to DAG migration strategy, allowing for more flexible
expression representation without breaking existing code.
§Examples
use rssn::symbolic::core::Expr;
// Representing a + b + c + d as a single n-ary operation
let sum = Expr::AddList(vec![
Expr::Variable("a".to_string()),
Expr::Variable("b".to_string()),
Expr::Variable("c".to_string()),
Expr::Variable("d".to_string()),
]);MulList(Vec<Expr>)
N-ary Multiplication (Product of a list of expressions).
This variant represents the product of multiple expressions in a single operation,
which is more efficient than nested binary Mul operations for associative operations.
It’s part of the AST to DAG migration strategy, allowing for more flexible
expression representation without breaking existing code.
§Examples
use rssn::symbolic::core::Expr;
// Representing a * b * c * d as a single n-ary operation
let product = Expr::MulList(vec![
Expr::Variable("a".to_string()),
Expr::Variable("b".to_string()),
Expr::Variable("c".to_string()),
Expr::Variable("d".to_string()),
]);Sin(Arc<Expr>)
The sine function.
Cos(Arc<Expr>)
The cosine function.
Tan(Arc<Expr>)
The tangent function.
Exp(Arc<Expr>)
The natural exponential function, e^x.
Log(Arc<Expr>)
The natural logarithm, ln(x).
Abs(Arc<Expr>)
The absolute value function, |x|.
Sqrt(Arc<Expr>)
The square root function.
Eq(Arc<Expr>, Arc<Expr>)
Represents an equation (left = right).
Lt(Arc<Expr>, Arc<Expr>)
Less than (<).
Gt(Arc<Expr>, Arc<Expr>)
Greater than (>).
Le(Arc<Expr>, Arc<Expr>)
Less than or equal to (<=).
Ge(Arc<Expr>, Arc<Expr>)
Greater than or equal to (>=).
Matrix(Vec<Vec<Expr>>)
A matrix, represented as a vector of row vectors.
Vector(Vec<Expr>)
A vector (or column matrix).
Complex(Arc<Expr>, Arc<Expr>)
A complex number with real and imaginary parts.
Transpose(Arc<Expr>)
Matrix transpose.
MatrixMul(Arc<Expr>, Arc<Expr>)
Matrix-matrix multiplication.
MatrixVecMul(Arc<Expr>, Arc<Expr>)
Matrix-vector multiplication.
Inverse(Arc<Expr>)
Matrix inverse.
Derivative(Arc<Expr>, String)
The derivative of an expression with respect to a variable.
DerivativeN(Arc<Expr>, String, Arc<Expr>)
The N-th derivative of an expression.
Integral
A definite integral of integrand with respect to var from lower_bound to upper_bound.
VolumeIntegral
A volume integral of a scalar field over a specified volume.
SurfaceIntegral
A surface integral of a vector field over a specified surface.
Limit(Arc<Expr>, String, Arc<Expr>)
A limit of an expression as a variable approaches a point.
Sum
A summation of body with var from from to to.
Series(Arc<Expr>, String, Arc<Expr>, Arc<Expr>)
A finite or infinite series expansion.
Summation(Arc<Expr>, String, Arc<Expr>, Arc<Expr>)
A summation over a range (similar to Sum).
Product(Arc<Expr>, String, Arc<Expr>, Arc<Expr>)
A product of terms over a range.
ConvergenceAnalysis(Arc<Expr>, String)
Represents a convergence analysis for a series.
AsymptoticExpansion(Arc<Expr>, String, Arc<Expr>, Arc<Expr>)
An asymptotic expansion of a function.
Sec(Arc<Expr>)
Secant function.
Csc(Arc<Expr>)
Cosecant function.
Cot(Arc<Expr>)
Cotangent function.
ArcSin(Arc<Expr>)
Arcsine (inverse sine).
ArcCos(Arc<Expr>)
Arccosine (inverse cosine).
ArcTan(Arc<Expr>)
Arctangent (inverse tangent).
ArcSec(Arc<Expr>)
Arcsecant (inverse secant).
ArcCsc(Arc<Expr>)
Arccosecant (inverse cosecant).
ArcCot(Arc<Expr>)
Arccotangent (inverse cotangent).
Sinh(Arc<Expr>)
Hyperbolic sine.
Cosh(Arc<Expr>)
Hyperbolic cosine.
Tanh(Arc<Expr>)
Hyperbolic tangent.
Sech(Arc<Expr>)
Hyperbolic secant.
Csch(Arc<Expr>)
Hyperbolic cosecant.
Coth(Arc<Expr>)
Hyperbolic cotangent.
ArcSinh(Arc<Expr>)
Inverse hyperbolic sine.
ArcCosh(Arc<Expr>)
Inverse hyperbolic cosine.
ArcTanh(Arc<Expr>)
Inverse hyperbolic tangent.
ArcSech(Arc<Expr>)
Inverse hyperbolic secant.
ArcCsch(Arc<Expr>)
Inverse hyperbolic cosecant.
ArcCoth(Arc<Expr>)
Inverse hyperbolic cotangent.
LogBase(Arc<Expr>, Arc<Expr>)
Logarithm with a specified base.
Atan2(Arc<Expr>, Arc<Expr>)
Two-argument arctangent.
Binomial(Arc<Expr>, Arc<Expr>)
Binomial coefficient, “n choose k”.
Factorial(Arc<Expr>)
Factorial, n!.
Permutation(Arc<Expr>, Arc<Expr>)
Permutations, P(n, k).
Combination(Arc<Expr>, Arc<Expr>)
Combinations, C(n, k).
FallingFactorial(Arc<Expr>, Arc<Expr>)
Falling factorial.
RisingFactorial(Arc<Expr>, Arc<Expr>)
Rising factorial.
Path(PathType, Arc<Expr>, Arc<Expr>)
A path for path integrals (e.g., line, circle).
Boundary(Arc<Expr>)
Represents the boundary of a domain.
Domain(String)
Represents a named domain (e.g., for integrals).
Pi
The mathematical constant Pi (π).
E
The mathematical constant E (e, Euler’s number).
Infinity
Represents infinity.
NegativeInfinity
Represents negative infinity.
Gamma(Arc<Expr>)
The Gamma function.
Beta(Arc<Expr>, Arc<Expr>)
The Beta function.
Erf(Arc<Expr>)
The error function.
Erfc(Arc<Expr>)
The complementary error function.
Erfi(Arc<Expr>)
The imaginary error function.
Zeta(Arc<Expr>)
The Riemann Zeta function.
BesselJ(Arc<Expr>, Arc<Expr>)
Bessel function of the first kind.
BesselY(Arc<Expr>, Arc<Expr>)
Bessel function of the second kind.
LegendreP(Arc<Expr>, Arc<Expr>)
Legendre polynomial.
LaguerreL(Arc<Expr>, Arc<Expr>)
Laguerre polynomial.
HermiteH(Arc<Expr>, Arc<Expr>)
Hermite polynomial.
Digamma(Arc<Expr>)
The digamma function (psi function).
KroneckerDelta(Arc<Expr>, Arc<Expr>)
The Kronecker delta function.
And(Vec<Expr>)
Logical AND of a vector of expressions.
Or(Vec<Expr>)
Logical OR of a vector of expressions.
Not(Arc<Expr>)
Logical NOT.
Xor(Arc<Expr>, Arc<Expr>)
Logical XOR (exclusive OR).
Implies(Arc<Expr>, Arc<Expr>)
Logical implication (A => B).
Equivalent(Arc<Expr>, Arc<Expr>)
Logical equivalence (A <=> B).
Predicate
A predicate with a name and arguments.
ForAll(String, Arc<Expr>)
Universal quantifier (“for all”).
Exists(String, Arc<Expr>)
Existential quantifier (“there exists”).
Union(Vec<Expr>)
A union of sets or intervals.
Interval(Arc<Expr>, Arc<Expr>, bool, bool)
An interval with a lower and upper bound, and flags for inclusion.
Polynomial(Vec<Expr>)
A dense polynomial represented by its coefficients.
SparsePolynomial(SparsePolynomial)
A sparse polynomial.
Floor(Arc<Expr>)
The floor function.
IsPrime(Arc<Expr>)
A predicate to check if a number is prime.
Gcd(Arc<Expr>, Arc<Expr>)
Greatest Common Divisor (GCD).
Mod(Arc<Expr>, Arc<Expr>)
Modulo operation.
Solve(Arc<Expr>, String)
Represents the action of solving an equation for a variable.
Substitute(Arc<Expr>, String, Arc<Expr>)
Represents the substitution of a variable in an expression with another expression.
System(Vec<Expr>)
Represents a system of equations to be solved.
Solutions(Vec<Expr>)
Represents the set of solutions to an equation or system.
ParametricSolution
A parametric solution, e.g., for a system of ODEs.
RootOf
Represents the i-th root of a polynomial.
InfiniteSolutions
Represents infinite solutions.
NoSolution
Represents that no solution exists.
Ode
An ordinary differential equation (ODE).
Pde
A partial differential equation (PDE).
GeneralSolution(Arc<Expr>)
The general solution to a differential equation.
ParticularSolution(Arc<Expr>)
A particular solution to a differential equation.
Fredholm(Arc<Expr>, Arc<Expr>, Arc<Expr>, Arc<Expr>)
A Fredholm integral equation.
Volterra(Arc<Expr>, Arc<Expr>, Arc<Expr>, Arc<Expr>)
A Volterra integral equation.
Apply(Arc<Expr>, Arc<Expr>)
Application of a function to an argument.
Tuple(Vec<Expr>)
A tuple of expressions.
Dag(Arc<DagNode>)
A node in a Directed Acyclic Graph (DAG) for expression sharing.
This is now the preferred representation for all expressions. When serialized, the DAG structure is preserved.
Distribution(Arc<dyn Distribution>)
A probability distribution.
Max(Arc<Expr>, Arc<Expr>)
Maximum of two expressions.
Quantity(Arc<UnitQuantity>)
A unified quantity with its value and unit string.
QuantityWithValue(Arc<Expr>, String)
A temporary representation of a value with a unit string, before unification.
CustomZero
CustomString(String)
CustomArcOne(Arc<Expr>)
CustomArcTwo(Arc<Expr>, Arc<Expr>)
CustomArcThree(Arc<Expr>, Arc<Expr>, Arc<Expr>)
CustomArcFour(Arc<Expr>, Arc<Expr>, Arc<Expr>, Arc<Expr>)
CustomArcFive(Arc<Expr>, Arc<Expr>, Arc<Expr>, Arc<Expr>, Arc<Expr>)
CustomVecOne(Vec<Expr>)
CustomVecTwo(Vec<Expr>, Vec<Expr>)
CustomVecThree(Vec<Expr>, Vec<Expr>, Vec<Expr>)
CustomVecFour(Vec<Expr>, Vec<Expr>, Vec<Expr>, Vec<Expr>)
CustomVecFive(Vec<Expr>, Vec<Expr>, Vec<Expr>, Vec<Expr>, Vec<Expr>)
UnaryList(String, Arc<Expr>)
Generic unary operation identified by a name.
This variant allows for extensible unary operations without modifying the Expr enum.
Operations are registered in the DYNAMIC_OP_REGISTRY with their properties
(associativity, commutativity, etc.). This is part of the plugin system and
future-proofing strategy.
§Examples
use rssn::symbolic::core::{Expr, register_dynamic_op, DynamicOpProperties};
use std::sync::Arc;
// Register a custom operation
register_dynamic_op("my_func", DynamicOpProperties {
name: "my_func".to_string(),
description: "My custom function".to_string(),
is_associative: false,
is_commutative: false,
});
// Use it
let expr = Expr::UnaryList(
"my_func".to_string(),
Arc::new(Expr::Variable("x".to_string()))
);BinaryList(String, Arc<Expr>, Arc<Expr>)
Generic binary operation identified by a name.
This variant allows for extensible binary operations without modifying the Expr enum.
Operations are registered in the DYNAMIC_OP_REGISTRY with their properties.
§Examples
use rssn::symbolic::core::{Expr, register_dynamic_op, DynamicOpProperties};
use std::sync::Arc;
// Register a custom binary operation
register_dynamic_op("my_binop", DynamicOpProperties {
name: "my_binop".to_string(),
description: "My custom binary operation".to_string(),
is_associative: true,
is_commutative: true,
});
// Use it
let expr = Expr::BinaryList(
"my_binop".to_string(),
Arc::new(Expr::Variable("x".to_string())),
Arc::new(Expr::Variable("y".to_string()))
);NaryList(String, Vec<Expr>)
Generic n-ary operation identified by a name.
This variant allows for extensible n-ary operations without modifying the Expr enum.
Operations are registered in the DYNAMIC_OP_REGISTRY with their properties.
This is particularly useful for operations that can take a variable number of arguments.
§Examples
use rssn::symbolic::core::{Expr, register_dynamic_op, DynamicOpProperties};
// Register a custom n-ary operation
register_dynamic_op("my_nary", DynamicOpProperties {
name: "my_nary".to_string(),
description: "My custom n-ary operation".to_string(),
is_associative: true,
is_commutative: false,
});
// Use it
let expr = Expr::NaryList(
"my_nary".to_string(),
vec![
Expr::Variable("a".to_string()),
Expr::Variable("b".to_string()),
Expr::Variable("c".to_string()),
]
);Implementations§
Source§impl Expr
impl Expr
pub fn re(&self) -> Self
pub fn im(&self) -> Self
pub fn to_f64(&self) -> Option<f64>
Sourcepub fn op(&self) -> DagOp
pub fn op(&self) -> DagOp
Returns the operation type of the expression in a unified way.
This method handles both regular expressions and DAG nodes, returning the operation regardless of internal representation.
§Returns
DagOp- The operation type corresponding to this expression
Sourcepub fn children(&self) -> Vec<Expr>
pub fn children(&self) -> Vec<Expr>
Returns the children of the expression in a unified way.
This method handles both regular expressions and DAG nodes, returning the direct child expressions regardless of internal representation.
§Returns
Vec<Expr>- A vector containing the direct children of this expression
Source§impl Expr
impl Expr
pub fn clone_box_dist(&self) -> Result<Arc<dyn Distribution>, String>
pub fn clone_box_quant(&self) -> Result<Arc<UnitQuantity>, String>
Source§impl Expr
impl Expr
Sourcepub fn pre_order_walk<F>(&self, f: &mut F)
pub fn pre_order_walk<F>(&self, f: &mut F)
Performs a pre-order traversal of the expression tree. It visits the current node first, then its children.
§Arguments
f- A mutable function that takes a reference to anExprand is applied to each node during traversal
Sourcepub fn post_order_walk<F>(&self, f: &mut F)
pub fn post_order_walk<F>(&self, f: &mut F)
Performs a post-order traversal of the expression tree. It visits the children first, then the current node.
§Arguments
f- A mutable function that takes a reference to anExprand is applied to each node during traversal
Sourcepub fn in_order_walk<F>(&self, f: &mut F)
pub fn in_order_walk<F>(&self, f: &mut F)
Performs an in-order traversal of the expression tree. For binary operators, it visits the left child, the node itself, then the right child. For other nodes, the behavior is adapted as it’s not strictly defined.
§Arguments
f- A mutable function that takes a reference to anExprand is applied to each node during traversal
pub fn normalize(&self) -> Expr
Source§impl Expr
impl Expr
Sourcepub fn new_constant(c: f64) -> Expr
pub fn new_constant(c: f64) -> Expr
Creates a new Constant expression, managed by the DAG.
Sourcepub fn new_variable(name: &str) -> Expr
pub fn new_variable(name: &str) -> Expr
Creates a new Variable expression, managed by the DAG.
Sourcepub fn new_bigint(i: BigInt) -> Expr
pub fn new_bigint(i: BigInt) -> Expr
Creates a new BigInt expression, managed by the DAG.
Sourcepub fn new_rational(r: BigRational) -> Expr
pub fn new_rational(r: BigRational) -> Expr
Creates a new Rational expression, managed by the DAG.
Sourcepub fn new_infinity() -> Expr
pub fn new_infinity() -> Expr
Creates a new Infinity expression, managed by the DAG.
Sourcepub fn new_negative_infinity() -> Expr
pub fn new_negative_infinity() -> Expr
Creates a new NegativeInfinity expression, managed by the DAG.
Sourcepub fn new_transpose<A>(a: A) -> Expr
pub fn new_transpose<A>(a: A) -> Expr
Creates a new Transpose expression, managed by the DAG.
Sourcepub fn new_inverse<A>(a: A) -> Expr
pub fn new_inverse<A>(a: A) -> Expr
Creates a new Inverse expression, managed by the DAG.
Sourcepub fn new_arcsin<A>(a: A) -> Expr
pub fn new_arcsin<A>(a: A) -> Expr
Creates a new ArcSin expression, managed by the DAG.
Sourcepub fn new_arccos<A>(a: A) -> Expr
pub fn new_arccos<A>(a: A) -> Expr
Creates a new ArcCos expression, managed by the DAG.
Sourcepub fn new_arctan<A>(a: A) -> Expr
pub fn new_arctan<A>(a: A) -> Expr
Creates a new ArcTan expression, managed by the DAG.
Sourcepub fn new_arcsec<A>(a: A) -> Expr
pub fn new_arcsec<A>(a: A) -> Expr
Creates a new ArcSec expression, managed by the DAG.
Sourcepub fn new_arccsc<A>(a: A) -> Expr
pub fn new_arccsc<A>(a: A) -> Expr
Creates a new ArcCsc expression, managed by the DAG.
Sourcepub fn new_arccot<A>(a: A) -> Expr
pub fn new_arccot<A>(a: A) -> Expr
Creates a new ArcCot expression, managed by the DAG.
Sourcepub fn new_arcsinh<A>(a: A) -> Expr
pub fn new_arcsinh<A>(a: A) -> Expr
Creates a new ArcSinh expression, managed by the DAG.
Sourcepub fn new_arccosh<A>(a: A) -> Expr
pub fn new_arccosh<A>(a: A) -> Expr
Creates a new ArcCosh expression, managed by the DAG.
Sourcepub fn new_arctanh<A>(a: A) -> Expr
pub fn new_arctanh<A>(a: A) -> Expr
Creates a new ArcTanh expression, managed by the DAG.
Sourcepub fn new_arcsech<A>(a: A) -> Expr
pub fn new_arcsech<A>(a: A) -> Expr
Creates a new ArcSech expression, managed by the DAG.
Sourcepub fn new_arccsch<A>(a: A) -> Expr
pub fn new_arccsch<A>(a: A) -> Expr
Creates a new ArcCsch expression, managed by the DAG.
Sourcepub fn new_arccoth<A>(a: A) -> Expr
pub fn new_arccoth<A>(a: A) -> Expr
Creates a new ArcCoth expression, managed by the DAG.
Sourcepub fn new_digamma<A>(a: A) -> Expr
pub fn new_digamma<A>(a: A) -> Expr
Creates a new Digamma expression, managed by the DAG.
Sourcepub fn new_complex<A, B>(a: A, b: B) -> Expr
pub fn new_complex<A, B>(a: A, b: B) -> Expr
Creates a new Complex expression, managed by the DAG.
Sourcepub fn new_matrix_mul<A, B>(a: A, b: B) -> Expr
pub fn new_matrix_mul<A, B>(a: A, b: B) -> Expr
Creates a new MatrixMul expression, managed by the DAG.
Sourcepub fn new_matrix_vec_mul<A, B>(a: A, b: B) -> Expr
pub fn new_matrix_vec_mul<A, B>(a: A, b: B) -> Expr
Creates a new MatrixVecMul expression, managed by the DAG.
Sourcepub fn new_log_base<A, B>(a: A, b: B) -> Expr
pub fn new_log_base<A, B>(a: A, b: B) -> Expr
Creates a new LogBase expression, managed by the DAG.
Sourcepub fn new_implies<A, B>(a: A, b: B) -> Expr
pub fn new_implies<A, B>(a: A, b: B) -> Expr
Creates a new Implies expression, managed by the DAG.
Sourcepub fn new_equivalent<A, B>(a: A, b: B) -> Expr
pub fn new_equivalent<A, B>(a: A, b: B) -> Expr
Creates a new Equivalent expression, managed by the DAG.
Sourcepub fn new_bessel_j<A, B>(a: A, b: B) -> Expr
pub fn new_bessel_j<A, B>(a: A, b: B) -> Expr
Creates a new BesselJ expression, managed by the DAG.
Sourcepub fn new_bessel_y<A, B>(a: A, b: B) -> Expr
pub fn new_bessel_y<A, B>(a: A, b: B) -> Expr
Creates a new BesselY expression, managed by the DAG.
Sourcepub fn new_legendre_p<A, B>(a: A, b: B) -> Expr
pub fn new_legendre_p<A, B>(a: A, b: B) -> Expr
Creates a new LegendreP expression, managed by the DAG.
Sourcepub fn new_laguerre_l<A, B>(a: A, b: B) -> Expr
pub fn new_laguerre_l<A, B>(a: A, b: B) -> Expr
Creates a new LaguerreL expression, managed by the DAG.
Sourcepub fn new_hermite_h<A, B>(a: A, b: B) -> Expr
pub fn new_hermite_h<A, B>(a: A, b: B) -> Expr
Creates a new HermiteH expression, managed by the DAG.
Sourcepub fn new_kronecker_delta<A, B>(a: A, b: B) -> Expr
pub fn new_kronecker_delta<A, B>(a: A, b: B) -> Expr
Creates a new KroneckerDelta expression, managed by the DAG.
Sourcepub fn new_vector<I, T>(elements: I) -> Expr
pub fn new_vector<I, T>(elements: I) -> Expr
Creates a new Vector expression, managed by the DAG.
Sourcepub fn new_union<I, T>(elements: I) -> Expr
pub fn new_union<I, T>(elements: I) -> Expr
Creates a new Union expression, managed by the DAG.
Sourcepub fn new_polynomial<I, T>(elements: I) -> Expr
pub fn new_polynomial<I, T>(elements: I) -> Expr
Creates a new Polynomial expression, managed by the DAG.
Sourcepub fn new_tuple<I, T>(elements: I) -> Expr
pub fn new_tuple<I, T>(elements: I) -> Expr
Creates a new Tuple expression, managed by the DAG.
Sourcepub fn new_matrix<I, J, T>(elements: I) -> Expr
pub fn new_matrix<I, J, T>(elements: I) -> Expr
Creates a new Matrix expression, managed by the DAG.
pub fn new_predicate<I, T>(name: &str, args: I) -> Expr
pub fn new_forall<A>(var: &str, expr: A) -> Expr
pub fn new_exists<A>(var: &str, expr: A) -> Expr
pub fn new_interval<A, B>( lower: A, upper: B, incl_lower: bool, incl_upper: bool, ) -> Expr
pub fn new_sparse_polynomial(p: SparsePolynomial) -> Expr
pub fn new_custom_zero() -> Expr
pub fn new_custom_string(s: &str) -> Expr
Sourcepub fn new_custom_arc_one<A>(a: A) -> Expr
👎Deprecated since 0.1.18: Please use the ‘UnaryList’ variant instead.
pub fn new_custom_arc_one<A>(a: A) -> Expr
Creates a new CustomArcOne expression, managed by the DAG.
Sourcepub fn new_custom_arc_two<A, B>(a: A, b: B) -> Expr
👎Deprecated since 0.1.18: Please use the ‘BinaryList’ variant instead.
pub fn new_custom_arc_two<A, B>(a: A, b: B) -> Expr
Creates a new CustomArcTwo expression, managed by the DAG.
pub fn new_custom_arc_three<A, B, C>(a: A, b: B, c: C) -> Expr
pub fn new_custom_arc_four<A, B, C, D>(a: A, b: B, c: C, d: D) -> Expr
pub fn new_custom_arc_five<A, B, C, D, E>(a: A, b: B, c: C, d: D, e: E) -> Expr
Sourcepub fn new_custom_vec_one<I, T>(elements: I) -> Expr
👎Deprecated since 0.1.18: Please use the ‘NaryList’ variant instead.
pub fn new_custom_vec_one<I, T>(elements: I) -> Expr
Creates a new CustomVecOne expression, managed by the DAG.
Sourcepub fn new_custom_vec_two<I, T>(elements: I) -> Expr
👎Deprecated since 0.1.18: Please use the ‘NaryList’ variant instead.
pub fn new_custom_vec_two<I, T>(elements: I) -> Expr
Creates a new CustomVecTwo expression, managed by the DAG.
Sourcepub fn new_custom_vec_three<I, T>(elements: I) -> Expr
👎Deprecated since 0.1.18: Please use the ‘NaryList’ variant instead.
pub fn new_custom_vec_three<I, T>(elements: I) -> Expr
Creates a new CustomVecThree expression, managed by the DAG.
Sourcepub fn new_custom_vec_four<I, T>(elements: I) -> Expr
👎Deprecated since 0.1.18: Please use the ‘NaryList’ variant instead.
pub fn new_custom_vec_four<I, T>(elements: I) -> Expr
Creates a new CustomVecFour expression, managed by the DAG.
Sourcepub fn new_custom_vec_five<I, T>(elements: I) -> Expr
👎Deprecated since 0.1.18: Please use the ‘NaryList’ variant instead.
pub fn new_custom_vec_five<I, T>(elements: I) -> Expr
Creates a new CustomVecFive expression, managed by the DAG.
Sourcepub fn to_dag(&self) -> Result<Expr, String>
pub fn to_dag(&self) -> Result<Expr, String>
Converts this expression to DAG form if not already.
This is a key function for the AST→DAG migration. It ensures that any expression, whether in old AST form or new DAG form, is converted to a canonical DAG representation.
§Returns
Ok(Expr::Dag)- The expression in DAG formErr(String)- If conversion fails
§Examples
use rssn::symbolic::core::Expr;
use std::sync::Arc;
// Old AST form
let ast = Expr::Add(
Arc::new(Expr::Variable("x".to_string())),
Arc::new(Expr::Constant(1.0))
);
// Convert to DAG
let dag = ast.to_dag().unwrap();
assert!(dag.is_dag());Sourcepub fn to_dag_form(&mut self)
pub fn to_dag_form(&mut self)
Converts this expression to DAG form in-place.
This is a convenience method that converts the expression to DAG form and replaces the current value.
§Examples
use rssn::symbolic::core::Expr;
let mut expr = Expr::Constant(1.0);
assert!(!expr.is_dag());
expr.to_dag_form();
assert!(expr.is_dag());Sourcepub fn to_ast(&self) -> Result<Expr, String>
pub fn to_ast(&self) -> Result<Expr, String>
Converts a DAG expression back to AST form (for serialization).
This is used internally for backward-compatible serialization. Note: This may fail for expressions that cannot be represented in AST form.
§Returns
Ok(Expr)- The expression in AST formErr(String)- If conversion fails
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Expr
impl<'de> Deserialize<'de> for Expr
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Mul<Expr> for Multivector
impl Mul<Expr> for Multivector
Source§impl Ord for Expr
impl Ord for Expr
Source§impl PartialOrd for Expr
impl PartialOrd for Expr
impl Eq for Expr
Auto Trait Implementations§
impl Freeze for Expr
impl !RefUnwindSafe for Expr
impl Send for Expr
impl Sync for Expr
impl Unpin for Expr
impl !UnwindSafe for Expr
Blanket Implementations§
Source§impl<T> AlignerFor<1> for T
impl<T> AlignerFor<1> for T
Source§impl<T> AlignerFor<1024> for T
impl<T> AlignerFor<1024> for T
Source§type Aligner = AlignTo1024<T>
type Aligner = AlignTo1024<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<128> for T
impl<T> AlignerFor<128> for T
Source§type Aligner = AlignTo128<T>
type Aligner = AlignTo128<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<16> for T
impl<T> AlignerFor<16> for T
Source§impl<T> AlignerFor<16384> for T
impl<T> AlignerFor<16384> for T
Source§type Aligner = AlignTo16384<T>
type Aligner = AlignTo16384<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<2> for T
impl<T> AlignerFor<2> for T
Source§impl<T> AlignerFor<2048> for T
impl<T> AlignerFor<2048> for T
Source§type Aligner = AlignTo2048<T>
type Aligner = AlignTo2048<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<256> for T
impl<T> AlignerFor<256> for T
Source§type Aligner = AlignTo256<T>
type Aligner = AlignTo256<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<32> for T
impl<T> AlignerFor<32> for T
Source§impl<T> AlignerFor<32768> for T
impl<T> AlignerFor<32768> for T
Source§type Aligner = AlignTo32768<T>
type Aligner = AlignTo32768<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<4> for T
impl<T> AlignerFor<4> for T
Source§impl<T> AlignerFor<4096> for T
impl<T> AlignerFor<4096> for T
Source§type Aligner = AlignTo4096<T>
type Aligner = AlignTo4096<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<512> for T
impl<T> AlignerFor<512> for T
Source§type Aligner = AlignTo512<T>
type Aligner = AlignTo512<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<64> for T
impl<T> AlignerFor<64> for T
Source§impl<T> AlignerFor<8> for T
impl<T> AlignerFor<8> for T
Source§impl<T> AlignerFor<8192> for T
impl<T> AlignerFor<8192> for T
Source§type Aligner = AlignTo8192<T>
type Aligner = AlignTo8192<T>
AlignTo* type which aligns Self to ALIGNMENT.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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
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> ⓘ
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> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<'a, T> RCowCompatibleRef<'a> for Twhere
T: Clone + 'a,
impl<'a, T> RCowCompatibleRef<'a> for Twhere
T: Clone + 'a,
Source§fn as_c_ref(from: &'a T) -> <T as RCowCompatibleRef<'a>>::RefC
fn as_c_ref(from: &'a T) -> <T as RCowCompatibleRef<'a>>::RefC
Source§fn as_rust_ref(from: <T as RCowCompatibleRef<'a>>::RefC) -> &'a T
fn as_rust_ref(from: <T as RCowCompatibleRef<'a>>::RefC) -> &'a T
Source§impl<S> ROExtAcc for S
impl<S> ROExtAcc for S
Source§fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
offset. Read moreSource§fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
offset. Read moreSource§fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
offset. Read moreSource§fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
offset. Read moreSource§impl<S> ROExtOps<Aligned> for S
impl<S> ROExtOps<Aligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
offset) with value,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
Source§impl<S> ROExtOps<Unaligned> for S
impl<S> ROExtOps<Unaligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
offset) with value,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
Source§impl<T> SelfOps for Twhere
T: ?Sized,
impl<T> SelfOps for Twhere
T: ?Sized,
Source§fn piped<F, U>(self, f: F) -> U
fn piped<F, U>(self, f: F) -> U
Source§fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
piped except that the function takes &Self
Useful for functions that take &Self instead of Self. Read moreSource§fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
piped, except that the function takes &mut Self.
Useful for functions that take &mut Self instead of Self.Source§fn mutated<F>(self, f: F) -> Self
fn mutated<F>(self, f: F) -> Self
Source§fn observe<F>(self, f: F) -> Self
fn observe<F>(self, f: F) -> Self
Source§fn as_ref_<T>(&self) -> &T
fn as_ref_<T>(&self) -> &T
AsRef,
using the turbofish .as_ref_::<_>() syntax. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.