0% found this document useful (0 votes)
19 views36 pages

Lecture 05 - Properties of Regular Expression-2024-1 2

The document discusses properties of regular expressions and provides an example of using a finite automaton to represent the union of two regular languages. Specifically, it shows how to construct a new finite automaton (FA3) that accepts the union of the languages defined by regular expressions r1 and r2 by combining the transition tables of the FAs (FA1 and FA2) that accept r1 and r2 respectively. The example demonstrates this by taking the union of a language with "aa" and one ending in "b".

Uploaded by

najlaalotaibi18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views36 pages

Lecture 05 - Properties of Regular Expression-2024-1 2

The document discusses properties of regular expressions and provides an example of using a finite automaton to represent the union of two regular languages. Specifically, it shows how to construct a new finite automaton (FA3) that accepts the union of the languages defined by regular expressions r1 and r2 by combining the transition tables of the FAs (FA1 and FA2) that accept r1 and r2 respectively. The example demonstrates this by taking the union of a language with "aa" and one ending in "b".

Uploaded by

najlaalotaibi18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

Lecture 05 –Properties of Regular expression-1

(Dr. Nida Aslam)

 Union of Regular Languages


 Concatenation of Regular Languages
 Complement of Regular Languages
 Intersection of Regular Languages
2/15/2024
Regular Expression
 Regular Expression is the representor of the regular languages.

 Regular languages are all those languages that finite automata accept.

 Language is the collection of string

 It is a way of representing regular languages.

 Regular expressions have an important role in computer science applications.

 In applications involving text, users may want to search for strings that satisfy certain
patterns.

 Regular expressions provide a powerful method for describing such patterns.

2/16/2024 2
Properties of the regular expression
 1. Union:

 The union of two regular languages, L1 and L2, which are represented using L1 ∪ L2, is also
regular and which represents the set of strings that are either in L1 or L2 or both.

 IF L1 and L2 are two regular languages then their union L1 ∪ L2 is also a union.

𝐿1 𝑈 𝐿2 = 𝑆 𝑆 𝑖𝑠 𝑖𝑛 𝐿1 𝑜𝑟 𝑆 𝑖𝑠 𝑖𝑛 𝐿2}

 Example: L1 = (1+0).(1+0) = {00 , 10, 11, 01} and L2 = {∈ , 100}


then L1 ∪ L2 = {∈, 00, 10, 11, 01, 100}.

2/16/2024 3
Properties of the regular expression
 2. Concatenation:

 The concatenation of two regular languages, L1 and L2, which are represented using L1
∘ L2 is also regular and which represents the set of strings that are formed by taking
any string in L1 concatenating it with any string in L2.

𝐿1 ∘ 𝐿2 = 𝑆 𝑆 𝑖𝑠 𝑖𝑛 𝐿1 𝑓𝑜𝑙𝑙𝑜𝑤𝑒𝑑 𝑏𝑦 𝐿2}

Example: L1 = { 0,1 } and L2 = { 00, 11}


then 𝐿1 ∘ 𝐿2 = {000, 011, 100, 111}.

2/18/2024 4
Properties of the regular expression
 3. Intersection:

 If L1 and L2 are two regular languages then their intersection is also an intersection.

𝐿1 ∩ 𝐿2 = 𝑆 𝑆 𝑖𝑠 𝑖𝑛 𝐿1 𝑎𝑛𝑑 𝐿2}

Example: L1 = { 0,1, 00, 10 } and L2 = { 00, 11}


then𝐿1 ∩ 𝐿2= {00}.

2/18/2024 5
Properties of the regular expression
 4. Complement:

 If L1 is a regular languages then L1’ contains all the other words in the language
except the words in the language L1.

Example: L1 = { 0,1, 00, 10 }


then𝐿1′= it contains all the possible words except the words in language L1.

2/18/2024 6
Properties

1. Union of Regular Languages

2. Concatenation of Regular Languages

3. Intersection of Regular Languages

4. Complement of Regular Languages

