The SAT verifier machine to SAT is in NP
DefinitionThe SAT verifier machine#✓fully proved
For a flag \(\mathit{cap}\), the host machine is the finite multi-stack Turing machine whose stacks are the host stacks, with the input stack as input (its alphabet is that of the pair encoding: tagged formula bits, a separator and tagged witness bits), the output stack (alphabet the booleans) as output, the host alphabets on all stacks, the host labels as labels, the first phase-0 label as start label, a boolean internal state initially false, and the host program with flag \(\mathit{cap}\) as program.
def tm (cap : Bool) : FinTM2 where
K := HK
k₀ := .inp
k₁ := .out
Γ := HΓ
Λ := HLab
main := .ph .m1
σ := Bool
initialState := false
m := hprog cap
inductive HK | inp | out | X | W | T | B | S | A | C | V | P | F | CC | LC | X1 | W1 | U
deriving DecidableEq
CSLibExt/Computability/Complexity/SatVerifierTM.lean:56
@[reducible] def HΓ : HK → Type
| .inp => G
| .out => Bool
| _ => Sym
CSLibExt/Computability/Complexity/SatVerifierTM.lean:65
inductive HLab
| ph (p : P0)
| tok (l : Tokenizer.Lab)
| flt (l : Karp.Filter3.Lab)
| chk (l : Check.DLab ⊕ Lookup.Lab)
| clean (ans : Bool)
| fin (ans : Bool)
deriving DecidableEq
CSLibExt/Computability/Complexity/SatVerifierTM.lean:79
def hprog (cap : Bool) : HLab → TM2.Stmt HΓ HLab Bool
| .ph .m1 => moveB (Γ := HΓ) HK.inp HK.X1 dX Sym.bit (.ph .m1) (.ph .m2)
| .ph .m2 => moveB (Γ := HΓ) HK.X1 HK.X Sym.bit? Sym.bit (.ph .m2) (.ph .sep)
| .ph .sep => .pop .inp (fun s _ => s) (.goto fun _ => .ph .m3)
| .ph .m3 => moveB (Γ := HΓ) HK.inp HK.W1 dW Sym.bit (.ph .m3) (.ph .m4)
| .ph .m4 => moveB (Γ := HΓ) HK.W1 HK.W Sym.bit? Sym.bit (.ph .m4) (.tok Tokenizer.start)
| .tok l => mapS embT φT (Tokenizer.prog l)
| .flt l => mapS embF φF (Karp.Filter3.prog cap l)
| .chk l => mapS embC φC (Check.prog lkH Lookup.start l)
| .clean ans => cleanS workKs (.clean ans) (.fin ans)
| .fin ans => .push .out (fun _ => ans) (.load (fun _ => false) .halt)
CSLibExt/Computability/Complexity/SatVerifierTM.lean:188
Uses 10 · Used by 4
TheoremPhase 0 of the SAT verifier host#✓fully proved
Let \(c\) be a flag, \(x\) and \(w\) bit strings of lengths \(m\) and \(n\), \(v\) an internal state, and \(S\) host stacks whose input stack holds the pair encoding \(x \# w\) and whose other stacks are all empty. Then there are an internal state \(v'\) and host stacks \(S'\) such that the host program with flag \(c\) runs in exactly \(2m + 2n + 5\) steps from the configuration at the phase-0 label \(m_1\) with internal state \(v\) and stacks \(S\) to the configuration at the start label of the tokenizer with internal state \(v'\) and stacks \(S'\), the stack \(X\) of \(S'\) holds the bits of \(x\) in order and the stack \(W\) holds the bits of \(w\) in order, each as a name-bit symbol, and every other stack of \(S'\) is empty.
theorem phase0_run (x w : List Bool) (v : Bool) (S : ∀ k, List (HΓ k))
(hinp : S .inp = Cslib.Complexity.DenseSAT.Verifier.pairEncode (x, w))
(h0 : ∀ k, k ≠ .inp → S k = []) :
∃ v' S', Run (hprog cap) (2 * x.length + 2 * w.length + 5) ⟨some (.ph .m1), v, S⟩
⟨some (.tok Tokenizer.start), v', S'⟩ ∧
S' .X = x.map Sym.bit ∧ S' .W = w.map Sym.bit ∧ ∀ k, k ≠ .X → k ≠ .W → S' k = []
@[reducible] def HΓ : HK → Type
| .inp => G
| .out => Bool
| _ => Sym
CSLibExt/Computability/Complexity/SatVerifierTM.lean:65
def pairEncode (p : List Bool × List Bool) : List G :=
p.1.map Sum.inl ++ Sum.inr none :: p.2.map fun b => Sum.inr (some b)
CSLibExt/Computability/Complexity/DenseSATVerifier.lean:71
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 hprog (cap : Bool) : HLab → TM2.Stmt HΓ HLab Bool
| .ph .m1 => moveB (Γ := HΓ) HK.inp HK.X1 dX Sym.bit (.ph .m1) (.ph .m2)
| .ph .m2 => moveB (Γ := HΓ) HK.X1 HK.X Sym.bit? Sym.bit (.ph .m2) (.ph .sep)
| .ph .sep => .pop .inp (fun s _ => s) (.goto fun _ => .ph .m3)
| .ph .m3 => moveB (Γ := HΓ) HK.inp HK.W1 dW Sym.bit (.ph .m3) (.ph .m4)
| .ph .m4 => moveB (Γ := HΓ) HK.W1 HK.W Sym.bit? Sym.bit (.ph .m4) (.tok Tokenizer.start)
| .tok l => mapS embT φT (Tokenizer.prog l)
| .flt l => mapS embF φF (Karp.Filter3.prog cap l)
| .chk l => mapS embC φC (Check.prog lkH Lookup.start l)
| .clean ans => cleanS workKs (.clean ans) (.fin ans)
| .fin ans => .push .out (fun _ => ans) (.load (fun _ => false) .halt)
CSLibExt/Computability/Complexity/SatVerifierTM.lean:188
def start : Lab := .un true
CSLibExt/Computability/Complexity/SatTokenizer.lean:115
inductive Sym
| bit (b : Bool) | lit (p : Bool) | cl | val (b : Bool) | dead
deriving DecidableEq
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:41
Uses 17 · Used by 1
TM2 SAT verifierTheoremThe tokenizer embeds in the SAT verifier host#✓fully proved
For every flag \(c\), the tokenizer program embeds in the host program with flag \(c\) along the stack embedding of the tokenizer into the host and the map of tokenizer labels into host labels, which sends the tokenizer's accepting label to the start label of the clause-length filter, its rejecting label to the cleanup label with answer false, and every other label \(\ell\) to the host label running the tokenizer at \(\ell\). That is, for every tokenizer label \(\ell\), either the tokenizer's statement at \(\ell\) is the halt statement, or the host program's statement at the image of \(\ell\) is the tokenizer's statement at \(\ell\) translated along this embedding and label map.
theorem embeds_tok : Embeds embT φT Tokenizer.prog (hprog cap)
def Embeds (M : Λ → TM2.Stmt Γ Λ σ) (M' : Λ' → TM2.Stmt Γ' Λ' σ) : Prop :=
∀ l, M' (φ l) = mapS E φ (M l) ∨ M l = .halt
MathlibExt/Computability/TuringMachine/StackEmbedding.lean:76
def embT : SEmb (fun _ : Tokenizer.K => Sym) HΓ where
e := eT
inj a b h := by cases a <;> cases b <;> first | rfl | exact absurd h (by decide)
ι k := match k with
| .X => Equiv.refl Sym | .W => Equiv.refl Sym | .T => Equiv.refl Sym
| .B => Equiv.refl Sym | .CC => Equiv.refl Sym | .LC => Equiv.refl Sym
CSLibExt/Computability/Complexity/SatVerifierTM.lean:111
def φT (l : Tokenizer.Lab) : HLab :=
if l = .acc then .flt Karp.Filter3.start else if l = .rej then .clean false else .tok l
CSLibExt/Computability/Complexity/SatVerifierTM.lean:163
def prog : Lab → TM2.Stmt (fun _ : K => Sym) Lab Bool
| .un true => unary .CC (.un true) .cls
| .un false => unary .LC (.un false) .lits
| .cls => pop .CC (fun _ o => o.isSome) <| branch id (goto fun _ => .un false)
(goto fun _ => .fin)
| .lits => pop .LC (fun _ o => o.isSome) <| branch id (goto fun _ => .nm none)
(push .T (fun _ => .cl) <| goto fun _ => .cls)
| .nm last => peek .X (fun _ o => topIsBit true o) <| branch id
(pop .X (fun s _ => s) <| peek .X (fun _ o => isBit Sym.bit? o) <| branch id
(pop .X (fun _ o => bitOf Sym.bit? o) <| push .T (fun s => .bit s) <|
push .B (fun s => .bit s) <|
goto fun s => .nm (some s))
⋯
CSLibExt/Computability/Complexity/SatTokenizer.lean:88
def hprog (cap : Bool) : HLab → TM2.Stmt HΓ HLab Bool
| .ph .m1 => moveB (Γ := HΓ) HK.inp HK.X1 dX Sym.bit (.ph .m1) (.ph .m2)
| .ph .m2 => moveB (Γ := HΓ) HK.X1 HK.X Sym.bit? Sym.bit (.ph .m2) (.ph .sep)
| .ph .sep => .pop .inp (fun s _ => s) (.goto fun _ => .ph .m3)
| .ph .m3 => moveB (Γ := HΓ) HK.inp HK.W1 dW Sym.bit (.ph .m3) (.ph .m4)
| .ph .m4 => moveB (Γ := HΓ) HK.W1 HK.W Sym.bit? Sym.bit (.ph .m4) (.tok Tokenizer.start)
| .tok l => mapS embT φT (Tokenizer.prog l)
| .flt l => mapS embF φF (Karp.Filter3.prog cap l)
| .chk l => mapS embC φC (Check.prog lkH Lookup.start l)
| .clean ans => cleanS workKs (.clean ans) (.fin ans)
| .fin ans => .push .out (fun _ => ans) (.load (fun _ => false) .halt)
CSLibExt/Computability/Complexity/SatVerifierTM.lean:188
Uses 35 · Used by 1
TM2 SAT verifierTheoremThe embedded lookup meets the lookup contract#✓fully proved
The clause-check driver, with the embedded lookup program as its lookup sub-program and the lookup's start label as the label it calls, meets the driver's lookup contract with constants \(a = 8\) and \(b = 4\): from the lookup's start label, with a reversed name block \(q\) on the token stack \(T\) above a rest that does not begin with a name bit, the table stack of an entry list \(es\) on \(B\), and the stacks \(S\), \(A\), \(C\), \(V\) empty, it reaches the driver's return label within \(8m + 4\) steps, where \(m\) is the length of the table stack, with \(V\) holding the single bit of the live value of \(q\) in \(es\) and every other stack unchanged.
theorem lookupSpec : Check.LookupSpec lkH Lookup.start 8 4
def LookupSpec (lk : LL → Stmt LL) (l0 : LL) (a b : ℕ) : Prop :=
∀ (q : List Bool) (es : List Ent) (R : List Sym), R.head?.bind Sym.bit? = none →
∀ (v : Bool) (St : ∀ _ : K, List Sym), St .T = (q.map Sym.bit).reverse ++ R →
St .B = tblStk es → St .S = [] → St .A = [] → St .C = [] → St .V = [] →
∃ v', RunLe (prog lk l0) (a * (tblStk es).length + b) ⟨some (.inr l0), v, St⟩
⟨some (.inl .ret), v', update St .V [Sym.bit (liveVal es q)]⟩
CSLibExt/Computability/Complexity/SatCheck.lean:94
def lkH (l : Lookup.Lab) : Check.Stmt Lookup.Lab := mapS embL φL (Lookup.prog l)
CSLibExt/Computability/Complexity/SatVerifierTM.lean:132
def start : Lab := .init
CSLibExt/Computability/Complexity/SatLookup.lean:95
Uses 27 · Used by 1
TM2 SAT verifierTheoremThe cleanup stacks are distinct#✓fully proved
The list of stacks emptied by the cleanup of the SAT verifier host has no repeated entries.
theorem workKs_nodup : workKs.Nodup
def workKs : List HK := [.inp, .X, .W, .T, .B, .S, .A, .C, .V, .P, .F, .CC, .LC, .X1, .W1, .U]
CSLibExt/Computability/Complexity/SatVerifierTM.lean:185
Uses 2 · Used by 1
TheoremCleanup of the SAT host#✓fully proved
Let \(m\) be a natural number and let \(S\) assign contents to the host stacks so that every stack has length at most \(m\) and the output stack is empty. Then for every flag \(c\), answer bit \(a\) and internal state \(v\), the host program with flag \(c\) goes in at most \(m + 1\) steps from the cleanup label with answer \(a\), internal state \(v\) and stacks \(S\) to the final label with answer \(a\), internal state false and every stack empty.
theorem clean_host (ans : Bool) (m : ℕ) (v : Bool) (S : ∀ k, List (HΓ k))
(hl : ∀ k, (S k).length ≤ m) (ho : S .out = []) :
RunLe (hprog cap) (m + 1) ⟨some (.clean ans), v, S⟩ ⟨some (.fin ans), false, fun _ => []⟩
@[reducible] def HΓ : HK → Type
| .inp => G
| .out => Bool
| _ => Sym
CSLibExt/Computability/Complexity/SatVerifierTM.lean:65
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 hprog (cap : Bool) : HLab → TM2.Stmt HΓ HLab Bool
| .ph .m1 => moveB (Γ := HΓ) HK.inp HK.X1 dX Sym.bit (.ph .m1) (.ph .m2)
| .ph .m2 => moveB (Γ := HΓ) HK.X1 HK.X Sym.bit? Sym.bit (.ph .m2) (.ph .sep)
| .ph .sep => .pop .inp (fun s _ => s) (.goto fun _ => .ph .m3)
| .ph .m3 => moveB (Γ := HΓ) HK.inp HK.W1 dW Sym.bit (.ph .m3) (.ph .m4)
| .ph .m4 => moveB (Γ := HΓ) HK.W1 HK.W Sym.bit? Sym.bit (.ph .m4) (.tok Tokenizer.start)
| .tok l => mapS embT φT (Tokenizer.prog l)
| .flt l => mapS embF φF (Karp.Filter3.prog cap l)
| .chk l => mapS embC φC (Check.prog lkH Lookup.start l)
| .clean ans => cleanS workKs (.clean ans) (.fin ans)
| .fin ans => .push .out (fun _ => ans) (.load (fun _ => false) .halt)
CSLibExt/Computability/Complexity/SatVerifierTM.lean:188
Uses 9 · Used by 1
TheoremName lengths in an occurrence table#✓fully proved
For every list \(n_0, \dots, n_{k-1}\) of natural numbers and every list \(w\) of bits, the names of the entries of the occurrence table of \(n_0, \dots, n_{k-1}\) and \(w\), in order, have the lengths of the binary codes of \(n_0, \dots, n_{k-1}\) (Mathlib's encoding of natural numbers as bit lists).
theorem entsOf_map_length (ns : List ℕ) :
∀ w : List Bool,
(entsOf ns w).map (fun e => e.1.length) = ns.map fun n => (encodeNat n).length
def entsOf : List ℕ → List Bool → List Ent
| [], _ => []
| n :: ns, [] => (encodeNat n, none) :: entsOf ns []
| n :: ns, b :: bs => (encodeNat n, some b) :: entsOf ns bs
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:74
Uses 2 · Used by 1
TM2 SAT verifierDefinitionInitial stacks of the SAT verifier host#✓fully proved
For a word \(l\) over the input alphabet \(G\), the initial host stacks on \(l\) hold \(l\) on the input stack and leave every other stack empty.
def initS (l : List G) : ∀ k, List (HΓ k) := update (fun _ => []) HK.inp l
abbrev G := Cslib.Complexity.DenseSAT.Verifier.G
CSLibExt/Computability/Complexity/SatVerifierTM.lean:53
@[reducible] def HΓ : HK → Type
| .inp => G
| .out => Bool
| _ => Sym
CSLibExt/Computability/Complexity/SatVerifierTM.lean:65
inductive HK | inp | out | X | W | T | B | S | A | C | V | P | F | CC | LC | X1 | W1 | U
deriving DecidableEq
CSLibExt/Computability/Complexity/SatVerifierTM.lean:56
Uses 3 · Used by 2
DefinitionTokenizer stacks after phase 0#✓fully proved
For bit lists \(x\) and \(w\), these tokenizer stack contents put the bits of \(x\) on the formula stack \(X\) and the bits of \(w\) on the witness stack \(W\) (each bit as a bit symbol), and leave every other tokenizer stack (token, table and the two counters) empty.
def tokS (x w : List Bool) : ∀ _ : Tokenizer.K, List Sym
| .X => x.map Sym.bit
| .W => w.map Sym.bit
| _ => []
inductive K | X | W | T | B | CC | LC
deriving DecidableEq
CSLibExt/Computability/Complexity/SatTokenizer.lean:38
inductive Sym
| bit (b : Bool) | lit (p : Bool) | cl | val (b : Bool) | dead
deriving DecidableEq
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:41
Uses 2 · Used by 1
TM2 SAT verifierDefinitionDriver stacks after tokenization#✓fully proved
For a CNF formula \(\varphi\) and a witness \(w\), these are the contents of the clause-check driver's stacks once the tokenizer has accepted \(\varphi\): the token stack holds the token list of \(\varphi\) reversed, the table stack holds the table-stack encoding of the occurrence table of \(\varphi\) and \(w\), and every other stack is empty.
def chkS (φ : CNF) (w : List Bool) : ∀ _ : Check.K, List Sym
| .T => (toks φ).reverse
| .B => tblStk (ents φ w)
| _ => []
abbrev CNF := List CNFClause
CSLibExt/Logics/Propositional/CNF/Basic.lean:33
inductive K | T | B | S | A | C | V | P | F
deriving DecidableEq
CSLibExt/Computability/Complexity/SatCheck.lean:38
inductive Sym
| bit (b : Bool) | lit (p : Bool) | cl | val (b : Bool) | dead
deriving DecidableEq
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:41
def toks (φ : CNF) : List Sym := φ.flatMap clauseToks
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:57
def tblStk (es : List Ent) : List Sym := (es.flatMap entToks).reverse
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:71
def ents (φ : CNF) (w : List Bool) : List Ent := entsOf (varsOf φ) w
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:80
Uses 6 · Used by 1
DefinitionStep budget before the cleanup#✓fully proved
For an input length \(N\), the number \((2N + 5) + (2N + 2) + (2N + 2) + (N(8N + 9) + 1)\).
It budgets the host steps before the cleanup: its four summands budget phase 0, the tokenizer, the clause-length filter and the clause-check driver.
def preSteps (N : ℕ) : ℕ := (2 * N + 5) + (2 * N + 2) + (2 * N + 2) + (N * (8 * N + 9) + 1)
Used by 2
TheoremCleanup phase of the SAT verifier host#✓fully proved
Fix either value of the 3SAT flag, an answer bit \(b\), a natural number \(m\), an internal state \(v\), and host stacks \(S\) such that every stack of \(S\) has length at most \(m\) and the output stack of \(S\) is empty. Then for some \(n \le m + 2\), the host program runs in exactly \(n\) steps from the configuration at the cleanup label with answer \(b\), internal state \(v\) and stacks \(S\) to the halted configuration with internal state false, the one-symbol word \(b\) on the output stack and every other stack empty.
theorem finish (ans : Bool) (m : ℕ) (v : Bool) (S : ∀ k, List (HΓ k))
(hl : ∀ k, (S k).length ≤ m) (ho : S .out = []) :
∃ n, n ≤ m + 2 ∧ Run (hprog cap) n ⟨some (.clean ans), v, S⟩
⟨none, false, update (fun _ => []) HK.out [ans]⟩
@[reducible] def HΓ : HK → Type
| .inp => G
| .out => Bool
| _ => Sym
CSLibExt/Computability/Complexity/SatVerifierTM.lean:65
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 hprog (cap : Bool) : HLab → TM2.Stmt HΓ HLab Bool
| .ph .m1 => moveB (Γ := HΓ) HK.inp HK.X1 dX Sym.bit (.ph .m1) (.ph .m2)
| .ph .m2 => moveB (Γ := HΓ) HK.X1 HK.X Sym.bit? Sym.bit (.ph .m2) (.ph .sep)
| .ph .sep => .pop .inp (fun s _ => s) (.goto fun _ => .ph .m3)
| .ph .m3 => moveB (Γ := HΓ) HK.inp HK.W1 dW Sym.bit (.ph .m3) (.ph .m4)
| .ph .m4 => moveB (Γ := HΓ) HK.W1 HK.W Sym.bit? Sym.bit (.ph .m4) (.tok Tokenizer.start)
| .tok l => mapS embT φT (Tokenizer.prog l)
| .flt l => mapS embF φF (Karp.Filter3.prog cap l)
| .chk l => mapS embC φC (Check.prog lkH Lookup.start l)
| .clean ans => cleanS workKs (.clean ans) (.fin ans)
| .fin ans => .push .out (fun _ => ans) (.load (fun _ => false) .halt)
CSLibExt/Computability/Complexity/SatVerifierTM.lean:188
inductive HK | inp | out | X | W | T | B | S | A | C | V | P | F | CC | LC | X1 | W1 | U
deriving DecidableEq
CSLibExt/Computability/Complexity/SatVerifierTM.lean:56
Uses 8 · Used by 1
TM2 SAT verifierDefinitionAnswer of the SAT host#✓fully proved
For a flag \(c\) and a pair \((x, w)\) of bit strings, the host's answer is false if \(x\) does not decode to a CNF formula. If \(x\) decodes to a formula \(\varphi\), give each variable \(n\) the value \(w_i\) (counting from \(0\)), where \(i\) is the first position of \(n\) in the list of variable occurrences of \(\varphi\) read clause by clause, and the value false if \(i \ge |w|\). Then the answer is true exactly when both (a) \(c\) is false or every clause of \(\varphi\) has at most three literals, and (b) every clause of \(\varphi\) contains a literal \((n, b)\) whose variable \(n\) has value \(b\).
def ans (p : List Bool × List Bool) : Bool :=
((decodeCNF p.1).map fun φ => (!cap || Karp.is3 φ) && checkSpec φ (ents φ p.2)).getD false
def decodeCNF (input : List Bool) : Option CNF := do
let (φ, rest) ← decodeCNFAux input
if rest.isEmpty then some φ else none
CSLibExt/Computability/CookLevin.lean:108
def is3 (φ : CNF) : Bool := φ.all fun C => decide (C.length ≤ 3)
CSLibExt/Computability/Complexity/Karp/ThreeSat.lean:46
def checkSpec (φ : CNF) (es : List Ent) : Bool :=
φ.all fun C => C.any fun l => liveVal es (encodeNat l.1) == l.2
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:87
def ents (φ : CNF) (w : List Bool) : List Ent := entsOf (varsOf φ) w
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:80
Uses 5 · Used by 5
DefinitionExplicit step bound of the SAT verifier machine#✓fully proved
For a flag \(\mathit{cap}\) and an input length \(N\), let \(s(N) = (2N + 5) + (2N + 2) + (2N + 2) + (N(8N + 9) + 1)\) be the number of steps allowed before the cleanup, and let \(p\) be the per-step push budget of the host machine with that flag. The total step bound is \(s(N) + (N + p \cdot s(N)) + 2\).
When the cleanup starts, every stack has length at most \(N + p \cdot s(N)\); the cleanup and the output step then take at most that many steps plus \(2\).
noncomputable def totalSteps (N : ℕ) : ℕ :=
preSteps N + (N + TM2Composition.pushBound (tm cap) * preSteps N) + 2
def preSteps (N : ℕ) : ℕ := (2 * N + 5) + (2 * N + 2) + (2 * N + 2) + (N * (8 * N + 9) + 1)
CSLibExt/Computability/Complexity/SatVerifierTM.lean:405
noncomputable def pushBound (M : FinTM2) : ℕ := ∑ l, pushes (M.m l)
MathlibExt/Computability/TuringMachine/Composition.lean:421
def tm (cap : Bool) : FinTM2 where
K := HK
k₀ := .inp
k₁ := .out
Γ := HΓ
Λ := HLab
main := .ph .m1
σ := Bool
initialState := false
m := hprog cap
CSLibExt/Computability/Complexity/SatVerifierTM.lean:203
Uses 3 · Used by 1
TheoremInitial configuration of the SAT verifier machine#✓fully proved
For every flag \(c\) and every word \(l\) over the input alphabet \(G\) of the host, the initial configuration of the SAT verifier machine with flag \(c\) on \(l\) (its start label, its initial internal state, \(l\) on the input stack and every other stack empty) is the configuration at the phase-0 label \(m_1\) with internal state false and the initial host stacks on \(l\).
theorem initList_tm (l : List G) : initList (tm cap) l = ⟨some (.ph .m1), false, initS l⟩
abbrev G := Cslib.Complexity.DenseSAT.Verifier.G
CSLibExt/Computability/Complexity/SatVerifierTM.lean:53
def tm (cap : Bool) : FinTM2 where
K := HK
k₀ := .inp
k₁ := .out
Γ := HΓ
Λ := HLab
main := .ph .m1
σ := Bool
initialState := false
m := hprog cap
CSLibExt/Computability/Complexity/SatVerifierTM.lean:203
def initS (l : List G) : ∀ k, List (HΓ k) := update (fun _ => []) HK.inp l
CSLibExt/Computability/Complexity/SatVerifierTM.lean:390
Uses 6 · Used by 1
DefinitionStep bound of the SAT verifier machine#✓fully proved
For a flag \(\mathit{cap}\), let \(p\) be the per-step push budget of the host machine with that flag (the sum over its labels of the number of push instructions in each label's statement). The step bound is the polynomial \((p + 1)(8X^2 + 15X + 10) + X + 2\) with natural-number coefficients, in the input length \(X\).
noncomputable def time : Polynomial ℕ :=
Polynomial.C (TM2Composition.pushBound (tm cap) + 1) *
(Polynomial.C 8 * Polynomial.X ^ 2 + Polynomial.C 15 * Polynomial.X + Polynomial.C 10) +
Polynomial.X + Polynomial.C 2
noncomputable def pushBound (M : FinTM2) : ℕ := ∑ l, pushes (M.m l)
MathlibExt/Computability/TuringMachine/Composition.lean:421
def tm (cap : Bool) : FinTM2 where
K := HK
k₀ := .inp
k₁ := .out
Γ := HΓ
Λ := HLab
main := .ph .m1
σ := Bool
initialState := false
m := hprog cap
CSLibExt/Computability/Complexity/SatVerifierTM.lean:203
Uses 2 · Used by 1
TM2 SAT verifier
DefinitionThe TM2 SAT verifier#✓fully proved
For a flag \(\mathit{cap}\), the host machine with that flag computes the host's answer in polynomial time. For every pair \((x, w)\) of bit lists, started on the input \(x \# w\) (the bits of \(x\), a separator, then the bits of \(w\)), it halts with the single bit \(\mathrm{ans}_{\mathit{cap}}(x, w)\) on its output stack and every other stack empty within \(T(n)\) steps, where \(n\) is the length of \(x \# w\) and \(T\) is the host's polynomial step bound. Here \(\mathrm{ans}_{\mathit{cap}}(x, w)\) is false unless \(x\) decodes to a CNF formula \(\varphi\); in that case it is true exactly when \(\varphi\) passes the clause check against the table built from \(w\) and, if \(\mathit{cap}\) is true, every clause of \(\varphi\) has at most three literals.
Cslib.Complexity.SatVerifier.Machine.verifier · 23 lines
noncomputable def verifier :
TM2ComputableInPolyTime Cslib.Complexity.DenseSAT.Verifier.pairEncode (fun b : Bool => [b])
(fun p => ans cap p) where
tm := tm cap
inputAlphabet := Equiv.refl G
outputAlphabet := Equiv.refl Bool
time := time cap
outputsFun := fun p => by
obtain ⟨x, w⟩ := p
have h := host_run cap x w
have hn := (Classical.choose_spec h).1
have r := (Classical.choose_spec h).2
unfold TM2OutputsInTime
refine { steps := Classical.choose h, evals_in_steps := ?_, steps_le_m := ?_ }
· change (flip bind (TM2.step (hprog cap)))^[_] (some (initList (tm cap) _)) =
Option.map (haltList (tm cap)) (some _)
erw [List.map_id, List.map_id, initList_tm, Option.map_some, haltList_tm]
exact r
· refine hn.trans (le_of_eq ?_)
simp only [totalSteps, time, preSteps_eq, Polynomial.eval_add, Polynomial.eval_mul,
Polynomial.eval_C,
Polynomial.eval_pow, Polynomial.eval_X]
ring
def pairEncode (p : List Bool × List Bool) : List G :=
p.1.map Sum.inl ++ Sum.inr none :: p.2.map fun b => Sum.inr (some b)
CSLibExt/Computability/Complexity/DenseSATVerifier.lean:71
def ans (p : List Bool × List Bool) : Bool :=
((decodeCNF p.1).map fun φ => (!cap || Karp.is3 φ) && checkSpec φ (ents φ p.2)).getD false
CSLibExt/Computability/Complexity/SatVerifierTM.lean:424
def tm (cap : Bool) : FinTM2 where
K := HK
k₀ := .inp
k₁ := .out
Γ := HΓ
Λ := HLab
main := .ph .m1
σ := Bool
initialState := false
m := hprog cap
CSLibExt/Computability/Complexity/SatVerifierTM.lean:203
abbrev G := Cslib.Complexity.DenseSAT.Verifier.G
CSLibExt/Computability/Complexity/SatVerifierTM.lean:53
noncomputable def time : Polynomial ℕ :=
Polynomial.C (TM2Composition.pushBound (tm cap) + 1) *
(Polynomial.C 8 * Polynomial.X ^ 2 + Polynomial.C 15 * Polynomial.X + Polynomial.C 10) +
Polynomial.X + Polynomial.C 2
CSLibExt/Computability/Complexity/SatVerifierTM.lean:596
Uses 79 · Used by 1
TheoremThe SAT host's answer is polynomial-time#✓fully proved
For each value of the flag \(\mathit{cap}\) (with or without the three-literal clause filter), the host's answer, as a function from pairs \((x, w)\) of bit strings to Booleans, is polynomial-time computable under the canonical bitstring encodings.
theorem isPolyTime_ans : ComplexityTheory.IsPolyTime fun p => ans cap p
def IsPolyTime {α β : Type} [BitstringEncoding α] [BitstringEncoding β]
(f : α → β) : Prop :=
IsPolyTimeWithEncoding (BitstringEncoding.toEncoding (α := α))
(BitstringEncoding.toEncoding (α := β)) f
MathlibExt/Computability/Complexity.lean:186
def ans (p : List Bool × List Bool) : Bool :=
((decodeCNF p.1).map fun φ => (!cap || Karp.is3 φ) && checkSpec φ (ents φ p.2)).getD false
CSLibExt/Computability/Complexity/SatVerifierTM.lean:424
Uses 15 · Used by 2
TheoremThe SAT verifier is polynomial-time#✓fully proved
The function that maps a pair \((x, w)\) of bit strings to the Boolean answer of the SAT verifier on \((x, w)\) (its return value, ignoring its declared time cost) is polynomial-time computable under the canonical bitstring encodings.
theorem isPolyTime_satVerifier :
ComplexityTheory.IsPolyTime fun xw => (satVerifier xw).ret
def IsPolyTime {α β : Type} [BitstringEncoding α] [BitstringEncoding β]
(f : α → β) : Prop :=
IsPolyTimeWithEncoding (BitstringEncoding.toEncoding (α := α))
(BitstringEncoding.toEncoding (α := β)) f
MathlibExt/Computability/Complexity.lean:186
def satVerifier : List Bool × List Bool → TimeM Nat Bool := fun xw =>
match decodeCNF xw.1 with
| none => pure false
| some φ => checkCNF (varsOf φ) xw.2 φ
CSLibExt/Computability/SatTimeM.lean:103
Uses 18 · Used by 3
TheoremSAT is in NP#✓fully proved
The decision problem SAT, which accepts exactly the bit strings that encode a satisfiable CNF formula, belongs to the class NP.
Variable indices are binary-coded in the encoding of formulas.
theorem satDec_mem_NP : satDec ∈ ComplexityTheory.NP
noncomputable def satDec : MetaMathlibExt.ComplexityTheory.DecisionProblem :=
fun x => if x ∈ SATLang then true else false
CSLibExt/Computability/CookLevin.lean:391
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
Uses 6
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.