Trigonometric and complex rewrites
Trigonometric, logarithmic, exponential, and complex rewrites are separated from general simplification because their identities depend on domains and branch behavior.
expand_complex#
Explicit context
func expandComplex(inputExpression: UniffiExpression) -> UniffiExpressionCalling forms
Expression method: UniffiExpression.expandComplex
func expandComplex() -> UniffiExpressionDecompose an expression exactly as real_part(expression) + i*imaginary_part(expression).
Products, integer powers, and exp, sin, cos, sinh, and cosh are expanded through
their Cartesian identities. Symbol assumptions determine which atoms are real. Unknown atoms
and branch-sensitive operations such as logarithms and non-integer powers remain represented by
symbolic real- and imaginary-part calls. The directed operation also expands a supported modulus
under real assumptions: abs(x + i*y) becomes sqrt(x^2 + y^2), and exact integer powers under
the modulus preserve their original poles while expanding the Cartesian norm. Oversized or
unsupported modulus arguments remain unchanged or wrapper-bearing.
real_part#
Explicit context
func realPart(target: UniffiExpression) -> UniffiExpressionReturn the exact real component of an expression. For example, if y is declared real,
real_part(exp(i*y)) is cos(y). An atom whose reality is unknown returns a symbolic
real_part(atom) call. The returned expression is always known to be real.
imaginary_part#
Explicit context
func imaginaryPart(target: UniffiExpression) -> UniffiExpressionCalling forms
Expression method: UniffiExpression.imaginaryPart
func imaginaryPart() -> UniffiExpressionReturn the exact imaginary component of an expression. For example, if y is declared real,
imaginary_part(exp(i*y)) is sin(y). An atom whose reality is unknown returns a symbolic
imaginary_part(atom) call. The returned expression is always known to be real.
combine_powers#
Explicit context
func combinePowers(inputExpression: UniffiExpression) -> UniffiExpressionCalling forms
Expression method: UniffiExpression.combinePowers
func combinePowers() -> UniffiExpressionCombine same-exponent powers into a single power of the merged base
(x^a * y^a -> (x*y)^a) at every product node where the rewrite is provably
valid. This identity is false across the branch cut of the complex logarithm —
at x = y = -1 and a = 1/2 the left side is i*i = -1 while the right side
is sqrt(1) = 1 — so it fires only when the exponent is provably an integer or
when every combined base is provably positive. Positivity of the merged base
is not enough: (-2)^x * (-3)^x is left alone, because at x = 1/2 combining it
to 6^x would flip the sign of the result. Positive numeric-literal bases need
no assumptions at all, so 2^x * 3^x becomes 6^x and (1/2)^x * 3^x becomes
(3/2)^x. With n declared an integer, x^n * y^n becomes (x*y)^n; the
exponent gate recurses structurally, so a compound exponent like 2*n gates the
same way. There is no force mode: a site whose gate is not provable is left
unchanged, and an expression with no provable site is returned as-is.
expand_power_base#
Explicit context
func expandPowerBase(inputExpression: UniffiExpression) -> UniffiExpressionCalling forms
Expression method: UniffiExpression.expandPowerBase
func expandPowerBase() -> UniffiExpressionSplit a power whose base is structurally a product into a product of powers
((x*y)^a -> x^a * y^a) at every power node whose exponent is provably an
integer — the only unconditionally valid gate for this direction, since the split
introduces x^a and y^a individually and each needs its own base off the cut.
With n declared an integer, (x*y)^n becomes x^n * y^n. Kahan's example
(x*y)^(1/2) over unconstrained x, y is left unchanged, as is any other
unprovable site; there is no force mode. A base that is not structurally a
product is never decomposed, so 6^x is not split into 2^x * 3^x.
denest_powers#
Explicit context
func denestPowers(inputExpression: UniffiExpression) -> UniffiExpressionCalling forms
Expression method: UniffiExpression.denestPowers
func denestPowers() -> UniffiExpressionFlatten a power of a power into a single power ((x^a)^b -> x^(a*b)) at every
power node whose outer exponent is provably an integer, which is valid on the
principal branch because an integer power never routes through log. With n
declared an integer, (x^a)^n becomes x^(a*n). A fractional outer exponent is
left unchanged — ((-1)^2)^(1/2) is 1 while (-1)^(2*(1/2)) is -1 — and
there is no force mode. A base that is not structurally a power is untouched.
simplify_trigonometric#
Explicit context
func simplifyTrigonometric(target: UniffiExpression) -> UniffiExpressionCalling forms
Expression method: UniffiExpression.simplifyTrigonometric
func simplifyTrigonometric() -> UniffiExpressionFu-style trigonometric simplification toward fewer/cheaper trig calls.
expand_trigonometric#
Explicit context
func expandTrigonometric(target: UniffiExpression) -> UniffiExpressionCalling forms
Expression method: UniffiExpression.expandTrigonometric
func expandTrigonometric() -> UniffiExpressionExpand trig/hyperbolic functions of sums and positive integer literal multiple angles. The directed operation may increase expression size; unsupported, symbolic, noninteger, or over-budget multipliers remain unchanged. A successful expansion is structurally idempotent, and recursively admitted sums are expanded in the same pass.
combine_trigonometric#
Explicit context
func combineTrigonometric(target: UniffiExpression) -> UniffiExpressionCalling forms
Expression method: UniffiExpression.combineTrigonometric
func combineTrigonometric() -> UniffiExpressionInverse direction of expand_trigonometric: product-to-sum and
angle-recombination rules.
combine_logarithm#
Explicit context
func combineLogarithm(inputExpression: UniffiExpression) -> UniffiExpressionCalling forms
Expression method: UniffiExpression.combineLogarithm
func combineLogarithm() -> UniffiExpressionand when the transformation preserves the expression's domain.
expand_logarithm#
Explicit context
func expandLogarithm(inputExpression: UniffiExpression) -> UniffiExpressionCalling forms
Expression method: UniffiExpression.expandLogarithm
func expandLogarithm() -> UniffiExpressionand , applied only where the operands are provably positive. Operands of unknown sign pass through unchanged.
rewrite_as_exponential#
Explicit context
func rewriteAsExponential(inputExpression: UniffiExpression) -> UniffiExpressionCalling forms
Expression method: UniffiExpression.rewriteAsExponential
func rewriteAsExponential() -> UniffiExpressionEuler-form rewriter: replace every trigonometric/hyperbolic call with the equivalent complex-exponential expression (bottom-up).
rewrite_as_trigonometric#
Explicit context
func rewriteAsTrigonometric(inputExpression: UniffiExpression) -> UniffiExpressionCalling forms
Expression method: UniffiExpression.rewriteAsTrigonometric
func rewriteAsTrigonometric() -> UniffiExpressionInverse of rewrite_as_exponential. Recognition is shape-strict: canonical
Euler forms collapse back to trig/hyperbolic calls, anything else passes
through unchanged, so the round trip is the identity.
rewrite_trigonometric_basis#
Explicit context
func rewriteTrigonometricBasis(
target: UniffiExpression,
basis: UniffiTrigonometricBasis,
) -> UniffiExpressionCalling forms
Expression method: UniffiExpression.rewriteTrigonometricBasis
func rewriteTrigonometricBasis(basis: UniffiTrigonometricBasis) -> UniffiExpressionRewrite trigonometric and hyperbolic calls toward one of five named bases:
sine_cosine, tangent, exponential, trigonometric, or hyperbolic.
The sine/cosine basis maps tan(x) to sin(x)/cos(x) and reciprocal calls to
reciprocal powers; the tangent basis recognizes existing exact quotients such
as sin(x)/cos(x) but leaves a bare sin(x) unchanged; the exponential basis
maps sin(x) to its Euler form; the trigonometric basis recognizes those
canonical Euler forms; and the hyperbolic basis maps explicit imaginary
arguments such as sin(i*x) to i*sinh(x). Only identities with the same
singularities on the whole complex domain are offered. In particular, the
half-angle rewrite of a bare sine into tangent is excluded because it introduces
undefined points. An unknown basis name is an error, and nodes without a valid
rewrite are returned unchanged.