Documentation

Complexity.Computability.Circuit.Boolean.SortingTrace

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 #

Main results #

References #

def Cslib.Circuits.Boolean.bitonicSortTraceCircuit.select {a t n m r : ℕ} (cs : Fin a → Fin t) (rs : Fin n → Fin m) :
Circuit signature (t * 2 + m * r) (a * 2 + n * r)

Select controls and records independently by free wiring.

Instances For

    Reverse a comparison layer, reading the saved decision and its complement.

    Instances For
      def Cslib.Circuits.Boolean.bitonicSortTraceCircuit.unhalves {a b n r : ℕ} (left : Circuit signature (a * 2 + n * r) (n * r)) (right : Circuit signature (b * 2 + n * r) (n * r)) :
      Circuit signature ((a + b) * 2 + (n + n) * r) ((n + n) * r)

      Reverse two independent circuits using the matching halves of their controls and records.

      Instances For
        def Cslib.Circuits.Boolean.bitonicSortTraceCircuit.unchain {a b n r : ℕ} (first : Circuit signature (a * 2 + n * r) (n * r)) (second : Circuit signature (b * 2 + n * r) (n * r)) :
        Circuit signature ((a + b) * 2 + n * r) (n * r)

        Preserve the first controls while undoing the second stage, then undo the first stage.

        Instances For
          theorem Cslib.Circuits.Boolean.bitonicSortTraceCircuit.pairs_comp {a b : ℕ} (flags : BitString a) (f : Fin b → Fin a) :
          pairs (flags ∘ f) = pairs flags ∘ f

          Undo the child merges before reversing the first comparison layer.

          Instances For

            Undo the final merge before reversing the two child sorts.

            Instances For

              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.