3.7 Don't cares
Why this matters
Some rows of a truth table do not matter: the input can never happen, or nobody looks at the output when it does. A circuit is free to answer 0 or 1 on those rows, and a good designer uses that freedom to make the circuit smaller. The same freedom is what keeps a real design from carrying logic for situations that cannot occur.
Learning goals
Section titled “Learning goals”- Explain what a don't care is and name two situations that produce one.
- Mark the don't cares of a function as X on a map and recognize them in a truth table.
- Choose each X as 0 or 1 so that groups get larger, and leave an X alone when it does not help.
- Compare the results of setting every X to 0, setting every X to 1, and choosing each one on its merits.
Intuition first
Section titled “Intuition first”Suppose a function takes a decimal digit written in four bits. The codes for 0 to 9 are 0000 to 1001, and the six codes 1010 to 1111 are never produced by anything upstream. What should the function output for 1100? Any answer is fine, because the input will never be 1100. So the designer can write down whichever answer gives the smallest circuit.
A software version is a function with a precondition: it is only ever called with a digit from 0 to 9, so what it does for other values is up to the implementer. One thing differs. Hardware never reports a precondition violation. If a wiring fault did send 1100, the circuit would output whatever the minimized logic happens to compute for it, with no error raised. A don't care is a promise from the rest of the system that this will not be needed.
What a don't care is
Section titled “What a don't care is”A don't care is an input pattern for which the function's output may be either 0 or 1, because the pattern never occurs or because the output is ignored when it does. In a table or on a map it is written X.
A function with don't cares has three kinds of rows: those that must output 1, those that must output 0, and those that are free. Only the first two kinds are held to anything. The X in this section is a choice that the designer makes. The X that a simulator shows on a waveform is something else, a wire whose value is unknown, and Section 3.9 returns to how a SystemVerilog case statement states a don't care to a synthesis tool.
Don't cares come from two places. The first is inputs that cannot occur, such as the six unused codes of a digit in four bits. The second is outputs that are ignored: when another output already tells the rest of the circuit not to look at this one, the value on those rows is free too. Section 3.9 uses both in design examples. Don't cares in a function always come from its specification, and never from the designer's wishes: you cannot make a row a don't care just because it would be convenient.
Choosing the X values
Section titled “Choosing the X values”The example for this section is the map in Figure 3.7.1. Its function has five 1s, three X cells, and eight 0s.
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 0 | 0 | X | 0 |
| CD=01 | 1 | 1 | X | 1 |
| CD=11 | 1 | 1 | 0 | 0 |
| CD=10 | 0 | X | 0 | 0 |
Description: A four-variable Karnaugh map with columns AB and rows CD, drawn with brackets, containing five 1s, three X cells and eight 0s.
There are three obvious ways to treat the X cells, and the example works through each.
Every X as 0. The X cells become 0s, and the map is an ordinary map of five 1s, shown in Figure 3.7.2. The 2-by-2 square in the rows where D=1 and the columns where A=0 covers four of them and gives . The fifth 1, where A, B, C and D are 1, 0, 0, 1, has a neighbor across the edge of the map, the 1 where they are 0, 0, 0, 1, and the two form a horizontal pair wrapping around the left and right edges in the row where C=0 and D=1 and the columns where B=0, which gives .
F =
- 2-by-2 square: the rows where D=1 and the columns where A=0
- horizontal pair, wraps left and right: the row where C=0 and D=1 and the columns where B=0 (2 cells)
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 0 | 0 | 0 | 0 |
| CD=01 | 1 | 1 | 0 | 1 |
| CD=11 | 1 | 1 | 0 | 0 |
| CD=10 | 0 | 0 | 0 | 0 |
Groups drawn:
- not A and D: 2-by-2 square in the rows where D=1 and the columns where A=0; 4 cells.
- not B and not C and D: horizontal pair wrapping around the left and right edges in the row where C=0 and D=1 and the columns where B=0; 2 cells.
Description: The same map with the three X cells replaced by 0, and two groups: a square and a pair wrapped around the left and right edges.
Every X as 1. Now there are eight 1s, and every one of them must be covered, including the two former X cells where A, B, C and D are 1, 1, 0, 0 and 0, 1, 1, 0. No group of four holds either of them without also holding a 0, so each needs a pair of its own. The map in Figure 3.7.3 needs four terms, which is more than with every X as 0.
F =
- 2-by-2 square: the rows where D=1 and the columns where A=0
- row of four: the row where C=0 and D=1 (4 cells)
- vertical pair: the rows where C=0 and the column where A=1 and B=1 (2 cells)
- vertical pair: the rows where C=1 and the column where A=0 and B=1 (2 cells)
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 0 | 0 | 1 | 0 |
| CD=01 | 1 | 1 | 1 | 1 |
| CD=11 | 1 | 1 | 0 | 0 |
| CD=10 | 0 | 1 | 0 | 0 |
Groups drawn:
- not A and D: 2-by-2 square in the rows where D=1 and the columns where A=0; 4 cells.
- not C and D: row of four in the row where C=0 and D=1; 4 cells.
- A and B and not C: vertical pair in the rows where C=0 and the column where A=1 and B=1; 2 cells.
- not A and B and C: vertical pair in the rows where C=1 and the column where A=0 and B=1; 2 cells.
Description: The same map with the three X cells replaced by 1, and four groups.
Choosing wisely. The X cells are not obligations. A 1 must be covered, and an X may be covered if that makes a group bigger. Here one X helps: the cell where A, B, C and D are 1, 1, 0, 1 lets the pair from the first attempt grow into the row of four, whose term has two variables instead of three. The other two X cells are left out, and they stay 0 in the circuit.
F =
- 2-by-2 square: the rows where D=1 and the columns where A=0
- row of four: the row where C=0 and D=1 (4 cells); 1 of the cells is a don't care
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 0 | 0 | X | 0 |
| CD=01 | 1 | 1 | X | 1 |
| CD=11 | 1 | 1 | 0 | 0 |
| CD=10 | 0 | X | 0 | 0 |
Groups drawn:
- not A and D: 2-by-2 square in the rows where D=1 and the columns where A=0; 4 cells.
- not C and D: row of four in the row where C=0 and D=1; 4 cells, 1 of them don't care.
Description: The don't-care map with two groups: the same square as before, and a group of four that covers the row where C is 0 and D is 1 and uses one X cell.
This is the only minimal sum-of-products form of F (2 terms and 4 literals).
The answers of the three attempts agree on every input that matters: (for every input that is not a don't care) and (for every input that is not a don't care). They can differ only on the X rows. The first and the third, for example, differ at exactly one input pattern, where A, B, C and D are 1, 1, 0, 1: the first answer gives 0 there and the third gives 1. The third answer has two terms of two variables each, while the first has two terms with five variables in all. Setting every X to 1 was the worst of the three, not the best.
The rule
Section titled “The rule”The grouping rules of the previous section (Definition 3.6.1) stay in force with one addition: a group may hold X cells as well as 1s, and still never a 0. Two sentences cover what the example added. Every 1 must be in some group, and a group must never contain a 0. An X may be in a group, and it may be left out, whichever makes the groups bigger and fewer. An X that ends up inside a group is a 1 in the circuit that you build, and an X that is in no group is a 0. A group of nothing but X cells is never worth drawing, because it would add a term and cover no 1. The finished circuit has no "don't care" output: for each X pattern it gives a definite 0 or 1, decided by whether your groups happen to cover that cell, and that is why nothing else in the design may count on it.
Notice what this does not say. It does not say that every X should be grouped, and it does not say that none should. What matters is whether an X makes some group bigger.
Don't cares from impossible inputs
Section titled “Don't cares from impossible inputs”The digit example from the start of the section is typical. Take a function that is 1 when a digit in four bits is 5 or more.
The digits 5 to 9 are the codes 0101, 0110, 0111, 1000 and 1001. The codes 1010 to 1111 are impossible, so they are X. Figure 3.7.5 lists the function.
| A | B | C | D | F |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 0 |
| 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 1 |
| 0 | 1 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 | 1 |
| 1 | 0 | 0 | 1 | 1 |
| 1 | 0 | 1 | 0 | X |
| 1 | 0 | 1 | 1 | X |
| 1 | 1 | 0 | 0 | X |
| 1 | 1 | 0 | 1 | X |
| 1 | 1 | 1 | 0 | X |
| 1 | 1 | 1 | 1 | X |
Description: A sixteen-row truth table with inputs A, B, C and D and output F, with don't care entries X for the codes 1010 to 1111.
The same function with the six impossible codes treated as 0 needs three groups, all of them pairs, shown in Figure 3.7.6.
F =
- vertical pair: rows 01 and 11, column 01 (2 cells)
- vertical pair: rows 11 and 10, column 01 (2 cells)
- vertical pair: rows 00 and 01, column 10 (2 cells)
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 0 | 0 | 0 | 1 |
| CD=01 | 0 | 1 | 0 | 1 |
| CD=11 | 0 | 1 | 0 | 0 |
| CD=10 | 0 | 1 | 0 | 0 |
Groups drawn:
- not A and B and D: vertical pair in rows CD=01 and 11, column AB=01; 2 cells.
- not A and B and C: vertical pair in rows CD=11 and 10, column AB=01; 2 cells.
- A and not B and not C: vertical pair in rows CD=00 and 01, column AB=10; 2 cells.
Description: A four-variable Karnaugh map with five 1s and three pairs.
The don't cares change that. All of the codes that start with a 1 are either 8 or 9, which are 1s, or impossible, which are X, so the whole group of eight in columns AB=11 and 10 can be one group, with the one-variable term A. The remaining 1s are 5, 6 and 7. They share B, and each sits in a group of four whose other two cells are X: the 2-by-2 square in rows CD=01 and 11, columns AB=01 and 11 gives and the 2-by-2 square in rows CD=11 and 10, columns AB=01 and 11 gives .
F =
- group of eight: columns 11 and 10 (8 cells); 6 of the cells are don't care
- 2-by-2 square: rows 01 and 11, columns 01 and 11; 2 of the cells are don't care
- 2-by-2 square: rows 11 and 10, columns 01 and 11; 2 of the cells are don't care
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 0 | 0 | X | 1 |
| CD=01 | 0 | 1 | X | 1 |
| CD=11 | 0 | 1 | X | X |
| CD=10 | 0 | 1 | X | X |
Groups drawn:
- A: group of eight in columns AB=11 and 10; 8 cells, 6 of them don't care.
- B and D: 2-by-2 square in rows CD=01 and 11, columns AB=01 and 11; 4 cells, 2 of them don't care.
- B and C: 2-by-2 square in rows CD=11 and 10, columns AB=01 and 11; 4 cells, 2 of them don't care.
Description: A four-variable Karnaugh map with six X cells, a group of eight and two groups of four.
The result has three terms and five variables written in total, against three terms and nine variables without the don't cares, and the circuit gives the right answer for every digit from 0 to 9.
Course conventions
Section titled “Course conventions”How CSE 369 writes this
In CSE 369 we write the letter X in a cell for a don't care, and the rule is that a don't care is used only when it helps: it joins a group when that makes the group bigger, and otherwise it is left alone. A function with don't cares can have several equally good answers, so the book says "a minimal form" for it, as for any function with more than one minimum.
Pitfalls
Section titled “Pitfalls”Common pitfall
- Setting every X to 1 because "more 1s means bigger groups". Every 1 you create must be covered, and a new 1 that no large group can reach costs a term.
- Setting every X to 0 and never looking for a group that one X would enlarge. The answer is correct but larger than it needs to be.
- Drawing a group to cover an X. An X needs no cover, so a group of nothing but X cells adds a term for nothing.
- Deciding on a don't care because it is convenient. A don't care must come from the specification: an input that cannot occur or an output that is ignored.
- Relying on what the circuit outputs on a don't care. An X inside a group gives 1 in your circuit and an X outside every group gives 0, but another correct answer would choose differently, so nothing else in the system may depend on it.
Check your understanding
Section titled “Check your understanding”Take the quiz (5 questions)
How many terms does a minimal sum of products have for the function in Figure 3.7.1, using the X cells as you like?
Which of these is a minimal sum of products for that function?
How many variables does a minimal sum of products for the digit test "5 or more" write in total, using the impossible codes as don't cares?
A digit in four bits is odd. How many variables does a minimal sum of products write in total when the impossible codes are treated as 0?
Which of these rows can be marked as a don't care?
Exercises
Section titled “Exercises”A digit in four bits is odd. The codes 1010 to 1111 never occur. Find a minimal sum of products with the impossible codes as don't cares, and compare it with the answer when they are treated as 0.
Hint
Solution
The odd digits 1, 3, 5, 7 and 9 are the codes 0001, 0011, 0101, 0111 and 1001, and all of them have D equal to 1. The other cells where D is 1 are 1011, 1101 and 1111, which are impossible codes and therefore X. So every cell where D is 1 is either a 1 or an X, and together they form one group of eight in rows CD=01 and 11. The function is just .
F =
- group of eight: rows 01 and 11 (8 cells); 3 of the cells are don't care
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 0 | 0 | X | 0 |
| CD=01 | 1 | 1 | X | 1 |
| CD=11 | 1 | 1 | X | X |
| CD=10 | 0 | 0 | X | X |
Groups drawn:
- D: group of eight in rows CD=01 and 11; 8 cells, 3 of them don't care.
Description: A four-variable Karnaugh map with six X cells and one group of eight.
If the impossible codes were treated as 0, the map would have only five 1s and the best cover would be the 2-by-2 square in rows CD=01 and 11, columns AB=00 and 01 for and the horizontal pair wrapping around the left and right edges in row CD=01, columns AB=10 and 00 for . That is two terms and five variables, against one term and one variable. For the digits 0 to 9 the two circuits give the same answers.
F =
- 2-by-2 square: rows 01 and 11, columns 00 and 01
- horizontal pair, wraps left and right: row 01, columns 10 and 00 (2 cells)
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 0 | 0 | 0 | 0 |
| CD=01 | 1 | 1 | 0 | 1 |
| CD=11 | 1 | 1 | 0 | 0 |
| CD=10 | 0 | 0 | 0 | 0 |
Groups drawn:
- not A and D: 2-by-2 square in rows CD=01 and 11, columns AB=00 and 01; 4 cells.
- not B and not C and D: horizontal pair wrapping around the left and right edges in row CD=01, columns AB=10 and 00; 2 cells.
Description: A four-variable Karnaugh map with five 1s and two groups.
The map below is for a function of three inputs with three don't cares.
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| C=0 | X | X | 1 | 0 |
| C=1 | 0 | 1 | X | 0 |
Description: A three-variable Karnaugh map with two 1s, three X cells and three 0s.
- Find a minimal sum of products when every X is taken as 0.
- Find a minimal sum of products when every X is taken as 1.
- Choose the X cells to get the smallest sum of products you can, and say which X cells your answer uses as 1.
Hint
Solution
Part 1. With every X as 0, the two 1s are the cells where A, B and C are 0, 1, 1 and 1, 1, 0. They differ in two inputs, so they are not neighbors, and each needs its own term: .
F =
- single cell: the row where C=1 and the column where A=0 and B=1
- single cell: the row where C=0 and the column where A=1 and B=1
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| C=0 | 0 | 0 | 1 | 0 |
| C=1 | 0 | 1 | 0 | 0 |
Groups drawn:
- not A and B and C: single cell in the row where C=1 and the column where A=0 and B=1; 1 cell.
- A and B and not C: single cell in the row where C=0 and the column where A=1 and B=1; 1 cell.
Description: A three-variable map with two 1s that do not touch, each outlined alone.
Part 2. With every X as 1 there are five 1s. Four of them, the cells where B is 1, form a group of four with the term , and the fifth, where A, B and C are all 0, has a neighbor in that group: the cell where A is 0, B is 1 and C is 0. Together they give , two terms.
F =
- 2-by-2 square: the columns where B=1
- horizontal pair: the row where C=0 and the columns where A=0 (2 cells)
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| C=0 | 1 | 1 | 1 | 0 |
| C=1 | 0 | 1 | 1 | 0 |
Groups drawn:
- B: 2-by-2 square in the columns where B=1; 4 cells.
- not A and not C: horizontal pair in the row where C=0 and the columns where A=0; 2 cells.
Description: A three-variable map with five 1s, a group of four and a pair.
Part 3. The two 1s are both in the columns where B is 1, and the other two cells of those columns are X. Taking those two X cells as 1 makes a 2-by-2 square in the columns where B=1 with the term . The X cell where A, B and C are all 0 would add a 1 that needs covering, so it is left as 0. The answer is a single variable, and it uses two of the three X cells.
F =
- 2-by-2 square: the columns where B=1; 2 of the cells are don't care
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| C=0 | X | X | 1 | 0 |
| C=1 | 0 | 1 | X | 0 |
Groups drawn:
- B: 2-by-2 square in the columns where B=1; 4 cells, 2 of them don't care.
Description: A three-variable map with one group of four that holds both 1s and two X cells.
A digit in four bits is prime, that is 2, 3, 5 or 7. The codes 1010 to 1111 are impossible. Find a minimal sum of products and say which impossible codes your groups use.
Hint
Solution
The 1s are 0010, 0011, 0101 and 0111. Two groups of four cover them, and each one reaches into the impossible codes. The 2-by-2 square wrapping around the left and right edges in rows CD=11 and 10, columns AB=10 and 00 holds 2 and 3 together with the impossible codes 1010 and 1011, and its term is . The 2-by-2 square in rows CD=01 and 11, columns AB=01 and 11 holds 5 and 7 together with the impossible codes 1101 and 1111, and its term is . So the answer is . It uses four of the six impossible codes as 1 and leaves 1100 and 1110 as 0.
F =
- 2-by-2 square, wraps left and right: rows 11 and 10, columns 10 and 00; 2 of the cells are don't care
- 2-by-2 square: rows 01 and 11, columns 01 and 11; 2 of the cells are don't care
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 0 | 0 | X | 0 |
| CD=01 | 0 | 1 | X | 0 |
| CD=11 | 1 | 1 | X | X |
| CD=10 | 1 | 0 | X | X |
Groups drawn:
- not B and C: 2-by-2 square wrapping around the left and right edges in rows CD=11 and 10, columns AB=10 and 00; 4 cells, 2 of them don't care.
- B and D: 2-by-2 square in rows CD=01 and 11, columns AB=01 and 11; 4 cells, 2 of them don't care.
Description: A four-variable Karnaugh map with six X cells and two groups of four.
The function H is given as a product of sums, , and G is the complement of H. Find a minimal sum of products for G.
Hint
Solution
Complementing H and applying DeMorgan twice turns the product of sums into a sum of products:
| Expression | Law used |
|---|---|
| DeMorgan | |
| DeMorgan |
Each product marks the cells where one of H's sums is 0. The vertical pair in the column where A=0 and B=0 is where the sum is 0, the horizontal pair in the row where C=1 and the columns where A=0 is where is 0, and the horizontal pair in the row where C=0 and the columns where B=1 is where is 0.
The first two products lie inside a larger rectangle: the 2-by-2 square in the columns where A=0 has the term and covers both. Together with the pair for , it covers every 1 of G, so a minimal sum of products is .
G =
- 2-by-2 square: the columns where A=0
- horizontal pair: the row where C=0 and the columns where B=1 (2 cells)
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| C=0 | 1 | 1 | 1 | 0 |
| C=1 | 1 | 1 | 0 | 0 |
Groups drawn:
- not A: 2-by-2 square in the columns where A=0; 4 cells.
- B and not C: horizontal pair in the row where C=0 and the columns where B=1; 2 cells.
Description: A three-variable map with a group of four and a pair that overlap in one cell.