Documentation

Complexity.Computability.Circuit.Boolean.Comparison

Comparing and selecting words #

Circuits over the De Morgan basis that compare words of w bits, read as numbers with the least significant bit first (BitString.equivFin), and select one of two words.

Zero-width words and keys are allowed; the comparator of empty words returns true. Pairwise keyed selection preserves the first payload on equal keys.

A balanced tree of keyed minimums selects a record with the least key among many (Cslib.Circuits.Boolean.tournamentCircuit).

Main definitions #

Main results #

References #

Adapted from Samuel Schlesinger's earlier Complexitylib modules Circuits/{Multiplexer,BinaryComparison,BinaryMinimum,KeyedMinimum}.

The multiplexer #

def Cslib.Circuits.Boolean.muxBit {w : ℕ} (i : Fin w) :
Formula signature (1 + (w + w) + 1)

Bit i of the multiplexer, (c ∧ a i) ∨ (¬c ∧ b i), on the control c, the words a and b, and the negated control.

Instances For

    The multiplexer: reading a control bit c and words a and b, it outputs a when c is true and b otherwise.

    Instances For
      @[simp]
      theorem Cslib.Circuits.Boolean.eval_muxCircuit {w : ℕ} (c : Bool) (a b : BitString w) :
      (muxCircuit w).eval interpretation (Fin.append (fun (x : Fin 1) => c) (Fin.append a b)) = if c = true then a else b

      The comparator #

      One step of the comparator, on le, x k, y k and ¬x k: (¬x k ∧ y k) ∨ (le ∧ (¬x k ∨ y k)).

      Instances For

        One step of the comparator: from whether x ≤ y on the bits below k, and from x k and y k, whether x ≤ y on the bits up to k.

        Instances For
          theorem Cslib.Circuits.Boolean.eval_leStep (b c d : Bool) :
          leStep.eval interpretation (Fin.append (fun (x : Fin 1) => b) ![c, d]) = fun (x : Fin 1) => !c && d || b && (!c || d)
          def Cslib.Circuits.Boolean.lowBits (w : ℕ) :
          Fin (w + w) → Fin (w + 1 + (w + 1))

          The first w bits of each of two words of w + 1 bits.

          Instances For
            def Cslib.Circuits.Boolean.topBits (w : ℕ) :
            Fin 2 → Fin (w + 1 + (w + 1))

            The last bit of each of two words of w + 1 bits.

            Instances For

              The comparator: reading words x and y of w bits, it outputs whether x ≤ y as numbers with the least significant bit first.

              Instances For

                The minimum and the keyed minimum #

                The minimum: reading words x and y of w bits, it outputs the smaller, x on ties.

                Instances For
                  def Cslib.Circuits.Boolean.keyBits (k p : ℕ) :
                  Fin (k + k) → Fin (k + p + (k + p))

                  The keys of two records.

                  Instances For

                    The keyed minimum: reading two records of a key of k bits followed by a payload of p bits, it outputs the one with the smaller key, the first on ties.

                    Instances For