195 Complexity — NP
195.1 Overview
This module defines the class \(\mathsf{NP}\) following Arora–Barak Definition 2.1: a language over the binary alphabet is in \(\mathsf{NP}\) when membership is witnessed by certificates of length exactly \(C \cdot (|x|+1)^c\) whose concatenation with the input is accepted by a verifier language in \(\mathsf{P}\). It proves \(\mathsf{P} \subseteq \mathsf{NP}\) and shows (Arora–Barak Exercise 2.1) that bounded-length certificates, paired with the input through a self-delimiting encoding, define the same class; the supporting material covers marker padding and stripping of certificates, the bounded search that recovers the input/certificate boundary, and polynomial-time deciders for the two converted verifier languages.
195.2 Declarations
A language \(L \subseteq \{ 0,1\} ^{*}\) belongs to the class \(\mathsf{NP}\) if there exist natural numbers \(C\) and \(c\) and a verifier language \(V \in \mathsf{P}\) such that for every binary string \(x\), \(x \in L\) holds if and only if there is a certificate \(u \in \{ 0,1\} ^{*}\) of length exactly \(|u| = C \cdot (|x|+1)^c\) whose concatenation \(xu\) with \(x\) lies in \(V\).
Every language \(L \subseteq \{ 0,1\} ^{*}\) decidable in polynomial time belongs to \(\mathsf{NP}\); that is, for every \(L \in \mathsf{P}\) there exist \(C, c \in \mathbb {N}\) and a language \(V \in \mathsf{P}\) such that for every binary string \(x\), \(x \in L\) if and only if some \(u \in \{ 0,1\} ^{*}\) with \(|u| = C \cdot (|x|+1)^c\) has \(xu \in V\).
The partial map \(\mathrm{strip}\) on binary strings that deletes the last \(1\) together with the run of \(0\)s following it. It is defined recursively: \(\mathrm{strip}(\varepsilon )\) is undefined, and for a bit \(b\) and a string \(v\), \(\mathrm{strip}(bv) = b\, \mathrm{strip}(v)\) when \(\mathrm{strip}(v)\) is defined, while if \(\mathrm{strip}(v)\) is undefined then \(\mathrm{strip}(1v) = \varepsilon \) and \(\mathrm{strip}(0v)\) is undefined. Thus \(\mathrm{strip}(v)\) is the prefix of \(v\) preceding its last \(1\), and is undefined when \(v\) contains no \(1\).
Let \(\mathrm{strip}\) be the partial map on binary strings defined by: \(\mathrm{strip}(\varepsilon )\) is undefined, and for a bit \(b\) and a string \(v\), \(\mathrm{strip}(bv) = b\, \mathrm{strip}(v)\) when \(\mathrm{strip}(v)\) is defined, while otherwise \(\mathrm{strip}(1v) = \varepsilon \) and \(\mathrm{strip}(0v)\) is undefined. Then for every \(k \in \mathbb {N}\), \(\mathrm{strip}(0^k)\) is undefined.
Let \(\mathrm{strip}\) be the partial map on binary strings defined by: \(\mathrm{strip}(\varepsilon )\) is undefined, and for a bit \(b\) and a string \(v\), \(\mathrm{strip}(bv) = b\, \mathrm{strip}(v)\) when \(\mathrm{strip}(v)\) is defined, while otherwise \(\mathrm{strip}(1v) = \varepsilon \) and \(\mathrm{strip}(0v)\) is undefined. Then for every binary string \(u\) (possibly empty, possibly containing \(1\)s) and every \(k \in \mathbb {N}\), \(\mathrm{strip}(u\, 1\, 0^k) = u\).
Let \(\mathrm{strip}\) be the partial map on binary strings defined by: \(\mathrm{strip}(\varepsilon )\) is undefined, and for a bit \(b\) and a string \(v\), \(\mathrm{strip}(bv) = b\, \mathrm{strip}(v)\) when \(\mathrm{strip}(v)\) is defined, while otherwise \(\mathrm{strip}(1v) = \varepsilon \) and \(\mathrm{strip}(0v)\) is undefined. Then for every binary string \(v\): \(\mathrm{strip}(v)\) is undefined if and only if \(v = 0^{|v|}\) consists only of zeros; and for every binary string \(u\), \(\mathrm{strip}(v) = u\) if and only if \(v = u\, 1\, 0^k\) for some \(k \in \mathbb {N}\).
For all \(C, c \in \mathbb {N}\), the map \(\mathbb {N} \to \mathbb {N}\) given by \(n \mapsto n + (C+1)(n+1)^c\) is strictly increasing (also when \(c = 0\)).
For all \(C, c, n \in \mathbb {N}\),
For \(C, c, m \in \mathbb {N}\), the partial value \(\mathrm{split}_{C,c}(m)\) is the least \(n \in \{ 0, 1, \dots , m\} \) satisfying \(n + (C+1)(n+1)^c = m\), found by searching \(0, 1, \dots , m\) in increasing order; it is undefined when no such \(n\) exists.
For \(C, c, m \in \mathbb {N}\) let \(\mathrm{split}_{C,c}(m)\) be the least \(n \le m\) with \(n + (C+1)(n+1)^c = m\), and undefined if there is none. Then for all \(C, c, m, n \in \mathbb {N}\), \(\mathrm{split}_{C,c}(m) = n\) if and only if \(n + (C+1)(n+1)^c = m\).
For \(C, c, m \in \mathbb {N}\) let \(\mathrm{split}_{C,c}(m)\) be the least \(n \le m\) with \(n + (C+1)(n+1)^c = m\), and undefined if there is none. Then for all \(C, c \in \mathbb {N}\), \(\mathrm{split}_{C,c}(0)\) is undefined.
For \(C, c \in \mathbb {N}\) and a language \(V \subseteq \{ 0,1\} ^{*}\), the language \(V^{\mathrm{pair}}_{C,c}\) consists of the binary strings \(y\) that the aligned pair parser decodes as a pair \((x, u)\) — that is, \(y = \langle x, u\rangle \) is a well-formed self-delimiting pair encoding, consisting of \(x\) with every bit doubled, then the separator \(01\), then \(u\) verbatim — such that \(|u| = C(|x|+1)^c\) and the concatenation \(xu\) lies in \(V\).
Let \(C, c \in \mathbb {N}\) and \(V \subseteq \{ 0,1\} ^{*}\), write \(\langle x, u\rangle \) for the self-delimiting pair encoding of binary strings \(x\) and \(u\) (\(x\) with every bit doubled, then the separator \(01\), then \(u\)), and let \(V^{\mathrm{pair}}_{C,c}\) be the set of strings that the aligned pair parser decodes as a pair \((x, u)\) with \(|u| = C(|x|+1)^c\) and \(xu \in V\). Then for all binary strings \(x\) and \(u\), \(\langle x, u\rangle \in V^{\mathrm{pair}}_{C,c}\) if and only if \(|u| = C(|x|+1)^c\) and \(xu \in V\).
Let \(C, c \in \mathbb {N}\) and \(V \subseteq \{ 0,1\} ^{*}\). The aligned pair parser reads a binary string in two-bit blocks from the left, taking \(00\) and \(11\) as the bits \(0\) and \(1\) of a first component until the first block \(01\), after which the remaining suffix is the second component; it fails on every other string. Let \(V^{\mathrm{pair}}_{C,c}\) be the set of strings that this parser decodes as a pair \((x, u)\) with \(|u| = C(|x|+1)^c\) and \(xu \in V\). If \(y\) is a binary string on which the parser fails, then \(y \notin V^{\mathrm{pair}}_{C,c}\).
For \(C, c \in \mathbb {N}\) and a language \(V \subseteq \{ 0,1\} ^{*}\), the language \(V^{\mathrm{pad}}_{C,c}\) consists of the binary strings \(y\) for which there is a least \(n \le |y|\) with \(n + (C+1)(n+1)^c = |y|\), and, writing \(y = xv\) with \(|x| = n\), the suffix \(v\) contains a \(1\), the prefix \(u\) of \(v\) preceding its last \(1\) satisfies \(|u| \le C(n+1)^c\), and \(\langle x, u\rangle \in V\). Here \(\langle x, u\rangle \) is the self-delimiting pair encoding: \(x\) with every bit doubled, then the separator \(01\), then \(u\) verbatim.
Let \(C, c \in \mathbb {N}\) and \(V \subseteq \{ 0,1\} ^{*}\), and let \(V^{\mathrm{pad}}_{C,c}\) be the set of binary strings \(y\) such that, for the least \(n\) with \(n + (C+1)(n+1)^c = |y|\) (which must exist), the suffix \(v\) of \(y\) after its first \(n\) bits contains a \(1\), and the prefix \(u\) of \(v\) preceding its last \(1\) satisfies \(|u| \le C(n+1)^c\) and \(\langle x, u\rangle \in V\), where \(x\) is the first \(n\) bits of \(y\) and \(\langle x, u\rangle \) is the self-delimiting pair encoding (\(x\) with every bit doubled, then \(01\), then \(u\)). If \(y\) is a binary string such that no \(n \le |y|\) satisfies \(n + (C+1)(n+1)^c = |y|\), then \(y \notin V^{\mathrm{pad}}_{C,c}\).
Let \(C, c \in \mathbb {N}\) and \(V \subseteq \{ 0,1\} ^{*}\), and let \(V^{\mathrm{pad}}_{C,c}\) be the set of binary strings \(y\) such that, for the least \(n\) with \(n + (C+1)(n+1)^c = |y|\) (which must exist), the suffix \(v\) of \(y\) after its first \(n\) bits contains a \(1\), and the prefix \(u\) of \(v\) preceding its last \(1\) satisfies \(|u| \le C(n+1)^c\) and \(\langle x, u\rangle \in V\), where \(x\) is the first \(n\) bits of \(y\) and \(\langle x, u\rangle \) is the self-delimiting pair encoding (\(x\) with every bit doubled, then \(01\), then \(u\)). Then for all binary strings \(x\) and \(v\) with \(|v| = (C+1)(|x|+1)^c\), the concatenation \(xv\) lies in \(V^{\mathrm{pad}}_{C,c}\) if and only if \(v\) contains a \(1\) and the prefix \(u\) of \(v\) preceding its last \(1\) satisfies \(|u| \le C(|x|+1)^c\) and \(\langle x, u\rangle \in V\).
Let \(C, c \in \mathbb {N}\) and \(V \subseteq \{ 0,1\} ^{*}\), and let \(V^{\mathrm{pad}}_{C,c}\) be the set of binary strings \(y\) such that, for the least \(n\) with \(n + (C+1)(n+1)^c = |y|\) (which must exist), the suffix \(v\) of \(y\) after its first \(n\) bits contains a \(1\), and the prefix \(u\) of \(v\) preceding its last \(1\) satisfies \(|u| \le C(n+1)^c\) and \(\langle x, u\rangle \in V\), where \(x\) is the first \(n\) bits of \(y\) and \(\langle x, u\rangle \) is the self-delimiting pair encoding (\(x\) with every bit doubled, then \(01\), then \(u\)). Then for every binary string \(x\) (even one containing \(1\)s), the string \(x\, 0^{(C+1)(|x|+1)^c}\) does not lie in \(V^{\mathrm{pad}}_{C,c}\).
Let \(C, c \in \mathbb {N}\) and \(V \subseteq \{ 0,1\} ^{*}\), and let \(V^{\mathrm{pad}}_{C,c}\) be the set of binary strings \(y\) such that, for the least \(n\) with \(n + (C+1)(n+1)^c = |y|\) (which must exist), the suffix \(v\) of \(y\) after its first \(n\) bits contains a \(1\), and the prefix \(u\) of \(v\) preceding its last \(1\) satisfies \(|u| \le C(n+1)^c\) and \(\langle x, u\rangle \in V\), where \(x\) is the first \(n\) bits of \(y\) and \(\langle x, u\rangle \) is the self-delimiting pair encoding (\(x\) with every bit doubled, then \(01\), then \(u\)). Let \(x, u\) be binary strings and \(k \in \mathbb {N}\) with \(|u\, 1\, 0^k| = (C+1)(|x|+1)^c\) and \(C(|x|+1)^c \lt |u|\). Then \(x\, u\, 1\, 0^k \notin V^{\mathrm{pad}}_{C,c}\).
Let \(C, c \in \mathbb {N}\) and \(V \subseteq \{ 0,1\} ^{*}\), and let \(V^{\mathrm{pad}}_{C,c}\) be the set of binary strings \(y\) such that, for the least \(n\) with \(n + (C+1)(n+1)^c = |y|\) (which must exist), the suffix \(v\) of \(y\) after its first \(n\) bits contains a \(1\), and the prefix \(u\) of \(v\) preceding its last \(1\) satisfies \(|u| \le C(n+1)^c\) and \(\langle x, u\rangle \in V\), where \(x\) is the first \(n\) bits of \(y\) and \(\langle x, u\rangle \) is the self-delimiting pair encoding (\(x\) with every bit doubled, then \(01\), then \(u\)). Then for every binary string \(x\), there exists \(v\) with \(|v| = (C+1)(|x|+1)^c\) and \(xv \in V^{\mathrm{pad}}_{C,c}\) if and only if there exists \(u\) with \(|u| \le C(|x|+1)^c\) and \(\langle x, u\rangle \in V\).
The function on binary strings that sends \(z\) to the concatenation \(ab\) when the aligned pair parser decodes \(z\) as a pair \((a, b)\) — that is, when \(z = \langle a, b\rangle \) is a well-formed self-delimiting pair encoding (\(a\) with every bit doubled, then \(01\), then \(b\)) — and sends every other string to the empty string.
For \(D, e, m \in \mathbb {N}\) let \(\mathrm{solve}_{D,e}(m)\) be the least \(i \le m\) with \(i + D(i+1)^e = m\), undefined if there is none, and for \(C, c, m \in \mathbb {N}\) let \(\mathrm{split}_{C,c}(m)\) be the least \(n \le m\) with \(n + (C+1)(n+1)^c = m\), undefined if there is none. Then for all \(C, c \in \mathbb {N}\), the partial functions \(\mathrm{solve}_{C+1,c}\) and \(\mathrm{split}_{C,c}\) on \(\mathbb {N}\) are equal.
Let \(\mathrm{strip}\) be the partial map on binary strings defined by: \(\mathrm{strip}(\varepsilon )\) is undefined, and for a bit \(b\) and a string \(v\), \(\mathrm{strip}(bv) = b\, \mathrm{strip}(v)\) when \(\mathrm{strip}(v)\) is defined, while otherwise \(\mathrm{strip}(1v) = \varepsilon \) and \(\mathrm{strip}(0v)\) is undefined. Let \(\mathrm{last}(v)\) be computed by reversing \(v\), discarding the leading \(0\)s of the reversal, and, if a \(1\) remains, deleting it and returning the reversal of what follows it, while \(\mathrm{last}(v)\) is undefined if no \(1\) remains. Then \(\mathrm{last}\) and \(\mathrm{strip}\) are equal as partial maps on \(\{ 0,1\} ^{*}\).
For \(C, c \in \mathbb {N}\), the Boolean function \(\beta _{C,c}\) on binary strings that, on a string \(z\) which the aligned pair parser decodes as a pair \((a, b)\) — that is, \(z = \langle a, b\rangle \) is a well-formed self-delimiting pair encoding (\(a\) with every bit doubled, then \(01\), then \(b\)) — returns true exactly when \(|b| \le C(|a|+1)^c\), and returns false on every string that is not a well-formed pair encoding.
For \(C, c \in \mathbb {N}\) let \(\beta _{C,c}(z)\), for a binary string \(z\), be the bit \(1\) if \(z = \langle a, b\rangle \) is a well-formed self-delimiting pair encoding (\(a\) with every bit doubled, then \(01\), then \(b\)) with \(|b| \le C(|a|+1)^c\), and the bit \(0\) otherwise. Then for all \(C, c \in \mathbb {N}\) the map sending \(z\) to the one-bit string \(\beta _{C,c}(z)\) is polynomial-time computable: some finite multi-tape Turing machine over the binary alphabet computes it within \(D(n+1)^d\) steps on every input of length \(n\), for some constants \(D, d \in \mathbb {N}\).
Let \(V \subseteq \{ 0,1\} ^{*}\) be a language in \(\mathsf{P}\), and let \(\mathbf{1}_V(x)\) be the bit \(1\) if \(x \in V\) and \(0\) otherwise. Then the map sending a binary string \(x\) to the one-bit string \(\mathbf{1}_V(x)\) is polynomial-time computable: some finite multi-tape Turing machine over the binary alphabet computes it within \(D(n+1)^d\) steps on every input of length \(n\), for some constants \(D, d \in \mathbb {N}\).
Let \(V \subseteq \{ 0,1\} ^{*}\) be a language and let \(\mathbf{1}_V(x)\) be the bit \(1\) if \(x \in V\) and \(0\) otherwise. If the map sending a binary string \(x\) to the one-bit string \(\mathbf{1}_V(x)\) is polynomial-time computable, i.e. some finite multi-tape Turing machine over the binary alphabet computes it within \(D(n+1)^d\) steps on every input of length \(n\) for some constants \(D, d\), then \(V \in \mathsf{P}\).
For a binary string \(z\), let \(\pi _1(z)\) and \(\pi _2(z)\) be the two components \(a\) and \(b\) when \(z = \langle a, b\rangle \) is a well-formed self-delimiting pair encoding (\(a\) with every bit doubled, then \(01\), then \(b\)), and let both be the empty string otherwise. Then for all \(C, c \in \mathbb {N}\), the map sending \(z\) to the one-bit string recording whether \(C(|\pi _1(z)|+1)^c \le |\pi _2(z)|\) is polynomial-time computable: some finite multi-tape Turing machine over the binary alphabet computes it within \(D(n+1)^d\) steps on every input of length \(n\), for some constants \(D, d \in \mathbb {N}\).
Let \(C, c \in \mathbb {N}\) and let \(V \subseteq \{ 0,1\} ^{*}\) be a language in \(\mathsf{P}\). Then the language of binary strings \(y\) that are well-formed self-delimiting pair encodings \(y = \langle x, u\rangle \) (\(x\) with every bit doubled, then the separator \(01\), then \(u\) verbatim) with \(|u| = C(|x|+1)^c\) and \(xu \in V\) also belongs to \(\mathsf{P}\).
For \(C, c \in \mathbb {N}\), the function on binary strings that, given \(y\), finds the least \(n \le |y|\) with \(n + (C+1)(n+1)^c = |y|\); if such an \(n\) exists it outputs the self-delimiting pair encoding \(\langle x, v\rangle \) (\(x\) with every bit doubled, then \(01\), then \(v\)), where \(x\) is the first \(n\) bits of \(y\) and \(v\) the remaining bits, and otherwise it outputs the empty string.
The function on binary strings that, on a well-formed self-delimiting pair encoding \(z = \langle a, v\rangle \) (\(a\) with every bit doubled, then \(01\), then \(v\)) in which \(v\) contains a \(1\), outputs \(\langle a, u\rangle \), where \(u\) is the prefix of \(v\) preceding its last \(1\); on every other string (a malformed pair, or a pair whose second component has no \(1\)) it outputs the empty string.
Let \(C, c \in \mathbb {N}\) and let \(V \subseteq \{ 0,1\} ^{*}\) be a language in \(\mathsf{P}\). Consider the language \(V^{\mathrm{pad}}_{C,c}\) of binary strings \(y\) such that, for the least \(n\) with \(n + (C+1)(n+1)^c = |y|\) (which must exist), the suffix \(v\) of \(y\) after its first \(n\) bits contains a \(1\), and the prefix \(u\) of \(v\) preceding its last \(1\) satisfies \(|u| \le C(n+1)^c\) and \(\langle x, u\rangle \in V\), where \(x\) is the first \(n\) bits of \(y\) and \(\langle x, u\rangle \) is the self-delimiting pair encoding (\(x\) with every bit doubled, then \(01\), then \(u\)). Then \(V^{\mathrm{pad}}_{C,c} \in \mathsf{P}\).
For a language \(L \subseteq \{ 0,1\} ^{*}\), the following are equivalent: (i) \(L \in \mathsf{NP}\), i.e. there are \(C', c' \in \mathbb {N}\) and a language \(V' \in \mathsf{P}\) such that for every binary string \(x\), \(x \in L\) if and only if some \(u\) with \(|u| = C'(|x|+1)^{c'}\) has \(xu \in V'\); (ii) there are \(C, c \in \mathbb {N}\) and a language \(V \in \mathsf{P}\) such that for every binary string \(x\), \(x \in L\) if and only if some binary string \(u\) with \(|u| \le C(|x|+1)^c\) has \(\langle x, u\rangle \in V\), where \(\langle x, u\rangle \) is the self-delimiting pair encoding consisting of \(x\) with every bit doubled, then the separator \(01\), then \(u\) verbatim.