Chapter 23: TM Languages

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


Recursively enumerable and recursive languages

Note that TM’s have three kinds of behavior:

  1. enter a halt state (and accept)
  2. crash -- no transition specified (and reject)
  3. loop forever (and reject)
Definition: Any language accepted by a TM is called a recursively enumerable (r.e.) language or set. Definition: Any language L accepted by a TM that either halts and accepts, or crashes and rejects (never loops) is called a recursive language (or recursive set).

The TM that accepts L will:

Note: We will now be assuming that any computation that can be programmed on any computer can be programmed on a TM.  In the proofs that follow that involve TM’s, we will make arguments based on our knowledge of what can be programmed on conventional machines.  If required, those arguments could be backed up by (laboriously) constructing the appropriate TM.


If a language L is recursive, so is L¢

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:

  1. Remove all HALT (accept) states.
  2. Where transitions are missing (causing crashes), provide transitions to a new HALT (accept) state.
  3. A crash caused by trying to move left from the beginning of the tape can easily be turned into a HALT (and accept) (see p. 538)
Now, any sentence accepted by T will be rejected by T¢ , and any sentence rejected by T will accepted by T¢ .


If L and L¢ are both r.e., then L is recursive

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:

If it is T that halts, x is in L, and T1 will be programmed to halt (accept).
If it is T¢ that halts, then x is in L¢ , and T1 will be propgrammed to crash (reject).

T1 is a TM that loops forever on no input, and accepts exactly the language L.  Hence, L is recursive.


The r.e. languages are closed under È

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.

The r.e. languages are closed under Ç

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:

(Step 2) run the input on T2:
Encoding a TM

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.


A non-r.e. language L1

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.

In either case, a contradiction arises, so L1 is not r.e.


The halting problem

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

if (Ti loops on xi ) then T will halt and accept xi
if (Ti does not loop on xi) then run Ti on xi if (Ti accepts xi) then T will reject xi
if (Ti rejects xi) then T will accept xi
Q:  what does T do?
A:  accepts exactly the language L1 = (xi | Ti rejects xi)

This is a contradiction, because L1 is not r.e. !!


A r.e. language L2 that is not recursive

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:

run Ti on xi if (Ti accepts xi) then T will accept xi
if (Ti crashes) then T will reject xi
if (Ti loops) then T will (of course) loop
T accepts exactly L2, so L2 is r.e.

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.

Hosted by www.Geocities.ws

1