CSE 311: Foundations of Computing. Lecture 27: Undecidability

Similar documents
CSE 311 Lecture 28: Undecidability of the Halting Problem. Emina Torlak and Kevin Zatloukal

CSE 311: Foundations of Computing. Lecture 26: Cardinality

CSE 311: Foundations of Computing. Lecture 26: Cardinality, Uncomputability

CSE 311: Foundations of Computing. Lecture 26: More on Limits of FSMs, Cardinality

highlights proof by contradiction what about the real numbers?

Turing Machine Recap

computability and complexity theory

1 Showing Recognizability

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.

CSE 105 THEORY OF COMPUTATION

CITS2211 Discrete Structures (2017) Cardinality and Countability

Discrete Mathematics for CS Spring 2007 Luca Trevisan Lecture 27

CSCI3390-Lecture 6: An Undecidable Problem

Lecture Notes: The Halting Problem; Reductions

Decidability and Undecidability

One-to-one functions and onto functions

Discrete Mathematics and Probability Theory Spring 2014 Anant Sahai Note 20. To Infinity And Beyond: Countability and Computability

A non-turing-recognizable language

CSE 4111/5111/6111 Computability Jeff Edmonds Assignment 3: Diagonalization & Halting Problem Due: One week after shown in slides

ECS 120 Lesson 18 Decidable Problems, the Halting Problem

ACS2: Decidability Decidability

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

CSE 105 Theory of Computation

Intro to Theory of Computation

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

1 Reals are Uncountable

Decidable Languages - relationship with other classes.

Math 3361-Modern Algebra Lecture 08 9/26/ Cardinality

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

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

CSE 105 Theory of Computation

Computability, Undeciability and the Halting Problem

CS 361 Meeting 26 11/10/17

Lecture 13: Foundations of Math and Kolmogorov Complexity

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

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

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

Undecibability. Hilbert's 10th Problem: Give an algorithm that given a polynomial decides if the polynomial has integer roots or not.

Great Theoretical Ideas

Computational Models Lecture 8 1

Understanding Computation

Chapter 20. Countability The rationals and the reals. This chapter covers infinite sets and countability.

Turing & the Uncomputable; Intro to Time Complexity

CSE 311: Foundations of Computing I Autumn 2014 Practice Final: Section X. Closed book, closed notes, no cell phones, no calculators.

CPSC 421: Tutorial #1

Computational Models Lecture 8 1

Introduction to Turing Machines. Reading: Chapters 8 & 9

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

Turing Machines Part III

TURING MAHINES

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

Algorithms: Lecture 2

CS20a: Turing Machines (Oct 29, 2002)

Computational Models Lecture 8 1

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

Turing Machines, diagonalization, the halting problem, reducibility

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

Turing Machines. Lecture 8

ON COMPUTAMBLE NUMBERS, WITH AN APPLICATION TO THE ENTSCHENIDUGSPROBLEM. Turing 1936

Decidability (What, stuff is unsolvable?)

Great Theoretical Ideas in Computer Science. Lecture 5: Cantor s Legacy

CSE355 SUMMER 2018 LECTURES TURING MACHINES AND (UN)DECIDABILITY

Most General computer?

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

CS154, Lecture 12: Kolmogorov Complexity: A Universal Theory of Data Compression

16.1 Countability. CS125 Lecture 16 Fall 2014

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

Acknowledgments 2. Part 0: Overview 17

CSE 105 THEORY OF COMPUTATION

acs-07: Decidability Decidability Andreas Karwath und Malte Helmert Informatik Theorie II (A) WS2009/10

15-251: Great Theoretical Ideas in Computer Science Lecture 7. Turing s Legacy Continues

4.2 The Halting Problem

CS154, Lecture 10: Rice s Theorem, Oracle Machines

What languages are Turing-decidable? What languages are not Turing-decidable? Is there a language that isn t even Turingrecognizable?

Turing Machines. Reading Assignment: Sipser Chapter 3.1, 4.2

Reading Assignment: Sipser Chapter 3.1, 4.2

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

Decidability: Church-Turing Thesis

Decidability: Reduction Proofs

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

