PowerPoint Presentation no w Σ* L is decidable ... make a TM N that shifts w over one cell, puts a...

29
1 Lecture 11: More on Undecidability and Reductions 6.045

Transcript of PowerPoint Presentation no w Σ* L is decidable ... make a TM N that shifts w over one cell, puts a...

1

Lecture 11:More on Undecidability

and Reductions

6.045

2

Midterm: 2:35-4:00pm, Walker Memorial (50-340)

All pset and practice midterm solutions

are on piazza!

Thursday (3/23)

3

Midterm: 2:35-4:00pm, Walker Memorial (50-340)

All pset and practice midterm solutions

are on piazza!

FAQ: What material is on the midterm?

Everything up to this lecture (Lectures 1-11)

But we’ll focus more on earlier material

FAQ: Can I bring notes?

Yes, one single-sided sheet of notes, letter paper

Thursday (3/23)

w L ?

accept reject

TM

yes no

w Σ*

L is decidable

(recursive)

w L ?

accept reject or loop

TM

yes no

w Σ*

L is recognizable

(recursively enumerable)

4

Theorem: L is decidableiff both L and L are recognizable

5

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

The Acceptance Problem for TMs

Theorem [Turing]:ATM is recognizable, but NOT decidable!

Given: code of a Turing machine M andan input w for that Turing machine,

Decide: Does M accept w?

ATM decidable⇒ There is an algorithm ALG which, given any code and input,

ALG determines in finite time if the code will stop and output 1 when executed

6

Theorem: ATM is recognizable but NOT decidable

Corollary: ATM is not recognizable!

7

Reducing One Problem to Another

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

8

A Bf

f

Let f : Σ* Σ* be a computable function

such that w A f(w) B

Say: “A is mapping reducible to B” Write: A m B

Σ* Σ*

9

𝑬𝑸𝑫𝑭𝑨 = { (D1,D2) | D1 and D2 are DFAs, L(D1)=L(D2)}

𝑬𝑸𝑹𝑬𝑮𝑬𝑿 = { (R1,R2) | R1 and R2 are regexps, L(R1)=L(R2)}

Another Example

Then, (R1,R2) ∈ 𝑬𝑸𝑹𝑬𝑮𝑬𝑿⇔ L(D1)=L(R1)=L(R2)=L(D2)⇔ L(D1)=L(D2) ⇔ (D1,D2) ∈ 𝑬𝑸𝑫𝑭𝑨

Theorem: 𝑬𝑸𝑹𝑬𝑮𝑬𝑿 ≤m𝑬𝑸𝑫𝑭𝑨

Proof: Mapping reduction f from 𝑬𝑸𝑹𝑬𝑮𝑬𝑿 to 𝑬𝑸𝑫𝑭𝑨:f: On input z, decode z into a pair (R1,R2),

Convert R1,R2 into NFAs N1,N2, Convert NFAs N1,N2 into DFAs D1,D2. Output (D1,D2)

So f is a mapping reduction from 𝑬𝑸𝑹𝑬𝑮𝑬𝑿 to 𝑬𝑸𝑫𝑭𝑨

10

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

11

A mapping reduction from ATM to HALTTM

Theorem: ATM ≤m HALTTM

f(z) := Decode z into a pair (M, w) Construct a TM M’ with the specification:“M’(w) = Simulate M on w.

if the sim accepts then acceptelse loop forever”

Output (M’, w)

We have z ATM (M’, w) HALTTM

Corollary: HALTTM is undecidable

12

Theorem: ATM ≤m HALTTM

Corollary: : ATM ≤m : HALTTM

Corollary: : HALTTM is unrecognizable!Proof: If : HALTTM were recognizable, then : ATM would also be recognizable, because : ATM ≤m : HALTTM . But it’s not!

Question: ATM ≤m : ATM ?

13

Theorem: HALTTM m ATM

Proof: Define the computable function f:

f(z) := Decode z into a pair (M, w) Construct a TM M’ with the specification: “M’(w) = Simulate M on w.

If the simulation halts, then accept”Output (M’, w)

Claim: (M, w) HALTTM (M’, w) ATM

14

Corollary: HALTTM m ATM

Yo, T.M.! I can give you the magical power

to either solve the halting problem, or

the acceptance problem. Which do you want?

Wow, hm, so hard to choose…

I can’t decide!

15

The Emptiness Problem for TMs

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

Given a program, does it reject or loop on all inputs?

Theorem: EMPTYTM is not recognizable

Proof: Show that¬ATM m EMPTYTM

f(z) := Decode z into (M, w). Output code of the TM:“M’(x) := if (x = w) then output answer of M(w),

else reject”Observe: EITHER L(M’) =? OR L(M’) = {w}

z=(M,w) ∉ ATM M doesn’t accept w L(M’) =?

M’ ∈ EMPTYTM f(z) ∈ EMPTYTM

