55
Closure under the Regular Operations Closure under the Regular Operations – p.1/26

Automata 7

Embed Size (px)

Citation preview

Page 1: Automata 7

Closure under the RegularOperations

Closure under the Regular Operations – p.1/26

Page 2: Automata 7

Application of NFA

� Now we use the NFA to show that the collection ofregular languages is closed under regular operationsunion, concatenation, and star

Earlier we have shown this closure for union using aCartesian product of DFA

For uniformity reason we reconstruct that proof usingNFA

Closure under the Regular Operations – p.2/26

Page 3: Automata 7

Application of NFA

� Now we use the NFA to show that the collection ofregular languages is closed under regular operationsunion, concatenation, and star

� Earlier we have shown this closure for union using aCartesian product of DFA

For uniformity reason we reconstruct that proof usingNFA

Closure under the Regular Operations – p.2/26

Page 4: Automata 7

Application of NFA

� Now we use the NFA to show that the collection ofregular languages is closed under regular operationsunion, concatenation, and star

� Earlier we have shown this closure for union using aCartesian product of DFA

� For uniformity reason we reconstruct that proof usingNFA

Closure under the Regular Operations – p.2/26

Page 5: Automata 7

Theorem 1.45

The class of regular languages is closed under the unionoperation

Proof idea:

Let regular languages and be recognized by NFA and, respectively

To show that is regular we will construct an NFA thatrecognizes

must accept its input if either or accepts its input. Hence,must have a new state that will allow it to guess

nondeterministically which of or accepts it

Guessing is implemented by transitions from the new state tothe start states of and , as seen in Figure 1

Closure under the Regular Operations – p.3/26

Page 6: Automata 7

Theorem 1.45

The class of regular languages is closed under the unionoperation

Proof idea:

Let regular languages and be recognized by NFA and, respectively

To show that is regular we will construct an NFA thatrecognizes

must accept its input if either or accepts its input. Hence,must have a new state that will allow it to guess

nondeterministically which of or accepts it

Guessing is implemented by transitions from the new state tothe start states of and , as seen in Figure 1

Closure under the Regular Operations – p.3/26

Page 7: Automata 7

Theorem 1.45

The class of regular languages is closed under the unionoperation

Proof idea:

Let regular languages

��� and

��� be recognized by NFA

�� and

�� , respectively

To show that is regular we will construct an NFA thatrecognizes

must accept its input if either or accepts its input. Hence,must have a new state that will allow it to guess

nondeterministically which of or accepts it

Guessing is implemented by transitions from the new state tothe start states of and , as seen in Figure 1

Closure under the Regular Operations – p.3/26

Page 8: Automata 7

Theorem 1.45

The class of regular languages is closed under the unionoperation

Proof idea:

Let regular languages

��� and

��� be recognized by NFA

�� and

�� , respectively

To show that

�� � �� is regular we will construct an NFA

thatrecognizes

�� � ��

must accept its input if either or accepts its input. Hence,must have a new state that will allow it to guess

nondeterministically which of or accepts it

Guessing is implemented by transitions from the new state tothe start states of and , as seen in Figure 1

Closure under the Regular Operations – p.3/26

Page 9: Automata 7

Theorem 1.45

The class of regular languages is closed under the unionoperation

Proof idea:

Let regular languages

��� and

��� be recognized by NFA

�� and

�� , respectively

To show that

�� � �� is regular we will construct an NFA

thatrecognizes

�� � ��

� �

must accept its input if either

�� or

�� accepts its input. Hence,

must have a new state that will allow it to guessnondeterministically which of

�� or

�� accepts it

Guessing is implemented by transitions from the new state tothe start states of and , as seen in Figure 1

Closure under the Regular Operations – p.3/26

Page 10: Automata 7

Theorem 1.45

The class of regular languages is closed under the unionoperation

Proof idea:

Let regular languages

��� and

��� be recognized by NFA

�� and

�� , respectively

To show that

�� � �� is regular we will construct an NFA

thatrecognizes

�� � ��

� �

must accept its input if either

�� or

�� accepts its input. Hence,

must have a new state that will allow it to guessnondeterministically which of

�� or

�� accepts it

Guessing is implemented by � transitions from the new state tothe start states of

�� and

�� , as seen in Figure 1Closure under the Regular Operations – p.3/26

Page 11: Automata 7

An NFA recognizing � �

��� ��

��

��� ��

��

��

��

��

��

��

Figure 1: Construction of

to recognize

� � � ��

Closure under the Regular Operations – p.4/26

Page 12: Automata 7

Proof

Let

��� � �� ��� �� � � �� � ��

, and

��� � �� ��� �� � � �� � ��

Construct

� � �� � �� � �� �

to recognize� � � � � using the

following procedure:

Closure under the Regular Operations – p.5/26

Page 13: Automata 7

Construction procedure

1.

� � ��� � � � � � � � � : That is, the states of

are all states on

��

and

�� with the addition of a new state � �

2. The start state of is

3. The accept states of are : That is, the accept statesof are all the accept states of and

4. Define so that for any and any :

if

if

if and

if and .

Closure under the Regular Operations – p.6/26

Page 14: Automata 7

Construction procedure

1.

� � ��� � � � � � � � � : That is, the states of

are all states on

��

and

�� with the addition of a new state � �2. The start state of

is � �

3. The accept states of are : That is, the accept statesof are all the accept states of and

4. Define so that for any and any :

if

if

if and

if and .

Closure under the Regular Operations – p.6/26

Page 15: Automata 7

Construction procedure

1.

� � ��� � � � � � � � � : That is, the states of

are all states on

��

and

�� with the addition of a new state � �2. The start state of

is � �

3. The accept states of

are

� � �� � �� : That is, the accept statesof

are all the accept states of�� and

��

4. Define so that for any and any :

if

if

if and

if and .

Closure under the Regular Operations – p.6/26

Page 16: Automata 7

Construction procedure

1.

� � ��� � � � � � � � � : That is, the states of

are all states on

��

and

�� with the addition of a new state � �2. The start state of

is � �

3. The accept states of

are

� � �� � �� : That is, the accept statesof

are all the accept states of�� and

��

4. Define

so that for any � � �

and any � � ��� :

� �� � � � �

�� ���� �� �

���� � � � � if � � � �

���� � � � � if � � � �

��� � � � ��

��� if � � � � and � � �

�� if � � � � and � � � �.

Closure under the Regular Operations – p.6/26

Page 17: Automata 7

Application

Consider the alphabet

� � � �� � �

and the languages:

� � � � � � ��� �� � � �� �� � � � � � � �� �

� � � � � �� �� � � � �� � � � � � ��� � � � �

� � � � � � � �� � � � � � � � � � � � �

� � � � � � � �� � �� � �� � � � � � � � � � � �� � � � �

Use the construction given in the proof of theorem 1.45 to

give the state diagrams recognizing the languages

� � �

and

� �

.

Closure under the Regular Operations – p.7/26

Page 18: Automata 7

Theorem 1.47

The class of regular languages is closed underconcatenation operation

Proof idea: Assume two regular languages,

� � and

� � rec-

ognized by NFAs

� � and

��� , respectively. Construct

as

suggested in Figure 2

Closure under the Regular Operations – p.8/26

Page 19: Automata 7

Construction of NFA

���

� �

���

��

� �

��

� � � ���

��� � � ���

�Figure 2: Construction of

to recognize

� � � ��

Closure under the Regular Operations – p.9/26

Page 20: Automata 7

Construction procedure

� Combine

��� and

��� into a new automaton�

thatstarts in the start state of

� �

Add transitions from the accept states of to thestart state of

Set accept states of to be the accept states on

Closure under the Regular Operations – p.10/26

Page 21: Automata 7

Construction procedure

� Combine

��� and

��� into a new automaton�

thatstarts in the start state of

� �

� Add � transitions from the accept states of

� � to thestart state of

� �

Set accept states of to be the accept states on

Closure under the Regular Operations – p.10/26

Page 22: Automata 7

Construction procedure

� Combine

��� and

��� into a new automaton�

thatstarts in the start state of

� �

� Add � transitions from the accept states of

� � to thestart state of

� �

� Set accept states of

to be the accept states on

� �

Closure under the Regular Operations – p.10/26

Page 23: Automata 7

Proof

Let

��� � �� ��� �� � � �� � ��

recognize

� � and

�� � �� � � �� � � �� � ��

recognize

� � .

Construct

� � �� � �� � �� � ��

by the following procedure:

Closure under the Regular Operations – p.11/26

Page 24: Automata 7

Construction procedure

1.

� � � � � � � . The states of

are all states of�� and

��

2. The start state is the state of

3. The accept states is the set of the accept states of

4. Define so that for any and any :

if and

if and

if and

if .

Closure under the Regular Operations – p.12/26

Page 25: Automata 7

Construction procedure

1.

� � � � � � � . The states of

are all states of�� and

��

2. The start state is the state � � � of

��

3. The accept states is the set of the accept states of

4. Define so that for any and any :

if and

if and

if and

if .

Closure under the Regular Operations – p.12/26

Page 26: Automata 7

Construction procedure

1.

� � � � � � � . The states of

are all states of�� and

��

2. The start state is the state � � � of

��

3. The accept states is the set

�� of the accept states of

��

4. Define so that for any and any :

if and

if and

if and

if .

Closure under the Regular Operations – p.12/26

Page 27: Automata 7

Construction procedure

1.

� � � � � � � . The states of

are all states of�� and

��

2. The start state is the state � � � of

��

3. The accept states is the set

�� of the accept states of

��

4. Define

so that for any � � �

and any � � ��� :

� �� � � � �

�� ��� �� �

���� � � � � if � � � � and � �� ��

���� � � � � if � � �� and � � � �

���� � � � � � � � ��� if � � �� and � � �

���� � � � � if � � � � .

Closure under the Regular Operations – p.12/26

Page 28: Automata 7

Application

Consider the alphabet

� � � �� � �

and the languages:

� � � � � � � � � � �

� � � � � � � � � � � � � � � � �� � � � � �

� � � � � �� �� � � � �� � � � � � �� � � � �

� � ��

Use the construction given in the proof of theorem 1.47 to

give the state diagrams recognizing the languages

�� �

and

� �

where � is concatenation operator.

Closure under the Regular Operations – p.13/26

Page 29: Automata 7

Theorem 1.49

The class of regular languages is closed under staroperation

Proof idea: we have a regular language� � , recognized by

the NFA

��� and want to prove that�� � is also a regular

language.

The procedure to prove this theorem is by construction of

the NFA

that recognizes

�� � as shown in Figure 3

Closure under the Regular Operations – p.14/26

Page 30: Automata 7

Procedure for the construction of

���

��

��

���

Figure 3: Construction of

to recognize

� ��

Closure under the Regular Operations – p.15/26

Page 31: Automata 7

More on the proof idea

� �

is like

� � with a new start state and an � transitionfrom the new start state to �

Since the new start state is an accepts state

We add transitions from the previous accept states ofto the start state of allowing the machine to read

and recognize strings of the form where

Closure under the Regular Operations – p.16/26

Page 32: Automata 7

More on the proof idea

� �

is like

� � with a new start state and an � transitionfrom the new start state to �

� Since � � �� � the new start state is an accepts state

We add transitions from the previous accept states ofto the start state of allowing the machine to read

and recognize strings of the form where

Closure under the Regular Operations – p.16/26

Page 33: Automata 7

More on the proof idea

� �

is like

� � with a new start state and an � transitionfrom the new start state to �

� Since � � �� � the new start state is an accepts state

� We add � transitions from the previous accept states of

�� to the start state of� � allowing the machine to read

and recognize strings of the form � � ��� � �

� ��� where

� �� � � � � ��� � � �

Closure under the Regular Operations – p.16/26

Page 34: Automata 7

Proof

Let

��� � �� ��� �� � � �� � ��

recognize

� � .Construct

� � �� � �� � �� �

by the procedure:

Closure under the Regular Operations – p.17/26

