# Languages Finite State Machines

Document Sample

```					                Chapter 6
Languages: Finite State Machines

Discrete Math by R.S. Chang, Dept. CSIE, NDHU                           1
Chapter 6 Languages: Finite State Machines
6.1 Language: The Set Theory of Strings
: a nonempty finite set of symbols, collectively
called an alphabet.
{0,1,2,11} or {a,b bb} is not considered as an alphabet.
That is, juxtaposition of symbols is not included in an alphabet.

Def. 6.1 If  is an alphabet and n  Z + , we define the powers
of  recursively as follows:
(1)  1   , and
(2)  n+1  {xy | x   , y   n }, where xy denotes the
justaposition of x and y .
In general, for all n  Z + , |  n |  |  |n
Def. 6.2 Define  0  { }, where  denotes the empty string .

Note (1) { }   since    and (2) { }  
Discrete Math by R.S. Chang, Dept. CSIE, NDHU                           2
Chapter 6 Languages: Finite State Machines
6.1 Language: The Set Theory of Strings

Def. 6.3 If  is any alphabet, then
                                
+
(a)                n
   and (b)     n   *
n1                            n 0
*
Ex. 6.2 For  = {0,1}, the set  consists of all strings of 0' s
and 1' s together with the empty string.

Def. 6.4 string equivalence
w1  x1x 2  x m , w2  y1 y 2  y n . w1  w2 if m  n and
xi  yi ,1  i  m.

Def. 6.5 length of a string: w  x1x 2  x n , then w  n.
Furthermore,  = 0.

Discrete Math by R.S. Chang, Dept. CSIE, NDHU                      3
Chapter 6 Languages: Finite State Machines
6.1 Language: The Set Theory of Strings

Def. 6.6 concatenation operation
x  x1x 2  x m , y  y1 y 2  y n , xy  x1x 2  x m y1 y 2  y n
We have x  x  x and xy  x  y , for any x , y   * .
2           2        3     3
If  1  {0,1,2},  2  {a , b, c}, then  1  3   3  1   2  1   1  2 .
2    2         2           2
2               2            3      3
But,  1  3   3  1   2  1   1  2  5.
2        2           2              2
Def. 6.7 The power of a string
x 0   , x 1  x , x 2  xx ,  , x n1  xx n , 
Ex. 6.3 If  = {0,1} and x = 01, then x n  a string of n 0' s and
n 1' s where the first symbol is 0 and the symbols alternate. Here
xn  n x .
y         recognizer of         yes, y in L
L={xn|x=01,n in N}                                  L
no

Discrete Math by R.S. Chang, Dept. CSIE, NDHU                                       4
Chapter 6 Languages: Finite State Machines
6.1 Language: The Set Theory of Strings

Def. 6.8 If x , y   * and w = xy , then x is called a prefix of w, and
if x   , then x is said to be a proper prefix. Similarly, y is called a
suffix of w; it is a proper suffix when x   .
x = x1x 2  x n has n + 1 prefixes (suffixes), n of which are proper.

Def. 6.9 If x , y , z   * and w = xyz , then y is called a substring of w.
When y  w, y is a proper substring.
How many substrings are there for x = x1x 2  x n ?
 , x1 (n), x 2  (n  1), , x n1 , x n1x n , x n :1  2  3 (n)  1

Def. 6.10 For a given alphabet  , any subset of  * is called a
language over  . This includes  , the empty language.

Discrete Math by R.S. Chang, Dept. CSIE, NDHU                                  5
Chapter 6 Languages: Finite State Machines
6.1 Language: The Set Theory of Strings

Def. 6.11 For an alphabet  and languages A, B   * , the
concatenation of A and B, denoted AB, is {ab| a  A, b  B}.

Ex. 6.10 S = {x , y , z}, A = {x , xy , z}, B = { , y}.
Then AB = {x , xy , z , xyy , zy}, BA = {x , xy , z , yx , yxy , yz}
So, (1) | AB|= 5  6 =| BA| and (2) | AB|= 5  6 =| A|| B|
In general, for finite languages A and B, | AB|  | A|| B|.

Also for x  AB, the decomposition into x = ab where a  A
and b  B is not unique. For example, A = {0,1,00},
B = {11,10,011}. Then x = 0011 = (00)(11) = (0)(011).

Discrete Math by R.S. Chang, Dept. CSIE, NDHU                           6
Chapter 6 Languages: Finite State Machines
6.1 Language: The Set Theory of Strings

Theorem 6.1 For an alphabet  , let A, B, C   * . Then
(a) A{ } = { }A = A (b) ( AB)C = A(BC ) (c) A(B  C ) = AB  AC
(d) (B  C ) A = BA  CA (e) A(B  C )  AB  AC
(f) (B  C ) A  BA  CA.
Proof of (f): x  (B  C ) A  x = yz , y  B  C , z  A 
y  B, y  C , z  A  yz  BA, yz  CA  yz  BA  CA.
And with  = {x , y , z}, B = {x , xx , y}, C = {y , xy}, and A = {y , yy}.
Then xyy  BA  CA, but xyy  (B  C ) A.

Def. 6.12 (a) A 0  { }, A1  A, A n1  {ab| a  A, b  A n }
(b) A +   nZ  A n , the positive closure of A
(c) A +   nN A n  A   { }, the Kleene closure of A

Discrete Math by R.S. Chang, Dept. CSIE, NDHU                                 7
Chapter 6 Languages: Finite State Machines
6.1 Language: The Set Theory of Strings

Ex. 6.12 Let  = {x , y}.
(a) If A = {xx , xy , yx , yy} =  2 , then A * is the language of all
strings in  * where the length of the string is even.
(b) If B = {x , y}, then BA * consists of all the strings in  * of
odd length. Also BA *  A *B,  *  A *  BA * .
(d) {x}* {y}*  {x , y}*

Ex. 6.13 A = { , x , x 3 , x 4 ,}, B = {x n | n  0}, then
A 2  B 2  B, but A  B.

Discrete Math by R.S. Chang, Dept. CSIE, NDHU                               8
Chapter 6 Languages: Finite State Machines
6.1 Language: The Set Theory of Strings

Lemma 6.1 Let  be an alphabet, with languages A, B   * .
If A  B, then A n  B n for all n  Z + .
Proof: Let S (n): A  B  A n  B n .
S (1) is true. Assume S (k ) is true. For x  A k +1 , x  x1x 2
where x1  A and x 2  A k (by definition). Therefore,
x1  B, x 2  B k , and x  B k+1 .

Discrete Math by R.S. Chang, Dept. CSIE, NDHU                       9
Chapter 6 Languages: Finite State Machines
6.1 Language: The Set Theory of Strings

Theorem 6.2 For an alphabet  and languages A, B   * ,
(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 * ) *
Proof of (g): (1) A  A * , B  B *  ( A  B)  ( A *  B * ) 
( A  B) *  ( A *  B * ) * . Conversely, A, B  A  B  A * , B *
 ( A  B) *  A *  B *  ( A  B) *  ( A *  B * ) *
 ( A  B) * (2) A * , B *  A *B *  A *  B *  A *B * 
( A *  B * ) *  ( A *B * ) * . Conversely, if xy  A *B * where
x  A * , y  B * . Then xy  A *  B *  xy  ( A *  B * ) * .
So A *B *  ( A *  B * ) *  (A *B * ) *  ( A *  B * ) * .
Discrete Math by R.S. Chang, Dept. CSIE, NDHU                           10
Chapter 6 Languages: Finite State Machines
6.1 Language: The Set Theory of Strings
recursively defined sets
Ex. 6.14  = {0,1}, define A = {x | x   * , x contains only 1
occurrence of the symbol 0}. Then A can be recurively defined as
follows: (1) 0  A (2) for any x  A, 1x , x1  A.

Ex. 6.15  = {(, )} and A   * consisting of those nonempty
strings of parentheses that are grammatically correct for algebraic
expressions. A can de defined as (1) ()  A (2) for any x , y  A,
xy  A and (x )  A.

Ex. 6.16  = {0,1} and A   * where x  A if the number of 0' s
in x is equal to the number of 1' s. Then A can be defined as
(1)   A (2) if x  A, then 01x , x 01, 0x1, 10x , x10, 1x 0  A.
Which languages in the above examples are harder to recognize?
Discrete Math by R.S. Chang, Dept. CSIE, NDHU                         11
Chapter 6 Languages: Finite State Machines
6.1 Language: The Set Theory of Strings
Ex. 6.16 Given an alphabet  , consider the string x = x 1 x 2  x n
6.17
in  * . Define the reversal of x, x R  x n x n 1 x1 . x R can be
recursively defined as (1)  R   (2) for any n  N, if x   n+1 ,
then we can write x = zy where z   , y   n . Then x R  y R z.
R R
Using this definition, we can prove that (x 1 x 2 ) R  x 2 x1 .
Proof: Induction on the length of x1 . If x 1  0, then x 1   and
(x 1 x 2 ) R  ( x 2 ) R  x 2  x 2   x 2  R  x 2 x1 . Assume the
R     R        R        R R

result is true for any y, x 2   * where y  k . Now for x 1 , x 2
where x 1  zy1 with z  1, y1  k . ( x1 x 2 ) R  ( zy1 x 2 ) R 
R R         R              R R
( y1 x 2 ) R z  x 2 y1 z  x 2 ( zy1 ) R  x 2 x1 .

Which one is harder, xx or xxR?
If x=xR, x is called a palindrome. (noon, madam, did,...)
Discrete Math by R.S. Chang, Dept. CSIE, NDHU                              12
Chapter 6 Languages: Finite State Machines
6.2 Finite State Machines: A First Encounter

A vending machine: 20c for cola (C), root beer(RB)
and accepting 5c, 10c, and 25c, and returning the necessary changes
Purchase root beer           t0       t1      t2       t3      t4
(white button)
State             s0         s1        s2         s3    s0
Input             5c         5c        10c        W
Output            N           N         N          RB

Purchase cola                                     t0         t1         t2
(black button)
State            s0         s3         s0
Input            25c        B
Output           5c         C

Discrete Math by R.S. Chang, Dept. CSIE, NDHU                                              13
Chapter 6 Languages: Finite State Machines
6.2 Finite State Machines: A First Encounter
The major features of such a machine:
(1) in only one of finitely many states at a given time
(state set S)
(2) accept as input only a finite number of symbols
(input alphabet set I)
(3) state transition function depending on input and current state
( v: S  I  S is the next state function)
(4) finite set of output alphabet set O (optional)
( w: S  I  O is the output function)
(5) deterministic (vs. nondeterministic)

Discrete Math by R.S. Chang, Dept. CSIE, NDHU                            14
Chapter 6 Languages: Finite State Machines
6.2 Finite State Machines: A First Encounter

Def. 6.13 A finite state machine is a five - tuple M = (S , I , O , v , w).
(or use final states set F instead of O)
Ex. 6.17
1,0
v        w              0,0

0    1      0     1        start          1,0           0,0
s0            s1            s2
s0         s0    s1 0 0                                             1,1
s1         s2    s1 0 0
s2          s0    s1 0 1
0,0
state transition table                              state transition diagram

Discrete Math by R.S. Chang, Dept. CSIE, NDHU                                            15
Chapter 6 Languages: Finite State Machines
6.2 Finite State Machines: A First Encounter

language A={x|x in {0,1}* and has at least 1 0's}
1,0
1

start
s0                                      start
s0
x
0,1                        x
0,1                                                          0
1,1                               0        1
final state
s1                                               s1
x is in A if the output contains 1's.             x is in A if the machine stays at
s1 when the input is consumed.
Discrete Math by R.S. Chang, Dept. CSIE, NDHU                                         16
Chapter 6 Languages: Finite State Machines
6.2 Finite State Machines: A First Encounter
Ex. 6.19 Design a 1-bit binary adder.

00,0                            01,0
01,1                            10,0
10,1                            11,1
11,0
start
s0                                s1

00,1

state to remember a carry

Discrete Math by R.S. Chang, Dept. CSIE, NDHU                                  17
Chapter 6 Languages: Finite State Machines
6.3 Finite State Machines: A Second Encounter
sequence recognizer

Ex. 6.20 Construct a machine that recognizes each occurrence
of the sequence 111 as it is encountered in any input string of {0,1}*.
For example, input 1110101111, the output should be 0010000011.

a minimal machine (3 states) 1,1               1,1
0,0

1,0
1,0                              1,1
start
s0                            s1         s2           s3
0,0
0,0
0,0
Discrete Math by R.S. Chang, Dept. CSIE, NDHU                                18
Chapter 6 Languages: Finite State Machines
6.3 Finite State Machines: A Second Encounter
Ex. 6.21 recognize the occurrences of 111 that end
in a position that is a multiple of three. (input 1110111,
output 0010000)
1,1
0,0
1,0                1,0
start
s0                 s1                 s2

0,0                     0,0
used to consume
0,0
s4   extra symbols
s3              1,0
before counting
0,0
1,0
Discrete Math by R.S. Chang, Dept. CSIE, NDHU                                 19
Chapter 6 Languages: Finite State Machines
6.3 Finite State Machines: A Second Encounter
Ex. 6.23 Languages that cannot be recognized by a
finite state machine. A={0i1i|i is a positive integer}
Assume there is a FSM that recognizes A with n states.

start     s0         s1        s2 ...     si ...   sj   ... sn-1

transition for x= 0n1n                     by the pigeonhole principle,
this cycle must exist

If x is recognized, then 0n-(j-i+1)1n would also be recognized.
Therefore, such FSM cannot exist.

Discrete Math by R.S. Chang, Dept. CSIE, NDHU                                       20
Chapter 6 Languages: Finite State Machines
6.3 Finite State Machines: A Second Encounter
k-unit delay machines
input x = x1x 2  x m , output w(s0 , x )  000x1x 2  x m .


k 0's
Ex. 6.25 1-unit delay machine

0,0
0,0        s1                    remembering 0
start
s0
0,1               1,0

1,0         s2            1,1    remembering 1

Discrete Math by R.S. Chang, Dept. CSIE, NDHU                                21
Chapter 6 Languages: Finite State Machines
6.3 Finite State Machines: A Second Encounter
Ex. 6.25 2-unit delay machine
start

s0
1,0
0,0
s1                                      s2
0,0       0,0           1,0                         0,0         1,0
0,0                                1,1
1,0                                     0,1
s3                    s4               s5                 s6
1,1

0,1                          1,0

Discrete Math by R.S. Chang, Dept. CSIE, NDHU                                        22
Chapter 6 Languages: Finite State Machines
6.3 Finite State Machines: A Second Encounter
Def. 6.14 (a) reachable v(si,x)=sj (b) transient state
v(s,x)=s implies x=  , s2 is the only transient state.
(c) sink state v(s,x)=s for all x s
s3 is the only sink              0  0,0            0,1
(d) submachine                  1,0 0,1
(e) strongly connected                                          1,1
s2 1,1 s1                 s4            s5
for any si,sj, si is
reachable from sj                       1,1                   0,1    1,1
0,1                 0,0               0,0
s3      s7            s6
1,0
a strongly
1,0        1,1     connected
0,0                submachine
Discrete Math by R.S. Chang, Dept. CSIE, NDHU                                    23
Chapter 6 Languages: Finite State Machines
6.3 Finite State Machines: A Second Encounter
Def. 6.15 Let si , s j be two distinct states. A shortest
input string x  I + is called a transfer (or transition) sequence
from si to s j if
(a) v (si , x )  s j (b) v (si , y )  s j  y  x . (may not be unique)
Ex. 6.26          v        w          Find a transfer sequence from s0 to s2.
0 1 0 1
s0          s6 s1 0 1                             0 s0     1
s6                         s1
s1          s5 s0 0 1
s2          s1 s2 0 1                   1       0               0        1
s3          s4 s0 0 1                              s3            s5        s0
s6               1      1      0
s4          s2 s1 0 1                         0
s5          s3 s5 0 1                       s4          s0   s5        s3
s6          s3 s6 0 1                  1    0
s1        s2
Discrete Math by R.S. Chang, Dept. CSIE, NDHU                                       24
Chapter 6 Languages: Finite State Machines

Exercise: P291: 16
P298: 6
P305: 4,6

Discrete Math by R.S. Chang, Dept. CSIE, NDHU   25

```
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
 views: 16 posted: 1/26/2012 language: English pages: 25
How are you planning on using Docstoc?