Skip to content
Symi Docs
Swift
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#

Expression method

func isStale() -> 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#

Expression method

func add(other: UniffiExpression) -> UniffiExpression

subtract#

Expression method

func subtract(other: UniffiExpression) -> UniffiExpression

multiply#

Expression method

func multiply(other: UniffiExpression) -> UniffiExpression

divide#

Expression method

func divide(other: UniffiExpression) -> UniffiExpression

power#

Expression method

func power(exponent: UniffiExpression) -> UniffiExpression

negate#

Expression method

func negate() -> UniffiExpression

Substitution and structure#

substitute#

Expression method

func substitute(
    variable: UniffiExpression,
    value: UniffiExpression,
) -> UniffiExpression

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

rewrite_in_terms_of#

Explicit context

func rewriteInTermsOf(
    target: UniffiExpression,
    source: UniffiExpression,
    replacement: UniffiExpression,
) -> UniffiExpression
Calling forms

Expression method: UniffiExpression.rewriteInTermsOf

func rewriteInTermsOf(
    source: UniffiExpression,
    replacement: UniffiExpression,
) -> UniffiExpression

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#

Expression method

func freeVariables() -> [String]

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

expression_type#

Expression method

func expressionType() -> String

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#

Expression method

func nodeCount() -> UInt64

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

duplicate#

Expression method

func duplicate() -> UniffiExpression

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#

Expression method

func equals(other: UniffiExpression) -> Bool

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#

Expression method

func isMatrix() -> Bool

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

is_equality#

Expression method

func isEquality() -> Bool

True for equal(a, b) relation nodes.

is_integral#

Expression method

func isIntegral() -> Bool

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

is_union#

Expression method

func isUnion() -> Bool

is_image_set#

Expression method

func isImageSet() -> Bool

is_finite_set#

Expression method

func isFiniteSet() -> Bool

is_interval#

Expression method

func isInterval() -> Bool

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#

Expression method

func isReal() -> UniffiTruthValue

is_positive#

Expression method

func isPositive() -> UniffiTruthValue

is_negative#

Expression method

func isNegative() -> UniffiTruthValue

is_integer#

Expression method

func isInteger() -> UniffiTruthValue

is_rational#

Expression method

func isRational() -> UniffiTruthValue

is_nonzero#

Expression method

func isNonzero() -> UniffiTruthValue

is_nonnegative#

Expression method

func isNonnegative() -> UniffiTruthValue

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#

Expression method

func isFinite() -> UniffiTruthValue

is_defined#

Expression method

func isDefined() -> UniffiTruthValue

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#

Expression method

func intervalLower() -> UniffiExpression

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

interval_upper#

Expression method

func intervalUpper() -> UniffiExpression

integral_integrand#

Expression method

func integralIntegrand() -> UniffiExpression

integral_variable#

Expression method

func integralVariable() -> String

integral_lower_bound#

Expression method

func integralLowerBound() -> UniffiExpression?

None for indefinite integrals.

integral_upper_bound#

Expression method

func integralUpperBound() -> UniffiExpression?

union_components#

Expression method

func unionComponents() -> [UniffiExpression]

image_set_lambda_expression#

Expression method

func imageSetLambdaExpression() -> UniffiExpression

image_set_variable#

Expression method

func imageSetVariable() -> String

image_set_domain#

Expression method

func imageSetDomain() -> UniffiExpression

to_list#

Expression method

func toList() -> [UniffiExpression]

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#

Expression method

func symbolName() -> String

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

numerator_denominator#

Explicit context

func numeratorDenominator(target: UniffiExpression) -> UniffiExpressionExpressionTuple
Calling forms

Expression method: UniffiExpression.numeratorDenominator

func numeratorDenominator() -> UniffiExpressionExpressionTuple

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#

Explicit context

func numerator(target: UniffiExpression) -> UniffiExpression
Calling forms

Expression method: UniffiExpression.numerator

func numerator() -> UniffiExpression

Returns the structural numerator from numerator_denominator.

denominator#

Explicit context

func denominator(target: UniffiExpression) -> UniffiExpression
Calling forms

Expression method: UniffiExpression.denominator

func denominator() -> UniffiExpression

Returns the structural denominator from numerator_denominator.

Example#

is_nonpositive#

Expression method

func isNonpositive() -> UniffiTruthValue

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#

is_algebraic#

Expression method

func isAlgebraic() -> UniffiTruthValue

Provides the is_algebraic operation on this mobile object.

is_complex#

Expression method

func isComplex() -> UniffiTruthValue

Provides the is_complex operation on this mobile object.

is_composite#

Expression method

func isComposite() -> UniffiTruthValue

Provides the is_composite operation on this mobile object.

is_even#

Expression method

func isEven() -> UniffiTruthValue

Provides the is_even operation on this mobile object.

is_extended_real#

Expression method

func isExtendedReal() -> UniffiTruthValue

Provides the is_extended_real operation on this mobile object.

is_infinite#

Expression method

func isInfinite() -> UniffiTruthValue

Provides the is_infinite operation on this mobile object.

is_irrational#

Expression method

func isIrrational() -> UniffiTruthValue

Provides the is_irrational operation on this mobile object.

is_natural#

Expression method

func isNatural() -> UniffiTruthValue

Provides the is_natural operation on this mobile object.

is_odd#

Expression method

func isOdd() -> UniffiTruthValue

Provides the is_odd operation on this mobile object.

is_positive_integer#

Expression method

func isPositiveInteger() -> UniffiTruthValue

Provides the is_positive_integer operation on this mobile object.

is_transcendental#

Expression method

func isTranscendental() -> UniffiTruthValue

Provides the is_transcendental operation on this mobile object.

is_zero#

Expression method

func isZero() -> UniffiTruthValue

Provides the is_zero operation on this mobile object.

Symi documentation · Swift