cp405 theory of...

98
CP405 Theory of Computation

Upload: others

Post on 18-Mar-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

CP405Theory of Computation

Page 2: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists
Page 3: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Test

Page 4: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Language: a set of stringsComputation as a test if a string is in a languageDFA: limited memory automatonRegular Language: a language accepted by a DFARegular Operations (closed): A B, AB, A∪ *, A, A∩BNFA: non-deterministic finite automatonDFA == NFA == regex (computational power)GNFA: NFA with regex transitionsProve lang. is non-regular with pumping lemmaPOSIX extended regexes are not formally regular (no corr. DFA)CFG: context-free grammar generates CFLSome languages are CF and not regularCFL are used for programming languagesAll regular languages are CFEvery CFL can be converted to Chomsky Normal Form (CNF)

- Rules are two vars, one terminal, or start->epsilonCNF string expansions require 2n-1 stepsL-Systems: formal grammars for modeling morphogenesis PDA == CFG (computational power)Non-deterministic PDA > Deterministic PDA (comp. power)Context-sensitive grammar > Context-free grammar (comp power)Prove lang. is not context-free with pumping lemmaTM > PDA (comp. power)TM can accept, reject, or loop foreverTM match intuitive definition of algorithmJava, Python, etc. are == TM (comp power)Linear Bounded Automata (LBA) == TM with finite tapeLBA == context-sensitive grammars (comp power)Post Tag System chops and concatenates strings (== TM)Queue Machine like PDA with queue in place of stack (== TM)PDA with two stacks == TMCounter Machines (pebbles in holes) with two registers (== TM)Random Access Machines provide indirect addressing (== TM)

Page 5: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Decidability

● Is everything computable?

● Do TMs always terminate?

Page 6: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Finite Languages

Regular Languages DFA/NFA

Deterministic Context-Free Languages

DPDA

Context-Sensitive LanguagesCSG/LBA

Context-Free LanguagesCFG/PDA

Something with TMs...

Page 7: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Decidable Languages

A language, L, is decidable (or recursive) if there exists a TM, M, that terminates correctly on every input string, w.

Page 8: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Decidable Languages

A language, L, is decidable (or recursive) if there exists a TM, M, that terminates correctly on every input string, w.

if w L, M terminates in the accept state ∈

if w L, M terminates in the reject state∉

Notice: M always terminates!

Page 9: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Decidable Languages

A language, L, is decidable (or recursive) if there exists a TM, M, that terminates correctly on every input string, w.

if w L, M terminates in the accept state ∈

if w L, M terminates in the reject state∉

A language that is not decidable is called undecidable.

Page 10: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Encoding Computational Models

a0

0

a1

1

a2

0,1DFA Number states: 3

Start state: 0Accept states: 2Transitions 0: 2 1Transitions 1: 1 1Transitions 2: 2 2

0,1

Page 11: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Encoding Computational Models

a0

0

a1

1

a2

0,1DFA Number states: 3

Start state: 0Accept states: 2Transitions 0: 2 1Transitions 1: 1 1Transitions 2: 2 2

0,13#0#2#2,1#1,1#2,2$

Page 12: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Encoding Computational Models

a0

0

a1

1

a2

0,1DFA Number states: 3

Start state: 0Accept states: 2Transitions 0: 2 1Transitions 1: 1 1Transitions 2: 2 2

0,13#0#2#2,1#1,1#2,2$

3#0#2#2,1#1,1#2,2$011With input:

Page 13: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Encoding Computational Models

a0

0

a1

1

a2

0,1DFA Number states: 3

Start state: 0Accept states: 2Transitions 0: 2 1Transitions 1: 1 1Transitions 2: 2 2

0,13#0#2#2,1#1,1#2,2$

11#0#10#10,1#1,1#10,10$011To binary:

3#0#2#2,1#1,1#2,2$011With input:

Page 14: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Encoded Model

Given a model M and a string input w:

⟨M, w⟩ = the binary encoding of M followed by the binary encoding of w.

Page 15: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ADFA = { M, w : M is a DFA that accepts w}⟨ ⟩

Is ADFA decidable?

Page 16: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ADFA = { M, w : M is a DFA that accepts w}⟨ ⟩

Is ADFA decidable?

Yes.

If the input does not have a legal encoding of a DFA, then reject. (No infinite loop)

Otherwise a TM can reconstruct M and then run M on w. (No infinite loop)

Page 17: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ANFA = { M, w : M is an NFA that accepts w}⟨ ⟩

