Presentation is loading. Please wait.

Presentation is loading. Please wait.

More variants of Turing Machines

Similar presentations


Presentation on theme: "More variants of Turing Machines"— Presentation transcript:

1 More variants of Turing Machines
The Chinese University of Hong Kong Fall 2009 CSC 3130: Automata theory and formal languages More variants of Turing Machines Andrej Bogdanov

2 What does a computer look like?
CPU instruction memory 0000 PC arithmetic logical unit data memory 1010 0100 0000 registers R0 R1 R2 R3 peripheral devices

3 What does a computer look like?
CPU instruction memory PC 0000 load 0001 0001 write R3 0010 store R5 0011 add R5 0100 jpos 0011 ... 0000 arithmetic logical unit R0 0100 R1 1010 data memory registers R2 0000 0000 0001 0010 0011 0100 R3 0000 0110 0110 0110 0110 0110

4 Instruction set load x Put the value x into R0 load Rk
Copy the value of Rk into R0 store Rk Copy the value of R0 into Rk read Rk Copy the value at memory location Rk into R0 write Rk Copy the value of R0 into memory location Rk add Rk Add R0 and Rk, and put result in R0 jump n Set PC to n jzero n Set PC to n, if R0 is zero jpos n Set PC to n, if R0 is positive

5 Random access machines
instruction meaning program counter PC 1 2 3 4 5 load -7 R0 := -7 write R2 M[R2] := R0 store R1 R1 := R0 add R1 R0 := R0 + R5 jzero 3 if R0 = 0 then PC := 3 accept registers R0 R1 R2 M 2 1 2 2 memory 1 2 3 4 It has registers that can store arbitrary values, a program counter, and a random-access memory

6 Random access machines
instruction meaning PC 1 2 3 1 2 3 4 5 load -7 R0 := -7 write R2 M[R2] := R0 save R1 R1 := R0 add R1 R0 := R0 + R1 jzero 3 if R0 = 0 then PC := 3 accept 4 5 R0 -7 -14 R1 -7 R2 M -7 1 2 3 4 The instructions are indexed by the program counter

7 Random access machines
Random access machines are equivalent to Turing Machines Simulating a Turing Machine on a RAM: M 1 2 1 PC head tape R0 2 M 1 2 1

8 Simulating a TM on a RAM … program M … … … save R1 handle for state q0
1 2 3 6 7 8 9 10 save R1 save head position read R1 read tape contents x add -1 jzero 6 if x = 1 goto line 6 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 M q1 1/2R q0 qacc 1 2 1 30 save R1 handle for state q1 200 accept handle for state qacc

9 Simulating a RAM on a Turing Machine
The configuration of a RAM consists of Program counter Contents of registers Indices and contents of all nonempty memory cells PC 14 configuration = (14, 3, -7, 5, (0, 2), (2, 1), (3, 2)) R0 3 R1 -7 R2 5 M 2 1 2 1 2 3 4

10 Simulating a RAM on a Turing Machine
The TM has a simulation tape and a scratch tape The simulation tape stores RAM configuration The TM has a set of states corresponding to each program instruction of the RAM The TM tape is updates according to RAM instruction M (14,3,-7,5,(0,2),(2,1),(3,2))

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

12 Nondeterministic Turing Machine
1 The transition function is nondeterministic: The language recognized by N are those strings that can lead N to end in qacc d: (Q – {qacc, qrej})   → subsets of (Q  G  {L, R})

13 Equivalence of NTM and TM
Nondeterministic Turing Machines recognize the same languages as Turing Machines Let us look more deeply into NTMs Nondeterministic choices can be numbered 1/2R 1 q5 q3 The first m steps of the computation are then fully specified by a sequence of m numbers q6 1/1L 2 1/1R 3

14 Simulating a nondeterministic TM
input tape N M 1 simulation tape 1 1 address tape 1 3 2 2 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

15 How to use the address tape
input tape N M 1 simulation tape 1 1 address tape 1 3 2 2 Suppose N accepts x when nondeterminism = Then we want to make sure the address tape contains the string at some point in its execution To ensure this we try all possibilities for the address tape

16 Simulating a nondeterministic TM
input tape x Description of M: 1 Initially: x = input of N a is empty 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, abort simulation. If N enters its accept state, accept and halt. If N enters its reject state, abort simulation. simulation tape z 1 address tape a 1 3 2 2

17 Simulating a nondeterministic TM
Try all possible choices of the address tape: address tape abort simulation runs out of choices at q0 abort simulation runs out of choices at q1 1 abort impossible choice at q0 2 M 1/1R q1 abort out of choices at q0 1 1 1 1 q0 2 0/1R 0/0R qacc accept 1 2 input: 10

18 Simulating a nondeterministic TM
Try all possible choices of the address tape: address tape abort simulation runs out of choices at q0 abort simulation runs out of choices at q1 1 abort impossible choice at q0 0/0L M 2 2 1/1R q1 abort out of choices at q0 1 1 1 1 q0 1 2/0R 0/0L abort out of choices at q1 qacc 1 2 input: 10 Simulation will loop forever

19 Correctness of simulation
If N accepts x: Eventually, M will encounter the correct a Description of M: 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, abort simulation. If N enters its accept state, accept and halt. If N enters its reject state, abort simulation. So M will accept Provided that all previous simulations halt!

20 Correctness of simulation
Claim: Simulation step always halts (never loops) Description of M: 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, abort simulation. If N enters its accept state, accept and halt. If N enters its reject state, abort simulation. Since a is finite, the simulation will eventually run out of choices

21 Correctness of simulation
If N does not accept x, then for every a: Description of M: Either N will loop, so simulation runs out of choices 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, abort simulation. Or N rejects, so simulation is abandoned anyway In either case, simulation fails, so M loops forever!

22 Context-free languages are recognizable
Since Nondeterministic Turing Machines are more general than Pushdown Automata, it follows that In fact Context-free languages are recognizable (by TMs) Context-free languages are decidable (by TMs)

23 Recap of computational models
NTM NFA DFA PDA TM toy computers RAM


Download ppt "More variants of Turing Machines"

Similar presentations


Ads by Google