Download presentation

Presentation is loading. Please wait.

Published byOscar Pynes Modified about 1 year ago

1
Chapter 6 Languages: finite state machines Yen-Liang Chen Dept of Information Management National Central University

2
6.1 Language: the set theory of strings We use to denote a nonempty finite set of symbols, collectively called an alphabet. Definition 6.1. If is an alphabet and n Z +, we define the power of as follows: (1) 1 = ; and (2) n+1 ={xy x , y n }, where xy denotes the juxtaposition of x and y. Ex 6.1

3
Empty string and sentences Definition 6.2. 0 ={ }, where denotes the empty string. (1)Although , ; (2) { } since ; (3) { } because { } =1. We refer to the elements of + or * as strings, words, sentences Ex 6.2

4
Equal and concatenation Definition 6.4. Two strings w 1 =x 1 x 2 …x n + and w 2 =y 1 y 2 …y m + are equal, written as w 1 =w 2, if n=m and x i =y i for 1 i n. Definition 6.5. Let w=x 1 x 2 …x n +. The length of w, denoted as w , is n. Definition 6.6. Let x=x 1 x 2 …x n + and y=y 1 y 2 …y m + The concatenation of x and y, xy, is x 1 x 2 …x n y 1 y 2 …y m. The concatenation of x and is x =x. The concatenation of and x is x=x. Finally, the concatenation of and is. Since x =x= x, the element is the identity for the operation of concatenation.

5
Power, prefix and postfix Definition 6.7. The power of x is defined as: x 0 =, x 1 =x, and x n+1 =x x n. Ex 6.3 Definition 6.8. If x, y * and w=xy, then x is a prefix of w, and if y , then x is a proper prefix of w. Similarly, y is a suffix of w; it is a proper suffix when x .

6
Examples Ex 6.4: Consider the string w=abbcc. What are the prefixes, proper prefixes, suffixes and proper suffixes of w? Ex 6.6, If w=w 1 w 2 =w 3 w 4, then (1) w 1 is a prefix of w 3, or w 3 is a prefix of w 1 ; and (2) w 2 is a suffix of w 4, or w 4 is a suffix of w 2. Let w=(abb)(cc)=(a)(bbcc)

7
Substring and language Definition 6.9. If x, y, z * and w=xyz, then y is called as a substring of w. When at least one of x and z is different from, we call y a proper substring. Ex 6.7 Definition For a given , any subset of * is called a language over . This includes , the empty language. Ex 6.8, Ex 6.9.

8
the concatenation of languages Definition For languages A, B in *, the concatenation of A and B, denoted AB, is {ab a A, b B}. Note that AB BA and AB BA . Ex 6.10 Theorem 6.1. For A, B, C *, we have (a) A{ }={ }A=A; (b) (AB)C=A(BC); (c) A(B C)=AB AC; (d) (B C)A=BC CA; (e) A(B C) AB AC; (f) (B C)A BA CA. x, xy in A; yz in B; z in C xyz in AB AC But xyz not in A(B C)

9
Closure Ex A={x}, then (1) A 0 ={ }; (2) A n ={x n }; (3) A + ={x n n 1}; (4)A*={x n n 0} Ex A={, x, x 3, x 4,…} and B={x n n 0}. Then A 2 =B 2 but A B.

10
Examples Ex 6.12 A={xx, xy, yx, yy}. A * is the language of all strings w in * where the length of w is even. A={xx, xy, yx, yy} and B={x, y}. What is BA * ? What is {x}{x, y} * ? What is {x}{x, y} + ? What is {x, y} * {yy}? What is {x} * {y} * ? Why {x}*{y} * {x, y} * ?

11
Properties Lemma 6.1. Let A, B *. If A B, then for all n Z +, A n B n. Theorem 6.2. For A, B *, we have (a) A AB*, (b) A B*A; (c) A B A* B*, (d) A B A + B +, (e) AA*=A*A=A +, (f) A*A*=A*=(A*)*=(A*) + =(A + )*; (g) (A B)*=(A* B*)*=(A*B*)*.

12
Examples Ex Let ={0, 1} and A *, where each word in A contains exactly one occurrence of the symbol 0. Then the language can be defined as: (a) 0 A, (b) 1x and x1 is in A, if x is in A. Ex Let ={(, )} and A *, where A contains those nonempty strings of parentheses that are grammatically correct for algebraic expressions. Then the language can be defined as: (a) ( ) is in A; (b) For all x, y in A, we have (1) xy A, and (2) (x) A.

13
The reverse of string Ex 6.16 The reverse of x= x 1 x 2 …x n is x R = x n x n-1 …x 1. We can define it recursively: (a) R = ; and (2) if x=zy n+1, where z in and y in n, then x R =(zy) R =(y R )z. Based on this definition, we can show that for x 1, x 2 *, we have (x 1 x 2 ) R =x 2 R x 1 R.

14
6.2 Finite state machine: a first course The machine can be in only one of finitely many sates at a given time. The machine will accept as input only a finite number of symbols, referred to as the input alphabet. An output and a next state are determined by each combination of inputs and internal states. The machine operates in a deterministic manner.

15

16
Finite state machine A finite state machine is a five-tuple M=(S, IA, OA, v, w), where S = the set of internal states fro M; IA is the input alphabet for M; OA is the output alphabet; v: S IA S; w: S IA OA

17
Ex 6. 17

18
Ex 6.18

19
Ex 6.19

20
6.3 Finite state machine: a second encounter Ex We want to construct a machine that recognizes each occurrence of the sequence 111 as it is encountered in an input string x *. This machine is a recognizer of the language A= {0, 1}*{111}. For example, if x= , then the output is

21
Ex We want to recognize the occurrence of 111 that ends in a position that is a multiple of 3.

22
Ex We want to recognize the occurrence of 0101 in an input string. Figure 6.12(a). We want to recognize the occurrence of 0101 in an input string but its start position is a multiple of four. Figure 6.12(b).

23
Ex It is impossible to have a finite state machine to represent A={0 i 1 i i Z + }. Suppose we can and let S =n 1. Table 6.8 shows the state transition for string 0 n+1 1 n+1. Since S =n, there must have two states s i and s j, where i< j, such that s i =s j. Removing the loop from s i+1 to s j, we have the table shown in Figure This new sequence means the machine can accept the string x=0 (n+1)-(j-i) 1 n+1. This is a contradiction.

24

25
Ex 6.24 One-unit delay machine. If x= x 1 x 2 …x n-1 x n, then the output will be 0 x 1 x2…x n-1.

26
Ex Two-unit delay machine. If x= x 1 x 2 …x n-1 x n, then the output will be 0 0x 1 x 2 …x n-2.

27
Definition For s i, s j S, s j is reachable from s i if s i =s j or if there is an input string x such v(s i, x)=s j. A state s is transient if v(s, x)=s for x IA* implies x=. Once leaving, never go back to itself. A state s is sink if v(s, x)=s for x IA*. A submachine of M. Let S 1 S and IA 1 IA. If v 1 =v S1 IA1: S 1 IA 1 S has its range within S 1. A machine is strongly connected if for any states s i, s j S, s j is reachable from s i.

28

29
Transfer sequence For a machine M, let s i, s j S. An input string x is called a transfer sequence from s i to s j if (a) v(s i, x)=s j, (b) for any y with v(s i, y)=s j y x .

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google