Reversing sorting circuits with saved comparison decisions #
The forward circuits in Sorting sort records once and retain the comparison controls.
This module reverses those decisions on new payloads using the same CSLib circuit representation.
Reversal inspects only the controls, so answer payloads may have a different width and need not
contain keys or unique identifiers.
A trace has BitonicSort.sortTraceSize d decisions stored as twice that many control wires,
followed by BitonicSort.arity d consecutive records. The reverse circuit expects complementary
control pairs; arbitrary pairs are not asserted to describe a permutation.
Reversal costs six gates per answer bit and comparison. These are circuit gate costs with free wiring, not bounds on retained storage or the circuit constructor's runtime.
Main definitions #
Cslib.Circuits.Boolean.bitonicUnsortCircuit: reverse saved decisions on new payloads.
Main results #
Cslib.Circuits.Boolean.eval_bitonicUnsortCircuit: reverse arbitrary paired decisions.Cslib.Circuits.Boolean.eval_bitonicUnsortCircuit_sort: restore transformed sorted records. The transformation is a semantic parameter; its implementation cost is not included.Cslib.Circuits.Boolean.size_bitonicUnsortCircuit: exact reversal gate count.
References #
- K. E. Batcher, Sorting Networks and Their Applications.
- Extends the sorting backend adapted from S. Schlesinger, Boolean circuit mass production formalization.
Undo the child merges before reversing the first comparison layer.
Instances For
Undo the final merge before reversing the two child sorts.
Instances For
The reverse merge implements reversal for every paired trace and payload.
The reverse sorter implements reversal for every paired trace and payload.
A reverse merge charges only switching; saved controls require no new negations.
A reverse sort charges only switching; saved controls require no new negations.
Reversing a sort uses six gates per payload bit and comparison.
Saved controls restore transformed records, even when the answer has a different width.