Top Banner
1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2
37

1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

Dec 22, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

1

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

15-453

For next time: Read 2.1 & 2.2

Page 2: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

2

MINIMIZING DFAs

Page 3: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

3

IS THIS MINIMAL?

11

1

1

0

0

00

NO

Page 4: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

4

IS THIS MINIMAL?

0

1

01

Page 5: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

5

THEOREMFor every regular language L, there exists a unique (up to re-labeling of the states)

minimal DFA M such that L = L(M)

Page 6: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

6

NOT TRUE FOR NFAs

0

0

0

0

Page 7: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

7

EXTENDING Given DFA M = (Q, Σ, , q0, F) extend

to : Q Σ* → Q as follows:

(q, ε) =

(q, ) =

(q, w1 …wk+1 ) = ( (q, w1 …wk ), wk+1 )

^

^

^

^ ^

A string w Σ* distinguishes states q1 from q2 if

(q1, w) F (q2, w) F ^ ^

q

(q, )

Page 8: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

8

00,1

00

1

1

1

q0

q1

q2

q3

ε distinguishes accept from non-accept states

Page 9: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

9

Fix M = (Q, Σ, , q0, F) and let p, q, r Q

Definition:

p is distinguishable from q iff there is a w Σ* that distinguishes p from q

p is indistinguishable from q iff p is not distinguishable from q

Page 10: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

10

Fix M = (Q, Σ, , q0, F) and let p, q, r Q

Define relation “~”:

p ~ q iff p is indistinguishable from q

p ~ q iff p is distinguishable from q /

Proposition: “~” is an equivalence relation

p ~ p (reflexive)

p ~ q q ~ p (symmetric)

p ~ q and q ~ r p ~ r (transitive)

p q r

w wSuppose not:

Page 11: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

11

so “~” partitions the set of states of M into disjoint equivalence classes

Fix M = (Q, Σ, , q0, F) and let p, q, r Q

q0

Qq

[q] = { p | p ~ q }

Proposition: “~” is an equivalence relation

Page 12: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

12

11

1

1

0

0

00

Page 13: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

13

Algorithm MINIMIZE

Input: DFA M

Output: DFA MMIN such that:

M MMIN

MMIN has no inaccessible states

MMIN is irreducible

states of MMIN are pairwise distinguishable||

Theorem: MMIN is the unique minimum

Page 14: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

17

TABLE-FILLING ALGORITHMInput: DFA M = (Q, Σ, , q0, F)

(2) EM = { [q] | q Q }

(1) DM = { (p,q) | p,q Q and p ~ q }/

•Make best effort to find pairs of states that are distinguishable.

•Pairs left over will be indistinguishable.

IDEA!

Output:

Page 15: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

18

TABLE-FILLING ALGORITHMInput: DFA M = (Q, Σ, , q0, F)

Output:

(2) EM = { [q] | q Q }

(1) DM = { (p,q) | p,q Q and p ~ q }/

q0

q1

qi

qn

q0 q1 qi qn

Base Case: p accepts and q rejects p ~ q/

Page 16: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

19

TABLE-FILLING ALGORITHMInput: DFA M = (Q, Σ, , q0, F)

Output:

(2) EM = { [q] | q Q }

(1) DM = { (p,q) | p,q Q and p ~ q }/

q0

q1

qi

qn

q0 q1 qi qn

Base Case: p accepts and q rejects p ~ q/

Recursion:d d d

d

d

p p

q q~/

p ~ q/

Page 17: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

20

1 0

1

0 1

0,1

0

q0

q0 q1

q1

q2

q2 q3

q3

q0 q1 q2 q3

d d d

d

d

d

Page 18: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

21

11

1

1

0

0

00

q0

q0 q1

q1

q2

q2 q3

q3 d d

d

d

q0 q1

q2q3

Page 19: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

22

If 2 states are not distinguished by table-filling algorithm, then they are equivalent

Proof (by contradiction):

Suppose there exist states p and q that aren’t distinguished by the T-F algorithm, but p ~ q /

Then there exists w such that:

(p, w) F and (q, w) F ^ ^

Of all such bad pairs, let (p, q) be a pair with the smallest |w| So, w = w, where ΣLet p = (p,) and q = (q,)

Then (p, q) is also a bad pair

(Why is |w| >0 ?)

Page 20: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

23

Algorithm MINIMIZE

Input: DFA M

Output: DFA MMIN

(1) Remove all inaccessible states from M

