Counting a zero followed by ones

Lax100001.Rows · concepts/Lax100001/Rows.lean · lax-100001

proven

Natural Language Statement

Theorem

The ones of a binary word cut its zeros into groups. Group ss holds the zeros that have exactly ss ones before them. A word with JJ ones has the groups 0,1,…,J0, 1, \ldots, J. The number of occurrences of 0\texttt{0} followed by rr ones is determined by the sizes of these groups: a zero in group ss has J−sJ - s ones after it, and it starts as many occurrences as there are ways to choose rr of those ones.

Concept map
100%

Preparing this local graph with the browser’s fonts…

Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A
Evidence

Each proof establishes this claim relative to its assumptions.

In the paper

  • page 4 of this submission's paper

Lean source

1/-
2Copyright (c) 2026 Anonymous. All rights reserved.
3Released under Apache 2.0 license as described in the file LICENSE.
4Authors: ChatGPT (OpenAI), Claude (Anthropic)
5-/
6import Lax100001.Counting
7import Mathlib.Algebra.BigOperators.Group.Finset.Basic
8import Mathlib.Data.Nat.Choose.Basic
9
10/-!
11---
12title: Counting a zero followed by ones
13type: theorem
14---
15The ones of a binary word cut its zeros into groups. Group ss holds the zeros that have exactly
16ss ones before them. A word with JJ ones has the groups 0,1,…,J0, 1, \ldots, J. The number of
17occurrences of 0\texttt{0} followed by rr ones is determined by the sizes of these groups: a zero
18in group ss has J−sJ - s ones after it, and it starts as many occurrences as there are ways to
19choose rr of those ones.
20-/
21
22namespace Lax100001.Rows
23
24open Counting
25
26/-- The sizes of the groups of zeros of word\mathit{word}.
27
28Entry ss counts the zeros of word\mathit{word} that have exactly ss ones before them, and the list
29has one entry for each of the J+1J + 1 groups, where JJ is the number of ones. For example,
30groups [false, true, false, true, true, false]=[1,1,0,1]\texttt{groups [false, true, false, true, true, false]} = [1, 1, 0, 1]: the word 010110\texttt{010110}
31has one zero before the first one, one between the first and second ones, none between the second
32and third ones, and one after the third one. -/
33def groups : Word → List ℕ
34 | [] => [0]
35 | true :: tail => 0 :: groups tail
36 | false :: tail =>
37 match groups tail with
38 | [] => [1]
39 | a :: rest => (a + 1) :: rest
40
41/-- The number of occurrences of 0\texttt{0} followed by rr ones in a word is the sum over the
42groups ss of the size of group ss times (J−sr)\binom{J-s}{r}, where JJ is the number of ones and
43J+1J + 1 is the number of groups. For the word 010110\texttt{010110} and r=2r = 2 the groups are
44[1,1,0,1][1, 1, 0, 1]. The sum is
451⋅(32)+1⋅(22)+0⋅(12)+1⋅(02)1 \cdot \binom{3}{2} + 1 \cdot \binom{2}{2} + 0 \cdot \binom{1}{2} + 1 \cdot \binom{0}{2}, which
46is 44.
47-/
48axiom count_zero_ones (word : Word) (r : ℕ) :
49 count word (false :: List.replicate r true) =
50 ∑ s ∈ Finset.range (groups word).length,
51 (groups word)[s]! * ((groups word).length - 1 - s).choose r
52
53end Lax100001.Rows
54