Professional Documents
Culture Documents
Chapter 3 - RE
Chapter 3 - RE
(Theory of Computation)
Chapter 3: Regular Expressions
1
Chapter 3 Regular Expressions
• We have studied that a regular language can be described by dfa
and nfa. In this chapter we look at another way of representing
regular languages.
3.1 Regular Expressions
• Formal Definition of a Regular Expression
Definition 3.1
Let Σ be a given alphabet. Then
1. ,
ε and a Σ are all regular expressions. These are called primitive
regular expressons.
2. If r1 and r2 are regular expressions, so are r1 r2 , r1 r2 , r1* and (r1 ).
3. A string is a regular expression if and only if it can derived from
the primitive regular expressions by a finite number of applications
of the rules in (2).
Example 3.1 For {a, b, c}, the string (a b c)
(c ) is a regular
expression, but (a b ) is not a regular expression.
• Language Associated with Regular Expressions
Definition 3.2
The language L(r) denoted by any regular expression r is defined
by the following rules.
1. is a reguar expression denoting the empty set,
2. ελ is a regular expression denoting {ε}
{λ}, Termination
3. for every a Σ , a is a regular expression denoting {a}. condition
If r1 and r2 are regular expressions, then
4. L(r1 r2 ) L(r1 ) L(r2 ),
5. L(r1 r2 ) L(r1 )L(r2 ), Reduce L(r ) to simpler components.
6. L((r1 )) L(r1 ),
7. L(r1* ) ( L(r1 ))* .
Example 3.2 Exhibit the language L(a* ・ (a+b)) in set notation.
Solution L(a * (a b)) L(a * ) L(a b) ( L(a ))* ( L(a ) L(b))
{ελ, a, aa, aaa,...}{a, b} {a, aa, aaa,..., b, ab, aab,...}
Example 3.3
For Σ {a,b}, the expression r (a b)*(a bb)
is regular. It denotes the language
L(r ) L((a b)* ) L(a bb) ( L(a b))* L(a bb)
( L(a ) L(b))* ( L(a ) ( L(b) L(b))) {a, b}*{a, bb}
{ε , a, b, ab, ba,...} {a, bb, aa, abb, ba, bbb,...}
Example 3.4
What is the language described by the regular expression: r=(aa)*(bb)*b ?
Example 3.5
For {0,1}, give a regular expression r such that
L(r) {w Σ * : w has at least one pair of consequtive zeros}
Example 3.6
Find a regular expression for the language
L {w {0,1} : w has no pair of consevutive zeros}.
Solution: r (1 01) (0 ε )
*
3.2 Connection Between Regular Expressions and
Regular Languages
• Given regular expression r, we have defined a language L(r ).
• A language is said to be regular, if it is accepted by a dfa (or by
an nfa since dfa and nfa are equivalent).
What is the relation between regular expressions and regular language?
Regular languages Regular expressions
r = a* + (a*ba*ba*ba*)*
Algorithm for the conversion of Regular Expression to ɛ-NFA
•For a, NFA is
•For a + b, NFA is
Example 3.9
Draw NFA for a + b + ab: