0% found this document useful (0 votes)
5 views

class5

The document provides an overview of regular expressions and their relationship with regular languages, including definitions, examples, and properties. It explains how to construct regular expressions from languages and vice versa, as well as how to determine membership, emptiness, and finiteness of regular languages. The document also discusses equivalent regular expressions and presents various proofs related to the closure properties of regular languages.

Uploaded by

houndclegane860
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

class5

The document provides an overview of regular expressions and their relationship with regular languages, including definitions, examples, and properties. It explains how to construct regular expressions from languages and vice versa, as well as how to determine membership, emptiness, and finiteness of regular languages. The document also discusses equivalent regular expressions and presents various proofs related to the closure properties of regular languages.

Uploaded by

houndclegane860
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 45

Regular Expressions

1
Regular Expressions
Regular expressions
describe regular languages

Example: (a  b c) *

describes the language


a, bc*  , a, bc, aa, abc, bca,...

2
Recursive Definition
Primitive regular expressions: ,  , 

Given regular expressions r1 andr2

r1  r2
r1 r2
Are regular expressions
r1 *
r1 
3
Examples

A regular expression: a  b c * (c   )

Not a regular expression: a  b 

4
Languages of Regular Expressions

Lr  : language of regular expression


r

Example
L(a  b c) *  , a, bc, aa, abc, bca,...

5
Definition

For primitive regular expressions:

L  

L   

La  a
6
Definition (continued)

For regular expressionsr1 r2


and

Lr1  r2  Lr1  Lr2 

Lr1 r2  Lr1  Lr2 

Lr1 * Lr1 *

Lr1  Lr1 
7
Example
a  b a *
Regular expression:

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 

Lr  a, bb, aa, abb, ba, bbb,...

9
Example

Regular expression r aa * bb * b

2n 2m
Lr  {a b b : n, m 0}

10
Example

Regular expression r (0  1) * 00 (0  1) *

L(r )= { all strings with at least


two consecutive 0 }

11
Example

Regular expression r (1  01) * (0   )

L(r )= { all strings without


two consecutive 0 }

12
Equivalent Regular Expressions

Definition:

Regular expressionsr1 andr2

are equivalent ifL( r1 ) L( r2 )

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

For any regular expression r


the language L(r ) is regular

Proof by induction on the size of r


18
Induction Basis
,
Primitive Regular Expressions: , 
NFAs

L( M1 )  L( )

regular
L( M 2 ) {} L( )
languages
a
L( M 3 ) {a} L(a )

19
Inductive Hypothesis

Assume
for regular expressions r1 andr2
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:

L((r1 )) is a regular language

25
Proof - Part 2

Languages
Generated by  Regular
Languages
Regular Expressions

For any regular languageL there is


a regular expression r with L( r ) L

Proof by construction of regular expression


26
Since L is regular take the
NFA M that accepts it

L ( M ) L

Single final state


27
From M construct the equivalent
Generalized Transition Graph
in which transition labels are regular
expressions

Example:
M
a c a c
a, b a b
28
b b
Another Example:
a
q0 q1 a, b q2
b

b b
a
q0 q1 a  b q2
b
29
b b
Reducing the states:
a
q0 q1 a  b q2
b

bb * a b

q0 bb * (a  b) q2
30
Resulting Regular Expression:

bb * a b

q0 bb * (a  b) q2

r (bb * a ) * bb * (a  b)b *

L ( r ) L ( M ) L
31
In General
Removing states: e
d c
qi q qj
a b

ae * d ce * b
ce * d
qi qj
ae * b
32
The final transition graph:
r1 r4
r3
q0 qf
r2

The resulting regular expression:

r r1 * r2 (r4  r3r1 * r2 ) *

L ( r ) L ( M ) L
33
Standard Representations
of Regular Languages

Regular Languages

FAs

Regular
NFAs
Expressions

34
When we say: We are given
a Regular Language L

We mean: Language L is in a standard


representation

35
Elementary Questions

about

Regular Languages

36
Membership Question
Question: Given regular languageL
and string w
how can we check if w  L ?

Answer: Take the DFA that accepts L


and check if w is accepted

37
DFA
w
w L

DFA
w
w L

38
Question: Given regular languageL
how can we check
if Lis empty: ( L  ) ?

Answer: Take the DFA that accepts L

Check if there is any path from


the initial state to a final state
39
DFA

L 

DFA

L 

40
Question: Given regular language L
how can we check
if Lis finite?

Answer:Take the DFA that accepts L

Check if there is a walk with cycle


from the initial state to a final state
41
DFA

L is infinite

DFA

L is finite

42
Given regular languages L1 and
Question: L2
how can we check if L1 L2 ?

Answer: Find if ( L1  L2 )  ( L1  L2 ) 

43
( L1  L2 )  ( L1  L2 ) 

L1  L2  and L1  L2 

L1 L2 L L2 L1 L1
2
L1  L2 L2  L1

L1 L2
44
( L1  L2 )  ( L1  L2 ) 

L1  L2  or L1  L2 

L1 L2 L2 L1

L1  L2 L2  L1

L1 L2
45

You might also like