Cook-Levin: the counter-machine view shared by the clause generators

InductiveStages of the multiplication routine#✓fully proved

The stages of the counter-machine multiplication routine form the four-element type with elements head, body, l2 and rest.

inductive MS | head | body | l2 | rest
  deriving DecidableEq
Used by 65
Used byThe accept generator as a finite multi-stack machine · Run of the accept generator's precomputation · Generator machine for the accept family · Precomputation stages of the accept generator · Loop-body stages of the cell-shift generator · Loop body of the cell-shift generator · Labels of the cell-shift generator · Correctness of the shift generator on one block · Correctness of the shift generator on the situation chain · One iteration of the overflow loop of the cell-shift generator · The cell-shift generator · Precomputation stages of the shift generator · One iteration of the in-range loop of the cell-shift generator · Correctness of the shift generator, with its explicit time bound · The cell-shift generator as a finite stack machine · Setup and loop stages of a cell-shift block · Block stages of the cell-shift generator · One iteration of the time loop of the shift generator · One phase-loop iteration of the initial-row generator · Labels of the initial-row generator · The I3 loop · Counter part of one I3 iteration · Correctness of the init generator, with its explicit time bound · The init generator as a finite multi-stack machine · The initial-row generator · Run of the precomputation (initial-row generator) · The counter part of the initial-row generator · Labels of the first precomputation part · Labels of the second precomputation part · Correctness of the clause-family generator, with its explicit time bound · The clause-family generator as a finite stack machine · Labels of the clause-family generator · Literal routine of the transition-clause generator · Run of one literal routine (transition-clause generator) · Stages of the transition-clause generator's literal routine · Generator machine for the transition clause families · Stages of the transition-clause generator's precomputation · One iteration of the time loop · The reduction machine halts with the emitted formula · The reduction machine · Generator run for one cell · Control labels of the one-hot generator · One stack iteration of the one-hot generator · Correctness of the one-hot generator, with its explicit time bound · The one-hot generator as a finite multi-stack machine · The one-hot generator · Stages of the one-hot precomputation · Generator run over one time step · The multiplication routine of a counter machine · The host as a finite multi-stack Turing machine · The host program · Sequencing · The counter program · The counter program's run · The full program · The full machine as a finite multi-stack Turing machine · One Horner round · The statements of one Horner round · Horner rounds · Stages of a Horner round · Labels of the counter program · The power loop · Power-loop program · The precomputation · Stages of the power loop

InductiveStacks of a counter machine#✓fully proved

For a type \(C\), the stacks of a counter machine with counters indexed by \(C\) are an output stack \(\mathrm{out}\) and one counter stack \(c_x\) for each \(x \in C\).

inductive SK (C : Type)
  | out
  | c (x : C)
  deriving DecidableEq, Fintype
