Lecture 05 - Properties of Regular Expression-2024-1 2
Lecture 05 - Properties of Regular Expression-2024-1 2
Regular languages are all those languages that finite automata accept.
In applications involving text, users may want to search for strings that satisfy certain
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}
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}
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}
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.
2/18/2024 6
Properties
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.
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.
2/16/2024 10
Example-1
Step 1: Create the transition Table
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
a b
z2=x2 or y1
→ z1 z2 z3
Upon reading letter b from z1 means it will be read from x1 and y2.
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
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
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