class5
class5
1
Regular Expressions
Regular expressions
describe regular languages
Example: (a b c) *
2
Recursive Definition
Primitive regular expressions: , ,
r1 r2
r1 r2
Are regular expressions
r1 *
r1
3
Examples
4
Languages of Regular Expressions
Example
L(a b c) * , a, bc, aa, abc, bca,...
5
Definition
L
L
La a
6
Definition (continued)
Lr1 Lr1
7
Example
a b a *
Regular expression:
9
Example
2n 2m
Lr {a b b : n, m 0}
10
Example
11
Example
12
Equivalent Regular Expressions
Definition:
13
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.
14
Regular Expressions
and
Regular Languages
15
Theorem
Languages
Generated by
Regular Expressions
Regular
Languages
16
We will show:
Languages
Generated by Regular
Languages
Regular Expressions
Languages
Generated by Regular
Languages
Regular Expressions
17
Proof - Part 1
Languages
Generated by Regular
Languages
Regular Expressions
L( M1 ) L( )
regular
L( M 2 ) {} L( )
languages
a
L( M 3 ) {a} L(a )
19
Inductive Hypothesis
Assume
for regular expressions r1 andr2
that
L(r1 ) and L(r2 ) are regular languages
20
Inductive Step
We will prove:
Lr1 r2
Lr1 r2
Are regular
Languages
Lr1 *
Lr1
21
By definition of regular expressions:
Lr1 Lr1
22
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 *
23
Therefore:
Are regular
Lr1 r2 Lr1 Lr2
languages
24
And trivially:
25
Proof - Part 2
Languages
Generated by Regular
Languages
Regular Expressions
L ( M ) L
Example:
M
a c a c
a, b a b
28
b b
Another Example:
a
q0 q1 a, b q2
b
b b
a
q0 q1 a b q2
b
29
b b
Reducing the states:
a
q0 q1 a b q2
b
bb * a b
q0 bb * (a b) q2
30
Resulting Regular Expression:
bb * a b
q0 bb * (a b) q2
r (bb * a ) * bb * (a b)b *
L ( r ) L ( M ) L
31
In General
Removing states: e
d c
qi q qj
a b
ae * d ce * b
ce * d
qi qj
ae * b
32
The final transition graph:
r1 r4
r3
q0 qf
r2
L ( r ) L ( M ) L
33
Standard Representations
of Regular Languages
Regular Languages
FAs
Regular
NFAs
Expressions
34
When we say: We are given
a Regular Language L
35
Elementary Questions
about
Regular Languages
36
Membership Question
Question: Given regular languageL
and string w
how can we check if w L ?
37
DFA
w
w L
DFA
w
w L
38
Question: Given regular languageL
how can we check
if Lis empty: ( L ) ?
L
DFA
L
40
Question: Given regular language L
how can we check
if Lis finite?
L is infinite
DFA
L is finite
42
Given regular languages L1 and
Question: L2
how can we check if L1 L2 ?
Answer: Find if ( L1 L2 ) ( L1 L2 )
43
( L1 L2 ) ( L1 L2 )
L1 L2 and L1 L2
L1 L2 L L2 L1 L1
2
L1 L2 L2 L1
L1 L2
44
( L1 L2 ) ( L1 L2 )
L1 L2 or L1 L2
L1 L2 L2 L1
L1 L2 L2 L1
L1 L2
45