Turing Machine Recap

Similar documents
Undecidability and Rice s Theorem. Lecture 26, December 3 CS 374, Fall 2015

Lecture Notes: The Halting Problem; Reductions

Decidability. Linz 6 th, Chapter 12: Limits of Algorithmic Computation, page 309ff

Turing Machines Part III

CSCI3390-Lecture 6: An Undecidable Problem

1 Showing Recognizability

Decidability: Church-Turing Thesis

Decidability and Undecidability

Most General computer?

CS20a: Turing Machines (Oct 29, 2002)

CSE 105 Theory of Computation

CS 301. Lecture 18 Decidable languages. Stephen Checkoway. April 2, 2018

Undecidability. Andreas Klappenecker. [based on slides by Prof. Welch]

Introduction to Turing Machines. Reading: Chapters 8 & 9

Undecidability COMS Ashley Montanaro 4 April Department of Computer Science, University of Bristol Bristol, UK

Lecture 23: Rice Theorem and Turing machine behavior properties 21 April 2009

Decision Problems with TM s. Lecture 31: Halting Problem. Universe of discourse. Semi-decidable. Look at following sets: CSCI 81 Spring, 2012

1 Acceptance, Rejection, and I/O for Turing Machines

CPSC 421: Tutorial #1

CSE 105 THEORY OF COMPUTATION

16.1 Countability. CS125 Lecture 16 Fall 2014

15-251: Great Theoretical Ideas in Computer Science Fall 2016 Lecture 6 September 15, Turing & the Uncomputable

Section 14.1 Computability then else

CS151 Complexity Theory. Lecture 1 April 3, 2017

Notes for Lecture Notes 2

TURING MAHINES

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION

CS154, Lecture 10: Rice s Theorem, Oracle Machines

Undecidability. We are not so much concerned if you are slow as when you come to a halt. (Chinese Proverb)

1 Computational Problems

Computational Models Lecture 8 1

There are two main techniques for showing that problems are undecidable: diagonalization and reduction

Decidability (What, stuff is unsolvable?)

Turing & the Uncomputable; Intro to Time Complexity

CSE 105 Theory of Computation

} Some languages are Turing-decidable A Turing Machine will halt on all inputs (either accepting or rejecting). No infinite loops.

Computational Models Lecture 8 1

Computational Models Lecture 8 1

The Turing Machine. Computability. The Church-Turing Thesis (1936) Theory Hall of Fame. Theory Hall of Fame. Undecidability

CSE 311: Foundations of Computing. Lecture 27: Undecidability

CS5371 Theory of Computation. Lecture 12: Computability III (Decidable Languages relating to DFA, NFA, and CFG)

CS20a: Turing Machines (Oct 29, 2002)

CSCE 551: Chin-Tser Huang. University of South Carolina

Turing Machines. Lecture 8

Intro to Theory of Computation

CS 361 Meeting 26 11/10/17

A non-turing-recognizable language

Theory of Computation

1 Definition of a Turing machine

A Note on Turing Machine Design

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) October,

CSE 105 THEORY OF COMPUTATION

The Unsolvability of the Halting Problem. Chapter 19

uring Reducibility Dept. of Computer Sc. & Engg., IIT Kharagpur 1 Turing Reducibility

Decidability: Reduction Proofs

CSE355 SUMMER 2018 LECTURES TURING MACHINES AND (UN)DECIDABILITY

Turing s thesis: (1930) Any computation carried out by mechanical means can be performed by a Turing Machine

Lecture 12: Mapping Reductions

U.C. Berkeley CS278: Computational Complexity Professor Luca Trevisan August 30, Notes for Lecture 1

ECS 120 Lesson 18 Decidable Problems, the Halting Problem

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

Lecture 13: Foundations of Math and Kolmogorov Complexity

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

1 Reals are Uncountable

CSCI3390-Assignment 2 Solutions

Midterm Exam 2 CS 341: Foundations of Computer Science II Fall 2018, face-to-face day section Prof. Marvin K. Nakayama

SD & Turing Enumerable. Lecture 33: Reductions and Undecidability. Lexicographically Enumerable. SD & Turing Enumerable

Undecidability. Almost all Languages are undecidable. Question: Is it just weird languages that no one would care about which are undecidable?

Problems, and How Computer Scientists Solve Them Manas Thakur

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

CS5371 Theory of Computation. Lecture 14: Computability V (Prove by Reduction)

