Skip to content

Undecidability

Not all problems can be solved by algorithms. Some are undecidable — no Turing machine exists that always halts and correctly answers the question.


Diagonalization

Cantor's diagonalization showed: The set of all languages over {0,1} is uncountable, but the set of all Turing machines is countable.

Countability of TMs

Every TM can be encoded as a finite binary string M. The set of all finite strings over {0,1} is countable (lexicographic order). Therefore, TMs are countable — but the powerset of {0,1} (all languages) is uncountable.

Conclusion: There exist languages that are not RE (most languages, in fact).


ATM is Undecidable

ATM={M,wM is a TM and M accepts w}

Theorem: ATM is RE but not recursive (not decidable).

Proof by diagonalization: Suppose there is a decider H for ATM:

H(M,w)={acceptif M accepts wrejectif M does not accept w

Construct the "diagonal" TM D:

D(<M>):
    Run H(<M, <M>>)
    If H accepts, reject
    If H rejects, accept

Now, what does D do on input D?

  • If D accepts D, then H(D,D) accepts, meaning D rejects D — contradiction
  • If D rejects D, then H rejects, meaning D accepts D — contradiction

Therefore, H cannot exist. ATM is undecidable.


The Halting Problem

HALTTM={M,wM halts on input w}

Theorem: HALTTM is undecidable.

Proof by reduction from ATM: Assume R decides HALTTM. Construct S to decide ATM:

S(<M, w>):
    Run R(<M, w>)
    If R rejects, reject   (M doesn't halt, so can't accept)
    If R accepts, simulate M on w until it halts
        If M accepts, accept
        If M rejects, reject

S would be a decider for ATM — but we just proved ATM is undecidable. Contradiction. So HALTTM is undecidable.


Proving Undecidability by Reduction

To prove problem P is undecidable, reduce a known undecidable problem to P:

AmB (mapping reduction) and A undecidable B undecidable

A mapping reduction from A to B is a computable function f such that:

wAf(w)B

Notable Undecidable Problems

ETM: Emptiness of TM Language

ETM={ML(M)=}

Undecidable (not even RE). Reduction from ATM.

EQTM: Equivalence of TMs

EQTM={M1,M2L(M1)=L(M2)}

Undecidable (not RE). Reduction from ETM: fix M2 as a TM that rejects everything.

REGULARTM: Is L(M) Regular?

REGULARTM={ML(M) is regular}

Undecidable (not RE). Rice's Theorem applies.

CFLTM: Is L(M) Context-Free?

Similarly undecidable.


Rice's Theorem

Any nontrivial property of the RE languages is undecidable.

A property P of RE languages is nontrivial if:

  • There exists a TM M1 such that L(M1)P
  • There exists a TM M2 such that L(M2)P

Formal Statement

Let P be any nontrivial subset of RE languages. Then:

LP={ML(M)P}

is undecidable.

Consequences

Almost every semantic question about programs is undecidable:

  • Does the program halt on all inputs?
  • Does the program compute f(x)=x2?
  • Is the program's output always positive?
  • Are two programs equivalent?
  • Does the program contain a virus?

Rice's Theorem says: you cannot algorithmically determine any nontrivial behavioral property of programs by inspecting their code.


Post's Correspondence Problem (PCP)

Given two lists of strings A=(a1,,ak) and B=(b1,,bk), does there exist a sequence of indices i1,i2,,im (m1) such that:

ai1ai2aim=bi1bi2bim

Theorem: PCP is undecidable.

PCP is a powerful tool for proving undecidability — many problems (ambiguity of CFGs, emptiness of intersection of CFLs, etc.) reduce to PCP.


The Recursion Theorem

For any computable function f that transforms TM descriptions, there exists a TM M such that:

L(M)=L(f(M))

In other words: TMs can obtain and use their own description.

Consequences:

  • There exists a TM that prints its own description (a "quine")
  • Used to prove Rice's Theorem elegantly
  • Underpins self-referential constructions in computability theory

Hierarchy of Undecidability

DecidableREco-REΣ2Π2
  • RE (Σ1): Semi-decidable — TM halts and accepts on YES instances
  • co-RE (Π1): Complement is RE — TM halts and accepts on NO instances
  • Δ1 = Recursive = RE co-RE
  • Higher levels correspond to problems with alternating quantifiers

ATM is RE-complete. ETM is co-RE-complete. EQTM is Π2-complete.