Turing machines Finite automaton no storage Pushdown automaton storage is a stack What if we give the automaton a more flexible storage? What is the most powerful of automata? In this lecture we will introduce the Turing machine, a simple mathematical model of a computer. Despite its simplicity, the Turing machine is equivalent in computing power to the digital computer as we know it today.
The Turing machine model A formal model for an effective procedure should possess certain properties. 1. Each procedure should be finitely describable. 2. The procedure should consist of discrete steps, each of which can be carried out mechanically. Such a model was introduced by Alan Turing in 1936.
Turing machine A Turing machine (TM) is an automaton whose storage is a tape. This tape is divided into cells, each of which is capable of holding one symbol. It has a read-write head that can travel right or left and that can read and write a single symbol on each move. The TM has neither an input file nor any special output mechanism. Whatever input and output is necessary will be done on the machine s tape. Read-write head Control unit Tape
Turing machine Definition A Turing machine M is defined by M = (Q, Σ, Γ, δ, q 0,, F ), where Q is the set of states, Σ is the input alphabet, Γ is a finite set of symbols called the tape alphabet, δ is the transition function defined as δ : Q Γ Q Γ {L, R}, (the move symbols L, R indicate whether the read-write head moves left or right one cell after the new symbol has been written on the tape.) Γ is a special symbol called the blank, q 0 Q is the inital state, F Q is the set of final states. We assume that Σ Γ \ { }.
Turing machine The automaton starts in the given initial state with some information on the tape. It then goes through a sequence of steps controlled by δ. The contents of any cell on the tape may be examined and changed many times. Eventually the whole process may terminate, which is achieved by putting the TM into a halt state. A TM is said to halt whenever it reaches a configuration for which δ is not defined. We assume that no transitions are defined for any final state, so the TM will halt whenever it enters a final state.
Turing machine Example 1:
Turing machine Example 2:
Turing machine Summarizing the main features of our TM model: 1. The TM has a tape that is unbounded in both directions, allowing any number of left and right moves. 2. The TM is deterministic in the sense that δ defines at most one move for each configuration. 3. There is no special input file. We assume that at the inital time the tape has some specified content. 4. Similarly, there is no special output device. Whenever the machine halts, some or all of the contents of the tape may be viewed as output.
Turing machine The most convenient way to exhibit a sequence of configurations of a TM uses the idea of an instantaneous description. Any configuration is completely determined by the current state, the contents of the tape, and the position of the read-write head. We use the notation in which x 1 qx 2 or a 1 a 2... a k 1 qa k a k+1... a n is the instantaneous description of a machine in state q (scanning a k ).
Turing machine The instantaneous description gives only a finite amount of information to the right and left of the read-write head. The unspecified part of the tape is assumed to contain all blanks. If the position of blanks is relevant, the blank symbol may appear in the instantaneous description.
Turing machine A move from one configuration to another will be denoted by. If δ(q 1, c) = (q 2, e, R), then the move abq 1 cd abeq 2 d is made whenever the internal state is q 1, the tape contains abcd, and the read-write head is on the c. The symbol has the usual meaning of an arbitrary number of moves. We use M to distinguish between several machines.
Turing machine Definition Let M = (Q, Σ, Γ, δ, q 0,, F ) be a TM. Then any string a 1... a k 1 q 1 a k a k+1... a n, with a i Γ and q 1 Q is an instantaneous description of M. A move a 1... a k 1 q 1 a k a k+1... a n a 1... a k 1 bq 2 a k+1... a n is possible iff δ(q 1, a k ) = (q 2, b, R). A move a 1... a k 1 q 1 a k a k+1... a n a 1... q 2 a k 1 ba k+1... a n is possible iff δ(q 1, a k ) = (q 2, b, L).
Turing machine Definition (continued) M is said to halt starting from some inital configuration if x 1 q i x 2 x 1 q i x 2 y1 q j ay 2 for any q j and a, for which δ(q j, a) is undefined. The sequence of configurations leading to a halt state will be called a computation. If, from the initial configuration x 1 qx 2, the machine goes into a loop and never halts, then we write x 1 qx 2.
Turing machines as language acceptors A string w is written on the tape, with blanks filling out the unused portions. The machine is started in the initial state q 0 with the read-write head positioned on the leftmost symbol of w. If, after a sequence of moves, the TM enters a final state and halts, then w is considered to be accepted.
Turing machines as language acceptors Definition Let M = (Q, Σ, Γ, δ, q 0,, F ) be a Turing machine. The language accepted by M is L(M) = {w Σ + q 0 w x 1 q f x 2 for some q f F, x 1, x 2 Γ }. This definition tells us that the machine will halt when w L(M). When w is not in L(M) then the machine can halt in a non-final state or it can enter an infinite loop and never halt.
Turing machines as language acceptors Example: For Σ = {a, b}, we design a TM that accepts L = {a n b n n 1}. Intuitively, the problem is solved in the following fashion: Starting at the leftmost a we check it off by replacing it with some x aaabbb xaabbb We travel to the right to find the leftmost b, which we check off by replacing it with y. xaaybb We go left again to the leftmost a xaaybb Traveling back and forth we match each a with a corresponding b.
Turing machines as transducers Turing machines are not only interesting as language acceptors, they also provide us with a simple abstract model for digital computers. The primary purpose of a computer is to transform input to output, it acts as a transducer. Modeling computers using Turing machines The input for a computation will be all the nonblank symbols on the tape at the initial time. At the conclusion of the computation, the output will be whatever is then on the tape. Thus, we can view a TM transducer M as an implementation of a function f defined by ŵ = f(w), provided that q 0 w q f ŵ, for some final state q f.
Turing machines as transducers Definition A function f with domain D is said to be Turingcomputable or just computable if there exists some TM M = (Q, Σ, Γ, δ, q 0,, F ) such that q f F, for all w D. q 0 w q f f(w), All the common mathematical functions, no matter how complicated, are Turing-computable.
Turing machines as transducers Example: Given two positive integers x and y, we design a TM that computes x + y. We use unary notation to represent positive integers. Any positive integer x is represented by w(x) = {1} +, such that w(x) = x. Initially w(x) and w(y) are on the tape in unary notation, seperated by a single 0, with the read-write head on the leftmost symbol of w(x). After computation, w(x + y) in on the tape followed by a single 0, and the read-write head positioned at the left end of the result.
Turing machines as transducers Example (continued): We want to design a TM for performing the computation where q f is a final state. q 0 w(x)0w(y) q f w(x + y)0, All we need to do is to move the seperating 0 to the right end of w(y), so that the addition amounts to nothing more than the concatenation of the two strings. Unary notation for practical computations is cumbersome, but very convenient for programming Turing machines. The resulting programs are much shorter and simpler than binary or decimal representations.
Turing machines as transducers Adding numbers is one of the fundamental operations of any computer, one that plays a part in the synthesis of more complicated instructions. Other basic operations are copying strings and simple comparisons. These can also be done easily on a Turing machine.
Turing machines as transducers Example: Let x and y be two positive integers represented in unary notation. We construct a Turing machine that will halt in a final state q y if x y and that will halt in a non-final state q n if x < y. More precisely, the machine is to perform the computation q 0 w(x)0w(y) q y w(x)0w(y) if x y, q 0 w(x)0w(y) q n w(x)0w(y) if x < y. Instead of matching a s and b s, we match each 1 on the left of the dividing 0 with the 1 on the right.
Turing machines as transducers Example (continued): At the end of the matching, we will have on the tape either xx... 110xx... x or xx... xx0xx... x11, depending on whether x > y or y > x. In the first case, when we attempt to match another 1, we encounter the blank at the right of the working space. This can be used as a signal to enter the state q y (halt in final state). In the second case, we still find a 1 on the right when all 1 s on the left have been replaced. We use this to get into the state q n (halt in non-final state). This example makes the important point that a TM can be programmed to make decisions based on arithmetic comparisons.
Combining TM s for complicated tasks We have shown explicitly how some important operations found in all computers can be done on a TM. Since, in digital computers, such primitive operations are the building blocks for more complex instructions, let us see how these basic operations can also be put together on a TM. We can describe TM s in several ways at a high level, namely either with pseudo code or block diagrams. In a block diagram, we encapsulate computations in boxes whose function is described, but whose interior details are not shown. By using such boxes, we implicitly claim that they can actually be constructed.
Combining TM s for complicated tasks Example: Designing a TM that computes the function f(x, y) = x + y if x y, = 0 if x < y. We first use a comparing machine to determine whether or not x y. If so, the comparer sends a start signal to the adder which then computes x + y. If not, the eraser is started and changes every 1 to a blank.
Combining TM s for complicated tasks Example (continued): The computations to be done by the Comparer C are q C,0 w(x)0w(y) q A,0 w(x)0w(y) if x y, q C,0 w(x)0w(y) q E,0 w(x)0w(y) if x < y. Computations performed by the adder A q A,0 w(x)0w(y) q A,f w(x + y)0 Computations performed by the eraser E q E,0 w(x)0w(y) q E,f 0 The result is a single TM that combines the action of C, A, and E.
References LINZ, P. An introduction to Formal Languages and Automata. Jones and Bartlett Learning, 2012. HOPCROFT, J. and ULLMAN, J. Introduction to Automata Theory, Languages and Computation. Addison-Wesley, 1979.