Proofs: Hyperquicksort
These are the human proofs of Hyperquicksort, at full length.
Hyperquicksort sorts in processor order full
This proof shows: correctness.
Let . For a processor number and , write for bit of . Call the rounds by their dimension , which runs from down to . Let be the subcube of dimension that contains : the processors whose numbers agree with on the bits above bit .
Lemma 1. Keys are kept and lists stay sorted
Proof. Line L1 sorts each list. In a round, a pair splits its two sorted lists into four sorted parts, and lines L6 and L7 put each key into exactly one of the two merged lists. Merging two sorted lists gives a sorted list. Processors not in a pair with a pivot keep their lists. So after every round, the multiset of all keys is the input, and each list is sorted.
Lemma 2. Keys stay inside the subcubes of later rounds
After round , and in all later rounds, keys move only between processors that agree on bits and above.
Proof. In round , keys move only between and , which differ only in bit . If , they agree on bits and above.
Lemma 3. Round i splits each subcube by its pivot
Let be the pivot of the subcube in round . After round , every key on a processor of with bit equal to is at most , and every key on a processor of with bit equal to is greater than .
Proof. The processors of with bit equal to are paired with those with bit equal to by , and every processor of is in exactly one pair. By lines L6 and L7, after the round the lower processor of each pair holds exactly the keys at most of the pair, and the upper one holds exactly the keys greater than . If no processor of has keys, there is nothing to show.
Theorem. The output is sorted in processor order
At the end, each list is sorted, and for every key on processor is at most every key on processor .
Proof. By Lemma 1 the lists are sorted and hold the input keys. Let and let be the highest bit where they differ, so and , and both lie in the subcube . By Lemma 3, right after round , the processors of with bit equal to hold only keys at most the pivot of , and those with bit equal to hold only keys greater than . By Lemma 2, all later moves are between processors that agree on bit and above, so the keys of the lower half of stay in the lower half, and the same for the upper half. So at the end, every key on is at most , and every key on is greater than .