Documentation

CslibFrontier.Foundations.Data.Nat.AlignedPacking

Aligned packing of power-size blocks #

Blocks of sizes b ^ ℓ i, for i in a finite set s, fit side by side into [0, ∑ i ∈ s, b ^ ℓ i) so that every block starts at a multiple of its own size (Nat.exists_aligned_packing). Place the blocks in decreasing order of size: each starting point is then a sum of larger powers of b, all divisible by the next block's size.

For b = 2 an aligned block is a binary address prefix: the numbers in the block of i are those whose bits above position ℓ i are the bits of its start. A circuit reading a table of all the blocks at an address in block i therefore needs only the bits of the start above ℓ i and the offset bits below, with no addition.

Main results #

theorem Nat.exists_aligned_packing {ι : Type u_1} (b : ℕ) (ℓ : ι → ℕ) (s : Finset ι) :
∃ (o : ι → ℕ), (∀ i ∈ s, b ^ ℓ i ∣ o i ∧ o i + b ^ ℓ i ≤ ∑ j ∈ s, b ^ ℓ j) ∧ ∀ i ∈ s, ∀ j ∈ s, ∀ (t : ℕ), o i ≤ t → t < o i + b ^ ℓ i → o j ≤ t → t < o j + b ^ ℓ j → i = j

Aligned packing. Blocks of sizes b ^ ℓ i, for i ∈ s, can be placed at pairwise disjoint positions o i inside [0, ∑ i ∈ s, b ^ ℓ i) so that each starts at a multiple of its size: place them in decreasing order of size.