Used by 114
Used byTime bound of the accept generator for a concrete machine · Correctness of the accept generator, with its explicit time bound · Polynomial time bound of the accept generator · The accept generator as a finite multi-stack machine · Run of the accept cell chain · One clause of the accept generator · Run of the code-clause chain of the accept generator · Literal routine of the accept generator · Run of the literal routine of the accept generator · Run of the accept generator's precomputation · Generator machine for the accept family · Loop body of the cell-shift generator · One clause of the cell-shift generator · Correctness of the shift generator on one block · Correctness of the shift generator on the situation chain · Correctness of the shift generator on the stack chain of a situation · Literal routine of the cell-shift generator · One literal routine of the cell-shift generator · The literal routines of one clause of the cell-shift generator · One iteration of the overflow loop of the cell-shift generator · The pushed-fill chain of the cell-shift generator · The cell-shift generator · The decrement chain takes \(n\) steps · One iteration of the in-range loop of the cell-shift generator · Correctness of the shift generator, with its explicit time bound · Polynomial time bound for the shift generator · The cell-shift generator as a finite stack machine · Block stages of the cell-shift generator · One iteration of the time loop of the shift generator · The in-range chain of the cell-shift generator · One phase-loop iteration of the initial-row generator · Run of one clause (initial-row generator) · Stacks of a counter machine with an extra input stack · Alphabets of a counter machine with an input stack · The I3 loop on the whole input · The I3 loop · Counter part of one I3 iteration · Stacks of a counter machine with an input stack · The init generator at the stack cap · Time and output of the init generator for an encoding · Correctness of the init generator, with its explicit time bound · Polynomial time bound for the init generator · The init generator as a finite multi-stack machine · The initial-row generator · The counter stacks inside the generator's stacks · The literal routine of the initial-row generator · Run of one literal routine (initial-row generator) · Run of the literal routines of a clause (initial-row generator) · One phase loop · Run of the precomputation (initial-row generator) · The counter part of the initial-row generator · The read chain · Run lifting · Run of the transition-family generator on one clause · Stack alphabets of the generator · Correctness of the clause-family generator · Correctness of the clause-family generator, with its explicit time bound · Polynomial time bound for the clause-family generator · The clause-family generator as a finite stack machine · Stacks of the clause-family generator · Literal routine of the transition-clause generator · Run of one literal routine (transition-clause generator) · Run of the literal routines of a clause (transition-clause generator) · Generator machine for the transition clause families · One iteration of the time loop · Time bound of the situation-definition generator on the tables of a machine · Time bound of the shift generator on the tables of a machine · Time bound of the transition-clause generator on the tables of a machine · Generator run for one cell · One clause of the one-hot generator · One stack iteration of the one-hot generator · One-hot generator: the routine for one literal · Run of one literal routine (one-hot generator) · Run of the literal routines of a clause (one-hot generator) · Correctness of the one-hot generator, with its explicit time bound · Polynomial time bound for the one-hot generator · The one-hot generator as a finite multi-stack machine · The one-hot generator · Generator run over one row of at-most-one clauses · Generator run over the first rows and the at-least-one clause · Generator run over one time step · Budgeted runs transport along equal counter values · Gap emission in the counter view · The multiplication routine of a counter machine · Alphabets of a counter machine · Stacks holding given counter values · A runtime for loop in the counter view · Host stack renaming for the accept generator · Host stack renaming for the shift generator · Host stack renaming for the init generator · Host stack renaming for the situation-definition generator · Host stack renaming for the update generator · Embedding of the accept generator into the host · Embedding of the shift generator into the host · Embedding of the init generator into the host · Embedding of the situation-definition generator into the host · Embedding of the update generator's stacks into the host · The host as a finite multi-stack Turing machine · The host program · The assembled generator, after the precomputation · Sequencing · The counter program · The counter program's run · Stack renaming of the counter program · Embedding of the counter program's stacks · The full program · One Horner round · The statements of one Horner round · Horner rounds · The power loop · Power-loop program · The precomputation · Unit targets of a multi-target transfer · Multi-target transfer

AbbreviationAlphabets of a counter machine#✓fully proved

For a type \(C\), the output stack \(\mathrm{out}\) of a counter machine with counters indexed by \(C\) has the Booleans as its alphabet, and each counter stack \(c_x\) has a one-element alphabet.

abbrev SΓ (C : Type) : SK C → Type
  | .out => Bool
  | .c _ => Unit
