Time hierarchy (Hartmanis–Stearns 1965):
OpenPvsNP.P_ne_ECook (p. 7–8): "The method of diagonalization with reduction has been used very successfully in computability theory to prove a host of problems undecidable ... It has also been used successfully in complexity theory to prove super-exponential lower bounds for very hard decidable problems." Cook defines (p. 9) " ... the class of languages recognizable in exponential time; that is the class of languages such that for some Turing machine with for some ." The separation of polynomial from exponential time is the time hierarchy theorem of Hartmanis and Stearns (1965), the model case of a class separation that diagonalization does prove.
Theorem. : the class of languages decidable within a polynomial number of steps is not the class of languages decidable within steps for some constants . Since every polynomial is eventually below , , so the theorem says that some language is decidable in exponential time but in no polynomial time.
Formalization Note E is defined through Mathlib's Turing.TM2ComputableInTime with the time function bounded by for all (equivalent to , since the bound can absorb finitely many exceptions). A proof requires a coding of multi-stack machines by binary strings, a universal multi-stack machine that simulates a coded machine for a prescribed number of steps with at most exponential overhead, and the diagonal language; none of this exists in Mathlib.
import Definitions.Def_PvsNP import Mathlib
namespace PvsNP theorem P_ne_E : P ≠ E := by sorry end PvsNP
Read-back
What the Lean code literally says, in plain math · claude-fable-5-1
Read-back: PvsNP.P_ne_E
The statement. The theorem asserts that two specific sets of languages over the two-letter alphabet , called and below, are not equal as sets:
Here a string is a finite list of Booleans (the empty string included), a language is an arbitrary set of such strings, and and are sets of languages. The statement is only the negation of set equality: it says it is not the case that every language in lies in and every language in lies in . Classically this is equivalent to: there is a language lying in exactly one of , . The statement does not say which of the two sets contains such an , does not assert , and does not assert that either set is a proper subset of the other. There are no hypotheses, free variables, or typeclass assumptions: it is a closed proposition. Both and are custom definitions from the preamble, unfolded in full below; everything hinges on a particular stack-machine model (also unfolded).
The machine model (used by both sets). A bundled stack machine consists of:
- a finite index set of stacks (with decidable equality), together with two distinguished indices (input stack) and (output stack), which are not required to be distinct;
- for each stack index a type of stack symbols; only is required to be finite (but see the alphabet conditions below, which force and to be two-element types); the symbol types of any other stacks are arbitrary types, not required to be finite;
- a finite type of program labels with a distinguished label ;
- a finite type of internal states with a distinguished initial state ;
- a program , assigning to each label a statement. A statement is a finite tree built from: with (push on stack , continue with ); with (update the state from the top of stack , if any, without removing it); (same, but remove the top element if present; popping an empty stack leaves it empty); with ; with ; with ; and . The functions appearing in statements are arbitrary set-theoretic functions (no computability requirement on them; their domains are finite).
A configuration is a triple : a current label (with meaning "halted"), an internal state , and a family of stacks, each a finite list over . One step of from executes the entire statement — all of its pushes/peeks/pops/loads/branches, however many — until it reaches a (giving the new configuration ) or a (giving ). A step from a configuration with label is undefined (the computation is over). Time is measured as the number of such steps; a single step may perform an unbounded-in-principle but program-fixed finite number of stack operations.
The initial configuration for an input list over is with (first symbol of on top) and for every other . The halting configuration for an output list over is with and for every . Note that the halting configuration requires the internal state to be exactly the initial state again, and every stack other than the output stack to be exactly empty.
" outputs on input within steps" means: there is a natural number such that after exactly steps from the initial configuration for the configuration is exactly the halting configuration for (formally, the -fold iterate of the step function, extended to so that an undefined step stays undefined, applied to the initial configuration equals of the halting configuration). Because a halted configuration has no successor, this forces every intermediate configuration to be non-halted, and the machine to halt precisely at step .
Deciders. Let be a total function on strings. A machine computing with time function (this is the Mathlib notion TM2ComputableInTime with input encoding the identity on strings and output encoding ) is a bundled stack machine together with
- a bijection (input alphabet) and a bijection (output alphabet), so both and are two-element types;
- a time function (the structure's
timefield), an arbitrary function of the input length; - for every string (including the empty string, of length ), a witness that outputs the one-element list on input (the string transported symbol-wise onto the input alphabet) within steps, in the exact sense defined above (halting with state , output stack holding exactly one symbol, all other stacks empty).
A polynomial-time machine computing (TM2ComputableInPolyTime, same encodings) is the same, except that the time field is a polynomial with natural-number coefficients, and the step bound for input is .
The set . A language belongs to if and only if there exists a total function such that
- there exists (as a mere existence statement,
Nonempty) a polynomial-time machine computing in the sense just defined, and - for every string : .
Condition 2 means is exactly ; in particular is determined by , and the empty language and the language of all strings are obtained from constant .
The set . A language belongs to if and only if there exists a total function such that
- there exists a machine computing with some time function (the
TM2ComputableInTimestructure above), together with natural numbers such that
and 2. for every string : .
In item 1 the bound is on the machine's declared time function itself (for all , including and lengths of no particular interest), not directly on the actual step counts; the actual step count on input is separately required to be . The parameters and range over all natural numbers: is allowed (giving a constant bound ), and is allowed (giving , which would require halting in steps; since the initial configuration is never a halting configuration, no machine satisfies this, so that case contributes nothing). No monotonicity or other regularity of is required.
Summary of what is asserted. With = "languages for some admitting a bundled stack machine, of the exact form above, whose step count on every input is at most for a polynomial " and = "languages for some admitting such a machine whose declared time function satisfies for all , for some ", the theorem states precisely that these two sets of languages over are distinct.