MELJUN CORTES Automata Theory (Automata16)

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

description

MELJUN CORTES Automata Theory (Automata16)

Transcript of MELJUN CORTES Automata Theory (Automata16)

Page 1: MELJUN CORTES Automata Theory (Automata16)

CSC 3130: Automata theory and formal languages

Variants of Turing Machines

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

MELJUN CORTESMELJUN CORTES

Page 2: MELJUN CORTES Automata Theory (Automata16)

Recognizing versus decidingRecognizing versus deciding

Looping is an undesirable behavior so we sayLooping is an undesirable behavior so we say

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 Automata Theory (Automata16)

Turing MachinesTuring Machinesstate control

infinite tape

0 1 0

input

Why is this a universal model of computation?

Page 4: MELJUN CORTES Automata Theory (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 Automata Theory (Automata16)

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

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

Different tape heads can be moved independentlyDifferent tape heads can be moved independently

state controltape 1 …0 1 0

tape 2 …0 1

tape 3 …1 0 0

Page 6: MELJUN CORTES Automata Theory (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 Automata Theory (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 Automata Theory (Automata16)

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

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

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 Automata Theory (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 program counterThe instructions are indexed by the program counter

Page 10: MELJUN CORTES Automata Theory (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

head

tape

Page 11: MELJUN CORTES Automata Theory (Automata16)

save R1 handle for state q0

0

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 Automata Theory (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 cellsIndices and contents of all nonempty memory cells

14PC

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 Automata Theory (Automata16)

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

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

The simulation tape stores RAM configurationThe simulation tape stores RAM configuration

The TM has a set of states corresponding to eachThe TM has a set of states corresponding to 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 Automata Theory (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

c

s

(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 Automata Theory (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 strings that are those 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 Automata Theory (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 Automata Theory (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 Automata Theory (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 Automata Theory (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 Automata Theory (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 Automata Theory (Automata16)

Correctness of simulationCorrectness of simulation

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