CMPT 710/407 - Complexity Theory Lecture 4: Complexity Classes, Completeness, Linear Speedup, and Hierarchy Theorems

CS 125 Section #10 (Un)decidability and Probability November 1, 2016

Finish K-Complexity, Start Time Complexity

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Midterm Exam 2 CS 341: Foundations of Computer Science II Fall 2016, face-to-face day section Prof. Marvin K. Nakayama

Warm-Up Problem. Please fill out your Teaching Evaluation Survey! Please comment on the warm-up problems if you haven t filled in your survey yet.

A Universal Turing Machine

Reducability. Sipser, pages

ACS2: Decidability Decidability

CS481F01 Solutions 8

CSE 105 THEORY OF COMPUTATION

Automata Theory CS S-FR2 Final Review

Theory of Computation p.1/?? Theory of Computation p.2/?? We develop examples of languages that are decidable

Decidability. Human-aware Robotics. 2017/10/31 Chapter 4.1 in Sipser Ø Announcement:

Introduction to Languages and Computation

6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, Class 8 Nancy Lynch

Foundations of Computer Science Lecture 23 Languages: What is Computation?

COMP/MATH 300 Topics for Spring 2017 June 5, Review and Regular Languages

Theory of Computation

highlights proof by contradiction what about the real numbers?

Limits of Computability

Final Exam (Version B) December 16, 2014 Name: NetID: Section: 1 2 3

Final Exam Version A December 16, 2014 Name: NetID: Section: # Total Score

CpSc 421 Homework 9 Solution

Turing s Legacy Continues

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

CSCE 551 Final Exam, Spring 2004 Answer Key

Mapping Reducibility. Human-aware Robotics. 2017/11/16 Chapter 5.3 in Sipser Ø Announcement:

Transcription:

Turing Machine Recap

DFA with (infinite) tape. One move: read, write, move, change state.

High-level Points Church-Turing thesis: TMs are the most general computing devices. So far no counter example Every TM can be represented as a string. Think of TM as a program but in a very lowlevel language. Universal Turing Machine M u that can simulate a given M on a given string w

Decision Problems A yes/no question over many instances Given grammar G, is G ambiguous? Given a TM M, does L(M) = {0,1} *? Given DFAs M 1 and M 2, does L(M 1 ) = L(M 2 )? Given a graph G, is G connected? Given a graph G, nodes s and t, and number d, is there a path from s to t of distance d or less?

