December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We...

26
December 1, 2009 Theory of Computation Lecture 21: Turing Machines II 1 Simulation of Simulation of L L n n in in T T We will now construct a Post-Turing We will now construct a Post-Turing program program Q Q that that simulates simulates P P step by step by step. step. Of course, the information available to Of course, the information available to Q Q must be put onto the must be put onto the tape tape . . Therefore, we have to use a system for Therefore, we have to use a system for storing the values of all variables at storing the values of all variables at certain positions on the tape: certain positions on the tape: B x B x 1 B x B x 2 2 B … B x B … B x m B z B z 1 B z B z 2 B … B z B … B z k B y B y , , where x where x 1 , x , x 2 , …, x , …, x m , z , z 1 , z , z 2 , …, z , …, z k , y are , y are the current values of the variables X the current values of the variables X 1 , , X X 2 , …, X , …, X m , Z , Z 1 , Z , Z 2 , …, Z , …, Z k , Y (using the , Y (using the

Transcript of December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We...

Page 1: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

1

Simulation of Simulation of LLnn in in TT

We will now construct a Post-Turing program We will now construct a Post-Turing program QQ that that simulatessimulates PP step by step. step by step.

Of course, the information available to Of course, the information available to QQ must be put must be put onto the onto the tapetape..

Therefore, we have to use a system for storing the Therefore, we have to use a system for storing the values of all variables at certain positions on the tape:values of all variables at certain positions on the tape:

B xB x11 B x B x2 2 B … B xB … B xmm B z B z11 B z B z22 B … B z B … B zkk B y B y , ,

where xwhere x11, x, x22, …, x, …, xmm, z, z11, z, z22 , …, z , …, zkk, y are the current , y are the current

values of the variables Xvalues of the variables X11, X, X22, …, X, …, Xmm, Z, Z11, Z, Z22 , …, Z , …, Zkk, Y , Y

(using the original variable names). (using the original variable names).

Page 2: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

2

Simulation of Simulation of LLnn in in TT

An advantage of this system is that the An advantage of this system is that the initial tape initial tape configurationconfiguration is already in the correct form: is already in the correct form:

B xB x11 B x B x2 2 B … B xB … B xmm . .

What needs to be done now is to show how to program What needs to be done now is to show how to program the effect of each instruction type of the effect of each instruction type of LLnn in the language in the language

TT..

In the following, we will define some In the following, we will define some macros macros that will that will help us to do this task.help us to do this task.

Page 3: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

3

Simulation of Simulation of LLnn in in TT

The macro The macro GOTO LGOTO L has the expansion has the expansion

IF sIF s00 GOTO L GOTO L // Remember: s// Remember: s00 = B = B

IF sIF s11 GOTO L GOTO L

::

IF sIF snn GOTO L GOTO L

Page 4: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

4

Simulation of Simulation of LLnn in in TT

The macro The macro RIGHT TO NEXT BLANKRIGHT TO NEXT BLANK has the has the expansionexpansion

[A][A] RIGHTRIGHT

IF B GOTO EIF B GOTO E

GOTO AGOTO A

The macro The macro LEFT TO NEXT BLANKLEFT TO NEXT BLANK has the expansion has the expansion

[A][A] LEFTLEFT

IF B GOTO EIF B GOTO E

GOTO AGOTO A

Page 5: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

5

Simulation of Simulation of LLnn in in TT

The macro The macro MOVE BLOCK RIGHTMOVE BLOCK RIGHT has the expansion has the expansion

[C][C] LEFTLEFT

IF sIF s00 GOTO A GOTO A00

IF sIF s11 GOTO A GOTO A11

::

IF sIF snn GOTO A GOTO Ann

[A[Aii]] RIGHTRIGHT i = 1, 2, …, ni = 1, 2, …, n

PRINT sPRINT sii ::

LEFTLEFT ::

GOTO CGOTO C ::

[A[A00]] RIGHTRIGHT

PRINT BPRINT B

LEFTLEFT

Example:Example:ss33BsBs11ss22BB

ss33BsBs11ss22BB

ss33BsBs11ss22BB

ss33BsBs11ss22ss22

ss33BsBs11ss22ss22

ss33BsBs11ss22ss22

ss33BsBs11ss22ss22

ss33BsBs11ss11ss22

ss33BsBs11ss11ss22

ss33BsBs11ss11ss22

ss33BsBs11ss11ss22

ss33BBsBBs11ss22

ss33BBsBBs11ss22

Page 6: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

6

Simulation of Simulation of LLnn in in TT

The macro The macro ERASE A BLOCKERASE A BLOCK has the expansion has the expansion

[A][A] RIGHTRIGHT

IF B GOTO EIF B GOTO E

PRINT BPRINT B

GOTO AGOTO A

This program causes the head to move to the right, This program causes the head to move to the right, erasing everything between its initial position and the erasing everything between its initial position and the first blank to its right.first blank to its right.

Page 7: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

7

Simulation of Simulation of LLnn in in TT

We introduce another convention:We introduce another convention:

A number in square brackets after the name of a A number in square brackets after the name of a macro indicates macro indicates how many timeshow many times the macro the macro expansion is to be inserted into the program.expansion is to be inserted into the program.

For example,For example,

MOVE BLOCK RIGHT [4]MOVE BLOCK RIGHT [4]

is short foris short for

MOVE BLOCK RIGHT MOVE BLOCK RIGHT MOVE BLOCK RIGHT MOVE BLOCK RIGHT MOVE BLOCK RIGHT MOVE BLOCK RIGHT MOVE BLOCK RIGHT MOVE BLOCK RIGHT

Page 8: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

8

Simulation of Simulation of LLnn in in TT

Now we can start simulating the three instruction types Now we can start simulating the three instruction types in the language in the language LLnn by Post-Turing programs. by Post-Turing programs.

We begin the instruction type We begin the instruction type VVjj s siiVVjj . .

In order to place the symbol sIn order to place the symbol s ii to the left of the j-th to the left of the j-th

variable on the tape, the values of the variables Vvariable on the tape, the values of the variables V jj, …, , …,

VVll must all be must all be moved one square to the rightmoved one square to the right to to

make room.make room.

After inserting sAfter inserting s ii the tapehead must the tapehead must go backgo back to the to the

blank at the left of the value of Vblank at the left of the value of V11 in order to be ready in order to be ready

for the next simulated instruction.for the next simulated instruction.

Page 9: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

9

Simulation of Simulation of LLnn in in TT

Here is the program for the simulation of Here is the program for the simulation of VVjj s siiVVjj::

RIGHT TO NEXT BLANK [ l ]RIGHT TO NEXT BLANK [ l ]

MOVE BLOCK RIGHT [ l – j + 1 ]MOVE BLOCK RIGHT [ l – j + 1 ]

RIGHTRIGHT

PRINT sPRINT sii

LEFT TO NEXT BLANK [ j ]LEFT TO NEXT BLANK [ j ]

Page 10: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

10

Simulation of Simulation of LLnn in in TT

Now we want to show how to simulate Now we want to show how to simulate VVjj V Vjj-- . .

The problem here is that if VThe problem here is that if V jj contains the null string, it contains the null string, it

must be left unchanged.must be left unchanged.

Thus, we move to the blank immediately to the right of Thus, we move to the blank immediately to the right of the value of Vthe value of Vjj..

Then we move one step to the left, and if we find Then we move one step to the left, and if we find another blank there, Vanother blank there, V jj must contain the null string must contain the null string

(indicated by two successive blanks).(indicated by two successive blanks).

Page 11: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

11

Simulation of Simulation of LLnn in in TT

Here is the program for the simulation of Here is the program for the simulation of VVjj V Vjj-- : :

RIGHT TO NEXT BLANK [ j ]RIGHT TO NEXT BLANK [ j ]

LEFTLEFT

IF B GOTO CIF B GOTO C // V// Vjj contains null string contains null string

MOVE BLOCK RIGHT [ j ]MOVE BLOCK RIGHT [ j ]

RIGHTRIGHT

GOTO EGOTO E

[C][C] LEFT TO NEXT BLANK [ j - 1 ]LEFT TO NEXT BLANK [ j - 1 ]

Page 12: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

12

Simulation of Simulation of LLnn in in TT

And finally, here is the program for the simulation of And finally, here is the program for the simulation of IF VIF Vjj ENDS s ENDS sii GOTO L GOTO L::

RIGHT TO NEXT BLANK [ j ]RIGHT TO NEXT BLANK [ j ]

LEFTLEFT

IF sIF sii GOTO C GOTO C // V// Vjj ends in s ends in sii

GOTO DGOTO D

[C][C] LEFT TO NEXT BLANK [ j ]LEFT TO NEXT BLANK [ j ]

GOTO LGOTO L // Note: transfer all labels from // Note: transfer all labels from LLnn to to TT

[D][D] RIGHTRIGHT // V// Vjj could contain null string could contain null string

LEFT TO NEXT BLANK [ j ]LEFT TO NEXT BLANK [ j ]

Page 13: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

13

Simulation of Simulation of LLnn in in TTNow we are able to translate any program in the language Now we are able to translate any program in the language LLnn

into a corresponding program in into a corresponding program in TT..

There is only one thing that There is only one thing that needs to be fixedneeds to be fixed::

After the program terminates, we want After the program terminates, we want only the string yonly the string y to to remain on the tape as the program’s output.remain on the tape as the program’s output.

This can be done by appending the following code to our This can be done by appending the following code to our generated generated TT program: program:

ERASE A BLOCK [ l – 1 ]ERASE A BLOCK [ l – 1 ]

This will erase the values of the first l – 1 variables on the tape, This will erase the values of the first l – 1 variables on the tape, so only the last variable will remain and the final tape so only the last variable will remain and the final tape configuration will beconfiguration will be

… … B B B y B B B …B B B y B B B …

Page 14: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

14

Simulation of Simulation of TT in in LLThe next thing we want to prove is the following:The next thing we want to prove is the following:

Theorem 6.1:Theorem 6.1: If there is a Post-Turing program that If there is a Post-Turing program that computes the partial function f(xcomputes the partial function f(x11, …, x, …, xmm), then f is ), then f is

partially computable.partially computable.

Since our definition of partial computability is based on Since our definition of partial computability is based on the language the language LL, this theorem states the following:, this theorem states the following:

If the m-ary partial function f on A* is computed by a If the m-ary partial function f on A* is computed by a program of program of TT, then there is a program of , then there is a program of LL that that computes f (using base n values of strings).computes f (using base n values of strings).

Page 15: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

15

Simulation of Simulation of TT in in LLBased on Theorem 6.1 and also Theorems 3.2 and Based on Theorem 6.1 and also Theorems 3.2 and 5.1, we can derive another Theorem:5.1, we can derive another Theorem:

Theorem 6.2:Theorem 6.2: Let f be an m-ary partial function on A*, Let f be an m-ary partial function on A*, where A is an alphabet of n symbols. Then the where A is an alphabet of n symbols. Then the following conditions are all equivalent:following conditions are all equivalent:1. f is partially computable;1. f is partially computable;2. f is partially computable in 2. f is partially computable in LLnn;;

3. f is computed strictly by a Post-Turing program;3. f is computed strictly by a Post-Turing program;4. f is computed by a Post-Turing program.4. f is computed by a Post-Turing program.

The fact that there are so many equivalent notions of The fact that there are so many equivalent notions of computability constitutes important evidence for the computability constitutes important evidence for the correctness of Church’s Thesis.correctness of Church’s Thesis.

Page 16: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

16

Simulation of Simulation of TT in in LLFor the proof of Theorem 6.1, let us now consider an For the proof of Theorem 6.1, let us now consider an m-ary partial function on N.m-ary partial function on N.

Corollary 6.3: Corollary 6.3:

For any n, l 1, an m-ary partial function f on N is For any n, l 1, an m-ary partial function f on N is partially computable in partially computable in LLnn if and only if it is also if and only if it is also

partially computable in partially computable in LLll..

Proof:Proof:

Each of these conditions is equivalent to the function f Each of these conditions is equivalent to the function f being partially computable.being partially computable.

Page 17: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

17

Simulation of Simulation of TT in in LLConsidering the language Considering the language LL11, we have:, we have:

Corollary 6.4: Corollary 6.4:

Every partially computable function is computed strictly Every partially computable function is computed strictly by some Post-Turing program that uses only the by some Post-Turing program that uses only the symbols ssymbols s00 and s and s11..

Proof:Proof:

This follows immediately from the fact that we can This follows immediately from the fact that we can simulate simulate LLnn in in TT, as shown before., as shown before.

Page 18: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

18

Simulation of Simulation of TT in in LLNow let Now let PP be a Post-Turing program that computes f. be a Post-Turing program that computes f.

We want to construct a program We want to construct a program QQ in the language in the language LL that computes f.that computes f.

QQ will consist of three sections: will consist of three sections:BEGINNINGBEGINNINGMIDDLEMIDDLEENDEND

The MIDDLE section will simulate The MIDDLE section will simulate PP in a step-by-step in a step-by-step “interpretive” manner.“interpretive” manner.

The BEGINNING section will arrange the input to The BEGINNING section will arrange the input to QQ in in the appropriate format for MIDDLE.the appropriate format for MIDDLE.

The END section will extract the output.The END section will extract the output.

Page 19: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

19

Simulation of Simulation of TT in in LLLet f be an m-ary partial function on A*, where A = Let f be an m-ary partial function on A*, where A = {s{s11, …, s, …, snn}.}.

The Post-Turing program The Post-Turing program PP will also use the blank B will also use the blank B and perhaps other symbols sand perhaps other symbols sn+1n+1, …, s, …, srr (we are not (we are not

assuming that the computation is strict).assuming that the computation is strict).

We write the symbols that We write the symbols that PP uses in the following uses in the following order:order:

ss11, …, s, …, snn,, ssn+1n+1, …, s, …, srr, B., B.

The program The program QQ will simulate will simulate PP by using the numbers by using the numbers that strings on this alphabet represent in base r + 1 as that strings on this alphabet represent in base r + 1 as “codes” for the corresponding strings.“codes” for the corresponding strings.

Page 20: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

20

Simulation of Simulation of TT in in LLNote that we will write the blank as sNote that we will write the blank as s r+1r+1 instead of s instead of s00..

The current tape configuration will be kept track of by The current tape configuration will be kept track of by QQ using three numbers stored in the variables L, H, using three numbers stored in the variables L, H, and R.and R.

H will contain the numerical value of the symbol H will contain the numerical value of the symbol currently being scanned by the head.currently being scanned by the head.

L will contain a number that represents in base r + 1L will contain a number that represents in base r + 1a string of symbols w such that the tape contents to a string of symbols w such that the tape contents to the left of the head consists of infinitely many blanks the left of the head consists of infinitely many blanks followed by w.followed by w.

R will contain a number that represents in a similar R will contain a number that represents in a similar manner the string of symbols to the right of the string.manner the string of symbols to the right of the string.

Page 21: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

21

Simulation of Simulation of TT in in LL

Example:Example:

Consider the following tape configuration for r = 3 Consider the following tape configuration for r = 3 (so we will use base 4):(so we will use base 4):

… … B B B sB B B s11 s s33 s s22 B s B s11 s s22 B B B … B B B …

Obviously, H = 2.Obviously, H = 2.

L = 1·4 + 3 = 7L = 1·4 + 3 = 7

R = 4·4R = 4·422 + 1·4 + 2 = 70 (remember that B = s + 1·4 + 2 = 70 (remember that B = sr+1r+1))

Page 22: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

22

Simulation of Simulation of TT in in LL

We are now able to simulate all of the instruction types We are now able to simulate all of the instruction types of of TT by programs of by programs of LL..

As usual, we will specify how to simulate each type of As usual, we will specify how to simulate each type of instruction.instruction.

An instruction An instruction PRINT sPRINT sii is simulated in is simulated in LL by by

H iH i

An instruction An instruction IF sIF sii GOTO L GOTO L is simulated in is simulated in LL by by

IF H = i GOTO LIF H = i GOTO L

Page 23: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

23

Simulation of Simulation of TT in in LL

An instruction An instruction RIGHTRIGHT is simulated in is simulated in LL by by

L CONCATL CONCATr+1r+1(L, H)(L, H)

H LTENDH LTENDr+1r+1(R)(R)

R LTRUNCR LTRUNCr+1r+1(R)(R)

IF R 0 GOTO EIF R 0 GOTO E

R r + 1R r + 1 // if R = 0, then there is a blank// if R = 0, then there is a blank

// (s// (sr+1r+1) to the right of the head) to the right of the head

Page 24: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

24

Simulation of Simulation of TT in in LL

An instruction An instruction LEFTLEFT is simulated in is simulated in LL by by

R CONCATR CONCATr+1r+1(H, R)(H, R)

H RTENDH RTENDr+1r+1(L)(L)

L RTRUNCL RTRUNCr+1r+1(L)(L)

IF L 0 GOTO EIF L 0 GOTO E

L r + 1L r + 1 // if L = 0, then there is a blank// if L = 0, then there is a blank

// (s// (sr+1r+1) to the left of the head) to the left of the head

Page 25: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

25

Simulation of Simulation of TT in in LL

Now the Now the MIDDLEMIDDLE section of section of QQ can be generated by can be generated by replacing each instruction in replacing each instruction in PP by its simulation. by its simulation.

When we write When we write BEGINNINGBEGINNING and and ENDEND, we must , we must consider the following:consider the following:

f is an m-ary function on {sf is an m-ary function on {s11, …, s, …, snn}*.}*.

Thus the initial values of XThus the initial values of X11, …, X, …, Xmm for for QQ are numbers are numbers

that represent the input strings in base n.that represent the input strings in base n.

However, the computations in However, the computations in QQ assume a base r + 1 assume a base r + 1 representation of the input strings.representation of the input strings.

Page 26: December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.

December 1, 2009 Theory of Computation Lecture 21: Turing Machines II

26

Simulation of Simulation of TT in in LL

Fortunately, we have Theorem 1.1 of Chapter 5, which Fortunately, we have Theorem 1.1 of Chapter 5, which tells us that the functions UPCHANGEtells us that the functions UPCHANGEn,ln,l and and

DOWNCHANGEDOWNCHANGEn,ln,l are computable. are computable.

Now we can develop the Now we can develop the BEGINNINGBEGINNING section. section.

Its task is to calculate the initial values of L, H, and R, Its task is to calculate the initial values of L, H, and R, which represent the initial tape configurationwhich represent the initial tape configuration

B xB x11 B x B x22 B … B x B … B xmm,,

where the numbers xwhere the numbers x11, …, x, …, xmm are represented in are represented in

base n notation. base n notation.