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

Similar documents
CSE 311: Foundations of Computing. Lecture 27: Undecidability

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

CSE 105 THEORY OF COMPUTATION

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

CSE 311: Foundations of Computing. Lecture 26: Cardinality

Turing Machine Recap

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

There are problems that cannot be solved by computer programs (i.e. algorithms) even assuming unlimited time and space.

CSE 105 THEORY OF COMPUTATION

CSE 311 Lecture 25: Relating NFAs, DFAs, and Regular Expressions. Emina Torlak and Kevin Zatloukal

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

CSCI3390-Lecture 6: An Undecidable Problem

Final Exam Review. 2. Let A = {, { }}. What is the cardinality of A? Is

Practice Midterm Exam Solutions

A non-turing-recognizable language

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

Contribution of Problems

CSE 105 Theory of Computation

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

Discrete Mathematics. W. Ethan Duckworth. Fall 2017, Loyola University Maryland

Decidability: Church-Turing Thesis

One-to-one functions and onto functions

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

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

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

CSE 311 Lecture 13: Primes and GCD. Emina Torlak and Kevin Zatloukal

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.

Introduction to Turing Machines. Reading: Chapters 8 & 9

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

Discrete Mathematics and Probability Theory Fall 2012 Vazirani Note 1

CS70 is a course about on Discrete Mathematics for Computer Scientists. The purpose of the course is to teach you about:

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

Decidability (What, stuff is unsolvable?)

1 Reals are Uncountable

6.8 The Post Correspondence Problem

Contribution of Problems

Turing Machines. Lecture 8

CSE 311 Lecture 11: Modular Arithmetic. Emina Torlak and Kevin Zatloukal

CITS2211 Discrete Structures (2017) Cardinality and Countability

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

Introduction to the Theory of Computing

cse 311: foundations of computing Fall 2015 Lecture 6: Predicate Logic, Logical Inference

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

Theory Bridge Exam Example Questions

Announcements. CS243: Discrete Structures. Sequences, Summations, and Cardinality of Infinite Sets. More on Midterm. Midterm.

Great Theoretical Ideas

Learning Goals of CS245 Logic and Computation

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Turing Machines. Reading Assignment: Sipser Chapter 3.1, 4.2

Reading Assignment: Sipser Chapter 3.1, 4.2

CPSC 421: Tutorial #1

Preparing for the CS 173 (A) Fall 2018 Midterm 1

ACS2: Decidability Decidability

First-Order Logic (FOL)

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

Solutions to Old Final Exams (For Fall 2007)

Lecture 1. Econ 2001: Introduction to Mathematical Methods (a.k.a. Math Camp) 2015 August 10

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

CSE 105 THEORY OF COMPUTATION

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

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

Final exam study sheet for CS3719 Turing machines and decidability.

Intro to Theory of Computation

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

1 Showing Recognizability

Economics 204 Summer/Fall 2017 Lecture 1 Monday July 17, 2017

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

PROOFS IN PREDICATE LOGIC AND COMPLETENESS; WHAT DECIDABILITY MEANS HUTH AND RYAN 2.3, SUPPLEMENTARY NOTES 2

Regular Languages and Finite Automata

Reducability. Sipser, pages

Section 14.1 Computability then else

16.1 Countability. CS125 Lecture 16 Fall 2014

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

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

CSE 311: Foundations of Computing I. Lecture 1: Propositional Logic

4.2 The Halting Problem

Notes for Lecture Notes 2

Lecture Notes: The Halting Problem; Reductions

CSCI 2200 Foundations of Computer Science Spring 2018 Quiz 3 (May 2, 2018) SOLUTIONS

CpSc 421 Final Exam December 6, 2008

1 Functions, relations, and infinite cardinality

Limits of Computability

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

Handbook of Logic and Proof Techniques for Computer Science

UNIVERSITY OF VICTORIA DECEMBER EXAMINATIONS MATH 122: Logic and Foundations

CS481F01 Solutions 8

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

CP405 Theory of Computation

CSE 105 Theory of Computation

Approximation Algorithms

Understanding Computation

Decidable and undecidable languages

CS 4110 Programming Languages & Logics. Lecture 25 Records and Subtyping

CS20a: Turing Machines (Oct 29, 2002)

CSE 105 THEORY OF COMPUTATION

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

Turing Machines Part III

Turing machine recap. Universal Turing Machines and Undecidability. Alphabet size doesn t matter. Robustness of TM

Lecture 11: Gödel s Second Incompleteness Theorem, and Tarski s Theorem

Nondeterministic finite automata

