Deferred forms
Deferred forms preserve an operation symbolically until its variables, bounds, or assumptions are sufficiently known. Use execute or the corresponding eager operation when you want evaluation.
Unevaluated form constructors#
integral#
Explicit context
func integral(
integrand: UniffiExpression,
variable: String,
lower: UniffiExpression?,
upper: UniffiExpression?,
) -> UniffiExpressionBuild an unevaluated integral node (indefinite when bounds are omitted).
Use integrate/integrate_definite for eager evaluation, or execute on
the node. A definite integral node has a numerical value only on explicit
request, through integrate_definite_numeric
or evaluate_numeric.
derivative_unevaluated#
Explicit context
func derivativeUnevaluated(
target: UniffiExpression,
variable: String,
order: UInt64,
) -> UniffiExpressionCalling forms
Expression method: UniffiExpression.derivativeUnevaluated
func derivativeUnevaluated(
variable: String,
order: UInt64,
) -> UniffiExpressionConstructs an unevaluated derivative node of an arbitrary expression, the
name stating the deferral outright. The variable may be a name or a
same-context symbol expression. Nothing is differentiated here: use
execute on the node, or
differentiate — spelled diff on a Python
expression — to differentiate now.
derivative#
Explicit context
func derivative(
target: UniffiExpression,
variable: String,
order: UInt64,
) -> UniffiExpressionCalling forms
Expression method: UniffiExpression.derivative
func derivative(variable: String, order: UInt64) -> UniffiExpressionThe same deferred constructor as derivative_unevaluated, under its short
spelling. Nothing is differentiated here: use
execute on the node, or
differentiate to differentiate now.
This is not the derivative of a named unknown function. An equation built from
this placeholder is not recognised by the differential-equation classifiers,
which read the structural derivative built by
UndefinedFunction.derivative.
summation#
Explicit context
func summation(
summand: UniffiExpression,
index: String,
lower: UniffiExpression,
upper: UniffiExpression,
) -> UniffiExpressionBuild a summation node . execute evaluates it when a closed form or
finite expansion exists. For the indefinite anti-difference see
summation_indefinite on the calculus page. Definite hypergeometric sums are
closed by Zeilberger creative telescoping: a defining recurrence is produced
and verified, then closed to a hypergeometric form when one exists (e.g.
. When no hypergeometric closed form exists
(Apéry-type sums such as the central Delannoy numbers ),
execute returns the verified defining recurrence as a recurrence_equation
node rather than declining. Every result is symbolically verified before return,
so a sum outside the closed scope stays an unevaluated summation placeholder
rather than a guess. Its numerical value is produced only on explicit request,
through summation_numeric or
evaluate_numeric.
Bounds. The summation range no longer has to be 0..n. Bounds may be any
integer-affine form in the parameters () or a min/max of such
forms (). They are admitted by proof: the
term's own zero extension — a binomial coefficient vanishes outside
— gives an interval outside which the summand is provably
zero, and the declared bounds are accepted only when they are at least that
wide. A declared range that clips the support is refused rather than answered.
Parameters. Any number of parameters is admitted. One carries the
recurrence and the rest ride along symbolically, so
is closed with m and n intact.
Domain. Results involving binomial coefficients and factorials are proved
on the non-negative-integer domain, under the combinatorial convention that
binomial(n, k) is zero outside . They are not claimed as
unrestricted Gamma-analytic identities, and the integrality and non-negativity
each result depends on are recorded during normalization rather than assumed
silently.
Alternating squared binomial rows. is closed as the
coefficient of in : it is 0 for odd n and
for even n, so . A
constant factor and an integer offset in the sign's exponent pass through. A literal row supplies
its own parity; a symbolic row is closed only when the assumption context proves it a
non-negative integer and decides whether it is even or odd, and is otherwise left to the general
recurrence machinery.
Logarithmic and polylogarithmic series. An infinite sum
with exact rational bases, integer
offsets, and a positive integer order s is the polylogarithm at
less its exact prefix below L. It is evaluated wherever the defining
series converges: absolutely for , and on for . At and
the series converges only conditionally, by the alternating-series test, and its sum is
the boundary value by Abel's theorem, so
. A conditionally convergent series is never split
term by term, because rearranging it can change its sum.
Finite trigonometric progressions. execute closes finite linear
combinations of sin(phase + stride*index) and
cos(phase + stride*index) when the coefficients, phase, and stride are
index-free and the bounds prove a finite nonnegative integer count. The result
is a piecewise centered trigonometric form: the branch
exp(i*stride) = 1 evaluates the constant progression directly, and its
complement uses the finite Fourier quotient. This branch ledger preserves the
value at removable singularities instead of silently dividing by
sin(stride/2). An unconstrained symbolic range, nonlinear index phase, or
branch budget overflow leaves the summation unevaluated.
Resource behaviour. A search that reaches a resource ceiling before its
derived mathematical bound preserves the unevaluated summation node. That
outcome is a statement about the search, never a claim that no closed form or
recurrence exists; the same placeholder is also what an out-of-scope summand
produces, so the placeholder should never be read as a negative result.
C-finite summands. A summand built from C-finite sequences — sequences
satisfying a homogeneous linear recurrence with constant coefficients, of which
fibonacci_number is the built-in this release registers — is not
hypergeometric and is closed by a separate route. The admitted class is the
finite state algebra generated by fixed non-negative shifts and affine
subsequences of those sequences, closed under rational scaling, addition,
finite products, and fixed non-negative integer powers, so
and are both
in scope. The anti-difference is constructed by solving one exact linear
system in that algebra, not guessed and tested. A separate route recognizes the
binomial transform for an admitted g, giving
.
Floor-bounded ranges. An upper bound of the form
with exact integers a, b and positive m is admitted.
It is normalized by Euclidean division on the parameter into a complete,
disjoint ledger of m residue strata, on each of which the bound is an ordinary
affine expression; empty strata are recorded explicitly rather than inherited
from a combinatorial convention. On top of that, affine binomial diagonals
are closed by a
structural Pascal decomposition whose moving boundary terms are each proved
zero, giving .
Verification. Every C-finite and floor-bounded result carries two
independent exact checks before it is returned: the construction identity is
replayed (the forward difference in the state algebra, the transformed state
against directly accumulated exact sums, or the Pascal decomposition against its
residue ledger and boundary terms), and the returned expression is then proved
equal to the derived recurrence's unique solution on a complete initial window.
A presentation such as fibonacci_number(2n) is admitted only after that
uniqueness argument closes — never by matching a name. When a recurrence is
found but no expression in the language represents its solution, the sum stays
an unevaluated summation node.
Domain. These identities are proved on the non-negative-integer stratum and record that assumption; a parameter the assumption context proves negative declines instead. Zero extension of a binomial is used only where the built-in's own semantics prove it — both arguments non-negative with the bottom above the top — and never for a negative top argument, where the built-in is undefined.
product#
Explicit context
func product(
multiplicand: UniffiExpression,
index: String,
lower: UniffiExpression,
upper: UniffiExpression,
) -> UniffiExpressionDefinite indexed product , a first-class
indexed_product binder (rendered \prod in LaTeX). The result is the closed
form produced by the product engine. A range the assumption context proves
reversed is the empty product 1. Otherwise the engine tries, in order:
- Rational anti-quotients. Factorial and Pochhammer recognition (); telescoping and rational products via Gamma quotients (); and exact shift-orbit reduction over the rationals and the Gaussian rationals, which discovers an anti-quotient whenever numerator and denominator factors are integer shifts of one another (, ).
- Balanced rational infinite products. With
upper = infinityand an exact finite integer lower bound, a shift-free rational residual that splits into affine factors with equal factor counts and equal shift sums converges, and its value is the Gamma quotient of Euler's finite definition (, Wallis ). Unequal counts, unequal shift sums, a surviving constant content, a factor that vanishes on the range, or a pole on the range are not closed by this route; the telescoped partial product below still decides the ones whose partial products provably tend to zero. - Periodic interlacing. A bounded period generated by an exact root of unity (currently and ) splits the range into complete residue blocks which are routed through the rational machinery (). Every terminal prefix of a block must separately be proved to tend to one, so a regrouping that converges while the ordered product oscillates is declined.
- Finite Gamma grids. A
gammamultiplicand whose argument is affine in the index over an exact concrete integer range is materialised and normalised by Gamma recurrence, Euler reflection, and the Gauss multiplication formula (). A symbolically complete Gauss grid, whose cardinality is proved equal to the grid denominator, is closed by the multiplication formula without materialising any factor. - Parametric root-of-unity products. The homogeneous quadratic family is the complete factorisation of over the -th roots of unity with and removed. The result is the total piecewise , because the published quotient is on the second stratum.
Every result is symbolically grounded in the multiplicative discrete
Newton–Leibniz identity P(upper+1)/P(lower) and, for an infinite product, in a
finite partial-product identity whose step quotient and lower endpoint are
verified exactly before its limit is taken.
The value of an infinite product is the limit of its partial products. When
the telescoped partial product P(m+1)/P(lower) is proved to tend to exactly
zero, the product is 0
(); in the classical
terminology that reserves convergence for a nonzero limit, such a product
diverges to zero. Partial products that grow without bound, oscillate, or have
an undecided limit leave the product unevaluated.
Domain. The root-of-unity family needs n to be a proved positive
integer: the assumption context must say so, and a free symbol is never
silently treated as an integer. Cancellation across a shifted factor is performed
only after proving that the cancelled factor is nonzero at every integer of the
range, so the same formal cancellation is admitted below a pole and refused on
it. Anything outside this closed scope — an irreducible higher-degree
multiplicand with algebraic roots, a coefficient field beyond and
, an unbounded or unproved period, a q-product, or an infinite
product whose convergence is not proved — stays an unevaluated indexed_product
placeholder rather than a guess.
product_indefinite#
Explicit context
func productIndefinite(
multiplicand: UniffiExpression,
index: String,
) -> UniffiExpressionIndefinite (anti-quotient) product: the P(k) satisfying
P(k+1)/P(k) = multiplicand(k), the multiplicative analogue of
summation_indefinite. A rational multiplicand over or
is first put through exact shift-orbit reduction, which returns a
purely rational anti-quotient whenever the numerator and denominator factors pair
up across integer shifts ( gives ); what the
reduction leaves behind falls back to the Gamma-quotient anti-quotient.
Index-free-base powers close through the summation anti-difference of their
exponent. Declines to the unevaluated indexed_product placeholder when no closed
form is in scope.
piecewise#
Not exposed by the Swift bindings. Available as Context.piecewise in Python, Context.piecewise in WASM / JavaScript, api::solving::Session::piecewise in Rust.
Build a piecewise expression from (value, condition) pairs with first-match
semantics; otherwise appends an always-true final branch. Branches whose
condition is provably false are dropped at construction; if every condition
fails the result is the undefined sentinel. The result keeps the
facts its conditions and values were derived under. Values
whose facts contradict one another — each valid only where its own condition
selects it — still form a piecewise expression, whose facts are then recorded as
unknown rather than refused.
Notes: WASM takes a flat interleaved array
[value_0, condition_0, value_1, condition_1, ...].
Example#
summation_indefinite#
Explicit context
func summationIndefinite(
summand: UniffiExpression,
index: String,
) -> UniffiExpressionCalling forms
Expression method: UniffiExpression.summationIndefinite
func summationIndefinite(index: String) -> UniffiExpressionThe anti-difference of summand: a closed form with
. It is the
discrete counterpart of an indefinite integral, and it sits here beside
product_indefinite for the same reason — when no closed
form is found, the unevaluated summation is what is returned.