Turing Machines and Decidability – Halting Problem, Rice Theorem and Undecidability Explained

Home
CS & IT
Theory of Computation
Turing Machines & Decidability
Key Takeaways:

  • A Turing Machine (TM) is the mathematical model for any computer — it has infinite tape memory and can read, write, and move left or right.
  • The Church-Turing Thesis says that anything computable by any physical device can be computed by a Turing machine.
  • A language is decidable (recursive) if a TM always halts with accept or reject. It is semi-decidable (recursively enumerable) if a TM halts and accepts for strings in the language but may loop forever on strings outside it.
  • The Halting Problem is undecidable — no algorithm can determine for all programs whether they halt on a given input.
  • Rice’s Theorem says that every non-trivial semantic property of programs (Turing machines) is undecidable.
  • Undecidability is proved by reduction: showing that if your problem were decidable, you could solve a known-undecidable problem.

1. Turing Machine — Formal Model

A Turing Machine (TM) is an idealised computing device that captures the notion of “algorithm” precisely. Unlike real computers, it has unlimited memory in the form of an infinite tape. Think of it as a theoretical robot that reads and writes on a paper tape of unlimited length, moving left or right one cell at a time, following a set of rules based on what it currently reads and what state it is in.

Formal Definition

A TM is a 7-tuple M = (Q, Σ, Γ, δ, q0, qaccept, qreject) where:

  • Q — finite set of states
  • Σ — input alphabet (does not include the blank symbol ⊔)
  • Γ — tape alphabet (Σ ⊂ Γ, and ⊔ ∈ Γ)
  • δ : Q × Γ → Q × Γ × {L, R} — transition function: current state + tape symbol → new state + write symbol + move direction
  • q0 — start state
  • qaccept — accept state (immediately halts on entry)
  • qreject — reject state (immediately halts on entry)

How a TM Runs

  1. Input w is placed on the tape; all other cells are blank
  2. Head starts at the leftmost cell, machine is in q0
  3. At each step: read current symbol, apply δ, write new symbol, move head L or R, change state
  4. Halt if reaching qaccept (accept) or qreject (reject). May loop forever otherwise.

Example: TM for {0n1n | n ≥ 1}

Repeatedly: scan left to right, find a 0, replace with X, then find the corresponding 1, replace with X. If all 0s and 1s are matched (tape has only Xs and blanks) — accept. If counts don’t match — reject.

2. Turing Machine Variants

All the following variants are equivalent in power — they recognise exactly the same class of languages as the standard TM. This robustness supports the Church-Turing Thesis.

VariantDescriptionEquivalent to Standard TM?
Multi-tape TMk tapes, each with its own headYes — simulate by interleaving tape contents
Nondeterministic TM (NTM)Multiple choices at each step; accepts if any branch acceptsYes — simulate via BFS of all computation branches
EnumeratorTM with a printer; prints all strings in a languageYes — a language is RE iff some enumerator enumerates it
2-stack PDAPDA with two stacks instead of oneYes — simulate tape with two stacks
Semi-infinite tape TMTape only extends to the rightYes — fold the left portion into the right
Stay-option TMHead can also stay in place (L, R, or S)Yes — S is simulated by going right then left

3. Church-Turing Thesis

The Church-Turing Thesis is not a theorem (it cannot be proved) but a widely accepted claim:

Every effectively computable function can be computed by a Turing machine.

Alan Turing and Alonzo Church (working with lambda calculus) independently arrived at equivalent models of computation in the 1930s — before electronic computers existed. The thesis means that any programming language, any modern computer, any physical mechanism that computes can be simulated by a Turing machine. TMs define the ceiling of what any computation can achieve.

The thesis is supported by decades of evidence: every model of computation proposed (RAM machines, cellular automata, quantum computers for classical computation, etc.) has been shown equivalent to TMs. No counter-example has ever been found.

4. Decidable vs Undecidable Languages

Hierarchy of Languages

ClassAlso CalledTM BehaviourExample
DecidableRecursiveTM always halts (accept or reject)ADFA, EDFA, ACFG
Semi-Decidable (only)RE but not recursiveTM halts on accept; may loop on rejectATM, Halting problem
Not even RENon-RENo TM recognises itcomplement of ATM

Some Decidable Problems

  • ADFA — does DFA M accept string w? (Simulate M on w)
  • EDFA — is the language of DFA M empty? (Graph reachability from start to any accept state)
  • EQDFA — do two DFAs accept the same language? (Construct DFA for symmetric difference, check if empty)
  • ACFG — does CFG G generate string w? (CYK algorithm — O(n3))
  • ECFG — is the language of CFG G empty? (Check if start variable can derive a terminal string)

5. The Halting Problem

The Halting Problem asks: given a program P and an input I, does P halt (terminate) when run on I? Alan Turing proved in 1936 that no algorithm can solve this for all programs and inputs.

Formal Statement

Let HALTTM = {<M, w> | TM M halts on input w}. This language is undecidable.

Proof by Contradiction (Diagonalisation)

  1. Assume a TM H exists that decides HALTTM: H accepts <M,w> if M halts on w, rejects otherwise.
  2. Build a new TM D that takes a TM description <M> as input and:
    • Runs H on <M, <M>> (asking “does M halt when given its own description?”)
    • If H says “halts” — D loops forever
    • If H says “doesn’t halt” — D accepts and halts
  3. Ask: what does D do on input <D> (its own description)?
    • If D halts on <D>, then H says “halts,” so D loops — contradiction
    • If D loops on <D>, then H says “doesn’t halt,” so D halts — contradiction
  4. Both cases give a contradiction, so H cannot exist.

