knowledge

Theory of Computation: Lecture 4

Turing machines, configurations, recognizable and decidable languages, basic TM algorithm design, unary powers of two, and the Church-Turing thesis.

From Finite Memory to Work Tape

Finite automata have fixed memory: no matter how long the input is, the machine remembers only one of finitely many states. That is why languages such as

C={w{0,1}w has as many 0s as 1s}C=\{w\in\{0,1\}^*\mid w\text{ has as many }0\text{s as }1\text{s}\}

are not regular. The problem itself is easy for an ordinary algorithm: count the symbols, or pair them off. What finite automata lack is memory whose used portion can grow with the input.

Tape. A row of cells used as memory. Each cell stores one symbol. A head points to one cell at a time and can read or overwrite that cell. The input starts in the leftmost cells; the rest of the tape is blank.

Unbounded work memory. Memory with no fixed finite bound on how many tape cells may be used during a computation. Each input still uses only finitely many cells at any finite time, but longer inputs may require more cells.

A finite automaton has a fixed notebook with one page. A Turing machine has a finite program and as much blank paper as the computation needs.

Single-tape encoding. Storing the input, work memory, and output on one tape. Different regions of the tape can be separated by delimiters such as #. Several tapes may be easier to draw, but one tape is enough to represent the same computation.

Turing Machines

Turing machine (TM). A finite-state control attached to an infinite tape. At each step, the machine reads the symbol under its head, writes one tape symbol, moves the head one cell left or right, and enters a new state.

  • Finite control. The program has finitely many states, independent of the input length.
  • Tape. A one-way infinite sequence of cells, initially holding the input followed by blanks.
  • Head. The pointer to the current tape cell. It can read, overwrite, and move left or right.
  • Halting states. The accept and reject states stop the computation immediately.

Finite automata read a string once, left to right, and never change it. Turing machines may revisit earlier cells, rewrite symbols, and use blank cells as work space.

Because it can revisit and rewrite cells, a TM can compare the two ends of a string against each other, which a one-pass finite automaton cannot do.

Formal Turing machine. A Turing machine is a 7-tuple

M=(Q,Σ,Γ,δ,q0,qaccept,qreject)M=(Q,\Sigma,\Gamma,\delta,q_0,q_{\text{accept}},q_{\text{reject}})

with the following parts:

SymbolRole
QQfinite set of states
Σ\Sigmainput alphabet, not containing the blank symbol \sqcup
Γ\Gammatape alphabet, with Γ\sqcup\in\Gamma and ΣΓ\Sigma\subseteq\Gamma
δ\deltatransition function
q0Qq_0\in Qstart state, where computation begins
qacceptQq_{\text{accept}}\in Qaccepting halting state
qrejectQq_{\text{reject}}\in Qrejecting halting state, with qrejectqacceptq_{\text{reject}}\ne q_{\text{accept}}

Only non-halting states need transitions:

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

If δ(q,a)=(r,b,R)\delta(q,a)=(r,b,R), then in state qq reading aa, the machine writes bb, moves one cell right, and enters state rr. The case δ(q,a)=(r,b,L)\delta(q,a)=(r,b,L) is the same except that the head moves left.

At minimum, a TM description must make three distinguished states clear:

StateRole
q0q_0first state of the computation
qacceptq_{\text{accept}}halts with answer yes
qrejectq_{\text{reject}}halts with answer no

Extra states are working states used before the machine halts.

State graph of a TM. A directed graph drawing of the transition function: the graph and the 7-tuple describe the same machine. Nodes are states, the incoming arrow marks q0q_0, and an edge label has the form

ab,Da\to b,D

meaning: if the head reads aa, write bb, move in direction D{L,R}D\in\{L,R\}, and enter the target state.

A complete machine fits in a small graph. Let MM decide

L={w{0,1}w has no 1}=0,L=\{w\in\{0,1\}^*\mid w\text{ has no }1\}=0^*,

the strings made only of 0s. One working state suffices: stay in q0q_0, walking right over each 0 without changing it, until the head meets the first blank (accept, the input was all 0s) or the first 1 (reject). The blank in this and every later figure is the tape blank \sqcup.

0->0,R⊔->⊔,R1->1,Rq0qacceptqreject
A complete TM for 0*: loop right over 0s, accept at the first blank, reject at the first 1.
Graph featureMeaning
incoming arrowstart state q0q_0
self-loop on q0q_0read 0, rewrite it, keep scanning right
double circleaccepting halt qacceptq_{\text{accept}}
node qrejectq_{\text{reject}}rejecting halt
edge label ab,Da\to b,Dread aa, write bb, move DD

In the graph, qacceptq_{\text{accept}} and qrejectq_{\text{reject}} are drawn with no outgoing edges.

The input alphabet says what may appear in the original input. The tape alphabet says what the machine may use while computing, including marks such as XX and the blank symbol \sqcup.

