43
TDDC95 Introduction to the Theory of Computation Lecture 6 Gustav Nordh Department of Computer and Information Science [email protected] 2009-09-18

TDDC95 Introduction to the Theory of Computation - Lecture 6

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: TDDC95 Introduction to the Theory of Computation - Lecture 6

TDDC95Introduction to the Theory of Computation

Lecture 6

Gustav NordhDepartment of Computer and Information Science

[email protected]

2009-09-18

Page 2: TDDC95 Introduction to the Theory of Computation - Lecture 6

Outline

Undecidability of the halting problemReductionsSummary of ComputabilityTime Complexity

Page 3: TDDC95 Introduction to the Theory of Computation - Lecture 6

Undecidability of the halting problem

Construct a tool/debugger that can tell whether a Javaprogram will go into an infinite loop on input w .

Impossible! This problem is undecidableThere is no Turing machine U that given a Turing machineM and string w can determine whether M will loop on inputw

Page 4: TDDC95 Introduction to the Theory of Computation - Lecture 6

Undecidability of the halting problem

Construct a tool/debugger that can tell whether a Javaprogram will go into an infinite loop on input w .Impossible! This problem is undecidable

There is no Turing machine U that given a Turing machineM and string w can determine whether M will loop on inputw

Page 5: TDDC95 Introduction to the Theory of Computation - Lecture 6

Undecidability of the halting problem

Construct a tool/debugger that can tell whether a Javaprogram will go into an infinite loop on input w .Impossible! This problem is undecidableThere is no Turing machine U that given a Turing machineM and string w can determine whether M will loop on inputw

Page 6: TDDC95 Introduction to the Theory of Computation - Lecture 6

Undecidability of the halting problem

ATM = {〈M, w〉 | M is a Turing machine that accepts w}

TheoremATM is Turing-recognizable

Proof.Let U be a Turing machine that works as follows:

1 Check that the input 〈M, w〉 is a legal encoding of a Turingmachine M and string w (otherwise reject)

2 Simulate M on input w3 If M enters the accept state, then U accepts 〈M, w〉4 If M enters the reject state, then U rejects 〈M, w〉

Page 7: TDDC95 Introduction to the Theory of Computation - Lecture 6

Undecidability of the halting problem

ATM = {〈M, w〉 | M is a Turing machine that accepts w}

TheoremATM is Turing-recognizable

Proof.Let U be a Turing machine that works as follows:

1 Check that the input 〈M, w〉 is a legal encoding of a Turingmachine M and string w (otherwise reject)

2 Simulate M on input w3 If M enters the accept state, then U accepts 〈M, w〉4 If M enters the reject state, then U rejects 〈M, w〉

Page 8: TDDC95 Introduction to the Theory of Computation - Lecture 6

Undecidability of the halting problem

ATM = {〈M, w〉 | M is a Turing machine that accepts w}

TheoremATM is Turing-recognizable

Proof.Let U be a Turing machine that works as follows:

1 Check that the input 〈M, w〉 is a legal encoding of a Turingmachine M and string w (otherwise reject)

2 Simulate M on input w3 If M enters the accept state, then U accepts 〈M, w〉4 If M enters the reject state, then U rejects 〈M, w〉

Page 9: TDDC95 Introduction to the Theory of Computation - Lecture 6

Undecidability of the halting problem

ATM = {〈M, w〉 | M is a Turing machine that accepts w}

TheoremATM is undecidable

Proof.1 Assume that ATM is decidable by a Turing machine H2 Construct a new Turing machine D which takes 〈M〉 as

input and works as follows:Run H on 〈M, 〈M〉〉 and output the opposite of what Houtputs

3 Running D on input 〈D〉 results in a contradiction becauseD rejects 〈D〉 if D accepts 〈D〉

Page 10: TDDC95 Introduction to the Theory of Computation - Lecture 6

Undecidability of the halting problem

ATM = {〈M, w〉 | M is a Turing machine that accepts w}

TheoremATM is undecidable

