1 / 23

CSC 3130: Automata theory and formal languages

Fall 2009. The Chinese University of Hong Kong. CSC 3130: Automata theory and formal languages. More variants of Turing Machines. Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130. What does a computer look like?. CPU. instruction memory. PC. 0000. arithmetic logical unit.

Download Presentation

CSC 3130: Automata theory and formal languages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Fall 2009 The Chinese University of Hong Kong CSC 3130: Automata theory and formal languages More variants of Turing Machines Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130

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

  3. What does a computer look like? CPU instruction memory 0000 load 0001 0001 write R3 0010 store R5 0011 add R5 0100 jpos 0011 ... PC 0000 arithmeticlogical unit R0 0100 R1 data memory 1010 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 • It has registers that can store arbitrary values, aprogram counter, and a random-access memory programcounter PC 0 0 1 2 3 4 5 load -7R0 := -7 write R2M[R2] := R0 store R1R1 := R0 add R1R0 := R0 + R5 jzero 3 if R0 = 0then PC := 3 accept registers R0 0 R1 0 R2 0 … M 2 1 2 2 0 memory 1 2 3 4 0

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

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

  8. Simulating a TM on a RAM program 0 save R1handle for state q0 0 1 2 3 6 7 8 9 10 save R1save head positionread R1read tape contents x add -1 jzero 6if 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 … … 30 save R1handle for state q1 1 2 1 … 200 accepthandle 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 0 1 2 0 0 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 eachprogram 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)) s 1. Copy R1 to scratch tape -7 c (14,-,-7,5,(0,2),(2,1),(3,2)) 2. Write R1 to conf tape s -7 . c Make more spaceas needed (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 (14,-7,-7,5,(0,2),(2,1),(3,2)) 3. Erase scratch tape

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

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

  14. Simulating a nondeterministic TM input tape N M … 0 1 0 simulation tape … 0 1 0 … address tape 0 1 0 … 1 3 2 2 k = maximum number ofnondeterministic 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 … 0 1 0 simulation tape … 0 1 0 … address tape 0 1 0 … 1 3 2 2 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

  16. Simulating a nondeterministic TM input tape x Description of M: … 0 1 0 Initially: x = input of Na 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 … 0 1 0 address tape a … 1 3 2 2

  17. Simulating a nondeterministic TM Try all possible choices of the address tape: address tape abortsimulation runs out of choices at q0 … abortsimulation runs out of choices at q1 … 1 abortimpossible choice at q0 … 2 M q1 1/1R abortout of choices at q0 … q0 1 1 0/0R 0/1R 1 1 qacc accept … 1 2 2 input: 10

  18. Simulating a nondeterministic TM Try all possible choices of the address tape: address tape abortsimulation runs out of choices at q0 … abortsimulation runs out of choices at q1 … 1 abortimpossible choice at q0 0/0L M … 2 q1 1/1R abortout of choices at q0 … 1 1 q0 2/0R 0/0L 1 1 1 abortout of choices at q1 qacc … 1 2 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 previoussimulations 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 orsimulation 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 eventuallyrun 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 Non 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 isabandoned 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

More Related