Configurations and Computation

Configuration. A complete snapshot of a Turing machine computation: current state, current head position, and the finite visible part of the tape.

The notation uqvuqv, with u,vΓu,v\in\Gamma^* and qQq\in Q, means the state is qq, the visible tape content is uvuv with the head on the first symbol of vv, and every other cell is blank.

If u=ϵu=\epsilon, the head is on the leftmost tape cell. If v=ϵv=\epsilon, the head scans the blank cell immediately after uu.

q7101101111
The configuration u q7 v with u = 1011 and v = 01111: the head scans the first cell of v.

Transition between configurations. Suppose the current configuration is uaqibvuaq_i bv, so the head scans bb and aa is the symbol immediately to its left.

If δ(qi,b)=(qj,c,L)\delta(q_i,b)=(q_j,c,L), then the next configuration is

uqjacv.uq_jacv.

The machine overwrites bb by cc and moves left, so the head now scans aa. If δ(qi,b)=(qj,c,R)\delta(q_i,b)=(q_j,c,R), then the next configuration is

uacqjv.uacq_jv.

At the left edge, a left move keeps the head on the first cell. At the right edge of the shown word, blank cells are added as needed.

Computation. On input wΣw\in\Sigma^*, the starting configuration is q0wq_0w. Write CCC\vdash C' when configuration CC yields CC' in one step. The machine repeatedly applies valid transitions until it reaches qacceptq_{\text{accept}}, reaches qrejectq_{\text{reject}}, or never halts.

Resolving a run. Take the machine MM for 00^*. On input 00 every step is forced, and the run reaches qacceptq_{\text{accept}} in three moves:

q000  0q00  00q0  00qaccept.q_0\,00\ \vdash\ 0\,q_0\,0\ \vdash\ 00\,q_0\,\sqcup\ \vdash\ 00\,\sqcup\,q_{\text{accept}}.

Each 0 is rewritten as the head steps right; reading the trailing blank in q0q_0 sends MM to qacceptq_{\text{accept}}. The same run reads as one tape per configuration, the scanned cell shown inverted:

q000read 0, write 0, step rightq000read 0, write 0, step rightq000blank reached in q0qaccept00no 1 was seen: accept
Run of M on 00: the head walks right over the 0s and halts in q_accept at the first blank.

A single 1 derails the run. On 01 the first 0 is consumed, but reading the 1 in q0q_0 triggers qrejectq_{\text{reject}}:

q001  0q01  01qreject.q_0\,01\ \vdash\ 0\,q_0\,1\ \vdash\ 0\,1\,q_{\text{reject}}.

Unlike a DFA, a Turing machine does not always produce an answer. It may run forever.

An infinite computation does not have to repeat a configuration. The tape can keep changing, or the head can keep moving into fresh blank cells, so there are infinitely many possible configurations. Repetition is forced only when the computation is confined to finitely many configurations.

Recognizers and Deciders

Turing-recognizable language. A language LΣL\subseteq\Sigma^* recognized by some Turing machine MM: for every input ww,

  1. if wLw\in L, then MM accepts ww;
  2. if wLw\notin L, then MM rejects ww or loops forever.

A recognizer is allowed to fail to answer no.

Turing-decidable language. A language LΣL\subseteq\Sigma^* decided by some Turing machine MM: for every input ww, the machine halts, and it accepts exactly when wLw\in L.

Every decidable language is recognizable: a decider is a recognizer that also halts on all no-instances. The converse is not automatic, because looping is not the same as rejecting.

Input typeRecognizer for LLDecider for LL
wLw\in Lmust acceptmust accept and halt
wLw\notin Lmay reject or loopmust reject and halt

Recognition is a semi-answer: yes is reliable, no may never arrive. Decision is a total yes/no algorithm.

Designing Turing-Machine Algorithms

Turing machines are usually designed at a high level. A step such as "scan right until the next unmarked 1" is valid when it can be implemented by finitely many states moving one cell at a time.

Recipe: designing a TM decider.

  1. Choose work symbols. Add tape symbols that store progress, such as XX for a crossed-off input symbol.
  2. Use sweeps. Move left-to-right or right-to-left while a state records the small finite fact needed for the sweep.
  3. Maintain an invariant. State what the marks mean after each pass.
  4. Separate halting cases. Say exactly when the machine accepts and when it rejects.
  5. Prove termination. For a decider, show that every loop makes finite progress toward a halt.

Example 1. Equal numbers of 0s and 1s.

The language CC from the opening is not regular, yet it is decidable.

The machine pairs off one 0 with one 1 per sweep until nothing is left. It uses

Q={q0,q1,q2,q3,qA,qR},Σ={0,1},Γ={0,1,X,},Q=\{q_0,q_1,q_2,q_3,q_A,q_R\},\qquad \Sigma=\{0,1\},\qquad \Gamma=\{0,1,X,\sqcup\},

