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.

Extend a fixed-length bit string to a total assignment by setting every out-of-range variable to false. This is the canonical semantic bridge from typed Boolean functions to formula and branching-program syntax.

Equations
Instances For
    @[simp]
    theorem Complexity.BitString.toTotal_apply {n : } (x : BitString n) (i : Fin n) :
    x.toTotal i = x i

    The total extension agrees with the original bit string on every in-range index.

    theorem Complexity.BitString.toTotal_of_lt {n : } (x : BitString n) (i : ) (h : i < n) :
    x.toTotal i = x i, h

    An explicit natural index below the arity is read from the original bit string by the total extension.

    theorem Complexity.BitString.toTotal_of_le {n : } (x : BitString n) (i : ) (h : n i) :

    Every out-of-range index is false in the canonical total extension.

    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.