BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general...

29
BU CS 332 – Theory of Computation Lecture 15: Undecidable and Unrecognizable Languages Reductions Reading: Sipser Ch 4.2, 5.1 Mark Bun March 23, 2020

Transcript of BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general...

Page 1: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

BU CS 332 – Theory of Computation

Lecture 15:• Undecidable and

Unrecognizable Languages• Reductions

Reading:Sipser Ch 4.2, 5.1

Mark BunMarch 23, 2020

Page 2: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

How can we compare sizes of infinite sets?Definition: Two sets have the same size if there is a correspondence (bijection) between them

A set is countable if• it is a finite set, or• it has the same size as ℕ, the set of natural numbers

3/23/2020 CS332 - Theory of Computation 2

Page 3: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

A general theorem about set sizesTheorem: Let 𝑋𝑋 be a set. Then the power set 𝑃𝑃(𝑋𝑋) does not have the same size as 𝑋𝑋.

Proof: Assume for the sake of contradiction that there is a correspondence 𝑓𝑓:𝑋𝑋 → 𝑃𝑃(𝑋𝑋)

Goal: Use diagonalization to construct a set 𝑆𝑆 ∈ 𝑃𝑃(𝑋𝑋) that cannot be the output 𝑓𝑓(𝑥𝑥) for any 𝑥𝑥 ∈ 𝑋𝑋

3/23/2020 CS332 - Theory of Computation 3

Page 4: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

Undecidable Languages

3/23/2020 CS332 - Theory of Computation 4

Page 5: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

Problems in language theory

3/23/2020 CS332 - Theory of Computation 5

𝑨𝑨𝐃𝐃𝐃𝐃𝐃𝐃decidable

𝑨𝑨𝐂𝐂𝐃𝐃𝐂𝐂decidable

𝑬𝑬𝐃𝐃𝐃𝐃𝐃𝐃decidable

𝑬𝑬𝐂𝐂𝐃𝐃𝐂𝐂decidable

𝑬𝑬𝑬𝑬𝐃𝐃𝐃𝐃𝐃𝐃decidable

𝑨𝑨𝐓𝐓𝐓𝐓?

𝑬𝑬𝐓𝐓𝐓𝐓?

𝑬𝑬𝑬𝑬𝐓𝐓𝐓𝐓?

𝑬𝑬𝑬𝑬𝐂𝐂𝐃𝐃𝐂𝐂?

Page 6: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

UndecidabilityThese natural computational questions about computational models are undecidable

I.e., computers cannot solve these problems no matter how much time they are given

3/23/2020 CS332 - Theory of Computation 6

Page 7: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

An existential proofTheorem: There exists an undecidable language over {0, 1}Proof: A simplifying assumption: Every string in {0, 1}∗ is the encoding 𝑀𝑀 of some Turing machine 𝑀𝑀

Set of all Turing machines: 𝑋𝑋 = {0, 1}∗

Set of all languages over {0, 1}:

There are more languages than there are TM deciders!

3/23/2020 CS332 - Theory of Computation 7

all subsets of {0, 1}∗= 𝑃𝑃(𝑋𝑋)

Page 8: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

An existential proofTheorem: There exists an unrecognizable language over {0, 1}Proof: A simplifying assumption: Every string in {0, 1}∗ is the encoding 𝑀𝑀 of some Turing machine 𝑀𝑀

Set of all Turing machines: 𝑋𝑋 = {0, 1}∗

Set of all languages over {0, 1}:

There are more languages than there are TM recognizers!

3/23/2020 CS332 - Theory of Computation 8

all subsets of {0, 1}∗= 𝑃𝑃(𝑋𝑋)

Page 9: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

An explicit undecidable language

3/23/2020 CS332 - Theory of Computation 9

TM 𝑀𝑀

𝑀𝑀1

𝑀𝑀2

𝑀𝑀3

𝑀𝑀4

Page 10: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

An explicit undecidable language

3/23/2020 CS332 - Theory of Computation 10

TM 𝑀𝑀 𝑀𝑀( 𝑀𝑀1 )? 𝑀𝑀( 𝑀𝑀2 )? 𝑀𝑀( 𝑀𝑀3 )? 𝑀𝑀( 𝑀𝑀4 )?

𝑀𝑀1 Y N Y Y𝑀𝑀2 N N Y Y𝑀𝑀3 Y Y Y N𝑀𝑀4 N N Y N

