OctoInform Beta

OpenAI preprint, September 2026 · §5. A language hard at every sufficiently large length

Lemma 5.1: Explicit quadratic one-tape simulation of a multitape Turing machine MM via stack machines and linear multitape compilation of stack machines

Quadratic one-tape simulation of multitape Turing machines.

Hover over a blue or green term in the text, or a node in the graph, to find it in the other. Select it to read its declaration both in Lean and in words.

The setting

In sequential time complexity, deterministic multitape Turing machines provide a flexible model of computation, whereas deterministic one-tape Turing machines have a simpler architecture suited to diagonalization and simulation arguments. Any fixed deterministic multitape Turing machine can be simulated by a fixed deterministic one-tape Turing machine with quadratic overhead in the input length and running time. In the Lean library, this simulation is factored through multi-stack machines: a multitape Turing machine is first simulated by a finite-state machine with two stacks per tape, and any stack machine is compiled into a one-tape Turing machine by a multi-track sweeping construction. Any stack machine also compiles directly into a multitape Turing machine with linear time overhead.

Multitape and one-tape Turing machines

A tape head move μ∈{left,stay,right}\mu \in \{\text{left}, \text{stay}, \text{right}\} has integer head move displacement Δ(μ)∈{−1,0,1}\Delta(\mu) \in \{-1, 0, 1\}, given by Δ(left)=−1\Delta(\text{left}) = -1, Δ(stay)=0\Delta(\text{stay}) = 0, and Δ(right)=1\Delta(\text{right}) = 1.✦

A deterministic multitape Turing machine MM consists of a positive number of tapes a≥1a \ge 1, a number of states q≥3q \ge 3, a tape alphabet size σ≥3\sigma \ge 3, and a transition function δM:{0,…,q−1}×{0,…,σ−1}a→{0,…,q−1}×{0,…,σ−1}a×{left,stay,right}a.\begin{aligned} \delta_M :\; &\{0, \dots, q - 1\} \times \{0, \dots, \sigma - 1\}^a \\ &\to \{0, \dots, q - 1\} \times \{0, \dots, \sigma - 1\}^a \times \{\text{left}, \text{stay}, \text{right}\}^a. \end{aligned}(1)✦ States 00, 11, and 22 are the start, accept, and reject states. Symbol 00 is the blank symbol✦, and the Boolean tape symbol encoding maps 00 to 11 and 11 to 22✦.

A configuration C=(p,h,τ)C = (p, h, \tau) of MM specifies a state p∈{0,…,q−1}p \in \{0, \dots, q - 1\}, head positions h:{0,…,a−1}→ℤh : \{0, \dots, a - 1\} \to \mathbb{Z}, and tape contents τ:{0,…,a−1}×ℤ→{0,…,σ−1}\tau : \{0, \dots, a - 1\} \times \mathbb{Z} \to \{0, \dots, \sigma - 1\}.✦ A configuration is halted if p∈{1,2}p \in \{1, 2\}.✦ Given a binary string w=w0⋯w|w|−1∈{0,1}*w = w_0 \cdots w_{|w|-1} \in \{0, 1\}^*, the initial configuration has state 00, all heads at position 00, tape 00 at cell zz holding the Boolean tape symbol of wzw_z for 0≤z<|w|0 \le z < |w|, and symbol 00 on every other cell of every tape.✦

