Transcript ppt

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
Basic Two-Level Minimization Steps
The basic steps are the same for K-Map and Quine McCluskey
(QM):
1. Form all PIs
2. Determine a minimum cost set of PIs to cover all minterms (MTs)
a) Determine EPIs, include them in the final expression and delete all MTs
they cover
b) 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.
QM: Forming all PIs using the Tabular Method
Step 1
1.
2.
3.
4.
5.
6.
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 # if 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.
Issues 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.
# of MT/ ABCD
1’s DC
1
2
3
1
0001
2
0010
8
1000
3
0011
5
0101
6
0110
9
1001
7
0111
13
1101
# of Impl. ABCD Diff. Tricks for quick PI formation
(MT/DC
1’s list)
set
1
PI1
2
1,3
00x1
2
1,5
0x01
4
1,9
x001
8
2,3
001x
1
2,6
0x10
4
8,9
100x
1
3,7
0x11
4
5,7
01x1
2
5,13
x101
8
6,7
011x
1
9,13
1x01
4
Impl. ABCD Diff.
(MT/DC
set
list)
PI2
1, 3
5, 7
0xx1
2,4
PI3
1, 5 xx01
9,13
4,8
PI4
2, 3
6, 7
1,4
0x1x
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/DCs 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 sufficientcond. 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.
QM: The PI Table (PIT)—Min-Cost MT Covering
2a
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
QM: The PIT—Min-Cost MT Covering (cont.)
2b
Row
covering
*
2a
How? Will see shortly.
2a
2b
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.
Inclusion removal/deletion
• 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.
QM: The PIT—Min-Cost MT Covering (cont.)
*
*
QM: The PIT—Min-Cost MT Covering (cont.)
Inclusion
deletions
*
EPIs
*
PI2
PI1
QM: The PIT—Min-Cost MT Covering (cont.)
Exclusion deletions
C
C
Covering
by one MT/col
of another
In these cases both PIs cover each other,
But that may not always be the case
PI1
C
C
PI2
Covering
by one
PI/row 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
Both row & col
covering rules
reduce the
complexity of the
min-cost covering
problem. However
row-covering does
not necessarily
preserve
optimality (why?),
while col-covering
does (why?)
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?
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/include
s Cj will
cover/include
the covering
col. Ci; thus the
latter is automatically incl.
in the final
expr. when
including Cj
QM: The PIT—Min-Cost MT Covering (cont.)
Exclusion deletions
C
C
Pseudo-EPIs
PI1
C
C
*
PI3
*
PI4
PI2
Inclusion deletions
f = PI1 + PI2 + PI3 + PI4
Covering
by one MT/col
of another
QM: The PI Table—Min-Cost MT Covering (cont.)
QM: The PI Table—Min-Cost MT Covering (cont.)
*
C
C
*
*
*
(same a pseudo EPI)
(for incl. removal)
This is actually
a good heuristic.
We will
see can
Betternot
heuristics
than random
choice
better onesbelater.
used, as shown in subsequent slides
(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.
Q-M: Don’t Cares
• 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
CD
f   m(1,3,5, 6,9)
AB
00 01 11
10
AD 00
0
4
12
8
x ABC
01
1
1
5
1
13
9
1
11
3
x
7
x
15
11
10
2
x
6
1
14
10
  d(2, 7,8,13)
AC
x
CD
f   m(1,3,5, 6,9)
  d(2, 7,8,13)
G1
Column 1 Column2
Column3
1
0001
00-1(1,3)
0--1(1,3,5,7)
PI2
2
0010
0-01(1,5)
--01(1,5,9,13)
PI3
8
1000
-001(1,9)
0-1-(2,3,6,7)
PI4
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)
PI1
Note: Do not remove intermediate
implicants that have only X’s (why?).
Only final PIs w/ only X’s should be
removed from the final set of Pis.
Delete either
col 1 or 5
1
3
5
6
PI1
∩
9
1
3
*
PI3
EPI
PI4
6
9
PI2
PI2
*
f   m(1,3,5, 6,9)
  d(2, 7,8,13)