Proof.1 Assume that ATM is decidable by a Turing machine H2 Construct a new Turing machine D which takes 〈M〉 as

input and works as follows:Run H on 〈M, 〈M〉〉 and output the opposite of what Houtputs

3 Running D on input 〈D〉 results in a contradiction becauseD rejects 〈D〉 if D accepts 〈D〉

Page 11: TDDC95 Introduction to the Theory of Computation - Lecture 6

Undecidability of the halting problem

ATM = {〈M, w〉 | M is a Turing machine that accepts w}

TheoremATM is undecidable

Proof.1 Assume that ATM is decidable by a Turing machine H2 Construct a new Turing machine D which takes 〈M〉 as

input and works as follows:Run H on 〈M, 〈M〉〉 and output the opposite of what Houtputs

3 Running D on input 〈D〉 results in a contradiction becauseD rejects 〈D〉 if D accepts 〈D〉

Page 12: TDDC95 Introduction to the Theory of Computation - Lecture 6

An explicit language which is not Turing-recognizable

ATM = {w | w /∈ ATM}

Theorem

ATM is not Turing-recognizable

Proof.1 Assume with the aim of reaching a contradiction that ATM

is Turing-recognizable.2 Let M1 be a Turing machine recognizing ATM and M2 a

Turing machine recognizing ATM .3 On input w run both M1 and M2 on w in parallel4 If M1 accepts, then reject. If M2 accepts, then accept.5 This shows that ATM is decidable, which is a contradiction

Page 13: TDDC95 Introduction to the Theory of Computation - Lecture 6

An explicit language which is not Turing-recognizable

ATM = {w | w /∈ ATM}

Theorem

ATM is not Turing-recognizable

Proof.1 Assume with the aim of reaching a contradiction that ATM

is Turing-recognizable.2 Let M1 be a Turing machine recognizing ATM and M2 a

Turing machine recognizing ATM .3 On input w run both M1 and M2 on w in parallel4 If M1 accepts, then reject. If M2 accepts, then accept.5 This shows that ATM is decidable, which is a contradiction

Page 14: TDDC95 Introduction to the Theory of Computation - Lecture 6

An explicit language which is not Turing-recognizable

ATM = {w | w /∈ ATM}

Theorem

ATM is not Turing-recognizable

Proof.1 Assume with the aim of reaching a contradiction that ATM

is Turing-recognizable.

2 Let M1 be a Turing machine recognizing ATM and M2 aTuring machine recognizing ATM .

3 On input w run both M1 and M2 on w in parallel4 If M1 accepts, then reject. If M2 accepts, then accept.5 This shows that ATM is decidable, which is a contradiction

Page 15: TDDC95 Introduction to the Theory of Computation - Lecture 6

An explicit language which is not Turing-recognizable

ATM = {w | w /∈ ATM}

Theorem

ATM is not Turing-recognizable

Proof.1 Assume with the aim of reaching a contradiction that ATM

is Turing-recognizable.2 Let M1 be a Turing machine recognizing ATM and M2 a

Turing machine recognizing ATM .

3 On input w run both M1 and M2 on w in parallel4 If M1 accepts, then reject. If M2 accepts, then accept.5 This shows that ATM is decidable, which is a contradiction

Page 16: TDDC95 Introduction to the Theory of Computation - Lecture 6

An explicit language which is not Turing-recognizable

ATM = {w | w /∈ ATM}

Theorem

ATM is not Turing-recognizable

Proof.1 Assume with the aim of reaching a contradiction that ATM

is Turing-recognizable.2 Let M1 be a Turing machine recognizing ATM and M2 a

Turing machine recognizing ATM .3 On input w run both M1 and M2 on w in parallel

4 If M1 accepts, then reject. If M2 accepts, then accept.5 This shows that ATM is decidable, which is a contradiction

Page 17: TDDC95 Introduction to the Theory of Computation - Lecture 6

An explicit language which is not Turing-recognizable

ATM = {w | w /∈ ATM}

Theorem

