Reusing nested temporary storage across source calls #
Implementation.make allocates one result cell outside the temporary scopes.
Each call to Implementation.work allocates two nested temporary arrays, reads
the outer temporary array after the inner scope has released its storage, and
writes the result cell. A return from inside the outer scope also releases its
temporary storage. The returned result is longer-lived than either scratch
array; no copied host implementation or algorithm-specific lowering is used.
The mathematical result depends on whether an iteration and a nonempty read occur, while the required temporary capacity is independent of the iteration count. Source correctness and termination do not require a RAM capacity or instruction budget.
Source-visible locals, without compiler completion slots.
Equations
Instances For
Equations
Instances For
Apply a chosen mathematical contract to the native block action. Continuations see ordinary mutable outputs; proved frames restore the fixed captures.
Fold an actual source invocation back to its named ordinary-argument observation.
This actual source block, retaining its loop or allocation-scope semantics.
Equations
Instances For
Coordinate conversion for composing this named observation.
Restore complete lexical coordinates without unfolding proof fields.
The named function's actual independently interpreted source body.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Author relations use visible locals and actual endpoint heaps. The existing action still returns its full locals and actual source control.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Compose the actual body specification with safe scratch release. Surviving locals and return values stay rooted; current retained contents are not rolled back.
Enter this source boundary with empty private completion slots.
Equations
Instances For
The actual source block observed with ordinary named local inputs.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The checked representation of this field at its current heap.
Equations
Instances For
Local completion does not produce an enclosing source return.
The ordinary mutable locals of this source loop.
Equations
Instances For
Source-visible locals, without compiler completion slots.
Equations
Instances For
The source program's declared first-order signatures.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Observe the same body and its actual local completion slot. Mapping the result neither changes source control nor performs heap cleanup.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Apply a supplied source contract with ordinary named arguments and its actual returned value and final heap. No callee body or new contract is inferred.
Complete lexical coordinates for this source block.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A supplied body contract may change the heap or complete the local block. Continuing and completed results have separate mathematical postconditions.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Coordinate conversion for composing this named observation.
The checked representation of this field at its current heap.
Equations
Instances For
Relational total correctness with ordinary mutable parameters and fixed captures. The existing block contract retains both actual heaps and excludes faults.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Introduce named mutable variables directly, without unpacking internal coordinates.
Source-visible locals, without compiler completion slots.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The actual source block observed with ordinary named local inputs.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The source-named mathematical value of this local.
Equations
- Complexity.Language.Examples.Scope.Implementation.Source.make_loop1.model_count whileState✝ = whileState✝.2.2.2.2
Instances For
Author relations use visible locals and actual endpoint heaps. The existing action still returns its full locals and actual source control.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Apply the same completion contract at independently named source inputs. The actual action has canonical arguments, so native specification lookup does not need to infer a tuple from its projections.
Actual visible coordinates reconstruct the named mathematical locals.
The source-named mathematical value of this local.
Equations
- Complexity.Language.Examples.Scope.Implementation.Source.make_loop1.model_n whileState✝ = whileState✝.2.2.2.1
Instances For
Budget-free total correctness with ordinary source parameters and relational initial/final heap postconditions. This is the existing source function contract.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Resume from actual mutable locals; immutable captures are preserved by the source frame.
The source contract is equivalent to ordinary curried preconditions and successful result/heap postconditions, including termination and absence of faults.
Apply the same completion contract at independently named source inputs. The actual action has canonical arguments, so native specification lookup does not need to infer a tuple from its projections.
Apply a supplied source contract with ordinary named arguments and its actual returned value and final heap. No callee body or new contract is inferred.
Equations
Instances For
Ordinary arguments and the actual result observed in their real source heaps. This interface does not assert the existence of a total mathematical model.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The original full scratch safety condition after actual frame restoration. Ancestor slots are empty at entry; the current completion remains a checked root.
Actual finite execution fixes every ancestor completion slot. This restores full locals; it does not discard roots or assume successful cleanup.
Apply the visible completion contract, reconstructing the full output from this same actual execution rather than guessing hidden coordinates.
Restore complete lexical coordinates without unfolding proof fields.
Complete identity observations coincide with the proved coordinate equivalence.
Ordinary arguments and the actual result observed in their real source heaps. This interface does not assert the existence of a total mathematical model.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A named mathematical constructor has the corresponding visible coordinates.
Actual finite execution fixes every ancestor completion slot. This restores full locals; it does not discard roots or assume successful cleanup.
Prove the actual body contract using mathematical locals and the real completion value. Continuing and completed outcomes retain the actual heap.
Restore the same full locals, retaining the ancestor slots from entry.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Close the actual scratch boundary from visible body relations. Roots are checked before reclamation; the author's postcondition uses the heap after that same reclamation. Private slots are restored by the body frame.
The source-visible values retain only roots from this heap.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The actual declared argument environment, constructed from ordinary source parameters. This is proof-side parameter transport, not an additional runtime operation.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Local completion exits through the actual next false-guard step.
This named source function's index in its declared signature table.
Equations
Instances For
Apply a chosen mathematical contract to the native block action. Continuations see ordinary mutable outputs; proved frames restore the fixed captures.
Complete lexical coordinates for this source block.
Equations
Instances For
Apply the visible completion contract, reconstructing the full output from this same actual execution rather than guessing hidden coordinates.
Lossless proof coordinates, including fixed and shadowed captures.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Prove the actual guard contract directly from ordinary mathematical locals. The input-coordinate and output-representation transport is shared.
Prove a named loop from independent mathematical guard and body contracts. Actual guard effects and early body returns are retained; only normal iterations decrease.
The actual parsed lexical body, with its enclosing return type.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Compose mathematical contracts at the actual heaps before and after an effectful guard. Continuing rounds decrease from the state before the guard; a false guard or a completed body establishes the final condition.
The source-named mathematical value of this local.
Equations
- Complexity.Language.Examples.Scope.Implementation.Source.make_loop1.model_out whileState✝ = whileState✝.2.1
Instances For
A complete identity local view is exactly the original visible coordinates. Raw handles contribute equality only; contents remain heap-dependent contracts.
Source lexical immutability preserves these captures on every actual exit.
Prove a named loop from independent mathematical guard and body contracts. Actual guard effects and early body returns are retained; only normal iterations decrease.
The actual value-producing guard, reevaluated on every iteration.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Project source-visible coordinates from the unchanged full locals.
Equations
Instances For
Compose an increasing count and a transitive heap frame from the actual guard and body contracts. The guard preserves the count and heap; normal body steps increase the count by one. Array effects and the exit consequence remain supplied mathematical facts, without a runtime budget.
The actual source block observed with ordinary named local inputs.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Apply a predicate, postcondition or bound with ordinary source parameters to the actual argument environment. No new contract or execution is introduced.
Equations
Instances For
Lossless proof coordinates, including fixed and shadowed captures.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Resume from actual mutable locals; immutable captures are preserved by the source frame.
Reuse an existing visible body contract across this actual scratch boundary. The consequences prove non-escape and the desired observations after trimming the current final heap, without rebuilding the body proof.
The named function's actual independently interpreted source body.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Prove the ordinary-parameter source contract with a total-correctness triple for the same action. The ghost initial heap equals the actual entry heap; successful results use the actual final heap, and faults are excluded.
The source-named mathematical value of this local.
Equations
- Complexity.Language.Examples.Scope.Implementation.Source.make_loop1.model_remaining whileState✝ = whileState✝.1
Instances For
Coordinate conversion for composing this named observation.
Apply a chosen mathematical contract to the native block action. Continuations see ordinary mutable outputs; proved frames restore the fixed captures.
Author relations use visible locals and actual endpoint heaps. The existing action still returns its full locals and actual source control.
Equations
- One or more equations did not get rendered due to their size.
Instances For
One source-body equation in ordinary monadic notation; named callees remain opaque.
Continuing completion coordinates recover the same full entry.
Coordinate conversion for composing this named observation.
The same source action, without an asserted total mathematical model.
Equations
Instances For
Author relations use visible locals and actual endpoint heaps. The existing action still returns its full locals and actual source control.
Equations
- One or more equations did not get rendered due to their size.
Instances For
One source-body equation in ordinary monadic notation; named callees remain opaque.
The named function's actual partial source action, with ordinary typed arguments and an explicitly supplied shared heap.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Prove this actual loop with fixed captures and well-founded progress on its mutable locals. Only normal body exits must decrease; guard effects, returns and faults retain their real heap.
Actual finite execution fixes every ancestor completion slot. This restores full locals; it does not discard roots or assume successful cleanup.
Apply the same completion contract at independently named source inputs. The actual action has canonical arguments, so native specification lookup does not need to infer a tuple from its projections.
The original full scratch safety condition after actual frame restoration. Ancestor slots are empty at entry; the current completion remains a checked root.
Enter this source boundary with empty private completion slots.
Equations
Instances For
The current local result; actual source control is unchanged.
Equations
Instances For
Introduce named mutable variables directly, without unpacking internal coordinates.
Extract a field's observation without source-coordinate transport.
Actual finite execution fixes every ancestor completion slot. This restores full locals; it does not discard roots or assume successful cleanup.
Local completion does not produce an enclosing source return.
Apply the visible completion contract, reconstructing the full output from this same actual execution rather than guessing hidden coordinates.
Apply the same completion contract at independently named source inputs. The actual action has canonical arguments, so native specification lookup does not need to infer a tuple from its projections.
Reuse an existing visible body contract across this actual scratch boundary. The consequences prove non-escape and the desired observations after trimming the current final heap, without rebuilding the body proof.
The actual source block observed with ordinary named local inputs.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Prove this actual loop with fixed captures and well-founded progress on its mutable locals. Only normal body exits must decrease; guard effects, returns and faults retain their real heap.
Extract a field's observation without source-coordinate transport.
This named source function's index in its declared signature table.
Equations
Instances For
Coordinate conversion for composing this named observation.
Author relations use visible locals and actual endpoint heaps. The existing action still returns its full locals and actual source control.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Actual finite execution fixes every ancestor completion slot. This restores full locals; it does not discard roots or assume successful cleanup.
Actual finite execution fixes every ancestor completion slot. This restores full locals; it does not discard roots or assume successful cleanup.
Apply the same completion contract at independently named source inputs. The actual action has canonical arguments, so native specification lookup does not need to infer a tuple from its projections.
The actual parsed lexical body, with its enclosing return type.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Local completion does not produce an enclosing source return.
The actual source block observed with ordinary named local inputs.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Apply the visible completion contract, reconstructing the full output from this same actual execution rather than guessing hidden coordinates.
Coordinate conversion for composing this named observation.
This actual source block, retaining its loop or allocation-scope semantics.
Equations
Instances For
Continuing completion coordinates recover the same full entry.
The original full scratch safety condition after actual frame restoration. Ancestor slots are empty at entry; the current completion remains a checked root.
Author relations use visible locals and actual endpoint heaps. The existing action still returns its full locals and actual source control.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A supplied actual guard contract, expressed through mathematical indices. Each output observation is made at the real final heap.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Close the actual scratch boundary from visible body relations. Roots are checked before reclamation; the author's postcondition uses the heap after that same reclamation. Private slots are restored by the body frame.
The actual declared argument environment, constructed from ordinary source parameters. This is proof-side parameter transport, not an additional runtime operation.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Prove this actual loop using a related mathematical state and well-founded progress. Fixed captures are retained by the generated execution frames.
Observe the same guard in mathematical coordinates. Control and the actual final heap are untouched; this is not another source implementation.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Compose the actual loop from mathematical local contracts. The supplied guard preserves the index and heap; only a continuing body needs descent. The step relation describes mathematical progress, not a pure implementation.
Extract a field's observation without source-coordinate transport.
Equations
Instances For
Prove the ordinary-parameter source contract with a total-correctness triple for the same action. The ghost initial heap equals the actual entry heap; successful results use the actual final heap, and faults are excluded.
Apply the same completion contract at independently named source inputs. The actual action has canonical arguments, so native specification lookup does not need to infer a tuple from its projections.
Fixed lexical captures, independent of the shared heap.
Equations
Instances For
The source-named mathematical value of this local.
Equations
- Complexity.Language.Examples.Scope.Implementation.Source.make_loop1.model_value whileState✝ = whileState✝.2.2.1
Instances For
Relate this actual loop to a mathematical state without private completion slots. Only a continuing body supplies another invariant and a decrease; a local result exits through the real next guard.
The current local result; actual source control is unchanged.
Equations
Instances For
Source lexical immutability preserves these captures on every actual exit.
The current local result; actual source control is unchanged.
Equations
- Complexity.Language.Examples.Scope.Implementation.Source.make_loop1.pending locals✝ = locals✝.2.2.1
Instances For
Assemble mathematical locals using source-variable parameter names.
Equations
Instances For
Lossless proof coordinates, including fixed and shadowed captures.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The actual source block observed with ordinary named local inputs.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The source-visible values retain only roots from this heap.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The source contract is equivalent to ordinary curried preconditions and successful result/heap postconditions, including termination and absence of faults.
Introduce named mutable variables directly, without unpacking internal coordinates.
Resume from actual mutable locals; immutable captures are preserved by the source frame.
The actual parsed lexical body, with its enclosing return type.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The actual guard leaves the private completion slots empty. Only the source-visible locals and heap may change before the loop body.
Continuing completion coordinates recover the same full entry.
This actual source block, retaining its loop or allocation-scope semantics.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Restore the same full locals, retaining the ancestor slots from entry.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Enter this source boundary with empty private completion slots.
Equations
Instances For
The same source action, without an asserted total mathematical model.
Equations
Instances For
The real guard's contract mentions only source-visible inputs and outputs. Its compiler-slot frame is supplied by the generated bridge.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Apply the visible completion contract, reconstructing the full output from this same actual execution rather than guessing hidden coordinates.
Complete lexical coordinates for this source block.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The checked representation of this field at its current heap.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Extract a field's observation without source-coordinate transport.
Project source-visible coordinates from the unchanged full locals.
Equations
Instances For
Rearrange complete identity locals into their actual visible source order.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Compose the actual body specification with safe scratch release. Surviving locals and return values stay rooted; current retained contents are not rolled back.
Coordinate conversion for composing this named observation.
Relational total correctness with ordinary mutable parameters and fixed captures. The existing block contract retains both actual heaps and excludes faults.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Project source-visible coordinates from the unchanged full locals.
Equations
Instances For
The named function's actual partial source action, with ordinary typed arguments and an explicitly supplied shared heap.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Local completion does not produce an enclosing source return.
The source-visible values retain only roots from this heap.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Local completion does not produce an enclosing source return.
Ordinary mathematical values of the loop's lexical source bindings.
Equations
Instances For
Budget-free total correctness with ordinary source parameters and relational initial/final heap postconditions. This is the existing source function contract.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Restore the same full locals, retaining the ancestor slots from entry.
Equations
Instances For
The checked representation of this field at its current heap.
Equations
Instances For
Local completion does not produce an enclosing source return.
The finite table of actual named source bodies.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The checked representation of this field at its current heap.
Equations
Instances For
The actual source block observed with ordinary named local inputs.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Source lexical immutability preserves these captures on every actual exit.
Relational total correctness with ordinary mutable parameters and fixed captures. The existing block contract retains both actual heaps and excludes faults.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The same complete environment, grouped by source mutability.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Restore complete lexical coordinates without unfolding proof fields.
Extract a field's observation without source-coordinate transport.
Apply a predicate, postcondition or bound with ordinary source parameters to the actual argument environment. No new contract or execution is introduced.
Equations
Instances For
Apply the visible completion contract, reconstructing the full output from this same actual execution rather than guessing hidden coordinates.
Restore grouped locals using the checked coordinate projection laws.
A single call either writes the value read from its initialized scratch array or leaves the result cell unchanged when that array is empty.
Equations
Instances For
One permanent result cell and two simultaneously allocated scratch arrays suffice independently of how many calls the loop performs.
Equations
- Complexity.Language.Examples.Scope.heapLimit entryCursor n = entryCursor + 1 + 2 * n
Instances For
The inner body allocates its actual scratch array and then falls through. Its contract mentions only the original source variables and actual heap.
A nested allocation-only scope releases its entire fresh suffix. Both borrowed handles were live on entry, so neither is an escaping temporary.
The actual outer body reads its still-live temporary after inner cleanup. The ordinary contents contract describes the write to the surviving output.
Returning from the outer scope preserves the output's updated contents while releasing the temporary object from the actual final heap.
The declared worker terminates and updates the ordinary contents of its borrowed output. No word width, memory capacity or time budget is assumed.
A source call reuses the worker's mathematical contents contract at its actual entry and final heaps, through the generated ordinary-argument bridge.
Only the remaining call count changes in the loop. The first completed nonempty call sets the result; all later calls preserve that same value.
Equations
Instances For
The newly initialized output satisfies the loop invariant before any call.
A real call's contents contract advances the loop invariant. Termination
uses the ordinary decrease of remaining, separately from machine cost.
At loop exit the result has the ordinary mathematical array contents.
The loop's source variables, selected by name. The buffer field records its handle; the invariant separately describes its contents at the current heap.
Equations
- Complexity.Language.Examples.Scope.loopModel out count n value remaining = Complexity.Language.Examples.Scope.Implementation.Source.make_loop1.mkModel remaining out value n count
Instances For
The actual guard decides positivity without changing the mathematical locals or heap. Its contract accepts any additional entry-heap condition.
The worker's actual contents contract proves one mathematical loop round. Continuing rounds update the invariant; a local return supplies the final result.
The loop's actual guard preserves its full lexical state and decides the ordinary positivity test used by the termination argument.
A real loop body calls the scoped worker and decreases only the remaining count. Its contents contract and complete local update also serve the separate resource proof; neither needs to re-prove the worker's behavior.
Lean's existing well-founded measure proves termination of the actual source loop. The relation concerns mathematical progress, not a machine budget; its body contract carries the current heap through every real call.
One source declaration allocates the surviving result and repeatedly uses the same nested scratch scopes. Its successful result has the ordinary array contents, for every count and every initial heap, including both empty cases.
The mathematical contract supplies actual finite source evaluation and the retained output contents without a separate termination or budget proof.
The same named declaration's source contract is ready for the separate range, capacity, instruction-count and physical-space proofs.