Uses 1 · Used by 90
Used byTime bound of the accept generator for a concrete machine · Correctness of the accept generator, with its explicit time bound · Polynomial time bound of the accept generator · The accept generator as a finite multi-stack machine · Run of the accept cell chain · One clause of the accept generator · Run of the code-clause chain of the accept generator · Literal routine of the accept generator · Run of the literal routine of the accept generator · Run of the accept generator's precomputation · Generator machine for the accept family · Loop body of the cell-shift generator · One clause of the cell-shift generator · Correctness of the shift generator on one block · Correctness of the shift generator on the situation chain · Correctness of the shift generator on the stack chain of a situation · Literal routine of the cell-shift generator · One literal routine of the cell-shift generator · The literal routines of one clause of the cell-shift generator · One iteration of the overflow loop of the cell-shift generator · The pushed-fill chain of the cell-shift generator · The cell-shift generator · The decrement chain takes \(n\) steps · One iteration of the in-range loop of the cell-shift generator · Correctness of the shift generator, with its explicit time bound · Polynomial time bound for the shift generator · The cell-shift generator as a finite stack machine · Block stages of the cell-shift generator · One iteration of the time loop of the shift generator · The in-range chain of the cell-shift generator · One phase-loop iteration of the initial-row generator · Run of one clause (initial-row generator) · Stacks of a counter machine with an extra input stack · Alphabets of a counter machine with an input stack · The I3 loop · Counter part of one I3 iteration · Correctness of the init generator, with its explicit time bound · The initial-row generator · The counter stacks inside the generator's stacks · The literal routine of the initial-row generator · Run of one literal routine (initial-row generator) · Run of the literal routines of a clause (initial-row generator) · One phase loop · Run of the precomputation (initial-row generator) · The counter part of the initial-row generator · The read chain · Run lifting · Run of the transition-family generator on one clause · Stack alphabets of the generator · Correctness of the clause-family generator, with its explicit time bound · Run of one literal routine (transition-clause generator) · Run of the literal routines of a clause (transition-clause generator) · One iteration of the time loop · Time bound of the shift generator on the tables of a machine · Generator run for one cell · One clause of the one-hot generator · One stack iteration of the one-hot generator · One-hot generator: the routine for one literal · Run of one literal routine (one-hot generator) · Run of the literal routines of a clause (one-hot generator) · Correctness of the one-hot generator, with its explicit time bound · Polynomial time bound for the one-hot generator · The one-hot generator as a finite multi-stack machine · The one-hot generator · Generator run over one row of at-most-one clauses · Generator run over the first rows and the at-least-one clause · Generator run over one time step · Budgeted runs transport along equal counter values · Gap emission in the counter view · The multiplication routine of a counter machine · Stacks holding given counter values · A runtime for loop in the counter view · Embedding of the accept generator into the host · Embedding of the shift generator into the host · The host as a finite multi-stack Turing machine · The host program · The assembled generator, after the precomputation · Sequencing · The counter program · The counter program's run · Embedding of the counter program's stacks · The full program · One Horner round · The statements of one Horner round · Horner rounds · The power loop · Power-loop program · The precomputation · Unit targets of a multi-target transfer · Multi-target transfer

DefinitionStacks holding given counter values#✓fully proved

For a type \(C\), counter values \(f : C \to \mathbb{N}\) and a list \(o\) of Booleans, \(\mathrm{st}(f, o)\) is the stack contents of a counter machine whose output stack \(\mathrm{out}\) holds \(o\) and whose counter stack \(c_x\) holds exactly \(f(x)\) copies of the unit symbol, for each \(x \in C\).

def st (f : C → ℕ) (o : List Bool) : ∀ k, List (SΓ C k)
  | .out => o
  | .c x => cnt () (f x)
