Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE465 FSM State Minimization for Completely Specified Machines Shantanu Dutt Acknowledgement: Slides prepared by Huan Ren from Prof. Dutt’s Lecture Notes.

Similar presentations


Presentation on theme: "ECE465 FSM State Minimization for Completely Specified Machines Shantanu Dutt Acknowledgement: Slides prepared by Huan Ren from Prof. Dutt’s Lecture Notes."— Presentation transcript:

1 ECE465 FSM State Minimization for Completely Specified Machines Shantanu Dutt Acknowledgement: Slides prepared by Huan Ren from Prof. Dutt’s Lecture Notes (some modifications made by Prof. Dutt)

2 State Minimization of Seq. Ckts. Removal of redundant states Important because: Cost(a): # of FFs # of states Cost(b): logic complexity # of states Easier to diagnose faults if there are no redundant states Example: Odd-parity detection 0 (even)1 (odd) Reset 1/1 1/0 A B C D 0/00/1 1/1 1/0 0/0 1/0 1/1 0/1 Minimal FSM Non-minimal FSM Can this sub- optimal design be corrected by systematic techniques? Reset

3 Definitions Two states S i and S j are 1-equivalent, if any input sequence (can be multiple bits) of length 1 produce identical output responses. Two states S i and S j are k-equivalent, if any input sequence of length k produces identical output sequences. Example 1 01 AC/1B/0 BC/1E/0 CB/1E/0 DD/0B/1 EE/0A/1 Initial State. Input sequence A B C D E equiv.

4 Examples (contd.) Example1 (contd.) Init. St. Input sequence A B C D E equiv. General formulation for number of i/p sequence of length k for m i/p bits: 2 mk

5 Examples (contd.) Example 2: Parity detection A B C D 1/1 1/0 0/0 1/0 1/1 0/1 Init. st. Input Sequence A B C D equiv. R

6 Definitions (Contd.) Basic Definition: States S i,……,S j 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 S i,……,S j when the i/p seq. starts.  S i,……,S j are k-equivalent for all k Alternative (and more practical!) definition for equivalence: S i and S j are equiv. if and only if for every possible i/p I p of length 1 (i) The o/p’s produced by states S i = o/p’s produced by S j. (ii) The next states S k for S i and S l for S j are equivalent. Definition: Implied pairs (or implied next-state [NS] pairs) of a pair of states S i, S j is a pair of states S k,S l which are N.S.’s of S i and S j for the same 1-length I/P I p This is a recursive definition that helps in detecting more equiv. states once some sets of equiv. states are detected. SiSi SjSj SkSk SlSl 0/1 SpSp SqSq 1/0 Implied pairs of S i, S j Implied pairs of S i, S j

7 Equivalent State Detection Using the 2 nd State Equiv Defn Idea 1: Using defn. 2’s negation—Si, Sj are non-equiv. if any of their implied pairs are not equiv. (i.e., not k-equiv. for some k), iteratively find non-equiv state pairs Stop when no more non-equiv state pairs cannot be found The remaining state pairs are equivalent (a la Sherlock Holmes!—after all alternatives are eliminated the remaining possibility has to be correct, however, implausible it may seem to be) This is the partitioning method Idea 2: Bootstrap the equiv state-pair finding process by finding a base & easy-to- detect-&-verify pattern that implies equivalency, e.g., see the foll. pattern which implies equiv. of states B and C: Use these initial pair of equiv states to determine other equiv state pairs using defn. 2. This is the implication table method B C State pair 0/1 E 1/0

8 Definitions (Contd.) The second definition is the same as the first one Necessity for (i) is clear Necessity for (ii), let S k, S l not be equivalent => There is an input seq. I 1,……,I t that produces different o/p’s starting from states S k and S l => The seq. I p, I 1,……,I t produces diff. o/p starting from S i and S j => S i, S j are not equiv. Sufficiency SiSi Sk1Sk1 I p 1 /O p 1 O/P O 1 Sk2Sk2 O2O2 SjSj Sl1Sl1 I p 1 /O p 1 O1O1 Sl2Sl2 O2O2 … … Same Equiv. Consider any i/p seq I p, I 1,……,I t After recv’ing I p S i & S j produce the same o/p and fo to equiv states (by defn) S k p & S l p Since S k p & S l p are equiv states, seq I 1,……,I t will produce identical o/ps from either state Thus S i & S j produce identical o/ps for any arbitrary seq, and are thus equivalent

