Post on 19-Dec-2015
transcript
Fall 2006 Costas Busch - RPI 1
Regular Expressions
Fall 2006 Costas Busch - RPI 2
Regular ExpressionsRegular expressions describe regular languages
Example:
describes the language
*)( cba
,...,,,,,*, bcaabcaabcabca
Fall 2006 Costas Busch - RPI 3
Recursive Definition
,,
1
1
21
21
*
r
r
rr
rr
Are regular expressions
Primitive regular expressions:
2r1rGiven regular expressions and
Fall 2006 Costas Busch - RPI 4
Examples
)(* ccbaA regular expression:
baNot a regular expression:
Fall 2006 Costas Busch - RPI 5
Languages of Regular Expressions : language of regular expression
Example
rL r
,...,,,,,*)( bcaabcaabcacbaL
Fall 2006 Costas Busch - RPI 6
Definition
For primitive regular expressions:
aaL
L
L
Fall 2006 Costas Busch - RPI 7
Definition (continued)
For regular expressions and
1r 2r
2121 rLrLrrL
2121 rLrLrrL
** 11 rLrL
11 rLrL
Fall 2006 Costas Busch - RPI 8
ExampleRegular expression: *aba
*abaL *aLbaL *aLbaL *aLbLaL
*aba ,...,,,, aaaaaaba
,...,,,...,,, baababaaaaaa
Fall 2006 Costas Busch - RPI 9
Example
Regular expression bbabar *
,...,,,,, bbbbaabbaabbarL
Fall 2006 Costas Busch - RPI 10
Example
Regular expression bbbaar **
}0,:{ 22 mnbbarL mn
Fall 2006 Costas Busch - RPI 11
Example
Regular expression *)10(00*)10( r
)(rL = { all strings containing substring 00 }
Fall 2006 Costas Busch - RPI 12
Example
Regular expression )0(*)011( r
)(rL = { all strings without substring 00 }
Fall 2006 Costas Busch - RPI 13
Equivalent Regular Expressions
Definition:
Regular expressions and
are equivalent if
1r 2r
)()( 21 rLrL
Fall 2006 Costas Busch - RPI 14
Example L= { all strings without substring 00 }
)0(*)011(1 r
)0(*1)0(**)011*1(2 r
LrLrL )()( 211r 2rand
are equivalentregular expressions
Fall 2006 Costas Busch - RPI 15
Regular Expressionsand
Regular Languages
Fall 2006 Costas Busch - RPI 16
Theorem
LanguagesGenerated byRegular Expressions
RegularLanguages
Fall 2006 Costas Busch - RPI 17
LanguagesGenerated byRegular Expressions
RegularLanguages
LanguagesGenerated byRegular Expressions
RegularLanguages
Proof:
Fall 2006 Costas Busch - RPI 18
Proof - Part 1
r)(rL
For any regular expression
the language is regular
LanguagesGenerated byRegular Expressions
RegularLanguages
Proof by induction on the size of r
Fall 2006 Costas Busch - RPI 19
Induction BasisPrimitive Regular Expressions: ,,Corresponding NFAs
)()( 1 LML
)(}{)( 2 LML
)(}{)( 3 aLaML
regularlanguages
a
Fall 2006 Costas Busch - RPI 20
Inductive Hypothesis Suppose that for regular expressions and , and are regular languages
1r 2r)( 1rL )( 2rL
Fall 2006 Costas Busch - RPI 21
Inductive StepWe will prove:
1
1
21
21
*
rL
rL
rrL
rrL
Are regular Languages
Fall 2006 Costas Busch - RPI 22
By definition of regular expressions:
11
11
2121
2121
**
rLrL
rLrL
rLrLrrL
rLrLrrL
Fall 2006 Costas Busch - RPI 23
)( 1rL )( 2rLBy inductive hypothesis we know: and are regular languages
Regular languages are closed under:
*1
21
21
rL
rLrL
rLrL Union
Concatenation
Star
We also know:
Fall 2006 Costas Busch - RPI 24
Therefore:
** 11
2121
2121
rLrL
rLrLrrL
rLrLrrL
Are regularlanguages
)())(( 11 rLrL is trivially a regular language(by induction hypothesis)
End of Proof-Part 1
Fall 2006 Costas Busch - RPI 25
Using the regular closure of these operations,we can construct recursively the NFA that accepts
M)()( rLML
Example: 21 rrr )()( 11 rLML
)()( 22 rLML
)()( rLML
Fall 2006 Costas Busch - RPI 26
For any regular language there is a regular expression with
Proof - Part 2
LanguagesGenerated byRegular Expressions
RegularLanguages
Lr LrL )(
We will convert an NFA that accepts to a regular expression
L
Fall 2006 Costas Busch - RPI 27
Since is regular, there is aNFA that accepts it
LM
LML )(
Take it with a single final state
Fall 2006 Costas Busch - RPI 28
From construct the equivalentGeneralized Transition Graphin which transition labels are regular
expressions
M
Example:
a
ba,
cM
a
ba
c
CorrespondingGeneralized transition graph
Fall 2006 Costas Busch - RPI 29
Another Example:
ba a
b
b
0q 1q 2q
ba,a
b
b
0q 1q 2q
b
bTransition labels are regular expressions
Fall 2006 Costas Busch - RPI 30
Reducing the states:
ba a
b
b
0q 1q 2q
b
0q 2q
babb*
)(* babb
Transition labels are regular expressions
Fall 2006 Costas Busch - RPI 31
Resulting Regular Expression:
0q 2q
babb*
)(* babb
*)(**)*( bbabbabbr
LMLrL )()(
Fall 2006 Costas Busch - RPI 32
In GeneralRemoving a state:
iq q jqa b
cde
iq jq
dae* bce*dce*
bae*
Fall 2006 Costas Busch - RPI 33
0q fq
1r
2r
3r4r
*)*(* 213421 rrrrrrr LMLrL )()(
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
Fall 2006 Costas Busch - RPI 34
Standard Representations of Regular Languages
Regular Languages
DFAs
NFAsRegularExpressions
Fall 2006 Costas Busch - RPI 35
When we say: We are given a Regular Language
We mean:
L
Language is in a standard representation
L
(DFA, NFA, or Regular Expression)