The default context and module-level functions
Every operation in Symi runs against a context — the symbol table, the
assumption records, and the hash-consed expression store. You can manage
contexts explicitly (see Construction and parsing), but
for everyday use the bindings provide a default context: a context created
automatically per thread (per module instance in WASM), shared by a set of
module-level functions that mirror the Context class methods one-for-one.
const raw = require("./pkg-node/symi_wasm.js");
const { createFacade } = require("./facade/symi.js");
const symi = createFacade(raw);
const x = symi.symbol("x");
console.log(symi.parse("x^2 + 2*x + 1").toString());
console.log(symi.pi.multiply(x.power(2)).toString());Rules of the model:
- One default context per thread. The Rust core is thread-safe and its
public types are
Send + Sync, but a default context is a convenience for a caller who did not make one, so each thread gets its own rather than sharing one implicitly. The Python classes are unsendable and WebAssembly is single-threaded today, so in those hosts objects never cross threads anyway. Objects made by module functions and bydefault_context()interoperate freely; objects from an explicitcontext()must not be mixed in (as ever, contexts do not mix). - Assumptions are per-name and session-wide.
symbol("x", positive=True)refines whatxmeans everywhere in the default context, retroactively. Refinement is monotonic: strengthening an unknown property is allowed, contradicting an earlier declaration raises an error.clear_assumptionsis the escape hatch; a freshcontext()gives full isolation. - Memory is bounded by live objects. The expression store holds weak
references: expressions you no longer hold are reclaimed automatically, so
there is no module-level
reset_contextand long sessions do not leak.interner_lengthreports the live count. - Structural constructors use the default context.
matrix,point_2d,segment_2d,polygon_2d,triangle_2d, andcircle_2dare both exported classes and default-context constructors: callMatrix([[x, y]])in Python orsymi.matrix([[x, y]])through the JavaScript facade. Their methods on an explicitContext()remain available for isolated construction.undefined_functionis a module-level factory in Python and on the raw WASM module (undefinedFunction); it has no class constructor.reset_contextis likewise context-only: resetting the shared default context would strand every live object, and the weak store removes the memory reason to do it. - Python
import *shadows builtins. The module exportsabs,min, andmax; useimport symi as scin code that also needs the Python builtins.
Functions#
default_context#
Not exposed by the WASM / JavaScript bindings. Available as module.default_context in Python, api::defaults::Session::default_context in Rust.
Return a handle to the thread's default context — the same context every module-level function and direct structural-class constructor uses. Pass it to code written against the explicit-context API. Each call returns a new handle to the same underlying context.
clear_assumptions#
Not exposed by the WASM / JavaScript bindings. Available as Context.clear_assumptions in Python, UniffiSession.clearAssumptions in Kotlin, UniffiSession.clearAssumptions in Swift, api::Session::clear_assumptions in Rust.
Reset one symbol's assumptions to the default (complex domain, every property unknown). This is the only sanctioned widening operation: it is explicit and per-symbol, and the symbol's identity is untouched, so existing expressions remain structurally valid. Use it when a monotonic-refinement conflict blocks a re-declaration you actually intend.
assumptions_of#
Not exposed by the WASM / JavaScript bindings. Available as Context.assumptions_of in Python, UniffiSession.assumptionsOf in Kotlin, UniffiSession.assumptionsOf in Swift, api::Session::assumptions_of in Rust.
Return the symbol's current assumptions as a native Python mapping or
JavaScript record with domain, positive, negative, nonzero, and
finite fields. The variable may be a name or same-context symbol. The domain
is one of complex, real, rational, integer, natural, or
positive_integer; truth-valued fields are yes, no, or unknown.
interner_length#
Not exposed by the WASM / JavaScript bindings. Available as Context.interner_length in Python, UniffiSession.internerLength in Kotlin, UniffiSession.internerLength in Swift, api::Session::interner_length in Rust.
Number of live expressions currently interned in the context. Dead entries awaiting the amortized sweep are not counted. Useful for observing memory in long-running sessions and in tests that assert the store stays bounded.
Example#
This family is not part of the recommended JavaScript facade in this release. Call it through the generated symi.raw layer, whose entries are listed with their wasm-bindgen signatures above, and read Migration for the ownership rules that apply there.
Additional API#
assumptionsOf#
Raw WebAssembly: Default context
assumptionsOf(name: string): stringReturn every assumption declared about one symbol, as a list of proposition texts such as "real(x)" or "prime(n)". The variable may be a name or same-context symbol. The list is what was declared, not what can be proved; use ask for a three-valued verdict.
Calling forms
Explicit context: Context.assumptionsOf
assumptionsOf(value: VariableLike): Record<string, string>Raw WebAssembly: Explicit context: Context.assumptionsOf
assumptionsOf(name: string): stringSymiFacade method: SymiFacade.assumptionsOf
assumptionsOf(value: VariableLike): Record<string, string>clearAssumptions#
Raw WebAssembly: Default context
clearAssumptions(name: string): voidReset one symbol's assumptions to the default (complex domain, every property unknown).
Calling forms
Raw WebAssembly: Explicit context: Context.clearAssumptions
clearAssumptions(name: string): voiddefaultContext#
Raw WebAssembly: Default context
defaultContext(): ContextReturn a handle to the thread's default context — the same context every module-level function and direct structural-class constructor uses. Use it for undefined_function, or to pass to code written against the explicit-context API. Each call returns a new handle to the same underlying context.
internerLength#
Raw WebAssembly: Default context
internerLength(): numberNumber of live expressions currently interned in the context. Dead entries awaiting the amortized sweep are not counted. Useful for observing memory in long-running sessions and in tests that assert the store stays bounded.