The Timpson Lyceum seal

The Timpson Lyceum · Computation Theory

Lecture 12 (Computation Theory) Turing Machines

Turing Machines – Lecture 12

Overview

This lecture introduces the Turing machine, the most powerful model of computation we study and a faithful abstraction of a general-purpose computer with unbounded memory. After the limitations of pushdown automata, the Turing machine gains the ability to both read and write a two-way-movable head on an infinite tape, and it accepts or rejects the instant it enters a dedicated halt state rather than waiting to finish reading the input. We define the machine formally as a 7-tuple, build up the notion of a configuration and the yields relation that links one configuration to the next, and then state precisely what it means for a machine to accept, reject, or loop forever. Finally we distinguish the two central language classes of the rest of the course: Turing-recognizable and decidable.

Key Concepts

From PDA to Turing machine. A pushdown automaton has a state control, a read-only input, and a stack. A Turing machine keeps the state control but replaces the input + stack with a single tape:

Transition notation. An edge labeled a, b → R means: if the head reads a, write b, then move right. If you read and write the same symbol you may abbreviate a → R (read a, leave it, move right). There is no "stay" action; you can only move left or right.

Formal definition. A Turing machine is a 7-tuple (Q,Σ,Γ,δ,q0,qaccept,qreject)(Q, \Sigma, \Gamma, \delta, q_0, q_{\text{accept}}, q_{\text{reject}}):

Implicit reject. Because the machine is deterministic, any (state, symbol) pair with no drawn transition is understood to go to qrejectq_{\text{reject}}. Diagrams omit these edges (there would be one from nearly every state) — they are implied.

Left-edge behavior. If the head is on the leftmost cell and is told to move left, it stays put. To avoid relying on this, mark the left end with a sentinel symbol (e.g. $) so the program never tries to run off the left edge.

Configuration. A configuration captures the entire instantaneous state of the machine — like a save file. For state qq and tape strings u,v∈Γ∗u, v \in \Gamma^*, write u q vu\,q\,v to mean: the tape contains uvuv (then blanks), the machine is in state qq, and the head is on the first symbol of vv. Example: with the head reading the 0 in 0 1 X | y 1 0 while in state q5q_5, the configuration is 0 1 X q5 y 1 00\,1\,X\,q_5\,y\,1\,0.

The "yields" relation. Configuration C1C_1 yields C2C_2 if the machine can move legally from C1C_1 to C2C_2 in one step. Concretely, if δ(qi,b)=(qj,c,R)\delta(q_i, b) = (q_j, c, R) then u qi b vu\,q_i\,b\,v yields u c qj vu\,c\,q_j\,v; if δ(qi,b)=(qj,c,L)\delta(q_i, b) = (q_j, c, L) then u a qi b vu\,a\,q_i\,b\,v yields u qj a c vu\,q_j\,a\,c\,v.

Acceptance / rejection / looping. MM accepts ww if there is a sequence of configurations C1,C2,…,CnC_1, C_2, \dots, C_n where C1C_1 is the start configuration q0wq_0 w, each CiC_i yields Ci+1C_{i+1}, and CnC_n is an accepting configuration. Rejection is defined the same way ending in a rejecting configuration. Crucially, a Turing machine need not do either — it may loop forever. (Finite automata and PDAs couldn't loop because they consumed input each step; Turing machines have no such guarantee.)

Two language classes (the heart of the rest of the course):

Describing machines at a high level. Drawing full diagrams is extremely tedious, so for anything nontrivial we instead give a step-by-step procedure (a verbose pseudocode), and assume a reader could build the actual machine from it. A common first line is "scan the input to confirm it has the form of some regular expression," which is trivially Turing-implementable since any regular language is.

Worked Example

Goal: build a Turing machine recognizing {0n1n∣n≥0}\{0^n 1^n \mid n \ge 0\} by pairing each 0 with a 1. Strategy: replace the leftmost 0 with X, scan right to the leftmost 1 and replace it with Y, return left, and repeat; accept iff every symbol is crossed off. Trace the input 0011 (then blanks) by listing configurations, where q1q_1 scans right over 0's and q2q_2 scans left over 0's:

q0 0011  →0,X→R  X q1 011→0→R  X0 q1 11→1,Y→L  X q2 0Y1→0→L  q2 X0Y1→X→R  X q0 0Y1→0,X→R  XX q1 Y1  →Y→R  XXY q1 1→1,Y→L  XX q2 YY  →  ∗    XXYY q0 ⊔  →⊔  qaccept\begin{aligned} q_0\,0011 \;&\xrightarrow{0,X \to R}\; X\,q_1\,011 \\ &\xrightarrow{0 \to R}\; X0\,q_1\,11 \\ &\xrightarrow{1,Y \to L}\; X\,q_2\,0Y1 \\ &\xrightarrow{0 \to L}\; q_2\,X0Y1 \\ &\xrightarrow{X \to R}\; X\,q_0\,0Y1 \\ &\xrightarrow{0,X \to R}\; XX\,q_1\,Y1 \;\xrightarrow{Y \to R}\; XXY\,q_1\,1 \\ &\xrightarrow{1,Y \to L}\; XX\,q_2\,YY \;\xrightarrow{\;*\;}\; XXYY\,q_0\,\sqcup \;\xrightarrow{\sqcup}\; q_{\text{accept}} \end{aligned}

After all 0's are X and all 1's are Y, the head scans right over the Y's; reading a blank with nothing left to match means the counts were equal, so the machine accepts. Any leftover 0/1, or a missing partner, falls through to the implicit reject.

Summary