𝐿𝐿 = 𝑀𝑀 𝑀𝑀 is a TM that does not accept on input 𝑀𝑀 }Suppose 𝐷𝐷 decides 𝐿𝐿

𝐷𝐷( 𝐷𝐷 )?

𝐷𝐷

Page 11: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

An explicit undecidable languageTheorem: 𝐿𝐿 = 𝑀𝑀 𝑀𝑀 is a TM that does not accept oninput 𝑀𝑀 } is undecidableProof: Suppose for contradiction, that 𝐷𝐷 decides 𝐿𝐿

Corollary: 𝑆𝑆𝑆𝑆TM = �𝐿𝐿 = 𝑀𝑀 𝑀𝑀 is a TM that accepts oninput 𝑀𝑀 } is undecidable3/23/2020 CS332 - Theory of Computation 11

Page 12: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

A more useful undecidable language𝑆𝑆TM = 𝑀𝑀,𝑤𝑤 𝑀𝑀 is a TM that accepts input 𝑤𝑤}Theorem: 𝑆𝑆TM is undecidable

But first: 𝑆𝑆TM is Turing-recognizableThe following “universal TM” 𝑈𝑈 recognizes 𝑆𝑆TM

On input 𝑀𝑀,𝑤𝑤 :1. Simulate running 𝑀𝑀 on input 𝑤𝑤2. If 𝑀𝑀 accepts, accept. If 𝑀𝑀 rejects, reject.

3/23/2020 CS332 - Theory of Computation 12

Page 13: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

More on the Universal TM"It is possible to invent a single machine which can be used to compute any computable sequence. If this machine U is supplied with a tape on the beginning of which is written the S.D ["standard description"] of some computing machine M, then U will compute the same sequence as M.”

- Turing, “On Computable Numbers…” 1936

• Foreshadowed general-purpose programmable computers• No need for specialized hardware: Virtual machines as software

3/23/2020 CS332 - Theory of Computation 13

Harvard architecture: Separate instruction and data pathways

von Neumann architecture: Programs can be treated as data

Page 14: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

A more useful undecidable language𝑆𝑆TM = 𝑀𝑀,𝑤𝑤 𝑀𝑀 is a TM that accepts input 𝑤𝑤}Theorem: 𝑆𝑆TM is undecidableProof: Assume for the sake of contradiction that TM 𝐻𝐻decides 𝑆𝑆TM:

𝐻𝐻 𝑀𝑀,𝑤𝑤 = � accept if 𝑀𝑀 accepts 𝑤𝑤reject if 𝑀𝑀 does not accept 𝑤𝑤

Idea: Show that 𝐻𝐻 can be used to decide the (undecidable) language 𝑆𝑆𝑆𝑆TM -- a contradiction.

3/23/2020 CS332 - Theory of Computation 14

Page 15: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

A more useful undecidable language𝑆𝑆TM = 𝑀𝑀,𝑤𝑤 𝑀𝑀 is a TM that accepts input 𝑤𝑤}Suppose 𝐻𝐻 decides 𝑆𝑆TM

Consider the following TM 𝐷𝐷.On input 𝑀𝑀 where 𝑀𝑀 is a TM:1. Run 𝐻𝐻 on input 𝑀𝑀, 𝑀𝑀2. If 𝐻𝐻 accepts, accept. If 𝐻𝐻 rejects, reject.

Claim: 𝐷𝐷 decides 𝑆𝑆𝑆𝑆TM = 𝑀𝑀 𝑀𝑀 is a TM that accepts on input 𝑀𝑀 }

…but this language is undecidable

3/23/2020 CS332 - Theory of Computation 15

Page 16: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

Unrecognizable LanguagesTheorem: A language 𝐿𝐿 is decidable if and only if 𝐿𝐿 and �𝐿𝐿are both Turing-recognizable.Proof:

3/23/2020 CS332 - Theory of Computation 16

Page 17: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

Classes of Languages

3/23/2020 CS332 - Theory of Computation 17

context free

regular

recognizable

decidable

Page 18: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

Reductions

3/23/2020 CS332 - Theory of Computation 18

Page 19: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

A more useful undecidable language𝑆𝑆TM = 𝑀𝑀,𝑤𝑤 𝑀𝑀 is a TM that accepts input 𝑤𝑤}Theorem: 𝑆𝑆TM is undecidableProof: Assume for the sake of contradiction that TM 𝐻𝐻decides 𝑆𝑆TM:

