Minesweeper consistency
AbbreviationMinesweeper instances#✓fully proved
A Minesweeper instance consists of a number of rows \(R\), a number of columns \(C\) and a finite list of clues, where \(R\) and \(C\) are natural numbers and each clue is a triple \((r, c, k)\) of natural numbers giving a row \(r\), a column \(c\) and the number \(k\) shown.
abbrev MinesweeperInstance := ℕ × ℕ × List (ℕ × ℕ × ℕ)
DefinitionWell-formed Minesweeper instances#✓fully proved
A Minesweeper instance with \(R\) rows, \(C\) columns and a list of clues is well formed when every clue \((r, c, k)\) in the list satisfies \(r < R\), \(c < C\) and \(k \le 8\).
def WellFormed (i : MinesweeperInstance) : Prop :=
∀ clue ∈ i.2.2, clue.1 < i.1 ∧ clue.2.1 < i.2.1 ∧ clue.2.2 ≤ 8
abbrev MinesweeperInstance := ℕ × ℕ × List (ℕ × ℕ × ℕ)
WantedExt/Complexity/NPComplete/MinesweeperWanted.lean:47
Uses 1 · Used by 1
DefinitionFeasible Minesweeper instances#✓fully proved
Index rows and columns by natural numbers, and call a cell \((r', c') \ne (r, c)\) a neighbour of \((r, c)\) when \(|r' - r| \le 1\) and \(|c' - c| \le 1\). A Minesweeper instance with \(R\) rows, \(C\) columns and a list of clues is feasible when there is a finite set \(M\) of cells \((r, c)\) with \(r < R\) and \(c < C\) (the mines) such that for every clue \((r, c, k)\) in the list the cell \((r, c)\) is not in \(M\) and exactly \(k\) cells of \(M\) are neighbours of \((r, c)\).
def MinesweeperFeasible
(i : MinesweeperInstance) : Prop :=
∃ mines : List (ℕ × ℕ), mines.Nodup ∧ (∀ m ∈ mines, m.1 < i.1 ∧ m.2 < i.2.1) ∧
∀ clue ∈ i.2.2, (clue.1, clue.2.1) ∉ mines ∧
((mines.filter (fun m => decide (m.1 ≤ clue.1 + 1) && decide (clue.1 ≤ m.1 + 1) &&
decide (m.2 ≤ clue.2.1 + 1) && decide (clue.2.1 ≤ m.2 + 1) &&
!(m == (clue.1, clue.2.1))))).length = clue.2.2
abbrev MinesweeperInstance := ℕ × ℕ × List (ℕ × ℕ × ℕ)
WantedExt/Complexity/NPComplete/MinesweeperWanted.lean:47
Uses 1 · Used by 1
DefinitionMinesweeper consistency as a decision problem#✓fully proved
The Minesweeper consistency decision problem accepts a bitstring \(x\) exactly when \(x\) decodes, under the canonical bitstring encoding, to a Minesweeper instance that is well formed and feasible, that is, admits a mine placement consistent with all of its clues. It rejects every bitstring that does not decode to a Minesweeper instance.
noncomputable def minesweeperDec :
MetaMathlibExt.ComplexityTheory.DecisionProblem := fun x =>
match MetaMathlibExt.BitstringEncoding.bitDecode
(α := MinesweeperInstance) x with
| some i => decide (WellFormed i ∧ MinesweeperFeasible i)
| none => false
abbrev DecisionProblem := List Bool → Bool
MathlibExt/Computability/Complexity.lean:170
def bitDecode [BitstringEncoding α] (l : List Bool) : Option α := toEncoding.decode l
MathlibExt/Computability/Complexity.lean:58
abbrev MinesweeperInstance := ℕ × ℕ × List (ℕ × ℕ × ℕ)
WantedExt/Complexity/NPComplete/MinesweeperWanted.lean:47
def WellFormed (i : MinesweeperInstance) : Prop :=
∀ clue ∈ i.2.2, clue.1 < i.1 ∧ clue.2.1 < i.2.1 ∧ clue.2.2 ≤ 8
WantedExt/Complexity/NPComplete/MinesweeperWanted.lean:50
def MinesweeperFeasible
(i : MinesweeperInstance) : Prop :=
∃ mines : List (ℕ × ℕ), mines.Nodup ∧ (∀ m ∈ mines, m.1 < i.1 ∧ m.2 < i.2.1) ∧
∀ clue ∈ i.2.2, (clue.1, clue.2.1) ∉ mines ∧
((mines.filter (fun m => decide (m.1 ≤ clue.1 + 1) && decide (clue.1 ≤ m.1 + 1) &&
decide (m.2 ≤ clue.2.1 + 1) && decide (clue.2.1 ≤ m.2 + 1) &&
!(m == (clue.1, clue.2.1))))).length = clue.2.2
WantedExt/Complexity/NPComplete/MinesweeperWanted.lean:54
Uses 12 · Used by 1
TheoremMINESWEEPER CONSISTENCY is NP-complete#●ready to prove
The Minesweeper consistency decision problem lies in NP, and every decision problem in NP has a polynomial-time many-one reduction to it.
public theorem_wanted minesweeper_npComplete :
minesweeperDec ∈ MetaMathlibExt.ComplexityTheory.NP ∧
∀ L : MetaMathlibExt.ComplexityTheory.DecisionProblem,
L ∈ MetaMathlibExt.ComplexityTheory.NP →
Cslib.CookLevin.PolyManyOneRed L minesweeperDec
noncomputable def minesweeperDec :
MetaMathlibExt.ComplexityTheory.DecisionProblem := fun x =>
match MetaMathlibExt.BitstringEncoding.bitDecode
(α := MinesweeperInstance) x with
| some i => decide (WellFormed i ∧ MinesweeperFeasible i)
| none => false
WantedExt/Complexity/NPComplete/MinesweeperWanted.lean:64
def NP : DecisionComplexityClass :=
{ L | ∃ (p : Polynomial ℕ), ∃ R : (List Bool × List Bool) → Bool,
IsPolyTime R ∧
∀ x, L x ↔ ∃ w : List Bool, w.length ≤ p.eval x.length ∧ R (x, w) }
MathlibExt/Computability/Complexity.lean:200
abbrev DecisionProblem := List Bool → Bool
MathlibExt/Computability/Complexity.lean:170
def PolyManyOneRed (L₁ L₂ : MetaMathlibExt.ComplexityTheory.DecisionProblem) : Prop :=
∃ reduce : List Bool → List Bool,
MetaMathlibExt.ComplexityTheory.IsPolyTime reduce ∧ ∀ x, L₁ x = L₂ (reduce x)
CSLibExt/Computability/CookLevin.lean:396
Sources
- R. Kaye, "Minesweeper is NP-complete" (2000).
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.