210 likes | 354 Views
ECE465. FSM State Minimization for Completely Specified Machines Shantanu Dutt. Acknowledgement: Slides prepared by Huan Ren from Prof. Dutt’s Lecture Notes. A. C. Reset. 0 (even). 1 (odd). B. D. State Minimization of Seq. Ckts. Removal of redundant states Important because:
E N D
ECE465 FSM State Minimization for Completely Specified Machines Shantanu Dutt Acknowledgement: Slides prepared by Huan Ren from Prof. Dutt’s Lecture Notes
A C Reset 0 (even) 1 (odd) B D State Minimization of Seq. Ckts. • Removal of redundant states • Important because: • Cost(a), # of FFs # of states • Cost(b), logic complexity # of states • Easiest to diagnose faulty if there are no redundant states • Example: Odd-parity detection 0/1 Reset 1/1 1/1 Can this sub-optimal design be corrected by systematic techniques? 1/0 0/0 0/0 1/0 1/0 0/0 0/1 1/1 0/1 Minimal FSM Non-minimal FSM
2-equiv. Definitions • Two states Si and Sj are 1-equivalent, if any input sequence (can be multiple bits) of length 1 produce identical output responses. • Two states Si and Sj are k-equivalent, if any input sequence of length k produce identical output sequences. • Example 1
3-equiv. Examples (contd.) • Example1 (contd.)
0/1 1/1 A C 1/0 2-equiv. 0/0 0/0 B D 1/0 1/1 0/1 Examples (contd.) • Example 2: Parity detection R
Definitions (Contd.) • States Si,……,Sj of a seq. ckt. are said to be equivalent if and only if for every possible i/p seq. of any length, the o/p’s produced by the ckt will be identical irrespective of whether the ckt is in states Si,……,Sj when the i/p seq. starts. Si,……,Sj are k-equivalent for all k • Alternative (and more practical!) definition for equivalence: • Si and Sjare equiv. if and only if for every possible i/p Ip of length 1 • (i) The o/p’s produced by states Si= o/p’s produced by Sj. • (ii) The next states Skfor Si and Slfor Sj are equivalent. This is a recursive definition that helps in detecting more equiv. states once some sets of equiv. states are detected.
Equiv. Ip1/Op1 Si Sj … Ip1/Op1 … Equiv. Sk1 Sk2 Sl1 Sl2 Equiv. O/P O1 O2 O1 O2 Same Definitions (Contd.) • The second definition is the same as the first one • Necessity for (i) is clear • Necessity for (ii), let Sk, Sl not be equivalent => There is an input seq. I1,……,It that produces different o/p’s starting from states Sk and Sl => The seq. Ip, I1,……,It produces diff. o/p starting from Si and Sj => Si, Sjare not equiv. • Consider any i/p seq Ip, I1,……,It • After recv’ing Ip Si & Sj produce the same o/p and fo to equiv states (by defn) Skp & Slp • Since Skp & Slp are equiv states, seq I1,……,Itwill produce identical o/ps from either state • Thus Si & Sj produce identical o/ps for any arbitrary seq, and are thus equivalent • Sufficiency
Definitions (Contd.) • For a set S of elements, a binary relation R is a set of ordered pairs (Si, Sj) s.t. Si, Sj belong to S, and SiΔSj, where Δ is the property represented by R • A relation R on elements of S is reflexive if xΔx e.g., Δ is ≤ • A relation R on elements of S is symmetricif xΔy => yΔx e.g., Δ is = • A relation R on elements of S is transitiveif xΔy and yΔz => xΔz e.g., ≤ and = • A relation R on elements of S is equivalentif it is reflexive, symmetric and transitive. Example: Blood-relation • A relation R is a compatibility relation if it is reflexive and symmetric. Example: Friendship
Definitions (Contd.) • Note 1: If there is an equivalence relation R on a set S, the the elements of S can be partitioned into disjoint subsets called equivalence classes, where elements in each subset are related to each other by relation R: Important concept for completely specified FSMs • Note 2: If there is a compatibility relation R on a set S, then R defines subsets of S referred to as compatibility classes (the elements in a subset Si are related to each other by R). These subsets are not disjoint, in general. Important concept for incompletely specified FSMs Compatibiity classes may intersect Equivalent classes are disjoint
Minimization Method for Completely Specified FSMs • Two methods. Partitioning and Implication Table • Partitioning steps Use condition (i) of the alternative equivalency defn to determine initial partition P0=subsets/blocks of 1-equiv. states; /* k-equivalency & equivalency are equivalence classes */ i=0; Repeat i=i+1 For each subset/block Cj in Pi do Begin Two or more states in Cj are placed in the same block of Pi+1 iff for each I/P value of length 1 their next states lie in the same block of Pi End Pi+1=set of all new blocks created. Until (Pi+1=Pi)/* Note: this uses condition (ii) of the alternative equivalency defn to construct equivalent state sets */
Partitioning Method • Let Pk be the final partition • Pk is an equivalence relation. • All blocks in Pk contain equivalent sets • Eliminate all but one state in each block Ci denoted repr(Ci) of Pk and reduces the FSM as follows • A) For arc(s) from states in Ci to a state in Cj, draw an arc with same labels from repr(Ci) to repr(Cj) • b) Resulting FSM is minimized.
A1 A2 B1 B2 Partitioning Method • Lemma 1: If there are two states that are k-equiv. but not (k+1)-equiv then the algorithm will detect this in iteration k • Proof by induction • Basis: not 1-equiv. is caught at iteration 0 • Hypothesis: True for k=m • To prove for k=m+1, use property: If two states A1 and B1 are (m+1) but not (m+2) equiv., at least one of their N.S. pairs (A2, B2) has to be m equiv. but not (m+1)-equiv. • Hence, A2 and B2 are in diff. blocks of Pm according to the hypothesis • Thus, by the procedure, A1 and B1 will be in diff. blocks of Pm+1 at the end of iteration m+1. m equiv. m 1 equiv. Am+1 Bm+1 Am+2 Bm+2
Partitioning Method • Theorem 1: All blocks only contain equivalent states after the algorithm terminates. • Proof: Assume the program terminates at iteration k • Following lemma 1, if two states are not j equiv. for j≤k, they are put into different blocks. • Since Pk+1=Pk, for any further iteration j (j>k), the partition will not change . • For any two states not j-equiv. for j>k, they will be put in two blocks in iteration j, and hence also in iteration k. Thus all states in a block are equivalent. • Theorem 2: All equivalent states are in the same blocks (number of blocks are minimized), i.e., 2 equivalent states will not be in different blocks, • Proof by induction of # of iterations to stop • Basis: True for iter. 1. • Hypothesis: True for iter. l • Proof for iter. l+1: if Si and Sj are equiv., their next states are also equiv., and hence in the same block in iter l by hypothesis. • Therefore, Si and Sj are put in the same block in iter. l+1
P1=(A,B) (C,D) A C Reset A D B D Partitioning Method Example 0/1 1/1 P0=(A,B) (C,D) 1/0 0/0 0/0 P1=(A,B) (C,D) No change from P0; stop 1/0 1/1 0/1 Non-minimal STD 1/1 1/0 0/0 0/1 Minimal STD
P0=(A,B,C) (D,E) Need to check for each I/P of length 1 X=0 C C B D E X=1 B E E B A N.S.’s P1=(A) (B,C) (D,E) N.S. will not change, but whether N.S.’s belong to same blocks will X=0 C B D E X=1 E E B A 0 1 P2=(A) (B,C) (D) (E) X=0 C B X=1 E E A B/1 B/0 B B/1 E/0 D D/0 B/1 E E/0 A/1 Partitioning Method Example 0 1 A C/1 B/0 B C/1 E/0 C B/1 E/0 D D/0 B/1 E E/0 A/1 P4=(A) (B,C) (D) (E)
State Minimization (Contd.) • Definition • Implication Table • Implied pairs of a pairs of states Si, Sj is a pair of states Sk,Sl which are N.S.’s of Si and Sj for the same 1-length I/P Ip • Implication Table Procedure (good manual method for small problems) • Step 1: Form an implication table (a diag’ed square) by vertically listing all states except the first, and horizontally listing all states except the last. 0 1 • Step 2: Put X’s for state pairs in the table that are not 1- equiv. A C/1 B/0 B C/1 E/0 C B/1 E/0 D D/0 B/1 E E/0 A/1
BE BCBE AB Implication Table Procedure • Step 3: Use condition (ii) for equiv. states for other squares. • a) Put a ‘\/’ mark if the implied pairs in a cell: • either contains only the states that define the cell • or is the same state (e.g., (E,E)) • Step 3: Use condition (ii) for equiv. states for other squares. • b) For the remaining cells, write all implied pairs of the states defining the cell that not meet the above two conditions 0 1 B A C/1 B/0 C B C/1 E/0 C B/1 E/0 D D D/0 B/1 E E E/0 A/1 A B C D
Implication Table Procedure • Step 4: • Repeat • Put a mark ‘\/’ if all implied pairs have the mark ‘\/’ in their cell • Put a X if any implied pair has an X in its cell • Until no change. • Step 5: Remaining cells (w/ only implied states or ‘\/’) are equiv. • Step 6: For every closed system (see defn in next slide) of implied pairs w/ neither ‘\/’ nor X marks in them, put a ‘\/’ mark in each cell in this cycle • Form the largest equivalent sets by transitivity (Si, Sj) and (Sj, Sk)=>(Si, Sj, Sk) Note: (Si, Sk) will also be equivalent from the implication table, since “equivalent” is an equivalence relation
AD BE CF D BE E ADCF F AD G H CHBG A B C D E F G Implication Table Example B C A closed system of state pairs w/ implication arcs • An implication arc • AD BE means the AD state pair is equivalent if the BE state pair is equivalent • A closed system of state pairs is a group of state pairs s.t.: • (a) there is a directed path betw. any 2 state pairs, and • (b) there are no outgoing arcs from any state pair to another state pair outside this group Equiv. Classes: (AD) (BE) (CF) (G) (H)
AF BDAF DFAF DF BD DGAF BGAF DGAF BCAF BC BCDF B C D E F G Equivalence classes: (AF) (BC)(BH)=(BCH) (D) (E) (G) H A B C D E F G