Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computability and Undecidability

Similar presentations


Presentation on theme: "Computability and Undecidability"— Presentation transcript:

1 Computability and Undecidability
We have seen lots of things computers can do. Q. Is there anything they cannot do?

2 Computability and Undecidability
We have seen lots of things computers can do. Q. Is there anything they cannot do? A. Yes—almost everything.

3 Today we'll see some things that cannot be computed.
And prove that they cannot be computed, no matter what program, what language, what machine, how long you wait, anything.

4 Why? 1. Too many functions, so few programs...
2. There are many interesting functions that cannot be computed, e.g. various compiler optimizations.

5 Why? 1. Too many functions, so few programs...
Orders of infinity [Cantor 1890] 2. There are many interesting functions that cannot be computed, e.g. various compiler optimizations.

6 Why? 1. Too many functions, so few programs...
Orders of infinity [Cantor 1890] 2. There are many interesting functions that cannot be computed, e.g. various compiler optimizations. Undecidability of the halting problem [Turing 1936] Godel's incompleteness theorem [Godel 1936]

7 Plan 1. Show there are countably many programs. This means we can pair them up in a one-to-one fashion with the natural numbers N = {0,1,2,...}. 2. Show there are uncountably many functions. It's impossible to pair them up with the elements of N. 3. There must be some function that isn't programmable. 4. An interesting one—the halting problem.

8 Example {0,1,2} is the same size as {2,4,6}:
Definition [Cantor, 1890] Two sets are the same size if there is an exact one-to-one pairing between them. Example {0,1,2} is the same size as {2,4,6}: 0  2 1  4 2  6 Definition A set is countable if it is the same size as N = {0,1,2,…}.

9 Examples of countable sets
2N = {0,2,4,6,…} Z = {…,-3,-2,-1,0,1,2,3,…} 0   0 1   -1 2   1 3   -2 4   2 5   -3 6   3 7   -4 … … n  2n 2n  n … 2n+1  -1-n

10 Rationals 1/1 1/2 1/3 1/4 1/5 ... 2/1 2/2 2/3 2/4 2/5 ... 3/1 3/2 3/3 3/4 3/5 ... 4/1 4/2 4/3 4/4 4/5 ... 5/1 5/2 5/3 5/4 5/5 ...

11 Rationals 1/1 1/2 1/3 1/4 1/5 ... 2/1 2/2 2/3 2/4 2/5 ... 3/1 3/2 3/3 3/4 3/5 ... 4/1 4/2 4/3 4/4 4/5 ... 5/1 5/2 5/3 5/4 5/5 ...

12 Rationals 1/1 1/2 1/3 1/4 1/5 ... 2/1 2/2 2/3 2/4 2/5 ... 3/1 3/2 3/3 3/4 3/5 ... 4/1 4/2 4/3 4/4 4/5 ... 5/1 5/2 5/3 5/4 5/5 ...

13 Rationals 1/1 1/2 1/3 1/4 1/5 ... 2/1 2/2 2/3 2/4 2/5 ... 3/1 3/2 3/3 3/4 3/5 ... 4/1 4/2 4/3 4/4 4/5 ... 5/1 5/2 5/3 5/4 5/5 ...

14 Rationals 1/1 1/2 1/3 1/4 1/5 ... 2/1 2/2 2/3 2/4 2/5 ... 3/1 3/2 3/3 3/4 3/5 ... 4/1 4/2 4/3 4/4 4/5 ... 5/1 5/2 5/3 5/4 5/5 ...

15 Rationals 1/1 1/2 1/3 1/4 1/5 ... 2/1 2/2 2/3 2/4 2/5 ... 3/1 3/2 3/3 3/4 3/5 ... 4/1 4/2 4/3 4/4 4/5 ... 5/1 5/2 5/3 5/4 5/5 ...

16 Rationals 1/1 1/2 1/3 1/4 1/5 ... 2/1 2/2 2/3 2/4 2/5 ... 3/1 3/2 3/3 3/4 3/5 ... 4/1 4/2 4/3 4/4 4/5 ... 5/1 5/2 5/3 5/4 5/5 ...

17 Rationals 1/1 1/2 1/3 1/4 1/5 ... 2/1 2/2 2/3 2/4 2/5 ... 3/1 3/2 3/3 3/4 3/5 ... 4/1 4/2 4/3 4/4 4/5 ... 5/1 5/2 5/3 5/4 5/5 ...

18 Rationals 1/1 1/2 1/3 1/4 1/5 ... 2/1 2/2 2/3 2/4 2/5 ... 3/1 3/2 3/3 3/4 3/5 ... 4/1 4/2 4/3 4/4 4/5 ... 5/1 5/2 5/3 5/4 5/5 ...

19 Rationals 1/1 1/2 1/3 1/4 1/5 ... 2/1 2/2 2/3 2/4 2/5 ... 3/1 3/2 3/3 3/4 3/5 ... 4/1 4/2 4/3 4/4 4/5 ... 5/1 5/2 5/3 5/4 5/5 ...

20 Rationals 1/1 1/2 1/3 1/4 1/5 ... 2/1 2/2 2/3 2/4 2/5 ... 3/1 3/2 3/3 3/4 3/5 ... 4/1 4/2 4/3 4/4 4/5 ... 5/1 5/2 5/3 5/4 5/5 ... 2

21 Rationals 1/1 1/2 1/3 1/4 1/5 ... 2/1 2/2 2/3 2/4 2/5 ... 3/1 3/2 3/3 3/4 3/5 ... 4/1 4/2 4/3 4/4 4/5 ... 5/1 5/2 5/3 5/4 5/5 ... 2 4

