收藏 分享(赏)

自动机答案—翻译.doc

上传人:gnk289057 文档编号:8158258 上传时间:2019-06-11 格式:DOC 页数:68 大小:628KB
下载 相关 举报
自动机答案—翻译.doc_第1页
第1页 / 共68页
自动机答案—翻译.doc_第2页
第2页 / 共68页
自动机答案—翻译.doc_第3页
第3页 / 共68页
自动机答案—翻译.doc_第4页
第4页 / 共68页
自动机答案—翻译.doc_第5页
第5页 / 共68页
点击查看更多>>
资源描述

1、1Solutions for Section 2.2Exercise 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 th

2、e right. Each state can be represented by a sequence of three 0s or 1s, 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

3、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 0

4、11r*000a 100r 011r*001a 101r 000a010r 110r 001a*010a 110r 001a011r 111r 010a100r 010r 111r*100a 010r 111r101r 011r 100a*101a 011r 100a110r 000a 101a*110a 000a 101a111r 001a 110aExercise 2.2.2The statement to be proved is -hat(q,xy) = -hat(-hat(q,x),y) , and we proceed by induction on the length of y

5、. 证明:通过对|y|进行归纳,来证明 (q , xy)= ( (q , x) , y) ,具体过程如下: 2Basis: 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 st

6、atement to be proved is p = -hat(p,) , which is easy to recognize as the basis in the definition of -hat . 基础: =0,则 y=。那么需证 (q,x)= ( (q ,x),),记 p= (q,x),命题变为 p=y(p ,), 由 的定义知这显然成立。Induction: Assume the statement for strings shorter than y, and break y = za, where a is the last symbol of y. The steps

7、 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 表达式 Reason 原因( (q,x),y) Start 开始( (q,x),za) y=za by assumption 由假设 y=za( ( (q,x),z),a) Definition of -hat , treating -hat(q,x) as

8、 a state 的定义, 把 (q,x) 看作是一个状态( (q,xz),a) Inductive hypothesis 归纳假设(q,xza) Definition of -hat 的定义(q,xy) y=zaExercise 2.2.4(a)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 分别表示以,和 00结尾的串的状态。0 1-A B A3B C A*C C AExercise 2.2.6(

9、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 dont 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,

10、 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 happe

11、ns to 5a+b if we multiply by 2 and add 1. 对于一个二进制整数,如果读入一个比特,其值等于原数乘以;否则等于原数乘以再加以 1。而任意一个数均可写成形如 5a+b,其中 a任意,0*q0 q0 q1q1 q2 q3q2 q4 q0q3 q1 q2q4 q3 q4There is a small matter, however, that this automaton accepts strings with leading 0s. Since the problem calls for accepting only those strings that

12、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: 但是上

13、述自动机仍接受以开头的字符串。因为题目要求只接受以开头的串,可增加一个初始状态 s和“死亡状态”d。在状态初始状态 s, 若看到,则转到状态 q1;若看到, 则直接转到状态 d,识别终止。所求自动机如下: 0 14-s d q1*q0 q0 q1q1 q2 q3q2 q4 q0q3 q1 q2q4 q3 q4d d dExercise 2.2.9Part (a) is an easy induction on the length of w, starting at length 1. Basis: |w| = 1. Then -hat(q 0,w) = -hat(q f,w), becaus

14、e 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(q 0,za) = (-hat(q 0,z),a) = (-hat(q f,z),a) by the inductive hypothesis = -hat(q f,za) = -hat(q f,w). 证明:a) 通过对 w长度的归纳证明。 基础: 若 |w| = 1,则 w 是一个符号,此时

15、需证 (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(q 0,x) = qf. Since x, we know by part (a) that -hat(q f,x) = qf. It is then a simple induction on k

16、to show that -hat(q0,xk) = qf. Basis: For k=1 the statement is given. Induction: Assume the statement for k-1; i.e., -hat(q 0,xSUPk-1) = qf. Using Exercise 2.2.2, -hat(q 0,xk) = -hat(-hat(q 0,xk-1),x) = -hat(q f,x) by the inductive hypothesis = qf by (a). b) x是属于 L(A)的非空串,也即串 x被接收,因此 (q0,x) = qf ,则由

17、 a)知 (qf,x) = (q0,x)= qf 。现在通过对 k 的归纳来证明 (q0,xk) = qf 。5基础: 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.10The automaton tells whether the number of 1s seen is even (state A) or odd (state B), accepting i

18、n 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 1s. Basis: |w| = 0. Then w, the empty string surely has an even number of 1s, namely zero 1s, and (A,w) = A. Induction: Assume the statement for strings shorter than w. Then w = za, wher

19、e a is either 0 or 1. Case 1: a = 0. If w has an even number of 1s, so does z. By the inductive hypothesis, (A,z) = A. The transitions of the DFA tell us (A,w) = A. If w has an odd number of 1s, then so does z. By the inductive hypothesis, -hat(A,z) = B, and the transitions of the DFA tell us -hat(A

20、,w) = B. Thus, in this case, -hat(A,w) = A if and only if w has an even number of 1s. Case 2: a = 1. If w has an even number of 1s, then z has an odd number of 1s. 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 1s, then z has a

21、n even number of 1s. 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 1s. 这个自动机表示,状态 A表示偶数个 1,状态 B表示奇数个 1,不管串有偶数个还是奇数个1,都会被接受。当且仅当串 w中有偶数个 1时, (A,w) = A.。 用归纳法证明如下基础: |w|

22、 = 0。空串当然有偶数个 1 ,即 0个 1,且 (A,w) = A. 归纳:假设对于比 w 短的串命题成立。令 w = za, 其中 a 为 0 或 1。 6情形 1: a = 0. 如果 w有偶数个 1, 则 z有偶数个 1。由归纳假设, (A,z) = A。由转移表的 DFA知 (A,w) = A.如果 w有奇数个 1, 则 z有奇数个 1. 由归纳假设, (A,z) = B, 由转移表的 DFA 知 (A,w) = B. 因此这种情况下 (A,w) = A 当且仅当 w 有偶 数个 1。 情形 2: a = 1. 如果 w有偶数个 1, 则 z有奇数个 1。由归纳假设, (A,z)

23、= B. 由转移表的 DFA知 (A,w) = A. 如果 w有奇数个 1, 则 z有偶数个 1。由归纳假设, (A,z) = A, 由转移表的 DFA知 (A,w) = B. 因此这种情况下 (A,w) = A 当且仅当 w 有偶数 个 1. 综合上述情形,命题得证。Solutions for Section 2.3Exercise 2.3.1Here 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

24、,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 AB D CC E AD F C*E F G*F F G*G E H*H E HExercise 2.3.4(a)The idea is to use a state qi, for i = 0,1,.,9 to represent the idea that we have se

25、en 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: 7记状态 qi为已经看到 i并猜测 i就是结尾将要重复的数字,i = 0,1,.,9 。初始状态为 qs,终止状态为 qf。我们可以

26、一直停留在状态 qs,表示尚未猜测。转移表如下: 0 1 . 9-qs qs,q0 qs,q1 . qs,q9q0 qf q0 . q0q1 q1 qf . q1. . . . .q9 q9 q9 . qf*qf . Solutions for Section 2.4Exercise 2.4.1(a)Well 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 tra

27、nsition table is: 记 q0为初始状态。q1, q2 和 q3识别 abc; q4, q5 和 q6 识别 abd, q7 到 q10 识别 aacd. 转移表如下: a b c d-q0 q0,q1,q4,q7 q0 q0 q0q1 q2 q2 q3 *q3 q4 q5 q5 q6*q6 q7 q8 q8 q9 q9 q10*q10 Exercise 2.4.2(a)The subset construction gives us the following states, each representing the subset of the NFA states indi

28、cated: 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, 8respectively. 由子集构造法可得以下 DFA的状态,其中每一个状态都是 NF

29、A状态的子集: 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 AB C D A AC C D E AD B A F GE B A A H*F B A A A*G B A A A*H B A A ASolutions for Section 2.5Exercise 2.5.1For

30、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 bs and cs only. To begin, notice that the only way

31、s 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 bs and cs only, is accepted, with the exception of the string b. However, we have to allow

32、 as as well. When we try to insert as in these strings, yet keeping the length to 3 or less, we find that every string of as bs, and cs with at most one a is accepted. Also, the strings consisting of one c and up to 2 as are accepted; other strings are rejected. b) 由于输入 a状态总是保持不变,因此只需考虑输入 b和 c的情况。可以

33、看出,从状态 p第一次到 r且只经过 b,c 和 转移的路径为 bb, bc 和 c ;到 r之后,读入 b仍可回到 r,读入 c回到 p ,则可通过继续读入串 bb, bc和 c 回到 r。因此,每一个由 b和 c组成的长度小于等于 3的串可以被接受,除了串 b不能接受。向这些串中插入 a,并保持长度小于等于 3,就会得到所有由 a,b,c 组成的,至多含有一个 a9的可被接受的串。由一个 c和两个 a组成的任意串也是可以被接受的。其它的串均被拒绝。There are three DFA states accessible from the initial state, which is t

34、he closure of p, or p. Let A = p, B = p,q, and C = p,q,r. Then the transition table is: 由初始状态,即 p的 闭包或者p,有 3个状态可以达到。令 A = p, B = p,q, C = p,q,r。转移表如下: a b c-A A B CB B C C*C C C CSolutions for Section 3.1Exercise 3.1.1(a)The simplest approach is to consider those strings in which the first a precede

35、s the first b separately from those where the opposite occurs. The expression: c*a(a+c)*b(a+b+c)* + c*b(b+c)*a(a+b+c)* 首先考虑第一个 a在第一个 b的前面,然后再考虑相反的情况。表达式为: c*a(a+c)*b(a+b+c)* + c*b(b+c)*a(a+b+c)* Exercise 3.1.2(a)(Revised 9/5/05) The trick is to start by writing an expression for the set of strings t

36、hat have no two adjacent 1s. Here is one such expression: (10+0)*(+1) To see why this expression works, the first part consists of all strings in which every 1 is followed by a 0. To that, we have only to add the possibility that there is a 1 at the end, which will not be followed by a 0. That is th

37、e job of (+1). 首先写出没有两个 1相邻的串的集合,如下:(10+0)*(+1) 。表达式的第一部分表示每个 1之后都紧跟一个 0的这样的串组成。为了表示结尾可能是 1的情况,则可在串尾处加上 (+1)。 Now, we can rethink the question as asking for strings that have a prefix with no adjacent 1s followed by a suffix with no adjacent 0s. The former is the expression we developed, and the lat

38、ter is the same expression, with 0 and 1 interchanged. Thus, a solution to this problem is (10+0)*(+1)(01+1)*(+0). 10Note that the +1 term in the middle is actually unnecessary, as a 1 matching that factor can be obtained from the (01+1)* factor instead. 题目要求的串可由两部分组成,也就是,前缀没有相邻的 1,后缀没有相邻的 0。前半部分也就是

39、已经给出的(10+0)*(+1),根据对称性后半部分可将上式的 1和 0交换得到。所求即为(10+0)*(+1)(01+1)*(+0)。注意中间的 +1 项没有作用,因为 1可以由后面的(01+1)* 项得到。因此最后得到的正则表达式为(10+0)*(01+1)*(+0)Exercise 3.1.4(a)This expression is another way to write no adjacent 1s. You should compare it with the different-looking expression we developed in the solution to

40、 Exercise 3.1.2(a). The argument for why it works is similar. (00*1)* says every 1 is preceded by at least one 0. 0* at the end allows 0s after the final 1, and (+1) at the beginning allows an initial 1, which must be either the only symbol of the string or followed by a 0. 你可以与练习 3.1.2(a)中我们给出的不同样子