Uses 3 · Used by 65
Used byTime bound of the accept generator for a concrete machine · Correctness of the accept generator, with its explicit time bound · Polynomial time bound of the accept generator · Run of the accept cell chain · One clause of the accept generator · Run of the code-clause chain of the accept generator · Run of the literal routine of the accept generator · Run of the accept generator's precomputation · One clause of the cell-shift generator · Correctness of the shift generator on one block · Correctness of the shift generator on the situation chain · Correctness of the shift generator on the stack chain of a situation · One literal routine of the cell-shift generator · The literal routines of one clause of the cell-shift generator · One iteration of the overflow loop of the cell-shift generator · The pushed-fill chain of the cell-shift generator · The decrement chain takes \(n\) steps · One iteration of the in-range loop of the cell-shift generator · Correctness of the shift generator, with its explicit time bound · Polynomial time bound for the shift generator · One iteration of the time loop of the shift generator · The in-range chain of the cell-shift generator · One phase-loop iteration of the initial-row generator · Run of one clause (initial-row generator) · The I3 loop on the whole input · The I3 loop · Counter part of one I3 iteration · The init generator at the stack cap · Time and output of the init generator for an encoding · Correctness of the init generator, with its explicit time bound · Polynomial time bound for the init generator · Run of one literal routine (initial-row generator) · Run of the literal routines of a clause (initial-row generator) · One phase loop · Run of the precomputation (initial-row generator) · Run of the transition-family generator on one clause · Correctness of the clause-family generator · Correctness of the clause-family generator, with its explicit time bound · Polynomial time bound for the clause-family generator · Run of one literal routine (transition-clause generator) · Run of the literal routines of a clause (transition-clause generator) · One iteration of the time loop · Time bound of the situation-definition generator on the tables of a machine · Time bound of the shift generator on the tables of a machine · Time bound of the transition-clause generator on the tables of a machine · Generator run for one cell · One clause of the one-hot generator · One stack iteration of the one-hot generator · Run of one literal routine (one-hot generator) · Run of the literal routines of a clause (one-hot generator) · Correctness of the one-hot generator, with its explicit time bound · Polynomial time bound for the one-hot generator · Generator run over one row of at-most-one clauses · Generator run over the first rows and the at-least-one clause · Generator run over one time step · Budgeted runs transport along equal counter values · Gap emission in the counter view · A runtime for loop in the counter view · Sequencing · The counter program's run · One Horner round · Horner rounds · The power loop · The precomputation · Multi-target transfer

DefinitionThe multiplication routine of a counter machine#✓fully proved

Let \(a, a_d, b, c, t\) be counters, let \(\mathrm{mk}\) assign a label to each stage of the multiplication routine, and let \(\mathrm{next}\) be a label. The routine assigns to each stage the following counter-machine instruction. At head: pop a unit from \(a\), then push a unit onto \(a_d\) and go to \(\mathrm{mk}(\mathrm{body})\), or go to \(\mathrm{mk}(\mathrm{rest})\) if \(a\) was empty. At body: pop a unit from \(b\), then push a unit onto each of \(c\) and \(t\) and go to \(\mathrm{mk}(\mathrm{body})\), or go to \(\mathrm{mk}(\mathrm{l2})\) if \(b\) was empty. At l2: pop a unit from \(t\), then push a unit onto \(b\) and go to \(\mathrm{mk}(\mathrm{l2})\), or go to \(\mathrm{mk}(\mathrm{head})\) if \(t\) was empty. At rest: pop a unit from \(a_d\), then push a unit onto \(a\) and go to \(\mathrm{mk}(\mathrm{rest})\), or go to \(\mathrm{next}\) if \(a_d\) was empty. In each instruction the pop sets the flag to true if a unit was popped and to false if the counter was empty, and the pushes leave the flag unchanged.

Started at head with \(a, a_d, b, c, t\) distinct and \(a_d\) and \(t\) empty, the routine ends at \(\mathrm{next}\) having added \(a \cdot b\) to \(c\), with every other counter unchanged; \(a_d\) serves as the loop index and \(t\) as scratch.

def mulS (a ad b c t : C) (mk : MS → Λ) (next : Λ) : MS → TM2.Stmt (SΓ C) Λ Bool
  | .head => forHead (.c a) (.c ad) () (mk .body) (mk .rest)
  | .body => xfer (.c b) [⟨.c c, ()⟩, ⟨.c t, ()⟩] (mk .body) (mk .l2)
  | .l2 => xfer (.c t) [⟨.c b, ()⟩] (mk .l2) (mk .head)
  | .rest => xfer (.c ad) [⟨.c a, ()⟩] (mk .rest) next
Uses 6 · Used by 27

TheoremGap emission in the counter view#✓fully proved

