Polynomial-time computation, the classes and , and
DefinitionPNPMission_ComplexityLanguages are sets of bit strings (List Bool). A function on bit strings is polynomial-time computable when Mathlib's multi-stack Turing machine model Turing.TM2ComputableInPolyTime computes it, with the identity encoding on bit strings (alphabet ) and, for decision functions, the one-symbol encoding of a bit.
A language is in when its characteristic function is polynomial-time computable. It is in when there are a language and a polynomial with coefficients in such that
where the pair writes each bit of as the two bits , then a separator , then . The statement says that a language is in if and only if it is in .
import Mathlib
namespace PNPMission
/-- Encoding of bit strings over the alphabet `Bool` (the identity encoding). -/
def bitStringEncoding : List Bool → List Bool := id
/-- Encoding of a single bit as a one-symbol string. -/
def boolEncoding : Bool → List Bool := fun b => [b]
/-- A function on bit strings is computable in polynomial time by a multi-stack Turing machine
(Mathlib's `Turing.TM2ComputableInPolyTime`, with the identity encoding on bit strings). -/
def PolyTimeComputable (f : List Bool → List Bool) : Prop :=
Nonempty (Turing.TM2ComputableInPolyTime bitStringEncoding bitStringEncoding f)
/-- A language `L` of bit strings is in `P`: its characteristic function is computable in
polynomial time. -/
def InP (L : Set (List Bool)) : Prop :=
∃ f : List Bool → Bool, (∀ x, f x = true ↔ x ∈ L) ∧
Nonempty (Turing.TM2ComputableInPolyTime bitStringEncoding boolEncoding f)
/-- Pairing of an input `x` with a witness `w` as one bit string: every bit `b` of `x` is written
as `true, b`, then comes the separator `false`, then `w`. -/
def pairBits (x w : List Bool) : List Bool :=
x.flatMap (fun b => [true, b]) ++ [false] ++ w
/-- A language `L` is in `NP`: there are a verifier language `V ∈ P` and a polynomial `p` such that
`x ∈ L` exactly when some witness `w` of length at most `p(|x|)` has `pairBits x w ∈ V`. -/
def InNP (L : Set (List Bool)) : Prop :=
∃ (V : Set (List Bool)) (p : Polynomial ℕ), InP V ∧
∀ x : List Bool, x ∈ L ↔ ∃ w : List Bool, w.length ≤ p.eval x.length ∧ pairBits x w ∈ V
/-- `P = NP`, as an equality of classes of languages of bit strings. -/
def PEqNP : Prop := ∀ L : Set (List Bool), InNP L ↔ InP L
end PNPMission
Read-back
What the Lean code literally says, in plain math · claude-sonnet-5-5 (independent blind auditor)
bitStringEncoding. The identity function on finite bit strings: for every (finite lists over Bool).
boolEncoding. The function sending a single bit to the one-element list .
PolyTimeComputable. For , the proposition that the type of Mathlib's Turing.TM2ComputableInPolyTime structures, with bitStringEncoding as input and output encoding, is nonempty for : some multi-stack Turing machine computes in polynomial time under the identity encodings. The meaning of polynomial time is that of Mathlib's structure. This definition is not used by the later declarations.
InP. For , holds iff there is with for all , and a TM2ComputableInPolyTime structure for with bitStringEncoding as input encoding and boolEncoding as output encoding, so the input is the identity encoding of and the output is the one-symbol string . is otherwise unrestricted.
pairBits. for : each bit of becomes the block , then the separator , then unchanged. Its length is .
InNP. holds iff there exist with and a polynomial such that for every : . The witness ranges over all bit strings of length at most , including the empty string.
PEqNP. , with no further hypotheses.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.