9 Definitions (Contd.) For a set S of elements, a binary relation R is a set of ordered pairs (S i, S j ) s.t. S i, S j belong to S, and S i ΔS j, where Δ is the actual relation represented by R A relation R on elements of S is reflexive if xΔx, e.g., Δ is ≤, state equivalency (SE) A relation R on elements of S is symmetric if xΔy  yΔx, e.g., Δ is =, SE A relation R on elements of S is transitive if xΔy and yΔz  xΔz e.g., ≤, SE A relation R on elements of S is equivalent if it is reflexive, symmetric and transitive. Example: sibling relationship, =, SE A relation R is a compatibility relation if it is reflexive and symmetric. Example: friendship, gcd (greatest common divisor) > 1

10 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—each equiv. class of equiv. state does not conflict w/ any other class, and thus can replace each equiv. class in a well-defined way by a single state 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 S i are related to each other by R). These subsets are not disjoint, in general. Important concept for incompletely specified FSMs—need to find maximal set of mutually compatible states for maximum reduction in the # of states Equivalent classes are disjoint Compatibiity classes may intersect

11 Minimization Method for Completely Specified FSMs Two methods. Partitioning and Implication Table The Partitioning Method: Use condition (i) of the alternative equivalency defn to determine initial partition P 1 =subsets/blocks of 1-equiv. states; /* k-equivalency & equivalency are equivalence classes */ i=0; Repeat i = i+1; For each subset/block C j in P i do Begin Two or more states in C j are placed in the same block of P i+1 iff for each I/P value of length 1 their next states lie in the same block of P i. Otherwise, the relevant states are separated into diff. blocks based on where their next states lie. End P i+1 =set of all new blocks created. /* each bl. contains (i+1)-equiv states */ Until (P i =P i+1 ) /* Note: this uses condition (ii) of the alternative equivalency defn to construct equivalent state sets */

12 Partitioning Method (contd) Let P k be the final partition P k is an equivalence relation. All blocks in P k contain equivalent sets Eliminate all but one state in each block C i denoted repr(C i ) of P k and reduces the FSM as follows A) For arc(s) from states in C i to a state in C j, draw an arc (w/ the same input/output values) with same labels from repr(C i ) to repr(C j ). Do not duplicate arcs. b) Resulting FSM is minimized.

13 Partitioning Method: Example 1 A B C D 1/1 1/0 0/0 1/0 1/1 0/1 Non-minimal STD P 1 =(A,B) (C,D) P 2 =(A,B) (C,D) No change from P 1 ; stop AD Reset 1/1 1/0 0/00/1 Minimal STD P 1 =(A,B) (C,D) X=0: NS: B A C D X=1: NS: C D A B

14 Partitioning Method: Example 2 A/1E/0E B/1D/0D E/0B/1C E/0C/1B B/0C/1A 10 P 1 =(A,B,C) (D,E) X=0 C C B D E X=1 B E E B A N.S.’s Need to check for each I/P of length 1 P 2 =(A) (B,C) (D,E) X=0 C B D E X=1 E E B A N.S. will not change, but whether N.S.’s belong to same blocks will P 4 =(A) (B,C) (D) (E) = P 3 X=0 C B X=1 E E P 3 =(A) (B,C) (D) (E) A/1E/0E B/1D/0D E/0B/1B B/0B/1A 10

