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