CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Variants of Turing Machines Fall 2008
Recognizing versus deciding Looping is an undesirable behavior so we say –Such TM are called deciders The language recognized by a TM is the set of all inputs that make it reach q acc A TM decides language L if it recognizes L and does not loop on any input acceptrejectloop
Turing Machines state control … infinite tape 010 input Why is this a universal model of computation?
The 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.
Variant 1: The multitape Turing Machine The transition may depend on the contents of all the cells Different tape heads can be moved independently state control tape 1 … 010 tape 2 … 01 tape 3 … 100
Variant I: The multitape Turing Machine Multitape Turing Machines recognize the same languages as single-tape Turing Machines M … 010 … 01 … 100 = {0, 1, ☐ } S … 01010##0#10 ’ = {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 … 01010##0#10 ’ = {0, 1, ☐, 0, 1, ☐, #} #
Variant 2: The random access machine It has registers that can store arbitrary values, a program counter, and a random-access memory load -7 R 0 := -7 write R3 M[R 3 ] := R 0 store R5 R 5 := R 0 add R5 R 0 := R 0 + R 5 jpos 3 if R 0 > 0 then PC := 3 accept instructionmeaning PC 0 R0R0 0 R1R1 0 R2R2 2 M program counter registers memory …
Variant 2: The random access machine load -7 R 0 := -7 write R2 M[R 2 ] := R 0 save R1 R 1 := R 0 add R1 R 0 := R 0 + R 1 jzero 3 if R 0 = 0 then PC := 3 accept instructionmeaning PC 0 R0R0 0 R1R1 0 R2R2 0 M … The instructions are indexed by the program counter
Variant 2: The random access machine Simulating a Turing Machine on a RAM: Random assess machines recognize the same languages as Turing Machines PC 2 R0R0 1 M 2100 … M … 211 head tape
save R1 handle for state q 0 0 Simulating a TM on a RAM M q0q0 q1q1 q acc 1/2R … 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 q 1 program … 211 save R1 handle for state q 1 … … … accept handle for state q acc
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 14 PC 3 R0R0 -7 R1R1 5 R2R2 2 M … configuration = (14, 3, -7, 5, (0, 2), (2, 1), (3, 2)) 0
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 (14,3,-7,5,(0,2),(2,1),(3,2)) M
Simulating a RAM on a Turing Machine Example: load R1 (14,3,-7,5,(0,2),(2,1),(3,2)) 2. Write R 1 to conf tape c 1. Copy R 1 to scratch tape -7 s (14,-,-7,5,(0,2),(2,1),(3,2)) -7 c s (14,-,-7,5,(0,2),(2,1),(3,2)) c c. c.. Make more space as needed (14,-7,-7,5,(0,2),(2,1),(3,2)) c 3. Erase scratch tape
Variant 3: Nondeterministic Turing Machine The transition function is nondeterministic: The language recognized by N are those strings that can lead N to end in q acc N … 010 : (Q – {q acc, q rej }) → subsets of (Q {L, R})
Equivalence of NTM and TM Let us look more deeply into NTMs Nondeterministic Turing Machines recognize the same languages as Turing Machines q3q3 q5q5 1/2R q6q6 1/1L 1/1R 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 N … 100 k = maximum number of nondeterministic choices in any state M … 100 … 100 … 321 input tape 2 simulation tape address tape 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 ’ = ∪ {1,..., k}
How to use the address tape Suppose N accepts x when nondeterminism = Then we want to make sure the address tape contains the string at some point in its execution N … 100 M … 100 … 100 … 321 input tape 2 simulation tape address tape To ensure this we try all possibilities for the address tape
Simulating a nondeterministic TM … 100 … 100 … 321 input tape x 2 simulation tape z address tape a 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, abandon simulation. If N enters its accept state, accept and halt. If N enters its reject state, abandon simulation. Description of M:
Correctness of simulation If N accepts x : 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 previous simulations halt!
Correctness of simulation Claim: 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 eventually run out of choices
Correctness of simulation If N does not accept x, then for every a : 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 is abandoned anyway In either case, simulation fails, so M loops forever!
Context-free languages are recognizable Corollary In 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