Longest path
AbbreviationLongest-path instances#✓fully proved
A longest-path instance is a tuple \((n, E, K, s, t)\) consisting of a natural number \(n\), the number of vertices; a list \(E\) of pairs of natural numbers, the edges; and natural numbers \(K\), the length bound, \(s\), the start vertex, and \(t\), the target vertex.
abbrev LongestPathInstance := ℕ × List (ℕ × ℕ) × ℕ × ℕ × ℕ
DefinitionGraph of a longest-path instance#✓fully proved
For a longest-path instance with vertex count \(n\) and edge list \(E\), its graph is the graph of the edge list \(E\) on \(n\) vertices: 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\).
def Graph (i : LongestPathInstance) : SimpleGraph (Fin i.1) :=
Cslib.Complexity.Karp.edgeGraph i.1 i.2.1
abbrev LongestPathInstance := ℕ × List (ℕ × ℕ) × ℕ × ℕ × ℕ
WantedExt/Complexity/NPComplete/LongestPathWanted.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-path instances#✓fully proved
A longest-path instance \((n, E, K, s, t)\) is well formed when \(s < n\), \(t < n\), the list \(E\) has no repeated entries, and every pair \((u, v)\) in \(E\) satisfies \(u < n\), \(v < n\) and \(u \ne v\), and its reverse \((v, u)\) does not belong to \(E\).
def WellFormed (i : LongestPathInstance) : 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) ∧
i.2.2.2.1 < i.1 ∧ i.2.2.2.2 < i.1
abbrev LongestPathInstance := ℕ × List (ℕ × ℕ) × ℕ × ℕ × ℕ
WantedExt/Complexity/NPComplete/LongestPathWanted.lean:45
Uses 1 · Used by 1
DefinitionFeasibility of a longest-path instance#✓fully proved
A longest-path instance \((n, E, K, s, t)\) is feasible when the graph of \(E\) on \(n\) vertices has a simple path from \(s\) to \(t\) with at least \(K\) edges, that is, a list \(v_0, \dots, v_m\) of pairwise distinct vertices with \(m \ge K\), \(v_0 = s\) and \(v_m = t\), in which \(v_j\) and \(v_{j+1}\) are adjacent for every \(j < m\).
def LongestPathFeasible
(i : LongestPathInstance) : Prop :=
∃ path : List (Fin i.1), path.Nodup ∧ i.2.2.1 + 1 ≤ path.length ∧
(path.head?.map fun v => (v : ℕ)) = some i.2.2.2.1 ∧
(path.getLast?.map fun v => (v : ℕ)) = some i.2.2.2.2 ∧
∀ j (h : j + 1 < path.length),
(Graph i).Adj (path[j]'(by omega)) (path[j + 1]'h)
abbrev LongestPathInstance := ℕ × List (ℕ × ℕ) × ℕ × ℕ × ℕ
WantedExt/Complexity/NPComplete/LongestPathWanted.lean:45
def Graph (i : LongestPathInstance) : SimpleGraph (Fin i.1) :=
Cslib.Complexity.Karp.edgeGraph i.1 i.2.1
WantedExt/Complexity/NPComplete/LongestPathWanted.lean:48
Uses 2 · Used by 1
DefinitionThe LONGEST PATH decision problem#✓fully proved
LONGEST PATH is the decision problem that accepts a bitstring \(x\) exactly when \(x\) decodes, under the canonical bitstring encoding, to a longest-path instance \((n, E, K, s, t)\) that is well formed and in which the graph of \(E\) on \(n\) vertices has a simple path from \(s\) to \(t\) with at least \(K\) edges. Bitstrings that do not decode to a longest-path instance are rejected.
noncomputable def longestPathDec :
MetaMathlibExt.ComplexityTheory.DecisionProblem := fun x =>
match MetaMathlibExt.BitstringEncoding.bitDecode
(α := LongestPathInstance) x with
| some i => decide (WellFormed i ∧ LongestPathFeasible 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 LongestPathInstance := ℕ × List (ℕ × ℕ) × ℕ × ℕ × ℕ
WantedExt/Complexity/NPComplete/LongestPathWanted.lean:45
def WellFormed (i : LongestPathInstance) : 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) ∧
i.2.2.2.1 < i.1 ∧ i.2.2.2.2 < i.1
WantedExt/Complexity/NPComplete/LongestPathWanted.lean:53
def LongestPathFeasible
(i : LongestPathInstance) : Prop :=
∃ path : List (Fin i.1), path.Nodup ∧ i.2.2.1 + 1 ≤ path.length ∧
(path.head?.map fun v => (v : ℕ)) = some i.2.2.2.1 ∧
(path.getLast?.map fun v => (v : ℕ)) = some i.2.2.2.2 ∧
∀ j (h : j + 1 < path.length),
(Graph i).Adj (path[j]'(by omega)) (path[j + 1]'h)
WantedExt/Complexity/NPComplete/LongestPathWanted.lean:58
Uses 12 · Used by 1
TheoremLONGEST PATH is NP-complete#●ready to prove
The LONGEST PATH decision problem belongs to NP, and every decision problem in NP has a polynomial-time many-one reduction to LONGEST PATH.
public theorem_wanted longestPath_npComplete :
longestPathDec ∈ MetaMathlibExt.ComplexityTheory.NP ∧
∀ L : MetaMathlibExt.ComplexityTheory.DecisionProblem,
L ∈ MetaMathlibExt.ComplexityTheory.NP →
Cslib.CookLevin.PolyManyOneRed L longestPathDec
noncomputable def longestPathDec :
MetaMathlibExt.ComplexityTheory.DecisionProblem := fun x =>
match MetaMathlibExt.BitstringEncoding.bitDecode
(α := LongestPathInstance) x with
| some i => decide (WellFormed i ∧ LongestPathFeasible i)
| none => false
WantedExt/Complexity/NPComplete/LongestPathWanted.lean:68
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 PATH.
Uses 5
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.