Introduction

A Turing machine (TM) is a finite-state controller with a doubly infinite (or one-way infinite) tape and a read/write head. It is the standard model of general-purpose computation. Languages recognized by TMs are the recursively enumerable (r.e.) languages; languages decided by TMs that always halt are the recursive (decidable) languages. The working core is the definitions, simple TM designs, variants (multitape, nondeterministic) and the Church-Turing thesis at statement level.

Prerequisites

Core concepts

Formal definition

A TM is M=(Q,Σ,Γ,δ,q0,qaccept,qreject)M = (Q, \Sigma, \Gamma, \delta, q_0, q_{\mathrm{accept}}, q_{\mathrm{reject}}) with tape alphabet Γ\Gamma containing the blank ⊔\sqcup, input alphabet Σ⊂Γ∖{⊔}\Sigma \subset \Gamma \setminus \{\sqcup\}, and

δ:(Q∖{qaccept,qreject})×Γ→Q×Γ×{L,R}.\delta: (Q \setminus \{q_{\mathrm{accept}}, q_{\mathrm{reject}}\}) \times \Gamma \to Q \times \Gamma \times \{L,R\}.

A step reads the tape cell under the head, writes a symbol, moves one cell left or right, and updates the state. Computation accepts by entering qacceptq_{\mathrm{accept}} and rejects by entering qrejectq_{\mathrm{reject}}.

Configurations

