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

fun isStale(): kotlin.Boolean

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

fun add(other: UniffiExpression): UniffiExpression

subtract#

Expression method

fun subtract(other: UniffiExpression): UniffiExpression

multiply#

Expression method

fun multiply(other: UniffiExpression): UniffiExpression

divide#

Expression method

fun divide(other: UniffiExpression): UniffiExpression

power#

Expression method

fun power(exponent: UniffiExpression): UniffiExpression

negate#

Expression method

fun negate(): UniffiExpression

Substitution and structure#

substitute#

Expression method

fun 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

fun rewriteInTermsOf(
    target: UniffiExpression,
    source: UniffiExpression,
    replacement: UniffiExpression,
): UniffiExpression
Calling forms

Expression method: UniffiExpression.rewriteInTermsOf

fun 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

fun freeVariables(): List<kotlin.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

fun expressionType(): kotlin.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

fun nodeCount(): kotlin.ULong

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

duplicate#

Expression method

fun 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

fun equals(other: UniffiExpression): kotlin.Boolean

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

fun isMatrix(): kotlin.Boolean

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

is_equality#

Expression method

fun isEquality(): kotlin.Boolean

True for equal(a, b) relation nodes.

is_integral#

Expression method

fun isIntegral(): kotlin.Boolean

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

is_union#

Expression method

fun isUnion(): kotlin.Boolean

is_image_set#

Expression method

fun isImageSet(): kotlin.Boolean

is_finite_set#

Expression method

fun isFiniteSet(): kotlin.Boolean

is_interval#

Expression method

fun isInterval(): kotlin.Boolean

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

fun isReal(): UniffiTruthValue

is_positive#

Expression method

fun isPositive(): UniffiTruthValue

is_negative#

Expression method

fun isNegative(): UniffiTruthValue

is_integer#

Expression method

fun isInteger(): UniffiTruthValue

is_rational#

Expression method

fun isRational(): UniffiTruthValue

is_nonzero#

Expression method

fun isNonzero(): UniffiTruthValue

is_nonnegative#

Expression method

fun 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

fun isFinite(): UniffiTruthValue

is_defined#

Expression method

fun 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

fun intervalLower(): UniffiExpression

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

interval_upper#

Expression method

fun intervalUpper(): UniffiExpression

integral_integrand#

Expression method

fun integralIntegrand(): UniffiExpression

integral_variable#

Expression method

fun integralVariable(): kotlin.String

integral_lower_bound#

Expression method

fun integralLowerBound(): UniffiExpression?

None for indefinite integrals.

integral_upper_bound#

Expression method

fun integralUpperBound(): UniffiExpression?

union_components#

Expression method

fun unionComponents(): List<UniffiExpression>

image_set_lambda_expression#

Expression method

fun imageSetLambdaExpression(): UniffiExpression

image_set_variable#

Expression method

fun imageSetVariable(): kotlin.String

image_set_domain#

Expression method

fun imageSetDomain(): UniffiExpression

to_list#

Expression method

fun toList(): List<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

fun symbolName(): kotlin.String

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

numerator_denominator#

Explicit context

fun numeratorDenominator(target: UniffiExpression): UniffiExpressionExpressionTuple
Calling forms

Expression method: UniffiExpression.numeratorDenominator

fun 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

fun numerator(target: UniffiExpression): UniffiExpression
Calling forms

Expression method: UniffiExpression.numerator

fun numerator(): UniffiExpression

Returns the structural numerator from numerator_denominator.

denominator#

Explicit context

fun denominator(target: UniffiExpression): UniffiExpression
Calling forms

Expression method: UniffiExpression.denominator

fun denominator(): UniffiExpression

Returns the structural denominator from numerator_denominator.

Example#

is_nonpositive#

Expression method

fun 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

fun isAlgebraic(): UniffiTruthValue

Provides the is_algebraic operation on this mobile object.

is_complex#

Expression method

fun isComplex(): UniffiTruthValue

Provides the is_complex operation on this mobile object.

is_composite#

Expression method

fun isComposite(): UniffiTruthValue

Provides the is_composite operation on this mobile object.

is_even#

Expression method

fun isEven(): UniffiTruthValue

Provides the is_even operation on this mobile object.

is_extended_real#

Expression method

fun isExtendedReal(): UniffiTruthValue

Provides the is_extended_real operation on this mobile object.

is_infinite#

Expression method

fun isInfinite(): UniffiTruthValue

Provides the is_infinite operation on this mobile object.

is_irrational#

Expression method

fun isIrrational(): UniffiTruthValue

Provides the is_irrational operation on this mobile object.

is_natural#

Expression method

fun isNatural(): UniffiTruthValue

Provides the is_natural operation on this mobile object.

is_odd#

Expression method

fun isOdd(): UniffiTruthValue

Provides the is_odd operation on this mobile object.

is_positive_integer#

Expression method

fun isPositiveInteger(): UniffiTruthValue

Provides the is_positive_integer operation on this mobile object.

is_transcendental#

Expression method

fun isTranscendental(): UniffiTruthValue

Provides the is_transcendental operation on this mobile object.

is_zero#

Expression method

fun isZero(): UniffiTruthValue

Provides the is_zero operation on this mobile object.

Symi documentation · Kotlin