Transcription:

CSE 311 Lecture 28: Undecidability of the Halting Problem Emina Torlak and Kevin Zatloukal 1

Topics Final exam Logistics, format, and topics. Countability and uncomputability A quick recap of Lecture 27. Undecidability of the halting problem Important problems computers can t solve. 2

Final exam Logistics, format, and topics. 3

Final exam logistics Monday, December 10 in JHN 102 Section A at 16:30-18:20, Section B at 14:30-16:20. 4

Final exam logistics Monday, December 10 in JHN 102 Section A at 16:30-18:20, Section B at 14:30-16:20. Important: take the exam at the time assigned to your section. If you have a scheduling conflict, email the staff ASAP. Bring your UW ID and have it ready to be checked during the exam. 4

Final exam logistics Monday, December 10 in JHN 102 Section A at 16:30-18:20, Section B at 14:30-16:20. Important: take the exam at the time assigned to your section. If you have a scheduling conflict, email the staff ASAP. Bring your UW ID and have it ready to be checked during the exam. Final review session is on Sunday, Dec 09 at 15:00-17:00 in GWN 301. Bring your questions! 4

Final exam format and topics Format 8 problems in 110 minutes. Closed book, closed notes, no calculators, no cellphones. 5

Final exam format and topics Format 8 problems in 110 minutes. Closed book, closed notes, no calculators, no cellphones. Questions and topics (1) Write a regex, DFA, CFG for given languages. (2) A formal proof. (3) A proof by strong induction. (4) A proof by structural induction. (5) NFA to DFA conversion. (6) DFA minimization. (7) A proof that a language is irregular. (8) Short answers on modular arithmetic, relations, logic, uncomputability. 5

Final exam format and topics Format 8 problems in 110 minutes. Closed book, closed notes, no calculators, no cellphones. Questions and topics (1) Write a regex, DFA, CFG for given languages. (2) A formal proof. (3) A proof by strong induction. (4) A proof by structural induction. (5) NFA to DFA conversion. (6) DFA minimization. (7) A proof that a language is irregular. (8) Short answers on modular arithmetic, relations, logic, uncomputability. You ve solved similar problems on homeworks and in sections. Do the easy parts of all the problems first. Don t get stuck on one problem! 5

Countability and uncomputability A quick recap of Lecture 27. 6

Countable and uncountable sets Countable set A set is countable iff it has the same cardinality as some subset of. N 7

Countable and uncountable sets Countable set A set is countable iff it has the same cardinality as some subset of. N Countable sets N (natural numbers) Z (integers) Q + (positive rational numbers) Σ over finite Σ All (Java) programs Shown by dovetailing. 7

Countable and uncountable sets Countable set A set is countable iff it has the same cardinality as some subset of. N Countable sets N (natural numbers) Z (integers) Q + (positive rational numbers) Σ over finite Σ All (Java) programs Uncountable sets All real numbers in [0, 1) All functions from N to {0, 1} Shown by dovetailing. Shown by diagonalization. 7

Uncomputable functions We have seen that The set of all (Java) programs is countable. The set of all functions f : N {0, 1} is uncountable. So there must be some function that is not computable by any program! All General Programming {0 n 1 n 2 n : n 0} Context-Free S 0S1 ε Regular 0*1* Finite {010,11, 21} Java CFG DFA NFA Regex C++ C... 8

Uncomputable functions We have seen that The set of all (Java) programs is countable. The set of all functions f : N {0, 1} is uncountable. So there must be some function that is not computable by any program! We ll study one such important function today. halt(p, x) Context-Free S 0S1 ε Regular 0*1* All General Programming {0 n 1 n 2 n : n 0} Finite {010,11, 21} Java CFG DFA NFA Regex C++ C... 8

Undecidability of the halting problem Important problems computers can t solve. 9

First, some notation We ll be talking about (Java) code. code(p) will denote the code of the program P. 10

First, some notation We ll be talking about (Java) code. code(p) will denote the code of the program P. Consider this program: public static boolean P(String x) { return x.matches("public.*"); } 10

First, some notation We ll be talking about (Java) code. code(p) will denote the code of the program P. Consider this program: public static boolean P(String x) { return x.matches("public.*"); } What is P(code(P))? 10

First, some notation We ll be talking about (Java) code. code(p) will denote the code of the program P. Consider this program: public static boolean P(String x) { return x.matches("public.*"); } What is P(code(P))? true 10

And now, the halting problem! The Halting Problem Given an input x and code(p) for any program P, output true if P halts on the input x, and output false if does not halt (diverges) on the input. P x 11

