{"ok":true,"data":{"commit":"4186ab2739015c0efa3783c76b4987259c8e34b7","path":"PvsNP/Complexity/Completeness.lean","oid":"e2950ed6cdb2562731bc2972e022c27139c124f1","size":1757,"range_start":0,"range_end":1757,"truncated":false,"binary":false,"encoding":"utf8","content":"import PvsNP.Complexity.NP\n\n/-!\n# NP-hardness and NP-completeness\n\n`NPHard L`: every language in NP reduces to `L`. `NPComplete L`: `L` is in NP and NP-hard.\n\nProved here: hardness passes up along reductions, and an NP-hard language in P puts all of NP in P.\nNo concrete NP-complete language is proved to be one yet: that is the Cook–Levin theorem, on the\nroadmap.\n-/\n\nnamespace PvsNP\n\nvariable {α : Type}\n\n/-- Every NP language reduces to `L`. -/\ndef NPHard (L : Language α) : Prop := ∀ L' : Language α, InNP L' → L' ≤ₚ L\n\n/-- `L` is in NP and NP-hard. -/\ndef NPComplete (L : Language α) : Prop := InNP L ∧ NPHard L\n\nnamespace NPHard\n\n/-- If `L` is NP-hard and `L ≤ₚ L'`, then `L'` is NP-hard. -/\ntheorem of_reduces {L L' : Language α} (hL : NPHard L) (h : L ≤ₚ L') : NPHard L' :=\n  fun L'' hL'' => (hL L'' hL'').trans h\n\n/-- An NP-hard language in P puts every NP language in P. -/\ntheorem all_inP {L : Language α} (hL : NPHard L) (hP : InP L) :\n    ∀ L' : Language α, InNP L' → InP L' :=\n  fun L' hL' => InP.of_reduces (hL L' hL') hP\n\nend NPHard\n\nnamespace NPComplete\n\n/-- If `L` is NP-complete, `L ≤ₚ L'` and `L' ∈ NP`, then `L'` is NP-complete. -/\ntheorem of_reduces {L L' : Language α} (hL : NPComplete L) (h : L ≤ₚ L') (hL' : InNP L') :\n    NPComplete L' :=\n  ⟨hL', hL.2.of_reduces h⟩\n\n/-- An NP-complete language is in P exactly when all of NP is. -/\ntheorem inP_iff {L : Language α} (hL : NPComplete L) :\n    InP L ↔ ∀ L' : Language α, InNP L' → InP L' :=\n  ⟨hL.2.all_inP, fun h => h L hL.1⟩\n\n/-- Any two NP-complete languages reduce to each other. -/\ntheorem reduces {L L' : Language α} (hL : NPComplete L) (hL' : NPComplete L') : L ≤ₚ L' :=\n  hL'.2 L hL.1\n\nend NPComplete\n\nend PvsNP\n"},"meta":{"request_id":"1f2ea154-469","took_us":112,"limits":{"limit":600,"remaining":594,"window_ms":60000,"reset_ms":505,"cost":1,"streams":{"limit":16,"open":0}}}}