This is a diagonalisation argument — the same technique Cantor used to prove that real numbers are more numerous than integers.

ATM is Semi-Decidable (RE) but Undecidable

ATM = {<M, w> | TM M accepts w} is recognisable (RE): the Universal TM U simulates M on w, accepting if M accepts. But ATM is undecidable — U might loop forever when M loops, so we can never reliably reject.

6. Reductions

A reduction from problem A to problem B (written A ≤m B) is a computable function f such that w ∈ A iff f(w) ∈ B. Reductions transfer computability properties:

  • If A ≤m B and B is decidable, then A is decidable.
  • Contrapositive: if A is undecidable and A ≤m B, then B is undecidable.

Standard Undecidable Problems (by reduction from ATM or HALTTM)

ProblemDescriptionDecidable?
ATMDoes TM M accept w?No (semi-decidable)
HALTTMDoes TM M halt on w?No (semi-decidable)
ETMIs L(M) empty?No (not even RE)
EQTMDo two TMs accept the same language?No (not even RE)
REGULARTMIs L(M) a regular language?No (Rice’s Theorem)
Post Correspondence ProblemDo dominos match up?No

7. Rice’s Theorem

Rice’s Theorem is one of the most powerful results in computability theory. It generalises all the specific undecidability results into one sweeping statement.

Rice’s Theorem: Every non-trivial semantic property of Turing machines is undecidable.

Terminology

  • A property of TMs is a set P of TM descriptions — those machines that have the property.
  • A property is semantic if it depends only on L(M) (the language recognised) and not on M’s internal structure.
  • A property is non-trivial if some TMs have it and some don’t (P is neither empty nor contains all TMs).

What Rice’s Theorem Means in Practice

You cannot write a program that correctly determines for all programs whether:

  • A program terminates on all inputs
  • A program is equivalent to another program
  • A program accepts any input at all
  • A program accepts strings of length 5
  • A program computes a particular mathematical function

Each of these is a non-trivial semantic property — and Rice’s Theorem says they are all undecidable. This is why automated program verification tools are fundamentally limited and must use approximations (static analysis, bounded model checking, etc.).

8. Recognisable but Undecidable Languages

A language L is Turing-recognisable (RE) if some TM accepts every string in L (but may loop on strings not in L). A language L is co-RE if its complement is RE.

Key Theorem: A language L is decidable if and only if both L and its complement are Turing-recognisable.

This gives us a test for undecidability: if L is RE but its complement is not RE, then L is undecidable. For example:

  • ATM is RE (simulate M on w; accept if M accepts) but not co-RE, so undecidable.
  • The complement of ATM is not RE — there is no TM that recognises it at all.
  • ETM is not RE — and neither is its complement — so it is even harder than ATM.

9. Common Misconceptions

Misconception 1: A non-deterministic TM is more powerful than a deterministic TM.
False. Both recognise exactly the same class of languages (RE). Non-determinism matters for complexity (time efficiency) — that is the essence of the P vs NP question — but not for what is computable vs uncomputable.

Misconception 2: Undecidable means impossible — no program can help at all.
Not quite. Undecidable means no algorithm can solve the problem correctly for all inputs. Tools can still be built that solve most practical cases. Compilers do termination analysis, and static analysis tools handle common cases — they just cannot be complete and correct simultaneously.

Misconception 3: The Halting Problem says programs can’t tell if other programs halt.
More precisely: no single program can correctly determine halting for all programs and inputs. Programs can often determine halting for specific programs or restricted input classes. Termination analysis in program verification is an active research field.

Misconception 4: Rice’s Theorem applies to syntactic properties of programs.
Rice’s Theorem only applies to semantic properties — those that depend on what a TM computes (its language), not how it is structured. Syntactic properties like “does the TM have more than 5 states” are decidable — you just count the states.

Misconception 5: If a problem is undecidable, it is always semi-decidable.
No. Some problems are not even semi-decidable (not RE). ETM (is the language of TM M empty?) is an example — neither ETM nor its complement is RE.

10. Frequently Asked Questions

What is a Turing machine and how does it relate to modern computers?

A Turing machine is an abstract mathematical model of computation — an infinite tape with a read-write head that moves left or right based on rules. Modern computers are physical implementations that are equivalent in computational power: anything a modern computer can compute, a TM can compute (just much slower). The Church-Turing Thesis formalises this equivalence. TMs are used theoretically because their simplicity makes them easier to reason about than real hardware.

Why is the Halting Problem undecidable?

The proof uses self-reference and diagonalisation. Assume a halting-detector H exists. Build a program D that asks H “would D halt on its own description?” and then does the opposite — halting if H says it won’t, and looping if H says it will. D applied to its own description creates a contradiction in either case. This means H cannot exist. The argument is similar to the liar’s paradox (“this sentence is false”) — self-reference creates an unsolvable situation.

What does Rice’s Theorem mean for software testing?

Rice’s Theorem means you cannot build a tool that correctly answers “does this program do X?” for every non-trivial X and every program. In practice: no automated testing tool can guarantee it has found all bugs; no static analyser can correctly flag all and only the programs that have a particular property. Tools must either miss some bugs (incomplete) or raise false alarms (unsound). This is a fundamental theoretical limit, not an engineering shortcoming.

What is the difference between decidable and semi-decidable (recognisable)?

A decidable language has a TM that always halts — it gives a definitive yes or no for every input. A semi-decidable (Turing-recognisable) language has a TM that halts and accepts for strings in the language, but may loop forever for strings not in the language. You can never be sure a looping TM will ever give an answer — you cannot distinguish “still computing” from “will never finish.” Decidable problems always give answers in finite time; semi-decidable ones only guarantee answers for strings in the language.

Leave a Comment