Skip to content
Symi Docs
Rust

The Rust manual covers the recommended facade. The complete native crate is documented in the native Rust API reference.

On this page

Expression methods

Single-subject operations (transforms, calculus, solving, output) are also available directly as methods on Expression — e.simplify(), e.integrate("x"), e.solve("x"), e.to_latex(), … — delegating to the context the expression belongs to. The entries in the operation chapters document parameters and semantics; the method form drops the leading expression argument. Exact input conversion and context ownership are specified in Conversions and collections and Context safety.

is_stale#

api::Expression method

pub fn is_stale(&self) -> bool
Calling forms and variants

Variant using local assumptions — api::AssumptionScope method: api::AssumptionScope::is_stale

pub fn is_stale(&self) -> bool

Reports whether resetting the owning context invalidated the expression. All other operations reject a stale receiver with an actionable error.

Arithmetic#

Python uses the native operators + - * / ** -; operands may be expressions, integers, or exact fractions. JavaScript uses the equivalent named methods and accepts facade expressions, bigint, and safe integral number values. All route through the auto-simplifying builders.

add#

api::Session method

pub fn add(
    &self,
    left: &Expression,
    right: &Expression,
) -> Result<Expression, ApiError>
Calling forms

api::Expression method: api::Expression::add

pub fn add(&self, other: &Expression) -> Result<Expression, ApiError>

subtract#

api::Session method

pub fn subtract(
    &self,
    left: &Expression,
    right: &Expression,
) -> Result<Expression, ApiError>
Calling forms

api::Expression method: api::Expression::subtract

pub fn subtract(
    &self,
    other: &Expression,
) -> Result<Expression, ApiError>

multiply#

api::Session method

pub fn multiply(
    &self,
    left: &Expression,
    right: &Expression,
) -> Result<Expression, ApiError>
Calling forms

api::Expression method: api::Expression::multiply

pub fn multiply(
    &self,
    other: &Expression,
) -> Result<Expression, ApiError>

divide#

api::Session method

pub fn divide(
    &self,
    numerator: &Expression,
    denominator: &Expression,
) -> Result<Expression, ApiError>
Calling forms

api::Expression method: api::Expression::divide

pub fn divide(&self, other: &Expression) -> Result<Expression, ApiError>

power#

api::Session method

pub fn power(
    &self,
    base: &Expression,
    exponent: &Expression,
) -> Result<Expression, ApiError>
Calling forms

api::Expression method: api::Expression::power

pub fn power(
    &self,
    exponent: &Expression,
) -> Result<Expression, ApiError>

negate#

api::Expression method

pub fn negate(&self) -> Result<Expression, ApiError>

Substitution and structure#

substitute#

api::Session method

pub fn substitute(
    &self,
    target: &Expression,
    variable: &Expression,
    value: &Expression,
) -> Result<Expression, ApiError>
Calling forms

api::Expression method: api::Expression::substitute

pub fn substitute(
    &self,
    variable: &Expression,
    value: &Expression,
) -> Result<Expression, ApiError>

Replace every free occurrence of the named symbol with value, re-running auto-simplification.

rewrite_in_terms_of#

api::algebra::Session method

pub fn rewrite_in_terms_of(
    &self,
    target: &Expression,
    source: &Expression,
    replacement: &Expression,
) -> Result<Expression, ApiError>
Calling forms

api::expression_operations::Expression method: api::expression_operations::Expression::rewrite_in_terms_of

pub fn rewrite_in_terms_of(
    &self,
    source: &Expression,
    replacement: &Expression,
) -> Result<Expression, ApiError>

Rewrite the target in terms of replacement under the caller-supplied formal relation replacement = source. Exact subtrees, canonical additive and multiplicative extractions, integer exponential families, and positive same-base power families are supported. Every inferred match is accepted only when substituting source back exactly reconstructs the matched target. Fractional exponential relations and branch-sensitive power identities conservatively remain unchanged. To introduce a displayed name such as z, pass symbol("z") as replacement; assigning the source expression to a host-language variable named z does not create a symbolic name.

free_variables#

api::Expression method

pub fn free_variables(&self) -> Result<Vec<String>, ApiError>

Sorted names of the free symbols. Bound binders (integration variables, image-set parameters) are excluded; the constants pi/e are not symbols.

expression_type#

api::expression_operations::Expression method

pub fn expression_type(&self) -> Result<ExpressionTypeName, ApiError>

Top-level node kind: one of integer, rational, symbol, constant, sum, product, power, factorial, function_call, derivative, integral, summation, laplace_transform, inverse_laplace_transform, fourier_transform, inverse_fourier_transform, piecewise, ordinary_differential_equation, recurrence_equation, interval, finite_set, set_union, set_intersection, set_complement, image_set, condition_set.

node_count#

api::Expression method

pub fn node_count(&self) -> Result<usize, ApiError>

Number of nodes in the expression tree — the size measure used by the simplifier; useful for comparing alternative forms.

duplicate#

api::Expression method

pub fn duplicate(&self) -> Result<Expression, ApiError>

