Professional Documents
Culture Documents
Lecture 03
Lecture 03
Calculabilitate,
Complexitate
1
Properties of
Regular Languages
2
For regular languages L1 and L2
we will prove that:
Union: L1 L2
Concatenation: L1L2
Star: L1 * Are regular
Languages
Reversal: R
L1
Complement: L1
Intersection: L1 L2
3
We say: Regular languages are closed under
Union: L1 L2
Concatenation: L1L2
Star: L1 *
Reversal: R
L1
Complement: L1
Intersection: L1 L2
4
A useful transformation: use one accept state
NFA
a
b 2 accept states
a
b
Equivalent
a
NFA 1 accept state
a b
b
5
In General
NFA
Equivalent NFA
Single
accepting
state
6
Extreme case
7
Take two languages
LM1 L1 LM 2 L2
NFA M1 NFA M2
8
Example
M1
n0
a
n
L1 {a b} b
M2
a
L2 ba b
9
Union
NFA for L1 L2
M1
M2
10
Example
n
NFA for L1 L2 {a b} {ba}
n
L1 {a b}
a
b
L2 {ba}
b a
11
Concatenation
M1 M2
12
Example
n n
NFA for L1L2 {a b}{ba} {a bba}
n
L1 {a b}
a
L2 {ba}
b b a
13
Star Operation
NFA for L1 * w w1w2 wk
wi L1
M1
L1 *
14
Example
n
NFA for L1* {a b} *
n
L1 {a b}
a
b
15
Reverse
R
NFA for L1
L1 M1 M1
M1
a
n
L1 {a b} b
M1
a
R n
L1 {ba } b
17
Complement
L1 M1 L1 M1
M1
n a a, b
L1 {a, b} * {a b}
b a, b
19
Intersection
L1 regular
We show L1 L2
L2 regular regular
20
DeMorgan’s Law: L1 L2 L1 L2
L1 , L2 regular
L1 , L2 regular
L1 L2 regular
L1 L2 regular
L1 L2 regular
21
Example
n
L1 {a b} regular
L1 L2 {ab}
L2 {ab, ba} regular regular
22
Another Proof for Intersection Closure
Machine M1 Machine M2
DFA for L1 DFA for L2
qi , p j
State in M1 State in M2
24
DFA M1 DFA M2
q1 a q2 p1 a p2
transition transition
DFA M
q1, p1 a q2 , p2
New transition
25
DFA M1 DFA M2
q0 p0
initial state initial state
DFA M
q0 , p0
New initial state
26
DFA M1 DFA M2
qi pj pk
DFA M
qi , p j qi , pk
n0 m0
L1 {a b} n m
L2 {ab }
M1 M2
a b
q0 b q1 p0 a p1
a, b b a
q2 p2
a, b a, b
28
Automaton for intersection
n n
L {a b} {ab } {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
29
M simulates in parallel M1 and M 2
L( M ) L( M1 ) L( M 2 )
30
Regular Expressions
31
Regular Expressions
Regular expressions
describe regular languages
Example: (a b c) *
32
Recursive Definition
Primitive regular expressions: , ,
r1 r2
r1 r2
Are regular expressions
r1 *
r1
33
Examples
34
Languages of Regular Expressions
Example
L(a b c) * , a, bc, aa, abc, bca,...
35
Definition
L
L
La a
36
Definition (continued)
Lr1 Lr1
37
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,...
38
Example
Regular expression r a b * a bb
39
Example
Lr {a b
2n 2m
b : n, m 0}
40
Example
Regular expression r (0 1) * 00 (0 1) *
41
Example
42
Equivalent Regular Expressions
Definition:
43
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
regular expressions
44
Regular Expressions
and
Regular Languages
45
Theorem
Languages
Generated by
Regular Expressions
Regular
Languages
46
Proof:
Languages
Generated by Regular
Languages
Regular Expressions
Languages
Generated by Regular
Languages
Regular Expressions
47
Proof - Part 1
Languages
Generated by Regular
Languages
Regular Expressions
regular
L( M 2 ) {} L( )
languages
a
L( M 3 ) {a} L(a )
49
Inductive Hypothesis
Suppose
that for regular expressions r1 and r2 ,
L(r1 ) and L(r2 ) are regular languages
50
Inductive Step
We will prove:
Lr1 r2
Lr1 r2
Are regular
Languages
Lr1 *
Lr1
51
By definition of regular expressions:
Lr1 Lr1
52
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 *
53
Therefore:
Are regular
Lr1 r2 Lr1 Lr2
languages
Example: r r1 r2
L(M1 ) L(r1 )
L(M ) L(r )
L(M2 ) L(r2 )
55
Proof - Part 2
Languages
Generated by Regular
Languages
Regular Expressions
L( M ) L
Example: Corresponding
M Generalized transition graph
a c a c
a, b ab
58
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
59
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
60
Resulting Regular Expression:
bb * a b
q0 bb * (a b) q2
r (bb * a ) * bb * (a b)b *
L(r ) L( M ) L
61
In General
Removing a state: e
d c
qi q qj
a b
ae * d ce * b
ce * d
qi qj
ae * b
62
By repeating the process until
two states are left, the resulting graph is
Initial graph Resulting graph
r1 r4
r3
q0 qf
r2
The resulting regular expression:
r r1 * r2 (r4 r3r1 * r2 ) *
L(r ) L( M ) L
End of Proof-Part 2 63
Standard Representations
of Regular Languages
Regular Languages
DFAs
Regular
NFAs
Expressions
64
When we say: We are given
a Regular Language L
65