Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Cook Proposition 1(a): if L1≤pL2L_1 \le_p L_2L1​≤p​L2​ and L2∈PL_2 \in \mathbf{P}L2​∈P, then L1∈PL_1 \in \mathbf{P}L1​∈P

Proved
PvsNP.mem_P_of_pReducible

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

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

Cook, Proposition 1(a) (p. 4): "If L1≤pL2L_1 \le_p L_2L1​≤p​L2​ and L2∈PL_2 \in \mathbf{P}L2​∈P, then L1∈PL_1 \in \mathbf{P}L1​∈P."

For all languages L1,L2⊆{0,1}∗L_1, L_2 \subseteq \{0,1\}^*L1​,L2​⊆{0,1}∗: if there is a polynomial-time computable function f:{0,1}∗→{0,1}∗f : \{0,1\}^* \to \{0,1\}^*f:{0,1}∗→{0,1}∗ with x∈L1  ⟺  f(x)∈L2x \in L_1 \iff f(x) \in L_2x∈L1​⟺f(x)∈L2​ for all xxx (Cook's Definition 3), and L2L_2L2​ has a polynomial-time decision procedure, then L1L_1L1​ has one. Cook calls the proposition "easy to prove"; this part is the closure of P\mathbf{P}P under polynomial-time many-one reductions and is the analogue of "if L1≤mL2L_1 \le_m L_2L1​≤m​L2​ and L2L_2L2​ is decidable then L1L_1L1​ is decidable" from computability theory (p. 3).

Formalization Note The proof is the composition of the machine computing fff with the machine deciding L2L_2L2​, the polynomial bound coming from ∣f(x)∣≤p(∣x∣)|f(x)| \le p(|x|)∣f(x)∣≤p(∣x∣): this is exactly the polynomial-time composition of multi-stack machines that Mathlib records as proof_wanted TM2ComputableInPolyTime.comp. L1L_1L1​ and L2L_2L2​ are explicit universally quantified arguments.

Preamble
import Definitions.Def_PvsNP
import Mathlib
Formal statement
namespace PvsNP
theorem mem_P_of_pReducible (L₁ L₂ : Language Bool) (h : PReducible L₁ L₂) (h₂ : L₂ ∈ P) :
    L₁ ∈ P := 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. 4, Proposition 1, part (a), and the preceding Definition 3
Read-back

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

Read-back: PvsNP.mem_P_of_pReducible

Statement. For every pair of sets L1,L2L_1, L_2L1​,L2​ of finite Boolean strings (a "language over {true,false}\{\mathsf{true},\mathsf{false}\}{true,false}" is literally an arbitrary subset of the set Σ∗:=List(Bool)\Sigma^* := \mathrm{List}(\mathrm{Bool})Σ∗:=List(Bool) of finite lists of Booleans, the empty list included; no decidability, finiteness or other restriction is placed on L1L_1L1​ or L2L_2L2​, and either may be empty or all of Σ∗\Sigma^*Σ∗), if

  1. L1L_1L1​ is p-reducible to L2L_2L2​ in the sense spelled out below (hypothesis hhh), and
  2. L2L_2L2​ belongs to the class P\mathsf{P}P defined below (hypothesis h2h_2h2​),

then L1L_1L1​ belongs to P\mathsf{P}P. The theorem is a bare implication between these three membership/relational facts; it asserts nothing about the machine, polynomial, or decision function witnessing the conclusion beyond their existence.


Hypothesis hhh: "L1L_1L1​ is p-reducible to L2L_2L2​". There exists a total function f:Σ∗→Σ∗f : \Sigma^* \to \Sigma^*f:Σ∗→Σ∗ such that

  • fff is polynomial-time computable (unfolded below with input encoding ea=ide_a = \mathrm{id}ea​=id and output encoding eb=ide_b = \mathrm{id}eb​=id, i.e. a string is fed to and read from the machine as itself), and
  • for every string x∈Σ∗x \in \Sigma^*x∈Σ∗:   x∈L1  ⟺  f(x)∈L2\; x \in L_1 \iff f(x) \in L_2x∈L1​⟺f(x)∈L2​ (a biconditional, for all strings, including the empty string).

Hypothesis h2h_2h2​: "L2∈PL_2 \in \mathsf{P}L2​∈P". There exists a total function χ:Σ∗→Bool\chi : \Sigma^* \to \mathrm{Bool}χ:Σ∗→Bool such that

  • χ\chiχ is polynomial-time computable in the sense unfolded below, with input encoding ea=ide_a = \mathrm{id}ea​=id and output encoding eb=encodeBoole_b = \mathrm{encodeBool}eb​=encodeBool, where encodeBool(b)=[b]\mathrm{encodeBool}(b) = [b]encodeBool(b)=[b] is the one-element list containing bbb; and
  • for every string w∈Σ∗w \in \Sigma^*w∈Σ∗:   w∈L2  ⟺  χ(w)=true\; w \in L_2 \iff \chi(w) = \mathsf{true}w∈L2​⟺χ(w)=true.

Conclusion: "L1∈PL_1 \in \mathsf{P}L1​∈P". There exists a total function χ′:Σ∗→Bool\chi' : \Sigma^* \to \mathrm{Bool}χ′:Σ∗→Bool that is polynomial-time computable (same sense, encodings id\mathrm{id}id and encodeBool\mathrm{encodeBool}encodeBool) with w∈L1  ⟺  χ′(w)=truew \in L_1 \iff \chi'(w) = \mathsf{true}w∈L1​⟺χ′(w)=true for all www.


The notion "ggg is polynomial-time computable with encodings ea,ebe_a, e_bea​,eb​" (used above with g=fg = fg=f, ea=eb=ide_a = e_b = \mathrm{id}ea​=eb​=id; and with g=χg = \chig=χ or χ′\chi'χ′, ea=ide_a = \mathrm{id}ea​=id, eb=encodeBoole_b = \mathrm{encodeBool}eb​=encodeBool). It is the mere existence (a proposition, "nonempty") of the following data:

  1. A bundled stack machine MMM (a finite "TM2" in Mathlib's sense), consisting of:
    • a finite type KKK of stack indices with decidable equality, and two designated indices k0k_0k0​ (input stack) and k1k_1k1​ (output stack) — k0=k1k_0 = k_1k0​=k1​ is allowed;
    • for each k∈Kk \in Kk∈K a type Γk\Gamma_kΓk​ of symbols that may be stored on stack kkk; only Γk0\Gamma_{k_0}Γk0​​ is required to be finite (the other Γk\Gamma_kΓk​ are arbitrary types, subject only to the alphabet bijections below for k1k_1k1​);
    • a finite type Λ\LambdaΛ of function labels with a designated label main\mathrm{main}main;
    • a finite type σ\sigmaσ of internal states with a designated initialState\mathrm{initialState}initialState;
    • a program mmm assigning to every label ℓ∈Λ\ell \in \Lambdaℓ∈Λ a statement m(ℓ)m(\ell)m(ℓ). Statements are finite trees built from: push onto stack kkk a symbol computed from the internal state; peek at the top of stack kkk (an optional symbol, absent if the stack is empty) and update the internal state; pop the top of stack kkk and update the internal state; load, i.e. apply a function σ→σ\sigma \to \sigmaσ→σ to the internal state; branch on a Boolean function of the internal state between two sub-statements; goto a label chosen as a function of the internal state; and halt. The functions inside statements (e.g. σ→Γk\sigma \to \Gamma_kσ→Γk​, σ→Λ\sigma \to \Lambdaσ→Λ) are arbitrary mathematical functions.
  2. Alphabet bijections ιin:Γk0≃Bool\iota_{\mathrm{in}} : \Gamma_{k_0} \simeq \mathrm{Bool}ιin​:Γk0​​≃Bool and ιout:Γk1≃Bool\iota_{\mathrm{out}} : \Gamma_{k_1} \simeq \mathrm{Bool}ιout​:Γk1​​≃Bool (in all three uses in this theorem both the input and output symbol types are in bijection with Bool\mathrm{Bool}Bool).
  3. A polynomial p∈N[X]p \in \mathbb{N}[X]p∈N[X] with natural-number coefficients (of any degree, constants included; p=0p = 0p=0 is a legal polynomial).
  4. A correctness-and-time proof: for every input aaa (here every a∈Σ∗a \in \Sigma^*a∈Σ∗), writing
in(a):=ιin−1 applied elementwise to ea(a),out(a):=ιout−1 applied elementwise to eb(g(a)),\mathrm{in}(a) := \iota_{\mathrm{in}}^{-1}\text{ applied elementwise to } e_a(a), \qquad \mathrm{out}(a) := \iota_{\mathrm{out}}^{-1}\text{ applied elementwise to } e_b(g(a)),in(a):=ιin−1​ applied elementwise to ea​(a),out(a):=ιout−1​ applied elementwise to eb​(g(a)),

the machine, started in the configuration

C0(a)=(label=main, state=initialState, stack k0=in(a), every other stack=[ ]),C_0(a) = \bigl(\text{label} = \mathrm{main},\ \text{state} = \mathrm{initialState},\ \text{stack } k_0 = \mathrm{in}(a),\ \text{every other stack} = [\,]\bigr),C0​(a)=(label=main, state=initialState, stack k0​=in(a), every other stack=[]),

reaches after exactly some number sss of steps the configuration

Chalt(a)=(label=none (halted), state=initialState, stack k1=out(a), every other stack=[ ]),C_{\mathrm{halt}}(a) = \bigl(\text{label} = \text{none (halted)},\ \text{state} = \mathrm{initialState},\ \text{stack } k_1 = \mathrm{out}(a),\ \text{every other stack} = [\,]\bigr),Chalt​(a)=(label=none (halted), state=initialState, stack k1​=out(a), every other stack=[]),

with

s  ≤  p(∣ea(a)∣),s \;\le\; p\bigl(|e_a(a)|\bigr),s≤p(∣ea​(a)∣),

where ∣ea(a)∣|e_a(a)|∣ea​(a)∣ is the length of the encoded input list (for ea=ide_a = \mathrm{id}ea​=id this is just the length ∣a∣|a|∣a∣ of the input string). More precisely, the requirement is that iterating the one-step transition sss times from C0(a)C_0(a)C0​(a) (in the option-valued sense where a halted configuration, whose label is "none", steps to "no configuration", which is then absorbing) yields precisely the configuration Chalt(a)C_{\mathrm{halt}}(a)Chalt​(a): same halted label, internal state equal to initialState\mathrm{initialState}initialState again, output stack equal to out(a)\mathrm{out}(a)out(a), and all other stacks empty (if k0=k1k_0 = k_1k0​=k1​, the single stack must hold out(a)\mathrm{out}(a)out(a)). The witness sss is a specific natural number depending on aaa, and since the target configuration is halted, it is exactly the number of steps at which the machine halts.

What one "step" is. From a configuration with current label ℓ\ellℓ, internal state vvv and stacks SSS, one step executes the entire statement m(ℓ)m(\ell)m(ℓ) — following pushes, peeks, pops, loads and branches in sequence — until it hits a goto\mathrm{goto}goto (yielding a new configuration with the chosen label) or a halt\mathrm{halt}halt (yielding a configuration with label "none"). Thus the time bound counts executed labelled function bodies, not individual stack operations. A configuration with label "none" has no successor.

Specialisations relevant to this theorem.

  • For the reduction fff (encodings id,id\mathrm{id}, \mathrm{id}id,id): the input stack initially holds ιin−1\iota_{\mathrm{in}}^{-1}ιin−1​ of the bits of xxx (in order), and at halting the output stack must hold ιout−1\iota_{\mathrm{out}}^{-1}ιout−1​ of the bits of f(x)f(x)f(x), within pf(∣x∣)p_f(|x|)pf​(∣x∣) steps.
  • For the deciders χ,χ′\chi, \chi'χ,χ′ (encodings id,encodeBool\mathrm{id}, \mathrm{encodeBool}id,encodeBool): at halting the output stack must consist of the single symbol ιout−1(χ(w))\iota_{\mathrm{out}}^{-1}(\chi(w))ιout−1​(χ(w)), within pχ(∣w∣)p_\chi(|w|)pχ​(∣w∣) steps.
  • In all cases the run must terminate for every string, including the empty string [ ][\,][] (for which the bound is p(0)p(0)p(0), the constant coefficient), and the internal state must be back at initialState\mathrm{initialState}initialState at halting.

Degenerate/edge observations (about what the quantifiers literally include). L1,L2L_1, L_2L1​,L2​ range over all subsets of Σ∗\Sigma^*Σ∗. The functions f,χf, \chif,χ are arbitrary total functions; only the existence of a machine as above certifies them. If p(∣a∣)=0p(|a|) = 0p(∣a∣)=0 for some aaa, the bound forces s=0s = 0s=0, which would require C0(a)=Chalt(a)C_0(a) = C_{\mathrm{halt}}(a)C0​(a)=Chalt​(a), impossible since their labels differ (main\mathrm{main}main vs. none); so such a polynomial can never witness the property for that input. Polynomial-time computability is stated as a proposition (existence of the data), not as an explicit machine; hence the hypotheses and conclusion are all propositions, and the theorem provides no construction. Nothing in the statement relates the polynomial of fff, the polynomial of χ\chiχ, or the size ∣f(x)∣|f(x)|∣f(x)∣ of reduced strings to the polynomial of χ′\chi'χ′; the conclusion only demands that some polynomial and some machine for some χ′\chi'χ′ exist.

Human review
  • Endorsed by Shuze Chen · Sep 10, 2026

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