41、的表达式作比较。为什么起作用的原因是类似的。这个表达式是 “没有相邻的 1”的另一种描述方式。(00*1)* 表示每个 1 的前面都至少有一个 0做前缀。最后的 0* 允许在最后一个 1后面有 0。开头的(+1) 允许初始为 1,要么串就只有这一个符号,要么后面跟着的就是 0。 Exercise 3.1.5The language of the regular expression . Note that * denotes the language of strings consisting of any number of empty strings, concatenated, but

42、that is just the set containing the empty string. 正则表达式 。*表示由任意多个空串组成的串,也是只包含空串的集合。 Solutions for Section 3.2Exercise 3.2.1Part (a): The following are all R0 expressions; we list only the subscripts. R11 = + 1; R12 = 0; R13 = phi; R21 = 1; R22 = ; R23 = 0; R31 = phi; R32 = 1; R33 = +0. a) 下面就是所有 R0

43、的表达式;我们只写出下标: R11 = +1;R12 = 0; R13 = (phi); R21 = 1; R22 = ; R23 = 0; R31 = (phi); R32 = 1; R33 = +0. Part (b): Here all expression names are R(1); we again list only the subscripts. R11 = 1*; R12 = 1*0; R13 = phi; R21 = 11*; R22 = +11*0; R23 = 0; R31 = phi; R32 = 1; R33 = +0. 11b) 下面就是所有 R (1) 的表达

44、式;我们只写出下标:R11 = 1*; R12 = 1*0; R13 = phi; R21 = 11*; R22 = +11*0; R23 = 0; R31 = phi; R32 = 1; R33 = +0. Part (e): Here is the transition diagram转移图: If we eliminate state q2 we get: 如果消除状态 q2,有: Applying the formula in the text, the expression for the ways to get from q1 to q3 is: 1 + 01 + 00(0+10)

45、*11*00(0+10)* 由课本中的公式,q1 到 q3的正则表达式:1 + 01 + 00(0+10)*11*00(0+10)* Exercise 3.2.4(a)利用定理 3。7 每个用正则表达式来定义的语言也可用穷自动机来定义Exercise 3.2.6(a)(Revised修改 1/16/02) LL* or L+. Exercise 3.2.6(b)The set of suffixes of strings in L. (以)L 中串(作为)后缀/下标的集合。Exercise 3.2.8Let R(k)ijm be the number of paths from state i

46、 to state j of length m that go 12through no state numbered higher than k. We can compute these numbers, for all states i and j, and for m no greater than n, by induction on k. 令 R(k)ijm 为从状态 i到状态 j,长度为 m,且没有经过编号大于 k的路径的个数。对于所有状态 I和 j,以及 m(mn) ,通过对 k归纳来计算这个个数。 Basis: R0ij1 is the number of arcs (or

47、more precisely, arc labels) from state i to state j. R0ii0 = 1, and all other R0ijms are 0. 基础: k=0, R0ij1 是由状态 i到状态 j的箭弧(更准确的说,是箭弧标号)的个数。 R0ii0 = 1,其他的 R0ijms 都为 0。Induction: R(k)ijm is the sum of R(k-1)ijm and the sum over all lists (p1,p2,.,pr) of positive integers that sum to m, of R(k-1)ikp1 *

48、R(k-1)kkp2 *R(k-1)kkp3 *.* R(k-1)kkp(r-1) * R(k-1)kjpr. Note r must be at least 2. 归纳: R(k)ijm 是 R(k-1)ijm 的和, R(k-1)ikp1 * R(k-1)kkp2 *R(k-1)kkp3 *.* R(k-1)kkp(r-1) * R(k-1)kjpr。 (p1,p2,.,pr)是所有和为 m的正整数序列,r 大于等于 2。 The answer is the sum of R(k)1jn, where k is the number of states, 1 is the start state, and j is any accepting state. 答案就是 R(k)1jn的总和,其中 k是状态个数,1 为开始状态,j 是任意接受状态。 Solution

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报