P versus NP
"Quickly" means in time bounded by a polynomial in the size of the input. P is the class of problems solvable that fast; NP is the class whose solutions can be verified that fast. Most researchers expect P ≠ NP, but no proof exists in either direction.
In Lean
Draft definitions of P and NP, built on Mathlib's multi-stack Turing machines, are in lean/MPP/Defs/PvsNP.lean. They need review by complexity theorists before any result stated with them means anything.
Gaps
pnp-000P ≠ NPMillennium Problem open
Lean statement
import Mathlib
import MPP.Defs.PvsNP
open MPP.PvsNP
theorem main :
¬ PEqualsNPContext
The Millennium Problem in the separating direction, with the draft definitions of `MPP/Defs/PvsNP.lean`. Any approach must get past the known barriers: relativization (Baker–Gill–Solovay), natural proofs (Razborov–Rudich) and algebrization (Aaronson–Wigderson). Say in your PR which barrier your idea avoids and why.
Gap file · solution goes in lean/MPP/Solutions/Pnp000.lean
pnp-001P = NPMillennium Problem open
Lean statement
import Mathlib
import MPP.Defs.PvsNP
open MPP.PvsNP
theorem main :
PEqualsNPContext
The other direction: a polynomial-time algorithm for every NP language. Almost all experts expect this to be false; a constructive attempt would start from an NP-complete problem such as SAT.
Gap file · solution goes in lean/MPP/Solutions/Pnp001.lean
pnp-002P is contained in NPopen
Lean statement
import Mathlib
import MPP.Defs.PvsNP
open MPP.PvsNP
theorem main :
∀ L : Lang, InP L → InNP LContext
Sanity check of the definitions: a machine for L gives a verifier that ignores the witness. The work is building a TM2 machine that strips the pair encoding and composing polynomial-time machines in Mathlib's `Turing.FinTM2` framework.
Gap file · solution goes in lean/MPP/Solutions/Pnp002.lean
pnp-003The trivial language is in Popen
Lean statement
import Mathlib
import MPP.Defs.PvsNP
open MPP.PvsNP
theorem main :
InP (fun _ => true)Context
Build an explicit `Turing.FinTM2` machine that ignores its input and outputs `true`, then prove its running time is bounded by a polynomial. A first exercise in the TM2 API.
Sketch
See `Turing.idComputableInPolyTime` in Mathlib for the shape of such a proof.
Gap file · solution goes in lean/MPP/Solutions/Pnp003.lean
pnp-004P is closed under complementopen
Lean statement
import Mathlib
import MPP.Defs.PvsNP
open MPP.PvsNP
theorem main :
∀ L : Lang, InP L → InP (fun x => !L x)Context
Run the machine for L, then flip the output bit. Follows from composition (gap pnp-006) with a machine that negates one bit.
Depends on
Gap file · solution goes in lean/MPP/Solutions/Pnp004.lean
pnp-005The pair encoding is injectiveopen
Lean statement
import Mathlib
import MPP.Defs.PvsNP
open MPP.PvsNP
theorem main :
∀ x w x' w' : List Bool, pair x w = pair x' w' → x = x' ∧ w = w'Context
Checks that `pair` in the definition of NP loses no information.
Sketch
Induction on x, generalizing x'. Doubled bits are [b, b]; the separator is the first position where two consecutive bits differ at an even offset.
Gap file · solution goes in lean/MPP/Solutions/Pnp005.lean
pnp-006Polynomial-time machines composeopen
Lean statement
import Mathlib
open Turing
theorem main :
∀ {α β γ αΓ βΓ γΓ : Type} {eα : α → List αΓ} {eβ : β → List βΓ} {eγ : γ → List γΓ}
{f : α → β} {g : β → γ},
TM2ComputableInPolyTime eα eβ f → TM2ComputableInPolyTime eβ eγ g →
Nonempty (TM2ComputableInPolyTime eα eγ (g ∘ f))Context
Mathlib lists this as `proof_wanted TM2ComputableInPolyTime.comp` in Mathlib/Computability/TuringMachine/Computable.lean. A proof here can go upstream to Mathlib, and it unlocks most P vs NP gaps (closure properties, P ⊆ NP).
Sketch
One stack per stack of each machine: run the first machine, copy its output stack to the input stack of the second, run the second. The time bound is p(n) + (copy cost) + q(p(n)), still a polynomial.
Gap file · solution goes in lean/MPP/Solutions/Pnp006.lean