Complexitylib: a blueprint for computational complexity in Lean

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

Definition 95 \(\mathsf{DTIME}\)
✓
#

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\).

Definition 96 \(\mathsf{NTIME}\)
✓
#

\(\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\).

Definition 97 \(\mathsf{P}\)
✓
#

\(\mathsf{P} = \bigcup _{k} \mathsf{DTIME}(n^k)\).

Definition 98 \(\mathsf{NP}\)
✓
#

\(\mathsf{NP} = \bigcup _{k} \mathsf{NTIME}(n^k)\). This is the machine definition; the certificate form is Theorem 126 (one direction, formalized) and Theorem 127 (the other, planned).

Definition 99 \(\mathsf{coNP}\)
✓
#

\(\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).

Definition 100 \(\mathsf{FP}\)
✓
#

\(\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.

Definition 101 \(\mathsf{EXP}\) and \(\mathsf{NEXP}\)
✓
#

\(\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}\).

Proof ▶

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}\).

Proof ▶

\(\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.

Theorem 104 \(\mathsf{NP} \subseteq \mathsf{PSPACE}\)

\(\mathsf{NP} \subseteq \mathsf{PSPACE}\), and hence \(\mathsf{NP} \subseteq \mathsf{EXP}\).

Proof ▶

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 180. 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}\).

Proof ▶

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.

Proof ▶

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 106, 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}\), \(\mathsf{L}\), or \(\mathsf{FP}\).

Proof ▶

Theorem 106 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 108) concludes.

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 57).

\(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\).

Proof ▶

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)\).

Proof ▶

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.

Lemma 110 Identity and composition in \(\mathsf{FP}\)
✓

The identity function is in \(\mathsf{FP}\), and if \(f, g \in \mathsf{FP}\) then \(g \circ f \in \mathsf{FP}\).

Proof ▶

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\).

Proof ▶

Constants lie in Cobham’s algebra, so they are in \(\mathsf{FP}\) by the soundness half of Theorem 115. 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\).

Theorem 112 Closure under polynomial-time preimages
✓

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}\).

Proof ▶

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\).

Proof ▶

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 111.

4.3 Cobham’s theorem: FP as a programming language

Definition 114 Cobham’s function algebra
✓

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}\).

Proof ▶

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 117. 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.

Proof ▶

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)|\).

Proof ▶

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.

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 )\).

  1. 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}\).

  2. 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 \).

  3. 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}\).

  4. 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\).

  5. 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}\).

  6. 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}\).

Proof ▶

The concatenation is a loop by Lemma 117, 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.

Definition 119 Polynomial-time numbers and tests
✓
#

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 119, the following are polynomial-time, for polynomial-time numbers \(f, g, n, b, k, c\) and predicates \(p, q\).

  1. 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))\) and \(\max (f(z), g(z))\).

  2. 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}\).

  3. 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)\).

  4. \(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}\).

Proof ▶

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 118, 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 117 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 111. The last claim is Lemma 113.

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.

Let \(w, n, c\) be polynomial-time numbers in the sense of Definition 119, let \(s \in \mathsf{FP}\), and for a string \(x\) let \(v(x)\) be its value as a binary numeral, least significant bit first.

  1. 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\).

  2. \(\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\).

  3. 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\).

Proof ▶

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 120; the expansion of width \(w(z)\) is the bitwise description of Lemma 118, 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.

Lemma 122 Streaming folds in \(\mathsf{FP}\)

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.

Proof ▶

An instance of Lemma 117, 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

Definition 123 Pair language and balanced relations
✓

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|)\).

Definition 124 \(\mathsf{FNP}\) and \(\mathsf{TFNP}\)
✓
#

\(\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)\).

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}\).

Proof ▶

The guess-and-verify machine built for \(\mathrm{SAT}\) is generic: it guesses a string of length at most \(|x| + 1\), pairs it with the input, and runs the deterministic verifier, which handles linearly bounded witnesses (the two linear statements). 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 and the first linear one live in Classes/NP/Internal/GuessVerify.lean, the relational one in SAT/Internal/LinearGuessVerify.lean.

Theorem 126 \(\mathsf{FNP}\) witnesses give \(\mathsf{NP}\)
✓

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}\).

Proof ▶

