214 Complexity — Wrappers
214.1 Overview
This module provides the output-isolation wrappers of the machine-construction library for multi-tape Turing machines over the Boolean alphabet. It contains the capture transform, under which a host machine simulates a source machine in lockstep while recording the source’s output on one extra work tape and emitting nothing itself; its forwarding dual, under which the source’s output is appended to the host’s own output; the halt-redirect transformation, which runs a machine silently and halts exactly when the last bit it emitted is a designated bit, entering an idle loop otherwise; and a timed conditional, which computes \(x \mapsto f_1(x)\) if \(p(x)\) and \(x \mapsto f_2(x)\) otherwise within a constant multiple of the decider’s running time plus the slower branch’s running time.
214.2 Declarations
Let \(S\) and \(H\) be sets of control states, \(\iota : S \to H\) a map and \(r \in H\) a designated return state. Given an action \(a\) of a Boolean Turing machine with \(k\) work tapes and state set \(S\), its capture transform is the action of a machine with \(k+1\) work tapes and state set \(H\) that moves the input head as \(a\) does and performs \(a\)’s write and head move on each of the first \(k\) work tapes; on the last work tape it writes the bit \(b\) and moves right if \(a\) emits \(b\), and neither writes nor moves if \(a\) emits nothing; it emits nothing on the output tape; and its successor state is \(\iota (q')\) if \(a\) has successor state \(q'\), and \(r\) if \(a\) halts.
Let \(S\) and \(H\) be sets of control states, \(\iota : S \to H\) a map, \(r \in H\) a return state, and \(p\), \(o\) Boolean words. For a configuration \(c\) of a Boolean Turing machine with \(k\) work tapes and state set \(S\) on an input \(x\), with output word \(u\), its capture image is the configuration on \(x\) of a machine with \(k+1\) work tapes and state set \(H\) whose control state is \(\iota (q)\) if \(c\) is in state \(q\) and \(r\) if \(c\) is halted; whose input head and first \(k\) work tapes (contents and head positions) are those of \(c\); whose last work tape holds the word \(pu\) in cells \(0, \dots , |pu|-1\), blank elsewhere, with its head at cell \(|pu|\); and whose output tape holds \(o\).
Let \(S\) and \(H\) be sets of states, \(\iota : S \to H\), \(r \in H\), and \(p\), \(o\) Boolean words. For every action \(a\) and every configuration \(c\) of a Boolean Turing machine with \(k\) work tapes and state set \(S\) on an input \(x\), applying the capture transform of \(a\) to the capture image of \(c\) gives the capture image of the configuration obtained by applying \(a\) to \(c\). Here the capture transform of \(a\) performs \(a\) on the input and the first \(k\) of \(k+1\) work tapes, writes \(a\)’s emitted bit (if any) on the last tape and moves that head right, emits nothing, and maps the successor through \(\iota \) with a halt replaced by \(r\); and the capture image of \(c\) has state \(\iota (q)\) (or \(r\) if \(c\) is halted), the input head and work tapes of \(c\) on the first \(k\) tapes, the word \(p\) followed by the output of \(c\) stored from cell \(0\) of the last tape with that head just past its end, and output \(o\).
Let \(M\) be a Turing machine over the Boolean alphabet with \(k\) work tapes and state set \(S\), let \(N\) be one with \(k+1\) work tapes and state set \(H\), and let \(\iota : S \to H\) and \(r \in H\). Suppose that for every \(s \in S\), every (possibly blank) input symbol \(\sigma \) and every tuple \((w_0, \dots , w_k)\) of work-tape symbols, the transition of \(N\) at \((\iota (s), \sigma , w_0, \dots , w_k)\) is the capture transform of the transition of \(M\) at \((s, \sigma , w_0, \dots , w_{k-1})\): \(M\)’s action on the input and first \(k\) tapes, its emitted bit (if any) written on the last tape followed by a right move, no output, and a halt replaced by entering \(r\). Let \(p\), \(o\) be Boolean words, \(c_0\) a configuration of \(M\) on an input \(x\), and \(t \in \mathbb {N}\) such that \(M\) run from \(c_0\) is not halted at any time \(t' \lt t\); then running \(N\) for \(t\) steps from the capture image of \(c_0\) yields the capture image of the configuration \(M\) reaches after \(t\) steps from \(c_0\), where the capture image of a configuration \(c\) has state \(\iota (q)\) (or \(r\) if \(c\) is halted), the input head and work tapes of \(c\) on the first \(k\) tapes, the word \(p\) followed by the output of \(c\) stored from cell \(0\) of the last tape with that head just past its end, and output \(o\).
Let \(S\) and \(H\) be sets of control states, \(\iota : S \to H\) a map and \(r \in H\) a designated return state. Given an action \(a\) of a Boolean Turing machine with \(k\) work tapes and state set \(S\), its forwarding transform is the action of a machine with the same \(k\) work tapes and state set \(H\) that has the same input-head move, the same writes and head moves on every work tape, and the same emitted bit (if any) as \(a\), and whose successor state is \(\iota (q')\) if \(a\) has successor state \(q'\), and \(r\) if \(a\) halts.
Let \(S\) and \(H\) be sets of control states, \(\iota : S \to H\) a map, \(r \in H\) a return state, and \(p\) a Boolean word. For a configuration \(c\) of a Boolean Turing machine with \(k\) work tapes and state set \(S\) on an input \(x\), its forwarding image is the configuration on \(x\) of a machine with \(k\) work tapes and state set \(H\) whose control state is \(\iota (q)\) if \(c\) is in state \(q\) and \(r\) if \(c\) is halted, whose input-head position, work-tape contents and work-head positions are those of \(c\), and whose output tape holds \(p\) followed by the output of \(c\).
Let \(S\) and \(H\) be sets of states, \(\iota : S \to H\), \(r \in H\), and \(p\) a Boolean word. For every action \(a\) and every configuration \(c\) of a Boolean Turing machine with \(k\) work tapes and state set \(S\) on an input \(x\), applying the forwarding transform of \(a\) (same head moves, writes and emission as \(a\), successor mapped through \(\iota \), a halt replaced by \(r\)) to the forwarding image of \(c\) (state mapped through \(\iota \), or \(r\) if \(c\) is halted, the same tapes and heads, output \(p\) followed by the output of \(c\)) gives the forwarding image of the configuration obtained by applying \(a\) to \(c\).
Let \(M\) and \(N\) be Turing machines over the Boolean alphabet with \(k\) work tapes each and state sets \(S\) and \(H\), and let \(\iota : S \to H\) and \(r \in H\). Suppose that for every \(s \in S\), every (possibly blank) input symbol \(\sigma \) and every tuple \(w\) of \(k\) work-tape symbols, the transition of \(N\) at \((\iota (s), \sigma , w)\) is the forwarding transform of the transition of \(M\) at \((s, \sigma , w)\): the same head moves, writes and emission, with the successor mapped through \(\iota \) and a halt replaced by entering \(r\). Let \(p\) be a Boolean word, \(c_0\) a configuration of \(M\) on an input \(x\), and \(t \in \mathbb {N}\) such that \(M\) run from \(c_0\) is not halted at any time \(t' \lt t\); then running \(N\) for \(t\) steps from the forwarding image of \(c_0\) yields the forwarding image of the configuration \(M\) reaches after \(t\) steps from \(c_0\), where the forwarding image of a configuration \(c\) has state \(\iota (q)\) (or \(r\) if \(c\) is halted), the input head, work tapes and work heads of \(c\), and output \(p\) followed by the output of \(c\).
Let \(M\) be a Turing machine over the Boolean alphabet with finitely many states, state set \(Q\), initial state \(q_0\) and \(k\) work tapes, and let \(b\) be a bit. The halt-redirected machine of \(M\) and \(b\) has \(k\) work tapes, control states the pairs \((s, \rho )\) with \(s \in Q\) and \(\rho \) either a bit or empty, together with one loop state \(\ell \), and initial state \((q_0, \text{empty})\). In state \((s, \rho )\) it performs \(M\)’s input move and work-tape writes and moves at \(s\) but emits nothing, updates the register to \(\rho '\), the bit \(M\) emits if there is one and \(\rho \) otherwise, and enters \((s', \rho ')\) if \(M\) moves to state \(s'\), while if \(M\) halts it halts when \(\rho ' = b\) and enters \(\ell \) otherwise; in state \(\ell \) it moves no head, writes and emits nothing, and stays in \(\ell \).
Let \(S\) be a set of states, \(b\) a bit, \(q\) either a state in \(S\) or the halting marker, and \(\rho \) either a bit or empty. The redirected control state, an optional element of \((S \times \{ \text{empty}, \mathrm{false}, \mathrm{true}\} ) \sqcup \{ \ell \} \), is the simulation state \((s, \rho )\) if \(q = s \in S\); if \(q\) is the halting marker, it is the halting marker when \(\rho = b\) (so never when \(\rho \) is empty) and the loop state \(\ell \) otherwise.
Let \(S\) be a set of states, \(b\) a bit, \(a\) an action of a Boolean Turing machine with \(k\) work tapes and state set \(S\), and \(\rho \) either a bit or empty. Let \(\rho '\) be the bit \(a\) emits if there is one, and \(\rho \) otherwise. The redirected action is the action on \(k\) work tapes with state set \((S \times \{ \text{empty}, \mathrm{false}, \mathrm{true}\} ) \sqcup \{ \ell \} \) that has the same input move and work-tape writes and moves as \(a\), emits nothing, and has successor \((s', \rho ')\) if \(a\) has successor \(s'\), while if \(a\) halts it halts when \(\rho ' = b\) and enters the loop state \(\ell \) otherwise.
Let \(M\) be a finite-state Turing machine over the Boolean alphabet and \(b\) a bit, and consider the halt-redirected machine of \(M\) and \(b\), which simulates \(M\) silently while recording the last bit \(M\) has emitted, halts when \(M\) halts with that bit equal to \(b\), and otherwise enters an idle loop state \(\ell \). For a configuration \(c\) of \(M\) on an input \(x\), let \(\rho \) be the last bit of the output of \(c\) (empty if that output is empty); the redirected image of \(c\) is the configuration of the halt-redirected machine on \(x\) with the input head, work tapes and work heads of \(c\), empty output, and control state \((q, \rho )\) if \(c\) is in state \(q\), while if \(c\) is halted it is halted when \(\rho = b\) and in \(\ell \) otherwise.
Let \(M\) be a finite-state Turing machine over the Boolean alphabet and \(b\) a bit, and consider the halt-redirected machine of \(M\) and \(b\), which simulates \(M\) silently while recording the last bit \(M\) has emitted, halts when \(M\) halts with that bit equal to \(b\), and otherwise enters a loop state \(\ell \). For every configuration \(c\) of the halt-redirected machine on an input \(x\) whose control state is \(\ell \), and every \(t \in \mathbb {N}\), running the halt-redirected machine for \(t\) steps from \(c\) returns exactly \(c\).
Let \(M\) be a finite-state Turing machine over the Boolean alphabet with \(k\) work tapes, \(b\) a bit, \(c\) a configuration of \(M\) on an input \(x\), \(a\) an action of \(M\), and \(\rho \) the last bit of the output of \(c\) (empty if that output is empty). Applying the redirected action of \(a\) with register \(\rho \) (the moves and writes of \(a\), no emission, register updated to \(a\)’s emitted bit if any, and on a halt of \(a\) either halting when the updated register equals \(b\) or entering the loop state otherwise) to the redirected image of \(c\) (the tapes and heads of \(c\), empty output, and state determined by \(c\)’s state and the last bit of its output in the same way) gives the redirected image of the configuration obtained by applying \(a\) to \(c\).
Let \(M\) be a finite-state Turing machine over the Boolean alphabet and \(b\) a bit, and consider the halt-redirected machine of \(M\) and \(b\), which simulates \(M\) silently while recording the last bit \(M\) has emitted, halts when \(M\) halts with that bit equal to \(b\), and otherwise enters an idle loop state. For a configuration \(c\) of \(M\) on an input \(x\), let its redirected image carry the tapes and heads of \(c\), empty output, and the state \((q, \rho )\) when \(c\) is in state \(q\) and \(\rho \) is the last bit of its output (empty if none), or, when \(c\) is halted, the halting state if \(\rho = b\) and the loop state otherwise. Then for every such \(c\), halted or not, one step of the halt-redirected machine from the redirected image of \(c\) gives the redirected image of one step of \(M\) from \(c\).
Let \(M\) be a finite-state Turing machine over the Boolean alphabet and \(b\) a bit, and consider the halt-redirected machine of \(M\) and \(b\), which simulates \(M\) silently while recording the last bit \(M\) has emitted, halts when \(M\) halts with that bit equal to \(b\), and otherwise enters an idle loop state. For every input \(x\) and every \(t \in \mathbb {N}\), the configuration of the halt-redirected machine after \(t\) steps from its initial configuration on \(x\) is the redirected image of the configuration of \(M\) after \(t\) steps from its initial configuration on \(x\): the same tapes and heads, empty output, and state \((q, \rho )\) if \(M\) is in state \(q\) and the last bit it has emitted is \(\rho \) (empty if none), or, if \(M\) has halted, halted when \(\rho = b\) and in the loop state otherwise.
Let \(M\) be a finite-state Turing machine over the Boolean alphabet, \(b\) a bit, \(x\) and \(w\) Boolean words, and \(t \in \mathbb {N}\). Consider the halt-redirected machine of \(M\) and \(b\), which simulates \(M\) without emitting anything while recording the last bit \(M\) has emitted, halts when \(M\) halts with that bit equal to \(b\), and otherwise enters an idle loop state. If \(M\) on input \(x\) halts within \(t\) steps with output \(w\), and \(w\) is nonempty with last bit \(b\), then the halt-redirected machine on input \(x\) halts within \(t\) steps with empty output.
Let \(M\) be a finite-state Turing machine over the Boolean alphabet, \(b\) a bit, \(x\) and \(w\) Boolean words, and \(t \in \mathbb {N}\). Consider the halt-redirected machine of \(M\) and \(b\), which simulates \(M\) without emitting anything while recording the last bit \(M\) has emitted, halts when \(M\) halts with that bit equal to \(b\), and otherwise enters an idle loop state. If \(M\) on input \(x\) halts within \(t\) steps with output \(w\), and either \(w\) is empty or its last bit differs from \(b\), then for every \(u \in \mathbb {N}\) the halt-redirected machine, run for \(u\) steps from its initial configuration on \(x\), is not halted.
Let \(D\) be a finite-state Turing machine over the Boolean alphabet with \(k\) work tapes, state set \(Q\) and initial state \(q_0\), and let \(m \in \mathbb {N}\). The padded machine has \(k + m\) work tapes, state set \(Q\) and initial state \(q_0\); in state \(q\), reading input symbol \(\sigma \) and work-tape symbols \(w_0, \dots , w_{k+m-1}\), it performs \(D\)’s action at \((q, \sigma , w_0, \dots , w_{k-1})\) on the input head and the first \(k\) work tapes, with the same emission and successor state, while writing nothing on the last \(m\) work tapes and keeping their heads still.
Let \(D\), \(M_1\), \(M_2\) be finite-state Turing machines over the Boolean alphabet with \(k_D\), \(k_1\), \(k_2\) work tapes and state sets \(Q_D\), \(Q_1\), \(Q_2\). The timed conditional controller has \(k_D + k_1 + k_2 + 1\) work tapes, split into a decider block of \(k_D\) tapes, a branch block of \(k_1 + k_2\) tapes and one capture tape; its states are those of \(Q_D\), two administrative states (back and read), a rewind-start and a rewind-scan state for each bit \(\beta \), and those of \(Q_1 \sqcup Q_2\); and its initial state is \(D\)’s. In a state of \(D\) it performs \(D\)’s transition on the input and the decider block, writes \(D\)’s emitted bit (if any) on the capture tape and moves that head right, emits nothing, leaves the branch block idle, and enters the back state where \(D\) would halt; the back state moves the capture head one cell left and enters the read state; the read state reads the bit \(\beta \) under the capture head (\(\mathrm{false}\) if blank) and enters rewind-start for \(\beta \); rewind-start moves the input head left and enters rewind-scan; rewind-scan keeps moving the input head left while it reads an input symbol and, on reading the blank boundary, moves right and enters the initial state of \(M_1\) if \(\beta \) is \(\mathrm{true}\) and of \(M_2\) otherwise (all four administrative states writing and emitting nothing and keeping the other heads still); and in a state of \(M_i\) it performs \(M_i\)’s transition, including its emission and halting, on the input and on \(M_i\)’s own \(k_i\) tapes within the branch block, leaving all other work tapes idle.
Let \(D\), \(M_1\), \(M_2\) be finite-state Turing machines over the Boolean alphabet with \(k_D\), \(k_1\), \(k_2\) work tapes, and consider the timed conditional controller for them, whose work tapes form a decider block of \(k_D\) tapes, a branch block of \(k_1 + k_2\) tapes and one capture tape, and whose states include a copy of the states of \(M_1\) and \(M_2\). Let \(c\) be a configuration on an input \(x\) of the two-branch union machine (which runs \(M_1\) on the first \(k_1\) and \(M_2\) on the last \(k_2\) of its \(k_1 + k_2\) work tapes, according to whether its state belongs to \(M_1\) or \(M_2\)), let \(\tau \) and \(h\) be contents and head positions for \(k_D\) tapes, and let \(\beta \) be a bit. The branch-phase configuration is the controller configuration on \(x\) whose state is the copy of \(c\)’s state (halted if \(c\) is halted), whose input head and output are those of \(c\), whose decider block holds \(\tau \) with heads \(h\), whose branch block holds \(c\)’s work tapes and heads, and whose capture tape holds the bit \(\beta \) in cell \(0\), blank elsewhere, with its head at cell \(0\).
Let \(D\), \(M_1\), \(M_2\) be finite-state Turing machines over the Boolean alphabet with \(k_D\), \(k_1\), \(k_2\) work tapes, and consider the timed conditional controller for them, whose work tapes form a decider block of \(k_D\) tapes, a branch block of \(k_1 + k_2\) tapes and one capture tape, and whose states include a copy of the states of \(D\) and an administrative back state. For a configuration \(c\) of \(D\) on an input \(x\), with output \(u\), the decider-phase configuration is the controller configuration on \(x\) whose state is the copy of \(c\)’s state, or the back state if \(c\) is halted; whose input head is that of \(c\); whose decider block holds \(c\)’s work tapes and heads; whose branch block is blank with every head at cell \(0\); whose capture tape holds \(u\) in cells \(0, \dots , |u|-1\), blank elsewhere, with its head at cell \(|u|\); and whose output is empty.
Let \(D\), \(M_1\), \(M_2\) be finite-state Turing machines over the Boolean alphabet, and consider the timed conditional controller for them, which first runs \(D\) silently on a decider block of tapes while copying \(D\)’s output onto a capture tape. Let \(c\) be a configuration of \(D\) on an input \(x\) and \(t \in \mathbb {N}\) such that \(D\) run from \(c\) is not halted at any time \(s \lt t\). Then running the controller for \(t\) steps from the decider-phase configuration of \(c\) (state of \(c\), or the back state if \(c\) is halted; \(c\)’s input head, work tapes and heads on the decider block; a blank branch block; \(c\)’s output stored from cell \(0\) of the capture tape with that head just past it; empty output) yields the decider-phase configuration of the configuration \(D\) reaches after \(t\) steps from \(c\).
Let \(D\), \(M_1\), \(M_2\) be finite-state Turing machines over the Boolean alphabet, and consider the timed conditional controller for them, with a decider block, a branch block and a capture tape as work tapes. For every input \(x\), the initial configuration of the controller on \(x\) equals the decider-phase configuration of \(D\)’s initial configuration on \(x\): \(D\)’s initial state, the initial input-head position, every work tape of all three blocks blank with its head at cell \(0\), and empty output.
Let \(D\), \(M_1\), \(M_2\) be finite-state Turing machines over the Boolean alphabet with \(k_D\), \(k_1\), \(k_2\) work tapes, consider the timed conditional controller for them, and for a bit \(\beta \) consider the two-branch union machine that runs \(M_1\) or \(M_2\) on disjoint blocks of \(k_1\) and \(k_2\) work tapes and starts in the initial state of \(M_1\) if \(\beta \) is \(\mathrm{true}\) and of \(M_2\) otherwise. Let \(c\) be a configuration of the union machine on an input \(x\), \(\tau \) and \(h\) contents and head positions for \(k_D\) tapes, and \(t \in \mathbb {N}\). Then running the controller for \(t\) steps from the branch-phase configuration of \((c, \tau , h, \beta )\) (the state, input head, output and work tapes of \(c\) on the branch block, \(\tau \) and \(h\) on the decider block, and the bit \(\beta \) in cell \(0\) of the capture tape with that head at cell \(0\)) yields the branch-phase configuration of \((c', \tau , h, \beta )\), where \(c'\) is the configuration the union machine reaches after \(t\) steps from \(c\).
Let \(D\), \(M_1\), \(M_2\) be finite-state Turing machines over the Boolean alphabet, and consider the timed conditional controller for them, whose work tapes form a decider block, a branch block and a capture tape, and whose states include a rewind-start state for each bit. For a configuration \(c\) of \(D\) on an input \(x\) and a bit \(\beta \), the ready-to-rewind configuration is the controller configuration on \(x\) in the rewind-start state for \(\beta \), with the input head of \(c\), the decider block holding \(c\)’s work tapes and heads, the branch block blank with every head at cell \(0\), the capture tape holding the bit \(\beta \) in cell \(0\), blank elsewhere, with its head at cell \(0\), and empty output.
Let \(D\), \(M_1\), \(M_2\) be finite-state Turing machines over the Boolean alphabet, and consider the timed conditional controller for them, with a decider block, a branch block and a capture tape as work tapes. Let \(c\) be a halted configuration of \(D\) on an input \(x\) whose output is the one-bit word \(\beta \). Then two steps of the controller from the decider-phase configuration of \(c\) (in the back state, with \(c\)’s input head and work tapes on the decider block, a blank branch block, \(\beta \) in cell \(0\) of the capture tape with that head at cell \(1\), and empty output) reach the ready-to-rewind configuration of \(c\) and \(\beta \), which differs only in being in the rewind-start state for \(\beta \) with the capture head at cell \(0\).
Let \(D\), \(M_1\), \(M_2\) be finite-state Turing machines over the Boolean alphabet with \(k_D\), \(k_1\), \(k_2\) work tapes, consider the timed conditional controller for them, let \(x\) be a Boolean word, \(\beta \) a bit and \(T \in \mathbb {N}\), and suppose \(D\) on input \(x\) halts within \(T\) steps with output the one-bit word \(\beta \). Then there exist \(a \le 2T + 5\) and contents \(\tau \) and head positions \(h\) for \(k_D\) tapes such that after \(a\) steps from its initial configuration on \(x\) the controller is in the branch-phase configuration built from the initial configuration on \(x\) of the two-branch union machine selecting \(\beta \): in the copy of the initial state of \(M_1\) if \(\beta \) is \(\mathrm{true}\) and of \(M_2\) otherwise, with the initial input-head position, a blank branch block with every head at cell \(0\), the decider block holding \(\tau \) with heads \(h\), the bit \(\beta \) in cell \(0\) of the capture tape with that head at cell \(0\), and empty output.
Let \(D\), \(M_1\), \(M_2\) be finite-state Turing machines over the Boolean alphabet, let \(p\) be a Boolean predicate on Boolean words, \(f_1\) and \(f_2\) functions from Boolean words to Boolean words, and \(T_0, T_1, T_2 : \mathbb {N} \to \mathbb {N}\). Suppose that on every input \(x\), \(D\) halts within \(T_0(|x|)\) steps with output the one-bit word \(p(x)\), \(M_1\) halts within \(T_1(|x|)\) steps with output \(f_1(x)\), and \(M_2\) halts within \(T_2(|x|)\) steps with output \(f_2(x)\). Then there exist a finite-state Turing machine \(M\) over the Boolean alphabet and a constant \(c \in \mathbb {N}\) such that on every input \(x\), \(M\) halts within \(c \cdot (T_0(|x|) + \max (T_1(|x|), T_2(|x|)) + 1)\) steps with output \(f_1(x)\) if \(p(x)\) holds and \(f_2(x)\) otherwise.