430 likes | 440 Views
Learn how to minimize automata to optimize efficiency in language recognition. Understand equivalence, unification, and algorithms for minimalization, presented with real-life examples. Discover the terminology and techniques involved.
E N D
Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein
Overview • Minimalization • Equivalence • Minimalization algorithm • Examples Rina Zviel-Girshin @ASC
Example over ={0,1} Consider the following automata that accept L = *. A: B: C: Rina Zviel-Girshin @ASC
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. Rina Zviel-Girshin @ASC
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. Rina Zviel-Girshin @ASC
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). Rina Zviel-Girshin @ASC
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. Rina Zviel-Girshin @ASC
Example of automaton q0 and q2 have the same behavior. For each letter go to the same state: for 1 to q3 and for 0 to q1. Rina Zviel-Girshin @ASC
Example (cont) The minimal automaton: Rina Zviel-Girshin @ASC
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 Rina Zviel-Girshin @ASC
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. Rina Zviel-Girshin @ASC
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 Rina Zviel-Girshin @ASC
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 Rina Zviel-Girshin @ASC
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. Rina Zviel-Girshin @ASC
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. Rina Zviel-Girshin @ASC
Example • In this example q0 and q2 are equivalent because after first letter of the word they go to the same state. • That means that for each word with length greater than 1 they behave in the same way. Rina Zviel-Girshin @ASC
Example • So there is no separation word of any length between q0 and q2. Rina Zviel-Girshin @ASC
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. Rina Zviel-Girshin @ASC
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. Rina Zviel-Girshin @ASC
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. Rina Zviel-Girshin @ASC
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}. Rina Zviel-Girshin @ASC
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}. Rina Zviel-Girshin @ASC
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. Rina Zviel-Girshin @ASC
Example (cont.) • The classes of Q remain the same: {q0},{q1,q2}. • So it is a final partition of Q. Rina Zviel-Girshin @ASC
Example (cont.) • The minimal automaton has two states {q0},{q1,q2}. Rina Zviel-Girshin @ASC
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. Rina Zviel-Girshin @ASC
Theorem If 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. Rina Zviel-Girshin @ASC
Theorem If 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. Rina Zviel-Girshin @ASC
Theorem conclusion Conclusion: • The computation of equivalence states stops when Ek=Ek+1. Rina Zviel-Girshin @ASC
Minimalization algorithm Input: A DFA A. Output: A minimal state DFA B. • Divide Q into two subsets: • final states F and • non final states Q-F. Rina Zviel-Girshin @ASC
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. Rina Zviel-Girshin @ASC
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. Rina Zviel-Girshin @ASC
Example • Construct a minimal DFA equivalent to a given DFA: Rina Zviel-Girshin @ASC
Example (cont.) E0={{q0,q3}, {q1,q2}} E1=E0 Rina Zviel-Girshin @ASC
Example (cont.) So the minimal DFA is: Rina Zviel-Girshin @ASC
b Another example • Construct a minimal DFA equivalent to a given DFA Rina Zviel-Girshin @ASC
b Another example (cont.) 1. First lets find the states that are 0-equivalent: E0 = { F, Q-F} = { {q4}, {q0,q1,q2,q3}} Rina Zviel-Girshin @ASC
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}. Rina Zviel-Girshin @ASC
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}} Rina Zviel-Girshin @ASC
Another example (cont.) 3. Now we find the states that are 2-equivalent. The only class that can be divided is {q0,q1,q2}. ab is a separating word So q0 san be separated from q1,q2. E2 = { {q4}, {q3}, {q0}, {q1,q2}} Rina Zviel-Girshin @ASC
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}}. Rina Zviel-Girshin @ASC
Another example (cont.) The resulting automaton is: Rina Zviel-Girshin @ASC
Any Questions? Rina Zviel-Girshin @ASC