complexity and computability theory i lecture #8 instructor: rina zviel-girshin lea epstein

43
Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel- Girshin Lea Epstein

Upload: oscar-shelton

Post on 18-Jan-2016

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Complexity and Computability Theory I

Lecture #8

Instructor: Rina Zviel-Girshin

Lea Epstein

Page 2: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 2

Overview

MinimalizationEquivalenceMinimalization algorithmExamples

Page 3: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 3

Example over ={0,1}Consider the following automata that accept L = *.

A: B:

q0

0,1

0,1

q1q0 q0q0

0,1

C:q0

0

0,1

q1q0q1

1

0,1

Page 4: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 4

Minimalization

• Input A DFA A

• Output A DFA B such that L(B)=L(A)

• B accepts the same language A does

• B has a minimal number of states among all DFA’s accepting the language

• Such B will be called the minimal DFA of A.

Page 5: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 5

Minimalization Idea

• We will convert a non minimal DFA into a minimal DFA. 

• What do we mean when we say:

“The automaton is not minimal”.

• That means exist at least two states which can be unified into one. 

Page 6: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 6

Unification• Two states can be unified if they have the same

behavior. • For all possible strings, whether we are in one

state or another, we get the same result – – either both lead to accepting the string (to an

accepting state)

or – both lead to rejection of the string (to a non

accepting state).

Page 7: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 7

Example from real life• An automaton which decides whether to take an

umbrella• We have two states:

– one “there is rain outside” and – another “drops of water are falling from the sky”– then on input “I have to go out”, both will lead to

the same conclusion of the need of umbrella. • Therefore the states can be unified.

Page 8: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 8

Example of automaton

q1

1

1

q3q0

1

0

q2

00

1

0

q0 and q2 have the same behavior.

For each letter go to the same state: for 1 to q3 and for 0 to q1.

Page 9: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 9

Example (cont)

The minimal automaton:

q1

1

q3q0,q2

1

0

0

1

0

Page 10: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 10

State equivalence

• States that have the same behavior and therefore can be united called equivalent states.

• Informally: Two states are equivalent if there is no string

which leads from one to an accepting state and from the other to a non accepting state.

• Formally:Two states p and q are equivalent iff for all w*

’(q,w)F iff ’(p,w)F

Page 11: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 11

Separating words

• If two states p and q are not equivalent then there is a string w which leads from one state to an accepting state and from the other to a non accepting state.

• Such a word w is called a separation word for the two states.

• Either ’(q,w)F and ’(p,w)F

or ’(q,w)F and ’(p,w)F• We can also say that p and q are separated by w.

Page 12: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 12

k-equivalence

• Informally:

Two states p and q are k-equivalent if they have no separating word of length not exceeding k (less or equal k)

 

• Notation: pEkq

Page 13: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 13

Example

• States q0 and q1 are 2-equivalent because the is no separation word of length less or equal 2.

q0E2q1

• But states q0 and q1 are not 3-equivalent because there is a word w=000 that separates them.

’(q0,000)=q3F and ’(q1,000)=q4F

q1 q4q0

0

q2

0

0

q3

0 0

Page 14: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 14

k-equivalence• Formally: Two states p and q are k-equivalent if”f for all

w* such that |w|k ’(q,w)F iff ’(p,w)F

  Other formulations of the same definition.• If there is a separating word its length is greater

than k.• For all words of length not greater than k p and q

are equivalent.

Page 15: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 15

Equivalence of states

• Two states are equivalent if they are k-equivalent for all k.

 or

• There is no separating word of any length between the states.

 

Page 16: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 16

Example • In this example q0 and q2 are equivalent because after first letter of the word they go to the same state.

q1

1

1

q3q0

1

0

q2

00

1

0

• That means that for each word with length greater than 1 they behave in the same way.

Page 17: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 17

Example

q1

1

1

q3q0

1

0

q2

00

1

0

• So there is no separation word of any length between q0 and q2.

Page 18: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 18

Terminology

• We will use the term set of states Q for the set of all states of an automaton.

• The “clusters” of an equivalence relation states are called classes.

• Q can be divided into classes of states. • In previous example:

{q0,q2} is called a class.

Page 19: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 19

Minimalization algorithm technique

• The minimalization algorithm will use the dynamic programming technique.

• We will incrementally separate the set of states into equivalent subsets using k equivalence.

Page 20: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 20

Minimalization algorithm technique (cont.)

• Step by step we will find whether there is a separating word of the class and divide the class which it separates into subclasses.

• At each step we will increase the length of separating word starting with 0.

• At each step we will use the result of the previous step and apply a simple checking mechanism on the classes derived in the previous step.

Page 21: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 21

Example

• There is a word of length 0 that separates between q0 and q1,q2.

• So we can divide the Q into two classes: {q0},{q1,q2}.

q1

q00

0,1

1

q2

q0

0,1

Page 22: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 22

Example (cont.)

• The class with only one state can't be divided into subclasses.