Is ANFA decidable?

Page 18: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ANFA = { M, w : M is an NFA that accepts w}⟨ ⟩

Is ANFA decidable?

Yes.

First convert the NFA into an equivalent DFA. (No infinite loop)

Run the DFA and return its result. (No infinite loop)

Page 19: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ACFG = { G, w : G is a CFG with w L(G)}⟨ ⟩ ∈

Is ACFG decidable?

Page 20: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ACFG = { G, w : G is a CFG with w L(G)}⟨ ⟩ ∈

Is ACFG decidable?

???

We can have non-terminating expansions:

CFGS AB→A BB | a | → εB AAA | b | → ε

Page 21: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ACFG = { G, w : G is a CFG with w L(G)}⟨ ⟩ ∈

Is ACFG decidable?

???

We can have non-terminating expansions:

CFGS AB→A BB | a | → εB AAA | b | → ε

ExpansionSABBBBAAABBBBAABBAAABAABB...

Page 22: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ACFG = { G, w : G is a CFG with w L(G)}⟨ ⟩ ∈

Is ACFG decidable?

Yes.

First convert the CFG into CNF. (No infinite loop)

Try all derivations of length: 2n-1 (n = |w|). (No infinite loop)

Page 23: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ALBA = { M, w : M is an LBA that accepts w}⟨ ⟩

Is ALBA decidable?

Page 24: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ALBA = { M, w : M is an LBA that accepts w}⟨ ⟩

Is ALBA decidable?

Yes.

Run M on w for at most the following # of steps:

Page 25: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ALBA = { M, w : M is an LBA that accepts w}⟨ ⟩

Is ALBA decidable?

Yes.

Run M on w for at most the following # of steps:

QCΣC

where Q is the number of statesC is the number of tape cellsΣ is the alphabet

Page 26: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ATM = { M, w : M is a TM that accepts w}⟨ ⟩

Is AATM decidable?

Page 27: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ATM = { M, w : M is a TM that accepts w}⟨ ⟩

Is AATM decidable?

NO. �

Page 28: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ATM = { M, w : M is a TM that accepts w}⟨ ⟩

Assume AATM is decidable and show a contradiction:

Page 29: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ATM = { M, w : M is a TM that accepts w}⟨ ⟩

Assume AATM is decidable and show a contradiction:

There exists decider(M, w) always halts

Page 30: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Assume AATM is decidable and show a contradiction:

There exists decider(M, w) always halts

def rudeReverser(M):'''Input is a machine that takes an

encoding of a machine as input.'''return not decider(M, M)

ATM = { M, w : M is a TM that accepts w}⟨ ⟩

Page 31: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ATM = { M, w : M is a TM that accepts w}⟨ ⟩

Assume AATM is decidable and show a contradiction:

There exists decider(M, w) always halts

def rudeReverser(M):'''Input is a machine that takes an

encoding of a machine as input.'''return not decider(M, M)

print rudeReverser(rudeReverser)

Page 32: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ATM = { M, w : M is a TM that accepts w}⟨ ⟩

Assume AATM is decidable and TM D decides it.

Define TM R that takes input M :⟨ ⟩R runs D on M, M⟨ ⟨ ⟩⟩R returns the opposite result

Run R on input R ?⟨ ⟩

Page 33: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

This sentence is false.

Page 34: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

The barber shaves every man who does not shave himself.

Who shaves the barber?

Page 35: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

This difficulty with ATM is called the acceptance problem

For example this means we cannot write a Python program that will determine if any other Python program will produce the correct output or loop forever!

Page 36: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

HALT = { M, w : M is a TM that terminates on w}⟨ ⟩

This related language is even a bit simpler.

Does the TM even complete its execution on a given string?

This is called the halting problem.

Page 37: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Connection with Countable/Uncountable Infinities

Recall: ℕ: set of natural numbers {1, 2, 3, ...}

Any set that is finite or has a bijection with is ℕsaid to be countable.

Page 38: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ℤ is Countableℕ: set of natural numbers {1, 2, 3, ...}ℤ: set of integers {...,-3, -2, -1, 0, 1, 2, 3, ...}:

We need a function ƒ that is a bijection between and .ℕ ℤ

Page 39: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ℤ is Countableℕ: set of natural numbers {1, 2, 3, ...}ℤ: set of integers {...,-3, -2, -1, 0, 1, 2, 3, ...}:

We need a function ƒ that is a bijection between and .ℕ ℤ

Arrange elements of in this order:ℤ0, 1, -1, 2, -2, 3, -3, ...