2/18/2024 7
Union of Regular Languages
 Union of Regular Expression

 Rule:

 If there is an FA called FA1 that accepts the language defined by the regular expression r1

 And there is an FA called FA2 that accepts the language defined by the regular expressions r2,

 Then there is an FA called FA3 that accepts the language defined by the regular expression (rl + r2).

 We are going to prove this by showing how to construct the new machine in the most
reasonable way.

2/16/2024 8
Example-1
 Consider two Finite Automate FA1 and FA1 perform the union operation.

FA1 as language having aa somewhere. FA2 as language ending over b.

2/18/2024 9
Example-1
 The language the new machine accepts will be the union of these two languages.

 We shall call the states in this new machine z1, z2 , z3 , and so on, for as many as we
need.

 We shall define this machine by its transition table.

2/16/2024 10
Example-1
Step 1: Create the transition Table

FA1 as language having aa somewhere. FA2 as language ending over b.

a b
a b
→ x1 x2 x2
→ y1 y1 y2
x2 x3 x1
*y2 y1 y2
*x3 x3 X3

2/18/2024 11
Example 1
 Let us define z1, z1 =x1 or y1. z1 will be the initial state.

z1=x1 or y1
4v L

a b
→ z1 guy 2 Yuya 3

In z1 , both x1 and y2 is the


initial state therefore z1 is
also an initial state
2/18/2024 12
Example 1: z1=x1 or y1
Upon reading letter a from z1 means it will be read from x2 and y1.
→z1=x1 or y1
z2=x2 or y1
*z3=x1 or y2

a b
z2=x2 or y1
→ z1 z2 z3

Upon reading letter b from z1 means it will be read from x1 and y2.

In z3 y2 is the final state


therefore z3 is also a final
z3=x1 or y2 state
2/18/2024 13
Example 1: Z2=x2 or y1 →z1=x1 or y1
Upon reading letter a from z2 means it will be read from x3 and y2.
z2=x2 or y1
*z3=x1 or y2
*z4=x3 or y1

z4=x3 or y1
a b
Upon reading letter b from z2 means it will be read from x1 and y2.
→ z1 z2 z2
z2 z4 z3

z3=x1 or y2
2/18/2024 14
Example 1: Z3=x1 or y2
Upon reading letter a from z3 means it will be read from x2 and y1.
→z1=x1 or y1
z2=x2 or y1
*z3=x1 or y2
*z4=x3 or y1
Z2=x2 or y1
a b
Upon reading letter b from z3 means it will be read from x1 and y2.
→ z1 z2 z2
z2 z4 z3
*z3 z2 z3

Z3=x1 or y2
2/18/2024 15
Example 1: Z4=x3 or y1
Upon reading letter a from z4 means it will be read from x3 and y1.
→z1=x1 or y1
z2=x2 or y1
*z3=x1 or y2
*z4=x3 or y1

z4=x3 or y1 *z5=x3 or y2

Upon reading letter b from z4 means it will be read from x3 and y2.
a b
→ z1 z2 z2
z2 z4 z3
*z3 z2 z3
*z4 z4 z5

z5=x3 or y2
2/18/2024 16
Example 1: Z4=x3 or y2
Upon reading letter a from z5 means it will be read from x3 and y1.
→z1=x1 or y1
z2=x2 or y1
*z3=x1 or y2
*z4=x3 or y1

z4=x3 or y1 *z5=x3 or y2

Upon reading letter b from z5 means it will be read from x3 and y2.
a b
→ z1 z2 z2
z2 z4 z3
*z3 z2 z3
*z4 z4 z5
*z5 z4 z5
z5=x3 or y2
2/18/2024 17
Example 1: Final Answer

a b
→ z1 z2 z2
z2 z4 z3
*z3 z2 z3
*z4 z4 z5
*z5 z4 z5

18
Example 2

 Suppose we have the machine FA1, which accepts


 Second machine FA2 , which accepts all
the language of all words over the alphabet {a,b} words that have both an even number
such that they contain aa somewhere. of total a's and an even number of
total b's (this is the language EVEN-
EVEN).

2/18/2024 19
Example 2

