Professional Documents
Culture Documents
and
Recursive Languages
A. Senthil - Professor/CSE
1
Definition:
A language is recursively enumerable
if some Turing machine accepts it
A. Senthil - Professor/CSE
2
Let L be a recursively enumerable language
and M the Turing Machine that accepts it
For string w:
if w L then M halts in a final state
In other words:
A language is recursive if there is
a membership algorithm for it
A. Senthil - Professor/CSE
4
Let L be a recursive language
and M the Turing Machine that accepts it
For string w:
A. Senthil - Professor/CSE
5
Computing Functions
with
Turing Machines
A. Senthil - Professor/CSE 6
A function f (w) has:
f (w)
w D f ( w) S
A. Senthil - Professor/CSE 7
A function may have many parameters:
f ( x, y ) x y
A. Senthil - Professor/CSE 8
Integer Domain
Decimal: 5
Binary: 101
Unary: 11111
A function f is computable if
there is a Turing Machine M such that:
A function f is computable if
there is a Turing Machine M such that:
q0 w q f f ( w)
Initial Final
Configuration Configuration
x, y are integers
Turing Machine:
A. Senthil - Professor/CSE 12
x y
Start 1 1 1 0 1 1
q0
initial state
A. Senthil - Professor/CSE 13
x y
Start 1 1 1 0 1 1
q0 initial state
x y
Finish 1 1 1 1 0
q f final state
A. Senthil - Professor/CSE 14
The 0 helps when we use
the result for other operations
x y
Finish 1 1 1 1 0
q f final state
A. Senthil - Professor/CSE 15
Turing machine for function f ( x, y ) x y
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q 1 0, L q3
2
, R
q4
A. Senthil - Professor/CSE 16
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
A. Senthil - Professor/CSE 17
Time 0 1 1 0 1 1
q0
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q 1 0, L q3
2
, R
q4
A. Senthil - Professor/CSE 18
Time 1 1 1 0 1 1
q0
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q 1 0, L q3
2
, R
q4
A. Senthil - Professor/CSE 19
Time 2 1 1 0 1 1
q0
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q 1 0, L q3
2
, R
q4
A. Senthil - Professor/CSE 20
Time 3 1 1 1 1 1
q1
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q 1 0, L q3
2
, R
q4
A. Senthil - Professor/CSE 21
Time 4 1 1 1 1 1
q1
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q 1 0, L q3
2
, R
q4
A. Senthil - Professor/CSE 22
Time 5 1 1 1 1 1
q1
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q 1 0, L q3
2
, R
q4
A. Senthil - Professor/CSE 23
Time 6 1 1 1 1 1
q2
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q 1 0, L q3
2
, R
q4
A. Senthil - Professor/CSE 24
Time 7 1 1 1 1 0
q3
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q 1 0, L q3
2
, R
q4
A. Senthil - Professor/CSE 25
Time 8 1 1 1 1 0
q3
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q 1 0, L q3
2
, R
q4
A. Senthil - Professor/CSE 26
Time 9 1 1 1 1 0
q3
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q 1 0, L q3
2
, R
q4
A. Senthil - Professor/CSE 27
Time 10 1 1 1 1 0
q3
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q 1 0, L q3
2
, R
q4
A. Senthil - Professor/CSE 28
Time 11 1 1 1 1 0
q3
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q 1 0, L q3
2
, R
q4
A. Senthil - Professor/CSE 29
Time 12 1 1 1 1 0
q4
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q 1 0, L q3
2
, R
HALT & accept q4
A. Senthil - Professor/CSE 30
Another Example
x is integer
Turing Machine:
Start 1 1 1
q0 initial state
2x
Finish 1 1 1 1 1
q f final state
A. Senthil - Professor/CSE 32
Turing Machine Pseudocode for f ( x) 2 x
• Repeat:
• Find rightmost $, replace it with 1
A. Senthil - Professor/CSE 33
Turing Machine for f ( x) 2 x
1 $, R 1 1, L 1 1, R
q0 , L q1 $ 1, R q2
, R 1, L
q3
A. Senthil - Professor/CSE 34
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
A. Senthil - Professor/CSE 35
Another Example
1 if x y
The function f ( x, y )
0 if x y
is computable
A. Senthil - Professor/CSE 36
Turing Machine for
1 if x y
f ( x, y )
0 if x y
Input: x0 y
Output: 1 or 0
A. Senthil - Professor/CSE 37
Turing Machine Pseudocode:
• Repeat
A. Senthil - Professor/CSE 39
Block Diagram
Turing
input output
Machine
A. Senthil - Professor/CSE 40
Example: x y if x y
f ( x, y )
0 if x y
x, y
Adder x y
x, y x y
Comparer
x y Eraser 0
A. Senthil - Professor/CSE 41