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

Chapter 2

This document discusses regular expressions and regular languages. It begins by defining regular expressions and how they are used to represent languages accepted by finite automata. It then provides examples of regular expressions and how to construct finite automata from regular expressions. The document also discusses properties of regular languages and sets. Finally, it covers the pumping lemma, which can be used to determine if a language is regular or not.

Uploaded by

Natanem Yimer
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Chapter 2

This document discusses regular expressions and regular languages. It begins by defining regular expressions and how they are used to represent languages accepted by finite automata. It then provides examples of regular expressions and how to construct finite automata from regular expressions. The document also discusses properties of regular languages and sets. Finally, it covers the pumping lemma, which can be used to determine if a language is regular or not.

Uploaded by

Natanem Yimer
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Chapter Two

Regular Expressions

Regular expressions and Regular grammars


RE to FA
Applications of RE
Pumping lemma and non-regular language
grammars.

Page 1
 Regular Expression
• Languages accepted by finite automata are easily described by simple expression is called Regular
Expression.
• Most effective way to represent any language.
• ε is a Regular Expression indicates the language containing an empty string.
(L (ε) = {ε})
• φ is a Regular Expression denoting an empty language. (L (φ) = { })
• x is a Regular Expression where L = {x}
• If X is a Regular Expression denoting the language L(X) and Y is a Regular Expression denoting
the language L(Y), then
– X + Y is a Regular Expression corresponding to the language
L(X) ∪ L(Y) where L(X+Y) = L(X) ∪ L(Y).
– X.Y is a Regular Expression corresponding to the language
L(X) . L(Y) where L(X.Y) = L(X) . L(Y)
– R* is a Regular Expression corresponding to the language L(R*)
where L(R*) = (L(R))* Page 2
 Application of RE
1. Effective representation of language
2. Text editor
3. Lexical Analyzer

Page 3
• Some RE Examples

Page 4

Page 5
Example 3.3: Construct the RE for language accepting all the stings
which are having any number of a’s is followed by any number b’s is
followed by any number of c’s over the input set ∑ = {a, b, c}
R = (any number of a) (any number of b) (any number of c)
R = a* b* c*
Example 3.4: write a RE to denote the language L over ∑ ={a, b}
such that all the strings do not contain the substring ab
L = {ε, a, b, bb, ba, baa, …..}
R = b* a*

Page 6
Quiz 5%
1. Languages accepted by finite automata are easily described by simple expression is
called_____________________________. 0.5 Mark
2. Write Regular Expression(RE) for all the strings containing any number of a’s and
b’s? 1 Mark
3. Construct the RE for language accepting all the stings which are ending with 00 over
the input set ∑ = {0, 1} ? 1 Mark
4. If L = {starting and ending with ‘a’ and having any combination of b’s in between }
what is RE? and draw its NDFA? 1 Mark
5. Write a RE to denote the language L over ∑ ={a, b} such that all the strings do not
contain the substring ab? 1.5
L =?
R =?

Answer.pptx Page 7
 Regular Sets

• Any set that represents the value of the Regular Expression is called
a Regular Set.
 Properties of Regular Sets

• Property 1. The union of two regular set is regular.

• Property 2. The intersection of two regular set is regular.

• Property 3. The complement of a regular set is regular.

• Property 4. The difference of two regular set is regular.

• Property 5. The reversal of a regular set is regular.

• Property 6. The closure of a regular set is regular.

• Property 7. The concatenation of two regular sets is regular. Page 8


 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)


Page 9
 Identities Related to Regular Expressions
• Given R, P, L, Q as regular expressions, the following identities hold −
• ∅* = ε
• ε* = ε
• RR* = R*R
• R*R* = R*
• (R*)* = R*
• RR* = R*R
• (PQ)*P =P(QP)*
• (a+b)* = (a*b*)* = (a*+b*)* = (a+b*)* = a*(ba*)*
• R + ∅ = ∅ + R = R (The identity for union)
• R ε = ε R = R (The identity for concatenation)
• ∅ L = L ∅ = ∅ (The annihilator for concatenation)
• R + R = R (Idempotent law)
• L (M + N) = LM + LN (Left distributive law)
• (M + N) L = ML + NL (Right distributive law)
• ε + RR* = ε + R*R = R* Page 10
 Constructing FA from RE
