0% found this document useful (0 votes)
8 views

regular expression

The document provides a comprehensive overview of regular expressions, including their formal definitions, identities, and closure properties. It includes examples of how to represent specific sets using regular expressions and discusses theorems related to regular expressions, such as Arden's theorem. Additionally, it covers properties of regular sets, such as union, intersection, and complement, along with proofs for each property.

Uploaded by

Arpit Srivastava
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

regular expression

The document provides a comprehensive overview of regular expressions, including their formal definitions, identities, and closure properties. It includes examples of how to represent specific sets using regular expressions and discusses theorems related to regular expressions, such as Arden's theorem. Additionally, it covers properties of regular sets, such as union, intersection, and complement, along with proofs for each property.

Uploaded by

Arpit Srivastava
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 87

CSE322

Regular Expressions and


their Identities
Lecture #6
Regular Expressions
We give a formal recursive definition of regular expressions over ∑
as follows:
1. Any terminal symbol (i.e. an element of ∑), Λ and ∅ are regular
expressions. When we view a in ∑ as a regular expression, we
denote it by a.
2. The union of two regular expressions R1and R2 , written as R 1 +
R2, is also a regular expression.
3. The concatenation of two regular expressions R1and R2, written as
R1 R2, is also a regular expression.
4. The iteration (or closure) of a regular expression R written as R*, is
also a regular expression.
5.If R is a regular expression, then (R) is also a regular expression.
6. The regular expressions over∑ are precisely those obtained
recursively by the application of the rules 1-5 once or several times
Definitions
Any set represented by a regular expression is
called a regular set.
If for example, a, b ε ∑. Then
(i) a denotes the set {a},

(ii) a + b denotes {a, b},

(iii) ab denotes {ab},

(iv) a* denotes the set {lambda, a, aa. aaa, ... } and

(v) (a + b)* denotes {a, b}*. The set represented by R is denoted by L(R),
Questions

Describe the following sets by regular expressions:


(a) {101}
(b) {abba}
(c) {01,10}
(d) {Λ ,ab}
(e) {abb,a, b, bba}
(f){Λ , 0, 00, 000.... }
(g) {1, 11, 111 ... }
Solution
(a) Now. {1}. {O} are represented by 1 and O. respectively. 101 is obtained
by concatenating 1,0 and 1 So. {10 I} is represented by 101.

(b) abba represents {abba}.

(c) As {01, 10} is the union of {01} and {10}, we have {01, 10}
represented by 01 + 10

(d) The set {Λ , ab} is represented by Λ + ab

(e) The set {abb, a, b, bba} is represented by abb + a + b + bba.

f) As {Λ , 0, 00, 000, ... } is simply {O}*. it is represented by 0*

(g) Any element in {1, 11, 111, ... } can be obtained by concatenating
1 and any element of {1}*. Hence 1(1)* represents {1, 11, 111, ... }
Problem
Solution
• Which of the following does not represents
the given language?
Language: {0,01}
a) 0+01
b) {0} U {01}
c) {0} U {0}{1}
d) {0} ^ {01}
IDENTITIES FOR REGULAR
EXPRESSIONS
THEORM

Theorem :
(Arden' s theorem) Let P and Q be two regular expressions
over ∑. If P does not contain Λ, then the following equation in
R, namely
R = Q + RP
has a unique solution (i.e. one and only one solution) given
by R = QP*.
PROBLEM
SOLUTION
• Which among the following looks similar to the given
expression?
((0+1). (0+1)) *
a) {xϵ {0,1} *|x is all binary number with even length}
b) {xϵ {0,1} |x is all binary number with even length}
c) {xϵ {0,1} *|x is all binary number with odd length}
d) {xϵ {0,1} |x is all binary number with odd length}
PROBLEM & SOLUTION
• Regular expressions are closed under
a) Union
b) Intersection
c) Kleen star
d) All of the mentioned
Difference between Null and Ø
TRANSITION SYSTEM CONTAINING Λ -MOVES

Suppose we want to replace a Λ -move from vertex V1 to vertex V2' Then


we proceed as follows:

Step 1- Find all the edges starting from V2.

Step 2- Duplicate all these edges starting from V1' without changing the edge
labels.

Step 3- If V1 is an initial state, make V2 also as initial state.

Step 4- If V2 is a final state. make V1 also as the final state.


EXAMPLE
EXAMPLE
• Concatenation of R with Ф outputs:
a) R
b) Ф
c) R.Ф
d) None of the mentioned
Remove all the epsilon transitions in the given diagram and compute the
number of a-transitions in the result?

a) 5
b) 7
c) 9
d) 6
• Which of the following does not belong to
input alphabet if S={a, b}* for any language?

