The row of a diamond in the HAMPATH emitter to A row starts at its left end
TheoremThe row of a diamond in the HAMPATH emitter#✓fully proved
Let \(B\), \(m\) and \(i\) be natural numbers, write \(\tau = m + i(3m+2)\) for the top vertex of diamond \(i\) and \(\rho_l = \tau + 1 + l\) for its row vertices, and encode an arc \((a, b)\) by the bits \(1^a 0 1^b 0\). Let \(s\) be a quiescent state of the emitter whose counters satisfy \(P = \tau\), \(M = 3m\), \(L = 0\), \(R = 0\), \(N \le B\), \(J \le B\) and \(D \le B\), and suppose \(\rho_{3m} \le B\). Then for every internal bit \(v\) there is an internal bit \(v'\) such that the emitter goes, in at most \(B(8B+15) + 2B + 5\) steps, from label \(\mathsf{r0}\) with bit \(v\) and the stacks of \(s\) to label \(\mathsf{e0}\) with bit \(v'\) and the stacks of the state obtained from \(s\) by setting \(R = \rho_{3m}\) and appending to its edge bits the codes of the arcs \((\rho_l, \rho_{l+1})\) and \((\rho_{l+1}, \rho_l)\) for \(l = 0, \dots, 3m-1\), in this order.
theorem drowFull_run (Bd m dI : ℕ) (s : MS) (v : Bool) (hp : s.p = hpT m dI)
(hmm : s.mm = 3 * m) (hl : s.l = 0) (hr : s.r = 0) (hn : s.n ≤ Bd) (hj : s.j ≤ Bd)
(hd : s.d ≤ Bd) (hB : hpR m dI (3 * m) ≤ Bd) :
∃ v', RunLe prog (Bd * (8 * Bd + 15) + 2 * Bd + 5) ⟨some .r0, v, s.stk⟩
⟨some .e0, v', { s with
r := hpR m dI (3 * m),
q := s.q ++ Karp.edgeBits ((List.range (3 * m)).flatMap (rowE m dI)) }.stk⟩
structure MS where
/-- The token stack. -/
t : List Sym
/-- The output stack. -/
o : List Bool
/-- The tokens in reading order. -/
f : List Sym
/-- The distinct variables. -/
v : List Sym
/-- The variable walk's other side. -/
w : List Sym
/-- The edge bits so far, in reading order. -/
⋯
CSLibExt/Computability/Complexity/Karp/HamPathEmitMachine.lean:284
def hpT (m i : ℕ) : ℕ := m + i * (3 * m + 2)
CSLibExt/Computability/Complexity/Karp/HamPath.lean:66
def hpR (m i l : ℕ) : ℕ := hpT m i + 1 + l
CSLibExt/Computability/Complexity/Karp/HamPath.lean:69
def RunLe (M : Λ → TM2.Stmt Γ Λ σ) (B : ℕ) (c d : TM2.Cfg Γ Λ σ) : Prop :=
∃ n, n ≤ B ∧ Run M n c d
MathlibExt/Computability/TuringMachine/Program.lean:901
def prog : Lab → TM2.Stmt Γ Lab Bool
| .a0 => .peek .T (fun _ o => o.isNone) <| .branch id (.goto fun _ => .b0) <|
.peek .T (fun _ o => o == some .cl) <| .branch id
(.pop .T (fun s _ => s) <| .push .F (fun _ => Sym.cl) <| .push .C (fun _ => Sym.cl) <|
pushList .M [Sym.cl, Sym.cl, Sym.cl] <| .goto fun _ => .a0)
(.pop .T (fun _ o => o == some (.lit true)) <| .push .F (fun s => Sym.lit s) <|
.goto fun _ => .anm)
| .anm => moveB .T .F Sym.bit? Sym.bit .anm (.aw false)
| .aw f => .peek .V (fun _ o => o.isNone) <| .branch id (.goto fun _ => .ab f)
(.goto fun _ => .ac f)
| .ac f => cmpB .F .V .X .Y Sym.bit? Sym.bit? Sym.bit Sym.bit (.ac f) (.ar1 true) (.ar1 f)
| .ar1 f => moveB .X .F Sym.bit? Sym.bit (.ar1 f) (.ar2 f)
⋯
CSLibExt/Computability/Complexity/Karp/HamPathEmitMachine.lean:188
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
def rowE (m i l : ℕ) : List (ℕ × ℕ) := [(hpR m i l, hpR m i (l + 1)), (hpR m i (l + 1), hpR m i l)]
CSLibExt/Computability/Complexity/Karp/HamPathEmitSpec.lean:49
Uses 17 · Used by 1
TheoremThe detours of a diamond#✓fully proved
Let \(B, i, y \in \mathbb{N}\), let \(\varphi\) be a CNF formula with \(m\) clauses and token list \(\mathrm{toks}(\varphi)\), let \(\nu\) be a list of symbols and \(b\) a state bit, and let \(s\) be a quiescent state of the emitter such that \(F\) holds \(\mathrm{toks}(\varphi)\), \(T\) and the scratch stack \(X\) are empty, \(V\) holds the name of \(y\), then a clause separator, then \(\nu\), the counter \(P\) equals the top of diamond \(i\) for \(m\) clauses, the counters \(J\) and \(D\) are \(0\), the counters \(N\) and \(R\) are at most \(B\), the binary encoding of \(y\) has length at most \(B\), and row vertex \(3m\) of diamond \(i\) is at most \(B\). Then for some state bit \(b'\) the emitter goes in at most \(|\mathrm{toks}(\varphi)|(3B + 6) + m(16B + 26) + 2B + 5\) steps from label \(\mathrm{e0}\) with state bit \(b\) and the stacks of \(s\) to label \(\mathrm{t0}\) with state bit \(b'\) and the stacks of \(s\) changed as follows: \(F\) becomes empty, \(T\) becomes \(\mathrm{toks}(\varphi)\) reversed, \(J\) becomes \(m\), \(D\) becomes row vertex \(3m + 1\) of diamond \(i\), and the edge-bit list \(q\) is extended by the bits of the detour arcs, for \(j = 0, \dots, m - 1\) in order, of clause \(j\) of \(\varphi\) in diamond \(i\) for variable \(y\).
theorem ddet_run (Bd dI y : ℕ) (φ : CNF) (VR : List Sym) (s : MS) (v : Bool)
(hf : s.f = toks φ) (ht : s.t = []) (hv : s.v = name y ++ Sym.cl :: VR) (hx : s.x = [])
(hp : s.p = hpT φ.length dI) (hj : s.j = 0) (hd : s.d = 0) (hn : s.n ≤ Bd) (hr : s.r ≤ Bd)
(hy : (encodeNat y).length ≤ Bd) (hB : hpR φ.length dI (3 * φ.length) ≤ Bd) :
∃ v', RunLe prog ((toks φ).length * (3 * Bd + 6) + φ.length * (16 * Bd + 26) + 2 * Bd + 5)
⟨some .e0, v, s.stk⟩
⟨some .t0, v', { s with
f := [], t := (toks φ).reverse, j := φ.length, d := hpR φ.length dI (3 * φ.length + 1),
q := s.q ++ Karp.edgeBits ((List.range φ.length).flatMap
(fun j => detE φ.length dI y j (φ.getD j []))) }.stk⟩
abbrev CNF := List CNFClause
CSLibExt/Logics/Propositional/CNF/Basic.lean:33
inductive Sym
| bit (b : Bool) | lit (p : Bool) | cl | val (b : Bool) | dead
deriving DecidableEq
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:41
structure MS where
/-- The token stack. -/
t : List Sym
/-- The output stack. -/
o : List Bool
/-- The tokens in reading order. -/
f : List Sym
/-- The distinct variables. -/
v : List Sym
/-- The variable walk's other side. -/
w : List Sym
/-- The edge bits so far, in reading order. -/
⋯
CSLibExt/Computability/Complexity/Karp/HamPathEmitMachine.lean:284
def toks (φ : CNF) : List Sym := φ.flatMap clauseToks
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:57
abbrev name (x : ℕ) : List Sym := (encodeNat x).map Sym.bit
CSLibExt/Computability/Complexity/Karp/HamPathEmitMachine.lean:574
def hpT (m i : ℕ) : ℕ := m + i * (3 * m + 2)
CSLibExt/Computability/Complexity/Karp/HamPath.lean:66
def hpR (m i l : ℕ) : ℕ := hpT m i + 1 + l
CSLibExt/Computability/Complexity/Karp/HamPath.lean:69
def RunLe (M : Λ → TM2.Stmt Γ Λ σ) (B : ℕ) (c d : TM2.Cfg Γ Λ σ) : Prop :=
∃ n, n ≤ B ∧ Run M n c d
MathlibExt/Computability/TuringMachine/Program.lean:901
def prog : Lab → TM2.Stmt Γ Lab Bool
| .a0 => .peek .T (fun _ o => o.isNone) <| .branch id (.goto fun _ => .b0) <|
.peek .T (fun _ o => o == some .cl) <| .branch id
(.pop .T (fun s _ => s) <| .push .F (fun _ => Sym.cl) <| .push .C (fun _ => Sym.cl) <|
pushList .M [Sym.cl, Sym.cl, Sym.cl] <| .goto fun _ => .a0)
(.pop .T (fun _ o => o == some (.lit true)) <| .push .F (fun s => Sym.lit s) <|
.goto fun _ => .anm)
| .anm => moveB .T .F Sym.bit? Sym.bit .anm (.aw false)
| .aw f => .peek .V (fun _ o => o.isNone) <| .branch id (.goto fun _ => .ab f)
(.goto fun _ => .ac f)
| .ac f => cmpB .F .V .X .Y Sym.bit? Sym.bit? Sym.bit Sym.bit (.ac f) (.ar1 true) (.ar1 f)
| .ar1 f => moveB .X .F Sym.bit? Sym.bit (.ar1 f) (.ar2 f)
⋯
CSLibExt/Computability/Complexity/Karp/HamPathEmitMachine.lean:188
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
def detE (m i x j : ℕ) (C : CNFClause) : List (ℕ × ℕ) :=
(if (x, true) ∈ C then [(hpR m i (3 * j + 1), j), (j, hpR m i (3 * j + 2))] else []) ++
(if (x, false) ∈ C then [(hpR m i (3 * j + 2), j), (j, hpR m i (3 * j + 1))] else [])
CSLibExt/Computability/Complexity/Karp/HamPathEmitSpec.lean:52
Uses 23 · Used by 1
TheoremEnd of a diamond#✓fully proved
Let \(\varphi\) be a CNF formula with token list \(\mathrm{toks}(\varphi)\), let \(y \in \mathbb{N}\) have binary encoding \(\mathrm{bin}(y)\), let \(\nu\) be a list of symbols and \(b\) a state bit, and let \(s\) be a quiescent state of the emitter whose stack \(T\) holds \(\mathrm{toks}(\varphi)\) reversed, whose stack \(F\) is empty, and whose stack \(V\) holds the name of \(y\), then a clause separator, then \(\nu\). Let \(p, n, r, j, d\) be the values of the counters \(P, N, R, J, D\) of \(s\). Then for some state bit \(b'\) the emitter goes in exactly \(|\mathrm{toks}(\varphi)| + |\mathrm{bin}(y)| + n + p + r + j + d + 9\) steps from label \(\mathrm{t0}\) with state bit \(b\) and the stacks of \(s\) to label \(\mathrm{h0}\) with state bit \(b'\) and the stacks of the quiescent state obtained from \(s\) by emptying \(T\), setting \(F\) to \(\mathrm{toks}(\varphi)\) and \(V\) to \(\nu\), prepending the reversed name of \(y\) to \(G\), setting \(P\) to \(n + 1\), and setting \(N\), \(R\), \(J\) and \(D\) to \(0\).
theorem dback_run (φ : CNF) (y : ℕ) (VR : List Sym) (s : MS) (v : Bool)
(ht : s.t = (toks φ).reverse) (hf : s.f = []) (hv : s.v = name y ++ Sym.cl :: VR) :
∃ v', Run prog ((toks φ).length + (encodeNat y).length + s.n + s.p + s.r + s.j + s.d + 9)
⟨some .t0, v, s.stk⟩
⟨some .h0, v', { s with
t := [], f := toks φ, v := VR, g := (name y).reverse ++ s.g, p := s.n + 1, n := 0,
r := 0, j := 0, d := 0 }.stk⟩
abbrev CNF := List CNFClause
CSLibExt/Logics/Propositional/CNF/Basic.lean:33
inductive Sym
| bit (b : Bool) | lit (p : Bool) | cl | val (b : Bool) | dead
deriving DecidableEq
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:41
structure MS where
/-- The token stack. -/
t : List Sym
/-- The output stack. -/
o : List Bool
/-- The tokens in reading order. -/
f : List Sym
/-- The distinct variables. -/
v : List Sym
/-- The variable walk's other side. -/
w : List Sym
/-- The edge bits so far, in reading order. -/
⋯
CSLibExt/Computability/Complexity/Karp/HamPathEmitMachine.lean:284
def toks (φ : CNF) : List Sym := φ.flatMap clauseToks
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:57
abbrev name (x : ℕ) : List Sym := (encodeNat x).map Sym.bit
CSLibExt/Computability/Complexity/Karp/HamPathEmitMachine.lean:574
def Run (n : ℕ) (c d : TM2.Cfg Γ Λ σ) : Prop :=
(flip bind (TM2.step M))^[n] (some c) = some d
MathlibExt/Computability/TuringMachine/Program.lean:84
def prog : Lab → TM2.Stmt Γ Lab Bool
| .a0 => .peek .T (fun _ o => o.isNone) <| .branch id (.goto fun _ => .b0) <|
.peek .T (fun _ o => o == some .cl) <| .branch id
(.pop .T (fun s _ => s) <| .push .F (fun _ => Sym.cl) <| .push .C (fun _ => Sym.cl) <|
pushList .M [Sym.cl, Sym.cl, Sym.cl] <| .goto fun _ => .a0)
(.pop .T (fun _ o => o == some (.lit true)) <| .push .F (fun s => Sym.lit s) <|
.goto fun _ => .anm)
| .anm => moveB .T .F Sym.bit? Sym.bit .anm (.aw false)
| .aw f => .peek .V (fun _ o => o.isNone) <| .branch id (.goto fun _ => .ab f)
(.goto fun _ => .ac f)
| .ac f => cmpB .F .V .X .Y Sym.bit? Sym.bit? Sym.bit Sym.bit (.ac f) (.ar1 true) (.ar1 f)
| .ar1 f => moveB .X .F Sym.bit? Sym.bit (.ar1 f) (.ar2 f)
⋯
CSLibExt/Computability/Complexity/Karp/HamPathEmitMachine.lean:188
Uses 25 · Used by 1
TheoremOne diamond#✓fully proved
Let \(B, i, y \in \mathbb{N}\), let \(u\) be a list of natural numbers, let \(\varphi\) be a CNF formula with \(m\) clauses and token list \(\mathrm{toks}(\varphi)\), let \(b\) be a state bit, and let \(s\) be a quiescent state of the emitter such that \(T\) and the scratch stack \(X\) are empty, \(F\) holds \(\mathrm{toks}(\varphi)\), \(V\) is the variable stack of the list \(y\) followed by \(u\), the counter \(P\) equals the top of diamond \(i\) for \(m\) clauses, the counter \(M\) equals \(3m\), the counters \(N, R, L, J, D\) are \(0\), and \(B\) bounds the top of diamond \(i + 1\), the length of the binary encoding of \(y\), and the length of \(\mathrm{toks}(\varphi)\). Then for some state bit \(b'\) the emitter goes in at most \(30B^2 + 100B + 100\) steps from label \(\mathrm{h0}\) with state bit \(b\) and the stacks of \(s\) back to label \(\mathrm{h0}\) with state bit \(b'\) and the stacks of \(s\) changed as follows: \(V\) becomes the variable stack of \(u\), \(P\) becomes the top of diamond \(i + 1\), the edge-bit list \(q\) is extended by the bits of the arcs of diamond \(i\) of \(\varphi\) for variable \(y\), and the reversed name of \(y\) is prepended to \(G\).
theorem diamond_run (Bd : ℕ) (φ : CNF) (dI y : ℕ) (ys : List ℕ) (s : MS) (v : Bool)
(ht : s.t = []) (hf : s.f = toks φ) (hv : s.v = vstk (y :: ys)) (hx : s.x = [])
(hp : s.p = hpT φ.length dI) (hmm : s.mm = 3 * φ.length) (hn : s.n = 0) (hr : s.r = 0)
(hl : s.l = 0) (hj : s.j = 0) (hd : s.d = 0) (hBd : hpT φ.length (dI + 1) ≤ Bd)
(hy : (encodeNat y).length ≤ Bd) (hL : (toks φ).length ≤ Bd) :
∃ v', RunLe prog (30 * Bd * Bd + 100 * Bd + 100) ⟨some .h0, v, s.stk⟩
⟨some .h0, v', { s with
v := vstk ys, p := hpT φ.length (dI + 1), q := s.q ++ Karp.edgeBits (diamondEdges φ dI y),
g := (name y).reverse ++ s.g }.stk⟩
abbrev CNF := List CNFClause
CSLibExt/Logics/Propositional/CNF/Basic.lean:33
structure MS where
/-- The token stack. -/
t : List Sym
/-- The output stack. -/
o : List Bool
/-- The tokens in reading order. -/
f : List Sym
/-- The distinct variables. -/
v : List Sym
/-- The variable walk's other side. -/
w : List Sym
/-- The edge bits so far, in reading order. -/
⋯
CSLibExt/Computability/Complexity/Karp/HamPathEmitMachine.lean:284
def toks (φ : CNF) : List Sym := φ.flatMap clauseToks
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:57
def vstk (vs : List ℕ) : List Sym := vs.flatMap fun x => name x ++ [Sym.cl]
CSLibExt/Computability/Complexity/Karp/HamPathEmitMachine.lean:577
def hpT (m i : ℕ) : ℕ := m + i * (3 * m + 2)
CSLibExt/Computability/Complexity/Karp/HamPath.lean:66
def RunLe (M : Λ → TM2.Stmt Γ Λ σ) (B : ℕ) (c d : TM2.Cfg Γ Λ σ) : Prop :=
∃ n, n ≤ B ∧ Run M n c d
MathlibExt/Computability/TuringMachine/Program.lean:901
def prog : Lab → TM2.Stmt Γ Lab Bool
| .a0 => .peek .T (fun _ o => o.isNone) <| .branch id (.goto fun _ => .b0) <|
.peek .T (fun _ o => o == some .cl) <| .branch id
(.pop .T (fun s _ => s) <| .push .F (fun _ => Sym.cl) <| .push .C (fun _ => Sym.cl) <|
pushList .M [Sym.cl, Sym.cl, Sym.cl] <| .goto fun _ => .a0)
(.pop .T (fun _ o => o == some (.lit true)) <| .push .F (fun s => Sym.lit s) <|
.goto fun _ => .anm)
| .anm => moveB .T .F Sym.bit? Sym.bit .anm (.aw false)
| .aw f => .peek .V (fun _ o => o.isNone) <| .branch id (.goto fun _ => .ab f)
(.goto fun _ => .ac f)
| .ac f => cmpB .F .V .X .Y Sym.bit? Sym.bit? Sym.bit Sym.bit (.ac f) (.ar1 true) (.ar1 f)
| .ar1 f => moveB .X .F Sym.bit? Sym.bit (.ar1 f) (.ar2 f)
⋯
CSLibExt/Computability/Complexity/Karp/HamPathEmitMachine.lean:188
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
def diamondEdges (φ : CNF) (i x : ℕ) : List (ℕ × ℕ) :=
let m := φ.length
[(hpT m i, hpR m i 0), (hpT m i, hpR m i (3 * m)), (hpR m i 0, hpT m (i + 1)),
(hpR m i (3 * m), hpT m (i + 1))] ++
(List.range (3 * m)).flatMap (fun l => [(hpR m i l, hpR m i (l + 1)),
(hpR m i (l + 1), hpR m i l)]) ++
(List.range m).flatMap fun j =>
(if (x, true) ∈ φ.getD j [] then [(hpR m i (3 * j + 1), j), (j, hpR m i (3 * j + 2))]
else []) ++
(if (x, false) ∈ φ.getD j [] then [(hpR m i (3 * j + 2), j), (j, hpR m i (3 * j + 1))]
else [])
CSLibExt/Computability/Complexity/Karp/HamPath.lean:72
abbrev name (x : ℕ) : List Sym := (encodeNat x).map Sym.bit
CSLibExt/Computability/Complexity/Karp/HamPathEmitMachine.lean:574
Uses 30 · Used by 1
TheoremThe diamonds#✓fully proved
Let \(B \in \mathbb{N}\) and let \(\varphi\) be a CNF formula with \(m\) clauses, token list \(\mathrm{toks}(\varphi)\) and list of distinct variables \(\mathrm{vars}(\varphi)\) of length \(k\). Suppose the top of diamond \(k\) for \(m\) clauses, the length of \(\mathrm{toks}(\varphi)\), and the length of the binary encoding of every \(y \in \mathrm{vars}(\varphi)\) are at most \(B\). Let \(\mathrm{vars}(\varphi)\) split as a list \(\pi\) followed by a list \(u\), let \(b\) be a state bit, and let \(s\) be a quiescent state of the emitter such that \(T\) and the scratch stack \(X\) are empty, \(F\) holds \(\mathrm{toks}(\varphi)\), \(V\) is the variable stack of \(u\), the counter \(P\) equals the top of diamond \(|\pi|\), the counter \(M\) equals \(3m\), the counters \(N, R, L, J, D\) are \(0\), and the edge-bit list \(q\) is the bits of the arcs of diamonds \(0, \dots, |\pi| - 1\) in order, diamond \(i\) taken for the \(i\)-th entry of \(\mathrm{vars}(\varphi)\). Then for some state bit \(b'\) and some stack contents \(g'\) the emitter goes in at most \(|u|(30B^2 + 100B + 100)\) steps from label \(\mathrm{h0}\) with state bit \(b\) and the stacks of \(s\) back to label \(\mathrm{h0}\) with state bit \(b'\) and the stacks of \(s\) changed as follows: \(V\) becomes empty, \(P\) becomes the top of diamond \(k\), \(q\) becomes the bits of all arcs of the construction for \(\varphi\), and \(G\) becomes \(g'\).
theorem diamonds_run (Bd : ℕ) (φ : CNF) (hBd : hpT φ.length (hamVars φ).length ≤ Bd)
(hL : (toks φ).length ≤ Bd) (hnm : ∀ y ∈ hamVars φ, (encodeNat y).length ≤ Bd) :
∀ (ys pre : List ℕ), hamVars φ = pre ++ ys → ∀ (s : MS) (v : Bool), s.t = [] →
s.f = toks φ → s.v = vstk ys → s.x = [] → s.p = hpT φ.length pre.length →
s.mm = 3 * φ.length → s.n = 0 → s.r = 0 → s.l = 0 → s.j = 0 → s.d = 0 →
s.q = Karp.edgeBits ((List.range pre.length).flatMap
(fun i => diamondEdges φ i ((hamVars φ).getD i 0))) →
∃ v' g', RunLe prog (ys.length * (30 * Bd * Bd + 100 * Bd + 100)) ⟨some .h0, v, s.stk⟩
⟨some .h0, v', { s with
v := [], p := hpT φ.length (hamVars φ).length, q := Karp.edgeBits (hamEdges φ),
g := g' }.stk⟩
abbrev CNF := List CNFClause
CSLibExt/Logics/Propositional/CNF/Basic.lean:33
def hpT (m i : ℕ) : ℕ := m + i * (3 * m + 2)
CSLibExt/Computability/Complexity/Karp/HamPath.lean:66
def hamVars (φ : CNF) : List ℕ := (varsOf φ).dedup
CSLibExt/Computability/Complexity/Karp/HamPath.lean:63
def toks (φ : CNF) : List Sym := φ.flatMap clauseToks
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:57
structure MS where
/-- The token stack. -/
t : List Sym
/-- The output stack. -/
o : List Bool
/-- The tokens in reading order. -/
f : List Sym
/-- The distinct variables. -/
v : List Sym
/-- The variable walk's other side. -/
w : List Sym
/-- The edge bits so far, in reading order. -/
⋯
CSLibExt/Computability/Complexity/Karp/HamPathEmitMachine.lean:284
def vstk (vs : List ℕ) : List Sym := vs.flatMap fun x => name x ++ [Sym.cl]
CSLibExt/Computability/Complexity/Karp/HamPathEmitMachine.lean:577
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
def diamondEdges (φ : CNF) (i x : ℕ) : List (ℕ × ℕ) :=
let m := φ.length
[(hpT m i, hpR m i 0), (hpT m i, hpR m i (3 * m)), (hpR m i 0, hpT m (i + 1)),
(hpR m i (3 * m), hpT m (i + 1))] ++
(List.range (3 * m)).flatMap (fun l => [(hpR m i l, hpR m i (l + 1)),
(hpR m i (l + 1), hpR m i l)]) ++
(List.range m).flatMap fun j =>
(if (x, true) ∈ φ.getD j [] then [(hpR m i (3 * j + 1), j), (j, hpR m i (3 * j + 2))]
else []) ++
(if (x, false) ∈ φ.getD j [] then [(hpR m i (3 * j + 2), j), (j, hpR m i (3 * j + 1))]
else [])
CSLibExt/Computability/Complexity/Karp/HamPath.lean:72
def RunLe (M : Λ → TM2.Stmt Γ Λ σ) (B : ℕ) (c d : TM2.Cfg Γ Λ σ) : Prop :=
∃ n, n ≤ B ∧ Run M n c d
MathlibExt/Computability/TuringMachine/Program.lean:901
def prog : Lab → TM2.Stmt Γ Lab Bool
| .a0 => .peek .T (fun _ o => o.isNone) <| .branch id (.goto fun _ => .b0) <|
.peek .T (fun _ o => o == some .cl) <| .branch id
(.pop .T (fun s _ => s) <| .push .F (fun _ => Sym.cl) <| .push .C (fun _ => Sym.cl) <|
pushList .M [Sym.cl, Sym.cl, Sym.cl] <| .goto fun _ => .a0)
(.pop .T (fun _ o => o == some (.lit true)) <| .push .F (fun s => Sym.lit s) <|
.goto fun _ => .anm)
| .anm => moveB .T .F Sym.bit? Sym.bit .anm (.aw false)
| .aw f => .peek .V (fun _ o => o.isNone) <| .branch id (.goto fun _ => .ab f)
(.goto fun _ => .ac f)
| .ac f => cmpB .F .V .X .Y Sym.bit? Sym.bit? Sym.bit Sym.bit (.ac f) (.ar1 true) (.ar1 f)
| .ar1 f => moveB .X .F Sym.bit? Sym.bit (.ar1 f) (.ar2 f)
⋯
CSLibExt/Computability/Complexity/Karp/HamPathEmitMachine.lean:188
def hamEdges (φ : CNF) : List (ℕ × ℕ) :=
(List.range (hamVars φ).length).flatMap fun i => diamondEdges φ i ((hamVars φ).getD i 0)
CSLibExt/Computability/Complexity/Karp/HamPath.lean:85
Uses 22 · Used by 1
TheoremThe output phase of the HAMPATH emitter#✓fully proved
Let \(s\) be a quiescent state of the emitter whose variable stack \(V\) is empty, with clause count \(C = c\), diamond-top counter \(P = p\), edge bits \(q\) and output stack \(o\). Then for every internal bit \(v\) there are an internal bit \(v'\) and stacks \(S'\) such that the emitter goes in exactly \(|q| + 4p + 2c + 11\) steps from label \(\mathsf{h0}\) with bit \(v\) and the stacks of \(s\) to label \(\mathsf{done}\) with bit \(v'\) and stacks \(S'\), and the output stack of \(S'\) is \(1^c 0 1^p 0 1^{p+1} 0\) followed by \(q\) and then \(o\).
theorem final_run (s : MS) (v : Bool) (hv : s.v = []) :
∃ v' S', Run prog (s.q.length + 4 * s.p + 2 * s.c + 11) ⟨some .h0, v, s.stk⟩
⟨some .done, v', S'⟩ ∧ S' .O = List.replicate s.c true ++ false ::
(List.replicate s.p true ++ false :: (List.replicate (s.p + 1) true ++ false ::
(s.q ++ s.o)))
structure MS where
/-- The token stack. -/
t : List Sym
/-- The output stack. -/
o : List Bool
/-- The tokens in reading order. -/
f : List Sym
/-- The distinct variables. -/
v : List Sym
/-- The variable walk's other side. -/
w : List Sym
/-- The edge bits so far, in reading order. -/
⋯
CSLibExt/Computability/Complexity/Karp/HamPathEmitMachine.lean:284
def Run (n : ℕ) (c d : TM2.Cfg Γ Λ σ) : Prop :=
(flip bind (TM2.step M))^[n] (some c) = some d
MathlibExt/Computability/TuringMachine/Program.lean:84
def prog : Lab → TM2.Stmt Γ Lab Bool
| .a0 => .peek .T (fun _ o => o.isNone) <| .branch id (.goto fun _ => .b0) <|
.peek .T (fun _ o => o == some .cl) <| .branch id
(.pop .T (fun s _ => s) <| .push .F (fun _ => Sym.cl) <| .push .C (fun _ => Sym.cl) <|
pushList .M [Sym.cl, Sym.cl, Sym.cl] <| .goto fun _ => .a0)
(.pop .T (fun _ o => o == some (.lit true)) <| .push .F (fun s => Sym.lit s) <|
.goto fun _ => .anm)
| .anm => moveB .T .F Sym.bit? Sym.bit .anm (.aw false)
| .aw f => .peek .V (fun _ o => o.isNone) <| .branch id (.goto fun _ => .ab f)
(.goto fun _ => .ac f)
| .ac f => cmpB .F .V .X .Y Sym.bit? Sym.bit? Sym.bit Sym.bit (.ac f) (.ar1 true) (.ar1 f)
| .ar1 f => moveB .X .F Sym.bit? Sym.bit (.ar1 f) (.ar2 f)
⋯
CSLibExt/Computability/Complexity/Karp/HamPathEmitMachine.lean:188
Uses 16 · Used by 1
TheoremCorrectness and running time of the HAMPATH emitter#✓fully proved
Let \(\varphi\) be a CNF formula with token sequence \(\mathrm{toks}(\varphi)\), let \(o\) be a list of bits, and let \(S\) be stacks in which the token stack \(T\) holds \(\mathrm{toks}(\varphi)\) reversed, the output stack \(O\) holds \(o\), and every other stack is empty. Then for every internal bit \(v\) there are an internal bit \(v'\) and stacks \(S'\) such that the emitter goes, in at most \(2000(|\mathrm{toks}(\varphi)| + 1)^5\) steps, from its start label with bit \(v\) and stacks \(S\) to label \(\mathsf{done}\) with bit \(v'\) and stacks \(S'\), and the output stack of \(S'\) is Sipser's HAMPATH instance for \(\varphi\) followed by \(o\) (so the instance is read top-first).
theorem run (φ : CNF) (o : List Bool) (v : Bool) (St : ∀ k, List (Γ k))
(hT : St .T = (toks φ).reverse) (hO : St .O = o) (h0 : ∀ k, k ≠ .T → k ≠ .O → St k = []) :
∃ v' S', RunLe prog (2000 * ((toks φ).length + 1) ^ 5) ⟨some start, v, St⟩
⟨some .done, v', S'⟩ ∧ S' .O = toHam φ ++ o
abbrev CNF := List CNFClause
CSLibExt/Logics/Propositional/CNF/Basic.lean:33
@[reducible] def Γ : K → Type
| .O => Bool
| _ => Sym
CSLibExt/Computability/Complexity/Karp/HamPathEmitMachine.lean:69
def toks (φ : CNF) : List Sym := φ.flatMap clauseToks
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:57
def RunLe (M : Λ → TM2.Stmt Γ Λ σ) (B : ℕ) (c d : TM2.Cfg Γ Λ σ) : Prop :=
∃ n, n ≤ B ∧ Run M n c d
MathlibExt/Computability/TuringMachine/Program.lean:901
def prog : Lab → TM2.Stmt Γ Lab Bool
| .a0 => .peek .T (fun _ o => o.isNone) <| .branch id (.goto fun _ => .b0) <|
.peek .T (fun _ o => o == some .cl) <| .branch id
(.pop .T (fun s _ => s) <| .push .F (fun _ => Sym.cl) <| .push .C (fun _ => Sym.cl) <|
pushList .M [Sym.cl, Sym.cl, Sym.cl] <| .goto fun _ => .a0)
(.pop .T (fun _ o => o == some (.lit true)) <| .push .F (fun s => Sym.lit s) <|
.goto fun _ => .anm)
| .anm => moveB .T .F Sym.bit? Sym.bit .anm (.aw false)
| .aw f => .peek .V (fun _ o => o.isNone) <| .branch id (.goto fun _ => .ab f)
(.goto fun _ => .ac f)
| .ac f => cmpB .F .V .X .Y Sym.bit? Sym.bit? Sym.bit Sym.bit (.ac f) (.ar1 true) (.ar1 f)
| .ar1 f => moveB .X .F Sym.bit? Sym.bit (.ar1 f) (.ar2 f)
⋯
CSLibExt/Computability/Complexity/Karp/HamPathEmitMachine.lean:188
def start : Lab := .a0
CSLibExt/Computability/Complexity/Karp/HamPathEmitMachine.lean:277
def toHam (φ : CNF) : List Bool :=
Path.encodeP (hpT φ.length 0) (hpT φ.length (hamVars φ).length)
(hpT φ.length (hamVars φ).length + 1) (hamEdges φ)
CSLibExt/Computability/Complexity/Karp/HamPath.lean:89
Uses 35 · Used by 1
DefinitionThe row of a diamond with its clauses inserted#✓fully proved
Let \(m\) and \(i\) be natural numbers and \(c : \mathbb{N} \to \mathbb{N}\) a map, and write \(r_l = m + i(3m + 2) + 1 + l\) for the row vertices of diamond \(i\). The row of diamond \(i\) for \(c\) is the list \(r_0, r_1, \dots, r_{3m}\) in which, for every \(j < m\) with \(c(j) = i\), the clause vertex \(j\) is inserted right after \(r_{3j+1}\).
def hfRow (m i : ℕ) (c : ℕ → ℕ) : List ℕ :=
(List.range (3 * m + 1)).flatMap fun l =>
hpR m i l :: if l % 3 = 1 ∧ c (l / 3) = i then [l / 3] else []
def hpR (m i l : ℕ) : ℕ := hpT m i + 1 + l
CSLibExt/Computability/Complexity/Karp/HamPath.lean:69
Uses 1 · Used by 8
DefinitionClauses picked up by a diamond#✓fully proved
For natural numbers \(m\) and \(i\) and a map \(c : \mathbb{N} \to \mathbb{N}\), the clauses picked up by diamond \(i\) are the list of all \(j < m\) with \(c(j) = i\), in increasing order.
These are the clause vertices of the row of diamond \(i\), in row order.
def hfPicks (m i : ℕ) (c : ℕ → ℕ) : List ℕ :=
(List.range (3 * m + 1)).flatMap fun l => if l % 3 = 1 ∧ c (l / 3) = i then [l / 3] else []
DefinitionThe visit of a diamond#✓fully proved
For \(m\) clauses, a diamond \(i\), a clause-to-diamond map \(c\) and a direction \(b\), the visit of diamond \(i\) is the list consisting of its top \(T_i = m + i(3m+2)\) followed by its row with the clauses sent to \(i\) by \(c\) inserted, read left to right if \(b\) is true and right to left otherwise.
def hfDiamond (m i : ℕ) (c : ℕ → ℕ) (b : Bool) : List ℕ :=
hpT m i :: if b then hfRow m i c else (hfRow m i c).reverse
def hpT (m i : ℕ) : ℕ := m + i * (3 * m + 2)
CSLibExt/Computability/Complexity/Karp/HamPath.lean:66
def hfRow (m i : ℕ) (c : ℕ → ℕ) : List ℕ :=
(List.range (3 * m + 1)).flatMap fun l =>
hpR m i l :: if l % 3 = 1 ∧ c (l / 3) = i then [l / 3] else []
CSLibExt/Computability/Complexity/Karp/HamPathForward.lean:46
Uses 2 · Used by 8
DefinitionThe forward path through the diamonds#✓fully proved
Let \(m\) and \(k\) be natural numbers, let \(c : \mathbb{N} \to \mathbb{N}\) be a map and let \(d : \mathbb{N} \to \{\mathrm{true}, \mathrm{false}\}\) give each diamond \(i\) a direction \(d(i)\). The forward path through the first \(k\) diamonds is the list obtained by concatenating, for \(i = 0, 1, \dots, k - 1\) in this order, the traversal of diamond \(i\) for \(c\) in direction \(d(i)\), and then appending the vertex \(m + k(3m + 2)\), the top of diamond \(k\). Here the traversal of diamond \(i\) is its top \(m + i(3m + 2)\) followed by its row \(r_0, r_1, \dots, r_{3m}\), where \(r_l = m + i(3m + 2) + 1 + l\) and the clause vertex \(j\) is inserted right after \(r_{3j+1}\) for every \(j < m\) with \(c(j) = i\); the row is read left to right if \(d(i)\) is true and right to left otherwise.
def hfPath (m k : ℕ) (c : ℕ → ℕ) (d : ℕ → Bool) : List ℕ :=
(List.range k).flatMap (fun i => hfDiamond m i c (d i)) ++ [hpT m k]
def hfDiamond (m i : ℕ) (c : ℕ → ℕ) (b : Bool) : List ℕ :=
hpT m i :: if b then hfRow m i c else (hfRow m i c).reverse
CSLibExt/Computability/Complexity/Karp/HamPathForward.lean:55
def hpT (m i : ℕ) : ℕ := m + i * (3 * m + 2)
CSLibExt/Computability/Complexity/Karp/HamPath.lean:66
Uses 2 · Used by 6
TheoremClause vertices picked up by a row#✓fully proved
Let \(m\) and \(i\) be natural numbers and let \(c : \mathbb{N} \to \mathbb{N}\). A natural number \(v\) is one of the clause vertices picked up by the row of diamond \(i\) under \(c\), for \(m\) clauses, if and only if \(v < m\) and \(c(v) = i\).
theorem mem_hfPicks {m i v : ℕ} {c : ℕ → ℕ} : v ∈ hfPicks m i c ↔ v < m ∧ c v = i
def hfPicks (m i : ℕ) (c : ℕ → ℕ) : List ℕ :=
(List.range (3 * m + 1)).flatMap fun l => if l % 3 = 1 ∧ c (l / 3) = i then [l / 3] else []
CSLibExt/Computability/Complexity/Karp/HamPathForward.lean:51
Uses 1 · Used by 1
TheoremThe clause vertices of a row are distinct#✓fully proved
For all natural numbers \(m\), \(i\) and every function \(c : \mathbb{N} \to \mathbb{N}\), the list of clause vertices picked up by the row of diamond \(i\) under \(c\), for \(m\) clauses, has no repeated entries.
theorem nodup_hfPicks (m i : ℕ) (c : ℕ → ℕ) : (hfPicks m i c).Nodup
def hfPicks (m i : ℕ) (c : ℕ → ℕ) : List ℕ :=
(List.range (3 * m + 1)).flatMap fun l => if l % 3 = 1 ∧ c (l / 3) = i then [l / 3] else []
CSLibExt/Computability/Complexity/Karp/HamPathForward.lean:51
Uses 1 · Used by 1
TheoremEach clause is picked up by exactly one row#✓fully proved
Let \(m, k\) be natural numbers and let \(c\) send every clause \(j < m\) to a diamond \(c(j) < k\). For each diamond \(i\), list the clauses \(j < m\) with \(c(j) = i\) in increasing order (the clause vertices picked up by the row of diamond \(i\)). Concatenating these lists for \(i = 0, \dots, k - 1\) gives a permutation of \(0, 1, \dots, m - 1\).
theorem flatMap_hfPicks_perm {m k : ℕ} {c : ℕ → ℕ} (hc : ∀ j < m, c j < k) :
(List.range k).flatMap (fun i => hfPicks m i c) ~ List.range m
def hfPicks (m i : ℕ) (c : ℕ → ℕ) : List ℕ :=
(List.range (3 * m + 1)).flatMap fun l => if l % 3 = 1 ∧ c (l / 3) = i then [l / 3] else []
CSLibExt/Computability/Complexity/Karp/HamPathForward.lean:51
Uses 3 · Used by 1
TheoremThe vertices of a diamond row#✓fully proved
For natural numbers \(m\) and \(i\) and a map \(c : \mathbb{N} \to \mathbb{N}\), let \(r = m + i(3m + 2) + 1\) be the left end of the row of diamond \(i\). The row of diamond \(i\) for \(c\) (with its clause vertices inserted) is a permutation of the concatenation of the list \(r, r + 1, \dots, r + 3m\) and the list of clauses picked up by diamond \(i\) for \(c\), that is, of all \(j < m\) with \(c(j) = i\) in increasing order.
theorem hfRow_perm (m i : ℕ) (c : ℕ → ℕ) :
hfRow m i c ~ List.range' (hpR m i 0) (3 * m + 1) ++ hfPicks m i c
def hfRow (m i : ℕ) (c : ℕ → ℕ) : List ℕ :=
(List.range (3 * m + 1)).flatMap fun l =>
hpR m i l :: if l % 3 = 1 ∧ c (l / 3) = i then [l / 3] else []
CSLibExt/Computability/Complexity/Karp/HamPathForward.lean:46
def hpR (m i l : ℕ) : ℕ := hpT m i + 1 + l
CSLibExt/Computability/Complexity/Karp/HamPath.lean:69
def hfPicks (m i : ℕ) (c : ℕ → ℕ) : List ℕ :=
(List.range (3 * m + 1)).flatMap fun l => if l % 3 = 1 ∧ c (l / 3) = i then [l / 3] else []
CSLibExt/Computability/Complexity/Karp/HamPathForward.lean:51
Uses 3 · Used by 1
TheoremA diamond visit is a block of consecutive vertices plus its clauses#✓fully proved
For \(m\) clauses, a diamond \(i\), a clause-to-diamond map \(c\) and a direction \(b\), let \(T_i = m + i(3m+2)\) be the top of diamond \(i\). The visit of diamond \(i\) in direction \(b\) is a rearrangement of the list that consists of \(T_i, T_i + 1, \dots, T_i + 3m + 1\) and then the clauses \(j < m\) with \(c(j) = i\) in increasing order.
theorem hfDiamond_perm (m i : ℕ) (c : ℕ → ℕ) (b : Bool) :
hfDiamond m i c b ~ List.range' (hpT m i) (3 * m + 2) ++ hfPicks m i c
def hfDiamond (m i : ℕ) (c : ℕ → ℕ) (b : Bool) : List ℕ :=
hpT m i :: if b then hfRow m i c else (hfRow m i c).reverse
CSLibExt/Computability/Complexity/Karp/HamPathForward.lean:55
def hpT (m i : ℕ) : ℕ := m + i * (3 * m + 2)
CSLibExt/Computability/Complexity/Karp/HamPath.lean:66
def hfPicks (m i : ℕ) (c : ℕ → ℕ) : List ℕ :=
(List.range (3 * m + 1)).flatMap fun l => if l % 3 = 1 ∧ c (l / 3) = i then [l / 3] else []
CSLibExt/Computability/Complexity/Karp/HamPathForward.lean:51
Uses 6 · Used by 1
TheoremThe first \(t\) diamonds occupy consecutive vertices#✓fully proved
For natural numbers \(m\) and \(t\), let \(T_i = m + i(3m+2)\). Concatenating, for \(i = 0, \dots, t - 1\), the lists \(T_i, T_i + 1, \dots, T_i + 3m + 1\) of \(3m + 2\) consecutive numbers (the top and the row of diamond \(i\)) gives the list \(m, m + 1, \dots, m + t(3m+2) - 1\), that is, the numbers from \(m\) to \(T_t - 1\) in increasing order.
theorem flatMap_range'_hpT (m t : ℕ) :
(List.range t).flatMap (fun i => List.range' (hpT m i) (3 * m + 2)) =
List.range' m (t * (3 * m + 2))
def hpT (m i : ℕ) : ℕ := m + i * (3 * m + 2)
CSLibExt/Computability/Complexity/Karp/HamPath.lean:66
Uses 1 · Used by 1
TheoremThe forward path visits every vertex once#✓fully proved
Let \(m, k\) be natural numbers, let \(c\) send every clause \(j < m\) to a diamond \(c(j) < k\), let \(d\) be any directions, and let \(T_k = m + k(3m+2)\). The forward path through the first \(k\) diamonds in directions \(d\) with clause choice \(c\) is a permutation of the list \(0, 1, \dots, T_k\).
theorem hfPath_perm {m k : ℕ} {c : ℕ → ℕ} (d : ℕ → Bool) (hc : ∀ j < m, c j < k) :
hfPath m k c d ~ List.range (hpT m k + 1)
def hfPath (m k : ℕ) (c : ℕ → ℕ) (d : ℕ → Bool) : List ℕ :=
(List.range k).flatMap (fun i => hfDiamond m i c (d i)) ++ [hpT m k]
CSLibExt/Computability/Complexity/Karp/HamPathForward.lean:59
def hpT (m i : ℕ) : ℕ := m + i * (3 * m + 2)
CSLibExt/Computability/Complexity/Karp/HamPath.lean:66
Uses 7 · Used by 1
TheoremChain condition for a diamond row#✓fully proved
Let \(R\) be a relation on \(\mathbb{N}\), let \(m\) and \(i\) be natural numbers and \(c : \mathbb{N} \to \mathbb{N}\) a map, and write \(r_l = m + i(3m + 2) + 1 + l\) for the row vertices of diamond \(i\). If \(R(r_l, r_{l+1})\) holds for every \(l < 3m\), and \(R(r_{3j+1}, j)\) and \(R(j, r_{3j+2})\) hold for every \(j < m\) with \(c(j) = i\), then the row of diamond \(i\) for \(c\) is a chain for \(R\): every entry is related by \(R\) to the next one.
theorem isChain_hfRow {R : ℕ → ℕ → Prop} {m i : ℕ} {c : ℕ → ℕ}
(hrow : ∀ l < 3 * m, R (hpR m i l) (hpR m i (l + 1)))
(hdet : ∀ j < m, c j = i → R (hpR m i (3 * j + 1)) j ∧ R j (hpR m i (3 * j + 2))) :
(hfRow m i c).IsChain R
def hpR (m i l : ℕ) : ℕ := hpT m i + 1 + l
CSLibExt/Computability/Complexity/Karp/HamPath.lean:69
def hfRow (m i : ℕ) (c : ℕ → ℕ) : List ℕ :=
(List.range (3 * m + 1)).flatMap fun l =>
hpR m i l :: if l % 3 = 1 ∧ c (l / 3) = i then [l / 3] else []
CSLibExt/Computability/Complexity/Karp/HamPathForward.lean:46
Uses 2 · Used by 1
TheoremA row starts at its left end#✓fully proved
For \(m\) clauses, a diamond \(i\) and any clause-to-diamond map \(c\), the row of diamond \(i\) read left to right, with the clauses sent to \(i\) by \(c\) inserted, starts at its left end, the row vertex \(T_i + 1\), where \(T_i = m + i(3m+2)\) is the top of diamond \(i\).
theorem head?_hfRow (m i : ℕ) (c : ℕ → ℕ) : (hfRow m i c).head? = some (hpR m i 0)
def hfRow (m i : ℕ) (c : ℕ → ℕ) : List ℕ :=
(List.range (3 * m + 1)).flatMap fun l =>
hpR m i l :: if l % 3 = 1 ∧ c (l / 3) = i then [l / 3] else []
CSLibExt/Computability/Complexity/Karp/HamPathForward.lean:46
def hpR (m i l : ℕ) : ℕ := hpT m i + 1 + l
CSLibExt/Computability/Complexity/Karp/HamPath.lean:69
Uses 2 · Used by 1
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.