Documentation

Complexitylib.Circuits.BitString

Fixed-length bit strings and lists #

Circuits consume fixed-length functions BitString n = Fin n → Bool, while machine languages consume List Bool. This module makes List.ofFn the canonical serialization and provides round-trip lemmas in both directions.

The variable-length equivalence is already available from Mathlib as List.equivSigmaTuple : List Bool ≃ Σ n, BitString n.

Serialize a fixed-length bit string in increasing index order.

Equations
Instances For
    def Complexity.BitString.ofList (xs : List Bool) {n : } (h : xs.length = n) :

    Read a list of the specified length as a fixed-length bit string.

    Equations
    Instances For
      @[simp]

      Serialization preserves length: toList of an n-bit string has length n.

      @[simp]
      theorem Complexity.BitString.getElem_toList {n : } (x : BitString n) (i : Fin n) :
      x.toList[i] = x i

      Indexing into the serialized list agrees with the original bit string: x.toList[i] = x i.

      @[simp]
      theorem Complexity.BitString.toList_ofList (xs : List Bool) {n : } (h : xs.length = n) :
      (ofList xs h).toList = xs

      Round trip, list side: serializing ofList xs h recovers the original list xs.

      @[simp]

      Round trip, bit-string side: deserializing toList x recovers the original bit string x.

      @[simp]
      theorem Complexity.BitString.toList_inj {n : } {x y : BitString n} :
      x.toList = y.toList x = y

      Serialization is injective: two bit strings have equal toList iff they are equal.

      @[simp]
      theorem Complexity.BitString.toList_map {n : } (f : BoolBool) (x : BitString n) :
      (toList fun (i : Fin n) => f (x i)) = List.map f x.toList

      Serialization commutes with pointwise maps: toList (f ∘ x) = x.toList.map f.

      @[simp]

      Serialization sends Fin.append to list append: toList (x ++ y) = x.toList ++ y.toList.