Bit Indices #
Given n : ℕ, we define Nat.bitIndices n, which is the List of indices of 1s in the
binary expansion of n. If s : Finset ℕ and n = ∑ i ∈ s, 2 ^ i, then
Nat.bitIndices n is the sorted list of elements of s.
The lemma twoPowSum_bitIndices proves that summing 2 ^ i over this list gives n.
This is used in Combinatorics.colex to construct a bijection equivBitIndices : ℕ ≃ Finset ℕ.
TODO #
Relate the material in this file to Nat.digits and Nat.bits.
The function which maps each natural number ∑ i ∈ s, 2 ^ i to the list of
elements of s in increasing order.
Instances For
theorem
Nat.bitIndices_bit_true
(n : ℕ)
:
(bit true n).bitIndices = 0 :: List.map (fun (x : ℕ) => x + 1) n.bitIndices
theorem
Nat.bitIndices_bit_false
(n : ℕ)
:
(bit false n).bitIndices = List.map (fun (x : ℕ) => x + 1) n.bitIndices
@[simp]
theorem
Nat.bitIndices_two_mul_add_one
(n : ℕ)
:
(2 * n + 1).bitIndices = 0 :: List.map (fun (x : ℕ) => x + 1) n.bitIndices
@[simp]
theorem
Nat.bitIndices_two_mul
(n : ℕ)
:
(2 * n).bitIndices = List.map (fun (x : ℕ) => x + 1) n.bitIndices
@[simp]
theorem
Nat.bitIndices_two_pow_mul
(k n : ℕ)
:
(2 ^ k * n).bitIndices = List.map (fun (x : ℕ) => x + k) n.bitIndices
@[simp]
@[irreducible]
theorem
Nat.bitIndices_twoPowsum
{L : List ℕ}
(hL : L.SortedLT)
:
(List.map (fun (i : ℕ) => 2 ^ i) L).sum.bitIndices = L
Together with Nat.twoPowSum_bitIndices, this implies a bijection between ℕ and Finset ℕ.
See Finset.equivBitIndices for this bijection.