Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Cook p. 5: Satisfiability is in NP\mathbf{NP}NP

Open
PvsNP.sat_mem_NP

by korbonits · Sep 8, 2026 · Mathlib 0df444a (Lean v4.33.1)

complexity-theorymillennium-prizenp-completenessp-vs-nppolynomial-timesatisfiabilityturing-machines

Cook (p. 5): "Thus the problem Satisfiability is: Given a propositional formula FFF, determine whether FFF is satisfiable. To show that this is in NP\mathbf{NP}NP, we define the polynomial-time checking relation R(x,y)R(x,y)R(x,y), which holds iff xxx codes a propositional formula FFF and yyy codes a truth assignment to the variables of FFF that makes FFF true."

SAT∈NP\mathrm{SAT} \in \mathbf{NP}SAT∈NP: there are k∈Nk \in \mathbb{N}k∈N and a polynomial-time checking relation RRR such that, for every binary string www, www is the code of a satisfiable CNF formula if and only if there is a string yyy with ∣y∣≤∣w∣k|y| \le |w|^k∣y∣≤∣w∣k and R(w,y)R(w,y)R(w,y). Here SAT\mathrm{SAT}SAT is the set of strings www of the form encodeCNF F for a CNF formula FFF that is true under some truth assignment.

Formalization Note The certificate coding is the prover's choice: for instance the truth values of the variables occurring in FFF, of which there are at most ∣w∣/4|w|/4∣w∣/4, so k=1k = 1k=1 works. The checker must be an explicit multi-stack machine that parses the two-bit block coding of the formula, rejects malformed strings, and evaluates the formula under the certificate within a polynomial number of steps; no such machine-building infrastructure exists in Mathlib.

Preamble
import Definitions.Def_PvsNP
import Mathlib
Formal statement
namespace PvsNP
theorem sat_mem_NP : SAT ∈ NP := by sorry
end PvsNP
Source
S. Cook, The P versus NP problem, Clay Mathematics Institute Millennium Prize Problem description (2000), https://www.claymath.org/wp-content/uploads/2022/06/pvsnp.pdf, p. 5, paragraph 'In practice, a member of NP is expressed as a decision problem ...', definition of the checking relation R(x, y) for Satisfiability
Read-back

What the Lean code literally says, in plain math · claude-fable-5-1

Read-back: PvsNP.sat_mem_NP

Statement. The theorem has no hypotheses and no free variables. It asserts a single membership fact:

SAT∈NP,\mathrm{SAT} \in \mathrm{NP},SAT∈NP,

where both sides are the bundle's own definitions, unfolded below. Throughout, a string means a finite list of Booleans (elements of {false,true}\{\mathsf{false},\mathsf{true}\}{false,true}, written 000 and 111 below), ∣w∣|w|∣w∣ is the length of a string www, and a language is a set of strings.


What SAT\mathrm{SAT}SAT is

SAT\mathrm{SAT}SAT is the set of strings www for which there exists a "CNF" FFF with enc⁡(F)=w\operatorname{enc}(F) = wenc(F)=w and FFF satisfiable, where:

  • A literal is a pair (b,i)(b, i)(b,i) with bbb a Boolean and i∈Ni \in \mathbb{N}i∈N (any natural number, including 000). A clause is a finite list of literals (possibly empty, possibly with repetitions, in a fixed order). A CNF is a finite list of clauses (possibly empty, possibly with repetitions).
  • An assignment is an arbitrary function τ:N→{false,true}\tau : \mathbb{N} \to \{\mathsf{false},\mathsf{true}\}τ:N→{false,true} (no finiteness or finite-support condition).
  • The literal (b,i)(b,i)(b,i) evaluates under τ\tauτ to τ(i)\tau(i)τ(i) if b=trueb = \mathsf{true}b=true and to ¬τ(i)\lnot\tau(i)¬τ(i) if b=falseb = \mathsf{false}b=false.
  • A clause evaluates to true\mathsf{true}true iff some literal in it evaluates to true\mathsf{true}true; in particular the empty clause evaluates to false\mathsf{false}false.
  • A CNF evaluates to true\mathsf{true}true iff every clause in it evaluates to true\mathsf{true}true; in particular the empty CNF evaluates to true\mathsf{true}true.
  • FFF is satisfiable iff there exists an assignment τ\tauτ under which FFF evaluates to true\mathsf{true}true. So the empty CNF is satisfiable, and any CNF containing an empty clause is not.

