Date post: | 22-Dec-2015 |
Category: |
Documents |
View: | 220 times |
Download: | 3 times |
1
A Single Final Statefor Finite Accepters
2
ObservationAny Finite Accepter (NFA or DFA)
can be converted to an equivalent NFA
with a single final state
3
Example
a
b
b
aNFA
Equivalent NFA
a
b
b
a
4
In GeneralNFA
Equivalent NFA
Singlefinal state
5
Extreme Case
NFA without final state
Add a final state
6
Properties of Regular Languages
7
PropertiesTake any regular languages andWe will prove:
1L 2L
21 LL
21LL
*1L
Union:
Concatenation:
Star:Are regularLanguages
Complement:
Intersection: 21 LL
1L
8
We SayRegular Languages are closedclosed:
– Under union:
– Under concatenation:
– Under the star operation:
– Under complement:
– Under intersection:
21 LL
21LL
*1L
21 LL
1L
9
For regular languages and take NFAs and with
1M 2M
22
11
LML
LML
1M 2M
Single final state
1L 2L
10
Example
baL n1
baL 2
a
b
ab
1M
2M
11
UnionNFA for
1M
2M
21 LL
12
Example
a
b
ab
baL n1
baL 2
abbaLL n ,21 NFA for
13
ConcatenationNFA for 21LL
1M 2M
14
Example NFA for
a
b ab
baL n1 baL 2
bbaababaLL nn 21
15
Star OperationNFA for *1L
1M
16
ExampleNFA for *1* baL n
a
b
baL n1
17
ComplementFor the complement of regular language :
Take the DFA that accepts
Construct such that: – Each final state of is nonfinal in nonfinal final
We have:
LL
LM
M M M
LMLML
18
Example
a
b ba,
ba, baL n
a
b ba,
ba, baL n
19
IntersectionFor regular languages and : 1L 2L
21
2121
LL
LLLL
1Lregular
1L
regular
2L 2L
21 LL
regular
21 LL
21 LL regular
regular
20
ExampleRegular languages:
lkbaL 1 babL m2
bbLL m 21The language
0,, mlk
is regular
21
Regular Expressions
22
Regular ExpressionsRegular expressionsare another way of expressing regular languages
Example:
Stands for the language
*)( cba
,...,,,,,*, bcaabcaabcabca
23
Recursive DefinitionRegular Expressions:
• Primitive regular expressions:
• Given regular expressions and
,,
2r1r
11
21
21
*
r
r
rr
rr
Are regular expressions
24
ExamplesA regular expression
Not a regular expression
)(* ccba
ba
25
Languages of Regular Expressions : language of regular expression
Example
rL r
,...,,,,,*)( bcaabcaabcacbaL
26
Definition
For primitive regular expressions:
aaL
L
L
27
Definition (continued)For regular expressions and
1r 2r
11
11
2121
2121
**
rLrL
rLrL
rLrLrrL
rLrLrrL
28
ExampleRegular expression: *aba
*abaL
,...,,,...,,,
,...,,,,
*
*
*
*
baababaaaaaa
aaaaaaba
aba
aLbLaL
aLbaL
aLbaL
29
Example
Regular expression bbabar *
,...,,,,, bbbbaabbaabbarL
30
Example
Regular expression bbbaar **
0,:22 mnbbarL mn
31
Example
Regular expression *)10(00*)10( r
)(rL = { all strings with at least two consecutive 0 }
32
Example
Regular expression )0(*)011( r
)(rL = { all strings without two consecutive 0 }
33
Equivalent Regular Expressions
Definition:
Regular expressions and
are equivalent if
1r 2r
)()( 21 rLrL
34
Example L= { all strings with at least
two consecutive 0 }
)0(*)011(1 r
)0(*1)0(**)011*1(2 r
LrLrL )()( 211r 2rand
are equivalentregular expr.
35
Regular Expressionsand
Regular Languages
36
Theorem
The class of languages described by Regular expressionsis identical to the Regular languages
37
In Other Words
• For any regular expression the language is regular
• For any regular language there is a regular expression with
r
)(rL
L
r LrL )(
38
ProofFirst we prove:
• For any regular expression the language is regular
r)(rL
39
Induction BasisPrimitive Regular Expressions: ,,
NFAs
)()( 1 LML
)(}{)( 2 LML
)(}{)( 3 aLaML
regularlanguages
40
Inductive Hypothesis
Assume for regular expressions andthat and are regular languages
1r 2r
)( 1rL )( 2rL
41
Inductive StepWe will prove that:
1
1
21
21
*
rL
rL
rrL
rrL
Are regular Languages
42
By definition of regular expressions:
11
11
2121
2121
**
rLrL
rLrL
rLrLrrL
rLrLrrL
43
By inductive hypothesis and are regular languages
We know:
)( 1rL )( 2rL
Regular languagesare closed under union concatenation star operation
*1
21
21
rL
rLrL
rLrL
44
Therefore:
** 11
2121
2121
rLrL
rLrLrrL
rLrLrrL
Are regularlanguages
45
And trivially:
))(( 1rL is a regular language
46
Proof - Second PartNow we want to prove:
• For any regular language there is a regular expression with
L
r LrL )(
47
Since is regular take the NFA that accepts it
LM
LML )(
Single final state
48
From Construct the equivalentGeneralized Transition Graph
labels of transitions are regular expressions
M
Example:
a
ba,
cM
a
ba
c
49
Another Example:
ba a
b
b
0q 1q 2q
ba,a
b
b
0q 1q 2q
b
b
50
Reducing the states:
ba a
b
b
0q 1q 2q
b
0q 2q
babb*
)(* babb
51
Resulting Regular Expression:
0q 2q
babb*
)(* babb
*)(**)*( bbabbabbr
LMLrL )()(
52
In GeneralRemoving states:
iq q jqa b
cde
iq jq
dae* bce*dce*
bae*
53
Obtaining the final regular expression:
0q fq
1r
2r
3r4r
*)*(* 213421 rrrrrrr
LMLrL )()(