Documentation

CslibFrontier.Foundations.Data.BitString.List.Positions

Selecting and restoring positions of a bit list #

readPositions selects bits in a supplied order. restorePositions writes those selected bits back into a full list, retaining a reference list at unselected positions. Both operations are executable and total: out-of-range reads and missing selected bits are false, and restoring keeps the reference list's length. A repeated position uses its first occurrence in the selected list.

Main definitions #

Main results #

Read bits at the supplied positions, using false outside the list.

def Cslib.BitString.restorePositions (positions : List ℕ) (reference bits : List Bool) :

Restore selected bits, keeping the reference bits at all other positions. A repeated position uses its first occurrence, and missing selected bits are false.

@[simp]
theorem Cslib.BitString.length_readPositions (positions : List ℕ) (word : List Bool) :
(readPositions positions word).length = positions.length

Reading positions returns one bit per position.

@[simp]
theorem Cslib.BitString.length_restorePositions (positions : List ℕ) (reference bits : List Bool) :
(restorePositions positions reference bits).length = reference.length

Restoring positions preserves the reference list's length.

theorem Cslib.BitString.getD_readPositions_idxOf {positions : List ℕ} (word : List Bool) {j : ℕ} (hj : j ∈ positions) :
(readPositions positions word).getD (List.idxOf j positions) false = word.getD j false

The first occurrence of a selected position contains the original bit at that position.

theorem Cslib.BitString.getD_restorePositions (positions : List ℕ) (reference bits : List Bool) {j : ℕ} (hj : j < reference.length) :
(restorePositions positions reference bits).getD j false = if j ∈ positions then bits.getD (List.idxOf j positions) false else reference.getD j false

Restored bits come from the selected word at selected positions and the reference elsewhere.

theorem Cslib.BitString.restorePositions_readPositions (positions : List ℕ) (reference word : List Bool) (hlength : word.length = reference.length) (houtside : ∀ j < reference.length, j ∉ positions → word.getD j false = reference.getD j false) :
restorePositions positions reference (readPositions positions word) = word

Reading and restoring selected positions recovers a list that agrees with the reference at all unselected positions. Repeated or out-of-range selected positions do not affect the identity.