Chapter 28: Pigeon-hole and double counting #
A proposed formalization of Chapter 28 of Proofs from THE BOOK (Aigner–Ziegler). The supplied proofs are undergoing verification with the repository's pinned Lean toolchain.
- Pigeon-hole principle, including the strong form (1).
- Numbers: Claims 1 and 2, and the sharpness examples.
- Sequences: Erdős–Szekeres (book proof), sharpness for
mnnumbers, the dimension ofKₙ(dim K₃ = dim K₄ = 3,dim K₁₂ ≤ 4, monotonicity, anddim(Kₙ) ≥ log₂ log₂ n).
- Sequences: Erdős–Szekeres (book proof), sharpness for
- Sums: contiguous block sums divisible by
n.
- Sums: contiguous block sums divisible by
- Double counting (3).
- Numbers again:
Hₙ − 1 < t̄(n) ≤ Hₙandlog n − 1 < t̄(n) < log n + 1.
- Numbers again:
- Graphs: handshaking lemma (4), Reiman's bound (6) for
C₄-free graphs, the graphGp(noC₄,p² + p + 1vertices, degrees, the trace argument givingp + 1points on the conic,p²solutions ofx² + y² + z² = 0, and|E(Gp)| = (n−1)/4 · (1 + √(4n−3))).
- Graphs: handshaking lemma (4), Reiman's bound (6) for
- Sperner's lemma (double-counting proof, abstract form and for the standard
triangulation) and Brouwer's fixed point theorem for
n = 2(andn = 1).
- Sperner's lemma (double-counting proof, abstract form and for the standard
triangulation) and Brouwer's fixed point theorem for
===================== Part: Basic =====================
Pigeon-hole and double counting — basic results #
Sections 1, 3, the double counting principle, Section 4 (numbers again) and the first part of Section 5 (graphs) of Chapter 28.
Handshaking lemma: The sum of vertex degrees equals twice the number of edges.
This is also available in Mathlib as SimpleGraph.sum_degrees_eq_twice_card_edges,
which uses darts (oriented edges) as the intermediate counting object. Our proof
follows the book's double-counting argument more faithfully: we count incidence
pairs (v, e) with v ∈ e, swap the summation order via
Finset.sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow, then observe each edge
contributes exactly 2.
Double Counting #
Double counting: the sum over rows of the number of related columns equals
the sum over columns of the number of related rows. This is a direct wrapper
around Mathlib's Finset.sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow.
5. Graphs — C₄-free edge bound #
In a C₄-free graph, the sum of C(d(v), 2) over all vertices is at most C(n, 2).
This is the key combinatorial inequality: each pair of vertices can have at most one common neighbor (otherwise they'd form a 4-cycle), so the number of "cherries" (paths of length 2) is at most the number of vertex pairs.
If a simple graph on n vertices contains no 4-cycle (C₄), then |E| ≤ ⌊n/4 · (1 + √(4n − 3))⌋.
The proof uses sum_choose_deg_le_choose_card together with the handshaking lemma
and Cauchy–Schwarz / Jensen.
4. Numbers again #
Double counting for divisor sums: Σ_{j=1}^{n} (number of divisors of j) = Σ_{i=1}^{n} ⌊n/i⌋.
Both sides count pairs (i, j) with 1 ≤ i ≤ n, 1 ≤ j ≤ n, and i ∣ j. LHS groups by j (divisors of j), RHS groups by i (multiples of i up to n).
The average number of divisors is bounded by the harmonic sum:
∑ j in [1,n], t(j) ≤ n * Hₙ where t(j) = #(divisors j) and Hₙ = ∑ 1/i.
Lower bound: ∑ t(j) > n·Hₙ − n, i.e., t̄(n) > Hₙ − 1 > log n − 1.
===================== Part: PigeonHole =====================
The pigeon-hole principle: strong form and sharpness of the claims in Section 1 #
Pigeon-hole principle, strong form (1). If f : N → R with |R| = r > 0 and
|N| = n, then some a ∈ R has |f⁻¹(a)| ≥ ⌈n / r⌉.
===================== Part: ErdosSzekeres =====================
Section 2 of Chapter 28: Sequences #
- The Erdős–Szekeres theorem on monotone subsequences, with the book's proof (label every element by the length of a longest increasing subsequence starting there, and apply the pigeon-hole principle in the strong form (1)).
- The sharpness remark: for
mnnumbers the statement fails in general. - The dimension of the complete graph
Kₙand the bounddim(Kₙ) ≥ log₂ log₂ n.
The increasing subsequences (inside S) starting at i.
Equations
- chapter28.incSeqs f S i = {t ∈ S.powerset | i ∈ t ∧ (∀ j ∈ t, i ≤ j) ∧ StrictMonoOn f ↑t}
Instances For
The length tᵢ of a longest increasing subsequence (inside S) starting at i.
Equations
- chapter28.incLen f S i = (chapter28.incSeqs f S i).sup Finset.card
Instances For
The key observation: if i < j and aᵢ < aⱼ, then tᵢ > tⱼ.
Erdős–Szekeres (book proof), finset version. If f is injective on a finite set S
of indices with |S| > m n, then there is an increasing subsequence of length m + 1 or a
decreasing subsequence of length n + 1.
Claim 3 (Erdős–Szekeres): In any sequence a₁, …, a_{mn+1} of mn + 1 distinct real
numbers there is an increasing subsequence of length m + 1 or a decreasing subsequence of
length n + 1 (or both).
The counterexample sequence of length mn used for the sharpness remark:
n decreasing blocks, each block an increasing run of length m.
Instances For
Sharpness remark. For mn numbers the Erdős–Szekeres statement is no longer true in
general: the sequence esSharpSeq of length m n is injective and has neither an increasing
subsequence of length m + 1 nor a decreasing subsequence of length n + 1.
===================== Part: KnDimension =====================
The dimension of the complete graph Kₙ (Section 2 of Chapter 28) #
Let N = {1, …, n}. Permutations π₁, …, πₘ of N represent Kₙ if for every three
distinct numbers i, j, k there is a permutation in which k comes after both i and j.
The dimension dim(Kₙ) is the smallest such m. We encode a permutation by its
position function σ : Equiv.Perm (Fin n), where σ x is the position of x.
Main results:
dimK_mono:dim(Kₙ) ≤ dim(Kₙ₊₁);dimK_three,dimK_four:dim(K₃) = dim(K₄) = 3;dimK_twelve_le: the four permutations from the margin representK₁₂;dimK_ge_log_log:dim(Kₙ) ≥ log₂ log₂ n(inequality (2)).
Erdős-Szekeres on finsets: Given a finset S of size > m² and a function f injective on S, there exists a subset T ⊆ S of size > m on which f is monotone.
Iterated Erdős-Szekeres: Given p injective functions on Fin n and a finset S with |S| > 2^(2^p), there exists a subset T ⊆ S with |T| > 2 that is simultaneously monotone (each function is either strictly increasing or strictly decreasing on T).
Simultaneous monotone triple: For n > 2^(2^p) and p injective functions Fin n → ℝ, there exists a subset of size > 2 that is monotone for all of them.
This captures the lower bound dim(Kₙ) ≥ ⌈log₂(⌈log₂ n⌉)⌉: fewer than ⌈log₂(⌈log₂ n⌉)⌉ linear orders cannot separate all triples.
Ceiling-log formulation: If p < ⌈log₂(⌈log₂ n⌉)⌉, then p injective functions on Fin n cannot separate all triples. This is the dim(Kₙ) ≥ ⌈log₂(⌈log₂ n⌉)⌉ bound.
The permutations π 0, …, π (m-1) of Fin n represent Kₙ: for every three distinct
i, j, k there is a permutation in which k comes after both i and j. Each permutation
is encoded by its position function (π l x is the position of x in the l-th ordering).
Equations
Instances For
Equations
An injective ranking of Fin n is induced by a permutation (its position function).
The dimension dim(Kₙ): the smallest number of permutations representing Kₙ.
Equations
- chapter28.dimK n = sInf {m : ℕ | ∃ (π : Fin m → Equiv.Perm (Fin n)), chapter28.RepresentsK n m π}
Instances For
Kₙ is always represented by n permutations (put each k last once).
Rankings given by listing the elements of Fin n in order.
Equations
- chapter28.listRank L l x = List.idxOf x (L l)
Instances For
dim(K₃) = 3, using π₁ = (1,2,3), π₂ = (2,3,1), π₃ = (3,1,2).
dim(K₄) = 3, using π₁ = (1,2,3,4), π₂ = (2,4,3,1), π₃ = (1,4,3,2).
The four permutations from the margin represent K₁₂, so dim(K₁₂) ≤ 4.
The key step of (2): p permutations cannot represent Kₙ when n > 2^(2^p), because
iterated Erdős–Szekeres yields three numbers a < b < c which are monotone in every
permutation, so b never comes after both a and c.
===================== Part: Divisors =====================
Section 4 of Chapter 28: the average number of divisors #
With t(j) the number of divisors of j and t̄(n) = (1/n) ∑_{j ≤ n} t(j), we prove
Hₙ − 1 < t̄(n) ≤ Hₙ and
log n − 1 < Hₙ − 1 − 1/n < t̄(n) ≤ Hₙ < log n + 1 (for n ≥ 2).
The average number of divisors t̄(n) = (1/n) ∑_{j=1}^{n} t(j).
Equations
- chapter28.avgDivisors n = 1 / ↑n * ∑ j ∈ Finset.Icc 1 n, ↑j.divisors.card
Instances For
Hₙ − 1 < t̄(n) ≤ Hₙ.
The average number of divisors:
log n − 1 < Hₙ − 1 − 1/n < t̄(n) ≤ Hₙ < log n + 1 for all n ≥ 2.
Consequently |t̄(n) − log n| < 1 for n ≥ 2.
===================== Part: ReimanGraph =====================
The Reiman graph Gp (Section 5 of Chapter 28, second part) #
The Reiman graph Gp: a tight construction for the C₄-free bound #
The book constructs a graph Gp for each odd prime p:
- Vertices = points of PG(2,p), i.e., one-dimensional subspaces of (ZMod p)³
- Two vertices [u],[v] are adjacent iff ⟨u,v⟩ = u₁v₁ + u₂v₂ + u₃v₃ = 0
- Gp is C₄-free
- Edge count achieves the bound from
c4_free_edge_bound
We use Mathlib's Projectivization and Projectivization.orthogonal.
The projective plane over 𝔽ₚ.
Equations
- chapter28.PG2 p = Projectivization (ZMod p) (Fin 3 → ZMod p)
Instances For
The Reiman graph Gp: vertices are points of PG(2,p), adjacency is orthogonality.
Equations
- chapter28.reimanGraph p = SimpleGraph.fromRel fun (v w : chapter28.PG2 p) => Projectivization.orthogonal v w
Instances For
Adjacency in Gp: distinct orthogonal points.
The number of vertices of Gp is p² + p + 1. Note: The tex assumes p is an odd prime, but oddness is not needed for the cardinality formula — only that p is a prime (hence ZMod p is a field).
In PG(2,F), if a point x is orthogonal to two distinct points a and c, then x = cross a c. This is the uniqueness of the intersection of two hyperplanes (each hyperplane is the set of points orthogonal to a given point). Proof: by the BAC-CAB identity, w × (u × v) = (w·v)u − (u·w)v = 0 when w·u = 0 and w·v = 0, so the representatives are proportional.
Key lemma for no C₄: if two distinct points v, w are both orthogonal to two distinct points a, b, then v = w. Equivalently, the "orthogonal complement" hyperplanes of distinct points intersect in at most a single projective point.
This is the projective geometry fact that two distinct hyperplanes in PG(2,p) meet in exactly one point.
Note: The tex states this for 4 distinct vertices (6 pairwise ≠ conditions), but the proof only needs a ≠ c and b ≠ d. The other four ≠ conditions follow from Adj being irreflexive (loopless graph).
Each vertex's degree: p if self-orthogonal, p+1 otherwise. The orthogonal hyperplane of [v] in PG(2,p) has p+1 projective points. If v·v = 0, then [v] is among them and the degree is p; otherwise p+1.
===================== Part: ReimanEdges =====================
The number of edges of the Reiman graph Gp #
We follow the book: the number of vertices of Gp of degree p is the number of
self-orthogonal points (points on the conic x² + y² + z² = 0), which equals trace A for the
symmetric 0/1 matrix A with a_{vw} = 1 ↔ ⟨v, w⟩ = 0. Since A² = pI + J and A𝟙 = (p+1)𝟙,
every eigenvalue of A is p + 1 or ±√p; since the trace is an integer and √p is
irrational, trace A = p + 1.
The purely numerical part of the eigenvalue argument. If the real numbers μ i
(i ranging over a set of size N = p² + p + 1) are all roots of (x − (p+1))(x² − p),
their squares sum to N (p + 1) and their sum is an integer, then their sum is p + 1.
Equations
Equations
The matrix A of the book: a_{vw} = 1 if ⟨v, w⟩ = 0 and 0 otherwise
(rows and columns are indexed by the points of the projective plane).
Equations
- chapter28.reimanMatrix p v w = if Projectivization.orthogonal v w then 1 else 0
Instances For
Fact 1: every row of A contains exactly p + 1 ones.
A² = p I + J.
A satisfies (A − (p+1) I)(A² − p I) = 0.
Every eigenvalue of A is p + 1, √p or −√p.
For a real symmetric matrix, trace (A²) = ∑ λᵢ².
The number of vertices of Gp, as a Fintype.card.
The trace argument: trace A = p + 1.
Claim. Exactly p + 1 points of the projective plane lie on the conic
x² + y² + z² = 0 (i.e. are self-orthogonal); these are the vertices of degree p.
Edge count of Gp: 2 |E(Gp)| = p (p + 1)².
Edge count of Gp, book form: with n = p² + p + 1 vertices,
|E(Gp)| = (n − 1)/4 · (1 + √(4n − 3)), which almost agrees with Reiman's bound (6).
===================== Part: Sperner =====================
Section 6 of Chapter 28: Sperner's lemma (combinatorial core) #
We formalize the double-counting proof of Sperner's lemma for an abstract triangulation.
A triangulation is given by a finite family of "small triangles" tri i (i ∈ T), each a
set of three vertices. Colors are 0, 1, 2 (the book's 1, 2, 3).
The book's "partial dual graph" argument counts the incidences between small triangles and
edges whose endpoints carry the colors 0 and 1 ("doors"). We represent a door by the
ordered pair (u, v) with col u = 0 and col v = 1.
- Every edge lies in at most two small triangles (interior edges in two, boundary edges in one), and
- the number of boundary doors is odd,
then the number of tricolored triangles is odd (in particular, nonzero). We also prove the one-dimensional lemma used for the boundary: along a path whose endpoints have different colors there is an odd number of color changes.
A small triangle is tricolored if all three colors occur among its vertices.
Equations
- chapter28.Tricolored col t = ∀ (c : Fin 3), ∃ v ∈ t, col v = c
Instances For
Equations
The number of small triangles containing both u and v.
Instances For
All doors of the triangulation.
Equations
- chapter28.doorPairs T tri col = T.biUnion fun (i : ι) => chapter28.doorsIn col (tri i)
Instances For
Sperner's lemma (abstract double-counting form). If every edge lies in at most two small triangles and the number of doors lying in exactly one small triangle (the boundary doors) is odd, then the number of tricolored triangles is odd.
The one-dimensional Sperner lemma. If a path of vertices 0, 1, …, k is colored with two
colors and the endpoints have different colors, then the number of color changes along the
path is odd.
===================== Part: SpernerGrid =====================
Sperner's lemma for the standard triangulation of a triangle #
The big triangle V₁V₂V₃ is subdivided into k² small triangles. A vertex is a pair
(a, b) of natural numbers with a + b ≤ k (barycentric coordinates (a, b, k − a − b) / k);
V₁ = (k, 0), V₂ = (0, k), V₃ = (0, 0).
The small triangles are the "upward" triangles {(a,b), (a+1,b), (a,b+1)} with
a + b + 1 ≤ k and the "downward" triangles {(a+1,b), (a,b+1), (a+1,b+1)} with
a + b + 2 ≤ k.
We verify the hypotheses of the abstract Sperner lemma sperner_odd for this triangulation:
every edge lies in at most two small triangles, and for a Sperner coloring the boundary doors
are exactly the color changes along the side V₁V₂, of which there is an odd number.
Indices of upward small triangles.
Equations
- chapter28.gridUp k = {x ∈ Finset.range k ×ˢ Finset.range k | x.1 + x.2 + 1 ≤ k}
Instances For
Indices of downward small triangles.
Equations
- chapter28.gridDown k = {x ∈ Finset.range k ×ˢ Finset.range k | x.1 + x.2 + 2 ≤ k}
Instances For
Index set of all small triangles of the k-th subdivision.
Equations
Instances For
The small triangle with a given index.
Instances For
Whether the i-th side vertex has color 0.
Equations
- chapter28.sideColor k col i = decide (col (chapter28.sideVertex k i) = 0)
Instances For
The door at position i of the side (if there is a color change there).
Equations
- chapter28.sideDoor k col i = if col (chapter28.sideVertex k i) = 0 then (chapter28.sideVertex k i, chapter28.sideVertex k (i + 1)) else (chapter28.sideVertex k (i + 1), chapter28.sideVertex k i)
Instances For
A Sperner coloring of the k-th subdivision: vertices on the side opposite to Vᵢ do not
get the color of Vᵢ. (Then Vᵢ gets color i, and the side VᵢVⱼ only uses colors
i and j.)
Instances For
The boundary doors of a Sperner coloring are exactly the color changes along V₂V₁.
Sperner's lemma for the k-th standard subdivision of a triangle.
For every Sperner coloring the number of tricolored small triangles is odd.
In particular, a tricolored small triangle exists.
===================== Part: Brouwer =====================
Brouwer's fixed point theorem in dimension 2, via Sperner's lemma #
Following the book, we first prove that every continuous map f : Δ → Δ of the triangle
Δ = conv{e₁, e₂, e₃} ⊆ ℝ³ has a fixed point: color a point v by the smallest index i
with f(v)ᵢ < vᵢ, apply Sperner's lemma to finer and finer triangulations, and pass to a
limit using compactness of Δ. Then we transfer the result to the disk B², which is
homeomorphic to Δ.
The fixed point property of a set S: every continuous self-map of S has a fixed point.
Equations
- chapter28.HasFixedPointProperty S = ∀ (f : X → X), ContinuousOn f S → Set.MapsTo f S S → ∃ x ∈ S, f x = x
Instances For
The fixed point property is inherited along a retraction-type pair of maps (in particular along homeomorphisms).
The coloring λ(v) = min {i : f(v)ᵢ < vᵢ} #
If v is not a fixed point, then the i-th coordinate of f(v) − v is negative for the
color i of v.
Points of the k-th subdivision #
Brouwer's theorem for the triangle #
Brouwer's fixed point theorem for the triangle Δ. Every continuous map f : Δ → Δ
has a fixed point.
Transfer to the disk B² #
The affine map from Δ ⊆ ℝ³ to the plane.
Equations
- chapter28.simplexToPlane x = !₂[x 0 - 1 / 3, x 1 - 1 / 3]
Instances For
The triangle Δ, placed in the plane with its barycenter at the origin.
Instances For
Brouwer's fixed point theorem for the disk, in fixed-point-property form: the closed
unit disk B² ⊆ ℝ² has the fixed point property (since it is homeomorphic to Δ).
Brouwer's fixed point theorem (n = 2). Every continuous map of the closed unit disk
of ℝ² into itself has a fixed point.
Brouwer's fixed point theorem (n = 1), from the intermediate value theorem.