0% found this document useful (0 votes)
11 views65 pages

Lecture 03

Uploaded by

Andrei Circei
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)
11 views65 pages

Lecture 03

Uploaded by

Andrei Circei
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/ 65

Automate,

Calculabilitate,
Complexitate

1
Properties of
Regular Languages

2
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
3
We say: Regular languages are closed under

Union: L1  L2
Concatenation: L1L2
Star: L1 *
Reversal: R
L1
Complement: L1
Intersection: L1  L2
4
A useful transformation: use one accept state

NFA
a
b 2 accept states
a
b

Equivalent
a
NFA 1 accept state
a b

b 

5
In General
NFA

Equivalent NFA
 Single
 accepting

state
6
Extreme case

NFA without accepting state

Add an accepting state


without transitions

7
Take two languages

Regular language L1 Regular language L2

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

NFA M1 NFA M2

Single accepting state Single accepting state

8
Example

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

M2
a
L2  ba b

9
Union
NFA for L1  L2
M1

 M2

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

 L2  {ba}
b a
11
Concatenation

NFA for L1L2

M1 M2

12
Example

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

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

13
Star Operation
NFA for L1 * w  w1w2  wk
 wi  L1
M1
  L1 *
 


14
Example

n
NFA for L1*  {a b} *

n
L1  {a b}
a
 b 


15
Reverse
R
NFA for L1
L1 M1 M1

1. Reverse all transitions

2. Make initial state accepting state


and vice versa
16
Example

M1
a
n
L1  {a b} b

M1
a
R n
L1  {ba } b

17
Complement

L1 M1 L1 M1

1. Take the DFA that accepts L1

2. Make accepting states non-final,


and vice-versa
18
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

19
Intersection

L1 regular
We show L1  L2
L2 regular regular

20
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
Another Proof for Intersection Closure

Machine M1 Machine M2
DFA for L1 DFA for L2

Construct a new DFA M that accepts L1  L2

M simulates in parallel M1 and M 2


23
States in M

qi , p j

State in M1 State in M2

24
DFA M1 DFA M2

q1 a q2 p1 a p2
transition transition

DFA M

q1, p1 a q2 , p2
New transition
25
DFA M1 DFA M2

q0 p0
initial state initial state

DFA M

q0 , p0
New initial state
26
DFA M1 DFA M2

qi pj pk

accept state accept states

DFA M
qi , p j qi , pk

New accept states

Both constituents must be accepting states


27
Example:

n0 m0
L1  {a b} n m
L2  {ab }
M1 M2
a b
q0 b q1 p0 a p1
a, b b a
q2 p2
a, b a, b
28
Automaton for intersection
n n
L  {a b}  {ab }  {ab}
a, b

q0 , p0 a q0 , p1 b q1, p1 a q2 , p2

b a b a
q1, p2 b q0 , p2 q2 , p1

a b
a, b
29
M simulates in parallel M1 and M 2

M accepts string w if and only if:


M1 accepts string w
and M 2 accepts string w

L( M )  L( M1 )  L( M 2 )
30
Regular Expressions

31
Regular Expressions
Regular expressions
describe regular languages

Example: (a  b  c) *

describes the language


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

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

Given regular expressions r1 and r2

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

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

Not a regular expression: a  b  

34
Languages of Regular Expressions

Lr  : language of regular expression r

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

35
Definition

For primitive regular expressions:

L   

L    

La   a
36
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 
37
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,...
38
Example

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

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

39
Example

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

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

40
Example

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

L(r ) = { all strings containing substring 00 }

41
Example

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

L(r ) = { all strings without substring 00 }

42
Equivalent Regular Expressions

Definition:

Regular expressions r1 and r2

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

43
Example
L = { all strings without substring 00 }

r1  (1  01) * (0   )
r2  (1* 011*) * (0   )  1* (0   )

r1 and r2
L(r1 )  L(r2 )  L
are equivalent
regular expressions
44
Regular Expressions
and
Regular Languages

45
Theorem

Languages
Generated by
Regular Expressions
 Regular
Languages

46
Proof:

Languages
Generated by  Regular
Languages
Regular Expressions

Languages
Generated by  Regular
Languages
Regular Expressions

47
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


48
Induction Basis
Primitive Regular Expressions: ,  , 
Corresponding
NFAs
L( M1 )    L()

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

49
Inductive Hypothesis

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

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

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

Lr1 
51
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 
52
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 *
53
Therefore:

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

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

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

L((r1 ))  L(r1 ) is trivially a regular language


(by induction hypothesis)
End of Proof-Part 1 54
Using the regular closure of these operations,
we can construct recursively the NFA M
that accepts L(M )  L(r )

Example: r  r1  r2
L(M1 )  L(r1 )
L(M )  L(r )


L(M2 )  L(r2 ) 

55
Proof - Part 2

Languages
Generated by  Regular
Languages
Regular Expressions

For any regular language L there is


a regular expression r with L( r )  L

We will convert an NFA that accepts L


to a regular expression 56
Since L is regular, there is a
NFA M that accepts it

L( M )  L

Take it with a single final state


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

Example: Corresponding
M Generalized transition graph

a c a c
a, b ab
58
b b
Another Example:
a
q0 q1 a, b q2
b

Transition labels b b
are regular a
expressions q0 q1 a  b q2
b
59
b b
Reducing the states:
a
q0 q1 a  b q2
b

Transition labels
are regular bb * a b
expressions
q0 bb * (a  b) q2
60
Resulting Regular Expression:

bb * a b

q0 bb * (a  b) q2

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

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

ae * d ce * b
ce * d
qi qj
ae * b
62
By repeating the process until
two states are left, the resulting graph is
Initial graph Resulting graph
r1 r4
r3
q0 qf
r2
The resulting regular expression:
r  r1 * r2 (r4  r3r1 * r2 ) *
L(r )  L( M )  L
End of Proof-Part 2 63
Standard Representations
of Regular Languages

Regular Languages

DFAs

Regular
NFAs
Expressions

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

We mean: Language L is in a standard


representation

(DFA, NFA, or Regular Expression)

65

You might also like