Skip to main content

Module expr

Module expr 

Source
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, not operations.
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).
SimplifyOpts
Options controlling Expr::simplify_with. Options for configuring the simplification engine.

Enums§

ExprType
Structural classification of an expression node.

Traits§

Sort
Marker trait for expression sorts.

Type Aliases§

BoolEx
A boolean expression — comparisons and logical operations.
Ex
A numeric expression — the primary type for symbolic math.
SetEx
A set-valued expression — intervals, finite sets, unions.