22 Rationals 1/1 1/2 1/3 1/4 1/5 ... 2/1 2/2 2/3 2/4 2/5 ... 3/1 3/2 3/3 3/4 3/5 ... 4/1 4/2 4/3 4/4 4/5 ... 5/1 5/2 5/3 5/4 5/5 ... 8

23 Rationals 1/1 1/2 1/3 1/4 1/5 .. 2/1 2/2 2/3 2/4 2/5 ... 3/1 3/2 3/3 3/4 3/5 ... 4/1 4/2 4/3 4/4 4/5 ... 5/1 5/2 5/3 5/4 5/5 ... 8 10

24 Rationals 1/1 1/2 1/3 1/4 1/5 .. 2/1 2/2 2/3 2/4 2/5 .. 3/1 3/2 3/3 3/4 3/5 ... 4/1 4/2 4/3 4/4 4/5 ... 5/1 5/2 5/3 5/4 5/5 ...

25 Rationals 1/1 1/2 1/3 1/4 1/5 .. 2/1 2/2 2/3 2/4 2/5 .. 3/1 3/2 3/3 3/4 3/5 .. 4/1 4/2 4/3 4/4 4/5 ... 5/1 5/2 5/3 5/4 5/5 ...

26 There are countably many Dylan programs
every Dylan program is a finite string of characters number them lexicographically 0  (empty string) strings of length 0 1  a strings of length 1 2  b . … . 26  z . 27  aa strings of length 2 28  ab . 29  ac . 702  zz . 703  aaa strings of length 3 704  aab .

27 But there are uncountably many functions!
There are even uncountably many Boolean valued functions of one argument f:N  {#t,#f} All the following sets are the same size, and all uncountable: Boolean valued functions of one argument infinite binary strings, e.g real numbers in the interval [0,1] paths in the infinite complete binary tree subsets of N

28 Consider the set of all Boolean valued functions of one
argument f:N  {#t,#f}. Let's show this set is not countable. Any such function f can be thought of as a row in an infinite table, where we list in column n the value of the function on input n: n = odd? #f #t #f #t #f #t #f #t #f #t ... prime? #f #f #t #t #f #t #f #t #f #f ... even? #t #f #t #f #t #f #t #f #t #f ... =4? #f #f #f #f #t #f #f #f #f #f ... ...

29 S0 #f #t #f #t #f #t #f #t #f #t ... S1 #f #f #t #t #f #t #f #t #f #f ... S2 #t #f #t #f #t #f #t #f #t #f ... S3 #f #f #f #f #t #f #f #f #f #f ... S4 #f #t #f #f #t #t #t #f #f #t ... .

30 S0 #f #t #f #t #f #t #f #t #f #t ... S1 #f #f #t #t #f #t #f #t #f #f ... S2 #t #f #t #f #t #f #t #f #t #f ... S3 #f #f #f #f #t #f #f #f #f #f ... S4 #f #t #f #f #t #t #t #f #f #t ...

31 S0 #f #t #f #t #f #t #f #t #f #t ... S1 #f #f #t #t #f #t #f #t #f #f ... S2 #t #f #t #f #t #f #t #f #t #f ... S3 #f #f #f #f #t #f #f #f #f #f ... S4 #f #t #f #f #t #t #t #f #f #t ... d = #t #t #f #t #f

32 The Halting Problem Given a program prog and an argument arg, does
(prog arg) halt and return a value? Example (define prog (method (x) (x 3))) (define arg inc) (prog arg) ==> 4 but (define prog (method (x) (prog x))) (define arg 3) (prog arg) runs forever

33 Wouldn't it be nice if we had a program halts?
that could test whether (prog arg) will halt... (halts? prog arg) ==> #t if (prog arg) halts and returns a value #f if it doesn't.

34 Wouldn't it be nice if we had a program halts?
that could test whether (prog arg) will halt... (halts? prog arg) ==> #t if (prog arg) halts and returns a value #f if it doesn't. Unfortunately, halts? does not exist.

35 Proof by contradiction (essentially a diagonalization
argument). Suppose there were such a program halts?. (define Cantor (method ((p <function>)) (if (halts? p p) (not (p p)) #f))) Note Cantor always halts on any <function>, e.g. (Cantor (method (x) 4)) ==> (not ((method (x) 4) (method (x) 4))) ==> (not 4) ==> #f

36 It halts, as we just argued. What is its value?
What about (Cantor Cantor)? It halts, as we just argued. What is its value? (define Cantor (method ((p <function>)) (if (halts? p p) (not (p p)) #f))) (Cantor Cantor) ==> (if (halts? Cantor Cantor) (not (Cantor Cantor)) #f ==> (not (Cantor Cantor))

37 It halts, as we just argued. What is its value?
What about (Cantor Cantor)? It halts, as we just argued. What is its value? (define Cantor (method ((p <function>)) (if (halts? p p) (not (p p)) #f))) (Cantor Cantor) ==> (if (halts? Cantor Cantor) (not (Cantor Cantor)) #f ==> (not (Cantor Cantor))

38 Turing's Halting Theorem
Conclusion: halts? does not exist. We have just proved ...and none of the neat programming tricks we've taught you can possibly help. Turing's Halting Theorem It is undecidable whether a given program halts on a given input.

39 Other undecidable problems
the dead code problem: given a block of code in a program, will that code ever be executed? the equivalence problem: given two programs, do they compute the same function?

40 We've enjoyed teaching this class very much, and we hope that we've given you some sense of what computer science is like. We hope to see you later on in some of our upper level courses. Thanks!


Download ppt "Computability and Undecidability"

Similar presentations


Ads by Google