Calculus
Calculus follows a uniform construct-versus-evaluate model; the summary table
is in Evaluation and constants. Every variable
parameter accepts a name or a same-context symbol expression.
Each operation below is one entry with its receivers listed together: the
default context, an explicit context, and — where the operation takes an
expression — the expression itself all reach the same operation, and an
assumption scope reaches it under the assumptions that scope adds. The
collapsed calling forms block on each entry gives the exact signature of
each.
Three tasks are spelled differentiate or derivative, and they are not
interchangeable:
differentiate#
Explicit context
fun differentiate(
target: UniffiExpression,
variable: kotlin.String,
): UniffiExpression
Calling forms
Expression method: UniffiExpression.differentiate
fun differentiate(variable: kotlin.String): UniffiExpression
Symbolic derivative with respect to variable, evaluated now. The derivative is
total: unknown function calls produce derivative nodes.
The derivative is formal: each rule is applied without checking where it holds.
abs(x) differentiates to signum(x), signum(x) to 0, and a piecewise
expression branch by branch with its conditions unchanged. The result is the
derivative only where the expression is differentiable, so a finite value of it
at x = 0 for abs(x), at the switch of a step function, or on a branch cut is
not evidence that a derivative exists there.
integrate#
Explicit context
fun integrate(
target: UniffiExpression,
variable: kotlin.String,
): UniffiExpression
Calling forms and variants
Expression method: UniffiExpression.integrate
fun integrate(variable: kotlin.String): UniffiExpression
Variant using local assumptions — UniffiAssumptionScope method: UniffiAssumptionScope.integrate
fun integrate(
target: UniffiExpression,
variable: kotlin.String,
): UniffiExpression
Indefinite integration (no constant of integration). The variant on an
assumption scope runs the same integration
under that scope's captured assumptions, which can close a branch the durable
context leaves open; the scope is immutable and the owning context is
unchanged. When every symbolic
strategy fails, the result is an unevaluated integral node, never a
guess. Real symbolic parameters can produce a piecewise antiderivative
whose conditions describe the supported parameter strata. A parameter value
outside every branch is undefined rather than a hidden declined branch.
integrate_definite#
Explicit context
fun integrateDefinite(
inputExpression: UniffiExpression,
variable: kotlin.String,
lower: UniffiExpression,
upper: UniffiExpression,
): UniffiExpression
Calling forms and variants
Expression method: UniffiExpression.integrateDefinite
fun integrateDefinite(
variable: kotlin.String,
lower: UniffiExpression,
upper: UniffiExpression,
): UniffiExpression
Variant using local assumptions — UniffiAssumptionScope method: UniffiAssumptionScope.integrateDefinite
fun integrateDefinite(
target: UniffiExpression,
variable: kotlin.String,
lowerBound: UniffiExpression,
upperBound: UniffiExpression,
): UniffiExpression
Definite integration over [lower, upper] (bounds may be infinite). Falls
back to an unevaluated bounded integral node when no exact evaluation
exists. For supported real radicals, absolute values, and explicit piecewise
expressions, the evaluator forms an exact ordered partition at domain, zero,
pole, and branch boundaries. It integrates the selected formula on each open
cell and accepts it only after an exact derivative residual check. Singular
or excluded endpoints are evaluated by the appropriate one-sided limit.
Reversed bounds negate the forward integral. A closed primitive that jumps
only because of its representation, such as the pole of arctan(1/(1 - x))
or a principal logarithm of a complex affine argument crossing its cut, is
not split there: the exact jump is subtracted, and a jump that cannot be
placed exactly declines. Several standard families are evaluated without a
primitive: ∫0∞xs−1/(1+cxn)mdx through the Beta
function, even rational functions on the half-line as half their residue sum,
∫0∞xs−1/(ebx∓1)dx=Γ(s)ζ(s)b−s and
Γ(s)η(s)b−s, and log(csinx) or log(ccosx) over whole
quarter periods where the factor is nonnegative; each applies only after its
convergence hypotheses are proved. log(1 + c x)/x integrates to
-polylogarithm(2, -c x), and a definite integral whose interval would take
the polylogarithm across its cut declines. The operation uses ordinary
improper-integral semantics and never infers a Cauchy principal value; an
undecidable order, sign, domain, branch, or limit makes the whole route
decline atomically. Use integrate_definite_detailed when a proved
divergence, a principal value, or a declared parameter region matters.
integrate_definite_detailed#
Explicit context
fun integrateDefiniteDetailed(
target: UniffiExpression,
variable: kotlin.String,
lowerBound: UniffiExpression,
upperBound: UniffiExpression,
interpretation: UniffiDefiniteIntegrationInterpretation,
constraint: UniffiExpression?,
): UniffiDefiniteIntegrationResult
Definite integration that keeps its verdict distinct from its value, so a
proved divergence is never confused with a declined request. interpretation
is ordinary (every one-sided improper contribution must converge
independently) or cauchy_principal_value (an independent symmetric
exclusion about each finite interior singularity, and a symmetric truncation
of a whole-line request; a singular finite bound or a single infinite bound
stays an ordinary limit). Divergence is proved from the integrand itself: at
each singular point and each infinite bound a certified leading power and
logarithm term is compared with the integrable threshold, so no closed
antiderivative is needed. A principal value is taken as the limit of one
grouped truncated expression per cutoff, never as a difference of separately
divergent halves. An undecided bound order, an incomplete singular set, or an
unsettled limit declines with a typed reason. constraint is a logical
expression on the parameters that holds throughout the request and reaches
every strategy; a malformed or contradictory constraint is an error. WASM
takes interpretation and constraint as optional arguments, and a
constraint handle is taken by value. Kotlin and Swift take the interpretation
as a typed enumeration.
DefiniteIntegrationResult#
What integrate_definite_detailed returns. It keeps the verdict separate from
the value, so a proved divergence is never read as a declined request, and a
declined request never as a proved answer. Its members are:
Each member's exact host type and spelling follows below.
UniffiDefiniteIntegrationResult method
fun declineReason(): UniffiDefiniteIntegrationDeclineReason?
The reason, present exactly when the verdict is declined.
UniffiDefiniteIntegrationResult method
fun divergenceDirection(): UniffiDefiniteIntegrationDivergenceDirection?
The signed infinity of a divergent request, when a single direction was established.
UniffiDefiniteIntegrationResult method
fun interpretation(): UniffiDefiniteIntegrationInterpretation
The interpretation under which the request was answered.
UniffiDefiniteIntegrationResult method
fun value(): UniffiExpression?
The exact value, present exactly when the verdict is evaluated.
UniffiDefiniteIntegrationResult method
fun verdict(): UniffiDefiniteIntegrationVerdict
Whether the request was evaluated, proved divergent, or declined.
integrate_iterated#
Explicit context
fun integrateIterated(
inputExpression: UniffiExpression,
variables: List<kotlin.String>,
): UniffiExpression
Calling forms
Expression method: UniffiExpression.integrateIterated
fun integrateIterated(variables: List<kotlin.String>): UniffiExpression
Iterated indefinite integration, applying the single-variable pipeline once
per entry of variables in left-to-right order (innermost binder first).
An empty list returns the input unchanged. If any stage fails to close, the
remaining binders wrap the intermediate as nested unevaluated integral
nodes — no partial evaluation through an unclosed inner integral.
limit#
Explicit context
fun limit(
target: UniffiExpression,
variable: kotlin.String,
point: UniffiExpression,
direction: UniffiLimitDirection,
): UniffiExpression
Calling forms
Expression method: UniffiExpression.limit
fun limit(
variable: kotlin.String,
point: UniffiExpression,
direction: UniffiLimitDirection,
): UniffiExpression
limit(expression, variable, point, direction="two_sided") constructs a deferred limit.
evaluate_limit#
Explicit context
fun evaluateLimit(
target: UniffiExpression,
variable: kotlin.String,
point: UniffiExpression,
direction: UniffiLimitDirection,
): UniffiExpression
Calling forms and variants
Expression method: UniffiExpression.evaluateLimit
fun evaluateLimit(
variable: kotlin.String,
point: UniffiExpression,
direction: UniffiLimitDirection,
): UniffiExpression
Variant using local assumptions — UniffiAssumptionScope method: UniffiAssumptionScope.evaluateLimit
fun evaluateLimit(
target: UniffiExpression,
variable: kotlin.String,
point: UniffiExpression,
direction: UniffiLimitDirection,
): UniffiExpression
evaluate_limit(expression, variable, point, direction="two_sided") runs the eager limit engine.
It returns an unevaluated limit when the engine cannot close the result.
Use evaluate_limit_detailed to tell a proved nonexistence from a limit the
engine could not decide; both stay unevaluated here.
Limit of the expression as variable approaches point. direction is one
of "two_sided", "from_left", "from_right". Undecidable limits return an
unevaluated form.
The limit variable moves along the real line; every other symbol is a fixed
parameter. A two-sided limit at a finite point exists only when both one-sided
limits exist and agree, so limit(1/x, x, 0) and limit(x/abs(x), x, 0) stay
unevaluated. infinity and -infinity are the two real tails, and the
direction is ignored there. A point that depends on the limit variable, or a
center proved non-real (such as i), is not a real approach and the limit stays
unevaluated. A sign that depends on a parameter is decided only from a fact in
scope: limit(a/x^2, x, 0) is infinity under a > 0 and stays unevaluated
when the sign of a is unknown.
Beyond direct substitution and simple poles, every closed limit rests on
symbolic evidence: continuity of the composed germ, proved signs, and
expansions whose residuals are carried to the end. A numeric sample never
authorises a result. The certified routes are:
- Eventual germ signs.
abs(g) and signum(g) reduce to the branch valid
on the requested approach side once the sign of g is proved on a punctured
one-sided neighbourhood — from the local parameter and its powers, from exact
constant multiples and products, or from a leading term that strictly
dominates its own certified residual. So limit(x/abs(x), x, 0, "from_right")
is 1 and limit(signum((x-2)^3), x, 2, "from_left") is -1, while a
two-sided limit whose one-sided values disagree stays unevaluated.
- Bounded perturbations. A uniformly bounded remainder is discarded against
a divergent scale by a squeeze certificate, so
limit(log(x)/(log(x)+sin(x)), x, infinity) is 1 and
limit(sin(x)/log(x), x, infinity) is 0. The bounded grammar is exact
constants, sin, cos, signum, abs, and their sums, products and
nonnegative integer powers; a reciprocal needs a separately proved positive
lower bound.
- Exponential-logarithmic dominance. At infinity, and one-sidedly at a
finite real point through the substitution
a + 1/t or a - 1/t, the most rapidly
varying exponential and logarithmic subexpressions are rewritten as powers of
a small auxiliary variable and expanded recursively through the slower
scales. A cancelled leading term requests further terms instead of dropping a
residual, so an exponentially small correction amplified by a large
exponential is kept:
limit((exp(x*exp(-x)/(exp(-x)+exp(-2*x^2/(x+1))))-exp(x))/x, x, infinity)
is -exp(2), and
limit(x*log(x)*log(x*exp(x)-x^2)^2/log(log(x^2+2*exp(exp(3*x^3*log(x))))), x, infinity)
is 1/3.
- Gamma asymptotics.
factorial, gamma and log_gamma of an argument
c*t + h, with c > 0 and a shift h independent of the limit variable,
expand through Stirling's series with the shifted Bernoulli-polynomial
corrections and explicitly bounded remainders. The shift may be symbolic or
complex, so limit(gamma(z+a)/gamma(z)*exp(-a*log(z)), z, infinity) is 1
for every fixed a, and limit(factorial(n)^(1/n)/n, n, infinity) is 1/e.
A principal logarithm or a non-integer power of a Gamma value requires a
real shift. digamma and polygamma of a fixed nonnegative integer order
follow the differentiated series, and beta reduces to its Gamma quotient
when every fixed argument is proved off the Gamma poles, so
limit(x*(digamma(x) - log(x)), x, infinity) is -1/2. An argument running
along the negative axis through infinitely many poles stays unevaluated.
- Large-argument and endpoint theorems. Each of these values is replaced by
its literature expansion with one remainder proved bounded, and an answer
stands only when that remainder drops out:
bessel_j, bessel_y, hankel_first_kind and hankel_second_kind of a
fixed order proved real, and bessel_i and bessel_k of any fixed order, as
a real argument tends to +infinity (DLMF 10.17, 10.40); airy_ai and
airy_bi as a real argument tends to either infinity (DLMF 9.7);
error_function_complementary and error_function as a real argument tends
to either infinity (DLMF 7.12); zeta on a real tail through its Dirichlet
series; and elliptic_k(m), whose argument is the parameter m, as m
tends to 1 from below (DLMF 19.12). So
limit(2*sqrt(pi)*x^(1/4)*exp(2*x^(3/2)/3)*airy_ai(x), x, infinity) and
limit(sqrt(pi)*x*exp(x^2)*error_function_complementary(x), x, infinity)
are 1, limit(bessel_j(0, x), x, infinity) is 0, and
limit(elliptic_k(m)/log(16/(1-m)), m, 1, "from_left") is 1/2. An
oscillation whose amplitude does not vanish, such as sqrt(x)*bessel_j(0, x),
is never given a value, and neither is an order that moves with the
variable or a Bessel argument on its branch cut. polylogarithm(s, z) with
the real part of s proved greater than 1 tends to zeta(s) as z tends
to 1 from below, where its defining series converges on the closed unit
disk; the right side of 1 lies on the branch cut and stays unevaluated.
- Local meromorphic data.
zeta near s = 1 contributes its pole and
finite part, 1/(s-1) + euler_gamma + O(s-1), to ordinary local arithmetic,
so limit(zeta(x) - 1/(x-1), x, 1) is euler_gamma. A cancellation that
needs further Laurent coefficients declines; no numeric Stieltjes constant is
substituted.
- Hypergeometric reduction. Admissible parameter cancellation and the
binomial identity
hypergeometric_pfq([a], [], u) = (1-u)^(-a) on the disk
|u| < 1 apply before asymptotics, so
limit(hypergeometric_pfq([1, k], [1], z/k), k, infinity) is exp(z) for
every fixed complex z. Cancellation never passes through a nonpositive
integer lower parameter.
- Products and integrals. A definite
product of affine factors is
reduced to its rising-factorial Gamma form, checked by its initial value and
shift quotient, before the Gamma asymptotics apply. A sequence limit needs
the index proved to be a positive integer, for example inside
assuming(positive_integer_assumption(n)); there
n^x/(x*product(1 + x/k, k, 1, n)) tends to gamma(x). At the excluded
parameters x = 0, -1, -2, ... the input is undefined and no value is
returned, and without integer evidence the limit stays unevaluated. A limit
over the positive integers that should not depend on a declaration is asked
with evaluate_sequence_limit instead. A bounded
integral whose endpoint moves with the limit variable is expanded from a
local series of an analytic integrand together with its integrated remainder,
in either orientation, so
limit(x*integral(exp(-t^2), t, 0, x)/(1-exp(-x^2)), x, 0) is 1. When no
closed form exists, a factor integral(f(t), t, a(x), b(x)) of a product whose
endpoints both tend to the same finite c, with an integrand that does not
depend on the limit variable and is built only from functions continuous where
defined, is replaced by its leading term L*((b-c)^(k+1) - (a-c)^(k+1))/(k+1),
where f(t)/(t-c)^k tends to a proved nonzero real L from both sides and the
weight (t-c)^k keeps one sign between the endpoints. So
limit(integral(sin(t)/t, t, 0, x)/x, x, 0) is 1. An integrand that depends on
the limit variable is admitted when it expands exactly into terms g(t)*h(x),
each g with a finite limit at c and each h with a finite limit on the
approach; its leading term is f(c, x0)*(b - a) when that value is a proved
nonzero real, so limit(x*integral(sin(t)/t + arctan(x), t, 0, 1/x), x, infinity)
is 1 + pi/2. An integrand coupling both variables in one factor, such as
cos(x*t), is not separated. The replacement is made only in a product, never
in a sum, where the neglected relative error could cancel, and a limit is never
moved inside an integral over a fixed interval.
- Squeezes. A product with a bounded oscillating factor is squeezed by an
envelope built from certified magnitudes and uniform bounds, so
limit(x*sin(1/x), x, 0) is 0. A min or max of arguments proved real is
bounded by the sum of their envelopes, so limit(x*max(sin(1/x), 0), x, 0) is
0. A dirac_delta is a distribution, not a function, and no pointwise limit
of it is ever returned.
The decline boundary is deliberate, not incidental. A bound is not a limit, so
limit(sin(x), x, infinity) and limit(exp(sin(x)), x, infinity) stay
unevaluated; so does a reciprocal of an expression that may cross zero, such as
limit(1/sin(x), x, infinity), and any cancellation between two unrelated
oscillations. A real logarithm is only approached from the side on which its
argument is positive: limit(arctan(-log(x)), x, 0, "from_right") is pi/2,
while the left and two-sided limits stay unevaluated. The Gamma routes decline
unless the argument tends to positive infinity along the real axis, so a
negative-axis argument, an argument approaching a Gamma pole, and a shift that
moves with the limit variable all stay unevaluated. An unresolved constant sign
or equality, an unsupported branch, and an improper integral whose limit would
have to be interchanged with integration also decline. Exact identities keep
priority over asymptotic normalisation, and every proof or rewrite budget
exhaustion returns the unevaluated form rather than a guess.
The table below records what the engine does with each special function on five
kinds of approach: a regular finite point, a singular finite point (a pole, a
branch point or an end of the real domain), the two real infinities, and a
complex approach (evaluate_complex_limit or evaluate_complex_sector_limit).
supported means a representative request is decided exactly, declined that
it stays unevaluated because no
certified theorem covers it, and — that the function has no such point. A
declined cell is a capability boundary, not a wrong answer: the request is
returned unevaluated.
evaluate_limit_detailed#
Explicit context
fun evaluateLimitDetailed(
target: UniffiExpression,
variable: kotlin.String,
point: UniffiExpression,
direction: UniffiLimitDirection,
): UniffiLimitResult
The limit classification that evaluate_limit projects to an expression,
keeping the status apart from the value. The arguments and the semantics are
those of evaluate_limit, so a finite status carries exactly the value
evaluate_limit returns and a signed infinity is the infinity it returns.
does_not_exist is reported only with a proof: both one-sided limits at a
finite point were proved and proved different, as for 1/x or x/abs(x) at
0, or the expression is defined near the approach and two admissible
sequences tending to it give proved and different limits, as for sin(x) or
exp(sin(x)) at infinity and sin(1/x) at 0, whose sine is 1 and -1
along the points where its argument is pi/2 + 2*pi*n and 3*pi/2 + 2*pi*n.
A limit the engine did not derive is unknown, never does_not_exist, so
sin(a*x) at infinity with an unknown parameter a is unknown. Kotlin and Swift take the direction as a typed
enumeration; WASM takes it as an optional argument.
sequence_limit#
Explicit context
fun sequenceLimit(
target: UniffiExpression,
index: kotlin.String,
): UniffiExpression
Calling forms
Expression method: UniffiExpression.sequenceLimit
fun sequenceLimit(index: kotlin.String): UniffiExpression
sequence_limit(expression, index) constructs the deferred limit of a sequence as
its positive-integer index tends to infinity. execute evaluates it.
evaluate_sequence_limit#
Explicit context
fun evaluateSequenceLimit(
target: UniffiExpression,
index: kotlin.String,
): UniffiExpression
Calling forms and variants
Expression method: UniffiExpression.evaluateSequenceLimit
fun evaluateSequenceLimit(index: kotlin.String): UniffiExpression
Variant using local assumptions — UniffiAssumptionScope method: UniffiAssumptionScope.evaluateSequenceLimit
fun evaluateSequenceLimit(
target: UniffiExpression,
index: kotlin.String,
): UniffiExpression
evaluate_sequence_limit(expression, index) evaluates the limit of a sequence as
index runs through the positive integers to infinity. It returns the deferred
sequence_limit(expression, index) when the limit is not decided or does not
exist; evaluate_sequence_limit_detailed tells the two apart.
A sequence limit is a different question from the real limit at infinity. The
real limit of sin(pi*x) does not exist, but sin(pi*n) is 0 at every integer,
so evaluate_sequence_limit(n*sin(pi*n), n) is 0. The index only names the
variable that runs through the positive integers: declarations about the index
symbol neither change the answer nor are changed by it, and the real evaluate_limit of the same expression is never
affected. Only a scope that proves the index non-integer, non-real or
nonpositive leaves no positive-integer tail, and the limit then stays
unevaluated. Every other symbol is a parameter, with its assumptions in force.
Each result rests on one of three exact theorems:
- Integer identities and the real extension. The term is first rewritten by
identities that hold at every integer:
floor and ceiling of an
integer-valued argument, a sign alternation (-c)^(a*n + b) reduced to
(-1)^n or a constant, a whole number of half periods removed from a
trigonometric argument, factorial(n) as gamma(n + 1), and a definite
summation or indexed_product whose bounds depend on n replaced by its
closed form. If the rewritten term, read as a function of a real variable, has
a limit at infinity, so does the sequence. So floor(n)/n is 1,
(1 + 1/n)^n is e, and the Riemann sum (1/n)*summation(k/n, k, 1, n) is
1/2. A real limit that does not exist is never read as nonexistence of the
sequence.
- Residue classes. A sign alternation, a trigonometric argument
(p/q)*pi*n or a floor of (p/q)*n repeats with a period the engine
certifies, up to 24. The classes n = q*j + r are settled as sequences of
their own: the limit is their common value, and two classes with proved
different limits prove that the limit does not exist. So (-1)^n,
sin(pi*n/2) and n*(-1)^n have no limit, while (-1)^n/n and
floor(n/2)/n tend to 0 and 1/2.
- Ratio test. For terms of one eventual sign with a successive ratio tending
to
rho, rho < 1 gives 0 and rho > 1 gives the signed infinity. A ratio
tending to 1 decides nothing.
An eventually monotone, bounded sequence converges, but the monotone convergence
theorem does not name the limit. Such a proof is used in two ways only: a
convergent sequence takes the limit of a residue class whose limit is decided,
and it is never reported as divergent or nonexistent. Monotonicity is read from
the sign of the derivative of the real extension, or of the summand of a partial
sum; the bound is a uniform constant, or for a partial sum of terms shrinking
towards zero the convergent improper integral of the summand (the integral test).
So the partial sums of 1/k^2 are known to converge while their value stays
unevaluated.
A sequence whose behaviour on the integers none of these settles stays
unevaluated, even when its real extension is understood: sin(n) and
(-1)^(n^2) are left undecided rather than given a value.
evaluate_sequence_limit_detailed#
Explicit context
fun evaluateSequenceLimitDetailed(
target: UniffiExpression,
index: kotlin.String,
): UniffiLimitResult
The classification that evaluate_sequence_limit projects to an expression,
with the same arguments and the LimitResult members of
evaluate_limit_detailed. does_not_exist is reported only with a proof: two
residue classes of the index with proved different limits, or one class proved
to have none, as for (-1)^n or sin(pi*n/2). A sequence the engine did not
settle, such as sin(n), is unknown. invalid_approach means the assumptions
prove the index non-integer or non-real, and no_admissible_neighborhood that
they prove it nonpositive or the expression undefined.
complex_limit#
Explicit context
fun complexLimit(
target: UniffiExpression,
variable: kotlin.String,
point: UniffiExpression,
): UniffiExpression
complex_limit(expression, variable, point) constructs the deferred limit of an
expression as the variable tends to a finite point through a punctured complex
disk. execute evaluates it.
evaluate_complex_limit#
Explicit context
fun evaluateComplexLimit(
target: UniffiExpression,
variable: kotlin.String,
point: UniffiExpression,
): UniffiExpression
evaluate_complex_limit(expression, variable, point) evaluates the limit as the
variable tends to point through every point of a punctured complex disk, not
along the real line. It returns the deferred complex_limit(expression, variable, point) when the limit is not decided, does not exist, or is a pole;
evaluate_complex_limit_detailed tells these apart. A complex limit is never a
signed infinity: no value represents complex infinity, so a pole is left
unevaluated. There is no direction argument, and the real evaluate_limit
keeps rejecting a center proved non-real in every direction.
The variable is bound by the request, so a declaration that it is real does not
narrow the disk. The point must be finite, defined and independent of the
variable; infinity is approached through evaluate_complex_sector_limit.
A limit is decided by the first of these that applies:
- Holomorphy at the point. An expression proved holomorphic at the point
takes its exact value there:
exp(z) at i is exp(i).
- Laurent expansion. An expression proved meromorphic at the point has the
same Laurent expansion in every direction: a removable singularity takes its
constant term, as
sin(z)/z tends to 1 at 0, and a pole is reported as
an unbounded magnitude.
- Special-function poles. A pole of
zeta at 1 or of gamma at a
nonpositive integer is removed by an exact identity, the Laurent expansion
zeta(u) = 1/(u - 1) + H(u) with H(1) = euler_gamma and the recurrence
gamma(u) = gamma(u + n + 1)/(u (u + 1) ... (u + n)). So
zeta(z) - 1/(z - 1) tends to euler_gamma at 1 and z*gamma(z) to 1 at
0.
- Magnitude of principal powers. A product of meromorphic factors and real
powers of them is bounded through
|u^a| = |u|^a, which holds on every branch:
sqrt(z)*sin(z) tends to 0 at 0.
Nonexistence is proved along rays point + t*e^(i*theta*pi) with t -> 0+ and
theta a multiple of 1/4: one ray with a proved finite value and another with
a proved different value, a signed divergence, or no limit. So
conjugate(z)/z has no limit at 0: it is 1 along the real axis and -1
along the imaginary axis. A point on a branch cut, such as log(z) at -1, is
left unevaluated rather than given the value of the principal branch.
evaluate_complex_limit_detailed#
Explicit context
fun evaluateComplexLimitDetailed(
target: UniffiExpression,
variable: kotlin.String,
point: UniffiExpression,
): UniffiLimitResult
The classification that evaluate_complex_limit projects to an expression, with
the LimitResult members of evaluate_limit_detailed. The status is finite,
does_not_exist or unknown; it is never a signed infinity. A proved pole is
unknown with the reason unbounded_magnitude.
complex_sector_limit#
Explicit context
fun complexSectorLimit(
target: UniffiExpression,
variable: kotlin.String,
lowerAngle: UniffiExpression,
upperAngle: UniffiExpression,
): UniffiExpression
complex_sector_limit(expression, variable, lower_angle, upper_angle) constructs
the deferred limit of an expression as the variable tends to infinity with its
argument in the closed sector from lower_angle to upper_angle. execute
evaluates it.
evaluate_complex_sector_limit#
Explicit context
fun evaluateComplexSectorLimit(
target: UniffiExpression,
variable: kotlin.String,
lowerAngle: UniffiExpression,
upperAngle: UniffiExpression,
): UniffiExpression
evaluate_complex_sector_limit(expression, variable, lower_angle, upper_angle)
evaluates the limit as the variable tends to infinity inside the closed sector
lower_angle <= arg(z) <= upper_angle, uniformly over the sector. The angles
must be rational multiples of pi, with lower_angle <= upper_angle and an
opening of at most 2*pi; anything else is an invalid approach. A sector of
opening zero is a single ray. The deferred complex_sector_limit is returned
when the limit is not decided.
Every theorem is checked on the whole closed sector:
- Rational functions compare degrees in every direction:
(z^2 + 1)/(2*z^2 + i) tends to 1/2.
- Magnitude envelopes. A product whose factors have certified bounds tends to
0 when their powers of abs(z) add to a negative number, or when one factor
decays exponentially and none grows faster than a power. The certified factors
are polynomials, z^a, log(z), exp(c*z + b) with c a real or imaginary
constant (bounded where the real part of c*z is never positive and decaying
where it is negative), airy_ai(z) for abs(arg(z)) <= pi/3 (DLMF 9.7.5) and
bessel_k(nu, z) with fixed nu for abs(arg(z)) <= pi/2 (DLMF 10.40.2). So
z^10*exp(-z) tends to 0 for -pi/3 <= arg(z) <= pi/3, but exp(-z) is not
decided on the closed right half-plane, where it does not tend to 0 along the
imaginary axis.
- Stirling's formula. On a sector separated from the negative real axis, a
product
c*z^b*gamma(z + h_1)^e_1*... with integer exponents adding to zero
tends to c when b + e_1*h_1 + ... is 0 (DLMF 5.11.8): `gamma(z + a)/gamma(z
- b)*z^(b - a)
tends to1. A sector that reaches the negative axis, where the poles of gamma` accumulate, is not decided.
- Principal logarithms. On a sector where
log(c*z) does not cross its cut,
log(c*z) = log(z) + log(abs(c)) + i*arg, with the branch fixed for the whole
sector: log(-z) - log(z) tends to -i*pi for pi/4 <= arg(z) <= 3*pi/4. A
sector on which -z crosses the negative real axis is not decided.
- Sums and products of decided parts.
Nonexistence is proved along the two edges and the bisector of the sector, as
for a finite point.
evaluate_complex_sector_limit_detailed#
Explicit context
fun evaluateComplexSectorLimitDetailed(
target: UniffiExpression,
variable: kotlin.String,
lowerAngle: UniffiExpression,
upperAngle: UniffiExpression,
): UniffiLimitResult
The classification that evaluate_complex_sector_limit projects to an
expression, with the LimitResult members of evaluate_limit_detailed. A
magnitude proved to grow without bound, as for z^2 or
gamma(z + 1/3)/gamma(z), is unknown with the reason unbounded_magnitude.
joint_limit#
Explicit context
fun jointLimit(
target: UniffiExpression,
variables: List<kotlin.String>,
point: List<UniffiExpression>,
relativeDomain: UniffiExpression?,
): UniffiExpression
joint_limit(expression, variables, point, relative_domain=None) constructs the
deferred joint limit of an expression as the ordered variables tend together to
the center with the same order, optionally relative to a domain given as a
logical expression over relations. execute evaluates it.
evaluate_joint_limit#
Explicit context
fun evaluateJointLimit(
target: UniffiExpression,
variables: List<kotlin.String>,
point: List<UniffiExpression>,
relativeDomain: UniffiExpression?,
): UniffiExpression
evaluate_joint_limit(expression, variables, point, relative_domain=None)
evaluates the limit of a real function of two or more variables as the point
(x_1, ..., x_d) tends to (a_1, ..., a_d) through every point of a punctured
neighborhood, or through every point of relative_domain near the center when
a domain is given. It returns the deferred joint_limit(expression, variables, point, relative_domain) when the limit is not decided.
A joint limit is not an iterated limit. x*y/(x^2 + y^2) tends to 0 along each
axis and both iterated limits at (0, 0) are 0, yet it has no joint limit:
it is 1/2 along y = x. Agreement of iterated limits, or of any number of
paths, is never used as evidence of a joint limit.
The variables need at least two entries, must be distinct, and need one center
coordinate each; a request that breaks this is an error. The variables are
bound by the request, so declarations about them do not narrow the
neighborhood: state a restriction as relative_domain instead, such as
x > 0 and y > 0. The center must be free of the variables and finite, and a
coordinate proved non-real is an invalid approach. A domain must have the
center as an accumulation point; this is certified by an exact ray from the
center that stays in the domain — or, for a domain such as y = x^2, by a ray
lifted onto that curve — and a domain that cannot be certified is left
undecided.
A limit is decided by the first of these that applies:
- Joint continuity. The expression is shown, rule by rule, to be defined
near the center and continuous in all variables at once, and takes its value
there:
exp(x*y) at (1, 2) is exp(2), and sqrt(x^2 + y^2) at (0, 0) is
0. Continuity in each variable separately is not used.
- Radial norm bound. A certified bound
|f| <= C*r^k with k > 0, where r
is the distance to the center, proves the limit 0. Polynomial factors
contribute their order of vanishing; a denominator whose lowest-order
homogeneous part vanishes only at the center contributes minus that order,
checked exactly by a Sturm root count in two variables or by Sylvester's
criterion for a quadratic part; |sin u| <= |u| and |cos u| <= 1 for real u.
So x^2*y/(x^2 + y^2), x*y/sqrt(x^2 + y^2) and
(x^2 + y^2)*sin(1/(x^2 + y^2)) all tend to 0 at (0, 0).
- Sums. When every term is continuous or has a vanishing bound, the limit
is the sum of the continuous values:
x^2*y/(x^2 + y^2) + cos(x) tends to 1.
- Constant leading quotient. For a rational function
P/Q whose
denominator has a definite lowest-order part Q_d, a numerator with
P_d = k*Q_d gives the limit k when P - k*Q vanishes to a higher order:
(x^2 + 2*y^2 + x^3)/(x^2 + 2*y^2) tends to 1.
- Composition. Sums, products and powers of parts with limits take the
combined limit, and an expression that is exactly
g(u) for a function g
of one variable and an inner expression u tending to b takes the
one-variable limit of g at b. When g is not continuous at b, the
points where u = b must be excluded:
either u - b is certified nonzero near the center, or the domain states it,
as x*y != 0. So sin(x^2 + y^2)/(x^2 + y^2) tends to 1, and
sin(x*y)/(x*y) tends to 1 relative to x*y != 0; without that domain it
is undefined on the axes and is left unevaluated. A domain also excludes
u = b when it signs every factor of u - b: relative to x > 0 and y > 0,
x*y > 0, so sin(x*y)/(x*y) tends to 1 there too.
- Weighted charts. A rational function of two variables whose
denominator's lowest-order part vanishes along some direction, such as
x^2*y^2/(x^2 + y^4), is covered by the four charts x=±tp,y=utq
and y=±tq,x=utp with |u| <= 1, for coprime weights p, q up to
8. These charts contain every point near the center. When, in every chart,
each denominator factor is t^m times a polynomial in u with no root on
[-1, 1] (an exact Sturm count) and the numerator minus k times the
denominator vanishes to a higher power of t, the limit is k, with a bound
uniform in u; checking finitely many slopes is never part of the proof. So
x^2*y^2/(x^2 + y^4) and x^3*y^2/(x^4 + y^2) tend to 0.
- Curves and surfaces as domains. When a domain condition is an equation
that solves for one variable as a polynomial in the others with no constant
term, such as
y = x, y = x^2 or z = x + y, the limit relative to that
domain is the limit of the expression restricted to it, in one variable
fewer. With one variable left, the domain near the center is two branches,
and the limit is the common value of the remaining branches. So
x*y/(x^2 + y^2) has the limit 1/2 relative to y = x, 2/5 relative to
y = 2*x, and x^2*y/(x^4 + y^2) has 1/2 relative to y = x^2. Two
branches with different limits prove nonexistence: x/sqrt(x^2 + y^2)
relative to y = x. Several equations are restricted one at a time.
A certified bound |f| >= c*r^k with k < 0 proves that the magnitude grows
without bound, as for 1/(x^2 + y^2); a joint limit is never reported as a
signed infinity, so this is left unevaluated. Relative to a domain, two paths
with opposite infinite limits are still sought first, so 1/x relative to
x != 0 does not exist.
Nonexistence is proved by two exact paths x_i = a_i + c_i*t^(k_i), t -> 0+,
that stay in the domain, along which the expression is defined, and along
which the one-variable limits are proved different: two finite values whose
difference has a proved sign, a finite value against an infinity, or opposite
infinities. The paths searched are the coordinate axes, lines, and curves such
as y = x^2, so x^2*y/(x^4 + y^2) does not exist (0 along y = 0, 1/2
along y = x^2), and relative to x > 0 and y > 0, x*y/(x^2 + y^2) does not
exist (paths inside the quadrant give 1/2 and 2/5). A path whose limit is
not decided never contributes, and when no pair is found the result is
undecided. A symbolic parameter that could make the two path values equal
blocks the proof: a*x*y/(x^2 + y^2) is undecided until a is declared
nonzero, and a value is never chosen for one parameter value alone.
evaluate_joint_limit_detailed#
Explicit context
fun evaluateJointLimitDetailed(
target: UniffiExpression,
variables: List<kotlin.String>,
point: List<UniffiExpression>,
relativeDomain: UniffiExpression?,
): UniffiLimitResult
The classification that evaluate_joint_limit projects to an expression, with
the LimitResult members of evaluate_limit_detailed. The status is finite,
does_not_exist (two admissible paths with limits proved different) or
unknown; it is never a signed infinity. A magnitude proved
to grow without bound is unknown with the reason unbounded_magnitude, and a
domain the center does not accumulate is unknown with the reason
no_admissible_neighborhood when the domain is proved empty.
LimitResult#
What evaluate_limit_detailed, evaluate_sequence_limit_detailed, evaluate_complex_limit_detailed, evaluate_complex_sector_limit_detailed and evaluate_joint_limit_detailed return. Its members are:
Each member's exact host type and spelling follows below.
UniffiLimitResult method
fun declineReason(): UniffiLimitDeclineReason?
The reason, present exactly when the status is unknown.
UniffiLimitResult method
fun status(): UniffiLimitStatus
Whether the limit is finite, a signed infinity, proved nonexistent, or undecided.
UniffiLimitResult method
fun value(): UniffiExpression?
The exact limit, present exactly when the status is finite.
singularities#
Explicit context
fun singularities(
target: UniffiExpression,
variable: kotlin.String,
): UniffiExpression
Calling forms and variants
Expression method: UniffiExpression.singularities
fun singularities(variable: kotlin.String): UniffiExpression
Variant using local assumptions — UniffiAssumptionScope method: UniffiAssumptionScope.singularities
fun singularities(
target: UniffiExpression,
variable: kotlin.String,
): UniffiExpression
The singular points of the expression in the complex plane, as a set
expression (finite set, union, image set for periodic families, …). Rational
denominators are solved over the complex numbers even when the variable has
real assumptions. Multivalued functions contribute their finite branch
points; a conventional principal-branch cut is not returned as though every
point on it were singular.
continuous_domain#
Explicit context
fun continuousDomain(
target: UniffiExpression,
variable: kotlin.String,
): UniffiExpression
Calling forms and variants
Expression method: UniffiExpression.continuousDomain
fun continuousDomain(variable: kotlin.String): UniffiExpression
Variant using local assumptions — UniffiAssumptionScope method: UniffiAssumptionScope.continuousDomain
fun continuousDomain(
target: UniffiExpression,
variable: kotlin.String,
): UniffiExpression
The subset of the real line on which the expression is continuous in
variable, as a set expression. Compound rational square-root radicands are
lowered to an exact univariate semialgebraic condition when supported, so,
for example, sqrt(x + 1/x - 2) has continuous real domain (0, infinity).
summation_indefinite#
Anti-difference: a closed form F with F(index+1)−F(index)=summand.
Strategy stack: constant summands, linearity, polynomial power sums, rational
summands (Abramov), hypergeometric summands (Gosper), and finally C-finite
summands solved in a finite sequence state algebra (see summation on the
construction page for that admitted class — ∑F(k)2 closes here). Outside that
scope the result is an unevaluated summation placeholder. The existing
summation binding (construction page) remains the definite/unevaluated entry
point.
Gosper runs as a decision procedure over the term's own coefficient field
Q(parameters), so symbolic parameters inside binomial, factorial, Pochhammer
or Gamma arguments are admitted rather than rejected — binomial(n, k) and
2^(-n) * binomial(n, k) are read the same way binomial(7, k) is. A summand
that is a sum is first tested for being a rational multiple of one
hypergeometric term, because a binomial difference such as
2^(-n)*binomial(n,k) - 2^(-(n+1))*binomial(n+1,k) has an anti-difference
while neither half does; only when that fails does linearity distribute.
Three outcomes are distinguished internally and all three surface as the
unevaluated placeholder, which is never a claim that no closed form exists:
the summand is outside the admitted term class; the term is admitted and
Gosper proves it has no hypergeometric anti-difference (the classical
binomial(n, k) case); or a resource ceiling stopped the search before its
mathematical bound. Anti-differences carrying combinatorial factors are proved
on the non-negative-integer domain — the convention under which
binomial(n, k) is zero outside 0≤k≤n — and are not claimed as
unrestricted Gamma-analytic identities.
evaluate_on_grid#
Explicit context
fun evaluateOnGrid(
inputExpression: UniffiExpression,
variable: kotlin.String,
grid: List<kotlin.Double>,
): List<kotlin.Double>
Evaluate at each grid point, substituting variable. Positions where
evaluation fails (pole, complex value, unbound symbol) hold NaN. Intended for
plotting.
Each grid value denotes its exact binary value, the expression is evaluated
with 128-bit intermediate arithmetic, and the result is rounded to a float.
The value is an approximation with no error bound; use evaluate_numeric for
digits that are proved. The 128-bit intermediates survive cancellation and
intermediate overflow that binary64 arithmetic does not, at a cost of
microseconds per point. In automatic execution mode, a grid whose total work
is large enough — a few hundred points of arithmetic, a few dozen of an
elementary function, or two of a special function — is split into contiguous
point ranges evaluated in parallel; the values are identical to the sequential
ones. A
compiled machine function
evaluates the same expression in binary64 arithmetic far faster and reports a
status for each output in place of NaN.
evaluate_on_grid_points#
Explicit context
fun evaluateOnGridPoints(
inputExpression: UniffiExpression,
variables: List<kotlin.String>,
points: List<kotlin.Double>,
): List<kotlin.Double>
Multi-variable companion to evaluate_on_grid: evaluate at each point of a
flat row-major coordinate array (one coordinate per variable, so the points
length must be a multiple of the variable count), returning one float per
point. Positions where evaluation fails hold NaN. Raises when variables is
empty or the lengths disagree. Intended for sampling surfaces and implicit
curves.
execute#
Explicit context
fun execute(target: UniffiExpression): UniffiExpression
Calling forms
Expression method: UniffiExpression.execute
fun execute(): UniffiExpression
Re-dispatch every unevaluated node (integral, derivative, summation,
transform, ODE/recurrence placeholder) in the expression; useful after
substitution has changed the inputs.
Example#
integrate_definite_under_constraint#
Explicit context
fun integrateDefiniteUnderConstraint(
target: UniffiExpression,
variable: kotlin.String,
lowerBound: UniffiExpression,
upperBound: UniffiExpression,
constraint: UniffiExpression,
): UniffiExpression
Calling forms
Expression method: UniffiExpression.integrateDefiniteUnderConstraint
fun integrateDefiniteUnderConstraint(
variable: kotlin.String,
lowerBound: UniffiExpression,
upperBound: UniffiExpression,
constraint: UniffiExpression,
): UniffiExpression
Definite integration under a local bounded logical constraint. The constraint
holds for this call only: it is not recorded on any symbol, so it cannot leak
into a later operation on the same context. Use it when the integral is
determined only on part of a parameter range — a sign condition on a parameter,
say — without committing the context to that condition.
See Assumptions for durable symbol assumptions and for
AssumptionScope, which applies a set of assumptions to a whole block of
operations rather than to one call.