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

Sets

Sets are ordinary Expression values; constructors route through auto-simplification (degenerate intervals collapse, unions splice and deduplicate, etc.). Take results apart with the structural accessors on the expressions page.

interval#

api::sets::Session method

pub fn interval(
    &self,
    lower: &Expression,
    upper: &Expression,
    lower_inclusive: bool,
    upper_inclusive: bool,
) -> Result<Expression, ApiError>

Real-line interval. Closed by default; endpoints at infinity are forced open. Degenerate shapes collapse (empty interval →\to empty set, single point →\to finite set, (−∞,∞)→(-\infty, \infty)\to real line).

real_line#

api::Session method

pub fn real_line(&self) -> Expression

The set R\mathbb{R}.

complex_plane#

api::Session method

pub fn complex_plane(&self) -> Expression

The set C\mathbb{C} — the ambient universe, and the domain a variable ranges over when it carries no realness assumption.

integer_set#

api::Session method

pub fn integer_set(&self) -> Expression

The set Z\mathbb{Z}.

empty_set#

api::Session method

pub fn empty_set(&self) -> Expression

The empty set ∅\varnothing.

finite_set#

api::Session method

pub fn finite_set<IteratorType>(
    &self,
    elements: IteratorType,
) -> Result<Expression, ApiError>
where
    IteratorType: IntoIterator<Item = Expression>,

Finite set; elements are deduplicated and canonically ordered. An empty list gives the empty set.

set_union#

api::sets::Session method

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

Union, computed eagerly where the structural rules allow (overlapping or touching interval pairs merge; nested unions splice, ∅\varnothing drops, R\mathbb{R} absorbs); otherwise the structural set_union node.

set_intersection#

api::sets::Session method

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

Intersection, computed eagerly where the structural rules allow (interval pairs, finite-set membership filtering; R\mathbb{R} drops, ∅\varnothing absorbs); otherwise the structural set_intersection node.

set_complement#

api::sets::Session method

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

The relative complement a∖ba \setminus b.

image_set#

api::sets::Session method

pub fn image_set<'a, VariableType>(
    &self,
    lambda_expression: &Expression,
    variable: VariableType,
    domain: &Expression,
) -> Result<Expression, ApiError>
where
    VariableType: Into<VariableLike<'a>>,

The set {lambda_expression⁡:variable⁡∈domain⁡}\{\operatorname{lambda\_expression} : \operatorname{variable} \in \operatorname{domain}\}; variable is a binder over lambda_expression. Finite domains are enumerated element-wise at construction.

condition_set#

api::sets::Session method

pub fn condition_set<'a, VariableType>(
    &self,
    variable: VariableType,
    condition: &Expression,
    domain: &Expression,
) -> Result<Expression, ApiError>
where
    VariableType: Into<VariableLike<'a>>,

The set {variable⁡∈domain⁡:condition⁡}\{\operatorname{variable} \in \operatorname{domain} : \operatorname{condition}\}. This is also solveset's honest "unsolved" residue shape.

is_member#

api::sets::Session method

pub fn is_member(
    &self,
    element: &Expression,
    set: &Expression,
) -> Result<TruthValue, ApiError>
Calling forms

api::expression_operations::Expression method: api::expression_operations::Expression::is_member

pub fn is_member(
    &self,
    set: &Expression,
) -> Result<TruthValue, ApiError>

Three-valued membership: True only on structural proof, False only on a structural counterexample, None otherwise. Covers ∅\varnothing, R\mathbb{R}, finite sets, intervals, unions, intersections, complements.

is_subset#

api::sets::Session method

pub fn is_subset(
    &self,
    smaller: &Expression,
    larger: &Expression,
) -> Result<TruthValue, ApiError>

Three-valued subset query: ∅⊆\varnothing \subseteq anything, structural equality, finite-set element checks, interval-in-interval endpoint tests; None otherwise.

enumerate_set_in_interval#

api::sets::Session method

pub fn enumerate_set_in_interval(
    &self,
    set: &Expression,
    lower: &Expression,
    upper: &Expression,
    lower_inclusive: bool,
    upper_inclusive: bool,
    limit: Option<usize>,
) -> Result<SetEnumeration, ApiError>

Exact elements of a set inside [lower⁡,upper⁡][\operatorname{lower}, \operatorname{upper}], in increasing order, as {"outcome": str, "elements": list[Expression]}. outcome is "complete" when those are exactly the elements in the interval, "truncated" when limit cut the list short (the family is still solved), and "declined" when the set's shape is not enumerable — never a licence to approximate. Handles finite sets, affine image sets over Z\mathbb{Z}, unions, complements, and the unevaluated set_intersection(interval, image_set) shape solveset_in_domain returns for a lattice too wide to materialize. limit defaults to 64. WASM returns a SetEnumeration object with outcome and elements getters.

Example#

Set construction and membership over exact elements.

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

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let session = Session::new();
    let elements = session.finite_set([
        session.integer(1),
        session.integer(2),
        session.integer(3),
    ])?;

    println!("{}", elements);
    println!("{}", session.parse("x^2 - 2")?.solve_as_set(&session.symbol("x"))?);
    Ok(())
}

Additional API#

length#

api::expression_operations::Expression method

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

The number of elements of a finite-set expression.

api::sets#

api module

pub mod sets;

Set construction and query operations of the native API.

DEFAULT_ENUMERATION_LIMIT#

api::sets constant

pub const DEFAULT_ENUMERATION_LIMIT: usize = crate::sets::enumerate::DEFAULT_ENUMERATION_LIMIT;

The default ceiling on how many elements one set enumeration produces.

EnumerationVerdict#

api re_export

pub use results::EnumerationVerdict;

How far a set enumeration got.

Calling forms

Type: api::results::EnumerationVerdict

pub enum EnumerationVerdict

EnumerationVerdict.Complete#

api::results::EnumerationVerdict variant

Complete,

Every element inside the interval was produced.

EnumerationVerdict.Declined#

api::results::EnumerationVerdict variant

Declined,

The set's shape is not enumerable by this procedure.

EnumerationVerdict.Truncated#

api::results::EnumerationVerdict variant

Truncated,

The requested limit was reached and more elements remain.

EnumerationVerdict.name#

api::results::EnumerationVerdict method

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

The stable lowercase spelling shared by every binding.

SetEnumeration#

api re_export

pub use results::SetEnumeration;

The elements a set enumeration produced inside an interval.

Calling forms

Type: api::results::SetEnumeration

pub struct SetEnumeration

SetEnumeration.elements#

api::results::SetEnumeration method

pub fn elements(&self) -> Vec<Expression>

The enumerated elements in increasing order.

SetEnumeration.outcome#

api::results::SetEnumeration method

pub fn outcome(&self) -> EnumerationVerdict

Whether the enumeration is complete, truncated, or declined.