A configuration uqvu q v means tape contents uvuv (infinite blanks beyond), state qq, head on the first symbol of vv. One step: if δ(q,b)=(p,c,R)\delta(q, b) = (p, c, R) then u q bv⊢uc p vu\,q\,bv \vdash u c\,p\,v; if δ(q,b)=(p,c,L)\delta(q, b) = (p, c, L) then ua q bv⊢u p ac vua\,q\,bv \vdash u\,p\,ac\,v. On a one-way infinite tape a left move in the leftmost cell leaves the head where it is (Sipser's convention).

Three outcomes

On input ww a TM accepts (reaches qacceptq_{\mathrm{accept}}), rejects (reaches qrejectq_{\mathrm{reject}}, or in HMU's convention halts with no move defined), or loops (runs forever). Looping is not rejection: an observer can never be sure that a long run will not still accept.

Recognizers versus deciders

  • Recognizer. Accepts every string in LL, and either rejects or loops on strings not in LL. LL is r.e.
  • Decider. Always halts; accepts iff the string is in LL. LL is recursive (decidable).

Every decidable language is r.e.; the converse is false (for example ATMA_{\mathrm{TM}} is r.e. but undecidable).

Variants

Multitape TMs, nondeterministic TMs, and TMs with stay-option heads all recognize the same class of languages as single-tape deterministic TMs (Sipser 3.2; HMU 8.4). Time bounds change; language power does not.

ModelPowerCost of simulation by a 1-tape DTM
kk-tape TM= TMt(n)t(n) steps become O(t(n)2)O(t(n)^2)
Nondeterministic TM= TM (both for recognizing and for deciding)t(n)t(n) steps become 2O(t(n))2^{O(t(n))} (breadth-first search of the computation tree)
Stay option, two-way infinite or semi-infinite tape, multiple heads, 2-D tape= TMpolynomial
Two-stack PDA; queue automaton; 2-counter machine= TMtwo stacks hold the tape left and right of the head
PDA (one stack); 1-counter machineCFL or smallernot universal
Linear bounded automaton (tape limited to the input)CSLthe membership problem is decidable
TM that never writes, or that only moves rightregulara read-only two-way head adds no power (2DFA = DFA)
Enumerator (prints strings, possibly forever)REprints LL iff a TM recognizes LL

A language is decidable iff some enumerator prints it in string order (shortlex). A finite automaton with a stack is not a TM; with two stacks it is.

How it works

High-level design macros

TMs are described at a high level in exams: "scan right to the first aa, cross it off, scan right to the first bb," and so on. Storage in the finite state holds a constant amount of data; the tape holds unbounded data.

Example: recognize anbncna^n b^n c^n

Repeatedly cross off one aa, one bb, one cc from left to right; accept when nothing but crossed symbols remain; reject on mismatch. Example 1 gives the full transition table and a trace.

Turing machine tape configuration and a transition step
Figure 1. TM configuration with tape cells, head on one cell, and current state; one transition shows write and move for the a^n b^n c^n crossing-off machine.

In Figure 1 the state labels qscanq_{\mathrm{scan}} and qbq_b are q0q_0 and q1q_1 of the table in Example 1: the step drawn is δ(q0,a)=(q1,X,R)\delta(q_0, a) = (q_1, X, R).

Algorithms and pseudocode

Text
TM-STEP(M, config)
1  read symbol under head
2  apply delta to get (new_state, write, dir)
3  write symbol; move head; set state
4  if state is accept or reject: halt

Practice both a high-level TM description and step-by-step transition traces.

Mathematical explanation

Church-Turing thesis

Every effectively computable function is computable by a Turing machine. It is a thesis, not a theorem: it identifies the informal notion of algorithm with TM computability. All standard programming languages are TM-equivalent in power.

Encoding machines

Finite descriptions of TMs can be encoded as strings (or integers). That encoding enables universal machines and undecidability proofs in Decidability and Undecidability.

Worked examples

Example 1: {anbncn}\{a^n b^n c^n\}

Tape alphabet {a,b,c,X,Y,Z,⊔}\{a, b, c, X, Y, Z, \sqcup\}; aa becomes XX, bb becomes YY, cc becomes ZZ. Any pair not listed goes to qrejectq_{\mathrm{reject}}.

StateReadsWrite, move, nextMeaning
q0q_0aaX,R,q1X, R, q_1cross the leftmost aa
q0q_0YYY,R,q4Y, R, q_4no aa left: check the rest
q0q_0⊔\sqcupacceptempty input (n=0n = 0)
q1q_1a,Ya, Ysame, R,q1R, q_1skip to the first bb
q1q_1bbY,R,q2Y, R, q_2cross it
q2q_2b,Zb, Zsame, R,q2R, q_2skip to the first cc
q2q_2ccZ,L,q3Z, L, q_3cross it, turn back
q3q_3a,b,Y,Za, b, Y, Zsame, L,q3L, q_3return left
q3q_3XXX,R,q0X, R, q_0next round
q4q_4YYY,R,q4Y, R, q_4only YY's, then ZZ's
q4q_4ZZZ,R,q5Z, R, q_5
q5q_5ZZZ,R,q5Z, R, q_5
q5q_5⊔\sqcupacceptall counts matched

Trace on aabbcc (first round): q0 aabbcc⊢Xq1 abbcc⊢Xa q1 bbcc⊢XaYq2 bcc⊢XaYb q2 cc⊢XaYq3 bZc⊢Xa q3 YbZc⊢Xq3 aYbZc⊢q3 XaYbZc⊢Xq0 aYbZcq_0\,aabbcc \vdash X q_1\,abbcc \vdash Xa\,q_1\,bbcc \vdash XaY q_2\,bcc \vdash XaYb\,q_2\,cc \vdash XaY q_3\,bZc \vdash Xa\,q_3\,YbZc \vdash X q_3\,aYbZc \vdash q_3\,XaYbZc \vdash X q_0\,aYbZc. The whole run accepts after 23 steps. On anbncna^n b^n c^n the machine takes exactly 4n2+3n+14n^2 + 3n + 1 steps, so it runs in O(n2)O(n^2) time on inputs of length 3n3n; it halts on every input, so it is a decider. It rejects abcc (in q5q_5 it reads cc) and aabbc (in q2q_2 it reaches ⊔\sqcup looking for a second cc).

Example 2: {ww∣w∈{0,1}∗}\{ ww \mid w \in \{0,1\}^* \}

Find the middle (mark off matching ends, or use multitape copy); compare halves. Decidable.

Example 3: multitape simulation

A kk-tape TM simulates on one tape by interleaving tracks; the language is unchanged.

Example 4: nondeterministic TM

Guess a witness (for example a satisfying assignment) and verify deterministically. Nondeterministic TMs recognize and decide exactly the same languages as deterministic ones (Sipser 3.2); only the time can grow exponentially. An NTM decider must halt on every branch.

Example 5: loops

A TM whose only move is "on any symbol, move right" never halts, so it recognizes ∅\emptyset but is not a decider. The language ∅\emptyset is still decidable, by a different TM that rejects at once. Decidability is a property of the language (some TM decides it), not of one machine.

Example 6: closure, and "L and its complement both RE"

  • Decidable languages are closed under union, intersection, complement, concatenation and star. RE languages are closed under union, intersection, concatenation and star, but not complement.
  • For union of two recognizers, run them alternately one step at a time (dovetailing); running M1M_1 to completion first fails when M1M_1 loops.
  • Theorem. If LL and L‾\overline{L} are both RE, then LL is decidable: run both recognizers in parallel; exactly one accepts, and it must halt. Hence ATM‾\overline{A_{\mathrm{TM}}} is not RE.
  • Four groups. Call LL co-RE when L‾\overline{L} is RE. The theorem says RE and co-RE together give exactly the decidable languages, so every language falls in exactly one of four groups.
GroupExampleArgument
decidable (recursive)ADFA={⟨D,w⟩∣D a DFA accepting w}A_{\mathrm{DFA}} = \{\langle D, w \rangle \mid D \text{ a DFA accepting } w\}a TM runs DD on ww for ∣w∣\lvert w \rvert steps and always halts
RE but not co-REATMA_{\mathrm{TM}}, HALTTMHALT_{\mathrm{TM}}the universal TM recognizes ATMA_{\mathrm{TM}}, which is undecidable by diagonalization; HALTTMHALT_{\mathrm{TM}} is recognized by simulation and is undecidable because ATM≤mHALTTMA_{\mathrm{TM}} \le_m HALT_{\mathrm{TM}}; an undecidable RE language is not co-RE, by the theorem
co-RE but not REATM‾\overline{A_{\mathrm{TM}}}, ETM={⟨M⟩∣L(M)=∅}E_{\mathrm{TM}} = \{\langle M \rangle \mid L(M) = \emptyset\}ATM‾\overline{A_{\mathrm{TM}}} is the complement of an RE language and is not RE, by the theorem; ETM‾\overline{E_{\mathrm{TM}}} is RE (dovetail MM over all strings and accept when one is accepted), and ATM‾≤mETM\overline{A_{\mathrm{TM}}} \le_m E_{\mathrm{TM}}, so ETME_{\mathrm{TM}} is not RE
neither RE nor co-REEQTM={⟨M1,M2⟩∣L(M1)=L(M2)}EQ_{\mathrm{TM}} = \{\langle M_1, M_2 \rangle \mid L(M_1) = L(M_2)\}ATM‾≤mEQTM\overline{A_{\mathrm{TM}}} \le_m EQ_{\mathrm{TM}}, so it is not RE; ATM≤mEQTMA_{\mathrm{TM}} \le_m EQ_{\mathrm{TM}}, so ATM‾≤mEQTM‾\overline{A_{\mathrm{TM}}} \le_m \overline{EQ_{\mathrm{TM}}} and it is not co-RE
  • The reductions. For a pair ⟨M,w⟩\langle M, w \rangle let MwM_w be the TM that ignores its own input, runs MM on ww and accepts if MM accepts. Then L(Mw)=Σ∗L(M_w) = \Sigma^* if MM accepts ww, and L(Mw)=∅L(M_w) = \emptyset otherwise. Let M∅M_\emptyset reject everything and MallM_{\mathrm{all}} accept everything.
    • ⟨M,w⟩↦⟨Mw⟩\langle M, w \rangle \mapsto \langle M_w \rangle maps ATM‾\overline{A_{\mathrm{TM}}} to ETME_{\mathrm{TM}}.
    • ⟨M,w⟩↦⟨M∅,Mw⟩\langle M, w \rangle \mapsto \langle M_\emptyset, M_w \rangle maps ATM‾\overline{A_{\mathrm{TM}}} to EQTMEQ_{\mathrm{TM}}.
    • ⟨M,w⟩↦⟨Mall,Mw⟩\langle M, w \rangle \mapsto \langle M_{\mathrm{all}}, M_w \rangle maps ATMA_{\mathrm{TM}} to EQTMEQ_{\mathrm{TM}}.
  • "Not RE" alone does not place a language: ETME_{\mathrm{TM}} is not RE but is co-RE, while EQTMEQ_{\mathrm{TM}} is neither.

Example 7: counting argument

TMs have finite descriptions, so there are countably many. The set of languages over {0,1}\{0,1\} is the power set of a countable set, which is uncountable (diagonalization). Therefore most languages are not RE. The diagonal language {⟨M⟩∣M does not accept ⟨M⟩}\{\langle M \rangle \mid M \text{ does not accept } \langle M \rangle\} is an explicit example.

Important properties and observations

  • Tape is unbounded but only finitely many non-blank cells appear at any finite time.
  • Acceptance needs only reach qacceptq_{\mathrm{accept}}; the tape contents at accept can be anything.
  • PDA ⊊\subsetneq TM in power ({anbncn}\{a^n b^n c^n\} separates them).
  • Universal TM: a TM UU with L(U)={⟨M,w⟩∣M accepts w}L(U) = \{ \langle M,w \rangle \mid M \text{ accepts } w \}.

Common misconceptions.

  • "TMs always halt." Only deciders do.
  • "Nondeterministic TMs recognize more languages." They do not.
  • "Infinite tape means infinite time is allowed for a decision." Decisions must halt in finite time.
  • "A TM with a two-way read-only tape is more powerful than a DFA." It accepts only regular languages.
  • "A two-stack PDA is just a PDA." Two stacks simulate a tape, so it is as powerful as a TM.
  • "Rejecting and looping are the same." For a recognizer they both mean "not in LL", but only a halting reject can be observed.

GATE examination perspective

  • RECOGNIZE VS DECIDE. Keep the words apart: a recognizer may loop on strings outside LL; a decider halts on every input.
  • HIGH-LEVEL DESCRIPTIONS. Write clear phases; do not invent 50-state tables unless asked.
  • VARIANTS PRESERVE LANGUAGES. Quote the equivalence.
  • SEPARATION EXAMPLES. anbncna^n b^n c^n not CFL but decidable.
  • MODEL POWER TABLE. Two stacks, a queue, or two counters equal a TM; one stack does not; read-only TMs are finite automata.
  • COMPLEMENT RULE. LL RE and L‾\overline{L} RE implies decidable; so if LL is RE but not decidable, L‾\overline{L} is not RE.
  • FOUR GROUPS. Decidable; RE not co-RE (ATMA_{\mathrm{TM}}); co-RE not RE (ATM‾\overline{A_{\mathrm{TM}}}, ETME_{\mathrm{TM}}); neither (EQTMEQ_{\mathrm{TM}}). Place a language by checking both LL and L‾\overline{L}.
  • STEP COUNTING. Crossing-off machines take quadratic time on one tape; a second tape makes {anbncn}\{a^n b^n c^n\} linear.

Summary

Sources

  1. M. Sipser, Introduction to the Theory of Computation, 3rd ed., Cengage Learning: Section 3.1 (Turing machines), Section 3.2 (variants: multitape, nondeterministic, enumerators), Section 3.3 (the definition of algorithm), Section 4.2 (undecidability; the diagonalization method).
  2. J. E. Hopcroft, R. Motwani, J. D. Ullman, Introduction to Automata Theory, Languages, and Computation, 3rd ed., Pearson Addison-Wesley, Section 8.2 (the Turing machine), Section 8.3 (programming techniques for TMs), Section 8.4 (extensions to the basic TM), Section 8.5 (restricted TMs: semi-infinite tapes, multistack machines, counter machines).
  3. P. Linz, An Introduction to Formal Languages and Automata, 6th ed., Jones & Bartlett Learning, Section 9.1 (the standard Turing machine), Section 10.1 to 10.5 (other models: variations, multitape, nondeterministic, universal TM, linear bounded automata), Section 11.1 (recursive and recursively enumerable languages).

Next steps