Set bits and binary finite-set codes #
The increasing list of set bits of a natural number can be obtained by testing every index
below the number. Mathlib's Finset.equivBitIndices identifies natural numbers with finite
sets of natural numbers, using ∑ x ∈ D, 2 ^ x as the code of a finite set D.
The i-th bit of the code ∑ j ∈ s, 2 ^ j records whether i ∈ s. Bitwise union, intersection
and difference decode to the corresponding finite-set operations, and inserting x sets bit x.
Bounded filtering keeps the requested members of a binary code, and least-element search returns
none precisely for the zero code.
References #
- Mathlib's
Finset.equivBitIndicessupplies the binary finite-set equivalence.
The set bits of n are found by filtering the finite interval below n.
Binary union decodes to finite-set union.
Binary intersection decodes to finite-set intersection.
Inserting x into a finite set sets bit x of its binary code.
Binary difference decodes to finite-set difference.
Decoding bounded filtering gives the corresponding filtered finite set.
The least member of a binary-coded finite set, or none for the empty set.
Instances For
Least-element search is the head of the increasing list of set bits.
Least-element search succeeds precisely at a member below every other member.
Least-element search returns none exactly for the zero code.