Www.nskinfo.com && Department of nskinfo-i education CS2303-THEORY OF COMPUTATION Chapter: Closure.

Post on 26-Mar-2015

215 views 1 download

Tags:

Transcript of Www.nskinfo.com && Department of nskinfo-i education CS2303-THEORY OF COMPUTATION Chapter: Closure.

www.nskinfo.com && www.nsksofttch.comDepartment of nskinfo-i education

CS2303-THEORY OF COMPUTATION

•Chapter:

Closure Properties of Regular Languages

1

2

Closure Properties

• A closure property is a statement that a certain operation on languages, when applied to languages in a class (e.g., the regular languages), produces a result that is also in that class.

• For regular languages, we can use any of its representations to prove a closure property.

Closure Property ….• Resultant languages obtained by performing

some operations on regular languages are also regular

• Union • Intersection• Complement • Difference • Kleene’s star • Concatenation • Reversal• Homomorphism• Inverse Homomorphism

Closure of Regular languages under boolean operations

• Or : Let L and M be languages over alphabet ∑. Then L ᴜ M is the language that contains all strings that are are in either or both of L and M.

• And: Let L and M be languages over alphabet ∑. Then L ∩ M is the language that contains all strings that are both in L and M.

• * : Let L be a language over alphabet ∑. Then L’, the complement of L, is the set of strings in ∑* that are not in L.

5

Closure Under Union

• If L and M are regular languages, so is L M.• Proof: Let L and M be the languages of regular

expressions R and S, respectively.• Then R+S is a regular expression whose

language is L M.

6

Closure Under Concatenation and Kleene Closure

• Same idea:– RS is a regular expression whose language is

LM.– R* is a regular expression whose language is

L*.

Closure under Complement Operator

• Represented by L’ or Lᶜ.• Denoted by L’ = ∑* - L• Introduce a new state called “Dead ” state and

transitions are added from the states to the dead state on left out input symbols

• Accepting states are made as non accepting and vice versa

Closure of regular languages under Intersection operator

• The intersection of two sets is the set of elements that are not in the complement of either set.

• Using Demorgans Law

L1 L2 = ( L’1 L’2)’

9

Closure of regular languages under Intersection ……

• If L and M are regular languages, then so is L M.

• Proof: Let A and B be DFA’s whose languages are L and M, respectively.

• Construct C, the product automaton of A and B.

• Make the final states of C be the pairs consisting of final states of both A and B.

10

Example: Product DFA for Intersection

A

C

B

D

0

1

0, 1

1

1

00

[A,C] [A,D]0

[B,C]

1

0

1

0

1

[B,D]

0

1

Closure under Difference Operator

• L-M is the difference of L and M, is the set of strings that are in language L but not in language M.

• L – M = L ∩ M’

• Property of the language and set theory

• Since regular languages are closed under complement and intersection operators it may be concluded that L1 – L2 is also regular

12

Closure under Difference …..

• Proof: Let A and B be DFA’s whose languages are L and M, respectively.

• Construct C, the product automaton of A and B.

• Make the final states of C be the pairs where A-state is final but B-state is not.

13

Example: Product DFA for Difference

A

C

B

D

0

1

0, 1

1

1

00

[A,C] [A,D]0

[B,C]

1

0

1

0

1

[B,D]

0

1

Notice: differenceis the empty language

Reversal of a language

• Reversal of a string w with symbols a1 a2….an is a string represented as WR with symbols ana n-1….a1

• For example if W =110110 then WR = 011011.

15

Closure under Reversal of a language

• Given language L, LR is the set of strings whose reversal is in L.

• Example: L = {0, 01, 100}; LR = {0, 10, 001}.

• Proof: Let E be a regular expression for L.• We show how to reverse E, to provide a

regular expression ER for LR.

16

Reversal of a Regular Expression• Basis: If E is a symbol a, ε, or ∅, then ER = E.• Induction: If E is

– F+G, then ER = FR + GR.– FG, then ER = GRFR – F*, then ER = (FR)*.

• Set of states in M2 are same as that of M1

• Initial state is a new state with transitions to all accepting states of M1

• Final state is only one state and that is the initial state of M1

• Reverse all transitions • (i.e.) (p, a) = q, are rewritten as (q, a) = p

Given the NFA in Fig to accept strings that end with 1, construct a NFA to accept language of strings that begin with 1.

A B

0,1

1 B

Fig 5.9

Using the steps given above

(i) A new initial state C is introduced with transitions to the final state B and state B is made as non final state.

(ii) Initial state A is made as final state.

• All the transitions are reversed

A

0,1

1 B A

C

Fig 5.10

Homomorphism

• Substitute a particular string for each symbol.• Denoted by h(L)• Ex: h(0) =ab h(1)=Є if the string w=0011 then• h(w)=h(0)h(0)h(1)h(1)• =abab• Theorem: If L is a regular language over

alphabet ∑ and h is a homomorphism on ∑, then h(L) is also regular language.

Inverse Homomorphism

• Let L be the language over alphabet T. Then h-1(L) is the set of string w in ∑ * such that h(w) is in L.

• h-1(L) = {w | h(w) is in L}.• Ex: r=(010)* h(0) =a h(1)=bb • h-1(L) =(abba)* Theorem: If h is a homomorphism from alphabet ∑

to alphabet T, and L is a regular language over T, then h-1(L) the inverse homomorphism of the language L is also a regular language.

Illustration

Consider two languages L1 and L2, where

L1 is the set of all strings that end with 01and

L2 is the set of all strings that end with 001 and construct

FAs to accept the languages L1 L2, L1 L2, L1’ and L1 - L2.

Fig 5.11 DFA recognizing the language L1 of strings that end with 01

A C 0

B

0

1

0 1

1

p q s 0 0

r 1

Fig 5.12 DFA accepting strings that end with 001

1 0

0

1

1

q0

q P r S

0

0 1

A C 0

B

0

1

0 b

a

1 b

a

1

0 1

1

0

1

Fig 5.13 NFA recognizing the language L1 L2

0

Fig 5.14 FA recognizing the language L’1

A C 0 B

0

1

1

1

B A

q

B

0 0 p r

B

s 1 b

a

Fig 5.15 FA accepting language L’2

1

0

0 1 1

Fig 5.16 FA accepting language (L’1 L’2)

A C 0 B

0

1

0 1

1

B A

q

B

0 0 p r

B s

1

1

0

0 1

q0

1

q0

B,Q

A,P

B,R

C,S

0

1

0

1 0

1

0 b

a 1

1

0

Fig 5.17 DFA accepting language (L’1 L’2)

q0

B,Q

A,P

B,R

C,S

0

1

0

0

1

0

1

1

0

Fig 5.18 DFA accepting language (L’1 L’2)’

1

Fig 5.19 NFA accepting language L’1 L2

A A 0 B B C

0

1

1 1

p q s 0 0 r

1

1 0

0

1

q0