Latin square completion
AbbreviationLatin square completion instances#✓fully proved
An instance of LATIN SQUARE COMPLETION is a pair \((n, G)\) of a natural number \(n\), the intended size, and a list \(G\) of lists of natural numbers, read as the rows of a partial grid in which the entry \(0\) marks a blank cell.
DefinitionWell-formed Latin square completion instances#✓fully proved
An instance \((n, G)\) of LATIN SQUARE COMPLETION is well formed when \(n > 0\), \(G\) has exactly \(n\) rows, every row of \(G\) has length \(n\), and every entry of \(G\) is at most \(n\).
def WellFormed (i : LatinSquareCompletionInstance) : Prop :=
0 < i.1 ∧ i.2.length = i.1 ∧ (∀ row ∈ i.2, row.length = i.1) ∧
∀ row ∈ i.2, ∀ x ∈ row, x ≤ i.1
abbrev LatinSquareCompletionInstance := ℕ × List (List ℕ)
WantedExt/Complexity/NPComplete/LatinSquareCompletionWanted.lean:45
Uses 1 · Used by 1
DefinitionCompletable partial Latin squares#✓fully proved
An instance \((n, G)\) of LATIN SQUARE COMPLETION is feasible when there is a grid \(C\) consisting of \(n\) rows of length \(n\) such that for all \(r, c < n\) the entry \(G_{rc}\) is either \(0\) or equal to \(C_{rc}\), every row of \(C\) is a permutation of \(1, \dots, n\), and every column of \(C\) is a permutation of \(1, \dots, n\). Here \(G_{rc}\) is taken to be \(0\) when \(G\) has no entry in row \(r\) and column \(c\).
def LatinSquareCompletionFeasible
(i : LatinSquareCompletionInstance) : Prop :=
∃ completion : List (List ℕ), completion.length = i.1 ∧
(∀ row ∈ completion, row.length = i.1) ∧
(∀ r < i.1, ∀ c < i.1, (i.2.getD r []).getD c 0 = 0 ∨
(i.2.getD r []).getD c 0 = (completion.getD r []).getD c 0) ∧
(∀ r < i.1, (completion.getD r []).Perm ((List.range i.1).map (· + 1))) ∧
∀ c < i.1, ((List.range i.1).map
(fun r => (completion.getD r []).getD c 0)).Perm ((List.range i.1).map (· + 1))
abbrev LatinSquareCompletionInstance := ℕ × List (List ℕ)
WantedExt/Complexity/NPComplete/LatinSquareCompletionWanted.lean:45
Uses 1 · Used by 1
DefinitionLATIN SQUARE COMPLETION as a decision problem#✓fully proved
The decision problem LATIN SQUARE COMPLETION accepts a bitstring \(x\) exactly when \(x\) decodes, under the canonical bitstring encoding of pairs of a natural number and a list of lists of natural numbers, to an instance \((n, G)\) that is well formed (\(n > 0\) and \(G\) consists of \(n\) rows of length \(n\) with entries at most \(n\)) and feasible (\(G\) can be completed to an \(n \times n\) grid whose rows and columns are permutations of \(1, \dots, n\) and which agrees with \(G\) on its nonzero entries). Bitstrings that do not decode, or that decode to a malformed instance, are rejected.
noncomputable def latinSquareCompletionDec :
MetaMathlibExt.ComplexityTheory.DecisionProblem := fun x =>
match MetaMathlibExt.BitstringEncoding.bitDecode
(α := LatinSquareCompletionInstance) x with
| some i => decide (WellFormed i ∧ LatinSquareCompletionFeasible 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 LatinSquareCompletionInstance := ℕ × List (List ℕ)
WantedExt/Complexity/NPComplete/LatinSquareCompletionWanted.lean:45
def WellFormed (i : LatinSquareCompletionInstance) : Prop :=
0 < i.1 ∧ i.2.length = i.1 ∧ (∀ row ∈ i.2, row.length = i.1) ∧
∀ row ∈ i.2, ∀ x ∈ row, x ≤ i.1
WantedExt/Complexity/NPComplete/LatinSquareCompletionWanted.lean:48
def LatinSquareCompletionFeasible
(i : LatinSquareCompletionInstance) : Prop :=
∃ completion : List (List ℕ), completion.length = i.1 ∧
(∀ row ∈ completion, row.length = i.1) ∧
(∀ r < i.1, ∀ c < i.1, (i.2.getD r []).getD c 0 = 0 ∨
(i.2.getD r []).getD c 0 = (completion.getD r []).getD c 0) ∧
(∀ r < i.1, (completion.getD r []).Perm ((List.range i.1).map (· + 1))) ∧
∀ c < i.1, ((List.range i.1).map
(fun r => (completion.getD r []).getD c 0)).Perm ((List.range i.1).map (· + 1))
WantedExt/Complexity/NPComplete/LatinSquareCompletionWanted.lean:53
Uses 12 · Used by 1
TheoremLATIN SQUARE COMPLETION is NP-complete#●ready to prove
The decision problem LATIN SQUARE COMPLETION on bitstrings lies in NP, and every decision problem in NP reduces to it by a polynomial-time many-one reduction.
public theorem_wanted latinSquareCompletion_npComplete :
latinSquareCompletionDec ∈ MetaMathlibExt.ComplexityTheory.NP ∧
∀ L : MetaMathlibExt.ComplexityTheory.DecisionProblem,
L ∈ MetaMathlibExt.ComplexityTheory.NP →
Cslib.CookLevin.PolyManyOneRed L latinSquareCompletionDec
noncomputable def latinSquareCompletionDec :
MetaMathlibExt.ComplexityTheory.DecisionProblem := fun x =>
match MetaMathlibExt.BitstringEncoding.bitDecode
(α := LatinSquareCompletionInstance) x with
| some i => decide (WellFormed i ∧ LatinSquareCompletionFeasible i)
| none => false
WantedExt/Complexity/NPComplete/LatinSquareCompletionWanted.lean:65
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
- C. J. Colbourn, "The complexity of completing partial Latin squares" (1984).
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.