(2) Apply Table-Filling algorithm to get EM = { [q] | q is an accessible state of M }

MMIN = (QMIN, Σ, MIN, q0 MIN, FMIN)

QMIN = EM, q0 MIN = [q0], FMIN = { [q] | q F }

MIN( [q], ) = [ ( q, ) ]

Must show MIN is well defined!

Page 21: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

24

Algorithm MINIMIZE

Input: DFA M

Output: DFA MMIN

(1) Remove all inaccessible states from M

(2) Apply Table-Filling algorithm to get EM = { [q] | q is an accessible state of M }

MMIN = (QMIN, Σ, MIN, q0 MIN, FMIN)

QMIN = EM, q0 MIN = [q0], FMIN = { [q] | q F }

MIN( [q], ) = [ ( q, ) ]

Claim: MMIN M

Page 22: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

25

1

0

1010

1

0

1

0q0 q1

q2

MINIMIZE

Page 23: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

26

1 0

1

0

1

0,1

0

q0 q1

q3

q5

q4

0

1

q2

0,1q0

q0 q1

q1

q3

q3 q4

q4

d

dd

d

d d

q5

q5

d

d

d

Page 24: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

27

1 0

1

00,1

0

q0 q1

q3

q5

q4

0

1

q0

q0 q1

q1

q3

q3 q4

q4

d

dd

d

d d

q5

q5

d

d

d

Page 25: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

29

*MMIN is the unique minimal DFA equivalent to M

Suppose MMMIN, and M has no inaccessible states and is irreducible

Claim: There exists a 1-1 onto correspondence (preserving transitions) between M and MMIN

Page 26: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

30

*MMIN is the unique minimal DFA equivalent to M

Suppose MMMIN, and M has no inaccessible states and is irreducible

Claim: There exists a 1-1 onto correspondence (preserving transitions) between M and MMIN

NB: If M is minimal, then M has no inaccessible states and is irreducible. (So claim implies * )

This Claim is also implying the converse, ie if M has no inaccessible states and is irreducible, then M is minimal.

Proof. Let Mmin ( M MMIN) be minimal. Then Mmin MMIN

So, by Claim, both Mmin and M are isomorphic to MMIN

NOT TRUE for NFAs !

Page 27: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

31

Proof: We will construct a map recursively

Base Case: q0 MIN → q0

Recursive Step: If p → p

q

qThen q → q

*MMIN is the unique minimal DFA equivalent to M

Suppose MMMIN, and M has no inaccessible states and is irreducible

Claim: There exists a 1-1 onto correspondence (preserving transitions) between M and MMIN

Page 28: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

32

Base Case: q0 MIN → q0

Recursive Step: If p → p

q

qThen q → q

We need to prove:

The map is defined everywhere

The map is well defined

The map is a bijection

Page 29: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

33

That is, for all q MMIN there is a q M such that q → q

If q MMIN, there is w such that MIN(q0 MIN,w) = q

Base Case: q0 MIN → q0

Recursive Step: If p → p

q

qThen q → q

The map is defined everywhere

^

Let q = (q0,w) ^

Page 30: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

34

Base Case: q0 MIN → q0

Recursive Step: If p → p

q

qThen q → q

The map is well defined

Suppose there exist q and q such that q → q and q → q

We show that q and q are indistinguishable, so it must be that q = q

Page 31: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

35

MMIN M

Suppose there exist q and q such that q → q and q → q

q

u

q0

q

v

q0

q

u

q0 MIN

q

v

q0 MIN

Suppose q and q are not indistinguishable

w

Accep

t

w Reject

w Reject

w

Accep

t

Page 32: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

36

Base Case: q0 MIN → q0

Recursive Step: If p → p

q

qThen q → q

The map is onto

For all q M there is a q MMIN such that q → q

If q M, there is w such that (q0,w) = q^

Let q = MIN(q0 MIN,w) ^

Page 33: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

37

MMIN M

Suppose there exist p and q such that p → q and q → q

q

u

q0

q

v

q0

p

u

q0 MIN

q

v

q0 MIN

Suppose p and q are not indistinguishable

w

Accep

t

w Reject

w Reject

w

Accep

t

The map is 1-1

Page 34: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

38

How do we prove two regular expressions are equivalent?

Page 35: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

39

Page 36: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

40

Page 37: 1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 For next time: Read 2.1 & 2.2.

41

Finish Reviewing Chapter 1 of the book andRead 2.1 & 2.2 for next time