37
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

  • Upload
    baylee

  • View
    39

  • Download
    0

Embed Size (px)

DESCRIPTION

15-453. FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY. TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A A. MINIMIZING DFAs. THURSDAY Jan 24. 0. 1. 0. 1. 1. 0. 1. 0. IS THIS MINIMAL?. NO. 0. 1. 1. 0. IS THIS MINIMAL?. THEOREM. - PowerPoint PPT Presentation

Citation preview

Page 1: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

15-453

Page 2: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

MINIMIZING DFAsTHURSDAY Jan 24

Page 3: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

IS THIS MINIMAL?

111

1

0

0

00

NO

Page 4: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

IS THIS MINIMAL?

0

1

01

Page 5: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

NOT TRUE FOR NFAs

0

0

0

0

Page 7: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

: Q Σ* → Q as follows:

(q, ε) =

(q, ) =(q, 1 …k+1 ) = ( (q, 1 …k ), k+1 )

^

^^^ ^

String w Σ* distinguishes states q1 and q2 iff (q1, w) F (q2, w) F ^ ^

q

(q, )

^Note: (q0, w) F M accepts w

Page 8: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

: Q Σ* → Q as follows:

(q, ε) =

(q, ) =(q, 1 …k+1 ) = ( (q, 1 …k ), k+1 )

^

^^^ ^

String w Σ* distinguishes states q1 and q2 iff

q

(q, )

^Note: (q0, w) F M accepts w

exactly ONE of (q1, w), (q2, w) is a final state^ ^

Page 9: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

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

p is indistinguishable from q iff p is not distinguishable from q ifffor all w Σ*, (p, w) F (q, w) F^ ^

Page 10: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

00,1

00

1

1

1

q0

q1

q2

q3

ε distinguishes accept from non-accept states

Page 11: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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 relationp ~ p (reflexive)p ~ q q ~ p (symmetric)p ~ q and q ~ r p ~ r (transitive)

Proof (of transitivity): for all w, we have: (p, w) F (q, w) F (r, w) F

^ ^ ^

Page 12: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

Proposition: ~ is an equivalence relation

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

q0

Q

q

[q] = { p | p ~ q }

Page 13: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

111

1

0

0

00

Page 14: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Algorithm MINIMIZE

Input: DFA M

Output: DFA MMIN such that:

MMMIN (that is, L(M) = L(MMIN))

MMIN has no inaccessible states

MMIN is irreducible

all states of MMIN are pairwise distinguishable||

Theorem: MMIN is the unique minimum DFA

Page 15: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Intuition: States of MMIN will be blocks of equivalent states of M

We’ll find these equivalent states witha “Table-Filling” Algorithm

Page 16: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

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

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

• We know how to find those pairs of states that ε distinguishes…

• Use this and recursion to find those pairs distinguishable with longer strings

• Pairs left over will be indistinguishable

IDEA:

Output:

Page 17: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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 18: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

Recursion: if there is σ Σand states p, q satisfying D D

D (p, ) =

p

(q, ) = q~/ p ~ q/

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

Repeat until no more new D’s

Page 19: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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 20: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

111

1

0

0

00q0

q0 q1

q1

q2

q2 q3

q3 D D

D

D

q0 q1

q2q3

Page 21: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Claim: If p, q are distinguished by Table-Filling algorithm, then p ~ q

Proof: By induction on the length of the string distinguishing them.If (p, q) is marked D at the start, then one’s in F and one isn’t, so ε distinguishes p and q

Then there are states p, q, and string w such that:

(p, w) F and (q, w) F ^ ^2. p = (p,) and q = (q,), where Σ

The string w distinguishes p and q!

/

Suppose (p, q) is marked D at a later point.

1. (p, q) are marked D p ~ q (by induction)

/

Page 22: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Claim: If p, q are not distinguished by Table-Filling algorithm, then p ~ q

Proof (by contradiction):Suppose the pair (p, q) is not marked D by the algorithm, yet p ~ q (a “bad pair”) /

Then there is a string w such that:

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

Of all such bad pairs, let p, q be a pair with the shortest w

So, w = w, where ΣLet p = (p,) and q = (q,)

Then (p, q) is also a bad pair, but with a SHORTER w !

(Why is |w| >0 ?)

Page 23: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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 }

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

MIN( [q], ) = [ ( q, ) ]Must show MIN is well defined!

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

Page 24: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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 }

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

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

MIN( [q], ) = [ ( q, ) ]Claim: MMIN M

Page 25: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

1

0

10101

0

1

0q0 q1

q2

MINIMIZE

Page 26: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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 Dq5

q5

D

D

D

Page 27: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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 Dq5

q5

D

D

D

Page 28: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

*MMIN is the unique minimal DFA equivalent to MClaim: Suppose MMMIN, and M has no inaccessible states and is irreducible. Then there is a bijection that preserves transitions between M and MMIN

Page 29: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

*MMIN is the unique minimal DFA equivalent to MClaim: Suppose MMMIN, and M has no inaccessible states and is irreducible. Then there is a bijection that preserves transitions between M and MMIN

Note: If M is minimal, then M has no inaccessible states and is irreducible. (So the Claim implies *)

Corollary to the Claim: If M has no inaccessible states and is irreducible, then M is minimal.

Proof: Let Mmin M be minimal. Then Mmin MMIN

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

NOT TRUE for NFAs !

Page 30: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Proof: We construct a map from MMIN to M recursively

Base Case: q0 MIN → q0

Recursive Step: If p → p

q

qThen q → q

*MMIN is the unique minimal DFA equivalent to MClaim: Suppose MMMIN, and M has no inaccessible states and is irreducible. Then there is a bijection that preserves transitions between M and MMIN

Page 31: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Base Case: q0 MIN → q0

Recursive Step: If p → p

q

qThen q → q

We need to prove:The map is defined everywhereThe map is well definedThe map is a bijection

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

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

Let q = (q0,w). q will map to q ^

Page 32: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Base Case: q0 MIN → q0

Recursive Step: If p → p

q

qThen q → q

The map is well definedSuppose 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 33: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

MMIN M

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

q

uq0

q

vq0

qu

q0 MIN

qv

q0 MIN

Suppose q and q are distinguishable

w

Accept

w Reject

w Reject

w

Accept

Contradiction!

Page 34: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Base Case: q0 MIN → q0

Recursive Step: If p → p

q

qThen q → q

The map is ontoFor 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 35: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

MMIN M

Suppose there are distinct p and q such that p → q and q → q

q

uq0

q

vq0

pu

q0 MIN

qv

q0 MIN

Suppose p and q are distinguishable

w

Accept

w Reject

w Reject

w

Accept

The map is 1-1

Contradiction!

Page 36: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

How can we prove that two regular expressions are

equivalent?

Page 37: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

WWW.FLAC.WSFinish reviewing Chapter 1 of the book and read 2.1 & 2.2 for next time