Representing a Power Set with Bit Patterns
The power set contains all subsets of a set. Indexing elements lets a Boolean choice describe each subset uniquely.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Read three bits
For ordered labels A, B, C, a pattern of one, zero, one denotes A and C. All zeros denote the empty subset. With three independent choices there are eight patterns. See recursive subset generation for another enumeration.
Preserve the indexing convention
Reordering the labels changes how the pattern is interpreted unless positions are remapped. The collection identifier associated with each position can be useful when saving such data across versions.[1]
Fix the association between bits and values
Let bits from least to most significant mean A, B and C. The mask \(5=101_2\) represents \(\{A,C\}\), and \(2=010_2\) represents \(\{B\}\). A three-bit mask of zero represents the empty subset. See generating subsets recursively.
000 → {}
001 → {A}
010 → {B}
101 → {A,C}
111 → {A,B,C}
Translate operations only within one agreed encoding
Bitwise AND computes intersection and OR computes union for masks referring to the same element ordering. Complement needs a width so the result keeps only bits associated with the universe. Test zero, the all-set mask and two overlapping subsets.