ATM is not Turing-recognizable

Proof.1 Assume with the aim of reaching a contradiction that ATM

is Turing-recognizable.2 Let M1 be a Turing machine recognizing ATM and M2 a

Turing machine recognizing ATM .3 On input w run both M1 and M2 on w in parallel4 If M1 accepts, then reject. If M2 accepts, then accept.5 This shows that ATM is decidable, which is a contradiction

Page 18: TDDC95 Introduction to the Theory of Computation - Lecture 6

Reductions

DefinitionA function f : Σ∗ → Σ∗ is computable if some Turing machine Mon every input w halts with f (w) on its tape

Page 19: TDDC95 Introduction to the Theory of Computation - Lecture 6

Reductions

DefinitionA function f : Σ∗ → Σ∗ is computable if some Turing machine Mon every input w halts with f (w) on its tape

Page 20: TDDC95 Introduction to the Theory of Computation - Lecture 6

Reductions

DefinitionLanguage A is mapping reducible to language B if there is acomputable function f : Σ∗ → Σ∗ such that for every w

w ∈ A iff f (w) ∈ B

The function f is called a reduction from A to BIf A is mapping reducible to B then we write A ≤m B

Page 21: TDDC95 Introduction to the Theory of Computation - Lecture 6

Reductions

TheoremIf B is decidable and A ≤m B, then A is decidable

Proof.Let MB be a Turing machine that decides B and f the reductionfrom A to B. Given input w :

1 Compute f (w)

2 Run MB on f (w), accept if MB accepts f (w), and reject ifMB rejects f (w)

Page 22: TDDC95 Introduction to the Theory of Computation - Lecture 6

Reductions

TheoremIf B is decidable and A ≤m B, then A is decidable

Proof.Let MB be a Turing machine that decides B and f the reductionfrom A to B. Given input w :

1 Compute f (w)

2 Run MB on f (w), accept if MB accepts f (w), and reject ifMB rejects f (w)

Page 23: TDDC95 Introduction to the Theory of Computation - Lecture 6

Reductions

TheoremIf A is undecidable and A ≤m B, then B is undecidable

Proof.Assume with the aim of reaching a contradiction that B isdecidable. Let MB be a Turing machine that decides B and f thereduction from A to B. Given input w :

1 Compute f (w)

2 Run MB on f (w), accept if MB accepts f (w), and reject ifMB rejects f (w)

3 This shows that A is decidable, which is a contradiction

Page 24: TDDC95 Introduction to the Theory of Computation - Lecture 6

Reductions

TheoremIf A is undecidable and A ≤m B, then B is undecidable

Proof.Assume with the aim of reaching a contradiction that B isdecidable. Let MB be a Turing machine that decides B and f thereduction from A to B. Given input w :

1 Compute f (w)

2 Run MB on f (w), accept if MB accepts f (w), and reject ifMB rejects f (w)

3 This shows that A is decidable, which is a contradiction

Page 25: TDDC95 Introduction to the Theory of Computation - Lecture 6

Reductions

TheoremIf B is Turing-recognizable and A ≤m B, then A isTuring-recognizable

Page 26: TDDC95 Introduction to the Theory of Computation - Lecture 6

Reductions

TheoremIf A is not Turing-recognizable and A ≤m B, then B is notTuring-recognizable

Page 27: TDDC95 Introduction to the Theory of Computation - Lecture 6

Reductions

ETM = {〈M〉 | M is a Turing machine and L(M) = ∅}

TheoremETM is undecidable

Proof.ATM ≤m ETM (Theorem 5.2 in Sipser)

Page 28: TDDC95 Introduction to the Theory of Computation - Lecture 6

Reductions

ETM = {〈M〉 | M is a Turing machine and L(M) = ∅}

TheoremETM is undecidable

Proof.ATM ≤m ETM (Theorem 5.2 in Sipser)

Page 29: TDDC95 Introduction to the Theory of Computation - Lecture 6

Reductions

ETM = {〈M〉 | M is a Turing machine and L(M) = ∅}

