Documentation

CslibFrontier.DataStructure.PackedLane

Fixed-width packed W-bit word lanes #

A natural-number word packs consecutive W-bit lanes in little-endian order, with lane j extracted via (word >>> (j * W)) &&& (2 ^ W - 1) (laneGet). This module provides the shared pure Nat bitwise/radix laws for laneGet used by packed SWAR search trees and character tries: division-and-modulus and bit-level characterizations, lane extensionality, base-2 ^ W expansion of bounded words (word_eq_sum_laneGet), and bounded-word digit injectivity (eq_of_forall_laneGet_eq_of_lt). These are pure natural-number identities and make no machine word-width or runtime claims.

Main definitions #

Main results #

Extract the W-bit lane at index j from word.

theorem Cslib.DataStructure.laneGet_eq_div_mod (W word j : ℕ) :
laneGet W word j = word / 2 ^ (j * W) % 2 ^ W

Division-and-modulus characterization of laneGet.

theorem Cslib.DataStructure.laneGet_lt (W word j : ℕ) :
laneGet W word j < 2 ^ W

Every extracted W-bit lane is strictly less than 2 ^ W.

theorem Cslib.DataStructure.testBit_laneGet (W word j b : ℕ) :
(laneGet W word j).testBit b = (decide (b < W) && word.testBit (j * W + b))

Bit b of laneGet W word j is word.testBit (j * W + b) when b < W, and false otherwise.

theorem Cslib.DataStructure.eq_of_forall_laneGet_eq {W a b : ℕ} (hW : 0 < W) (h : ∀ (k : ℕ), laneGet W a k = laneGet W b k) :
a = b

Two words are equal when all of their W-bit lanes (0 < W) agree.

theorem Cslib.DataStructure.laneGet_sum_mul_pow {W n : ℕ} {f : ℕ → ℕ} (hf : ∀ j < n, f j < 2 ^ W) (k : ℕ) :
laneGet W (∑ j ∈ Finset.range n, f j * 2 ^ (j * W)) k = if k < n then f k else 0

Extracting lane k from a sum of n bounded W-bit lanes recovers f k for k < n and 0 otherwise.

theorem Cslib.DataStructure.word_eq_sum_laneGet {W n word : ℕ} (hW : 0 < W) (hw : word < 2 ^ (n * W)) :
word = ∑ j ∈ Finset.range n, laneGet W word j * 2 ^ (j * W)

Base-2 ^ W expansion of any word < 2 ^ (n * W) into its first n lanes.

theorem Cslib.DataStructure.eq_of_forall_laneGet_eq_of_lt {n W a b : ℕ} (ha : a < 2 ^ (n * W)) (hb : b < 2 ^ (n * W)) (hd : ∀ d < n, laneGet W a d = laneGet W b d) :
a = b

Words < 2 ^ (n * W) are uniquely determined by their first n W-bit lanes.