Composing functions with local bindings #
The function squaredNorm calls square twice and keeps both returned values
in lexical locals. Neither function needs a main program, input/output
streams or a hand-written register table. Their correctness proofs use the
same source declarations and the reusable contract for square.
The addSquare helper reuses square for one accumulator update. The
sumSquares array traversal calls this helper at each element; its complete
list specification and separate cost proof are in Examples.Ram.ArrayFold.
The result equation observes the implementation through Ram.Func.eval.
Arithmetic is machine-word arithmetic: the natural-number corollary encodes
the sum of squares modulo the word range, without claiming that overflow is
absent. These are semantic observations, not a second executable algorithm.
The independent cost proof reads the lengths of the two compiled calls: each
invocation of square takes 23 transitions, including its multiplication in
the return expression and its calling-convention code. Thus squaredNorm has
body time 46. Its own final addition and enclosing call/return are outside
Ram.Func.bodyTime; they must be charged when this function is called.
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's compiled call, retaining the complete machine result.
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
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
The declared parameters' actual by-value word fields.
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
Equations
Instances For
Instances For
Local slots are inferred from parameters and lexical value bindings.
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'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 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 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
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
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
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
The declared parameters' actual by-value word fields.
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
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 compiled body count, excluding its enclosing call overhead.
Equations
- One or more equations did not get rendered due to their size.
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
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
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
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
The declared parameters' actual by-value word fields.
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
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
Squaring returns a word and leaves all caller state unchanged.
The two calls compose through their returned values. Their private local frames do not appear in the continuation proof, and no separate specification of intermediate local-variable states is needed.
One array-fold step reuses the same square function through its contract. The accumulator and returned value are words; shared state is unchanged.
The program's semantic value is the sum of squares, independently of the caller's registers, memory and streams. The equation includes termination.
For encoded natural arguments the result is the encoded mathematical sum of squares; encoding retains the word model's modular arithmetic.
The fold step's body makes one actual square call. Its final addition and the enclosing call are counted by its caller, independently of this body equation.
Every completed body execution has the same count, obtained by adding the actual generated call blocks. No result specification enters this proof.
The exact count yields an independent conditional bound on invocations.
Termination is supplied separately by squaredNorm_contract.
Functional correctness supplies the invocation; the separate count proof identifies its cost without replaying the value computation.
Body time is a property of the same invocation as squaredNorm_eval,
not a supplied annotation. Each of its two completed calls takes 23 steps.