efdb9565 / PvsNP / Complexity / Completeness.lean

1import 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
8Proved here: hardness passes up along reductions, and an NP-hard language in P puts all of NP in P.
9No concrete NP-complete language is proved to be one yet: that is the Cook–Levin theorem, on the
10roadmap.
11-/
12
13namespace PvsNP
14
15variable {α : Type}
16
17/-- Every NP language reduces to `L`. -/
18def NPHard (L : Language α) : Prop := ∀ L' : Language α, InNP L' → L' ≤ₚ L
19
20/-- `L` is in NP and NP-hard. -/
21def NPComplete (L : Language α) : Prop := InNP L ∧ NPHard L
22
23namespace NPHard
24
25/-- If `L` is NP-hard and `L ≤ₚ L'`, then `L'` is NP-hard. -/
26theorem 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. -/
30theorem 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
34end NPHard
35
36namespace NPComplete
37
38/-- If `L` is NP-complete, `L ≤ₚ L'` and `L' ∈ NP`, then `L'` is NP-complete. -/
39theorem 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. -/
44theorem 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. -/
49theorem reduces {L L' : Language α} (hL : NPComplete L) (hL' : NPComplete L') : L ≤ₚ L' :=
50 hL'.2 L hL.1
51
52end NPComplete
53
54end PvsNP