# PvsNP/Complexity/Completeness.lean @ 5bdcd988ce31c5e20bc679e5aca17f88eaa6ccc7

````
import PvsNP.Complexity.NP

/-!
# NP-hardness and NP-completeness

`NPHard L`: every language in NP reduces to `L`. `NPComplete L`: `L` is in NP and NP-hard.

Proved here: hardness passes up along reductions, and an NP-hard language in P puts all of NP in P.
No concrete NP-complete language is proved to be one yet: that is the Cook–Levin theorem, on the
roadmap.
-/

namespace PvsNP

variable {α : Type}

/-- Every NP language reduces to `L`. -/
def NPHard (L : Language α) : Prop := ∀ L' : Language α, InNP L' → L' ≤ₚ L

/-- `L` is in NP and NP-hard. -/
def NPComplete (L : Language α) : Prop := InNP L ∧ NPHard L

namespace NPHard

/-- If `L` is NP-hard and `L ≤ₚ L'`, then `L'` is NP-hard. -/
theorem of_reduces {L L' : Language α} (hL : NPHard L) (h : L ≤ₚ L') : NPHard L' :=
  fun L'' hL'' => (hL L'' hL'').trans h

/-- An NP-hard language in P puts every NP language in P. -/
theorem all_inP {L : Language α} (hL : NPHard L) (hP : InP L) :
    ∀ L' : Language α, InNP L' → InP L' :=
  fun L' hL' => InP.of_reduces (hL L' hL') hP

end NPHard

namespace NPComplete

/-- If `L` is NP-complete, `L ≤ₚ L'` and `L' ∈ NP`, then `L'` is NP-complete. -/
theorem of_reduces {L L' : Language α} (hL : NPComplete L) (h : L ≤ₚ L') (hL' : InNP L') :
    NPComplete L' :=
  ⟨hL', hL.2.of_reduces h⟩

/-- An NP-complete language is in P exactly when all of NP is. -/
theorem inP_iff {L : Language α} (hL : NPComplete L) :
    InP L ↔ ∀ L' : Language α, InNP L' → InP L' :=
  ⟨hL.2.all_inP, fun h => h L hL.1⟩

/-- Any two NP-complete languages reduce to each other. -/
theorem reduces {L L' : Language α} (hL : NPComplete L) (hL' : NPComplete L') : L ≤ₚ L' :=
  hL'.2 L hL.1

end NPComplete

end PvsNP

````

API: `https://git.neoopensource.com/v1/repos/pvsnp/blob?rev=5bdcd988ce31c5e20bc679e5aca17f88eaa6ccc7&path=PvsNP%2FComplexity%2FCompleteness.lean`