Let \(M\) be a counter machine, let \(P, Q, T_1, T_2\) be pairwise distinct counters, let \(y\) be a list of Booleans, let \(\mathrm{dec}\), \(\mathrm{cmp}\), \(\mathrm{emit}\), \(z\), \(\mathrm{next}\) be labels, and let \(r\), \(r'\), \(\mathrm{out}\) assign a label to each comparison outcome \(\omega\), which is one of \(\mathrm{lt}\), \(\mathrm{eq}\), \(\mathrm{gt}\). In the instructions below, every pop sets the flag to true if a unit was popped and to false if the stack was empty, and pushing or prepending leaves the flag unchanged. Suppose that at \(\mathrm{dec}\), \(M\) pops a unit from \(P\) and goes to \(\mathrm{cmp}\), or to \(z\) if \(P\) was empty; at \(\mathrm{cmp}\), \(M\) pops a unit from each of \(P\) and \(Q\), pushes a unit onto \(T_1\) if \(P\) was nonempty and onto \(T_2\) if \(Q\) was nonempty, and goes back to \(\mathrm{cmp}\) if both were nonempty, and otherwise to \(r(\mathrm{lt})\), \(r(\mathrm{eq})\) or \(r(\mathrm{gt})\) according as only \(Q\), neither, or only \(P\) was nonempty; for each \(\omega\), at \(r(\omega)\), \(M\) pops a unit from \(T_1\), then pushes a unit onto \(P\) and stays at \(r(\omega)\), or goes to \(r'(\omega)\) if \(T_1\) was empty; at \(r'(\omega)\), \(M\) pops a unit from \(T_2\), then pushes a unit onto \(Q\) and stays at \(r'(\omega)\), or goes to \(\mathrm{out}(\omega)\) if \(T_2\) was empty; \(\mathrm{out}(\mathrm{eq}) = \mathrm{next}\) and \(\mathrm{out}(\mathrm{lt}) = \mathrm{out}(\mathrm{gt}) = \mathrm{emit}\); and at \(\mathrm{emit}\), \(M\) prepends \(y\) to the output stack and goes to \(\mathrm{dec}\). Let \(q, g \in \mathbb{N}\) and let \(F\) be counter values with \(F(P) = q + g + 1\), \(F(Q) = q\) and \(F(T_1) = F(T_2) = 0\). Then for every flag \(v\) and every list \(o\) of Booleans, \(M\) goes in exactly \(g(3q + 6) + 3q + 4\) steps from label \(\mathrm{dec}\), flag \(v\) and stacks \(\mathrm{st}(F, o)\) to label \(\mathrm{next}\), flag false and stacks \(\mathrm{st}(F', y^g o)\), where \(F'\) agrees with \(F\) except that \(F'(P) = q\), and \(y^g o\) is \(g\) copies of \(y\) followed by \(o\).

theorem gapS {P Q T1 T2 : C} {ys : List Bool} {dec cmpL emitL ifZero next : Λ}
    {r rB out : Ordering → Λ}
    (hdec : M dec = decr (.c P) ifZero cmpL)
    (hcmp : M cmpL = cmpStep (.c P) (.c Q) (.c T1) (.c T2) () () cmpL (r .lt) (r .eq) (r .gt))
    (hr : ∀ o, M (r o) = xfer (.c T1) [⟨.c P, ()⟩] (r o) (rB o))
    (hrB : ∀ o, M (rB o) = xfer (.c T2) [⟨.c Q, ()⟩] (rB o) (out o))
    (hout : ∀ o, out o = if o = .eq then next else emitL)
    (hemit : M emitL = emitR .out ys dec)
    (hnd : ([.c P, .c Q, .c T1, .c T2, .out] : List (SK C)).Nodup) (q gap : ℕ) (F : C → ℕ)
    (hP : F P = q + gap + 1) (hQ : F Q = q) (h1 : F T1 = 0) (h2 : F T2 = 0) (v : Bool)
    (o : List Bool) :
    Run M (gap * (3 * q + 6) + 3 * q + 4) ⟨some dec, v, st F o⟩
      ⟨some next, false, st (update F P q) (rep ys gap ++ o)⟩
Uses 12 · Used by 4

TheoremBudgeted runs transport along equal counter values#✓fully proved

Let \(M\) be a counter machine, let \(K, X \in \mathbb{N}\), let \(F\) and \(F'\) be counter values with \(F = F'\), let \(l\) be a label or the halting state, \(v\) a flag, \(o\) a list of Booleans and \(d\) a configuration. If there is \(n\) with \(K + n \le X\) such that \(M\) goes in exactly \(n\) steps from the configuration with label \(l\), flag \(v\) and stacks \(\mathrm{st}(F', o)\) to \(d\), then the same holds from the configuration with label \(l\), flag \(v\) and stacks \(\mathrm{st}(F, o)\).

theorem bud_st {K X : ℕ} {F F' : C → ℕ} {l : Option Λ} {v : Bool} {o : List Bool}
    {d : TM2.Cfg (SΓ C) Λ Bool} (h : F = F') (h' : Bud M K X ⟨l, v, st F' o⟩ d) :
    Bud M K X ⟨l, v, st F o⟩ d
Uses 4 · Used by 13

TheoremA runtime for loop in the counter view#✓fully proved

Let \(M\) be a counter machine, let \(c \ne c_d\) be counters, and let \(\mathrm{head}\), \(\mathrm{body}\), \(\mathrm{rest}\), \(\mathrm{next}\) be labels such that at \(\mathrm{head}\), \(M\) pops a unit from \(c\), then pushes a unit onto \(c_d\) and goes to \(\mathrm{body}\), or goes to \(\mathrm{rest}\) if \(c\) was empty; and at \(\mathrm{rest}\), \(M\) pops a unit from \(c_d\), then pushes a unit onto \(c\) and stays at \(\mathrm{rest}\), or goes to \(\mathrm{next}\) if \(c_d\) was empty. Each of these pops sets the flag to true if a unit was popped and to false if the stack was empty, and the pushes leave the flag unchanged. Let \(n, B \in \mathbb{N}\), let \(\mathrm{blk}\) assign a list of Booleans to each natural number, and let \(f\) be counter values with \(f(c) = n\) and \(f(c_d) = 0\); for \(t < n\) write \(g_t\) for the counter values that agree with \(f\) except that \(g_t(c) = t\) and \(g_t(c_d) = n - t\), and write juxtaposition of lists for concatenation. Suppose that for every \(t < n\) and every list \(o\) of Booleans, \(M\) goes in at most \(B\) steps from label \(\mathrm{body}\), flag true and stacks \(\mathrm{st}(g_t, o)\) to label \(\mathrm{head}\), some flag and stacks \(\mathrm{st}(g_t, \mathrm{blk}(t)\, o)\). Then for every flag \(v\) and every list \(o\) of Booleans, \(M\) goes in at most \(n(B + 1) + n + 2\) steps from label \(\mathrm{head}\), flag \(v\) and stacks \(\mathrm{st}(f, o)\) to label \(\mathrm{next}\), flag false and stacks \(\mathrm{st}(f, \mathrm{blk}(0)\, \mathrm{blk}(1) \cdots \mathrm{blk}(n-1)\, o)\).

The body runs with \(c\) holding \(t = n - 1, \dots, 0\) in that order, so the blocks end up in ascending order.

theorem stLoop {c cd : C} {head body rest next : Λ}
    (hHead : M head = forHead (.c c) (.c cd) () body rest)
    (hRest : M rest = xfer (.c cd) [⟨.c c, ()⟩] rest next) (hc : c ≠ cd) (n B : ℕ)
    (blk : ℕ → List Bool) (f : C → ℕ) (hfc : f c = n) (hfcd : f cd = 0)
    (hbody : ∀ t < n, ∀ o, ∃ v', RunLe M B
      ⟨some body, true, st (update (update f c t) cd (n - t)) o⟩
      ⟨some head, v', st (update (update f c t) cd (n - t)) (blk t ++ o)⟩)
    (v : Bool) (o : List Bool) :
    RunLe M (n * (B + 1) + n + 2) ⟨some head, v, st f o⟩
      ⟨some next, false, st f ((List.range n).flatMap blk ++ o)⟩
Uses 9 · Used by 6
8 fully proved

The dependency explorer needs JavaScript and its graph data.

Download the complete graph data.