The string coding enc⁡\operatorname{enc}enc. Write bits⁡(i)\operatorname{bits}(i)bits(i) for the list of binary digits of iii with the least significant digit first and no leading zeros: bits⁡(0)\operatorname{bits}(0)bits(0) is the empty list, bits⁡(1)=[1]\operatorname{bits}(1) = [1]bits(1)=[1], bits⁡(2)=[0,1]\operatorname{bits}(2) = [0,1]bits(2)=[0,1], bits⁡(5)=[1,0,1]\operatorname{bits}(5) = [1,0,1]bits(5)=[1,0,1], and for i>0i>0i>0 the last entry is always 111. Then:

  • A literal (b,i)(b,i)(b,i) is encoded by taking the list b::bits⁡(i)b :: \operatorname{bits}(i)b::bits(i) (polarity bit first, then the digits of iii), replacing each entry ccc by the two-symbol block 0 c0\,c0c, and appending the block 1 01\,010:
enc⁡(b,i)  =  0 b    0 c0    0 c1⋯0 cm−1    1 0,bits⁡(i)=[c0,…,cm−1].\operatorname{enc}(b,i) \;=\; 0\,b\;\; 0\,c_0\;\; 0\,c_1 \cdots 0\,c_{m-1}\;\; 1\,0, \qquad \operatorname{bits}(i) = [c_0,\dots,c_{m-1}].enc(b,i)=0b0c0​0c1​⋯0cm−1​10,bits(i)=[c0​,…,cm−1​].

For example enc⁡(true,0)=0 1 1 0\operatorname{enc}(\mathsf{true},0) = 0\,1\,1\,0enc(true,0)=0110 and enc⁡(false,2)=0 0  0 0  0 1  1 0\operatorname{enc}(\mathsf{false},2) = 0\,0\;0\,0\;0\,1\;1\,0enc(false,2)=00000110.

  • A clause [ℓ1,…,ℓr][\ell_1,\dots,\ell_r][ℓ1​,…,ℓr​] is encoded as the concatenation enc⁡(ℓ1)⋯enc⁡(ℓr)\operatorname{enc}(\ell_1)\cdots\operatorname{enc}(\ell_r)enc(ℓ1​)⋯enc(ℓr​) followed by the block 1 11\,111. The empty clause is encoded as 1 11\,111.
  • A CNF [C1,…,Cs][C_1,\dots,C_s][C1​,…,Cs​] is encoded as the concatenation enc⁡(C1)⋯enc⁡(Cs)\operatorname{enc}(C_1)\cdots\operatorname{enc}(C_s)enc(C1​)⋯enc(Cs​) with no terminator. The empty CNF is encoded as the empty string.

Consequently a string is in SAT\mathrm{SAT}SAT only if it is literally of the form enc⁡(F)\operatorname{enc}(F)enc(F) for some CNF FFF (in particular, it has even length and decomposes into the two-symbol blocks above); the empty string is in SAT\mathrm{SAT}SAT (via the empty CNF); and 1 11\,111 is not in SAT\mathrm{SAT}SAT (its only decoding is the CNF consisting of one empty clause).


What NP\mathrm{NP}NP is

A language LLL belongs to NP\mathrm{NP}NP iff there exist a function RRR from pairs of strings to Booleans and a natural number kkk (possibly k=0k = 0k=0) such that

  1. RRR is a polynomial-time checker in the sense unfolded below, and
  2. for every string www:
w∈L  ⟺  ∃ y a string with ∣y∣≤∣w∣k and R(w,y)=true.w \in L \iff \exists\, y \text{ a string with } |y| \le |w|^{k} \text{ and } R(w,y) = \mathsf{true}.w∈L⟺∃y a string with ∣y∣≤∣w∣k and R(w,y)=true.

Edge cases of item 2: if k=0k = 0k=0 then ∣w∣0=1|w|^0 = 1∣w∣0=1 for every www (including www empty, since 00=10^0 = 100=1), so certificates have length at most 111; if k≥1k \ge 1k≥1 and www is the empty string, the only admissible certificate is the empty string. RRR is a total function and must be computed by the machine on all pairs (w,y)(w,y)(w,y), not only those with ∣y∣≤∣w∣k|y|\le|w|^k∣y∣≤∣w∣k.

