AFTD Auto-Formalizing Theoretical Domains

grid57_stack_at_most_fifty_two

theoremverifiedformalization

Every box-free binary coloring of a five-by-seven-by-n grid has at most 52 layers.

Statement

theorem grid57_stack_at_most_fifty_two {n : ℕ} (f : Fin 5 → Fin 7 → Fin n → Bool)
    (hf : grid_box_free f) : n ≤ 52
Formalizes
arXiv:2611.19635, section 6: the five-by-seven rectangle minimum is eight, and counting colored rectangle slots gives the upper bound of 52 layers.
Verified
28 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 7
  • grid_box_freeA 2-coloring $f : [a] \times [b] \times [c] \to \{0, 1\}$ is box-free if for all $x_1 < x_2 \le a$, $y_1 < y_2 \le b$, and…
  • 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$.…
  • layer_mono_card_sum_leLayer bound (Lemma 4.1 core): for a box-free colouring of $[a]\times[b]\times[c]$, the total number of monochromatic rectangles summed…
  • ordered_patterns_five_seven_cardThe $5\times 7$ grid has exactly $2\binom52\binom72 = 420$ ordered coloured rectangle slots.
  • 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…
  • ordered_patternsThe finite set of ordered coloured rectangle patterns of an $a\times b$ grid, i.e. the patterns with $x_1<x_2$ and $y_1<y_2$. Its…
  • 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 1

Read back from the Lean

For any natural number n and any function f : Fin 5 → Fin 7 → Fin n → Bool, if f is "grid box free" (that is, there do not exist x₁ < x₂ in Fin 5, y₁ < y₂ in Fin 7, and z₁ < z₂ in Fin n such that f assigns the same Boolean value to all eight vertices {x₁, x₂} × {y₁, y₂} × {z₁, z₂}), then n ≤ 52.

Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.

The proof, explained

The theorem is proved by double-counting monochromatic rectangles across the layers of the grid. Each 5-by-7 layer must contain at least 8 monochromatic rectangles, yielding a lower bound of 8n across all n layers. On the other hand, because the coloring is box-free, no monochromatic rectangle pattern can appear in more than one layer, which caps the total count at the 420 possible patterns on a 5-by-7 grid. Comparing the two bounds yields 8n ≤ 420, forcing n ≤ 52.

  1. Each layer contains at least 8 monochromatic rectangles.

    For each layer index z, the slice f(·, ·, z) defines a binary coloring of a 5-by-7 grid. By the lemma `layer_mono_five_seven_ge_eight`, every such 2D coloring has at least 8 monochromatic rectangles.

    lines 3–4

    uses layer_mono_five_seven_ge_eight

      have hl (z : Fin n) : 8 ≤ (layer_mono f z).card :=
        layer_mono_five_seven_ge_eight (fun x j => f x j z)
  2. The sum over all layers of 8 is at most the total number of monochromatic rectangles across all layers.

    Applying `Finset.sum_le_sum` to the pointwise lower bound of 8 rectangles per layer shows that summing 8 over the n layers is bounded by the sum of the layer rectangle counts.

    line 5

    uses Finset.sum_le_sum

      have hh := Finset.sum_le_sum (s := Finset.univ) (fun z _ => hl z)
  3. The sum of monochromatic rectangle counts across all layers is at most 420.

    Because the coloring f is box-free, two different layers cannot share the same monochromatic rectangle with the same color, meaning each pattern appears at most once. Hence, by `layer_mono_card_sum_le`, the sum of monochromatic rectangles over all layers is bounded by the total number of patterns, which `ordered_patterns_five_seven_card` evaluates to 420.

    lines 6–7

    uses layer_mono_card_sum_le, ordered_patterns_five_seven_card

      have hg := layer_mono_card_sum_le f hf
      rw [ordered_patterns_five_seven_card] at hg
  4. The lower bound simplifies to 8n ≤ ∑ z, |layer_mono f z|.

    The simplifier evaluates the sum of the constant 8 over the n elements of `Fin n` into 8 * n.

    line 8

      simp at hh
  5. n ≤ 52.

    Combining the lower bound 8n and the upper bound 420 gives 8n ≤ 420. Since 52 * 8 = 416 ≤ 420 < 424 = 53 * 8, the largest natural number satisfying this inequality is 52. The `omega` tactic completes the linear integer arithmetic deduction.

    line 9

      omega
layer_mono_five_seven_ge_eight
Every 2-coloring of a 5-by-7 grid contains at least 8 monochromatic rectangles.
Finset.sum_le_sum
If f(i) ≤ g(i) for every element i in a finite set s, then the sum of f over s is at most the sum of g over s.
layer_mono_card_sum_le
For any box-free 3D grid coloring, the sum over all layers of the number of monochromatic rectangles in each layer cannot exceed the total number of rectangle patterns on the 2D base grid.
ordered_patterns_five_seven_card
There are exactly 420 monochromatic rectangle patterns on a 5-by-7 grid (computed as (5 choose 2) * (7 choose 2) * 2 = 10 * 21 * 2).

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

theorem grid57_stack_at_most_fifty_two {n : ℕ} (f : Fin 5 → Fin 7 → Fin n → Bool)    (hf : grid_box_free f) : n ≤ 52 := by  have hl (z : Fin n) : 8 ≤ (layer_mono f z).card :=    layer_mono_five_seven_ge_eight (fun x j => f x j z)  have hh := Finset.sum_le_sum (s := Finset.univ) (fun z _ => hl z)  have hg := layer_mono_card_sum_le f hf  rw [ordered_patterns_five_seven_card] at hg  simp at hh  omega
See it in the graphDiscuss this resultChallenge it