You are on page 1of 41

Recursively Enumerable

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

if w L then M halts in a non-final state


or loops forever
3
Definition:
A language is recursive
if some Turing machine accepts it
and halts on any input string

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:

if w L then M halts in a final state

if w L then M halts in a non-final state

A. Senthil - Professor/CSE
5
Computing Functions
with
Turing Machines

A. Senthil - Professor/CSE 6
A function f (w) has:

Domain: D Result Region: S

f (w)
w D f ( w)  S

A. Senthil - Professor/CSE 7
A function may have many parameters:

Example: Addition function

f ( x, y )  x  y

A. Senthil - Professor/CSE 8
Integer Domain

Decimal: 5

Binary: 101

Unary: 11111

We prefer unary representation:

easier to manipulate with Turing machines


A. Senthil - Professor/CSE 9
Definition:

A function f is computable if
there is a Turing Machine M such that:

Initial configuration Final configuration


 w   f (w) 

q0 initial state q f final state

For all w D Domain


A. Senthil - Professor/CSE 10
In other words:

A function f is computable if
there is a Turing Machine M such that:


q0 w  q f f ( w)

Initial Final
Configuration Configuration

For all w D Domain


A. Senthil - Professor/CSE 11
Example

The function f ( x, y )  x  y is computable

x, y are integers

Turing Machine:

Input string: x0 y unary

Output string: xy 0 unary

A. Senthil - Professor/CSE 12
x y

Start  1 1  1 0 1  1 

q0
initial state

The 0 is the delimiter that


separates the two numbers

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

The function f ( x)  2 x is computable

x is integer

Turing Machine:

Input string: x unary

Output string: xx unary


A. Senthil - Professor/CSE 31
x

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

• Replace every 1 with $

• Repeat:
• Find rightmost $, replace it with 1

• Go to right end, insert 1

Until no more $ remain

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

Match a 1 from x with a 1 from y

Until all of x or y is matched

• If a 1 from x is not matched


erase tape, write 1 ( x  y)
else
erase tape, write 0
A. Senthil - Professor/CSE
( x  y) 38
Combining Turing Machines

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

You might also like