CSCE 355 Foundations of Computation Lecture 16 b
CSCE 355 Foundations of Computation Lecture 16 b Turing Machines Topics: n n June 23, 2015 Closure Properties of Context Free Languages Cocke-Younger-Kasimi Parsing Algorithm
Chomsky Hierarchy http: //en. wikipedia. org/wiki/Chomsky_hierarchy Grammar Languages Automaton Production rules (constraints) Type-0 Recursively enumerable Turing machine α β no restrictions Type-1 Context-sensitive Linear-bounded nondeterministic Turing machine αAβ αγβ Type-2 Context-free Non-deterministic pushdown automaton A α Type-3 Regular DFA A a or A a. B – 2– ialc slides Ullman Stanford 2010 CSCE 355 Summer 2015
Alan Turing – 3– ialc slides Ullman Stanford 2010 CSCE 355 Summer 2015
Turing-Machine Theory • The purpose of theory of Turing machines is to prove that certain specific languages have no algorithm. • Start with a language about Turing machines themselves. • Reductions are used to prove more common questions undecidable. – 4– ialc slides Ullman Stanford 2010 4 CSCE 355 Summer 2015
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 – 5– ialc slides Ullman Stanford 2010 5 CSCE 355 Summer 2015
Why Turing Machines? • Why not deal with C programs or something like that? • Answer: You can, but it is easier to prove things about TM’s, because they are so simple. n And yet they are as powerful as any computer. l More so, in fact, since they have infinite memory. – 6– ialc slides Ullman Stanford 2010 6 CSCE 355 Summer 2015
Then Why Not Finite-State Machines to Model Computers? • In principle, you could, but it is not instructive. • Programming models don’t build in a limit on memory. • In practice, you can go to Fry’s and buy another disk. • But finite automata vital at the chip level (modelchecking). – 7– ialc slides Ullman Stanford 2010 7 CSCE 355 Summer 2015
Turing-Machine Formalism • 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). u 7. – 8– All tape except for the input is blank initially. A set of final states (F ⊆ Q, typically). ialc slides Ullman Stanford 2010 8 CSCE 355 Summer 2015
Conventions • a, b, … are input symbols. • …, X, Y, Z are tape symbols. • …, w, x, y, z are strings of input symbols. • , , … are strings of tape symbols. – 9– ialc slides Ullman Stanford 2010 9 CSCE 355 Summer 2015
The Transition Function • Takes two arguments: 1. 2. δ(q, Z) is either undefined or a triple of the form (p, Y, D). • n n n – 10 – A state, in Q. A tape symbol in Γ. p is a state, the next state. Y is the new tape symbol, replacing the Z. D is a direction, L or R. ialc slides Ullman Stanford 2010 10 CSCE 355 Summer 2015
Actions of the PDA • If δ(q, Z) = (p, Y, D) then, in state q, scanning Z under its tape head, the TM: 1. 2. 3. Changes the state to p. Replaces Z by Y on the tape. Moves the head one square in direction D. u – 11 – D = L: move left; D = R; move right. ialc slides Ullman Stanford 2010 11 CSCE 355 Summer 2015
Example reformatted – 12 – ialc slides Ullman Stanford 2010 CSCE 355 Summer 2015
Example: Turing Machine • This TM scans its input right, looking for a 1. • If it finds one, it changes it to a 0, goes to final state f, and halts. • If it reaches a blank, it changes it to a 1 and moves left. – 13 – ialc slides Ullman Stanford 2010 13 CSCE 355 Summer 2015
Example: Turing Machine – (2) • States = {q (start), f (final)}. • Input symbols = {0, 1}. • Tape symbols = {0, 1, B}. • δ(q, 0) = (q, 0, R). • δ(q, 1) = (f, 0, R). • δ(q, B) = (q, 1, L). – 14 – ialc slides Ullman Stanford 2010 14 CSCE 355 Summer 2015
Simulation of TM δ(q, 0) = (q, 0, R) δ(q, 1) = (f, 0, R) δ(q, B) = (q, 1, L) q . . . – 15 – B B 0 0 B B. . . ialc slides Ullman Stanford 2010 15 CSCE 355 Summer 2015
Simulation of TM δ(q, 0) = (q, 0, R) δ(q, 1) = (f, 0, R) δ(q, B) = (q, 1, L) q . . . – 16 – B B 0 0 B B. . . ialc slides Ullman Stanford 2010 16 CSCE 355 Summer 2015
Simulation of TM δ(q, 0) = (q, 0, R) δ(q, 1) = (f, 0, R) δ(q, B) = (q, 1, L) q . . . – 17 – B B 0 0 B B. . . ialc slides Ullman Stanford 2010 17 CSCE 355 Summer 2015
Simulation of TM δ(q, 0) = (q, 0, R) δ(q, 1) = (f, 0, R) δ(q, B) = (q, 1, L) q . . . – 18 – B B 0 0 1 B. . . ialc slides Ullman Stanford 2010 18 CSCE 355 Summer 2015
Simulation of TM δ(q, 0) = (q, 0, R) δ(q, 1) = (f, 0, R) δ(q, B) = (q, 1, L) q . . . – 19 – B B 0 0 1 B. . . ialc slides Ullman Stanford 2010 19 CSCE 355 Summer 2015
Simulation of TM δ(q, 0) = (q, 0, R) δ(q, 1) = (f, 0, R) δ(q, B) = (q, 1, L) f . . . – 20 – B B 0 0 0 B. . . No move is possible. The TM halts and accepts. ialc slides Ullman Stanford 2010 20 CSCE 355 Summer 2015
Instantaneous Descriptions of a Turing Machine • Initially, a TM has a tape consisting of a string of input symbols surrounded by an infinity of blanks in both directions. • The TM is in the start state, and the head is at the leftmost input symbol. – 21 – ialc slides Ullman Stanford 2010 21 CSCE 355 Summer 2015
TM ID’s – (2) • An ID is a string q , where is the tape between the leftmost and rightmost nonblanks (inclusive). • The state q is immediately to the left of the tape symbol scanned. • If q is at the right end, it is scanning B. n – 22 – If q is scanning a B at the left end, then consecutive B’s at and to the right of q are part of . ialc slides Ullman Stanford 2010 22 CSCE 355 Summer 2015
TM ID’s – (3) • As for PDA’s we may use symbols ⊦ and ⊦* to represent “becomes in one move” and “becomes in zero or more moves, ” respectively, on ID’s. • Example: The moves of the previous TM are n q 00⊦ 0 q 0⊦ 00 q⊦ 0 q 01⊦ n 00 q 1⊦ n 000 f n n n – 23 – ialc slides Ullman Stanford 2010 23 CSCE 355 Summer 2015
Formal Definition of Moves 1. 2. If δ(q, Z) = (p, Y, R), then u q. Z ⊦ Yp u If Z is the blank B, then also q⊦ Yp If δ(q, Z) = (p, Y, L), then u u – 24 – For any X, Xq. Z ⊦ p. XY In addition, q. Z ⊦p. BY ialc slides Ullman Stanford 2010 24 CSCE 355 Summer 2015
Languages of a TM • A TM defines a language by final state, as usual. • L(M) = {w | q 0 w⊦*I, where I is an ID with a final state}. • Or, a TM can accept a language by halting. • H(M) = {w | q 0 w⊦*I, and there is no move possible from ID I}. – 25 – ialc slides Ullman Stanford 2010 25 CSCE 355 Summer 2015
Equivalence of Accepting and Halting – 26 – 1. If L = L(M), then there is a TM M’ such that L = H(M’). 2. If L = H(M), then there is a TM M” such that L = L(M”). ialc slides Ullman Stanford 2010 26 CSCE 355 Summer 2015
Proof of 1: Acceptance -> Halting • Modify M to become M’ as follows: 1. 2. For each accepting state of M, remove any moves, so M’ halts in that state. Avoid having M’ accidentally halt. u u – 27 – Introduce a new state s, which runs to the right forever; that is δ(s, X) = (s, X, R) for all symbols X. If q is not accepting, and δ(q, X) is undefined, let δ(q, X) = (s, X, R). ialc slides Ullman Stanford 2010 27 CSCE 355 Summer 2015
Proof of 2: Halting -> Acceptance • Modify M to become M” as follows: 1. 2. 3. – 28 – Introduce a new state f, the only accepting state of M”. f has no moves. If δ(q, X) is undefined for any state q and symbol X, define it by δ(q, X) = (f, X, R). ialc slides Ullman Stanford 2010 28 CSCE 355 Summer 2015
Recursively Enumerable Languages • We now see that the classes of languages defined by TM’s using final state and halting are the same. • This class of languages is called the recursively enumerable languages. n – 29 – Why? The term actually predates the Turing machine and refers to another notion of computation of functions. ialc slides Ullman Stanford 2010 29 CSCE 355 Summer 2015
Recursive Languages • An algorithm is a TM that is guaranteed to halt whether or not it accepts. • If L = L(M) for some TM M that is an algorithm, we say L is a recursive language. n – 30 – Why? Again, don’t ask; it is a term with a history. ialc slides Ullman Stanford 2010 30 CSCE 355 Summer 2015
Example: Recursive Languages • Every CFL is a recursive language. n Use the CYK algorithm. • Every regular language is a CFL (think of its DFA as a PDA that ignores its stack); therefore every regular language is recursive. • Almost anything you can think of is recursive. – 31 – ialc slides Ullman Stanford 2010 31 CSCE 355 Summer 2015
- Slides: 31