Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 57

Turing Machine Acceptance and Halting: RE and Recursive Languages

Recommended resources

Hello! Welcome to the ninth module of our course on the Theory of Computation.

In our last lesson, we introduced the Universal Turing Machine (UTM), a single machine capable of simulating any other Turing Machine. We defined its language, , as the set of pairs where the machine M accepts input w. A crucial observation was that the UTM, in its faithful simulation, will loop forever if M loops on w. This means the UTM is a recognizer for , but not a decider, as it doesn't halt on all inputs.

Today, we will formalize this fundamental distinction. Our learning outcome is to define recursively enumerable (RE) and recursive languages in terms of Turing Machine acceptance and halting. These definitions form the bedrock of computability theory, allowing us to classify problems based on whether they are fully solvable or only partially solvable.

1. The Two Tiers of Solvability

The behavior of a Turing Machine on a given language's strings can be categorized into two main levels of "solvability." One is a stronger guarantee than the other. Let's start with the strongest guarantee.

Recursive Languages (Decidable Languages)

Imagine an algorithm that you can always rely on to give you a definitive "yes" or "no" answer in a finite amount of time. This is the essence of a recursive language.

A language is recursive if there exists a Turing Machine M that decides it. This means M halts on every input string w:

  • If , M halts in an accepting state.
  • If , M halts in a rejecting state.

Crucially, a TM that decides a language never loops. Because of this, recursive languages are also called decidable languages. The problem of determining membership in such a language is a "decidable problem."

Recursively Enumerable Languages (Turing-Recognizable Languages)

Now, consider a slightly weaker guarantee. Instead of a definitive yes/no, what if we only had a procedure that could confirm "yes" answers, but might run forever if the answer is "no"? This is the nature of a recursively enumerable language.

A language is recursively enumerable (RE) if there exists a Turing Machine M that recognizes it. This means:

  • If , M halts in an accepting state.
  • If , M either halts in a rejecting state or loops forever.

The term "recursively enumerable" comes from an alternative definition: a language is RE if there is a TM (an "enumerator") that can output all the strings of the language, one by one. RE languages are also known as Turing-recognizable or semi-decidable languages.

To get a clear grasp of these two definitions and their differences, let's watch a short, focused video.

Decidability and Undecidability

This video from Neso Academy provides clear, concise definitions for recursive and recursively enumerable languages, directly comparing their Turing Machine halting properties.

Watch the segment from 00:57 to 03:05. Pay close attention to the key difference: a TM for a recursive language always halts, while a TM for an RE language is only guaranteed to halt if the string is in the language.

For a more detailed textual explanation that reinforces these concepts, you can review the following document.

Lesson 8: Introduction to Recursive and ...

This document elaborates on the definitions of recursive and recursively enumerable languages and explicitly connects recursive languages with the concept of decidability.

Read the sections titled 'Recursive Languages' and 'Recursively enumerable languages' on the first page. Then, read the section 'Connection between decidability and recursive languages' on the third page. This will solidify the equivalence between the terms 'recursive' and 'decidable'.


2. The Relationship Between the Classes

From the definitions, you can see that any TM that is a decider (for a recursive language) also fits the criteria of being a recognizer (for an RE language). If a machine always halts, it certainly halts for strings in the language. This implies a clear hierarchical relationship:

The set of all recursive languages is a proper subset of the set of all recursively enumerable languages.

This relationship is perfectly captured by the following diagram:

Hierarchy of Recursive and Recursively Enumerable Languages
This diagram shows the nested relationship of language classes. Recursive languages are a subset of Recursively Enumerable languages. There are languages that are RE but not recursive, and languages that are not even RE.

This begs the question: what is an example of a language that is in the outer circle (RE) but not the inner one (Recursive)? We already have our canonical example: .

  • is Recursively Enumerable: As we discussed in the last lesson, the Universal Turing Machine U recognizes . Given input , U simulates M on w. If M accepts w, U halts and accepts. This perfectly matches the definition of a recognizer for an RE language.

  • is Not Recursive: The UTM U loops if M loops on w. Since U does not halt on all inputs, it is not a decider. Therefore, is not a recursive (decidable) language. (We will formally prove the undecidability of the closely related Halting Problem in a future lesson).