Polynomial-time checker. "RRR is a polynomial-time checker" means: there exists (as a mere existence statement) a package consisting of

  • a finite stack machine MMM of the following kind (Mathlib's bundled "TM2"): a finite index set KKK of stacks with decidable equality; two distinguished indices k0k_0k0​ (input stack) and k1k_1k1​ (output stack), which are allowed to coincide; for each k∈Kk \in Kk∈K a type Γk\Gamma_kΓk​ of stack symbols, where only Γk0\Gamma_{k_0}Γk0​​ is required to be finite (the other Γk\Gamma_kΓk​ are arbitrary types); a finite set Λ\LambdaΛ of labels with a distinguished label main\mathrm{main}main; a finite set Σ\SigmaΣ of internal states with a distinguished initial state s0s_0s0​; and a program assigning to each label a statement. A statement is a finite tree built from: push onto stack kkk a symbol computed from the current internal state; peek at the top of stack kkk (if any) and update the internal state by an arbitrary function of the state and that optional symbol; pop the top of stack kkk with the same kind of state update; replace the internal state by an arbitrary function of itself; branch on a Boolean function of the state; jump to a label computed from the state; or halt.
  • a bijection between Γk0\Gamma_{k_0}Γk0​​ and the four-element set {false,true}⊔{false,true}\{\mathsf{false},\mathsf{true}\} \sqcup \{\mathsf{false},\mathsf{true}\}{false,true}⊔{false,true}, and a bijection between Γk1\Gamma_{k_1}Γk1​​ and {false,true}\{\mathsf{false},\mathsf{true}\}{false,true};
  • a polynomial ppp with natural-number coefficients;

such that for every pair of strings (w,y)(w,y)(w,y) the following holds. Let the input word be

encodePair⁡(w,y)  =  [inl(w1),…,inl(w∣w∣), inr(y1),…,inr(y∣y∣)],\operatorname{encodePair}(w,y) \;=\; [\mathrm{inl}(w_1),\dots,\mathrm{inl}(w_{|w|}),\ \mathrm{inr}(y_1),\dots,\mathrm{inr}(y_{|y|})],encodePair(w,y)=[inl(w1​),…,inl(w∣w∣​), inr(y1​),…,inr(y∣y∣​)],

a word over the four-letter alphabet (letters of www tagged "left", letters of yyy tagged "right"), of length ∣w∣+∣y∣|w|+|y|∣w∣+∣y∣; transport it letter-by-letter through the inverse input bijection to obtain a list over Γk0\Gamma_{k_0}Γk0​​. The initial configuration has current label main\mathrm{main}main, internal state s0s_0s0​, stack k0k_0k0​ equal to this list (first letter of the input on top), and every other stack empty. The final configuration has no current label (halted), internal state equal to s0s_0s0​, stack k1k_1k1​ equal to the one-element list containing the preimage of R(w,y)R(w,y)R(w,y) under the output bijection, and every other stack empty. One step of the machine executes the entire statement attached to the current label (all of its pushes/pops/peeks/loads/branches, up to the jump or halt) and either moves to the new label or halts; a halted configuration has no successor. The requirement is that there is a number ttt of steps with

t  ≤  p(∣w∣+∣y∣)t \;\le\; p\big(|w| + |y|\big)t≤p(∣w∣+∣y∣)

such that iterating the step function exactly ttt times from the initial configuration yields exactly the final configuration described (so the machine halts at step ttt, not earlier and not later, in that exact configuration).


The assertion, assembled

The theorem asserts that there exist a Boolean-valued function RRR on pairs of strings, a natural number kkk, and a stack machine MMM with input/output bijections and a natural-coefficient polynomial ppp as above, such that MMM started on encodePair⁡(w,y)\operatorname{encodePair}(w,y)encodePair(w,y) halts in at most p(∣w∣+∣y∣)p(|w|+|y|)p(∣w∣+∣y∣) steps in the exact configuration encoding R(w,y)R(w,y)R(w,y) (for all w,yw, yw,y), and such that for every string www,

(∃F a CNF, enc⁡(F)=w ∧ ∃τ:N→{false,true}, F evaluates to true under τ)    ⟺    (∃y, ∣y∣≤∣w∣k ∧ R(w,y)=true).\big(\exists F \text{ a CNF},\ \operatorname{enc}(F) = w \ \wedge\ \exists \tau : \mathbb{N}\to\{\mathsf{false},\mathsf{true}\},\ F \text{ evaluates to } \mathsf{true} \text{ under } \tau\big) \;\iff\; \big(\exists y,\ |y| \le |w|^k \ \wedge\ R(w,y) = \mathsf{true}\big).(∃F a CNF, enc(F)=w ∧ ∃τ:N→{false,true}, F evaluates to true under τ)⟺(∃y, ∣y∣≤∣w∣k ∧ R(w,y)=true).

Nothing is asserted about P\mathrm{P}P, about NP-completeness, about 333-SAT, or about how RRR, kkk, MMM or ppp are chosen; only their existence.

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me