Paper
Classical Complexity Classes
5 pages · 40 marked passages · pdflatex · download PDF · lax-434930
-
The complexity class P
A language of finite binary strings belongs to if a deterministic Turing machine decides membership in that language in polynomial time. Precisely, there are a single machine and a polynomial such that, on every input , the machine halts within steps and returns the bit if belongs to the language and otherwise.
The definition uses mathlib's deterministic stack machines, the identity encoding of binary strings, and a singleton Boolean output. Time counts transitions of fixed finite instruction blocks. We also prove equivalence with elementary single-tape machines.
1 import Mathlib.Computability.TuringMachine.Computable 2 … module docstring, 16 lines 19 20 namespace Lax434930.PolynomialTime 21 22 /-- A finite binary string. -/ 23 abbrev Word := List Bool 24 25 /-- A language of finite binary strings. -/ 26 abbrev Language := Set Word 27 28 /-- Languages whose Boolean characteristic functions are computable in polynomial time. -/ 29 def P : Set Language := 30 {L | ∃ f : Word → Bool, 31 (∀ w, f w = true ↔ w ∈ L) ∧ 32 Nonempty (Turing.TM2ComputableInPolyTime id Computability.encodeBool f)} 33 34 end Lax434930.PolynomialTime 35 -
Finite-stack and elementary single-tape definitions of P
The finite-stack class requires every stack alphabet to be finite. The single-tape class uses a deterministic machine whose transitions each move the head one square or write one symbol. Its alphabet and control states are finite. The input is written in its original order, starting at the head, with blank tape elsewhere. The two input symbols are distinct and different from blank. A halted control state determines the Boolean answer; work tape need not be erased.
1 import Lax434930.PolynomialTime 2 import Mathlib.Computability.TuringMachine.PostTuringMachine 3 … module docstring, 13 lines 17 18 namespace Lax434930.MachineModels 19 20 open Turing PolynomialTime 21 22 /-- Polynomial-time stack deciders with finite alphabets at every stack. -/ 23 def FiniteStackP : Set Language := 24 {L | ∃ (f : Word → Bool) 25 (M : TM2ComputableInPolyTime id Computability.encodeBool f), 26 (∀ w, f w = true ↔ w ∈ L) ∧ ∀ k, Finite (M.tm.Γ k)} 27 28 /-- A finite elementary single-tape machine, with ordinary binary input. -/ 29 structure SingleTape where 30 Γ : Type 31 Q : Type 32 [alphabet : Fintype Γ] 33 [control : Fintype Q] 34 [blank : Inhabited Γ] 35 [initial : Inhabited Q] 36 input : Bool ↪ Γ 37 input_ne_blank : ∀ b, input b ≠ default 38 transition : TM0.Machine Γ Q 39 accept : Q → Bool 40 41 attribute [instance] SingleTape.alphabet SingleTape.control SingleTape.blank SingleTape.initial 42 43 /-- The standard single-tape formulation: one machine and one polynomial, 44 halting on every input, with acceptance exactly matching membership. -/ 45 def SingleTapeP : Set Language := 46 {L | ∃ (M : SingleTape) (p : Polynomial ℕ), ∀ w : Word, 47 ∃ c : TM0.Cfg M.Γ M.Q, 48 Nonempty (StateTransition.EvalsToInTime (TM0.step M.transition) 49 (TM0.init (w.map M.input)) (some c) (p.eval w.length)) ∧ 50 TM0.step M.transition c = none ∧ (M.accept c.q = true ↔ w ∈ L)} 51 52 end Lax434930.MachineModels 53 -
Binary encoding of an input and a certificate
To encode a pair of binary strings, replace each bit of by , then append a single followed by . This encoding has length and has a unique decoding. In particular, a polynomial bound in the encoded length is a polynomial bound in the combined input and certificate lengths.
- def✓
Lax434930.Certificates(1st statement) - def✓
Lax434930.Certificates(2nd statement) - def✓
Lax434930.Certificates(3rd statement)
1 import Lax434930.PolynomialTime 2 … module docstring, 11 lines 14 15 namespace Lax434930.Certificates 16 17 open PolynomialTime 18 19 /-- A self-delimiting encoding of the first string, followed by the second. -/ 20 def pair : Word → Word → Word 21 | [], y => true :: y 22 | b :: x, y => false :: b :: pair x y 23 24 /-- Decode a pair, rejecting a missing delimiter or an incomplete bit block. -/ 25 def unpair : Word → Option (Word × Word) 26 | [] => none 27 | true :: y => some ([], y) 28 | false :: [] => none 29 | false :: b :: rest => (unpair rest).map (fun p => (b :: p.1, p.2)) 30 31 /-- Encoding followed by decoding recovers both strings. -/ 32 axiom unpair_pair (x y : Word) : unpair (pair x y) = some (x, y) 33 34 /-- Distinct pairs of strings have distinct encodings. -/ 35 axiom pair_injective : Function.Injective (fun p : Word × Word => pair p.1 p.2) 36 37 /-- The encoding has linear length in its two arguments. -/ 38 axiom pair_length (x y : Word) : (pair x y).length = 2 * x.length + y.length + 1 39 40 end Lax434930.Certificates 41 - def✓
-
The complexity class NP
A binary language belongs to if there are a verifier language and a polynomial such that precisely when some binary certificate with satisfies . The verifier is a single deterministic polynomial-time decider on the explicit pair encoding, and its running time is polynomial in the combined input and certificate lengths. The certificate bound depends only on the original input length. This is the standard certificate definition of NP.
1 import Lax434930.Certificates 2 … module docstring, 14 lines 17 18 namespace Lax434930.NondeterministicPolynomialTime 19 20 open PolynomialTime Certificates 21 22 /-- Languages with polynomially bounded, polynomial-time verifiable certificates. -/ 23 def NP : Set Language := 24 {A | ∃ V : Language, V ∈ P ∧ ∃ p : Polynomial ℕ, ∀ x : Word, 25 x ∈ A ↔ ∃ y : Word, y.length ≤ p.eval x.length ∧ pair x y ∈ V} 26 27 end Lax434930.NondeterministicPolynomialTime 28 -
Finite Turing machines with a read-only input tape
A machine has finitely many control states, a finite work alphabet with a blank symbol, a read-only binary input tape between distinct endmarkers, and one initially blank, semi-infinite work tape. Both heads start at position zero, which is the input's left endmarker and the work tape's leftmost cell. One transition reads the two scanned symbols, writes one work symbol, changes state, and moves each head by at most one cell. An outward move at a tape boundary leaves that head in place.
The finite transition table gives a finite set of possible actions for each state and pair of scanned symbols. A deterministic machine has at most one action in every such set. A configuration with no successor is terminal, and its control state supplies an accept/reject bit. Acceptance means that some computation branch reaches an accepting terminal configuration. A decider has a finite bound on the lengths of all branches for each input, and accepts exactly the strings in its language. This bound need not be computable or satisfy any specified time bound.
Only the work tape is charged as space. Bounding its head below at every reachable configuration bounds every visited cell to the prefix , including blank cells and cells later erased. The input head is confined to positions and cannot act as an unbounded free counter. The transition table sees neither head position nor the input length; it sees only the control state and scanned symbols.
1 import Lax434930.PolynomialTime 2 import Mathlib.Data.Finset.Basic 3 4 set_option backward.isDefEq.respectTransparency false 5 6 /-! 7 --- 8 title: Finite Turing machines with a read-only input tape 9 type: definition 10 --- 11 A machine has finitely many control states, a finite work alphabet with a 12 blank symbol, a read-only binary input tape between distinct endmarkers, 13 and one initially blank, semi-infinite work tape. Both heads start at 14 position zero, which is the input's left endmarker and the work tape's 15 leftmost cell. One transition reads the two scanned symbols, writes one 16 work symbol, changes state, and moves each head by at most one cell. 17 An outward move at a tape boundary leaves that head in place. 18 19 The finite transition table gives a finite set of possible actions for 20 each state and pair of scanned symbols. A deterministic machine has at 21 most one action in every such set. A configuration with no successor is 22 terminal, and its control state supplies an accept/reject bit. Acceptance 23 means that some computation branch reaches an accepting terminal 24 configuration. A decider has a finite bound on the lengths of all branches 25 for each input, and accepts exactly the strings in its language. This 26 bound need not be computable or satisfy any specified time bound. 27 28 Only the work tape is charged as space. Bounding its head below at 29 every reachable configuration bounds every visited cell to the prefix 30 , including blank cells and cells later erased. The input 31 head is confined to positions and cannot act as an unbounded free 32 counter. The transition table sees neither head position nor the input 33 length; it sees only the control state and scanned symbols. 34 -/ 35 36 namespace Lax434930.SpaceMachines 37 38 open PolynomialTime 39 40 /-- The input alphabet, with two distinct endmarkers. -/ 41 inductive InputSymbol 42 | leftEnd 43 | bit (value : Bool) 44 | rightEnd 45 deriving DecidableEq, Fintype 46 47 /-- An elementary head movement, including staying in place. -/ 48 inductive Move 49 | left 50 | stay 51 | right 52 deriving DecidableEq, Fintype 53 54 /-- Move a head on a semi-infinite tape, keeping it at zero on a leftward exit. -/ 55 def Move.apply : Move → ℕ → ℕ 56 | .left, i => i - 1 57 | .stay, i => i 58 | .right, i => i + 1 59 60 /-- Read the immutable input at a head position, including its endmarkers. -/ 61 def readInput (w : Word) : ℕ → InputSymbol 62 | 0 => .leftEnd 63 | i + 1 => match w[i]? with 64 | some b => .bit b 65 | none => .rightEnd 66 67 /-- One local transition: change state, write a work symbol, and move the heads. -/ 68 structure Action (Γ Q : Type) where 69 state : Q 70 write : Γ 71 inputMove : Move 72 workMove : Move 73 74 /-- The complete finite description of a possibly nondeterministic machine. -/ 75 structure Machine where 76 Γ : Type 77 Q : Type 78 [alphabet : Fintype Γ] 79 [control : Fintype Q] 80 blank : Γ 81 start : Q 82 transition : Q → InputSymbol → Γ → Finset (Action Γ Q) 83 accept : Q → Bool 84 85 attribute [instance] Machine.alphabet Machine.control 86 87 /-- The two head positions, control state, and work-tape contents. -/ 88 structure Configuration (Γ Q : Type) where 89 state : Q 90 inputHead : ℕ 91 workHead : ℕ 92 tape : ℕ → Γ 93 94 /-- Configurations for a fixed machine. Only reachable configurations are used. -/ 95 abbrev Machine.Config (M : Machine) := Configuration M.Γ M.Q 96 97 /-- The work tape is blank; the input is supplied separately to the step relation. -/ 98 def Machine.initial (M : Machine) : M.Config := 99 ⟨M.start, 0, 0, fun _ => M.blank⟩ 100 101 /-- Execute one action. The input head is clipped to the two endmarkers. -/ 102 def Machine.execute (M : Machine) (w : Word) (c : M.Config) 103 (a : Action M.Γ M.Q) : M.Config := 104 ⟨a.state, min (a.inputMove.apply c.inputHead) (w.length + 1), 105 a.workMove.apply c.workHead, Function.update c.tape c.workHead a.write⟩ 106 107 /-- One legal transition consults only the state and the two scanned symbols. -/ 108 def Machine.Step (M : Machine) (w : Word) (c d : M.Config) : Prop := 109 ∃ a ∈ M.transition c.state (readInput w c.inputHead) (c.tape c.workHead), 110 d = M.execute w c a 111 112 /-- A computation prefix consisting of exactly the indicated number of transitions. -/ 113 inductive Machine.Run (M : Machine) (w : Word) : ℕ → M.Config → Prop 114 | zero : M.Run w 0 M.initial 115 | succ {n : ℕ} {c d : M.Config} : 116 M.Run w n c → M.Step w c d → M.Run w (n + 1) d 117 118 /-- No choice of action is available at a terminal configuration. -/ 119 def Machine.Terminal (M : Machine) (w : Word) (c : M.Config) : Prop := 120 ∀ d : M.Config, ¬ M.Step w c d 121 122 /-- All computation branches on this input have bounded finite length. -/ 123 def Machine.HaltsOn (M : Machine) (w : Word) : Prop := 124 ∃ t : ℕ, ∀ (n : ℕ) (c : M.Config), M.Run w n c → n ≤ t 125 126 /-- Existential acceptance at a terminal configuration. -/ 127 def Machine.Accepts (M : Machine) (w : Word) : Prop := 128 ∃ (n : ℕ) (c : M.Config), M.Run w n c ∧ M.Terminal w c ∧ M.accept c.state = true 129 130 /-- A decider halts on every branch and accepts exactly its language. -/ 131 def Machine.Decides (M : Machine) (A : Language) : Prop := 132 ∀ w : Word, M.HaltsOn w ∧ (M.Accepts w ↔ w ∈ A) 133 134 /-- The transition table has at most one action for each local observation. -/ 135 def Machine.Deterministic (M : Machine) : Prop := 136 ∀ (q : M.Q) (i : InputSymbol) (b : M.Γ), 137 ∀ a ∈ M.transition q i b, ∀ a' ∈ M.transition q i b, a = a' 138 139 /-- Every branch stays within the first `s` work cells, whether blank or nonblank. -/ 140 def Machine.UsesSpace (M : Machine) (w : Word) (s : ℕ) : Prop := 141 ∀ (n : ℕ) (c : M.Config), M.Run w n c → c.workHead < s 142 143 end Lax434930.SpaceMachines 144 -
Deterministic and nondeterministic space bounds
For a function , the classes DSPACE and NSPACE below use the exact bound on the number of work cells visited. There is one machine for all inputs, it halts on every branch, and every reachable configuration on an input of length respects the bound. DSPACE additionally requires deterministic transitions. Constant factors are quantified explicitly when the classical space classes are defined. We use as a positive logarithmic bound, so empty inputs are included without a special case.
1 import Lax434930.SpaceMachines 2 import Mathlib.Data.Nat.Log 3 … module docstring, 14 lines 18 19 namespace Lax434930.SpaceBounds 20 21 open PolynomialTime SpaceMachines 22 23 /-- Deterministic deciders using at most `s n` work cells on inputs of length `n`. -/ 24 def DSPACE (s : ℕ → ℕ) : Set Language := 25 {A | ∃ M : Machine, M.Deterministic ∧ M.Decides A ∧ 26 ∀ w : Word, M.UsesSpace w (s w.length)} 27 28 /-- Nondeterministic deciders using at most `s n` work cells on every branch. -/ 29 def NSPACE (s : ℕ → ℕ) : Set Language := 30 {A | ∃ M : Machine, M.Decides A ∧ ∀ w : Word, M.UsesSpace w (s w.length)} 31 32 /-- An integer logarithm that is positive even at input length zero. -/ 33 def logSpace (n : ℕ) : ℕ := Nat.log 2 (n + 2) 34 35 end Lax434930.SpaceBounds 36 -
The complexity class L
A binary language belongs to if a deterministic Turing machine decides membership using work space and a separate read-only input tape. Precisely, some positive constant bounds work space by on every input of length .
1 import Lax434930.SpaceBounds 2 … module docstring, 10 lines 13 14 namespace Lax434930.LogarithmicSpace 15 16 open PolynomialTime SpaceBounds 17 18 /-- Deterministic logarithmic work space. -/ 19 def L : Set Language := 20 {A | ∃ c : ℕ, 0 < c ∧ A ∈ DSPACE (fun n => c * logSpace n)} 21 22 end Lax434930.LogarithmicSpace 23 -
The complexity class NL
A binary language belongs to if a nondeterministic Turing machine decides membership using work space and a separate read-only input tape. Every branch halts and respects the space bound; membership means that at least one branch accepts. The bound is for one positive constant .
1 import Lax434930.SpaceBounds 2 … module docstring, 11 lines 14 15 namespace Lax434930.NondeterministicLogarithmicSpace 16 17 open PolynomialTime SpaceBounds 18 19 /-- Nondeterministic logarithmic work space. -/ 20 def NL : Set Language := 21 {A | ∃ c : ℕ, 0 < c ∧ A ∈ NSPACE (fun n => c * logSpace n)} 22 23 end Lax434930.NondeterministicLogarithmicSpace 24 -
The complexity class PSPACE
A binary language belongs to if one deterministic Turing machine decides membership using at most work cells on inputs of length , for some polynomial . The input tape is read-only and excluded from work space, and the machine always halts.
1 import Lax434930.SpaceBounds 2 … module docstring, 10 lines 13 14 namespace Lax434930.PolynomialSpace 15 16 open PolynomialTime SpaceBounds 17 18 /-- Deterministic polynomial work space. -/ 19 def PSPACE : Set Language := 20 {A | ∃ p : Polynomial ℕ, A ∈ DSPACE p.eval} 21 22 end Lax434930.PolynomialSpace 23 -
The complexity class NPSPACE
A binary language belongs to if one nondeterministic Turing machine decides membership using at most work cells on every branch on inputs of length , for some polynomial . All branches halt; at least one accepts precisely when the input belongs to the language. The input tape is read-only and excluded from work space.
1 import Lax434930.SpaceBounds 2 … module docstring, 12 lines 15 16 namespace Lax434930.NondeterministicPolynomialSpace 17 18 open PolynomialTime SpaceBounds 19 20 /-- Nondeterministic polynomial work space. -/ 21 def NPSPACE : Set Language := 22 {A | ∃ p : Polynomial ℕ, A ∈ NSPACE p.eval} 23 24 end Lax434930.NondeterministicPolynomialSpace 25 -
The complexity classes coNL and coNP
For a class of binary languages, consists of languages whose complements belong to . Complements are taken among all finite binary strings. In particular, means , and means . This operation complements each language; it does not take the set-theoretic complement of the class of languages.
1 import Lax434930.NondeterministicLogarithmicSpace 2 import Lax434930.NondeterministicPolynomialTime 3 … module docstring, 13 lines 17 18 namespace Lax434930.ComplementClasses 19 20 open PolynomialTime NondeterministicLogarithmicSpace NondeterministicPolynomialTime 21 22 /-- The class of languages whose complements belong to the given class. -/ 23 def co (C : Set Language) : Set Language := {A | Aᶜ ∈ C} 24 25 /-- Complements of languages in NL. -/ 26 def coNL : Set Language := co NL 27 28 /-- Complements of languages in NP. -/ 29 def coNP : Set Language := co NP 30 31 end Lax434930.ComplementClasses 32 -
The complexity class EXPTIME
A binary language belongs to if a deterministic Turing machine decides membership within transitions on every input of length , for some polynomial . The machine is the finite elementary single-tape machine defined here: input bits are distinct from blank, input appears in its original order, and each transition performs one move or one write. A terminal state's Boolean label gives the answer. The polynomial in the exponent may have any fixed degree; this is the usual EXPTIME, also called EXP.
1 import Lax434930.PolynomialTime 2 import Lax434930.MachineModels 3 … module docstring, 14 lines 18 19 namespace Lax434930.ExponentialTime 20 21 open PolynomialTime Lax434930.MachineModels Turing 22 23 /-- Deterministic time bounded by two to a polynomial in the input length. -/ 24 def EXPTIME : Set Language := 25 {A | ∃ (M : SingleTape) (p : Polynomial ℕ), ∀ w : Word, 26 ∃ c : TM0.Cfg M.Γ M.Q, 27 Nonempty (StateTransition.EvalsToInTime (TM0.step M.transition) 28 (TM0.init (w.map M.input)) (some c) (2 ^ p.eval w.length)) ∧ 29 TM0.step M.transition c = none ∧ (M.accept c.q = true ↔ w ∈ A)} 30 31 end Lax434930.ExponentialTime 32 -
Binary encoding of an input and a certificate
To encode a pair of binary strings, replace each bit of by , then append a single followed by . This encoding has length and has a unique decoding. In particular, a polynomial bound in the encoded length is a polynomial bound in the combined input and certificate lengths.
- def✓
Lax434930.Certificates(1st statement) - def✓
Lax434930.Certificates(2nd statement) - def✓
Lax434930.Certificates(3rd statement)
1 import Lax434930.PolynomialTime 2 … module docstring, 11 lines 14 15 namespace Lax434930.Certificates 16 17 open PolynomialTime 18 19 /-- A self-delimiting encoding of the first string, followed by the second. -/ 20 def pair : Word → Word → Word 21 | [], y => true :: y 22 | b :: x, y => false :: b :: pair x y 23 24 /-- Decode a pair, rejecting a missing delimiter or an incomplete bit block. -/ 25 def unpair : Word → Option (Word × Word) 26 | [] => none 27 | true :: y => some ([], y) 28 | false :: [] => none 29 | false :: b :: rest => (unpair rest).map (fun p => (b :: p.1, p.2)) 30 31 /-- Encoding followed by decoding recovers both strings. -/ 32 axiom unpair_pair (x y : Word) : unpair (pair x y) = some (x, y) 33 34 /-- Distinct pairs of strings have distinct encodings. -/ 35 axiom pair_injective : Function.Injective (fun p : Word × Word => pair p.1 p.2) 36 37 /-- The encoding has linear length in its two arguments. -/ 38 axiom pair_length (x y : Word) : (pair x y).length = 2 * x.length + y.length + 1 39 40 end Lax434930.Certificates 41 - def✓
-
no assumptions
Induct on the first word, decoding one two-bit block at a time.
-
Binary encoding of an input and a certificate
To encode a pair of binary strings, replace each bit of by , then append a single followed by . This encoding has length and has a unique decoding. In particular, a polynomial bound in the encoded length is a polynomial bound in the combined input and certificate lengths.
- def✓
Lax434930.Certificates(1st statement) - def✓
Lax434930.Certificates(2nd statement) - def✓
Lax434930.Certificates(3rd statement)
1 import Lax434930.PolynomialTime 2 … module docstring, 11 lines 14 15 namespace Lax434930.Certificates 16 17 open PolynomialTime 18 19 /-- A self-delimiting encoding of the first string, followed by the second. -/ 20 def pair : Word → Word → Word 21 | [], y => true :: y 22 | b :: x, y => false :: b :: pair x y 23 24 /-- Decode a pair, rejecting a missing delimiter or an incomplete bit block. -/ 25 def unpair : Word → Option (Word × Word) 26 | [] => none 27 | true :: y => some ([], y) 28 | false :: [] => none 29 | false :: b :: rest => (unpair rest).map (fun p => (b :: p.1, p.2)) 30 31 /-- Encoding followed by decoding recovers both strings. -/ 32 axiom unpair_pair (x y : Word) : unpair (pair x y) = some (x, y) 33 34 /-- Distinct pairs of strings have distinct encodings. -/ 35 axiom pair_injective : Function.Injective (fun p : Word × Word => pair p.1 p.2) 36 37 /-- The encoding has linear length in its two arguments. -/ 38 axiom pair_length (x y : Word) : (pair x y).length = 2 * x.length + y.length + 1 39 40 end Lax434930.Certificates 41 - def✓
-
no assumptions
Apply the decoder to an equality of encodings.
-
Binary encoding of an input and a certificate
To encode a pair of binary strings, replace each bit of by , then append a single followed by . This encoding has length and has a unique decoding. In particular, a polynomial bound in the encoded length is a polynomial bound in the combined input and certificate lengths.
- def✓
Lax434930.Certificates(1st statement) - def✓
Lax434930.Certificates(2nd statement) - def✓
Lax434930.Certificates(3rd statement)
1 import Lax434930.PolynomialTime 2 … module docstring, 11 lines 14 15 namespace Lax434930.Certificates 16 17 open PolynomialTime 18 19 /-- A self-delimiting encoding of the first string, followed by the second. -/ 20 def pair : Word → Word → Word 21 | [], y => true :: y 22 | b :: x, y => false :: b :: pair x y 23 24 /-- Decode a pair, rejecting a missing delimiter or an incomplete bit block. -/ 25 def unpair : Word → Option (Word × Word) 26 | [] => none 27 | true :: y => some ([], y) 28 | false :: [] => none 29 | false :: b :: rest => (unpair rest).map (fun p => (b :: p.1, p.2)) 30 31 /-- Encoding followed by decoding recovers both strings. -/ 32 axiom unpair_pair (x y : Word) : unpair (pair x y) = some (x, y) 33 34 /-- Distinct pairs of strings have distinct encodings. -/ 35 axiom pair_injective : Function.Injective (fun p : Word × Word => pair p.1 p.2) 36 37 /-- The encoding has linear length in its two arguments. -/ 38 axiom pair_length (x y : Word) : (pair x y).length = 2 * x.length + y.length + 1 39 40 end Lax434930.Certificates 41 - def✓
-
no assumptions
Each bit of the first word contributes two bits, and the delimiter contributes one.
-
Finite stack alphabets suffice
Requiring every work-stack alphabet to be finite leaves unchanged.
1 import Lax434930.MachineModels 2 … module docstring, 7 lines 10 11 namespace Lax434930.FiniteStackEquivalence 12 13 open PolynomialTime MachineModels 14 15 /-- Requiring all work alphabets to be finite does not change P. -/ 16 axiom finiteStackP_eq_P : FiniteStackP = P 17 18 end Lax434930.FiniteStackEquivalence 19 -
no assumptions
Retain the input/output symbols and the finite ranges of push instructions. Restricting each stack alphabet to these symbols preserves every transition and the original time polynomial.
-
Single-tape characterization of P
The elementary single-tape and stack-machine definitions of coincide. Both simulations include polynomial bounds for input conversion, execution, and final output conversion.
1 import Lax434930.MachineModels 2 … module docstring, 9 lines 12 13 namespace Lax434930.ModelEquivalence 14 15 open PolynomialTime MachineModels 16 17 /-- The elementary single-tape and stack definitions give the same class P. -/ 18 axiom singleTapeP_eq_P : SingleTapeP = P 19 20 end Lax434930.ModelEquivalence 21 -
After restricting stack alphabets, compile stacks to tape tracks with polynomial overhead. Conversely, simulate a tape by two stacks with linear overhead. Both bounds include input conversion and final output conversion.
-
P is closed under complement
If a language of binary strings belongs to , then its complement also belongs to . The complement is taken in the set of all finite binary strings.
1 import Lax434930.PolynomialTime 2 … module docstring, 9 lines 12 13 namespace Lax434930.ComplementClosure 14 15 open Lax434930.PolynomialTime 16 17 /-- The complement of a polynomial-time decidable language is polynomial-time decidable. -/ 18 axiom closed_under_complement (L : Language) : L ∈ P → Lᶜ ∈ P 19 20 end Lax434930.ComplementClosure 21 -
no assumptions
Compose the output-alphabet equivalence with Boolean negation. The same machine execution then computes the complemented answer with the same time bound. Negating the correctness equivalence identifies the complement language.
-
Single-tape P is closed under complement
The elementary single-tape class is closed under complement.
1 import Lax434930.MachineModels 2 … module docstring, 7 lines 10 11 namespace Lax434930.SingleTapeComplement 12 13 open PolynomialTime MachineModels 14 15 /-- Complement closure for the elementary single-tape definition. -/ 16 axiom closed_under_complement (L : Language) : 17 L ∈ SingleTapeP → Lᶜ ∈ SingleTapeP 18 19 end Lax434930.SingleTapeComplement 20 -
Transport the established complement theorem across the proved class equality.
-
The inclusion chain of complexity classes
The classical classes satisfy .
- thm✓
Lax434930.BasicProperties(1st statement) - thm✓
Lax434930.BasicProperties(2nd statement) - thm✓
Lax434930.BasicProperties(3rd statement) - thm✓
Lax434930.BasicProperties(4th statement) - thm✓
Lax434930.BasicProperties(5th statement)
1 import Lax434930.LogarithmicSpace 2 import Lax434930.NondeterministicLogarithmicSpace 3 import Lax434930.PolynomialSpace 4 import Lax434930.NondeterministicPolynomialSpace 5 import Lax434930.ComplementClasses 6 import Lax434930.ExponentialTime 7 import Lax434930.PolynomialSpaceEquality 8 … module docstring, 9 lines 18 19 namespace Lax434930.BasicProperties 20 21 open PolynomialTime LogarithmicSpace NondeterministicLogarithmicSpace 22 open NondeterministicPolynomialTime PolynomialSpace NondeterministicPolynomialSpace 23 open ExponentialTime 24 25 axiom L_subset_NL : L ⊆ NL 26 27 axiom NL_subset_P : NL ⊆ P 28 29 axiom P_subset_NP : P ⊆ NP 30 31 axiom NP_subset_PSPACE : NP ⊆ PSPACE 32 33 axiom NPSPACE_subset_EXPTIME : NPSPACE ⊆ EXPTIME 34 35 end Lax434930.BasicProperties 36 - thm✓
-
The inclusion chain of complexity classes
The classical classes satisfy .
- thm✓
Lax434930.BasicProperties(1st statement) - thm✓
Lax434930.BasicProperties(2nd statement) - thm✓
Lax434930.BasicProperties(3rd statement) - thm✓
Lax434930.BasicProperties(4th statement) - thm✓
Lax434930.BasicProperties(5th statement)
1 import Lax434930.LogarithmicSpace 2 import Lax434930.NondeterministicLogarithmicSpace 3 import Lax434930.PolynomialSpace 4 import Lax434930.NondeterministicPolynomialSpace 5 import Lax434930.ComplementClasses 6 import Lax434930.ExponentialTime 7 import Lax434930.PolynomialSpaceEquality 8 … module docstring, 9 lines 18 19 namespace Lax434930.BasicProperties 20 21 open PolynomialTime LogarithmicSpace NondeterministicLogarithmicSpace 22 open NondeterministicPolynomialTime PolynomialSpace NondeterministicPolynomialSpace 23 open ExponentialTime 24 25 axiom L_subset_NL : L ⊆ NL 26 27 axiom NL_subset_P : NL ⊆ P 28 29 axiom P_subset_NP : P ⊆ NP 30 31 axiom NP_subset_PSPACE : NP ⊆ PSPACE 32 33 axiom NPSPACE_subset_EXPTIME : NPSPACE ⊆ EXPTIME 34 35 end Lax434930.BasicProperties 36 - thm✓
-
no assumptions
Use the same machine and the same logarithmic bound, allowing nondeterminism.
-
The inclusion chain of complexity classes
The classical classes satisfy .
- thm✓
Lax434930.BasicProperties(1st statement) - thm✓
Lax434930.BasicProperties(2nd statement) - thm✓
Lax434930.BasicProperties(3rd statement) - thm✓
Lax434930.BasicProperties(4th statement) - thm✓
Lax434930.BasicProperties(5th statement)
1 import Lax434930.LogarithmicSpace 2 import Lax434930.NondeterministicLogarithmicSpace 3 import Lax434930.PolynomialSpace 4 import Lax434930.NondeterministicPolynomialSpace 5 import Lax434930.ComplementClasses 6 import Lax434930.ExponentialTime 7 import Lax434930.PolynomialSpaceEquality 8 … module docstring, 9 lines 18 19 namespace Lax434930.BasicProperties 20 21 open PolynomialTime LogarithmicSpace NondeterministicLogarithmicSpace 22 open NondeterministicPolynomialTime PolynomialSpace NondeterministicPolynomialSpace 23 open ExponentialTime 24 25 axiom L_subset_NL : L ⊆ NL 26 27 axiom NL_subset_P : NL ⊆ P 28 29 axiom P_subset_NP : P ⊆ NP 30 31 axiom NP_subset_PSPACE : NP ⊆ PSPACE 32 33 axiom NPSPACE_subset_EXPTIME : NPSPACE ⊆ EXPTIME 34 35 end Lax434930.BasicProperties 36 - thm✓
-
no assumptions
A finite deterministic stack machine computes reachability in a polynomial-size encoding of the original logarithmic-space machine's configurations. The checked compiler gives polynomial running time and the original acceptance definition gives the characteristic function.
-
The inclusion chain of complexity classes
The classical classes satisfy .
- thm✓
Lax434930.BasicProperties(1st statement) - thm✓
Lax434930.BasicProperties(2nd statement) - thm✓
Lax434930.BasicProperties(3rd statement) - thm✓
Lax434930.BasicProperties(4th statement) - thm✓
Lax434930.BasicProperties(5th statement)
1 import Lax434930.LogarithmicSpace 2 import Lax434930.NondeterministicLogarithmicSpace 3 import Lax434930.PolynomialSpace 4 import Lax434930.NondeterministicPolynomialSpace 5 import Lax434930.ComplementClasses 6 import Lax434930.ExponentialTime 7 import Lax434930.PolynomialSpaceEquality 8 … module docstring, 9 lines 18 19 namespace Lax434930.BasicProperties 20 21 open PolynomialTime LogarithmicSpace NondeterministicLogarithmicSpace 22 open NondeterministicPolynomialTime PolynomialSpace NondeterministicPolynomialSpace 23 open ExponentialTime 24 25 axiom L_subset_NL : L ⊆ NL 26 27 axiom NL_subset_P : NL ⊆ P 28 29 axiom P_subset_NP : P ⊆ NP 30 31 axiom NP_subset_PSPACE : NP ⊆ PSPACE 32 33 axiom NPSPACE_subset_EXPTIME : NPSPACE ⊆ EXPTIME 34 35 end Lax434930.BasicProperties 36 - thm✓
-
no assumptions
Extract the input from the existing pair encoding in linear time, then run the polynomial-time decider. The empty certificate suffices for every input.
-
Savitch's theorem
The polynomial-space form of Savitch's theorem is .
1 import Lax434930.PolynomialSpace 2 import Lax434930.NondeterministicPolynomialSpace 3 … module docstring, 8 lines 12 13 namespace Lax434930.PolynomialSpaceEquality 14 15 open PolynomialSpace NondeterministicPolynomialSpace 16 17 axiom PSPACE_eq_NPSPACE : PSPACE = NPSPACE 18 19 end Lax434930.PolynomialSpaceEquality 20 -
no assumptions
Deterministic machines are special cases of nondeterministic machines. Conversely, apply the proved Savitch simulation to the constructible bound . Its squared space bound is still polynomial.
-
The inclusion chain of complexity classes
The classical classes satisfy .
- thm✓
Lax434930.BasicProperties(1st statement) - thm✓
Lax434930.BasicProperties(2nd statement) - thm✓
Lax434930.BasicProperties(3rd statement) - thm✓
Lax434930.BasicProperties(4th statement) - thm✓
Lax434930.BasicProperties(5th statement)
1 import Lax434930.LogarithmicSpace 2 import Lax434930.NondeterministicLogarithmicSpace 3 import Lax434930.PolynomialSpace 4 import Lax434930.NondeterministicPolynomialSpace 5 import Lax434930.ComplementClasses 6 import Lax434930.ExponentialTime 7 import Lax434930.PolynomialSpaceEquality 8 … module docstring, 9 lines 18 19 namespace Lax434930.BasicProperties 20 21 open PolynomialTime LogarithmicSpace NondeterministicLogarithmicSpace 22 open NondeterministicPolynomialTime PolynomialSpace NondeterministicPolynomialSpace 23 open ExponentialTime 24 25 axiom L_subset_NL : L ⊆ NL 26 27 axiom NL_subset_P : NL ⊆ P 28 29 axiom P_subset_NP : P ⊆ NP 30 31 axiom NP_subset_PSPACE : NP ⊆ PSPACE 32 33 axiom NPSPACE_subset_EXPTIME : NPSPACE ⊆ EXPTIME 34 35 end Lax434930.BasicProperties 36 - thm✓
-
A finite nondeterministic machine guesses a bounded certificate and runs the original polynomial-time verifier within polynomial work space. Savitch's theorem, proved separately, then gives deterministic polynomial space and the inclusion.
-
The inclusion chain of complexity classes
The classical classes satisfy .
- thm✓
Lax434930.BasicProperties(1st statement) - thm✓
Lax434930.BasicProperties(2nd statement) - thm✓
Lax434930.BasicProperties(3rd statement) - thm✓
Lax434930.BasicProperties(4th statement) - thm✓
Lax434930.BasicProperties(5th statement)
1 import Lax434930.LogarithmicSpace 2 import Lax434930.NondeterministicLogarithmicSpace 3 import Lax434930.PolynomialSpace 4 import Lax434930.NondeterministicPolynomialSpace 5 import Lax434930.ComplementClasses 6 import Lax434930.ExponentialTime 7 import Lax434930.PolynomialSpaceEquality 8 … module docstring, 9 lines 18 19 namespace Lax434930.BasicProperties 20 21 open PolynomialTime LogarithmicSpace NondeterministicLogarithmicSpace 22 open NondeterministicPolynomialTime PolynomialSpace NondeterministicPolynomialSpace 23 open ExponentialTime 24 25 axiom L_subset_NL : L ⊆ NL 26 27 axiom NL_subset_P : NL ⊆ P 28 29 axiom P_subset_NP : P ⊆ NP 30 31 axiom NP_subset_PSPACE : NP ⊆ PSPACE 32 33 axiom NPSPACE_subset_EXPTIME : NPSPACE ⊆ EXPTIME 34 35 end Lax434930.BasicProperties 36 - thm✓
-
Apply the proved Savitch simulation, bound the deterministic machine's run length by its configuration count, and use the time-bounded stack and tape simulations.
-
P versus NP
The P versus NP problem asks whether every language with polynomially bounded, polynomial-time verifiable certificates can also be decided in deterministic polynomial time. We state the conjectured separation as an open question.
1 import Lax434930.PolynomialTime 2 import Lax434930.NondeterministicPolynomialTime 3 … module docstring, 10 lines 14 15 namespace Lax434930.PVersusNP 16 17 open PolynomialTime NondeterministicPolynomialTime 18 19 /-- The conjectured separation of P and NP, left as an open question. -/ 20 axiom P_ne_NP : P ≠ NP 21 22 end Lax434930.PVersusNP 23