Académique Documents
Professionnel Documents
Culture Documents
Any NFA can be converted to an equivalent NFA with a single final state
a a b
Example
NFA
a a b b P
Equivalent NFA
P
3
NFA
In General
Equivalent NFA
P P P
Courtesy Costas Busch - RPI
Extreme Case
NFA without final state
For regular languages we will prove that: Union: Concatenation: Star: Reversal: Complement: Intersection:
L1 and L2
L1 L2
L1L2 L1 *
R L1 Are regular Languages
L1
Courtesy Costas Busch - RPI
L1 L2
We say: Regular languages are closed under Union: Concatenation: Star: Reversal: Complement: Intersection:
L1 L2
L1L2 L1 *
R L1
L1
Courtesy Costas Busch - RPI
L1 L2
Regular language
L1
Regular language
L2
LM1
! L1
NFA
LM 2
! L2
NFA
M1
M2
Example
nu0
M1
a
b
L1 ! {a b}
M2 L2 ! _ a ba
b a
10
Union
NFA for
L1 L2 M1
P P
M2
11
Example
NFA for
L1 L2 ! {a b} {ba} L1 ! {a b}
a
b
P P
n
L2 ! {ba}
b
a
12
Concatenation
NFA for
L1L2 M1
P
M2
P
13
Example
NFA for
L1 ! {a b}
a b P
L2 ! {ba}
b a P
14
Star Operation
NFA for L1 *
M1
P
P
P L1 *
P
Courtesy Costas Busch - RPI 15
Example
NFA for
L1* ! {a b} *
P
w ! w1w2 . wk wi L1 n
L1 ! {a b}
a
P P
16
Reverse
NFA for
L1
M1
L1 d M1
1. Reverse all transitions 2. Make initial state final state and vice versa
Courtesy Costas Busch - RPI 17
Example
M1
a
L1 ! {a b}
a
R L1
d M1
b
! {ba }
18
Complement
L1
M1
L1
d M1
1. Take the DFA that accepts L1 2. Make final states non-final, and vice-versa
Courtesy Costas Busch - RPI 19
Example
M1
a
a, b
L1 ! {a b}
a, b
a L1 ! {a, b} * {a b}
n
a, b
d M1
b
Courtesy Costas Busch - RPI
a, b
20
Intersection
DeMorgans Law:
L1 L2 ! L1 L2
regular regular regular regular regular
21
L1 , L2 L1 , L2 L1 L2 L1 L2 L1 L2
Example
n
L1 L2 ! {ab}
regular
22
Regular Expressions
23
Regular Expressions
Regular expressions describe regular languages
Example:
(a b c) *
describes the language
Recursive Definition
Primitive regular expressions: Given regular expressions
, P, E
r1 and r2
r1 r2 r1 r2 r1 *
Are regular expressions
r1
Courtesy Costas Busch - RPI 25
Examples
A regular expression:
a b c * (c )
a b
26
Example
27
Definition
For primitive regular expressions:
L
! LP
! _Pa La
! _aa
Courtesy Costas Busch - RPI 28
Definition (continued)
For regular expressions r and r2 1
Lr1 r2
! Lr1
Lr2
Lr1 r2
! Lr1
Lr2
Lr1 *
! Lr1
* Lr1
! Lr1
Courtesy Costas Busch - RPI 29
Example
Regular expression:
a b a *
La b
a *
! La b
La *
! La b
La *
! La
Lb
La
* ! _aa _ a
_aa
* b ! _a, ba_P , a, aa, aaa,...a ! _a, aa, aaa,..., b, ba, baa,...a
Courtesy Costas Busch - RPI 30
Example
Regular expression
r ! a b * a bb
31
Example
Regular expression
r ! aa * bb * b
Lr ! {a b
2n 2m
b : n, m u 0}
32
Example
Regular expression
r ! (0 1) * 00 (0 1) *
33
Example
Regular expression
r ! (1 01) * (0 P )
34
r1 and r2 L(r1) ! L( r2 )
35
Example
37
Theorem
Languages Generated by Regular Expressions
Regular Languages
38
Theorem - Part 1
Languages Generated by Regular Expressions Regular Languages
Theorem - Part 2
Languages Generated by Regular Expressions Regular Languages
40
Proof - Part 1
41
Induction Basis
Primitive Regular Expressions: NFAs
, P, E
regular languages
L( M 3 ) ! {a} ! L(a )
Courtesy Costas Busch - RPI 42
Inductive Hypothesis
Assume for regular expressions r and r2 1 that L(r1 ) and L(r2 ) are regular languages
43
Inductive Step
We will prove:
Lr1 r2 Lr1 r2 Lr1 * Lr1
44
Lr1 r2
! Lr1
Lr2
Lr1 r2
! Lr1
Lr2
Lr1 *
! Lr1
* Lr1
! Lr1
Courtesy Costas Busch - RPI 45
We also know: Regular languages are closed under: Union Concatenation Star
Lr1 Lr2 Lr1 Lr2
Lr1
*
Courtesy Costas Busch - RPI 46
Therefore:
Lr1 r2
! Lr1
Lr2
Lr1 r2
! Lr1
Lr2
Lr1 *
! Lr1
*
Courtesy Costas Busch - RPI 47
And trivially:
48
Proof Part 2
49
L( M ) ! L
Example:
M
a
a, b
Courtesy Costas Busch - RPI
a
ab
51
Another Example:
b a q0 b q1 a, b
b q2
b a q0 b
Courtesy Costas Busch - RPI
q1 a b q2
52
b a
q0 b
q1 a b q2
bb * a q0 bb * ( a b)
b q2
53
bb * a q0
bb * ( a b)
q2
Removing states:
In General e g d qi
a
q
b
f
qj
ae * d
g ceced d **
ce * b
qi f aeb b ae * *
Courtesy Costas Busch - RPI
qj
55
r1 r3
r4
q0
r2
qf
L(r ) ! L( M ) ! L
Courtesy Costas Busch - RPI 56
Theorem
If L ! L ( A) for some DFA A Then there is a regular expression R such that
L ! L(R)
Proof: (by induction on the size of R) Let As states be {1, 2, , n} for some integer n Construct a collection of regular expressions that describe progressively broader sets of paths in DFA A
57
Let R be the regex that represent the set of strings w such that w is the label of a path from state i to j in A, and that path has no intermediate state whos label is greater than k. Note: beginning & end points, i.e. i & j are not intermediate so they can be greater than k
(k ) ij
58
Inductive Definition
Basis: k = 0 Since all states are >= 1, restriction on the paths is that the path must have no intermediate states at all. If i j An arc from i to j ( 0) Depending of the DFA A Rij may be , a or
( 0) ij
! a1 a2 . am
Inductive Definition
If i = j all loops from i to itself legal paths of length 0
(0) ij
! P a1 a2 . am
60
Inductive Definition
Induction: Suppose that there is a path from i to j that goes through no state with label higher than k. Consider two cases path does not go thru state k at all.
j
(k ) ij
!R
( k 1) ij
61
path goes thru state k at least once - More than once once
R R
( k 1) ik
(R
( k 1) ij
( k 1) * kk
R
( k 1) * kk
( k 1) kj
(k ) ij
!R
R
( k 1) ik
(R
) R
( k 1) kj
62