One transition step of MM leaves a halted configuration unchanged. Otherwise it evaluates δM(p,(τ(i,h(i)))i=0a−1)=(p′,s′,μ′)\delta_M(p, (\tau(i, h(i)))_{i=0}^{a-1}) = (p', s', \mu') from (1), updates the state to p′p', shifts each head position h(i)h(i) to h(i)+Δ(μi′)h(i) + \Delta(\mu'_i), and overwrites cell h(i)h(i) on each tape ii with si′s'_i while leaving all other cells unchanged. Iterating this transition step t∈ℕt \in \mathbb{N} times from the initial configuration produces the execution trace configuration after tt steps.✦ The machine MM halts on ww if its configuration after some tt steps is halted✦, and accepts ww if its state after some tt steps equals 11✦. The running time time⁡(M,w)∈ℕ\operatorname{time}(M, w) \in \mathbb{N} is the least t∈ℕt \in \mathbb{N} such that the configuration of MM on ww after tt steps is halted if MM halts on ww, and 00 otherwise.

A one-tape Turing machine consists of q≥3q \ge 3 states, σ≥3\sigma \ge 3 symbols, and a transition function mapping {0,…,q−1}×{0,…,σ−1}\{0, \dots, q - 1\} \times \{0, \dots, \sigma - 1\} into {0,…,q−1}×{0,…,σ−1}×{left,stay,right}\{0, \dots, q - 1\} \times \{0, \dots, \sigma - 1\} \times \{\text{left}, \text{stay}, \text{right}\}. Embedding a one-tape Turing machine as a multitape Turing machine sets a=1a = 1 and applies its transition function to the scanned symbol of tape 00.✦

Stack machines and multitape compilation

For a positive stack count d≥1d \ge 1, an alphabet size α≥2\alpha \ge 2, and a state count qSq_S, a stack machine command is one of four instructions: transition to a next state p′∈{0,…,qS−1}p' \in \{0, \dots, q_S - 1\}, push a symbol x∈{0,…,α−1}x \in \{0, \dots, \alpha - 1\} onto stack j∈{0,…,d−1}j \in \{0, \dots, d - 1\} and enter state p′p', pop the top symbol from stack jj and enter state p′p', or halt with a Boolean answer b∈{0,1}b \in \{0, 1\}.✦

A stack machine SS consists of d≥1d \ge 1 stacks, an alphabet size α≥2\alpha \ge 2, a state count qSq_S, an initial state p0∈{0,…,qS−1}p_0 \in \{0, \dots, q_S - 1\}, and a transition function δS\delta_S mapping a state p∈{0,…,qS−1}p \in \{0, \dots, q_S - 1\} and a tuple of stack top symbols v:{0,…,d−1}→{0,…,α−1}∪{⊥}v : \{0, \dots, d - 1\} \to \{0, \dots, \alpha - 1\} \cup \{\bot\} (where ⊥\bot marks an empty stack) to a stack machine command.✦

A configuration of SS holds a control state in {0,1}⊔{0,…,qS−1}\{0, 1\} \sqcup \{0, \dots, q_S - 1\} (either a halted Boolean answer or an active state) together with a finite sequence of symbols in {0,…,α−1}*\{0, \dots, \alpha - 1\}^* for each stack j∈{0,…,d−1}j \in \{0, \dots, d - 1\}.✦ On a binary string w∈{0,1}*w \in \{0, 1\}^*, the initial stack configuration has active state p0p_0, stack 00 holding ww under the input-bit encoding (0↦00 \mapsto 0, 1↦11 \mapsto 1) with w0w_0 at the top, and every other stack empty.✦ One stack machine step leaves a halted configuration unchanged; from an active state pp, it reads the top symbol (or ⊥\bot if empty) of each stack and executes the command returned by δS\delta_S: a next-state command updates the state, a push prepends the symbol to the target stack and updates the state, a pop removes the top symbol of the target stack (leaving an empty stack empty) and updates the state, and a halt command sets the state to the halted Boolean answer without altering the stacks. Iterating this step t∈ℕt \in \mathbb{N} times from the initial configuration yields the stack machine configuration after tt steps.✦

The compiled multitape Turing machine STMS^{\mathrm{TM}} has dd tapes, alphabet size α+1\alpha + 1 (where symbol 00 decodes to ⊥\bot and symbol x+1x + 1 decodes to x∈{0,…,α−1}x \in \{0, \dots, \alpha - 1\}), and 3+qS+dαqS3 + q_S + d\alpha q_S states enumerating the three standard Turing machine states {0,1,2}\{0, 1, 2\}, the qSq_S active states of SS, and the dαqSd\alpha q_S pending-push micro-states (j,x,p′)(j, x, p').✦ From start state 00, STMS^{\mathrm{TM}} enters active state p0p_0 without moving any head, while states 11 and 22 remain fixed. From an active state pp, it decodes the dd scanned tape symbols and evaluates δS\delta_S: a next-state command enters p′p' with all heads stationary; a push (j,x,p′)(j, x, p') moves head jj left by 11 into the pending-push micro-state (j,x,p′)(j, x, p'), which on the next step writes x+1x + 1 on tape jj and enters p′p'; a pop (j,p′)(j, p') writes 00 on tape jj, moves head jj right by 11, and enters p′p'; and a halt command with answer bb enters state 11 if b=1b = 1 and state 22 if b=0b = 0.

Sweeping one-tape compilation

A typed one-tape machine over a finite auxiliary state set UU and a finite auxiliary symbol set Σ\Sigma has state set {0,1,2}⊔U\{0, 1, 2\} \sqcup U, symbol set {0,1,2}⊔Σ\{0, 1, 2\} \sqcup \Sigma, and a transition function mapping ({0,1,2}⊔U)×({0,1,2}⊔Σ)(\{0, 1, 2\} \sqcup U) \times (\{0, 1, 2\} \sqcup \Sigma) into ({0,1,2}⊔U)×({0,1,2}⊔Σ)×{left,stay,right}(\{0, 1, 2\} \sqcup U) \times (\{0, 1, 2\} \sqcup \Sigma) \times \{\text{left}, \text{stay}, \text{right}\}. Enumerating its states and symbols compiles it into a one-tape Turing machine with 3+|U|3 + |U| states and 3+|Σ|3 + |\Sigma| symbols.✦

For a stack machine SS with dd stacks, alphabet size α\alpha, and qSq_S states, its sweep tape machine is a typed one-tape machine whose auxiliary symbols are pairs consisting of a bottom-marker bit and a dd-tuple of track entries in {0,…,α−1}∪{⊥}\{0, \dots, \alpha - 1\} \cup \{\bot\}, with the non-bottom all-empty pair represented by the blank symbol 00.✦ Its auxiliary control modes execute two phases. During initialization, from start state 00, the head steps left to place the bottom marker at cell −1-1, then repeatedly scans right to the end of the input word, removes the rightmost input bit by overwriting it with 00, carries that bit left past the bottom marker to the leftmost empty cell on track 00, and returns to the bottom marker; once no input bits remain, the machine enters the step-start mode for p0p_0 at the bottom marker, with stack 00 stored leftward from cell −2-2 and its top at the leftmost occupied cell.

To simulate one step from active state pp at the bottom marker, the sweep tape machine scans left along each track j=0,…,d−1j = 0, \dots, d - 1 in turn until it reaches the first cell empty on track jj, steps right to read the top symbol of stack jj (or ⊥\bot if track jj is empty), and returns to the bottom marker. Once all dd top symbols vv are collected, it dispatches the command δS(p,v)\delta_S(p, v): a next-state command enters the step-start mode for p′p'; a halt command enters state 11 if b=1b = 1 and state 22 if b=0b = 0; a push (j,x,p′)(j, x, p') scans left to the first cell empty on track jj, writes xx on track jj, and returns to the bottom marker in the step-start mode for p′p'; and a pop (j,p′)(j, p') scans left to the first cell empty on track jj, steps right, erases track jj if not at the bottom marker, and returns to the bottom marker in the step-start mode for p′p'. Compiling this typed one-tape machine yields the one-tape Turing machine SoneS^{\mathrm{one}}.✦

