Download presentation
Presentation is loading. Please wait.
Published byDewi Johan Modified over 6 years ago
1
Single Function Quine-McCluskey 2-Level Minimization
Shantanu Dutt University of Illinois at Chicago Acknowledgement: Transcribed to Powerpoint by Huan Ren from Prof. Shantanu Dutt’s handwritten notes (later added to significantly by Shantanu Dutt)
2
Basic Two-Level Minimization Steps
The basic steps are the same for K-Map and Quine McCluskey (QM): Form all PIs Determine a minimum cost set of PIs to cover all minterms (MTs) Determine EPIs, include them in the final expression and delete all MTs they cover Determine a min cost set of the remaining PIs to cover the remaining MTs. This is a really hard problem—NP-hard, i.e., to solve it optimally it takes a worst-case computation time that is exponential in the # of non-essential PIs.
3
QM: Forming all PIs using the Tabular Method
Step 1 G0 G1 G2 G3 Form groups Gi of MTs/DCs, w/ a MT/DC belonging to Gi if it has i 1’s in its binary (0, 1) or ternary (0, 1, - or x) representation. Note that 0 <= i <= n (the # of variables). Place the groups Gi’s in “rows” with increasing order of i. For each MT/DC a in Gi, look for MTs/DCs b that it has logical adjacency with (so that they can be combined to form a larger implicant) only in Gi+1. If such a MT/DC b found in Gi+1, then the larger implicant (a, b) covers both a and b, which need to tick mark both a, b to indicate this. Steps 1-3 are repeated in each subsequent “column” of larger implicants, as shown. The process stops when for the current col. no adjacent implicants are found, so no larger implicants can be formed. The implicants that are not tick-marked are PIs as they are not covered by any other implicant.
4
# of 1’s Impl. (MT/DC list) ABCD Diff. set G1 PI1 1,3 00x 1,5 0x 1,9 x 2,3 001x 1 2,6 0x 8,9 100x 1 G2 3,7 0x 5,7 01x 5,13 x 6,7 011x 1 9,13 1x # of 1’s MT/ DC ABCD G1 1 0001 2 0010 8 1000 G2 3 0011 5 0101 6 0110 9 1001 G3 7 0111 13 1101 Tricks for quick PI formation G1 Impl. (MT/DC list) ABCD Diff. set PI2 1, 3 5, 7 0xx1 2,4 PI3 1, 5 9,13 xx01 4,8 PI4 2, 3 6, 7 0x1x 1,4 Necessary (but not sufficient) conditions for combining 2 implicants to form a larger implicant that covers them (if the conditions are met, only then do we need to look at the ternary notations to determine combinability): Two MTs in only adj. groups can be combined only if their integer values differ by a power of 2. Two implicants in adj. groups can be combined only if their difference sets are the same and the pairwise absolute differences of their MT/DC list arranged in increasing order are the same and a power of 2 (e.g.: (i) g=(1,3), h=(5,7), DS for both is {2} & |(1,3)-(5,7)| = (4,4). Thus g,h may be combinable (but this is not a sufficient cond. and need to then look at their ternary notation), and from their ternary notation, they are. The # 4 from |g-h| is added to the diff. set of the combined implicants to obtain the diff. set {2, 4} of the larger implicant. (ii) g=(3,7), h=(9,13), DS for both is {4}, |(3,7)-(9,13)| = (6,6) and thus g,h are not combinable—same #’s in the g - h vector, but they are not a power of 2.
5
QM: The PI Table (PIT)—Min-Cost MT Covering
Inclusion removal/deletion: Removal of those PIs from the PIT that are to be included in the final expr. Thus the MTs they cover are also removed. * is used to indicate inclusion deletions (i.e. for EPIs and pseudo-EPIs—see later for definition); these are PIs included in the final minimized expression
6
QM: The PIT—Min-Cost MT Covering (cont.)
Exclusion removal/deletion: Removal of those PIs (via covering) from the PIT that are not to be included in the final expr. Thus the MTs they cover are not removed. Note: Some other PIs in the previous PIT, e.g., (0,4), were excl. deleted as they covered no MTs in the reduced PIT. 2b 2a * Row covering Inclusion removal/deletion How? Will see shortly.
7
Graphical Illustration of Covering in a PIT
(5,7,13,15) (8,9) (9.13) (BD) (AB’C’) Covers Shrunk (5,7,13,15) (8,9) (9.13) (BD) (AB’C’) (EPI) (EPI) (EPI) (EPI)
8
But, K-maps can be used effectively only up to 6-variable functions, and is susceptible to human error, especially for > 4 variables. QM is more methodical, applies to any # of variables, and does not rely on visual skills to identify PIs or a min-cost set of PIs to cover all MTs. It is thus also less prone to human errors if done manually, but more importantly it can be programmed and be used as a CAD tool for logic minimization.
9
QM: The PIT—Min-Cost MT Covering (cont.)
* *
10
QM: The PIT—Min-Cost MT Covering (cont.)
Inclusion deletions * PI1 EPIs * PI2
11
QM: The PIT—Min-Cost MT Covering (cont.)
A row Ri is said to cover row Rj, if Ri has X’s in all the cols that Rj has X’s in (& possibly more). The idea behind deleting the covered row Rj is that the covering row Ri does the job of Rj, and probably more. Q for optimality: At what cost? C Covering by one PI/row of another by one MT/col of another Identify “pseudo-EPIs” (EPIs in the reduced PIT), and remove them (inclusion removal—removal from PIT, and inclusion in the min. expression) and the MTs they cover. Repeat above steps until all MTs covered In these cases both PIs cover each other, But that may not always be the case Exclusion deletions PI1 PI2 A col Ci is said to cover col Cj, if Ci has X’s in all the rows that Cj has X’s in (and possibly more). The covering col. Ci is deleted. The idea is that that any PI that covers/includes Cj will cover/include the covering col. Ci; thus the latter is auto-matically incl. in the final expr. when including Cj Both row & col covering rules reduce the complexity of the min-cost covering problem by narrowing down the choices for PIs in the final SOP. However row-covering does not necessarily preserve optimality (why?), while col-covering does (why?)
12
QM: The PIT—Min-Cost MT Covering (cont.)
by one MT/col of another Exclusion deletions C Pseudo-EPIs PI1 * C PI3 C * PI4 PI2 Inclusion deletions f = PI1 + PI2 + PI3 + PI4
13
QM: The PI Table—Min-Cost MT Covering (cont.)
14
QM: The PI Table—Min-Cost MT Covering (cont.)
Better heuristics than random choice can be used, as shown in subsequent slides * (for incl. removal) C This is actually not a good heuristic. We will see better ones later. (same a pseudo EPI) (This includes checking if pseudo-EPIs exist and inclusion-deleting them as before. Go on applying all substeps in 2 until none of them apply; will see a more comprehensive procedure later) * * * Note: We need to explicitly consider cost of PIs in both breaking a cyclic PIT and in row coverings in order to better minimize the total # of gate i/ps in a 2-level gate impl. of the expr. Will see these considerations shortly.
15
Q-M: Don’t Cares AB CD 00 01 11 10 AD 00 4 12 8 x ABC 01 1 1 5 1 13 x
Q-M for functions with don’t cares: Difference from Q-M without X’s: Include X’s along w/ MTs when forming PIs using the tabular method (or using K-Maps) Eliminate PI’s that are composed of only X’s Don’t include X’s in the PI chart/table AB CD 00 01 11 10 AD 00 4 12 8 x ABC 01 1 1 5 1 13 x 91 CD 11 3 x 7 x 15 11 AC 10 2 x 6 1 14 10
16
Column 1 Column2 Column3 G1 1 0001 00-1(1,3) 0--1(1,3,5,7) 2 0010
0-01(1,5) --01(1,5,9,13) 8 1000 -001(1,9) 0-1-(2,3,6,7) 001-(2,3) G2 3 0011 0-10(2,6) 5 0101 100-(8,9) 6 0110 9 1001 0-11(3,7) 01-1(5,7) G3 7 0111 -101(5,13) 13 1101 011-(6,7) 1-01(9,13) PI2 PI3 PI4 PI1 Note: Final PIs w/ only X’s should be removed from the final set of Pis. However, do not remove intermediate implicants that have only X’s (why?).
17
PI Table * ∩ ∩ ∩ PIs 1 3 5 6 9 PI1 PI2 PI3 PI4 1 6 9 PI2 PI3
Do not list any DC’s in the cols of the PI Table. We do not need to cover them. Delete either col 1 or 5 ∩ Covering arrows ∩ PIs 1 3 5 6 9 PI1 PI2 PI3 PI4 1 6 9 PI2 PI3 3 ∩ * 1 * 1 EPI Pseudo EPI 1 1 2 1 1
18
QM+: An Extended QM-type Iterative Technique for Min-Cost Covering
In the PI Table (PIT), identify all EPIs, include them in the min. express & delete MTs they cover. Cost of a PI = # of literals +1 (AND & OR gate cost portions). Repeat While no pseudo EPIs can be identified and any of Rule 2, 1’, 1 can be applied do Reduce the RPIT further by using only the col covering rule (rule 2) and only row covering in which the covering row has cost <= that of the covered row (rule 1’). /* these coverings are optimal—proof? */ If no rule could be applied above then apply only one row covering rule (rule 1) w/ the least difference in cost between covering and covered row (break ties by max # of remaining MTs covered by the covering row). /* this part is sub-optimal so need to apply in a limited manner */ End While Identify EPIs in the RPIT—these new EPIs are called pseudo or secondary EPIs—and for each inclusion delete them and delete from the RPIT the MTs they cover. Until[no MTs left OR no pseudo EPIs exists] If the RPIT is cyclic, make it acyclic by choosing a PI for inclusion in the min expression that either: Covers the max # of remaining MTs; break ties based on smaller cost, and break further ties randomly. (Rule 3)—biggest bang heuristic OR has the smallest cost/(# of covered MTs); break ties by max. # of MTs covered, and further ties randomly. (Rule 4)—biggest bang-for-the-buck heuristic Until(all MTs are covered) PI A 32-mt PI C 16 X’s PI B 15 X’s C 1-mt Cost of a PI = # of literals +1 Non-opt. ex: In a 7-var. func, cost(A) = (7-1) +1 =7, cost(B+C) = (2+1)+(2+1) = 6 Row covering rule (Rule 1): If row i covers row j, delete the covered (subset) row, row j. If both rows i and j cover each other, delete the row w/ higher cost (# of literals). Rule 1’ (strong/good covering rule): Apply covering from row i to row j only if row i’s cost <= row j’s cost. Note that Rule 1’ is not in basic QM. Col covering rule (Rule 2): If col i covers col j delete the covering (superset) column, col i. If both cols I and j cover each other, then delete one of them arbitrarily
19
Cyclic PI Table—Examples of Rules 3 & 4
In the next set of examples we will only use Rule 1 (not 1’) just to illustrate the effect of Rules 3 and 4 and not mix up too many alternate rules Example 1: Cyclic PI set in K-map (no EPIs) of a 5-var. function f. Cost of a PI = # literals + 1 All red PIs have the same cost (each covers 2 MTs) The blue PI has a smaller cost as it covers 2 MTs and 2 DCs. bc bc de 1 de x a=0 a=1 Min-cost PI Cost PIs 1 2 3 4 5 6 4+1 PI1 Note: PI4=4,6,12,14 → # of literals = 5 (# of function variables) -2 = 3 → cost(PI4) = 3+1 = 4 (# of literals +1) 4+1 PI2 4+1 PI3 3+1 PI4 4+1 PI5 4+1 PI6
20
Cyclic PI Table (Contd.)
Rule 3: Heuristic for breaking the cycle in a cyclic PI chart Choose a PI for incl. deletion (incl. in expr., remove it and all MTs it covers) that covers the largest # of minterms Break a tie by choosing the PI that has the least cost . Break a further tie by choosing a PI in the tie arbitrarily. Rule 4: Choose PI with the smallest cost/(MTs covered) For previous example, # of MT’s covered are given to be the same If cost is not taken into account to break ties (and if so, this also amounts to randomly choosing a PI in this example), neither Rule 3 nor 4 used fully Choose PI1 arbitrarily for incl. deletion Reduced PIT on the right 5 2 2 PIs Cost 2 4 5 6 PI2 4+1 PI3 PI4 3+1 PI5 PI6 1 c 2 * 4 c * 5 c 3 Cost = 5+5+5=15
21
Cyclic PI Table (Contd.)
If cost is used to break ties of max MTs covered—Rule 3 (OR choice made by least cost/MT—Rule 4) By above criterion, choose PI4 first (for incl. deletion) 3 4 3 4 PIs 1 2 3 4 5 6 PIs 1 2 3 5 PI1 PI2 PI3 PI5 PI6 PI1 PI2 PI3 * 3 1 * PI4 PI5 2 * 4 PI6 Cost = = 14
22
Cyclic PI Table (Contd.): Ex. 2
BC BC 00 01 11 10 00 01 11 10 DE DE PI6=12,28 00 0 1 PI2=4,5,12,13 PI1=0,4 PI4=0,16 4 1 12 1 8 PI12=24,28 00 161 20 28 1 241 PI8=16,17,24,25 01 1 1 5 x 13 1 9 1 PI5=9,25 01 171 21 29 251 PI3=9,11,13,15 PI9=17,19 11 3 x 7 15 1 11x PI7=15,31 PI11=23,31 11 191 231 31 1 27 PI10=19,23 10 2 x 6 14 10 10 18 22 30 26 A=0 A=1
23
Taking # of MTs covered and cost into consideration (Rule 3, and in this case this results in the same soln. as applying the alternate Rule 4): Choose PI8 first (incl. deletion) 11 6 6 7 8 7 7 1 1 9 9 1 1 8 Cost PIs 4 9 12 13 15 16 17 19 23 24 25 28 31 4+1 PI1 3+1 PI2 PI3 PI4 PI5 PI6 PI7 PI8 PI9 PI10 PI11 PI12 * 6 * 7 2 5 * 8 * 11 * 1 3 * 9 10 4 cost = (AND gates’ cost) + 6 (6 PIs OR gate cost) = 22+6 = 28 PI3
24
# of MTs covered is ignored and only cost is taken into account w/ ties broken randomly (neither Rule 3 nor Rule 4 used, but not completely random either) Choose PI2 first (incl. deletion) based only on cost (Note also: PI2’s cost/MT = 4/3, while PI8’s is 4/4, so this is not a good choice by Rule 4, nor by Rule 3 as PI2 does not cover the max. # of MTs) 4 1 1 1 4 5 5 Cost PIs 4 9 12 13 15 16 17 19 23 24 25 28 31 4+1 PI1 3+1 PI2 PI3 PI4 PI5 PI6 PI7 PI8 PI9 PI10 PI11 PI12 2 * 1 * 4 3 * 5
25
* * * Reduced chart table: f=PI2+PI4+PI12+……
Again cyclic! Choose PI3 by cost 1 1 4 5 4 5 Cost PIs 9 15 17 19 23 25 31 3+1 PI3 4+1 PI5 PI7 PI8 PI9 PI10 PI11 * 1 2 3 * 4 6 or * 5 This cost is 4 more than when using # of MTs as the selection criteria in an acyclic PI table
26
Time-Complexity of QM Let p be the # of PIs and m the # of MTs in an n-variable function # of iterations of QM (each iter. consists of EPIs/p-EPIs incl. deletion or application of rules 1 or 2): In each iteration at least 1 col or row is deleted (incl. or excl. deletions). Thus # of worst-case iterations is O(p+m) = O(max(p, m)) (note could be Q(max(p, m)) but more analysis needed for that). Each iteration takes Q(max(m*p2, p*m2)) time due to worst-case of all pair-wise comparisons among rows and cols to determine row and col coverings, and Q(m*p) to determine EPIs (or psuedo-EPIs). Thus total time complexity is O(max(p,m))*(max(m*p2 , p*m2))) = O(max(m*p3, p2*m2, p*m3)) = O(max(m*p3, p*m3)), since if p < m, then p*m3 > p2*m2, else (p >= m) m*p3 >= p2*m2 What are the worst case values of p and m as functions of n?
27
Optimality Issues in QM: Bad Coverings
Venn Diagram type PI depictions below (neither PITs nor K-maps) 2-mt PI A 4-mt PI B 4-mt PI C 8-mt PI D 8-mt PI E X 4 X’s 8-mt PI F Optimal Soln. in a cyclic situation: Either F+B+C or D+E+A (cost=3n-7+3=3n-4). Either can be obtained by applying Rule 3 or 4 of QM+ to the above cyclic situation to choose either of E, F or D first, followed by Rule 1 (1 “bad covering” at the end stage, C covs E or A covs B, has to be used). Interestingly, even a random choice as in QM to break the cycle results in an optimal solution. 2 mts 1 mt 2-mt PI A 4-mt PI B 4-mt PI C 8-mt PI E X 6 X’s Optimal Soln in a non-cyclic situation: for a 4-var. function: Possibilities: E+D+A (cost=3n-4) or B+C (cost=2n-2). 2n-2 <= 3n-4 n >= 2, so B+C is optimal for n >= 2. QM gives us B+C in spite of “bad” coverings (C covers E; B covers D). 8-mt PI D 2 mts 1 mt The 2 examples here show that bad coverings will not always lead to a non-optimal solns, but they can, as we see later. However, QM (i.e., tech. using Rule 1, Rule 2, EPI/p-EPI and cycle-breaking only; no concept of good and bad coverings) is not optimal—it will not give us an optimal solution for all problems.
28
Optimality Issues in QM: Bad Coverings (contd.)
QM is not optimal due to the sub-optimal use of row covering when the covering row is of greater cost than the covered one, i.e., if applying such “bad” coverings, QM may not give us an optimal solution. 8-mt PI A 8-mt PI B 8-mt PI C 32-mt PI D 12 X’s 2 X’s 30 X’s 4 mts 2 mts Example: Optimal Soln: for a 7-var. function: A+D of cost (4+1) + (2+1) = 8. QM gives us B+C of cost (3+1) + (4+1) = 9, due to “bad” coverings (there are no good coverings, and initially, C of cost 4+1 covers D of cost 2+1 & applying Rule 1 to C, D first, we get rid of D). However, this issue is rectified for this example in QM+. How? No scope of applying Rule 1’ (good covering) only here. What is the solution if only bad coverings are available? Take a broader/more-global view of covering (between sets of PIs) to avoid applying bad coverings?
29
Optimality Issues in QM: When only bad coverings available
How about PI pair-to-pair covering? This opens up covering possibilities that were not there between single PIs, and good pair to pair coverings should also preserve optimality. In the above example, PI pair A+D will cover all others like A+C or B+C using good covering, and will end up as the optimal solution (only remaining PI). So the process is: Use regular QM until the only options are bad covering(s) or the PIT/RPIT is cyclic If the above happens: Switch to a PIT w/ rows that are PI-pairs and single PIs: what should be a PI-pair cost for 2-level and multi-level (factored) circuit implementation? The defns of good & bad row covs. remain the same; coverings can apply between any 2 rows. Cannot select any single PIs for inclusion deletion (ID) until some pair is initially selected for ID. Thus pseudo-EPIs for pairs are defined initially w/o considering coverage by single PIs. This is b/c we are unable to select a single PI initially so their coverage of MTs do not initially matter. After the initial PI-pair selection, remaining single PIs are back in contention and we first look for good coverings (gCs) by them, and if none, again look for gCs by pairs, and so on. When a PI pair Pij = {Pi, Pj} is incl. deleted (due to becoming p-EPI after >=1 good coverings), rows w/ single PIs of Pij are excl. deleted, and costs of other PI pairs that contain one of the PIs of Pij are appropriately reduced. PIs Cost MT 1 MT 2 MT 3 MT 4 MT 5 MT 6 MT 7 MT 8 MT 9 MT 10 PI A 4+1 X PI B 3+1 PI C PI D 2+1 {A,B} 9 {A,C} 10 {A,D} 8 {B,C} {B,D} 7 {C,D} 8-mt PI A 8-mt PI B 8-mt PI C 32-mt PI D 12 X’s 2 X’s 30 X’s 4 mts 2 mts MTs 1-2 MTs 3-6 MTs 7-10 gC bC bC gC gC gC Optimal solution {A,D} obtained in 1 shot(this may not always be the case)
30
Optimality Issues in QM: When only bad coverings available (contd)
However, a similar problem comes up if the only pair-to-pair coverings are bad ones or there are none (what to do then?). So this approach can mitigate the sub-optimality of single PI bad coverings (or no coverings in a cyclic PIT) due to good pair-to-pair coverings that open up, but not always. We can take the concept further to triple-PI sets, then quadruple-PI sets, etc., but in the extreme this approach “degenerates” into Petrick’s algorithm, which essentially considers all possible multi-PI sets that cover all MTs, and thus cover each other (and we only apply good coverings in this case, which are guaranteed to exist as we are considering all multi-PI sets—the optimal one good covers all others!).
31
Optimality Issues in QM (contd
Optimality Issues in QM (contd.): Proof of optimality of “good” covering Theorem: If row PIj covers row PIk in a PIT/RPIT and cost(PIj) <= cost(PIk) (this is the so-called “good” covering), then if PIk is exclusion deleted from the RPIT (i.e., PIk will not be included in the final SOP expression f), then this leads to a cost of the final SOP expression f that is <= the cost of f if PIk is not exclusion deleted (i.e., PIk is included in the final expr.) Proof: Two cases: Case 1: PIk is not in any optimal solution. Clearly, in this case, optimality of the final solution will not be affected by exclusion deleting PIk Case 2: PIk is in some optimal solution S. If PIj is also in the same solution, then we can reduce its cost by deleting PIk from S without affecting MT coverage in S (since PIj covers all the MTs of PIk not covered by “previously”-chosen EPIs or p-EPIs). Thus we reach a contradiction that S is an optimal solution. If PIj is not in S, we can replace PIk by PIj in S without affecting MT coverage in S, and reduce the cost of S or keep it the same (if cost(PIj) = cost(PIk) ). In the latter case, we get another optimal solution S’ that does not contain Pik Thus either PIk is not in any optimal solution or if it is, then we can get another optimal solution (i.e., one with the same cost) containing PIj instead of PIk. Hence optimality of the final solution will not be affected by exclusion deleting PIk QED
32
Optimality of QM (contd
Optimality of QM (contd.): 2nd Proof of optimality of “good” covering—more complex proof Theorem: If row PIj covers row PIk in an PIT/RPIT and cost(PIj) <= cost(PIk) (this is the so-called “good” covering), then if PIk is exclusion deleted from the RPIT (i.e., PIk will not be included in the final SOP expression f), then this leads to a cost of the final SOP expression f that is <= the cost of f if PIk is not exclusion deleted (i.e., PIk is included in the final expr.) Proof: For a PI PIr, let MT(PIr) be the set of MTs in the current RPIT covered by PIr. Case 1: MT(PIj) = MT(PIk). If PIk is included in f, then a smaller or same-cost solution can be obtained by replacing PIk by PIj and have PIj cover MT(PIk) (thus the same MTs as before are covered by f after this change). Case 2: MT(PIk) is a subset of MT(PIj). Let MT(PIj - PIk) be the set of MTs in the current RPIT covered by PIj and not by PIk. There are 2 subcases here: Case 2a: Less cost is incurred by covering MT(PIj - PIk) by PIj than any other single or multiple PIs. In other words, PIj is part of the optimal solution. Thus if PIk is chosen to cover MT(PIk), then this solution’s cost can be reduced by deleting PIk from the solution and not affecting the coverage of MT(PIk), since these MTs are covered by PIj that is already part of the optimal solution. Case 2b: Less cost is incurred by covering MT(PIj - PIk) by a set S of one or more PIs (see figure below where S = {PIr, PIm}) other than PIj (this can happen if PIs in S become pseudo-PIs later on in the QM process due to other MTs [i.e., MTs not in MT(PIj - PIk)], and are thus needed in f in any case, and they cover MT(PIj - PIk) essentially for free). In this case also, as in Case 1, if PIk is part of the final solution (to cover MT(PIk)), then a smaller or same-cost solution can be obtained by replacing PIk by PIj and and have PIj cover MT(PIk) (and thus the same MTs as before are covered by f after this change). Thus in all cases, PIj can replace PIk if the latter is present in f to result in a smaller or same-cost solution , while still covering all the MTs of PIk (and possibly more). Hence exclusion-deleting PIk due to “good” covering by PIj, leads to a cost of the final SOP expression f that is <= the cost of f if PIk is included in it. Thus good coverings retain the optimality of a solution QED PIk X X PIj X X X X PIr X X X PIm X X X MT(PIj – PIk) Current or future pseudo-singleton cols Set S in Case 2b
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.