All NEC Computer Engineering topics / Theory of Computation & Computer GraphicsUniversal Turing Machine Theory of Computation & Computer Graphics β Turing Machine, NEC licence examination syllabus (Nepal Engineering Council).
Universal Turing Machine
A machine that runs other machines β the theoretical origin of the stored-program computer.
π Where this lives: The universal Turing machine is the reason you own one computer rather than a drawer full of single-purpose devices. Before Turing's 1936 construction, a "computing machine" meant a machine built to perform one calculation. The universal machine established that a single fixed machine could perform any calculation given a description of it β which is precisely what it means to install software. Every general-purpose computer ever built is an engineering realisation of this idea. Search "universal Turing machine stored program computer von Neumann" .
Encoding and construction
A UNIVERSAL TURING MACHINE U TAKES AS INPUT A DESCRIPTION OF
ANOTHER TURING MACHINE M TOGETHER WITH AN INPUT w, AND SIMULATES
M ON w.
U( β¨M, wβ© ) behaves exactly as M(w)
Β· If M accepts w, U accepts.
Β· If M rejects w, U rejects.
Β· IF M LOOPS ON w, U LOOPS.
THE THIRD LINE IS NOT A DEFECT. U cannot do better than the
machine it simulates, and the later topics show that no machine
could.
ββ THE PREREQUISITE: ENCODING A MACHINE AS A STRING ββββββββ
U's input is a string, so M must be written as one. A
standard binary encoding:
Β· state qα΅’ encoded as 0β±
Β· tape symbol Xβ±Ό encoded as 0Κ²
Β· direction L = Dβ, R = Dβ encoded as 0α΅
Β· a transition Ξ΄(qα΅’, Xβ±Ό) = (qβ, Xβ, Dβ) encoded as
0β± 1 0Κ² 1 0α΅ 1 0Λ‘ 1 0α΅
Β· transitions separated by 11
A WORKED ENCODING. Take a machine with two transitions:
Ξ΄(qβ, Xβ) = (qβ, Xβ, R) β 0 1 0 1 00 1 00 1 00
Ξ΄(qβ, Xβ) = (qβ, Xβ, L) β 00 1 00 1 000 1 0 1 0
Concatenating with the 11 separator gives
010100100100 11 0010010001010
A 27-BIT STRING THAT COMPLETELY DESCRIBES THE MACHINE.
THREE CONSEQUENCES FOLLOW IMMEDIATELY, and they carry the
whole of the rest of the section:
1. EVERY TURING MACHINE IS A FINITE BINARY STRING.
2. THEREFORE TURING MACHINES ARE **COUNTABLE** β they can be
listed Mβ, Mβ, Mβ, β¦ by reading their encodings as binary
numbers.
Strings that are not valid encodings are taken to denote
a trivial machine that halts immediately, WHICH MAKES THE
ENUMERATION TOTAL: every index i denotes some machine Mα΅’.
3. A MACHINE CAN BE GIVEN ANOTHER MACHINE β OR ITSELF β AS
INPUT.
THE THIRD IS THE ONE THAT LEADS TO THE HALTING PROBLEM.
ββ HOW U WORKS βββββββββββββββββββββββββββββββββββββββββββββ
A convenient construction uses THREE TAPES:
TAPE 1 β the ENCODING of M, β¨Mβ©, never altered. This is the
"program".
TAPE 2 β a copy of M's tape, holding w initially and
updated as the simulation proceeds. This is the
"data".
TAPE 3 β M's CURRENT STATE, held as 0β±. This is the
"program counter".
THE SIMULATION LOOP:
1. Read the symbol under the head on tape 2.
2. Read the current state from tape 3.
3. SCAN TAPE 1 for a transition matching that (state,
symbol) pair.
4. If none is found, HALT as M would.
5. Otherwise, WRITE the new symbol on tape 2, MOVE tape 2's
head, and UPDATE tape 3 with the new state.
6. Repeat.
THE COST: each simulated step requires scanning the encoding
of M, so U runs with a SLOWDOWN proportional to |β¨Mβ©| β
A CONSTANT FACTOR for any fixed M, since the machine's
description does not grow with the input.
(Converting the three-tape U to a single tape adds the usual
quadratic factor of the multi-tape topic.)
THE STRUCTURAL POINT IS WORTH NAMING: TAPE 1 HOLDS THE
PROGRAM, TAPE 2 THE DATA, TAPE 3 THE PROGRAM COUNTER. THAT IS
THE ARCHITECTURE OF EVERY COMPUTER EVER BUILT, described a
decade before one existed.
Consequences: the stored program and the diagonal argument
ββ THE STORED-PROGRAM PRINCIPLE ββββββββββββββββββββββββββββ
A PROGRAM IS JUST DATA.
The encoding β¨Mβ© is a string like any other. It can be stored
on a tape, read, copied, modified, or passed as input.
THIS IS THE MOST CONSEQUENTIAL IDEA IN COMPUTING, and
everything below is a direct descendant:
Β· GENERAL-PURPOSE COMPUTERS β one machine, many programs
Β· OPERATING SYSTEMS β programs that run other programs
Β· COMPILERS AND INTERPRETERS β programs that read programs
as input
Β· VIRTUAL MACHINES AND EMULATORS β the JVM is a universal
machine for its bytecode
Β· SELF-MODIFYING CODE, and its descendants JIT compilation
and dynamic optimisation
Β· VIRUSES AND MALWARE β programs treating other programs as
data to be altered
Β· METAPROGRAMMING, reflection, and code generation
THE VON NEUMANN ARCHITECTURE β instructions and data sharing
one memory β IS THE ENGINEERING FORM OF THIS IDEA, and it is
why a buffer overflow can execute injected data as code: THE
HARDWARE CANNOT TELL THEM APART, BECAUSE IN PRINCIPLE THERE IS
NO DIFFERENCE.
ββ THE UNIVERSAL LANGUAGE ββββββββββββββββββββββββββββββββββ
L_u = { β¨M, wβ© : M accepts w }
L_u IS RECURSIVELY ENUMERABLE β U recognises it, by
simulation.
L_u IS **NOT** RECURSIVE β this is the halting problem, and
it is the standard example of the strict containment
RECURSIVE β RE established earlier.
NOTE THE STRUCTURE OF THAT PAIR OF FACTS: THE UNIVERSAL
MACHINE PROVES THE POSITIVE HALF, AND THE DIAGONAL ARGUMENT
BELOW PROVES THE NEGATIVE HALF. Together they place L_u
exactly.
ββ WHY UNIVERSALITY MAKES UNDECIDABILITY POSSIBLE ββββββββββ
THE ENCODING IS WHAT ENABLES SELF-REFERENCE, and self-
reference is what produces the paradox.
Because β¨Mβ© is a string, one may ask what M does when RUN ON
ITS OWN DESCRIPTION β M(β¨Mβ©). That question is meaningful
only because of the encoding.
THE DIAGONAL ARGUMENT, in outline:
Suppose a machine H decides halting: H(β¨Mβ©, w) says
whether M halts on w.
Build D as follows:
"On input β¨Mβ©:
run H on (β¨Mβ©, β¨Mβ©)
if H says M HALTS on β¨Mβ©, then LOOP FOREVER
if H says M LOOPS on β¨Mβ©, then HALT"
NOW ASK WHAT D DOES ON INPUT β¨Dβ©:
if D halts on β¨Dβ©, then by construction D loops β
CONTRADICTION
if D loops on β¨Dβ©, then by construction D halts β
CONTRADICTION
Therefore H cannot exist. β
THE ARGUMENT IS EXACTLY CANTOR'S DIAGONAL ARGUMENT AND
EXACTLY THE LIAR PARADOX, in computational dress. D is a
machine that does the opposite of whatever it is predicted
to do, and its existence depends entirely on being able to
feed a machine its own description.
ββ SMALL UNIVERSAL MACHINES ββββββββββββββββββββββββββββββββ
A recreational but instructive line of research: how small can
a universal machine be?
Turing's original was large. Minsky found a 7-state,
4-symbol universal machine in 1962. The record now stands at
a 2-state, 3-symbol machine, whose universality was proved
in 2007 β though the proof's use of an infinite
non-repeating initial tape is disputed.
THE LESSON IS THE ONE FROM THE TURING-COMPLETENESS TOPIC:
UNIVERSALITY IS ACHIEVED WITH ASTONISHINGLY LITTLE
MACHINERY. A system needs only a means of branching and
unbounded storage, which is why Turing completeness turns up
unintentionally in template systems, spreadsheet formulas
and card games.
ββ THE SUMMARY βββββββββββββββββββββββββββββββββββββββββββββ
ONE MACHINE CAN DO EVERYTHING ANY MACHINE CAN DO.
THE POSITIVE READING is the computer industry: build one
general machine and program it.
THE NEGATIVE READING is undecidability: because a machine can
reason about machines, it can be asked about itself β and some
such questions have no consistent answer.
BOTH FOLLOW FROM THE SAME FACT, that a program is a string.
THE MOST POWERFUL IDEA IN COMPUTING AND ITS DEEPEST
LIMITATION ARE THE SAME IDEA.
U(β¨M, wβ©) BEHAVES EXACTLY AS M(w) β INCLUDING LOOPING WHEN M LOOPS
TAPE 1: β¨Mβ© β the ENCODING, never altered
= THE PROGRAM
TAPE 2: M's tape, holding w
= THE DATA
TAPE 3: M's current state, as 0β±
= THE PROGRAM COUNTER
THAT IS THE ARCHITECTURE OF
EVERY COMPUTER EVER BUILT β
described a decade before one existed.
Cost: a constant-factor slowdown of |β¨Mβ©| per step.
ENCODING A MACHINE AS A BINARY STRING
Ξ΄(qα΅’, Xβ±Ό) = (qβ, Xβ, Dβ) β 0β± 1 0Κ² 1 0α΅ 1 0Λ‘ 1 0α΅ (transitions separated by 11)
Ξ΄(qβ,Xβ)=(qβ,Xβ,R) β 010100100100
Ξ΄(qβ,Xβ)=(qβ,Xβ,L) β 0010010001010
full machine β 010100100100 11 0010010001010 (27 bits)
THREE CONSEQUENCES β AND THE THIRD LEADS TO THE HALTING PROBLEM
1 every TM is a FINITE BINARY STRING Β· 2 so TMs are COUNTABLE, listable as Mβ, Mβ, Mββ¦ Β· 3 a machine can be given ITSELF as input
THE DIAGONAL ARGUMENT β A MACHINE THAT DEFIES ITS OWN PREDICTION
Suppose H decides halting. Build D:
on β¨Mβ©: run H on (β¨Mβ©, β¨Mβ©)
H says HALTS β LOOP FOREVER
H says LOOPS β HALT
NOW RUN D ON β¨Dβ©:
if D halts on β¨Dβ© β by construction it LOOPS β
if D loops on β¨Dβ© β by construction it HALTS β
So H cannot exist. β (Cantor's diagonal, in machine dress.)
The positive and negative readings come from one fact. A program is a string : that makes general-purpose computers possible, and it makes self-reference possible β so a machine can be asked about itself, and some such questions have no consistent answer. Computing's most powerful idea and its deepest limitation are the same idea.
π Go further: The von Neumann architecture β instructions and data sharing one memory β is the engineering form of "a program is just data", and it is why a buffer overflow can execute injected input as code. The hardware genuinely cannot distinguish them, because in principle there is no difference. Modern defences like NX bits, W^X and address space randomisation are all attempts to reimpose a separation that the underlying model deliberately abolished β retrofitting a distinction onto an architecture whose power comes precisely from not having one. Search "von Neumann architecture code data separation NX bit W^X" .
π‘ Exam angle: define the universal machine by U(β¨M,wβ©) = M(w) , including the looping case. Be able to describe a binary encoding scheme β unary state and symbol indices separated by 1s, transitions separated by 11 β and work a small example. State the three consequences : every TM is a finite string, TMs are countable, and a machine can take itself as input. Describe the three-tape construction and identify tape 1 as program, tape 2 as data, tape 3 as program counter. Know that L_u is RE but not recursive , and be able to give the diagonal argument constructing D from a hypothetical H.
Syllabus points Encoding of a Turing machine UTM concept 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.
Related topics in Turing Machine