Class 5
Class 5
1
Regular Expressions
Regular expressions
describe regular languages
Example: (a + b ⋅ c) *
2
Recursive Definition
Primitive regular expressions: ∅, λ , α
r1 + r2
r1 ⋅ r2
Are regular expressions
r1 *
( r1 )
3
Examples
4
Languages of Regular Expressions
Example
L( (a + b ⋅ c) *) = { λ , a, bc, aa, abc, bca,...}
5
Definition
L( ∅ ) = ∅
L( λ ) = { λ }
L( a ) = { a}
6
Definition (continued)
L( r1 + r2 ) = L( r1 ) ∪ L( r2 )
L( r1 ⋅ r2 ) = L( r1 ) L( r2 )
L( r1 *) = ( L( r1 ) ) *
L( ( r1 ) ) = L( r1 )
7
Example
Regular expression: ( a + b ) ⋅ a *
L( ( a + b ) ⋅ a *) = L( ( a + b ) ) L( a *)
= L( a + b ) L( a *)
= ( L( a ) ∪ L( b ) ) ( L( a ) ) *
= ( { a} ∪ { b} ) ( { a} ) *
= { a, b} { λ , a, aa, aaa,...}
= { a, aa, aaa,..., b, ba, baa,...}
8
Example
Regular expression r = ( a + b ) * ( a + bb )
9
Example
Regular expression r = ( aa ) * ( bb ) * b
L( r ) = {a b
2n 2m
b : n, m ≥ 0}
10
Example
Regular expression r = (0 + 1) * 00 (0 + 1) *
11
Example
12
Equivalent Regular Expressions
Definition:
13
Example
L = { all strings without
two consecutive 0 }
r1 = (1 + 01) * (0 + λ )
r2 = (1* 011*) * (0 + λ ) + 1* (0 + λ )
r1 and r2
L(r1 ) = L(r2 ) = L
are equivalent
regular expr.
14
Regular Expressions
and
Regular Languages
15
Theorem
Languages
Generated by
Regular Expressions
= Regular
Languages
16
We will show:
Languages
Generated by ⊆ Regular
Languages
Regular Expressions
Languages
Generated by ⊇ Regular
Languages
Regular Expressions
17
Proof - Part 1
Languages
Generated by ⊆ Regular
Languages
Regular Expressions
L( M1 ) = ∅ = L(∅)
regular
L( M 2 ) = {λ} = L(λ )
languages
a
L( M 3 ) = {a} = L(a )
19
Inductive Hypothesis
Assume
for regular expressions r1 and r2
that
L(r1 ) and L(r2 ) are regular languages
20
Inductive Step
We will prove:
L( r1 + r2 )
L( r1 ⋅ r2 )
Are regular
Languages
L( r1 *)
L( ( r1 ) )
21
By definition of regular expressions:
L( r1 + r2 ) = L( r1 ) ∪ L( r2 )
L( r1 ⋅ r2 ) = L( r1 ) L( r2 )
L( r1 *) = ( L( r1 ) ) *
L( ( r1 ) ) = L( r1 )
22
By inductive hypothesis we know:
L(r1 ) and L(r2 ) are regular languages
We also know:
Regular languages are closed under:
Union L( r1 ) ∪ L( r2 )
Concatenation L( r1 ) L( r2 )
Star ( L( r1 ) ) *
23
Therefore:
L( r1 + r2 ) = L( r1 ) ∪ L( r2 )
Are regular
L( r1 ⋅ r2 ) = L( r1 ) L( r2 )
languages
L( r1 *) = ( L( r1 ) ) *
24
And trivially:
25
Proof - Part 2
Languages
Generated by ⊇ Regular
Languages
Regular Expressions
Regular Languages
FAs
Regular
NFAs
Expressions
27
When we say: We are given
a Regular Language L
28
Elementary Questions
about
Regular Languages
29
Membership Question
Question: Given regular language L
and string w
how can we check if w ∈ L?
30
DFA
w
w∈ L
DFA
w
w∉ L
31
Question: Given regular language L
how can we check
if L is empty: ( L = ∅) ?
L≠∅
DFA
L=∅
33
Question: Given regular language L
how can we check
if L is finite?
L is infinite
DFA
L is finite
35
Question: Given regular languages L1 and L2
how can we check if L1 = L2 ?
Answer: Find if ( L1 ∩ L2 ) ∪ ( L1 ∩ L2 ) = ∅
36
( L1 ∩ L2 ) ∪ ( L1 ∩ L2 ) = ∅
L1 ∩ L2 = ∅ and L1 ∩ L2 = ∅
L1 L2 L L2 L1 L1
2
L1 ⊆ L2 L2 ⊆ L1
L1 = L2
37
( L1 ∩ L2 ) ∪ ( L1 ∩ L2 ) ≠ ∅
L1 ∩ L2 ≠ ∅ or L1 ∩ L2 ≠ ∅
L1 L2 L2 L1
L1 ⊄ L2 L2 ⊄ L1
L1 ≠ L2
38