Simulating a Turing machine with stacks

A typed stack machine over a finite stack index set II (with a distinguished input stack i0∈Ii_0 \in I), a finite alphabet AA (with an input-bit encoding {0,1}→A\{0, 1\} \to A), and a finite state set QQ (with an initial state) specifies a transition function mapping Q×(I→A∪{⊥})Q \times (I \to A \cup \{\bot\}) to typed stack commands (next state, push, pop, or halt) over (I,A,Q)(I, A, Q).✦ Compiling a typed stack machine into an untyped stack machine enumerates II with i0i_0 at index 00, enlarges the alphabet to size 2+|A|2 + |A| (reserving 00 and 11 for raw input bits decoded through the input-bit encoding, and encoding AA in the remaining |A||A| symbols), enumerates QQ, and translates each command accordingly.✦

Structured typed stack programs over (I,A)(I, A) are built inductively from no-op, constant push, dynamic push (choosing the pushed symbol as a function of the current stack tops), pop, sequential composition, conditional branching on stack tops, and while-loops on stack tops.✦ Each program compiles to a finite state space, an entry state, and a transition function, using command halt redirection to route a subprogram’s halting transitions into a continuation state.

For a deterministic multitape Turing machine MM with aa tapes, qq states, and σ\sigma symbols, its simulating typed stack machine has 2a2a stacks indexed by {0,…,a−1}×{left,right}\{0, \dots, a - 1\} \times \{\text{left}, \text{right}\}, alphabet {0,…,σ−1}\{0, \dots, \sigma - 1\}, input stack (0,right)(0, \text{right}), and MM’s Boolean tape symbol encoding.✦ Its state set consists of the qq states of MM together with the internal states of a step program for each transition payload π=(p′,s′,μ′)\pi = (p', s', \mu').✦ From a state pp of MM, it halts with answer 11 if p=1p = 1 and 00 if p=2p = 2; otherwise it reads the top of each right stack (i,right)(i, \text{right}) (defaulting to the blank symbol 00 if empty), computes π=δM(p,scanned)\pi = \delta_M(p, \text{scanned}), and enters the entry state of the step program for π\pi.✦ That step program sequences a single-tape update across all tapes i=0,…,a−1i = 0, \dots, a - 1 and redirects completion to the next Turing machine state p′p'. Compiling this typed stack machine to an untyped stack machine SMS_M and then to SMoneS_M^{\mathrm{one}} via the sweep tape machine, and embedding SMoneS_M^{\mathrm{one}} as a one-tape Turing machine, yields the embedded one-tape simulation Mˆ\widehat{M}.

The claim

Lemma 5.1. Let MM be a deterministic multitape Turing machine with aa tapes, let w∈{0,1}*w \in \{0, 1\}^* be a binary string of length |w||w|, and let t∈ℕt \in \mathbb{N}. If the configuration of MM on ww after tt steps is halted, then the embedded one-tape simulation Mˆ\widehat{M} halts on ww, accepts ww if and only if MM accepts ww, and satisfies time⁡(Mˆ,w)≤8(2a+1)(|w|+(8a+2)t+2)2.\operatorname{time}(\widehat{M}, w) \le 8(2a + 1)\bigl(|w| + (8a + 2)t + 2\bigr)^2.(2)✦ Furthermore, let SS be a stack machine, let w∈{0,1}*w \in \{0, 1\}^* be a binary string, let t∈ℕt \in \mathbb{N}, and let b∈{0,1}b \in \{0, 1\}. If after tt steps on ww the stack machine SS is in the halted state with answer bb, then its compiled multitape Turing machine STMS^{\mathrm{TM}} halts on ww, accepts ww if and only if b=1b = 1, and satisfies time⁡(STM,w)≤2t+1.\operatorname{time}(S^{\mathrm{TM}}, w) \le 2t + 1.(3)✦

In the paper, the result reads: for every fixed deterministic multitape Turing machine MM (denoted AA in the paper), there is a fixed deterministic one-tape Turing machine Mˆ\widehat{M} (denoted Aˆ\widehat{A}) with the same decisions such that if MM halts after tt steps on an input ww of length |w||w| (denoted TT and mm in the paper), then Mˆ\widehat{M} halts within OM((|w|+t+1)2)O_M((|w| + t + 1)^2) steps on ww.

What is checked

In the Lean library, the two bounds (2) and (3) of Lemma 5.1 are stated over deterministic multitape Turing machines MM (via the embedded one-tape simulation Mˆ\widehat{M} formed by composing the 2a2a-stack simulating machine, its untyped stack compilation, and the multi-track sweep tape machine) and over arbitrary stack machines SS (via the direct dd-tape compilation STMS^{\mathrm{TM}} with pending-push micro-states), for every binary string w∈{0,1}*w \in \{0, 1\}^* and every step count t∈ℕt \in \mathbb{N} at which the simulated machine has halted.