Longest cycle
AbbreviationInstances of LONGEST CYCLE#✓fully proved
An instance of LONGEST CYCLE is a triple \((n, E, K)\) of a natural number \(n\) (the number of vertices), a list \(E\) of pairs of natural numbers (the edges), and a natural number \(K\) (the bound).
abbrev LongestCycleInstance := ℕ × List (ℕ × ℕ) × ℕ
DefinitionGraph of a LONGEST CYCLE instance#✓fully proved
For an instance \((n, E, K)\) of LONGEST CYCLE, its graph is the simple graph on \(\{0, \dots, n-1\}\) in which distinct vertices \(i\) and \(j\) are adjacent when \((i, j)\) or \((j, i)\) belongs to \(E\). Loops are dropped, and pairs with an endpoint at least \(n\) contribute no edge.
def Graph (i : LongestCycleInstance) : SimpleGraph (Fin i.1) :=
Cslib.Complexity.Karp.edgeGraph i.1 i.2.1
abbrev LongestCycleInstance := ℕ × List (ℕ × ℕ) × ℕ
WantedExt/Complexity/NPComplete/LongestCycleWanted.lean:45
def edgeGraph (n : ℕ) (es : List (ℕ × ℕ)) : SimpleGraph (Fin n) :=
SimpleGraph.fromRel fun i j => ((i : ℕ), (j : ℕ)) ∈ es
CSLibExt/Computability/Complexity/Karp/Color.lean:51
Uses 2 · Used by 1
DefinitionWell-formed LONGEST CYCLE instances#✓fully proved
An instance \((n, E, K)\) of LONGEST CYCLE is well formed when the list \(E\) has no repeated entries and every pair \((u, v)\) in \(E\) satisfies \(u < n\), \(v < n\), \(u \ne v\) and \((v, u) \notin E\).
def WellFormed (i : LongestCycleInstance) : Prop :=
i.2.1.Nodup ∧ ∀ e ∈ i.2.1, e.1 < i.1 ∧ e.2 < i.1 ∧ e.1 ≠ e.2 ∧ (e.2, e.1) ∉ i.2.1
abbrev LongestCycleInstance := ℕ × List (ℕ × ℕ) × ℕ
WantedExt/Complexity/NPComplete/LongestCycleWanted.lean:45
Uses 1 · Used by 1
DefinitionFeasible LONGEST CYCLE instances#✓fully proved
An instance \((n, E, K)\) of LONGEST CYCLE is feasible when there are pairwise distinct vertices \(v_1, \dots, v_m\) of the graph of the instance, with \(m \ge K\) and \(m \ge 3\), such that \(v_j\) is adjacent to \(v_{j+1}\) for every \(1 \le j < m\) and \(v_m\) is adjacent to \(v_1\). That is, the graph has a simple cycle with at least \(K\) edges and at least three vertices.
def LongestCycleFeasible
(i : LongestCycleInstance) : Prop :=
∃ cycle : List (Fin i.1), cycle.Nodup ∧ i.2.2 ≤ cycle.length ∧ 3 ≤ cycle.length ∧
(∀ j (h : j + 1 < cycle.length),
(Graph i).Adj (cycle[j]'(by omega)) (cycle[j + 1]'h)) ∧
∀ h : cycle ≠ [], (Graph i).Adj (cycle.getLast h) (cycle.head h)
abbrev LongestCycleInstance := ℕ × List (ℕ × ℕ) × ℕ
WantedExt/Complexity/NPComplete/LongestCycleWanted.lean:45
def Graph (i : LongestCycleInstance) : SimpleGraph (Fin i.1) :=
Cslib.Complexity.Karp.edgeGraph i.1 i.2.1
WantedExt/Complexity/NPComplete/LongestCycleWanted.lean:48
Uses 2 · Used by 1
DefinitionThe decision problem LONGEST CYCLE#✓fully proved
LONGEST CYCLE accepts a bitstring \(x\) exactly when \(x\) decodes, under the canonical bitstring encoding of instances, to an instance of LONGEST CYCLE that is well formed and feasible. Bitstrings that do not decode, and bitstrings that decode to instances that are not well formed, are rejected.
noncomputable def longestCycleDec :
MetaMathlibExt.ComplexityTheory.DecisionProblem := fun x =>
match MetaMathlibExt.BitstringEncoding.bitDecode
(α := LongestCycleInstance) x with
| some i => decide (WellFormed i ∧ LongestCycleFeasible 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 LongestCycleInstance := ℕ × List (ℕ × ℕ) × ℕ
WantedExt/Complexity/NPComplete/LongestCycleWanted.lean:45
def WellFormed (i : LongestCycleInstance) : Prop :=
i.2.1.Nodup ∧ ∀ e ∈ i.2.1, e.1 < i.1 ∧ e.2 < i.1 ∧ e.1 ≠ e.2 ∧ (e.2, e.1) ∉ i.2.1
WantedExt/Complexity/NPComplete/LongestCycleWanted.lean:53
def LongestCycleFeasible
(i : LongestCycleInstance) : Prop :=
∃ cycle : List (Fin i.1), cycle.Nodup ∧ i.2.2 ≤ cycle.length ∧ 3 ≤ cycle.length ∧
(∀ j (h : j + 1 < cycle.length),
(Graph i).Adj (cycle[j]'(by omega)) (cycle[j + 1]'h)) ∧
∀ h : cycle ≠ [], (Graph i).Adj (cycle.getLast h) (cycle.head h)
WantedExt/Complexity/NPComplete/LongestCycleWanted.lean:57
Uses 12 · Used by 1
TheoremLONGEST CYCLE is NP-complete#●ready to prove
The decision problem LONGEST CYCLE belongs to NP, and every decision problem in NP has a polynomial-time many-one reduction to LONGEST CYCLE.
public theorem_wanted longestCycle_npComplete :
longestCycleDec ∈ MetaMathlibExt.ComplexityTheory.NP ∧
∀ L : MetaMathlibExt.ComplexityTheory.DecisionProblem,
L ∈ MetaMathlibExt.ComplexityTheory.NP →
Cslib.CookLevin.PolyManyOneRed L longestCycleDec
noncomputable def longestCycleDec :
MetaMathlibExt.ComplexityTheory.DecisionProblem := fun x =>
match MetaMathlibExt.BitstringEncoding.bitDecode
(α := LongestCycleInstance) x with
| some i => decide (WellFormed i ∧ LongestCycleFeasible i)
| none => false
WantedExt/Complexity/NPComplete/LongestCycleWanted.lean:66
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
- M. R. Garey and D. S. Johnson, Computers and Intractability (1979), LONGEST CYCLE.
Uses 5
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.