15 Partitioning Method—Why It works (basic idea)? Lemma 1: If there are two states A1, B1 that are k-equiv. but not (k+1)-equiv then the algorithm will detect this in iteration k Proof: By definition of (k+1)-equivalency, A1, B1 will have at least one implied next-state pair (A2, B2) that are (k-1)-equiv but not k-equiv (otherwise A1, B1 will be (k+1)-equiv.)  In iteration k, A2, B2 will be in diff. blocks (assuming lemma true for smaller values of k—proof by induction)  this will be detected in iter. k, and A1, B1 will thus be separated in diff. blocks at the end of iter. k. Theorem 1: All blocks contain equivalent states after the algorithm terminates. Proof: Suppose not for 2 states X, Y that are in the same block when algo terminates, and let algo terminate in iter. m.  By Lemma 1, X, Y are at least m-equiv.  By our assumption, then there must be a j >= m s.t.. X, Y are j-equiv but not (j+1)-equiv.  By Lemma 1, the algo will catch this in iter. j.  By Lemma 1, if we run the algo up to iter. j, the algo will separate X, Y in separate blocks in this iter. However, algo terminated in iter. m means Pm = Pm+1.  If we run the algo for more iterations, its partition input remains unchanged compared to iter. m, and it will thus producing the same result as iter. m  We will get:: Pm = Pm+1 = Pm+2 = ……. = Pj+1.  Thus X,Y remains in the same block in iter. j  X, Y are (j+1)-equiv and we reach a contradiction w/ our assumption.  Theorem 1 has to be true A1A1 A2A2 B1B1 B2B2 (k-1)-equiv, but not k-equiv. k-equiv, but not (k+1)-equiv.

16 Partitioning Method—Why It works? (detailed proofs) 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 (k=0): Not 1-equiv. is caught at iteration 0 (before iteration 1, i.e., when forming P 1 ) Hypothesis: True for k=m To prove for k=m+1: Use property: If two states A 1 and B 1 are (m+1)-equiv but not (m+2)-equiv., at least one of their N.S. pairs (A 2, B 2 ) has to be m-equiv. but not (m+1)-equiv. Can be easily proved by contradiction—do as an exercise. A1A1 A2A2 A m+1 A m+2 B1B1 B2B2 B m+1 B m+2 m equiv. 1 equiv. m Hence, by ind. hypothesis, A 2 and B 2 are in diff. blocks of P m+1 (i.e., their non-(m+1)-equiv. is detected in iter m) according to the hypothesis Thus, by the procedure, A 1 and B 1 will be in diff. blocks of P m+2 at the end of iteration m+1, i.e., their non-(m+2)- equiv is detected in iter m+1 not 1 equiv.

17 Partitioning Method (contd) Theorem 1: All blocks contain equivalent states after the algorithm terminates. Proof: Assume the program terminates at iteration m Following lemma 1, if two states are not i-equiv. for I ≤ m, they are put into different blocks. Since P m+1 =P m, for any future iteration j (j>m), i.e., if we were to run the procedure up to iteration j, the partition will not change: we will get P m = P m+1 = P m+2 = …… = P j If any two states in P k are not equiv  they are not j-equiv. for j > m, they will be put in two blocks in iteration j > m  procedure will continue till at least iteration j >m  P m+1 != P m, (otherwise the partitions will never change after P m ) and we reach a contradiction. Thus all states in a block are equivalent. Theorem 2: All equivalent states are in the same blocks, i.e., two equivalent states will not be in different blocks. Proof Outline: Follows from the procedure: If two states are in different blocks, then they were detected as not k-equivalent for some k, and thus are not equivalent. Thus no 2 equivalent states can be in different blocks after the procedure terminates. Hence each block will contain the maximal set of equivalence states, i.e., each block is an equivalence class

18 State Minimization—Implication Table Method Definition Implied pairs of a pair of states S i, S j is a pair of states S k,S l which are N.S.’s of S i and S j for the same 1-length I/P I p Implication Table Procedure (good manual method for small problems) Step 1: Form an implication table (a diagonaled square) by vertically listing all states except the first, and horizontally listing all states except the last. A/1E/0E B/1D/0D E/0B/1C E/0C/1B B/0C/1A 10 B C D E ABCD Step 2: Put X’s for state pairs in the table that are not 1- equiv.

