[go: up one dir, main page]

Academia.eduAcademia.edu
Journal of Complexity ( ) – Contents lists available at ScienceDirect Journal of Complexity journal homepage: www.elsevier.com/locate/jco Wang’s B machines are efficiently universal, as is Hasenjaeger’s small universal electromechanical toy✩ Turlough Neary a , Damien Woods b , Niall Murphy c,d,∗ , Rainer Glaschick e a Institute for Neuroinformatics, University of Zürich & ETH Zürich, Switzerland b California Institute of Technology, Pasadena, CA 91125, USA c Facultad de Informática, Universidad Politécnica de Madrid & CEI-Moncloa UPM-UCM, Spain d Microsoft Research, Cambridge, CB1 2FB, UK1 e Paderborn, Germany article info Article history: Received 29 September 2013 Accepted 31 January 2014 Available online xxxx Keywords: Polynomial time Computational complexity Small universal Turing machines Wang’s B machine Non-erasing Turing machines Models of computation abstract In the 1960s Gisbert Hasenjaeger built Turing Machines from electromechanical relays and uniselectors. Recently, Glaschick reverse engineered the program of one of these machines and found that it is a universal Turing machine. In fact, its program uses only four states and two symbols, making it a very small universal Turing machine. (The machine has three tapes and a number of other features that are important to keep in mind when comparing it to other small universal machines.) Hasenjaeger’s machine simulates Hao Wang’s B machines, which were proved universal by Wang. Unfortunately, Wang’s original simulation algorithm suffers from an exponential slowdown when simulating Turing machines. Hence, via this simulation, Hasenjaeger’s machine also has an exponential slowdown when simulating Turing machines. In this work, we give a new efficient simulation algorithm for Wang’s B machines by showing that they simulate Turing machines with only a polynomial slowdown. As a second result, we find that Hasenjaeger’s ✩ This work is the outcome of a visit by the authors to the Isaac Newton Institute for Mathematical Sciences in Cambridge (UK) for the centenary of Alan Turing’s birth, hosted by the 2012 program ‘‘Semantics and Syntax: A Legacy of Alan Turing’. ∗ Corresponding author at: Microsoft Research, Cambridge, CB1 2FB, UK. E-mail addresses: tneary@ini.phys.ethz.ch (T. Neary), woods@caltech.edu (D. Woods), a-nimurp@microsoft.com (N. Murphy), rainer@glaschick-pb.de (R. Glaschick). 1 Present affiliation. http://dx.doi.org/10.1016/j.jco.2014.02.003 0885-064X/© 2014 Elsevier Inc. All rights reserved. 2 T. Neary et al. / Journal of Complexity ( ) – machine also efficiently simulates Turing machines in polynomial time. Thus, Hasenjaeger’s machine is both small and fast. In another application of our result, we show that Hooper’s small universal Turing machine simulates Turing machines in polynomial time, an exponential improvement. © 2014 Elsevier Inc. All rights reserved. 1. Introduction In the 1960s Gisbert Hasenjaeger built Turing Machines from electromechanical relays and uniselectors, but never published details of these machines. Recently, Hasenjaeger’s family donated the machine shown in Fig. 1 to the Heinz Nixdorf MuseumsForum.2 At the request of the MuseumsForum, Glaschick reverse engineered the table of behavior for this machine [3,1], and, using Hasenjaeger’s notes [4], determined the machine’s encoding and operation. It was found that Hasenjaeger’s machine simulates Wang’s B machines [15]. Wang used a unary encoding when proving his B machines universal and hence they suffer from an exponential slowdown when simulating Turing machines. As a result, Hasenjaeger’s machine also suffers from an exponential slowdown. In this work, we show that Wang B machines and Hasenjaeger’s machine simulate Turing machines with polynomial slowdown via the following chain of simulations: Turing Machine → non-erasing Turing Machine → Wang B machine → Hasenjaeger’s universal Turing Machine where A → B denotes that A is simulated by B. With the exception of the Wang B machine simulation of non-erasing machines, all of the simulations in the above chain are known to be efficient: nonerasing Turing machines simulate Turing machines with a polynomial slowdown in time [17], and Hasenjaeger’s machine simulates Wang B machines in linear time. We complete the chain of efficient simulations by giving a new simulation algorithm that shows that Wang’s B machines simulate Turing machines with only a polynomial slowdown in the simulated Turing machine’s time. An immediate consequence of our new algorithm is that Hasenjaeger’s machine also simulates Turing machines in polynomial time. This adds to the growing body of work [16,11,12] showing that the simplest known universal models of computation need not suffer from a exponential slowdown. As mentioned above, the simulation of Turing machines by non-erasing Turing machines is already known to run with a polynomial slowdown [17]. However, to keep our paper self-contained, we give our own polynomial (cubic) time simulation in Section 2. This is followed by our main result in Section 3, where we show that Wang B machines simulate non-erasing Turing machines in linear time. So from Sections 2 and 3 we get Theorem 1. Theorem 1. Let M be a deterministic Turing machine with a single binary tape that runs in time t. Then there is a Wang B machine WM that simulates the computation of M in time O(t 3 ). In Section 4 we give a formal description of Hasenjaeger’s Turing machine and, for the sake of completeness, we show that Hasenjaeger’s machine simulates Wang B machines in linear time. So from Theorem 1 and Section 4 we get that Hasenjaeger’s machine is an efficient polynomial time simulator of Turing machines: Theorem 2. Let M be a deterministic Turing machine with a single binary tape that computes in time t. Hasenjaeger’s universal Turing machine simulates the computation of M in time O(t 3 ). 2 Heinz Nixdorf MuseumsForum, Paderborn, Germany. http://www.hnf.de/. T. Neary et al. / Journal of Complexity ( ) – 3 Fig. 1. Hasenjaeger’s universal electromechanical Turing machine. The wiring in the control unit encodes a universal program, that uses only four states and two symbols, for simulating Wang B machines. The program of a Wang B machine may be stored on the program tape. There are two additional tapes which are used for the simulation, a counter tape and a work tape. In Section 5 we apply Theorem 1 to show that a small universal Turing machine of Hooper’s [5,6] is efficiently universal by showing that it simulates Turing machines (via Wang B machines) in polynomial time. For the remainder of this section we discuss program-size in small universal Turing machines. Hasenjaeger’s machine has 4 states and 2 symbols, making it a remarkably small universal program. However, it uses 3 non-erasable tapes, and so making direct comparisons with other Turing machine models that have small universal programs (but have more or less tapes, tape dimensions, etc.) is not a straightforward matter. The standard model in the small universal Turing machine world consists of a single one dimensional tape with one tape head, a deterministic program, and the usual notion of a blank symbol [12]. Other more general models use larger numbers of tapes, higher tape dimensions, infinitely repeated blank words instead of a repeated blank symbol, and so on, and these more general models often have smaller universal programs. In the absence of formal tools, namely tight program-size overheads for simulations between these models, comparisons between them is at best challenging. Glaschick is the most recent author to propose a formula to compare such models [2]. As an example of the difficulty of comparing different Turing machine models, consider one of Priese’s [14] universal machines. Priese’s universal machine has 2 states, 2 symbols, a single 2dimensional tape with 2 tape heads, and uses an unconventional technique for ending its computation.3 However, for standard 2-state, 2-symbol machines it is known that no universal machines exist as their halting problem is decidable [7,13]. So, by generalizing aspects of the model, Priese found a machine model whose smallest universal programs have strictly less states and symbols than those of the standard model. Returning our attention to Hasenjaeger’s model, we note that while his machine has 3 tapes, the size of his program is still impressive when one considers that 2 tapes are read-only and the work tape is non-erasing. For more recent results on small non-erasing Turing machines one can look to the work of Margenstern [8,9] where he constructs small non-erasing single-tape machines and gives boundaries between universality and non-universality for various parameters in the model. More on the topic of small universal Turing machines can be found in the surveys [10,12]. 3 Priese’s machine does not end its computation using the standard method of halting on a state-symbol pair that has no transition rule: instead there is a choice, via the initial input encoding, of ending a computation either by entering a sequence of 6 repeating configurations or by halting when an attempt is made to move off the edge of the 2D tape. 4 T. Neary et al. / Journal of Complexity ( ) – 2. Non-erasing Turing machines simulate Turing machines in time O(t 3 ) Definition 3 (Binary Turing Machine). A binary Turing machine is a tuple M = (Q , {0, 1}, f , q0 , q|Q |−1 ). Here Q and {0, 1} are the finite sets of states and tape symbols respectively. 0 is the blank symbol, q0 ∈ Q is the start state, and q|Q |−1 ∈ Q is the halt state. The transition function f is of the form f : Q × {0, 1} → {0, 1} × {L, R} × Q and is undefined on {q|Q |−1 } × {0, 1}. We write f as a list of transition rules. Each transition rule is a quintuple (qi , x1 , x2 , D, qj ) with initial state qi ∈ Q , read symbol x1 ∈ {0, 1}, write symbol x2 ∈ {0, 1}, move direction D ∈ {L, R}, and next state qj ∈ Q . Definition 4 (Non-Erasing Turing Machine). A non-erasing Turing machine is a binary Turing machine where there are no transition rules that overwrite 1 with 0, that is, there is no transition rule of the form (qj , 1, 0, D, qk ), where qj , qk ∈ Q and D ∈ {L, R}. Lemma 5 (Zykin [17]). Let M be a deterministic single-tape binary Turing machine that runs in time t. Then there is a deterministic non-erasing Turing machine NM that simulates the computation of M in time O(t 3 ). Proof. We give a brief overview of how M is simulated by a deterministic non-erasing Turing machine NM with a single tape in time O(t 3 ). An arbitrary tape of M is encoded for NM as follows. Each symbol on the tape of M is encoded as three contiguous symbols on the tape of NM . The two rightmost symbols of each triple encode 0 and 1 as 10 and 01 respectively. The leftmost symbol of the triple is 1 if and only if NM is simulating that M ’s tape head is currently reading the symbol encoded by the pair immediately to its right. To simulate a timestep of M , NM simply makes a new copy of the encoded tape of M (to the right of the original), by scanning over and back repeatedly. During the copying process the encoded tape contents are appropriately modified to simulate the transition rule of M . This involves simulating the tape head movement of M by copying the 1 that encodes the tape head position of M to the left of the pair of symbols encoding the new read symbol. If we are simulating a rule where M changes a bit under its tape head, then the encoded read symbol (i.e. the triple) is appropriately changed by NM as it is being copied. The state-changes of M can be simulated by statechanges of NM in a straight-forward manner. Since M runs in time t, it uses at most t tape cells. Thus, NM takes O(t 2 ) steps when copying the encoding of an arbitrary configuration of M to simulate a single step of M . So t steps of M are simulated by NM in time O(t 3 ).  3. Wang B machines A Wang B machine is a computing machine with a single non-erasing bi-infinite tape that has a binary alphabet [15]. Unlike a Turing machine, which performs three operations in a single timestep (write a 1 to its tape, move its tape head, and move program control to a arbitrary location in its program), a Wang B machine can perform only one operation at each timestep. Also, in a Turing machine, control flow can jump to an arbitrary program location when reading 0 or 1, but a Wang B machine performs a control flow jump only upon reading 1. Definition 6 (Wang B Machine). A Wang B machine is a finite list of instructions W = I0 , I1 , I2 , . . . , In−1 where each instruction is of one of the following four forms: L: R: M: J (x): move tape head left, move tape head right, mark the current tape cell by writing the symbol 1, if the current cell contains the symbol 1 then jump to instruction Ix , otherwise move to the next instruction. T. Neary et al. / Journal of Complexity ( ) – 5 Instructions are executed by the machine one at a time, with the computation starting at instruction I0 . A left move or right move instruction (Ik ∈ {L, R}) moves the head one cell to the left or right on the tape. A mark instruction (Ik = M) marks the tape: if a cell is 0 (unmarked) it becomes 1 (marked), otherwise if a cell is 1 it stays as 1. For a jump instruction, Ik = J (x), where 0 ≤ x ≤ n − 1, if the current tape cell is 1 then the machine jumps to instruction Ix . Alternatively, when Ik = J (x) and the current cell is 0 the machine will either move to the next instruction Ik+1 if k < n − 1, or it will halt if k = n − 1. After each move or mark instruction Ik , the machine either moves to the next instruction Ik+1 if k < n − 1, or halts if k = n − 1. 3.1. Wang’s B machines simulate non-erasing Turing machines in linear time Theorem 7. Let N be a deterministic non-erasing Turing machine with a single binary tape that runs in time t. Then there is a Wang B machine WN that simulates the computation of N in time O(t ). Proof. We begin by giving the program for the Wang B machine WN followed by the encoding it uses to simulate N . We then show that WN simulates each transition rule in N in constant time, and so simulates the computation of N in time O(t ). 3.1.1. Encoding Let ⟨TRqi ,σ1 ⟩ denote a sequence of Wang B machine instructions that encode the transition rule TRqi ,σ1 = (qi , σ1 , σ2 , D, qj ) from N where qi , qj ∈ Q , σ1 , σ2 ∈ {0, 1} and D ∈ {R, L}. The sequence of instructions for WN is WN = R, J (8), ⟨TRq0 ,0 ⟩, ⟨TRq0 ,1 ⟩, R, J (21), ⟨TRq1 ,0 ⟩, ⟨TRq1 ,1 ⟩, .. . R, J (13i + 8), ⟨TRqi ,0 ⟩, ⟨TRqi ,1 ⟩, .. . R, J (13(|Q | − 2) + 8), ⟨TRq|Q |−2 ,0 ⟩⟨TRq|Q |−2 ,1 ⟩, M (1) where |Q | is the number of states in N , and ⟨TRqi ,0 ⟩ and ⟨TRqi ,1 ⟩ are the instruction sequences given by Eqs. (2) and (3). We now define Eqs. (2) and (3) which give the sequence of instructions used to simulate each transition rule.  R, M , M , M , M , J (13j) if TRqi ,0 = (qi , 0, 0, R, qj )   L, L, L, M , M , J (13j) if TRqi ,0 = (qi , 0, 0, L, qj ) ⟨TRqi ,0 ⟩ = M , R, M , M , M , J (13j) if TRqi ,0 = (qi , 0, 1, R, qj )  M , L, L, L, M , J (13j) if TRqi ,0 = (qi , 0, 1, L, qj )  R, M , M , M , J (13j) if TRqi ,1 = (qi , 1, 1, R, qj ) ⟨TRqi ,1 ⟩ = L, L, L, M , J (13j) if TRqi ,1 = (qi , 1, 1, L, qj ). (2) (3) (There are only two cases for ⟨TRqi ,1 ⟩ as non-erasing machines never overwrite 1 with 0.) We encode the symbols 0 and 1 of N as ⟨0⟩ = 10 and ⟨1⟩ = 11 respectively. An arbitrary configuration of N is given by qi , w0 w1 . . . wj−1 wj wj+1 . . . wn−1 (4) where qi is the current state, w0 . . . wn−1 is the tape contents, wk ∈ {0, 1} and the tape head position is given by an underline. The configuration in Eq. (4) is encoded as the B machine tape I13i , ⟨w0 ⟩ ⟨w1 ⟩ . . . ⟨wj−1 ⟩ wj1 wj2 ⟨wj+1 ⟩ . . . ⟨wn−1 ⟩ (5) 6 T. Neary et al. / Journal of Complexity ( ) – where ⟨wk ⟩ ∈ {⟨0⟩, ⟨1⟩}, the encoded read symbol wj1 wj2 = ⟨wj ⟩ is given in bold, and I13i is the next instruction to be executed and encodes that N is in state qi . Note that I13i is the first instruction in the sequence I13i , . . . , I13i+12 = R, J (13i + 8), ⟨TRqi ,0 ⟩, ⟨TRqi ,1 ⟩ that encodes the pair of transition rules for state qi . The infinite number of blank tape cells of N each contain the symbol 0, as do the blank tape cells of WN . Note that, during the simulation, WN may need to simulate the situation where the tape head of N moves to a blank tape cell. In this case, as described below, the simulator WN will move to the relevant blank portion of its own tape and convert the symbol pair 00 to 10 = ⟨0⟩. 3.1.2. Simulating transition rules At the start of each simulated timestep of machine N , our Wang machine WN has a configuration of the form given in Eq. (5). Each simulated timestep begins with WN choosing which transition rule to simulate by reading the encoded read symbol and then choosing which sequence (⟨TRqi ,0 ⟩ or ⟨TRqi ,1 ⟩) to execute. From Eq. (5), each simulated timestep begins with the tape head over the leftmost symbol of the encoded read symbol (⟨0⟩ = 10 or ⟨1⟩ = 11). So, immediately after we execute the first instruction (which is I13i = R) the tape head is over the rightmost symbol of ⟨0⟩ or ⟨1⟩ and the program control is at instruction I13i+1 = J (13i + 8). If we are reading ⟨0⟩ = 10, then the rightmost symbol is a 0 and so no jump occurs on J (13i + 8). This means that control moves to instruction I13i+2 , the leftmost instruction in ⟨TRqi ,0 ⟩. Alternatively, if we are reading ⟨1⟩ = 11, then the rightmost symbol is a 1 and J (13i + 8) will jump to instruction I13i+8 , sending control to the leftmost instruction of ⟨TRqi ,1 ⟩. (To see this, use Eq. (1) to count the number of instructions that precede ⟨TRqi ,1 ⟩, which gives 13i + 8, specifically 13 instructions for each state qj where j < i and a further 8 instructions for the sequence R, J (13i + 8), ⟨TRqi ,0 ⟩.) We now explain how the sequences in Eqs. (2) and (3) simulate the transition rules of N . Case 1. Read symbol of N is 1. As described at the beginning of Section 3.1.2, the simulation of each timestep begins with the execution of R, J (13i + 8). When the read symbol of N is 1, and the pair of instructions R, J (13i + 8) have executed, we have the following tape contents for WN ⟨w0 ⟩ ⟨w1 ⟩ . . . ⟨wj−2 ⟩ 10 11 ⟨wj+1 ⟩ . . . ⟨wn−1 ⟩. (6) (For illustration purposes, we assume that in N the symbol to the left of the read symbol is a 0, which is encoded as ⟨0⟩ = 10 in Eq. (6).) As described at the beginning of Section 3.1.2, when the read symbol of N is 1 the execution of R, J (13i + 8) is followed by the execution of the sequence ⟨TRqi ,1 ⟩. If we are simulating (qi , 1, 1, L, qj ), then from Eq. (3) the instruction sequence ⟨TRqi ,1 ⟩ = L, L, L, M , J (13j) is applied to the tape in Eq. (6) to give ⟨w0 ⟩ ⟨w1 ⟩ . . . ⟨wj−2 ⟩ 10 11 ⟨wj+1 ⟩ . . . ⟨wn−1 ⟩. (7) The tape in Eq. (7) is of the form in Eq. (5), hence the tape configuration is ready for the simulation of the next timestep. The jump instruction J (13j) sent the program control of WN to the first instruction of the sequence of instructions that encodes state qj . This is verified by counting the number of instructions to the left of R, J (13j + 8), ⟨TRqj ,0 ⟩, ⟨TRqj ,1 ⟩ using the same technique as above. So, the simulation of the transition rule (qi , 1, 1, L, qj ) is complete. To generalize this example to all possible cases for simulating a rule of the form (qi , 1, 1, L, qj ) we need only consider the encoded symbol (from N ) immediately to the left of the encoded read symbol (in our analysis i, j are already arbitrary). If the encoded symbol to the left of the tape head in Eq. (6) was ⟨1⟩ = 11 instead of ⟨0⟩ = 10, then it is verified in the same straightforward manner. If we are simulating the situation where N is at the left end of its tape (the tape is blank to the left: all 0s) and so contains the pair 00 immediately to the left of the encoded read symbol in Eq. (6). This 00 pair is changed to ⟨0⟩ = 10 by the M instruction that immediately proceeds the J (13j) instruction, correctly providing the symbol pair 10 that encodes the 0 as ⟨0⟩ = 10 for the next simulated timestep. Also, the 1 printed by this M instruction allows instruction J (13j) to jump the program control to the encoding of the next state qj . The case of simulating (qi , 1, 1, R, qj ) is verified by applying the sequence ⟨TRqi ,1 ⟩ = R, M , M , M , J (13j) from Eq. (3) to the tape in Eq. (6). This analysis is similar to the previous example and so we T. Neary et al. / Journal of Complexity ( ) – 7 omit the details. We simply note that after the first of the three M instructions is executed, the tape cell will always contain a 1 and so the second and third M instructions do not change the tape. (These extra M instructions are used for padding so that each encoded state has exactly 13 instructions.) Case 2. Read symbol of N is 0. As described at the beginning of Section 3.1.2, the simulation of each timestep begins with the execution of R, J (13i + 8). When the read symbol of N is 0, and the pair of instructions R, J (13i + 8) have been executed, we have the following tape contents for WN . ⟨w0 ⟩ ⟨w1 ⟩ . . . ⟨wj−1 ⟩ 10 11 ⟨wj+2 ⟩ . . . ⟨wn−1 ⟩. (8) (For illustration purposes, we assume that in N the symbol to the right of the read symbol is a 1, which is encoded as ⟨1⟩ = 11 as in Eq. (8).) As described at the beginning of Section 3.1.2, when the read symbol of N is 0 the execution of R, J (13i + 8) is followed by the execution of the sequence ⟨TRqi ,0 ⟩. If we are simulating (qi , 0, 1, R, qj ), then from Eq. (2) the sequence ⟨TRqi ,0 ⟩ = M , R, M , M , M , J (13j) is applied to the tape in Eq. (8) to give ⟨w0 ⟩ ⟨w1 ⟩ . . . ⟨wj−1 ⟩ 11 11 ⟨wj+2 ⟩ . . . ⟨wn−1 ⟩. (9) The first M instruction changed ⟨0⟩ = 10 to ⟨1⟩ = 11 simulating the printing of the write symbol by N . The tape in Eq. (9) is of the form found in Eq. (5) and is ready for the simulation of the next transition rule to begin. The jump instruction J (13j) sends the program control of WN to the instruction sequence of the program that encodes state qj . This is verified using the same technique as in the previous case. So, the simulation of (qi , 0, 1, R, qj ) is complete. To generalize this example to all possible cases for simulating a rule of the form (qi , 0, 1, R, qj ), we need only consider the encoded symbol (from N ) immediately to the right of the encoded read symbol (in our analysis i, j are already arbitrary). If the encoded symbol to the right of the tape head in Eq. (8) was ⟨1⟩ = 10 instead of ⟨1⟩ = 11, then it is verified in the same straightforward manner. If we are simulating the situation where N is at the right end of its tape (the tape is blank to the right: all 0s) and so contains the pair 00 immediately to the right of the encoded read symbol in Eq. (8). This 00 pair is changed to ⟨0⟩ = 10 by the second M in the sequence M , R, M , M , M , J (13j) which provides the symbol pair 10 = ⟨0⟩ that correctly encodes a 0 for the next simulated timestep. Also, the 1 printed by this M instruction allows instruction J (13j) to jump the program control to the encoding of the next state qj . As with the previous case, the extra M instructions are added for padding. The other cases for simulating N reading a 0 are verified by applying the appropriate sequences from Eq. (2) to the tape in Eq. (8). The details are similar to the previous example and are omitted. 3.1.3. Halting and time complexity When N enters its halt state, defined to be state q|Q |−1 in Definition 3, then WN executes the jump instruction J (13(|Q | − 1)) and jumps to the rightmost instruction in Eq. (1), an M instruction. Note that in order to jump to this M instruction we must have read a 1 on the tape, and so this M instruction does not change the tape. After executing this M instruction, WN is at the end of its list of instructions and so it halts. From Eqs. (1)–(3), exactly 13 instructions are used to encode the pair of transition rules for each state qi of N . Furthermore, from the above algorithm, the simulation of one of these transition rules involves the execution of at most 8 instructions (at most 8 timesteps). Thus WN simulates t steps of an arbitrary non-erasing Turing machine N in time O(t ).  4. Hasenjaeger’s electromechanical universal Turing machine We begin this section by briefly describing the electromechanical device constructed by Hasenjaeger [4], which implements a multi-tape Turing machine. As mentioned in Section 1, Glaschick [2] reverse engineered the physical wiring of Hasenjaeger’s electromechanical machine to find the Turing machine program left by the previous programmer, presumably Hasenjaeger, and with the help 8 T. Neary et al. / Journal of Complexity ( ) – of Hasenjaeger’s notes saw that it simulates Wang B machines. For completeness we include a proof that this program (wiring) for Hasenjaeger’s machine simulates Wang B machines in linear time.4 First we briefly describe Hasenjaeger’s electromechanical machine, which is shown in Fig. 1. • The control unit is constructed from 16 electromechanical relays which encode the main program (also called the state table) of the Hasenjaeger machine. This unit is limited to 4 states and operates on three tapes. • The program tape (P) is a device consisting of 20 switches, 18 of which are connected, and together represent a cyclic, bi-directional, read-only binary tape with 18 cells. (This short tape can be used to store a simulated program.) • The counter tape (C ) consists of two selector switches that represent a bi-directional, cyclic, readonly tape with 18 cells. It represents a tape where all cells contain a 1 except for a single cell that contains a 0. • The work tape (W ) is a bi-directional non-erasable ‘‘infinite’’ tape.5 Hasenjaeger’s electromechanical device, as wired, is an instance of a Turing machine. However, exactly what kind of Turing machine is a matter of opinion: there are a number of reasonable generalizations of this single device (machine instance) to get a general model of computation, here we give one. Formally, we write the tuple (Q , f , qs ) to denote an instance of a three-tape Turing machine of the following form. The three tapes are bi-directional and are denoted P, C and W . Each tape has alphabet {0, 1} and blank symbol 0. Tapes P and C are read-only, while W is non-erasing (i.e. 1s cannot be overwritten with 0s). To give an instance of such a machine, we would assign values to the tuple (Q , f , qs ), where Q is a set of states, f is a transition function (or transition table), of the form f : Q × {0, 1} × {0, 1} × {0, 1} → {L, R, _} × {L, R, _} × {L, R, _, 1} × Q , and qs ∈ Q is the start state. The machine works as follows. In state q ∈ Q , the machine reads a symbol from each of the tapes P, C , and W and, as dictated by f , for each tape does one of three things: move left (L), move right (R), do nothing (_). However, for the tape W it has an additional fourth option of marking (M) the tape cell with the symbol 1. Now we formally specify Hasenjaeger’s machine H = (Q , f , qs ) as an instance of the above model. H has four states Q = {q1 , q2 , q3 , q4 } and the start state is qs = q1 . The function f is given as a list of transition rules in Table 1. This table of behavior is derived from the wiring of the electromagnetic relays of Hasenjaeger’s device. Lemma 8. Let W be a Wang B machine that runs in time t. The multitape Turing machine H , defined above, simulates the computation of W in time O(t ). Proof. We begin by giving the encoding used by the program W , followed by a description of how the program simulates each of the four Wang B machine instructions as well as halting. We finish by giving the time analysis for this simulation. Encoding. The four Wang B machine instructions M, R, L and J (x) are encoded as binary words as follows: ⟨M ⟩ = 1, ⟨R⟩ = 01, ⟨L⟩ = 001, and ⟨J (x)⟩ = 0000y 1 (the value y ∈ {0, 1, 2, . . .} will be defined later). The Wang B machine program W = I0 , I1 , . . . , In−1 is encoded as a single binary word via Eq. (10). ⟨W ⟩ = ⟨I0 ⟩⟨I1 ⟩⟨I2 ⟩ . . . ⟨In−2 ⟩⟨In−1 ⟩⟨J (n)⟩. (10) The word ⟨W ⟩ ∈ {0, 1} is placed on H ’s circular program tape P. The C tape is defined to have length n + 2, with n + 1 of these cells containing the symbol 1, and the single remaining cell containing the symbol 0. The W tape has the same tape contents as that of the Wang B machine it simulates. At the beginning of a simulated computation step the tape head of P is over the leftmost symbol of the ∗ 4 Note that the machine can be re-programmed by re-wiring. 5 It is expected that the recent precipitous decline in the production of 35 mm film and paper punch tape will negatively impact the computing power of Hasenjaeger’s machine. T. Neary et al. / Journal of Complexity ( ) 9 – Table 1 The program f for Hasenjaeger’s universal machine H that simulates Wang’s B machines. The ∗ symbol denotes that the read symbol can be 0 or 1. The rule numbers on the left are not part of the program. Rule number 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Q q1 q1 q1 q2 q2 q2 q2 q3 q3 q3 q3 q4 q4 q4 P 1 1 0 1 0 1 0 0 1 0 1 0 1 ∗ C ∗ ∗ ∗ W 0 1 0 0 1 1 ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ 0 0 1 1 1 1 0 ∗ ∗ ∗ P R R R R R R R R R R L L L R C – – – – R L L – – R R – L – W 1 – – R – L – – – – – – – – Q′ q1 q1 q2 q1 q2 q1 q3 q3 q1 q3 q4 q4 q4 q1 encoded instruction it is simulating, C ’s tape head is over its single 0 symbol, and the tape head of W has the same location as the tape head of the Wang B machine it simulates. To help simplify our explanation, we give partial configurations for H where we display a small part of each tape surrounding the tape head. For example, the following configuration occurs at the beginning of a simulated computation step q1 P = . . . 1 001 . . . C = . . . 101 . . . W = . . . 100 . . . . Here, H ’s current state is q1 and the position of each of the three tape heads is given by an underline. Also, in the above example the tape head of P is over the leftmost symbol of an encoded left move instruction ⟨L⟩ = 001, and the C tape head is at cell C0 . Simulate M instruction. The Wang B machine M instruction is encoded as ⟨M ⟩ = 1 on the P tape. If the tape head of W is reading a 0 then we have a configuration of the form q1 P = . . . 1 1 001 . . . C = . . . 101 . . . W = . . . 100 . . . . (For the purposes of explanation, we have assumed that there is an encoded L instruction, given by ⟨L⟩ = 001, to the right of ⟨M ⟩ = 1 on the P tape.) Rule 1 from Table 1 is applied to the above configuration to give q1 P = . . . 1 1 001 . . . C = . . . 101 . . . W = . . . 110 . . . . The M instruction was simulated by printing a 1 to the W tape. Note that the tape head on the P tape has moved to the leftmost symbol of the next encoded instruction (⟨L⟩ = 001), and the current state of H is once again q1 . So the simulation of the M instruction is complete and H is configured to begin simulation of the next Wang machine instruction. In the case where the tape head of W is reading a 1, we simulate the M instruction by executing rule 2 from Table 1. This is very similar to the previous case above and so we omit the detail. Simulate R instruction. The Wang B machine right move instruction is encoded as ⟨R⟩ = 01 on the P tape. If the tape head of W is reading a 0 then we have a configuration of the form q1 P = . . . 1 01 001 . . . C = . . . 101 . . . W = . . . 100 . . . . Rules 3 and 4 from Table 1 are applied to the above configuration to give q1 P = . . . 1 01 001 . . . C = . . . 101 . . . W = . . . 100 . . . . The tape head of W was moved one place to the right to simulate the R instruction. Also, the tape head on the P tape has moved right 2 places to the leftmost symbol of the next encoded instruction (⟨L⟩ = 001), and the current state of H is once again q1 . So the simulation of the R instruction is 10 T. Neary et al. / Journal of Complexity ( ) – complete and H is configured to begin simulation of the next Wang machine instruction. In the case where the tape head of W is reading a 1, the computation proceeds in the same manner as above by executing rules 3 and 4 from Table 1. Simulate L instruction. The Wang B machine left move instruction is encoded as ⟨L⟩ = 001 on the P tape. If the tape head of W is reading a 0 then we have a configuration of the form q1 P = . . . 1 001 01 . . . C = . . . 101 . . . W = . . . 100 . . . . Rules 3, 5 and 6 from Table 1 are applied to the above configuration to give q1 P = . . . 1 001 01 . . . C = . . . 101 . . . W = . . . 100 . . . . The tape head of W was moved one place to the left to simulate the L instruction. Also, the tape head on the P tape has moved right 3 places to the leftmost symbol of the next encoded instruction (⟨R⟩ = 01), and the current state of H is once again q1 . So the simulation of the L instruction is complete and H is configured to begin simulation of the next Wang machine instruction. In the case where the tape head of W is reading a 1, the computation proceeds in the same manner as above by executing rules 3, 5 and 6 from Table 1. Simulate Ik = J (x) instruction. There are two cases to consider here, which are determined by the value of read symbol of the simulated Wang B machine. Case 1. Wang B machine’s read symbol is 0. In this case, H simulates program control for W moving from instruction Ik to instruction Ik+1 . This is simulated by moving the tape head to the leftmost symbol of ⟨Ik+1 ⟩. Instruction Ik = J (x) is encoded as ⟨Ik ⟩ = ⟨J (x)⟩ = 0000y 1 for some y ∈ {0, 1, 2, . . .} (y is defined below), and for the purposes of explanation we assume that Ik+1 = L. This gives the configuration q1 P = . . . 1 0000y 1 001 . . . C = . . . 01 . . . W = ...0.... After applying rules 3, 5 and 7 from Table 1 we get the following q3 P = . . . 1 00000y−1 1 001 . . . C = . . . 01 . . . W = ...0.... Next, rule 8 is applied y times followed by a single application of rule 9 to give q1 P = . . . 1 0000y 1 001 . . . C = . . . 01 . . . W = ...0.... In the configuration immediately above, the simulation of J (x) when the Wang machine read symbol is 0 is complete. Note that H has returned to state q1 and the tape head of P is over the leftmost symbol of the encoded instruction ⟨Ik+1 ⟩ = 001. Case 2. Wang B machine read symbol is 1. In this case, simulating the instruction Ik = J (x) involves moving the P tape head to the leftmost symbol of ⟨Ix ⟩. We begin with an overview, which includes specifying the encoding of jump instructions. Each encoded instruction contains a single 1 symbol, and so as we move through the P tape we can count the number of encoded instructions by counting the number of 1 symbols. If x 6 k, then, from Eq. (10), we can move from ⟨Ik ⟩ to ⟨Ix ⟩ on P by moving left until we have read the symbol 1 exactly k − x + 1 times, and then moving right. Recall that the P tape is circular, and so if x > k, using Eq. (10), we move from ⟨Ik ⟩ to ⟨Ix ⟩ on P by moving left until we have read the 1 symbol exactly (n + 2 + k − x) times, and then moving right. We are now ready to give the encoding for jump instructions. ⟨Ik ⟩ = ⟨J (x)⟩ = 0000y 1 where y=  k−x n+1+k−x if x 6 k if x > k. (11) In the simulation, moving from ⟨Ik ⟩ to ⟨Ix ⟩ is done in 2 stages. In the first stage the word ⟨J (x)⟩ = 0000y 1 is read and the value y + 1 is recorded by the tape head position on the C tape. In the second stage, using the value stored on the C tape, the tape head of P moves left until we have read the symbol 1 exactly y + 1 times. So, the tape head of P finishes its scan left immediately to the left of the 1 in ⟨Ix−1 ⟩; from there it moves right two cells to the leftmost symbol of ⟨Ix ⟩. T. Neary et al. / Journal of Complexity ( ) – 11 Now we give the details of how H simulates a jump from instruction Ik to instruction Ix . For the purposes of illustration we assume the instruction to the left of Ik is Ik−1 = L. This gives the configuration q1 P = . . . 001 0000y 1 . . . C = . . . 01y+1 . . . W = ...1.... First, rules 3, 5 and 7 from Table 1 are applied, and then rule 10 is applied y times, followed by a single application of rule 11, to give q4 . . . P = 001 0000y−1 01 . . . C = . . . 01y 1 . . . W = ...1.... In the configuration immediately above the value y + 1 is recorded by the position of the tape head of C , which is over y + 1th symbol to the right of the single 0 symbol. Rule 12 is applied y + 3 times to give q4 . . . P = 001 0000y 1 . . . C = . . . 01y 1 . . . W = ...1.... When 1 is read on tape P the value stored on tape C is decremented by moving left once on C using rule 13. This gives q4 . . . P = 001 0000y 1 . . . C = . . . 01y−1 11 . . . W = ...1.... The above process of decrementing the value stored in C by applying rules 12 and 13 continues until the tape head of C reads a 0, indicating that the scan left is finished (during this process Rule 13 is applied a total of y + 1 times). At this point we have a configuration that is of one of the following two forms q4 q4 P = . . . 01 . . . P = . . . 11 . . . C = . . . 01 . . . C = . . . 01 . . . W = ...1... W = ...1.... Rule 13 was applied y + 1 times reading a 1 each time. Rules 14 and 2 are applied to move the tape head of P right twice, placing it over the leftmost symbol of instruction ⟨Ix ⟩ to complete the simulation of Ik = J (x). Simulation of halting. Recall from Section 3, that a Wang B machine halts when it attempts to move to the non-existent instruction In after executing instruction In−1 . Since H does not have a distinguished halt state, it instead simulates halting by entering a repeating sequence of configurations. Note that in Eq. (10), as part of the Wang B machine encoding, there is an extra instruction (In = J (n)) that jumps to itself. So when program H simulates a Wang B machine that halts by attempting to move to instruction In , the program simulates the instruction J (n) which results in an infinite loop and signals the end of the simulation. (The jump instruction works as intended only if we have the assumption that the cell under W ’s tape head reads 1; it is easy to modify any Wang B program so that this is the case by having the program end with a single mark instruction, i.e. In−1 = M.) This jump works as follows. From Eq. (11), a jump instruction of the form In = J (n) is encoded as ⟨In ⟩ = ⟨J (n)⟩ = 0001. This gives the configuration q1 P = . . . 0001 . . . C = . . . 01 . . . W = ...1.... (12) From here, H simulates the jump instruction In = J (n), as described above. In this simple case, simulating the jump instruction involves executing exactly 10 rules (see Table 1) after which H returns to configuration (12). Hence we get an infinite loop where the tape contents are unchanged. Complexity analysis. The Wang B machine instructions M, R, and L are each simulated by Hasenjaeger’s machine in 1, 2 and 3 timesteps, respectively. The J (x) instruction is simulated in O(n2 ) timesteps, where n is the number of instructions in the Wang B machine program. Note that we consider n to be a constant, independent of the input length. Therefore, Hasenjaeger’s program H simulates t steps of the Wang B machine W in time O(t ).  5. Hooper’s small universal Turing machine simulates Turing machines in polynomial time Hooper [5,6] gave a small universal Turing machine with 1 state, 2 symbols and 4 tapes. Using similar techniques to Hasenjaeger, Hooper proved his machine universal by simulating a restricted 12 T. Neary et al. / Journal of Complexity ( ) – class of Wang B machines. In Hooper’s machine, a non-erasing work tape contains exactly the same contents as the tape of the Wang B machine it simulates, and a read-only unidirectional circular program tape stores the encoded Wang machine program. Hooper used a relative addressing technique like Hasenjaeger, but unlike Hasenjaeger, Hooper used two read–write counter tapes (instead of one read-only tape). Hooper’s simulation of Wang B machines runs in linear time, and so from Lemma 5 and by suitably modifying the proof of Theorem 7 we get the following result. Theorem 9. Let M be a deterministic Turing machine with a single binary tape that runs in time t. Then Hooper’s small universal Turing machine with 1 state, 2 symbols, and 4 tapes [5,6] simulates the computation of M in time O(t 3 ). Proof. Hooper’s machine simulates Wang B machines with the following restrictions: 1. In the program list if Ik = J (x), then Ik+1 ∈ {L, R}. 2. Each jump instruction jumps to {L, R}. 3. M instructions are executed only on tape cells that contain 0. Our proof of Theorem 7 is easily modified to include the above restrictions. For restriction 1, we add the instruction sequence L, R after each jump instruction in the program. This has no effect on the program as a move left followed by a move right has the same effect as no move. Our proof already satisfies restriction 2, as we either jump to the beginning of the sequence encoding a state qi (that is: R, J (13i + 8), ⟨TRqi ,0 ⟩, ⟨TRqi ,1 ⟩) or we jump to the beginning of a sequence of the form ⟨TRqi ,1 ⟩ (given in Eq. (3)). To satisfy restriction 3, each Ik = M instruction is replaced with the sequence J (k + 4), R, L, M , R, L. The J (k + 4) will jump over the M instruction if the cell already contains a 1, and the extra R, L instructions are introduced to satisfy restrictions 1 and 2. In addition to the above changes, we wish to maintain the property from the proof of Theorem 7 that the number of instructions used to encode each Turing machine state is the same for all states. Recall from Theorem 7 that each state qi is encoded as the sequence of 13 instructions R, J (13i + 8), ⟨TRqi ,0 ⟩, ⟨TRqi ,1 ⟩. This sequence has 3 jump instructions and to satisfy restriction 1 we added the extra instruction pair L, R for each jump. For restriction 3, we replaced each M instruction with J (k + 4), R, L, M , R, L. In Eq. (3) this gives an extra 15 instructions for the case (qi , 1, 1, R, qj ) and an extra 5 for the case (qi , 1, 1, L, qj ). To ensure that the instruction sequence is the same length for each case we append the length-10 sequence (L, R, )5 to the sequence for case (qi , 1, 1, L, qj ). Satisfying restriction 3 in Eq. (2) gives an extra 20 instructions for the cases (qi , 0, 0, R, qj ) and (qi , 0, 1, R, qj ), and an extra 10 for cases (qi , 0, 0, L, qj ) and qi , 0, 1, L, qj . To ensure that the instruction sequence is the same length for each case we append the length-10 sequence (L, R, )5 to the sequences for case (qi , 0, 0, L, qj ) and case (qi , 0, 1, L, qj ). Now the length of the sequence that encodes each state is 54 (instead of 13), and so we replace jumps of the from J (13i) with jumps of the from J (54i). The sequence R, J (13i + 8), ⟨TRqi ,0 ⟩ of length 8 has been replaced by a sequence of length 32, and so we replace jumps of the from J (13i + 8) with jumps of the form J (54i + 32). This completes our conversion to a Wang B machine with the 3 restrictions mentioned above.  Acknowledgments We thank Benedikt Löwe for inviting us to the Isaac Newton Institute for Mathematical Sciences in Cambridge (UK) to participate in the 2012 program ‘‘Semantics and Syntax: A Legacy of Alan Turing’’, and for facilitating this fun project. Finally, we thank David Soloveichik for translating the work of Zykin [17]. Turlough Neary was supported by Swiss National Science Foundation grant 200021-141029. Damien Woods was supported by the USA National Science Foundation under grants 0832824 (The Molecular Programming Project), CCF-1219274, and CCF-1162589. Niall Murphy was supported by a PICATA Young Doctors fellowship from CEI Campus Moncloa, UCM-UPM, Madrid, Spain. Rainer Glaschick was supported by the Heinz Nixdorf MuseumsForum, Germany. T. Neary et al. / Journal of Complexity ( ) – 13 References [1] R. Glaschick, Alan Turings Wirkung in Münster, Mitt. DMV 20 (2012) 42–49 (in German). [2] R. Glaschick, A Size Index for Multitape Turing Machines, Technical Report NI12061-SAS, Isaac Newton Institute for Mathematical Sciences, Cambridge, UK, 2012. [3] R. Glaschick, Turing machines in Münster, in: Alan Turing—His Work and Impact, Elsevier, ISBN: 9780123869807, 2013, pp. 71–77. [4] G. Hasenjaeger, On the early history of register machines, in: E. Börger (Ed.), Computation Theory and Logic, SpringerVerlag, London, UK, 1987, pp. 181–188. [5] P. Hooper, Some Small, Multitape Universal Turing Machines, Tech. Rep., Computation Laboratory, Harvard University, Cambridge, Massachusetts, 1963. [6] P. Hooper, Some small, multitape universal Turing machines, Inform. Sci. 1 (2) (1969) 205–215. [7] M. Kudlek, Small deterministic Turing machines, Theoret. Comput. Sci. 168 (2) (1996) 241–255. [8] M. Margenstern, Non-erasing Turing machines: a frontier between a decidable halting problem and universality, in: Z. Ésik (Ed.), FCT, in: LNCS, vol. 710, Springer, Heidelberg, Szeged, Hungry, 1993, pp. 375–385. [9] M. Margenstern, The laterality problem for non-erasing Turing machines on {0, 1} is completely solved, RAIRO Theor. Inform. Appl. 31 (2) (1997) 159–204. [10] M. Margenstern, Frontier between decidability and undecidability: a survey, Theoret. Comput. Sci. 231 (2) (2000) 217–251. [11] T. Neary, D. Woods, P-completeness of cellular automaton rule 110, in: ICALP 2006, Part I, in: LNCS, vol. 4051, Springer, Venice, Italy, 2006, pp. 132–143. [12] T. Neary, D. Woods, The complexity of small universal Turing machines: a survey, in: SOFSEM 2012: Theory and Practice of Computer Science, in: LNCS, vol. 7147, Springer, 2012, pp. 385–405. [13] L. Pavlotskaya, Solvability of the halting problem for certain classes of Turing machines, Math. Notes (Springer) 13 (6) (1973) 537–541; Translated from Mat. Zametki 13 (6) (1973) 899–909. [14] L. Priese, Towards a precise characterization of the complexity of universal and non-universal Turing machines, SIAM J. Comput. 8 (4) (1979) 508–523. [15] H. Wang, A variant to Turing’s theory of computing machines, J. ACM 4 (1) (1957) 63–92. [16] D. Woods, T. Neary, On the time complexity of 2-tag systems and small universal Turing machines, in: 47th Annual IEEE Symposium on Foundations of Computer Science (FOCS), IEEE, Berkeley, California, 2006, pp. 439–446. [17] G.P. Zykin, Remarks about a theorem of Hao Wang, Algebra Logika 2 (1963) 33–35 (in Russian).