A complete linear merge on the actual RAM machine #
The shared declaration in Array.Merge.Function uses the same fixed merge loop
as the reusable contract. Its input consists of two preloaded source arrays and a disjoint,
already allocated destination. The sources may overlap each other. The block
theorem explicitly starts at PC 1 and includes halt, not an implicit loader
or allocator. The bitwise-OR guard does not add the two counts in a word.
The result theorem observes standard List.merge in the halted target heap,
with both sources, destination-external heap words, I/O, and higher user
registers preserved by that same run. Sortedness is needed only by the final
sorted-merge theorem, not by the general machine execution theorem.
Function.merge executes the typed three-array function and returns its actual
shared state. Its mathematical contents theorem uses ordinary List.merge;
the separate count includes both the inner core call and the outer typed call.
Equations
Instances For
Observe the shared source loop as a standalone block. The callable interface below uses the same declaration, not another copy of its source.
Equations
- Ram.Examples.Merge.named = { registers := 5, declarations := [], main := Ram.Source.Array.Merge.mergeFunctions.function.mergeCore.body }
Instances For
All output observations are attached to one completed target execution. Heap preservation is stated inside the source-visible heap; compiler-private stack/control storage is not misidentified as user array storage.
- destination_array : ArrayRep finish.mem destination (Source.Array.unsignedMerge xs ys)
- frame (address : Word w) : BitVec.toNat address < heapLimit → BitVec.toNat address < BitVec.toNat destination ∨ BitVec.toNat destination + xs.length + ys.length ≤ BitVec.toNat address → finish.mem address = entry.mem address
Instances For
The source contract and existing checked compiler supply the complete target execution. The extra one is the actual halt; PC 1 excludes the unused input-header prologue from both the execution and its claimed budget.
General merge works even for unsorted source arrays and permits overlap
between them. Its actual result is standard List.merge, with unchanged
sources, a destination frame, final pointers/counts, and retained caller I/O.
When both source lists are sorted, the very same halted heap contains a sorted permutation of their concatenation. The mathematical bridge is the existing standard merge theorem, not an added sortedness assumption on the general machine execution rule.
Three existing represented arrays admit a merge into the independent destination. The two sources need not be disjoint from each other.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Termination of the typed wrapper and its core follows from budget-free correctness. Stack capacity pays for both live function frames.
Execute the three-array function and return its actual shared state. The lists and safety proofs are erased; no result or time budget is an input.
Equations
- Ram.Examples.Merge.Function.merge left right destination heapLimit entry safe hstack = (Ram.Source.Array.Merge.mergeFunctions.applyState.merge left right destination heapLimit entry ⋯).2
Instances For
Ordinary array representations specify the state produced by the actual typed application. Only the destination may change; both sources and I/O survive.
The actual destination contents equal standard list merge. Sortedness is not required for this equation about the implementation.
Upstream merge properties give a sorted permutation of both inputs, without reopening the implementation's loop, bindings or calling convention.
The complete typed invocation includes both core and wrapper calls, their returns, and the final halt. Preloading remains outside this count.