• But the class with more than one state can be divided. So lets check the class {q1,q2}.

q1

q00

0,1

1

q2

q0

0,1

Page 23: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 23

Example (cont.)

• For any word of length equal to 1 both of them lead to the same state q0.

• So there is no separation word between q1 and q2.• That means that they are 1-equivalent.

q1

q00

0,1

1

q2

q0

0,1

Page 24: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 24

Example (cont.)

• The classes of Q remain the same: {q0},{q1,q2}.

• So it is a final partition of Q.

q1

q00

0,1

1

q2

q0

0,1

Page 25: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 25

Example (cont.)

• The minimal automaton has two states {q0},{q1,q2}.

q1,q2q0

0,1

0,1q0

Page 26: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 26

When to stop?

• When do we stop to compute Ei?• When there is no difference between the

equivalent subsets of the last two states: Ek=Ek+1.

• Why?• Because for each letter of we go to

equivalent classes.

Page 27: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 27

TheoremIf Ek=Ek+1 then Ek+1=Ek+2.

Proof:

• Assume that Ek=Ek+1 and prove that for any pair of

states p and q pEk+1q iff pEk+2q.

• If pEk+2q then pEk+1q .If there is no separation

word of length k+2 so there is obviously no separation word of length less than k+2.

Page 28: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 28

TheoremIf Ek=Ek+1 then Ek+1=Ek+2.

Proof (cont.)• pEk+1q means that pEkq and for each

(p,)Ek(q,).

• We know that Ek=Ek+1.

• So we know that pEk+1q and for each (p,)Ek+1(q,). That means that pEk+2q.

Page 29: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 29

Theorem conclusion

Conclusion:

• The computation of equivalence states stops when Ek=Ek+1.

Page 30: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 30

Minimalization algorithm

Input: A DFA A.Output:

A minimal state DFA B. 1. Divide Q into two subsets:

• final states F and• non final states Q-F.

Page 31: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 31

Minimalization algorithm (cont.)

2. While in the previous step a change was made do at step j+1

for each j-equivalence class C (subset in the previous step)

for each pair of states p and q in C for each

if (p,) is not j-equal to (q,) than divide C into classes in such way that p and q will

be in different classes.

Page 32: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 32

Minimalization algorithm (cont.)

3. The set of the states in B is the set of classes resulting from the step 2.

4. The starting state of B will be the class that includes the starting state of A.

5. The final states of B will be the classes including final states of A.

6. Transition function of B: for each state P in B and

(P,)=R if for all pP A(p,)R.

Page 33: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 33

Example • Construct a minimal DFA equivalent to a

given DFA: q1q0

0

0

1

q2

q0

0

q0q3

1 0,1

1

Page 34: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 34

Example (cont.)E0={{q0,q3}, {q1,q2}}

E1=E0

q1q0

0

0

1

q2

q0

0

q0q3

1 0,1

1

Page 35: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 35

Example (cont.)

So the minimal DFA is:

q1,q2q0

0,1

0,1

q0,q3

Page 36: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 36

Another example • Construct a minimal DFA equivalent to a given

DFA

q1b

a

q2

q0 q0q3 q4

a

b

a

b

a

a

a,b

b

Page 37: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 37

Another example (cont.) 1. First lets find the states that are 0-equivalent:

E0 = { F, Q-F} = { {q4}, {q0,q1,q2,q3}}

q1b

a

q2

q0 q0q3 q4

a

b

a

b

a

a

a,b

b

Page 38: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 38

Another example (cont.) 2. Now we find the states that are 1-equivalent.

The only class that can be divided is {q0,q1,q2,q3}.

E1 a b

q0 q2 q1

q1 q3 q1

q2 q3 q2

q3 q3 q4

Page 39: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 39

Another example (cont.) • So for the word w=a all the states go to the same

class in E0. • Another word of length 1 is w=b. • We can see that {q0,q1,q2} go to the same class in

E0 and q3 goes to the other class. • So q3 should be separated from other states in its

class.• The separation word is b. • The result is:

E1 = { {q4}, {q3}, {q0,q1,q2}}

Page 40: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 40

Another example (cont.) 3. Now we find the states that are 2-equivalent. The only class that can be divided is {q0,q1,q2}.

E1 ab

q0 q2

q1 q4

q2 q4

So q0 san be separated from q1,q2.

E2 = { {q4}, {q3}, {q0}, {q1,q2}}

ab is a separating word

Page 41: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 41

Another example (cont.)

4. Now we find the states that are 3-equivalent.• The only class that can be divided is {q1,q2}.• It can't be divided. • Over a q1,q2 both go to q3 and than behave the

same way.• Over b each of them stay in the same non

accepting state.• So E2=E3= { {q4}, {q3}, {q0}, {q1,q2}}.

Page 42: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 42

Another example (cont.)

The resulting automaton is:

q1,q2a,bq0 q0q3 q4a

b a

a

a,b

Page 43: Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 43

Any Questions?