| 1 | import PvsNP.Complexity.Completeness |
| 2 | |
| 3 | /-! |
| 4 | # The P versus NP problem — OPEN |
| 5 | |
| 6 | This file **states** the P versus NP problem. It does not solve it, and nothing in this repository |
| 7 | claims to. `PNeNP` is a definition (a `Prop`), not a theorem; no axiom here assumes it or its |
| 8 | negation. `#print axioms` on any theorem of the project lists at most Lean's standard axioms |
| 9 | (`propext`, `Classical.choice`, `Quot.sound`). |
| 10 | |
| 11 | The problem is posed over the binary alphabet `Bool`, as usual. Over any finite alphabet with at least |
| 12 | two symbols the answer is the same, but that equivalence is not proved here. |
| 13 | |
| 14 | What *is* proved below: P = NP is the same as "P and NP have the same languages" (one inclusion is |
| 15 | P ⊆ NP), and for any NP-complete language `L`, P ≠ NP is the same as `L ∉ P`. |
| 16 | -/ |
| 17 | |
| 18 | namespace PvsNP |
| 19 | |
| 20 | |
| 21 | def PEqNP : Prop := ∀ L : Language Bool, InNP L → InP L |
| 22 | |
| 23 | |
| 24 | def PNeNP : Prop := ¬ PEqNP |
| 25 | |
| 26 | |
| 27 | theorem pEqNP_iff : PEqNP ↔ ∀ L : Language Bool, InP L ↔ InNP L := |
| 28 | ⟨fun h L => ⟨InP.inNP, h L⟩, fun h L hL => (h L).mpr hL⟩ |
| 29 | |
| 30 | |
| 31 | theorem pNeNP_iff : PNeNP ↔ ∃ L : Language Bool, InNP L ∧ ¬ InP L := by |
| 32 | unfold PNeNP PEqNP |
| 33 | constructor |
| 34 | · intro h |
| 35 | apply Classical.byContradiction |
| 36 | intro hne |
| 37 | exact h fun L hL => Classical.byContradiction fun hP => hne ⟨L, hL, hP⟩ |
| 38 | · intro ⟨L, hL, hP⟩ h |
| 39 | exact hP (h L hL) |
| 40 | |
| 41 | |
| 42 | theorem NPComplete.inP_iff_pEqNP {L : Language Bool} (hL : NPComplete L) : InP L ↔ PEqNP := |
| 43 | hL.inP_iff |
| 44 | |
| 45 | |
| 46 | theorem NPComplete.pNeNP_iff {L : Language Bool} (hL : NPComplete L) : PNeNP ↔ ¬ InP L := |
| 47 | not_congr hL.inP_iff_pEqNP.symm |
| 48 | |
| 49 | end PvsNP |