AFTD Auto-Formalizing Theoretical Domains

grid_box_free_iff_layers_disjoint

theoremverified

A colouring $f$ of $[a]\times[b]\times[c]$ is box-free if and only if any two distinct layers have disjoint sets of monochromatic coloured rectangle patterns. This reduces the 3-D box-free condition to a 2-D packing of pattern sets.

Statement

theorem grid_box_free_iff_layers_disjoint {a b c : ℕ} (f : Fin a → Fin b → Fin c → Bool) : grid_box_free f ↔ ∀ z₁ z₂ : Fin c, z₁ ≠ z₂ → Disjoint (layer_mono f z₁) (layer_mono f z₂)
Source
step towards grid_box_free_max_five_seven
Verified
28 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 6
  • 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…
  • mem_layer_monoMembership in $\mathrm{layer\_mono}(f,z)$: a pattern $(x_1,x_2,y_1,y_2,\mathrm{col})$ lies in the layer iff $x_1<x_2$, $y_1<y_2$, and all…
  • TotalPreorderA total preorder: a preorder where ≤ is total (complete). This is weaker than LinearOrder — it does NOT require antisymmetry or…
  • 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…
  • 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…
  • LinearOrder.toTotalPreorderEvery LinearOrder is a TotalPreorder.
Used by 1
  • 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…

The proof, explained

The proof establishes the bi-implication by observing that an 8-corner monochromatic box between layers $z < v$ is precisely the simultaneous occurrence of the same 4-corner monochromatic rectangle pattern in both layer $z$ and layer $v$. If the colouring is box-free, no such pattern can appear in two distinct layers, meaning distinct layers have disjoint pattern sets. Conversely, if pattern sets for distinct layers are pairwise disjoint, no shared pattern can exist between any pair of layers $z < v$, so no monochromatic box can be formed.

  1. To show distinct layers have disjoint pattern sets assuming $f$ is box-free, it suffices to derive a contradiction from a shared pattern between distinct layers $z \neq v$.

    We split the bi-implication into both directions. In the forward direction, we assume that $f$ is box-free and consider two distinct layers $z \neq v$. To prove that their sets of monochromatic rectangle patterns are disjoint, we suppose for contradiction that there exists a common pattern $p$ in both $\operatorname{layer\_mono}(f, z)$ and $\operatorname{layer\_mono}(f, v)$.

    lines 3–6

    uses Finset.disjoint_left.mpr

      constructor
      · intro hf z v hz
        apply Finset.disjoint_left.mpr
        intro p hp hq
  2. No pattern $p$ can belong to two ordered layers $i < k$ in a box-free colouring. automation

    We prove an auxiliary contradiction lemma: if $p = (x_1, x_2, y_1, y_2, \text{col})$ belongs to layer $i$ and layer $k$ with $i < k$, unpacking the membership condition via `mem_layer_mono` gives $x_1 < x_2$, $y_1 < y_2$, and shows that all four corners in layer $i$ and all four corners in layer $k$ share the colour $\text{col}$. These eight corners form a monochromatic box in $[a] \times [b] \times [c]$, contradicting the box-free assumption on $f$.

    lines 7–10

    uses mem_layer_mono

        have no (i k : Fin c) (hik : i < k) (hi : p ∈ layer_mono f i) (hk : p ∈ layer_mono f k) : False := by
          obtain ⟨hx,hy,h₁,h₂,h₃,h₄⟩ := (mem_layer_mono f i p).mp hi
          obtain ⟨_,_,h₅,h₆,h₇,h₈⟩ := (mem_layer_mono f k p).mp hk
          exact hf _ _ _ _ i k hx hy hik (by simp [h₁,h₂,h₃,h₄,h₅,h₆,h₇,h₈])
  3. The forward direction holds: distinct layers have disjoint monochromatic pattern sets.

    Since $z \neq v$, trichotomy gives either $z < v$ or $v < z$. In either case, applying the auxiliary contradiction lemma to the ordered pair of layers and the shared pattern $p$ yields a contradiction.

    lines 11–13

    uses lt_or_gt_of_ne

        rcases lt_or_gt_of_ne hz with h | h
        · exact no z v h hp hq
        · exact no v z h hq hp
  4. Assuming pairwise disjoint pattern sets, a monochromatic box on coordinates $x < u$, $j < k$, $z < v$ defines a 2-D pattern $p = (x, u, j, k, f(x, j, z))$.

    In the reverse direction, we assume that distinct layers have disjoint pattern sets and suppose there is a monochromatic box given by coordinates $x < u$, $j < k$, $z < v$, where all eight corners have the same colour. We unpack the equality of the eight corners and define the corresponding 2-D rectangle pattern $p$ with colour $f(x, j, z)$.

    lines 14–16

      · intro hh x u j k z v hx hj hz hb
        obtain ⟨h₂,h₃,h₄,h₅,h₆,h₇,h₈⟩ := hb
        let p : BoxPattern a b := (x,u,j,k,f x j z)
  5. The pattern $p$ belongs to both layer $z$ and layer $v$, contradicting their disjointness, so $f$ must be box-free.

    Using `mem_layer_mono`, the four corner equalities at layer $z$ show that $p \in \operatorname{layer\_mono}(f, z)$, and the four corner equalities at layer $v$ show that $p \in \operatorname{layer\_mono}(f, v)$. Since $z < v$, the two layers are distinct ($z \neq v$), so by the disjointness hypothesis, their pattern sets are disjoint. This contradicts $p$ belonging to both sets, completing the equivalence.

    lines 17–19

    uses mem_layer_mono, Finset.disjoint_left.mp

        have hm : p ∈ layer_mono f z := (mem_layer_mono f z p).mpr ⟨hx,hj,rfl,h₂.symm,h₃.symm,h₄.symm⟩
        have hn : p ∈ layer_mono f v := (mem_layer_mono f v p).mpr ⟨hx,hj,h₅.symm,h₆.symm,h₇.symm,h₈.symm⟩
        exact Finset.disjoint_left.mp (hh z v hz.ne) hm hn
