Elective Theory of Computation

Theory of ComputationUnit 69 min read

Recursive & Recursively Enumerable Languages: Definitions, Machines, Proofs & Real-World Links

Unit 6 of Theory of Computation explores recursive languages (decidable by Turing machines), recursively enumerable languages (recognizable but not necessarily decidable), and their relationship to computability. Covers Church-Turing thesis, halting problem, and practical implications in compilers, databases, and crypt

TAKEAWAYS:

  • Recursive languages are decidable (Turing machine halts on all inputs), while recursively enumerable languages are recognizable (Turing machine halts only on "yes" instances).
  • The halting problem proves no general algorithm can decide if a TM halts, separating recursive from recursively enumerable languages.
  • Post’s Correspondence Problem is a classic example of a recursively enumerable but non-recursive language.
  • Real-world applications include compiler optimizations (deciding if a program terminates) and database query planning (enumerating valid query paths).
  • Reduction techniques (e.g., mapping NP-complete problems to RE languages) are key tools in computability proofs.
  • Recursive languages are closed under complement, intersection, and union, while RE languages are only closed under union.


Core Definitions: Recursive vs. Recursively Enumerable Languages

Recursive and recursively enumerable (RE) languages are two fundamental classes in computability theory, distinguished by whether a Turing machine (TM) can decide (halt on all inputs) or merely recognize (halt only on "yes" instances) them.

1. Recursive Languages (Decidable)

A language is recursive if there exists a Turing machine that:

  • Halts on all inputs (accepts or rejects).
  • Correctly decides membership in .

Key Properties:

  • Closed under complement: If is recursive, so is .
  • Closed under union, intersection, and concatenation.
  • Example: .

2. Recursively Enumerable Languages (Recognizable)

A language is recursively enumerable (RE) if there exists a Turing machine that:

  • Halts and accepts if .
  • May loop forever if .

Key Properties:

  • Not closed under complement: If is RE, may not be RE.
  • Closed under union (but not intersection or complement).
  • Example: The halting problem is RE but not recursive.

Visual: Recursive vs. RE Languages

classDiagram
    class Recursive {
        +Decidable by TM
        +Closed under complement
        +Example: Even 1s in binary strings
    }
    class RE {
        +Recognizable by TM
        +Not closed under complement
        +Example: Halting problem
    }
    Recursive --|> RE : Subset
    note for Recursive "All recursive languages are RE, but not vice versa."

The Halting Problem: Why RE ≠ Recursive

The halting problem (proven undecidable by Alan Turing, 1936) shows that not all RE languages are recursive.

Proof Sketch (Reduction from to )

  1. Assume a TM decides .
  2. Construct a TM that:
    • On input , runs on .
    • If accepts, loops forever.
    • If rejects, accepts.
  3. Contradiction: would decide , but is not RE (by Rice’s Theorem).

Post’s Correspondence Problem (PCP): A Classic RE but Non-Recursive Language

PCP is a decision problem where:

  • Given pairs of strings , determine if there exists a sequence such that: .

Why PCP is RE but not recursive?

  • RE: A TM can enumerate all possible sequences and check for equality.
  • Not recursive: No TM can decide PCP in finite time (proven by Post, 1946).

Example (Solvable Instance):

Pairs: (a, ε), (b, a), (ε, b)
Solution: Choose indices 1, 2 → \( u_1u_2 = a \cdot b \), \( v_1v_2 = \varepsilon \cdot a = a \). Not equal.
Wait, let’s correct:
Pairs: (a, ε), (b, a), (ε, b)
Solution: Choose indices 1, 3 → \( u_1u_3 = a \cdot \varepsilon = a \), \( v_1v_3 = \varepsilon \cdot b = b \). Still no.
Better example:
Pairs: (a, ε), (ε, a)
Solution: Choose index 1 → \( u_1 = a \), \( v_1 = \varepsilon \). Not equal.
Hmm, perhaps a clearer example:
Pairs: (a, ε), (ε, a), (b, b)
Solution: Choose indices 1, 2 → \( u_1u_2 = a \cdot \varepsilon = a \), \( v_1v_2 = \varepsilon \cdot a = a \). **Equal!**

