Documentation

CslibFrontier.Foundations.Data.BitString.PadBlocks

Fixed-width blocks of a padded bit list #

BitString.padBlocks n L x reads the bit list x as L / n consecutive blocks of n bits, block i being BitString.listBlock n x i padded with false past the end of x. Only the first (L / n) * n positions take part: the block count is the floor L / n, so when n ∤ L the last L % n positions below L are dropped, and bits of x at positions ≥ (L / n) * n are ignored. The reading is exact (padBlocks_getElem_apply reads every bit of x) when n ∣ L and x.length ≤ L.

BitString.toBlocks n x is the case L = x.length: the consecutive blocks of n bits of x, without an incomplete last block. A list made of whole blocks is the concatenation of its blocks (flatMap_ofFn_toBlocks), so cutting is injective on such lists (toBlocks_injOn).

Main definitions #

Main results #

The first L / n blocks of n bits of the bit list x: block i is listBlock n x i, padded with false past the end of x. The block count is the floor L / n, so positions ≥ (L / n) * n are dropped; the reading is exact when n ∣ L and x.length ≤ L.

@[simp]
theorem Cslib.BitString.length_padBlocks (n L : ℕ) (x : List Bool) :
(padBlocks n L x).length = L / n

padBlocks n L x has L / n blocks, whatever the length of x.

theorem Cslib.BitString.padBlocks_getElem_apply (n L : ℕ) (x : List Bool) (i : ℕ) (hi : i < L / n) (j : Fin n) :
(padBlocks n L x)[i] j = x.getD (i * n + ↑j) false

Bit j of block i of padBlocks n L x is bit i * n + j of x, or false past its end.

The consecutive blocks of n bits of a bit list, without an incomplete last block: padBlocks with the length of the list itself as the bound.

theorem Cslib.BitString.getElem?_toBlocks (n : ℕ) (x : List Bool) (i : ℕ) :
(toBlocks n x)[i]? = if i < x.length / n then some fun (j : Fin n) => x.getD (i * n + ↑j) false else none
theorem Cslib.BitString.toBlocks_eq_map_range (n : ℕ) (x : List Bool) :
toBlocks n x = List.map (fun (i : ℕ) (j : Fin n) => x.getD (i * n + ↑j) false) (List.range (x.length / n))

The blocks of a list, read position by position.

A list made of whole n-bit blocks is the concatenation of its blocks.

listRows (L / n) n x is the word view of padBlocks n L x.

The rows of a list are the word view of its blocks.

theorem Cslib.BitString.toBlocks_injOn {n : ℕ} {x y : List Bool} (hx : n ∣ x.length) (hy : n ∣ y.length) (h : toBlocks n x = toBlocks n y) :
x = y

Cutting is injective on lists whose lengths are multiples of n.

theorem Cslib.BitString.toBlocks_append {n : ℕ} {a : List Bool} (ha : n ∣ a.length) (b : List Bool) :
toBlocks n (a ++ b) = toBlocks n a ++ toBlocks n b
@[simp]
theorem Cslib.BitString.toBlocks_ofFn {n : ℕ} (hn : 0 < n) (m : BitString n) :