Professional Documents
Culture Documents
Regular Expressions
Regular Expressions
Regular Languages
1
For regular languages L1 and L2
we will prove that:
Union: L1 L2
Concatenation: L1L2
Star: L1 * Are regular
Languages
R
Reversal: L1
Complement: L1
Intersection: L1 L2
2
We say: Regular languages are closed under
Union: L1 L2
Concatenation: L1L2
Star: L1 *
R
Reversal: L1
Complement: L1
Intersection: L1 L2
3
Regular language L1 Regular language L2
LM1 L1 LM 2 L2
NFA M1 NFA M2
M2
b a
L2 ba
5
Union
NFA for L1 L2
M1
M2
6
Example
n
NFA for L1 L2 {a b} {ba}
n
L1 {a b}
a
b
L2 {ba}
b a
7
Concatenation
M1 M2
8
Example
n n
NFA for L1L2 {a b}{ba} {a bba}
n
L1 {a b}
a L2 {ba}
b b a
9
Star Operation
NFA for L1 *
L1 *
M1
10
Example
n w w1w2 wk
NFA for L1* {a b} * wi L1
n
L1 {a b}
a
b
11
Reverse
R
NFA for L1
L1 M1 M1
M1
a
R n
L1 {ba } b
13
Complement
L1 M1 L1 M1
M1
n a a, b
L1 {a, b} * {a b}
b a, b
15
Intersection
DeMorgan’s Law: L1 L2 L1 L2
L1 , L2 regular
L1 , L2 regular
L1 L2 regular
L1 L2 regular
L1 L2 regular
16
Example
n
L1 {a b} regular
L1 L2 {ab}
L2 {ab, ba} regular regular
17
Regular Expressions
18
Regular Expressions
Regular expressions
describe regular languages
Example: (a b c) *
19
Recursive Definition
Primitive regular expressions: , ,
r1 r2
r1 r2
Are regular expressions
r1 *
r1
20
Examples
21
Languages of Regular Expressions
Example
L(a b c) * , a, bc, aa, abc, bca,...
22
Definition
L
L
La a
23
Definition (continued)
Lr1 Lr1
24
Example
Regular expression: a b a *
La b a * La b La *
La b La *
La Lb La *
a b a*
a, b , a, aa, aaa,...
a, aa, aaa,..., b, ba, baa,...
25
Example
Regular expression r a b * a bb
26
Example
2n 2m
Lr {a b b : n, m 0}
27
Example
Regular expression r (0 1) * 00 (0 1) *
28
Example
29
Equivalent Regular Expressions
Definition:
30
Example
L = { all strings without
two consecutive 0 }
r1 (1 01) * (0 )
r2 (1* 011*) * (0 ) 1* (0 )
r1 and r2
L(r1 ) L(r2 ) L
are equivalent
regular expr.
31
Regular Expressions
and
Regular Languages
32
Theorem
Languages
Generated by
Regular Expressions
Regular
Languages
33
Theorem - Part 1
Languages
Generated by Regular
Languages
Regular Expressions
34
Theorem - Part 2
Languages
Generated by Regular
Languages
Regular Expressions
35
Proof - Part 1
36
Induction Basis
Primitive Regular Expressions: , ,
NFAs
L( M1 ) L()
regular
L( M 2 ) {} L( )
languages
a
L( M 3 ) {a} L(a )
37
Inductive Hypothesis
Assume
for regular expressions r1 and r2
that
L(r1 ) and L(r2 ) are regular languages
38
Inductive Step
We will prove:
Lr1 r2
Lr1 r2
Are regular
Languages
Lr1 *
Lr1
39
By definition of regular expressions:
Lr1 Lr1
40
By inductive hypothesis we know:
L(r1 ) and L(r2 ) are regular languages
We also know:
Regular languages are closed under:
Union Lr1 Lr2
Concatenation Lr1 Lr2
Star Lr1 *
41
Therefore:
Are regular
Lr1 r2 Lr1 Lr2
languages
42
And trivially:
43
Proof – Part 2
44
Since L is regular take the
NFA M that accepts it
L( M ) L
Example:
M
a c a c
a, b ab
46
b b
Another Example:
a
q0 q1 a, b q2
b
b b
a
q0 q1 a b q2
b
47
b b
Reducing the states:
a
q0 q1 a b q2
b
bb * a b
q0 bb * (a b) q2
48
Resulting Regular Expression:
bb * a b
q0 bb * (a b) q2
r (bb * a ) * bb * (a b)b *
L(r ) L( M ) L
49
In General
Removing states: e
d c
qi q qj
a b
ae * d ce * b
ce * d
qi qj
ae * b
50
The final transition graph:
r1 r4
r3
q0 qf
r2
r r1 * r2 (r4 r3r1 * r2 ) *
L(r ) L( M ) L
51