Fall 2004 COMP 335 7
1L 2L
21LLConcatenation:
*1LStar:
21 LL Union:
Are regularLanguages
For regular languages and we will prove that:
1L
21 LL
Complement:
Intersection:
RL1Reversal:
Fall 2004 COMP 335 8
We say: Regular languages are closed under
21LLConcatenation:
*1LStar:
21 LL Union:
1L
21 LL
Complement:
Intersection:
RL1Reversal:
Fall 2004 COMP 335 9
1LRegular language
11 LML
1M
Single final state
NFA 2M
2L
Single final state
22 LML
Regular language
NFA
Fall 2004 COMP 335 17
Reverse
RL1
1M
NFA for
1M
1. Reverse all transitions
2. Make initial state final state and vice versa
1L
Fall 2004 COMP 335 19
Complement
1. Take the DFA that accepts 1L
1M1L
1M1L
2. Make final states non-final, and vice-versa
Fall 2004 COMP 335 21
Intersection
DeMorgan’s Law: 2121 LLLL
21 , LL regular
21 , LL regular
21 LL regular
21 LL regular
21 LL regular
Fall 2004 COMP 335 24
Regular ExpressionsRegular expressions describe regular languages
Example:
describes the language
*)( cba
,...,,,,,, * bcaabcaabcabca
Fall 2004 COMP 335 25
Recursive Definition
,,
1
1
21
21
*
r
r
rr
rr
Are regular expressions
Primitive regular expressions:
2r1rGiven regular expressions and
Fall 2004 COMP 335 27
Languages of Regular Expressions : language of regular expression
Example:
rL r
,...,,,,,)( * bcaabcaabcacbaL
Fall 2004 COMP 335 29
Definition (continued)
For regular expressions and
1r 2r
2121 rLrLrrL
2121 rLrLrrL
*1*
1 rLrL
11 rLrL
Fall 2004 COMP 335 30
ExampleRegular expression: *aba
*abaL *aLbaL *aLbaL
*aLbLaL *aba
,...,,,, aaaaaaba
,...,,,...,,, baababaaaaaa
Fall 2004 COMP 335 33
Example
Regular expression** )10(00)10( r
)(rL = {all strings with at least two consecutive 0}
Fall 2004 COMP 335 34
Example
Regular expression )0()011( * r
)(rL = { all strings without two consecutive 0 }
Fall 2004 COMP 335 35
Equivalent Regular Expressions
Definition:
Regular expressions and
are equivalent if
1r 2r
)()( 21 rLrL
Fall 2004 COMP 335 36
Example L= { all strings without
two consecutive 0 }
)0()011( *1 r
)0(1)0()0111( ****2 r
LrLrL )()( 211r 2rand
are equivalentReg. expressions
Fall 2004 COMP 335 39
Theorem - Part 1
r)(rL
1. For any regular expression
the language is regular
LanguagesGenerated byRegular Expressions
RegularLanguages
Fall 2004 COMP 335 40
Theorem - Part 2
LanguagesGenerated byRegular Expressions
RegularLanguages
Lr LrL )(
2. For any regular language , there is
a regular expression with
Fall 2004 COMP 335 41
Proof - Part 1
r)(rL
1. For any regular expression
the language is regular
Proof by induction on the size of r
Fall 2004 COMP 335 42
Induction BasisPrimitive Regular Expressions: ,,
NFAs
)()( 1 LML
)(}{)( 2 LML
)(}{)( 3 aLaML
regularlanguages
a
Fall 2004 COMP 335 43
Inductive Hypothesis
Assume for regular expressions andthat and are regular
languages
1r 2r)( 1rL )( 2rL
Fall 2004 COMP 335 45
By definition of regular expressions:
11
*1
*1
2121
2121
rLrL
rLrL
rLrLrrL
rLrLrrL
Fall 2004 COMP 335 46
)( 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 2004 COMP 335 49
Proof – Part 2
Lr LrL )(
2. For any regular language there is
a regular expression with
Proof by construction of regular expression
Fall 2004 COMP 335 51
From , construct an equivalentGeneralized Transition Graph in which
transition labels are regular expressions
M
Example:
a
ba,
cM
a
ba
c
Fall 2004 COMP 335 54
Resulting Regular Expression:
0q 2q
babb*
)(* babb
*)(**)*( bbabbabbr
LMLrL )()(