# COMS W3261 Computer Science Theory Lecture 12: October 15, 2012 Turing Machines

## Outline

• Turing machines
• Algorithms and recursive languages
• Some history
• Models of computation equivalent to Turing machines

## 1. Turing Machines

• A Turing machine is a generalization of a finite automaton. At any moment in time, it can be pictured as a finite-state control with a tape head reading a symbol on a square of its infinite input tape. Initially, a finite length input string a1a2 ... an appears on the input tape with the tape head reading a1 and the finite control in a designated initial state. The symbols of the input string appear in contiguous squares of the input tape. An infinite number of blank symbols are on the input tape to the left and to the right of the input string.
• Before a move, a Turing machine reads the symbol on the square of the input tape under the tape head and consults the transition function (its "program") stored in its finite-state control. During the move it makes a state transition, replaces the symbol on the input tape with another tape symbol, and shifts the tape head one square to the left or to the right. If after a finite (but perhaps very long) number of moves the Turing machine enters a final state, it halts and accepts the original input string a1a2 ... an. The Turing machine may enter a nonfinal state and halt, or it may make an infinite sequence of moves without entering a final state. In both these cases it does not accept the input string.

• More formally, a nondeterministic Turing machine M has seven components: (Q, Σ, Γ, δ, q0, B, F)
1. Q is the finite set of states of the finite control.
2. Σ is the finite set of input symbols.
3. Γ is the set of tape symbols; Σ is a subset of Γ.
4. δ is the transition function. It maps (Q × Γ) to subsets of (Q × Γ × {L,R}). If (p, Y, D) is in δ(q, X) and M is in state q reading the symbol X on the input tape, then M can
• go from state q to state p,
• replace the symbol X on the input tape by the symbol Y, and
• move its input head one square in the direction D where D can be either L (for left) or R (for right).
M is deterministic if there is at most one element in δ(q, X) for any state q and tape symbol X.
5. q0 is the start state.
6. B is the blank symbol. B is in Γ but not in Σ.
7. F, a subset of Q, is the set of final accepting states. We assume there are no transitions from a final state so that when M enters a final state it halts.

• During a sequence of moves we can represent the configuration of M by an instantaneous description (ID) of the form X1X2 ... Xi-1qXiXi+1 ... Xn. This ID says M is in state q reading the tape symbol Xi. To the left of Xi is the string of tape symbols X1X2 ... Xi-1. To the right of Xi is the string of tape symbols Xi+1 ... Xn. We do not show blanks on the input tape unless necessary.
• The read head may be one input square past the right end of the input reading a blank in which case M is in the ID
•    X1X2 ... XnqB.
• Moves by M are modeled by the following changes to the ID:
1. If (p, Y, L) is in δ(q, Xi), M can move to the ID
2.    X1X2 ... Xi-2pXi-1Y Xi+1 ... Xn.
If i = 1, then M moves to the blank to the left of X1 in which case the ID becomes
pBYX2 ... Xn.
If i = n and Y = B, then M replaces Xn by a blank and the ID becomes
X1X2 ... Xn-2pXn-1.
3. If (p, Y, R) is in δ(q, Xi), M can move to the ID
4.    X1X2 ... Xi-1YpXi+1 ... Xn.
If i = n, then M moves to the blank to the right of Xn in which case the ID becomes
X1X2 ... Xn-1YpB.
If i = 1 and Y = B, then M replaces X1 by a blank and the ID becomes
pX2 ... Xn.
• L(M), the language accepted by M, is the set of strings w in Σ* such that q0w |–* αpβ for some state p in F.
• We say that a language L is recursively enumerable if L = L(M) for some Turing machine M.
• See Example 8.2, p. 329, HMU for a TM that accepts the language {0n1n | n ≥ 1 }.

## 2. Algorithms and Recursive Languages

• We say that a language L is recursive if L = L(M) for some Turing machine M such that:
1. If w is in L, then M accepts w and therefore halts.
2. If w is not in L, then M eventually halts but never enters an accepting state.
• A Turing machine that halts on all inputs either in an accepting or nonaccepting state provides a precise definition for the term algorithm. This formalizes our intuitive notion of an algorithm as a collection of simple instructions for carrying out some task.
• A language L is said to be decidable if it is a recursive language.
• A language L is said to be undecidable if it is not a recursive language.

## 3. Some History

• Hilbert's problems
• In 1900, David Hilbert, the eminent mathematician of his day, presented a famous list of twenty-three problems at the International Congress of Mathematicians in Paris.
• Hilbert's tenth problem was to devise a process according to which it can be determined by a finite number of operations whether a polynomial with integer coefficients (Diophantine equation) has an integral root.
• For example, the polynomial Diophantine equation
6x3yz2 + 3xy2 - x3 - 10 = 0
over the variables x, y, and z has an integral root at x = 5, y = 3, and z = 0. The root is said to be integral because all variables are assigned integer values.
• In 1931 Kurt Gödel published his famous incompleteness theorems which basically said that in any reasonable system of formalizing the notion of provability in number theory, some true statements are unprovable. This shattered Hilbert's dream of finding a complete and consistent set of axioms for all of mathematics (Hilbert's second problem).
• In 1936 Alonzo Church wrote a paper in which he devised a notation called lambda calculus to define algorithms. Lambda calculus is the basis for the programming language Lisp.
• In 1936 Alan Turing wrote a paper ("On computable numbers with an application to the Entscheidungsproblem", Proc. London Math. Society) in which he defined Turing machines and showed that the halting problem for Turing machines is undecidable.
• The machine M in Alan Turing's paper accepted by just halting -- there is no final state. Let H(M) be the set of inputs w on which his machine halts. Turing showed that the set of pairs (M, w) such that w is in H(M) is recursively enumerable but not recursive.
• The Church-Turing thesis hypothesizes that any function that can be computed ("effectively computable function") can be computed on a Turing machine.
• In 1970, Yuri Matiyasevich showed that no algorithm exists for testing whether a Diophantine equation has integral roots.

## 4. Models of Computation Equivalent to Turing Machines

• Many variants of Turing machines have been defined such as:
• Turing machines with a semi-infinite input tape.
• Multitape Turing machines.
• Turing machines with tapes having multiple tracks.
• Nondeterministic Turing machines.
• All these machines are equivalent to our definition of a Turing machine.
• Other universal models of computation:
• Chomsky type 0 grammars. A type 0 grammar is like a context-free grammar (V, T, P, S) except that productions can be of the form α → β where α is a string of nonterminals and terminals with at least one nonterminal and β is any string of nonterminals and nonterminals.
• Lambda calculus.
• Pushdown automata with two or more stacks.
• Two-counter machines.
• Random access machines.
• Most programming languages.
• Real computers with an arbitrary amount of memory.
• Again, all these models are computationally equivalent to our definition of a Turing machine.

## 5. Practice Problems

1. Design a Turing machine that accepts all strings of a's and b's with an equal number of a's and b's. Show the sequence of moves your Turing machine makes on the input aabb.
2. HMU, Exercise 8.2.5.