Skip to content
Symi Docs
Kotlin
On this page

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

fun expandComplex(inputExpression: UniffiExpression): UniffiExpression
Calling forms

Expression method: UniffiExpression.expandComplex

fun expandComplex(): UniffiExpression

Decompose 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

fun realPart(target: UniffiExpression): UniffiExpression
Calling forms

Expression method: UniffiExpression.realPart

fun realPart(): UniffiExpression

Return 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

fun imaginaryPart(target: UniffiExpression): UniffiExpression
Calling forms

Expression method: UniffiExpression.imaginaryPart

fun imaginaryPart(): UniffiExpression

Return 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

fun combinePowers(inputExpression: UniffiExpression): UniffiExpression
Calling forms

Expression method: UniffiExpression.combinePowers

fun combinePowers(): UniffiExpression

Combine 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

fun expandPowerBase(inputExpression: UniffiExpression): UniffiExpression
Calling forms

Expression method: UniffiExpression.expandPowerBase

fun expandPowerBase(): UniffiExpression

Split 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

fun denestPowers(inputExpression: UniffiExpression): UniffiExpression
Calling forms

Expression method: UniffiExpression.denestPowers

fun denestPowers(): UniffiExpression

Flatten 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

fun simplifyTrigonometric(target: UniffiExpression): UniffiExpression
Calling forms

Expression method: UniffiExpression.simplifyTrigonometric

fun simplifyTrigonometric(): UniffiExpression

Fu-style trigonometric simplification toward fewer/cheaper trig calls.

expand_trigonometric#

Explicit context

fun expandTrigonometric(target: UniffiExpression): UniffiExpression
Calling forms

Expression method: UniffiExpression.expandTrigonometric

fun expandTrigonometric(): UniffiExpression

Expand 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

fun combineTrigonometric(target: UniffiExpression): UniffiExpression
Calling forms

Expression method: UniffiExpression.combineTrigonometric

fun combineTrigonometric(): UniffiExpression

Inverse direction of expand_trigonometric: product-to-sum and angle-recombination rules.

combine_logarithm#

Explicit context

fun combineLogarithm(inputExpression: UniffiExpression): UniffiExpression
Calling forms

Expression method: UniffiExpression.combineLogarithm

fun combineLogarithm(): UniffiExpression

log⁡a+log⁡b→log⁡(ab)\log a + \log b \rightarrow \log(a b) and nlog⁡a→log⁡(an)n\log a \rightarrow \log(a^n) when the transformation preserves the expression's domain.

expand_logarithm#

Explicit context

fun expandLogarithm(inputExpression: UniffiExpression): UniffiExpression
Calling forms

Expression method: UniffiExpression.expandLogarithm

fun expandLogarithm(): UniffiExpression

log⁡(ab)→log⁡a+log⁡b\log(a b) \rightarrow \log a + \log b and log⁡(an)→nlog⁡a\log(a^n) \rightarrow n\log a, applied only where the operands are provably positive. Operands of unknown sign pass through unchanged.

rewrite_as_exponential#

Explicit context

fun rewriteAsExponential(inputExpression: UniffiExpression): UniffiExpression
Calling forms

Expression method: UniffiExpression.rewriteAsExponential

fun rewriteAsExponential(): UniffiExpression

Euler-form rewriter: replace every trigonometric/hyperbolic call with the equivalent complex-exponential expression (bottom-up).

rewrite_as_trigonometric#

Explicit context

fun rewriteAsTrigonometric(inputExpression: UniffiExpression): UniffiExpression
Calling forms

Expression method: UniffiExpression.rewriteAsTrigonometric

fun rewriteAsTrigonometric(): UniffiExpression

Inverse 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

fun rewriteTrigonometricBasis(
    target: UniffiExpression,
    basis: UniffiTrigonometricBasis,
): UniffiExpression
Calling forms

Expression method: UniffiExpression.rewriteTrigonometricBasis

fun rewriteTrigonometricBasis(basis: UniffiTrigonometricBasis): UniffiExpression

Rewrite 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.

Example#

Symi documentation · Kotlin