Professional Documents
Culture Documents
Lecture 03
2nd Semester 2019-2020
• Regular Expressions
• Properties of Regular Languages
1. Regular Expressions
Regular Expressions
Regular expressions
describe regular languages
(a b c) *
Example:
a, bc* , a, bc, aa, abc, bca,...
describes the language
theory of computation 1
2/17/2020
Recursive Definition
Primitive regular expressions: , ,
r1 r2
r1 r2
Are regular expressions
r1 *
r1
4 2nd 2019-2020 Computation
Examples
A regular expression: a b c * (c )
Example
theory of computation 2
2/17/2020
Definition
For primitive regular expressions:
L
L
La a
7 2nd 2019-2020 Computation
Definition (continued)
For regular expressions r1 and r2
Lr1 Lr1
8 2nd 2019-2020 Computation
Example a b a *
Regular expression:
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,...
9 2nd 2019-2020 Computation
theory of computation 3
2/17/2020
Example
Regular expression r a b * a bb
Example
Example
Regular expression r (0 1) * 00 (0 1) *
theory of computation 4
2/17/2020
Example
Definition:
Regular expressions r1 and r2
are equivalent if
L(r1) L(r2 )
Example
L = { all strings without substring 00 }
r1 (1 01) * (0 )
r2 (1* 011*) * (0 ) 1* (0 )
r1 and r2
L(r1) L(r2 ) L
are equivalent
15
regular expressions
2nd 2019-2020 Computation
theory of computation 5
2/17/2020
Regular Expressions
and
Regular Languages
Theorem
Languages
Generated by
Regular Expressions
Regular
Languages
Proof:
Languages
Generated by Regular
Languages
Regular Expressions
Languages
Generated by Regular
Languages
Regular Expressions
18 2nd 2019-2020 Computation
theory of computation 6
2/17/2020
Proof - Part 1
Languages
Generated by Regular
Languages
Regular Expressions
Induction Basis
, ,
Corresponding Primitive Regular Expressions:
NFAs
L( M1 ) L()
regular
L( M 2 ) {} L( )
languages
a
L( M 3 ) {a} L(a)
20 2nd 2019-2020 Computation
Inductive Hypothesis
Suppose
that for regular expressions r1 andr2 ,
L(r1) and L(r2 ) are regular languages
theory of computation 7
2/17/2020
Inductive Step
Lr1 r2 We will prove:
Lr1 r2
Are regular
Languages
Lr1 *
22
Lr1
2nd 2019-2020 Computation
Lr1 * Lr1 *
Lr1 Lr1
23 2nd 2019-2020 Computation
We also know:
Regular languages are closed under:
Union Lr1 Lr2
Concatenation Lr1 Lr2
Star Lr1 *
24 2nd 2019-2020 Computation
theory of computation 8
2/17/2020
Therefore:
Are regular
Lr1 r2 Lr1 Lr2
languages
Lr1 * Lr1 *
Example: r r1 r2
L(M1 ) L(r1 )
L(M ) L(r )
L(M2 ) L(r2 )
Proof - Part 2
Languages
Generated by Regular
Languages
Regular Expressions
theory of computation 9
2/17/2020
L( M ) L
Example: Corresponding
M Generalized transition graph
a c a c
a, b ab
29 2nd 2019-2020 Computation
b b
Another Example:
a
q0 q1 a, b q2
b
Transition labels b b
are regular a
expressions q0 q1 a b q2
b
30 2nd 2019-2020 Computation
theory of computation 10
2/17/2020
b b
Reducing the states:
a
q0 q1 a b q2
b
Transition labels
are regular bb * a b
expressions
q0 bb * (a b) q2
31 2nd 2019-2020 Computation
bb * a b
q0 bb * (a b) q2
r (bb * a ) * bb * (a b ) b *
L( r ) L( M ) L
32 2nd 2019-2020 Computation
In Generale
Removing a state: d c
qi q qj
a b
ae * d ce * b
ce * d
qi qj
33
ae * b
2nd 2019-2020 Computation
theory of computation 11
2/17/2020
Standard Representations
of Regular Languages
Regular Languages
DFAs
Regular
NFAs
Expressions
Properties of
Regular Languages
theory of computation 12
2/17/2020
Union: L1 L2
Concatenation: L1L2
Star: Are regular
L1 *
Languages
Reversal: L1R
Complement: L1
37
Intersection: L1 L2 2nd 2019-2020 Computation
Union: L1 L2
Concatenation: L1L2
Star: L1 *
Reversal: L1R
Complement: L1
Intersection: L1 L2
38 2nd 2019-2020 Computation
NFA
a
b 2 accept states
a
b
Equivalent
a
NFA 1 accept state
a b
b
39 2nd 2019-2020 Computation
theory of computation 13
2/17/2020
In General
NFA
Equivalent NFA
Single
accepting
state
40 2nd 2019-2020 Computation
Extreme case
LM1 L1 LM 2 L2
NFA M1 NFA M2
theory of computation 14
2/17/2020
Example
M1
n0
a
L1 {a nb} b
M2
L2 ba b a
L1 L2 Union
M1 NFA for
M2
Example
n
NFA for L1 L2 {a b} {ba}
L1 {a nb}
a
b
L2 {ba}
b a
45 2nd 2019-2020 Computation
theory of computation 15
2/17/2020
Concatenation
L1L2
NFA for
M1 M2
Example
L1 {a nb}
a
L2 {ba}
b b a
Star Operation L1 *
w w1w2 wk NFA for
wi L1 M1
L1 *
48 2nd 2019-2020 Computation
theory of computation 16
2/17/2020
Example
L1 {a nb}
a
b
49
2nd 2019-2020 Computation
Reverse
NFA for L1R
L1 M1 M1
Example
M1
a
L1 {a nb} b
M1
a
L1R n
{ba } b
theory of computation 17
2/17/2020
Complement
L1 M1 L1 M1
Example
M1
a a, b
n b a, b
L1 {a b}
M1
a, b
L1 {a, b} * {a nb} a
b a, b
53 2nd 2019-2020 Computation
Intersection
L1 regular
We show L1 L2
L2 regular regular
theory of computation 18
2/17/2020
DeMorgan’s Law: L1 L2 L1 L2
L1 , L2 regular
L1 , L2 regular
L1 L2 regular
L1 L2 regular
L1 L2 regular
55 2nd 2019-2020 Computation
Example
L1 {a nb} regular
L1 L2 {ab}
L2 {ab, ba} regular regular
Machine M1 Machine M2
DFA for L1 DFA for L2
theory of computation 19
2/17/2020
States in M
qi , p j
State in M1 State in M2
DFA M1 DFA M2
q1 a q2 p1 a p2
transition transition
DFA M
q1, p1 a q2 , p2
New transition
59 2nd 2019-2020 Computation
DFA M1 DFA M2
q0 p0
initial state initial state
DFA M
q0 , p0
New initial state
60 2nd 2019-2020 Computation
theory of computation 20
2/17/2020
DFA M1 DFA M2
qi pj pk
DFA M
qi , p j qi , pk
Example:
M1 M2
a b
q0 b q1 p0 a p1
a, b b a
q2 p2
a, b a, b
62 2nd 2019-2020 Computation
L {a n b } {ab m } {ab }
a, b
q0 , p0 a q0 , p1 b q1, p1 a q2 , p2
b a b a
q1, p2 b q0 , p2 q2 , p1
a b
a, b
63 2nd 2019-2020 Computation
theory of computation 21
2/17/2020
M1 accepts string w
and M 2 accepts string w
L ( M ) L ( M1 ) L ( M 2 )
64 2nd 2019-2020 Computation
Non-regular languages
(Pumping Lemma)
theory of computation 22
2/17/2020
{a nb n : n 0}
Non-regular languages
{vv R : v {a, b}*}
Regular languages
a *b b*c a
b c ( a b) *
etc...
67 2nd 2019-2020 Computation
theory of computation 23