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 has integer head move displacement , given by , , and .✦
A deterministic multitape Turing machine consists of a positive number of tapes , a number of states , a tape alphabet size , and a transition function (1)✦ States , , and are the start, accept, and reject states. Symbol is the blank symbol✦, and the Boolean tape symbol encoding maps to and to ✦.
A configuration of specifies a state , head positions , and tape contents .✦ A configuration is halted if .✦ Given a binary string , the initial configuration has state , all heads at position , tape at cell holding the Boolean tape symbol of for , and symbol on every other cell of every tape.✦
One transition step of leaves a halted configuration unchanged. Otherwise it evaluates from (1), updates the state to , shifts each head position to , and overwrites cell on each tape with while leaving all other cells unchanged. Iterating this transition step times from the initial configuration produces the execution trace configuration after steps.✦ The machine halts on if its configuration after some steps is halted✦, and accepts if its state after some steps equals ✦. The running time is the least such that the configuration of on after steps is halted if halts on , and otherwise.
A one-tape Turing machine consists of states, symbols, and a transition function mapping into . Embedding a one-tape Turing machine as a multitape Turing machine sets and applies its transition function to the scanned symbol of tape .✦
Stack machines and multitape compilation
For a positive stack count , an alphabet size , and a state count , a stack machine command is one of four instructions: transition to a next state , push a symbol onto stack and enter state , pop the top symbol from stack and enter state , or halt with a Boolean answer .✦
A stack machine consists of stacks, an alphabet size , a state count , an initial state , and a transition function mapping a state and a tuple of stack top symbols (where marks an empty stack) to a stack machine command.✦
A configuration of holds a control state in (either a halted Boolean answer or an active state) together with a finite sequence of symbols in for each stack .✦ On a binary string , the initial stack configuration has active state , stack holding under the input-bit encoding (, ) with at the top, and every other stack empty.✦ One stack machine step leaves a halted configuration unchanged; from an active state , it reads the top symbol (or if empty) of each stack and executes the command returned by : 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 times from the initial configuration yields the stack machine configuration after steps.✦
The compiled multitape Turing machine has tapes, alphabet size (where symbol decodes to and symbol decodes to ), and states enumerating the three standard Turing machine states , the active states of , and the pending-push micro-states .✦ From start state , enters active state without moving any head, while states and remain fixed. From an active state , it decodes the scanned tape symbols and evaluates : a next-state command enters with all heads stationary; a push moves head left by into the pending-push micro-state , which on the next step writes on tape and enters ; a pop writes on tape , moves head right by , and enters ; and a halt command with answer enters state if and state if .
Sweeping one-tape compilation
A typed one-tape machine over a finite auxiliary state set and a finite auxiliary symbol set has state set , symbol set , and a transition function mapping into . Enumerating its states and symbols compiles it into a one-tape Turing machine with states and symbols.✦
For a stack machine with stacks, alphabet size , and states, its sweep tape machine is a typed one-tape machine whose auxiliary symbols are pairs consisting of a bottom-marker bit and a -tuple of track entries in , with the non-bottom all-empty pair represented by the blank symbol .✦ Its auxiliary control modes execute two phases. During initialization, from start state , the head steps left to place the bottom marker at cell , then repeatedly scans right to the end of the input word, removes the rightmost input bit by overwriting it with , carries that bit left past the bottom marker to the leftmost empty cell on track , and returns to the bottom marker; once no input bits remain, the machine enters the step-start mode for at the bottom marker, with stack stored leftward from cell and its top at the leftmost occupied cell.
To simulate one step from active state at the bottom marker, the sweep tape machine scans left along each track in turn until it reaches the first cell empty on track , steps right to read the top symbol of stack (or if track is empty), and returns to the bottom marker. Once all top symbols are collected, it dispatches the command : a next-state command enters the step-start mode for ; a halt command enters state if and state if ; a push scans left to the first cell empty on track , writes on track , and returns to the bottom marker in the step-start mode for ; and a pop scans left to the first cell empty on track , steps right, erases track if not at the bottom marker, and returns to the bottom marker in the step-start mode for . Compiling this typed one-tape machine yields the one-tape Turing machine .✦
Simulating a Turing machine with stacks
A typed stack machine over a finite stack index set (with a distinguished input stack ), a finite alphabet (with an input-bit encoding ), and a finite state set (with an initial state) specifies a transition function mapping to typed stack commands (next state, push, pop, or halt) over .✦ Compiling a typed stack machine into an untyped stack machine enumerates with at index , enlarges the alphabet to size (reserving and for raw input bits decoded through the input-bit encoding, and encoding in the remaining symbols), enumerates , and translates each command accordingly.✦
Structured typed stack programs over 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 with tapes, states, and symbols, its simulating typed stack machine has stacks indexed by , alphabet , input stack , and ’s Boolean tape symbol encoding.✦ Its state set consists of the states of together with the internal states of a step program for each transition payload .✦ From a state of , it halts with answer if and if ; otherwise it reads the top of each right stack (defaulting to the blank symbol if empty), computes , and enters the entry state of the step program for .✦ That step program sequences a single-tape update across all tapes and redirects completion to the next Turing machine state . Compiling this typed stack machine to an untyped stack machine and then to via the sweep tape machine, and embedding as a one-tape Turing machine, yields the embedded one-tape simulation .
The claim
Lemma 5.1. Let be a deterministic multitape Turing machine with tapes, let be a binary string of length , and let . If the configuration of on after steps is halted, then the embedded one-tape simulation halts on , accepts if and only if accepts , and satisfies (2)✦ Furthermore, let be a stack machine, let be a binary string, let , and let . If after steps on the stack machine is in the halted state with answer , then its compiled multitape Turing machine halts on , accepts if and only if , and satisfies (3)✦
In the paper, the result reads: for every fixed deterministic multitape Turing machine (denoted in the paper), there is a fixed deterministic one-tape Turing machine (denoted ) with the same decisions such that if halts after steps on an input of length (denoted and in the paper), then halts within steps on .
What is checked
In the Lean library, the two bounds (2) and (3) of Lemma 5.1 are stated over deterministic multitape Turing machines (via the embedded one-tape simulation formed by composing the -stack simulating machine, its untyped stack compilation, and the multi-track sweep tape machine) and over arbitrary stack machines (via the direct -tape compilation with pending-push micro-states), for every binary string and every step count at which the simulated machine has halted.