Define NP-hardness and NP-completeness

5775f68aClaude · 6d agoparent 9a243160files
NPHard L: every NP language reduces to L. NPComplete L: in NP and
NP-hard. Proved: hardness passes up along reductions, an NP-hard language
in P puts all of NP in P, an NP-complete language is in P exactly when
all of NP is, and NP-complete languages reduce to each other.

No concrete language is shown NP-complete yet (Cook–Levin is on the
roadmap).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Diff

2 files changed +55 -0
M PvsNP.lean +1 -0
@@ -9,6 +9,7 @@
99 import PvsNP.Complexity.P
1010 import PvsNP.Complexity.Reduction
1111 import PvsNP.Complexity.NP
12+import PvsNP.Complexity.Completeness
1213
1314 /-! # P versus NP in Lean 4
1415
@@ -0,0 +1,54 @@
1+import PvsNP.Complexity.NP
2+
3+/-!
4+# NP-hardness and NP-completeness
5+
6+`NPHard L`: every language in NP reduces to `L`. `NPComplete L`: `L` is in NP and NP-hard.
7+
8+Proved here: hardness passes up along reductions, and an NP-hard language in P puts all of NP in P.
9+No concrete NP-complete language is proved to be one yet: that is the Cook–Levin theorem, on the
10+roadmap.
11+-/
12+
13+namespace PvsNP
14+
15+variable {α : Type}
16+
17+/-- Every NP language reduces to `L`. -/
18+def NPHard (L : Language α) : Prop := ∀ L' : Language α, InNP L' → L' ≤ₚ L
19+
20+/-- `L` is in NP and NP-hard. -/
21+def NPComplete (L : Language α) : Prop := InNP L ∧ NPHard L
22+
23+namespace NPHard
24+
25+/-- If `L` is NP-hard and `L ≤ₚ L'`, then `L'` is NP-hard. -/
26+theorem of_reduces {L L' : Language α} (hL : NPHard L) (h : L ≤ₚ L') : NPHard L' :=
27+ fun L'' hL'' => (hL L'' hL'').trans h
28+
29+/-- An NP-hard language in P puts every NP language in P. -/
30+theorem all_inP {L : Language α} (hL : NPHard L) (hP : InP L) :
31+ ∀ L' : Language α, InNP L' → InP L' :=
32+ fun L' hL' => InP.of_reduces (hL L' hL') hP
33+
34+end NPHard
35+
36+namespace NPComplete
37+
38+/-- If `L` is NP-complete, `L ≤ₚ L'` and `L' ∈ NP`, then `L'` is NP-complete. -/
39+theorem of_reduces {L L' : Language α} (hL : NPComplete L) (h : L ≤ₚ L') (hL' : InNP L') :
40+ NPComplete L' :=
41+ ⟨hL', hL.2.of_reduces h⟩
42+
43+/-- An NP-complete language is in P exactly when all of NP is. -/
44+theorem inP_iff {L : Language α} (hL : NPComplete L) :
45+ InP L ↔ ∀ L' : Language α, InNP L' → InP L' :=
46+ ⟨hL.2.all_inP, fun h => h L hL.1⟩
47+
48+/-- Any two NP-complete languages reduce to each other. -/
49+theorem reduces {L L' : Language α} (hL : NPComplete L) (hL' : NPComplete L') : L ≤ₚ L' :=
50+ hL'.2 L hL.1
51+
52+end NPComplete
53+
54+end PvsNP