ƒ(x) = x/2 if x is even= -(x-1)/2 if x is odd

Page 40: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ℚ is Countableℕ: set of natural numbers {1, 2, 3, ...}ℚ: set of rational numbers. x/y where x and y are both integers and y is not 0

We need a function ƒ that is a bijection between and .ℕ ℚ

Page 41: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ℚ is Countableℕ: set of natural numbers {1, 2, 3, ...}ℚ: set of rational numbers. x/y where x and y are both integers and y is not 0

We need a function ƒ that is a bijection between and .ℕ ℚ

Arrange elements of in a table:ℚ

0 1 2 3 ...1 0/1 1/1 2/1 3/1 ...2 0/2 1/2 2/2 3/2 ...3 0/3 1/3 2/3 3/3 ...

... ... ... ... ... ...

Page 42: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ℚ is Countableℕ: set of natural numbers {1, 2, 3, ...}ℚ: set of rational numbers. x/y where x and y are both integers and y is not 0

We need a function ƒ that is a bijection between and .ℕ ℚ

Arrange elements of in a table:ℚ

0 1 2 3 ...1 0/1 1/1 2/1 3/1 ...2 0/2 1/2 2/2 3/2 ...3 0/3 1/3 2/3 3/3 ...

... ... ... ... ... ...

Page 43: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ℝ is Uncountableℕ: set of natural numbers {1, 2, 3, ...}ℝ: set of real numbers.

There is no function ƒ that is a bijection between and ℕ. And no bijection between and a subset of , {x: 0 ≤ ℝ ℕ ℝ

x ≤ 1}

Page 44: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ℝ is Uncountableℕ: set of natural numbers {1, 2, 3, ...}ℝ: set of real numbers.

There is no function ƒ that is a bijection between and ℕ. And no bijection between and a subset of , {x: 0 ≤ ℝ ℕ ℝ

x ≤ 1}

Assume leading to contradiction that there is a bijection ƒ from to {x: 0 ≤ x ≤ 1}:ℕ

Page 45: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ℝ is UncountableAssume that there is a bijection ƒ from to {x: 0 ≤ x ≤ 1}:ℕ

Then we can write out each corresponding value ƒ(x) in decimal form:

f(1) = 0.3871643948827364...f(2) = 0.7738395004947231...f(3) = 0.9248472021125333......

Page 46: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ℝ is UncountableAssume that there is a bijection ƒ from to {x: 0 ≤ x ≤ 1}:ℕ

Then we can write out each corresponding value ƒ(x) in decimal form:

f(1) = 0.3871643948827364...f(2) = 0.7738395004947231...f(3) = 0.9248472021125333......

Since ƒ is a bijection, each x from {x: 0 ≤ x ≤ 1} should appear exactly once on the right-hand side.

Page 47: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ℝ is Uncountablef(1) = 0.3871643948827364...f(2) = 0.7738395004947231...f(3) = 0.9248472021125333......

Let's create a number, y, in the following way:

y =

Page 48: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ℝ is Uncountablef(1) = 0.3871643948827364...f(2) = 0.7738395004947231...f(3) = 0.9248472021125333......

Let's create a number, y, in the following way:

y = 0.4

different!

Page 49: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ℝ is Uncountablef(1) = 0.3871643948827364...f(2) = 0.7738395004947231...f(3) = 0.9248472021125333......

Let's create a number, y, in the following way:

y = 0.44

different!

Page 50: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

ℝ is Uncountablef(1) = 0.3871643948827364...f(2) = 0.7738395004947231...f(3) = 0.9248472021125333......

Let's create a number, y, in the following way:

y = 0.445

different!

Page 51: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

f(1) = 0.3871643948827364...f(2) = 0.7738395004947231...f(3) = 0.9248472021125333......

Let's create a number, y, in the following way:

y = 0.445...

So y is in {x: 0 ≤ x ≤ 1}, but it does not appear on the right-hand side of the bijection.

ℝ is Uncountable

Page 52: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

f(1) = 0.3871643948827364...f(2) = 0.7738395004947231...f(3) = 0.9248472021125333......

Let's create a number, y, in the following way:

y = 0.445...

So y is in {x: 0 ≤ x ≤ 1}, but it does not appear on the right-hand side of the bijection. Contradiction!

So we cannot have a bijection and {x: 0 ≤ x ≤ 1} must be bigger.

ℝ is Uncountable

Page 53: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Diagonalization for Halting ProblemEvery TM can be encoded in a finite length binary string <M>.

