CSCE 355 Foundations of Computation Lecture 23 Turing

  • Slides: 28
Download presentation
CSCE 355 Foundations of Computation Lecture 23 Turing Machines Topics: n Pumping Lemma for

CSCE 355 Foundations of Computation Lecture 23 Turing Machines Topics: n Pumping Lemma for CFL Example n Chomsky hierarchy What’s Computable ? Turing Machines n n November 24, 2008

Last Time: n n Chomsky normal form Pumping Lemma for Context Free Languages New:

Last Time: n n Chomsky normal form Pumping Lemma for Context Free Languages New: n n – 2– Pumping Lemma for Context Free Languages Chomsky Hierarchy CSCE 355 Fall 2008

Pumping Lemma for CFLs Let L be a CFL. Then there exists a constant

Pumping Lemma for CFLs Let L be a CFL. Then there exists a constant n such that if z is a string in L of length at least n, then we can write z = uvwxy such that 1. |vwx| =< n 2. |vx| > 0 3. uviwxi y is in L – 3– for all i >= 0. CSCE 355 Fall 2008

Idea behind proof • Assume CNF (or do for L(G)-{ε}) • Consider Parse Tree

Idea behind proof • Assume CNF (or do for L(G)-{ε}) • Consider Parse Tree • Sufficiently long string z, means the parse tree must be sufficiently big. – 4– CSCE 355 Fall 2008

Example L = {ww | w in {0, 1}* } • Given L as

Example L = {ww | w in {0, 1}* } • Given L as above, suppose we chose n for the Pumping Lemma (for CFLs). • Choose z = • Consider arbitrary partition of z = uvwxy satisfying 1. 2. • – 5– | vwx| =< n |vx| > 0 Then show … CSCE 355 Fall 2008

Example continued – 6– CSCE 355 Fall 2008

Example continued – 6– CSCE 355 Fall 2008

Chomsky Hierarchy http: //en. wikipedia. org/wiki/Chomsky_hierarchy Grammar Languages Automaton Production rules (constraints) Type-0 Recursively

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 – 7– CSCE 355 Fall 2008

Chomsky Hierarchy Venn Diagram – 8– CSCE 355 Fall 2008

Chomsky Hierarchy Venn Diagram – 8– CSCE 355 Fall 2008

Alan Turing • British Mathematician • Led team that cracked Enigma (German Code) •

Alan Turing • British Mathematician • Led team that cracked Enigma (German Code) • Formalized concept of algorithms – model “any possible computation” • Turing Test AI • References n n n – 9– http: //www. turing. org. uk/turing/ http: //www-groups. dcs. stand. ac. uk/~history/Biographies/Turing. html http: //www-groups. dcs. stand. ac. uk/~history/Extras/Turing_running. html CSCE 355 Fall 2008

What is computable? – 10 – CSCE 355 Fall 2008

What is computable? – 10 – CSCE 355 Fall 2008

Hello World Programs 1. Hello. World. rb 2. Hello. Fermat. rb 3. Hello. World.

Hello World Programs 1. Hello. World. rb 2. Hello. Fermat. rb 3. Hello. World. Detecter 1. rb 4. Hello. World. Detecter 2. rb 5. Hello. World. Detecter 3. rb – 11 – CSCE 355 Fall 2008

Hello. World 0. rb puts "Hello World!" – 12 – CSCE 355 Fall 2008

Hello. World 0. rb puts "Hello World!" – 12 – CSCE 355 Fall 2008

Fermat’s Last Theorem • Conjecture from 1637 n "I have a truly marvellous proof

Fermat’s Last Theorem • Conjecture from 1637 n "I have a truly marvellous proof of this proposition which this margin is too narrow to contain. “ • proved by Andrew Wiles in 1995 (358 years later) • But for discussion assume still not proven. – 13 – http: //en. wikipedia. org/wiki/Fermat%27 s_Last_Theorem CSCE 355 Fall 2008

Hello. Fermat. rb n = 3; total = 3 ## Fermat’s Last Theorem Checker

Hello. Fermat. rb n = 3; total = 3 ## Fermat’s Last Theorem Checker as hello. World found. Solution = 0 while found. Solution = 0 1. upto(total-2) do |x| 1. upto(total-x-1) do |y| z = total-x-y if (x**n + y**n == z**n) puts "Hello World!" found. Solution = 1 end; total = total+1 puts "total=#{total}" – end; 14 – CSCE 355 Fall 2008

