Documentation

CslibFrontier.Foundations.Data.BitString.Support

Support subsets of list-represented bit strings #

Views word : List Bool as its support subset {i : Fin n | ofList n word i = true} via Cslib.BitString.ofList, padding short lists with false and ignoring indices ≥ n.

Conversely, Cslib.BitString.indicatorList is the word of n bits that sets bit i exactly when i ∈ S; on words of length n the two conversions are inverse.

Main definitions #

Main results #

Convert a Boolean indicator list to its support subset in Fin n via BitString.ofList.

@[simp]
theorem Cslib.BitString.mem_supportOfList {n : ℕ} {word : List Bool} {i : Fin n} :
i ∈ supportOfList n word ↔ word.getD (↑i) false = true

Coordinate i : Fin n lies in supportOfList n word iff word.getD i.val false = true.

@[simp]
theorem Cslib.BitString.supportOfList_ofFn_decide {n : ℕ} (S : Finset (Fin n)) :
supportOfList n (List.ofFn fun (i : Fin n) => decide (i ∈ S)) = S

Round-trip from S : Finset (Fin n) through List.ofFn (fun i => decide (i ∈ S)).

theorem Cslib.BitString.ofFn_decide_mem_supportOfList {n : ℕ} {word : List Bool} (hw : word.length = n) :
(List.ofFn fun (i : Fin n) => decide (i ∈ supportOfList n word)) = word

On words of length n, List.ofFn (fun i => decide (i ∈ supportOfList n word)) is word.

theorem Cslib.BitString.supportOfList_injective_of_length {n : ℕ} {w₁ w₂ : List Bool} (hw₁ : w₁.length = n) (hw₂ : w₂.length = n) (heq : supportOfList n w₁ = supportOfList n w₂) :
w₁ = w₂

On words of exact length n, supportOfList n is injective.

On words of exact length n, #(supportOfList n word) = word.count true.

theorem Cslib.BitString.count_true_ofFn_decide_mem {m k : ℕ} {S : Finset (Fin m)} (hS : S.card = k) :
List.count true (List.ofFn fun (u : Fin m) => decide (u ∈ S)) = k

The indicator list of a k-element subset of Fin m has k entries true.

Indicator words #

The indicator word of S : Finset (Fin n): bit i records whether i ∈ S.

theorem Cslib.BitString.indicatorList_supportOfList {n : ℕ} {word : List Bool} (hw : word.length = n) :

Every word of length n is the indicator word of its support.

theorem Cslib.BitString.getD_indicatorList {n : ℕ} (S : Finset (Fin n)) (i : Fin n) :
(indicatorList S).getD (↑i) false = decide (i ∈ S)

Adding an element sets its bit.

theorem Cslib.BitString.indicatorList_erase {n : ℕ} (S : Finset (Fin n)) (i : Fin n) :

Removing an element clears its bit.

The indicator word of {i} is the zero word with bit i set.