This video reinforces why is recognizable.

Acceptance for Turing Machines is Undecidable, but Recognizable

This video from Easy Theory explains why the language ATM is recognizable. The logic directly applies our definition of a recognizer.

Watch the first part of the video (00:00 - 02:47). The presenter constructs a 'recognizer' for ATM, which is exactly the simulation process we discussed for the UTM. This demonstrates that ATM fits the definition of a Turing-recognizable (and thus, RE) language.

Test your understanding!

Suppose you are studying a language L. You have designed a Turing Machine M for it. You test M on two strings:

  1. On input w1, M runs for a million steps and then halts in an accepting state.
  2. On input w2, M runs for ten million steps and is still running.

Based only on this information, can you classify the language L as recursive or RE?

Show answer

Based on this information, you can only say that L is recursively enumerable.

  • The behavior on w1 shows that M accepts a string in L, which is consistent with both recursive and RE definitions.
  • The behavior on w2 (looping) is allowed for a recognizer of an RE language if w2 is not in L. However, this behavior violates the definition of a decider for a recursive language, which must always halt.

Since we have observed a non-halting computation, we know M is not a decider. Therefore, L cannot be classified as recursive based on this TM. It is, however, consistent with L being RE.


3. A Decisive Characterization: Post's Theorem

The distinction between these two classes is elegantly captured by a result known as Post's Theorem. It gives us a way to test if a language is recursive by looking at its RE properties.

Theorem: A language is recursive if and only if both and its complement, , are recursively enumerable.

Let's break down the intuition behind this proof, which should resonate with your software engineering background.

  • Proof Sketch (⇒ "if" part): Assume both and are RE. This means we have a recognizer for and a recognizer for . We can build a new TM, , that decides . On any input w, does the following:
    1. It runs and "in parallel" on input w. (In a single-tape TM, this is done by alternating steps: run one step of , then one step of , and so on).
    2. Since any string w must be in either or , one of the two recognizers is guaranteed to eventually halt and accept.
    3. If accepts, then halts and accepts.
    4. If accepts, then halts and rejects.

This new machine, , is guaranteed to halt for every input w and give the correct answer. Therefore, is recursive.

  • Proof Sketch (⇐ "only if" part): This direction is simpler. If is recursive, there is a decider for it.
    • itself serves as a recognizer for , so is RE.
    • We can create a decider for by simply taking and swapping its accept and reject states. Since has a decider, it is also recursive, and therefore it is also RE.

This theorem provides a powerful link between the two classes. For the formal proof, which aligns with your interest in mathematical rigor, the following notes are an excellent resource.

Recursive and Recursively Enumerable Sets

These notes from Stephen Cook at the University of Toronto provide formal definitions and proofs, including a concise proof of the theorem we just discussed. This will provide the rigorous treatment you appreciate.

Please read the section titled 'Theorem A is recursive iff both A and Ac are r.e.' on page 79. The 'Slick Proof' provided is a very elegant formalization of the parallel simulation idea we just discussed.

An important consequence of this theorem is that if a language is RE but not recursive (like ), then its complement cannot be recursively enumerable.


Conclusion

In this lesson, we have established the formal definitions that distinguish between fully solvable problems and partially solvable ones within the framework of Turing Machines.

Key Takeaways:

  • A language is recursive (or decidable) if a Turing Machine exists that halts on all inputs, definitively accepting or rejecting.
  • A language is recursively enumerable (RE) (or Turing-recognizable) if a Turing Machine exists that is guaranteed to halt and accept strings within the language, but may loop on strings not in the language.
  • The class of recursive languages is a strict subset of the class of RE languages.
  • The language of the Universal Turing Machine, , is our primary example of a language that is RE but not recursive.
  • Post's Theorem provides a crucial link: a language is recursive if and only if both and its complement are recursively enumerable.

Preview of the Next Lesson:
Now that we have defined these important language classes, we can investigate their mathematical properties. In the next lesson, we will explore the closure properties of recursive and RE languages. We will ask questions like: If you take the union of two RE languages, is the result also RE? What about intersection or complement? Answering these questions helps us understand how these classes behave and how we can reason about the computability of complex problems.