Regular Expressions
Regular Expressions
Regular Expressions
Regular Expressions
Regular expressions
describe regular languages
Example:
(a b c) *
describes the language
Recursive Definition
Primitive regular expressions:
Given regular expressions
r1
, ,
and
r2
r1 r2
r1 r2
r1 *
r1
Examples
A regular expression:
a b c * (c )
a b
L r
Example
Definition
For primitive regular expressions:
L
L
L a a
Definition (continued)
For regular expressions r1 and r2
L r1 r2 L r1 L r2
L r1 r2 L r1 L r2
L r1 * L r1 *
L r1 L r1
Example
Regular expression: a b a *
L a b a * L a b L a *
L a b L a *
L a L b L a *
a b a *
a, b , a, aa, aaa,...
a, aa, aaa,..., b, ba, baa,...
Example
Regular expression
r a b * a bb
Example
Regular expression
L r {a b
r aa * bb * b
2n 2m
b : n, m 0}
Example
Regular expression
r (0 1) * 00 (0 1) *
Example
Regular expression
r (1 01) * (0 )
r1
and
r2
L(r1 ) L(r2 )
Example
r1 (1 01) * (0 )
r2 (1* 011*) * (0 ) 1* (0 )
L(r1 ) L(r2 ) L
r1
and r2
are equivalent
regular expressions
Regular Expressions
and
Regular Languages
Theorem
Languages
Generated by
Regular Expressions
Regular
Languages
Proof:
Languages
Generated by
Regular Expressions
Regular
Languages
Languages
Generated by
Regular Expressions
Regular
Languages
Proof - Part 1
Languages
Generated by
Regular Expressions
Regular
Languages
Induction Basis
Primitive Regular Expressions:
Corresponding
NFAs
, ,
L( M1 ) L()
L( M 2 ) {} L( )
a
L( M 3 ) {a} L(a )
regular
languages
Inductive Hypothesis
Suppose
that for regular expressions r1 and r2 ,
L(r1 ) and L(r2 ) are regular languages
Inductive Step
We will prove:
L r1 r2
L r1 r2
L r1 *
L r1
Are regular
Languages
L r1 r2 L r1 L r2
L r1 r2 L r1 L r2
L r1 * L r1 *
L r1 L r1
We also know:
Regular languages are closed under:
Union
Concatenation
Star
L r1 L r2
L r1 L r2
L r1 *
Therefore:
L r1 r2 L r1 L r2
L r1 r2 L r1 L r2
Are regular
languages
L r1 * L r1 *
L((r1 )) L(r1 )
L(M1 ) L(r1 )
L(M2 ) L(r2 )
L(M ) L(r )
Proof - Part 2
Languages
Generated by
Regular Expressions
Regular
Languages
L( M ) L
Example:
Corresponding
Generalized transition graph
M
a
c
a, b
c
ab
Another Example:
q0
q1 a, b
q2
Transition labels
are regular
expressions
q0
a
b
q1 a b q2
q0
q1 a b q2
Transition labels
are regular
expressions
bb * a
q0
b
bb * (a b)
q2
bb * a
q0
b
bb * (a b)
q2
r (bb * a ) * bb * (a b)b *
L(r ) L( M ) L
In General
e
Removing a state:
d
qi
c
qj
q
a
ae * d
ce * b
ce * d
qi
ae * b
qj
Resulting graph
r1
q0
r3
r2
r4
qf
r r1 * r2 (r4 r3r1 * r2 ) *
L(r ) L( M ) L
End of Proof-Part 2
Standard Representations
of Regular Languages
Regular Languages
DFAs
NFAs
Regular
Expressions
When we say:
We mean:
We are given
a Regular Language
Language L is in a standard
representation