You are on page 1of 23

Fall 2008 MELJUN P.

CORTES, MBA,MPA,BSCS,ACS
CSC 3130: Automata theory and formal languages

Variants of Turing Machines

Recognizing versus deciding
The language recognized by a TM is the set of all inputs that make it reach qacc
accept reject loop

Looping is an undesirable behavior so we say
A TM decides language L if it recognizes L and does not loop on any input Such TM are called deciders

Turing Machines
state control

input 0 1 0
infinite tape

Why is this a universal model of computation?

The Church-Turing Thesis
All arguments [for the CT Thesis] which can be given are bound to be, fundamentally, appeals to intuition, and for this reason rather unsatisfactory mathematically. The arguments which I shall use are of three kinds: 1. A direct appeal to intuition 2. A proof of the equivalence of two definitions (In case the new definition has greater intuitive appeal) 3. Giving examples of large classes of numbers which are computable.

1936: “On Computable Numbers, with an Application to the Entscheidungsproblem” Section 9. The extent of the computable numbers

Variant 1: The multitape Turing Machine
state control
tape 1 0 tape 2 0 1 1 0 … …

tape 3 1

0

0

The transition may depend on the contents of all the cells Different tape heads can be moved independently

Variant I: The multitape Turing Machine
Multitape Turing Machines recognize the same languages as single-tape Turing Machines
0 1 1 0 … …

G = {0, 1, ☐}

M

0

1

0

0

S

# 0

1

0 # 0

1

# 1

0

0 #
 

G = {0, 1, ☐, 0, 1, ☐, #}

Variant I: The multitape Turing Machine
For every transition in M, do following in S: Until you find the last #,
Find the next dotted symbol Update this symbol according to transition in M Move the dot according to transition in M If there is no space to move the dot, Move everything to the right of the dot to make space first Move head of S to beginning of tape

S

# 0

1

0 # 0

1

# 1

0

0 #
  

G = {0, 1, ☐, 0, 1, ☐, #}

PC 0 R0

Variant 2: The random access machine meaning instruction program
counter registers

0

R1
R2

0
0

0 1 2 3 4 5

load -7 write R3 store R5 add R5 jpos 3 accept

R0 := -7 M[R3] := R0 R5 := R0 R0 := R0 + R5 if R0 > 0 then PC := 3

M

2 0

1 1

2 2

2 3

0 4

memory

It has registers that can store arbitrary values, a program counter, and a random-access memory

PC 01 23 45 R0

Variant 2: The random access machine meaning instruction
0-7 -14 0-7 0 0 1 2 3 4 5 load -7 write R2 save R1 add R1 jzero 3 accept R0 := -7 M[R2] := R0 R1 := R0 R0 := R0 + R1 if R0 = 0 then PC := 3

R1
R2

M

0-7 0

0 1

0 2

0 3

0 4

The instructions are indexed by the program counter

Variant 2: The random access machine
Random assess machines recognize the same languages as Turing Machines

Simulating a Turing Machine on a RAM:
M
PC R0 M 2 1 2 1 0 0
1 2 1 …

Simulating a TM on a RAM
program
0 1 2 3 6 7 8 9 10

q1 q0 qacc

M

save R1 read R1 x add -1 … jzero 6

save head position handle for state q0 read tape contents

if x = 1 goto line 6

1

2

1

load 2 new value of cell write R1 write in memory load R1 recall head position add 1 move head to right … jump 30 go to state q1 handle for state q1 30 save R1

200 accept

handle for state qacc

Simulating a RAM on a Turing Machine
The configuration of a RAM consists of

  PC

R0 R1 R2 M

Program counter Contents of registers Indices and contents of all nonempty memory 14 cells configuration =
3

(14, 3, -7, 5, (0, 2), (2, 1), (3, 2))

-7 5 2 0 0 1 1 2 2 3 0 4

Simulating a RAM on a Turing Machine
The TM has a simulation tape and a scratch tape (14,3,-7,5,(0,2),(2,1),(3,2)) The simulation tape stores RAM M configuration

The TM has a set of states corresponding to each

Simulating a RAM on a Turing Machine (14,3,-7,5,(0,2),(2,1),(3,2))
Example: load R1
c
1. Copy R1 to scratch tape s -7 2. Write R1 to conf tape

c s c c

(14,-,-7,5,(0,2),(2,1),(3,2)) -7

Make more space as needed

. (14,-,-7,5,(0,2),(2,1),(3,2))
. (14,-,-7,5,(0,2),(2,1),(3,2) ) . (14,- ,-7,5,(0,2),(2,1),(3,2)) (14,-7,-7,5,(0,2),(2,1),(3,2))

c
3. Erase scratch tape

c

Variant 3: Nondeterministic Turing Machine N
0 1 0

The transition function is nondeterministic:
d: (Q – {qacc, qrej})  G → subsets of (Q  G  {L, R})

The language recognized by N are those strings that can lead N to end in qacc

Equivalence of NTM and TM
Nondeterministic Turing Machines recognize the same languages as Turing Machines

Let us look more deeply into NTMs

q3
➁ ➂

q5 q6

Nondeterministic choices can be numbered

The first m steps of the computation are then fully specified by a sequence of m numbers

Simulating a nondeterministic TM input tape
N
… 1 3

M

0 0

1

0

simulation tape … 1 0 address tape … 2 2

0

1

0

k = maximum number of
nondeterministic choices in any state

G’ = G ∪ {1,..., k}

Address tape specifies nondeterministic choices of N First, input is copied from input tape to simulation tape Then, M simulates N using address tape data

How to use the address tape
N
… 1 3

M

0 0

1

0

input tape …

simulation tape … 1 0 address tape … 2 2

0

1

0

Suppose N accepts x when nondeterminism = 11221321 Then we want to make sure the address tape contains the string 11221321 at some point in its execution To ensure this we try all possibilities for the address tape

Simulating a nondeterministic TM input tape x Description of M:
0 1 0 … simulation tape z Initially: … 0 1 0 x = input of N address tape a a is empty … 1 3 2 2 For all possible strings a: Copy x to z. Simulate N on input z using a as the nondeterminism If a specifies an invalid choice or simulation runs out of choices, abandon simulation. If N enters its accept state, accept and halt. If N enters its reject state, abandon simulation.

Correctness of simulation
Eventually, M will Description of M: encounter For all possible strings a: the correct a Copy x to z. Simulate N on input z using a as the nondeterminism If a specifies an invalid choice or So M will simulation runs out of choices, abandon simulation. accept If N enters its accept state, accept and halt. If N enters its reject state, abandon simulation.

If N accepts x:

Provided that all previous simulations halt!

Correctness of simulation
Claim: Simulation step always halts (never Description of M: loops)

For all possible strings a: Copy x to z. Simulate N on input z using a as the nondeterminism If a specifies an invalid choice or simulation runs out of choices, abandon simulation. If N enters its accept state, accept and halt. If N enters its reject state, abandon simulation. Since a is finite, the simulation will eventually run out of choices

Correctness of simulation
Description of M:

If N does not accept x, then for every a:

Either N will loop, so For all possible strings a: simulation Copy x to z. runs out as the nondeterminism Simulate N on input z using a of choices Or N rejects, If a specifies an invalid choice orso simulation is abandoned anyway simulation runs out of choices, abandon simulation. If N enters its accept state, accept and halt. If N enters its reject state, abandon simulation.

In either case, simulation fails, so M loops forever!

Context-free languages are recognizable
Corollary
If L is context-free, then it is recognizable by a TM

In fact
If L is context-free, then it is decided by some TM