28
CS154, Lecture 8: Undecidability, Mapping Reductions

CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

CS154, Lecture 8: Undecidability,

Mapping Reductions

Page 2: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

ATM = { (M, w) | M is a TM that accepts string w }

A Concrete Undecidable Problem:The Acceptance Problem for TMs

Theorem [Turing ‘30s]: ATM is recognizable but NOT decidable

Corollary: ATM is not recognizable

Page 3: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

ATM = { (M,w) | M is a TM that accepts string w }

ATM is undecidable: (proof by contradiction)

Suppose H is a machine that decides ATM

H( (M,w) ) =

Accept if M accepts w

Reject if M does not accept w

Define a new machine D as follows:D(M): Run H on (M,M) and output the opposite of H

D( M ) =

Reject if M accepts M

Accept if M does not accept M

D

D D

D D

Page 4: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

The table of outputs of H(x,y)

M1

M2

M3

M4

:

M1 M2 M3 M4…

accept accept

accept

accept

accept

accept

accept

reject

reject

reject

reject

reject

reject

reject

reject

reject

D

D

reject

accept

accept

accept

acceptreject

reject

accept ?

Page 5: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

M1

M2

M3

M4

:

M1 M2 M3 M4…

accept accept

accept

accept

accept

accept

accept

reject

reject

reject

reject

reject

reject

reject

reject

reject

reject

reject

accept

accept

D

D

reject

accept

accept

accept

acceptreject

reject

accept ?D(x) outputs the opposite of H(x,x)

The outputs of D(x)

D(D) outputs the opposite of H(D,D)=D(D)

Page 6: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

(constructive proof)

Let H be a machine that recognizes ATM

H( (M,w) ) =Accept if M accepts w

Reject or loops if M does not accept w

Define a new machine DH as follows:

DH(M): Run H on (M,M) until the simulation halts Output the opposite answer

ATM = { (M,w) | M is a TM that accepts string w }

ATM is undecidable:

Page 7: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

DH ( M ) =

Reject if M accepts M(i.e. if H( M , M ) = Accept)

Accept if M rejects M(i.e. if H( M , M ) = Reject)

Loops if M loops on M(i.e. if H( M , M ) loops)

DH

DH

DH DH

DH DH

DHDH

DH DH

DH DH

Note: There is no contradiction here!

DH must loop on DH

We have an instance (DH, DH) which is not in ATM

but H fails to tell us that! H(DH, DH) runs forever

DH

Page 8: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

That is:

Given the code of any machine H that recognizes ATM we can effectively construct an instance ( DH, DH ), where:

1. ( DH, DH ) does not belong to ATM

2. H runs forever on the input ( DH, DH )

So H cannot decide ATM

Given any program that recognizes the Acceptance Problem, we can efficiently construct an input where the program hangs!

Page 9: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

Theorem: ATM is recognizable but NOT decidable

Corollary: ATM is not recognizable!

Proof: Suppose ATM is recognizable. Then ATM and ATM are both recognizable…But that would mean they’re both decidable!

Page 10: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

HALTTM = { (M,w) | M is a TM that halts on string w }

Theorem: HALTTM is undecidable

The Halting Problem

Proof: Assume (for a contradiction) there is a TM H that decides HALTTM

We use H to construct a TM M’ that decides ATM

M’(M,w): Run H(M,w)If H rejects then reject

If H accepts, run M on w until it halts:

If M accepts, then acceptIf M rejects, then reject

Page 11: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

H

(M,w)

(M,w)

M

w

If M doesn’t halt:reject

If M halts

Does Mhalt on w?

M’

Page 12: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

Can often prove a language L is undecidableby proving: if L is decidable, then so is ATM

We reduce ATM to the language L

ATM ≤m L

Page 13: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

Mapping Reductions

f : Σ* → Σ* is a computable function if there is a Turing machine M that halts withjust f(w) written on its tape, for every input w

A language A is mapping reducible to language B, written as A ≤m B, if there is a computable f : Σ* → Σ* such that for every w,

w A f(w) B

f is called a mapping reduction (or many-one reduction) from A to B

Page 14: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

Let f : Σ* → Σ* be a computable function such that w A f(w) B

Say: A is mapping reducible to BWrite: A m B

A Bf

f

Σ* Σ*

