Expand description
The core expression handle and types. User-facing expression handle.
Ex is a lightweight handle to a symbolic expression. It holds a
reference-counted pointer to the shared ContextInner (which
contains both the arena and the assumption cache) plus an expression ID.
Clone is cheap (~5ns, just an Arc clone + u32 copy).
Ex is not Copy because it contains an Arc. This is a
deliberate trade-off: storing the context pointer means every method
(pow, sin, is_positive, operators, Display) works without
requiring any special scoping.
To reduce clone noise, all binary operators are implemented for every
combination of Ex and &Ex, and for i64 on both sides.
§Examples
use symplex::prelude::*;
let ctx = Context::new();
let x = ctx.symbol("x");
let expr = &x * &x + &x * 2 + 1;
assert_eq!(format!("{expr}"), "x^2 + 2*x + 1");Methods are chainable:
use symplex::prelude::*;
let ctx = Context::new();
let x = ctx.symbol("x");
let expr = x.powi(2).sin();
assert_eq!(format!("{expr}"), "sin(x^2)");use symplex::prelude::*;
let ctx = Context::new();
let x = ctx.symbol("x");
let expr = x.sin();
assert_eq!(format!("{expr}"), "sin(x)");Structs§
- Boolean
- Boolean sort: true/false values from comparisons and logic.
Supports
and,or,notoperations. - Expr
- A symbolic expression handle, parameterized by sort.
- Numeric
- Numeric sort: real, complex, and integer values. Supports arithmetic, calculus, and algebraic operations.
- SetValued
- Set-valued sort: intervals, finite sets, unions. Supports set operations (union, intersection, complement).
- Simplify
Opts - Options controlling
Expr::simplify_with. Options for configuring the simplification engine.
Enums§
- Expr
Type - Structural classification of an expression node.
Traits§
- Sort
- Marker trait for expression sorts.