Skip to content

A sum of an Iverson bracket is counted in closed form - #1575

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
sums-of-iverson-brackets
Sep 29, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
sums-of-iverson-brackets

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

A sum of an Iverson bracket is a count, and it is now written in closed form however long the range is. sum(iverson(2 divides k or 3 divides k), k, 1, 1000) is 667, where the expansion stops at 100 terms and left it as written.

What is read (IversonSum, tried before the expansion):

  • An equation linear in the index fixes it at a point p, and the sum is then a bracket again: p is whole, in the range, and satisfies the other conditions. In a nested sum, that bracket is what the next sum out counts.
  • A comparison linear in the index, with a numeric slope, bounds it from one side, and so does a membership in an interval.
  • A divisibility of a linear function of the index with whole coefficients fixes a residue class. Several classes combine into one or none, by the Chinese remainder theorem.
  • exists m in ZZ+ : m^e = k says the index is a perfect e-th power. Over a range from 1 it is counted by the integer roots of the ends, and two powers are the power of the least common multiple, so a square that is a cube is a sixth power.
  • A conjunct free of the index is a factor. So is a linear function of the index being whole, which depends only on its constant term. A product of brackets is the bracket of the conjunction.
  • not Q counts the range less Q, and Q or R counts Q and R less both.

What is left is the number of whole numbers from L to U in the class r modulo m, which is floor((U - r)/m) - floor((L - 1 - r)/m), or U - L + 1 with no class. It is never below zero, which is also the count of an empty range.

Examples:

  • Sullivan and Mackey's §8.7.4 Try 1: sum(iverson(not 2 divides k and not 5 divides k), k, 1, 99) is 40. With a symbolic n it is n - floor(n/2) - floor(n/5) + floor(n/10), each term inside max(0, ...).
  • Ex 8.7.5, the numbers up to 1000 that are not squares, cubes or fourth powers: 962. §8.7.4 Try 2, below 1000 and neither squares, cubes nor fifth powers: 960.
  • Ex 8.5.3: sum(sum(sum(iverson(a + b + c = 20), c, 0, 20), b, 0, 20), a, 0, 20) is 231, binomial(22, 2). The two inner sums are counted in closed form, and the outer one is written out over its 21 values.

A bound that is not a number is read as real, as a bound of the range that is not a number is read as whole. A comparison with a point off the real line has no truth value, and that sum is declined.

Suite: 13,505 passed, 0 failed on net10.0, and every target framework builds. Gate: passed, with allocation as the baseline says on all 19 gated benchmarks.

BREAKING-CHANGES.md: the iverson entry is extended, with rows measured on 2.5.0.

Part of #1409.

🤖 Generated with Claude Code

https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

The statement is read as conditions on the index. An equation linear in it fixes it at a
point, and the sum is a bracket again -- the point whole, in the range, and satisfying the
rest -- which a sum outside counts in turn. A comparison or a membership in an interval bounds
the index; a divisibility of a linear function of it fixes a residue class, several combining
by the Chinese remainder theorem; a statement that it is a perfect power is counted by the
roots of the ends, two powers as the power of the least common multiple. A conjunct free of the
index, or a linear function of it being whole, is a factor; a product of brackets is the bracket
of the conjunction; not and or are counted by inclusion and exclusion. It comes before the
expansion, so a long range is counted and not left as written: sum(iverson(2 divides k or
3 divides k), k, 1, 1000) is 667; Sullivan and Mackey's §8.7.4 Tries 1 and 2 are 40 and 960,
Ex 8.7.5 is 962, and Ex 8.5.3's three pirates count binomial(22, 2).

Part of #1409.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
@Rafael-SOWNet
Rafael-SOWNet merged commit 58987de into master Sep 29, 2026
31 checks passed
@Rafael-SOWNet
Rafael-SOWNet deleted the sums-of-iverson-brackets branch October 29, 2026 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant