Theory of Computation & Computer Graphics β Turing Machine, NEC licence examination syllabus (Nepal Engineering Council).
TM as an Enumerator
A machine that generates a language rather than testing it β and the reason "recursively enumerable" carries that name.
π Where this lives: The dovetailing technique in this topic is how a search engine crawls the web. There are infinitely many pages to fetch and each fetch might hang forever, so a crawler cannot process one site to completion before starting the next. It interleaves β a little work on each of many tasks, round-robin β so that no single stalled request blocks the rest. That is precisely the enumeration strategy proved correct here. Search "dovetailing interleaved computation fair scheduling crawler".
Enumerators and the equivalence theorem
AN ENUMERATOR IS A TURING MACHINE WITH AN ATTACHED PRINTER.
It takes NO INPUT. It runs, and from time to time it PRINTS a
string. THE LANGUAGE ENUMERATED IS THE SET OF STRINGS IT
EVENTUALLY PRINTS.
THREE PROPERTIES WORTH STATING IMMEDIATELY:
Β· IT MAY RUN FOREVER β indeed it must, if the language is
infinite.
Β· THE ORDER IS ARBITRARY unless the definition requires
otherwise.
Β· REPETITIONS ARE ALLOWED. A string printed twice is in the
language once; the language is a SET.
ββ THE THEOREM βββββββββββββββββββββββββββββββββββββββββββββ
A LANGUAGE IS RECURSIVELY ENUMERABLE IF AND ONLY IF SOME
ENUMERATOR ENUMERATES IT.
THIS IS WHERE THE NAME COMES FROM. "Recursively enumerable"
means, literally, "can be listed by a machine" β and the
theorem shows that listing and recognising are the same
capability viewed from two sides.
ββ DIRECTION 1: ENUMERATOR β RECOGNISER ββββββββββββββββββββ
THE EASY DIRECTION.
Given an enumerator E for L, build a recogniser M:
"On input w: run E. Each time E prints a string,
compare it with w. If they match, ACCEPT."
IF w β L, E EVENTUALLY PRINTS IT, so M accepts in finite
time.
IF w β L, E NEVER PRINTS IT, so M runs forever β WHICH IS
EXACTLY WHAT A RECOGNISER IS PERMITTED TO DO.
NOTE HOW THE PERMITTED NON-HALTING IS ESSENTIAL. A decider
could not be built this way, because M has no way to know
that E will never print w.
ββ DIRECTION 2: RECOGNISER β ENUMERATOR ββββββββββββββββββββ
THE HARDER DIRECTION, AND THE ONE THAT NEEDS DOVETAILING.
THE NAIVE ATTEMPT FAILS. One might write:
"For each string sβ, sβ, sβ, β¦ in turn: run M on sα΅’;
if it accepts, print sα΅’."
THIS IS WRONG. If M loops on sβ, the enumerator is stuck
forever and never reaches sβ β even though sβ might be in L.
A SINGLE NON-HALTING COMPUTATION BLOCKS THE ENTIRE
ENUMERATION.
THE DOVETAILING FIX:
"For i = 1, 2, 3, β¦
run M for i STEPS on each of the first i strings
sβ, β¦, sα΅’.
Print any string that has accepted."
NO COMPUTATION IS EVER RUN TO COMPLETION IN ONE GO β each
gets a bounded number of steps, and the bound grows.
WHY IT WORKS: if M accepts sβ±Ό after exactly k steps, then at
round i = max(j, k) the enumerator runs M on sβ±Ό for at least
k steps and sees the acceptance. SINCE max(j, k) IS FINITE,
EVERY ACCEPTED STRING IS PRINTED AT SOME FINITE ROUND. β
THE COST IS REDUNDANCY β round i redoes all the work of
round iβ1 β but computability is the question and efficiency
is not.
ββ THE PAIRING THAT MAKES IT WORK ββββββββββββββββββββββββββ
Dovetailing rests on the fact that PAIRS OF NATURAL NUMBERS
CAN BE ENUMERATED. Listing pairs (i, j) by DIAGONALS:
(1,1)
(1,2) (2,1)
(1,3) (2,2) (3,1)
(1,4) (2,3) (3,2) (4,1)
(1,5) (2,4) (3,3) (4,2) (5,1) β¦
giving the sequence
(1,1) (1,2) (2,1) (1,3) (2,2) (3,1) (1,4) (2,3) (3,2)
(4,1) β¦
EVERY PAIR APPEARS AT A FINITE POSITION. The pair (i, j)
sits on diagonal i + j β 1, at a position that is finite no
matter how large i and j are.
THIS IS CANTOR'S ARGUMENT THAT β Γ β IS COUNTABLE, and it is
the combinatorial engine behind every dovetailing
construction.
ββ LEXICOGRAPHIC ENUMERATION AND DECIDABILITY ββββββββββββββ
A SHARPER RESULT that separates the two classes cleanly:
A LANGUAGE IS **RECURSIVE** IF AND ONLY IF IT CAN BE
ENUMERATED IN LEXICOGRAPHIC ORDER β shortest first, and
alphabetically within each length.
THE PROOF OF THE USEFUL DIRECTION:
Suppose E enumerates L in lexicographic order. To decide
whether w β L, run E and watch its output.
Β· If w is printed, ACCEPT.
Β· IF E PRINTS ANY STRING **AFTER** w IN LEXICOGRAPHIC
ORDER, then w will never appear β REJECT.
Β· If L is finite and E stops, REJECT.
THE ORDERING SUPPLIES A STOPPING CONDITION, and that is
exactly what the arbitrary-order enumeration lacked. β
SO THE DISTINCTION BETWEEN THE TWO CLASSES REDUCES TO ONE
WORD:
RECURSIVELY ENUMERABLE β listable in SOME order
RECURSIVE β listable in SORTED order
AND THE GAP BETWEEN THEM IS THE GAP BETWEEN "IT WILL APPEAR
EVENTUALLY" AND "I CAN TELL WHEN TO STOP WAITING".
Consequences and technique
ββ ENUMERATION AS A PROOF TECHNIQUE ββββββββββββββββββββββββ
Several standard results are proved most easily by
constructing an enumerator.
CLOSURE OF RE UNDER UNION:
Given enumerators Eβ for Lβ and Eβ for Lβ, DOVETAIL THEM β
alternate steps of each, printing whatever either prints.
The result enumerates Lβ βͺ Lβ.
RUNNING Eβ TO COMPLETION FIRST WOULD FAIL, since Eβ may
never finish.
CLOSURE OF RE UNDER INTERSECTION:
Enumerate Lβ and Lβ simultaneously, keeping two growing
lists, and print any string that appears in both.
EVERY INFINITE RE LANGUAGE HAS AN INFINITE RECURSIVE SUBSET:
Enumerate L and print only those strings LONGER than every
string printed so far. The resulting subset is enumerated in
increasing length order, hence recursive by the result
above.
A LANGUAGE AND ITS COMPLEMENT BOTH RE βΉ RECURSIVE:
This is the complementation theorem of the acceptance topic,
and dovetailing is again the mechanism.
ββ THE CONNECTION TO COUNTABILITY ββββββββββββββββββββββββββ
An enumerator establishes that a language is COUNTABLE β it
puts the strings in correspondence with the natural numbers.
SINCE Ξ£* IS COUNTABLE, EVERY LANGUAGE IS COUNTABLE AS A SET,
so countability alone is not the issue. THE ISSUE IS WHETHER
THE LISTING CAN BE PRODUCED BY A MACHINE.
Β· Ξ£* itself is enumerable β list by length, then
alphabetically.
Β· The set of all TURING MACHINES is enumerable β encode each
as a string and list those strings.
Β· The set of all LANGUAGES is NOT β it is uncountable, by
Cantor's diagonal argument.
SO THERE ARE UNCOUNTABLY MANY LANGUAGES AND ONLY COUNTABLY
MANY ENUMERATORS, WHICH IS THE COUNTING PROOF THAT NON-RE
LANGUAGES EXIST, restated in the vocabulary of this topic.
ββ A CONCRETE ENUMERATOR βββββββββββββββββββββββββββββββββββ
ENUMERATING { aβΏbβΏ : n β₯ 0 }:
"For n = 0, 1, 2, 3, β¦
print aβΏbβΏ."
Output: Ξ΅, ab, aabb, aaabbb, β¦
NOTE THAT THIS IS IN LEXICOGRAPHIC ORDER BY LENGTH, which
confirms β by the theorem above β that the language is
RECURSIVE. And indeed it is: the Turing machine of the
earlier topic always halts.
ENUMERATING THE SET OF THEOREMS OF A FORMAL SYSTEM:
"Systematically generate every finite sequence of
formulas. For each, check whether it is a valid proof β
a MECHANICAL check. If so, print its last line."
THIS IS THE CLASSICAL EXAMPLE, and it is why the theorems of
arithmetic form a recursively enumerable set: PROOFS CAN BE
CHECKED MECHANICALLY EVEN THOUGH THEY CANNOT BE FOUND
MECHANICALLY.
GΓDEL'S INCOMPLETENESS THEOREM IS THE STATEMENT THAT THIS
SET IS NOT ALL TRUE STATEMENTS β and the undecidability of
the halting problem is its computational twin.
ββ THE SUMMARY βββββββββββββββββββββββββββββββββββββββββββββ
RECOGNISING and ENUMERATING are the same power.
DECIDING is strictly more.
AND THE DIFFERENCE HAS A CRISP FORM: AN ENUMERATOR IN
ARBITRARY ORDER TELLS YOU WHAT IS IN THE LANGUAGE BUT NEVER
WHAT IS OUT OF IT; AN ENUMERATOR IN SORTED ORDER TELLS YOU
BOTH, BECAUSE PASSING w WITHOUT PRINTING IT SETTLES THE
QUESTION.
The distinction between the two classes reduces to one word: recursively enumerable means listable in some order, recursive means listable in sorted order. The gap between them is the gap between "it will appear eventually" and "I can tell when to stop waiting".
π Go further: The theorems of arithmetic form a recursively enumerable set, and the reason is exactly the enumerator construction here: systematically generate every finite sequence of formulas, mechanically check whether each is a valid proof, and print the last line of any that is. Proofs can be checked mechanically even though they cannot be found mechanically. GΓΆdel's incompleteness theorem is the statement that this enumerable set is not all true statements β and the undecidability of the halting problem is its computational twin, published five years later and proved by essentially the same diagonal argument. Search "GΓΆdel incompleteness recursively enumerable theorems proof checking".
π‘ Exam angle: define an enumerator (no input, prints strings, arbitrary order, repeats allowed) and state the equivalence with recursive enumerability. The examinable proof is recogniser β enumerator: explain why the naive sequential approach fails when M loops, then give the dovetailing construction "run M for i steps on the first i strings" and the max(j,k) argument. Know the Cantor diagonal pairing that underlies it. The sharper theorem β recursive βΊ enumerable in lexicographic order β is the cleanest way to separate the classes, so give its proof and the stopping condition.
Syllabus points
Enumerating strings of a language
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.