Recap Lecture 16 Examples of Kleenes theorem part

  • Slides: 22
Download presentation
Recap Lecture 16 • Examples of Kleene’s theorem part III (method 3), NFA, examples,

Recap Lecture 16 • Examples of Kleene’s theorem part III (method 3), NFA, examples, avoiding loop using NFA, example, converting FA to NFA, examples, applying an NFA on an example of maze, NFA with null string, examples, RE corresponding to NFA with null string (task), converting NFA to FA (method 1, 2, 3) examples, NFA and Kleene’s theorem method 1, examples, NFA and Kleene’s theorem method 2, examples 1

Task • Determine the regular expression of the following NFA- 2 4+ a a

Task • Determine the regular expression of the following NFA- 2 4+ a a a 1 , b 3 b a 5 a 2

Solution of the Task 2 4+ a a a 1 , b 3 b

Solution of the Task 2 4+ a a a 1 , b 3 b a 5 a To eliminate state 5 the above NFA- may be reduced to the following 3

Solution continued … 2 +aa*a a a 1 - 4+ ba*a +b 3 To

Solution continued … 2 +aa*a a a 1 - 4+ ba*a +b 3 To eliminate state 2 the above NFA- may be reduced to the following 4

Solution continued … 1 - +b a( +aa*a) 4+ 3 ba*a To eliminate state

Solution continued … 1 - +b a( +aa*a) 4+ 3 ba*a To eliminate state 3 the above NFA- may be reduced to the following 5

Solution continued … 1 - a( +aa*a)+( +b)(a( +aa*a)+ba*a) 4+ Hence the RE is

Solution continued … 1 - a( +aa*a)+( +b)(a( +aa*a)+ba*a) 4+ Hence the RE is a( +aa*a)+( +b)(a( +aa*a)+ba*a) Which may be reduced to a+aaa*a+ba+baaa*a +bba*a OR a+aaa*a+baaa*a +bba*a 6

Task • Build an FA corresponding to the following NFA which accepts the language

Task • Build an FA corresponding to the following NFA which accepts the language of strings containing bb a, b 1 - a, b b 2 b 3+ 7

Solution of the Task a, b 1 a a, b b 2 b b

Solution of the Task a, b 1 a a, b b 2 b b 1 - a b (1, 2) b (1, 2, 3) + 3+ a b a (1, 3)+ It may be noted that the above method seems to be complicated, hence an easier method discussed by Martin, follows as 8

NFA to FA continued … Method 3: As discussed earlier that in an NFA,

NFA to FA continued … Method 3: As discussed earlier that in an NFA, there may be more than one transition for a certain letter and there may not be any transition for certain letter, so starting from the initial state corresponding to the initial state of given NFA, the transition table along with new labels of states, of the corresponding FA, can be built introducing an empty state for a letter having no transition at certain state and a state corresponding to the combination of states, for a letter having more than one transitions. 9 Following are the examples

Example • Consider the following NFA which accepts the language of strings containing bb

Example • Consider the following NFA which accepts the language of strings containing bb a, b x 1 - a, b b x 2 b x 3+ Using the method discussed earlier, the transition table corresponding to the required FA may be constructed as 10

Example continued … Old States New States after reading a b z 1 x

Example continued … Old States New States after reading a b z 1 x 1 z 1 (x 1, x 2) z 2 (x 1, x 2) (x 1 , ) x 1 z 1 (x 1 , x 2, x 3) z 3+ (x 1, x 2, x 3) (x 1, x 3) z 4 (x 1 , x 2, x 3) z 3 z 4+ (x 1, x 3) z 4 (x 1 , x 2, x 3) z 3 The corresponding transition diagram follows as 11

Example continued … a b b z 1 - a z 2 b z

Example continued … a b b z 1 - a z 2 b z 3+ a b a z 4+ 12

NFA and Kleene’s Theorem It has been discussed that, by Kleene’s theorem part III,

NFA and Kleene’s Theorem It has been discussed that, by Kleene’s theorem part III, there exists an FA corresponding to a given RE. If the given RE is as simple as r=aa+bbb or r=a(a+b)*, the corresponding FAs can easily be constructed. However, for a complicated RE, the RE can be decomposed into simple REs corresponding to which the FAs can easily be constructed and hence, using the method, constructing the FAs corresponding to sum, concatenation and closure of FAs, the required FA can also be constructed. It is to be noted that NFAs also help in proving Kleene’s theorem part III, as well. Two methods are discussed 13 in the following.

NFA and Kleene’s Theorem Method 1: The method is discussed considering the following example.

NFA and Kleene’s Theorem Method 1: The method is discussed considering the following example. Example: To construct the FAs for the languages L 1= {a}, L 2= {b} and L 3= { } Step 1: Build NFA 1, NFA 2 and NFA 3 corresponding to L 1, L 2 and L 3 , respectively as shown in the following diagram 14

NFA and Kleene’s Theorem (method 1 ) continued … • NFA 1 • NFA

NFA and Kleene’s Theorem (method 1 ) continued … • NFA 1 • NFA 2 • NFA 3 a - - + b + 15

NFA and Kleene’s Theorem (method 1 ) continued … Step 2: As discussed earlier

NFA and Kleene’s Theorem (method 1 ) continued … Step 2: As discussed earlier for every NFA there is an FA equivalent to it, hence there must be FAs for the above mentioned NFAs as well. The corresponding FAs can be considered as follows 16

NFA and Kleene’s Theorem (method 1 ) continued … b –– FA 1 a

NFA and Kleene’s Theorem (method 1 ) continued … b –– FA 1 a a –– + a, b FA 2 b + a, b 1 1 a, b FA 3 1 17

NFA and Kleene’s Theorem method 2 It may be observed that if an NFA

NFA and Kleene’s Theorem method 2 It may be observed that if an NFA can be built corresponding to union, concatenation and closure of FAs corresponding to the REs, then converting the NFA, thus, obtained into an equivalent FA, this FA will correspond to the given RE. Followings are the procedures showing how to obtain NFAs equivalent to union, concatenation and closure of FAs 18

NFA corresponding to Union of FAs Method: Introduce a new start state and connect

NFA corresponding to Union of FAs Method: Introduce a new start state and connect it with the states originally connected with the old start state with the same transitions as the old start state, then remove the –ve sign of old start state. This creates nondeterminism and hence results in an NFA. 19

Example b a x 4+ b • FA 2 x 2 a x 1

Example b a x 4+ b • FA 2 x 2 a x 1 - • FA 1 b a y 1 - a x 3 a, b b y 2+ 20

b a x 1 b a b x 2 a x 4+ b a

b a x 1 b a b x 2 a x 4+ b a a x 3 b a y 1 a, b b y 2+ NFA equivalent to FA 1 UFA 2 21

Summing Up • converting NFA to FA (method 3), example, NFA and Kleene’s theorem

Summing Up • converting NFA to FA (method 3), example, NFA and Kleene’s theorem method 1, examples, NFA and Kleene’s theorem method 2 , NFA corresponding to union of FAs, example 22