Sie sind auf Seite 1von 56

1

Properties of
Regular Languages

2
1
L
2
L
2 1
L L
Concatenation:
*
1
L
Star:
2 1
L L Union:
Are regular
Languages
For regular languages and
we will prove that:
1
L
2 1
L L
Complement:
Intersection:
R
L
1
Reversal:
3
We say: Regular languages are closed under
2 1
L L
Concatenation:
*
1
L
Star:
2 1
L L Union:
1
L
2 1
L L
Complement:
Intersection:
R
L
1
Reversal:
4
a
b
b
a
NFA
Equivalent
NFA


a
b
b
a
A useful transformation: use one accept state
2 accept states
1 accept state
5
NFA
Equivalent NFA
Single
accepting
state

In General
6


NFA without accepting state
Add an accepting state
without transitions
Extreme case
7
1
L Regular language
( )
1 1
L M L =
1
M
Single accepting state
NFA
2
M
2
L
Single accepting state
( )
2 2
L M L =
Regular language
NFA
Take two languages
8
} {
1
b a L
n
=
a
b
1
M
{ } ba L =
2
a
b
2
M
0 > n
Example
9
Union
NFA for
1
M
2
M
2 1
L L

10

a
b
a
b

} {
1
b a L
n
=
} {
2
ba L =
} { } {
2 1
ba b a L L
n
=
NFA for
Example
11
Concatenation

NFA for
2 1
L L
1
M
2
M

12

NFA for
a
b
a
b
} {
1
b a L
n
=
} {
2
ba L =
} { } }{ {
2 1
bba a ba b a L L
n n
= =

Example
13
Star Operation
NFA for
*
1
L
1
M

*
1
L e


1
2 1
L w
w w w w
i
k
e
=
14

NFA for * } { *
1
b a L
n
=
a
b
} {
1
b a L
n
=

Example
15
Reverse
R
L
1
1
M
NFA for
'
1
M
1. Reverse all transitions
2. Make initial state accepting state
and vice versa
1
L
16
} {
1
b a L
n
=
a
b
1
M
} {
1
n R
ba L =
a
b
'
1
M
Example
17
Complement
1. Take the DFA that accepts
1
L
1
M
1
L
'
1
M
1
L
2. Make accepting states non-final,
and vice-versa
18
} {
1
b a L
n
=
a
b
1
M
b a,
b a,
} { * } , {
1
b a b a L
n
=
a
b
'
1
M
b a,
b a,
Example
19
Intersection
1
L
regular
2
L
regular
We show
2 1
L L
regular
20
DeMorgans Law:
2 1 2 1
L L L L =
2 1
, L L
regular
2 1
, L L
regular
2 1
L L
regular
2 1
L L
regular
2 1
L L
regular
21
Example
} {
1
b a L
n
=
} , {
2
ba ab L =
regular
regular
} {
2 1
ab L L =
regular
22
Regular Expressions

23
Regular Expressions
Regular expressions
describe regular languages


Example:

describes the language


* ) ( c b a +
{ } { } ,... , , , , , * , bca abc aa bc a bc a =
24
Recursive Definition
( )
1
1
2 1
2 1
*
r
r
r r
r r

+
Are regular expressions
2
r
1
r
Given regular expressions and
25
Examples
( ) ) ( * C + + c c b a
A regular expression:
( ) + +b a
Not a regular expression:
26
Languages of Regular Expressions

: language of regular expression


Example



( ) r L r
( ) { } ,... , , , , , * ) ( bca abc aa bc a c b a L = +
27
Definition

For primitive regular expressions:
( )
( ) { }
( ) { } a a L
L
L
=
=
C = C

28
Definition (continued)

For regular expressions and


1
r
2
r
( ) ( ) ( )
2 1 2 1
r L r L r r L = +
( ) ( ) ( )
2 1 2 1
r L r L r r L =
( ) ( ) ( )* *
1 1
r L r L =
( ) ( ) ( )
1 1
r L r L =
29
Example
Regular expression:
( ) * a b a +
( ) ( ) * a b a L + ( ) ( ) ( ) * a L b a L + =
( ) ( ) * a L b a L + =
( ) ( ) ( ) ( ) ( )* a L b L a L =
{ } { } ( ) { } ( )* a b a =
{ }{ } ,... , , , , aaa aa a b a =
{ } ,... , , ,..., , , baa ba b aaa aa a =
30
Example

Regular expression

( ) ( ) bb a b a r + + = *
( ) { } ,... , , , , , bbb ba abb aa bb a r L =
31
Example

Regular expression ( ) ( ) b bb aa r * * =
( ) } 0 , : {
2 2
> = m n b b a r L
m n
32
Example

Regular expression * ) 1 0 ( 00 * ) 1 0 ( + + = r
) (r L
= { all strings containing substring 00 }
33
Example

Regular expression
) 0 ( * ) 01 1 ( + + = r
) (r L
= { all strings without substring 00 }
34
Equivalent Regular Expressions

Definition:

Regular expressions and

are equivalent if
1
r
2
r
) ( ) (
2 1
r L r L =
35
Example

L = { all strings without substring 00 }
) 0 ( * ) 01 1 (
1
+ + = r
) 0 ( * 1 ) 0 ( * *) 011 * 1 (
2
+ + + = r
L r L r L = = ) ( ) (
2 1
1
r
2
r and
are equivalent
regular expressions
36
Regular Expressions
and
Regular Languages

37
Theorem
Languages
Generated by
Regular Expressions
Regular
Languages
=
38
Languages
Generated by
Regular Expressions
Regular
Languages
_
Languages
Generated by
Regular Expressions
Regular
Languages
_
Proof:
39
Proof - Part 1
r
) (r L
For any regular expression
the language is regular
Languages
Generated by
Regular Expressions
Regular
Languages
_
Proof by induction on the size of
r
40
Induction Basis
Primitive Regular Expressions: o , , C
Corresponding
NFAs
) ( ) (
1
C = C = L M L
) ( } { ) (
2
L M L = =
) ( } { ) (
3
a L a M L = =
regular
languages
a
41
Inductive Hypothesis

Suppose
that for regular expressions and ,
and are regular languages


1
r
2
r
) (
1
r L ) (
2
r L
42
Inductive Step
We will prove:

( )
( )
( )
( ) ( )
1
1
2 1
2 1
*
r L
r L
r r L
r r L

+
Are regular
Languages
43
By definition of regular expressions:

( ) ( ) ( )
( ) ( ) ( )
( ) ( ) ( )
( ) ( ) ( )
1 1
1 1
2 1 2 1
2 1 2 1
* *
r L r L
r L r L
r L r L r r L
r L r L r r L
=
=
=
= +
44
) (
1
r L ) (
2
r L
By inductive hypothesis we know:
and are regular languages

Regular languages are closed under:
( ) ( )
( ) ( )
( ) ( )*
1
2 1
2 1
r L
r L r L
r L r L Union
Concatenation
Star
We also know:
45
Therefore:
( ) ( ) ( )
( ) ( ) ( )
( ) ( ) ( )* *
1 1
2 1 2 1
2 1 2 1
r L r L
r L r L r r L
r L r L r r L
=
=
= +
Are regular
languages
) ( )) ((
1 1
r L r L =
is trivially a regular language
(by induction hypothesis)
End of Proof-Part 1
46
Using the regular closure of these operations,
we can construct recursively the NFA
that accepts
M
) ( ) ( r L M L =
Example:
2 1
r r r + =
) ( ) (
1 1
r L M L =
) ( ) (
2 2
r L M L =
) ( ) ( r L M L =

47
For any regular language there is
a regular expression with
Proof - Part 2
Languages
Generated by
Regular Expressions
Regular
Languages
_
L
r
L r L = ) (
We will convert an NFA that accepts
to a regular expression
L
48
Since is regular, there is a
NFA that accepts it

L
M
L M L = ) (
Take it with a single final state
49
From construct the equivalent
Generalized Transition Graph
in which transition labels are regular expressions
M
Example:
a
b a,
c
M
a
b a +
c
Corresponding
Generalized transition graph
50
Another Example:
b a +
a
b
b
0
q
1
q
2
q
b a,
a
b
b
0
q
1
q
2
q
b
b
Transition labels
are regular
expressions
51
Reducing the states:
b a +
a
b
b
0
q
1
q
2
q
b
0
q
2
q
b
a bb*
) ( * b a bb +
Transition labels
are regular
expressions
52
Resulting Regular Expression:

0
q
2
q
b
a bb*
) ( * b a bb +
* ) ( * * ) * ( b b a bb a bb r + =
L M L r L = = ) ( ) (
53
In General
Removing a state:
i
q
q
j
q
a
b
c
d
e
i
q
j
q
d ae* b ce*
d ce*
b ae*
54
0
q
f
q
1
r
2
r
3
r
4
r
* ) * ( *
2 1 3 4 2 1
r r r r r r r + =
L M L r L = = ) ( ) (
The resulting regular expression:
By repeating the process until
two states are left, the resulting graph is
Initial graph Resulting graph
End of Proof-Part 2
55
Standard Representations
of Regular Languages
Regular Languages
DFAs
NFAs
Regular
Expressions
56
When we say:
We are given
a Regular Language
We mean:
L
Language is in a standard
representation
L
(DFA, NFA, or Regular Expression)

Das könnte Ihnen auch gefallen