An independent handle to the same underlying expression. The recommended JavaScript facade duplicates values before passing them through ownership-transferring raw WASM arrays, so ordinary facade calls are non-destructive. Callers using facade.raw directly must still duplicate a handle they intend to retain. Python arguments are borrowed.

Equality#

equals#

api::expression_operations::Expression method

pub fn equals(&self, other: &Expression) -> Result<bool, ApiError>

Mathematical equality test: simplify⁡(self⁡−other⁡)=0\operatorname{simplify}(\operatorname{self} - \operatorname{other}) = 0. A False result means "could not prove equal", not a disproof.

Shape queries#

is_matrix#

api::Expression method

pub fn is_matrix(&self) -> Result<bool, ApiError>

Always False on expressions and True on Matrix objects, so mixed result streams can be discriminated.

is_equality#

api::Expression method

pub fn is_equality(&self) -> Result<bool, ApiError>

True for equal(a, b) relation nodes.

is_integral#

api::Expression method

pub fn is_integral(&self) -> Result<bool, ApiError>

True for unevaluated integral nodes. (Distinct from the assumption query is_integer.)

is_union#

api::Expression method

pub fn is_union(&self) -> Result<bool, ApiError>

is_image_set#

api::Expression method

pub fn is_image_set(&self) -> Result<bool, ApiError>

is_finite_set#

api::Expression method

pub fn is_finite_set(&self) -> Result<bool, ApiError>

is_interval#

api::Expression method

pub fn is_interval(&self) -> Result<bool, ApiError>

Assumption queries (three-valued)#

All return True/False/None (undefined in JS): a definite verdict only on proof from the structure and the symbol assumptions.

is_real#

api::Expression method

pub fn is_real(&self) -> Result<TruthValue, ApiError>

is_positive#

api::Expression method

pub fn is_positive(&self) -> Result<TruthValue, ApiError>

is_negative#

api::Expression method

pub fn is_negative(&self) -> Result<TruthValue, ApiError>

is_integer#

api::Expression method

pub fn is_integer(&self) -> Result<TruthValue, ApiError>

is_rational#

api::Expression method

pub fn is_rational(&self) -> Result<TruthValue, ApiError>

is_nonzero#

api::Expression method

pub fn is_nonzero(&self) -> Result<TruthValue, ApiError>

is_nonnegative#

api::Session method

pub fn is_nonnegative(
    &self,
    target: &Expression,
) -> Result<TruthValue, ApiError>
Calling forms

api::Expression method: api::Expression::is_nonnegative

pub fn is_nonnegative(&self) -> Result<TruthValue, ApiError>

Answers True only on proof that the expression is greater than or equal to zero — an even power of a provably real base, a sum or product of such, or anything already provably positive. It never answers False: a failure to prove non-negativity is not a proof of negativity, so the undecided verdict is None.

is_finite#

api::Expression method

pub fn is_finite(&self) -> Result<TruthValue, ApiError>

is_defined#

api::Expression method

pub fn is_defined(&self) -> Result<TruthValue, ApiError>

Answers True only on proof that the expression denotes one scalar value at the active point, and False only on proof that it denotes none — a zero denominator, a zero logarithm argument, or a proved indeterminate extended-value combination. Definedness is pointwise: it says nothing about continuity or analyticity near the point, and a point on a chosen principal branch cut such as log(-1) is defined even though the principal logarithm is discontinuous there. The signed infinities are defined extended-real values but are not finite.

Structural accessors#

interval_lower#

api::Expression method

pub fn interval_lower(&self) -> Result<Expression, ApiError>

Lower endpoint of an interval node; raises on other shapes.

interval_upper#

api::Expression method

pub fn interval_upper(&self) -> Result<Expression, ApiError>

integral_integrand#

api::Expression method

pub fn integral_integrand(&self) -> Result<Expression, ApiError>

integral_variable#

api::Expression method

pub fn integral_variable(&self) -> Result<String, ApiError>

integral_lower_bound#

api::Expression method

pub fn integral_lower_bound(
    &self,
) -> Result<Option<Expression>, ApiError>

None for indefinite integrals.

integral_upper_bound#

api::Expression method

pub fn integral_upper_bound(
    &self,
) -> Result<Option<Expression>, ApiError>

union_components#

api::Expression method

pub fn union_components(&self) -> Result<Vec<Expression>, ApiError>

image_set_lambda_expression#

api::Expression method

pub fn image_set_lambda_expression(
    &self,
) -> Result<Expression, ApiError>

image_set_variable#

api::Expression method

pub fn image_set_variable(&self) -> Result<String, ApiError>

image_set_domain#

api::Expression method

pub fn image_set_domain(&self) -> Result<Expression, ApiError>

to_list#

api::Expression method

pub fn to_list(&self) -> Result<Vec<Expression>, ApiError>

Elements of a finite set; raises on other shapes. Python finite sets also support len() and iteration.

length#

Element count of a finite set (Python: len(expression)).

String conversion#

to_string#

Human-readable form; Python uses str(expression) / repr(expression).

