Proofs: Proxmap sort
These are the human proofs of Proxmap sort, at full length.
Proxmap sort sorts its input and is stable full
This proof shows: correctness, stability.
Let be non-decreasing with values in . Let be the hit counts of line L1, , and . The ranges are disjoint, in the order of , and cover , because and .
Invariant. Before iteration of line L4, for each : ; the cells hold the keys among with , in non-decreasing order, with equal keys in input order; and the other cells of are empty.
Initialization. and is empty, so the invariant holds for .
Maintenance. Let and . The keys of with class number , and is one more key of class , so and the cell of line L5 lies in ; it is empty by the invariant. Line L6 moves down while and , and each move shifts one cell right into the empty cell . This is one step of insertion sort on the sorted run : when the loop stops, every key in is greater than , and or . Line L7 puts at . The run is then sorted and has length . Equal keys keep input order, since comes after all earlier keys in input order and it does not pass a key that is equal to it. No cell outside is read or written, because at all times. With increased in line L5, the invariant holds for .
After the loop. With , each equals , so each is full and holds the keys of class in sorted, stable order. Take two cells . If they are in the same , then . If and with , then , and since is non-decreasing, is impossible, so . Two equal keys have the same class, so they are in the same and in input order. Line L8 copies to .