20
CS 3240 – Chapter 12

Limits of Algorithmic Computation

Embed Size (px)

DESCRIPTION

CS 3240 – Chapter 12. Limits of Algorithmic Computation. The Librarian Paradox The Mysteries of Self-Reference I. - PowerPoint PPT Presentation

Citation preview

Page 1: Limits of Algorithmic Computation

CS 3240 – Chapter 12

Page 2: Limits of Algorithmic Computation

CS 3240 - Chapter 12 2

An unfortunate library intern is given the task of creating a list of all books in the library that do not mention themselves. She toils all summer. In the end, she has a list. This she triumphantly adds to the reference section as “Non Self-Mentioning Books.”

She is just about to head back to campus, when the head librarian asks, “Shouldn’t that book itself be added to the list?” But when the intern adds it to the list, the book is no longer non-self-mentioning. And yet, if it’s not added, it should be added.”

Page 3: Limits of Algorithmic Computation

The Halting Dog Problem see online document

3CS 3240 - Chapter 12

Page 4: Limits of Algorithmic Computation

Question: Is there a Universal TM (H) that takes another TM (M) as input, along with an input string (w), and decides whether or not M halts on w? In other words, is there such an algorithm?

This would be very useful Could detect infinite loops in bad code! Could save us from wasting precious time

4CS 3240 - Chapter 12

Page 5: Limits of Algorithmic Computation

The halting algorithm, H, is depicted below:

5CS 3240 - Chapter 12

Page 6: Limits of Algorithmic Computation

Now define the TM, N(M) = H(M,M)

CS 3240 - Chapter 12 6

The machine N

Page 7: Limits of Algorithmic Computation

CS 3240 - Chapter 12 7

Page 8: Limits of Algorithmic Computation

Now define the machine D(M) which calls N(M) and: loops forever if M does halt on M returns No if M does not halt on M

CS 3240 - Chapter 12 8

The Machine D

Page 9: Limits of Algorithmic Computation

What is the result of D(D)?

CS 3240 - Chapter 12 9

Page 10: Limits of Algorithmic Computation

If D halts on D, then it loops forever (doesn’t halt)

If D does not halt on D, it halts on D with the result “N”

Both cases are self-contradictoryTherefore, there is no such

TM/procedure HThe Halting Problem is undecidable

10CS 3240 - Chapter 12

Page 11: Limits of Algorithmic Computation

Suppose h(M,w) is computable the algorithm h tells whether M halts on w

Construct the function g (M,w): if h(M,w) loop forever else return false

Now compute g(g,g): if g halts on g, then it doesn’t if g doesn’t halt on g, then it does (returning

false)CS 3240 - Chapter 12 11

Page 12: Limits of Algorithmic Computation

CS 3240 - Chapter 12 12

If the halting problem were decidable, we could build the machine above. (H is the halting algorithm)

For any recursively enumerable language, L, we feed its recognizing machine, M, and any string, w, to H. If M will halt on w, we return its answer. Otherwise we return No. This constitutes a procedure that decides any r.e. language (the “membership problem”). This implies that all r.e. languages are actually recursive. Contradiction! So H can’t exist.

Page 13: Limits of Algorithmic Computation

Problem A is reducible to problem B if B’s decidability implies A’s decidability in other words, we can use B to solve A A ⪯ B if S(B) ➱S(A) (B solvable implies A

solvable) We did this earlier:

we just reduced the Membership Problem to the Halting Problem (by “solving” M with H)

S(H) ➱S(M) Equivalent to ¬S(M) ➱¬S(H) (contrapositive)

CS 3240 - Chapter 12 13

Page 14: Limits of Algorithmic Computation

We will reduce H to B “If B is solvable so is H”

We do so by using B to “solve” H The construction of H from B in 2 steps:

Let Mw start with a blank tape and write w on it, then run M on w▪ Mw halts on a blank tape iff M halts on w

Construct H by taking (M,w) as input, building Mw and then feeding Mw to B (see next slide…)

CS 3240 - Chapter 12 14

Page 15: Limits of Algorithmic Computation

CS 3240 - Chapter 12 15

Page 16: Limits of Algorithmic Computation

Decide which unsolvable problem (A) to reduce usually the Halting or Membership problems key idea: arrange for M to accept w iff B

succeeds Modify M to interface with B

call the new machine Mw

you often run M on w inside Mw

Feed Mw and any other input (w) to B show that the output of Mw solves A

CS 3240 - Chapter 12 16

Page 17: Limits of Algorithmic Computation

Let R be the problem of deciding whether a TM, M, ever writes a given character, c, say, when applied to any string w.

We can reduce the Halting problem to R. Modify M to always write a # whenever it

halts. Call this machine Mw. Hence M halts iff Mw writes a #.

Now compute (M,w)->(Mw,#)->R See next slide.

CS 3240 - Chapter 12 17

Page 18: Limits of Algorithmic Computation

CS 3240 - Chapter 12 18

Page 19: Limits of Algorithmic Computation

Does a given TM, M, ever enter a given state, q?

We can reduce the Halting Problem, H, to this problem (call it E)

Given M and w, build Mw to always halt in q’:

▪ just draw an arrow for every letter from each halting state to a new state, q’

▪ arrange for w to be the input for Mw

now feed Mw,q’ to ECS 3240 - Chapter 12 19

Page 20: Limits of Algorithmic Computation

CS 3240 - Chapter 12 20