16

The Emptiness Problem for Other Models

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 | M is a regexp such that L(M) = ?}

17

The Equivalence Problem

Do two programs compute the same function?

Theorem: EQTM is not recognizable

Proof: Reduce EMPTYTM to EQTM

Let M? be a TM that always rejects immediately, so L(M?) = ?

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

Then M 2 EMPTYTM L(M) = L(M?) (M, M?) 2 EQTM

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

18

Moral: Analyzing Programs is

Really, Really Hard for Programs to Do.

19

Problem 1

{ (M, w) | M is a TM that on input w, tries to move its head past the left end of the input }

Problem 2

{ (M, w) | M is a TM that on input w, moves itshead left at least once, at some point}

Two Problems

20

Problem 1

Reduce ATM to L’Proof:

On input (M,w), make a TM N that shifts w over one cell,

puts a special symbol # on the leftmost cell, then simulates M(w) on its tape.

If M’s head moves to the cell with # but has not yet accepted, N moves the head back to the right.

If M accepts, N tries to move its head past the #.

(M,w) is in ATM if and only if (N,w) is in L’

L’ = { (M, w) | M is a TM that on input w, tries to move its head past the left end of the input }

21

Problem 2

On input (M,w), run M on w for |Q| + |w| + 1 steps,

where |Q| = number of states of M

Accept If M’s head moved left at allReject Otherwise

{ (M, w) | M is a TM that on input w, moves itshead left at least once, at some point}

(Why does this work?)

22

Moral: Analyzing Programs is

Really, Really Hard for Programs to Do.

How can we more easilytell when some “program analysis”

problem is undecidable?

23

Problem 3

REVERSE = { M | M is a TM with the property:for all w, M(w) accepts M(wR) accepts}.

Decidable or not?

REVERSE is undecidable.

24

Rice’s Theorem: Program Analysis is Hard

Then, L = {M | P(M) = 1} is undecidable.

A Huge Hammer for Undecidability!

Let P : {Turing Machines} → {0,1}.(Think of 0=false, 1=true) Suppose P satisfies:

1. (Nontrivial) There are TMs MYES and MNO

where P(MYES) = 1 and P(MNO) = 0

2. (Semantic) For all TMs M1 and M2, If L(M1) = L(M2) then P(M1) = P(M2)

25

Semantic Properties P(M)

• M accepts 0• L(M) = {0}

• L(M) is empty• L(M) = 𝚺∗

• M accepts 6045 strings• for all w, M(w) accepts M(wR) accepts

Not Semantic!

• M halts and rejects 0• M has at least 6045 states• M halts on all inputs

• M’s head tries to move off the left end of the tape on

some input

L = {M | P(M) = 1}is undecidable

Some Examples and Non-Examples

P is not semantic:There are M1 and M2

such that L(M1) = L(M2)and P(M1) ≠ P(M2)

26

Rice’s Theorem: If P is nontrivial and semantic, then L = {M | P(M) = 1} is undecidable.

Either reduce ATM or ¬ATM to the language LProof:

Case 1: Suppose P(M) = 0

Since P is nontrivial, there’s MYES such that P(MYES) = 1

Define M to be a TM such that L(M) =

Reduction from ATM to L On input (M,w), output:

“Mw(x) := If ((M accepts w) & (MYES accepts x)) then ACCEPT, else REJECT”

If M accepts w, then L(Mw) = L(MYES) Since P(MYES) = 1, we have P(Mw) = 1 and Mw L

If M does not accept w, then L(Mw) = L(M) = Since P(M) = 0, we have P(Mw) = 0 and Mw L

27

Rice’s Theorem: If P is nontrivial and semantic, then L = {M | P(M) = 1} is undecidable.

Either reduce ATM or ¬ATM to the language LProof:

Case 2: Suppose P(M) = 1

Since P is nontrivial, there’s MNO such that P(MNO) = 0

Define M to be a TM such that L(M) =

Reduction from ¬ATM to L On input (M,w), output:

“Mw(x) := If ((M accepts w) & (MNO accepts x)) then ACCEPT, else REJECT”

If M does not accept w, then L(Mw) = L(M) = Since P(M) = 1, we have P(Mw) = 1 and Mw L

If M accepts w, then L(Mw) = L(MNO) Since P(MNO) = 0, we have Mw L

28

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: Use Rice’s Theorem!P(M) := “L(M) is regular” is nontrivial: - there’s an M which never halts: P(M) = 1- there’s an M’ deciding {0n1n| n ≥ 0}: P(M’) = 0P is also semantic:If L(M) = L(M’) then L(M) is regular iff L(M’) is regular, so P(M) = 1 iff P(M’) = 1, so P(M) = P(M’)

By Rice’s Thm (case 2), we have¬ATM m REGULARTM

29

Next Episode:Your Midterm… Good Luck!