Topics
Recursively enumerable and recursive languages
If a language L
is recursive, so is L¢
If L and L¢
are both r.e., then L is recursive
The r.e. languages
are closed under È
The r.e. languages
are closed under Ç
Encoding a TM
A non-r.e. language L1
The halting problem
A r.e. language L2
that is not recursive
Note that TM’s have three kinds of behavior:
The TM that accepts L will:
That is, the recursive languages are closed under complementation.
Proof:
Suppose we have a non-looping TM T that accepts L. Create a new TM
T¢as follows:
Proof:
Let T be the TM for L, and T¢ be the
TM for L¢ . Given any input string x,
here is a non-looping program for determining whether x is in L:
The idea is to construct a TM T1 that will run T and T¢ on x "simultaneously" (by interleaving their instructions).
Think about how you would program this on an ordinary computer, which is nothing more than a "fancy" TM.
T1 will operate as follows:
1. Do step 1 for T (i.e. move it from its start state)
2. Do step 1 for T¢ (move it
from its start state)
3. Do step 2 for T
4. Do step 2 for T¢
etc. etc.
Eventually T or T¢ will halt and accept, because exactly one of the following is true:
T1 is a TM that loops forever on no input, and accepts exactly the language L. Hence, L is recursive.
Let T1 and T2 be the TM’s accepting L1 and L2. We construct a TM T that will accept L1 È L2 as follows:
T will alternate the steps of T1 and T2 as in the previous proof with the following outcomes:
If T1 halts (accepts), then T will halt and accept.
If T2 halts (accepts), T will halt and accept.
If T1 and T2 both crash, T will crash.
If T1 and T2 both loop, then T will (of course) loop.
Let T1 and T2 be the TM’s accepting L1 and L2. We construct a TM T that will accept L1 Ç L2 as follows:
(Step 1) run an input on T1:
It is possible to "encode" a TM as a sequence of symbols from some alphabet. In fact, the set of such TM encodings is a regular set!
Example:

Note: for encodings, we will by convention always make the start state #1 and the halt (accept state) #2 (we can always assume at most one halt state).
A "table" version of this machine can be written as follows.
States are written in "unary" notation (e.g. 3 = 111)
| old state | input | new state | new tape symbol | head move |
| 1 | a | 111 | b | R |
| 1 | b | 1 | b | R |
| 111 | a | 111 | b | L |
| 111 | D | 11 | b | L |
This table completely specifies the behavior of the TM. Now we can encode each row as a string:
Row 1: 1a111bR note the form: 1+(a+b) 1+(a+b)(R+L)
The whole machine has the encoding:
1a111bR1b1bR111a111bL111D 11bL
One can imagine a list of all such encodings (for given tape alphabets), from smallest to largest and in lexicographic order. We will refer to this as an enumeration of all TM’s.
There are languages that cannot be recognized by any TM. Consider the following rectangular array.
| x1 | x2 | x3 | x4 | … | xk | … | |
| T1 | A | ||||||
| T2 | R | ||||||
| T3 | R | ||||||
| T4 | A | ||||||
| … | … | ||||||
| Tk | A or R? | ||||||
| … |
Now define L1 = all xi such that Ti rejects xi. For our example, it would be:
L1 = { x2, x3, … )
Now is L1 r.e.? That is, is there some Ti that accepts L1?
Suppose Tk (see above) accepts L1. Consider xk.
Can one write a program (or TM = TH) that can determine whether or not any other program will loop forever on any given input? Let’s see what happens if such a machine TH exists.
We will incorporate TH into a new program T, whose inputs will be x1, x2, …:
Here is what T will be programmed to do on input xi:
run TH for (Ti with input xi) to determine whether it loops
This is a contradiction, because L1 is not r.e. !!
Consider again:
| x1 | x2 | x3 | x4 | … | xk | … | |
| T1 | A | ||||||
| T2 | R | ||||||
| T3 | R | ||||||
| T4 | A | ||||||
| … | … | ||||||
| Tk | A or R? | ||||||
| … |
and let L2 = L1¢= { xi | Ti accepts xi}.
Part 1: L2 is r.e.
We construct a program (TM = T) that proves it. Here is what T does
on input xi:
Part 2: L2 is not recursive.
If it were, its complement L1 would be recursive. But L1
is
not even r.e. Contradiction, so it’s not recursive.