Documentation

Complexity.Foundations.Data.BitString.List.Operations

Algebraic operations on lists of bits #

Finite bit strings and ordinary lists agree under pointwise XOR, Boolean dot products, basis vectors, subset sums and strict majority. List algorithms are total: an out-of-range basis index produces zeros, missing selectors are false, and pointwise XOR truncates to the shorter list. Collection XOR has a declared width and treats missing bits as false.

Main definitions #

Main results #

References #

Adapted from Probability/WordBits.lean and Crypto/Computational/GoldreichLevin/WordDecoder.lean and Crypto/Computational/Pseudoentropy/Boosting/Vote.lean and Crypto/Computational/GeneratorXor.lean on the cslib crypto branch at 5ff69ca93402e7c947208dc56396d6d86203ccd8.

theorem Cslib.BitString.ofFn_add {n : ℕ} (left right : BitString n) :
List.ofFn (left + right) = List.zipWith xor (List.ofFn left) (List.ofFn right)

Adding finite masks is exactly coordinatewise XOR of their word representations.

theorem Cslib.BitString.dotProduct_eq_foldl {n : ℕ} (left right : BitString n) :

A Boolean dot product is a pointwise AND followed by a parity fold on words.

Strict majority of a word of votes, choosing false on a tie.

Instances For

    Whether the correct votes fail to form a strict majority. This test uses natural arithmetic.

    Instances For

      The existing strict-majority operation is equivalently a comparison of vote counts.

      theorem Cslib.BitString.listStrictMajority_map {ι : Type} [DecidableEq ι] (indices : List ι) (hnodup : indices.Nodup) (vote : ι → Bool) :

      Listing each voting index once gives exactly finite-set strict majority.

      def Cslib.BitString.listSingle (dimension index : ℕ) :

      A coordinate mask, with all zeros when the index is outside the requested dimension.

      Instances For

        The coordinate-mask program agrees with the finite basis vector.

        All coordinate queries in their ordinary increasing order.

        Instances For
          theorem Cslib.BitString.listSingles_eq_ofFn (dimension : ℕ) :
          listSingles dimension = List.ofFn fun (index : Fin dimension) => List.ofFn (Pi.single index true)

          The coordinate masks list the finite basis vectors in increasing index order.

          def Cslib.BitString.listXorSelected (dimension : ℕ) (selector : List Bool) (rows : List (List Bool)) :

          XOR the rows selected by a word of bits. Missing selector bits are false. The accumulator starts at the requested dimension; rows of that dimension preserve its length.

          Instances For
            theorem Cslib.BitString.listXorSelected_eq_ofFn_sum {n k : ℕ} (selector : BitString k) (masks : Fin k → BitString n) :
            listXorSelected n (List.ofFn selector) (List.ofFn fun (i : Fin k) => List.ofFn (masks i)) = List.ofFn (∑ i : Fin k, if selector i = true then masks i else 0)

            On finite masks, the selector fold is exactly the sum of the selected rows.

            theorem Cslib.BitString.listXorSelected_eq_ofFn_sum_subset {n k : ℕ} (indices : Finset (Fin k)) (masks : Fin k → BitString n) :
            listXorSelected n (List.ofFn fun (i : Fin k) => decide (i ∈ indices)) (List.ofFn fun (i : Fin k) => List.ofFn (masks i)) = List.ofFn (∑ i ∈ indices, masks i)

            Selecting the characteristic word of a finite subset computes its mask sum.

            def Cslib.BitString.listXor (width : ℕ) (words : List (List Bool)) :

            XOR a collection at the supplied width, treating missing bits as false.

            Instances For
              @[simp]
              theorem Cslib.BitString.length_listXor (width : ℕ) (words : List (List Bool)) :
              (listXor width words).length = width

              The result has the declared width, also for an empty collection or short rows.

              theorem Cslib.BitString.listXor_eq_ofFn_sum {count : ℕ} (width : ℕ) (words : Fin count → List Bool) :
              listXor width (List.ofFn words) = List.ofFn (∑ i : Fin count, ofList width (words i))

              The list program agrees exactly with the sum of the finite bit-string views.

              theorem Cslib.BitString.listXor_pair (m : ℕ) (u v : List Bool) :

              Two-word listXor agrees with addition in BitString m.

              @[simp]

              Fixed-width view of a two-word listXor.

              Two-word listXor is commutative.

              theorem Cslib.BitString.getD_listXor_pair (m : ℕ) (u v : List Bool) (i : ℕ) (hi : i < m) :
              (listXor m [u, v]).getD i false = (u.getD i false ^^ v.getD i false)

              Below the width m, each bit of a two-word listXor is the XOR of the corresponding bits of the words, with missing bits read as false.

              theorem Cslib.BitString.getD_listRow_zero (m : ℕ) (u : List Bool) (i : ℕ) (hi : i < m) :
              (listRow m 0 u).getD i false = u.getD i false

              Below the width m, row 0 of a word agrees bitwise with the word itself, with missing bits read as false.