𝐻𝐻 𝑀𝑀,𝑤𝑤 = � accept if 𝑀𝑀 accepts 𝑤𝑤reject if 𝑀𝑀 does not accept 𝑤𝑤

Idea: Show that 𝐻𝐻 can be used to decide the (undecidable) language 𝑆𝑆𝑆𝑆TM -- a contradiction.

“A reduction from 𝑆𝑆𝑆𝑆TM to 𝑆𝑆TM”

3/23/2020 CS332 - Theory of Computation 19

Page 20: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

Scientists vs. EngineersA computer scientist and an engineer are stranded on a desert island. They find two palm trees with one coconut on each. The engineer climbs a tree, picks a coconut and eats.

The computer scientist climbs the second tree, picks a coconut, climbs down, climbs up the first tree and places it there, declaring success. “Now we’ve reduced the problem to one we’ve already solved.”

3/23/2020 CS332 - Theory of Computation 20

Page 21: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

Reductions

A reduction from problem 𝑆𝑆 to problem 𝐵𝐵 is an algorithm for problem 𝑆𝑆 which uses an algorithm for problem 𝐵𝐵 as a subroutine

If such a reduction exists, we say “𝑆𝑆 reduces to 𝐵𝐵”

3/23/2020 CS332 - Theory of Computation 21

Page 22: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

Two uses of reductionsPositive uses: If 𝑆𝑆 reduces to 𝐵𝐵 and 𝐵𝐵 is decidable, then 𝑆𝑆is also decidable

3/23/2020 CS332 - Theory of Computation 22

𝐸𝐸𝑄𝑄DFA = ⟨𝐷𝐷1,𝐷𝐷2⟩ 𝐷𝐷1,𝐷𝐷2 are DFAs and 𝐿𝐿(𝐷𝐷1) = 𝐿𝐿(𝐷𝐷2)}Theorem: 𝐸𝐸𝑄𝑄DFA is decidableProof: The following TM decides 𝐸𝐸𝑄𝑄DFA

On input ⟨𝐷𝐷1,𝐷𝐷2⟩ , where 𝐷𝐷1,𝐷𝐷2 are DFAs:1. Construct a DFA 𝐷𝐷 that recognizes the symmetric

difference 𝐿𝐿(𝐷𝐷1) △ 𝐿𝐿(𝐷𝐷2)2. Run the decider for 𝐸𝐸DFA on 𝐷𝐷 and return its output

Page 23: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

Two uses of reductionsNegative uses: If 𝑆𝑆 reduces to 𝐵𝐵 and 𝑆𝑆 is undecidable, then 𝐵𝐵 is also undecidable

3/23/2020 CS332 - Theory of Computation 23

𝑆𝑆TM = 𝑀𝑀,𝑤𝑤 𝑀𝑀 is a TM that accepts input 𝑤𝑤}Suppose 𝐻𝐻 decides 𝑆𝑆TM

Consider the following TM 𝐷𝐷.On input 𝑀𝑀 where 𝑀𝑀 is a TM:1. Run 𝐻𝐻 on input 𝑀𝑀, 𝑀𝑀2. If 𝐻𝐻 accepts, accept. If 𝐻𝐻 rejects, reject.

Claim: 𝐷𝐷 decides 𝑆𝑆𝑆𝑆TM = 𝑀𝑀 𝑀𝑀 is a TM that accepts on input 𝑀𝑀 }

Page 24: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

Two uses of reductionsNegative uses: If 𝑆𝑆 reduces to 𝐵𝐵 and 𝑆𝑆 is undecidable, then 𝐵𝐵 is also undecidable

Proof template:1. Suppose to the contrary that 𝐵𝐵 is decidable2. Using 𝐵𝐵 as a subroutine, construct an algorithm

deciding 𝑆𝑆3. But 𝑆𝑆 is undecidable. Contradiction!

3/23/2020 CS332 - Theory of Computation 24

Page 25: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

Halting Problem𝐻𝐻𝑆𝑆𝐿𝐿𝐻𝐻TM = 𝑀𝑀,𝑤𝑤 𝑀𝑀 is a TM that halts on input 𝑤𝑤}

Theorem: 𝐻𝐻𝑆𝑆𝐿𝐿𝐻𝐻TM is undecidableProof: Suppose for contradiction that there exists a decider 𝐻𝐻for 𝐻𝐻𝑆𝑆𝐿𝐿𝐻𝐻TM. We construct a decider for 𝑆𝑆TM as follows:On input 𝑀𝑀,𝑤𝑤 :1. Run 𝐻𝐻 on input 𝑀𝑀,𝑤𝑤2. If 𝐻𝐻 rejects, reject3. If 𝐻𝐻 accepts, simulate 𝑀𝑀 on 𝑤𝑤4. If 𝑀𝑀 accepts, accept. Otherwise, reject