We can build a table with both rows and columns corresponding to particular TMs:

⟨TM0⟩ ⟨TM1⟩ ⟨TM2⟩ ⟨TM3⟩ ...TM0 1 1 0 1 ...TM1 0 0 0 1 ...TM2 1 0 0 0 ...TM3 0 0 0 1 ...

... ... ... ... ... ...

Page 54: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

⟨TM0⟩ ⟨TM1⟩ ⟨TM2⟩ ⟨TM3⟩ ...TM0 1 1 0 1 ...TM1 0 0 0 1 ...TM2 1 0 0 0 ...TM3 0 0 0 1 ...

... ... ... ... ... ...

Diagonalization for Halting ProblemEvery TM can be encoded in a finite length binary string <M>.

We can build a table with both rows and columns corresponding to particular TMs:

Does TM1 halt when given ⟨TM2⟩ as input?

Page 55: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

⟨TM0⟩ ⟨TM1⟩ ⟨TM2⟩ ⟨TM3⟩ ...TM0 1 1 0 1 ...TM1 0 0 0 1 ...TM2 1 0 0 0 ...TM3 0 0 0 1 ...

... ... ... ... ... ...

Diagonalization for Halting ProblemEvery TM can be encoded in a finite length binary string <M>.

We can build a table with both rows and columns corresponding to particular TMs:

If we assume HALT is decidable, then there must exist a TM that returns these table values.

Page 56: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Diagonalization for Halting ProblemEvery TM can be encoded in a finite length binary string <M>.

We can build a table with both rows and columns corresponding to particular TMs:

⟨TM0⟩ ⟨TM1⟩ ⟨TM2⟩ ⟨TM3⟩ ...TM0 1 1 0 1 ...TM1 0 0 0 1 ...TM2 1 0 0 0 ...TM3 0 0 0 1 ...

... ... ... ... ... ...

Consider a TM, RudeReverser:Given x = TM⟨ n, TM⟨ n ,⟩⟩Run decider on x.Return the opposite value.

Page 57: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Diagonalization for Halting ProblemEvery TM can be encoded in a finite length binary string <M>.

We can build a table with both rows and columns corresponding to particular TMs:

⟨TM0⟩ ⟨TM1⟩ ⟨TM2⟩ ⟨TM3⟩ ... ⟨RR⟩

TM0 1 1 0 1 ...TM1 0 0 0 1 ...TM2 1 0 0 0 ...TM3 0 0 0 1 ...

... ... ... ... ... ...RR

Create a TM, RudeReverser:Given x = TM⟨ n, TM⟨ n ,⟩⟩Run decider on x.Return the opposite value.

RudeReverser is a TM so it must be somewhere in the table.

Page 58: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Diagonalization for Halting ProblemEvery TM can be encoded in a finite length binary string <M>.

We can build a table with both rows and columns corresponding to particular TMs:

Create a TM, RudeReverser:Given x = TM⟨ n, TM⟨ n ,⟩⟩Run decider on x.Return the opposite value.

RudeReverser is a TM so it must be somewhere in the table.

⟨TM0⟩ ⟨TM1⟩ ⟨TM2⟩ ⟨TM3⟩ ... ⟨RR⟩

TM0 1 1 0 1 ...TM1 0 0 0 1 ...TM2 1 0 0 0 ...TM3 0 0 0 1 ...

... ... ... ... ... ...RR 0 1 1 0

Page 59: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

⟨TM0⟩ ⟨TM1⟩ ⟨TM2⟩ ⟨TM3⟩ ... ⟨RR⟩

TM0 1 1 0 1 ...TM1 0 0 0 1 ...TM2 1 0 0 0 ...TM3 0 0 0 1 ...

... ... ... ... ... ...RR 0 1 1 0 0

Diagonalization for Halting ProblemEvery TM can be encoded in a finite length binary string <M>.

We can build a table with both rows and columns corresponding to particular TMs:

Create a new TM, RudeReverser:Given x = TM⟨ n, TM⟨ n ,⟩⟩Run decider on x.Return the opposite value.

If the decider returns 1, then RudeReverser must reverse it to 0.

Page 60: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

⟨TM0⟩ ⟨TM1⟩ ⟨TM2⟩ ⟨TM3⟩ ... ⟨RR⟩

TM0 1 1 0 1 ...TM1 0 0 0 1 ...TM2 1 0 0 0 ...TM3 0 0 0 1 ...

... ... ... ... ... ...RR 0 1 1 0 1