symbol_name#

api::Expression method

pub fn symbol_name(&self) -> Result<String, ApiError>

Returns the name of a symbol expression and rejects every other expression kind.

numerator_denominator#

api::Session method

pub fn numerator_denominator(
    &self,
    target: &Expression,
) -> Result<(Expression, Expression), ApiError>
Calling forms

api::Expression method: api::Expression::numerator_denominator

pub fn numerator_denominator(
    &self,
) -> Result<(Expression, Expression), ApiError>

Returns the exact structural numerator and denominator without combining sums or cancelling factors. Python returns a two-tuple and the JavaScript facade returns a record.

numerator#

api::Session method

pub fn numerator(
    &self,
    target: &Expression,
) -> Result<Expression, ApiError>
Calling forms

api::Expression method: api::Expression::numerator

pub fn numerator(&self) -> Result<Expression, ApiError>

Returns the structural numerator from numerator_denominator.

denominator#

api::Session method

pub fn denominator(
    &self,
    target: &Expression,
) -> Result<Expression, ApiError>
Calling forms

api::Expression method: api::Expression::denominator

pub fn denominator(&self) -> Result<Expression, ApiError>

Returns the structural denominator from numerator_denominator.

Example#

Inspect and rewrite an expression through its own methods.

Rust
use symi::api::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let session = Session::new();
    let x = session.symbol("x");
    let target = session.parse("(x^2 - 1)/(x + 1)")?;

    println!("{}", target.cancel()?);
    println!("{}", target.numerator()?);
    println!("{}", target.substitute(&x, &session.integer(3))?.execute()?);
    Ok(())
}

is_nonpositive#

api::Session method

pub fn is_nonpositive(
    &self,
    target: &Expression,
) -> Result<TruthValue, ApiError>
Calling forms

api::Expression method: api::Expression::is_nonpositive

pub fn is_nonpositive(&self) -> Result<TruthValue, ApiError>

Whether the expression is known to be nonpositive. Three-valued, like the other sign predicates on this page: None means the sign was not decided from the assumptions in force, not that the expression is positive. Compare is_nonnegative.

Additional API#

Expression#

Type

pub struct Expression

Public native data structure named expression.

api::expression_operations#

api module

pub mod expression_operations;

Receiver-shaped expression operations of the native API.

is_algebraic#

api::Expression method

pub fn is_algebraic(&self) -> Result<TruthValue, ApiError>

Query whether this expression is algebraic.

is_complex#

api::Expression method

pub fn is_complex(&self) -> Result<TruthValue, ApiError>

Query whether this expression is finite complex.

is_composite#

api::Expression method

pub fn is_composite(&self) -> Result<TruthValue, ApiError>

Query whether this expression is composite.

is_even#

api::Expression method

pub fn is_even(&self) -> Result<TruthValue, ApiError>

Query whether this expression is even.

is_extended_real#

api::Expression method

pub fn is_extended_real(&self) -> Result<TruthValue, ApiError>

Query whether this expression is extended-real.

is_infinite#

api::Expression method

pub fn is_infinite(&self) -> Result<TruthValue, ApiError>

Query whether this expression is infinite.

is_irrational#

api::Expression method

pub fn is_irrational(&self) -> Result<TruthValue, ApiError>

Query whether this expression is irrational.

is_natural#

api::Expression method

pub fn is_natural(&self) -> Result<TruthValue, ApiError>

Query whether this expression is natural.

is_odd#

api::Expression method

pub fn is_odd(&self) -> Result<TruthValue, ApiError>

Query whether this expression is odd.

is_positive_integer#

api::Expression method

pub fn is_positive_integer(&self) -> Result<TruthValue, ApiError>

Query whether this expression is a positive integer.

is_transcendental#

api::Expression method

pub fn is_transcendental(&self) -> Result<TruthValue, ApiError>

Query whether this expression is transcendental.

is_zero#

api::Expression method

pub fn is_zero(&self) -> Result<TruthValue, ApiError>

Query whether this expression is zero.

structural_hash#

api::Expression method

pub fn structural_hash(&self) -> u64

Provides the structural_hash operation on this native type.

ExpressionGraphMeasurements#

api re_export

pub use crate::operation::ExpressionGraphMeasurements;

The shape of one expression graph an operation was handed.

ExpressionTypeName#

Type

pub struct ExpressionTypeName(&'static str);

The structural kind of an expression node.

ExpressionTypeName.name#

api::expression_operations::ExpressionTypeName method

pub fn name(&self) -> &'static str

The stable lowercase spelling shared by every binding.

NumeratorDenominator#

api re_export

pub use results::NumeratorDenominator;

The numerator and denominator of a structural quotient split.

Calling forms

Type: api::results::NumeratorDenominator

pub struct NumeratorDenominator

NumeratorDenominator.denominator#

api::results::NumeratorDenominator method

pub fn denominator(&self) -> Expression

The denominator factor.

NumeratorDenominator.numerator#

api::results::NumeratorDenominator method

pub fn numerator(&self) -> Expression

The numerator factor.