a) a
b) b
c) e
d) none of the mentioned
• P, Q, R be regular expression over ∑, P is not ε,
then
R=Q + RP has a unique solution:
• a) Q*P
b) QP*
c) Q*P*
d) (P*O*) *
• The minimum number of transitions to pass to
reach the final state as per the following
regular expression is:
{a,b}*{baaa}

a) 4
b) 5
c) 6
d) 3
• Which of the following statements is not true?
a) Every language defined by any of the automata is also
defined by a regular expression
b) Every language defined by a regular expression can be
represented using a DFA
c) Every language defined by a regular expression can be
represented using NFA with e moves
d) Regular expression is just another representation for any
automata definition
Comparison Method
• A language is regular if and only if

a) accepted by DFA
b) accepted by PDA
c) accepted by LBA
d) accepted by Turing machine
Equivalence of Two Regular Expressions
• Which of the following does not represents
the given language?
Language: {0,01}

a) 0+01
b) {0} U {01}
c) {0} U {0}{1}
d) {0} ^ {01}
Closure properties of regular sets
• Property 1. The union of two regular set is regular.
• Proof −
• Let us take two regular expressions
• RE1 = a(aa)* and RE2 = (aa)*
• So, L1 = {a, aaa, aaaaa,.....} (Strings of odd length excluding Null)
• and L2 ={ ε, aa, aaaa, aaaaaa,.......} (Strings of even length including
Null)
• L1 ∪ L2 = { ε, a, aa, aaa, aaaa, aaaaa, aaaaaa,.......}
• (Strings of all possible lengths including Null)
• RE (L1 ∪ L2) = a* (which is a regular expression itself)
• Hence, proved.
Closure properties of regular sets
• Property 2. The intersection of two regular set is regular.
• Proof −
• Let us take two regular expressions
• RE1 = a(a*) and RE2 = (aa)*
• So, L1 = { a,aa, aaa, aaaa, ....} (Strings of all possible lengths excluding
Null)
• L2 = { ε, aa, aaaa, aaaaaa,.......} (Strings of even length including Null)
• L1 ∩ L2 = { aa, aaaa, aaaaaa,.......} (Strings of even length excluding
Null)
• RE (L1 ∩ L2) = aa(aa)* which is a regular expression itself.
• Hence, proved.
Closure properties of regular sets
• Property 3. The complement of a regular set is regular.
• Proof −
• Let us take a regular expression −
• RE = (aa)*
• So, L = {ε, aa, aaaa, aaaaaa, .......} (Strings of even length
including Null)
• Complement of L is all the strings that is not in L.
• So, L’ = {a, aaa, aaaaa, .....} (Strings of odd length excluding
Null)
• RE (L’) = a(aa)* which is a regular expression itself.
• Hence, proved.
Closure properties of regular sets
• Property 4. The difference of two regular set is regular.
• Proof −
• Let us take two regular expressions −
• RE1 = a (a*) and RE2 = (aa)*
• So, L1 = {a, aa, aaa, aaaa, ....} (Strings of all possible lengths
excluding Null)
• L2 = { ε, aa, aaaa, aaaaaa,.......} (Strings of even length including
Null)
• L1 – L2 = {a, aaa, aaaaa, aaaaaaa, ....}
• (Strings of all odd lengths excluding Null)
• RE (L1 – L2) = a (aa)* which is a regular expression.
Closure properties of regular sets
• Property 5. The reversal of a regular set is regular.
• Proof −
• We have to prove LR is also regular if L is a regular set.
• Let, L = {01, 10, 11, 10}
• RE (L) = 01 + 10 + 11 + 10
• LR = {10, 01, 11, 01}
• RE (LR) = 01 + 10 + 11 + 10 which is regular
• Hence, proved.
• Property 6. The closure of a regular set is regular.
• Proof −
• If L = {a, aaa, aaaaa, .......} (Strings of odd length excluding Null)
• i.e., RE (L) = a (aa)*
• L* = {a, aa, aaa, aaaa , aaaaa,……………} (Strings of all lengths excluding Null)
• RE (L*) = a (a)*
• Hence, proved.
Closure properties of regular sets
• Property 7. The concatenation of two regular sets is regular.
• Proof −
• Let RE1 = (0+1)*0 and RE2 = 01(0+1)*
• Here, L1 = {0, 00, 10, 000, 010, ......} (Set of strings ending in 0)
• and L2 = {01, 010,011,.....} (Set of strings beginning with 01)
• Then, L1 L2 =
{001,0010,0011,0001,00010,00011,1001,10010,.............}
• Set of strings containing 001 as a substring which can be
represented by an RE − (0 + 1)*001(0 + 1)*

You might also like