Diagonalization for Halting ProblemEvery TM can be encoded in a finite length binary string <M>.

We can build a table with both rows and columns corresponding to particular TMs:

Create a new TM, RudeReverser:Given x = TM⟨ n, TM⟨ n ,⟩⟩Run decider on x.Return the opposite value.

But if this value is 0, then the decider should return 0 and RudeReverser must reverse it to 1!

Page 61: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

⟨TM0⟩ ⟨TM1⟩ ⟨TM2⟩ ⟨TM3⟩ ... ⟨RR⟩

TM0 1 1 0 1 ...TM1 0 0 0 1 ...TM2 1 0 0 0 ...TM3 0 0 0 1 ...

... ... ... ... ... ...RR 0 1 1 0 0

Diagonalization for Halting ProblemEvery TM can be encoded in a finite length binary string <M>.

We can build a table with both rows and columns corresponding to particular TMs:

And we're left with the zero-one contradiction monster.

1

Page 62: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Rice's Theorem

All non-trivial properties of Turing machines (algorithms) are undecidable!

P1 = { M : M is a TM and L(M) = {1, 10}}⟨ ⟩P2 = { M : M is a TM and L(M) = }⟨ ⟩ ∅P3 = { M : L(M) is finite}⟨ ⟩

Page 63: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Rice's Theorem Definition

T = the set of all binary-encoded TMs

For all P T where:⊂● P ≠ and∅● encodings of any two TMs that have the same language are either both in P or both not in P

Then, P is undecidable.

Page 64: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Rice's Theorem

P4 = { M : M has 42 states}⟨ ⟩

Does P4 fit Rice's Theorem criteria?

Page 65: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Rice's Theorem

P4 = { M : M has 42 states}⟨ ⟩

Does P4 fit Rice's Theorem criteria?

No, because we could have:

TMA and TMB with L(TMA) = L(TMB)and TMA with 42 states and TMB with 43

states

Page 66: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Proof of Rice's Theorem

Show a connection between a language with a certain property, LP, and the halting problem.

In particular, if we can show that LP being decidable makes the halting problem decidable, then we have a contradiction.

Page 67: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Proof of Rice's Theorem

M∅ is a TM that accepts . Assume M∅ ⟨ ∅ ⟩ ∉ LP

Myes is a TM such that M⟨ yes ⟩ ∈ LP

Page 68: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

Proof of Rice's Theorem

M∅ is a TM that accepts . Assume M∅ ⟨ ∅ ⟩ ∉ LP

Myes is a TM such that M⟨ yes ⟩ ∈ LP

Note that L(M∅) ≠ L(Myes)

Assume leading to contradiction that there is a decider for the language LP.

Page 69: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

x Recognizerfor M

yes

keithswarz.com

Page 70: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

x

Recognizerfor M

yes

Page 71: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

x

Recognizerfor M

yes

Page 72: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

SimulateM on w

x

Recognizerfor M

yes

Page 73: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

SimulateM on w

x

Recognizerfor M

yes

x

Page 74: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

SimulateM on w

x

Recognizerfor M

yes

x

Machine M'

Page 75: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

SimulateM on w

x

Recognizerfor M

yes

x

M' = “On input x:Run M on w.If M halts, run M

yes on x.

Accept if Myes

accepts x.

Reject if Myes

rejects x.”

Machine M'

Page 76: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

SimulateM on w

x

Recognizerfor M

yes

x

M' = “On input x:Run M on w.If M halts, run M

yes on x.

Accept if Myes

accepts x.

Reject if Myes

rejects x.”

If M loops on w, what does M' do

on x?

Machine M'

Page 77: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

SimulateM on w

x

Recognizerfor M

yes

x

M' = “On input x:Run M on w.If M halts, run M

yes on x.

Accept if Myes

accepts x.

Reject if Myes

rejects x.”

If M loops on w, what does M' do

on x?

Machine M'

Page 78: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

SimulateM on w

x

Recognizerfor M

yes

x

M' = “On input x:Run M on w.If M halts, run M

yes on x.

Accept if Myes

accepts x.

Reject if Myes

rejects x.”

If M loops on w, what does M' do

on x?

M' always loops.

Machine M'

Page 79: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

SimulateM on w

x

Recognizerfor M

yes

x

M' = “On input x:Run M on w.If M halts, run M

yes on x.

Accept if Myes

accepts x.

Reject if Myes

rejects x.”

If M loops on w, what does M' do

on x?

