Recursively Enumerable
and
Recursive Languages
Fall 2005 Costas Busch - RPI 1
Definition:
A language is recursively enumerable
if there is a Turing machine that accepts it
Also known as: Turing Recognizable languages
orTuring Acceptable languages
Fall 2005 Costas Busch - RPI 2
Let L be a recursively enumerable language
and M the Turing Machine that accepts it
For any string w :
if w L then M halts in an accept state
if w L then M halts in a non-accept state
or loops forever
Fall 2005 Costas Busch - RPI 3
Definition:
A language is recursive
if there is a Turing machine accepts it
and the machine halts on every input string
Also known as decidable languages
Fall 2005 Costas Busch - RPI 4
Let L be a recursive language
Then there is a Turing machine M
that accepts L such that:
For any string w:
if w L then M halts in an accept state
if w L then M halts in a non-accept state
Fall 2005 Costas Busch - RPI 5
We will prove:
1. There is a specific language L
which is not recursively enumerable
(not accepted by any Turing Machine)
2. There is a specific language L
which is recursively enumerable
but not recursive
Fall 2005 Costas Busch - RPI 6
Non Recursively Enumerable
L
Recursively Enumerable
L
Recursive
Fall 2005 Costas Busch - RPI 7
A Language which
is not
Recursively Enumerable
Fall 2005 Costas Busch - RPI 8
Consider alphabet {a}
Strings: a, aa, aaa, aaaa,
1 2 3 4
a a a a
Fall 2005 Costas Busch - RPI 9
Consider Turing Machines
that accept languages over alphabet {a}
They are countable:
M1, M 2 , M 3 , M 4 ,
(There is an enumeration procedure that
generates them)
Fall 2005 Costas Busch - RPI 10
Each machine accepts some language over {a}
M1, M 2 , M 3 , M 4 ,
L( M1), L( M 2 ), L( M 3 ), L( M 4 ),
Note that it is possible to have
L( M i ) L( M j ) for i j
Since, a language could be accepted by more than one
Turing machine
Fall 2005 Costas Busch - RPI 11
Example language accepted by M i
L( M i ) {aa, aaaa, aaaaaa}
2 4 6
L( M i ) {a , a , a }
Binary representation
1 2 3 4 5 6 7
a a a a a a a
L( M i ) 0 1 0 1 0 1 0
Fall 2005 Costas Busch - RPI 12
Example of binary representations
1 2 3 4
a a a a
L ( M1 ) 0 1 0 1
L( M 2 ) 1 0 0 1
L( M 3 ) 0 1 1 1
L( M 4 ) 0 0 0 1
Fall 2005 Costas Busch - RPI 13
Consider the language
i i
L {a : a L( M i )}
L consists of the 1’s in the diagonal
Fall 2005 Costas Busch - RPI 14
1 2 3 4
a a a a
L ( M1 ) 0 1 0 1
L( M 2 ) 1 0 0 1
L( M 3 ) 0 1 1 1
L( M 4 ) 0 0 0 1
3 4
L {a , a ,}
Fall 2005 Costas Busch - RPI 15
Consider the language L
i i
L {a : a L( M i )}
i i
L {a : a L( M i )}
L consists of the 0’s in the diagonal
Fall 2005 Costas Busch - RPI 16
1 2 3 4
a a a a
L ( M1 ) 0 1 0 1
L( M 2 ) 1 0 0 1
L( M 3 ) 0 1 1 1
L( M 4 ) 0 0 0 1
1 2
L {a , a ,}
Fall 2005 Costas Busch - RPI 17
Theorem:
Language L is not recursively enumerable
Proof:
Assume for contradiction that
L is recursively enumerable
There must exist some machine Mk
that accepts L : L( M k ) L
Fall 2005 Costas Busch - RPI 18
1 2 3 4
a a a a
L ( M1 ) 0 1 0 1
L( M 2 ) 1 0 0 1
L( M 3 ) 0 1 1 1
L( M 4 ) 0 0 0 1
Question: M k M1 ? L( M k ) L
Fall 2005 Costas Busch - RPI 19
1 2 3 4
a a a a
L ( M1 ) 0 1 0 1
L( M 2 ) 1 0 0 1
L( M 3 ) 0 1 1 1
L( M 4 ) 0 0 0 1
1
a L( M k )
Answer: M k M1
1
Fall 2005 Costas Busch - RPI
a L ( M1 ) 20
1 2 3 4
a a a a
L ( M1 ) 0 1 0 1
L( M 2 ) 1 0 0 1
L( M 3 ) 0 1 1 1
L( M 4 ) 0 0 0 1
Question: M k M 2 ? L( M k ) L
Fall 2005 Costas Busch - RPI 21
1 2 3 4
a a a a
L ( M1 ) 0 1 0 1
L( M 2 ) 1 0 0 1
L( M 3 ) 0 1 1 1
L( M 4 ) 0 0 0 1
2
a L( M k )
Answer: Mk M2
2
Fall 2005 Costas Busch - RPI
a L( M 2 ) 22
1 2 3 4
a a a a
L ( M1 ) 0 1 0 1
L( M 2 ) 1 0 0 1
L( M 3 ) 0 1 1 1
L( M 4 ) 0 0 0 1
Question: M k M 3 ? L( M k ) L
Fall 2005 Costas Busch - RPI 23
1 2 3 4
a a a a
L ( M1 ) 0 1 0 1
L( M 2 ) 1 0 0 1
L( M 3 ) 0 1 1 1
L( M 4 ) 0 0 0 1
3
a L( M k )
Answer: M k M3
3
Fall 2005 Costas Busch - RPI
a L( M 3 ) 24
Similarly: Mk Mi for any i
Because either:
i i
a L( M k ) a L( M k )
or
i i
a L( M i ) a L( M i )
the machine M k cannot exist
L is not recursively enumerable
End of Proof
Fall 2005 Costas Busch - RPI 25
Non Recursively Enumerable
L
Recursively Enumerable
Recursive
Fall 2005 Costas Busch - RPI 26
A Language which is
Recursively Enumerable
and not Recursive
Fall 2005 Costas Busch - RPI 27
We will prove that the language
i i
L {a : a L( M i )}
Is recursively But not
enumerable recursive
There is a Every machine
Turing Machine that accepts L
that accepts L doesn’t halt
on some input string
Fall 2005 Costas Busch - RPI 28
1 2 3 4
a a a a
L ( M1 ) 0 1 0 1
L( M 2 ) 1 0 0 1
L( M 3 ) 0 1 1 1
L( M 4 ) 0 0 0 1
3 4
L {a , a ,}
Fall 2005 Costas Busch - RPI 29
Theorem: The language
i i
L {a : a L( M i )}
is recursively enumerable
Proof: We will give a Turing Machine that
accepts L
Fall 2005 Costas Busch - RPI 30
Turing Machine that accepts L
For any input string w
i
• Compute i , for which wa
• Find Turing machine M i
(using the enumeration procedure
for Turing Machines)
i
• Simulate M i on input a
• If M i accepts, then accept w
End of Proof
Fall 2005 Costas Busch - RPI 31
Observation:
Recursively enumerable
i i
L {a : a L( M i )}
Not recursively enumerable
i i
L {a : a L( M i )}
(Thus, L is not recursive either)
Fall 2005 Costas Busch - RPI 32
Theorem:
If a language X is recursive,
then its complement X is recursive too
Proof:
Build a Turing machine M that
accepts X and halts on every input
Fall 2005 Costas Busch - RPI 33
(accepts X and halts on every input string)
Turing Machine M
On any input string w do:
1. Let M be the Turing machine that accepts X
and halts on every input string
2. Run M with input string w
If M accepts then reject
If M rejects then accept
Fall 2005 Costas Busch - RPI 34
M M
qi qi x x, R
For all tape symbols x
not read in the other
transitions of qi
qj qj
Transform M to M
END OF PROOF
Fall 2005 Costas Busch - RPI 35
i i
Theorem: L {a : a L( M i )}
is not a recursive language
Proof: If L is recursive
The complement
of a recursive language
is recursive
Then L is recursive
However, L is not Turing acceptable!
Contradiction!!!!
Fall 2005 Costas Busch - RPI 36
Non Recursively Enumerable
L
Recursively Enumerable
L
Recursive
Fall 2005 Costas Busch - RPI 37
Turing acceptable languages
and
Enumeration Procedures
Fall 2005 Costas Busch - RPI 38
We will prove:
(weak result)
• If a language is recursive then
there is an enumeration procedure for it
(strong result)
• A language is recursively enumerable
if and only if
there is an enumeration procedure for it
Fall 2005 Costas Busch - RPI 39
Theorem:
if a language L is recursive then
there is an enumeration procedure for it
Proof:
Let M be the Turing machine that accepts L
and halts on every input
Use M to build the enumeration procedure
for L
Fall 2005 Costas Busch - RPI 40
~
Let M be an enumerator that prints
all strings from input alphabet in proper order
a
b
aa
Example:
ab
alphabet is {a, b} ba (proper order)
bb
aaa
aab
......
Fall 2005 Costas Busch - RPI 41
Enumeration procedure for L
Repeat:
~ generates a string w
M
M checks if w L
YES: print w to output
NO: ignore w
This part terminates,
because L is recursive
Fall 2005 Costas Busch - RPI 42
Enumeration Machine for L
~ M
M Give me
Enumerates all next string
If M accepts wi output
strings of
then print wi to
input alphabet string wi All strings
output
of L
Generates all Tests each string
Strings in alphabet if it is accepted by M
Fall 2005 Costas Busch - RPI 43
Example: L {b, ab, bb, aaa,....}
~ Enumeration
M M Output
w1 a reject
w2 b accept b
w3 aa reject
ab accept ab
ba reject
bb accept bb
aaa accept aaa
aab reject
Fall 2005 Costas Busch - RPI END OF PROOF 44
Theorem:
if language L is recursively enumerable then
there is an enumeration procedure for it
Proof:
Let M be the Turing machine that accepts L
Use M to build the enumeration procedure
for L
Fall 2005 Costas Busch - RPI 45
Enumeration Machine for L
~ M
M
Enumerates all
Accepts L
strings of input alphabet
in proper order
Fall 2005 Costas Busch - RPI 46
NAIVE APPROACH
Enumeration procedure for L
Repeat:
~ generates a string w
M
M checks if w L
YES: printw to output
NO: ignore w
Problem: If w L
machine M may loop forever
Fall 2005 Costas Busch - RPI 47
BETTER APPROACH
~ Generates first string w
M 1
M executes first step on w1
~ Generates second string w
M 2
M executes first step on w2
second step on w1
Fall 2005 Costas Busch - RPI 48
~ Generates third string w
M 3
M executes first step on w3
second step on w2
third step on w1
And so on............
Fall 2005 Costas Busch - RPI 49
String: w1 w2 w3 w4
1 1 1 1
Step in
2 2 2 2
computation
of string
3 3 3 3
4 4 4 4
Fall 2005 Costas Busch - RPI 50
If for any string wi
machine M halts in an accepting state
then it prints wi on the output
End of Proof
Fall 2005 Costas Busch - RPI 51
Theorem:
If for language L
there is an enumeration procedure
then L is recursively enumerable
Proof:
Using the enumerator for L
we will build a Turing machine
that accepts L
Fall 2005 Costas Busch - RPI 52
Input Tape
w
Turing Machine that accepts L
w
Enumerator wi Compare
for L Give me the
If same,
next string Accept and Halt
in the
enumeration
sequence
Fall 2005 Costas Busch - RPI 53
Turing machine that accepts L
For any input string w
Loop:
• Using the enumerator of L ,
generate the next string of L
• Compare generated string with w
If same, accept and exit loop
End of Proof
Fall 2005 Costas Busch - RPI 54
By Combining the last two theorems,
we have proven:
A language is recursively enumerable
if and only if
there is an enumeration procedure for it
Fall 2005 Costas Busch - RPI 55