lecture 18 various tms. allow the head not move theorem. if the head is allowed to stay at the cell...

47
Lecture 18 Various TMs

Upload: brian-jonah-cameron

Post on 24-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Lecture 18 Various TMs

Page 2: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Allow the head not move

Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the DTM is still Turing-computable.

Proof. Consider DTM M=(Q,Σ,Γ,δ,s) whereδ: Q x Γ → Q x Γ x {R, L, H} and H meansthat the head stays at the current cell. We

construct M’=(Q U Q’, Σ, Γ, δ’,s) as follows:

Page 3: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

• Q’ = {q’ | q ε Q}

• For q ε Q,

δ’(q, a) = (p, b, R) if δ(q, a) = (p, b, R)

δ’(q, a) = (p, b, L) if δ(q, a) = (p, b, L)

δ’(q, a) = (p’, b, R) if δ(q, a) = (p, b, H)

For p’ ε Q’,

δ’(p’, a) = (p, a, L).

M and M’ compute the same function.

Page 4: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Corollary. A language is accepted by a DTM, which allows the head not to move, iff it is Turing-acceptable.

Why this is a corollary?

Because every language accepted by a DTM is the definition domain of a function computable by a DTM of the same type.

Corollary. A language is decided by a DTM, which allows the head not to move, iff it is Turing-decidable.

Page 5: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Two-way DTM

1 2 3ab

Page 6: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Theorem. Every function computed by a two-way DTM is Turing-computable.

$

1 2 3

a b

Page 7: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Consider a two-way DTM M=(Q, Σ, Γ, δ,s). Construct a DTM M’ = (Q U Q’,Σ’,Γ’,δ’,s) to simulate M as follows:

• Q’={q’ | q ε Q}

• Γ’ ={(a, b) | a, b ε Γ } U { (B, $) }

• Σ’ ={(a, B) | a ε Σ}

• For q ε Q,

δ’(q, $) = (q’,$,R)

δ’(q, (a, c)) = (p,(b,c),D) if δ(q,a)=(p,b,D)

Page 8: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

• For q’ ε Q’,

δ’(q’, $) = (q, $, R)

δ’(q’,(c,a)) = (p’,(c,b),R) if δ(q,a)=(p,b,L)

δ’(q’,(c,a)) = (p’,(c,b),L) if δ(q,a)=(p,b,R)

δ’(q’,(c,a)) = (p’,(c,b),H) if δ(q,a)=(p,b,H)

Page 9: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Multi-tape DTM

Input tape(read only)

Storage tapes

Output tape

(possibly, write only)

Page 10: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Theorem. A function can be computed by a multitape DTM iff it isTuring-computable.

Proof.

tape

head

tape

head

tape

headX

X

X

Page 11: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

To simulate a move of the multitape DTM, the one-tape DTM needs two trips:

• Trip 1: read all symbols at heads.• Trip 2: erase and write at cells scaned by heads.

Questions:• How many moves does one-tape DTM needs to

simulate t moves of a multitape DTM?• How many states does one-tape DTM needs to

simulate a multitape DTM?

Page 12: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Nondeterministic TM (NTM)

• There are multiple choices for each transition.

• For each input x, the NTM may have more than one computation paths.

• An input x is accepted if at least one computation path leads to the final state.

• L(M) is the set of all accepted inputs.

Page 13: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

• A function f(x) is computed by an NTM M if for every x ε L(M), M gives output f(x) whenever it reaches the final state.

Theorem. A function can be computed by an NTM iff it is Turing-computable.

Proof. Idea: Enumerate all possible computation paths of certain length from small to large.

Implement: set a tape to do the enumeration.

Page 14: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

• Suppose for each transition, there are at most c choices. Then on the enumeration tape, the DTM enumerate all strings on alphabet {a1, a2, …, ac}: ε, a1, a2, …, ac, a1a2, a1a3, ….

• When a string ai1ai2∙∙∙aim is written on the enumeration tape, the DTM simulates the NTM by making the ij –th choice at the j-th move.

• DTM halts iff it found a computation path of NTM which halts.

Page 15: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

• Question: How many moves does a DMT needs to simulate t moves of a NTM?

