Introduction To Computer Theory by Cohen Solutions Manual
Introduction To Computer Theory by Cohen Solutions Manual
ele To =
OMS
Bie
_SESOND EDITION |
Se
Ws PREPARED oY |
py CHANAH BRENENSON
Digitized by the Internet Archive
In 2022 with funding from
Kahle/Austin Foundation
https://archive.org/details/solutionsmanualt0000bren
SOLUTIONS MANUAL
TO ACCOMPANY
INTRODUCTION TO
COMPUTER THEORY
SECOND EDITION
DANIEL I. A. COHEN
Hunter College
City University of New York
Prepared by
CHANAH BRENENSON
=a
m¢es#8- 2 4 2 .)
=
Fer)
08 8
ie
tee) ed
CONTENTS
Chapter |
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Chapter 11
Chapter 12
Chapter 13
Chapter 14
Chapter 15
Chapter 16
Chapter 17
Chapter 18
Chapter 19
Chapter 20
Chapter 21
Chapter 22
Chapter 23
Chapter 24
Chapter 25
“4
a ae ee :
| ——— a
7 _
-
CHAPTER 1
The main goal of this chapter is to give at least a vague idea of what Computer Theory
might be and why it might be studied. This course is often required of all majors and so
they enrol without even the usual pretense of acting volitionally. Unlike courses offering
programming skills this one is not primarily vocational -- it is, of course indirectly of benefit
to the art of programming, but it’s main thrust is intellectual enrichment. Plumbers may not
know exactly who invented plumbing but they do know why, and perhaps how, it came
about. For all their mental achievements programmers generally have no basis for
answering this same question about their profession.
Computer Science majors are very suspicious about being slipped extra theoretical math
courses under the guise of "this will be good for you somehow." To allay this fear we
emphasize that this is not a course in mathematics as such but a course in mathematical
models, a friendly technique that arises in social science and linguistics and other
unthreatening subjects. Of course, this is a course in mathematics. Haha. But the joke
is more on the mathematical community who have no idea what beautiful results lie in this
disenfranchised corner of their discipline -- this despite the fact that its grandfathers,
Hilbert, Gédel, Church, von Neuman et al., are held in reverence for their other, more
“pure” contributions.
In general the format of this text is in the classical theorem-proof-theorem-proof model, but
unfortunately most students who need to know the material in this course are (functionally)
mathematically illiterate. Even if they have been forced to take a course in Calculus or
Linear Algebra they have almost no conception of what it means to prove anything. Worse
yet, they are afraid of ever being responsible for constructing proofs themselves. This
book is realistically sensitive to this deplorable situation and it takes great pains to
assuage such anxiety. This is a gentle introduction to the art of providing convincing
explanations (i.e. proofs) for proposed propositions that may even usefully serve as a
primer for those math majors who suffer from proof-anxiety.
For the student who is more sophisticated mathematically there are other texts which
cover approximately this same material in many fewer pages. Some of these books are
excellent. We can recommend, without reservation, the following list from our own
experience: Hopcroft and Ullman, Lewis and Papadimetriou, Mana, Harrison, Kain, Minsky,
etc. No claim is made that this list is exhaustive and there may be many more texts of
recent vintage of which we are unaware.
Students should be informed about these books as possible other sources of reference,
though they should be cautioned about the vast disparity that may exist in notation and be
alerted to possible subtle differences in definitions. If any of these books are approached
they should be read from page one.
Before our current book was released there was some confusion as to whether the books
listed above were texts for graduate courses or undergraduate courses. There is a strong
2
Even though it is certainly true that the books listed above are more advanced this does
not mean that they contain everything of value that is in our text. There are original
contributions to be found among these pages, not original theorems but some new ideas
in the proofs, some original problems, some useful examples and many instances where
an idea that is only vaguely sketched in other sources is made explicit here. (Sometimes
making an idea explicit can seem painful or frightening, but there is always what seems
to us a good justification for giving a student more than just the impression that she knows
what is going on.)
If a student finds this book easy, let her read through it quickly. There are 600 pages here
and no one is going to read it over night, but we believe strongly that a bright student
should be encouraged to set her own pace. For the strongest foundation in this subject
one might start by finishing this book and then read one (or all) of the texts mentioned
before. A student who approaches the more advanced books already knowing most of the
material in them (our material) will not only have an easier time reading but will develop
an appreciation for the power of the advanced mathematical notation for its efficiency and
Clarity of abstraction.
We generally avoid advanced mathematical notation for two reasons: psychological and
pedagogical. The fear and alienation engendered by a page of symbols more than
neutralizes the efficacy of introducing the notation as it defeats the purpose of education.
It is also true that far too often a student (or a professional mathematician) gets a false
sense of confidence in the material by merely having followed the manipulation of the
symbols on the paper. We have too frequently heard, "I! followed everything you did in
class but | couldn't do the problems." It is our belief that the hasty adoption of abstract
notation is largely responsible for this predicament. Notation should be introduced only
when a student feels that her thoughts are flying faster than her ability to express them.
At that point students should be encouraged to invent their own personalized shorthand
bearing their own private meanings. Only as a final stage, when the need for a
standardized medium of communications becomes clear, should symbolism be introduced.
The important mistake not to make is to feel that a subject becomes more rigorous, more
precise or more mathematical because it is riddled with symbols. Greek letters are no
more exact than the English words that defined them. Many shoddy proofs go undetected
because they are disguised in opaque notation. If an argument is rigorous in symbols it
remains rigorous when expressed in English sentences. What it takes us 600 pages to
do here could have been condensed to fifty -- with complete loss of educational value.
CHAPTER 2
It is important to distinguish for the student what material from this chapter will be required
in the future and what will not. Obviously the silly languages L,, L,, L, and , are not
important for the rest of the book, though they do reappear briefly in Chapter 3. On the
other hand the language PALINDROME must become a member of our immediate family.
A big fuss should be made about the null word and the Kleene star. We have found that
Theorem 1 is a good introduction to the concept of proof. We challenge the students to
provide "an explanation of why this is true that would convince someone who didn't already
believe it." There is usually some obliging student in the class who doesn't understand the
result and when the other students try to convince him that it is not only true but painfully
obvious he is sometimes able to shake their confidence in their ability to articulate their
thoughts. This is the beginning of the understanding of what proof is all about.
| have assumed throughout the book that the readers are acquainted with standard
elementary computer programming concepts such as the notion of formal strings of
characters, concatenation, prime numbers, factorials, symbolic logic, etc. Other than that
the text is so self-contained that it defines many terms the student is already familiar with.
What could be the harm?
It is our habit to give exactly 20 questions per chapter many of which have multiple parts.
Problem # 20 is usually more theoretical in nature and often quite challenging. Sometimes
#20 is so difficult that it contains a hint that gives virtuaily the whole problem away. This
#20 is not too hard.
Chapter Two
5 words of length 4; 8 words of length 13; 13 words of length 6. In general, the number of
words of length n is the sum of the number of words of length (n-1) and the number of
words of length (n-2), a Fibonacci sequence.
(mi) Continuing the proofs above applied now to the palindrome string z", repeatedly remove
two copies of z at a time, one from either end, until if n is odd only a palindrome
string z remains. Ifn is even, then stop shrinking the string when zz remains. Note
that any palindrome can be viewed as a string concatenated with its own reverse. zz
is palindrome and zz = z reverse(z), implies that z = reverse(z) and z is palindrome.
(iv) The are four palindromes of length 3; aaa, aba, bab, bbb and of length 4; aaaa, abba,
baab, bbbb. For each odd length palindrome insert another copy of the middle
letter adjacent to it to make an even length palindrome.
(v) By using the algorithm in part one, we can reduce any palindrome to a central core of one
or two letters. On {a, b}, there are as many palindromes of length 2 (aa, bb) as there
are of length 1 (a, b). To make palindromes of length 2n, choose a core of length 2,
and then make n-1 choices for the letters to the left which determine the letters to the
right. To make palindromes of length 2n-1, choose a core of length 1 and then make
n-1 choices for the other letters. In each case n choices determine the word. Since
there are two choices for letters, there are 2" palindrome words of length 2n or 2n-1.
(i) Sc T, so S*c T*. 5bbd is the only word in T but not in S. However, bb € S so bbbb
e€ S* and T* c S*, therefore S* = T*.
(ii) Sc T, so S*c T*. However there is no way to generate bbb with the elements of S, so
Si71 Tt.
(iii) S* = T* even though S # T only when all the words in the symmetric difference can be
generated by words in the intersection.
ee (i) (S*)* includes A even is S does not, so (S*)*= S*. S* = S** by Theorem 1.
(ii) There can be no factor in (S*) that is not in S*, (S*)" cS’. In general, any set
is contained in its positive closure, S* < (S*)’. Therefore (S")’ = S”.
(iii) Yes. IfA € S, then S* = S*. (S*)* = (S*)* = (S*)*. IfA € S then A € S* anyway, and
(S*)' =(S*)* = S*=S*UA = (S*)*.
12, No words in S* contain an odd number of b's (each factor contributes two if any), so none
of the examples is in the set.
Chapter Two
Is. This is the same as saying that the language L would allow all concatenations that did not
produce squares. First observe that A= AA, so A cannot be in the language. Consider
Ww, #W, andw,w,€L. Letw=ww, sinceA€Ll, wW#w, sow =Www, €L where
W, # W,, finally let w, = w,w, € L. However, w; = w,w,w,W, = W3W; Which is a square so
ws € L.
16. Let S = {aaa}, S* has one six-letter word and no seven-letter words nor eight-letter words.
However it is impossible for S* for any S to contain more six-letter words than twelve-letter
words because for every six-letter word w there is a twelve-letter word ww in S*.
18. (iv) S* and T* both represent the set of all strings of a's and b's. Therefore T must include
at least the words a and b, which is the set S.
(v) S={a, bb}, T= {a, aa, bb }.
20. Since T is closed and S c T, any factors in S concatenated together two at a time will be a
word in T. Likewise concatenating factors in S any number of times produces a word in T.
That is any word in S* is also in T. However we are given that T + S* so T contains some
words that are not in S*. We can conclude that S* is a proper subset of T, in other words S*
is smaller than T, and in symbols S* c T.
CHAPTER 3
Computer Science majors are familiar with the term "recursive programming" and this will
be very helpful with the concept of recursive definitions. The same idea of self-reference
is not carried over directly to "recursively enumerable" since that is a back formation from
"recursive functions." Students should be told not to worry that the mathematical examples
of polynomial and derivative set a precedent of a strong connection between this course
and mathematical analysis. These examples are just too perfect not to have been
included. if Calculus were properly taught the concept of recursive definition would have
been introduced there.
Why have we defined recursion but avoided all reference to proof by mathematical
induction. The answer is simply that we hate proofs by mathematical induction. They
verify the truth of a result without shedding any understanding of why the claim is true or
where it came from. It is a fine tool for research but a poor one for education. It is
employed by lazy authors who wish to compress as many results into as short a space as
possible. The benefit of this in a textbook is a mystery to me.
Chapter Three
Rule 1: xismL,
Rule 2: [fw is in L, then so is wx.
2+2=4
4+2=6 4+4=8
12+2=14
We must show 1) that all positive even numbers can be produced from this definition and 2)
that the definition produces nothing else.
1) We have 2 and 4 and 2+4=6, 4+4=8, 6+4=10, 8+4=12, ..., so ifthere is an even number
that cannot be produced from this definition it is large. Let us suppose that there are some
such numbers and let us call the smallest of them n, (that is n is the smallest even number that
cannot be produced from this definition). But that means that all smaller even numbers can
be produced by this definition, and in particular, that n-4 can be produced. So to produce n,
we apply rule Rule 2 to n-4. Since there is no smallest even number that cannot be produced
from this definition, all even numbers can.
2) How can we produce an odd number from this definition? If we add an even number to
some arbitrary integer n the resulting sum has the same parity as n. The increment in the
definition, 4, is even. Both of the elements known to be in the set (2 and 4) are even.
Chapter Three
Therefore application of Rule 2 will never alter the parity, and all numbers in the set will be
even.
We can make up any rules as long as they do not change the parity and providing that they
cover all cases. IfRule 1 lists the smallest n even numbers and the increment in Rule 2 is 2n
(the next highest in the set), both conditions are met. There are infinitely many such lists of
rules.
(a) 3 is nm ALEX (Rule 1). x is in ALEX (Rule 2). 3x is n ALEX (Rule 3). 2 is in
ALEX (Rule 1). x+2 is in ALEX (Rule 3). Therefore by ALEX Rule 1, x+2 and 3x
are both m ALEX. Since x+2 is n ALEX, by Rule 2a, so is (x+2) and by Rule 2g, so
is (x+2)™.
(b) Elementary calculus contains rules for differentiating sums, differences, products,
quotients, and exponetiations of differntiable functions. By the rules given here, if
these functions are polynomials, they are composed only of elements that are
differentiable functions and are therefore differentiable.
(c) No, when it is a matter of polynomials, the permissible functions are all defined in the
other rules.
(((((3)x)+7)x)-9) contains only two products: the product of 3 and x and the product of
(((3)x)+7) and x.
Chapter Three
LS: Not without very careful stipulation of many contingencies. It is much more practical to
allow them to accumulate and eliminate redundancy in (or reduce) the configuration later.
17. This is the set of positive rational numbers. Starting with Rule 1 and applying addition, we
get the positive natural numbers. Then applying x/y, we get all the fractions.
Chapter Three
20. (i) xyz can be any word in the set. Rule | gives us an initial element. So far 3-
PERMUTATION = {123}. Let xyz = 123 and applying rule 2 gives zyx = 321 and
yzx = 231. So far our set is {123, 321, 231}. Now let xyz be a different element in
the set; xyz = 321. Applying rule 2 on xyz = 321 gives zyx = 123 and yzx = 213.
Only the second string is a new element, when added makes {123, 321, 231, 213}.
Apply rule 2 on xyz = 231 gives zyx = 132 and yzx = 312. Both ofthese can be
added to our set, hence {123, 321, 231, 213, 132, 312 }. Applying the rule to the
remaining three elements , 213, 132 and 312 does not generate any new elments so
we have verified the six 3-PERMUTATION’s.
(ii) Of the 24 possible arrangements of the digits 1, 2, 3, 4, only these 8 can be obtained from
this definition by the same method detailed in part (i):
1234 4321 2341 3214 1432 3412 4123 2143
12
CHAPTER 4
Throughout the text we stick to the alphabet {a,b} instead of the more logical alphabet
{0,1}. We are not the only text to do this. We find that O and 1 are hopelessly overworked
in Computer Science already: boolean, binary, bit string etc. We already use the plus sign
for disjunction and for union; if it sat between bit strings the temptation to mistake it for
addition would be too great.
In the text we emphasize the distinction between a language defining expression and the
language it defines -- perhaps we over emphasize this. In class we are certainly much
more careless. The fact that r* really means (r)* is another example of the confusion of
word and object that should be made clear. In this chapter we begin the theme of finite
versus infinite. The only infinite that we can really deal with is that which can be made
finite. In future chapters this motif will echo furiously.
The distinction we belabor between having a well-defined language (by regular expression
say) and actually Knowing what the language is, is crucial to understanding that the
concept of meaning is not (yet) properly part of mathematics. Hence there are no
algorithms for it and no theorems about it. This is what it is that makes Artificial
Intelligence artificial.
The complicated regular expression for the language EVEN-EVEN is worth covering since
this language will appear many times throughout the text. It will be revisited every time we
introduce a new characteristic of languages.
13
Chapter Four
The language associated with (r, + r,)r, is the language of all words made up of an initial
factor from the language associated with either r, or r, and a second factor from the language
associated with r,. The language associated with r,r, + rr, is the language of all words of
the following two types: a factor from the language associated with r, followed by a factor
from the language associated with r, or else a factor from the language associated with yr,
followed by a factor from the language associated with r,. But these are merely two ways of
saying the same thing: all words in either language must end with a factor from the language
associated with r,, and the first factor must be from languages associated with either r, or
r.
a* b a* b a* (b + A) a*
Building on previous results, we have the language aaa but no triple 5, to which we add its
a-b complement: the language with bbb but no triple a.
a*((b + bb)aa*)*(b + bb + A) aaa a*((b + bb)aa*)*(b + bb + A)
+ b*((a + aa) bb*)*(a + aa + A) bbb b*((a + aa)bb*)*(a + aa + A)
(i) b*a*
(ii) (at+ba)*b* + b* a(at+ba)* (A+ b)
10. b* (ab*ab*a)* b*
12. (i) (atb)* ab (at+b)* is a regular expression for the language of all words containing the
substring ab: arbitrary ab arbitrary. (at+b)* a (atb)* b (atb)* is a similar regular
expression of the form arbitrary a arbitrary b arbitrary. The difference is the
additional requirement of some string between the mandatory a and b. Soto show
equivalence, we need to show that for all choices for the middle arbitrary string, a
14
Chapter Four
arbitrary b contains an ab. In all cases, once an ab is located then the substrings to
the left and right each become the new choices for the front and back arbitrary’s. If
the middle arbitrary = A, then the expressions are clearly identical. Ifthe middle
arbitrary contains the mandatory ab then just redefine the origins of the substrings
on either side. Otherwise the middle arbitrary does not contains the mandatory ab.
In this case the substring must either start with a 5 or end with an a, either way an
ab is formed by using the mandatory a or b that surround the middle arbitrary string.
Therefore the two expressions are equivalent.
(i1) (at+b)* ab (at+b)* represents all the strings containing the substring ab. Compared
with all possible strings of a's and b's, there are three types of strings missing: strings
of all a's, strings of all b's, and strings in which all b's precedes all a's. Since b*a*
contributes all these missing strings, the union is (at+b)*.
(iti) | Substituting (a+b)* for the expression in the brackets gives an equivalent expression
as proved in part (ii). Now the resulting expression is exactly the same as above.
(iv) | Wecan keep making substitutions of this kind, so there are infinitely more beasts in
the cave.
13: (i) Every word in S* is the concatenate of some finite number of words from S. Let us say
w is the concatenation of k words from S, then w is also an element of SX. Therefore if we
take the union of S* for all k, we get S*.
(ii) Obvious.
14. No. Let L=(atb)*. L and L* differ by only A, but L” and L* differ by A, a, and 3.
15; (i) (ab)*a alternates the a's and b's and tacks on an a at the end. a(ba)* starts with an
a and then alternates the b's and a's. Both define odd length strings the no double
letters, where every word begins and ends in a.
(ii) (a*+b)* can not generate more words than (at+b)* which already generates
everything. Moreover a* can just as easily be generated by (a+b)*.
(ii) Again (a*+b*)* can not generate more words than (at+b)* and either factor can just
as easily be generated by (atb)*.
16. (1) A* is all the words produced by concatenating factors of length zero. There is only
one such word, A.
(11) a*bis the language of all words that have exactly one b which is the last letter. Its
Kleene closure, (a*b)*, is the language of all words that do not end in a.
Concatenating the a* permits words to end ina. So (a*b)*a* gives all words over
{a, b}. Symmetrically, ba* is all the words that have one 3S, the first letter. Its
closure is all words that begin with 56. Concatenating the initial a* gives all words
over {a, b}, so the regular expressions define the same language.
(iii) Similar to the previous problem only this time both expressions define the language
of all words over {a, b} where the 5's occur in clumps divisible by three.
Chapter Four
17. (i) (atbb)*aa describes the language of string where 5's occur in even clumps and every
word ends in double a. Apply closure only adds the null word, because we can
already use the factor inside the parentheses to make any strings of aa.
(ii) Both expressions define all strings of only a's. (aa)* gives the even length strings and
then (A+a) gives the option of having no a’s at all or an odd number.
(ii) a(aa)* gives all strings with an odd number of a's. (A+a) gives the option of even length
strings of a's. Every word must have one final 6. +b allows for the string with no a's.
This is the same as any number of a's if any followed by a single b; a*b.
(iv) a(bata)*b describes words that begin with a and end with 5. In the body of any word
b's are always followed by an a (which prevents clumps of 5's), however the clumps
of a's are unrestricted. The associated language contains all strings where each b is
surrounded by at least one a on either side and that ends in b. aa*b(aa*b)*
describes the same language where each d is preceded by at least one a.
(v) The three cases are clear in the first regular expression: A or all words that begin with a
or all words that contain the substring aa. Since the entire second expression is
starred, it produces A. The second factor of the second expression (ab*)* generates
all words that begins with a. If the first factor, (b*a)* is taken at least once then the
last one juxtaposed with ab* produces the desired double a; ...b*aab*....
ibs). (i) R=SR+T defines R as containing all the words in T and also all words composed of an
initial part from S concatenated with another words from R. This permits us to
continue concatenating factors from S as many times as we like, but we are still
required to finish the word with a factor from R. The only type of factor from R that
does not entail this kind of recursion is a factor from the language T. So we have any
number of factors from S followed by a factor from T, or we have just a factor from
T, equivalently S*T.
(ii) R=S*T defines R as words with any number (if any) factors from S followed by a single
factor from T. If the star operator is taken for zero, we have for R any word in T.
Suppose the star operator is taken once, then we have exactly one word from S —
followed by one word from T. But the word from T is itself a factor from R, so we
can see that this word is in the set SR. Consider what happens if we take the star
more than once; the star operates on S, so we have SR, SSR, SSSR.... all in the set
S*T. In fact, we established S*T in this way. The difference between S*T and S°T
is that only S*T contains T. But that means that S*T must equal exactly SR+T.
16
Chapter Four
20. (i) It is easiest to understand this in terms of the recursive definition of regular expressions.
Any letter of the alphabet is itself. a regular expression. The rule for forming regular
expressions apply to these and to all more complicated regular expressions. Each
regular expression describes a set. Equivalent expressions describe equivalent sets.
The equivalences are not disturbed by taking unions, products, or Kleene closures.
This means that any set must be considered a building block in the construction of
other sets.
(ii) With R = (ba*)* and S = (b+A), we have
(R*S)* R* = R* (SR*)*
CHAPTER 5
It is the policy of this text to define all machines in terms of their pictorial representation
and base all proofs about the machines on the ability to argue from the pictures. It is
therefore important that this ability be developed as early as possible. This chapter
contains no theorems, only a definition and illustrations, yet it is very important to begin
the ability to reason from pictures at this stage. Students should be reassured that
although there is also a non-pictorial tabular representation of these machines the pictorial
representations are every bit as sound a mathematical object.
All the pictures in this chapter of FA's are planar graphs whose edges are drawn without
crossing. Students sometimes need to be informed that if the pictorial representation
requires crossed edges this is perfectly fine so long as they are drawn so that no confusion
arises.
Chapter Five
E
Chapter Five
(1) (ii)
If all the states in an FA are final then automatically all
strings are accepted because no matter where the string
ends its accepted.
(iti) | Not necessarily, for the non-plus states may be unreachable as in the following FA:
ab a a,b
>)
(i)
(ii)
(iti)
20
Chapter Five
10.
a,
21
Chapter Five
(il)
C0 © ¢ }
oe b : b a,b b a bh b
a a,b co © me ; 7@) iO
b a,b b b b b A
a,b b a
(11) Transition tables for two-state machine has four cells, (two rows and two columns).
Each may be filled with 1 or 2. So there are 2* possibilities. There are still the same
four ways to designate final states. Hence the total number of different transition
tables is suprise 64, (2°4).
ive An FA with a designated start state and two other states can have up to three final states if
any at all. There is only one way it can have no final states, there are three ways it can have
one final state, there are three ways that it can have two final states, and only one way that
the FA can have three final states. For each of these 8 possibilities, there are 6 transitions
each of which can have one of three destinations. In total, there are 3°8 = 729*8 = 5832
different finite automata of three states.
2.
(iii) The language accepted by NIF is the reverse of every word in the language accepted by
FIN. If there was a path from one state to another on FIN by a sequence of letters,
then there must be a path on NIF using the sequence backwards.
(iv) The FIN pictured above accepts the non-palindrome words ab and FIN = NIF.
22
Chapter Five
(ii)
L5,
16.
a.b a
17 (i) The language of odd length words over {a,b} that end with a.
(ii) The language of all words over {a,b} of even length that end with a.
(ii) The language of all words over {a,b} of even length that have a's in all even numbered
positions.
(iv) (aatab+bat+bb)*a
(at+b)(aatab+bat+bb)*a
(aat+ba)*(aatba)
18. We start in state 1 and remain there until we encounter an a. State 2 = we have just read an
a. Scan any a's and return to state 1 on reading c. State 3 = we have read a 5 following an
23
Chapter Five
a. Reading an a puts us back to state 2 and reading a D sets us back to state 1. However
state 4 = we have just found a substring abc, and if the whole sequence was read the string
is accepted.
Now states 4, 5 and 6 exactly mirror states 1, 2 and 3. Returning to state 1 indicates that we
just found another occurrence of the substring abc. Being in one of the first three states
means that we have read an even number of abc substrings (if any) and are in the midst of
finding another one. Ending in an accepting state, 4, 5 or 6, means that we have read an odd
number of abc's.
ee (i) This FA starts out like a binary tree. For the first three letters of the input, each time we
read a letter we reach some node on the next level. However reading any more letters
traps us in the dead end state at the bottom. So no word of more than three letters
can be accepted.
(11) There are exactly three final states in the machine. Concatenation of the labels on the
transitions to these states shows that the machine accepts the words a, aab and bab.
(iii) Eliminate the three existing pluses. Place new pluses in each of the following states, the
right-most node on level two, the third node from the left on level three and the
second node from the right also on level three.
(iv) Each of the 15 possible strings with less than four letters is represented by one of the
nodes (excluding the dead end state). (Note the lexicographic order.) Simply mark
those nodes that represent the words in the language with plus signs.
(v) Since L is finite, we can determine the longest word and then build a binary tree large
enough to accommodate it. Next we add a dead end state with transitions from all
the leaves and itself: For every word in L, we place a plus in the appropriate, unique
state.
20. Even though the binary tree is infinite, the machine retains its uniqueness property (of the
machines described in problem 19) that the path for every string ends in a different state.
Surely just by placing the plus signs in the nodes that represent words in L would constitute
an Infinite Automata. However, the machine obviously fails to define the language because
no one can write an down the infinitely large picture.
24
CHAPTER 6
It is stated in the text that TG's were invented in 1957 to simplify the proof of Theorem 6
which (as we see later) was proved in 1956. Clearly the 1956 version of Kleene's
Theorem did not explicitly mention TG's. We are committed to develop this subject in
logical order, not chronological order. Paradoxically, the oldest mathematics in the book
is the material at the end.
The transpose operator of problem #17 will be brought up again later and it may be useful
to cover it now.
2)
Chapter Six
2n1 6 (1)7 ah ba bb
a
If the TG has an odd number of states, simply add another state. If your definition insists that
the graph be connected, then add an edge from that state to any other state with an arbitrary
label. With no transitions to enter the new state, it can not possibly interfere with the
language accepted.
There are infinitely many TG's with two states over any non-empty alphabet.
Proof by constructive algorithm: Ifthe TG has no plus state, then we must add a plus state
that cannot be reached from the start state. Ifthe TG has only one plus state, no conversion
is necessary. Otherwise, add a new plus state. Then for every original final state, delete the
plus and add a A-transition from that state to the new plus state. Any string that was
accepted by the old machine will be accepted by the new one by taking the A-move, and no
string will be able to reach the new + state that could not reach one of the final states on the
old machine.
26
Chapter Six
(i) There are many machines that accept this (and other any finite) language. One way to
build this FA is to designate a start state. For every word in L, add a plus state and
a transition from the start state with the word as the label.
(ii) Two states are required; a start state and a final state. The one edge should be labeled
with each word in the language, ie. w, W, W, ...W, The reason why one state is not
enough is that the word x which is a concatenation of two words in the language
would then be accepted even though x is not in the language and there is no label x.
Make a new designated start state. Add two A-transition edges, one to the start state of TG1
and one to the start state of TG2. The final states remain the same as on the individual
machines. The resulting machine TG3 now accepts all the words that used to be accepted by
TGI by taking the A-edge to the old start state on TG1 and continuing to a final state.
Similarly TG3 accepts all the words that were accepted by TG2 and finally accepts no words
that were not accepted by either TG1 or TG2.
10. This time no new states will be necessary. Simply add A-transitions from every plus state in
TGI to every start state of TG2. Next erase the minus from the TG2's start state. Finally
delete all the pluses from any state that came from TG1, leaving the pluses in TG2's states
unchanged. The resulting machine TG4 is a connected graph that accepts words that are the
concatenation of a word from L1 followed by a word from L2.
ae L*. L* must contain A, and unless A was a word in L originally, it will not be accepted by
the modified machine.
12; (i) Ifthere are no transitions that lead into the start state then we can simply make this a final
state as well. Otherwise we can add a new state marked + with a A-edge to the
original start state and then remove the old minus sign.
(ii) Add A-transitions from all final states back to the start state. IfL1 includes A then stop
otherwise now apply one of the methods described in part one.
ee For every sub-expression that consists entirely of letters of the alphabet we can make a
separate TG that accepts it by the method described in problem 8 for finite languages. For
any sub-expressions that are joined with a + in the regular expression, their respective (mini)
Zi
Chapter Six
TG’s can be combined as described in problem 9. For each sub-expression that is starred in
the regular expression, the appropriate TG can be transformed as outlined in problem 12(ii).
14. Let us number the states clockwise from - (1) to + (3) and around to 6.
From start, there are two choices for the first a: 1-2 or 1-6.
1-6 If we take 1-6 edge then we have no more choices. We take the only outgoing b-
edge and arrive at 4, then bb-edge to 5, a-loop at 5, bbb-edge to 3, ab-edge back
to 4. The remaining string is ba and there is no edge we can take so the input crashes.
1-2 In this case there are five choices for bbb: 2-2-2-2, 2-2-2-3, 2-2-3-3, 2-3-3-3, 2-6.
2-6 gives us two choices for a:
6-1 in which the word crashes, or
6-3 in which case we loop at 3 for bbb, take the ab-edge to 4 and crash.
2-2-2-2 means that we use a to get to 3, then loop at 3 for bbb, take ab-edge to 4 and
crash with ba left unread.
(2-2-2-3, 2-2-3-3, 2-3-3-3) For the other three choices have read abbb when they
reach state 3. Follow the ab-edge to 4, bb-edge to 5, a-loop at 5, bb-edge to 6, and
finally a-edge to 3, where the word is accepted.
To summarize the paths are: 1-2-2-2-3-4-5-5-6-3, 1-2-2-3-3-4-5-5-6-3, 1-2-3-3-3-4-5-5-6-3.
And there are no other possible paths.
ies
(i) If there are edges out of the final state by which a string can reach the same or another
plus state, the new machine will accept not only the old language L and ba but also
the product of ba and all strings that can be formed by concatenating the labels on the
path from the final state to itself or another final state.
(ii) If there is a circuit that goes back to the start state, we face a problem similar to the one
above: the machine will accept L and ba and also the product of any strings that can
finish their processing in the start state concatenated with the string ba.
(iii) Add a new start state and a new final state to the machine and connect them with a
transition labeled ba. Connect the minus state to another minus state by a A-edge.
1th (i) Change all final states of the FA into start states of the TG for the transpose. Change the
start state of the FA into a final state in the TG. Reverse the direction of every
transition in the FA. This machine accepts exactly the reverse of every word in the
original language.
(ii) First apply all the steps outlined in part one. Then if the original machine was a TG not
an FA, then we must also change the labels. For each edge, replace each string that
28
Chapter Six
18. We can think of a word in the language of a TG as the concatenate of edge labels on a path
from-to +. Suppose no edge of T has a label of odd length. Then no concatenate of edge
labels from T can possibly produce a string of odd length. So if L is the language of T and
if L contains an odd length word the T must have a edge with a label of odd length.
20. (i) In a machine without A-edges, every transition consumes at least one letter of input.
Therefore, we know that Step 2 is true. The list in Step 3 is exhaustive; it includes
all possible paths through the machine (where a path is represented by the sequence
of integers that number its consecutive edges) and also sequences of integers that
cannot represent paths because the edges are discontinuous in the graph. There is an
upper bound on the magnitude of the integers used as edge numbers and on the
length of the sequence. Since the list is finite , we can actually check it for the two
required characteristics: 1) Does the sequence represent a path from a start state to
a final state, and 2) when we concatenate the edge labels, does the result match the
word we are testing? Since all possible paths are listed, if our test word has a path we
must find it. Since we test paths for validity at Step 4, we are not deceived by
matching edge labels on an invalid path. The list and the procedures we apply to it
are finite and so this algorithm must terminate.
(ii) In a machine with A-edges, it is not true that every transition consumes at least one letter
ofinput. We can use infinitely many A-transitions without consuming any letters at
all, and therefore we cannot set an upper bound on the length of the path that gives
us the test word.
29
CHAPTER 7
It is possible to teach Computer Science without covering Computer Theory but it is not
possible to teach Computer Theory without covering Kleene's Theorem. We believe that
the excruciating detail that we go through in this proof is completely justified and several
grounds:
1. the theorem is so important it merits a complete proof
2. the proof is a beautiful example of the strength of recursive definitions
3. it is an important illustration of the technique of proof by constructive
algorithm
There is one pitfall that we must be careful to avoid here. We do not want to over
emphasize the importance of developing facility with the method of conversion. It is only
important to see that conversion is possible; it is not important to "get good" at doing it.
In some courses it is necessary to drill on a new technique until the students become
expert in applying it. That is not the case here. The only purpose the examples and
problems serve in this chapter are to insure that the student really understands what is
going on. It would be misleading to give the impression that the ability to convert regular
expressions into FA's and vice versa has practical or commercial value.
We have heard of zealous students (or intense teachers) who have written (assigned)
computer programs to perform the algorithms on FAs in this chapter. As long as it does
not displace some of the more important material this seems harmless.
Many authors prove Kleene’s Theorem by first proving that nondeterminism can be
removed from FA’s and then the result follows easily. We include this approach in this
edition without replacing the old method for two reasons. The old method is a perfect
illustration of the nature of how to design a constructive algorithm -- an art which can only
be taught by example. And the fact that there are two proofs for the same result is in itself
a great example of the power of mathematical techniques as opposed to mathematical
results alone. Each proof is in essence its own separate result.
30
Chapter Seven
1. (i) (atb)*b
ab 2 a ab a atb
bb a bba
aba
a
ath 6 ieee eer +)
bba
(iii) (at+b)*(atb)
atb
abba
at+bt+abba
Oe G
Ona @
Chapter Seven
(iv) (atb)*
atb
a atb+baa(at+b)*abb
A
er baa A+baa
baa(atb)*abb
A
a @Q- *(A+baa) Se
(v) a*bb(at+b)*
a e? is abbatabb+bb atb
( )a* abbatabb+bb(atb)* ()
(vi)
a a
iy ab A ab —Oao)
baa bb bb
baaab
a
(-)*%> ab ©) ab(a+baaab+abbbb)*ab O
baaab abbbb
Chapter Seven
(i)
(ii)
(iti)
(i)
33
Chapter Seven
(it)
3
(i)
(ii)
34
Chapter Seven
(iit)
(iv) a b a
b a
(v) b a b a
a b 2
(i) a
(ii)
(i)
35
Chapter Seven
36
Chapter Seven
9. (i) The point is to ensure the option of getting from any final state to the start state. If there
is only one final state which is also the start state no changes are necessary. In
general, for every transition from the start state to some state x (possibly the start
state) with label /, add an edge from each final state to x with able /. (If the original
start had an /-edge to a final state then the resultant machine will have an /-loop at
that final state.) If there are no incoming edges (or loops) at the start state then
simply insert a + sign in order to accept A. However if there is even one incoming
edge at start then make a clone start state. The new start state is marked + and has
edges going to the same places as the original start state. (If the original start had a
loop on c, then there is a c-edge from the new start to the old start in addition to the
c-loop which is still at the old start.) After the edges are drawn then erase the - sign
from the old start state.
(ii)
(itt)
(iv)
10. 9(11)
9(iii)
37
Chapter Seven
Le (i) (ili)
a,b( 7 |; 7)a,b 6-"6r a,b
a b a a
12. (i) Both the machines and the languages are different. The product language does not
include A, while the closure does.
(ii) The product and the closure define the same language but the machines are different.
a b b
(iit) (iv)
a e
b a,b
b a,b b
38
Chapter Seven
(viii)
15; An NFA-A can be converted into an FA by treating states on the FA as representing a subset
of states on the NFA-A. Begin with making a new start state whose set includes the old start
state and any other state that can be reached from any state in the set by a A-edge. The a-
edge goes to a state whose set includes all destination states that could be reached by an a-
edge from any state on the NFA-A that is in the set of the source state on the FA. Likewise,
draw the b-edge to a state which represents the subset of states reachable from any state in
the source-state-set. For each new state generated in the FA, before drawing the appropriate
outgoing edges, add to its associated set any state that is reachable by a A-edge from any
state already in the set. When all the states in a set have no edge for a given able on the
NFA-A, then draw that edge to the dead-end state on the FA. However, if at least one
member of the set associated with a source state has an edge with that able then (even though
some other member state would have gone to the dead-end) the edge is draw to a destination
state whose set includes the optimistic choices. Continue drawing edges and generating new
states until every state on the FA has both an a and b edge. Any state on the FA that
represents a state which was final on the NFA-A must be marked with a +.
39
Chapter Seven
16.
17; (i) Union can be accomplished by adding a new start state with two A edges, each one
leading to an original start state. Then remove the extra - signs.
(ii) Product is made by adding A edges from each final state in FA, to the start state of FA,.
(iii) Similarly the closure machine is produced by adding A edges from each final state to the
start state and if the start state does not already have a + sign as well then add it.
—
a
do)
AQ
Chapter Seven
el
No paths from - to +, and this machine “oono words.
4]
CHAPTER 8
This is the first chapter with is truly independent of the rest of the book. Despite the fact
that it is mentioned later when output become a hallmark of Turing machines, the material
here is not required there.
However there are good reasons for not skipping this chapter unless absolutely necessary.
For one thing Mealy and Moore machines model sequential circuits and these are an
important topic in courses in computer logic, switching theory and architecture.
The topic of nondeterministic finite automata with output would very interesting to discuss
at this point. Students should be able to appreciate the fact that a single input may take
several different paths but not necessarily give different outputs. This question is
interesting but too much of a digression for the main text.
The AND and OR gates in the feedback circuits are not drawn using the usual symbols.
The purpose for this was to not disadvantage students who had not seen those symbols
before.
Some of the problems emphasize the nature of the transducer as a function from strings
to strings. The ultimate importance of this is beyond the scope of undergraduate
education.
42
Chapter Eight
2: (i) For each state there are two choices of output 0/1, hence there are 2* ways of labeling the
states. Then any of the eight edges can lead to any of the four states, that’s 4° ways.
So there are 2*4° four state Moore machines.
(ii) There are 2" Moore machines for n states where the input and the output alphabet each
have exactly two characters.
(i)
(iv)
43
Chapter Eight
1. (i) 100000 (ii) 000111 (iii) 111010 (iv) 000110 (v) 001001
3. (i) 000111 (ii) 010101 (iii) 011111 (iv) 101111 (v) 110101
We can convert a Less machine into a Mealy machine by the same algorithm that we used to
convert a Moore machine into a Mealy machine. (The start state of the Less machine will
have no print instruction unless there is at least one edge into it, but this is not a problem.)
To convert a Mealy machine into the equivalent Less machine, we follow the algorithm for
converting Mealy to Moore. We do not have to worry about a print instruction for a start
state with no in-edges since the start state of a Less machine does not print unless it is re-
entered. It is possible that there are other states in the machine that have no in-edges. Output
imstructions for such states can be chosen arbitrarily without affecting the results obtained by
running the machines, because such states can never be entered. (This point applies equally
to Moore machines.)
(li)
10.
New B= old A
Output = Input AND old B
BE >)" 1/1
Lz.
|
he (i)
0/0,1/1
0/0,1/1,$/$
(i1) There is no way of knowing when the last letter is read and its time to print the letter
that was read first.
14. Me, does not change the string at all so reprocessing a string through it any number of times
does not change it. Me, swaps I's for 0's and 0' for 1's but reprocessing will return them to
their original values.
hey This machine flips the first bit and preserves the rest. So to undo the effect on the first bit,
simply run the resulting string through the machine again.
16.
(yess Ou 1/0, Coe
a If Me, took two different input strings, x and y, and outputted the same string z then when
z is fed into Me,, it could at best produce one of the original strings x or y and Me,Me, would
not be an identity for all strings. So Me, must produce a unique string for each input so that
Me, can distinguish it.
18. It is easy to have a machine that does not change the outputs from Me,. Let us say that the
output of Me, is zero for all puts. Then Me, could be any machine at all and Me,Me, would
acts like an identity because (Me,(Me,Me,) = Me,. But this is not a true identity because an
identity must act on all inputs not just the one string that constitutes the only possible output
46
Chapter Eight
for a particular machine. So we note the fact that we confirmed in problem 17 that is that all
Me;'s that can possibly participate in an Me Mg identity must have the property that its
function is bijective. Hence for each input x Me, produces a unique y which when fed into
Me, reproduces x, likewise for each x fed into Me, the resultant y reproduces x on Me .
This proves that if Me,Me, is an identity then Me,Me, is also an identity.
19. M, flips just the first bit leaving the rest of the string unchanged if the first bit was 0,
otherwise it takes the complement of the entire string. M, recovers the changes that M
makes on a string. It flips the first bit alone if the first bit was 1, otherwise it flips all the bits
in the string. M,M, = M.M, = Identity. The two machines are inverses of each other.
20. After you read the first bit Mealy machines must produce the first output bit but there is no
way of knowing what the last bit will be at the onset of processing. So transpose cannot be
implemented by Mealy machines.
47
CHAPTER 9
Any student who has never seen a Venn diagram should still be able to work out De
Morgan's law for themselves.
This is another chapter in which it is possible to over emphasize the facility with the
techniques of conversion, while missing the basic point that it is only the possibility of
conversion that we are truly interested in.
This chapter is another good place to discuss the problems of finite and infinite. A student
should be able to notice that despite the fact that the union of two regular languages is
regular the union of infinitely many regular languages is not necessarily regular (assuming
for the moment that there are non-regular languages). This is because any language can
be considered the union of its separate words each as a regular language. On the other
hand students may want to test their skill at the conjecture that the intersection of infinitely
many regular languages is still regular, even if this intersection is still an infinite language.
48
Chapter Nine
ia! ( } Gast
2 yk? 7
és Sea
(ao ta)
in
al a xs
Pig ee\
49
Chapter Nine
es Seated
le liee lislialeas
a} ral a ie
al Sar |
Ne af ‘ ke
5
aes.
_ 2
~K
a Soas
on
12. a(a+b)*aa(a+b)* (starts with 2 contains #2)
7 Z g,0
ome ae ieee
i @) (+3
eas
3 |
49.9 A_, 2
PE ol)
<a
eee
Nice
a5s
bs Fe ae Tbe
ale i+}
he Ie el eae a
| | “af
Pe) ‘ I 3, Be 5
“j a = = io} Oo <
ak | ae oo
ar, eet ee aN!
33
50
Chapter Nine
15. (ab+ bb) (A + blab+bh+a(ba)*b?lb(ab+bb)*+a(ba)*]) (even length. no double a)
2
oe eae
§ yet
C It ! A ee
‘
2
a ah)
(es
Cae
ie eee ee an
rei i
ee a eee
a
a ) yo
(ed
17. (aa+bb+(ab+ba)(aa+bb)*(ab+ba))* (EVEN-EVEN)
2
oie ale
ps EA 2
al A |
oe
ae
ee
ee
f)L EEE.
af)
i ee % ea,
20. There are many such: the set of finite languages, the set of
languages of words of even length, the set of languages that
begin with an 2 etc.
51
CHAPTER 10
Both the pumping lemma and the pumping lemma with length are worth covering in detail.
If the example PRIME is skipped as being "too mathematical" then one of the examples
from the problem section should be substituted.
Students should also be encouraged to worry about whether all languages that are
nonregular can be proven so using the pumping lemma. This raises both the question of
whether the pumping lemma is a necessary and sufficient condition and the possibility of
true statements (e.g. that some L is non-regular) having no known method of proof.
Perhaps some more non-regular languages should be shown to be “pumpable” to drive
home the point.
Myhill-Nerode is new in this edition. | didn’t include it in the first edition because its
customary application is to find the “minimal” FA that accepts a given language. This is
not a question that interests us enough to suffer through the distinction between the two
types of equivalence classes that the theorem requires. However, as an alternate method
of proving that certain languages are non-regular, it is simple, direct and useful. | like
having multiple approaches to mathematical chores. It adds depth of understanding.
Especially since the Pumping Lemma is difficult to conceptualize as a mere foo/ without
this parallel approach.
The quotient languages section is skippable. The only future reference made to this result
is in Chapter 22 in the proof that a Read-Only TM is just an FA. Both of these results can
be sacrificed if the whole book is attempted in one term.
52
Chapter Ten
(i) Let xyz be a word in {a"b"'}. Consider y, it could be one of three possible forms: 4 ,
a‘b*, or b*. Ify=a" then xyyz would have too many a’s to be a word in the language.
Ify= b* then xyyz would have too many b’s. If y = a*b* then xyyz would have some
a’s among the b’s instead of separated.
(ii) Let xyz be a word in {a"b"a"}. Consider y, it could be one of five possible forms: a’, a°b’,
a’b‘a’, b'a’ orb’. Ify =a’ then xyz would have too many a’s on one side of the b’s.
If y = b* then xyyz would have too many b’s. Ify=db6 ory=4bd ory=ba
then xyyz would have some b’s among the a’s instead of all clumped in the center.
(iii) Let xyz be a word in {a"b™}. Consider y, it could be one of three possible forms: d ,
a’b’, or b’. Just like part (i) doubling y would spoil the proportion or the order of the
word.
(iv) Let xyz be a word in {a"ba"}. Consider y, it could be one of five possible forms similar
to part (ii): a, a°b, a"ba’, ba” or b. If y= a" then xyyz would have too many a’s on
one side of the b. If y=b or y=a'b or y=a'ba’ or y= ba’ then xyyz would have too
many b’s.
(v) Using the stronger Pumping Lemma, |xy|<N (number of states), consider xyz = a“b‘a.
Hence y must be contained in the first set of a’s and when pumped the a’s would not
balance the b’s. So xyz is not in the language.
Consider the infinite set of strings aa*b. For each string x in this set, a different string z is
needed to make xz a word in any of the five languages. So in each case there are
infinitely many classes.
For this we need the Pumping Lemma with length condition. Let the FA have N states.
Consider xyz = a“ba“b a word in DOUBLEWORD. |x|<N so xy = av and when pumped,
it is no longer in DOUBLEWORD.
(i) Using the length condition in the Pumping Lemma, consider xyz = aXba“*!. y is a string
of a’s preceding the b. When pumped the number of trailing a’s will be too few to
indicate the length.
(ii) Consider the infinite set b*. For each string a different z is necessary to constitute a word
in TRAILING-COUNT. Therefore there are infinitely many classes.
(i) Consider xyz = a™bba™, where m is an even number greater than N, a word in
EVENPALINDROME. _y is a string of a’s preceding the bb. When pumped the
number of succeeding a’s will be too few. Likewise for ODDPALINDROME simply
consider xyz = a™ba™.
(ii) Again consider a*bb or a*b, and note that any such string will be in a different class.
(i) The squares have an interesting property. Consecutive squares differ by consecutive odd
numbers. 17= 1 27=14+3 3? =14345 947 = 143+54+7
53
Chapter Ten
(ii) For each p, xa’ is a square for infinitely many x’s. (x=a"”, s =n’) However xa’ and
xa are both squares only when n’-p = m’-q for some n and m. But then n’-m’ = p-q
which cannot happen for large 7 and m. This is because, as we have seen above) the
gap between the squares keep increasing and get above p-q and stop there. Therefore
xa’ and xa! are in SQUARE only for finitely many x’s. The class of x’s which become
square by concatenation with @’ is different from the class of x’s which become square
by concatenating with a*. So a’ and a’ would require different states in an FA for any
different p and g. Hence the machine would need infinitely many states and
SQUARE is not regular.
(i) Consider w = xyz = ab" € DOUBLESQUARE. If, contains the substring ab then xyyz
contains two ab substrings and is not in DOUBLESQUARE. Therefore y is all a’s
or all b’s. In either case xyyz increases only one letter not both and so breaks the form
a'b”. Therefore w cannot be pumped and the language is not regular.
(ii) For each n, a’bx is only a word in the language when x = b”’. So there are infinitely many
different classes.
8,9. (i) The argument in 7(i) never used the fact that 7 was restricted to squares, so the proof
works equally well for DOUBLEPRIME and DOUBLEFACTORIAL.
(ii) The same as 7(ii). Notice that all three problems are special cases of the following
general theorem: Let n,, n,, ns, ... be an infinite sequence of integers. The L = a"'b™,
a@p™ a™b™.... is nonregular by either the Pumping Lemma or Myhil-Nerode.
10. (iii) Let xyz be a word in {a"b"c"}. Consider y, it could be one of five possible forms: 4 ,
a‘b’, b’, a’b’c’, b’c’ orc’. Ify isa string of all the same letter than xyyz would have
too many occurrences of that letter. If y= ab’ ory=ab¢ ory=6B¢é then the
order of the letters in xyyz would be mixed up.
(iv) Consider again a*b, for each string a different z is needed to make a word. So there are
infinitely many classes.
11. For each string in the infinite set a*, consider z to be of the form ba*b. No two strings from
54
Chapter Ten
the former set will both be accepted by the same string from the latter set. So there infinitely
many classes.
12. For each string in the infinite set (*x, a different number of close parentheses are needed to
bring the word to acceptance, so there are an infinite number of classes.
a: (i) IfMOREA were regular then a) MOREB would be regular by symmetry b) MOREA’ and
MOREB’ would both be regular by theorem 11 c) EQUAL would be regular by
theorem 12. But we have shown in the chapter (albeit also by indirect proof) that
EQUAL is nonregular. So we conclude that MOREA is not regular.
(ii) Because there is a way to divide words so that they can be pumped. Namely let y be
some substring of only a’s. If there were more a’s than b’s originally then adding
more a’s preserves (and enhances) this property.
(iii) Consider b*; 5° and b* where p<q are in different classes since a”''b” is in MOREA but
a’*'b* in not in MoreA.
14. (i) Infinite union is not regular. Let L be any nonregular language. Each single word of L
is a regular language itself, but the union of these infinitely many languages is not
regular.
(ii) Infinite intersection is not regular. Let L be any nonregular language. The complement
of each single word in L is regular. The intersection of all these languages is L’,
which is also nonregular.
16. (i) Suppose PRIME’ was regular, then its complement PRIME would be regular but PRIME
was already shown to be nonregular. So PRIME’ is also nonregular.
(ii) The length of every word in PRIME’ has some divisor, k, that is PRIME’ = {a‘"}. To
satisfy the Pumping Lemma, let x = A, y = a‘, and z= a‘). Then xy"z = akaker)
which clearly still has a divisor k and is in PRIME’.
(iii) The Pumping Lemma sets the condition on regular languages. We use the contra
positive of the conditional as our proof method. Ifa language does satisfy the lemma
then no conclusion about regularity can be drawn.
17. (i) By Theorem 5, any finite set of words is a regular language. By Theorem 10, the set of
regular languages is closed under union, so the addition of a finite ser of words to a
regular language yields a regular language.
55
Chapter Ten
(ii) The difference between two sets is the intersection of the first with the complement of
the second. Since any finite set of words is a regular language its complement is
regular. By Theorem 12, the intersection of two regular languages is regular.
(ii), (iv) if nonregular + finite = regular then regular - finite = nonregular (in short hand)
and we know the latter to be false, hence the antecedent is false. So if a language is
nonregular, adding or eliminating a few words does not effect its “regularity”.
18. Given an FA that accepts P, take a word in Q, say e.g. bba. Then some (maybe none) of the
states of the FA have the property that from there bba will take them to a + state. Label these
states with a ty “bba’’. Do the same for all words in Q (in theory only since this is infinitely
many steps.) Any states in the FA that have a complete set of labels Dba, ..., for all words
in Q, are the final states of the FA for P/Q. Since these states all define Myhil-Nerode classes
and there are at most finitely many off them P/Q is regular.
(ii) Every string contains the substring () at least once. Let y = (), then pumping the word
preserves the necessary property.
20. (i) It should be clear from the discussion that S, is the finite set of words accepted by the FA
before entering the circuit and S, the finite set of words accepted by the FA on the
first trip around the circuit. Concatenating (a")* after S, simply permits any number
of trips around the circuit. [For a more complete discussion of ultimate periodicity see
Harrison, pp. 47-50.]
(ii) This problem clarifies the relationship pf the Pumping Lemma to the concept of ultimate
periodicity. No matter how many words we take to be in the finite set S,, and no
matter how large we make the circuit (i.e. the size of the finite set S,), the circuit will
bring the number of a’s in an accepted word to a magnitude expressed in base 10 by
an odd number of digits.
56
CHAPTER 11
Students have often complained that this chapter belabors some obvious points.
Decidability seems trivial as long as the question in question is decidable. As trivial as
decidability seems to them now, that is just how impossible un-decidability seems to them
later. When a class takes this position they can be given harder questions to puzzle over,
such as: given two regular expressions, without converting them into FA's, determine
through algebraic means whether they are equivalent. Once we have shown that the
question is algorithmicly decidable are there necessarily also algebraic algorithms? If that
question seems too easy (of course it isn’t, but who Knows whether someday a student will
answer it), ask them to decide whether the language of one regular expression is a subset
of the language of the other. Or find an algebraic way of writing down the regular
expression that defines the intersection of the languages of two other regular expressions.
If a class has had some graph theory they may want to investigate methods of deciding
whether the language accepted by an FA is infinite simply by looking at the graph itself
(disregarding labels). They will have to decide whether there is a path from a start state
to a final state that contains an circuit. There are such algorithms that involve pruning the
graph of redundant edges and moving the start and final states.
Chapter Eleven
Setse Ry Zp
| |JSy
Sh[|
hd
— Fy |
I} eH
oe I~.
SIs
+ m1 mn Tyed
am Ly]
Sy}
-
Pea
cE
I
2
ne
i)
ima cn
if Be
bel
pa
Chapter Eleven
Aas
"t)
7h;
|ON
4
nal
»
Pod
YL
pba
t_ e
Lair
|)
Sey
Sint)
S|]
ee er, vy.
sy j—
lal
"Sy
eT
RI
Se ee |
Ord
Cod
"ay
es
Chapter Eleven
Chapter Eleven
Chapter 12
On the surface we present one primary reason for introducing CFG’s: regular expressions
were inadequate to define all interesting languages and therefore we turned to the metnod
of defining human languages to find a more powerful tool. If this were really the case, and
our whole goal was to find the most powerful language defining structure, why did we
waste time on Part | at all since Part Il is better (dominating), and Part III will be better still.
There must be a reason why Parts | and II exist. Students should be asked to figure this
out for themselves.
Loosely speaking, Chomsky’s goal in inventing generative grammars was that he had a
fundamental theory of why humans can learn to speak and why all human languages are
So similar (assuming that they are). He reasoned that all human brains come hard-wired
(like nest-building in birds) with a language grammar of everything but the terminals. Each
human language invented need only supply the terminals “chair’, “table”, “cat”, etc. Infants
know the grammar already and are eager to learn the terminals so that they can form
sentences. | like to have the students speculate on this possibility and to contrast it to
computers, programs, and Al. If this were really literally the case why would so few
human-uttered sentences be grammatical?
| think the term Polish Notation for Lukasiewicz Notation is politically incorrect and
demeaning. The man deserves personal credit, not synecdoche. This is also a topic
which, if not already presented in some other course, all CS students should learn.
Chapter Twelve
There is only one nonterminal S. There are only two productions, S > aS and S > bb.
We must apply the second production exactly once to eliminate the nonterminal S from
the working string and form a word. (Therefore all words in the language of the grammar
end in bb.) As soon as we apply it we are finished, since there can never be more than one
occurrence of S in the working string. Ifwe apply the first no times at all we make the
word bb. If we apply it exactly n times, we make a"bb. Thus, we can make all of a*bb. We
can make nothing else because we have only the two productions offered, and the
substring bb must terminate the word.
The grammar has three nonterminals. S > XYX gives us a word of three factors. The
outside factors are each of type X which we recognize as having the form as grammars for
the language of the expression (a+b)*. The center factor is type Y, which allows only the
string bbb. Since all strings in the language start from S all must have the Y factor in the
middle, with an X factor concatenated before it and one after it, just as in the regular
expression (at+b)*bbb(at+b)*.
(i) a(atb)* The X factor in this grammar is exactly like the X factor in the grammar of
Problem 2, and generates the same language, namely (atb)*. Since S gives the
single production S > aX, the grammar produces all words that begin with a.
(ii) (at+tb)*a(at+b)*a(at+b)* Again, what the X factor produces is entirely arbitrary. The S
production requires exactly two a's (in addition to any that might be introduced
from X). So this grammar gives the language of all strings that have at least two
a's.
(i) By taking X > A, we get the null string from X. We must apply this production once
to eliminate the nonterminal X. To make the substring b" for any 7, we apply the
other X production exactly n times before eliminating X.
(ii) We have shown that X gives us all of b*. We can derive any of the strings in the
language from wherever the nonterminal X occurs in a workins string, by applylng
productions as shown above. The requisite a’s are included in this S production.
(iii) Consider the two productions S + SS and S > A. By applying the former production
n+] times and then applying the latter to any one of the resulting S’s, we derive a
working string of exactly n S's. Since we have shown that S can produce any
number of S's (including 0), we see that we can use it to derive something we
might call S*. Each S can generate XaXaX, which is a word from b*ab*ab*.
Therefore the language generated is (b*ab*ab*)* = [all strings with an even
number of a’s]-[b*]+[A].
63
Chapter Twelve
(iv) This language includes no words with an odd number of a’s, since each repetition of
the factor(b*ab*ab*) introduces exactly two of them. The number of b’s
introduced with any factor is entirely arbitrary. However, there is no way to
generate any b's at all without also introducing two a’s. Therefore, of all the
words with no b's, only A can be generated.
(v) We have already shown that we can make all words over (at+b)* that have some
positive even number of a’s, and A. We must show that adding the new production
S > XS to the grammar gives us the possibility of producing the words in b*
without adding undesirable strings to the language. By using the sequence S = XS
= XA = X we can easily see that we can now derive the strings in b* from S.
Since we have not introduced an unpaired a into the grammar, we may safely
assert that we can now produce all strings with an even number of a's.
This grammar generates the language of all words that either begin with a or contain the
substring baa (or both). The word abaa can be derived in two ways:
S = aX = abX = abaX = abaaX = abaaA = abaa
S = XbaaX = abaaX = abaaA = abaa
Chapter Twelve
(i) S- Sbla
(ii) S + XY
X-+aX|A
Y-bY|A
(iii) S-+SS|baa|abb|A
(i) S-+aS|bxX|A
X-aS|bY|A
Y-aS|A
(i) S-aS|bY
Xoax
|bY
Y->aY|bZ|A
Z->aZ\|A
(ii) S-bS|aX|A
X-+aX|A
(iv) S-aS|bX|A
X-bxX|aY|A
Y->bxX/A
This grammar generates the language of all words containing a (positive) number of d's
divisible by 3.
65
Chapter Twelve
Le S - SS| EXE
X-aX|a
E + EQUAL
12. | We can convert the CFG for any CFL into its transpose by replacing the right sides of
each production with its reverse: S > XY becomes S > YX.
13. Inthe productions, the nonterminals on the left side of S become the letters of the word
and the a’s on the right side of S keep count of the number of letters in the word.
(it) CFG 2 S
/\\
CFG 3 S
/\
CFG 4
3 aS
" ay
A
Xs
a a
66
Chapter Twelve
CFG 5
CFG 4
CFG 5
>=
—
O oyOo N CO iy,oO LF
ay
TS
2s
na ae
De
x, Nx
=Naa
67
Chapter Twelve
(ix) CFG 5 S
/\
bA
/\
aS
/\
ab
16. (i) babababab
(ii) aab
(iii) aaaaaaaa
(iv) aaa
(v) aaaa
Chapter Twelve
aaSaSaaSaS
Chapter Twelve
ees Se ery
Leen DHX DAP
L__ bbbX- bddd
(v) ambiguous
S— bA— ba
baS — babA baba
L___ baaB baab
bbAA- bbaA abaa
bbAa abaa
bbbAAA
bbAbAA
bbaSA
bbAaS
aB — ab
abS — abaB abab
= abod abba
aaBB- aaBb aabb
aabB aabb
aaaBBB
aaBaBB
aabSB
aaBbS
20. The binary operators are V, A and >. The unary operator is ~. Using prefix notation, we
can distinguish between infix ~pVq = (~p)Vq and ~pVq = ~(pVq) by writing V~pq and
~Vpq respectively. Construct a grammar analogous to the one used to generate the prefix
trees and proceed in the same fashion.
710
Chapter 13
We make an enormous big deal out of Chomsky Normal Form, in part for the parallel to
regular grammars, in part for proving later that there is a PDA for every CFG, in part for
parsing by CYK, and in part to prepare for Kuroda Normal Form for CSLs. However the
true reason for all the fanfare is that this conversion in its naive form provides two
wonderful examples of when what seems like a completely well defined algorithm is
actually not.
If the teacher would rather cover the whole mater in one class, fine.
Notice also that there is mathematical induction disguised in the proof of the grammar for
EQUAL.
q3
Chapter Thirteen
Chapter Thirteen
Il. G) Sa aX] bX al b
X> al b
(ii) S> aX] bS| al b
Xa akla
(ii) Sa aS| bY) 6
Xa axa
(VY) Sa Yar] O41 al Yel 2741 5
X> Xank) Xal a¥1 a] X67 X61 OF] 6
12. (i) Choose a symbol for a new nonterminal, * , and add the production * > A. This will
not change the grammar because *¥ is not derivable from S.
(ii) Add a new unit production * > N, where N is some nonterminal already in the
grammar. Again this will not adversly effect the grammar for the same reason as
above.
£4 LR |
Ae
74
Chapter Thirteen
Pa» XE L (
T> ¥& Cas
Ra &C
(Vv) \1- and 2-letters] S> a] 5] AA| AZ| BA| BB
is-tewers)| = S-+ AR | AR ARL AR |BR |BR | BR | BR
(4-letters} S23 R, £y | Ry 3 By Bs | Ry ky | ky ky | By; | By |
Ry Ry | RyRy | RyRy | RR
[5-letters| S+ Bks | A fs, | Ay | eA | fy B| Ks,A
[6-letters] S+ Ry Ks,
hy > AA Kh, BB 7 AB
h,7- AB Bs > Ry ky Ata
> BA > hy A Ba b
(vi) S+ GR,\SA\AS\ 4
5+ RRs| RyRy | As) 2B | Bl RBI AR | AB
S94 Ky es,| hy Ks | ky; | Rs Ay | Ay A | A A | BR, BA
hy> AS Ky SA Avta
hy SB Bs + SH; Bo b
k,> BS
Yes. For example the word aababb can be derived in at least two ways from the
srammat>S
AY | 2OC VY, XY| enya ey,
TS
_ Chapter Thirteen
19. Draw the derivation tree for the word in question. Start with
the original production from the Start symbol & Thereafter,
find on the tree the node corresponding to the rightmost
nonter minal in the working string and apply to the
nonter minal whatever production shows in the derivation tree.
Since, at any point in the derivation of a word, if there is at
least one nonter minal in the working string, there is a
rightmost nonter minal, this works for all grammars. Since
every word derivable from a CFG has at least one derivation
tree and since that tree (by definition) terminates when the
word is formed, the process is finite.
20. Since the conditions specify that A is not a word in Z we know
(by Theorem 21) that there is a CFG in CNF for Z. We derive
our grammar from this one. We Know that in the process of
deriving a word in Z we start with a string of all nonterminals
(the single nonterminal 5) and end up with a string of all
terminals (the word). We observe that whatever nonterminals
were used in the derivation process have all been turned into
terminals eventually, since none can have been eliminated
directly by applying a A-production. We do not have to worry
about both nonterminals on the right af a production arrow; if
we know that they will both eventually turn into terminals
then, in particular, the first one will. Start by separating the
productions.
Step |. For all “dead” productions, that is, of the form WV a,
act, paint x blue and paint the nonterminal on the left of the
production arrow red (at that place only).
Step 2. Wherever a nonterminal that is red somewhere appears
to the right of a production arrow, paint it red.
Step 3. For all productions having a right side that begins with a
red nonter minal, replace each of them by the set of all blue
terminals that can be generated by that red nonterminal. Now
paint the nonterminal to the left of the production arrow in
76
Chapter Thirteen
each of these productions red (again, only at that place).
Repeat Steps 2 and 3 until nothing new is colored. All useful
productions (see Chapter /9) now begin with a terminal. All
useful nonterminals will be red. Any productions that do not
now begin with a termina! cannot ever be used in the
derivation of a word.
ars
Chapter 14
We define PDAs as pictures, not i/lustrated by pictures. Manna does this too, but slightly
differently. We correspond runs of inputs to trace tables, but we never replace the pictures
by tables (that is until the proof that every PDA corresponds to a CFG). To define PDAs
(or FAs or TMs for that mater) by transition functions is a simple exercise in the elementary
theory of using function notation but it adds nothing of pedagogical merit to the discussion.
We could eliminate the pictures from all of graph theory and be left with graph-less theory
with no intuitive combinatorial value. Let us not do this.
PDA languages can also be defined by acceptance by empty STACK, completely read
TAPE, etc. If we had world enough and time we would prove the equivalence of these
other definitions to the one given here, but this task seems less exciting than progressing,
as quickly as possible, to TMs where the true surprises lie.
it would be nice to prove by an elementary argument at the early stages of this chapter,
that PALINDROME cannot be accepted by a deterministic PDA. When | figure out one
of these slick proofs | will print a new edition. Till then the necessity of the non-
deterministic nature of PDAs will have to rest on arguments like the one given here. That
generation by CFG allows (and requires) choice and that that is wny PDAs, in order to
correspond to them, must also have choice in the nature of non-determinism, is bogus.
Remember that generation of words from regular expressions also allows choice but FAs
can be defined as deterministic (this is because for them NFA=FA). So this feeling is
imprecise to the point of being misleading. Try to do something about this in class.
Personally, it is still a heuristic mystery why CFLs are not closed under complementation.
78
Chapter Fourteen
ACCEPT
3. (i) STATE
START
(ii) STATE
go
Chapter Fourteen
REJECT
(iv) STATE
START
READ,
PUSH @
ACCEPT
Ageia
2p22)
(ii) S > 4555| 2656
(iii) No. (It can be proven nonregular with the weak form of the
pumping lemma.)
80
Chapter Fourteen
5. (i)STATE STACK
START A
READ, A
PUSH #
81
Chapter Fourteen
By
>o>Oo
Oo
&m&
mem
TAPE
aaaabb
aaabD
aaabb
28D
aabb
abb
abb
bb
bb
PLY
rer
&
82
Chapter Fourteen
Chapter Fourteen
(ii) Focus on the four loops dividing the machine into four steps. The first loop reads n a’s
pushing then on the stack, the next pushes m b’s on the stack. The third loop
matches the second clump of a’s with the b’s on the stack to ensure that there are
ma’s. Finally the last loop matched the last clump of b’s with the a’s on the stack
hoping to find exactly n of them.
(i) The strings aba are all in different Myhil-Nerode classes since b” tums only one of
them into a word.
9. (i) STATE STACK TAPE
START A ab
READ, A b
PUSH 7 > b
READ, I A
POP, A A
READ» A A
ACCEPT
(ii) STATE ST ACK TAPE
START A bbba
READ, A bba
PUSH x I bba
READ, x ba
PUSH 2x IX ba
READ, XI a
POP, d€ a
READ, X A
POP, é A
READ, A A
POP, A A
ACCEPT
10. The algorithm for accepting any string of length 22(2 0) is to
read a letters while looping at READ,and then cross to POP,
on the 2+1t) letter and continue the rest of the word from
84
Chapter Fourteen
there. The loop at READ, puts some number of y's into the
STACK. After the transition is made to POP, nothing more can
be pushed. Starting with the transition letter, for every letter
we read we must be able to pop a counter. When the TAPE
reads A, the STACK must also read A. In other words, the
number of letters read in the first loop (counters in the
STACK) must equal the number of letters read in the second
loop, so the total number of letters in the string must be a
double, that is, an even number.
No word of odd length can be accepted because it is impossible
to break it into two equal parts. If |2/2] is the transition
letter, there will be one fewer counter in the STACK than
remaining letters on the TAPE and the string will crash
popping A at POP). If [n/2] is the transition letter, the TAPE
will empty first, and the string will crash popping y at POP».
S+ SS | aa| 2h| ba| 66
or
@,b
12. (i) STATE ST ACK TAPE
START A aa
READ, A a
PUSH x I a
READ, Ps A
POP, A A
READ, A A
POP, A A
ACCEPT
(ii) STATE ST ACK TAPE
START A babaaa
READ, A abaaa
PUSH x § a0aaa
READ, Ti baaa
PUSH x XX baaa
85
Chapter Fourteen
READ, xX aaa
PRS YS ¢ OG ¢ aaa
READ, III aa
POP, Tr aa
READ? jee a
POP, DG a
READ, § A
POP, A A
READ, A A
ACCEPT
“eee¥*We have to start the second part of the process with the first of
the trailing #‘s; that is, when the TAPE is reduced to eractly as
many #'s as there are y ‘s in the STACK: reading the first of
those # 's should initiate phase 2.
(iii) For a word to be accepted by this machine it must contain at
least one a that is not followed by any 4's. The string
babaaab must crash either by reading 4 in READ,, by popping
4 in POP, of by reading 4 in RBAD,.
(iv) For a word to be accepted by this machine it must have even
length. (The structure of the machine is exactly like that of the
machine for Problem 9.) If the last letter counted is the second
6 in the string, the string will crash reading A in POP,. If the
last letter counted is the a following that 4, the string will
crash popping A in POP».
1S If length(s) = 2, then every string in TRAILINGCOUNT has
length 2.7, in other words, all strings are of even length.
Further, while the first n letters are arbitrary, the last letters
must all be #s. We have established (by the pairing of _r's
popped to letters read) that this machine accepts onty words of
even length. The transition from the READ - PUSH loop is 2
Thereafter, reading any other letter will cause the string to
crash. Therefore, this machine accepts exactly those strings of
even length of which the second half is all as.
86
Chapter Fourteen
14.
1S. UG) a ab, CC COC COCE COCO ECECCORD CO ACD: Cad aad
abhcc ache cabc acch cach, ccab, aabbhe aabcb, aachb,
acaDb, caabh, abhece achcc cabcco accch, cacch, ccacb,
cccabh, aaabbb, aabbhcco aabche aachhc acabbc caahbhc
aabcch, aacaca, acabcbh, caabcbh, aacchb, acachb, caacbhb,
accabb, cacabb, ccaabb, abccce acbhccc cabcce acchcc
cachcc ccabcc accche cacche ccachc cccabc accccb,
cacccb, ccach, cccach, ccccab
(ii) Use a counterexample of the form (#54), which is a subset of
this language,
(iii)
(iv) Sa FathY | ¥
X> aXbh| X¥ | YX
auch |Z
87
Chapter Fourteen
Chapter Fourteen
(ii)
(iii) Use a counterexample of the form (4#*5#) and the strong form
of the Pumping Lemma.
(iv) Sa SS| 4Sb| 2b
(v) They are matched pairs (equal numbers of #s and 4's), where
the nesting requires that each close parenthesis (4) be prepared
by an open parenthesis ( #) that has preceded it.
89
Chapter 15
This theorem has two halves. | always cover the first and skip the second. This is jpso
facto inexcusable but | plead the necessity of time constraints. | do think the proof in the
text is understandable and self-contained and can be assigned to students to read as long
as they are promised it will not appear on the final exam. | have not made the usual big
deal that the STACK must always return to a previous length condition and that that is why
the Net nonterminals will always be sufficient. This is partially because it is as obvious as
many other points that are slurred over expressly and partly because our approach seems
to include this as a necessary consequence -- also the STACK-content graph-pictures
appearing in other texts always seem to imply that the STACK contains a continuous rather
than discrete number of elements, which negates the mathematical precision of the whole
exercise.
90
Chapter Fifteen
leet seal
(ii)
PUSH&
oT
Chapter Fifteen
START PUSH S
REAL)
2 as
\ f ase 6 x7 :
Sy a i PUSH 4
7 AC gerry ao [PUSHA} >
eee VAG :
“ SS > we :
AT :
Sy
.
ape
( ACCEPT
6X
Ue
|es Pages
{PUSHS| [PUSHB
START
FUSHS
(RE HA
SCCERT = READ
START }] PUSH S
eS
SR pAp ea
:
ihe, x i
ne aera Ec
eee a
w/a:
READ >——(
4
ACCEPT
fe
=
ee
2d
92
Chapter Fifteen
: {PUSHY} [PUSH 5)
READ A A c —
» PUSH AJA
Nor eS
ao
4 ~~ y 5°ae Hey ia
ACCEPT RE AD wv
~—1 PUSH 4L-f PUSH 4
(ii) None
To (h)
[BOSH] {PUSH
1a PUSH = PUSH
ea
§4 x
\
aa)
PUSH 3” PUSH 4
98
Chapter Fifteen
(ii)
.
Vai YON
oe Wolo Pane bans >
deemed
ie Siew
eee IVoYV boi rOvy pai S66
5535 IH IS BID 5565 L636 B66
bhb695 2bI5h bIbSd Sbb55 bbh95 bd55h
5058395 365398 SSOBHO 56368
bb 968 IDHISH bbbbdH6 666356
5bhID5
bh56356
9. The same process can be used to create PDA's for any CFG's.
Everything is stacked; nonterminals, when popped, follow
procedures as given, terminals are read.
10. (i) Use the strong form of the Pumping Lemma. Consider a
machine with 7 states and the counterexample of ((27 a )27).
(ii) Sa SSI(S)IS+ SIS* lal bla
(iii) CNF: Sa ZA| SP| SAlalblA
Ra SC
L- ( C+) P-3+ ABs
C START)
FLUSH ©
READ 3
bee apy. t PUGH 2
ahyGnd ‘POP,
7‘ae
ReaD
%. ‘ ae 7 Pa oe
ie { P -
: Sb ex
7 ~ ve a . a ie hy =e :- Se A a
CREAD
», vy
4——" CREAD>
.. a
RE~ AD; rd> ACCEPT
——$$__—~
Lf ‘. /
%.a x ns /
94
Chapter Fifteen
(iv)
\/
12. (i), (ii) Yes to both. Note that the question refers to rows in the
table, not to paths through the machine. Rows just show
alternative paths available between consecutive joint states,
without restrictions of consistency.
(iii) No. Now we are talking about paths to ACCEPT. To get
there we must POP everything, including the $, from the STACK.
We cannot have pushed more letters than we POP.
13 Gi) -a(arb)* the language of all words beginning with 2
(ii-iii) FROM 10 READ POP PUSH ROW
START READ $ $
READ, HERE F $ ease 42
95
Chapter Fifteen
HERE HERE a 3
HERE READ, b 4
READ, READ, a Saeers 5
READ, READ, b $ $ 6
READ} ACCEPT A $ 7
14. (i) WX F and Z represent the sets of possible joints. Not all
combinations are useful in the production of words.
PROD; S-> NET(START, ACCEPT, $)
PROD? NET(START,Y, $) > Row,NET(READ;,4 $)
PROD; Net(READ,,.4°$ Rowgner(READ,, Y/a)ner( MZ abeer(ZW, Dhol W, X $)
PROD, NET(HERE, HERE, 4) + Row;
PRODs NET (HERE, READ2,) + Row,
PROD, NET(READ2,¥,$)+ RowsNET(READ2,¥ $)
PROD? NET(READ>,4$)+ RowgNET(READ2, X$)
PROD NET(READ2,ACCEPT,$) + Row?
All derivations begin
PROD, .5-» NET(START, ACCEPT, $) + PROD2 NET(START,ACCEPT, $)
+ Row ;NET(READ; ACCEPT, $)
+> PRODs, 4. 5 Row ; Row 2Row3Row3zRow, NET(READ2,ACCEPT, $)
There is no choice so far. This gives us
+ PROD, Row,Row,Row3Row3Row, J Row7
where
X Rows 1 |Row, 41 A.
The CFG for the row-language is
5S Row, Row 2RowzKow3;Row, JY Row;
X= Rows 1 | Row, 41 A.
(ii) To covert it to the language over = = (a 45) add the productions
Row; > A RoW5 > @
Row, > @ Row, > 5b
Row; > A Row, > A
Row, 7 A
96
Chapter Fifteen
5. (i) S 7 ARIAB
Rk 7 SB
A 24
B34)
(ii)
LUSHS|
Chapter Fifteen
Chapter Fifteen
20. In these PDA’s each path from the POP goes to either a sequence of two PUSH. ’s or a
READ state before loopmg back to POP. A deterministic PDA has one such loop per
stack letter, m this case, nontermmal So starting with the single S edge emanating form
the POP, at most one path will lead to accept, recognizmg only one word. The S edge
99
Chapter Fifteen
either goes directly to a READ in which case the word is only one letter, or replaces S
with two nonterminals (which may be the same). For each of these nonterminals there is
only one path to follow from POP which have the same possibilities as S just described.
100
Chapter 16
This chapter is more important for its convincing discussion of why certain languages are
inherently not context free than it is for the Pumping Lemma itself. The parallel between
self-embeddedness and FA-loops / Kleene closure, is a profound insight and the
beginning of mathematical sophistication about this whole subject. Perhaps we give too
many pictures illustrating the same point, but the point itself is reiteration and so it is better
to iterate too many time than too few. It is actually not all that important in practice to
develop facility with demonstrating that languages are not CFLs but it is an easy advanced
topic to formulate test questions about and so students should attend carefully to it to
become prepared for Master’s and PhD qualifying exams.
There are two sloppinesses in this chapter. One is whether it is necessary for a self-
embedded nonterminal to reproduce using the very same production X-NN or whether it
is sufficient that the second occurrence use a different production X-MM. The other
carelessness is counting the rows of the derivation tree -- is the S symbol the zero-th row,
is the bottom row of all terminals counted in the tree? Some times p+7 should be just p or
p+2. The point is clear enough and the issue is that there is some predictable finiteness
about how far one must go to use the Pumping Lemma -- O(p), as complexity analysis
would say. Long enough and just so long. If you wish to be more precise about this go
to it.
Remember to emphasize that, like the Pumping Lemma for regular languages, this one is
a necessary but not sufficient condition for CFLs; and not all non-CFLs can be shown to
be so using the Pumping Lemma, even with length.
Chapter Sixteen
1 Only SPA
2.(i)To make az Apply 5+ AA and then A a twice.
To make 54 Apply S> 88 and then 2 & twice.
To make any longer word in NONNULLEVENPALINDROME:
If the length of the word is 2, then for m1 times,
If the nert letter is 2 apply the productions S54 AY and
A SA; if the next letter is 6 apply the productions 5S» AY
and /> S& Then, if the 7" letter is 2 use S> AA; if 5 use
S + BB Then apply the dead productions A> 4 and B> 6.
This shows we can make every word in the language. We can
make nothing else.
The only choices from § are S+ AA and S+ 8&2 which lead
only to dead productions, and $a AY and S+ AY Since the
only choice from Y is 43 SA, the choice of S~+ AY gives the
structure 5% ASA. Identically, S» AY must give the
symmetrical derivation 5% #5 So the grammar produces
only palindromes of even length, and does not produce A.
(ii)
Sy Ss
‘\ ‘N
AA a8
te Lal
gad BaD
(iii) Putting the grammar into the binary form of CNF did not
change the result. The real difference comes from introducing
the productions 53 AA and S57 #84 which do not reintroduce
the nonterminal S It is still true that only the shortest words
in the language can be derived without using a self-embedded
nonter minal.
3. The theorem does not give the “wrong” number, it just gives an
upper bound that is well above the actual result in this case, 4.
If a word of length 4 guarantees self-embedding, a word of 64
must also.
102
Chapter Sixteen
te So) Wy
Pe
ty.
Spal
oo
sO
Atlin
ih
Chapter Sixteen
Chapter Sixteen
Use the strong form of the Pumping Lemma and a long word of
the form #°6"c° where > 22.
Use the weak form of the Pumping Lemma. If v and yp
contain parts of s only, yyvvryyz changes the s part but not
the reverse(s) part, so they no longer correspond, and
similarly if they contain substrings from the middle (reversed)
section only. If they contain substrings from both parts, since
UPDOWNUP does not have the bilateral symmetry of
PALINDROME either the inflated left s will not match the
inlated right s or the inflated. s will not correspond to the
central reversed section.
is. 29 20. The Pumping Lemma for CFL over a one letter alphabet is the same as the
Pumping Lemma for regular languages over one letter.
W = uvxyz = a?ata‘ava'
uv'xy"z = aPa™a‘a™a’ = aPirt gnats)
While w=xyz= a‘ata"
xy"z = afa™éa" = al an®
Both are of the form a@™™ anconstan)_
If a language fails the Pumping Lemma for regular languages then it fails the
Pumping Lemma for CFL
105
Chapter 17
One of the high points of this chapter is definitely that the machine proof for the closure
of CFLs under product is bogus. This is yet another mathematical caveat. More is learned
from wrong answers than from right answers, especially if they are someone else’s. The
cautionary tales of these “almost” proofs are as important in learning wnat PROOF is and
what PROOF isn’t as are numerous examples of correct proofs alone.
In the proof involving the intersection of a PDA and an FA we state that the PUSH states
need no FA labels because no branching occurs at such states. Profs. A. Barnard, L.
Leenen and T.A. Meyer have pointed out to me (and their students) that a better
explanation is that FAs only change state when reading input. | feel that this is what |
meant, but they state it better.
106
Chapter Seventeen
(i) S > aX
X > aX|bx|A
(it) S > aB|bA
A-aS|bAA|a
B > bS |aBB|b
(iit) S + SS|BS|USU|A
B = aa| bb
U = ab|ba
(iv) Srey
X > aXb | ab
Y > aYb | ab
(i) S + XY
X > aXb | ab
Y > bYa|ba
(ii) Do NY
X > aXbb | abb
Y > bbYa| bba
(iii) S> ky
X > aXbb | abb
Y > bYa|ba
(iv) S > eZ
X > aXb|ab
Y <2abY2.|/ba
Z > aZb |ab
We get all words of the form a"b"a™b"
5 nd 25, 5 | ab
S,+ bS,a\ ba
(ii) No. Every word in the closure of this language must be
factored into substrings that are words in EQUAL. The string
4ababhb is in EQUAL but not in the closure of this language.
(iti)
5} > a5; b| ab
57 bS,a\ ba
107
Chapter Seventeen
Chapter Seventeen
(iv) S+ SSIA
5; > Xa
X~> bOXLA
(VY) $+ 5.5515,
517 56
Q> ala
6. (See also Chapter 4, Problem 20.)
(i) Any language is regular that can be defined by a regular
expression. Replace each 2 in the regular expression for Z by
s,and each 5 by s, Since the strings can be represented by
regular expressions, this can be done. The resulting regular
expression defines the substitution language, which is
therefore regular.
(ii) In the CFG for the language, change each terminal 2 tothe
string s,and each 4 to the string s, Eventually, in the
derivation of any word in the original language, the terminal
must have come from some production where it occurred on
the right side. This occurrence has been changed to the
substitute string.
7c) Ley i me
X> AXb| 2ab
Av» aAla
Ys a¥B | abb
Ba 6B \b
(ii) Saud
X 7 aXb| ab
Yo b¥2 | ba
(iii) Sa XY
AX LZaaz
Z> al | bZ\A
Yo arl\6¥\a
109
Chapter Seventeen
Shaws b ys Bare
Chapter Seventeen
Chapter Seventeen
Chapter Seventeen
17. (i) The algorithm works fundamentally by de Morgan’s law (see
Chapter 10, p. 183), that is, we complement the union of the
complements. If a PDA is nondeterministic then some word that
is accepted by one path will be rejected on another path. When
the ACCEPT/REJECT status of the states is changed, such a word
Will still be accepted, by one of the paths that did not work on the
original machine. This shows that the procedure is bad, since a
word cannot be in a language and its complement both.
(ii) Yes. It may result in a nondeterministic PDA, however.
13. (i) The PDA is on page 350. The FA and the intersection machine
are below. Note that the alphabet is= = (2 45, ¥}). The FA
accounts for all transitions. The PDA accounts for strings that
a
en
SS S
ae
(ii) First note that any J causes the string to be rejected by taking
it to a state that includes FA state 3. These states have no
A- edges. The #s read initially are stacked. The Y causes a
transition to the next state of both machines. Thereafter, any Y
read (or popped) causes rejection. For every #read, the stack
is popped. If TAPE and STACK are both empty at the same
time, the string is accepted. As many #’s must be read after
the XY as were stacked before.
19. (4267) a(a+b)*
abe,
3 son gl
a
Chapter Seventeen
piaeD) 7 (a+b)*aa (as byeer ER -EVEN
@
7) b
e(2)5
BOae
-) 2
G) Tejeme2G
y oh
? é 3)
Oo
(i) (2959
\
aN
RAO Ba EA,
Be ve
PUSH
| @ Foden
a READ,
>A Por, SE
SCACCERT
4 SS per: bee
(foQD
(ii) ¢
: 7: es va \ xX
ESLER : css) ep eaten)
a
b men: 5
NC @
Ae 2 pecan “aN
PRP ONE
(iii) (2252 922)
Chapter Seventeen
(iv) (422622 n=0, 1, 2,...)
CSTART )
mo S ue 2
RUE. WAS OP x6
BA oo = 4 ve
es Ne
Q *, ‘ a NY *. | A oO
2avs os we ny 5 a cx oe 2 ra ‘ BS a s By a ) we a
aN Xx
rs Ss Pa .
Chapter 18
The numerous references to what is undecidable can only be verified by something like
Rice’s Theorem which cannot be given until after TMs are studied, but by PART Ill we
have about lost interest in CFLs and their petty questions. What is undecidable about TMs
becomes so much more interesting. Perhaps in another edition Rice’s Theorem and the
proofs of the undecidability of the questions in this section will be formally presented. At
the moment students must be satisfied with a feeble “we'll see soon” type of excuse.
The CYK algorithm as presented in the first edition of this text turns out to be not the CYK
algorithm at all, but my own invention. Oh my. It is a perfectly effective algorithm for
deciding whether w can be generated from G but it is not the creation of John Cocke. |
made his acquaintance in the summer of 1979 at IBM Research at Yorktown Heights, NY
and over one lunch |jumped too quickly to an interpretation of what he said. The algorithm
made perfect sense to me and | published it as his. This is a disservice to C and Y and
K since their version is better. They have my apologies, as do the students who have read
the first edition. But since the theorem was decidability the proof was not wrong, merely
the attribution. And as is stated repeatedly throughout the text, it is not how best to do it
that we are concerned with but whether it can be done at all. Still it benooved me to
correct this mistake, and we do here present the CYK in all its glory.
The PDA-transducer for parsing simple arithmetic is a valuable link to courses on compiler
construction, and for those students not taking such a course a satisfactory convincing
demonstration of how compiling can be done. It is quick reading and needn't take up much
class time. On the other hand, it is interesting to discuss what it means for a
nondeterministic machine to be a transducer. What if the same input string can produce
many different outputs, is this a problem or an opportunity?
116
Chapter Eighteen
(i) no words
(li) = yes; ab
(iii) yes; baba
(iv) no words
(v) yes; abbbb
The algorithm actually does not really use the fact that the grammar is in CNF at all.
Allowing t to be a terminal or string of terminals covers grammars in any form.
If the only nonterminal is S then a live production means that S is self-embedded and can
generate strings with any number of occurances of S. Moreover a dead production means
that all those S can be turned into substrings of terminals. Hence the infinitely many
strings generated of any length are all words.
117
Chapter Eighteen
12. (i) No
118
Chapter Eighteen
;
i eay es
aaaa abaa rk
aaab
baba bbba fore bbbb
(iii) No
ay;
T trom F trom S
(il (/* 442 hon ( F* + S)iron( F* F + Strom (F* 7+ 1Mtron( 7+ tron( 7+ &)
tron( J+ J trom( 7+ & )tron( £ trom Ftrom Ttron & trom S
UY £*( 4+ )trom FY S42 jtrom F*(F +f bron F*( 7 +7 trom F*( T+ F)
from FY T+T hon F*( 7 +8 hrm F*(F rom F* Firen F* STtron trom § from S
Pry =7) sacle 7)” Kiron (A metal Finca a eaeence a) Be
tron (J) * Strom (AF) * Stran F * StrenF *FironF *trom
J Jiro FirmS
is(i) 5% £9 &-73 F739 T/ F- 13 FIF-T3(8)/F- T
3 (F-T)/F- TA (T- 7)/ F- Ta(F- 7)/ F- T
> ((£)- TP) F-T3 ((#+T) -T)/F-T3 ((7+7)- TF -T
>((F+ 7)- 7)/ F- Ta((f+ 7)- T)/ F- T
>((/+ /)- T)/ F- T(t /)- 72 F)/ F-T
> ((7+ S)- 12 F)/IF-T (r+ 1)- Fe FF) F-T
> ((4+ /)-f2
F)/ F- 73 (re f)- ff) F-T
> ((/+ /)- ft /)/ 4-79 (4+ s)- ft f)/7-F
> ((/+ /)- 424) / f-4
(ji) 59 89 #+TAT+ Tan k+TaA f+ Tad i+ Tadi+Fads¢+ sf
gi) S9 F9 F-7T9 7-79 TF -197* AFT FFE -T
> PA F-T3 G1 F-TaA L
ss (-T? Pe t- FR ttli-s
(vy) Se £9 F3 AF HAFS HFS dis ds
Left to right: divide the quotient of the two left parts by the
120
Chapter Eighteen
Chapter Eighteen
(iv)
STACK TAPE OUTPUT STATE STACK TAPE OUTPUT
A (3+5)+7*3 START is (3*4+5}*(2+ 34)
A 3+5)+ 783 READ A 3*4+5)*(2+3*4)
( (3+5)+783 PUSH ( ( 3*4+5)*(2+3"4)
( +5)+ 783 READ ( ™4+5)(2+3*4)
( +5)+793 3 PRINT ( *4+5)*(2+3%4) 3
( 5)+733 READ ( 4+5)}*(2+3*4)
A 5)+7*3 POP b 4+5)9(2+3"4)
( 5)+743 PUSH( — ( 4+5}*(2+3*4)
+( b)e7s3 PUSH® = * 4+5}*(2+3*4)
+( )+7*3 READ * +5)}7(2+3*4)
+( )+7*3 5 PRINT *( +5)*(2+3*4)
+( +783 READ <i 5}#(2+3*4)
( +783 POP ( 5)?(2+3*4)
( +783 + PRINT ( 5 }*(2+3*4)
A +783 POP A 5}*(2+3"4)
a 783 - PUSH( ( 5}#(2+3*4)
a 73 PUSH + +( 5}*(2+3*4)
+ 73 READ +( (2+3*4)
A 23 PRINT +( }*(2+3*4) A
+ 33 7 “READ +( *(2+3%4)
+ 3 POP ( *(2+3*4)
4 3 PRINT ( *(2+3%4)
’ 3 POP a *(2+3%4)
ty 3 READ i (2+3*4)
By A POP A (2+3*4)
a, ; 3 PUSH® (2+3*4)
oa A READ * 2+3*4)
+ a PUSH( ss (® 2+3%4)
+ a s READ (8 +3*4)
A s PRINT (# +3%4)
A A + READ (* 3*4)
: " POP z 384)
35+73%+ PUSH( ( 3*4)
; 3547384 PUSHi+? 2 (© 9_33*4)
fe 5+73%+ READ +(® —-*4)
3 5+73%+ PRINT +(f 84)
3 +73%4 READ +(® = 4)
53 +7384 POP (* 4)
53 733% PUSH+ +(* 4)
8 7384 PUSH * *4(* 4)
8 38, READ #(® )
122
Chapter Eighteen
3*+ PRINT a, (® ) 4
By READ a,(3 rn
By POP +(® a
+ PRINT +(® ri “
+ POP (= a
A PRINT ( 4 +
4 POP . a
A READ z a
A 29 POP A A
PRINT 4 A .
ACCEPT 3485523480
START 34*5+234%+*
4*5+234%+* PUSH 3 cn deWf bot
4*5+234%+* READ Sa
*5+ 2348+" PUSH 4 4:42) D7 oe
¥5 42348" READ 432 17 +
5+234*+* MPY P2032. Eee
5+234%+* READ {2-2 17 =
+234%+* ADD 1417 *
m2 3ate* READ IC ie dae
234*+* MPY 238 a
234*+* READ 238 a
Z4%>* PRINT 238
aay 34*+%
Zel} 4*+*
17. The machine on p. §22 can evaluate prefix with one slight
alteration and one major intuitive leap: The alteration is the
exchange of open and close parentheses in the processing: the
intuition is that the infix string must be fed in backwards. The
output of this transducer is the transpose of the prefix equivalent
of the reverse of the original string.
. Again, the trick is to feed in the reverse of the prefix string. If
this is done, we process just as we did postfix. It should be noted
that the reverse of a prefix expression is not its postfix
equivalent.
19. While an algorithm is not necessarily restricted to a single sTACK,
it is worth demonstrating that only one is needed to do this.
123
Chapter Eighteen
> PRINT”
(START ) ae
AX POP ACCEPT )
Loe es
7 N Af ve
SH sigri CREAD =, hein ee ows ah
eee Sy PRINT ACRE AD PRINT,
er :
mee DNS.
SOF eA a aN
ele
Ey
FLISH
— ty FRINT A
Hs AHN a
“POP
mee Nis
~ “
ees Sone Oe
7 PRINT“ PRINT POPSC
At
(ACCEPT)
124
Chapter 19
Turing machine definitions and their associated pictorial representations are fairly
standard with the exception that we have chosen the unauthentic version of the one-way
infinite TAPE. In general | would have said that this is a bad choice and the two-way TAPE
has obvious advantages: (1) we do not have the artificial threat of inadvertently crashing
by a left TAPE HEAD move, (2) the association to Post machines, 2PDAs and multi-track
TAPE TMs is easier to make, and (3) it is Turing’s own choice. The reasons for not using
this scheme are: (1) in order to hook onto the students previous intuition developed on the
PDA, whose TAPE is one-way infinite because it is a manifestation of the FA invisible
TAPE, (2) it does tend to anchor the input as opposed to letting it float in indeterminate
space where we are constantly in fear of losing its location, (3) it helps us begin to draw
the inference that computers are examples of limited TMs, and (4) it justifies numbering
the cells from (i). 4>3 QED.
Yes, there is some unjustified asymmetry between illustrating INSERT over a two letter
alphabet while we illustrate DELETE over a three letter alphabet. The purpose is clearly
that the earlier example is drawn in a simpler fashion and INSERT is more natural to be
the first discussed, especially since we have the perennial “rewind the TAPE HEAD to cell
’ problem. The instructor should probably do some blackboard version of the alphabet
of n letters if he feels the need for pure mathematical full generality. But | have a feling
that any student who has the mental abstraction capability to understand the design
for the alphabet ) = {x,, X, ...x, }can imagine it for herself from what is presented in
the text.
There is no such thing as giving too many examples of TMs. Being able to work within the
constraints of the TM instruction set is the essence of understanding how a computer
works. Unlike FAs or PDAs, programming TMs is real programming.
125
Chapter Nineteen
Chapter Nineteen
(4,4,2) (2,9,8’)
(6,6,£) (*,4,2)
(6,50)
(i) af ne
CHAT
———_.,
eT ; aRT : #224)
(4, 4A). ————. (AA,4) ».2 6 2
irae TT - OSS)
IQA") iy x
27,
Chapter Nineteen
7.(i) In states 4 and 7, the last letter has been compared to the first
and changed toa A if it matches. The transitions at both states
are a loop on gor Sand a transition to 1 on A. Since the
transitions match perfectly the states can be coalesced.
(ii) By using the algorithm of deleting an initial and then deleting
a terminal 4, the machine can be constructed with 5 states
including START and HALT. (See 6(ii), above.)
8(i) leat>2e#Aar3 2Amr4edAar5S #AX7 #AX48 2 AY
910 ##4> 12 #e* > 8 tee> 13 #e*Q > HALT
(ii) l sa2232 #Aga3 2Aaagn3# Asahi 42#AsarS #Aara
6#Aat71 AgX¥> 2 2 AAX CRASH
(iii) 1 #gaaa> 2 pAgaa> 3 #8Aaaa7> 3 #Aaaa>3 4 Aaam
+4 sAaag>5 #AagX> 6 # Agak 6 #Aaako | #2Agarxy
32 #AAaxn 3 #2AAafr 4 #AAayxyr 5S #AAXNR7 #2AAXY
97 #AAXY> 8 sAAXNX@> 10 #2 ANY 10 #8 AXXO 12 #2 AY
212 #2 At > 8 AeXs 10 satX> 10 eetXs 12 eee
912 seers 8 saeee > 13 wees 13 eeeeA > HALT
(iv) 1 Saehbaabh 292% Aabaabh 293% Aabhaah +3 * Aasbaab
93% Aahsab 93% Ashbaah 33% Ashaah > 4% Aabaab
295 *%AsbazgY 26% AabaayY 26% Aahgay 26% Aabaay
a6 %*AghaaY 26% Aabaak 391 *AabaaY 92* AAbaay
33 *AAbaalY 293 * AAbaal 393 *®AADaal 9 4"% AAbaayY
45% AADAXY 26 *AADAXY 2 6 * AADAXY 2 1 B®AADAXY
+1 %AABaXYY 322% AABAXY 93 * AABAX 248% AABANXY
a5 *AABYYY 27 8 AABXXY 397 B®AABXY 397 8AABXXY
38 *4ABYXY 28 FR ABYYY 910 #8 ABLLY310 88 ABLXY
+1288 4AB*NVY
a1288 AB SHY 3912 FR AB* YY 8 BR AB*NY
>10 #8 BY 310 F884 B* VY 310 FRR AVY 312 BHR Bt PY
+12 #88 BY s12 #88 PY 4B eee BY 9 wHHHMEY
49 ##ee P,Q atte YQ aeeetee | jy aes
+] ] RADA” => 8 sea he 313 on eee 313 non eett
tee
ren yees) EN EL) QUbdd
{INSERT#}-9C ; Caner ae
Z nat
START
(24,8) (44.00) (6,8,L)
ba
14. The loop at 5 can be (222); (6,6,Z), (4, 4,2). We know that
there is a * to prevent a crash by moving left from cell i, so
there is no reason not to loop on A as well as on azand 2
130
Chapter Nineteen
Chapter Nineteen
(a,A,L vy NGL)
4
(2,062)(AAR) 16a
(A681
19. (i)
(b,b,R) (a,a,R)
aie ©) (A,A.R)
START es) AAR)
(b,b,R)
(ii)
(b,A,R) AR b AR A.aR
START
(A,b,R)
20.
182
Chapter 20
Many instructors skip this chapter but then find themselves embarrassed by the references
to it in the later sections of the text (in particular the next chapter and the discussion of r.e.
and recursive languages). | personally believe that the work of Emile Post is as brilliant
as Turing’s and that but for the Allied decoding project Colossus, Post would get an equal
share in the credit for founding computer theory. The fact that changing a STACK into a
QUEUE escalates the ability of the device orders of magnitude is an insight of the greatest
importance in this subject. Most people mistakenly believe that the Post model is limited
as a practical model of a computer since it does not provide random access to the data
field, only to the two ends of the STORE. However they then fail to realize that Turing’s
model also provides us with only two data cells of access at any instruction, the cell to the
right of the TAPE HEAD and the cell to the left. The true advantage of Turing’s description
is that in its two-dimensional form, it allows us to imagine the whole blackboard as a TAPE
to be operated on and so heuristically explains why the TM can perform all known and
knowable “algorithms.”
The fact that given READ-FRONT and ADD-BACK we can write subprograms for ADD-
FRONT and READ-BACK whereas given ADD-FRONT and READ-FRONT we are stuck,
is the purest example of the importance of data structures as a deep field of investigation.
Another selling point for the importance of this chapter is that it is the first and best
example for simulating one entire machine on another (except for Mealy = Moore, which
is essentially trivial). This is a skill that crops up in the actual practice of computer science
all the time, and the student should have the theoretical basis of how to do it: equate data
bases and instruction sets.
The whole chapter can be treated in one class and it richly deserves at least that.
Chapter Twenty
li) START- #525 > READ2-426 + READ, -25 > READ> -4 READ, - A
+ READ» - A - ACCEPT
(ii) START-ba255a READ)- 24664 > READ3- a654 4 READ)- 54a READ- ba
+ READ? - 4 READ3 - A ~ READ)- A - ACCEPT
(iii) START - 242555 READ) - 24665 + READ, - 2605 ADD a- abbba
+ READ, - £644 > READ2 - baa >READ3 - 22 > ADD 6- 226 9READ3 - 2b
+ READ, - 6>READ, - A > READ» - A > ACCEPT
(iv) START - 225555 4 READ) - 2654 9 READ, - 5566 ADD 2- bbbba
+ READ, - 554 > READ2 - 662 READ - 52 ADD 5- 525 > READ, - 25
+ ADD 5 - 266 + READ3 - 56-4 READ? - £7 READ3-A
+ [ADD 6- 5 READ3- A + ADD 6...) INFINITE LOOP
a START - 6646428 ~% READ - babaa8 > READ3 - 26248 ADD 6- s6a82b
> READ3 - 54420 + READ - saab > READ3 - 440 > READ) - 24 > READ, -
6 ADD 2- 62 READ, - 2 > READ) - A> READ, - A 7 CRASH
2 and 3. The machine works as follows: READ, is the state of having
consumed equal numbers of zs and Os. If the string becomes
null in this state we accept it. READ, is the state of just having
read the first excess z READ;of just having read the first extra
b. In these states, reading the minority letter just cancels out
the previous excess letter. However, if we read the majority
letter in one of these states we add it to the STORE. A String
that contains a single surplus # consumes all the d's and the
non-excess #s, perhaps on several passes through the input.
Finally, the extra 4 is read in READ», control transfers to READ,
where the string crashes reading A. A symmetric argument
applies for 4's. More than one letter in excess results in the
cancellation of equal numbers of both, as before, but once the
minority letter has been exhausted there is no way to pair the
excess letters. Every excess letter after the first is added to the
STORE, which is never shortened to A.
Chapter Twenty
4.
ao:
ae AG
vy
&
5.
(ACCEPT ea
6.
7A)
READ >
A
i335
Chapter Twenty
(ii)
START
8.
EA : 4
| SHE pea [Sue }<E
<FEAD) :
ae, Sy
{2 a Ya
D> REJECT }
ACCEPT)
10. By Theorem 45, every regular language can be accepted by
some Turing machine. By Theorem 47 every Turing machine
can be converted into a Post machine. Therefore all regular
languages can be accepted by some PM.
136
Chapter Twenty
11 (i)
start state
EADS. <REAU
i:
7 .
eccccccesesese® Ao
acc cesses
ecco escocsccconcosrces®
halt state
Chapter Twenty
+ ADD A- 92544 SUB- A* 255>SUB- bA* ab>+READS -A"2b7 ADD & A*%abb
~ SUB- AA* s6-+READ ¢- A*’a67 ADD a- * aba READ - 4624-4 ADD A- shah
+ ADD * - bah" + SUB- *a5ah 4 SUB- A* aba ACCEPT ,
Note in (iii) and (iv) that the initial A* at ACCEPT shows that the
(simulated) TAPE HEAD is reading the first blank after the input.
(v) a(a+b)*b
(vi)
-———_-.. we aN ; WeoN, > ieee
USTART JX READ >=] SUB LC READ > ACCEPT)
:
See
NGA
4Neal
eitesers
123) (ii)
(START
ies] 5
13.(i)
START}
a, | we
Ceca ae LG
anLan READ) CACCEPT)
ave NY
(ii) Take a counterexample of the form (4”24”) and use thestrong form of the
Pumping Lemma for regular languages. :
(iii) It can be generated by the CFG S #Sa| a5b| 55a| bSb| 2
14. The algorithm in the chapter does not account for SUB. 1. Read and delete the
rightmost letter; 2. Move all the way left; 3. Insert A before the string: 4. Writs
the deleted letter onto the A; 5. Return the head to the reading position:
138
Chapter Twenty
(A,4,2)
START )(4,6,2) (28,84
Cy re wy
@,¢,£)
r, n=) 5
-(4,4,R) (A644) Let Xoo
“ Cany,=,1)
1):
? *« ACCEFT
en)? [AG 3
d b
READ
START SoA 4 ie
BAY ADD b
ADD é
(i) START- 42565 ADD *- #255" > READ ;- 254" ss READ>- bL°> ADD «-bh*2
> READ,-4° > READ2- * > READ4- A> ADD #-*" 3 READ,-A CRASH
Chapter Twenty
We
(o0CEPT)
140
Chapter Twenty
(TART [a0§]
TET
Se a
mea
19.(i) Delete the first letter and remember it by path choice: mark
the end of the string with *: use INSERT to write the
remembered first letter right after the *. When * is read, all
letters have been processed. The INSERT routine will have to
be a variant of the one presented that permits replacing A by
the letter to be inserted.
-¢ ae
Set Sait Ina
E wy M4 os
| START
yt : .
)-
- a Ee ‘ ‘ c
-
ba eee te eer ees
Se a ( x pa{ = ,
We | atat
i fA (Sere
wu
CAN 2 a fa wae,
Doct Sit i”
Mess! ‘ . *
t %
,
- aes < ~.
Chapter Twenty
(ii) Mark the end of the string with # and use $ to separate the
reversed string from the unreversed. Read the first letter and
remember it by path choice. Cycle through the string reading
and adding each letter as it is encountered. When # is read it
is added back and the remembered letter is added
immediately after it. The rest of the string is ignored (i.e., read
a letter, add it), until the $ that marks the end of one trip
through the input. When the initial READ state reads # the
entire string has been reversed. Cycling through to $ puts it in
the right order and removes the two markers. _
fe
READ:ee
os ey a f [ALL 3|
Chapter 21
This is another chapter that should not be skipped. Again it takes only one class and it
pays off in two ways - it organizes the whole structure of the course OPDA. 1PDA, 2PDA,
and at the same time it begins to convince students that TMs are in some sense “ultimate”
expressions of algorithm design: TM = 2PDA = 3PDA = 4PDA =... .
Several of the variations covered in the next chapter could be proven equivalent to kKPDAs
as easily as to TMs directly. We did not do this for fear of disadvantaging the students
who were told to skip this chapter. If this chapter is covered in your course, keep it in mind
as a variant method of covering much of the material in the rest of the course.
Students should also be advised to read the excellent books by Minsky, not only a founder
of the subject but a great expositor.
143
1.(i) STATE TAPE STACK; STACK, (ii) STATE TAPE STACK, STACK,
START a2255 A A START babah A A
READ #b5 A A READ abab oA A
PUSH; 2 255 2 A PUSH 5 2625 A b
READ 55 a A READ bab A b
PUSH; 2 55 ag A PUSH; « bab a b
READ 6 a2 A READ ab a b
PUSH 4 5 ab PUSH) 5 25 2 bb
READ A a2 b READ 6 a bb
PUSH» A a8 bb PUSH; a 5 a2 bb
READ A PF bb READ A a2 bb
POP; & 2 bb PUSH) 4 4 a2 bbb
POP, A FI b READ A aa bbb
PoP, A A b POP; A P bbb
POP> A A A POP 4 a bb
POP; A A A POP; A d bb
POP, A A A ACCEPT POP, A d b
POP; A d b
POP> A A A CRASH
As the entire string is read, 4's are pushed onto STACK, J's
onto STACK,. When the input is exhausted, the stacks are
compared. To get to accept, they must both run out at the
same time. Therefore, the strings accepted by this machine
must have the same number of #3 as Ds.
we a FON re /
cer, Gr treT Fors APory POP,
ay * Ne
144
4.
(START |
ot eo \
(ACCEPT }<READSEREA
%.
( START =o,
VAN
ReSGPOF, S2AFUSHS
EI 5]
2a
oy io:
ACCEPT }4 : f
6.
1p
ACCEPT
145
L)
({a,b,#],=,R)
([a,b,c,#],=,L)
9.
START A ACCEPT
a Cc
Kea
b
READ Y
;
- ADD c
10.
FOP2 x ACCEPT
a
146
(ii)
<< s
A
Con) aa
a Cc
b
a
p
c
HWE
: 7
147
6
sb
148
14.
15.
Chapter Twenty One
16.(i) START £663 240633 Aap 393 Ashk 9 4 Arba 5 Anbs 3 6 Ashe
96Aa0h
296A26/ 3 6Aadr > 6-Ashbe
97 Ash > 8 AAD
+8AAbL°
> 8AALY > 8 AAD +8 AAD 79 AA DL 4 HALT AAD
(ii) START
622 3Aga> 2A52 92 A509 4 Absa > 5 Abas > 6 Absa
>6Absar?
> 6Abse > 6 Aba > 6- Abas? 37-Abse®
11 - bAase >
11- AA se? 11 - AAasse 9 11 - AAage 9 11 - AAaa? 9 12- AAae 3 13 -
AAs? > 14- Adasth > 19 - AAae 63 20 - AAse’ 6 21 - Abas AO 24-
AA satBA> 25 - AA se” BA - CRASH |
17.(i)STATE APE STACK; STACK» (ii) STATE APE STACK; STACK>
START abba A A START bab26 A A
READ bba A A READ asba6 A 4
PUSH? 4 66a A a PUSH? 5 2625 A b
READ ba A a READ bab A b
PUSH2 6 ba) A ba PUSH2 2 620 A ab
READ a A ba READ #5 A ab
PUSH) 62 OA bba PUSH) 5 ab bab
READ A A bbha READ 5 A bab
PUSH2 4 4 A abba PUSH) # 5 A sbhab
READ A A shbs READ A A sbab
POP) A A bbs PUSH 6 AOA babab
PUSH; # A 4 bbha READ A A babab
POP, A a ba POP, A Fal abhab
PUSH; 5A ba bar PUSH, 6 A b abab
POP> A ba a POP? A b bab
PUSH; 5A bba 2 PUSH; « A ab bab
POP, A bha A POP A ab ab
PUSH; 2A abba A PUSH; 6 & bab ab
POP, A sbbe A POP, A bab
POP AG aye PUSH; A abab
POP; A be A POP A ehah A
POP A a A PUSH;5 A babab A
150
19. Lis accepted by some 2PDA; therefore, by Minsky’s Theorem, there is a PM that accepts L.
In chapter 20, problem 20 there is a PM that accepts L’. (It is not possible to use the
reversing procedure of problem 19 as a preprocessor unless the algorithm either uses only one
stack for processing or simulates a PM, in which case a marker can be uses to separate the
reversed input in one stack from the contents of the other stack.)
20. (i) Use the folded tape model. If all three stacks were beg maintained on a single track tape,
and the tape was folded at the pot of the tape head then two stacks could easily simulate the
tape head movement (move right means pop 2 x, push | x; move left means pop 1 x, push
2 x.) So initially place four #’s one stack 1 subsequently pop 1-push2 the items over to stack
2 to adjust to the top of the desired stack before changing that stack. Finally before the
simulator resumes processing, restore the stacked stacks to stack 1 with a series of pop2-
push operations. For the most part stack 1 will look like:
#
stack |
if
stack 2
i
stack 3
#
(ii) Obvious.
151
Chapter 22
Despite the fact that all of these results are very important, the student who has suffered
through all that has come before should be able to create most of these proofs for herself,
with the possible exception of the equivalence of nondeterminism and determinism. Once
the trick of how to do this is seen it should be obvious that it is not important to use a multi-
track TAPE but that a few markers on the one track TAPE should suffice.
| toyed with the idea of proving that NPM=PM and that N2PDA=2PDA as separate results
independent of TMs. The trouble was that since the best place to organize the idea of “try
every alternative in sequence until we find one that works” is with TMs, and the best time
is after the introduction of PMs and 2PDAs and their equivalence to TMs, by the point that
the proof would be easy it is already moot.
(ii) Each of the two plain states needs a twin state to handle the different move
directions. Also notice in the machine below that we distinguish between a move
left and move right to HALT. The tape head can always move right but moving
left from the cell 1 causes a crash. Hence we needed to add yet one more new
state.
A/a
meee
a/A
())
<u b/
START 7
(: ‘ r)
$, A
iS # $, $ A, $,
(‘ =, /) (:
$, ‘) (: > >
a Clearly k+1 markers are needed to separate the data section of the & tracks. In addition, in
order to keep track of the position of the tape head, we need k more markers of a different
symbol. Notice that this method provides extra versatility, because each of the k abstract
tape heads can move independently of the others. In total that makes 2k+1 markers - not
all of which must be different. Now we already have INSERT and DELETE subroutines,
so we can easily maintain that the markers surround real data without extra working
space. Any time we encounter an end of data section marker for some track we can
always insert the necessary blanks and keep working.
6. (i) 1) Scan the tape inserting zeros on the track 1 for as long as there are digits in a
cell on tracks 2, 3, or 4.
2a) For each combination of values for carryl, digit2, digit3, and digit4 such that
their sum is a single digit, place the result on track 5 and move left.
2b) For each combination of values for carry], digit2, digit3, and digit4 such that
their sum is 10 + a single digit, place the single digit result on track 5,
move left, place a | on track 1 (carry) and do not move the tape head.
2c) For each combination of values for carry1, digit2, digit3, and digit4 such that
their sum is 20 + a single digit, place the digit result on track 5, move left
and place a 2 on track | (carry) and do not move the tape head.
3) Finally when the tape head encounters the $ marking the end of the tape, bring
down any carry that might remain, e.g. copy track 1 cell 1 to track 5 cell 1.
[55
(ii)
9<sum<20
\o A : + — A teQo
8
19 <sum+l < 30
Ear)<——
one SERED eee
9 < sum+? < 20
(Assume tracks | and 2 contain “$bit-string*” and tracks 3, 4, and 5 contain “$*”
1) Copy bit-string from track | unto track 4 in between the $ and * markers.
2) Read rightmost bit on track 2. (Scan right to left bitwise)
3) If the bit = 1 then align data on tracks 3 and 4, add the two bit-strings placing sum on
track 5. Copy track 5 onto track 3 (between the markers).
4) Insert 0 to the left of * on track 4.
5) If there is more data on track 2, GOTO step 2.
(i)
156
ade)
Monee
(i) For inserting or deleting from track 2, each instruction takes the form (any,
>
any,
Using the notation (state, read, write, move, state) the following is a method for
INSERT d:
(1, a,d,R, 2) (1,b
(2, a, a, R, 2) (2, b, a,
(3, a, b, R,2) (3, b
DELETE: (1,a, #, R, 2) C1, b, #,
(24, 2 2 )4e4D. Dy
(3.3. A. 4). (270 AAs
(4,74. a, L,
(ii)
157
5B 98
(:a ye ) (=) Compact a’s
10.
Reset head
to non-A
on Track 2
a (i) Assume that cells 1 contain $’s. Read2 means on track 2, etc.
1) scan $, write2 #
2) readl a, write] A, GOTO 3
read1 5, write] B, GOTO 4
readlA, goto5
3) reset track 2 to # - read2 #, write2 a - write2 # - reset track 1 to A - read1 A,
writel a, move right, GOTO 2.
4) reset track 2 to # - read2 #, write2 A - reset track 2 to $ - move right - read2 a,
write2 # - reset track 1 to B - read1 B, writel 5 - move nght GOTO 2
5) reset track 2 to # - read2 #, write2 a - HALT
158
16.
(ii) As in problem 6, place two markers, y and z, on track 2 of the tape, in consecutive cells.
Alternately, move y one cell to the left and z cell to the right until one of the markers
in situated under a non-blank character.
(iii) The machine is as described above, except that the markers are on the same track so the
checking for an input letter must be done before moving the marker each time.
19; Using the Myhill Nerode theorem, since r is regular there is a finite number of equivalence
classes for this language. Chop (r) certainly defines fewer equivalence classes. Hence the
number of classes for Chop (r) is finite and Chop (r) is regular.
20. The difference between instructions (right)(left) and (left)(right) is that the net result is the
suffix of one expression in the other as opposed to the prefix. We do not have a suffix
language that is known to be regular. However, if use the transpose if the strings then take
the correct prefix and transpose again then we have essentially obtained the suffix. We
160
already know that the Transpose language and Prefix language of regular languages are also
regular. So the agglomerated instruction is
Chapter 23
In the previous edition this was two different chapters. The amalgamation has focused
attention on the r.e. languages as a class with questions similar to those answered or
considered for regular languages and CFLs. | think | previously made too much of the
details of the decoding process. Good programmers and readers of this text up to this
point should be able to write TM code to do most of the tasks required without my help.
The encoding of TMs for the purpose of constructing the languages ALAN and
MATHISON is another example of where we have started with a basically pictorial
description of a machine and then later had to convert it into and algebraic equivalent in
order to establish some results. This again does not mean that it would have been
superior to have started with the algebraic formulation in place of the pictorial one
Originally.
The existence of the loop set, and in fact its inevitability for certain languages not just
certain machines, is a point to dwell on since it is the foreshadowing of the Halting
Problem. The sooner the ineluctability of indecisiveness is appreciated as an essential
of the language and not a fault of the programmer, the better.
We have avoided the standard black-boxing of TMs and tying them together with mystery
strings such as “feed the output of this into that’, or “run it on both machines” and instead
give explicit illustrations of how this can be done. | find that more satisfying. After the
details are covered an overall view of what is going on should emerge (as in Kafka’s Penal
Colony).
The significance of the non-r.e. language should not be minimized since it paradoxically
undercuts the promised universality of the TM. The Halting Problem should be presented
as a problem in two senses. | hope the machine LAMBDA is clear. One could, of course,
write it out as an example for some particular word if one thought that would increase any
student’s understanding.
162
(a,a,R)
b,b,R)
(b,b,R) (b,b,R)
@aaR)
SS (a,a,R)
(ii) (*,A,R)
(b,b,R)
AAR START (b.A.R), (kK,*,R)
4 & (a,*,L)
x
gee aD
R (a,a,L)
(b,*L) («,*,L)
(A,A,L)
(a,A,R
(aA
(a,A,R) (b,A,R)
Chapter Twenty Three
(v) > >*,R)
(*,A,R tR (b,b,R)
ee
“0g (a,*,L)
(*,*,R)
(a,a,R) \hss
FAM ee RED
2. accept(7;) is the language of the regular expression aa*b(a+b)*
reject( 7,) is the language of the regular expression a* + b(a+b)*
loop( 7;) is empty
3. accept( 7,)is the language of the regular expression aa(a+b)?
reject( 7>) is the language of the regular expression
(ab+ba+bb)(a+b)*
loop( 75) is empty
4. J, modified 7p, modified
START @ 2") (START%.
‘pad(630) yaaa
(aber h) ED meee O22 2.GRD
(4455, eyyee Hees ) A#;=,)
($A%5 eo _ M68
a (ariy,=,) (203 (ny,=,0%
7; remember that the INSERT subroutine must also be run in
alternating steps on the two machines as described in 12, above.
164
BASE! Cua )
(non#Z,=,2 )
(non ¢,=,24) (4)
(START (#2824) 73 (82,6)
NG5,8,28)
4m, fariy,= 2,8). i Lars,
— )eH
(6
fons
on (ron
* =, 2
JAM)
(non 2,=,2) | Se nat )
(A%,L£
aS LP ene a faye A 2k)y, Thad)
ee
“ (8, 8%5=,22) 17)
; i \(4,4,28)
(8%)
aGny,= 28)!
OP
a
(2,422)
ou2ey19)(4 #5228)
S (i) We use the modifications of Problems 12 and 14. The TAPE
Jp PpXaAA.... The INSERT routines (after states
after Step 1 is #192
2 and 14) leave both 7; and 7; in g, and cell i symbols in the
first data cells. These traces assume this preprocessing has
been done.
(i)1 *1*24A** 9, g,AAAA... Il *192AA¥* 9, Gi AAAA 2°192AA** G7,G)AAAA
Z *1¢2AA™* g) QiAAAA 8 *1¢2AA**A GQ AAAA 10*1#2 AA**A GAAAA
12 *1*2AA**A
GAA GA rhe #1 *2AAFFA gi AA Ba 15*1*2AA**A GAs GA
15 *1*2AA**A
GAA GA 19 *1°2AA*FAAAA A 22*1*2AA*FAAAA AAA
Use the algorithm in Chapter 19 to convert an FA into a TM. The - state becomes START;
a transition labeled a becomes an instruction (a,A,R); a transition labeled 5 becomes an
instruction (b,A,R); from every + state add the instruction (A,A,R) on an edge to ACCEPT;
from every non+ state add the instruction (A,A,R) on an edge to REJECT. Since every
instruction cause a move right, eventually the input string will be exhausted and when the first
blank cell is encountered, the string is either accepted or rejected.
Yes. Don’t worry about nondeterminism: Make a TM that performs the CYK algorithm,
taking a CFG and a target string as input and accepting the string if it can be generated by the
grammar and rejecting it otherwise. The CYK algorithm is a decision procedure for
membership for CFL’s; no input causes it to loop indefinitely.
Recall Theorem 60 which states that if a language and its complement are both recursively
enumerable then they are both recursive. L is the complement of MUN and MUN is r.e.
(Theorem 62). Hence L is recursive. By symmetry M and N are also recursive.
Equivalent cases have been given the same number. Case | is (i), case 6 is (ii) and case 5 is
(iii) all as given. Cases 2 and 3 are impossible by Theorem 60. Case 4 is impossible by
Theorem 61.
10. (i) Let R, be the machine that accepts L, and R, the machine for L, then we construct R,
by the algorithm of Theorem 61. That is simulate running the two TM’s alternately on the
one input string. Ifthe string was accepted by either machine then it will be accepted by Rg.
Accept (R;)=L,+L,. L(R 3) is recursive because loop (R ,) and loop (R ,) were each
therefore loop(R 3) = @. Reject (R ;) = reject (R ,) M reject (R ,) + reject (R ,) M loop (R 5)
+ loop (R,) N reject (R,) = L,' nL,’.
(i1) Using DeMorgan’s Law, we can conclude that the intersection language is recursive
using the facts already established that complements (in Theorem 60) and union of two
recursive languages (as shown above) are recursive. _ If one wanted to construct the
machine, it would be similar to the union machine; simulate testing a string on both machines
simultaneously in alternation. Only difference is that once one machine accepts the string then
the simulator must continue to test the string on the other machine without forgetting that if
and when this second machine (with longer processing) accepts the simulator accepts and
HALTS.
167
11. Ifloop(T) was finite then the machine could be modified to check for those particular set of
strings and reject them. The result would be an empty loop set and the language would be
recursive. Since the language is specifically not recursive the loop language must be infinite
and moreover it cannot be regular.
12. Construct a TM that accepts the product of two r.e. languages. Instead of testing one input
string on two machines, we need to try all possible ways of dividing the input into two strings
testing the first substring on machine for L, and the latter substring on the machine for L,.
(There are +1 ways of dividing the input, where 7 is the length of the input.) Again we must
use sufficient interlacing to avoid getting stuck in loop before exhausting all choices.
Altermatively we can simplify the solution by using a nondeterministic machine to magically
divide the word into two in the most favorable way.
For product the division was simply into two parts, but for Kleene closure there can
be any number of parts. The complexity using the first method would increase dramatically
because of the multiple nesting necessary. However using a similar nondeterministic machine,
Kleene closure can be implemented easily, by magically dividing the string into favorable
parts.
14. Yes, consider the palindrome abaabbaaba for the TM START A,b,L (HALT |
ie
(vi) ALAN, this string is not in CWL.
16.
a*ba*b(atb)
(a,a,R)
a eel
b(atb )[(ataaa)a*ba
+ *ba‘b(atb)*]*
b(atb)’} HALT
We use regular expressions as edge lables as a shorthand for inserting their FAs in TM
form. There is a simple regular expression for CWL. However we must be certain
that the word has the two properties that make it a TM: There must be a START
state and there may not be any edges emanating from HALT (state 2). The above
machine accounts for these things. Also note that this machine accepts encoded
nondeterministic TM’s.
7; Blue paint would follow the simple path from START to HALT and claim that the machine
accepts some word(s); in this case (atb)(atb)a. However because of the abilities to move
left and to write on the tape, the existence of a path is not sufficient proof of acceptance of
a word. As we see, since the first edge writes a 5, it can not possibly back up and read an a
from that same cell.
18. Examine T,,; it accepts all strings if and only if T, accepts the particular string w. T, accepts
all strings except w if and only if T, does not accept w. Imagine that there is a machine
ACCEPTALL which takes an encoded TM as input and outputs yes or no. Then use T, to
be the input of ACCEPTALL. The effect is a machine that will decide if T, accepts w. This
is the Halting Problem which is unsolvable. Hence there is no such decision procedure for
ACCEPTALL.
19. Let T, be a machine such that accept ([F ) = (at+b)*, then this EQUIVALENCE machine
reduces to ACCEPTALL of the previous problem.
169
20) If the word “heterothetic” is homothetic - it really does describe itself. Of course,
because it is homothetic it also doesn’t describe itself; it describes its opposite. So
“heterothetic” is also heterothetic. But because it is heterothetic, it becomes
homothetic. And so on.
170
Chapter 24
The proof by Chomsky and Schutzenberger (of whose recent passing | have just sadly
learned) that type O = TM, | consider to be a triumph of mankind equal to any work of art
or science. Any who skip this material are risking my personal wrath.
New in this edition, but important for gratifying comprehensiveness as well as their
important Computer Science application, is the discussion of context-sensitive languages.
The next fifty years will see natural language processing as a dominant issue. Teachers
who know some Al teaching students who want to know some Al will easily bring in the
relevent applications.
How explicit one wants to be about the usefulness of the linear bound in |bas is a matter
of choice. | considered it important for two reasons: it distinguishes a different type of
machine for a different type of grammar, and because in answers the question of
decidability of membership, which distinguishes CSLs from r.e. languages.
The product and Kleene closure of r.e. languages could have been done in the previous
chapter but that would have deprived us of the pleasure of cooking the “obvious”
grammatical proofs. And since this is book about learning what a proof is and ISN’T (as
well as about pleasure) we delayed this presentation till here.
171
B 7b Bw bB,\ 6b
(iii) EQUAL is recursive. The TM built in Chapter 24 (pp. 569-573)
accepts or rejects all strings. Or, by Chapter 28, Problem 11, all
CFL's are recursive, and EQUAL was shown to be context free in
Chapter 13.
S.(i) 5 > ABCS > ABCABCS % ABCABCA> ABACBC® ABABCC
> 9 2bacc
(ii) S% ABCS® ABCABCS? ' ABCABCABCS® ABCABCABCA
= ABCABCABC »% ACBABCABC % CABABCABC
» CBAABCABC 9% CBAABCACE % CBAABCCAB
> CBAABCCBA > ..> chaabccha
6. The argument is similar to that of Problem 2: We generate the
terminals 2 Sand c from the simple nonterminals 4A, Band C
respectively; we always add one of each or none at all, so we can
never have a working string with unequal numbers of (Aor 4),
(Zor 6) and (Cor o, and therefore never derive a strings in
which the number of each does not equal the numbers of each of
the others.
Chapter Twenty Four
7. Again, the argument is an extensionof that of Problem 3. Props 2
and 4 say that if an J is out of place to the left, it can be moved
right; Props 3 and 5 say the same for & Props 6 and 7 for C Props
5 and 7 say that if an A is out of place to the right it can be
moved left; Props 2 and 6 say the same for & Props 3 and 4 for C
Therefore, any of these letters (and they are the only ones we
have to work with) can be moved either left or right past either
of the others, so all permutations can be derived.
8.(i) S29 GVY2 AXA
(ii) S39 UWVY> aUyVyY> aUVarxy> avakt> ava = 42
(iii) 5S OVX bUZ4% bYVbX® LALA HALA = bb
(iv) S32 OVA? aUVYyX> aUVarX> abUuZax> abUaZX
> abUaVbAX> abUVabX> abv abXk> ab abi = abab
4. We can make the left w of our string by applying Prop 2 if we
want the next letter to be 2 and Prop 3 if we wantittobe 6. (If
the string is already long enough we use Prop 10.) Until we reach
this point we always have a UV in the working string when we
are ready to choose the next letter, at the beginning from Prop 1,
thereafter because Props 2 and 3 leave a // in the working string
Props 4 and 5 return a V which is moved immediately to the
right of the J by Props 12 and 13.
A working string with a ¥ or a Z in it has added the next letter
to its first half but not yet added that letter to its second half.
Props 2 and 3 introduce the new first half letter and the Y or Z
for the second half. Props 4 and 5 add to the second half of the
string the same letter that was added to the first half. Prods 6-9
move the ¥ or Z to the right where it can be expanded in
combination with the final Y That expansion restores the V to
the working string and Props 12 and 13 move the V left until it
meets the & This leaves the working string in the form wUVwX
which can either be expanded by repeating this process or
terminated with Props 10 and 11, making it ww.
10.) wOVwY (0S pA wy Ul wA WA. We have no other choice.
174
a3a4A
(v) The working string can contain at most one 2 For every A
preceding it, Prop 8 gives us one a Without removing the Jfrom
the string. Then Prop 9 introduces the new nonterminal £ (at
the first AD occurrence) and an 4 and Prop 10 continues the
process of giving one afor each & We started with exactly 2
A's and no &s. Prop 8 gives us amore 738, ProD 9 gives us one 2
and Prop 10 gives us (71) as, for a total of 27 as. We also
have the nonterminal £ which gives us aby Prop 11. This is
2n+1 4s in addition to the 2 already accounted for in (iii),
for a total of (72+ 27+ 1) 2s, that is, (2 +1)? of them.
(¥) ProD | gives us the word 24 or al?
We have shown that application of Props 2-7 gives us a working
string of the form ga*
Ba An / and that this string eventually
gives us a word of the form 2(#!)?. Therefore, this grammar
can produce any gn
As we have seen from the tree (Par¢ (‘)) _— if we try to apply
ProD 9 before moving the 4's to the right of the 2's we cannot
complete a word. So the only sequences that produce any
words are those which give us 29*for some 2.
This grammar generates the language (26727, n>0.) Wegeta
single initial afrom Prop 1. Then, by applying Prop 2(b)
immediately, we get the word 262 If instead we apply Prop
2(a) we add no more 4s to the left of the string, we keep a
single YY part, add one 4 anda /Z part. Prop 3 moves the 4's
left through the Z's. When the 2's are all to the right of the 4's
(just left of the final 2) they can become 4s, otherwise they do
not terminate. Therefore the only words that can be formed are
those with a solid clump of #s on the right preceded by a solid
clump of 4's, after a single initial 2 Any such string can be
formed: Apply Prop 1, then Prop 2(a) 7-1! times , then apply
Prop 2(b) and finally Props 3 and 4 to terminate. To change this
to a grammar for #°6°#2 make Prop 2(a) read Y¥> 2¥VbA.
3. (i) 2b, aabb, 288bbb, aaaabbbb (ii) (#962)
177
14. Combine the context-sensitive grammars the same way we combined CFG. Ensure that the
nonterminal symbols for each language are different. Let the start symbols be S, and S,
respectively. Add the new productions S > S,|S,. Since there is a CSG that generates the
union language, it is context-sensitive.
1D; Again ensure that the symbols used for nonterminals in each grammar are different and add
the new production S > S,S,. The new grammar produces exactly the words of the product
language.
16. We do not have a simple technique for combining the grammars however we can describe the
TM that would accept the intersection of two languages. Using Theorem 79 that shows that
membership is Turing decidable for type 1 languages, let T, be a TM that decides if a string
is m one CSL and let T, be a membership TM for another CSL. Then construct a third TM
which takes an input string and runs it on T, if the result is no then reject the string but if the
result of T, is yes then run the string on T,. Again if the result is negative then reject and if
positive then accept; the string is a word in the intersection language.
7. Even more simple than problems 14 and 15, we can form the grammar for the Kleene closure
language by adding the new productions S > SS| A.
18. To construct a grammar for the reverse language, transpose each side of each production of
the CSG. For example XYZ~- BbaaaT becomes ZYX~- TaaabB. The length
condition is maintained and so the grammar is still context-sensitive.
1S (i) Convert the grammar in a way similar to the way we converted CFG to CNF. Except for
productions which are already i good form, change all terminals to appropriate nonterminals.
When necessary, add the corresponding N - t. Now shorten strings on either side of the rules
by introducing unique nonterminals to represent the remaining part. For example, XYZ -
BaCD first becomes XYZ ~ BACD (adding A > a if it is not already a rule.) Then XYZ
becomes XR, where R , > YZ and BACD becomes BR, where R, > AR, andR,; > CD.
The replacement productions of XYZ + BACD are:
XR, > BR, Ri > ¥Z R, > AR, R, > CD
(ii) Yes. Comparable to the CYK algorithm for CNF, use a variant for KNF where the
various possibilities for each length are tested.
20. (i) Remember that the productions of the grammar are restricted in length such that the
working string of any derivation of any word grows increasingly longer. Since there is no
way of shortening the working string, at every point in the derivation the length of string must
be less than or equal to the input if the word is to be derived at all.
(ii) Recall from the text that the format ofthe tape is $input$
178
Chapter 25
There is no doubt but that this material on recursive functions is anticlimactic, obvious, and
tedious. Still, it is necessary to include it here in order to prepare the student for possible
future investigations into more advanced topics. | wouldn't waste too much time on it
(especially since the term is probably over already anyway) but skip straight to a quick trip
through Church’s Thesis (a must) and on to TMs as language generators.
The theorems about language generation in lexicographic order are not only important but
tie together several key concepts form the course: what the problem in looping is all
about, why algorithms have to have predictable stopping times, why nondeterminism can
be simulated by determinism but at an important cost, and why doing many things at once
is a necessity but not a complete cure.
P79
(START
—$—(8,9,h'}
> — (44,2) 'Oye sO arwai HALT )
ERE es ae -[3,3,2)
59 Pd f
eR EE) (55,4) oa Ve G54)
D, be :
GNC ae
ML, : Bees
CO Fe
(2.1.2) 8,5] a : lesa
Y Lex 99)
3.4)
(START)
C12)
9. Again, this machine assumes that the inputs are the same length.
(cha£itaa2) ‘ (START ) 2
CO,0,4")
Guihee geBigsa Co.
es$9.0 4% 4G. ,
~40 B44) e, (LEAF \G)2/8)
’ 7* & se Se my : a
© Ae x :
(AA (ab,8) ye ws ne
mae A) Z Ms
(Aa.0)Sankey)
LT 4
1) aiiee
oa
(1,8,4)des ee
/ A a =
ye
ye (2.38)
,
GIA.
NGSad
ea
DUG).
ya a a] | ats
C12 (44,4)
8 eeuso S @,
“DELETE AGE)
—--———{ }
leSO SVUS) |\ $2)
(y, 2, +) CC,C1,agy) a
epmece beastie ~
WS
10. This machine interprets any string in b(ab)* as Papi Atie
(where mis the number of 4's in the input and the value of the
/'th number is the number of consecutive 4s following the th
b) and leaves as output some string in ba*, where the value of
the number is the number of 4's in the longest input clump.
—_ (Aoeje t4,3,)
( START A © we
F (8,5,4 (aan NeSw mers
(65,8) 2*, *
(2,3,8) -y
. ix ,¥,2) (3A) Bank) aR
Ca9% 1%,4,4)
(SSA! evel 4 mame es
[ 662) J ex) (2,a,8)-
(é,8,2 )-—————— fe SY a at
S00) Ri ie —+ DELETE}
[) 4 HALT
7hCOpare O xmemeg
+ DELETE |
(555)
&,*,5)
(START
(2,4, 3 (Sets
aoe
a (A431
“a : jt
ca soe!
a
ae
4)}———415)
t piers)
{HALT} te
(48,4) uae £Xe
ex)
(445)
(ii) START
aabaaabaabaaba +| Aabaaabaabaaba
~|Aabeaabheaabhaabha ~2 AF aaabhaahaabha 92 Af aaabaabhaaha
23 AF aaabaabaaba >| AA* aaabaabaaba +1 AA* gaabaabaaba
+1 AA* 2zaabaabhaaba +) AA* s2abaabaaba +1 AA* 2226a2abaaba
92 AA* aag aabaaba 932 AA* 2a% aabaaba 92 AA* aad aabaaba
+2 AA* aaz# aabaaba 92 AA* 2am aabaaba +3 AA* aad aabaaba
+4 AA* gaz aabaaba +4 AA* aga aabaaba +4 AA‘ aag aabaaba
94 AA* aad aabaaba 94 AA* aad dabaaba ~94 AA‘ aaa aabaaba
24 AA‘ zaz aabaaba +5 AA* aae aaaaba 95 AA’ aadz a@tAaba
+5 AA* 2am aad ba ~5 AA* 282 a@AsAa +5 AA‘ 284 @&AAAAA
+6 AA* 727 2@aAAAA +6 AA* 72d @asAA +6 AA* 2a 2akA
96 AA* 222 2ah 96 AA* aaz 24 +6 AA* 22% 228
36 AA* 227 24 97 AA* aaah 4a 27 AA* 2a@A 484
27 AA* BAA 228 +7 AA*AAAA 22 77 AAAAAAA28 ~— HALT
184
the divisor with one from the dividend (changing both to 4).
States 14,15, 8: Subtraction complete: Restore the divisor to
lower case and begin a new subtraction.
States 11,26: The dividend has been entirely marked and a new
subtraction is just beginning; i.e. the remainder is zero.
States 18, 19: The dividend has been entirely marked and a
subtraction is in process. There is a nonzero remainder.
ae [9,02 ) abe
CALA OIL), < (x4 4°) Fr (S52)
a8)j aus)
/ es ee,
Gaz), ono aEeaeey, pula 2a¥
ieAo) “(any=,2)
(GULETE 2)
States 26-27-28: Noremainder. Delete all A's and change * to 2
(4.4.4 Me- (4,2,
aig BR) ISSEY
EN peeps asi
(4,4,51¢ i
ae CELETEL
Dldlenz. erase (he testo the string,
ee
188
19. To determine whether a number is prime, we need to know if the number has any divisors.
So we would like to test integers 2 through the object number. We can use repeated
‘subtraction’ to simulate the division process. When subtracting the a’s on the right from the
a’s on the left we change them into b’s so that we can restore the original a" if desired. Next
we need to decide whether
(i) the process is incomplete, subtract again.
or (11) the process is complete and the number is a divisor - the number is not a prime.
or (iii) the “division/subtraction’ of the second number is complete but not a divisor of the
first. In this case, we need to decide whether there is still a possible divisor or not,
in the latter case the first number is a prime.
(A; a,b,#; R)
START
It may print out any language, but we cannot know which.
i =a @unr Cwmet)
Pee,
o%