2.3 Formal Definition of Finite State Automata Definition 3 : A finite state automaton(FA) M = (, Q, , q 0, F), where is a finite set alphabet, Q is a finite set of states, : Q Q is a transition function, q 0 Q is the initial state, F Q is the set of final states. Note : A finite state automaton (FA) M defined above is a deterministic finite state automaton (DFA), since each move of the machine is uniquely determined. Example : A finite state automaton M 1 = (, Q, 1, q 0, F), where = {0, 1}, Q ={q 0, q 1, q 2 , q t }, q 0 Q is the initial state, F ={q 1, q 2}, 1 : Q Q is defined as below. 1 0 q0 q 1 q2 q2 q2 q0 1 0 q1 1 0, 1 q2 q1 qt qt qt qt qt q2 0, 1 qt trap state 0, 1 The state q t is a trap state in the machine M 1. For simplicity, we can ignore the trap state. Then the transition function and transition diagram of M 1 becomes as follows. 1 0 q0 q 1 q2 q2 q2 0 q2 0, 1 1 q0 q1 1 q2 In this case, the machine accepts the strings over {0, 1} interpreted as numbers in binary. An FA M = (, Q, , q 0, F), extend the transition function : Q Q to a function * : Q * Q defined by (1) *(q, ) = q, and (2) *(q, a) = ( *(q, ), a), for all string and a . Note: *(q, ) = p means after reading an FA M changes from state q to p. It may include 0, 1or more moves. Example : 1*(q 0, 1010) = q 2 1*(q 0, 1010) = 1 ( 1*(q 0, 101) , 0) = 1( 1( 1*(q 0, 10), 1) , 0) = 1( 1( 1( 1*(q 0, 1), 0), 1) , 0) = 1( 1( 1( 1( 1*(q 0, ), 1), 0), 1) , 0) = 1( 1( 1( 1(q 0, 1), 0), 1) , 0) = 1( 1( 1(q 2, 0), 1) , 0) = 1( 1(q 2, 1) , 0) = 1(q 2 , 0) = q 2 Definition 4 : The set L accepted by an FA M = (, Q, , q 0, F) can be defined as L = L(M) ={ * | *(q 0, ) F}. Definition 2 and definition 4 are equivalent, since *(q 0, ) = q F is same as q 0 |--* q . Definition 5 : A language L over an alphabet is said to be regular if there is an FA M = (, Q, , q 0, F) that accepts L. Example : The set of strings over {0, 1} interpreted as numbers in binary is a regular language. Example : The set of strings over {0, 1} those have even number of 0’s and even number of 1’s is regular. Example : Design an FA M to accept strings over {0, 1}, and while the strings interpreted as binary numbers they all are congruent to 1 mod 3. Solution : The most important part to design an FA M is to design the transition diagram of the FA. In this case, the state q n of the machine can be classified as n mod 3 for some n, i.e, after reading the machine enters the state q n. q0 0 1 q1 q2 1 0 0 1 qt 1 q’0 0 The strings 100, 1101, 110100 are accepted by the machine, since 100 1101 110100 1 mod 3. The way to design an FA M is similar to design a program. But the expressive methods are different, so are the processes. To design an FA M, usually we first to connect the initial state to a final state. Next, add states and connect those states with the required input symbols. Example : Design an FA M to accept strings over {0, 1} ending with the substring 010. Solution : Step 1: construct states from the initial state to a final state with the input string 010 as follows. 0 q0 1 q1 0 q2 q3 Step 2 : Consider the initial state q 0 with input 1. The input symbol 1 does not help to form a string of 010. Hence, we let it repeat again back to state q 0. 1 0 q0 1 q1 0 q2 q3 Step 3 : Consider the state q 1 with input 0. The input symbol 0 does not affect the ending string 010. Hence, we let it repeat again back to state q 1. 1 0 0 q0 1 1 q1 0 q2 q3 Step 4 : Consider the state q 2 with input 1. The input symbol 1 breaks up the ending string 010. Hence, we have to connect the state q 2 back to state q 0 in order to start to form an ending string 010. 1 0 0 q0 1 1 q1 1 0 q2 q3 Step 5 : Consider the state q 3 with input 0. The input symbol 0 appending to the end of the string 010 forms a new string 0100. We only need to add two more symbols 10 to get a string ending with 010. Hence, we need connect the state q 3 back to state q 1. 1 0 q0 0 0 1 1 q1 1 0 q2 q3 Step 6 : Consider the state q 3 with input 1. The input symbol 1 appending to the end of the string 010 forms a new string 0101. We only need to add one more symbol 0, and we can get a string ending with 010. Hence, we need connect the state q 3 back to state q 2. 1 0 q0 0 0 1 1 q1 1 0 q2 q3 1 Example : Design an FA M to accept strings over {0, 1} such that the 2nd symbol from the right end of the strings is 0. Solution : Step 1: construct states from the initial state to a final state with the input string 00 as follows. 0 q0 0 q1 q2 Step 2: At the state q 0, repeating the symbol 1 does not affect the result. The state q 0 is done. At the state q 2, repeating the symbol 0 the strings must be accepted by the machine. Hence, it goes to the same state q 2. 0 1 0 q0 0 q1 q2 Step 3: At the state q 1, reading the symbol 1 the machine must enter a new final state q 3. And the state q 1 is done. 0 0 q0 q1 q2 0 1 1 q3 Step 4: At the state q 2, reading the symbol 1 the machine must enter a new final state q 4. And the state q 2 is done. 0 0 q0 q1 1 q2 1 1 q3 q4 0 Step 5: At the state q 3, reading the symbol 0 the machine must enter the state q 1. In this case, the state q 3 is quite similar to the state q 0. 0 0 q0 q1 1 1 q2 0 0 1 q3 q4 Step 6: At the state q 3, reading the symbol 1 the machine must enter the state q 0 because of 2 consecutive 1’s. The state q 3 is done. 0 0 q0 1 q1 1 1 q2 0 q3 1 q4 0 Step 7: At the state q 4, reading the symbol 0 the machine must enter the state q 1. In this case, the state q 4 is equivalent to the state q 3. 0 0 q0 1 q1 1 1 q2 0 0 q3 0 1 q4 Step 8: Now we can drop out the state q 4, and change (q 2, 1) = q3. 0 0 q0 1 q1 1 1 q2 0 q3 1 0 Example : Design an FA M to accept strings over {0, 1} so that each 3 consecutive symbols in a string containing at least 2 0’s. Solution : There could be many states in the machine. It may require a large piece of paper to draw the transition diagram of the machine. In stead of drawing the transition diagram of the machine, it is sufficient to describe the transition function as follows. Let Q = {q } {q a | a= 0 or 1} {q ab | a, b = 0 or 1} {q abc | a, b, c = 0 or 1} The initial state is q . The transition function has the following properties: (1) (q , a) = q a, for a = 0 or 1, (2) (q a, b) = q ab, for a, b = 0 or 1, (3) (q ab, c) = q abc, for a, b, c = 0 or 1, (4) (q abc, d) = q abc, for a, b, c, d = 0 or 1, and a+b+c > 1 (5) (q abc, d) = q bcd, for a, b, c, d = 0 or 1, and a+b+c < 2 Final states are of the form q abc , where a, b, c = 0 or 1 and at least two of a, b and c are 0’s. Example : Design an FA M to accept strings over {0, 1} so that the evaluation of the string according to the following operation is same as the evaluation of R. 0 1 0 0 0 1 1 0 The operation is not associative. Hence the way to evaluate from left to right may be different from that to evaluate from right to left. The evaluation of the string 1000 = 100 = 10 = 1. The evaluation of the string 1000 R = 0001 = 001 = 01 = 0. The string 1000 is not accepted by M. The evaluation of the string 1100 = 000 = 00 = 0. The evaluation of the string 1100 R = 0011 = 011 = 01 = 0. The string 1100 is accepted by M. This problem is not easy to handle, since we have to consider two different ways to evaluate the same string. We list the solution first, and leave the constructive method later until we reach section 2.4 nondeterministic FA. Solution : 0, 1 0 0 q0 1 q1 q2 1 q4 0, 1 1 0 q5 1 0 q3