• O(c )t

Page 16: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Church-Turing Thesis

Any reasonably computable function

is a Turing-computable function.

Page 17: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Theorem. A language A is Turing-decidable iff both A and its complement A are Turing-acceptable.

Proof. The forward direction is easy. For the backward direction, suppose one-tape

DTMs M and M’ accept A and A respectively. Construct 4-tape DTM M* as follows:

• Use a storage tape to simulate M and another storage tape to simulate M’.• M* halts iff M or M’ halts.• If M halts, then M* outputs 1.• If M’ halts, then M* outputs 0.

Page 18: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Lecture 19 Recursive Functions

Page 19: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Initial Functions

• Zero function ζ(n) = 0.

• Successor σ(n) = n+1, for n ε N.

• Projection πi (n1,…,nk) = ni.k

Page 20: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Composition

• Let m, k be two integers.

• Given functions g: N → N and hi: N → N for I = 1, 2, …, m, define f: N → by

f(n1,…,nk) = g(h1(n1,…,nk),…,hm(n1,…,nk)

• f is called the composition of g and h1, …, hm.

• f = go(h1,…,hm)

m k

k

Page 21: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Primitive Recursion

• Let k > 0. Given g: N → N and h: N → N,

(when k=0, g is a constant),

define f : N → N by

f(n1,…nk,0) = g(n1,…,nk)

f(n1,…,nk,m+1) = h(n1,…,nk,m,f(n1,…nk,m)

k k+2

k+1

Page 22: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Primitive Recursive Functions

• All initial functions are primitive recursive.

• If g and h1, …, hm are primitive recursive,

so is go(h1, …, hk).

• If g and h are primitive recursive,

so is f obtained from g and h by primitive recursion.

• Nothing else is primitive recursive.

Page 23: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Add(m, n) = m+n

• Add(m,0) = π1 (m)

• Add(m, n+1) = σ( π3 (m,n, add(m, n)))

1

3

Page 24: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

mult(m, n) = mn

• mult(m, 0) = ζ(m)

• Mult(m, n+1) =

add(π1(m,n,mult(m,n)), π3(m, n, mult(m,n))3 3

Page 25: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

minus(m,n)= m-n if m > n; 0 if m<n

• pred(m) = minus(m,1)

pred(0) = ζ(0)

pred(m+1) = m = π1 (m, pred(m))

• minus(m,0) = π1 (m)

minus(m, n+1) = pred(π3(m,n,minus(m, n))

2

1

3

Page 26: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Pairing Function

• A function f: N → N is a pairing function if it satisfies the following conditions:

(1) f is 1-to-1 and onto;

(2) f is primitive recursive;

(3) f(i, j) < f(i+1, j), f(i, j) < f(i, j+1).• For example,

jjiji

ji 2

)1)(( ),(

2

Page 27: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

• Two “inverse” functions i = g(f(i,j)) and

j = h(f(i, j)) are also primitive recursive.

0 1

2

3

4

5

6

7

8

9

10

11

12

13

14

Page 28: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Bounded minimization

• Given g: N → N, define f by

f(n1, …, nk, m) = min {i | g(n1, …, nk, i)=1}

if there exists i < m such

that g(n1, …, nk, i) =1;

= 0, otherwise.

• If g is primitive recursive, so is f.

K+1

Page 29: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Unbounded minimization

• Given g: N → N, define f by f(n1, …, nk) = min {i | g(n1, …, nk, i)=1} if there exists i such that g(n1, …, nk, i) =1; = ↑, otherwise.

• f may not be primitive recursive, even if g is.

K+1

Page 30: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Partial Recursive Functions

• All initial functions are partial recursive.• If g is a total recursive function, then f

obtained from g by unbounded minimization is partial recursive.

• If g and h1,…, hk are partial recursive, so is go(h1,…,hk).

• If g and h are partial recursive, so is f obtained from g and h by primitive recursion.

Page 31: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Over Σ*

• Zero function ζ(x) = ε.

• Successor σa(x) = xa for a in Σ.

• Projection (no change)

• Composition (no change)

• Primitive recursion (need a change, m+1 is replaced by ma)

• Unbounded minimization (need to give a linear ordering of Σ*)

Page 32: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

From Σ* to Γ* for Σ* c Γ*

• Zero function ζ(x) = ε.

• Successor σa(x) = xa for a in Γ.

• N can be considered as a subset of {0, 1}* if we represent n by 1…1

n

Page 33: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Theorem

• A function is partial recursive iff it is Turing-computable.

Page 34: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Theorem

The following are equivalent:

• A is r.e.

• A is Turing-acceptable.

• A is the range of a primitive recursive function.

• A is the domain of a partial recursive function.

Page 35: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Pairing function on Σ*

• Let π(i, j) be a pairing function on N.

• Let φ be a 1-to-1 onto mapping from N to Σ*.

• Let μ be a 1-to-1 onto mapping from Σ* to N.

• Then p(x, y) = φ(π(μ(x), μ(y)) is a pairing function on Σ*.

Page 36: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Lecture 20 Universal TM

Page 37: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Code of a DTM

• Consider a one-tape DTM M = (Q, Σ, Γ, δ, s). It can be encoded as follows:

First, encode each state, each direction, and each symbol into a natural number (code(B) = 0, code(R) =1, code(L) = 2, code(s)=3, code(h)=4, ... ). Then encode each transition δ(q, a) = (p, b, D) into a string

0 10 10 10 10 q a p b D

Page 38: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

• The code of M is obtained by combining all codes codei of transitions together:

111code111code211∙∙∙11codem111.

Remark:

• Each TM has many codes.

• All codes of TMs form a Turing-decidable language.

Page 39: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Universal DTM

• One can design a three-tape DTM M* which behaves as follows:

On input <x, M>, M* first decodes M on the second tape and then simulates M on the output tape.

• Clearly, L(M*) = { <x, M> | x ε L(M)}. Thus,

Theorem 1. { <x, M> | x ε L(M)} is Turing-acceptable.

Page 40: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

• Next, we prove

Theorem 2. { <x, M> | x ε L(M)} isn't Turing-decidable.

• To do so, we consider

A = { M | M accepts M}

and prove

Lemma. A isn't Turing-decidable.

Page 41: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Barber cuts his own hair

Class 1: {Barber | he can cut his own hair}

Class 2: {Barber | he cannot cut own hair}

Question: Is there a barber who cuts hair of everybody in class 2, but not cut hair of anybody in class 1.

Answer: No!!!

Proof. Suppose such a barber exists. If he cuts his own hair, then he is in class 1 and hence he cannot cut his own hair, a contradiction.

Page 42: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

If he cannot cut his own hair, then he belongs to class 2 and hence he can cut his own hair, a contradiction.

• This argument is called diagonalization.

hair

barber

Page 43: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Example. There exists an irrational number.

Proof. Consider all rational numbers in (0,1). They are countable, a1, a2, …. Now, we construct a number such that its i-th digit is different from the i-th digit of ai.

Then this number is not rational.

a1

a2

digits

Page 44: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Proof. For contradiction, suppose that A is accepted by a one-tape DTM M’. We look at M’ on input M’.

• If M’ accepts M’, then M’ is in A, which means that M’ rejects M’, a contradiction.

• If M’ rejects M’, then M’ isn’t in A which means that M’ accepts M’, a contradiction.

Page 45: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Many-one reduction

• Consider two sets A ε Σ* and B ε Γ*. If there exists a Turing-computable total function f : Σ* → Γ* such that

x ε A iff f(x) ε B,

then we say that A is many-one reducible to B, and write A ≤m B.

Page 46: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

• A = { M | M accepts M}

• B = {<x,M> | M accepts x}

Claim. A ≤m B.

Proof. Define f(M) = <M,M>.

M ε A iff M accepts M iff <M, M> ε B

Page 47: Lecture 18 Various TMs. Allow the head not move Theorem. If the head is allowed to stay at the cell in each move, then every function computed by the

Theorem. A ≤m B, B ≤m C imply A ≤m C.

(This means that ≤m is a partial ordering.)

Theorem. If A ≤m B and B is Turing-decidable, then A is Turing-decidable.

By this theorem, {<x, M> | M accepts x} isn’t Turing-decidable.