pub struct ExprPool { /* private fields */ }Implementations§
Source§impl ExprPool
impl ExprPool
Sourcepub const IMAGINARY_UNIT_NAME: &'static str = "I"
pub const IMAGINARY_UNIT_NAME: &'static str = "I"
Canonical name of the kernel-blessed imaginary unit i = √(−1).
Reserved: do not create an unrelated free symbol with this name and
Domain::Complex — the simplifier applies the algebraic power rules
i² = −1, i³ = −i, i⁴ = 1, … to any symbol matching this name and
domain (see ExprPool::is_imaginary_unit).
pub fn new() -> Self
Sourcepub fn intern(&self, data: ExprData) -> ExprId
pub fn intern(&self, data: ExprData) -> ExprId
Intern data, returning a shared ExprId. Identical structures
always return the same id; structural equality ⟺ id equality.
data is first brought to its canonical spelling, so that two
spellings of one value cannot hold two ids:
- a
Rationalwhose denominator is1is theIntegernumerator (rational(4, 2)isinteger(2)); - an
AddorMulof one argument is that argument, the emptyAddis0and the emptyMulis1; - a
Floatzero orNaNis stored with a positive sign.BigFloat’sEqalready identifies-0.0with0.0(and everyNaNwith every other), so without this the node a pool kept would depend on which spelling happened to be interned first.
The result may therefore be a node of a different kind than data.
Every constructor, and the pool-file loader, goes through here.
Sourcepub fn is_mult_commutative(&self, id: ExprId) -> bool
pub fn is_mult_commutative(&self, id: ExprId) -> bool
Whether every generator in the subtree rooted at id commutes under
multiplication. O(1): the flag was computed when id was interned.
pub fn depth(&self, id: ExprId) -> u32
Sourcepub fn with<R, F: FnOnce(&ExprData) -> R>(&self, id: ExprId, f: F) -> R
pub fn with<R, F: FnOnce(&ExprData) -> R>(&self, id: ExprId, f: F) -> R
Borrow a node by id and apply f without cloning. Lock-free.
pub fn is_empty(&self) -> bool
Sourcepub fn symbol(&self, name: impl Into<String>, domain: Domain) -> ExprId
pub fn symbol(&self, name: impl Into<String>, domain: Domain) -> ExprId
Free symbol; multiplication treats it as commuting with every other factor (default).
Sourcepub fn imaginary_unit(&self) -> ExprId
pub fn imaginary_unit(&self) -> ExprId
The first-class imaginary unit i = √(−1).
Represented as the interned, kernel-blessed commuting symbol
IMAGINARY_UNIT_NAME with
Domain::Complex. This is the canonical representation: the
simplifier knows the algebraic identities i² = −1, i³ = −i,
i⁴ = 1, and more generally i^(4k+r) → i^r for literal integer
exponents (no branch-cut identities — √(−1) → i, log/exp of
complex arguments etc. are not added).
Differentiation treats it as a constant (d/dx i = 0, like π/e)
and numeric evaluation declines (it has no f64 value), matching the
behaviour of other non-real atoms.
Sourcepub fn is_imaginary_unit(&self, id: ExprId) -> bool
pub fn is_imaginary_unit(&self, id: ExprId) -> bool
Returns true iff id is the canonical imaginary unit produced by
ExprPool::imaginary_unit (an interned Domain::Complex symbol named
IMAGINARY_UNIT_NAME).
Sourcepub fn symbol_commutative(
&self,
name: impl Into<String>,
domain: Domain,
commutative: bool,
) -> ExprId
pub fn symbol_commutative( &self, name: impl Into<String>, domain: Domain, commutative: bool, ) -> ExprId
Free symbol with explicit commutative flag (V3-2). commutative: false is for
matrix or operator generators where A*B and B*A must remain distinct.
pub fn integer(&self, n: impl Into<Integer>) -> ExprId
pub fn rational( &self, numer: impl Into<Integer>, denom: impl Into<Integer>, ) -> ExprId
pub fn float(&self, value: f64, prec: u32) -> ExprId
pub fn add(&self, args: Vec<ExprId>) -> ExprId
pub fn mul(&self, args: Vec<ExprId>) -> ExprId
pub fn pow(&self, base: ExprId, exp: ExprId) -> ExprId
Sourcepub fn func(&self, name: impl Into<String>, args: Vec<ExprId>) -> ExprId
pub fn func(&self, name: impl Into<String>, args: Vec<ExprId>) -> ExprId
name(args…), unchecked.
The arity of a built-in name is not validated here — this is the
infallible constructor the library itself uses, always at the right
arity. Input from outside (a user, a parser, a file) should go through
ExprPool::try_func, which refuses sin() or EllipticPi(x).
Sourcepub fn try_func(
&self,
name: impl Into<String>,
args: Vec<ExprId>,
) -> Result<ExprId, FuncArityError>
pub fn try_func( &self, name: impl Into<String>, args: Vec<ExprId>, ) -> Result<ExprId, FuncArityError>
name(args…), refusing a built-in function name at the wrong arity
(see crate::kernel::func_arity::known_func_arity) with
FuncArityError (E-POOL-002).
Names outside the built-in table (user functions) take any arity.
Sourcepub fn piecewise(
&self,
branches: Vec<(ExprId, ExprId)>,
default: ExprId,
) -> ExprId
pub fn piecewise( &self, branches: Vec<(ExprId, ExprId)>, default: ExprId, ) -> ExprId
Build a Piecewise expression.
Branches are (cond, value) pairs where cond must be a
Predicate node. The default value is used when no condition
matches.
Sourcepub fn predicate(&self, kind: PredicateKind, args: Vec<ExprId>) -> ExprId
pub fn predicate(&self, kind: PredicateKind, args: Vec<ExprId>) -> ExprId
Build a Predicate node (symbolic boolean condition).
pub fn pred_lt(&self, a: ExprId, b: ExprId) -> ExprId
pub fn pred_le(&self, a: ExprId, b: ExprId) -> ExprId
pub fn pred_gt(&self, a: ExprId, b: ExprId) -> ExprId
pub fn pred_ge(&self, a: ExprId, b: ExprId) -> ExprId
pub fn pred_eq(&self, a: ExprId, b: ExprId) -> ExprId
pub fn pred_ne(&self, a: ExprId, b: ExprId) -> ExprId
pub fn pred_and(&self, args: Vec<ExprId>) -> ExprId
pub fn pred_or(&self, args: Vec<ExprId>) -> ExprId
pub fn pred_not(&self, a: ExprId) -> ExprId
pub fn pred_true(&self) -> ExprId
pub fn pred_false(&self) -> ExprId
Sourcepub fn root_sum(&self, poly: ExprId, var: ExprId, body: ExprId) -> ExprId
pub fn root_sum(&self, poly: ExprId, var: ExprId, body: ExprId) -> ExprId
Σ_{c : poly(c)=0} body[var := c] — a sum over the roots of poly.
Sourcepub fn big_o(&self, arg: ExprId) -> ExprId
pub fn big_o(&self, arg: ExprId) -> ExprId
O(arg) — symbolic big-O bound used in truncated series (V2-15).
Sourcepub fn pos_infinity(&self) -> ExprId
pub fn pos_infinity(&self) -> ExprId
Canonical +∞ symbol for limits at infinity (V2-16).
pub fn display(&self, id: ExprId) -> ExprDisplay<'_>
Source§impl ExprPool
impl ExprPool
Sourcepub fn checkpoint(&self, path: impl AsRef<Path>) -> Result<(), IoError>
pub fn checkpoint(&self, path: impl AsRef<Path>) -> Result<(), IoError>
V1-14 — write the current pool to path atomically. Equivalent to
save_to.
Sourcepub fn open_persistent(path: impl AsRef<Path>) -> Result<Self, IoError>
pub fn open_persistent(path: impl AsRef<Path>) -> Result<Self, IoError>
V1-14 — load a persisted pool, or return a fresh one if the file does
not exist. Equivalent to open_persistent.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ExprPool
impl RefUnwindSafe for ExprPool
impl Send for ExprPool
impl Sync for ExprPool
impl Unpin for ExprPool
impl UnsafeUnpin for ExprPool
impl UnwindSafe for ExprPool
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
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 more