# Turing Machines Chap 8 Turing Machines Recursive and

• Slides: 27

Turing Machines - Chap 8 Turing Machines Recursive and Recursively Enumerable Languages 1

Turing-Machine Theory v The purpose of theory of Turing machines is to prove that certain specific languages have no algorithm. v Start with a language about Turing machines themselves. v Reductions are used to prove more common questions undecidable. 2

Picture of a Turing Machine Action: based on the state and the tape symbol under the head: change state, rewrite the symbol and move the head one square. State . . . A B C A D . . . Infinite tape with squares containing tape symbols chosen from a finite alphabet 3

Why Turing Machines? v. Why not deal with C programs or something like that? v. Answer: You can, but it is easier to prove things about TM’s, because they are so simple. v And yet they are as powerful as any computer. v. More so, in fact, since they have infinite memory. 4

Turing-Machine Formalism v A TM is described by: 1. 2. 3. 4. 5. 6. A finite set of states (Q, typically). An input alphabet (Σ, typically). A tape alphabet (Γ, typically; contains Σ). A transition function (δ, typically). A start state (q 0, in Q, typically). A blank symbol (B, in Γ- Σ, typically). v All tape except for the input is blank initially. 7. A set of final states (F C Q, typically). 5

Conventions v a, b, … are input symbols. v X, Y, Z are tape symbols. v w, x, y, z are strings of input symbols. v , , … are strings of tape symbols. 6

The Transition Function v Takes two arguments: v A state, in Q. v A tape symbol in Γ. v δ(q, Z) is either undefined or a triple of the form (p, Y, D). v p is a state. v Y is the new tape symbol. v D is a direction, L or R. 7

Actions of the PDA v If δ(q, Z) = (p, Y, D) then, in state q, scanning Z under its tape head, the TM: v Changes the state to p. v Replaces Z by Y on the tape. v Moves the head one square in direction D. v D = L: move left; D = R; move right. 8

Example: Turing Machine v. This TM scans its input right, looking for a 1. v. If it finds one, it changes it to a 0, goes to final state f, and halts. v. If it reaches a blank, it changes it to a 1 and moves left. 9

Example: Turing Machine – (2) v. States = {q (start), f (final)}. v. Input symbols = {0, 1}. v. Tape symbols = {0, 1, B}. vδ(q, 0) = (q, 0, R). vδ(q, 1) = (f, 0, R). vδ(q, B) = (q, 1, L). 10

Moves of TM δ(q, 0) = (q, 0, R) δ(q, 1) = (f, 0, R) δ(q, B) = (q, 1, L) q . . . B B 0 0 B B. . . 11

Moves of TM δ(q, 0) = (q, 0, R) δ(q, 1) = (f, 0, R) δ(q, B) = (q, 1, L) q . . . B B 0 0 B B. . . 12

Moves of TM δ(q, 0) = (q, 0, R) δ(q, 1) = (f, 0, R) δ(q, B) = (q, 1, L) q . . . B B 0 0 B B. . . 13

Moves of TM δ(q, 0) = (q, 0, R) δ(q, 1) = (f, 0, R) δ(q, B) = (q, 1, L) q . . . B B 0 0 1 B. . . 14

Moves of TM δ(q, 0) = (q, 0, R) δ(q, 1) = (f, 0, R) δ(q, B) = (q, 1, L) q . . . B B 0 0 1 B. . . 15

Moves of TM δ(q, 0) = (q, 0, R) δ(q, 1) = (f, 0, R) δ(q, B) = (q, 1, L) f . . . B B 0 0 0 B. . . No move is possible. The TM halts and accepts. 16

Instantaneous Descriptions of a Turing Machine v Initially, a TM has a tape consisting of a string of input symbols surrounded by an infinity of blanks in both directions. v The TM is in the start state, and the head is at the leftmost input symbol. 17

TM ID’s – (2) v. An ID is a string q , where is the tape between the leftmost and rightmost nonblanks (inclusive). v. The state q is immediately to the left of the tape symbol scanned. v. If q is at the right end, it is scanning B. v. If q is scanning a B at the left end, then consecutive B’s at and to the right of q are part of . 18

TM ID’s – (3) v. As for PDA’s we may use symbols I--⊦ and |--* to represent “becomes in one move” and “becomes in zero or more moves, ” respectively, on ID’s. v. Example: The moves of the previous TM are q 00 |--⊦ 0 q 0 |-- 00 q |-- 0 q 01 |--⊦ 00 q 1 |-- 000 f 19

Formal Definition of Moves 20

Formal Definition of Moves 21

Languages of a TM v. The language L(M) accepted by a TM M is: L(M) = {w | q 0 w |--* I, where I is an ID with a final state}. 22

Turing machine - Second Example: 23

diagram representing Turing machines 24

Recursively Enumerable Languages v. We now see that the classes of languages defined by TM’s using final state and halting are the same. v. This class of languages is called the recursively enumerable languages. v. The term actually predates the Turing machine and refers to another notion of computation of functions. 25

Recursive Languages v An algorithm is a TM that is guaranteed to halt whether or not it accepts. v If L = L(M) for some TM M that is an algorithm, we say L is a recursive language. 26

Example: Recursive Languages v. Every CFL is a recursive language. v. Use the CYK algorithm. v. Every regular language is a CFL (think of its DFA as a PDA that ignores its stack); therefore every regular language is recursive. v. Almost anything you can think of is recursive. 27