Page 35: Automata 7

Construction procedure

1.

� � ��� � � � � � ; i.e. states of

�� plus a new state � �

2. Start state if is

3. ; that is, the accept states of are the acceptstates of plus the new start state

4. Define so that for any and :

if and

if and

if and

if and

if and .

Closure under the Regular Operations – p.18/26

Page 36: Automata 7

Construction procedure

1.

� � ��� � � � � � ; i.e. states of

�� plus a new state � �

2. Start state if

is � �

3. ; that is, the accept states of are the acceptstates of plus the new start state

4. Define so that for any and :

if and

if and

if and

if and

if and .

Closure under the Regular Operations – p.18/26

Page 37: Automata 7

Construction procedure

1.

� � ��� � � � � � ; i.e. states of

�� plus a new state � �

2. Start state if

is � �

3.

� � ��� � � � �� ; that is, the accept states of�

are the acceptstates of

�� plus the new start state

4. Define so that for any and :

if and

if and

if and

if and

if and .

Closure under the Regular Operations – p.18/26

Page 38: Automata 7

Construction procedure

1.

� � ��� � � � � � ; i.e. states of

�� plus a new state � �

2. Start state if

is � �

3.

� � ��� � � � �� ; that is, the accept states of�

are the acceptstates of

�� plus the new start state

4. Define

so that for any � � �

and � � �� :

� �� � � � �

�� �� ��� �� �� �

���� � � � � if � � � � and � �� ��

���� � � � � if � � �� and � � � �

���� � � � � � � � ��� if � � �� and � � �

��� � ��� if � � � � and � � �

�� if � � � � and � � � �.

Closure under the Regular Operations – p.18/26

Page 39: Automata 7

Application

Consider the alphabet

� � � �� � �

and the languages:

� � � � � �� �� � � � �� � � � � � ��� � � � �

� � � � � �� �� � � � �� � � � � � � �� �� � �� � � � �� � � �

� � ��

Use the construction given in the proof of theorem 1.49 to

give the state diagrams recognizing the languages

� �

,

� �

and

��

.

Closure under the Regular Operations – p.19/26

Page 40: Automata 7

Closure under complementation

� The class of regular languages is closed undercomplementation.

For that we will first show thatif is a DFA thatrecognizes a language , swapping the accept andnon-accept states in yields a new DFA thatrecognizes the complement of .

Closure under the Regular Operations – p.20/26

Page 41: Automata 7

Closure under complementation

� The class of regular languages is closed undercomplementation.

� For that we will first show thatif is a DFA thatrecognizes a language

, swapping the accept andnon-accept states in yields a new DFA thatrecognizes the complement of

.

Closure under the Regular Operations – p.20/26

Page 42: Automata 7

Proof

Let

� �

be the DFA

with accept and non-accept states swapped. Wewill show that

� �

recognizes the complement of�

1. uppose accept , i.e., if we run on we end in an acceptstate of

2. Because and have swapped accept/non-accept states, ifwe run on we would end in a non-accept state. Hence,

3. Similarly, if is not accepted by , it would be accepted by

Consequently, accepts those strings that are not accepted by

and therefore recognizes the complement of .

Closure under the Regular Operations – p.21/26

Page 43: Automata 7

Proof

Let

� �

be the DFA

with accept and non-accept states swapped. Wewill show that

� �

recognizes the complement of�

1. uppose

� �

accept �, i.e., if we run

� �

on � we end in an acceptstate of

� �

2. Because and have swapped accept/non-accept states, ifwe run on we would end in a non-accept state. Hence,

3. Similarly, if is not accepted by , it would be accepted by

Consequently, accepts those strings that are not accepted by

and therefore recognizes the complement of .

Closure under the Regular Operations – p.21/26

Page 44: Automata 7

Proof

Let

� �

be the DFA

with accept and non-accept states swapped. Wewill show that

� �

recognizes the complement of�

1. uppose

� �

accept �, i.e., if we run

� �

on � we end in an acceptstate of

� �

2. Because

and

� �

have swapped accept/non-accept states, ifwe run