∩ ∩
Covering
arrows
PIs
PI Table
PI3
1
1
1
2
Pseudo EPI 1
1
f  PI3  PI4  CD  AC
1
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
32-mt
PI B
16 X’s
– While there are MTs remaining and the reduced PIT (RPIT) is not cyclic do
• Check if EPIs can be identified in the RPIT—these new EPIs are called pseudo or
secondary EPIs—and if so take the same action as for original EPIs
32-mt
PI C
• While no pseudo EPIs can be identified and any of Rule 2, 1’, 1 can be applied do
C
16 X’s
– 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? */
1-mt PI A 1-mt
15 X’s
15 X’s
– 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 */
C
Non-opt. ex:
In a 7-var.
func, cost(A)
= (7-1) +1 –
=7,
cost(B+C)
= (2+1)+(2+1)
=6
• End While
– End While
If the RPIT is cyclic, make it acyclic by choosing a PI for inclusion in the min expression
that either:
1.
2.
Covers the max # of remaining MTs; break ties based on smaller cost, and break further ties randomly.
(Rule 3)
OR has the smallest cost/(# of covered MTs); break ties by max. # of MTs covered, and further ties
randomly. (Rule 4)
• Until(all MTs are covered)
• 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 Rule 1): 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
Cyclic PI Table—Examples of Rules 3 & 4
•
•
•
•
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.
f= m(1,2,3,4,5,6)   d(12,14)
Cost
PIs
4+1
PI1
4+1
PI2
4+1
PI3
3+1
PI4
4+1
PI5
4+1
PI6
1 2 3 4 5 6
bc
de
bc
1
1
de
1 1
1 1
1 1
x x
a=0
a=1
Min-cost PI
Note: PI4=4,6,12,14 →
# of literals = 5-2 = 3 →
cost(PI4) = 3+1 = 4
[# of literals +1]
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.
• 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) c
– Choose PI1 arbitrarily *
for incl. deletion
c
– Reduced PIT on the
*c
right
PIs
PI2
PI3
PI4
2
5 5
2
4
2
5
6
1
2
4
PI5
5
PI6
3
f=PI1  PI3  PI5
Cost = 5+5+5=15
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)
PIs
*
3
4
3
4
1
2
3
5
1 2 3 4 5 6
PI1
PIs
PI2
PI1
PI3
PI2
3
PI4
PI3
1
PI5
PI5
2
PI6
4
*
*
PI6
f  PI4  PI2  PI6
cost=2+3+3=11
Cost = 4+5+5 = 14
Cyclic PI Table (Contd.)
BC
00 01 11 10
DE
8
0
4
12
00 1 1
1
01
1
11
3
10
2
1
5
x
7
15
x
6
14
x
13
1
9
1
11
BC
00 01 11 10
DE
16
20
28
24
00
1
1 1
1
x
10
A=0
PI1=0,4 PI2=4,5,12,13
PI6=12,28 PI7=15,31
PI10=19,23
PI11=23,31
01
17
11
19
10
18
1
21
29
25
1
23
31
27
22
1
1
30
1
26
A=1
PI3=9,11,13,15 PI4=0,16 PI5=9,25
PI8=16,17,24,25 PI9=17,19
PI12=24,28
f= m(0,4,9,12,13,15,16,17,19,23,24,25,28,31)   d(5,11)
•
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)
Cost PIs
*
6
4+1
PI1
3+1
PI2
7
3+1
PI3
2
4+1
PI4
5
4+1
PI5
* 8
* 11
* 1
4+1
PI6
4+1
PI7
3+1
PI8
3
4+1
PI9
9
4+1
PI10
10 4+1
PI11
4+1
PI12
*
*
4
6
7
8
7
0 4 9 12 13
f  PI1  PI 2  PI6 +PI8  PI10  PI7
or  PI11
7
1
1
9
9
1
1
8
11
6
15 16 17 19 23 24 25 28 31
cost=4+3+4+3+4+4
4  3  4  3 (AND
 4  4gates’
 (7cost)
terms)
cost
+
6 (6 PIs
OR gate cost) = 22+6 = 28
=22
 7
 29