Finset.disjoint_left.mpr
Two finite sets are disjoint if no element belongs to both.
Finset.disjoint_left.mp
If two finite sets are disjoint, an element belonging to the first set cannot belong to the second set.
lt_or_gt_of_ne
In a linear order, if two elements are not equal, then one is strictly less than the other.
mem_layer_mono
A pattern $(x_1, x_2, y_1, y_2, \text{col})$ is in the monochromatic pattern set of layer $z$ if and only if $x_1 < x_2$, $y_1 < y_2$, and all four rectangle corners in layer $z$ have colour $\text{col}$.

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

/-- Box-free ⇔ distinct layers have disjoint monochromatic-rectangle pattern sets. -/theorem grid_box_free_iff_layers_disjoint {a b c : ℕ} (f : Fin a → Fin b → Fin c → Bool) : grid_box_free f ↔ ∀ z₁ z₂ : Fin c, z₁ ≠ z₂ → Disjoint (layer_mono f z₁) (layer_mono f z₂) := by  constructor  · intro hf z v hz    apply Finset.disjoint_left.mpr    intro p hp hq    have no (i k : Fin c) (hik : i < k) (hi : p ∈ layer_mono f i) (hk : p ∈ layer_mono f k) : False := by      obtain ⟨hx,hy,h₁,h₂,h₃,h₄⟩ := (mem_layer_mono f i p).mp hi      obtain ⟨_,_,h₅,h₆,h₇,h₈⟩ := (mem_layer_mono f k p).mp hk      exact hf _ _ _ _ i k hx hy hik (by simp [h₁,h₂,h₃,h₄,h₅,h₆,h₇,h₈])    rcases lt_or_gt_of_ne hz with h | h    · exact no z v h hp hq    · exact no v z h hq hp  · intro hh x u j k z v hx hj hz hb    obtain ⟨h₂,h₃,h₄,h₅,h₆,h₇,h₈⟩ := hb    let p : BoxPattern a b := (x,u,j,k,f x j z)    have hm : p ∈ layer_mono f z := (mem_layer_mono f z p).mpr ⟨hx,hj,rfl,h₂.symm,h₃.symm,h₄.symm⟩    have hn : p ∈ layer_mono f v := (mem_layer_mono f v p).mpr ⟨hx,hj,h₅.symm,h₆.symm,h₇.symm,h₈.symm⟩    exact Finset.disjoint_left.mp (hh z v hz.ne) hm hn
See it in the graphDiscuss this resultChallenge it