( ) ( ) if = M DFA 1 2 0 , 1 2 0 L ( M ) { 10 } - - PDF document

if m dfa 1 2 0 1 2 0 l m 10 2 1 q q q 1 2 0 1 0
SMART_READER_LITE
LIVE PREVIEW

( ) ( ) if = M DFA 1 2 0 , 1 2 0 L ( M ) { 10 } - - PDF document

Review Languages and Grammars Alphabets, strings, languages CS 301 - Lecture 3 Regular Languages NFA DFA Equivalence Deterministic Finite Automata Regular Expressions Nondeterministic Finite Automata Today: Fall 2008


slide-1
SLIDE 1

1

CS 301 - Lecture 3 NFA DFA Equivalence Regular Expressions

Fall 2008

Review

  • Languages and Grammars

– Alphabets, strings, languages

  • Regular Languages

– Deterministic Finite Automata – Nondeterministic Finite Automata

  • Today:

– Equivalence of NFA and DFA – Regular Expressions – Equivalence to Regular Languages

Equivalence of Machines

Machine is equivalent to machine if 1

M

2

M

( ) ( )

2 1

M L M L =

Example of equivalent machines

q

1

q 1 q

1

q

2

q 1 1 1 ,

NFA DFA

( )

* } 10 {

1 =

M L

( )

* } 10 {

2 =

M L

1

M

2

M

slide-2
SLIDE 2

2

Convert NFA to DFA

a b a λ q

1

q

2

q

NFA DFA

{ }

q

M M′

Begin with a set

  • f start states

DFA start state = Union of NFA Start States

Convert NFA to DFA

a b a λ q

1

q

2

q

NFA DFA

{ }

q

{ }

2 1,q

q a

M M′

From the NFA start states, where could we get on a? List the set of all possible states you can reach using just an a.

Convert NFA to DFA

a b a λ q

1

q

2

q

NFA DFA

{ }

q

{ }

2 1,q

q a ∅ b

M M′

From the NFA start states, where could we get on b? The set of all possible states you can reach may be empty! How did we get from q0 to q2 using only a? (think )

λ

Convert NFA to DFA

a b a λ q

1

q

2

q

NFA DFA

{ }

q

{ }

2 1,q

q a ∅ b a

M M′

From new set, where could we get on a?

slide-3
SLIDE 3

3

Convert NFA to DFA

a b a λ q

1

q

2

q

NFA DFA

{ }

q

{ }

2 1,q

q a ∅ b a b

M M′

From new set, where could we get on b?

Convert NFA to DFA

a b a λ q

1

q

2

q

NFA DFA

{ }

q

{ }

2 1,q

q a ∅ b a b b a,

M M′

From empty set, we can only get back to empyt set.

Convert NFA to DFA

a b a λ q

1

q

2

q

NFA DFA

{ }

q

{ }

2 1,q

q a ∅ b a b b a,

M M′

If a node has any NFA Final state, mark the node as Final in the DFA.

If the NFA has states the DFA has states in the powerset

,... , ,

2 1

q q q

{ }{ }{ }{ }

,.... , , , , , , ,

7 4 3 2 1 1

q q q q q q q ∅

Could This Produce Infinite States?

Powerset of finite set can be big, but it is not infinite! There are a finite number of NFA states by definition

slide-4
SLIDE 4

4

Procedure NFA to DFA

  • 1. Initial state of NFA:

Initial state of DFA:

q

{ }

q

Procedure NFA to DFA

  • 2. For every DFA’s state

Compute in the NFA Add transition to DFA

} ,..., , {

m j i

q q q

( )

( )

... , , * , , * a q a q

j i

δ δ } ,..., , {

m j i

q q q ′ ′ ′

( )

} ,..., , { }, ,..., , {

m j i m j i

q q q a q q q ′ ′ ′ = δ =

Procedure NFA to DFA

Repeat Step 2 for all letters in alphabet, until no more transitions can be added.

Procedure NFA to DFA

  • 3. For any DFA state

If some is a final state in the NFA Then, is a final state in the DFA

} ,..., , {

m j i

q q q

j

q } ,..., , {

m j i

q q q

slide-5
SLIDE 5

5

Theorem

Take NFA M Apply procedure to obtain DFA M′ Then and are equivalent :

M M′

( ) ( )

M L M L ′ =

Proof

( ) ( )

M L M L ′ =

( ) ( )

M L M L ′ ⊆

( ) ( )

M L M L ′ ⊇

AND

( ) ( )

M L M L ′ ⊆

First we show:

) (M L w∈

Take arbitrary: We will prove:

) (M L w ′ ∈ ) (M L w∈

q

f

q

w

k

w σ σ σ 

2 1

=

1

σ

2

σ

k

σ

q

f

q

: M : M

slide-6
SLIDE 6

6

q

f

q

k

w σ σ σ 

2 1

=

1

σ

2

σ

k

σ

: M

} { 0 q

1

σ

2

σ

k

σ

: M′

} , { …

f

q

) (M L w∈ ) (M L w ′ ∈

We will show that if

q

m

q n

a a a v 

2 1

=

1

a

2

a

n

a

: M

} { 0 q 1

a

2

a

n

a

: M′

} , { …

i

q

i

q

j

q

l

q

} , { …

j

q } , { …

l

q } , { …

m

q

More generally, we will show that if in :

M

(arbitrary string)

q

1

a

: M

} { 0 q 1

a

: M′

} , { …

i

q

i

q

Proof by induction on Induction Basis: 1

a v = | | v

Induction hypothesis:

k v ≤ ≤ | | 1

q

d

q

1

a

2

a

k

a

: M

i

q

j

q

c

q

} { 0 q 1

a

2

a

k

a

: M′

} , { …

i

q } , { …

j

q } , { …

c

q } , { …

d

q

k

a a a v 

2 1

=

slide-7
SLIDE 7

7

Induction Step:

1 | | + = k v

q

d

q

1

a

2

a

k

a

: M

i

q

j

q

c

q

} { 0 q 1

a

2

a

k

a

: M′

} , { …

i

q } , { …

j

q } , { …

c

q } , { …

d

q

1 1 2 1 + + ′

′ = =

k k v k

a v a a a a v       v′ v′

Induction Step:

1 | | + = k v

q

d

q

1

a

2

a

k

a

: M

i

q

j

q

c

q

} { 0 q 1

a

2

a

k

a

: M′

} , { …

i

q } , { …

j

q } , { …

c

q } , { …

d

q

1 1 2 1 + + ′

′ = =

k k v k

a v a a a a v       v′ v′

e

q

1 + k

a

1 + k

a

} , { …

e

q

q

f

q

k

w σ σ σ 

2 1

=

1

σ

2

σ

k

σ

: M

} { 0 q

1

σ

2

σ

k

σ

: M′

} , { …

f

q

) (M L w∈ ) (M L w ′ ∈

Therefore if We have shown:

( ) ( )

M L M L ′ ⊆

We also need to show:

( ) ( )

M L M L ′ ⊇

(proof is similar)

slide-8
SLIDE 8

8

NFAs Accept Regular Languages

We will prove: Languages accepted by NFAs Regular Languages

=

NFAs and DFAs have the same computation power

Languages accepted by DFAs

Languages accepted by NFAs Regular Languages Step 1 Proof: Every DFA is trivially an NFA Any language accepted by a DFA is also accepted by an NFA

L

Languages accepted by NFAs Regular Languages Step 2 Proof: Any NFA can be converted to an equivalent DFA Any language accepted by an NFA is also accepted by a DFA

L

slide-9
SLIDE 9

9

Regular Expressions

  • Regular expressions describe regular

languages

  • Example:

describes the language

* ) ( c b a ⋅ +

{ } { }

,... , , , , , * , bca abc aa bc a bc a λ =

Recursive Definition

α λ, , ∅

( )

1 1 2 1 2 1

* r r r r r r ⋅ +

Are regular expressions Primitive regular expressions: 2

r

1

r

Given regular expressions and

Examples

( )

) ( * ∅ + ⋅ ⋅ + c c b a

A regular expression:

( )

+ + b a

Not a regular expression:

Languages of Regular Expressions

  • : language of regular expression
  • Example

( )

r L r

( ) { }

,... , , , , , * ) ( bca abc aa bc a c b a L λ = ⋅ +

slide-10
SLIDE 10

10

Formal Definition

  • For primitive regular expressions:

( ) ( ) { } ( ) { }

a a L L L = = ∅ = ∅ λ λ

Definition (continued)

  • For regular expressions and

1

r

2

r

( ) ( ) ( )

2 1 2 1

r L r L r r L ∪ = +

( ) ( ) ( )

2 1 2 1

r L r L r r L = ⋅

( ) ( ) ( )*

*

1 1

r L r L =

( ) ( ) ( )

1 1

r L r L =

Example

( ) ( )

* a b a L ⋅ +

( ) ( ) ( )

* a L b a L + =

( ) ( )

* a L b a L + =

( ) ( ) ( ) ( ) ( )*

a L b L a L ∪ =

{ } { } ( ) { } ( )*

a b a ∪ =

{ }{ }

,... , , , , aaa aa a b a λ =

{ }

,... , , ,..., , , baa ba b aaa aa a =

Example

  • Regular expression

( ) ( )

bb a b a r + + = *

( ) { }

,... , , , , , bbb ba abb aa bb a r L =

slide-11
SLIDE 11

11

What’s Next

  • Read

– Linz Chapter 1, 2.1, 2.2, 2.3, (skip 2.4), Chapter 3 – JFLAP Startup, Chapter 1, 2.1, (skip 2.2) 3, 4

  • Next Lecture Topics from Chapter 3.2 and 3.3

– Regular Expressions and Regular Languages – Regular Grammars and Regular Languages

  • Quiz 1 in Recitation on Wednesday 9/17

– Covers Linz 1.1, 1.2, 2.1, 2.2, 2.3, and JFLAP 1, 2.1 – Closed book, but you may bring one sheet of 8.5 x 11 inch paper with any notes you like. – Quiz will take the full hour

  • Homework

– Homework 2 is Due Thursday