Folding an array through a proved function #
The sumSquares function in LocalBindings.functions calls addSquare for
each represented word. That step calls the existing square function; neither
the traversal proof nor the mathematical specification supplies a second
squaring implementation. The specification is the ordinary natural-number sum
of the squared decoded words, encoded back into the word range.
The source uses a scoped for element binding. Generated body and return
equations select the shared function rule, so this proof does not name the
private cursor, extract call expressions or reconstruct parameter frames.
The word-valued fold is the encoded ordinary sum of natural squares. This equation uses list homomorphisms, independently of a machine execution.
The function returns the mathematical sum of squares through its word encoding and preserves caller state. No stream driver or time bound is needed.
Observe the same implemented function using an ordinary list expression.
When the mathematical sum fits, the decoded result is exactly that natural number. The modular theorem above does not assume intermediate no-overflow.
Body time is observed from the terminating implementation and then identified by the independent loop count. It includes both nested calls.
Execute the same declared fold on a preloaded array. The projection retains the returned word, full call count and stopping reason; it performs no list loading.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The executable function application returns that list sum and the complete machine count, including its enclosing call and halt. Memory is preloaded; stack capacity is a safety premise, not a proposed execution budget.
Equations
- Ram.Examples.ArrayFold.Factorials.functions.importMap.Factorial i✝ = List.length { registers := 0, declarations := [] }.program + i✝
Instances For
Project the declared word, array, or Unit result of the normally terminating call.
Use runTotal or applyState to observe execution when the result is Unit.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instances For
The declared function's compiled body count, excluding its enclosing call overhead.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Execute the declared function's compiled call, retaining the complete machine result.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Execute the declared function and return its typed value and source shared state, excluding private stack cells and restoring caller registers while retaining actual stream effects.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The declared function's result and shared state, observed through its actual execution.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The declared function's result and shared state, observed through its actual execution.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Execute the declared function and return its typed value and source shared state, excluding private stack cells and restoring caller registers while retaining actual stream effects.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instances For
Instances For
The declared parameters' actual by-value word fields.
Execute the declared function's compiled call, retaining the complete machine result.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instances For
The declared parameters' actual by-value word fields.
Execute the declared function's compiled call, retaining the complete machine result.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
Project the declared word, array, or Unit result of the normally terminating call.
Use runTotal or applyState to observe execution when the result is Unit.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The declared function's result and shared state, observed through its actual execution.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instances For
Instances For
Instances For
Execute the declared function with a normal-halt proof, retaining its state and count.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Execute the declared function with a normal-halt proof, retaining its state and count.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Project the declared word, array, or Unit result of the normally terminating call.
Use runTotal or applyState to observe execution when the result is Unit.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Execute the declared function and return its typed value and source shared state, excluding private stack cells and restoring caller registers while retaining actual stream effects.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A varying-cost fold imports the existing recursive factorial implementation. The adapter performs one actual call; the traversal performs one adapter call per represented array element. Neither source body computes a host-side list.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
The declared function's compiled body count, excluding its enclosing call overhead.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instances For
The declared function's compiled body count, excluding its enclosing call overhead.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Execute the declared function with a normal-halt proof, retaining its state and count.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instances For
The mathematical update describes the adapter's returned word, including the word model's modular factorial and addition. It is not executable source.
Equations
- Ram.Examples.ArrayFold.Factorials.step accumulator x = accumulator + Ram.Examples.Factorial.value w (BitVec.toNat x)
Instances For
A bound on this element gives sufficient recursive call depth. Correctness uses only the imported factorial contract, without a proposed instruction budget.
The adapter body pays the factorial body's input-dependent bound and its actual 28-step call overhead. Its final addition belongs to its own return code.
The machine-word fold is the encoding of the ordinary sum of factorials. No no-overflow claim is implicit in this equality.
Sum the actual element-dependent factorial-call bounds. The additional 53 steps per element pay the adapter's enclosing call and the traversal; the final eight steps initialize and finish the array function's body.
Equations
Instances For
The returned scalar is an ordinary mathematical fold. The array is already represented in the entry heap, and the element bound supplies recursive depth; the invocation preserves every part of the caller's shared state.
The declaration's typed semantic result describes the implemented fold, not a second factorial algorithm or a stream-output wrapper.
With no overflow in the mathematical sum, the implemented fold has that exact natural-number value. Modular semantics remain available without this premise.
The independent bound sums factorial work at the actual array elements. Only their admissibility and the accumulator's mathematical invariant are used to instantiate the general data-dependent traversal rule.
Budget-free correctness establishes normal termination of the compiled invocation. The bound reserves the outer fold frame, adapter frame and recursive factorial frames; it is a sufficient address-space condition, not a peak-space claim.
The ordinary executable typed projection returns the mathematical fold and the unchanged shared state of this same compiled invocation.
The same executable run pays the element-dependent body bound plus its actual outer call, return and halt. No array-loading work is included.