meljun cortes automata16

23
CSC 3130: Automata theory and formal languages Variants of Turing Machines Fall 2008 MELJUN P. CORTES, MELJUN P. CORTES, MBA,MPA,BSCS,ACS MBA,MPA,BSCS,ACS MELJUN CORTES MELJUN CORTES

Upload: meljun-cortes

Post on 15-Jul-2015

65 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: MELJUN CORTES automata16

CSC 3130: Automata theory and formal languages

Variants of Turing Machines

Fall 2008MELJUN P. CORTES, MELJUN P. CORTES, MBA,MPA,BSCS,ACSMBA,MPA,BSCS,ACS

MELJUN CORTESMELJUN CORTES

Page 2: MELJUN CORTES automata16

Recognizing versus decidingRecognizing versus deciding

Looping is an undesirable behavior so we Looping is an undesirable behavior so we saysay

Such TM are called Such TM are called decidersdeciders

The language recognized by a TM is the set ofall inputs that make it reach qacc

A TM decides language L if it recognizes L anddoes not loop on any input

accept reject loop

Page 3: MELJUN CORTES automata16

Turing MachinesTuring Machinesstate control

infinite tape0 1 0

input

Why is this a universal model of computation?

Page 4: MELJUN CORTES automata16

The Church-Turing ThesisThe Church-Turing Thesis

“On Computable Numbers, with an Application to the Entscheidungsproblem”

1936:

Section 9. The extent of the computable numbers

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.

Page 5: MELJUN CORTES automata16

Variant 1: The multitape Turing Variant 1: The multitape Turing MachineMachine

The transition may depend on the The transition may depend on the contents of contents of all the cellsall the cells

Different tape heads can be moved Different tape heads can be moved independentlyindependently

state controltape 1 …0 1 0

tape 2 …0 1

tape 3 …1 0 0

Page 6: MELJUN CORTES automata16

Variant I: The multitape Turing Variant I: The multitape Turing MachineMachine

Multitape Turing Machines recognize the same

languages as single-tape Turing Machines

M…0 1 0

…0 1

…1 0 0

Γ = {0, 1, ☐}

S …0 1 0 10 # # 0 #1 0