•
•
# of MTs covered is ignored and only cost is taken into account w/ ties broken randomly (neither
Rule 3 nor Rule 4 used)
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
Cost PIs
*
*
2
4+1
PI1
1
3+1
PI2
3+1
PI3
4+1
PI4
4+1
PI5
4+1
PI6
4+1
PI7
3+1
PI8
4+1
PI9
4+1
PI10
4+1
PI11
4+1
PI12
4
3
*
5
1
1
1
0 4 9 12 13
4
5
5
15 16 17 19 23 24 25 28 31
• Reduced chart table: f=PI2+PI4+PI12+……
• Again cyclic! Choose PI3 by cost
1
Cost PIs
*
*
or
*
1
3+1
PI3
2
4+1
PI5
3
4+1
PI7
4
3+1
PI8
6
4+1
PI9
6
4+1
PI10
5
4+1
PI11
1
4
5
4
5
9 15 17 19 23 25 31
f  PI2  PI4  PI12 +PI3  PI8  PI11 +PI9
or  PI10
cost  3  4  4  3  3  4  4  (7 terms)  25  7  32
This cost is 4 more than
when using # of MTs as
the selection criteria in an
acyclic PI table
Time-Complexity and Optimality 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(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?
• Optimality issues in examples below.
8-mt PI E
8-mt PI E
4-mt PI C
6 X’s
4-mt PI C
4 X’s 2 mts 2 mts
2-mt PI A
X
4-mt PI B
4 X’s
1 mt 1 mt
8-mt PI F
X
2 mts
4 X’s 2 mts
2 mts
X
1 mt
6 X’s
2-mt PI A
4-mt PI B
1 mt
X
2 mts
8-mt PI D
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
8-mt PI D
>= 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).
Optimal Soln. in a cyclic situation: Either F+B+C
The 2 examples here show that bad coverings will not always lead to a
or D+E+A (cost=3n-7+3=3n-4). Either can be
obtained by applying Rule 3 or 4 to the above
non-optimal solns, but they can, as we see later. However, QM (i.e.,
cyclic situation to choose either of E, F or D first, tech. using Rule 1, Rule 2, EPI/p-EPI and cycle-breaking only; no
followed by Rule 1 (1 “bad covering” at the end
concept of good and bad coverings) is not optimal—it will not give us
stage, C covs E or A covs B, has to be used).
an optimal solution for all problems.
Optimality of QM (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.
32-mt PI D
Example
Optimal Soln: for a 7-var. function: A+D of cost
(4+1) + (2+1) = 8. QM gives us either A+C or B+C,
both of cost (4+1) + (4+1) = 10, due to “bad”
coverings (initially, C of cost 4+1 covers D of cost
2+1 & applying Rule 1 to C, D first, we get rid of D).
•
•
•
•
8-mt PI C
30 X’s
2 mts
2 X’s
8-mt PI A
4 mts 4 mts
4 X’s
8-mt PI B
No scope of applying Rule 1’ (good covering) only here. What is the solution if some bad coverings have to be
applied? Take a broader/more-global view?
How about 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 to be followed 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
• the defns of good & bad row covs. remain the same; coverings can apply between any 2 rows
• 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.
However, a similar problem comes up if the only pair-to-pair coverings are bad ones or there are none. 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-PIs, 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!).
Optimality of QM (contd.): Proof of optimality of “good” covering
•
•
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: Two cases:
1. 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
2. Case 2: PIk is in some optimal solution S.
a) 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.
b) 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. 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 containing
PIj instead of PIk. Hence optimality of the final solution will not be affected by exclusion deleting PIk
QED
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
PIj
Set S in Case 2b
PIr
PIm
X
X
X
X
MT(PIj – PIk)
X
X
X
X
X
X
X
X
Current or future pseudo-singleton cols