Page 15: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

Theorem: If A m B and B m C, then A m C

A Bf

f

g

g

C

Page 16: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

Theorem: If A m B and B is decidable, then A is decidable

Proof: Let M decide B.Let f be a mapping reduction from A to B

To decide A, we build a machine M’

M’(w):

1. Compute f(w)

2. Run M on f(w), output its answer

• w A f(w) B so w A ⇒M’ accepts w• w ∉ A ⇒M’ rejects w

Page 17: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

Theorem: If A m B and B is recognizable, then A is recognizable

Proof: Let M recognize B.Let f be a mapping reduction from A to B

To recognize A, we build a machine M’

M’(w):

1. Compute f(w)

2. Run M on f(w), output its answerif you ever receive one

Page 18: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

Corollary: If A m B and A is undecidable,then B is undecidable

Corollary: If A m B and A is unrecognizable,then B is unrecognizable

Theorem: If A m B and B is decidable, then A is decidable

Theorem: If A m B and B is recognizable, then A is recognizable

Page 19: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

The proof that the Halting Problem is undecidable can be seen as constructing a mapping reduction from ATM to HALTTM

Theorem: ATM ≤m HALTTM

f(M, w) := (M’, w) where“M’(w) = accepts if M(w) accepts else loops forever” how?

We have (M, w) ATM (M’, w) HALTTM

Page 20: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

Theorem: ATM ≤m HALTTM

Corollary: ATM ≤m HALTTM

Proof?

Corollary: HALTTM is unrecognizable!

Proof: If HALTTM were recognizable, then ATM would be recognizable…

Page 21: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

Theorem: HALTTM m ATM

Proof: Define the computable function

f(M, w) := (M’, w) where“M’(w) accepts if M(w) halts else loop forever” (how?)

Observe (M, w) HALTTM (M’, w) ATM

Page 22: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

Corollary: HALTTM m ATM

I can give you the magical power to either compute the halting problem, or the acceptance problem. Which do you want?

Surprise me

Page 23: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

The Emptiness Problem

EMPTYDFA = { M | M is a DFA such that L(M) = }

Given a DFA, does it reject every input?

Theorem: EMPTYDFA is decidable

Why?

EMPTYNFA = { M | M is a NFA such that L(M) = }

EMPTYREX = { R | R is a regexp such that L(R) = }

Page 24: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

The Emptiness Problem for TMs

EMPTYTM = { M | M is a TM such that L(M) = }

Given a program, does it reject every input?

Theorem: EMPTYTM is not recognizable

Proof: Show that¬ATM m EMPTYTM

f(M, w) := M’ where“M’(x) := M(x) if (x = w), else reject” (how?)

M, w ∈ ATM L(M’) ≠

M’ ∉ EMPTYTM

f(M, w) ∉ EMPTYTM

Page 25: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

The Regularity Problem for Turing Machines

REGULARTM = { M | M is a TM and L(M) is regular}

Given a program, is it equivalent to some DFA?

Theorem: REGULARTM is not recognizable

Proof: Show that ¬ATM m REGULARTM

f(M, w) := M’: where M’ is a TM such that“M’(x) := M(w) if (x = 0n1n) else reject” (how?)

(M, w) ATM f(M, w) = M’ such that M’ accepts {0n1n }(M, w) ATM f (M, w) = M’ such that M’ accepts nothing(M, w) ATM f(M,w) REGULARTM

Page 26: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

The Equivalence Problem

Do two programs compute the same function?

Theorem: EQTM is unrecognizable

Proof: Reduce EMPTYTM to EQTM

Let M be a “dummy” TM with no path from start state to accept state

Define f(M) := (M, M)

M EMPTYTM L(M) = L(M) = (M’, M) EQTM

EQTM = {(M, N) | M, N are TMs and L(M) = L(N)}

Page 27: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

Moral: Analyzing Programs is

Really, Really Hard.

Page 28: CS154, Lecture 8: Undecidability, Mapping Reductions · CS154, Lecture 8: Undecidability, Mapping Reductions. A TM = { (M, w) | M is a TM that accepts string w } A Concrete Undecidable

Post’s Correspondence Problem

Given a collection of domino types, can we build up a match?

PCP = { P | P is a set of dominos with a match }

Theorem: PCP is undecidable!