And now, the halting problem! The Halting Problem Given an input x and code(p) for any program P, output true if P halts on the input x, and output false if does not halt (diverges) on the input. P Can t we determine this by just running on? P x x 11

And now, the halting problem! The Halting Problem Given an input x and code(p) for any program P, output true if P halts on the input x, and output false if does not halt (diverges) on the input. P Can t we determine this by just running on? No! We can t tell if diverged on or is taking a long time to return. P x P x x 11

The halting problem is undecidable The Halting Problem Given an input x and code(p) for any program P, output true if P halts on the input x, and output false if does not halt (diverges) on the input. P Theorem (due to Alan Turing) There is no program that solves the halting problem. x 12

The halting problem is undecidable The Halting Problem Given an input x and code(p) for any program P, output true if P halts on the input x, and output false if does not halt (diverges) on the input. P Theorem (due to Alan Turing) There is no program that solves the halting problem. In other words, there is no program that computes the function described by the halting problem. This function is therefore uncomputable. Because the function outputs a boolean (a yes/no decision), we say that the underlying problem is undecidable. x 12

Proof by contradiction Suppose that H is a program that solves the halting problem. 13

Proof by contradiction Suppose that H is a program that solves the halting problem. Then, we can write the program D as follows: public static void D(String x) { if (H(x, x) == true) { while (true); // diverge } else { return; // halt } } 13

Proof by contradiction Suppose that H is a program that solves the halting problem. Then, we can write the program D as follows: public static void D(String x) { if (H(x, x) == true) { while (true); // diverge } else { return; // halt } } Does D(code(D)) halt? 13

Proof by contradiction Suppose that H is a program that solves the halting problem. Then, we can write the program D as follows: public static void D(String x) { if (H(x, x) == true) { while (true); // diverge } else { return; // halt } } Does D(code(D)) halt? H solves the halting problem means the following: If D(x) halts then H(code(D),x) is true otherwise H(code(D),x) is false. 13

Proof by contradiction Suppose that H is a program that solves the halting problem. Then, we can write the program D as follows: public static void D(String x) { if (H(x, x) == true) { while (true); // diverge } else { return; // halt } } Does D(code(D)) halt? H solves the halting problem means the following: If D(x) halts then H(code(D),x) is true otherwise H(code(D),x) is false. Suppose that D(code(D)) halts. Then, by definition of H, it must be that H(code(D),code(D)) is true. But in that case, D(code(D)) doesn t halt by definition of D. 13

Proof by contradiction Suppose that H is a program that solves the halting problem. Then, we can write the program D as follows: public static void D(String x) { if (H(x, x) == true) { while (true); // diverge } else { return; // halt } } Does D(code(D)) halt? H solves the halting problem means the following: If D(x) halts then H(code(D),x) is true otherwise H(code(D),x) is false. Suppose that D(code(D)) halts. Then, by definition of H, it must be that H(code(D),code(D)) is true. But in that case, D(code(D)) doesn t halt by definition of D. Suppose that D(code(D)) doesn t halt. Then, by definition of H, it must be that H(code(D),code(D)) is false. But in that case, D(code(D)) halts by definition of D. 13

Proof by contradiction Suppose that H is a program that solves the halting problem. Then, we can write the program D as follows: public static void D(String x) { if (H(x, x) == true) { while (true); // diverge } else { return; // halt } } Does D(code(D)) halt? H solves the halting problem means the following: If D(x) halts then H(code(D),x) is true otherwise H(code(D),x) is false. Suppose that D(code(D)) halts. Then, by definition of H, it must be that H(code(D),code(D)) is true. But in that case, D(code(D)) doesn t halt by definition of D. Suppose that D(code(D)) doesn t halt. Then, by definition of H, it must be that H(code(D),code(D)) is false. But in that case, D(code(D)) halts by definition of D. So we reach a contradiction in either case. Therefore, our assumption that H exists must be false. 13

Where did the idea for creating D come from? public static void D(Object x) { if (H(x, x) == true) { while (true); // diverge } else { return; // halt } } Note that D halts on code(p) iff H(code(P),code(P)) outputs false, i.e., iff P doesn t halt on the input code(p). Therefore, D differs from every program P on the input code(p). 14

Where did the idea for creating D come from? public static void D(Object x) { if (H(x, x) == true) { while (true); // diverge } else { return; // halt } } Note that D halts on code(p) iff H(code(P),code(P)) outputs false, i.e., iff P doesn t halt on the input code(p). Therefore, D differs from every program P on the input code(p). This sounds like diagonalization! 14

D is for diagonalization List all Java programs. This list exists because the set of all Java programs is countable. P 0 P 1 P 2 P 3 P 4 15

D is for diagonalization List all Java programs. This list exists because the set of all Java programs is countable. Let P stand for code(p). P 0 P 1 P 2 P 0 P 1 P 2 P 3 P 4 P 3 P 4 15

D is for diagonalization List all Java programs. This list exists because the set of all Java programs is countable. P Let stand for code(p). (P, x) entry is 1 if the program on input and 0 otherwise. x P halts P 0 P 1 P 2 P 3 P 4 P 0 P 1 P 2 P 3 P 4 0 1 1 0 1 1 1 0 1 0 1 0 1 0 0 0 1 1 0 1 0 1 1 1 1 15

D is for diagonalization List all Java programs. This list exists because the set of all Java programs is countable. P Let stand for code(p). (P, x) entry is 1 if the program on input and 0 otherwise. halts D behaves like the flipped diagonal D( P ) = P( P ), and differs from every in the list. P x P P 0 P 1 P 2 P 3 P 4 P 0 P 1 P 2 P 3 P 4 0 1 1 0 1 1 1 0 1 0 1 0 1 0 0 0 1 1 0 1 0 1 1 1 1 15

D is for diagonalization List all Java programs. This list exists because the set of all Java programs is countable. P Let stand for code(p). (P, x) entry is 1 if the program on input and 0 otherwise. halts D behaves like the flipped diagonal D( P ) = P( P ), and differs from every in the list. P x But the list is complete. So if D isn t included, it cannot exist! P P 0 P 1 P 2 P 3 P 4 P 0 P 1 P 2 P 3 P 4 0 1 1 0 1 1 1 0 1 0 1 0 1 0 0 0 1 1 0 1 0 1 1 1 1 15

The halting problem isn t the only hard problem B To show that a problem is undecidable: Prove that if there were a program deciding B then there would be a way to build a program deciding the halting problem. 16

The halting problem isn t the only hard problem B To show that a problem is undecidable: Prove that if there were a program deciding B then there would be a way to build a program deciding the halting problem. That is, prove is decidable halting problem is decidable. B 16

The halting problem isn t the only hard problem B To show that a problem is undecidable: Prove that if there were a program deciding B then there would be a way to build a program deciding the halting problem. That is, prove B is decidable halting problem is decidable. By contrapositive, halting problem is undecidable is undecidable. B 16

The halting problem isn t the only hard problem B To show that a problem is undecidable: Prove that if there were a program deciding B then there would be a way to build a program deciding the halting problem. That is, prove B is decidable halting problem is decidable. By contrapositive, halting problem is undecidable B is undecidable. Therefore, is undecidable. B 16

The halting problem isn t the only hard problem B To show that a problem is undecidable: Prove that if there were a program deciding B then there would be a way to build a program deciding the halting problem. That is, prove B is decidable halting problem is decidable. By contrapositive, halting problem is undecidable B is undecidable. Therefore, is undecidable. B Every non-trivial question about program behavior is undecidable. Termination, equivalence checking, verification, synthesis, 16

The halting problem isn t the only hard problem B To show that a problem is undecidable: Prove that if there were a program deciding B then there would be a way to build a program deciding the halting problem. That is, prove B is decidable halting problem is decidable. By contrapositive, halting problem is undecidable B is undecidable. Therefore, is undecidable. B Every non-trivial question about program behavior is undecidable. Termination, equivalence checking, verification, synthesis, But we can o"en decide these questions in practice! They are undecidable for arbitrary programs and properties. Yet decidable for many specific classes of programs and properties. And when we allow yes/no/don t know answers. 16

That s all folks! Propositional logic. Boolean logic, circuits, and algebra. Predicates, quantifiers and predicate logic. Inference rules and formal proofs for propositional and predicate logic. English proofs. Set theory. Modular arithmetic and prime numbers. GCD, Euclid s algorithm, modular inverse, and exponentiation. Induction and strong induction. Recursively defined functions and sets. Structural induction. Regular expressions. Context-free grammars and languages. Relations, composition, and reflexive-transitive closure. DFAs, NFAs, and product construction for DFAs. Finite state machines with output. Minimization algorithm for finite state machines. Conversion of regular expressions to NFAs. Subset construction to convert NFAs to DFAs. Equivalence of DFAs, NFAs, regular expressions. Method to prove languages are not regular. Cardinality, countability, and diagonalization. Undecidability and the halting problem. Go forth and prove great things! 17