TheoremETM is undecidable

Proof.ATM ≤m ETM (Theorem 5.2 in Sipser)

Page 30: TDDC95 Introduction to the Theory of Computation - Lecture 6

Reductions

EQTM = {〈M1, M2〉 | M1 and M2 are TMs and L(M1) = L(M2)}

TheoremEQTM is undecidable

Proof.ETM ≤m EQTM :

1 Let M2 be a Turing machine such that L(M2) = ∅2 Given a Turing machine M, let f (〈M〉) = 〈M, M2〉3 〈M〉 ∈ ETM iff L(M) = ∅ iff L(M) = L(M2) iff〈M, M2〉 ∈ EQTM

Page 31: TDDC95 Introduction to the Theory of Computation - Lecture 6

Reductions

EQTM = {〈M1, M2〉 | M1 and M2 are TMs and L(M1) = L(M2)}

TheoremEQTM is undecidable

Proof.ETM ≤m EQTM :

1 Let M2 be a Turing machine such that L(M2) = ∅2 Given a Turing machine M, let f (〈M〉) = 〈M, M2〉3 〈M〉 ∈ ETM iff L(M) = ∅ iff L(M) = L(M2) iff〈M, M2〉 ∈ EQTM

Page 32: TDDC95 Introduction to the Theory of Computation - Lecture 6

Reductions

EQTM = {〈M1, M2〉 | M1 and M2 are TMs and L(M1) = L(M2)}

TheoremEQTM is undecidable

Proof.ETM ≤m EQTM :

1 Let M2 be a Turing machine such that L(M2) = ∅2 Given a Turing machine M, let f (〈M〉) = 〈M, M2〉3 〈M〉 ∈ ETM iff L(M) = ∅ iff L(M) = L(M2) iff〈M, M2〉 ∈ EQTM

Page 33: TDDC95 Introduction to the Theory of Computation - Lecture 6

Reductions

EQTM = {〈M1, M2〉 | M1 and M2 are TMs and L(M1) = L(M2)}

TheoremEQTM is undecidable

Proof.ETM ≤m EQTM :

1 Let M2 be a Turing machine such that L(M2) = ∅

2 Given a Turing machine M, let f (〈M〉) = 〈M, M2〉3 〈M〉 ∈ ETM iff L(M) = ∅ iff L(M) = L(M2) iff〈M, M2〉 ∈ EQTM

Page 34: TDDC95 Introduction to the Theory of Computation - Lecture 6

Reductions

EQTM = {〈M1, M2〉 | M1 and M2 are TMs and L(M1) = L(M2)}

TheoremEQTM is undecidable

Proof.ETM ≤m EQTM :

1 Let M2 be a Turing machine such that L(M2) = ∅2 Given a Turing machine M, let f (〈M〉) = 〈M, M2〉

3 〈M〉 ∈ ETM iff L(M) = ∅ iff L(M) = L(M2) iff〈M, M2〉 ∈ EQTM

Page 35: TDDC95 Introduction to the Theory of Computation - Lecture 6

Reductions

EQTM = {〈M1, M2〉 | M1 and M2 are TMs and L(M1) = L(M2)}

TheoremEQTM is undecidable

Proof.ETM ≤m EQTM :

1 Let M2 be a Turing machine such that L(M2) = ∅2 Given a Turing machine M, let f (〈M〉) = 〈M, M2〉3 〈M〉 ∈ ETM iff L(M) = ∅ iff L(M) = L(M2) iff〈M, M2〉 ∈ EQTM

Page 36: TDDC95 Introduction to the Theory of Computation - Lecture 6

Incompleteness Theorem from Undecidability

Kurt Gödel (1906-1978)

Page 37: TDDC95 Introduction to the Theory of Computation - Lecture 6

Incompleteness Theorem from Undecidability (S, 6.2)

Theorem(Informally) There are true mathematical statements thatcannot be proved

Proof idea.1 The language of all true mathematical statements is