This is a reduction from 𝑆𝑆TM to 𝐻𝐻𝑆𝑆𝐿𝐿𝐻𝐻TM3/23/2020 CS332 - Theory of Computation 25

Page 26: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

Empty language testing for TMs𝐸𝐸TM = 𝑀𝑀 𝑀𝑀 is a TM and 𝐿𝐿 𝑀𝑀 = ∅}

Theorem: 𝐸𝐸TM is undecidableProof: Suppose for contradiction that there exists a decider 𝑅𝑅for 𝐸𝐸TM. We construct a decider for 𝑆𝑆TM as follows:On input 𝑀𝑀,𝑤𝑤 :1. Run 𝑅𝑅 on input ???

This is a reduction from 𝑆𝑆TM to 𝐸𝐸TM3/23/2020 CS332 - Theory of Computation 26

Page 27: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

Empty language testing for TMs𝐸𝐸TM = 𝑀𝑀 𝑀𝑀 is a TM and 𝐿𝐿 𝑀𝑀 = ∅}

Theorem: 𝐸𝐸TM is undecidableProof: Suppose for contradiction that there exists a decider 𝑅𝑅for 𝐸𝐸TM. We construct a decider for 𝑆𝑆TM as follows:On input 𝑀𝑀,𝑤𝑤 :1. Construct a TM 𝑀𝑀𝑀 as follows:

2. Run 𝑅𝑅 on input 𝑀𝑀′3. If 𝑅𝑅 , accept. Otherwise, reject

This is a reduction from 𝑆𝑆TM to 𝐸𝐸TM3/23/2020 CS332 - Theory of Computation 27

Page 28: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

Context-free language testing for TMs𝐶𝐶𝐶𝐶𝐿𝐿TM = 𝑀𝑀 𝑀𝑀 is a TM and 𝐿𝐿 𝑀𝑀 is context − free}

Theorem: 𝐶𝐶𝐶𝐶𝐿𝐿TM is undecidableProof: Suppose for contradiction that there exists a decider 𝑅𝑅for 𝐶𝐶𝐶𝐶𝐿𝐿TM. We construct a decider for 𝑆𝑆TM as follows:On input 𝑀𝑀,𝑤𝑤 :1. Construct a TM 𝑀𝑀𝑀 as follows:

2. Run 𝑅𝑅 on input 𝑀𝑀′3. If 𝑅𝑅 accepts, accept. Otherwise, reject

This is a reduction from 𝑆𝑆TM to 𝐶𝐶𝐶𝐶𝐿𝐿TM3/23/2020 CS332 - Theory of Computation 28

Page 29: BU CS 332 – Theory of Computation€¦ · 3/23/2020 CS332 - Theory of Computation 2. A general theorem about set sizes Theorem: Let 𝑋𝑋be a set. Then the power set 𝑃𝑃(𝑋𝑋)

Context-free language testing for TMs𝐶𝐶𝐶𝐶𝐿𝐿TM = 𝑀𝑀 𝑀𝑀 is a TM and 𝐿𝐿 𝑀𝑀 is context − free}

Theorem: 𝐶𝐶𝐶𝐶𝐿𝐿TM is undecidableProof: Suppose for contradiction that there exists a decider 𝑅𝑅for 𝐶𝐶𝐶𝐶𝐿𝐿TM. We construct a decider for 𝑆𝑆TM as follows:On input 𝑀𝑀,𝑤𝑤 :1. Construct a TM 𝑀𝑀𝑀 as follows:

𝑀𝑀𝑀 = “On input 𝑥𝑥,1. If 𝑥𝑥 ∈ 0𝑛𝑛1𝑛𝑛2𝑛𝑛 𝑛𝑛 ≥ 0}, accept2. Run TM 𝑀𝑀 on input 𝑤𝑤3. If 𝑀𝑀 accepts, accept.”

2. Run 𝑅𝑅 on input 𝑀𝑀′3. If 𝑅𝑅 accepts, accept. Otherwise, reject

This is a reduction from 𝑆𝑆TM to 𝐶𝐶𝐶𝐶𝐿𝐿TM3/23/2020 CS332 - Theory of Computation 29