on � we would end in a non-accept state. Hence, � �� �

3. Similarly, if is not accepted by , it would be accepted by

Consequently, accepts those strings that are not accepted by

and therefore recognizes the complement of .

Closure under the Regular Operations – p.21/26

Page 45: Automata 7

Proof

Let

� �

be the DFA

with accept and non-accept states swapped. Wewill show that

� �

recognizes the complement of�

1. uppose

� �

accept �, i.e., if we run

� �

on � we end in an acceptstate of

� �

2. Because

and

� �

have swapped accept/non-accept states, ifwe run

on � we would end in a non-accept state. Hence, � �� �

3. Similarly, if � is not accepted by

� �

, it would be accepted by

Consequently, accepts those strings that are not accepted by

and therefore recognizes the complement of .

Closure under the Regular Operations – p.21/26

Page 46: Automata 7

Proof

Let

� �

be the DFA

with accept and non-accept states swapped. Wewill show that

� �

recognizes the complement of�

1. uppose

� �

accept �, i.e., if we run

� �

on � we end in an acceptstate of

� �

2. Because

and

� �

have swapped accept/non-accept states, ifwe run

on � we would end in a non-accept state. Hence, � �� �

3. Similarly, if � is not accepted by

� �

, it would be accepted by

Consequently,

� �

accepts those strings that are not accepted by

and therefore

� �

recognizes the complement of

.

Closure under the Regular Operations – p.21/26

Page 47: Automata 7

Conclusion

� �

has been an arbitrary regular language. Therefore,our construction shows how to build an automaton torecognize its complement

Hence, the complement of any regular language isalso regular

Consequently the class of regular languages is closedunder complementation

Closure under the Regular Operations – p.22/26

Page 48: Automata 7

Conclusion

� �

has been an arbitrary regular language. Therefore,our construction shows how to build an automaton torecognize its complement

� Hence, the complement of any regular language isalso regular

Consequently the class of regular languages is closedunder complementation

Closure under the Regular Operations – p.22/26

Page 49: Automata 7

Conclusion

� �

has been an arbitrary regular language. Therefore,our construction shows how to build an automaton torecognize its complement

� Hence, the complement of any regular language isalso regular

� Consequently the class of regular languages is closedunder complementation

Closure under the Regular Operations – p.22/26

Page 50: Automata 7

Interesting property

If is an NFA that recognizes language�

, swapping its

accept and non-accept states doesn’t necessarily yield a

new NFA that recognizes the complement of

.

Closure under the Regular Operations – p.23/26

Page 51: Automata 7

Proof

We prove the interesting property by constructing acounter-example.

� Consider the construction in Figure 4, where bothNFA-s, and

, accept aa.

� 1

a

2

a,b

b

� 1

a

2

a,b

b

Figure 4: NFAs

and

� �

Closure under the Regular Operations – p.24/26

Page 52: Automata 7

Question

Is the class of languages recognized by NFAs closed under

complementation?

Closure under the Regular Operations – p.25/26

Page 53: Automata 7

Closure under complementation

� The class of languages recognized by NFA is stillclosed under complementation

This follows from the fact that the class of languagesrecognized by NFAs is precisely the class of languagesrecognized by DFA

The counter-example in Figure 4 shows the differencebetween the process of computations performed byDFAs and NFAs

Closure under the Regular Operations – p.26/26

Page 54: Automata 7

Closure under complementation

� The class of languages recognized by NFA is stillclosed under complementation

� This follows from the fact that the class of languagesrecognized by NFAs is precisely the class of languagesrecognized by DFA

The counter-example in Figure 4 shows the differencebetween the process of computations performed byDFAs and NFAs

Closure under the Regular Operations – p.26/26

Page 55: Automata 7

Closure under complementation

� The class of languages recognized by NFA is stillclosed under complementation

� This follows from the fact that the class of languagesrecognized by NFAs is precisely the class of languagesrecognized by DFA

� The counter-example in Figure 4 shows the differencebetween the process of computations performed byDFAs and NFAs

Closure under the Regular Operations – p.26/26