• We can use Thompson's Construction to find out a Finite Automaton from a
Regular Expression.
• We will reduce the regular expression into smallest regular expressions and converting
these to NFA and finally to DFA.
• Some basic FA expressions are the following −
• Case 1 − For a regular expression ‘a’, we can construct the following FA −

• Case 2 − For a regular expression ‘ab’, we can construct the following FA −

Page 11
• Case 3 − For a regular expression (a+b), we can construct the
following FA −

• Case 4 − For a regular expression (a+b)*, we can construct the


following FA −

Page 12
 Method to construct DFA from Null Transition in NDFA
• Step 1 Construct an NFA with Null moves from the given regular
expression.
• Step 2 Remove Null transition from the NFA and convert it into
its equivalent DFA.
Problem
• Convert the following RE into its equivalent DFA − 1 (0 + 1)* 0
Solution:- We will concatenate three expressions "1", "(0 + 1)*" and
"0“

• Now we will remove the ε transitions. After we remove


the ε transitions from the NDFA, we get the following −
Page 13
 Finite Automata with Null Moves (NFA-ε)
• A Finite Automaton with null moves (FA-ε) does transit not only
after giving input from the alphabet set but also without any input
symbol. This transition without input is called a null move.
• An NFA-ε is represented formally by a 5-tuple (Q, ∑, δ, q0, F),
consisting of
• Q − a finite set of states
• ∑ − a finite set of input symbols
• δ − a transition function δ : Q × (∑ ∪ {ε}) → 2Q
• q0 − an initial state q0 ∈ Q
• F − a set of final state/states of Q (F⊆Q).

• The above (FA-ε) accepts a string set − {0, 1, 01} Page 14


 Arden’s Method:

Page 15
Example: Construct RE from the given DFA

Page 16
Page 17
 Example : Construct the RE for the given DFA

Page 18
Page 19
Try Yourself

1. Construct the RE for the given DFA

2. Construct the RE for the given DFA

Page 20
Non Regular language

Regular language are the language can be represented by the


Regular expression but some languages can not represented using
regular expression, that language is called as non regular language.
• Non regular language can’t represented by finite automata.
• Theorem pumping lemma which is used to find out whether the
given string is accepted by regular expression or not. In short this
lemma tells whether the language is regular or not.

Page 21
Pumping Lemma
Theorem:
Let L be the regular set, then there is a constant n such that if z is any word in L,
and |z|>n, we may write z = uvw in such that |uv| ≤ n, |v| = 1 and for all i ≥ 0
uviw in L. furthermore n is should not grater than the number of states of DFA.

Suppose n states in DFA, Consider the inputs a1, a2, a3, …… am


m ≥ n are accepted by the DFA.
a1,….. ai, aj+1, …… am will be accepted by DFA

z = uviw i > 0
Page 22
 Applications of Pumping Lemma
• Pumping Lemma is to be applied to show that certain languages are not regular.
• It should never be used to show a language is regular.
• If L is regular, it satisfies Pumping Lemma.
• If L does not satisfy Pumping Lemma, it is non-regular.
• Method to prove that a language L is not regular
• At first, we have to assume that L is regular.
• So, the pumping lemma should hold for L.
• Use the pumping lemma to obtain a contradiction −
– Select w such that |w| ≥ c

– Select y such that |y| ≥ 1

– Select x such that |xy| ≤ c

– Assign the remaining string to z.

– Select k such that the resulting string is not in L.


Page 23
• Hence L is not regular.
 Problem
• Prove that L = {aibi | i ≥ 0} is not regular.
Solution −
• At first, we assume that L is regular and n is the number of states.
• Let w = anbn. Thus |w| = 2n ≥ n.
• By pumping lemma, let w = xyz, where |xy| ≤ n.
Let x = ap, y = aq, and z = arbn, where p + q + r = n, p ≠ 0, q ≠ 0, r ≠
0. Thus |y| ≠ 0.
• Let k = 2. Then xy2z = apa2qarbn.
• Number of as = (p + 2q + r) = (p + q + r) + q = n + q
• Hence, xy2z = an+q bn. Since q ≠ 0, xy2z is not of the form anbn.
• Thus, xy2z is not in L. Hence L is not regular.

Page 24
d !
En

You might also like