{
  "verdict": "pass",
  "decl": "Gomory.exists_domino_tiling",
  "author_status": "proved",
  "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",
  "source_sha256": "6a4d847db1e61f61267ce8f12de4118e9df7d46879aaad1d540492917bebecd2",
  "build_output": "'Gomory.exists_domino_tiling' depends on axioms: [propext, Classical.choice, Quot.sound]\n",
  "build": {
    "command": "lean -DautoImplicit=false Gomory.lean",
    "exit_code": 0,
    "lean_version": "Lean (version 4.36.0, x86_64-unknown-linux-gnu, commit 611c117bfaf7b7ae1cfcf246ce6fba31e8f509e9, Release)",
    "mathlib_pin": "fc4f59e577feb1a4956671bc04ac18aaaf8cd842",
    "bundles": [
      {
        "url": "https://github.com/Identity-md/lean-bundles/releases/download/pequalnp-e125f04d0dc6/lean-4.36.0-linux.tar.zst",
        "verified_sha256": "2b7ab1ed8b92d2e6abfaf41344823b510064dbc9c0260cac73eb496ab2dea6eb"
      },
      {
        "url": "https://github.com/Identity-md/lean-bundles/releases/download/pequalnp-e125f04d0dc6/pequalnp-e125f04d0dc6-packages-lean-4.36.0-linux-x64.tar.zst",
        "verified_sha256": "69b68c745d0bd8dba3ab21966f8cdb14f9373bd4f1df1d17680f4b80dad98a88"
      }
    ],
    "checks": "Compiled the extracted source unchanged in an empty directory against the two checksum-verified prebuilt bundles. Lean printed only the axiom report. The source contains none of the prohibited tokens. Ordinary decide checks finite tour facts."
  },
  "fidelity_review": {
    "verdict": "Faithful to the vetted existence theorem",
    "board": "Square is Fin 8 × Fin 8. Each coordinate independently ranges from 0 through 7.",
    "quantification_and_colour": "The theorem accepts arbitrary a and b. Its only hypothesis is inequality of (row + column) modulo 2, which implies distinct squares and is inhabited, for example by (0,0) and (0,1). There is no corner restriction or required ordering.",
    "remaining_squares": "Remaining a b is the subtype of squares unequal to both a and b, so exactly those two distinct squares are removed and all 62 others survive.",
    "adjacency": "Adjacent requires equal rows and consecutive column values, or equal columns and consecutive row values. Both directions are allowed. The addition by 1 occurs on natural-number coordinate values, so diagonals, self-pairs, and board wrap-around are excluded.",
    "coverage_disjointness_and_count": "The equivalence from Fin 31 × Fin 2 is onto all survivors and injective on endpoint slots. Each of 31 indices has two distinct endpoints, indices do not share squares, and the adjacency assertion applies to every index. The companion theorem also obtains the involution by swapping the two slots within each pair."
  },
  "prior_work": [
    {
      "scope": "Mathlib master and 1000+ database",
      "finding": "Searched the Lean source under Mathlib/ in the master snapshot e54979a532247ae4eb9d5578a8fd40a1bc332101 for Gomory, Q2916568, mutilated chessboard/checkerboard and domino tiling. No matching proof surfaced. docs/1000.yaml lists Q2916568 with title alone. The missing list contains it and the finished list returned no match.",
      "sources": [
        "https://api.github.com/repos/leanprover-community/mathlib4/commits/master",
        "https://raw.githubusercontent.com/leanprover-community/mathlib4/master/docs/1000.yaml",
        "https://leanprover-community.github.io/1000-missing.html",
        "https://leanprover-community.github.io/1000.html"
      ]
    },
    {
      "scope": "Mathlib open PRs",
      "finding": "GitHub issue search returned zero open PRs for each of Gomory, chessboard, domino and Q2916568. This verifies the named searches.",
      "sources": [
        "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+domino",
        "https://api.github.com/search/issues?q=repo%3Aleanprover-community%2Fmathlib4+is%3Apr+is%3Aopen+Q2916568"
      ]
    },
    {
      "scope": "GitHub and Lean Genius",
      "finding": "Searched Lean, JSON and Markdown files under proofs/Proofs of rjwalters/lean-genius at d8540c5a48f69a9f57b87c549c6e09dad63a0670 with the same terms. No matching proof surfaced. Broader indexed web searches surfaced related chessboard work. Exhaustive GitHub code search is UNVERIFIED because the API required authentication.",
      "sources": [
        "https://api.github.com/repos/rjwalters/lean-genius/commits/main",
        "https://api.github.com/search/code?q=%22mutilated+chessboard%22+language%3ALean",
        "https://gist.githubusercontent.com/avigad/1080e327ad6806884c9c5091f5c449bd/raw",
        "https://raw.githubusercontent.com/leansolving/leancsp/main/CSP/L2S/Proofs/MutilatedSB.lean"
      ]
    },
    {
      "scope": "Related GitHub formalizations",
      "finding": "Jeremy Avigad's Lean gist proves impossibility after deleting (0,0) and (7,7), two same-colour corners. LeanCSP studies symmetry breaking for the opposite-corner deletion model and verifies UNSAT for a 4×4 instance. Both concern same-colour deletions.",
      "sources": [
        "https://gist.githubusercontent.com/avigad/1080e327ad6806884c9c5091f5c449bd/raw",
        "https://raw.githubusercontent.com/leansolving/leancsp/main/CSP/L2S/Proofs/MutilatedSB.lean",
        "https://raw.githubusercontent.com/leansolving/leancsp/main/CSP/L2S/Backends/PB/Problems/MutilatedChessboard.lean"
      ]
    },
    {
      "scope": "Lean Zulip public archive",
      "finding": "Indexed searches for Gomory, mutilated chessboard and domino tiling surfaced a discussion about the corner-removal impossibility problem. No proof of the opposite-colour result surfaced. Unindexed or private Zulip discussion is UNVERIFIED.",
      "sources": [
        "https://leanprover-community.github.io/archive/stream/113489-new-members/topic/Advice.20on.20Definitions.html"
      ]
    },
    {
      "scope": "Priority",
      "finding": "No earlier Lean proof of the vetted statement was found in the searches above. Absolute priority is UNVERIFIED."
    }
  ],
  "explanation": {
    "statement": "Remove any two squares of different colours from the ordinary 8×8 chessboard. The remaining squares can be covered exactly once by 31 dominoes, each covering two squares with a common edge.",
    "proof": "Visit columns 1 through 7 of each row in alternating directions, then go back up column 0. This closed tour visits every square once and moves only along board edges, including its final step back to the start. Its colours alternate. Removing opposite-colour squares therefore cuts its cyclic order into two runs, each of even length. Pair consecutive squares within each run. The Lean proof constructs an index and its inverse for the surviving tour vertices and checks that the boundary between runs falls between pairs, including when a run is empty. It transfers the indexed pairs to the board using the tour equivalence and handles either order of the deleted squares."
  },
  "database_entry": {
    "wikidata_id": "Q2916568",
    "title": "Gomory's theorem",
    "decl": "Gomory.exists_domino_tiling",
    "file": "Gomory.lean",
    "yaml": "Q2916568:\n  title: Gomory's theorem\n  decl: Gomory.exists_domino_tiling\n"
  },
  "stuck": null,
  "repairs": [],
  "sources": [
    "https://api.imd.fun/artifacts/7f4f625037269466291ff1fe35c1299090331f4c79dd9d9a45e69446f2662ac6",
    "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/commits/master",
    "https://api.github.com/repos/rjwalters/lean-genius/commits/main",
    "https://raw.githubusercontent.com/leanprover-community/mathlib4/master/docs/1000.yaml",
    "https://raw.githubusercontent.com/leanprover-community/mathlib4/master/scripts/yaml_check.py",
    "https://leanprover-community.github.io/1000-missing.html",
    "https://leanprover-community.github.io/1000.html",
    "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+domino",
    "https://api.github.com/search/issues?q=repo%3Aleanprover-community%2Fmathlib4+is%3Apr+is%3Aopen+Q2916568",
    "https://api.github.com/search/code?q=%22mutilated+chessboard%22+language%3ALean",
    "https://leanprover-community.github.io/archive/stream/113489-new-members/topic/Advice.20on.20Definitions.html",
    "https://gist.githubusercontent.com/avigad/1080e327ad6806884c9c5091f5c449bd/raw",
    "https://raw.githubusercontent.com/leansolving/leancsp/main/CSP/L2S/Proofs/MutilatedSB.lean",
    "https://raw.githubusercontent.com/leansolving/leancsp/main/CSP/L2S/Backends/PB/Problems/MutilatedChessboard.lean"
  ]
}
