0% found this document useful (0 votes)
14 views57 pages

Class 4

1) Any NFA can be converted to an equivalent NFA with a single final state. 2) Regular expressions describe regular languages. The language of a regular expression is defined recursively based on the expressions structure and operators. 3) Languages generated by regular expressions are regular languages, and every regular language can be generated by some regular expression. This establishes a correspondence between regular expressions and regular languages.

Uploaded by

zohaibbigstar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views57 pages

Class 4

1) Any NFA can be converted to an equivalent NFA with a single final state. 2) Regular expressions describe regular languages. The language of a regular expression is defined recursively based on the expressions structure and operators. 3) Languages generated by regular expressions are regular languages, and every regular language can be generated by some regular expression. This establishes a correspondence between regular expressions and regular languages.

Uploaded by

zohaibbigstar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 57

Single Final State for NFAs

1
Any NFA can be converted

to an equivalent NFA

with a single final state

2
Example
a
NFA
a b

a Equivalent NFA

a b

b 

3
In General
NFA

Equivalent NFA

 Single
 final state
4
Extreme Case

NFA without final state

Add a final state


Without transitions

5
Properties of
Regular Languages

6
For regular languages L1 and L2
we will prove that:

Union: L1  L2
Concatenation: L1L2
Star: L1 * Are regular
Languages
Reversal: R
L1
Complement: L1
Intersection: L1  L2
7
We say: Regular languages are closed under

Union: L1  L2
Concatenation: L1L2
Star: L1 *
Reversal: R
L1
Complement: L1
Intersection: L1  L2
8
Regular language L1 Regular language L2

LM1   L1 LM 2   L2

NFA M1 NFA M2

Single final state Single final state


9
Example
M1
n0
a
n
L1  {a b} b

M2
a
L2  ba b

10
Union
NFA for L1  L2
M1

 

 M2 

11
Example
n
NFA for L1  L2  {a b}  {ba}
n
L1  {a b}
a
b
 

 L2  {ba} 
b a
12
Concatenation

NFA for L1L2

M1 M2
 

13
Example

n n
NFA for L1L2  {a b}{ba}  {a bba}

n
L1  {a b}
a
L2  {ba}
b  b a 

14
Star Operation
NFA for L1 *

  L1 *
M1
 


15
Example

n w  w1w2  wk
NFA for L1*  {a b} * wi  L1

n
L1  {a b}
a
 b 


16
Reverse
R
NFA for L1
L1 M1 M1

1. Reverse all transitions

2. Make initial state final state


and vice versa
17
Example
M1
a
n
L1  {a b} b

M1
a
R n
L1  {ba } b

18
Complement

L1 M1 L1 M1

1. Take the DFA that accepts L1

2. Make final states non-final,


and vice-versa
19
Example
M1
a a, b
n b a, b
L1  {a b}

M1
n a a, b
L1  {a, b} * {a b}
b a, b

20
Intersection
DeMorgan’s Law: L1  L2  L1  L2
L1 , L2 regular
L1 , L2 regular
L1  L2 regular
L1  L2 regular
L1  L2 regular
21
Example

n
L1  {a b} regular
L1  L2  {ab}
L2  {ab, ba} regular regular

22
Regular Expressions

23
Regular Expressions
Regular expressions
describe regular languages

Example: (a  b  c) *

describes the language


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

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

Given regular expressions r1 and r2

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

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

Not a regular expression: a  b  

26
Languages of Regular Expressions

Lr  : language of regular expression r

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

27
Definition

For primitive regular expressions:

L   

L    

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

For regular expressions r1 and r2

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

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

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

Lr1   Lr1 
29
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,...
30
Example

Regular expression r  a  bb * a  b 

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

31
Example

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

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

32
Example

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

L(r ) = { all strings with at least


One or two consecutive 0 }

33
Example

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

L(r ) = { all strings without


two consecutive 0 }

34
Equivalent Regular Expressions

Definition:

Regular expressions r1 and r2

are equivalent if L(r1 )  L(r2 )

35
Regular Expressions
and
Regular Languages

37
Theorem

Languages
Generated by
Regular Expressions
 Regular
Languages

38
Theorem - Part 1

Languages
Generated by  Regular
Languages
Regular Expressions

1. For any regular expression r


the language L(r ) is regular

39
Theorem - Part 2

Languages
Generated by  Regular
Languages
Regular Expressions

2. For any regular language L there is


a regular expression r with L( r )  L

40
Proof - Part 1

1. For any regular expression r


the language L(r ) is regular

Proof by induction on the size of r

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

L( M1 )    L()

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

42
Inductive Hypothesis

Assume
for regular expressions r1 and r2
that
L(r1 ) and L(r2 ) are regular languages

43
Inductive Step
We will prove:
Lr1  r2 

Lr1  r2 
Are regular
Languages
Lr1 *

Lr1 
44
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 
45
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 *
46
Therefore:

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

Are regular
Lr1  r2   Lr1  Lr2 
languages

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

47
And trivially:

L((r1 )) is a regular language

48
Proof – Part 2

2. For any regular language L there is


a regular expression r with L( r )  L

Proof by construction of regular expression

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

L( M )  L

Single final state


50
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
51
b b
Another Example:
a
q0 q1 a, b q2
b

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

bb * a b

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

bb * a b

q0 bb * (a  b) q2

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

L(r )  L( M )  L
54
In General
Removing states: g e
d c
qi q qj
a b
f
ae * d g  ce * d ce * b
ce * d
qi f  ae * b qj
ae * b
55
Reducing NFAs by equivalences – example

56
Reducing NFAs by equivalences – example

57
The final transition
graph: r1 r4
r3
q0 qf
r2

The resulting regular expression:


r  ( r1  r2 r4 * r3 ) * r2 r4 *
r  r1 * r2 (r4  r3 r1 * r2 ) *
L(r )  L( M )  L
58

You might also like