4 Polynomial time, reductions, and NP
This chapter covers deterministic and nondeterministic time classes, the polynomial-time function class \(\mathsf{FP}\), polynomial-time many-one (Karp) reductions, and the theory of \(\mathsf{NP}\)-completeness built on satisfiability. All class definitions are formalized, together with the closure of \(\mathsf{P}\) under Boolean operations and polynomial-time preimages, the closure of \(\mathsf{FP}\) under composition, the transfer of \(\mathsf{P}\) to and from CSLib’s multi-tape machines, Cobham’s machine-independent characterization of \(\mathsf{FP}\) in both directions, the direction “polynomial-time verifier implies \(\mathsf{NP}\)” of the witness characterization, and the Cook–Levin theorem with its corollaries for \(3\mathrm{SAT}\) and for the complement of \(\mathrm{SAT}\). The main open directions are the converse witness direction (every \(\mathsf{NP}\) language has a polynomial-time verifier), the equation \(\mathsf{NP} = \Sigma ^p_1\) (neither inclusion is stated yet), \(\mathsf{NP} \subseteq \mathsf{PSPACE}\), a catalog of further \(\mathsf{NP}\)-complete problems with explicit codecs, and \(\mathsf{FP}\) combinators that would let the existing bespoke machines be re-proved as short programs through Cobham’s theorem.
4.1 Time classes
For \(T \colon \mathbb {N} \to \mathbb {N}\), \(\mathsf{DTIME}(T)\) is the set of languages \(L\) for which there are a deterministic machine with some number \(k\) of work tapes and a function \(f\) with \(f = O(T)\) such that the machine decides \(L\) within time \(f\): on every input \(x\) it halts within \(f(|x|)\) steps with \(1\) in output cell \(1\) (the first cell after \(\triangleright \)) if \(x \in L\) and \(0\) there otherwise. Here \(f = O(T)\) means that \(f(n) \le C \cdot T(n)\) for some real constant \(C\) and all sufficiently large \(n\).
\(\mathsf{NTIME}(T)\) is the set of languages \(L\) for which some nondeterministic machine (two transition functions selected by a choice bit) and some \(f = O(T)\) satisfy: every computation path on input \(x\) halts within \(f(|x|)\) steps, and \(x \in L\) if and only if some choice sequence of length \(f(|x|)\) ends in the halting state with \(1\) in output cell \(1\). Rejecting paths are not required to write \(0\).
\(\mathsf{P} = \bigcup _{k} \mathsf{DTIME}(n^k)\).
\(\mathsf{coNP} = \{ L : \overline{L} \in \mathsf{NP}\} \), where \(\overline{L}\) is the complement of \(L\) in the set of all bit strings. The library forms every complement class with the same constructor (Complexity.complClass).
\(\mathsf{FP}\) is the set of functions \(f \colon \{ 0,1\} ^* \to \{ 0,1\} ^*\) for which some deterministic machine computes \(f\) within time \(T\) with \(T = O(n^d)\) for some \(d\): on every input \(x\) it halts within \(T(|x|)\) steps with \(f(x)\) written on the output tape, that is, output cells \(1, \ldots , |f(x)|\) hold the bits of \(f(x)\) and cell \(|f(x)| + 1\) is blank.
\(\mathsf{EXP} = \bigcup _{k} \mathsf{DTIME}(2^{n^k})\) and \(\mathsf{NEXP} = \bigcup _{k} \mathsf{NTIME}(2^{n^k})\).
For every \(T\), \(\mathsf{DTIME}(T) \subseteq \mathsf{NTIME}(T)\). Both classes are monotone under \(O(\cdot )\): if \(T_1 = O(T_2)\) then \(\mathsf{DTIME}(T_1) \subseteq \mathsf{DTIME}(T_2)\) and \(\mathsf{NTIME}(T_1) \subseteq \mathsf{NTIME}(T_2)\). Consequently \(\mathsf{P} \subseteq \mathsf{NP}\), \(\mathsf{P} \subseteq \mathsf{EXP}\), \(\mathsf{NP} \subseteq \mathsf{NEXP}\), and \(\mathsf{EXP} \subseteq \mathsf{NEXP}\).
A deterministic machine is a nondeterministic machine whose two transition functions coincide, and it decides the same language in the same time; this gives \(\mathsf{DTIME}(T) \subseteq \mathsf{NTIME}(T)\), hence \(\mathsf{P} \subseteq \mathsf{NP}\) and \(\mathsf{EXP} \subseteq \mathsf{NEXP}\) level by level. Monotonicity is transitivity of \(O(\cdot )\). The inclusions \(\mathsf{P} \subseteq \mathsf{EXP}\) and \(\mathsf{NP} \subseteq \mathsf{NEXP}\) follow from \(n^k \le 2^{n^k}\) and monotonicity.
\(\mathsf{P} \subseteq \mathsf{coNP}\), and hence \(\mathsf{P} \subseteq \mathsf{NP} \cap \mathsf{coNP}\). If \(\mathsf{P} = \mathsf{NP}\) then \(\mathsf{NP} = \mathsf{coNP}\); equivalently, \(\mathsf{NP} \neq \mathsf{coNP}\) implies \(\mathsf{P} \neq \mathsf{NP}\).
\(\mathsf{P}\) is closed under complement, so \(\mathsf{P} \subseteq \mathsf{coNP}\). Under \(\mathsf{P} = \mathsf{NP}\) the class \(\mathsf{NP}\) inherits closure under complement, and a class closed under complement equals its complement class.
\(\mathsf{NP} \subseteq \mathsf{PSPACE}\), and hence \(\mathsf{NP} \subseteq \mathsf{EXP}\).
Two routes are available, and neither is formalized yet. Directly: prove \(\mathsf{NTIME}(T) \subseteq \mathsf{NSPACE}(T)\) (not yet stated) exactly as \(\mathsf{DTIME}(T) \subseteq \mathsf{DSPACE}(T)\) is proved (a head moves at most one cell per step), then apply \(\mathsf{NPSPACE} \subseteq \mathsf{PSPACE}\) (Complexity.NPSPACE_subset_PSPACE, formalized in the space chapter). Alternatively, \(\mathsf{NP} \subseteq \Sigma ^p_1 \subseteq \mathsf{PH} \subseteq \mathsf{PSPACE}\), where only the first inclusion is missing: \(\Sigma ^p_1 \subseteq \mathsf{PH}\) is Complexity.SigmaP_subset_PH and \(\mathsf{PH} \subseteq \mathsf{PSPACE}\) is Theorem 208. In both cases \(\mathsf{PSPACE} \subseteq \mathsf{EXP}\) (Complexity.PSPACE_subset_EXP) gives the second claim.
Every regular binary language, in the sense shared by Mathlib and CSLib, is in \(\mathsf{DTIME}(n + 2)\) and hence in \(\mathsf{P}\). In particular, the languages of CSLib’s finite nondeterministic automata, one-way or two-way, and the preimages of subsets of finite monoids under monoid homomorphisms from binary strings are in \(\mathsf{P}\).
A finite-state scanner machine runs the deterministic automaton over the input in one pass and writes whether the final state accepts. For the other models, CSLib’s subset construction, its two-way-to-one-way theorem, and its finite-monoid characterization first show that the language is regular. Combined with Complexity.mem_P_of_isRegular, CSLib’s closure properties of regular languages give \(\mathsf{P}\)-membership of the resulting languages directly; the library does not state those instances separately.
If a machine with \(k\) work tapes decides \(L\) within time \(f\), then a multi-tape machine in CSLib’s model decides \(L\) within time and space \((2k + 3)(2f(|x|) + 5)\) on every input \(x\). CSLib’s machines take their alphabet as a parameter, and its complexity definitions use machines over the binary alphabet with finitely many states: a read-only input tape whose head cannot move more than one cell past either end of the input, two-way work tapes that start blank, and emitted output, with the work cells visited counted as space. Our languages are passed to CSLib with the identity encoding, and a decider emits the single bit \([x \in L]\). Consequently every language in \(\mathsf{DTIME}(T)\) is decided there within time and space \(t(|x|)\) for one function \(t = O(T)\), and every language in \(\mathsf{P}\) within time and space \(p(|x|)\) for one polynomial \(p\). The simulation is also space-faithful: a machine deciding \(L\) within time \(T\) and space \(S\) yields a CSLib decider within time \(2T + 4\) and space \((2k + 3)(S + 2)\), so \(\mathsf{DTISP}(T, S)\) transfers with time \(O(T)\) and space \(O(S + 1)\). A machine computing \(f\) within time \(T\) yields a CSLib machine computing \(f\), with the identity encodings of input and output, within time \(3T + 4\) and space \((2k + 3)(3T + 5)\), so every \(\mathsf{FP}\) function is CSLib-computable within polynomial time and space.
Each of the original machine’s work tapes and its output tape is simulated by a data tape and a marker tape whose heads move together; the simulator’s first step writes a \(1\) at position \(0\) of every marker tape, standing in for \(\triangleright \). It then executes one step of the original machine per step of its own. A further work tape counts how far the input head has run past the input, and a flag in the state distinguishes the blank before the input from the blank after it. When the original machine halts, the simulator rewinds its copy of the output tape, reads the verdict in cell \(1\), and emits it as one bit. Rewinding costs at most the original running time, and each work head visits at most one cell per step. Under a space bound, every simulated head stays within the original machine’s head bounds. To compute a function, the simulator instead copies output cells \(1, 2, \ldots \) to CSLib’s output until the first blank; only visited cells can be nonblank, so the output has length at most \(T\).
A CSLib multi-tape machine deciding \(L\) (with the identity encoding) within time \(t(|x|)\), under any space bound, yields one of our machines deciding \(L\) within time \(3t\). Hence CSLib time \(t\) gives \(\mathsf{DTIME}(t)\), and CSLib polynomial time gives \(\mathsf{P}\). Together with Theorem 119, a language is in \(\mathsf{P}\) if and only if some multi-tape machine in CSLib’s model decides it within polynomial time. The Lean equivalence states its right side with one polynomial bounding both time and space; the forward direction supplies the space bound, and the converse ignores it. This direction carries time only: the CSLib space bound is discarded, so there is as yet no converse for \(\mathsf{DTISP}\) or \(\mathsf{L}\).
Theorem 119 gives one direction. For the converse, the machines in CSLib’s complexity definitions are binary, so their tape symbols (blank, \(0\), \(1\)) are already ours. Fold each two-way work tape onto a one-sided tape, sending CSLib cell \(z \ge 0\) to cell \(2z + 1\) and \(z {\lt} 0\) to cell \(-2z\), and detect a crossing of the fold by bumping into \(\triangleright \). Track the clamped input head directly and write emitted bits from output cell \(1\). Each CSLib step takes three of our steps. For \(\mathsf{P}\), the time bound \(3p(n)\) is again a polynomial, and the polynomial normal form of \(\mathsf{P}\) (Lemma 125) concludes.
A CSLib machine computing a binary string function \(f\) with identity input and output encodings in time \(t(|x|)\) yields a canonical machine computing the same complete string in time \(3t(|x|)\). Consequently \(f\in \mathsf{FP}\) if and only if a CSLib machine computes it with polynomial bounds on time and space. The reverse transfer needs only the time bound.
Strengthen the folded simulation’s output invariant: the output prefix is correct, the head is at its end, and every subsequent cell is blank. Each emitted bit preserves this invariant. The halting configuration therefore satisfies the complete string-output contract, including for the empty string. The polynomial normal form and the forward simulator finish the equivalence.
A source machine has finite alphabet and control state sets, distinguished blank and initial states, and a faithful encoding of binary digits by tape symbols. Blank terminates the decoded output. The bounded output contract requires a halted source run from the literal encoded input whose entire right-of-head tape is the encoded output followed by blanks.
A source computation from input \(x\) to output \(y\) in at most \(T\) steps is simulated by a fixed finite-state binary CSLib machine in at most \(2|x|+T+|y|+4\) steps. Consequently, polynomial bounds on source time and full output length on every binary input establish canonical \(\mathsf{FP}\) membership for the computed string function.
Use one binary track per source symbol, with the blank encoded by all blank tracks. Copying and rewinding the input take \(2|x|+2\) steps. Every source write or move then takes one step, preserving relative tape contents. On source halting, enter an output phase that emits one bit per step and halts at the first blank, taking \(|y|+2\) additional steps. Apply the complete-output CSLib-to-canonical simulation.
Suppose a finite Mathlib machine computes \(f(x)\) with polynomial time and output bounds for inputs accepted by a fixed DFA. Returning \(f(x)\) on accepted inputs and the empty string on every other input defines a total function in \(\mathsf{FP}\). Validation adds \(2|x|+2\) source steps on accepted inputs; rejected inputs halt after \(|x|\) steps.
Scan the input without writing, retaining the DFA state. Rejection halts on the first blank, whose entire right-hand tape is blank. On acceptance, rewind to the blank preceding the input, move right to the original head, and execute the source machine with unchanged tape contents. Apply the finite-machine simulation and its complete-output polynomial bound.
4.2 Closure properties of P and FP
The projections of the pairing codec, the pairing of two \(\mathsf{FP}\) functions, and the pairing of an \(\mathsf{FP}\) value with the unchanged input are in \(\mathsf{FP}\); these facts are stated in the chapter on encodings (Theorem 70).
\(L \in \mathsf{P}\) if and only if some deterministic machine decides \(L\) within time \(n \mapsto p(n)\) for a polynomial \(p\) with natural-number coefficients. Likewise \(f \in \mathsf{FP}\) if and only if some deterministic machine computes \(f\) within time \(n \mapsto p(n)\) for such a polynomial \(p\).
A bound \(f = O(n^k)\) is dominated everywhere by an explicit polynomial, the finitely many small inputs being absorbed into its constant term, and deciding or computing within time \(f\) implies doing so within any pointwise larger bound. Conversely, a polynomial of degree \(d\) is \(O(n^d)\).
\(\mathsf{P}\) is closed under complement, union, intersection, set difference, and symmetric difference. In particular \(\{ L : \overline{L} \in \mathsf{P}\} = \mathsf{P}\). At the level of time bounds, \(L_1 \in \mathsf{DTIME}(T_1)\) and \(L_2 \in \mathsf{DTIME}(T_2)\) imply \(L_1 \cup L_2 \in \mathsf{DTIME}(T_1 + T_2)\).
Complement runs the decider and flips the output bit, in \(2f(n) + 4\) steps. Union runs both deciders in sequence, in \(10 f_1(n) + f_2(n)\) steps, which is \(O(T_1 + T_2)\). Intersection and difference follow by De Morgan, and symmetric difference is the union of the two differences.
The identity function is in \(\mathsf{FP}\), and if \(f, g \in \mathsf{FP}\) then \(g \circ f \in \mathsf{FP}\).
The identity is computed by copying the input to the output in \(n + 2\) steps. For composition, both time bounds are first put in polynomial normal form, and the two machines run in sequence on disjoint tapes, the output of the first becoming the input of the second; since \(|f(x)| \le T_f(|x|)\), the total time is polynomial.
Every constant function is in \(\mathsf{FP}\), and so is \(x \mapsto 1^{|x|}\). For every function \(g\) and every finite set \(S\) of strings, the function equal to \(g\) on \(S\) and to the empty string off \(S\) is in \(\mathsf{FP}\). Hence if \(k \in \mathsf{FP}\) and \(|k(x)| \le L\) for all \(x\), then \(x \mapsto g(k(x))\) is in \(\mathsf{FP}\) for every function \(g\).
Constants lie in Cobham’s algebra, so they are in \(\mathsf{FP}\) by the soundness half of Theorem 132. The unary length is written in one pass over the input, in \(n + 2\) steps. For a function supported on \(S\), the finite table of its values on \(S\) is hard-wired into the states of a machine that decides membership in \(S\) while scanning the input and then writes the stored value, in linear time. For the last claim take \(S\) to be the strings of length at most \(L\) and compose with \(k\).
If \(f \in \mathsf{FP}\) and \(L \in \mathsf{P}\), then \(f^{-1}(L) = \{ x : f(x) \in L\} \in \mathsf{P}\). The same holds with \(\mathsf{NP}\) in place of \(\mathsf{P}\).
Put both time bounds in polynomial normal form, then run the transducer for \(f\) and the decider for \(L\) on its output in sequence on disjoint tapes, deterministically or nondeterministically. The output of \(f\) has polynomial length, so the second stage runs in polynomial time in \(|x|\). In the nondeterministic case a decider that starts in its halting state accepts nothing, and the preimage of the empty language is handled directly.
The language of strings containing a \(1\) is in \(\mathsf{P}\). If \(f \in \mathsf{FP}\) and, for all \(x\), \(x \in L\) exactly when \(f(x)\) contains a \(1\), then \(L \in \mathsf{P}\). In particular, if \(g\) is Boolean-valued, the function \(x \mapsto [g(x)]\) (the one-bit string) is in \(\mathsf{FP}\), and \(x \in L \iff g(x) = 1\), then \(L \in \mathsf{P}\). Conversely, every \(L \in \mathsf{P}\) has such a Boolean-valued \(g\); so \(L \in \mathsf{P}\) if and only if some Boolean-valued \(g\) with \(x \mapsto [g(x)]\) in \(\mathsf{FP}\) satisfies \(x \in L \iff g(x) = 1\) for all \(x\). Finally, if \(k \in \mathsf{FP}\) and \(|k(x)| \le L\) for all \(x\), then \(\{ x : Q(k(x))\} \in \mathsf{P}\) for every predicate \(Q\).
A finite-state scanner decides the strings containing a \(1\) in \(n + 2\) steps, and \(L\) is the preimage of that language under \(f\). Together with Cobham’s theorem this lets membership in \(\mathsf{P}\) be established by writing a function rather than a machine. For the converse, run a polynomial-time decider for its time bound inside Cobham’s algebra (halted configurations are fixed points of the encoded step) and read off the verdict cell. The last claim takes \(g(x) = [Q(k(x))]\), which is in \(\mathsf{FP}\) by Lemma 128.
4.3 Cobham’s theorem: FP as a programming language
Bit strings are read least-significant bit first. Cobham’s algebra is the smallest class of functions \((\{ 0,1\} ^*)^n \to \{ 0,1\} ^*\), over all arities \(n\), that contains the projections, the empty-string constant, the bit successors \(x \mapsto b\, x\) (prepend \(b\)), and \(\mathrm{smash}(x, y) = 1^{|x| \cdot |y|}\), and is closed under composition and limited recursion on notation: if \(g, h_0, h_1, j\) are in the class and the function \(f\) defined by \(f(\varepsilon , v) = g(v)\) and \(f(b\, x, v) = h_b(x, f(x, v), v)\) satisfies \(|f(x, v)| \le |j(x, v)|\) for all \(x, v\), then \(f\) is in the class. The unary fragment is \(\mathsf{CobhamFP}\).
\(\mathsf{CobhamFP} = \mathsf{FP}\).
Soundness is an induction over the constructors of the algebra; limited recursion on notation is a fold whose width clamp is vacuous under Cobham’s side condition, run by Lemma 134. Completeness simulates a polynomial-time machine inside the algebra: a configuration is one block-aligned string with each tape split at its head, the transition function is a finite table, the run is iterated under a clock built from \(\mathrm{smash}\), and the output is read after a rewind.
For every \(n\) and \(f \colon (\{ 0,1\} ^*)^n \to \{ 0,1\} ^*\), \(f\) is in Cobham’s algebra if and only if there is \(g \in \mathsf{FP}\) with \(g(\mathrm{enc}(v)) = f(v)\) for all \(v\), where \(\mathrm{enc}\) is the canonical fixed-arity tuple encoding by nested pairing, \(\mathrm{enc}() = \varepsilon \) and \(\mathrm{enc}(v_0, v_1, \ldots , v_m) = \langle \mathrm{enc}(v_1, \ldots , v_m), v_0 \rangle \). The encoding \(\mathrm{enc}\) is itself in Cobham’s algebra at every arity.
The soundness induction is carried out at every arity; completeness composes the unary simulation with the tuple encoding, which is itself in the algebra.
Let \(F, \mathit{init}, \mathit{ruler}, \mathit{width} \in \mathsf{FP}\), and suppose \(|F^m(\mathit{init}(z))| \le |\mathit{width}(z)|\) for every \(z\) and every \(m \le |\mathit{ruler}(z)|\). Then \(z \mapsto F^{|\mathit{ruler}(z)|}(\mathit{init}(z))\) is in \(\mathsf{FP}\). The same holds when the width is replaced by a polynomial bound \(|F^m(\mathit{init}(z))| \le B(|z|)\), or by a constant \(c\) with \(|F^{m+1}(\mathit{init}(z))| \le |F^m(\mathit{init}(z))| + c\) for every \(m {\lt} |\mathit{ruler}(z)|\).
One machine iterates a truncated step once per bit of its own input, with a unary counter that stops applying \(F\) after \(|\mathit{ruler}(z)|\) rounds; the width bound keeps every intermediate state polynomially long. This machine is Complexity.Cobham.iterate_mem_FP in the proof-internal module Classes/P/Cobham/Internal.lean. The surface module Classes/P/Iterate.lean restates it and derives the variants: a polynomial bound has a ruler in \(\mathsf{FP}\) at least as long, and a per-step bound gives a polynomial one, because \(\mathit{init}(z)\) and \(\mathit{ruler}(z)\) are outputs of polynomial-time functions and so are polynomially long. Complexity.iterate_mem_FP_along states the bound on the values the states encode, when \(F\) computes a map on them.
Given an initializer \(I\) and a step \(F_x\) depending on an unchanged input \(x\), let \(G\) replace \(\mathrm{pair}(\varepsilon ,x)\) by \(\mathrm{pair}(I(x),x)\) and replace \(\mathrm{pair}(s,x)\), for nonempty \(s\), by \(\mathrm{pair}(F_x(s),x)\). On arbitrary strings it uses the total pair projections. If \(I\) and the function mapping a packed state and input to \(F_x(s)\) belong to \(\mathsf{FP}\), then \(G \in \mathsf{FP}\). Whenever \(F_x^j(I(x))\) is nonempty for every \(j{\lt}n\),
The last state may be empty; the extra call is exactly initialization.
Pairing, projections, and branching on emptiness are polynomial-time. Induction on \(n\) proves the orbit equation; nonemptiness prevents a later call from initializing again. Both the Savitch and IP stack walks use this controller and their existing encoded-step simulation theorems.
Let \(f \in \mathsf{FP}\), write \(1^i\) for the string of \(i\) ones, and write \(f_i(z) = f(\langle z, 1^i \rangle )\).
Concatenation over a range: the map \(\langle u, z \rangle \mapsto f_0(z) \, f_1(z) \cdots f_{|u| - 1}(z)\) is in \(\mathsf{FP}\). Hence for every \(m \in \mathsf{FP}\) the map \(z \mapsto f_0(z) \, f_1(z) \cdots f_{|m(z)| - 1}(z)\) is in \(\mathsf{FP}\).
List encoding: the same concatenation between a leading \(0\) and a trailing \(1\) is in \(\mathsf{FP}\). If \(f_i(z)\) is the serialization of the \(i\)-th entry of a list \(\ell \) with \(|\ell | = |u|\), it is the serialization of \(\ell \).
Counting: the map sending \(\langle 1^n, z \rangle \) to \(1^s\), where \(s = \sum _{i {\lt} n} |f_i(z)|\), is in \(\mathsf{FP}\).
Search: the map sending \(\langle 1^n, z \rangle \) to \(1^c\) is in \(\mathsf{FP}\), where, whenever some \(f_i(z)\) with \(i {\lt} n\) is nonempty, \(c\) is the least such \(i\).
Maximum: the map sending \(\langle 1^n, z \rangle \) to \(1^M\), where \(M = \max _{i {\lt} n} |f_i(z)|\) (and \(M = 0\) when \(n = 0\)), is in \(\mathsf{FP}\).
Bitwise description: if \(x \mapsto 1^{\ell (x)}\) is in \(\mathsf{FP}\) and \(f_i(x)\) is the single bit \(b(x, i)\) for all \(x\) and \(i\), then \(x \mapsto b(x, 0) \, b(x, 1) \cdots b(x, \ell (x) - 1)\) is in \(\mathsf{FP}\).
The concatenation is a loop by Lemma 134, whose state holds the output so far, the index in unary, and \(z\). After \(k \le |u|\) rounds the state holds \(k\) outputs of \(f\). Each is polynomially long in \(|\langle u, z \rangle |\), because an \(\mathsf{FP}\) function has polynomially long outputs, and \(k \le |\langle u, z \rangle |\), so the states are polynomially bounded and no bound has to be supplied. A range given by \(m\) is the first map applied to \(\langle m(z), z \rangle \). The other items are corollaries. The list encoder adds two constant bits. A count is the length of a concatenation. The search counts the \(j {\lt} n\) such that \(f_i(z)\) is empty for every \(i \le j\). The maximum is at most the total length \(s\), so it is the number of \(j {\lt} s\) such that some \(|f_i(z)|\) exceeds \(j\), which is a count of counts. A bitwise description is a concatenation of one-bit outputs.
In Lean, in Classes/P/Range.lean, with \(f\) reading \(\langle z, 1^i \rangle \) as above: Complexity.catRange_mem_FP and Complexity.flatMap_range_mem_FP are item 1, Complexity.listEncFn_mem_FP and Complexity.listEncFn_eq_bitstringEncode item 2, Complexity.countOver_mem_FP with Complexity.length_countOver and Complexity.countOver_eq_replicate item 3, Complexity.findFirst_mem_FP with Complexity.length_findFirst_eq and Complexity.findFirst_eq_replicate item 4, Complexity.maxFn_mem_FP with Complexity.maxFn_eq item 5, and Complexity.bitwise_mem_FP item 6. Concatenations over index ranges describe the Cook–Levin emitter, whose clause families are indexed that way.
A function \(f\) from strings to natural numbers is polynomial-time if \(z \mapsto 1^{f(z)}\) is in \(\mathsf{FP}\), that is, if its value can be written in unary in polynomial time. A predicate \(p\) on strings is polynomial-time if there is a Boolean-valued \(g\) with \(z \mapsto [g(z)]\) in \(\mathsf{FP}\) and \(p(z) \iff g(z) = 1\) for all \(z\).
In the sense of Definition 137, the following are polynomial-time, for polynomial-time numbers \(f, g, n, b, k, c\) and predicates \(p, q\).
The length \(|h(z)|\) of any \(h \in \mathsf{FP}\), every constant, and \(f(z) + g(z)\), \(f(z) \cdot g(z)\), \(f(z) \mathbin {\dot-} g(z)\), \(\min (f(z), g(z))\), \(\max (f(z), g(z))\), and \(f(z)^d\) for each fixed \(d\).
The predicates \(f(z) \le g(z)\), \(f(z) {\lt} g(z)\), \(f(z) = g(z)\), \(p \wedge q\), \(p \vee q\) and \(\neg p\), and the case distinction \(z \mapsto \) (\(f(z)\) if \(p(z)\), else \(g(z)\)). The same case distinction between two functions in \(\mathsf{FP}\) is in \(\mathsf{FP}\).
Loops over the indices below \(n(z)\), whose body reads \(\langle z, 1^i \rangle \): the sum of \(f(\langle z, 1^i \rangle )\), the number of \(i\) with \(p(\langle z, 1^i \rangle )\), the least such \(i\) (or \(n(z)\) if there is none), and the largest \(f(\langle z, 1^i \rangle )\). Also \(k(z)\) rounds of an update \(x \mapsto s(z, x)\) from \(a(z)\), when \(\langle z, 1^x \rangle \mapsto s(z, x)\) is polynomial-time and every value along the way is at most a polynomial-time number. Also the bounded quantifiers: \(p(\langle z, 1^i \rangle )\) for every \(i {\lt} n(z)\), and for some \(i {\lt} n(z)\).
\(f(z) / g(z)\) and \(f(z) \bmod g(z)\) (with \(f / 0 = 0\)), the capped power \(\min (b(z)^{k(z)}, c(z))\), the binary length of \(f(z)\), and the floor and ceiling logarithms of \(f(z)\) to the base \(b(z)\).
Every predicate \(z \mapsto Q(k(z))\) of a key \(k \in \mathsf{FP}\) of bounded length is polynomial-time. A language whose membership predicate is polynomial-time is in \(\mathsf{P}\).
Items 1 and 2 are closure rules of Cobham’s algebra on unary strings: concatenation, the length product, dropping and taking a prefix, the length comparison, the Boolean connectives on one-bit strings, and selection by a leading bit. A sum is a count of Lemma 136, a count is a sum of zeros and ones, and the maximum is the maximum of that lemma. The least \(i\) with \(p\) counts the \(j {\lt} n(z)\) at which \(p\) fails at every index up to \(j\), a count of counts. The universal quantifier holds when that count equals \(n(z)\), and the existential one is the negation of the universal quantifier of \(\neg p\). The update loop is an instance of Lemma 134 on \(\langle 1^x, z \rangle \), whose length is bounded because the bound is written by a polynomial-time function. Item 4 is derived from these: \(f / g\) counts the \(i {\lt} f\) with \(g {\gt} 0\) and \((i + 1) g \le f\), and \(f \bmod g = f - g \cdot (f / g)\); the capped power iterates \(x \mapsto \min (b x, c)\); the binary length of \(f\) counts the \(i {\lt} f\) with \(2^i \le f\), and the logarithms count the \(i {\lt} f\) with \(b^{i+1} \le f\) and with \(b^i {\lt} f\), comparing capped powers. A predicate of a bounded key has its one-bit verdict in \(\mathsf{FP}\) by Lemma 128. The last claim is Lemma 130.
In Lean, in Classes/P/Unary.lean, with the bounded quantifiers in Classes/P/BoundedQuant.lean, the bounded key in Classes/P/FinsetDomain.lean and the membership test in Classes/P/DecisionFn.lean.
If \(s\in \mathsf{FP}\) and the position \(i(z)\) is a polynomial-time unary number, returning the bit \(s(z)[i(z)]\), with false past the end, is in \(\mathsf{FP}\). Testing this bit is therefore a polynomial-time predicate. The length of the leading run of true bits of \(s(z)\) is also a polynomial-time unary number, including the case with no false terminator. Taking or dropping a prefix of polynomial-time unary length also preserves \(\mathsf{FP}\).
Use the existing Cobham bit reader and bounded leading-run loop. Prove that each bit before the take-while boundary is true and the bit at the boundary is false, using the false default when the whole string is true. The loop’s exact-length theorem then identifies its output length with that boundary. For slicing, write the requested length as a unary string and apply the existing take-length and drop-length machines.
Let \(w, n, c\) be polynomial-time numbers in the sense of Definition 137, let \(s \in \mathsf{FP}\), and for a string \(x\) let \(v(x)\) be its value as a binary numeral, least significant bit first.
The low \(w(z)\) bits of \(n(z)\), least significant first, and the minimal binary expansion \(\mathrm{bin}(n(z))\) are in \(\mathsf{FP}\) as functions of \(z\).
\(\min (v(s(z)), c(z))\) is a polynomial-time number; so is \(v(s(z))\) itself when \(v(s(z)) \le c(z)\) for all \(z\).
The serialization of \(s(z)\) as a list of bits, and the serialization of the number \(n(z)\), are in \(\mathsf{FP}\) as functions of \(z\).
Bit \(i\) of \(n\) is \(\lfloor n / 2^i \rfloor \bmod 2\), and capping the power at \(n + 1\) does not change the quotient, so each bit is a polynomial-time test of \(\langle z, 1^i \rangle \) by Lemma 138; the expansion of width \(w(z)\) is the bitwise description of Lemma 136, and \(\mathrm{bin}(n)\) is the expansion of width the binary length of \(n\). Reading a numeral back is a fold over its bits, from the last to the first, that doubles the value, adds the bit and caps the result at \(c(z)\). The cap keeps the states polynomially short and does not change the capped result, since doubling and adding preserve being at least \(c(z)\). The serialization of a bit list puts \(01\) or \(0011\) for each bit between a leading \(0\) and a trailing \(1\), which is a fold whose state is at most four times as long as the list; a number is serialized as the list \(\mathrm{bin}(n)\), so no width has to be supplied.
In Lean, in Classes/P/NatCodes.lean and Classes/P/DataEncode.lean; the folds are instances of Complexity.recFold_mem_FP_of_bound.
For a finite state set \(Q\), a transition \(\delta \colon Q \times \{ 0,1\} \to Q\), an initial state, and an output map \(o \colon Q \times \{ 0,1\} \to \{ 0,1\} ^*\), the transducer that scans \(z\) from left to right and emits \(o(q_i, z_i)\) at each position is in \(\mathsf{FP}\). More generally, the state may be a polynomially bounded string updated by an \(\mathsf{FP}\) step.
An instance of Lemma 134, with the state carrying the output produced so far, or limited recursion on notation directly. This statement is not yet formalized. What is formalized is a fold in the other direction, Complexity.recFold_mem_FP_of_bound in Classes/P/Iterate.lean. It reads the input from its last bit to its first and updates a polynomially short state by one of two \(\mathsf{FP}\) steps. The left-to-right scan, and the finite-state transducer with its output map, are not yet derived from it. Streaming passes of this kind describe the Tseitin transducer (one pass over a CNF encoding) and the \(\mathrm{SAT}\) verifier (a streaming evaluation); see the open directions at the end of this chapter.
4.4 Witnesses, FNP, and TFNP
For a relation \(R \subseteq \{ 0,1\} ^* \times \{ 0,1\} ^*\), \(\mathrm{pairLang}(R) = \{ \langle x, y \rangle : R(x, y)\} \) using the library’s pairing codec. \(R\) is polynomially balanced if there is a polynomial \(p\) with \(R(x, y) \Rightarrow |y| \le p(|x|)\).
\(\mathsf{FNP}\) is the set of polynomially balanced relations \(R\) with \(\mathrm{pairLang}(R) \in \mathsf{P}\). \(\mathsf{TFNP}\) is the set of \(R \in \mathsf{FNP}\) such that every \(x\) has some \(y\) with \(R(x, y)\).
Suppose an ordinary deterministic verifier decides \(L_0\) in time \(T\) and decision space \(S\). Let a concrete setup machine compute a unary witness bound \(B(n)\) in time \(A(n)\) and space \(U(n)\), restoring the input and leaving the required parked frame. There is a witness machine deciding \(\{ x : \exists y,\ |y| \le B(|x|) \land \langle x,y\rangle \in L_0\} \). It stores the finite certificate and paired virtual input on charged work tapes. Put \(R_B(n)=\max _{m\le B(n)} R(2n+2+m)\), \(G(n)=3B(n)+3\), and \(P_B(n)=4n+2B(n)+10\). Its bounds are
in time and
in charged space. No monotonicity of \(T\) or \(S\) is assumed. The online witness equivalence transfers these same compiler bounds to an NTM.
First realize the unary bound in a private setup block, reserving separate blank verifier and certificate tapes. The bounded guessing phase stores every certificate of length at most \(B(n)\) and no longer one. The remaining deterministic phases construct the pair and run the verifier in a disjoint work-tape block. Their contracts preserve the frame and bound every reachable prefix, including output travel. The certificate source is read once; the stored reusable copy is charged. For \(B(n)=n+1\), a concrete one-counter setup has \(A(n)=U(n)=4n+11\).
Let \(p\) be a polynomial and \(L_0 \in \mathsf{P}\) with \(\langle x, y \rangle \in L_0 \Rightarrow |y| \le p(|x|)\) for all \(x, y\). If, for all \(x\), \(x \in L \iff \exists y\, \langle x, y \rangle \in L_0\), then \(L \in \mathsf{NP}\). For linearly bounded witnesses no balance hypothesis on \(L_0\) is needed: if \(L_0 \in \mathsf{P}\) and, for all \(x\), \(x \in L \iff \exists y\, (|y| \le |x| + 1 \wedge \langle x, y \rangle \in L_0)\), then \(L \in \mathsf{NP}\). In relational form, if \(\mathrm{pairLang}(R) \in \mathsf{P}\), \(R(x, y) \Rightarrow |y| \le |x| + 1\), and \(x \in L \iff \exists y\, R(x, y)\) for all \(x\), then \(L \in \mathsf{NP}\).
Instantiate Theorem 144 with the concrete bound \(B(n)=n+1\). Its time is \(13n+32+T_B(n)\), which is polynomial whenever the verifier’s time is polynomial. This proves the linear witness statement; the online-witness equivalence supplies its NTM. A general polynomial bound is reduced to the linear case by padding the input with a polynomial-length ruler: the padded verifier checks the original verifier on the unpadded pair and checks that the ruler is long enough, which is in \(\mathsf{P}\) by intersection and a length-comparison verdict function, and the language is pulled back along the padding map. The polynomial statement is in Classes/NP/Verifier.lean and both linear ones in Classes/NP/Verifier/Linear.lean; SAT/Internal/LinearGuessVerify.lean keeps an older relational form proved through a \(\mathrm{SAT}\)-specialized guess-and-verify machine.
If \(R \in \mathsf{FNP}\) and \(x \in L \iff \exists y\, R(x, y)\) for all \(x\), then \(L \in \mathsf{NP}\). In particular \(\{ x : \exists y\, R(x, y)\} \in \mathsf{NP}\) for every \(R \in \mathsf{FNP}\).
The decider of \(\mathrm{pairLang}(R)\) is the verifier and the balance polynomial bounds the witnesses, so Lemma 145 applies. The construction is packaged as the named interface Complexity.NP.WitnessNTMConstruction (a polynomial-time decider for \(\mathrm{pairLang}(R)\) and a polynomial witness bound yield a polynomial-time nondeterministic decider for \(\{ x : \exists y\, R(x, y)\} \)), which Complexity.NP.witnessNTMConstruction proves unconditionally.
For every \(L \in \mathsf{NP}\) there is \(R \in \mathsf{FNP}\) with \(x \in L \iff \exists y\, R(x, y)\) for all \(x\). Together with Theorem 146, \(\mathsf{NP} = \{ L : \exists R \in \mathsf{FNP}\ \forall x\ (x \in L \iff \exists y\, R(x, y))\} \).
Replace the time bound \(f = O(n^k)\) by a dominating explicit polynomial \(p\); since every path halts within \(f(|x|) \le p(|x|)\) steps, acceptance within \(p(|x|)\) steps is equivalent to acceptance within \(f(|x|)\) steps. Take as witness the choice sequence of an accepting path, of length \(p(|x|)\). The verifier runs the machine deterministically along the given choices; Complexity.NTM.choiceTM already does this, and the same run is simulated inside Cobham’s algebra for the Sipser–Lautemann theorem, so the verdict can be written as a Cobham function and converted to \(\mathsf{P}\) with Lemma 130.
\(\mathsf{NP} = \Sigma ^p_1\) and \(\mathsf{coNP} = \Pi ^p_1\), for the certificate-quantifier levels of Definition 189.
Neither inclusion is formalized yet. \(\Sigma ^p_1\) is the bounded existential closure of \(\mathsf{P}\) (formalized as Complexity.SigmaP_one). For \(\Sigma ^p_1 \subseteq \mathsf{NP}\), apply Lemma 145 to \(L' \cap \{ \langle x, w \rangle : |w| \le p(|x|)\} \), whose length test is polynomial-time by the same length-comparison argument as the padded verifier in that lemma’s proof. For \(\mathsf{NP} \subseteq \Sigma ^p_1\), use Theorem 147. The \(\Pi ^p_1\) statement follows by complementation, using \(\Pi ^p_1 = \forall \mathsf{P}\) (Complexity.PiP_one).
\(\mathsf{FNP}\) is closed under disjunction: if \(R_1, R_2 \in \mathsf{FNP}\) then \(R_1 \vee R_2 \in \mathsf{FNP}\). If moreover a language \(L\) satisfies \(x \in L \iff \exists y\, R_1(x, y)\) and \(x \notin L \iff \exists y\, R_2(x, y)\) for all \(x\), then \(R_1 \vee R_2\) is in \(\mathsf{TFNP}\) (Megiddo–Papadimitriou).
The balance polynomials add, and the pair language of \(R_1 \vee R_2\) is the union of the two pair languages, which is in \(\mathsf{P}\). Every \(x\) has a witness for one side. The formalized statement takes the two witness relations as hypotheses; that every language in \(\mathsf{NP} \cap \mathsf{coNP}\) supplies such a pair would follow from the planned Theorem 147.
4.5 Reductions and completeness
\(L \le _p L'\) if there is \(f \in \mathsf{FP}\) with \(x \in L \iff f(x) \in L'\) for all \(x\).
\(L \le _p L\), and \(L_1 \le _p L_2 \le _p L_3\) implies \(L_1 \le _p L_3\).
The identity and composition are in \(\mathsf{FP}\).
If \(L_1 \le _p L_2\) then \(\overline{L_1} \le _p \overline{L_2}\), and for each \(\mathcal{C} \in \{ \mathsf{P}, \mathsf{NP}, \mathsf{coNP}\} \), \(L_2 \in \mathcal{C}\) implies \(L_1 \in \mathcal{C}\).
The same function reduces the complements, and \(L_1 = f^{-1}(L_2)\).
\(L\) is \(\mathsf{NP}\)-hard if \(L' \le _p L\) for every \(L' \in \mathsf{NP}\), and \(\mathsf{NP}\)-complete if moreover \(L \in \mathsf{NP}\).
If \(L_1\) is \(\mathsf{NP}\)-hard and \(L_1 \le _p L_2\), then \(L_2\) is \(\mathsf{NP}\)-hard; if moreover \(L_2 \in \mathsf{NP}\), then \(L_2\) is \(\mathsf{NP}\)-complete. (The variant NPComplete.transfer assumes \(L_1\) \(\mathsf{NP}\)-complete.)
Transitivity of \(\le _p\).
If \(L\) is \(\mathsf{NP}\)-hard and \(L \in \mathsf{P}\), then \(\mathsf{P} = \mathsf{NP}\). If \(L\) is \(\mathsf{NP}\)-complete, then \(L \in \mathsf{P} \iff \mathsf{P} = \mathsf{NP}\) and \(L \in \mathsf{coNP} \iff \mathsf{NP} = \mathsf{coNP}\).
Every \(\mathsf{NP}\) language pulls back into \(\mathsf{P}\) (respectively \(\mathsf{coNP}\)) along its reduction to \(L\).
\(L\) is \(\mathsf{coNP}\)-hard if \(L' \le _p L\) for every \(L' \in \mathsf{coNP}\), and \(\mathsf{coNP}\)-complete if moreover \(L \in \mathsf{coNP}\).
\(\overline{L} \in \mathsf{coNP}\) if and only if \(L \in \mathsf{NP}\). If \(L_1\) is \(\mathsf{coNP}\)-hard and \(L_1 \le _p L_2\), then \(L_2\) is \(\mathsf{coNP}\)-hard, and \(\mathsf{coNP}\)-complete if moreover \(L_2 \in \mathsf{coNP}\). The complement of an \(\mathsf{NP}\)-hard (respectively \(\mathsf{NP}\)-complete) language is \(\mathsf{coNP}\)-hard (respectively \(\mathsf{coNP}\)-complete), and the complement of a \(\mathsf{coNP}\)-hard (respectively \(\mathsf{coNP}\)-complete) language is \(\mathsf{NP}\)-hard (respectively \(\mathsf{NP}\)-complete).
The transfers are transitivity of \(\le _p\). For duality, a function reducing \(L_1\) to \(L_2\) also reduces \(\overline{L_1}\) to \(\overline{L_2}\): if \(L' \in \mathsf{coNP}\) then \(\overline{L'} \in \mathsf{NP}\) reduces to an \(\mathsf{NP}\)-hard \(L\), so \(L' \le _p \overline{L}\); the other direction is symmetric.
4.6 Satisfiability and the Cook–Levin theorem
A CNF formula is a list of clauses, a clause a list of literals, and a literal a sign with a variable index in \(\mathbb {N}\); an assignment is a bit string, with out-of-range variables read as false. Formulas are encoded as bit strings as follows: a literal is its sign bit followed by its variable index in unary, with every bit doubled; each literal is followed by the undoubled pair \(01\) and each clause by the undoubled pair \(10\). \(\mathrm{SAT}\) is the set of encodings of satisfiable formulas (so strings that encode no formula are excluded). The witness relation holds of \((z, \alpha )\) when \(z\) encodes some \(\varphi \), \(|\alpha | \le |z| + 1\), and \(\alpha \) satisfies \(\varphi \).
For every \(z\), \(z \in \mathrm{SAT}\) if and only if some \(\alpha \) is a witness for \(z\), and the witness relation is polynomially balanced. Its pair language is decided by a deterministic machine with three work tapes within a time bound that is \(O(n^2)\), so it is in \(\mathsf{P}\); and \(\mathrm{SAT} \in \mathsf{NP}\).
Unary variable indices give \(\max \mathrm{var}(\varphi ) \le |z|\), so a satisfying assignment can be truncated to length at most \(|z| + 1\); this makes \(z \in \mathrm{SAT}\) equivalent to the existence of a witness. The three-work-tape deterministic verifier parses the formula and evaluates it at the witness, so the pair language is in \(\mathsf{P}\), and the relational linear case of Lemma 145, which runs the generic finite-verifier compiler, gives \(\mathrm{SAT} \in \mathsf{NP}\).
\(\mathrm{SAT}\) is \(\mathsf{NP}\)-complete. More precisely, if a nondeterministic machine with any number of work tapes decides \(L\) within time \(T\) with \(T = O(n^c)\), then \(L \le _p \mathrm{SAT}\). For a machine \(N\) with one work tape, the tableau formula of \(N\) on \(x\) for \(s\) steps is satisfiable if and only if some choice sequence of length \(s\) makes \(N\) accept \(x\); and for every polynomial \(p\) the map sending \(x\) to the encoding of the tableau formula for \(p(|x|)\) steps is in \(\mathsf{FP}\).
The machine is first converted to one with a single work tape, and \(T\) is replaced by a dominating explicit polynomial \(p\), under which the machine still decides \(L\). The reduction maps \(x\) to the (variable-flattened) tableau formula for \(p(|x|)\) steps, which is satisfiable exactly when some path accepts. An emitter machine writes the seven encoded clause families of the tableau in polynomial time. Membership is Theorem 159.
The complement of \(\mathrm{SAT}\) (as a set of bit strings, so including all malformed strings) is \(\mathsf{coNP}\)-complete. \(\mathrm{SAT} \in \mathsf{P} \iff \mathsf{P} = \mathsf{NP}\), and \(\mathrm{SAT} \in \mathsf{coNP} \iff \mathsf{NP} = \mathsf{coNP}\).
\(3\mathrm{SAT}\) is the set of encodings, in the \(\mathrm{SAT}\) codec, of satisfiable CNF formulas in which every clause has exactly three literals.
There is a total function in \(\mathsf{FP}\) witnessing \(\mathrm{SAT} \le _p 3\mathrm{SAT}\). On the encoding \(z\) of a formula it outputs the encoding of an exact-3 formula that is satisfiable exactly when the source is: short nonempty clauses are padded by repeating literals, the empty clause becomes a contradictory pair of clauses on a fresh variable, and long clauses are split by a chain of fresh variables, all numbered from \(|z| + 1\) upward (the splitting is exact-3 from any starting counter and equisatisfiable from any counter above every source variable). On a malformed string it outputs a fixed unsatisfiable exact-3 formula. A deterministic machine computes the function within \(6n + 16384(n + 2)^4 + 49\) steps.
Equisatisfiability is proved clause by clause with a threaded fresh-variable counter; polynomial time is a bespoke streaming transducer.
\(3\mathrm{SAT}\) is \(\mathsf{NP}\)-complete.
Membership: a witness is a \(\mathrm{SAT}\) witness whose formula also passes the exact-3 syntax check, a regular property decided by a finite-state scanner. The paired verifier language is the intersection of the \(\mathrm{SAT}\) verifier language with the paired syntax language, hence in \(\mathsf{P}\), and witnesses have length at most \(|z| + 1\), so the linear case of Lemma 145 applies. Hardness: compose Cook–Levin with Tseitin splitting.
The language accepts exactly the canonical pair encodings \(\langle c, r \rangle \) (all other strings are rejected) of a tagged circuit-family code \(c\) and a ruler \(r\), whose contents are ignored and whose length fixes the assignment width, for which some \(w\) with \(|w| = |r|\) makes the serialized circuit evaluator return true on \(c\) and \(w\). The pair language of its witness relation is in \(\mathsf{P}\), and the language is in \(\mathsf{NP}\). The same holds for the extension variant, which accepts exactly the canonical encodings \(\langle c, \langle u, r \rangle \rangle \) for which some \(w\) with \(|w| = |r|\) makes the evaluator return true on \(c\) and \(u\, w\).
The paired witness language is an intersection of pair validation, the verified serialized circuit evaluator’s language pulled back along a polynomial-time repacking, and a length test, so it is in \(\mathsf{P}\); and witnesses have length at most the query length plus one, so the relational linear case of Lemma 145 applies. \(\mathsf{NP}\)-hardness of these languages is not yet stated.
4.7 More NP-complete problems
Fix a concrete prefix codec for Boolean formulas over \(\wedge \), \(\vee \), \(\neg \) and variables, and let \(\mathrm{FSAT}\) be the set of encodings of satisfiable formulas, malformed strings excluded. Then \(\mathrm{SAT} \le _p \mathrm{FSAT}\) (a CNF is a formula) and \(\mathrm{FSAT} \le _p \mathrm{SAT}\) (Tseitin encoding with one fresh variable per gate), so \(\mathrm{FSAT}\) is \(\mathsf{NP}\)-complete.
Membership by guess and verify with a formula evaluator; both reductions are streaming transducers, most easily written through Lemma 141.
Fix a codec for pairs \(\langle G, k \rangle \) of a finite simple graph (vertex count in unary and a row-major adjacency matrix) and a threshold \(k\) in unary, with malformed strings as no-instances. \(\mathrm{INDSET}\), \(\mathrm{CLIQUE}\), and \(\mathrm{VC}\) are the sets of \(\langle G, k \rangle \) such that \(G\) has an independent set of size at least \(k\), a clique of size at least \(k\), and a vertex cover of size at most \(k\), respectively.
\(\mathrm{INDSET}\) is \(\mathsf{NP}\)-complete.
Membership by guess and verify on a vertex subset. Hardness by \(3\mathrm{SAT} \le _p \mathrm{INDSET}\): one triangle per clause, edges between complementary literals, and \(k\) the number of clauses.
\(\mathrm{CLIQUE}\) and \(\mathrm{VC}\) are \(\mathsf{NP}\)-complete.
\(\mathrm{INDSET} \le _p \mathrm{CLIQUE}\) by complementing the edge set, and \(\mathrm{INDSET} \le _p \mathrm{VC}\) by \(\langle G, k \rangle \mapsto \langle G, n - k \rangle \), since \(S\) is independent exactly when its complement is a cover.
4.8 Noncommutative rational hitting lists
A rational formula has rational constants, \(n\) variables, addition, ordered multiplication, and inverse. Its size counts all syntax nodes. Evaluation at a tuple of rational matrices is partial: every inverse node requires a two-sided inverse of its operand. A formula is admissible if it has a defined evaluation in some positive matrix dimension, and nonzero if some such evaluation has a nonzero value.
An output is a finite list of matrix tuples with one common positive dimension. It hits size \(s\) if every admissible nonzero formula of size at most \(s\) has an invertible evaluation at a tuple in the list. The output encoding includes its dimension, list length, and every reduced rational entry. The generation contract counts ordinary Mathlib \(\mathrm{TM0}\) transitions from the two unary parameters \(n,s\), separated by a nonblank symbol, to the complete binary output at and right of the halted head.
OpenAI’s generator produces a hitting list for every \(s\geq 1\) and \(n\geq 1\). Its common dimension is at most \(256(n+s+1)^{10}\), its full binary output length is polynomial, and one fixed finite-state \(\mathrm{TM0}\) machine generates the list within a fixed polynomial number of transitions. The mathematical hitting and dimension bounds also hold for \(n=0\).
Adapt the 53-module solution closure of OpenAI’s rational hitting-list formalization. The proof passes through affine realizations, rank expansion, cyclotomic specialization, exact integer determinants, binary arithmetic, and a finite-stack-to-tape compiler. The runtime theorem here uses the source machine model; the following bridge transfers its exact encoding to the library’s canonical \(\mathsf{FP}\) model.
The input is \(\mathtt{true}^n\mathtt{false}\mathtt{true}^s\) with \(n,s\geq 1\). A five-state DFA validates this format. The total generator returns the complete binary encoding of the corresponding hitting list on valid inputs, and the empty string on all malformed strings.
The total hitting-list generator belongs to canonical \(\mathsf{FP}\). Its output on every positive unary parameter pair is exactly the source’s complete reduced-rational binary encoding; all other inputs produce empty output. This is a generation theorem, with no assertion about polynomial bit complexity for evaluating formulas on the resulting list.
Prove the five-state validator accepts precisely the two nonempty unary blocks and their separator. Parsing recovers the original parameters, and the input length is exactly \(n+s+1\). Bundle the source machine with its literal binary codec, apply its polynomial runtime and full output length bounds, and use the regular-domain guard theorem.
The inverse formula \(f^{-1}\) is admissible if and only if \(f\) is nonzero. Every admissible formula \(f\) in \(n\) variables has a defined evaluation in some dimension \(0{\lt}d\leq 256(n+|f|+3)^{10}\).
A defined inverse supplies a nonzero operand in positive matrix dimension. Conversely, an invertible hit for \(f\) supplies a defined inverse. For the dimension bound, use the list for size \(|f|+2\): either \(f\) or \(f+1\) has a nonzero evaluation, so a hit for one supplies a defined evaluation of \(f\) in the list’s polynomially bounded common dimension.
Evaluate exactly over rational matrices, rejecting singular inverse operands. On a list, the admissibility test searches for any defined value, and the nonzeroness test searches for a value with nonzero determinant. For a formula \(f\), use the generated list for size \(|f|+2\) for both tests.
The executable evaluator returns exactly the relationally defined values. A hitting list for size \(s\) detects nonzeroness of every formula of size at most \(s\). A hitting list for size \(s+2\) also detects admissibility of every such formula, even when it is identically zero. Consequently the two generated tests are total and correct, without an admissibility promise. No polynomial bit-time bound for these evaluation tests is asserted here.
At a defined point either \(f\) is nonzero or \(f+1\) is nonzero, and the latter has only two more syntax nodes. An invertible hit for either formula supplies a defined evaluation of \(f\). Conversely, every list tuple has positive dimension, so an invertible value is nonzero. The evaluator’s inverse branch uses the adjugate divided by the determinant; soundness and completeness follow by induction on syntax and on the evaluation relation.
4.9 Open directions
One refactor does not fit as a node.
Re-proving bespoke machines through Cobham. The \(\mathrm{SAT}\) verifier behind Theorem 159 and the older \(\mathrm{SAT}\)-specialized guess-and-verify machine take roughly 10.5 thousand lines, the Cook–Levin emitter and its assembly about 6.8 thousand, and the Tseitin transducer of Lemma 163 about 5 thousand. With the loops of Lemma 136 and the streaming folds of Lemma 141, each should become a short Cobham program plus a correctness proof about ordinary Lean functions, as already done for the Sipser–Lautemann matrix verdict.