where qA=qacceptq_A=q_{\text{accept}} and qR=qrejectq_R=q_{\text{reject}} are the halts, XX temporarily marks a matched symbol, and \sqcup is the blank. Each edge still reads as ab,Da\to b,D, with two shorthands: a comma-separated read set fires on any of the listed symbols, and an omitted write leaves the cell unchanged. So X,0RX,0\to R means "on XX or 00, leave the cell and move right".

⊔->R0->⊔,R1->⊔,RX->⊔,RX,0->R⊔->R1->X,L1,X->R0->X,L⊔->R0,1,X->L⊔->Rq0q1q2q3qAqR
The decider for C. Each loop through q0 erases the leftmost symbol, finds and marks its opposite, then walks back; q0 accepts when only blanks remain.

Read the diagram as one repeating loop:

  • q0q_0: pick the leftmost symbol. A 0 is erased (\sqcup) and the machine remembers "find a 1" by entering q1q_1; a 1 is erased and it enters q2q_2 to find a 0; a leftover XX is erased and skipped; a \sqcup means everything is gone, so accept.
  • q1q_1 / q2q_2: find the opposite symbol. q1q_1 runs right over 0s and Xs to the first 1, writes XX, and turns back in q3q_3; q2q_2 is the mirror image. Hitting \sqcup first means the partner is missing, so reject.
  • q3q_3: rewind. Walk left over everything until the blank gap on the left, then step right into q0q_0 for the next sweep.

Each completed loop erases one 0 and one 1, so the counts stay equal exactly when the tape empties cleanly into qAq_A.

The run on 0110 is traced configuration by configuration, the scanned cell inverted:

Run on 0110

q00110leftmost is 0q1110erased it, hunt for a 1q3X10marked the 1, rewindq0X10back at the leftq010clear the X, scan onq20erased a 1, hunt for a 0q3Xmarked the 0, rewindq0Xback at the leftq0clear the X, scan onqAonly blanks remain: accept
The machine erases 0 with its matching 1, then the remaining 1 with its matching 0, and accepts once only blanks remain.

The invariant is that each completed loop removes exactly one 0 and one 1 (one rewritten to \sqcup in q0q_0, its partner marked XX and then erased on the next sweep), so the consumed symbols always hold equally many 0s and 1s. Accepting requires a fully blank tape, which is reachable only when the counts matched; rejecting happens the instant q1q_1 or q2q_2 runs off the end with no partner. Every loop consumes two cells, so the remaining input strictly shrinks and the machine always halts.

The tape converts an unbounded counting problem into a bookkeeping problem: remember progress by writing on the input.

Example 2. Unary powers of two.

Let

P={02nn0}.P=\{0^{2^n}\mid n\ge 0\}.

A TM can decide PP by repeatedly testing whether the current number of unmarked zeros is even and then deleting half of them.

  1. If there are no unmarked zeros, reject.
  2. Sweep left to right over the unmarked zeros, alternating between keeping one and marking the next one as deleted.
  3. If exactly one unmarked zero was seen during the pass, accept.
  4. If an odd number greater than one was seen, reject.
  5. If an even number was seen, return to the left end and repeat on the unmarked zeros.

Each non-halting pass divides the number of unmarked zeros by 22. A positive integer eventually reaches 11 exactly when it is a power of two; otherwise, some pass reaches an odd number greater than 11 and rejects. Because the number of unmarked zeros strictly decreases after every non-halting pass, the machine always halts.

Accepted: 0, 00, 0000. Rejected: 000 and 000000; halving six unmarked zeros leaves three, and the next pass sees an odd count greater than one, so it rejects.

The Church-Turing Thesis

Algorithm. An effective finite procedure for solving a problem. Before Turing machines and equivalent models, this was an intuitive idea rather than a formal mathematical object.

Church-Turing thesis. The informal notion of an algorithm coincides with what a Turing machine can compute.

This is not a theorem, because one side is informal. Its force comes from robustness: Turing machines, λ\lambda-calculus, recursive functions, register machines, and ordinary programming languages all define the same class of computable functions. Variants such as multi-tape Turing machines may change efficiency, but not which languages are decidable.

Diophantine equation. A polynomial equation with integer coefficients whose solutions are required to be integers.

For example, 3x22xyy2z7=03x^2-2xy-y^2z-7=0 has the integer solution x=1x=1, y=2y=2, z=2z=-2.

Hilbert's tenth problem asked for an algorithm deciding whether an arbitrary Diophantine equation has an integer solution. Once "algorithm" had a formal meaning, the problem could be answered precisely: Matiyasevich proved in 1970, building on work of Davis, Putnam, and Robinson, that no such algorithm exists.

Turing machines therefore do two jobs at once. They show that simple finite programs with unbounded work tape can decide many non-regular languages, and they provide the language needed to prove that some computational problems have no algorithm at all.