→*z1=x1 or y1

a b
→* z1

a b
→ x1 x2 x1 a b
In z1 , both x1 and y2 is the
x2 x3 x1 → * y1 y3 y2 initial state therefore z1 is
also an initial state and
*x3 x3 x3 y2 y4 y1
also y1 is the final state
y3 y1 y4 therefore z1 is initial and
final state
y4 y2 y3
Z1=x1 or y1
2/18/2024 20
Example 2: z1=x1 or y1
a
→*z1=x1 or y1 a b
→* z1 guys
z2 x.us
z 3
z2=x2 or y3
z3=x1 or y2
Z2=x2 or y3

Z3=x1 or y2

2/18/2024 21
Example: z2 (x2 or y3)
a a b
→* z1=x1 or y1
→ *z1 z2 z3
z2=x2 or y3 z2 aug
z4 aug
z5
z3=x1 or y2
*z4=x3 or y1
Z4=x3 or y1
z5=x1 or y4

Z5=x1 or y4
2/18/2024 22
Example 2: z3 (x1 or y2)
a
→* z1=x1 or y1 a b
z2=x2 or y3 →* z1 z2 z3
z2 z4 z5
z3=x1 or y2
z3 augu
z x.ua
z
6 1
*z4=x3 or y1
Z6=x3 or y1
z5=x1 or y4
z6=x2 or y4
b

Z1=x1 or y1
2/18/2024 23
Example 2: z4 (x3 or y1)
a a b
→* z1=x1 or y1
→ *z1 z2 z3
z2=x2 or y3 z2 z4 z5
z3=x1 or y2 z3 z6 z1
*z4 z7 z8
*z4=x3 or y1

Z7=x3 or y3 z5=x1 or y4
z6=x2 or y4
b *z7=x3 or y3
*z8=x3 or y2

Z8=x3 or y2
2/18/2024 24
Example: z5 (x1 or y4)
a
→* z1=x1 or y1 a b

z2=x2 or y3 → *z1 z2 z3
z2 z4 z5
z3=x1 or y2
z3 z6 z1
*z4=x3 or y1 *z4 z7 z8
Z9=x2 or y2
z5=x1 or y4 z5 z9 z10
z6=x2 or y4
b *z7=x3 or y3
*z8=x3 or y2
z9=x2 or y2
z10=x1 or y3

Z10=x1 or y3
2/18/2024 25
Example: z6 (x2 or y4)
a →* z1=x1 or y1
z2=x2 or y3 a b
z3=x1 or y2 →* z1 z2 z3
z2 z4 z5
*z4=x3 or y1
z3 z6 z1
Z8=x3 or y2 z5=x1 or y4
*z4 z7 z8
z6=x2 or y4 z5 z9 z10
*z7=x3 or y3 z6 z8 z10
b
*z8=x3 or y2
z9=x2 or y2
z10=x1 or y3

Z10=x1 or y3
2/18/2024 26
Example: z7 (x3 or y3)
a
→* z1=x1 or y1 a b
z2=x2 or y3 → *z1 z2 z3
z3=x1 or y2 z2 z4 z5
z3 z6 z1
*z4=x3 or y1
z4 z7 z8
Z4=x3 or y1 z5=x1 or y4 z5 z9 z10
z6=x2 or y4 z6 z8 z10
b *z7=x3 or y3 z7 z4 z11

*z8=x3 or y2
z9=x2 or y2
z10=x1 or y3
*z11=x3 or y4
Z11=x3 or y4
2/18/2024 27
Example: z8 (x3 or y2)
a →* z1=x1 or y1
a b
z2=x2 or y3
→ *z1 z2 z3
z3=x1 or y2 z2 z4 z5
*z4=x3 or y1 z3 z6 z1
* z4 z7 z8
Z11=x3 or y4 z5=x1 or y4
z5 z9 z10
z6=x2 or y4
z6 z8 z10
*z7=x3 or y3 * z7 z4 z11
b
*z8=x3 or y2 *z8 z11 z4

