Interval ↔ digit-string counting #
Base-general (1 < b). Everything here feeds the lower comparison
le_base_pow_countOccurrences_champBlocks between the stream length and
b^k · (occurrence count) over [1, N]; the upper direction is derived
downstream (Positions.lean) from the lower one via the allWords
pigeonhole. Two relaxations keep this file small:
- occurrences at the head position of a number are never counted — the
interior positions already carry the main term, uniformly in
w(so now.head? = some 0case split anywhere), and - every cohort, full or not, is handled by the partial-cohort lower bound, so only lower periodic-count bounds are ever needed.
The exact counterparts (exact periodic count, per-position cards, exact
cohort sums, digitEquiv and its round-trips) live in
CountExtras.lean.
Generic counting and rounding lemmas (no base) #
Lower bound for periodic counting: over [A, A + t) with a left
endpoint divisible by p * q, the value n / p % q hits a fixed d < q
at least t / (p·q) · p times — p hits in each complete period p·q.
Proved directly by injecting range (t/(p·q)) ×ˢ range p; the main proof
never needs the exact count (card_Ico_filter_div_mod,
CountExtras.lean).
∑_{i<K} b^i < b^K for 1 < b.
bigDigits API #
Cardinalities #
Cohort decomposition #
Cohort decomposition of a sum over [1, b^M).
Stream and cohort length sums #
The stream-prefix length as a sum over the numbers 1..N.
Blocks at positions #
Substring ↔ arithmetic bridge: the block of w.length digits at
big-endian position j of an m-digit n equals w iff the
corresponding quotient-remainder is the value of w.
Partial-cohort block occurrence sums #
Every cohort is treated as a partial cohort [b^K, b^K + t) (a full one
has t = b^(K+1) - b^K), and only the interior positions j ≥ 1 are
counted — occurrences at the head of a number are dropped, which is
sound for a lower bound and uniform in w (a leading-zero w simply
never occurs there).
Partial-cohort occurrence sum as a sum of per-position cards.
Partial-cohort occurrence sum, lower bound (stated additively; drops the head position, which is only ever a nonnegative contribution).
Partial-cohort comparison, boundary induction, and general N #
Boundary comparison, lower: over the complete cohorts [1, b^K), the
stream length exceeds b^k times the occurrence count by at most
6·(k+1)·b^K. Each full cohort [b^K, b^(K+1)) is a partial cohort with
t = b^(K+1) - b^K (le_base_pow_countOccurrences_partial); the
geometric accumulation of the per-cohort errors 3(k+1)·b^(K+1) stays
below 6(k+1)·b^K because 2 ≤ b. Cohorts too short to fit w only
need their length bounded (the occurrence count is dropped at ≥ 0).