Sub topic 2
Running a Turing Machine: Configurations, Halting and Looping
Assume you know finite automata, context-free machines, and proof by contradiction. This chapter uses a deterministic Turing machine, so each state-symbol pair has at most one possible move.
Configurations
A configuration records the complete situation of a machine:
- its current state,
- the tape contents,
- the position of the head.
A common notation is u q v. Here, u is the tape content to the left of the head, q is the current state, and v begins with the symbol currently under the head.
For example, the configuration a q1 bba means:
- the tape contains
abbain the relevant region, - the machine is in state
q1, - the head is scanning the first
b.
The tape extends infinitely in both directions or, in some definitions, infinitely to the right. Unused cells contain the blank symbol, often written _.
A transition has the form
δ(q, X) = (p, Y, R)
It means that a machine in state q, scanning X, writes Y, moves right, and enters state p. A left move is written L.
Tracing a computation
Suppose a machine has these transitions:
δ(q0, a) = (q1, a, R)δ(q1, b) = (qa, b, R)
Starting with input ab, the computation is:
q0 aba q1 bab qa
The first step moves the head from a to b. The second step enters the accepting state qa.
The sequence of configurations is called a computation history. For a deterministic machine, the history is unique from a given starting configuration.
Halting, rejection, and looping
A machine halts when it enters a state with no further transition. Conventionally:
- an accepting state means accept,
- a rejecting state means reject,
- no transition may also be defined as rejection.
If the machine continues making transitions forever, it loops. A looping computation produces an infinite sequence of configurations and gives no final answer.
This difference matters:
| Behavior | Result on the input |
|---|---|
| Enters an accepting state | Accept |
| Enters a rejecting state | Reject |
| Runs forever | No answer |
A recognizer may accept every string in its language but loop on strings outside it. A decider must halt on every input, either accepting or rejecting.
Simulating with a step limit
A simulator can report acceptance or rejection when those events occur. If it stops after a fixed number of steps, the result “unknown” means only that the limit was reached.
def run(delta, word, max_steps=100):
tape = dict(enumerate(word))
head, state = 0, "q0"
for _ in range(max_steps):
if state == "qa":
return "accept"
symbol = tape.get(head, "_")
if (state, symbol) not in delta:
return "reject"
state, written, move = delta[(state, symbol)]
tape[head] = written
head += 1 if move == "R" else -1
return "unknown"
delta = {
("q0", "a"): ("q1", "a", "R"),
("q1", "b"): ("qa", "b", "R"),
}
print(run(delta, "ab")) # accept
print(run(delta, "aa")) # rejectExercise
Why cannot a simulator that stops after 100 steps always determine whether an arbitrary Turing machine halts?
Show answer
A machine might halt after more than 100 steps, or it might never halt. The step limit distinguishes neither case.