320 likes | 463 Views
Decidability in One Day – or maybe two (I can’t decide). CS 331, Tandy Warnow Some slides by Luay Nakhleh , Rice University. Outline. Countability and uncountability What is decidability? There has to be a language that is not decidable An example of a language that is not decidable
E N D
Decidability in One Day – or maybe two (I can’t decide) CS 331, Tandy Warnow Some slides by LuayNakhleh, Rice University
Outline • Countability and uncountability • What is decidability? • There has to be a language that is not decidable • An example of a language that is not decidable • Reductions again
Countability • Definition: A set S is countably infinite if there is a bijection from S to the positive integers. • A bijection from a set A to B is a function F such that • F is 1:1 (i.e., F(a)=F(b) if and only if a=b) • F is onto (i.e., for all b in B, there is an a in A such that F(a)=b)
Countable sets • Obviously the set of positive integers is countably infinite – F(x)=x • The set of negative integers is countably infinite • F(x) = -x • The set of integersis countably infinite • F(x) = 1+2x if x is non-negative • F(x) = –2x if x is negative
What about the following? • The set of finite subsets of the integers • The set of rational numbers • The set of functions from {0,1} to the integers • The set of functions from the integers to {0,1} • The set of strings over {0,1}* • The set of finite strings over {0,1}*
Cantor’s Diagonalization Cantor proved (by contradiction) that the set S of infinite length binary strings is uncountable. • Proof (By contradiction). Suppose S is countable. Then we can enumerate the elements of S s1, s2, s3, …, where each si is one infinitely long binary string. Let sij be the jth letter in string si. • Let s* be defined by s*ij = 1-sij • Then s* is different from every element in S, and so cannot be in S. • But s* is an infinite length binary string, and so must be in S. • Contradicton. • Hence S must not be countable.
What about the number of programs? • Assumption: Every program can be written down using a finite length string over the given alphabet. Hence, without loss of generality, we can write the program out in binary (over {0,1}*). • How many finite length binary strings are there? Is this countable or uncountable?
The set of finite binary strings is countable • Enumerate the set of finite binary strings as follows: • First write down the empty string • Then enumerate the strings of length 1 • Then enumerate the strings of length 2 • Etc. Hence the set of programs is countable
Basics • A language X is a set of strings (all finite length) over an alphabet. • Examples: • {anbn: n = 0,1,2,…} • {anbm: n,m = 0, 1, 2…} • {a,b,c,…,z}* • {0,1}* - 0* - 1*
Basics • A language X is a set of strings (all finite length) over an alphabet. • A program “accepts” a set of finite length strings. • L(M) is the set of strings accepted by program M. • Every program can be described by a finite length string over the alphabet. • The difference between countable and uncountable sets. • There are only countably many programs.
Decidability • A language X is decidable if there is an algorithm M that on input w: • M says “yes” if w in X • M says “no” if w not in X • Every problem/language you’ve seen so far in this class is decidable.
Finite programs can accept infinite languages Consider language L = {anbm: n>1, m>1}. Could you write a program to accept L? (In other words, is this language decidable?)
Finite programs can accept infinite languages Similarly, consider a language that would describe all Eulerian graphs (of any size). (So each string in this language represents a single Eulerian graph.) Could you write a program that would return YES if and only if the graph was Eulerian?
Finite programs, infinite languages • Similarly, consider the language of strings describing graphs that are 3-colorable. • Could you write a program to accept this language? • Note: this has nothing to do with how much time it takes, as long as it is finite.
Does there exist a language that is not decidable? • You are encouraged to think about it in terms of the programs you can write using some programming language, say C: • The number of possible languages is uncountable (as this is the number of all subsets of Σ*) • The number of possible C programs is countable (every program is a finite string over the “C language alphabet”, and the number of finite strings over any finite alphabet is countable).
Does there exist a language that is not decidable? • So, the number of languages is uncountable, and the number of programs in C is countable. • Therefore, there is at least one language for which there is no program (algorithm). • (In fact, there are an uncountable number of languages for which there are no programs.)
Can we find a specific language that is not decidable? • HP = {<M,w>: M is a C program, and w is a string, and M halts on w} • Or the decision problem version: • Input: C program M, and input w • Question: Does M halt on w? • We will prove that HP is NOT decidable.
Proof that HP is not decidable • HP = {<M,w>: M is a C program, and w is a string, and M halts on w} • We will prove that HP is NOT decidable by contradiction. • So suppose it is decidable. There some program exists that always terminates and answers “True” (or “yes”, whatever you prefer) for exactly those inputs <M,w> where M halts on w. • We will derive a contradiction. This will mean that HP is not decidable. • The remaining slides are based on http://www.cgl.uwaterloo.ca/~csk/halt
Proof that HP is not decidable • HP = {<M,w>: M is a C program, and w is a string, and M halts on w} • We will prove that HP is NOT decidable by contradiction. • So suppose it is decidable. There some program exists that always terminates and answers “True” (or “yes”, whatever you prefer) for exactly those inputs <M,w> where M halts on w. • We will derive a contradiction. This will mean that HP is not decidable. • The remaining slides are based on http://www.cgl.uwaterloo.ca/~csk/halt
Proof that HP is not decidable • HP = {<M,w>: M is a C program, and w is a string, and M halts on w} • We will prove that HP is NOT decidable by contradiction. • So suppose it is decidable. There some program exists that always terminates and answers “True” (or “yes”, whatever you prefer) for exactly those inputs <M,w> where M halts on w. • We will derive a contradiction. This will mean that HP is not decidable. • The remaining slides are based on http://www.cgl.uwaterloo.ca/~csk/halt
Proof that HP is not decidable • HP = {<M,w>: M is a C program, and w is a string, and M halts on w} • We will prove that HP is NOT decidable by contradiction. • So suppose it is decidable. There some program exists that always terminates and answers “True” (or “yes”, whatever you prefer) for exactly those inputs <M,w> where M halts on w. • We will derive a contradiction. This will mean that HP is not decidable. • The remaining slides are based on http://www.cgl.uwaterloo.ca/~csk/halt
HP (Halting Problem) • Assume HP is decidable and program WouldItStop (in C or whatever language) decides it. • So WouldItStop answers YES or NO on all inputs, and never goes into an infinite loop. • The input to WouldItStop is a pair <M,w> where M is a program and w is an input to the program, and WouldItStop(M,w) returns YES if M halts on w, and else returns NO. http://www.cgl.uwaterloo.ca/~csk/halt
HP • Assume HP is decidable and program WouldItStop decides it (=correctly answers it). • Create program stops_on_self that takes a C program M’ as input and does the following: • Runs WouldItStop on <M’,M’> and returns the same output (YES or NO) http://www.cgl.uwaterloo.ca/~csk/halt
HP • Assume HP is decidable and program WouldItStop decides it (=correctly answers it). • Create program stops_on_selfthat takes a C program M’ as input and does the following: • Runs WouldItStop on <M’,M’> and returns the same output (YES or NO) • We now create “BobsYerUncle” http://www.cgl.uwaterloo.ca/~csk/halt
Bob’s Yer Uncle Boolbobs_yer_uncle ( char * program) { if (stops_on_self( program ) ) { while ( 1 ) {} return FALSE } else { return TRUE; } } http://www.cgl.uwaterloo.ca/~csk/halt
Paradox What happens when you run bobs_yer_uncle on itself? Note: bobs_yer_uncle either returns TRUE or it runs forever. If it returns TRUE it’s because stops_on_self(bobs_yer_uncle) returned FALSE. But that means WouldItStop(bobs_yer_uncle, bobs_yer_uncle) returned FALSE. So think about it… Same kind of problem if bobs_yer_uncle runs forever. Contradiction!!! Hence, WouldItStop just cannot exist – no algorithm can solve the Halting Problem. You have just proved that the Halting Problem is undecidable!
Paradox What happens when you run bobs_yer_uncle on itself? Note: bobs_yer_uncle either returns TRUE or it runs forever. If it returns TRUE it’s because stops_on_self(bobs_yer_uncle) returned FALSE. But that means WouldItStop(bobs_yer_uncle, bobs_yer_uncle) returned FALSE. So think about it… Same kind of problem if bobs_yer_uncle runs forever. Contradiction!!! Hence, WouldItStop just cannot exist – no algorithm can solve the Halting Problem. You have just proved that the Halting Problem is undecidable!
Paradox What happens when you run bobs_yer_uncle on itself? Note: bobs_yer_uncle either returns TRUE or it runs forever. If it returns TRUE it’s because stops_on_self(bobs_yer_uncle) returned FALSE. But that means WouldItStop(bobs_yer_uncle, bobs_yer_uncle) returned FALSE. So think about it… Same kind of problem if bobs_yer_uncle runs forever. Contradiction!!! Hence, WouldItStop just cannot exist – no algorithm can solve the Halting Problem. You have just proved that the Halting Problem is undecidable!
Paradox What happens when you run bobs_yer_uncle on itself? Note: bobs_yer_uncle either returns TRUE or it runs forever. If it returns TRUE it’s because stops_on_self(bobs_yer_uncle) returned FALSE. But that means WouldItStop(bobs_yer_uncle, bobs_yer_uncle) returned FALSE. So think about it… Same kind of problem if bobs_yer_uncle runs forever. Contradiction!!! Hence, WouldItStop just cannot exist – no algorithm can solve the Halting Problem. You have just proved that the Halting Problem is undecidable!
Paradox What happens when you run bobs_yer_uncle on itself? Note: bobs_yer_uncle either returns TRUE or it runs forever. If it returns TRUE it’s because stops_on_self(bobs_yer_uncle) returned FALSE. But that means WouldItStop(bobs_yer_uncle, bobs_yer_uncle) returned FALSE. So think about it… Same kind of problem if bobs_yer_uncle runs forever. Contradiction!!! Hence, WouldItStop just cannot exist – no algorithm can solve the Halting Problem. You have just proved that the Halting Problem is undecidable!
Reductions Again • Recall reductions for proving NP-hardness! • If we drop the requirement that the reduction is computable in polynomial time, we get a tool to establish (un)decidability of other languages. • That is, if L1 reduces to L2 (where the mapping is computable, but not necessarily in poly time), then: If L2 is decidable, then L1 is decidable (equivalently, if L1 is undecidable, then L2 is undecidable). • Prove this result! (Somewhat easy, since it’s a simple composition of programs.)