Equivalently, languages: {<G> <G> encodes an unambiguous grammar} {<M> L(M) = {0,1} * } {<M 1 > # <M 2 > DFAs M 1 and M 2, accept the same language} {<G> <G> encodes a connected graph} {<G>#s#t#d <G> encodes a graph with nodes s and t, there is a path from s to t of distance d or less} Deciding membership in the language is solving the decision problem

Decidable A decision problem (language) is decidable if there is a TM that always halts that accepts the language. (The language is recursive.) I.e., there is an algorithm that always answers yes or no correctly. Note: since all finite languages are recursive, (they re regular in fact) any decision problem with only a finite number of instances is decidable, and not well-addressed by this theory...

Example 1: decidable or not? Is there a substring of exactly 374 consecutive 7 s in decimal expansion of π? This is decidable. There is an algorithm which is correct. It is one of these: Alg 1 Output yes Alg 2 Output no We just don t know which one it is But, there is an algorithm which will tell us which it is!

Moral This is nonsense There were no instances of the problem. It simply asks a single yes/no question. Not even clear what language corresponds to it Remember: decidability is for problems with many possible input instances

Example 2 Give n, is there a substring of exactly n consecutive 7 s in π? Language: {n decimal expansion of π contains the substring a7 n b, where a and b are not 7s} Is this language decidable? Is there a halting TM for it? Is it r.e.? (recall: a TM that may not halt but accepts if it should)

Example 3 Give n, is there a substring of at least n consecutive 7 s in π? Language: L = {n decimal expansion of π contains the substring 7 n } Is this language decidable? Is there a halting TM for it? In fact, it is regular! (L is either all of N, or equals {0,1,2,...,k} for some fixed k.)

Universal TM A single TM M u that can compute anything computable! Takes as input the description of some other TM M data w for M to run on Outputs the results of running M(w)

Recap: Typical TM code: 11101010000100100110100100000101011...11...11...111 Begins, ends with 111 Transitions separated by 11 Fields within transition separated by 1 Individual fields represented by 0s Note: this can be viewed as a natural number

Recap: Universal TM M u We saw a TM M u such that L(M u ) = { <M> # w M accepts w} Thus, M u is a stored-program computer. It reads a program <M> and executes it on data w L u = L(M u ) = { <M> # w M accepts w} is r.e.

High-level Points Church-Turing thesis: TMs are the most general computing devices. So far no counter example Every TM can be represented as a string. Think of TM as a program but in a very lowlevel language. Universal Turing Machine M u that can simulate a given M on a given string w

Undecidability

UNDECIDABLE EXP NP P........... R. E. this RECURSIVE... Dtime(n 3 ) Dtime(n 2 ) Dtime(n log n).. lecture not even accepted by a TM Dtime(n)

Undecidable Languages: Counting Argument Are there undecidable languages? Most languages are undecidable! Simple proof: # of TMs/algorithms is countably infinite since each TM can be represented as a natural number (it s description is a unique binary number) # of languages is uncountably infinite

Is L u decidable? Counting argument does not directly tell us about undecidablity of specific interesting languages Recall L u = { <M>#w M accepts w } is r.e. Is L u decidable?

Halting Problem Does given M halt when run on blank input? L halt = {<M> M halts when run on blank input} Is L halt decidable?

Who cares about halting TMs?

Who cares about halting TMs? Remember, TMs = programs Debugging is an important problem in CS Furthermore, virtually all math conjectures can be expressed as a halting-tm question. Example: Goldbach s conjecture: Every even number > 2 is the sum of two primes.

Program Goldbach is-sum-of-two-primes(n): boolean FOR p q < n IF p,q, prime AND p+q=n THEN RETURN TRUE RETURN FALSE goldbach() n = 4 WHILE is-sum-of-two-primes(n) n = n+2 HALT goldbach() halts iff Goldbach s conjecture is false

CS 125 assignment: Write a program that outputs Hello world. main() { printf( Hello world ); } Can you write an auto-grader? If so; you can solve Goldbach s conjecture...

goldbach() n = 4 WHILE is-sum-of-two-primes(n) n = n+2 HALT is-sum-of-two-primes(n): boolean FOR p q < n IF p,q, prime AND p+q=n RETURN FALSE THEN RETURN TRUE main() goldbach(); { printf( Hello world ); } AUTOGRADER So, deciding if a program prints Hello world is solving goldbach s conjecture CORRECT INCORRECT

Deciding halting problem Given program <M>, to determine if M halts, do the following: main() M() { printf( Hello world ); } So, deciding if a program prints Hello world is solving the halting problem AUTOGRADER Using same ideas, we can show that deciding anything about code behavior is not possible CORRECT INCORRECT

L u is not recursive Two proofs Slick proof Slow proof via diagonalization and reduction

L u is not decidable Warm-up: Self-reference leads to paradox In a town there is a barber who shaves all and only those who do not shave themselves Who shaves the barber? Homogenous words: self-describing English, short, polysyllabic Heterogenous words: non-self-describing Spanish, long, monosyllabic What kind of word is heterogenous?

L u is not decidable Proof by contradiction Suppose there was an algorithm (TM) that always halted, as follows: <M> # w TM accept-checker Check if M(w) accepts yes, M(w) accepts no, M(w) doesn t accept * * remember M(w) may not halt which is why this may be difficult We ll show how to use this as a subroutine to get a contradiction

L u is not decidable Proof by contradiction Suppose there was an algorithm (TM) as follows: TM Q <M> copy-arg <M> # <M> w TM accept-checker Decides if M(w) M(<M> accepts ) accepts doesn t accept reject Q(<M>) accepts iff M(<M>) doesn t accept Q(<M>) rejects iff M(<M>) accepts

L u is not decidable TM Q <M> copy-arg <M> # <M> TM accept-checker Decides if accepts M(<M> ) accept doesn t accept reject Q(<M>) accepts iff M(<M>) doesn t accept Q(<M>) rejects iff M(<M>) accepts Does Q(<Q>) accept or reject? either way, a contradiction, so assumption that accept-checker existed was wrong

L u is not decidable: Slow proof Use diagonalization to prove that a specific language L d is not r.e Show that if L u is decidable then L d is decidable which leads to contradiction

Diagonalization Fix alphabet to be {0,1} Recall that {0,1}* is countable: we can enumerate strings as w 0, w 1, w 2,... Recall that we established a correspondence between TMs and binary numbers hence TMs can be enumerated as M 0, M 1, M 2, A language L is a subset of {0,1}*

List of all r.e. languages w 0 w 1 w 2 w 3 w 4 w 5 w 6 w 7 w 8 w 9... M 0 no no no no no no no no no no... M 1 yes no no yes no yes yes yes yes no... M 2 no yes yes no no yes no yes no no... M 3 no yes no yes no yes no yes no yes... M 4 yes yes yes yes no no no no no no... M 5 no no no no no no no no no no... M 6 yes yes yes yes yes yes yes yes yes yes... M 7 yes yes no no yes yes yes no no yes... M 8 no yes no no yes no yes yes yes no... M 9 no no no yes yes no yes no yes yes.......................................

List of all r.e. languages w 0 w 1 w 2 w 3 w 4 w 5 w 6 w 7 w 8 w 9... M 0 no no no no no no no no no no... M 1 yes no no yes no yes yes yes yes no... M 2 no yes yes no no yes no yes no no... M 3 no yes no yes no yes no yes no yes... M 4 yes yes yes yes no no no no no no... M 5 no no no no no no no no no no... M 6 yes yes yes yes yes yes yes yes yes yes... M 7 yes yes no no yes yes yes no no yes... M 8 no yes no no yes no yes yes yes no... M 9 no no no yes yes no yes no yes yes....................................... Consider for each i, whether or not M i accepts w i

List of all r.e. languages w 0 w 1 w 2 w 3 w 4 w 5 w 6 w 7 w 8 w 9... M 0 yes no no no no no no no no no... M 1 yes yes no yes no yes yes yes yes no... M 2 no yes no no no yes no yes no no... M 3 no yes no no no yes no yes no yes... M 4 yes yes yes yes yes no no no no no... M 5 no no no no no yes no no no no... M 6 yes yes yes yes yes yes no yes yes yes... M 7 yes yes no no yes yes yes yes no yes... M 8 no yes no no yes no yes yes no no... M 9 no no no yes yes no yes no yes no....................................... Flip yes and no, defining L d = {w i w i not in L(M i )}

L d = {w i w i not in L(M i )} L d is not r.e. (Why not?) if it were, it would be accepted by some TM M k but L d contains w k iff L(M k ) does not contain w k so L d L(M k ) for any k so L d is not r.e.

Reduction X Y X reduces to Y X-solver I x I REDUCTION Y Y-solver YES NO If Y can be decided, then X can be decided. If X can t be decided, then Y can t be decided

L d L u L d -decider REDUCTION <M,w> L u decider YES M(w) doesn t accept NO M(w) does accept

L d L u L d -decider w i <Mi, w REDUCTION i > L u decider YES M i (w i ) doesn t accept NO M i (w i ) does accept The above is a reduction from L d to complement of L u Note that a language L is decidable iff L is decidable Hence L u is decidable iff L u decidable

L u is not decidable L d is not r.e. by diagonalization Suppose L u is decidable Then L u is also decidable We have shown L d L u which implies L d is decidable, a contradiction Therefore L u is not decidable (undecidable) No algorithm for L u

Using Reductions Once we have some seed problems such as L d and L u we can use reductions to prove that more problems are undecidable

Halting Problem Does given M halt when run on blank input? L halt = {<M> M halts when run on blank input} Show L halt is undecidable by showing L u L halt L u -decider YES REDUCTION L halt decider NO What are input and output of the reduction?

L u L halt L u -decider <M> # w REDUCTION <M > L halt decider YES NO Need: M halts on blank input iff M(w) accepts TM M const M const w run M(w) and halt if it accepts The REDUCTION doesn t run M on w. It produces code for M!

Example Suppose we have the code for a program isprime() and we want to check if it accepts the number 13 The reduction creates new program to give to decider for L halt : note that the reduction only creates the code, does not run any program itself. main() { If (isprime(13)) then HALT else LOOP FOREVER } boolean isprime(int i) { }

L u L halt L u -decider <M> # w REDUCTION <M > L halt decider YES NO Need: M halts on blank input iff M(w) accepts TM M const M const w run M(w) and halt if it accepts Correctness: L u -decider say yes iff M halts on blank input iff M(w) accepts iff <M>#w is in L u

More reductions about languages We ll show other languages involving program behavior are undecidable: L 374 = {<M> L(M) = {0 374 } } L Ø = {<M> L(M) is nonempty} L pal = {<M> L(M) = palindromes} many many others

L 374 = {<M> L(M) = {0 374 } } is undecidable Given a TM M, telling whether it accepts only the string 0 374 is not possible Proved by showing L u L 374 <M> # w <M > = REDUCTION: BUILD M instance of L u instance of L 374 What is L(M )? If M(w) accepts, L(M ) = If M(w) doesn t L(M ) = {0 374 } Ø x M : constants: M, w On input x, 0. if x 0 374, reject 1. if x = 0 374, then run M(w) accept x iff M(w) ever accepts w Q: How does the reduction know whether or not M(w) accepts? A: It doesn t have to. It just builds (code for) M.

If there is a decider M 374 to tell if a TM accepts the language {0 374 }... Decider for L u <M>#w <M > YES: REDUCTION: BUILD M M 374 L(M ) = {0 374 } iff M accepts w M : constants: M, w x On input x, 0. if x 0 374, reject 1. if x = 0 374, then 2. run M(w) accept x iff M(w) ever accepts w Recall L(M ) = {0 374 } iff M(w) accepts NO: L(M ) = Ø {0 374 } iff M doesn t accept w Since L u is not decidable, M 374 doesn t exist, and L 374 is undecidable

L 374 = {<M> L(M) = {0 374 } } is undecidable What about L accepts-374 = {<M> M accepts 0 374 } Is this easier? in fact, yes, since L 374 isn t even r.e., but L accepts-374 is but no, L accepts-374 is not decidable either The same reduction works: If M(w) accepts, L(M ) = {0 374 }, so M accepts 0 374 If M(w) doesn t, L(M ) = Ø, so M doesn t accept 0 374 More generally, telling whether or not a machine accepts any fixed string is undecidable

L Ø = {<M> L(M) is nonempty} is undecidable Given a TM M, telling whether it accepts any string is undecidable Proved by showing L u L Ø <M> # w instance of L u REDUCTION: BUILD M We want M to satisfy: If M(w) accepts, L(M ) If M(w) doesn t L(M ) Ø = Ø <M > = instance of L Ø x M : constants: M, w On input x, Run M(w) Accept x if M(w) accepts What is L(M )? If M(w) accepts, L(M ) = Σ * hence Ø If M(w) doesn t, L(M ) = Ø

If there is a decider M Ø to tell if a TM accepts a nonempty language... Decider for L u <M>#w <M > YES: REDUCTION: BUILD M M Ø L(M ) Ø iff M accepts w M : constants: M, w x On input x, Run M(w) Accept x if M(w) accepts NO: L(M ) = Ø iff M doesn t accept w Since L u is not decidable, M Ø doesn t exist, and L Ø is undecidable

L pal = {<M> L(M) = palindromes} is undecidable Given a TM M, telling whether it accepts the set of palindromes is undecidable Proved by showing L u L pal <M> # w instance of L u REDUCTION: BUILD M We want M to satisfy: If M(w) accepts, L(M ) If M(w) doesn t L(M ) <M > = instance of L pal = {palindromes} {palindromes} x M : constants: M, w On input x, Run M(w) Accept x if M(w) accepts and x is a palindrome

If there is a decider M pal to tell if a TM accepts the set of palindromes Decider for L u <M>#w <M > YES: REDUCTION: BUILD M M pal L(M ) = {palindromes} iff M accepts w M : constants: M, w x On input x, Run M(w) Accept x if M(w) accepts and x is a palindrome NO: L(M ) = Ø {palindromes} iff M doesn t accept w Since L u is not decidable, M pal doesn t exist, and L pal is undecidable

Lots of undecidable problems about languages accepted by programs Given M, is L(M) = {palindromes}? Given M, is L(M) Ø? Given M, is L(M) = {0 374 }? Given M, does L(M) contain 0 374? Given M, is L(M) = {0 p p is prime}? Given M, does L(M) contain any prime? Given M, does L(M) contain any word? Given M, does L(M) meet these formal specs? Given M, does L(M) = Σ *?

UNDECIDABLE EXP NP P........ R. E.... RECURSIVE... L u SUMMARY not even accepted by a TM Dtime(n 3 ) Dtime(n 2 ) Dtime(n log n) Dtime(n)