Theory of Computation & Computer Graphics β Turing Machine, NEC licence examination syllabus (Nepal Engineering Council).
TM as a Computing Function
Not just yes or no β a Turing machine transforms its input into an output, which is what "computing" really means.
π Where this lives: The equivalence between Turing machines and the Ξ»-calculus is the reason functional programming languages are as powerful as imperative ones. Alonzo Church's Ξ»-calculus, published the same year as Turing's paper, defines computation entirely in terms of function application with no machine, no tape and no state β and the two models compute exactly the same functions. Haskell, Lisp and the lambda expressions in modern Java and Python all descend from that formalism. Search "lambda calculus Turing equivalence functional programming".
Computing functions on the tape
A TURING MACHINE COMPUTES A FUNCTION f : Ξ£* β Ξ£* IF, STARTED
WITH w ON THE TAPE, IT HALTS WITH f(w) ON THE TAPE.
Such a machine is called a TRANSDUCER, as opposed to the
ACCEPTOR of the previous topic. The distinction is only in how
the result is read: an acceptor's answer is its final STATE, a
transducer's answer is its final TAPE.
ββ TOTAL AND PARTIAL FUNCTIONS βββββββββββββββββββββββββββββ
A TOTAL function is defined for every input.
A PARTIAL function may be undefined for some inputs β and for
a Turing machine, "undefined at w" means THE MACHINE DOES NOT
HALT ON w.
TURING MACHINES COMPUTE EXACTLY THE PARTIAL RECURSIVE
FUNCTIONS.
THOSE THAT ALWAYS HALT COMPUTE THE TOTAL RECURSIVE
FUNCTIONS.
THE CORRESPONDENCE WITH THE PREVIOUS TOPIC IS EXACT:
acceptor that may loop β recursively enumerable
language
acceptor that always halts β recursive language
transducer that may loop β partial recursive function
transducer that always
halts β total recursive function
THE SAME DISTINCTION APPEARS TWICE BECAUSE IT IS THE SAME
PHENOMENON: halting cannot be guaranteed.
ββ REPRESENTING NUMBERS ββββββββββββββββββββββββββββββββββββ
UNARY is standard in Turing machine work: the number n is
written as n consecutive 1s.
Β· 0 is the empty string or a single 0, by convention
Β· 3 is 111
Β· the pair (m, n) is written 1α΅ 0 1βΏ, with 0 as a separator
WHY UNARY RATHER THAN BINARY: arithmetic becomes trivial to
program β addition is concatenation, and comparison is
pairing off β at the price of exponentially longer tapes.
SINCE COMPUTABILITY IS THE QUESTION AND EFFICIENCY IS NOT, THE
TRADE IS WORTH IT.
BINARY IS USED WHEN COMPLEXITY MATTERS, which is why the later
complexity topics assume it: an input of value n has length
log n in binary and n in unary, and that difference is
precisely what makes some problems look polynomial in unary
and exponential in binary.
ββ WORKED: THE SUCCESSOR FUNCTION f(n) = n + 1 βββββββββββββ
Input 1βΏ, output 1βΏβΊΒΉ.
"Scan right to the first blank; write 1; halt."
TWO STATES SUFFICE. The simplest non-trivial computation
there is.
ββ WORKED: ADDITION f(m, n) = m + n ββββββββββββββββββββββββ
Input 1α΅ 0 1βΏ, output 1α΅βΊβΏ.
THE ELEGANT METHOD: the tape already holds m + n ones, just
with a 0 in the middle. So:
"1. Scan right to the 0 and REPLACE IT WITH 1.
2. Scan right to the blank, step back, and ERASE THE
LAST 1.
3. Halt."
VERIFICATION on 3 + 2, input 111011 of length 6:
after step 1: 111111 (six 1s)
after step 2: 11111 (five 1s) = 5 = 3 + 2 β
AND ON 1 + 1, input 101 of length 3:
after step 1: 111
after step 2: 11 = 2 β
AND ON 4 + 3, input 11110111 of length 8:
after step 1: 11111111
after step 2: 1111111 = 7 β
THE OUTPUT IS ALWAYS ONE SHORTER THAN THE INPUT, since the
separator became a 1 and one 1 was deleted β a useful check
that the construction is right.
ββ WORKED: MULTIPLICATION f(m, n) = m Γ n ββββββββββββββββββ
Harder, and it introduces the loop-and-copy idiom:
"1. Mark the first 1 of the m-block.
2. Copy the entire n-block to the far right of the tape,
after a delimiter.
3. Return, mark the next 1 of the m-block, and repeat
from step 2.
4. When every 1 of the m-block is marked, erase
everything except the copied region.
5. Halt."
THE n-BLOCK IS COPIED m TIMES, giving m Γ n ones. THE
MACHINE HAS IMPLEMENTED A LOOP, with the marks on the
m-block serving as the loop counter.
ββ WORKED: PROPER SUBTRACTION ββββββββββββββββββββββββββββββ
f(m, n) = m β n if m β₯ n, and 0 otherwise
("proper" or "monus" subtraction, since the naturals have no
negatives).
"Repeat: erase one 1 from each block. Stop when either
block is exhausted. If the n-block emptied first, what
remains of the m-block is the answer; otherwise the
answer is 0."
THE SAME PAIRING IDIOM AS THE aβΏbβΏ RECOGNISER, used
arithmetically.
Recursive functions and the equivalence
ββ THE ΞΌ-RECURSIVE FUNCTIONS βββββββββββββββββββββββββββββββ
An entirely different formalisation of computation, developed
by GΓΆdel and Kleene, which turns out to define exactly the
same class of functions.
THE INITIAL FUNCTIONS:
ZERO Z(x) = 0
SUCCESSOR S(x) = x + 1
PROJECTION Pα΅’βΏ(xβ,β¦,xβ) = xα΅’
THE OPERATIONS THAT BUILD NEW FUNCTIONS:
1. COMPOSITION
h(xΜ) = f( gβ(xΜ), β¦, gβ(xΜ) )
2. PRIMITIVE RECURSION
h(xΜ, 0) = f(xΜ)
h(xΜ, n+1) = g( xΜ, n, h(xΜ, n) )
β definition by recursion on one argument, with the
recursion guaranteed to terminate because n decreases.
3. MINIMISATION (the ΞΌ-operator)
h(xΜ) = ΞΌy [ f(xΜ, y) = 0 ]
β "the SMALLEST y making f(xΜ, y) zero".
THIS IS AN UNBOUNDED SEARCH, and it is the only operation
that can fail to terminate: if no such y exists, the
search runs forever.
THE FUNCTIONS BUILT WITHOUT MINIMISATION ARE THE PRIMITIVE
RECURSIVE FUNCTIONS. Adding minimisation gives the
ΞΌ-RECURSIVE (partial recursive) FUNCTIONS.
THE THEOREM:
A FUNCTION IS COMPUTABLE BY A TURING MACHINE IF AND ONLY
IF IT IS ΞΌ-RECURSIVE.
AND THE INSTRUCTIVE PART: MINIMISATION IS EXACTLY WHAT
CORRESPONDS TO A POSSIBLY-NON-HALTING COMPUTATION. Primitive
recursive functions are all TOTAL β every one of them always
terminates β because every loop is bounded in advance. THE
UNBOUNDED SEARCH IS THE "while" LOOP, AND THE "while" LOOP IS
WHERE NON-TERMINATION LIVES.
THIS MAPS DIRECTLY ONTO PROGRAMMING: a language with only
"for" loops of predetermined length computes exactly the
primitive recursive functions and always terminates; adding
"while" makes it Turing complete and makes termination
undecidable. THE TRADE IS UNAVOIDABLE AND IS MADE
DELIBERATELY IN TOTAL FUNCTIONAL LANGUAGES AND IN PROOF
ASSISTANTS, WHICH RESTRICT RECURSION TO GUARANTEE
TERMINATION.
ββ THE ACKERMANN FUNCTION ββββββββββββββββββββββββββββββββββ
A famous witness that the primitive recursive functions are a
PROPER subset:
A(0, n) = n + 1
A(m, 0) = A(m β 1, 1)
A(m, n) = A(m β 1, A(m, n β 1))
IT IS TOTAL AND COMPUTABLE β it always terminates and a
Turing machine can evaluate it β BUT IT IS NOT PRIMITIVE
RECURSIVE, because it grows faster than any primitive
recursive function.
A(4, 2) already has 19,729 digits.
SO "ALWAYS TERMINATES" DOES NOT IMPLY "BOUNDED LOOPS ARE
ENOUGH", which is exactly why minimisation had to be added.
ββ THE MODELS THAT ALL AGREE βββββββββββββββββββββββββββββββ
TURING MACHINES (Turing, 1936)
Ξ»-CALCULUS (Church, 1936)
ΞΌ-RECURSIVE FUNCTIONS (GΓΆdel, Kleene)
POST SYSTEMS (Post, 1936)
REGISTER MACHINES (Minsky)
CELLULAR AUTOMATA
every programming language
ALL PROVED EQUIVALENT IN WHAT THEY COMPUTE. THREE OF THEM WERE
PUBLISHED IN THE SAME YEAR, BY PEOPLE APPROACHING THE PROBLEM
FROM MACHINES, FROM FUNCTIONS AND FROM LOGIC β and they landed
on the same class.
THAT CONVERGENCE IS THE EVIDENCE FOR THE CHURCH-TURING
THESIS, and it is the same form of argument used for regular
languages, where four definitions converged. Here it
supports a far bolder claim: that this class is not one
notion of computation among many, but COMPUTATION ITSELF.
Minimisation β the unbounded search ΞΌy β is the while loop, and it is the only operation in the whole recursive-function framework that can fail to terminate. A language with only bounded for loops computes exactly the primitive recursive functions and always halts; adding while buys Turing completeness and costs decidable termination.
π Go further: That trade-off is made deliberately in real systems. Proof assistants like Coq and Agda, and total functional languages like Idris in its total fragment, restrict recursion so that every function provably terminates β which means they are not Turing complete, and cannot express every computable function. That is the point: a language whose programs always terminate can have its properties checked mechanically, which is exactly what a proof assistant needs. They give up universality to buy decidability, which is the same bargain the LBA makes with its bounded tape. Search "total functional programming Coq termination checker structural recursion".
π‘ Exam angle: define a transducer and note that "undefined" means "does not halt", giving the partial versus total recursive distinction. Know unary representation β n as 1βΏ, the pair (m,n) as 1α΅01βΏ β and be able to describe machines for successor, addition, multiplication and proper subtraction; the addition trick (replace the 0 with a 1, then delete one 1) is the most likely to be asked. List the initial functions and the three operations, and explain that minimisation is the sole source of non-termination and corresponds to the while loop. Mention the Ackermann function as total but not primitive recursive, and name the equivalent models supporting the Church-Turing thesis.
Syllabus points
Computing functions with a TM
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.