undecidable (by reduction from ATM )2 The language of all provable statements is Turing

recognizable by a Turing machine M3 Assume that all true statements are provable4 Given a statement Φ, run M in parallel on Φ and ¬Φ. One

of them is true and thus (by assumption) provable. If Φ isprovable then Φ is true and if ¬Φ is provable then Φ is false.

5 So M decides the truth of Φ. This is a contradiction (with 1above)

Page 38: TDDC95 Introduction to the Theory of Computation - Lecture 6

Incompleteness Theorem from Undecidability (S, 6.2)

Theorem(Informally) There are true mathematical statements thatcannot be proved

Proof idea.1 The language of all true mathematical statements is

undecidable (by reduction from ATM )

2 The language of all provable statements is Turingrecognizable by a Turing machine M

3 Assume that all true statements are provable4 Given a statement Φ, run M in parallel on Φ and ¬Φ. One

of them is true and thus (by assumption) provable. If Φ isprovable then Φ is true and if ¬Φ is provable then Φ is false.

5 So M decides the truth of Φ. This is a contradiction (with 1above)

Page 39: TDDC95 Introduction to the Theory of Computation - Lecture 6

Incompleteness Theorem from Undecidability (S, 6.2)

Theorem(Informally) There are true mathematical statements thatcannot be proved

Proof idea.1 The language of all true mathematical statements is

undecidable (by reduction from ATM )2 The language of all provable statements is Turing

recognizable by a Turing machine M

3 Assume that all true statements are provable4 Given a statement Φ, run M in parallel on Φ and ¬Φ. One

of them is true and thus (by assumption) provable. If Φ isprovable then Φ is true and if ¬Φ is provable then Φ is false.

5 So M decides the truth of Φ. This is a contradiction (with 1above)

Page 40: TDDC95 Introduction to the Theory of Computation - Lecture 6

Incompleteness Theorem from Undecidability (S, 6.2)

Theorem(Informally) There are true mathematical statements thatcannot be proved

Proof idea.1 The language of all true mathematical statements is

undecidable (by reduction from ATM )2 The language of all provable statements is Turing

recognizable by a Turing machine M3 Assume that all true statements are provable

4 Given a statement Φ, run M in parallel on Φ and ¬Φ. Oneof them is true and thus (by assumption) provable. If Φ isprovable then Φ is true and if ¬Φ is provable then Φ is false.

5 So M decides the truth of Φ. This is a contradiction (with 1above)

Page 41: TDDC95 Introduction to the Theory of Computation - Lecture 6

Incompleteness Theorem from Undecidability (S, 6.2)

Theorem(Informally) There are true mathematical statements thatcannot be proved

Proof idea.1 The language of all true mathematical statements is

undecidable (by reduction from ATM )2 The language of all provable statements is Turing

recognizable by a Turing machine M3 Assume that all true statements are provable4 Given a statement Φ, run M in parallel on Φ and ¬Φ. One

of them is true and thus (by assumption) provable. If Φ isprovable then Φ is true and if ¬Φ is provable then Φ is false.

5 So M decides the truth of Φ. This is a contradiction (with 1above)

Page 42: TDDC95 Introduction to the Theory of Computation - Lecture 6

Incompleteness Theorem from Undecidability (S, 6.2)

Theorem(Informally) There are true mathematical statements thatcannot be proved

Proof idea.1 The language of all true mathematical statements is

undecidable (by reduction from ATM )2 The language of all provable statements is Turing

recognizable by a Turing machine M3 Assume that all true statements are provable4 Given a statement Φ, run M in parallel on Φ and ¬Φ. One

of them is true and thus (by assumption) provable. If Φ isprovable then Φ is true and if ¬Φ is provable then Φ is false.

5 So M decides the truth of Φ. This is a contradiction (with 1above)

Page 43: TDDC95 Introduction to the Theory of Computation - Lecture 6

Summary on Computability (what to focus on)

Turing machines and the Church-Turing thesisDiagonalization and the undecidability of the haltingproblemMapping reducibility