Counting ones, and the two atoms level 3 counts with #
The Bit Sum Lemma is about how many ones a word has, and this file says what
that means and gives the two bit-level operations its base level
(LogTime/BitSum/Table.lean) breaks the circularity with.
The count #
DescriptiveComplexity.BitSum.onesBelow x w is the number of ones of x among
the first w positions. It is a Finset.card, not a recursion, because every
statement about it is about changing one bit: clearing a set bit lowers the
count by one (DescriptiveComplexity.BitSum.onesBelow_clear), and that single
fact is the whole recursion the level-3 table is pinned by. The width is a
parameter rather than “all of them” because levels 1 and 2 count ones below a
position, not of a whole element.
The two atoms #
DescriptiveComplexity.BitSum.ClearLow x x'–x'isxwith its lowest one cleared. It is first-order in≤andBIT(name the lowest set index, say every lower index is clear, and copy every bit but that one), the count drops by exactly one, and it exists wheneverx ≠ 0. This is what lets the table forpopcountbe pinned locally, by a recursion on the value rather than on the count.DescriptiveComplexity.BitSum.IsPowIx i p–pis the place value2 ^ i. In the index naming this is free (pis the element whose only bit is ati), which is the mirror image ofDescriptiveComplexity.powArithDef, where the same statement inFO(≤, +, ×)cost a certificate. It is how a level gets the number of values a sub-block can take, which is the gap of the table's sections.
Counting ones, in ℕ #
The number of ones of x below the position w.
Equations
- DescriptiveComplexity.BitSum.onesBelow x w = {i ∈ Finset.range w | x.testBit i = true}.card
Instances For
Dependency graph
Dependency graph
Clearing a one lowers the count by one – whichever one it is. The level-3 table clears the lowest, but the counting does not care.
Dependency graph
Clearing the lowest one #
x' is x with its lowest one cleared: an index that is set with
nothing set below it, and every other bit copied.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Dependency graph
Place values, in the index naming #
p is the place value of the index i: its only bit is at i. What
DescriptiveComplexity.powArithDef had to prove in FO(≤, +, ×) is, in the
index naming, this one line.
Equations
- DescriptiveComplexity.BitSum.IsPowIx i p = ∀ (j : A), DescriptiveComplexity.BitIx j p ↔ j = i