Theory of Computation & Computer Graphics β Turing Machine, NEC licence examination syllabus (Nepal Engineering Council).
Introduction to Turing Machines (TM)
The simplest machine that can compute anything computable β and the definition of "computable" itself.
π Where this lives: Alan Turing invented this machine in 1936 to answer a question in mathematical logic, and in doing so described the architecture of the stored-program computer years before one existed. The laptop you are reading this on is, in the precise technical sense of this section, a Turing machine with a large but finite tape β and no computer ever built, or ever buildable, can compute anything a Turing machine cannot. Search "Turing 1936 On Computable Numbers Entscheidungsproblem".
The model
A TURING MACHINE CONSISTS OF:
Β· AN INFINITE TAPE divided into cells, each holding one symbol
Β· A READ/WRITE HEAD positioned over one cell
Β· A FINITE CONTROL β a finite set of states
ON EACH STEP THE MACHINE:
1. READS the symbol under the head
2. WRITES a symbol to that cell (possibly the same one)
3. MOVES the head ONE cell LEFT or RIGHT
4. CHANGES state
THAT IS THE ENTIRE MODEL. It is deliberately, almost
perversely simple β and the claim of the section is that
nothing more powerful is possible.
ββ THE FORMAL DEFINITION βββββββββββββββββββββββββββββββββββ
M = (Q, Ξ£, Ξ, Ξ΄, qβ, B, F)
Q finite set of STATES
Ξ£ INPUT alphabet
Ξ TAPE alphabet, with Ξ£ β Ξ
Ξ΄ TRANSITION FUNCTION
Ξ΄ : Q Γ Ξ β Q Γ Ξ Γ {L, R}
qβ start state
B the BLANK symbol, B β Ξ but B β Ξ£
F accepting states
READ Ξ΄ CAREFULLY: Ξ΄(q, X) = (p, Y, D) means "in state q
reading X, go to state p, WRITE Y over X, and move in
direction D".
ββ HOW IT DIFFERS FROM WHAT CAME BEFORE ββββββββββββββββββββ
The whole section is best understood as a sequence of memory
upgrades:
FINITE AUTOMATON no memory beyond the state
reads input once, left to right
PUSHDOWN AUTOMATON a STACK β last-in-first-out only
input still read once, left to right
TURING MACHINE an unbounded TAPE that can be
READ AND WRITTEN AT ANY POSITION,
and the head MOVES IN BOTH DIRECTIONS
THREE CAPABILITIES ARE NEW, AND EACH MATTERS:
1. THE HEAD CAN MOVE LEFT, so the machine can revisit and
re-read.
2. THE MACHINE CAN WRITE, so the tape is memory rather than
merely input.
3. THE INPUT ITSELF CAN BE OVERWRITTEN β the tape serves as
input, working memory and output at once.
THIS IS WHY A TM CAN RECOGNISE aβΏbβΏcβΏ WHILE A PDA CANNOT: it
can mark an a, walk right to mark a b, walk further to mark a
c, then walk all the way back β comparing three counts by
physically crossing them off, which no single stack allows.
ββ INSTANTANEOUS DESCRIPTION βββββββββββββββββββββββββββββββ
The complete configuration is written
Ξ± q Ξ²
where q is the current state, Ξ± is the tape content to the
LEFT of the head, and Ξ² is the content from the head
RIGHTWARD. The head is on the FIRST SYMBOL OF Ξ².
So X X qβ a b b means: tape reads XXabb, machine in state
qβ, head on the third cell.
ββ ACCEPTANCE AND HALTING ββββββββββββββββββββββββββββββββββ
A TM ACCEPTS w if, started with w on the tape and the head on
its first symbol, it reaches an accepting state.
THE CRITICAL DIFFERENCE FROM ALL EARLIER MODELS:
A TURING MACHINE NEED NOT HALT.
A finite automaton always stops β it reads the input and
finishes. A TM may loop forever, and there is no way in
general to detect this from outside. THIS SINGLE FACT
GENERATES EVERYTHING IN THE LATER TOPICS: the halting
problem, undecidability, and the distinction between
recursive and recursively enumerable languages.
HENCE TWO CLASSES OF LANGUAGE:
RECURSIVELY ENUMERABLE (Turing-recognisable) β some TM
accepts exactly the strings in L. On strings NOT in L it
may reject OR LOOP FOREVER.
RECURSIVE (decidable) β some TM accepts exactly L AND
ALWAYS HALTS. It answers yes or no on every input.
RECURSIVE β RECURSIVELY ENUMERABLE, and the strictness of
that containment is proved by the halting problem.
ββ A FULLY WORKED MACHINE: L = { aβΏbβΏ } ββββββββββββββββββββ
THE STRATEGY: repeatedly cross off one a and one b until both
run out.
qβ β find the leftmost unmarked a
Ξ΄(qβ, a) = (qβ, X, R) mark the a as X, go right
Ξ΄(qβ, Y) = (qβ, Y, R) no a's left β check the rest
Ξ΄(qβ, B) = ACCEPT empty input accepted
qβ β scan right for the first unmarked b
Ξ΄(qβ, a) = (qβ, a, R)
Ξ΄(qβ, Y) = (qβ, Y, R)
Ξ΄(qβ, b) = (qβ, Y, L) mark the b as Y, turn back
qβ β scan left to the marked X
Ξ΄(qβ, a) = (qβ, a, L)
Ξ΄(qβ, Y) = (qβ, Y, L)
Ξ΄(qβ, X) = (qβ, X, R) back at the marker, repeat
qβ β verify only Y's remain
Ξ΄(qβ, Y) = (qβ, Y, R)
Ξ΄(qβ, B) = ACCEPT
TRACE ON aabb, head position shown in brackets:
qβ [a]abb mark a β X, move right
qβ X[a]bb scan right over a
qβ Xa[b]b found b β mark Y, turn left
qβ X[a]Yb scan left
qβ [X]aYb reached X, turn right
qβ X[a]Yb mark second a β X
qβ XX[Y]b skip Y
qβ XXY[b] found b β mark Y, turn left
qβ XX[Y]Y scan left
qβ X[X]YY reached X, turn right
qβ XX[Y]Y no a's left β state qβ
qβ XXY[Y] skip Y
qβ XXYY[B] blank reached β ACCEPT
THIRTEEN STEPS. Verified: aabb and ab ACCEPT; aab and abb
REJECT; the empty string ACCEPTS.
THE MECHANISM IS WORTH NAMING: THE MACHINE IS **COUNTING BY
PAIRING**, crossing off one of each. It never stores a
number anywhere β the marks on the tape ARE the count, and
that idea recurs throughout Turing machine construction.
Variants and the Church-Turing thesis
ββ THE REMARKABLE ROBUSTNESS OF THE MODEL ββββββββββββββββββ
Every one of the following variants recognises EXACTLY THE
SAME CLASS OF LANGUAGES as the basic machine:
Β· MULTIPLE TAPES (any fixed number)
Β· MULTIPLE TRACKS on one tape
Β· A TWO-WAY INFINITE TAPE (infinite in both directions)
Β· NON-DETERMINISM
Β· A STAY-PUT option in addition to L and R
Β· Larger tape alphabets
Β· MULTIPLE HEADS
Β· TWO-DIMENSIONAL tape
Β· A machine with TWO STACKS instead of a tape
NONE OF THESE ADDS POWER. Each is simulated by the basic model
with at most a polynomial slowdown (except non-determinism,
which costs exponentially in time but nothing in
computability).
THE TWO-STACK RESULT IS THE ONE THAT TIES THIS SECTION TO THE
LAST: A PDA WITH **TWO** STACKS IS EQUIVALENT TO A TURING
MACHINE. One stack holds the tape to the left of the head, the
other the tape to the right; moving the head is popping from
one and pushing to the other. THAT IS PRECISELY WHY {aβΏbβΏcβΏ}
NEEDED TWO STACKS AND WHY CONTEXT-FREE LANGUAGES ARE NOT
CLOSED UNDER INTERSECTION.
ββ THE CHURCH-TURING THESIS ββββββββββββββββββββββββββββββββ
Developed fully in a later topic, but stated here because it
is what gives the model its significance:
ANY FUNCTION THAT CAN BE COMPUTED BY ANY EFFECTIVE
PROCEDURE WHATSOEVER CAN BE COMPUTED BY A TURING MACHINE.
THIS IS NOT A THEOREM. It cannot be proved, because
"effective procedure" is an informal notion. IT IS A THESIS β
a claim about the relationship between a formal model and an
intuitive idea.
THE EVIDENCE IS THE CONVERGENCE OF INDEPENDENT DEFINITIONS.
In the 1930s several mathematicians formalised computation in
completely different ways:
TURING MACHINES (Turing, 1936)
Ξ»-CALCULUS (Church, 1936)
RECURSIVE FUNCTIONS (GΓΆdel, Herbrand)
POST SYSTEMS (Post)
REGISTER MACHINES (later)
ALL WERE PROVED EQUIVALENT. Every subsequent model β
cellular automata, quantum computers, every programming
language ever designed β has also proved equivalent in
COMPUTABILITY, whatever its advantages in speed or
convenience.
THAT IS THE SAME STYLE OF ARGUMENT USED FOR REGULAR
LANGUAGES IN AN EARLIER TOPIC, where four independent
definitions converged. Here the stakes are higher: the claim
is about the limits of computation itself.
ββ WHAT A TURING MACHINE IS FOR ββββββββββββββββββββββββββββ
IT IS NOT A PRACTICAL COMPUTER. Nobody programs one to get
work done; a machine to add two numbers takes dozens of
states.
ITS PURPOSE IS TO MAKE "COMPUTABLE" A MATHEMATICALLY PRECISE
TERM, so that one can PROVE things are impossible.
Β· Without a formal model, "no algorithm exists for X" is not
a statement that can be proved β only a report of failure
so far.
Β· With one, it becomes a theorem, and the later topics of
this section prove several.
THE THREE ROLES A TM PLAYS, each a later topic:
LANGUAGE RECOGNISER β decides membership
FUNCTION COMPUTER β transforms input to output on the tape
ENUMERATOR β generates the strings of a language
AND ONE MORE, WHICH IS THE DEEPEST: a Turing machine can be
ENCODED AS A STRING and given as input to another Turing
machine. THE UNIVERSAL TURING MACHINE, covered later, is the
theoretical statement of the STORED-PROGRAM COMPUTER β the
idea that a program is just data, which is the single most
consequential idea in computing.
The single fact that generates the rest of this section: a Turing machine need not halt. Every earlier model always stopped after reading its input. A TM may loop forever with no way to detect it from outside β and from that come the halting problem, undecidability, and the gap between recursive and recursively enumerable languages.
π Go further: The two-stack result deserves attention because it closes the loop with the previous section. A pushdown automaton with two stacks is exactly as powerful as a Turing machine: put the tape to the left of the head on one stack and the tape to the right on the other, and moving the head becomes popping from one and pushing to the other. So the jump from context-free to Turing-computable is literally one extra stack β which is why {aβΏbβΏcβΏ} sits just beyond the context-free languages, and why context-free languages fail to be closed under intersection. The Chomsky hierarchy's biggest gap has a strikingly small cause. Search "two stack pushdown automaton Turing equivalent".
π‘ Exam angle: give the 7-tuple and read Ξ΄ precisely β read, write, move, change state. Contrast the TM with the FA and PDA on the three new capabilities: leftward movement, writing, and overwritable input. Know the instantaneous description notation Ξ±qΞ². The likely long question is to design a TM and trace a string β the aβΏbβΏ crossing-off machine is the standard one, so learn its four states and be able to produce the trace. State that a TM need not halt and define recursive versus recursively enumerable. Mention that all variants are equivalent, especially the two-stack PDA, and state the Church-Turing thesis as a thesis rather than a theorem.
Syllabus points
TM model and definition (7-tuple)
Create a free account to tick topics off, take notes as you read, watch the video lessons and get a day-by-day study plan built around your exam date.