Section 4.1 - Karnaugh Map 4.1 Page 1 of 7 Karnaugh Map The Karnaugh map method is a simple, straightforward procedure for minimizing the number of operations in standard-form expressions. The Boolean n-cubes provide the basis for these maps. Each vertex in each n-cube represents a minterm of an n-variable Boolean function. Each Boolean function could be represented visually in the form of an n-cube by marking those vertices in which the value of that function is a 1, i.e. the 1-minterms. Ex., for the carry and sum functions: 110 ci 0 0 0 0 1 1 1 1 xi 0 0 1 1 0 0 1 1 yi 0 1 0 1 0 1 0 1 ci+1 0 0 0 1 0 1 1 1 si 0 1 1 0 1 0 0 1 cx 111 110 111 xy 011 010 cy 100 000 101 001 ci+1 = c'xy + cx'y + cxy' + cxy = xy + cy + cx 011 010 100 000 101 001 si = c'x'y + c'xy' + cx'y' + cxy To find the standard form of a function that contains the minimal number of operators, we use the concept of a Boolean subcube. In general, an m-subcube of an n-cube can be defined as that set of 2m vertices in which n - m of the variables will have the same value at every vertex, while the remaining m variables will take 110 111 on the 2m possible combinations of the values 0 and 1. For example, in the 3-cube: 011 The 2-subcube is defined as that set of 2m = 22 = 4 vertices in which n - m = 3 - 2 010 = 1 of the variable will have the same value at every vertex (0xx, or 1xx) while the remaining variables will take on the 2m = 22 = 4 possible combinations (x00, x01, x10, and x11). 100 101 The 1-subcube is defined as that set of 2m = 21 = 2 vertices in which n - m = 3 - 1 = 2 of the variables will have the same value at every vertex (00x, 01x, 10x, 000 001 or 11x) while the remaining variable will take on the 2m = 21 = 2 possible combinations (xx0, and xx1). Each subcube can be characterized by the n - m variable values that are the same for every vertex in the subcube. If a Boolean function has a value of 1 in each vertex of the m-subcube, the 2m 1-minterms in that subcube could be expressed by a single term of n - m literals. For example, in the carry function ci+1, the two 1-minterms (011, and 111) form a 1-subcube which could be expressed by the single term of n - m = 3-1 = 2 literals xy. • • To minimize the number of OR operators, we have to choose as few subcubes as possible while still covering all its 1-minterms. To minimize the number of AND operators, we have to choose the largest possible subcubes. We can determine and select the subcubes visually from a cube representation, or we could derive them from the two-dimensional form of this cube which is called a Karnaugh map, or map for short. There is a one-to-one correspondence between Boolean cubes and Karnaugh maps. Karnaugh maps are just twodimensional representation of Boolean cubes. The map is an array of squares. Each square corresponds to one vertex of the cube, i.e. one minterm of the Boolean function. Section 4.1 - Karnaugh Map Page 2 of 7 A two-variable map consists of 4 squares which correspond to the 4 minterms of a two-variable Boolean function. The largest subcube in a twovariable map is a 1-cube, which represents a single variable or its complement. x y 0 0 x'y' 1 xy' minterm numbers 1 0 x y 0 1 0 1 2 3 subcube subcube subcube subcube 0 x'y 2 1 3 1 xy x' y' y x A three-variable map consists of 8 squares. The largest subcubes are of size 2. These 2-subcubes can be expressed by a single literal. The 1-subcubes can be expressed by two literals. x yz 01 00 11 0 0 10 1 x'y'z' x'y'z x 3 x'yz yz 00 01 0 2 11 1 10 3 x z 2 0 x'yz' 00 yz 01 11 10 0 1 3 2 4 5 7 6 x'z yz y'z' xy' 0 z' 4 1 5 xy'z' xy'z 7 xyz 6 4 5 7 6 x 1 xyz' three-variable map 1 Examples of 2-subcubes Examples of 1-subcubes A four-variable map consists of 16 squares. yz wx 00 00 w'x' y'z' 0 w'x y'z' 11 12 wx y'z' wx' y'z' w'x' y'z 4 01 10 11 01 w'x y'z 1 5 13 wx y'z 8 wx' y'z 9 w'x' yz w'x yz yz 10 3 7 w'x' yz' w'x yz' wx 2 00 01 0 11 1 yz 10 3 wx 00 6 15 wx yz 14 wx yz' 11 wx' yz 10 wx' yz' 5 7 6 z' 01 12 13 15 11 3 2 4 5 7 6 w'z 14 12 13 xy 00 8 9 11 8 9 0 1 0 4 1 3 c 2 1 5 1 7 1 ci+1 = xy + cy + cx 6 1 11 10 10 Examples of 3-subcubes 10 14 xy x'y' Examples of 2 and 1-subcubes 00 01 0 0 10 3 1 4 1 11 1 1 2 1 5 w'yz' xy'z' w 10 10 11 01 15 11 If the minterm is a 1-minterm, a 1 will be placed inside its square, otherwise, it is left empty. Example, for the carry and sum functions: c 10 1 01 11 four-variable map 01 0 00 z 4 00 2 7 6 1 si = c'x'y + c'xy' + cx'y' + cxy Section 4.1 - Karnaugh Map 4.2 Page 3 of 7 Map Method of Simplification Four steps: 1) Map generation from truth table or functional expression. Place a 1 in the squares that correspond to 1minterms. 2) Prime implicant generation. A prime implicant (PI) is defined as a subcube that is not contained within any other subcube. e.g. In figure 4.13 below, w'z' is a PI but w'y'z' is not because w'y'z' is inside w'z'. A list of prime implicants is generated by inspecting each 1-minterm, finding the largest possible subcube of 1minterms that includes the minterm in question, and then adding that subcube to the list of prime implicants. If two or more different subcubes are discovered, they are all added to the list. If we rediscover a subcube that is already on the list, it will not be added the second time. 3) Essential prime implicant selection. An essential prime implicant (EPI) is the subcube that includes a 1-minterm that is not included in any other subcube. e.g. In figure 4.13 below, w'z' is an EPI because m0 is not in any other PI. However, w'y is not an EPI because all four of its 1-minterms are in another PI. Look for any 1-minterm that is included in only one prime implicant. This prime implicant is an EPI and is added to the cover list. 4) Create minimal cover. Generate a cover list consisting of the smallest possible number of prime implicants such that every 1-minterm is contained in at least one prime implicant. The cover list must include all the EPIs. Example: Using the map method, simplify the Boolean function F = w'y'z' + wz + xyz + w'y. yz wx 00 01 0 00 1 12 13 1 8 10 9 1 14 1 11 5 1 12 8 10 10 step 1) Figure 4.13. 7 13 1 w'y 6 1 15 14 11 10 1 9 1 2 1 1 11 1 10 3 1 4 01 11 1 6 1 01 0 00 1 15 00 2 7 1 11 wx 1 5 1 yz 10 3 1 1 4 01 11 1 step 2) w'z' yz wz Step 2) Do the 1-minterms in order. m0 is in w'z'. m2 is in w'z' and w'y. m3 is in w'y and yz. m4, m6, m7, same as m0, m2, m3 m9 and m13 are in wz. m11 and m15 are in wz and yz. Therefore, PI list = w'z', wz, yz, w'y. Step 3) EPI list: m0 and m4 are covered only by the PI w'z'. m9 and m13 are covered only by the PI wz. Therefore, EPI list = w'z', wz. Step 4) Cover list: The two EPIs w'z' and wz must be in the cover list. w'z' also covers m2 and m6. wz also covers m11 and m15. There are only two 1-minterms m3 and m7 that are not covered. These two 1-minterms can be covered by either yz or w'y since both of them are of the same size. (Note that if one was larger than the other, we would only use the larger one.) Therefore, there are two cover lists: (1) w'z', wz, yz and (2) w'z', wz, w'y. Thus, there are two simplified equivalent functional expressions for F = w'y'z' + wz + xyz + w'y: (1) F = w'z' + wz + yz (2) F = w'z' + wz + w'y. Section 4.1 - Karnaugh Map Page 4 of 7 Example: Using the map method, simplify the Boolean function F = w'x'yz' + w'xy + wxz + wx'y' + w'x'y'z'. yz wx 00 01 11 PI list: w'x'z', w'xy, wxz, wx'y', and x'y'z', wy'z, xyz, w'yz'. 10 w'x'z' 0 00 1 3 2 1 4 5 7 01 6 1 12 13 11 1 9 1 w'xy 1 15 14 wxz 11 10 wx'y' 1 8 10 EPI list: empty 1 1 x'y'z' wy'z xyz Cover lists: (1) w'x'z', w'xy, wxz, wx'y'. (2) x'y'z', wy'z, xyz, w'yz'. The two simplified equivalent functional expressions are: (1) F = w'x'z' + w'xy + wxz + wx'y'. (2) F = x'y'z' + wy'z + xyz + w'yz'. w'yz' However, bad if we had selected the two PIs w'x'z' and xyz, because now we would need 5 PIs to cover all the 1minterms. e.g. w'x'z', xyz, w'xy, wxz, and wx'y'. 4.3 Don't-Care Conditions Previously, we have considered only those Boolean functions that are completely specified. There are situations where the outputs are not specified for some input combinations, i.e. we do not specify whether the output is a 0 or a 1 for an input combination. Such a Boolean function is called an incompletely specified function, and the minterms for which the function is not specified are called don't-care minterms (d-minterms) or don't-care conditions. We can use d-minterms to further simplify the Boolean expression because we can assign either a 0 or a 1 to them in a way that will make our subcubes larger. Example: Convert BCD to nine's complements: Input Decimal x3 x 2 x 1 x 0 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 10 - 15 don't care x1x0 x3x2 00 01 0 11 1 00 10 3 1 4 01 1 11 X 5 x1x0 x3x2 7 8 x1x0 x3x2 15 X 12 11 9 11 X 10 X 10 y2 = x2x1' + x2'x1 = x2 ⊕ x1 X 3 2 5 7 6 13 X 8 15 14 X 11 10 X X 9 X y3 = x3' x2' x1' 01 11 1 3 5 12 8 13 X 1 01 1 15 14 X 11 X 11 10 X 10 1 6 01 0 1 X X 00 00 7 9 y1 = x1 2 1 1 X x1x0 x3x2 10 1 4 11 1 10 0 14 X 10 1 4 01 13 X 1 11 01 00 6 01 00 0 00 00 2 1 1 12 10 Output Decimal y3 y 2 y 1 y 0 9 1001 8 1000 7 0111 6 0110 5 0101 4 0100 3 0011 2 0010 1 0001 0 0000 10 - 15 don't care 11 1 10 3 2 1 4 5 7 6 1 12 8 13 X 9 X y0 = x0' 15 14 X 11 10 X X Section 4.1 - Karnaugh Map 4.4 Page 5 of 7 Tabulation Method Previously, finding subcubes in a map is essentially a trial-and-error procedure because it requires a person to recognize subcube patterns in a map. Gets more difficult with more variables. The tabulation method is an algorithmic exhaustive search method to find the subcubes in a map. Quite tedious for human but good for computers. Example: Find the prime implicants for the Boolean function F = w'y'z' + wz + xyz + w'y. From figure 4.13, we see that there are ten 1-minterms. Step (1): Generate a list of 0-subcubes. Group the 1-minterms such that each group Gi contains those minterms whose 1's count (number of variables whose values are equal to 1) is equal to i. Thus, in G0 the minterms have no 1's. In G1, the minterms have one 1's. In G2, the minterms have two 1's. etc. The "yes" and "no" flag indicates whether or not that subcube is covered by a larger subcube. The flag will be set to "yes" or "no" after we have generated the list of next-larger subcubes. Step (2): Generate a list of 1-subcubes. In the list of 0-subcubes, compare each of the minterms in group Gi with each of the minterms in group Gi+1 and generate a 1-subcube for group Gi in the list of 1-subcubes if these minterms differ in one variable. Note that "-" is not an indication of the value of a variable but is rather a placeholder for a variable that has already been eliminated from the expression. Group ID G0 G1 G2 G3 G4 Group ID G0 G1 G2 G3 Step (3): Generate a list of 2-subcubes. In the list of 1-subcubes, compare each of the minterms in group Gi with each of the minterms in group Gi+1 and generate a 2-subcube for group Gi in the list of 2-subcubes if these minterms differ in one variable. Group ID G0 G1 G2 Subcube Subcube Value Minterms w x y z m0 0 0 0 0 m2 0 0 1 0 m4 0 1 0 0 m3 0 0 1 1 m6 0 1 1 0 m9 1 0 0 1 m7 0 1 1 1 m11 1 0 1 1 m13 1 1 0 1 m15 1 1 1 1 List of 0-subcubes Subcube Covered yes yes yes yes yes yes yes yes yes yes Subcube Value Subcube Minterms w x y z m0, m2 0 0 0 m0, m4 0 0 0 m2, m3 0 0 1 m2, m6 0 1 0 m4, m6 0 1 0 m3, m7 0 1 1 m3, m11 0 1 1 m6, m7 0 1 1 m9, m11 1 0 1 m9, m13 1 0 1 m7, m15 1 1 1 m11, m15 1 1 1 m13, m15 1 1 1 List of 1-subcubes Subcube Covered yes yes yes yes yes yes yes yes yes yes yes yes yes Subcube Value Subcube Minterms w x y z m0, m2 m4, m6 0 0 m2, m3 m6, m7 0 1 m3, m7 m11, m15 1 1 m9, m11 m13, m15 1 1 List of 2-subcubes Subcube Covered no no no no Step (4): Repeat until all the subcube covered are "no". From the subcube values of all the "no" rows, the prime implicants are: w'z', w'y, yz, wz. Section 4.1 - Karnaugh Map Page 6 of 7 Example: Find the essential prime implicants and the minimal covers for the Boolean function F = w'y'z' + wz + xyz + w'y. Using the four PIs (w'z', w'y, yz, wz) obtained in the last example, we construct the EPI table. Prime Implicant Name Prime Implicant Expression P1 w'z' (0,2,4,6) P2 w'y (2,3,6,7) P3 yz (3,7,11,15) P4 wz (9,11,13,15) Implicant Minterms EPI covered minterms: Not covered minterms: Function Minterms 0 2 ⊗ × × 3 4 6 ⊗ × × × × 0 2 9 11 6 × 15 × ⊗ × ⊗ × 9 11 13 15 7 Step (1): Enter an × to indicate where a given minterm is covered by a given PI. Step (2): Indicate those columns that have only one × by circling that ×. Step (3): A PI row having a ⊗ is an EPI. Thus, EPI = w'z', wz. Step (4): The EPIs will cover the other ×'s in the same row. Step (5): Find the best way to cover the remaining minterms m3 and m7. Can use either w'y or yz. PI list: w'z', w'y, yz, wz EPI list: w'z', wz Cover list: (1) w'z', wz, w'y (2) w'z', wz, yz Minimal-cover expressions: (1) F = w'z' + wz + w'y (2) F = w'z' + wz + yz 13 × × 4 3 7 Section 4.1 - Karnaugh Map Page 7 of 7 Example: Find the minimal cover for the function with the 1-minterms 2, 6, 7, 8, 9, 13, 15. Group ID G1 G2 G3 G4 Subcube Subcube Value Minterms w x y z m2 0 0 1 0 m8 1 0 0 0 m6 0 1 1 0 m9 1 0 0 1 m7 0 1 1 1 m13 1 1 0 1 m15 1 1 1 1 List of 0-subcubes Prime Implicant Name Prime Implicant Expression P1 w'yz' (2, 6) P2 wx'y' (8, 9) P3 w'xy (6, 7) P4 wy'z (9, 13) P5 xyz (7, 15) P6 wxz (13,15) Subcube Covered yes yes yes yes yes yes yes Group ID G1 G2 G3 Implicant Minterms EPI covered minterms: Not covered minterms: Subcube Subcube Value Minterms w x y z m2, m6 0 1 0 m8, m9 1 0 0 m6, m7 0 1 1 m9, m13 1 0 1 m7, m15 1 1 1 m13, m15 1 1 1 List of 1-subcubes Subcube Covered no no no no no no Function Minterms 2 6 ⊗ × × 7 8 9 ⊗ × 13 × × × × 2 15 6 × 8 × × 13 15 9 7 Three minterms left uncovered: m7, m13, m15. m7 can be covered by P3 or P5. m13 can be covered by P4 or P6. m15 can be covered by P5 or P6. This can be expressed in terms of the following product of sums of these PIs: (P3 + P5)(P4 + P6)(P5 + P6) Multiplying the second and third sums produces the following expression: (P3 + P5)(P4P5 + P5P6 + P4P6 + P6) Since P6 covers the same minterms as do P5P6 (because the set of minterms covered by P5P6 is a subset of the set of minterms covered by P6) and P5P6 has fewer PIs, we can remove P5P6 from the expression. Similarly, we can remove P 4P6. This reduces the cover expression to (P3 + P5)(P4P5 + P6) Multiplying out this expressions yields P3P4P5 + P4P5 + P3P6 + P5P6 Again we can remove P3P4P5 because it is a subset of P4P5. Thus the final expression is P4P5 + P3P6 + P5P6 Finally, by combining these three options with the EPIs, we get the three different minimal covers: F = P1 + P2 + P4 + P5 = w'yz' + wx'y' + wy'z + xyz. F = P1 + P2 + P3 + P6 = w'yz' + wx'y' + w'xy + wxz. F = P1 + P2 + P5 + P6 = w'yz' + wx'y' + xyz + wxz.