Documentation

Complexity.Algorithms.WordRAM.RadixSort.Model

Stable binary radix sorting: mathematical specification #

The order is the unsigned order on encoded words. In particular this does not claim that sign-and-magnitude integer encodings are ordered as integers. The construction and proofs here are original; the executable native program is supplied separately.

Main definitions #

Main results #

Binary digit b of unsigned word v.

Instances For

    The stable subsequence of words whose digit b equals t.

    Instances For

      Stable zero/one partition at digit b.

      Instances For

        Apply the first bits binary radix passes, starting with the least significant bit.

        Instances For

          Every binary digit is below two.

          The native shift/remainder implementation reads precisely digit.

          A selection never increases the length.

          theorem Cslib.Algorithms.WordRAM.RadixSort.mem_select {b t v : ℕ} {xs : List ℕ} :
          v ∈ select b t xs ↔ v ∈ xs ∧ digit b v = t

          A selected word occurred in the original list and has the requested digit.

          theorem Cslib.Algorithms.WordRAM.RadixSort.select_append (b t : ℕ) (xs ys : List ℕ) :
          select b t (xs ++ ys) = select b t xs ++ select b t ys

          Appending an input word appends it to precisely its selected subsequence.

          A stable bit partition is a permutation of the input, including repeated words.

          Each pass keeps exactly the same number of words.

          All radix passes preserve the input multiset.

          theorem Cslib.Algorithms.WordRAM.RadixSort.partition_pairwise {b : ℕ} {xs : List ℕ} (hs : List.Pairwise (fun (u v : ℕ) => u % 2 ^ b ≤ v % 2 ^ b) xs) :
          List.Pairwise (fun (u v : ℕ) => u % 2 ^ (b + 1) ≤ v % 2 ^ (b + 1)) (partition b xs)

          A pass extends sortedness modulo 2^b to sortedness modulo 2^(b+1).

          theorem Cslib.Algorithms.WordRAM.RadixSort.passes_pairwise (bits : ℕ) (xs : List ℕ) :
          List.Pairwise (fun (u v : ℕ) => u % 2 ^ bits ≤ v % 2 ^ bits) (passes bits xs)

          The output is sorted on the low bits bits.

          theorem Cslib.Algorithms.WordRAM.RadixSort.passes_correct (bits : ℕ) (xs : List ℕ) (hbound : ∀ (v : ℕ), v ∈ xs → v < 2 ^ bits) :
          (passes bits xs).Perm xs ∧ List.Pairwise (fun (x1 x2 : ℕ) => x1 ≤ x2) (passes bits xs)

          Keys strictly below 2^bits are sorted in unsigned order after bits passes.