z9=x2 or y2
z10=x1 or y3
*z11=x3 or y4
Z4=x3 or y1
2/18/2024 28
Example: z9 (x2 or y2)
a
→* z1=x1 or y1
z2=x2 or y3
a b
z3=x1 or y2
→ *z1 z2 z3
*z4=x3 or y1
z2 z4 z5
Z11=x3 or y4 z5=x1 or y4 z3 z6 z1
z6=x2 or y4 * z4 z7 z8
z5 z9 z10
b *z7=x3 or y3
z6 z8 z10
*z8=x3 or y2
*z7 z4 z11
z9=x2 or y2 *z8 z11 z4
z10=x1 or y3 z9 z11 z1

Z1=x1 or y1 *z11=x3 or y4

2/18/2024 29
Example: z10 (x1 or y3)
a →* z1=x1 or y1
z2=x2 or y3 a b
→*
z3=x1 or y2 z2 z3
z1
*z4=x3 or y1 z2 z4 z5
z5=x1 or y4 z3 z6 z1
Z12=x2 or y1
*z4 z7 z8
z6=x2 or y4
z5 z9 z10
*z7=x3 or y3
b z6 z8 z10
*z8=x3 or y2 *z7 z4 z11
z9=x2 or y2 *z8 z11 z4
z9 z11 z1
z10=x1 or y3
z10 z12 z5
*z11=x3 or y4
Z5=x1 or y4
*z12=x2 or y1
2/18/2024 30
Example: z11 (x3 or y4)
a →* z1=x1 or y1
z2=x2 or y3 a b
→* z1 z2 z3
z3=x1 or y2
z2 z4 z5
*z4=x3 or y1
z3 z6 z1
z5=x1 or y4 *z4 z7 z8
Z8=x3 or y2
z6=x2 or y4 z5 z9 z10
z6 z8 z10
*z7=x3 or y3
b * z7 z4 z11
*z8=x3 or y2
*z8 z11 z4
z9=x2 or y2 z9 z11 z1
z10=x1 or y3 z10 z12 z5
*z11 z8 z7
*z11=x3 or y4
Z7=x3 or y3 *z12=x2 or y1
2/18/2024 31
Example: z12 (x2 or y1)
a →* z1=x1 or y1
a b
z2=x2 or y3
→* z1 z2 z3
z3=x1 or y2 z2 z4 z5
*z4=x3 or y1 z3 z6 z1
z5=x1 or y4 *z4 z7 z8
Z7=x3 or y3
z6=x2 or y4 z5 z9 z10
z6 z8 z10
*z7=x3 or y3
*z7 z4 z11
b
*z8=x3 or y2 *z8 z11 z4
z9=x2 or y2 z9 z11 z1

z10=x1 or y3 z10 z12 z5


*z11 z8 z7
*z11=x3 or y4
*z12 z7 z3
Z3=x1 or y2 *z12=x2 or y1
2/18/2024 32
Example 2: Final Answer
→* z1=x1 or y1
Create the Finite Automata z2=x2 or y3 a b
→* z1 z2 z3
z3=x1 or y2
z2 z4 z5
*z4=x3 or y1 z3 z6 z1
z5=x1 or y4 *z4 z7 z8
z6=x2 or y4 z5 z9 z10
z6 z8 z10
*z7=x3 or y3
a *z7 z4 z11
*z8=x3 or y2 *z8 z11 z4
z9=x2 or y2 z9 z11 z1
z10=x1 or y3 z10 z12 z5
*z11 z8 z7
*z11=x3 or y4
*z12 z7 z3
*z12=x2 or y1
2/18/2024 33
Example 3 Solve
 Given two FAs. First is FA of all the words ending over a and second is odd length words. Last
figure is expected output.
FA1U FA2

FA1

FA2

34
a b
2 22 23 X
by 2092 Vy
22 X2U ya Zy X2 Vy 2 Vy
23 X
v92 24 aug 2 X Uy

Zy X2Vy 22 23 X U
aug 92

a
2
a b 22

b b a a

a
23 a
24
b
End of Lecture - 05
Any questions?

2/15/2024 35

You might also like