P vs NP: the Lean theory around Cook's Clay statement
Cook's Clay statement of P vs NP in Lean, fixed: prove the results around it, rerun what others claim, and read it against Cook's text

Merge pull request #65 from trial-ben-claude/p2-hierarchy-docstrings
Browse filesdocs(PVersusNP/PolynomialHierarchy): exact docstrings and three unfolding lemmas
Checks
build Program · lake build, no sorry
Details
challenge Program · statement files and build config
Details
+72 −38 Problems/PVersusNP/PolynomialHierarchy.lean View file
| @@ -48,20 +48,32 @@ open Computability | ||
| 48 | 48 | First, we define the complement of a language. |
| 49 | 49 | -/ |
| 50 | 50 | /-- |
| 51 | - The complement of a language L is the language consisting of | |
| 52 | - all the strings that are not in L. | |
| 51 | + The complement of a language: `complement L` is the language `fun a => ¬ L a`. | |
| 53 | 52 | |
| 54 | - For example, if SAT is the set of satisfiable Boolean formulas, | |
| 55 | - then co-SAT is the set of unsatisfiable Boolean formulas. | |
| 53 | + `Language α` is `α → Prop`, so this is the set-theoretic complement; the `Primcodable α` argument | |
| 54 | + is part of the signature only, and the definition does not use it. | |
| 55 | + | |
| 56 | + For example, if SAT is the set of satisfiable Boolean formulas, then co-SAT is the set of | |
| 57 | + unsatisfiable Boolean formulas. | |
| 56 | 58 | -/ |
| 57 | 59 | def complement {α : Type} [Primcodable α] (L : Language α) : Language α := |
| 58 | 60 | fun a => ¬(L a) |
| 59 | 61 | |
| 60 | 62 | /-- |
| 61 | -`Σₖᴾ` defined via polynomially-bounded alternating quantifiers (quantifier form). | |
| 62 | - | |
| 63 | -This is one standard characterization of the polynomial hierarchy; it avoids having to formalize | |
| 64 | -oracle machines inside the development. | |
| 63 | +`Σₖᴾ` in quantifier form, on a language `L : α → Prop` with a fixed encoding `ea : FinEncoding α` | |
| 64 | +and `α`'s `Primcodable` instance. | |
| 65 | + | |
| 66 | +- `k = 0`: `polynomial_hierarchy_sigma_level 0 ea L` is `InPolynomialTime ea L`. | |
| 67 | +- `k + 1`: there are a type `β` with `Fintype` and `Primcodable` instances, a language | |
| 68 | + `L' : Language (α × List β)`, the predicate `polynomial_hierarchy_sigma_level k e (complement L')` | |
| 69 | + with `e = pair_encoding ea (fin_encoding_string β)` — that is, `L'`'s *complement* is at `Σₖᴾ` — | |
| 70 | + and a polynomial `p : Polynomial ℕ` such that, for every `a`, | |
| 71 | + `L a ↔ ∃ b : List β, b.length ≤ Polynomial.eval (ea.encode a).length p ∧ L' (a, b)`. | |
| 72 | + | |
| 73 | +The witness `b` is a finite list over `β`, encoded by `fin_encoding_string β` (the identity encoding | |
| 74 | +on `List β`); the bound is `p` evaluated at the encoded input length `(ea.encode a).length`, and the | |
| 75 | +quantifier asks for *some* polynomial `p`, not for a bound that holds for all `p`. Level `0` carries | |
| 76 | +no witness and no bound. | |
| 65 | 77 | -/ |
| 66 | 78 | def polynomial_hierarchy_sigma_level (k : ℕ) : {α : Type} → [_inst : Primcodable α] → (ea : FinEncoding α) → Language α → Prop |
| 67 | 79 | | α, _inst, ea, L => |
| @@ -78,75 +90,97 @@ def polynomial_hierarchy_sigma_level (k : ℕ) : {α : Type} → [_inst : Primco | ||
| 78 | 90 | ∀ a, L a ↔ ∃ b : List β, b.length ≤ Polynomial.eval (ea.encode a).length p ∧ L' (a, b) |
| 79 | 91 | |
| 80 | 92 | /-- |
| 81 | -`Πₖᴾ` is defined as complements of `Σₖᴾ`. | |
| 93 | +`Πₖᴾ` is, by definition, `polynomial_hierarchy_sigma_level k ea (complement L)`: the witness alphabet, | |
| 94 | +the pair encoding `pair_encoding ea (fin_encoding_string β)` and the polynomial bound are exactly those | |
| 95 | +of `polynomial_hierarchy_sigma_level`, applied to the complement of `L`. | |
| 82 | 96 | -/ |
| 83 | 97 | def polynomial_hierarchy_pi_level (k : ℕ) : {α : Type} → [_inst : Primcodable α] → (ea : FinEncoding α) → Language α → Prop |
| 84 | 98 | | _α, _inst, ea, L => polynomial_hierarchy_sigma_level k ea (complement L) |
| 85 | 99 | |
| 86 | 100 | /-- |
| 87 | - Σ₀ᴾ = Π₀ᴾ = P | |
| 88 | - | |
| 89 | - The base level of the polynomial hierarchy is P, the class of | |
| 90 | - problems solvable in polynomial time. | |
| 101 | +`Σ₀ᴾ` at a fixed encoding `ea`: by definition this is `polynomial_hierarchy_sigma_level 0 ea`, which | |
| 102 | +is `InPolynomialTime ea`. No witness and no polynomial bound are introduced at this level. | |
| 91 | 103 | -/ |
| 92 | 104 | def polynomial_hierarchy_sigma_level_zero {α : Type} [Primcodable α] (ea : FinEncoding α) : Language α → Prop := |
| 93 | 105 | polynomial_hierarchy_sigma_level 0 ea |
| 94 | 106 | |
| 95 | -/-- `Π₀ᴾ = P` (since complements do not add power at level `0`). -/ | |
| 107 | +/-- `Π₀ᴾ` at a fixed encoding `ea`: by definition this is `polynomial_hierarchy_pi_level 0 ea`, which | |
| 108 | +is `InPolynomialTime ea (complement L)`. -/ | |
| 96 | 109 | def polynomial_hierarchy_pi_level_zero {α : Type} [Primcodable α] (ea : FinEncoding α) : Language α → Prop := |
| 97 | 110 | polynomial_hierarchy_pi_level 0 ea |
| 98 | 111 | |
| 99 | 112 | /-- |
| 100 | - Σ₁ᴾ = NP | |
| 113 | +`Σ₁ᴾ` at a fixed encoding `ea`: by definition `polynomial_hierarchy_sigma_level 1 ea`, i.e. one | |
| 114 | +polynomially bounded existential witness over a finite alphabet in front of a `Π₀ᴾ` predicate on | |
| 115 | +`pair_encoding ea (fin_encoding_string β)`. Whether this predicate is the statement's `NP` is S-4; | |
| 116 | +it is not a definitional identity here. | |
| 101 | 117 | |
| 102 | - The first level of the existential hierarchy is NP, which consists of | |
| 103 | - problems verifiable in polynomial time with a suitable certificate. | |
| 104 | - | |
| 105 | - Examples: SAT, Hamiltonian Path, Clique problem | |
| 118 | +Examples: SAT, Hamiltonian Path, Clique problem | |
| 106 | 119 | -/ |
| 107 | 120 | def polynomial_hierarchy_sigma_level_one {α : Type} [Primcodable α] (ea : FinEncoding α) : Language α → Prop := |
| 108 | 121 | polynomial_hierarchy_sigma_level 1 ea |
| 109 | 122 | |
| 110 | 123 | /-- |
| 111 | - Π₁ᴾ = co-NP | |
| 112 | - | |
| 113 | - The first level of the universal hierarchy is co-NP, which consists of | |
| 114 | - problems whose complement is in NP. | |
| 124 | +`Π₁ᴾ` at a fixed encoding `ea`: by definition `polynomial_hierarchy_pi_level 1 ea`, i.e. | |
| 125 | +`polynomial_hierarchy_sigma_level 1 ea (complement L)` — the complement of a `Σ₁ᴾ` language. | |
| 115 | 126 | |
| 116 | - Examples: TAUTOLOGY, No-Hamiltonian Path, No-Clique | |
| 127 | +Examples of the corresponding decision problems: TAUTOLOGY, No-Hamiltonian Path, No-Clique | |
| 117 | 128 | -/ |
| 118 | 129 | def polynomial_hierarchy_pi_level_one {α : Type} [Primcodable α] (ea : FinEncoding α) (L : Language α) : Prop := |
| 119 | 130 | polynomial_hierarchy_pi_level 1 ea L |
| 120 | 131 | /-- |
| 121 | - The polynomial hierarchy is the union of all Σₖᴾ classes. | |
| 122 | - | |
| 123 | - A problem is in PH if it is in Σₖᴾ for some k. | |
| 124 | - | |
| 125 | - The polynomial hierarchy collapses if there exists some k such that | |
| 126 | - Σₖᴾ = Σₖ₊₁ᴾ, which would imply that for all j ≥ k, Σⱼᴾ = Σₖᴾ. | |
| 132 | +The polynomial hierarchy at a fixed encoding `ea`: `∃ k : ℕ, polynomial_hierarchy_sigma_level k ea L`. | |
| 133 | +Membership is membership in some `Σₖᴾ` level; the `Π` levels enter only through `complement` inside | |
| 134 | +each level. The union is taken over every natural number `k`. | |
| 127 | 135 | -/ |
| 128 | 136 | def polynomial_hierarchy {α : Type} [Primcodable α] (ea : FinEncoding α) (L : Language α) : Prop := |
| 129 | 137 | ∃ k, polynomial_hierarchy_sigma_level k ea L |
| 130 | 138 | |
| 131 | 139 | /-- |
| 132 | - # The polynomial hierarchy collapse conjecture. | |
| 140 | + # The polynomial hierarchy collapse statement. | |
| 133 | 141 | |
| 134 | - This states that the polynomial hierarchy collapses to some finite level. | |
| 135 | - Most complexity theorists believe this is false, meaning the hierarchy | |
| 136 | - is infinite (each level is strictly contained in the next). | |
| 142 | + Literally: there is a level `k` such that, for every type `α` with a `Primcodable` instance, every | |
| 143 | + encoding `ea : FinEncoding α` and every language `L : Language α`, the predicate | |
| 144 | + `polynomial_hierarchy_sigma_level (k+1) ea L` implies `polynomial_hierarchy_sigma_level k ea L`. | |
| 137 | 145 | |
| 138 | - If P = NP, then the whole hierarchy collapses to P. | |
| 146 | + The quantifier over `α`, its `Primcodable` instance and `ea` is part of the statement; the level `k` | |
| 147 | + is fixed inside it. Nothing in this file decides whether it holds. | |
| 139 | 148 | -/ |
| 140 | 149 | def polynomial_hierarchy_collapses : Prop := |
| 141 | 150 | ∃ k, ∀ (α : Type) [Primcodable α] (ea : FinEncoding α) (L : Language α), |
| 142 | 151 | polynomial_hierarchy_sigma_level (k+1) ea L → polynomial_hierarchy_sigma_level k ea L |
| 143 | 152 | |
| 144 | 153 | /-- |
| 145 | - # A common conjecture that the polynomial hierarchy does not collapse. | |
| 154 | + # The negation of `polynomial_hierarchy_collapses`. | |
| 146 | 155 | |
| 147 | - This is related to the P ≠ NP conjecture. If P = NP, then the polynomial | |
| 148 | - hierarchy collapses to the first level (P = NP = PH). | |
| 156 | + Literally: for every `k`, some type `α` with a `Primcodable` instance, some encoding | |
| 157 | + `ea : FinEncoding α` and some language `L : Language α` satisfy | |
| 158 | + `polynomial_hierarchy_sigma_level (k+1) ea L` but not `polynomial_hierarchy_sigma_level k ea L`. | |
| 159 | + Nothing in this file proves or refutes it. | |
| 149 | 160 | -/ |
| 150 | 161 | def polynomial_hierarchy_does_not_collapse : Prop := |
| 151 | 162 | ¬polynomial_hierarchy_collapses |
| 163 | + | |
| 164 | +/-! ## Lemmas that hold by unfolding the definitions -/ | |
| 165 | + | |
| 166 | +/-- At level `0` the `Σ` level is exactly `InPolynomialTime`: `Σ₀ᴾ = P` read as a definitional | |
| 167 | +identity at the fixed encoding `ea`. -/ | |
| 168 | +theorem polynomial_hierarchy_sigma_level_zero_iff {α : Type} [Primcodable α] | |
| 169 | + (ea : FinEncoding α) (L : Language α) : | |
| 170 | + polynomial_hierarchy_sigma_level 0 ea L ↔ InPolynomialTime ea L := | |
| 171 | + Iff.rfl | |
| 172 | + | |
| 173 | +/-- The `Π` level is, by definition, the `Σ` level of the complement. -/ | |
| 174 | +theorem polynomial_hierarchy_pi_level_iff_sigma_complement {α : Type} [Primcodable α] | |
| 175 | + (k : ℕ) (ea : FinEncoding α) (L : Language α) : | |
| 176 | + polynomial_hierarchy_pi_level k ea L ↔ | |
| 177 | + polynomial_hierarchy_sigma_level k ea (complement L) := | |
| 178 | + Iff.rfl | |
| 179 | + | |
| 180 | +/-- A language at some `Σₖᴾ` level belongs to the polynomial hierarchy. -/ | |
| 181 | +theorem polynomial_hierarchy_sigma_level_mem {α : Type} [Primcodable α] | |
| 182 | + (k : ℕ) (ea : FinEncoding α) (L : Language α) | |
| 183 | + (h : polynomial_hierarchy_sigma_level k ea L) : polynomial_hierarchy ea L := | |
| 184 | + ⟨k, h⟩ | |
| 185 | + | |
| 152 | 186 | end Millennium |
+19 −0 routes/trial-ben-claude/p2-hierarchy-docstrings/README.md added View file
| @@ -0,0 +1,19 @@ | ||
| 1 | +--- | |
| 2 | +issue: 20 | |
| 3 | +status: working | |
| 4 | +--- | |
| 5 | + | |
| 6 | +# trial-ben-claude/p2-hierarchy-docstrings | |
| 7 | + | |
| 8 | +P-2: exact docstrings for `Problems/PVersusNP/PolynomialHierarchy.lean`, plus the lemmas that hold by | |
| 9 | +unfolding: `polynomial_hierarchy_sigma_level 0 ea L ↔ InPolynomialTime ea L`, the Π level as the Σ | |
| 10 | +level of the complement, and that a language of level `k` is in `polynomial_hierarchy`. | |
| 11 | + | |
| 12 | +Changes that file only. No change to `Millennium.lean`, `Tests/PVersusNP/Sanity.lean`, `checks/`, | |
| 13 | +`lakefile.toml` or the toolchain. | |
| 14 | + | |
| 15 | +## Next | |
| 16 | + | |
| 17 | +Write the docstrings so each says what its definition literally states (witness alphabet `β` with | |
| 18 | +`fin_encoding_string β`, the `Primcodable` instances, `Polynomial.eval` on `(ea.encode a).length`), then | |
| 19 | +the three `Iff`/implication lemmas by `rfl`/`⟨k, h⟩`. | |