Recursive contract for the actual RAM merge-sort function #
The public measured contract combines independent functional recursion and
actual-time proofs. Initialization, both recursive calls and merge/copy-back
retain their original implementation, bounds and two-buffer frame. Functional
clients use recursive_total without choosing or threading unused time.
theorem
Ram.Source.Array.MergeSort.recursive_contract
{w control heapLimit selfFn : ℕ}
{functions : Program}
(hw : 2 ≤ w)
(lookup : functions[selfFn]? = some (function selfFn))
(xs : List (Word w))
:
(recursionSpec heapLimit selfFn w).Correct control functions heapLimit xs
The fixed function terminates on every represented array. Its ghost recursion argument is the list, ordered only by length; neither the budget nor the mathematical sorting operation is an executable instruction.
theorem
Ram.Source.Array.MergeSort.body_contract
{w control heapLimit selfFn : ℕ}
{functions : Program}
{base scratch : Word w}
{xs : List (Word w)}
(hw : 2 ≤ w)
(lookup : functions[selfFn]? = some (function selfFn))
:
The public preloaded-array body contract retains the final sorted array, scratch allocation, outside-memory frame, and both I/O observations.