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
There are no more ones than positions.
Dependency graph
Nothing is counted only when there is nothing: with all bits below w,
the count is 0 exactly at 0. This is the base case of the table.
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
What clearing costs: one one.
Dependency graph
Clearing a one makes the number smaller – so a recursion on “clear the lowest one” terminates, which is what the level-3 table's induction rests on.
Dependency graph
The lowest one can always be cleared: the result is smaller, hence a rank.
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
Instances For
Dependency graph
What a place value is worth.
Dependency graph
Every position has its place value, the two being the two namings of the same thing.
Dependency graph
Definability #
Clearing the lowest one is first-order in the bit logic.
Dependency graph
Being a place value is first-order in the bit logic – one quantifier and two atoms, where the other naming needed a two-element certificate.