19 Implication Table Procedure Step 3: Use cond. (ii) of defn. 2 for equiv. states for other squares. A/1E/0E B/1D/0D E/0B/1C E/0C/1B B/0C/1A 10 DCBA E D C AB BC BE BEB Step 3: 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))—singleton states b) For the remaining cells, write all implied pairs (do not include the same state pair and singleton states as they do not contribute to non-equivalency) of the states defining the cell that not meet the above two conditions B C State pair 0/1 E 1/0

20 Implication Table Procedure (contd) 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. Note: Cells w/ only implied pairs form closed systems (see defn in next slide) of implied pairs w/ neither ‘\ / ’ nor X marks in them. I/Ps to any state pairs in this system will either: remain in the closed system producing identical o/ps (since these state pairs are at least 1-equivalent) or go out of the system to either: (a) singleton states o (b) equivalent states, and from thereon also produce identical o/ps. Thus these state pairs are equivalent. Form the largest equivalent sets by transitivity: (S i, S j ) and (S j, S k )=>(S i, S j, S k ) Note: (S i, S k ) will also be equivalent from the implication table, since “state equivalence” is an equivalence relation A3B3A3B3 AB A1B1A1B1 A2B2A2B2 Equiv. states (a) Equiv. states Non-equiv states UV U1V1U1V1 U2V2U2V2 X (b) A1,B1 E,E C,D Closed System Equiv. states Singleton state Implication arc (c) A2,B2 A3,B3 A4,B4 X,Y Equiv. states

21 Implication Table Procedure A/1E/0E B/1D/0D E/0B/1C E/0C/1B B/0C/1A 10 DCBA E D C AB BC BE BEB X X X Only B, C are equivalent. Choose B as the repr. of (B,C) A/1E/0E B/1D/0D E/0B/1B B/0B/1A 10

22 Implication Table Example (contd) 01 AE/0D/0 BA/1F/0 CC/0A/1 DB/0A/0 ED/1C/0 F D/1 GH/1G/1 HC/1B/1 (AD) (BE) (CF) (G) (H) C B GFEDCBA H G F E CH BG AD AD CF BED AD BE CF A closed system of state pairs w/ implication arcs An implication arc AD  BE means BE is the implied state pair of AD 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 in the group to a state pair outside this group that is not the same state or equiv states Equiv. Classes: X

23 BC DF BCBC AF DG AF BG AF DG AF BD DFDF AF BD AF AF AD/0 F/0A/0 BC/1D/0E/1F/0 CC/1D/0E/1A/0 DD/0B/0A/0F/0 EC/1F/0E/1A/0 FD/0 A/0F/0 GG/0 A/0 HB/1D/0E/1A/0 GFEDCBA H G F E D C B Equivalence classes: (AF) (BC)(BH)=>(CH) => (BCH) (D) (E) (G)

24 AD/0 F/0A/0 BC/1D/0E/1F/0 CC/1D/0E/1A/0 DD/0B/0A/0F/0 EC/1F/0E/1A/0 FD/0 A/0F/0 GG/0 A/0 HB/1D/0E/1A/0 Equivalence classes: (AF) (BC)(BH)=>(CH) => (BCH) (D) (E) (G) AD/0 F/0A/0 BB/1D/0E/1A/0 DD/0B/0A/0F/0 EB/1A/0E/1A/0 GG/0 A/0 Choose B as the repr. of (BCH) & A as repr. of (A F)

25 Backup BDD CDDAF DDDBDAF EDDDFAFDF FDDBD GDDDGAFBGAFDGAF HDDBCAFBCBCDF ABCDEFG


Download ppt "ECE465 FSM State Minimization for Completely Specified Machines Shantanu Dutt Acknowledgement: Slides prepared by Huan Ren from Prof. Dutt’s Lecture Notes."

Similar presentations


Ads by Google