Questions on Hello. Fermat. rb • Will it print “Hello World!” ? • Is

Questions on Hello. Fermat. rb • Will it print “Hello World!” ? • Is it possible to modify the ruby interpreter to tell if it will print “Hello World!” ? – 15 – CSCE 355 Fall 2008

– 16 – http: //iti. zcu. cz/domazlice 08/ CSCE 355 Fall 2008

– 16 – http: //iti. zcu. cz/domazlice 08/ CSCE 355 Fall 2008

Hello. World. Tester. rb • Write ruby simulator “Hello. World. Tester. rb” that will

Hello. World. Tester. rb • Write ruby simulator “Hello. World. Tester. rb” that will test 1. Read a ruby program prog. rb and its input “I” 2. Simulate the program on that input 3. Print “yes” if the first thing “prog. rb” would print when run on Input would be “Hello World!” • Assumptions 1. All I/O is character based 2. Only using the function puts 3. Assume “print Hello World!” means the first characters printed are “Hello World!” – 17 – CSCE 355 Fall 2008

Hello. World. Tester. rb (figure 8. 3) Input Program Hello World! tester. rb H

Hello. World. Tester. rb (figure 8. 3) Input Program Hello World! tester. rb H yes no • To simplify n Input will just be “I” n Program will just be “P” Hello. World. Tester will just be H n I P – 18 – H yes no CSCE 355 Fall 2008

Hello. World. Tester 1. rb (figure 8. 4) I P H 1 yes Hello

Hello. World. Tester 1. rb (figure 8. 4) I P H 1 yes Hello World! • Modify the original Hello. World tester H so that when it would have printed “no” it now prints “Hello World!” • Note this new program H 1 behaves just like H except when H prints no. – 19 – CSCE 355 Fall 2008

Hello. World. Tester 2. rb (figure 8. 5) P H 2 yes Hello World!

Hello. World. Tester 2. rb (figure 8. 5) P H 2 yes Hello World! • Interested in programs that read other programs as their input • Now Modify H 1 to get H 2 • Treat P as both the program and its input “operate P on itself as the data” • Note on H 2’s behavior n n – 20 – If P would print “Hello World!” then H 2 prints yes Else if P would not print it then H 2 prints “Hello World!” CSCE 355 Fall 2008

What does H 2 do when run on itself ? (figure 8. 6) H

What does H 2 do when run on itself ? (figure 8. 6) H 2 yes Hello World! • But now consider P = H 2 • Note on H 2’s behavior now is n n – 21 – If H 2 would print “Hello World!” then H 2 prints yes Else if H 2 would not print it then H 2 prints “Hello World!” CSCE 355 Fall 2008

Contradiction • So assuming writing a program H that can tell whether another arbitrary

Contradiction • So assuming writing a program H that can tell whether another arbitrary program will print “Hello World!” is impossible • So some problems are not solvable by computers. • Godel’s Incompleteness Theorem – 22 – CSCE 355 Fall 2008

Turing Machines • Model of “any possible computation” i. e. an algorithm • Finite

Turing Machines • Model of “any possible computation” i. e. an algorithm • Finite State Control + “infinite tape” for memory – 23 – CSCE 355 Fall 2008

Formal Definition of Turing Machine M = (Q, Σ, Γ, δ, q 0 ,

Formal Definition of Turing Machine M = (Q, Σ, Γ, δ, q 0 , B, F) • Q • Σ • Γ • δ: Q x Γ x {L, R} n δ(q, X) = (p, Y, D) • q 0 • B – blank symbol in Γ but not in Σ • F – 24 – CSCE 355 Fall 2008

Instantaneous Descriptors • What do we need to describe to characterize the state of

Instantaneous Descriptors • What do we need to describe to characterize the state of a Turing Machine? n n n State Contents of the tape Where the read/write head is located • So an instantaneous descriptor looks like X 1 X 2…Xi-1 q Xi Xi+1, … Xn • exceptions – 25 – CSCE 355 Fall 2008

Moves of the Turing Machine • ID 1 ├ ID 2 • ID 1

Moves of the Turing Machine • ID 1 ├ ID 2 • ID 1 ├* ID 2 – 26 – CSCE 355 Fall 2008

Example figure 8. 9 – 27 – CSCE 355 Fall 2008

Example figure 8. 9 – 27 – CSCE 355 Fall 2008

Homework 1. 8. 2. 1 b – 28 – CSCE 355 Fall 2008

Homework 1. 8. 2. 1 b – 28 – CSCE 355 Fall 2008