Γ’ = {0, 1, ☐, 0, 1, ☐, #}

#

Page 7: MELJUN CORTES automata16

Variant I: The multitape Turing Variant I: The multitape Turing MachineMachine

For every transition in For every transition in MM, do following in , do following in SS::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 firstMove head of S to beginning of tape

S …0 1 0 10 # # 0 #1 0

Γ’ = {0, 1, ☐, 0, 1, ☐, #}

#

Page 8: MELJUN CORTES automata16

Variant 2: The random access Variant 2: The random access machinemachine

It has It has registersregisters that can store arbitrary that can store arbitrary values, avalues, aprogram counterprogram counter, and a , and a random-access random-access memorymemory

load -7 R0 := -7write R3 M[R3] := R0 store R5 R5 := R0 add R5 R0 := R0 + R5

jpos 3 if R0 > 0 then PC := 3accept

instruction meaning012345

0PC

0R0

0R1

0R2

2M 1 2 2 00 1 2 3 4

programcounter

registers

memory…

Page 9: MELJUN CORTES automata16

Variant 2: The random access Variant 2: The random access machinemachine

load -7 R0 := -7write R2 M[R2] := R0 save R1 R1 := R0 add R1 R0 := R0 + R1

jzero 3 if R0 = 0 then PC := 3accept

instruction meaning012345

0PC

0R0

0R1

0R2

0M 0 0 0 00 1 2 3 4

-7

-7

-7

-14

12345

The instructions are indexed by the The instructions are indexed by the program counterprogram counter

Page 10: MELJUN CORTES automata16

Variant 2: The random access Variant 2: The random access machinemachine

Simulating a Turing Machine on a RAM:Simulating a Turing Machine on a RAM:

Random assess machines recognize the same languages as Turing Machines

PC

2R0

1M 2 1 0 0 …

M …2 11

headtape

Page 11: MELJUN CORTES automata16

save R1 handle for state q00

Simulating a TM on a RAMSimulating a TM on a RAM

M

q0

q1

qacc

1/2R

save R1 save head position read R1 read tape contents x add -1jzero 6 if x = 1 goto line 6

load 2 new value of cellwrite R1 write in memoryload R1 recall head positionadd 1 move head to rightjump 30 go to state q1

program0123

6789

10

…2 11 save R1 handle for state q1

…accept handle for state qacc

30

200

Page 12: MELJUN CORTES automata16

Simulating a RAM on a Turing Simulating a RAM on a Turing MachineMachine

The configuration of a RAM consists ofThe configuration of a RAM consists of Program counterProgram counter Contents of registersContents of registers Indices and contents of all nonempty memory Indices and contents of all nonempty memory

cellscells14PC

3R0

-7R1

5R2

2M 0 1 2 01 2 3 4

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

0

Page 13: MELJUN CORTES automata16

Simulating a RAM on a Turing Simulating a RAM on a Turing MachineMachine

The TM has a simulation tape and a The TM has a simulation tape and a scratch tapescratch tape

The simulation tape stores RAM The simulation tape stores RAM configurationconfiguration

The TM has a set of states corresponding The TM has a set of states corresponding to eachto eachprogram instruction of the RAMprogram instruction of the RAM

The TM tape is updates according to RAM The TM tape is updates according to RAM instruction instruction

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

Page 14: MELJUN CORTES automata16

Simulating a RAM on a Turing Simulating a RAM on a Turing MachineMachine

Example: Example: load R1load R1(14,3,-7,5,(0,2),(2,1),(3,2))

2. Write R1 to conf tape

c

1. Copy R1 to scratch tape -7s

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

-7

cs

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

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

.

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

.

.

Make more spaceas needed

(14,-7,-7,5,(0,2),(2,1),(3,2))c3. Erase scratch tape

Page 15: MELJUN CORTES automata16

Variant 3: Nondeterministic Variant 3: Nondeterministic Turing MachineTuring Machine

The transition function is The transition function is nondeterministicnondeterministic::

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

N

…0 1 0

δ: (Q – {qacc, qrej}) × Γ → subsets of (Q × Γ × {L, R})

Page 16: MELJUN CORTES automata16

Equivalence of NTM and TMEquivalence of NTM and TM

Let us look more deeply into NTMsLet us look more deeply into NTMs

Nondeterministic Turing Machines recognize the same languages as Turing Machines

q3

q51/2R

q61/1L1/1R

Nondeterministic choices can be numbered➀

The first m steps of the computationare then fully specified by a sequenceof m numbers

Page 17: MELJUN CORTES automata16

Simulating a nondeterministic Simulating a nondeterministic TMTM

N

…1 00

k = maximum number ofnondeterministic choices in any state

M …1 00

…1 00

…3 21

input tape

2

simulation tape

address tape

Address tape specifies nondeterministic choices of N

First, input is copied from input tape to simulation tapeThen, M simulates N using address tape data

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

Page 18: MELJUN CORTES automata16

How to use the address tapeHow to use the address tape

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

N

…1 00

M …1 00

…1 00

…3 21

input tape

2

simulation tape

address tape

To ensure this we try all possibilities for the address tape

Page 19: MELJUN CORTES automata16

Simulating a nondeterministic Simulating a nondeterministic TMTM

…1 00

…1 00

…3 21

input tape x

2

simulation tape z

address tape a

Initially: x = input of N a is emptyFor 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.

Description of M:

Page 20: MELJUN CORTES automata16

Correctness of simulationCorrectness of simulation

If If NN accepts accepts xx::

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.

Eventually, M will encounter the correct a

Description of M:

So M will accept

Provided that all previoussimulations halt!

Page 21: MELJUN CORTES automata16

Correctness of simulationCorrectness of simulation

Claim: Claim: Simulation step always halts (never Simulation step always halts (never loops)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.

Description of M:

Since a is finite, the simulation will eventuallyrun out of choices

Page 22: MELJUN CORTES automata16

Correctness of simulationCorrectness of simulation

If If NN does not accept does not accept xx, then for every , then for every aa::

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.

Description of M:Either N will loop, so simulation runs out of choices

Or N rejects, so simulation isabandoned anyway

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

Page 23: MELJUN CORTES automata16

Context-free languages are Context-free languages are recognizablerecognizable

CorollaryCorollary

In factIn fact

If L is context-free, then it is recognizable by a TM

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