The decider of \(\mathrm{pairLang}(R)\) is the verifier and the balance polynomial bounds the witnesses, so Lemma 125 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.

Theorem 127 \(\mathsf{NP}\) languages have polynomial-time verifiers

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 126, \(\mathsf{NP} = \{ L : \exists R \in \mathsf{FNP}\ \forall x\ (x \in L \iff \exists y\, R(x, y))\} \).

Proof ▶

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 113.

\(\mathsf{NP} = \Sigma ^p_1\) and \(\mathsf{coNP} = \Pi ^p_1\), for the certificate-quantifier levels of Definition 161.

Proof ▶

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 125 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 127. The \(\Pi ^p_1\) statement follows by complementation, using \(\Pi ^p_1 = \forall \mathsf{P}\) (Complexity.PiP_one).

Theorem 129 \(\mathsf{NP} \cap \mathsf{coNP}\) search is total
✓

\(\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).

Proof ▶

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 127.

4.5 Reductions and completeness

Definition 130 Polynomial-time many-one reduction
✓
#

\(L \le _p L'\) if there is \(f \in \mathsf{FP}\) with \(x \in L \iff f(x) \in L'\) for all \(x\).

Lemma 131 \(\le _p\) is a preorder
✓

\(L \le _p L\), and \(L_1 \le _p L_2 \le _p L_3\) implies \(L_1 \le _p L_3\).

Proof ▶

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}\).

Proof ▶

The same function reduces the complements, and \(L_1 = f^{-1}(L_2)\).

Definition 133 \(\mathsf{NP}\)-hard and \(\mathsf{NP}\)-complete
✓

\(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}\).

Lemma 134 Hardness transfers along reductions
✓

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.)

Proof ▶

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}\).

Proof ▶

Every \(\mathsf{NP}\) language pulls back into \(\mathsf{P}\) (respectively \(\mathsf{coNP}\)) along its reduction to \(L\).

Definition 136 \(\mathsf{coNP}\)-hard and \(\mathsf{coNP}\)-complete
✓

\(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).

Proof ▶

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

Definition 138 \(\mathrm{SAT}\)
✓

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}\).

Proof ▶

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, and a \(\mathrm{SAT}\)-specialized guess-and-verify machine turns it into a nondeterministic decider. That machine is the one Lemma 125 later reuses for arbitrary verifiers; the proof here does not go through the lemma.

\(\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}\).

Proof ▶

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 139.

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}\).

Proof ▶

Completeness dualizes under complement (Lemma 137), and Theorem 135 applies to \(\mathrm{SAT}\).

Definition 142 \(3\mathrm{SAT}\)
✓
#

\(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.

Proof ▶

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.

Proof ▶

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 125 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\).

Proof ▶

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 125 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.

Proof ▶

Membership by guess and verify with a formula evaluator; both reductions are streaming transducers, most easily written through Lemma 122.

Definition 147 Graph problems

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.

Theorem 148 \(\mathrm{INDSET}\) is \(\mathsf{NP}\)-complete

\(\mathrm{INDSET}\) is \(\mathsf{NP}\)-complete.

Proof ▶

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.

Theorem 149 \(\mathrm{CLIQUE}\) and \(\mathrm{VC}\) are \(\mathsf{NP}\)-complete

\(\mathrm{CLIQUE}\) and \(\mathrm{VC}\) are \(\mathsf{NP}\)-complete.

Proof ▶

\(\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 Open directions

Two refactors do not fit as nodes.

  • Re-proving bespoke machines through Cobham. The \(\mathrm{SAT}\) verifier and guess-and-verify machine behind Theorem 139 take roughly 10.5 thousand lines, the Cook–Levin emitter and its assembly about 6.8 thousand, and the Tseitin transducer of Lemma 143 about 5 thousand. With the loops of Lemma 118 and the streaming folds of Lemma 122, each should become a short Cobham program plus a correctness proof about ordinary Lean functions, as already done for the Sipser–Lautemann matrix verdict.

  • Surface placement. Lemma 125 (mem_NP_of_poly_witness and mem_NP_of_linear_witness) lives in Classes/NP/Internal and its relational linear form in SAT/Internal; these are general tools and belong in a surface module under Classes/NP, as Lemma 117 now has one in Classes/P/Iterate.