Lect-19 Turing Machine 2
Lect-19 Turing Machine 2
A Turing Machine
Tape
...... ......
Read-Write head
Control Unit
Standard
Turing
Machine
(STM)
The Tape
Read-Write head
Read-Write head
1. Reads a symbol
2. Writes a symbol
3. Moves Left or Right
Formal Definitions
for
Turing Machines
Transition Function
q1 a → b, R q2
(q1, a) = (q2 , b, R)
Transition Function
q1 c → d, L q2
(q1, c) = (q2 , d , L)
Turing Machine:
Input Tape
alphabet alphabet
States
M = (Q, , , , q0 , , F )
Transition Accept
function states
Initial
blank
state
Configuration
c a b a
q1
Instantaneous description: ca q1 ba
Time 4 Time 5
x a y b x a y b
q2 q0
q2 q0
Time 6 Time 7
x x y b x x y b
q1 q1
A computation
q2 xayb x q0 ayb xx q1 yb xxy q1 b
q2 xayb x q0 ayb xx q1 yb xxy q1 b
Equivalent notation: q2 xayb xxy q1 b
Initial configuration: q0 w
Input string
a a b b
q0
The Accepted Language
L( M ) = {w : q0 w x1 q f x2 }
•Turing Recognizable
f (w)
w D f ( w) S
A function may have many parameters:
f ( x, y ) = x + y
Integer Domain
Decimal: 5
Binary: 101
Unary: 11111
A function f is computable if
there is a Turing Machine M such that:
q0 qf
initial state accept state
Initial Final
Configuration Configuration
x, y are integers
Turing Machine:
Start 1 1 1 0 1 1
q0
initial state
Start 1 1 1 0 1 1
q0 initial state
x+ y
Finish 1 1 1 1 0
q f final state
The 0 here helps when we use
the result for other operations
x+ y
Finish 1 1 1 1 0
q f final state
Execution Example: Time 0
x y
x = 11 (=2)
1 1 0 1 1
y = 11 (=2) q0
Final Result
x+ y
1 1 1 1 0
q4
Turing machine for function f ( x, y ) = x + y
Turing machine for function f ( x, y ) = x + y
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 → , L q2 1 → 0, L q3
→ , R
q4
Time 0 1 1 0 1 1
q0
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 → , L q 2
1 → 0, L q3
→ , R
q4
Time 1 1 1 0 1 1
q0
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 → , L q 2
1 → 0, L q3
→ , R
q4
Time 2 1 1 0 1 1
q0
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 → , L q 2
1 → 0, L q3
→ , R
q4
Time 3 1 1 1 1 1
q1
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 → , L q 2
1 → 0, L q3
→ , R
q4
Time 4 1 1 1 1 1
q1
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 → , L q 2
1 → 0, L q3
→ , R
q4
Time 5 1 1 1 1 1
q1
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 → , L q 2
1 → 0, L q3
→ , R
q4
Time 6 1 1 1 1 1
q2
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 → , L q 2
1 → 0, L q3
→ , R
q4
Time 7 1 1 1 1 0
q3
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 → , L q 2
1 → 0, L q3
→ , R
q4
Time 8 1 1 1 1 0
q3
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 → , L q 2
1 → 0, L q3
→ , R
q4
Time 9 1 1 1 1 0
q3
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 → , L q 2
1 → 0, L q3
→ , R
q4
Time 10 1 1 1 1 0
q3
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 → , L q 2
1 → 0, L q3
→ , R
q4
Time 11 1 1 1 1 0
q3
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 → , L q 2
1 → 0, L q3
→ , R
q4
Time 12 1 1 1 1 0
q4
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 → , L q 2
1 → 0, L q3
→ , R
HALT & accept q4
Another Example
Turing Machine:
Start 1 1 1
q0 initial state
2x
Finish 1 1 1 1 1
q f accept state
Turing Machine Pseudocode for f ( x) = 2 x
• Repeat:
• Find rightmost $, replace it with 1
q0 → , L q1 $ → 1, R q2
→ , R → 1, L
q3
Example
Start Finish
1 1 1 1 1 1
q0 q3
1 → $, R 1 → 1, L 1 → 1, R
q0 → , L q1 $ → 1, R q2
→ , R → 1, L
q3
Another Example
1 if x y
The function f ( x, y ) =
is computable 0 if x y
Input: x0 y
Output: 1 or 0
Turing Machine Pseudocode:
• Repeat
Turing
input output
Machine
Example: x + y if x y
f ( x, y ) =
0 if x y
x, y
Adder x+ y
x, y x y
Comparator
x y Eraser 0