Replaying and reversing bitonic sorting decisions #
Record one Boolean for each comparison in the existing bitonic algorithm. These decisions route arbitrary payloads and can be replayed in reverse to recover their original positions. In particular, a pointwise transformation of sorted records can be restored without sorting again or attaching unique identifiers. Equal keys need no special hypothesis: the trace records this sorter's actual choices, including the reversal of descending ties.
The trace definitions specify the decisions; they are not an optimized implementation of sorting with a trace. Circuit realizations must share comparisons and account for retained controls separately. The exact trace lengths below count Boolean decisions, not execution time.
Main definitions #
Cslib.BitonicSort.mergeTrace,Cslib.BitonicSort.sortTrace: record comparison decisions.Cslib.BitonicSort.routeSort: replay saved decisions on arbitrary payloads.Cslib.BitonicSort.unrouteSort: reverse those decisions.
Main results #
Cslib.BitonicSort.unrouteSort_routeSort,Cslib.BitonicSort.routeSort_unrouteSort: replay and reversal are mutually inverse for every trace, even one not obtained by sorting.Cslib.BitonicSort.routeSort_sortTrace: replay agrees with the existing bitonic algorithm.Cslib.BitonicSort.unrouteSort_comp_sort: restore pointwise transformed sorted records.Cslib.BitonicSort.four_mul_sortTraceSize: exact number of retained comparison decisions.
References #
Number of decisions retained by bitonic merge.
Instances For
Number of decisions retained by bitonic sorting.
Instances For
Extract merge controls in the order: current layer, left child, right child.
Instances For
Extract sort controls in the order: left sort, right sort, final merge.
Instances For
Saved merge decisions do not inspect the payload.
Reverse a sort's saved decisions after a pointwise transformation. Neither keys nor payloads need be distinct, and the transformed payload may have a different type.
Reversing saved decisions commutes with arbitrary pointwise transformations.
Reversal reads the same original position for every payload type. This is deliberately not a simp lemma: rewriting the identity payload would expand the right-hand side again.
Pointwise relations between two payload arrays survive reversal by the same saved trace.
Transfer specifications from sorted positions to literal original positions.
A merge retains one decision for each comparator, or d * 2^d / 2 decisions.
A sort retains d * (d + 1) * 2^d / 4 decisions.