Reductions in Computability Theory

CSCE 551 Final Exam, April 28, 2016 Answer Key

A Note on Turing Machine Design

Turing s Legacy Continues

Farewell (for now) to modular arithmetic...

CSE 105 THEORY OF COMPUTATION

Logic and Computation

A Universal Turing Machine

CSE 555 Homework Three Sample Solutions

Chap. 4,5 Review. Algorithms created in proofs from prior chapters

CSE 105 THEORY OF COMPUTATION

Exam Computability and Complexity

CSE 20 DISCRETE MATH. Fall

V Honors Theory of Computation

LECTURE 22: COUNTABLE AND UNCOUNTABLE SETS

WHY WORD PROBLEMS ARE HARD

Introduction to the Theory of Computing

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

Notes for Lecture Notes 2

Transcription:

CSE 311: Foundations of Computing Lecture 27: Undecidability

Last time: Countable sets A set is countable iff we can order the elements of as = {,,, Countable sets: N-the natural numbers Z - the integers Q-the rationals Σ - the strings over any finite Σ The set of all Java programs Shown by dovetailing

Last time: Not every set is countable Theorem [Cantor]: The set of real numbers between 0 and 1 is notcountable. Proof using diagonalization.

Last time: Proof that [0,1) is not countable Suppose, for the sake of contradiction, that there is a list of them: 1 2 3 4 Flipping 5 6 rule: 7 8 9... r 1 0. 5 1 0 0 0 If 0 digit 0is 5, make 0 it 01....... 5 r 2 0. 3 3 3 3 If 3 digit 3is not 35, make 3 it 5....... 5 r 3 0. 1 4 2 8 5 7 1 4...... 1 r 4 0. 1 4 1 5 9 2 6 5...... r 5 0. 1 2 1 2 2 5 1 2 2...... r =. 6 0. 2 5 0 0 0 0 5 0 0...... 5 r 7 0. 7 1 8 2 8 1 8 2...... rso 8 the 0. list is 6incomplete, 1 8which 0is a contradiction. 3 3 9 45...... For every : because the numbers differ on the -th digit! Thus the real numbers between 0 and 1 are not countable: uncountable.................................

A note on this proof The set of rational numbers in [0,1) also have decimal representations like this The only difference is that rational numbers always have repeating decimals in their expansions 0.33333... or.25000000... So why wouldn t the same proof show that this set of rational numbers is uncountable? Given any listing (even one that is good like the dovetailing listing) we could create the flipped diagonal number as before However, would not have a repeating decimal expansion and so wouldn t be a rational # It would not be a missing number, so no contradiction.

Last time: The set of all functions N {0,, 9is uncountable Supposed listing of all the functions: 1 2 3 4 Flipping 5 6rule: 7 8 9... f 1 0. 1 5 0 0 0 If 0$ 0=, 0set # 0 =...... 5 f 2 0. 3 3 3 3 If 3$ 3, 3set # 3 =...... 5 f 3 0. 1 4 2 8 5 7 1 4...... 1 f 4 0. 1 4 1 5 9 2 6 5...... f 5 0. 1 2 1 2 5 2 1 2 2...... f 6 0. 2 5 0 0 0 5 0 0 0...... 5 f 7 0. 7 1 8 2 8 1 8 2...... f 8 0. 6 1 8 0 3 3 9 4 5...... For all, we have # $ (). Therefore # $ for any and the list is incomplete! $ $: N {0,1,, 9 is not countable.................................

Last time: Uncomputable functions We have seen that: The set of all (Java) programs is countable The set of all functions N {0,, 9 is not countable So: There must be some function N {0,, 9 that is not computable by any program! Interesting maybe. Can we come up with an explicit function that is uncomputable?

A Simple Program public static void collatz(n) { if (n == 1) { return 1; if (n % 2 == 0) { return collatz(n/2) else { return collatz(3*n + 1) What does this program do? on n=11? on n=10000000000000000001? 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1

A Simple Program public static void collatz(n) { if (n == 1) { return 1; if (n % 2 == 0) { return collatz(n/2) else { return collatz(3*n + 1) What does this program do? on n=11? on n=10000000000000000001? Nobody knows whether or not this program halts on all inputs! Trying to solve this has been called a mathematical disease.

Recall our language picture All Java Context-Free Binary Palindromes 0* Regular Finite DFA NFA Regex {001, 10, 12

Some Notation We re going to be talking about Java code. CODE(P) will mean the code of the program P So, consider the following function: public String P(String x) { return new String(Arrays.sort(x.toCharArray()); What is P(CODE(P))? (((())))..;AACPSSaaabceeggghiiiilnnnnnooprrrrrrrrrrrsssttttttuuwxxyy{

Undecidability of The Halting Problem CODE(P) means the code of the program P The Halting Problem Given: - CODE(P) for any program P - input x Output: true if P halts on input x false if P does not halt on input x

Undecidability of the Halting Problem CODE(P) means the code of the program P The Halting Problem Given: - CODE(P) for any program P - input x Output: true if P halts on input x false if P does not halt on input x Theorem [Turing]: There is no program that solves the Halting Problem

Proof by contradiction Suppose that His a Java program that solves the Halting problem. Then we can write this program: public static void D(x) { if (H(x,x) == true) { else { while (true); /* don t halt */ return; /* halt */ Does D(CODE(D)) halt?

Does D(CODE(D)) halt? public static void D(x) { if (H(x,x) == true) { while (true); /* don t halt */ else { return; /* halt */

Does D(CODE(D)) halt? public static void D(x) { if (H(x,x) == true) { while (true); /* don t halt */ else { return; /* halt */ H solves the halting problem implies that H(CODE(D),x) is true iff D(x) halts, H(CODE(D),x) is false iff not Suppose that D(CODE(D)) halts. Then, by definition of H it must be that Note: H(CODE(D), Even though CODE(D)) the program is true D has a Which by while(true), the definition that of Ddoesn t means D(CODE(D)) mean that the doesn t halt program D actually goes into an infinite Suppose that loop D(CODE(D)) on input x, doesn t which is halt. what H has to Then, by definition determineof H it must be that H(CODE(D), CODE(D)) is false Which by the definition of D means D(CODE(D)) halts

Does D(CODE(D)) halt? public static void D(x) { if (H(x,x) == true) { while (true); /* don t halt */ else { return; /* halt */ H solves the halting problem implies that H(CODE(D),x) is true iff D(x) halts, H(CODE(D),x) is false iff not Suppose that D(CODE(D)) halts. Then, by definition of H it must be that H(CODE(D), CODE(D)) is true Which by the definition of D means D(CODE(D)) doesn t halt Suppose that D(CODE(D)) doesn t halt. Then, by definition of H it must be that H(CODE(D), CODE(D)) is false Which by the definition of D means D(CODE(D)) halts

Does D(CODE(D)) halt? public static void D(x) { if (H(x,x) == true) { while (true); /* don t halt */ else { return; /* halt */ H solves the halting problem implies that H(CODE(D),x) is true iff D(x) halts, H(CODE(D),x) is false iff not Suppose that D(CODE(D)) halts. Then, by definition of H it must be that H(CODE(D), CODE(D)) is true Which by the definition of D means D(CODE(D)) doesn t halt Suppose that D(CODE(D)) doesn t halt. Then, by definition of H it must be that H(CODE(D), CODE(D)) is false Which by the definition of D means D(CODE(D)) halts

Does D(CODE(D)) halt? public static void D(x) { if (H(x,x) == true) { while (true); /* don t halt */ else { return; /* halt */ H solves the halting problem implies that H(CODE(D),x) is true iff D(x) halts, H(CODE(D),x) is false iff not Suppose that D(CODE(D)) halts. Then, by definition of H it must be that H(CODE(D), CODE(D)) is true Which by the definition of D means D(CODE(D)) doesn t halt Suppose that D(CODE(D)) doesn t halt. Then, by definition of H it must be that H(CODE(D), CODE(D)) is false Which by the definition of D means D(CODE(D)) halts Contradiction!

Done We proved that there is no computer program that can solve the Halting Problem. There was nothing special about Java* [Church-Turing thesis] This tells us that there is no compiler that can check our programs and guarantee to find any infinite loops they might have.

Where did the idea for creating D come from? public static void D(x) { if (H(x,x) == true) { while (true); /* don t halt */ else { return; /* halt */ D halts on input code(p) iff H(code(P),code(P)) outputs false iff P doesn t halt on input code(p) Therefore for any program P, Ddiffers from P on input code(p)

Connection to diagonalization Write <P> for CODE(P) <P 1 > <P 2 > <P 3 > <P 4 > <P 5 > <P 6 >... Some possible inputs x P 1 P 2 P 3 P 4 P 5 P 6 P 7 P 8 P 9.. This listing of all programs really does exist since the set of all Java programs is countable The goal of this diagonal argument is not to show that the listing is incomplete but rather to show that a flipped diagonal element is not in the listing

Connection to diagonalization P 1 P 2 P 3 P 4 P 5 P 6 P 7 P 8 P 9.. Write <P> for CODE(P) <P 1 > <P 2 > <P 3 > <P 4 > <P 5 > <P 6 >... Some possible inputs x 0 1 1 0 1 1 1 0 0 0 1... 1 1 0 1 0 1 1 0 1 1 1... 1 0 1 0 0 0 0 0 0 0 1... 0 1 1 0 1 0 1 1 0 1 0... 0 1 1 1 1 1 1 0 0 0 1... 1 1 0 0 0 1 1 0 1 1 1... 1 0 1 1 0 0 0 0 0 0 1... 0 1 1 1 1 0 1 1 0 1 0........................... (P,x) entry is 1 if program P halts on input x and 0 if it runs forever

Connection to diagonalization P 1 P 2 P 3 P 4 P 5 P 6 P 7 P 8 P 9.. <P 1 > <P 2 > <P 3 > <P 4 > <P 5 > <P 6 >... Some possible inputs x 1 Write <P> for CODE(P) 0 1 1 0 1 Want 1 behavior 1 0 of program 0 0 # to be 1... 0 1 1 0 1 0 like 1 the 1 flipped 0 diagonal, 1 so 1 it can t 1... 1 0 10 0 0 be 0 in the 0 list 0 of all programs. 0 0 1... 0 1 1 0 1 1 0 1 1 0 1 0... 0 1 1 1 10 1 1 0 0 0 1... 0 1 1 0 0 0 1 1 0 1 1 1... 1 0 1 1 0 0 01 0 0 0 1... 0 1 1 1 1 0 1 10 0 1 0........................... (P,x) entry is 1 if program P halts on input x and 0 if it runs forever

The Halting Problem isn t the only hard problem Can use the fact that the Halting Problem is undecidable to show that other problems are undecidable General method: Prove that if there were a program deciding Bthen there would be a way to build a program deciding the Halting Problem. B decidable Halting Problem decidable Contrapositive: Halting Problem undecidable Bundecidable Therefore B is undecidable

A CSE 141 assignment Students should write a Java program that: Prints Hello to the console Eventually exits GradeIt, PracticeIt, etc. need to grade the students. How do we write that grading program? WE CAN T: THIS IS IMPOSSIBLE!

A related undecidable problem HelloWorldTestingProblem: Input: CODE(Q) and x Output: True if Q outputs HELLO WORLD on input x False if Q does not output HELLO WORLD on input x Theorem: The HelloWorldTesting Problem is undecidable. Proof idea: Show that if there is a program Tto decide HelloWorldTestingthen there is a program Hto decide the Halting Problem for code(p) and x.

A related undecidable problem Suppose there is a program Tthat solves the HelloWorldTestingproblem. Define program Hthat takes input CODE(P) and x and does the following: Creates CODE(Q) from CODE(P) by (1) removing all output statements from CODE(P), and (2) adding a System.out.println( HELLO WORLD ) immediately before any spot where P could halt Then runs Ton input CODE(Q) and x. IfP halts on input x then Q prints HELLO WORLD and halts and so H outputs true (because T outputs true on input CODE(Q)) If P doesn t halt on input x thenq won t print anything since we removed any other print statement from CODE(Q) so H outputs false We know that such an Hcannot exist. Therefore Tcannot exist.