grid57_agreements_le_rectangles_add_twenty
The total column agreements are at most the number of monochromatic rectangles plus twenty.
Statement
theorem grid57_agreements_le_rectangles_add_twenty (f : Fin 5 → Fin 7 → Bool) : (∑ j : Fin 7, grid57_column_agreements f j) ≤ (layer_mono (fun x y (_ : Fin 1) => f x y) 0).card + 20
- Source
- OP-1867: double counting row-pair/color incidences, related to arXiv:2611.19635 section 6.
- Verified
- 28 Nov 2026
- Axioms
Classical.choiceQuot.soundpropext- Built on 4
- grid57_column_agreementsThe number of agreeing unordered row pairs in a column of a binary five-by-seven layer.
- layer_monoFor a $2$-colouring $f$ of $[a]\times[b]\times[c]$ and a layer index $z$, $\mathrm{layer\_mono}(f,z)$ is the finite set of coloured…
- grid57_seven_column_repetition_bound_via_chooseFor any set of seven column positions, its size is at most one more than the number of increasing pairs it contains.
- BoxPatternA coloured rectangle pattern in an $a\times b$ grid: a pair of rows $x_1<x_2$, a pair of columns $y_1<y_2$, and a colour, encoded as the…
- Used by 2
- grid_five_seven_nine_rectangles_balanced_columnsIn every binary five-by-seven layer with at most nine monochromatic rectangles, each column contains exactly two or three true entries.
- layer_mono_five_seven_ge_eightEvery $2$-colouring of the $5\times 7$ grid contains at least $8$ monochromatic rectangles, counting both colours: $\rho(5,7) \ge 8$.…
The proof, explained
The proof establishes that the total column agreements in a 2-colored 5 × 7 grid are at most the number of monochromatic rectangles plus 20 by double-counting across all pairs of rows. For any fixed pair of rows x < u, the columns where they agree split into those where both are true and those where both are false. For each color, the repetition bound `grid57_seven_column_repetition_bound_via_choose` bounds the number of matching columns m by the number of matching column pairs (m choose 2) plus 1, so the total agreements for the row pair are at most its monochromatic rectangles plus 2. Summing this inequality over all (5 choose 2) = 10 row pairs yields the desired upper bound with an extra 10 × 2 = 20.
Define indicator functions A for row agreements in a column and R for monochromatic rectangles.
For any pair of rows x, u and column j, let A(x, u, j) be 1 if x < u and both rows share the same color in column j, and 0 otherwise. For rows x, u, columns j, k, and color c, let R(x, u, j, k, c) be 1 if x < u, j < k, and all four grid vertices (x, j), (x, k), (u, j), (u, k) have color c, and 0 otherwise.
let A (x u : Fin 5) (j : Fin 7) := if x < u ∧ f x j = f u j then 1 else 0 let R (x u : Fin 5) (j k : Fin 7) (c : Bool) := if x < u ∧ j < k ∧ f x j = c ∧ f x k = c ∧ f u j = c ∧ f u k = c then 1 else 0
The sum of column agreements equals the sum of A(x, u, j) over all rows x, u and columns j.
By definition, the agreements in column j count pairs of rows x < u with f(x, j) = f(u, j). Rewriting the cardinality of this filtered set as a sum of indicator values using `Finset.card_filter` and `Fintype.sum_prod_type`, and swapping the summation order between column j and row indices x, u using `Finset.sum_comm` (applied inside the x-sum via `Finset.sum_congr`), expresses the total column agreements as ∑ x, ∑ u, ∑ j, A x u j.
uses
Finset.card_filter,Fintype.sum_prod_type,Finset.sum_comm,Finset.sum_congrhave aa : (∑ j, grid57_column_agreements f j) = ∑ x, ∑ u, ∑ j, A x u j := by simp only [grid57_column_agreements, Finset.card_filter, Fintype.sum_prod_type, A] rw [Finset.sum_comm] apply Finset.sum_congr rfl intro x _ rw [Finset.sum_comm]
The number of monochromatic rectangles equals the sum of R(x, u, j, k, c) over all x, u, j, k, c.
Unfolding the definition of monochromatic rectangles (`layer_mono`) and converting the cardinality of the filtered set of rectangle configurations into an iterated sum of indicator values using `Finset.card_filter` and `Fintype.sum_prod_type` gives the desired representation.
uses
Finset.card_filter,Fintype.sum_prod_typehave rr : (layer_mono (fun x y (_ : Fin 1) => f x y) 0).card = ∑ x, ∑ u, ∑ j, ∑ k, ∑ c, R x u j k c := by simp only [layer_mono, Finset.card_filter, BoxPattern, Fintype.sum_prod_type, R]
For any pair of rows x, u, their column agreements are bounded by the monochromatic rectangles on those two rows plus 2 when x < u (and 0 otherwise).
When x ≥ u, both sides are zero because the indicators A and R require x < u. When x < u, the agreement indicator A(x, u, j) splits by color into I(j, true) + I(j, false), where I(j, c) indicates that f(x, j) = c and f(u, j) = c. For each color c, applying `grid57_seven_column_repetition_bound_via_choose` to the predicate on columns shows that the number of columns with both rows colored c is at most the number of column pairs with both rows colored c plus 1: ∑ j, I j c ≤ (∑ j, ∑ k, R x u j k c) + 1. Summing this inequality over both colors c ∈ {true, false} yields the bound with an extra 1 + 1 = 2.
uses
Fintype.sum_bool,grid57_seven_column_repetition_bound_via_choose,Finset.card_filter,Fintype.sum_prod_type,Finset.sum_add_distrib,if_poshave per (x u : Fin 5) : (∑ j, A x u j) ≤ (∑ j, ∑ k, ∑ c, R x u j k c) + (if x < u then 2 else 0) := by by_cases h : x < u · let I (j : Fin 7) (c : Bool) := if f x j = c ∧ f u j = c then 1 else 0 have splitColor (j : Fin 7) : A x u j = ∑ c, I j c := by cases hx : f x j <;> cases hu : f u j <;> simp [A, I, h, hx, hu, Fintype.sum_bool] have hc (c : Bool) : (∑ j, I j c) ≤ (∑ j, ∑ k, R x u j k c) + 1 := by have hh := grid57_seven_column_repetition_bound_via_choose (fun j => decide (f x j = c ∧ f u j = c)) simpa only [I, R, h, true_and, Finset.card_filter, Fintype.sum_prod_type, decide_eq_true_eq, and_assoc, and_left_comm, and_comm] using hh simp only [splitColor, Fintype.sum_bool, Finset.sum_add_distrib, if_pos h] have ht := hc true have hf := hc false omega · simp [A, R, h]
The sum of the row-pair adjustments (2 if x < u else 0) over all x, u ∈ Fin 5 equals 20.
There are (5 choose 2) = 10 pairs with x < u among the 5 rows. Each contributes 2 to the sum, giving 10 × 2 = 20, which is verified by kernel evaluation (`decide`).
have extra : (∑ x : Fin 5, ∑ u : Fin 5, (if x < u then 2 else 0 : ℕ)) = 20 := by decide
Summing the row-pair inequality over all pairs of rows yields the theorem.
Using the identities `aa` and `rr` to rewrite column agreements and rectangles as sums of A and R, and replacing 20 by the sum from `extra`, the goal reduces to showing that the sum of A(x, u, j) is at most the sum of R(x, u, j, k, c) + (2 if x < u else 0). This follows by applying `Finset.sum_le_sum` across all rows x and u to the pairwise bound `per x u`.
uses
Finset.sum_add_distrib,Finset.sum_le_sumrw [aa, rr, ← extra, ← Finset.sum_add_distrib] apply Finset.sum_le_sum intro x _ rw [← Finset.sum_add_distrib] exact Finset.sum_le_sum (fun u _ => per x u)
Finset.card_filter- The cardinality of the sub-finset of elements satisfying a decidable predicate p equals the sum over the finset of the indicator function of p (1 if p holds, 0 otherwise).
Fintype.sum_prod_type- A sum over all pairs in a Cartesian product of finite types equals the iterated sum over each component.
Finset.sum_comm- A double sum over two finite sets can have its order of summation exchanged: ∑ x ∈ s, ∑ y ∈ t, f x y = ∑ y ∈ t, ∑ x ∈ s, f x y.
Finset.sum_congr- Two sums over finite sets are equal if their index sets are equal and their summands are equal on every element of the index set.
Fintype.sum_bool- The sum of a function over the two-element boolean type is the sum of its values at true and false: ∑ b, f b = f true + f false.
grid57_seven_column_repetition_bound_via_choose- For any boolean predicate on 7 elements, the number of elements satisfying it is at most the number of pairs of elements satisfying it plus 1 (that is, m ≤ (m choose 2) + 1 for m ≤ 7).
Finset.sum_add_distrib- The sum of a sum of two functions over a finite set equals the sum of the first plus the sum of the second: ∑ (f x + g x) = ∑ f x + ∑ g x.
if_pos- If a proposition c holds, then the conditional expression `if c then t else e` reduces to t.
Finset.sum_le_sum- If f i ≤ g i for all elements i in a finite set, then the sum of f over the set is at most the sum of g over the set.
- The definition `layer_mono` is stated for general 3D box patterns with a dummy depth coordinate of type `Fin 1` evaluated at index 0, representing 2D monochromatic rectangles in the 5 × 7 grid.
- In line 27, the identity evaluating the row-pair adjustment to 20 is closed by `decide`, which computes the finite sum by direct evaluation in the kernel.
Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.
Lean source view module on GitHub
Choose a tactic — a marked line — to see the goals Lean had before and after it, as in Lean’s infoview. Step with ← → or j k.
theorem grid57_agreements_le_rectangles_add_twenty (f : Fin 5 → Fin 7 → Bool) : (∑ j : Fin 7, grid57_column_agreements f j) ≤ (layer_mono (fun x y (_ : Fin 1) => f x y) 0).card + 20 := by let A (x u : Fin 5) (j : Fin 7) := if x < u ∧ f x j = f u j then 1 else 0 let R (x u : Fin 5) (j k : Fin 7) (c : Bool) := if x < u ∧ j < k ∧ f x j = c ∧ f x k = c ∧ f u j = c ∧ f u k = c then 1 else 0 have aa : (∑ j, grid57_column_agreements f j) = ∑ x, ∑ u, ∑ j, A x u j := by simp only [grid57_column_agreements, Finset.card_filter, Fintype.sum_prod_type, A] rw [Finset.sum_comm] apply Finset.sum_congr rfl intro x _ rw [Finset.sum_comm] have rr : (layer_mono (fun x y (_ : Fin 1) => f x y) 0).card = ∑ x, ∑ u, ∑ j, ∑ k, ∑ c, R x u j k c := by simp only [layer_mono, Finset.card_filter, BoxPattern, Fintype.sum_prod_type, R] have per (x u : Fin 5) : (∑ j, A x u j) ≤ (∑ j, ∑ k, ∑ c, R x u j k c) + (if x < u then 2 else 0) := by by_cases h : x < u · let I (j : Fin 7) (c : Bool) := if f x j = c ∧ f u j = c then 1 else 0 have splitColor (j : Fin 7) : A x u j = ∑ c, I j c := by cases hx : f x j <;> cases hu : f u j <;> simp [A, I, h, hx, hu, Fintype.sum_bool] have hc (c : Bool) : (∑ j, I j c) ≤ (∑ j, ∑ k, R x u j k c) + 1 := by have hh := grid57_seven_column_repetition_bound_via_choose (fun j => decide (f x j = c ∧ f u j = c)) simpa only [I, R, h, true_and, Finset.card_filter, Fintype.sum_prod_type, decide_eq_true_eq, and_assoc, and_left_comm, and_comm] using hh simp only [splitColor, Fintype.sum_bool, Finset.sum_add_distrib, if_pos h] have ht := hc true have hf := hc false omega · simp [A, R, h] have extra : (∑ x : Fin 5, ∑ u : Fin 5, (if x < u then 2 else 0 : ℕ)) = 20 := by decide rw [aa, rr, ← extra, ← Finset.sum_add_distrib] apply Finset.sum_le_sum intro x _ rw [← Finset.sum_add_distrib] exact Finset.sum_le_sum (fun u _ => per x u)