Real-World Applications

1. Compiler Design (Termination Analysis)

  • Idea Used: Deciding if a program terminates (recursive language).
  • Example: eSewa’s payment validation system uses recursive checks to ensure transactions complete (no infinite loops in payment processing scripts).
  • How: The compiler’s static analyzer checks for loops with no exit conditions (a recursive decision problem).

2. Database Query Optimization (RE Languages)

  • Idea Used: Enumerating valid query paths (RE language).
  • Example: Ncell’s customer data queries enumerate possible paths to fetch records without exhaustively checking all combinations (RE but not recursive due to NP-hard subproblems).
  • How: The query planner generates candidate execution plans (RE) but cannot always decide the optimal one in polynomial time.

3. Cryptography (One-Way Functions)

  • Idea Used: RE languages for "hard" problems (e.g., factoring).
  • Example: Khalti’s transaction hashing relies on RE problems (e.g., discrete log) to ensure security. Breaking these would require enumerating solutions (RE) but is computationally infeasible.

Worked Example: Proving a Language is RE

Problem: Show is RE.

Solution:

  1. TM Construction: Build a TM that:
    • Enumerates all possible inputs .
    • Simulates on each .
    • If accepts any , accepts .
  2. Why RE?: halts and accepts if . If accepts no input, loops forever.

Trace:

Step Action Outcome
1 Enumerate Simulate on
2 If accepts, halt & accept Else, go to
... ... ...

Comparison Table: Recursive vs. RE Languages

Property Recursive Languages Recursively Enumerable Languages
Decision by TM Halts on all inputs (accept/reject) Halts only on "yes" inputs
Complement Closed Not closed (unless trivial)
Union Closed Closed
Intersection Closed Not closed
Example (halting problem)

Key Theorems and Proof Techniques

1. Rice’s Theorem

  • Statement: Any non-trivial property of TMs is undecidable.
  • Implication: Most "interesting" questions about TMs (e.g., "Does accept only strings of length 5?") are recursive.

2. S-m-n Theorem

  • Statement: For any , there exists a TM such that: computes .
  • Use: Enables encoding of multiple inputs into a single TM.

3. Reduction (Many-One)

  • Definition: if there exists a computable function such that: .
  • Example: Reduce to (as in the halting problem proof).

Exam Tip

  1. Definitions First: Always start with precise definitions of recursive/RE languages.
    • Bad: "Recursive languages are decidable."
    • Good: "A language is recursive if there exists a TM that halts on all inputs and accepts iff ."
  2. Proofs Require TMs: For questions like "Show is RE," construct a TM and describe its steps.
  3. Halting Problem: Know the reduction proof (not just the statement). Examiners love seeing that diagonalizes over .
  4. RE vs. Recursive: Emphasize that RE languages can be "recognized" but not necessarily decided. Use as your go-to example.
  5. Real-World Links: Connect to compilers (termination), databases (query planning), or cryptography (hard problems). Even if not asked, this shows depth.

Practice Questions (Self-Check)

  1. Short Answer:

    • Why is not RE?
    • Give an example of a language that is neither recursive nor RE.
  2. Proof:

    • Show is recursive.
  3. Application:

    • How might a Pathao driver’s route optimizer use RE languages? (Hint: Enumerating possible paths.)

Final Visual: Recursive vs. RE Hierarchy

flowchart TD
    A["All Languages"] --> B["Recursively Enumerable (RE)"]
    B --> C["Recursive"]
    C --> D["Regular/Context-Free"]

Based on the PU BE Computer (PU) syllabus for Theory of Computation, unit 6.

Discussion

Loading…