L(M') = Ø

Machine M'

Page 80: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

SimulateM on w

x

Recognizerfor M

yes

x

M' = “On input x:Run M on w.If M halts, run M

yes on x.

Accept if Myes

accepts x.

Reject if Myes

rejects x.”

Machine M'

Page 81: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

SimulateM on w

x

Recognizerfor M

yes

x

M' = “On input x:Run M on w.If M halts, run M

yes on x.

Accept if Myes

accepts x.

Reject if Myes

rejects x.”

If M halts on w, what does M' do

on x?

Machine M'

Page 82: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

SimulateM on w

x

Recognizerfor M

yes

x

M' = “On input x:Run M on w.If M halts, run M

yes on x.

Accept if Myes

accepts x.

Reject if Myes

rejects x.”

If M halts on w, what does M' do

on x?

Machine M'

Page 83: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

SimulateM on w

x

Recognizerfor M

yes

x

M' = “On input x:Run M on w.If M halts, run M

yes on x.

Accept if Myes

accepts x.

Reject if Myes

rejects x.”

If M halts on w, what does M' do

on x?

M' accepts x ifMyes accepts x

Machine M'

Page 84: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

SimulateM on w

x

Recognizerfor M

yes

x

M' = “On input x:Run M on w.If M halts, run M

yes on x.

Accept if Myes

accepts x.

Reject if Myes

rejects x.”

If M halts on w, what does M' do

on x?

L(M') = L(Myes)

Machine M'

Page 85: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

The Complete Construction

Decider for L

P

keithswarz.com

Page 86: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

The Complete Construction

Decider for L

P

⟨M, w ⟩

Page 87: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

The Complete Construction

Decider for L

P

ConstructM' from⟨M, w⟩

⟨M, w ⟩

Page 88: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

The Complete Construction

SimulateM on w

x

Recognizerfor M

yes

x

Decider for L

P

ConstructM' from⟨M, w⟩

⟨M, w ⟩

Page 89: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

The Complete Construction

SimulateM on w

x

Recognizerfor M

yes

x

Decider for L

P

ConstructM' from⟨M, w⟩

⟨M'⟩ ⟨M, w ⟩

Page 90: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

The Complete Construction

SimulateM on w

x

Recognizerfor M

yes

x

Decider for L

P

ConstructM' from⟨M, w⟩

⟨M'⟩ ⟨M, w ⟩

What happens if M halts on w?

Page 91: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

The Complete Construction

SimulateM on w

x

Recognizerfor M

yes

x

Decider for L

P

ConstructM' from⟨M, w⟩

⟨M'⟩ ⟨M, w ⟩

What happens if M halts on w?

L(M') L∈P

Page 92: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

The Complete Construction

SimulateM on w

x

Recognizerfor M

yes

x

Decider for L

P

ConstructM' from⟨M, w⟩

⟨M'⟩ ⟨M, w ⟩

What happens if M halts on w?

L(M') L∈P

Page 93: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

The Complete Construction

SimulateM on w

x

Recognizerfor M

yes

x

Decider for L

P

ConstructM' from⟨M, w⟩

⟨M'⟩ ⟨M, w ⟩

Page 94: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

The Complete Construction

SimulateM on w

x

Recognizerfor M

yes

x

Decider for L

P

ConstructM' from⟨M, w⟩

⟨M'⟩ ⟨M, w ⟩

What happens if M loops on w?

Page 95: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

The Complete Construction

SimulateM on w

x

Recognizerfor M

yes

x

Decider for L

P

ConstructM' from⟨M, w⟩

⟨M'⟩ ⟨M, w ⟩

What happens if M loops on w?

L(M') L∉P

Page 96: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

The Complete Construction

SimulateM on w

x

Recognizerfor M

yes

x

Decider for L

P

ConstructM' from⟨M, w⟩

⟨M'⟩ ⟨M, w ⟩

What happens if M loops on w?

L(M') L∉P

Page 97: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

The Complete Construction

SimulateM on w

x

Recognizerfor M

yes

x

Decider for L

P

ConstructM' from⟨M, w⟩

⟨M'⟩ ⟨M, w ⟩

Page 98: CP405 Theory of Computationcs.coloradocollege.edu/~mwhitehead/courses/2016_2017/CP405/Lectures/9.pdf · Decidable Languages A language, L, is decidable (or recursive) if there exists

The Complete Construction

SimulateM on w

x

Recognizerfor M

yes

x

Decider for L

P

ConstructM' from⟨M, w⟩

⟨M'⟩ ⟨M, w ⟩

This machine decides HALT!