http://www.zhiwenweb.cn/article.asp?id=1226
Solutions for Section 2.2
Exercise 2.2.1(a)
States correspond to the eight combinations of switch positions, and also must
indicate whether the previous roll came out at D, i.e., whether the previous input was
accepted. Let 0 represent a position to the left (as in the diagram) and 1 a position to
the right. Each state can be represented by a sequence of three 0's or 1's, representing
the directions of the three switches, in order from left to right. We follow these three
bits by either a indicating it is an accepting state or r, indicating rejection. Of the 16
possible states, it turns out that only 13 are accessible from the initial state, 000r. Here
is the transition table:
杠杆可能出现 8 种情况,影响着最终状态。并且也要说明,前面一个大理石球是
否从 D 滚出,也就是说,前一个输入是否被接受。令 0 代表向左方的状态(如
图表), 1 代表向右方。这三个杠杆的每一个状态都可以用三个数(0 或 1)组
成的序列表示。这个序列后面跟着字母 a 或者 r。a 代表接受状态,r 代表拒绝状
态。16 种可能的状态中,只有 13 种是从初始状态 000r 可达的。下面它的有穷自
动机的转移表。
A
B
->000r 100r 011r
*000a 100r 011r
*001a 101r 000a
010r 110r 001a
*010a 110r 001a
011r 111r 010a
100r 010r 111r
*100a 010r 111r
101r 011r 100a
*101a 011r 100a
110r 000a 101a
*110a 000a 101a
111r 001a 110a
Exercise 2.2.2
The statement to be proved is δ-hat(q,xy) = δ-hat(δ-hat(q,x),y), and we proceed by
induction on the length of y.
志文工作室
1
http://www.zhiwenweb.cn/article.asp?id=1226
证明:通过对|y|进行归纳,来证明ˆ (q , xy)=ˆ (ˆ (q , x) , y) ,具体过程如下:
Basis: If y = ε, then the statement is δ-hat(q,x) = δ-hat(δ-hat(q,x),ε). This statement
follows from the basis in the definition of δ-hat. Note that in applying this definition,
we must treat δ-hat(q,x) as if it were just a state, say p. Then, the statement to be
proved is p = δ-hat(p,ε), which is easy to recognize as the basis in the definition of
δ-hat.
基础: y =0,则 y=ε。那么需证ˆ (q,x)=ˆ (ˆ (q ,x),ε),记 p=ˆ (q,x),命题变为
p=ˆ (p ,ε), 由ˆ 的定义知这显然成立。
Induction: Assume the statement for strings shorter than y, and break y = za, where a
is the last symbol of y. The steps converting δ-hat(δ-hat(q,x),y) to δ-hat(q,xy) are
summarized in the following table:
归纳: 假设命题对于比 y 短的串成立, 且 y = za, 其中 a 是 y 的结尾符号。
ˆ (ˆ (q,x),y) 到ˆ (q,xy) 的变换总结在下表中:
Expression 表达式
ˆ (ˆ (q,x),y)
Start
开始
Reason 原因
ˆ (ˆ (q,x),za)
y=za by assumption
由假设 y=za
δ(ˆ (ˆ (q,x),z),a)
Definition of δ-hat, treating δ-hat(q,x) as a state
ˆ 的定义, 把ˆ (q,x) 看作是一个状态
δ(ˆ (q,xz),a)
Inductive hypothesis
归纳假设
ˆ (q,xza)
ˆ (q,xy)
Exercise 2.2.4(a)
Definition of δ-hat
ˆ 的定义
y=za
The intuitive meanings of states A, B, and C are that the string seen so far ends in 0, 1,
or at least 2 zeros.
状态 A, B,C 分别表示以1,0和 00 结尾的串的状态。
志文工作室
2
http://www.zhiwenweb.cn/article.asp?id=1226
0 1
->A B A
B C A
*C C A
Exercise 2.2.6(a)
The trick is to realize that reading another bit either multiplies the number seen so far
by 2 (if it is a 0), or multiplies by 2 and then adds 1 (if it is a 1). We don't need to
remember the entire number seen --- just its remainder when divided by 5. That is, if
we have any number of the form 5a+b, where b is the remainder, between 0 and 4,
then 2(5a+b) = 10a+2b. Since 10a is surely divisible by 5, the remainder of 10a+2b is
the same as the remainder of 2b when divided by 5. Since b, is 0, 1, 2, 3, or 4, we can
tabulate the answers easily. The same idea holds if we want to consider what happens
to 5a+b if we multiply by 2 and add 1.
对于一个二进制整数,如果读入一个比特0,其值等于原数乘以2;否则等
于原数乘以2再加以 1。而任意一个数均可写成形如 5a+b,其中 a 任意,0<= b
<=4,那么输入 0,原数变为 2(5a+b) = 10a+2b,由于 10a 是 5 的倍数,,因此 10a+2b
除以5的余数与 2b 相同。输入 1,则得 2(5a+b)+1 类似。因此对于所有的数只要
记住它被5除的余数就可以。由于 b 是 0, 1, 2, 3 或者 4, 我们可以容易得到该
DPA 的转移表,具体如下:
The table below shows this automaton. State qi means that the input seen so far has
remainder i when divided by 5.
其中状态 qi 代表输入串被5除的余数 i 的状态。
0 1
->*q0 q0 q1
q1 q2 q3
q2 q4 q0
q3 q1 q2
q4 q3 q4
There is a small matter, however, that this automaton accepts strings with leading 0's.
Since the problem calls for accepting only those strings that begin with 1, we need an
additional state s, the start state, and an additional ``dead state'' d. If, in state s, we see
a 1 first, we act like q0; i.e., we go to state q1. However, if the first input is 0, we
should never accept, so we go to state d, which we never leave. The complete
automaton is:
志文工作室
3
http://www.zhiwenweb.cn/article.asp?id=1226
但是上述自动机仍接受以0开头的字符串。因为题目要求只接受以1开头的串,
可增加一个初始状态 s 和“死亡状态”d。在状态初始状态 s, 若看到1,则转到
状态 q1;若看到0, 则直接转到状态 d,识别终止。所求自动机如下:
0 1
->s d q1
*q0 q0 q1
q1 q2 q3
q2 q4 q0
q3 q1 q2
q4 q3 q4
d d d
Exercise 2.2.9
Part (a) is an easy induction on the length of w, starting at length 1.
Basis: |w| = 1. Then δ-hat(q0,w) = δ-hat(qf,w), because w is a single symbol, and δ-hat
agrees with δ on single symbols.
Induction: Let w = za, so the inductive hypothesis applies to z. Then δ-hat(q0,w) =
δ-hat(q0,za) = δ(δ-hat(q0,z),a) = δ(δ-hat(qf,z),a) [by the inductive hypothesis] =
δ-hat(qf,za) = δ-hat(qf,w).
证明:a) 通过对 w 长度的归纳证明。
基础: 若|w| = 1,则 w 是一个符号,此时需证ˆ (q0,w) = ˆ (qf,w), 而对于单个符
号扩展转移函数ˆ 与转移函数δ的作用是一样的,得证。
归纳: 令 w = za, 假设对于 z 命题ˆ (q0,z) = ˆ (qf,z)成立。那么ˆ (q0,w) = ˆ (q0,za)
= δ(ˆ (q0,z),a) = δ(ˆ
(qf,z),a) [由归纳假设] = ˆ
(qf,za) = ˆ
(qf,w).
For part (b), we know that δ-hat(q0,x) = qf. Since xε, we know by part (a) that
δ-hat(qf,x) = qf. It is then a simple induction on k to show that δ-hat(q0,xk) = qf.
Basis: For k=1 the statement is given.
志文工作室
4
http://www.zhiwenweb.cn/article.asp?id=1226
Induction: Assume the statement for k-1; i.e., δ-hat(q0,xSUP>k-1) = qf. Using
Exercise 2.2.2, δ-hat(q0,xk) = δ-hat(δ-hat(q0,xk-1),x) = δ-hat(qf,x) [by the inductive
hypothesis] = qf [by (a)].
b) x 是属于 L(A)的非空串,也即串 x 被接收,因此ˆ (q0,x) = qf ,则由 a)知ˆ (qf,x)
=ˆ (q0,x)= qf 。现在通过对 k 的归纳来证明ˆ (q0,xk) = qf 。
基础: k=1 时,需证ˆ (q0,x) = qf ,由已知可得。
归纳:假设对于 k-1 命题成立,也就是说,ˆ (q0,xk-1) = qf 。由练习 2.2.2, ˆ (q0,xk)
=ˆ (ˆ (q0,xk-1),x) = ˆ (qf,x) [由归纳假设] = qf [由(a)]。
Exercise 2.2.10
The automaton tells whether the number of 1's seen is even (state A) or odd (state B),
accepting in the latter case. It is an easy induction on |w| to show that dh(A,w) = A if
and only if w has an even number of 1's.
Basis: |w| = 0. Then w, the empty string surely has an even number of 1's, namely
zero 1's, and ˆ (A,w) = A.
Induction: Assume the statement for strings shorter than w. Then w = za, where a is
either 0 or 1.
(A,z) = A. The transitions of the DFA tell us ˆ
Case 1: a = 0. If w has an even number of 1's, so does z. By the inductive hypothesis,
ˆ
number of 1's, then so does z. By the inductive hypothesis, δ-hat(A,z) = B, and the
transitions of the DFA tell us δ-hat(A,w) = B. Thus, in this case, δ-hat(A,w) = A if
and only if w has an even number of 1's.
(A,w) = A. If w has an odd
Case 2: a = 1. If w has an even number of 1's, then z has an odd number of 1's. By the
inductive hypothesis, δ-hat(A,z) = B. The transitions of the DFA tell us δ-hat(A,w) =
A. If w has an odd number of 1's, then z has an even number of 1's. By the inductive
hypothesis, δ-hat(A,z) = A, and the transitions of the DFA tell us δ-hat(A,w) = B.
Thus, in this case as well, δ-hat(A,w) = A if and only if w has an even number of 1's.
这个自动机表示,状态 A 表示偶数个 1,状态 B 表示奇数个 1,不管串有偶数个
还是奇数个 1,都会被接受。当且仅当串 w 中有偶数个 1 时,ˆ
(A,w) = A.。用
志文工作室
5
http://www.zhiwenweb.cn/article.asp?id=1226
归纳法证明如下
基础: |w| = 0。空串当然有偶数个 1 ,即 0 个 1,且ˆ
(A,w) = A.
归纳:假设对于比 w 短的串命题成立。令 w = za, 其中 a 为 0 或 1。
情形 1: a = 0. 如果 w 有偶数个 1, 则 z 有偶数个 1。由归纳假设,ˆ
(A,z) = A。
由转移表的 DFA 知ˆ (A,w) = A.如果 w 有奇数个 1, 则 z 有奇数个 1. 由归纳假设,
(A,z) = B, 由转移表的 DFA 知ˆ
ˆ
当且仅当 w 有偶数个 1。
(A,w) = B. 因此这种情况下ˆ (A,w) = A
情形 2: a = 1. 如果 w 有偶数个 1, 则 z 有奇数个 1。由归纳假设,ˆ
(A,z) = B.
由转移表的 DFA 知ˆ
(A,w) = A. 如果 w 有奇数个 1, 则 z 有偶数个 1。由归纳
假设, ˆ (A,z) = A, 由转移表的 DFA 知ˆ
A 当且仅当 w 有偶数个 1.
(A,w) = B. 因此这种情况下ˆ (A,w) =
综合上述情形,命题得证。
Solutions for Section 2.3
Exercise 2.3.1
Here are the sets of NFA states represented by each of the DFA states A through H: A
= {p}; B = {p,q}; C = {p,r}; D = {p,q,r}; E = {p,q,s}; F = {p,q,r,s}; G = {p,r,s}; H =
{p,s}.
下表就是利用子集构造法将 NFA 转化成的 DFA。其中构造的子集有:A = {p}; B
= {p,q}; C = {p,r}; D = {p,q,r}; E = {p,q,s}; F = {p,q,r,s}; G = {p,r,s}; H = {p,s}.
0 1
->A B A
B D C
C E A
D F C
*E F G
*F F G
*G E H
*H E H
志文工作室
6
http://www.zhiwenweb.cn/article.asp?id=1226
Exercise 2.3.4(a)
The idea is to use a state qi, for i = 0,1,...,9 to represent the idea that we have seen an
input i and guessed that this is the repeated digit at the end. We also have state qs, the
initial state, and qf, the final state. We stay in state qs all the time; it represents no
guess having been made. The transition table:
记状态 qi 为已经看到 i 并猜测 i 就是结尾将要重复的数字,i = 0,1,...,9 。初始状
态为 qs,终止状态为 qf。我们可以一直停留在状态 qs,表示尚未猜测。转移表
如下:
0
1
...
9
->qs {qs,q0} {qs,q1} ... {qs,q9}
q0 {qf}
q1 {q1}
... ...
q9 {q9}
*qf {}
{q0}
{qf}
...
{q9}
{}
... {q0}
... {q1}
... ...
... {qf}
... {}
Solutions for Section 2.4
Exercise 2.4.1(a)
We'll use q0 as the start state. q1, q2, and q3 will recognize abc; q4, q5, and q6 will
recognize abd, and q7 through q10 will recognize aacd. The transition table is:
记 q0 为初始状态。q1, q2 和 q3 识别 abc; q4, q5 和 q6 识别 abd,
别 aacd. 转移表如下:
q7 到 q10 识
a
c
d
->q0 {q0,q1,q4,q7} {q0} {q0} {q0}
b
q1 {}
q2 {}
*q3 {}
q4 {}
q5 {}
*q6 {}
q7 {q8}
q8 {}
q9 {}
{}
{q2} {}
{q3} {}
{}
{}
{}
{}
{}
{q5} {}
{}
{}
{q6}
{}
{}
{}
{}
{}
{}
{q9} {}
{}
{}
{}
{q10}
志文工作室
7
http://www.zhiwenweb.cn/article.asp?id=1226
*q10 {}
{}
{}
{}
Exercise 2.4.2(a)
The subset construction gives us the following states, each representing the subset of
the NFA states indicated: A = {q0}; B = {q0,q1,q4,q7}; C = {q0,q1,q4,q7,q8}; D =
{q0,q2,q5}; E = {q0,q9}; F = {q0,q3}; G = {q0,q6}; H = {q0,q10}. Note that F, G
and H can be combined into one accepting state, or we can use these three state to
signal the recognition of abc, abd, and aacd, respectively.
由子集构造法可得以下 DFA 的状态,其中每一个状态都是 NFA 状态的子集: A
= {q0}; B = {q0,q1,q4,q7}; C = {q0,q1,q4,q7,q8}; D = {q0,q2,q5}; E = {q0,q9}; F =
{q0,q3}; G = {q0,q6}; H = {q0,q10}.注意到 F, G 和 H 可以整合到一个接受状态
中,或者我们可以用这三个状态来分别标记已识别 abc, abd 和 aacd。
a b c d
->A B A A A
B C D A A
C C D E A
D B A F G
E B A A H
*F B A A A
*G B A A A
*H B A A A
Solutions for Section 2.5
Exercise 2.5.1
For part (a): the closure of p is just {p}; for q it is {p,q}, and for r it is {p,q,r}.
(a): 根据状态的ε闭包的的性质。求得,
p 的ε闭包:{p}; q 的ε闭包:{p,q}; r 的ε闭包:{p,q,r}。
For (b), begin by noticing that a always leaves the state unchanged. Thus, we can
think of the effect of strings of b's and c's only. To begin, notice that the only ways to
get from p to r for the first time, using only b, c, and ε-transitions are bb, bc, and c.
After getting to r, we can return to r reading either b or c. Thus, every string of length
3 or less, consisting of b's and c's only, is accepted, with the exception of the string b.
However, we have to allow a's as well. When we try to insert a's in these strings, yet
keeping the length to 3 or less, we find that every string of a's b's, and c's with at most
志文工作室
8