Standard merge specifications for RAM arrays #
unsignedMerge is only an abbreviation for the standard List.merge, with
unsigned word comparisons and left priority for equal heads. The step lemmas
do not require sorted inputs. Sortedness is used only to derive SortedPerm
and equality with the standard sorting functions.
These are mathematical specifications, not uncharged RAM operations.
Standard merge with the unsigned comparison used by the RAM program.
Equations
- Ram.Source.Array.unsignedMerge xs ys = xs.merge ys fun (a b : Ram.Word w) => decide (Ram.Source.Array.unsignedLE a b)
Instances For
Equal heads are emitted from the left input first.
The right head is emitted only when it is strictly smaller.
Emit the left cursor's element. The comparison premise is vacuous when the right cursor is past the end; no sortedness premise is needed.
Standard merge preserves both input multisets, even for unsorted inputs.
Sorted inputs give a sorted result by mathlib's existing merge theorem.
Merge independently verified sorted outputs into a sorted permutation of the concatenation of their original inputs.
The standard merge sort satisfies the same implementation-independent sorting specification as insertion sort.
A verified sorted permutation also equals standard merge sort.
Merging sorted lists returns the canonical sorting of their concatenation.
The same merge result agrees with standard merge sort.