{
  "status": "proved",
  "decl": "Gomory.exists_domino_tiling",
  "lean_source": "import Mathlib.Data.Fintype.Fin\nimport Mathlib.Logic.Equiv.Fin.Basic\nimport Mathlib.Tactic.FinCases\n\n/-!\n# Gomory's theorem on the mutilated chessboard\n\nA closed tour of the board reduces domino tiling to pairing the vertices in the two arcs\nleft by deleting vertices of opposite parity from an even cycle.\n-/\n\nnamespace Gomory\n\n/-- A directed step of a cycle in its usual cyclic order. -/\ndef CycleStep {n : ℕ} (x y : Fin n) : Prop :=\n  x.val + 1 = y.val ∨ (x.val + 1 = n ∧ y.val = 0)\n\n/-- The vertices remaining after two deletions. -/\nabbrev Remaining {α : Type*} (a b : α) := {x : α // x ≠ a ∧ x ≠ b}\n\n-- Read the surviving vertices starting just after the lower deleted index.\nprivate def arcVertex (n a b k : ℕ) : ℕ :=\n  if k < b - a - 1 then a + 1 + k\n  else if k < n - a - 2 then a + 2 + k\n  else k - (n - a - 2)\n\nprivate def arcIndex (n a b x : ℕ) : ℕ :=\n  if x < a then n - a - 2 + x\n  else if x < b then x - a - 1\n  else x - a - 2\n\n/-- Deleting vertices of opposite parity from an even cycle leaves consecutive pairs.\nThe equivalence enumerates the pairs and their two endpoints. -/\ntheorem exists_cycle_pairing {n : ℕ} (hn : n % 2 = 0) (a b : Fin n)\n    (hab : a.val < b.val) (hpar : a.val % 2 ≠ b.val % 2) :\n    ∃ e : Fin ((n - 2) / 2) × Fin 2 ≃ Remaining a b,\n      ∀ i, CycleStep (e (i, 0)).val (e (i, 1)).val := by\n  have ha := a.isLt\n  have hb := b.isLt\n  let e : Fin (n - 2) ≃ Remaining a b :=\n    { toFun := fun k => by\n        have hk := k.isLt\n        have h : arcVertex n a.val b.val k.val < n ∧\n            arcVertex n a.val b.val k.val ≠ a.val ∧\n            arcVertex n a.val b.val k.val ≠ b.val := by\n          unfold arcVertex\n          repeat' split\n          all_goals omega\n        exact ⟨⟨_, h.1⟩, fun hx => h.2.1 (congrArg Fin.val hx),\n          fun hx => h.2.2 (congrArg Fin.val hx)⟩\n      invFun := fun x => ⟨arcIndex n a.val b.val x.val.val, by\n        have hx := x.val.isLt\n        have hxa : x.val.val ≠ a.val := fun h => x.property.1 (Fin.ext h)\n        have hxb : x.val.val ≠ b.val := fun h => x.property.2 (Fin.ext h)\n        unfold arcIndex\n        split\n        · omega\n        · split <;> omega⟩\n      left_inv := by\n        intro k\n        apply Fin.ext\n        change arcIndex n a.val b.val (arcVertex n a.val b.val k.val) = k.val\n        have hk := k.isLt\n        unfold arcVertex arcIndex\n        repeat' split\n        all_goals omega\n      right_inv := by\n        intro x\n        apply Subtype.ext\n        apply Fin.ext\n        change arcVertex n a.val b.val (arcIndex n a.val b.val x.val.val) = x.val.val\n        have hx := x.val.isLt\n        have hxa : x.val.val ≠ a.val := fun h => x.property.1 (Fin.ext h)\n        have hxb : x.val.val ≠ b.val := fun h => x.property.2 (Fin.ext h)\n        unfold arcVertex arcIndex\n        repeat' split\n        all_goals omega }\n  have hsize : (n - 2) / 2 * 2 = n - 2 := by omega\n  let pairs : Fin ((n - 2) / 2) × Fin 2 ≃ Fin (n - 2) :=\n    finProdFinEquiv.trans (finCongr hsize)\n  refine ⟨pairs.trans e, fun i => ?_⟩\n  have hi := i.isLt\n  change arcVertex n a.val b.val (0 + 2 * i.val) + 1 =\n      arcVertex n a.val b.val (1 + 2 * i.val) ∨\n    (arcVertex n a.val b.val (0 + 2 * i.val) + 1 = n ∧\n      arcVertex n a.val b.val (1 + 2 * i.val) = 0)\n  simp only [Nat.zero_add]\n  -- The boundary between the arcs is even, so no pair crosses it.\n  have hboundary : (b.val - a.val - 1) % 2 = 0 := by omega\n  unfold arcVertex\n  repeat' split\n  all_goals omega\n\n/-- The row and column of a square on the ordinary chessboard. -/\nabbrev Square := Fin 8 × Fin 8\n\n/-- The parity of the sum of the row and column indices. -/\ndef color (x : Square) : ℕ := (x.1.val + x.2.val) % 2\n\n/-- Two squares share an edge in the ordinary board. -/\ndef Adjacent (x y : Square) : Prop :=\n  (x.1 = y.1 ∧ (x.2.val + 1 = y.2.val ∨ y.2.val + 1 = x.2.val)) ∨\n  (x.2 = y.2 ∧ (x.1.val + 1 = y.1.val ∨ y.1.val + 1 = x.1.val))\n\nprivate theorem adjacent_symm {x y : Square} (h : Adjacent x y) : Adjacent y x := by\n  simpa only [Adjacent, eq_comm (a := y.1), eq_comm (a := y.2),\n    or_comm (a := y.2.val + 1 = x.2.val), or_comm (a := y.1.val + 1 = x.1.val)] using h\n\n-- Snake through columns 1 through 7; return up column 0.\nprivate def tour (i : Fin 64) : Square :=\n  if h : i.val < 56 then\n    (⟨i.val / 7, by omega⟩,\n      ⟨if i.val / 7 % 2 = 0 then 1 + i.val % 7 else 7 - i.val % 7, by\n        split <;> omega⟩)\n  else (⟨63 - i.val, by omega⟩, 0)\n\nprivate def tourIndex (x : Square) : Fin 64 :=\n  ⟨if x.2.val = 0 then 63 - x.1.val\n    else 7 * x.1.val + (if x.1.val % 2 = 0 then x.2.val - 1 else 7 - x.2.val), by\n    have hr := x.1.isLt\n    have hc := x.2.isLt\n    split\n    · omega\n    · split <;> omega⟩\n\nprivate theorem tour_left_inv : ∀ i, tourIndex (tour i) = i := by decide\n\nprivate theorem tour_right_inv (r c : Fin 8) : tour (tourIndex (r, c)) = (r, c) := by\n  fin_cases r <;> fin_cases c <;> rfl\n\n/-- The closed tour visits every square exactly once. -/\ndef tourEquiv : Fin 64 ≃ Square where\n  toFun := tour\n  invFun := tourIndex\n  left_inv := tour_left_inv\n  right_inv := fun (r, c) => tour_right_inv r c\n\nprivate theorem tour_step_adjacent :\n    ∀ i : Fin 64, Adjacent (tour i) (tour (i + 1)) := by\n  intro i\n  unfold Adjacent\n  fin_cases i <;> decide\n\n/-- Every step of the tour joins two squares that share an edge, including the closing step. -/\ntheorem adjacent_tourEquiv {i j : Fin 64} (h : CycleStep i j) :\n    Adjacent (tourEquiv i) (tourEquiv j) := by\n  have hij : i + 1 = j := by\n    apply Fin.ext\n    change (i.val + 1) % 64 = j.val\n    have hj := j.isLt\n    rcases h with h | ⟨h, hz⟩ <;> omega\n  rw [← hij]\n  exact tour_step_adjacent i\n\n/-- Square colors alternate along the tour, starting with color 1. -/\ntheorem color_tourEquiv (i : Fin 64) : color (tourEquiv i) = (i.val + 1) % 2 := by\n  fin_cases i <;> rfl\n\nprivate theorem exists_ordered_domino_tiling (a b : Square)\n    (hab : (tourEquiv.symm a).val < (tourEquiv.symm b).val) (hcolor : color a ≠ color b) :\n    ∃ e : Fin 31 × Fin 2 ≃ Remaining a b,\n      ∀ i, Adjacent (e (i, 0)).val (e (i, 1)).val := by\n  let u := tourEquiv.symm a\n  let v := tourEquiv.symm b\n  have hpar : u.val % 2 ≠ v.val % 2 := by\n    have hau : color a = (u.val + 1) % 2 := by simpa [u] using color_tourEquiv u\n    have hbv : color b = (v.val + 1) % 2 := by simpa [v] using color_tourEquiv v\n    omega\n  obtain ⟨e, he⟩ := exists_cycle_pairing (n := 64) (by decide) u v hab hpar\n  let transport : Remaining u v ≃ Remaining a b :=\n    tourEquiv.subtypeEquiv (by\n      intro x\n      simp [u, v, Equiv.eq_symm_apply])\n  exact ⟨e.trans transport, fun i => adjacent_tourEquiv (he i)⟩\n\n/-- Gomory's theorem (Wikidata Q2916568): “The chessboard with any pair of squares of\ndifferent colors removed can be tiled with dominoes.”\n\nThe equivalence indexes exactly 31 dominoes, with two edge-adjacent squares per domino.\n-/\ntheorem exists_domino_tiling (a b : Square) (hcolor : color a ≠ color b) :\n    ∃ e : Fin 31 × Fin 2 ≃ Remaining a b,\n      ∀ i, Adjacent (e (i, 0)).val (e (i, 1)).val := by\n  rcases lt_trichotomy (tourEquiv.symm a).val (tourEquiv.symm b).val with h | h | h\n  · exact exists_ordered_domino_tiling a b h hcolor\n  · exact (hcolor (congrArg color (tourEquiv.symm.injective (Fin.ext h)))).elim\n  · obtain ⟨e, he⟩ := exists_ordered_domino_tiling b a h (Ne.symm hcolor)\n    let swap : Remaining b a ≃ Remaining a b :=\n      Equiv.subtypeEquivRight (fun _ => and_comm)\n    exact ⟨e.trans swap, he⟩\n\n/-- The partner map of a domino tiling is an involution of the remaining squares. -/\ntheorem exists_domino_partner (a b : Square) (hcolor : color a ≠ color b) :\n    ∃ f : Remaining a b → Remaining a b,\n      Function.Involutive f ∧ ∀ x, Adjacent x.val (f x).val := by\n  obtain ⟨e, he⟩ := exists_domino_tiling a b hcolor\n  let flip : Fin 31 × Fin 2 → Fin 31 × Fin 2 := fun (i, j) => (i, j + 1)\n  have hflip (p : Fin 31 × Fin 2) : flip (flip p) = p := by\n    obtain ⟨i, j⟩ := p\n    fin_cases j <;> rfl\n  refine ⟨fun x => e (flip (e.symm x)), ?_, ?_⟩\n  · intro x\n    simp only [e.symm_apply_apply, hflip, e.apply_symm_apply]\n  · intro x\n    obtain ⟨⟨i, j⟩, rfl⟩ := e.surjective x\n    simp only [e.symm_apply_apply]\n    fin_cases j\n    · exact he i\n    · exact adjacent_symm (he i)\n\nend Gomory\n\n#print axioms Gomory.exists_domino_tiling\n",
  "build_output": "'Gomory.exists_domino_tiling' depends on axioms: [propext, Classical.choice, Quot.sound]\n",
  "explanation": {
    "statement": "Any two squares of opposite colors may be removed from the ordinary 8×8 board. The 62 surviving squares can be covered exactly once by 31 dominoes, each joining two squares that share an edge.",
    "proof": "First consider a cycle with an even number n of vertices and cut it at indices a < b of opposite parity. Read the remaining vertices in cyclic order from just after a, skipping b. The first arc has b − a − 1 vertices, an even number. Since n − 2 is even, the second arc also has even length. Pair entries 2i and 2i + 1 in the resulting list. An even arc boundary guarantees that these pairs stay within their arcs, including when an arc is empty. On the chessboard, snake across columns 1–7 in alternating row directions, then return along column 0. The formal proof checks that the tour and its inverse are mutually inverse, that every step shares a board edge including step 63 back to 0, and that the tour colors alternate. Pull the two removed squares back to their tour indices and apply the cycle pairing. Transport the pairing to the board. The resulting enumeration has 31 two-square fibers.",
    "triage": {
      "grade": "A",
      "standard_proof_length": "One short proof paragraph with a diagram, or with the tour described in words.",
      "standard_proof_source": "https://scholarworks.iu.edu/iuswrrest/api/core/bitstreams/90973f1a-e66f-4a94-9b1a-02bf140c13fc/content",
      "mathlib_reuse": "Fin, finProdFinEquiv for turning a product of pair indices and endpoint indices into one range, finCongr for changing the size by equality, Equiv.subtypeEquiv for transport across the tour, fin_cases for the concrete board, and omega for the index arithmetic.",
      "mathlib_search": [
        "https://loogle.lean-lang.org/json?q=%22finProdFinEquiv%22",
        "https://loogle.lean-lang.org/json?q=%22Gomory%22",
        "https://api.github.com/repos/leanprover-community/mathlib4/git/trees/master?recursive=1"
      ],
      "new_lemmas": "A pairing theorem for an abstract even cycle, the explicit chessboard tour and its edge and parity checks, and transport from cycle pairs to board dominoes."
    },
    "build": {
      "command": "lean -DautoImplicit=false Gomory.lean",
      "exit_code": 0,
      "lean_version": "4.36.0",
      "mathlib_commit": "fc4f59e577feb1a4956671bc04ac18aaaf8cd842",
      "bundle_manifest": "https://github.com/Identity-md/lean-bundles/releases/download/pequalnp-e125f04d0dc6/fetch.json",
      "toolchain_pin_source": "https://api.github.com/repos/leanprover-community/mathlib4/commits/fc4f59e577feb1a4956671bc04ac18aaaf8cd842",
      "verification": "Both archives matched the SHA-256 checksums in fetch.json. Lean successfully compiled the source from a fresh scratch directory using the prebuilt package cache. Independent clean-clone rebuild by a different reviewer: UNVERIFIED."
    }
  },
  "fidelity": {
    "review": "Local clause-by-clause review of the compiled statement. Independent reviewer: UNVERIFIED.",
    "ordinary_board": "Square is Fin 8 × Fin 8, with each coordinate ranging from 0 to 7.",
    "arbitrary_opposite_colors": "Both squares are universally quantified. The sole hypothesis is inequality of their row-plus-column remainders modulo 2, which also implies the two squares are distinct.",
    "exact_deletions": "Remaining a b consists of exactly the squares unequal to both a and b.",
    "cover_and_disjointness": "The equivalence from Fin 31 × Fin 2 is surjective onto the survivors and injective on all endpoint slots. Thus every survivor occurs once and distinct dominoes are disjoint.",
    "edge_adjacency": "Adjacent requires equality in one coordinate and a difference of exactly one in the natural-number values of the other. This excludes diagonal neighbors and board wrap-around.",
    "count": "Fin 31 indexes exactly 31 dominoes, each with the two distinct endpoints indexed by Fin 2, so exactly 62 squares are covered.",
    "involution": "Gomory.exists_domino_partner swaps the two endpoint indices of each domino and transports that swap across the tiling equivalence, yielding an involution with adjacent partners."
  },
  "prior_work": [
    {
      "url": "https://leanprover-community.github.io/1000-missing.html",
      "finding": "Q2916568 is listed as Gomory's theorem on the missing page."
    },
    {
      "url": "https://leanprover-community.github.io/1000.html",
      "finding": "The companion page records finished formalizations. A search for Q2916568 there returned no match."
    },
    {
      "url": "https://api.github.com/repos/leanprover-community/mathlib4/git/trees/master?recursive=1",
      "finding": "Searched the Lean sources at Mathlib master e54979a532247ae4eb9d5578a8fd40a1bc332101 for Gomory, mutilated chessboard, 2916568, domino tiling, and domino cover. No matches."
    },
    {
      "url": "https://api.github.com/search/issues?q=repo%3Aleanprover-community%2Fmathlib4+is%3Apr+is%3Aopen+Gomory",
      "finding": "GitHub issue search found zero open Mathlib4 pull requests matching Gomory."
    },
    {
      "url": "https://api.github.com/search/issues?q=repo%3Aleanprover-community%2Fmathlib4+is%3Apr+is%3Aopen+chessboard",
      "finding": "GitHub issue search found zero open Mathlib4 pull requests matching chessboard."
    },
    {
      "url": "https://api.github.com/search/issues?q=repo%3Aleanprover-community%2Fmathlib4+is%3Apr+is%3Aopen+mutilated",
      "finding": "GitHub issue search found zero open Mathlib4 pull requests matching mutilated."
    },
    {
      "url": "https://github.com/rjwalters/lean-genius/tree/main/proofs/Proofs",
      "finding": "The lean-genius proofs directory was checked through its recursive Git tree at https://api.github.com/repos/rjwalters/lean-genius/git/trees/main?recursive=1. GitHub reported the tree was complete. No paths contained Gomory, mutilated, or chessboard. Full-text coverage of lean-genius proofs: UNVERIFIED."
    },
    {
      "url": "https://gist.githubusercontent.com/avigad/1080e327ad6806884c9c5091f5c449bd/raw/mutilated.lean",
      "finding": "Avigad formalizes the impossibility result for removing the bottom-left and top-right corners of an 8×8 board. Those squares have the same color."
    },
    {
      "url": "https://raw.githubusercontent.com/leanprover-community/mathlib3/da0111c4fe002f9aca19bb1d65b08c823bca299c/archive/examples/dominoes/dominoes.lean",
      "finding": "The Mathlib3 domino_coverings branch gives corners_removed_not_domino_coverable, an impossibility result for opposite-corner removal."
    },
    {
      "url": "https://github.com/Paul3435/open-math-lab/pull/177",
      "finding": "The linked PR proves small-board same-color corner and color-imbalance lemmas. Its summary gives no tiling existence result for arbitrary opposite-color deletions."
    },
    {
      "url": "https://raw.githubusercontent.com/leansolving/leancsp/e6bd621cce274e7380935ea40693805e03e200c5/CSP/L2S/Backends/PB/Problems/MutilatedChessboard.lean",
      "finding": "The Lean CSP benchmark certifies unsatisfiability for removal of same-color corners from a 4×4 board."
    },
    {
      "url": "https://light.artwaste.land/strata/the-mutilated-chessboard/",
      "finding": "The page describes Gomory’s positive result in prose and attributes the machine-checked proof to the same-color impossibility result."
    },
    {
      "url": "https://leanprover-community.github.io/archive/stream/113489-new-members/topic/Advice.20on.20Definitions.html",
      "finding": "Searches of the publicly indexed Zulip archive located discussion of the opposite-corner example. No proof of the positive theorem was found in those results. Full archive and private channels: UNVERIFIED."
    },
    {
      "url": "https://loogle.lean-lang.org/json?q=%22Gomory%22",
      "finding": "Loogle returned zero declarations with Gomory in their name."
    },
    {
      "url": "https://api.github.com/search/code?q=Gomory+chessboard+language%3ALean",
      "finding": "UNVERIFIED for authenticated global GitHub code search. The endpoint requires authentication. Public web searches and GitHub issue searches did not identify a prior proof of the positive theorem. Priority remains UNVERIFIED."
    }
  ],
  "database_entry": {
    "wikidata_id": "Q2916568",
    "title": "Gomory's theorem",
    "decl": "Gomory.exists_domino_tiling",
    "file": "Gomory.lean"
  },
  "stuck": null,
  "sources": [
    "https://leanprover-community.github.io/1000-missing.html",
    "https://leanprover-community.github.io/1000.html",
    "https://scholarworks.iu.edu/iuswrrest/api/core/bitstreams/90973f1a-e66f-4a94-9b1a-02bf140c13fc/content",
    "https://github.com/Identity-md/lean-bundles/releases/download/pequalnp-e125f04d0dc6/fetch.json",
    "https://api.github.com/repos/leanprover-community/mathlib4/commits/fc4f59e577feb1a4956671bc04ac18aaaf8cd842",
    "https://api.github.com/repos/leanprover-community/mathlib4/git/trees/master?recursive=1",
    "https://api.github.com/repos/rjwalters/lean-genius/git/trees/main?recursive=1",
    "https://api.github.com/search/issues?q=repo%3Aleanprover-community%2Fmathlib4+is%3Apr+is%3Aopen+Gomory",
    "https://api.github.com/search/issues?q=repo%3Aleanprover-community%2Fmathlib4+is%3Apr+is%3Aopen+chessboard",
    "https://api.github.com/search/issues?q=repo%3Aleanprover-community%2Fmathlib4+is%3Apr+is%3Aopen+mutilated",
    "https://leanprover-community.github.io/archive/stream/113489-new-members/topic/Advice.20on.20Definitions.html",
    "https://gist.githubusercontent.com/avigad/1080e327ad6806884c9c5091f5c449bd/raw/mutilated.lean",
    "https://raw.githubusercontent.com/leanprover-community/mathlib3/da0111c4fe002f9aca19bb1d65b08c823bca299c/archive/examples/dominoes/dominoes.lean",
    "https://github.com/Paul3435/open-math-lab/pull/177",
    "https://raw.githubusercontent.com/leansolving/leancsp/e6bd621cce274e7380935ea40693805e03e200c5/CSP/L2S/Backends/PB/Problems/MutilatedChessboard.lean",
    "https://loogle.lean-lang.org/json?q=%22finProdFinEquiv%22",
    "https://loogle.lean-lang.org/json?q=%22Gomory%22",
    "https://light.artwaste.land/strata/the-mutilated-chessboard/"
  ]
}
