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.BooleanReports 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): UniffiExpressionsubtract#
Expression method
fun subtract(other: UniffiExpression): UniffiExpressionmultiply#
Expression method
fun multiply(other: UniffiExpression): UniffiExpressiondivide#
Expression method
fun divide(other: UniffiExpression): UniffiExpressionpower#
Expression method
fun power(exponent: UniffiExpression): UniffiExpressionnegate#
Expression method
fun negate(): UniffiExpressionSubstitution and structure#
substitute#
Expression method
fun substitute(
variable: UniffiExpression,
value: UniffiExpression,
): UniffiExpressionReplace 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,
): UniffiExpressionCalling forms
Expression method: UniffiExpression.rewriteInTermsOf
fun rewriteInTermsOf(
source: UniffiExpression,
replacement: UniffiExpression,
): UniffiExpressionRewrite 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.StringTop-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.ULongNumber of nodes in the expression tree — the size measure used by the simplifier; useful for comparing alternative forms.
duplicate#
Expression method
fun duplicate(): UniffiExpressionAn 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.BooleanMathematical equality test: . A False result
means "could not prove equal", not a disproof.
Shape queries#
is_matrix#
Expression method
fun isMatrix(): kotlin.BooleanAlways False on expressions and True on Matrix objects, so mixed
result streams can be discriminated.
is_equality#
Expression method
fun isEquality(): kotlin.BooleanTrue for equal(a, b) relation nodes.
is_integral#
Expression method
fun isIntegral(): kotlin.BooleanTrue for unevaluated integral nodes. (Distinct from the assumption query
is_integer.)
is_union#
Expression method
fun isUnion(): kotlin.Booleanis_image_set#
Expression method
fun isImageSet(): kotlin.Booleanis_finite_set#
Expression method
fun isFiniteSet(): kotlin.Booleanis_interval#
Expression method
fun isInterval(): kotlin.BooleanAssumption 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(): UniffiTruthValueis_positive#
Expression method
fun isPositive(): UniffiTruthValueis_negative#
Expression method
fun isNegative(): UniffiTruthValueis_integer#
Expression method
fun isInteger(): UniffiTruthValueis_rational#
Expression method
fun isRational(): UniffiTruthValueis_nonzero#
Expression method
fun isNonzero(): UniffiTruthValueis_nonnegative#
Expression method
fun isNonnegative(): UniffiTruthValueAnswers 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(): UniffiTruthValueis_defined#
Expression method
fun isDefined(): UniffiTruthValueAnswers 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(): UniffiExpressionLower endpoint of an interval node; raises on other shapes.
interval_upper#
Expression method
fun intervalUpper(): UniffiExpressionintegral_integrand#
Expression method
fun integralIntegrand(): UniffiExpressionintegral_variable#
Expression method
fun integralVariable(): kotlin.Stringintegral_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(): UniffiExpressionimage_set_variable#
Expression method
fun imageSetVariable(): kotlin.Stringimage_set_domain#
Expression method
fun imageSetDomain(): UniffiExpressionto_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.StringReturns the name of a symbol expression and rejects every other expression kind.
numerator_denominator#
Explicit context
fun numeratorDenominator(target: UniffiExpression): UniffiExpressionExpressionTupleCalling forms
Expression method: UniffiExpression.numeratorDenominator
fun numeratorDenominator(): UniffiExpressionExpressionTupleReturns 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): UniffiExpressionReturns the structural numerator from numerator_denominator.
denominator#
Explicit context
fun denominator(target: UniffiExpression): UniffiExpressionReturns the structural denominator from numerator_denominator.
Example#
is_nonpositive#
Expression method
fun isNonpositive(): UniffiTruthValueWhether 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(): UniffiTruthValueProvides the is_algebraic operation on this mobile object.
is_complex#
Expression method
fun isComplex(): UniffiTruthValueProvides the is_complex operation on this mobile object.
is_composite#
Expression method
fun isComposite(): UniffiTruthValueProvides the is_composite operation on this mobile object.
is_even#
Expression method
fun isEven(): UniffiTruthValueProvides the is_even operation on this mobile object.
is_extended_real#
Expression method
fun isExtendedReal(): UniffiTruthValueProvides the is_extended_real operation on this mobile object.
is_infinite#
Expression method
fun isInfinite(): UniffiTruthValueProvides the is_infinite operation on this mobile object.
is_irrational#
Expression method
fun isIrrational(): UniffiTruthValueProvides the is_irrational operation on this mobile object.
is_natural#
Expression method
fun isNatural(): UniffiTruthValueProvides the is_natural operation on this mobile object.
is_odd#
Expression method
fun isOdd(): UniffiTruthValueProvides the is_odd operation on this mobile object.
is_positive_integer#
Expression method
fun isPositiveInteger(): UniffiTruthValueProvides the is_positive_integer operation on this mobile object.
is_transcendental#
Expression method
fun isTranscendental(): UniffiTruthValueProvides the is_transcendental operation on this mobile object.
is_zero#
Expression method
fun isZero(): UniffiTruthValueProvides the is_zero operation on this mobile object.