The witness encoding respects concatenation to Length of an encoded PATH instance
TheoremThe witness encoding respects concatenation#✓fully proved
For lists \(p\) and \(p'\) of natural numbers, the witness encoding of the concatenation of \(p\) and \(p'\) is the witness encoding of \(p\) followed by the witness encoding of \(p'\).
theorem encW_append (p p' : List ℕ) : encW (p ++ p') = encW p ++ encW p'
def encW (p : List ℕ) : List Bool := p.flatMap fun v => List.replicate v true ++ [false]
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:53
Uses 1 · Used by 1
TheoremDecoding the empty witness#✓fully proved
The witness decoder succeeds on the empty list of bits and returns the empty list of vertices.
theorem decodeW_nil : decodeW [] = some []
def decodeW (w : List Bool) : Option (List ℕ) :=
if w = [] then some [] else
match h : readUnaryLength w with
| none => none
| some (v, r) =>
have : r.length < w.length := Karp.length_lt_of_readUnaryLength h
(decodeW r).map (v :: ·)
termination_by w.length
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:56
Uses 3 · Used by 3
TheoremWitness decoding fails on a cut-off first number#✓fully proved
If a list \(w\) of bits is nonempty and reading a unary number (a run of true ended by false) from the front of \(w\) fails, that is, every bit of \(w\) is true, then the witness decoder fails on \(w\).
theorem decodeW_of_none {w : List Bool} (hw : w ≠ []) (h : readUnaryLength w = none) :
decodeW w = none
def readUnaryLength : List Bool → Option (Nat × List Bool)
| [] => none
| false :: rest => some (0, rest)
| true :: rest => (readUnaryLength rest).map fun result => (result.1 + 1, result.2)
CSLibExt/Computability/CookLevin.lean:46
def decodeW (w : List Bool) : Option (List ℕ) :=
if w = [] then some [] else
match h : readUnaryLength w with
| none => none
| some (v, r) =>
have : r.length < w.length := Karp.length_lt_of_readUnaryLength h
(decodeW r).map (v :: ·)
termination_by w.length
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:56
Uses 3 · Used by 2
TheoremDecoding peels off the first number#✓fully proved
If reading a unary number from the front of a list \(w\) of bits returns \(v\) with remaining bits \(r\), that is, \(w\) is \(v\) copies of true, then false, then \(r\), then the witness decoder succeeds on \(w\) exactly when it succeeds on \(r\), and its result on \(w\) is \(v\) followed by its result on \(r\).
theorem decodeW_of_some {w r : List Bool} {v : ℕ} (h : readUnaryLength w = some (v, r)) :
decodeW w = (decodeW r).map (v :: ·)
def readUnaryLength : List Bool → Option (Nat × List Bool)
| [] => none
| false :: rest => some (0, rest)
| true :: rest => (readUnaryLength rest).map fun result => (result.1 + 1, result.2)
CSLibExt/Computability/CookLevin.lean:46
def decodeW (w : List Bool) : Option (List ℕ) :=
if w = [] then some [] else
match h : readUnaryLength w with
| none => none
| some (v, r) =>
have : r.length < w.length := Karp.length_lt_of_readUnaryLength h
(decodeW r).map (v :: ·)
termination_by w.length
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:56
Uses 3 · Used by 3
TheoremDecoding inverts the witness encoding#✓fully proved
For every list \(p\) of natural numbers, the witness decoder applied to the witness encoding of \(p\) (each entry \(v\) written as \(v\) copies of true followed by false) succeeds and returns \(p\).
theorem decodeW_encW : ∀ p, decodeW (encW p) = some p
def decodeW (w : List Bool) : Option (List ℕ) :=
if w = [] then some [] else
match h : readUnaryLength w with
| none => none
| some (v, r) =>
have : r.length < w.length := Karp.length_lt_of_readUnaryLength h
(decodeW r).map (v :: ·)
termination_by w.length
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:56
def encW (p : List ℕ) : List Bool := p.flatMap fun v => List.replicate v true ++ [false]
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:53
Uses 6 · Used by 3
TheoremThe witness decoder succeeds only on encodings#✓fully proved
For every bit string \(w\) and every list \(p\) of natural numbers, if the witness decoder returns \(p\) on \(w\), then \(w\) is the witness encoding of \(p\).
theorem encW_of_decodeW : ∀ {p : List ℕ} {w : List Bool}, decodeW w = some p → encW p = w
def decodeW (w : List Bool) : Option (List ℕ) :=
if w = [] then some [] else
match h : readUnaryLength w with
| none => none
| some (v, r) =>
have : r.length < w.length := Karp.length_lt_of_readUnaryLength h
(decodeW r).map (v :: ·)
termination_by w.length
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:56
def encW (p : List ℕ) : List Bool := p.flatMap fun v => List.replicate v true ++ [false]
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:53
Uses 7 · Used by 2
TheoremThe witness codec#✓fully proved
For every list \(w\) of bits and every list \(p\) of natural numbers, the witness decoder returns \(p\) on \(w\) if and only if \(w\) is the witness encoding of \(p\), which writes each entry \(v\) of \(p\) as \(v\) copies of true followed by false.
theorem decodeW_eq_some {w : List Bool} {p : List ℕ} : decodeW w = some p ↔ encW p = w
def decodeW (w : List Bool) : Option (List ℕ) :=
if w = [] then some [] else
match h : readUnaryLength w with
| none => none
| some (v, r) =>
have : r.length < w.length := Karp.length_lt_of_readUnaryLength h
(decodeW r).map (v :: ·)
termination_by w.length
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:56
def encW (p : List ℕ) : List Bool := p.flatMap fun v => List.replicate v true ++ [false]
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:53
Uses 4 · Used by 1
TheoremWitness length#✓fully proved
For every list \(p = (v_1, \dots, v_k)\) of natural numbers, the witness encoding of \(p\) has length \(\sum_{i=1}^{k} (v_i + 1)\).
theorem length_encW (p : List ℕ) : (encW p).length = (p.map (· + 1)).sum
def encW (p : List ℕ) : List Bool := p.flatMap fun v => List.replicate v true ++ [false]
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:53
Uses 2 · Used by 1
TheoremWitness length bound#✓fully proved
For every natural number \(n\) and every list \(p\) of natural numbers all below \(n\), the witness encoding of \(p\) has length at most \(|p| \cdot n\).
theorem length_encW_le {n : ℕ} : ∀ {p : List ℕ}, (∀ v ∈ p, v < n) →
(encW p).length ≤ p.length * n
def encW (p : List ℕ) : List Bool := p.flatMap fun v => List.replicate v true ++ [false]
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:53
Uses 2 · Used by 1
TheoremA witness is at least as long as its vertex list#✓fully proved
For every list \(p\) of natural numbers, the witness encoding of \(p\) has length at least \(|p|\).
theorem length_le_length_encW (p : List ℕ) : p.length ≤ (encW p).length
def encW (p : List ℕ) : List Bool := p.flatMap fun v => List.replicate v true ++ [false]
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:53
Uses 2 · Used by 1
DefinitionArc check of a vertex list#✓fully proved
Given \(n \in \mathbb{N}\) and a list \(E\) of pairs of natural numbers, the arc check of a list \(p\) of natural numbers returns true when every two consecutive entries \(u, v\) of \(p\) satisfy \((u, v) \in E\), \(u < n\) and \(v < n\), and false otherwise; in particular every list with fewer than two entries passes.
TheoremChecking a vertex list against the arcs#✓fully proved
For every \(n \in \mathbb{N}\), every list \(E\) of pairs of natural numbers and every list \(p\) of natural numbers, the arc check of \(p\) against \(n\) and \(E\) returns true if and only if every two consecutive entries \(u, v\) of \(p\) form an arc of the digraph on \(0, \dots, n - 1\) listed by \(E\), that is, \((u, v) \in E\), \(u < n\) and \(v < n\).
theorem chainOk_iff (n : ℕ) (es : List (ℕ × ℕ)) :
∀ p, chainOk n es p = true ↔ p.IsChain (Path.arc n es)
def chainOk (n : ℕ) (es : List (ℕ × ℕ)) : List ℕ → Bool
| u :: v :: p => decide ((u, v) ∈ es ∧ u < n ∧ v < n) && chainOk n es (v :: p)
| _ => true
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:164
def arc (n : ℕ) (es : List (ℕ × ℕ)) (u v : ℕ) : Prop := (u, v) ∈ es ∧ u < n ∧ v < n
CSLibExt/Computability/Complexity/Path.lean:53
Uses 2 · Used by 1
DefinitionThe Hamiltonian path check#✓fully proved
Given a natural number \(n\), an edge list \(E\), vertices \(s\) and \(t\) and a list \(p\) of natural numbers, the Boolean test that \(p\) has no repeated entries, has length \(n\), has all entries below \(n\), has first entry \(s\) and last entry \(t\), and that every two consecutive entries \(u, v\) of \(p\) satisfy \((u, v) \in E\), \(u < n\) and \(v < n\).
def hamOk (n : ℕ) (es : List (ℕ × ℕ)) (s t : ℕ) (p : List ℕ) : Bool :=
decide p.Nodup && p.length == n && p.all (· < n) && p.head? == some s &&
p.getLast? == some t && chainOk n es p
def chainOk (n : ℕ) (es : List (ℕ × ℕ)) : List ℕ → Bool
| u :: v :: p => decide ((u, v) ∈ es ∧ u < n ∧ v < n) && chainOk n es (v :: p)
| _ => true
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:164
Uses 1 · Used by 8
TheoremThe Hamiltonian path check is correct#✓fully proved
For all natural numbers \(n\), \(s\), \(t\), every edge list \(E\) and every list \(p\) of natural numbers, the Hamiltonian path check on \((n, E, s, t, p)\) returns true if and only if \(p\) is a Hamiltonian path from \(s\) to \(t\) in the digraph on \(\{0, \dots, n-1\}\) with edge list \(E\).
theorem hamOk_iff {n : ℕ} {es : List (ℕ × ℕ)} {s t : ℕ} {p : List ℕ} :
hamOk n es s t p = true ↔ IsHamPath n es s t p
def hamOk (n : ℕ) (es : List (ℕ × ℕ)) (s t : ℕ) (p : List ℕ) : Bool :=
decide p.Nodup && p.length == n && p.all (· < n) && p.head? == some s &&
p.getLast? == some t && chainOk n es p
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:179
def IsHamPath (n : ℕ) (es : List (ℕ × ℕ)) (s t : ℕ) (p : List ℕ) : Prop :=
p.Nodup ∧ p.length = n ∧ (∀ v ∈ p, v < n) ∧ p.head? = some s ∧ p.getLast? = some t ∧
p.IsChain (Path.arc n es)
CSLibExt/Computability/Complexity/Karp/HamPath.lean:53
Uses 5 · Used by 2
DefinitionThe HAMPATH verifier#✓fully proved
Given bit strings \(x\) and \(w\), the verifier decodes \(x\) as a PATH instance, consisting of a start vertex \(s\), a target vertex \(t\), a vertex count \(n\) and an edge list \(E\), and decodes \(w\) as a witness, a list \(p\) of natural numbers each written in unary. If both decodings succeed, it accepts exactly when the Hamiltonian path check passes, that is, when \(p\) is a Hamiltonian path from \(s\) to \(t\) in the digraph on \(\{0, \dots, n-1\}\) with edge list \(E\). If either decoding fails, it rejects.
def hamCheck (x w : List Bool) : Bool :=
match Path.decodeP x, decodeW w with
| some (s, t, n, es), some p => hamOk n es s t p
| _, _ => false
def decodeP (x : List Bool) : Option (ℕ × ℕ × ℕ × List (ℕ × ℕ)) :=
match readUnaryLength x with
| none => none
| some (s, r) =>
match readUnaryLength r with
| none => none
| some (t, r') => (Karp.decodeE r').map fun p => (s, t, p.1, p.2)
CSLibExt/Computability/Complexity/Path.lean:44
def decodeW (w : List Bool) : Option (List ℕ) :=
if w = [] then some [] else
match h : readUnaryLength w with
| none => none
| some (v, r) =>
have : r.length < w.length := Karp.length_lt_of_readUnaryLength h
(decodeW r).map (v :: ·)
termination_by w.length
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:56
def hamOk (n : ℕ) (es : List (ℕ × ℕ)) (s t : ℕ) (p : List ℕ) : Bool :=
decide p.Nodup && p.length == n && p.all (· < n) && p.head? == some s &&
p.getLast? == some t && chainOk n es p
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:179
Uses 3 · Used by 7
TheoremWhat the HAMPATH verifier accepts#✓fully proved
For bit strings \(x\) and \(w\), the HAMPATH verifier accepts \((x, w)\) if and only if there are natural numbers \(s\), \(t\), \(n\), a list \(es\) of pairs of natural numbers and a list \(p\) of natural numbers such that \(x\) is the PATH encoding of \((s, t, n, es)\), \(w\) is the witness encoding of \(p\), and \(p\) is a Hamiltonian path from \(s\) to \(t\) in the digraph on \(0, \dots, n - 1\) with edge list \(es\).
theorem hamCheck_iff (x w : List Bool) : hamCheck x w = true ↔
∃ s t n es p, Path.encodeP s t n es = x ∧ encW p = w ∧ IsHamPath n es s t p
def hamCheck (x w : List Bool) : Bool :=
match Path.decodeP x, decodeW w with
| some (s, t, n, es), some p => hamOk n es s t p
| _, _ => false
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:189
def encodeP (s t n : ℕ) (es : List (ℕ × ℕ)) : List Bool :=
List.replicate s true ++ false :: (List.replicate t true ++ false :: Karp.encodeE n es)
CSLibExt/Computability/Complexity/Path.lean:40
def encW (p : List ℕ) : List Bool := p.flatMap fun v => List.replicate v true ++ [false]
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:53
def IsHamPath (n : ℕ) (es : List (ℕ × ℕ)) (s t : ℕ) (p : List ℕ) : Prop :=
p.Nodup ∧ p.length = n ∧ (∀ v ∈ p, v < n) ∧ p.head? = some s ∧ p.getLast? = some t ∧
p.IsChain (Path.arc n es)
CSLibExt/Computability/Complexity/Karp/HamPath.lean:53
Uses 12 · Used by 1
TheoremThe verifier on an encoded instance and witness#✓fully proved
For natural numbers \(s\), \(t\), \(n\), a list \(es\) of pairs of natural numbers and a list \(p\) of natural numbers, the HAMPATH verifier applied to the PATH encoding of \((s, t, n, es)\) and the witness encoding of \(p\) returns the same boolean as the Hamiltonian path check on \(n\), \(es\), \(s\), \(t\) and \(p\).
theorem hamCheck_encode (s t n : ℕ) (es : List (ℕ × ℕ)) (p : List ℕ) :
hamCheck (Path.encodeP s t n es) (encW p) = hamOk n es s t p
def hamCheck (x w : List Bool) : Bool :=
match Path.decodeP x, decodeW w with
| some (s, t, n, es), some p => hamOk n es s t p
| _, _ => false
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:189
def encodeP (s t n : ℕ) (es : List (ℕ × ℕ)) : List Bool :=
List.replicate s true ++ false :: (List.replicate t true ++ false :: Karp.encodeE n es)
CSLibExt/Computability/Complexity/Path.lean:40
def encW (p : List ℕ) : List Bool := p.flatMap fun v => List.replicate v true ++ [false]
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:53
def hamOk (n : ℕ) (es : List (ℕ × ℕ)) (s t : ℕ) (p : List ℕ) : Bool :=
decide p.Nodup && p.length == n && p.all (· < n) && p.head? == some s &&
p.getLast? == some t && chainOk n es p
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:179
Uses 8 · Used by 1
TheoremInstances that do not decode are rejected#✓fully proved
If the PATH instance decoder fails on a bit string \(x\), then for every bit string \(w\) the HAMPATH verifier rejects \((x, w)\), that is, returns false.
theorem hamCheck_of_decodeP {x : List Bool} (h : Path.decodeP x = none) (w : List Bool) :
hamCheck x w = false
def decodeP (x : List Bool) : Option (ℕ × ℕ × ℕ × List (ℕ × ℕ)) :=
match readUnaryLength x with
| none => none
| some (s, r) =>
match readUnaryLength r with
| none => none
| some (t, r') => (Karp.decodeE r').map fun p => (s, t, p.1, p.2)
CSLibExt/Computability/Complexity/Path.lean:44
def hamCheck (x w : List Bool) : Bool :=
match Path.decodeP x, decodeW w with
| some (s, t, n, es), some p => hamOk n es s t p
| _, _ => false
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:189
Uses 4 · Used by 1
TheoremWitnesses that do not decode are rejected#✓fully proved
If the witness decoder fails on a bit string \(w\), then for every bit string \(x\) the HAMPATH verifier rejects \((x, w)\), that is, returns false.
theorem hamCheck_of_decodeW (x : List Bool) {w : List Bool} (h : decodeW w = none) :
hamCheck x w = false
def decodeW (w : List Bool) : Option (List ℕ) :=
if w = [] then some [] else
match h : readUnaryLength w with
| none => none
| some (v, r) =>
have : r.length < w.length := Karp.length_lt_of_readUnaryLength h
(decodeW r).map (v :: ·)
termination_by w.length
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:56
def hamCheck (x w : List Bool) : Bool :=
match Path.decodeP x, decodeW w with
| some (s, t, n, es), some p => hamOk n es s t p
| _, _ => false
CSLibExt/Computability/Complexity/Karp/HamPathCheck.lean:189
Uses 4 · Used by 1
TheoremLength of an encoded PATH instance#✓fully proved
For all natural numbers \(s\), \(t\), \(n\) and every edge list \(E\), the encoding of the PATH instance \((s, t, n, E)\) has length \(s + t + n + 3 + \ell\), where \(\ell\) is the length of the bit encoding of the edge list \(E\).
theorem length_encodeP (s t n : ℕ) (es : List (ℕ × ℕ)) :
(Path.encodeP s t n es).length = s + t + n + 3 + (Karp.edgeBits es).length
def encodeP (s t n : ℕ) (es : List (ℕ × ℕ)) : List Bool :=
List.replicate s true ++ false :: (List.replicate t true ++ false :: Karp.encodeE n es)
CSLibExt/Computability/Complexity/Path.lean:40
def edgeBits (es : List (ℕ × ℕ)) : List Bool :=
es.flatMap fun e => List.replicate e.1 true ++ false :: (List.replicate e.2 true ++ [false])
CSLibExt/Computability/Complexity/Karp/Color.lean:160
Uses 2 · Used by 1
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.