---
title: Karnaugh maps in depth
heading: Four variables, don't-cares, and prime implicants
eyebrow: C7 · Lesson 14 · Karnaugh maps in depth
xp: 40
---

::: hook
Lesson 13 introduced the Karnaugh map as a picture of a truth table in which neighboring cells differ in one input, so that circling neighbors removes a variable. With four inputs the map becomes a 4 × 4 grid whose edges wrap around, and a systematic method is needed to be sure the result is minimal: find the largest possible groups (the prime implicants), take those that are unavoidable (the essential ones), and cover the rest as cheaply as possible. Inputs that can never occur, the don't-cares, are free to be either value, and using them well often halves a circuit.
:::

::: play
- F is written straight from its minterms, $\sum m(0, 2, 5, 7, 8, 10, 13, 15)$: eight AND terms of four inputs each. G is its minimized form, $\bar B\bar D + BD$.
- Compare them in the truth table: identical in all 16 rows. On the map, 0, 2, 8 and 10 are the four corners, a single group that wraps around both edges.
:::
:::

```sim logic
input A, B, C, D
output F, G
assign F = ~A&~B&~C&~D | ~A&~B&C&~D | ~A&B&~C&D | ~A&B&C&D | A&~B&~C&~D | A&~B&C&~D | A&B&~C&D | A&B&C&D
assign G = ~B & ~D | B & D
table: on
```

::: predict
## On a four-variable map, the four corner cells (minterms 0, 2, 8 and 10) are all 1. How many literals does the term covering them have?

- [ ] Four: corners aren't neighbors
- [ ] One
- [x] Two: $\bar B\bar D$
- [ ] Three

::: reveal
Two. The map wraps around both ways, so the four corners form a 2 × 2 block. Across those cells A and C both change, and B and D stay at 0, so the group is $\bar B\bar D$: a group of four removes two variables.
:::
:::

::: nameit
## The four-variable map

Rows are AB and columns CD, both in Gray order (00, 01, 11, 10), so every cell differs in one input from its four neighbors, **including across the edges**: the top row neighbors the bottom, the left column the right. Groups must be rectangles of 1, 2, 4, 8 or 16 cells; a group of $2^k$ cells is a product term with $k$ fewer literals.

## Prime and essential implicants

- An **implicant** is a group of 1s (a product term that's 1 only where f is 1).
- A **prime implicant** is a group that can't be made any bigger.
- An **essential** prime implicant covers some 1 that no other prime implicant covers; every minimal solution must include it.

**Method:** list the prime implicants; take all the essential ones; then cover any remaining 1s with as few (and as large) prime implicants as possible.

## Don't-cares

If some input combinations can never occur, or their outputs don't matter (a BCD digit never exceeds 9), mark them d. Treat each d as 1 when it lets a group grow, and as 0 otherwise; never make a group of d's alone. Different choices can give different, equally minimal answers.

## Products of sums

Group the 0s instead to get a minimal SOP for $\bar f$, then apply De Morgan to get a minimal POS for f. Sometimes the POS is smaller.
:::

::: example
## Minimize $f = \sum m(0, 2, 5, 7, 8, 10, 13, 15)$.

::: solution
1. **The corners.** Cells 0, 2, 8 and 10 give $\bar B\bar D$.
2. **The center block.** Cells 5, 7, 13 and 15 give BD.
3. **Cover the map.** Both are essential and together cover everything:
   $$\begin{aligned} f &= \bar B\bar D + BD \\ &= \overline{B \oplus D} \end{aligned}$$

**Answer:** $f = \bar B\bar D + BD$, which is $\overline{B \oplus D}$.
:::
:::

::: example
## Minimize $f = \sum m(1, 3, 7, 11, 15) + d(0, 2, 5)$.

::: solution
1. **The column.** The column CD = 11 (3, 7, 11, 15) gives CD.
2. **Cover minterm 1.** Minterm 1 is left; with don't-cares 0 and 2 it joins 3 in the top row, giving $\bar A\bar B$:
   $$f = CD + \bar A\bar B$$
3. **Another choice.** Using don't-care 5 instead, $\bar AD$ covers 1, 3, 5, 7:
   $$f = CD + \bar AD$$
   which is equally minimal.

**Answer:** $f = CD + \bar A\bar B$, or equally $f = CD + \bar AD$.
:::
:::

::: example
## Minimize $f = \sum m(0, 1, 2, 4, 5, 6, 8, 9, 12, 13, 14)$.

::: solution
1. **The big group.** Every cell with C = 0 is 1 (0, 1, 4, 5, 8, 9, 12, 13): an eight-cell group, $\bar C$, which leaves 2, 6 and 14.
2. **Cover 2 and 6.** Cells 0, 2, 4 and 6 form a square, $\bar A\bar D$, which covers 2 and 6.
3. **Cover 14.** Cells 4, 6, 12 and 14 form another, $B\bar D$, which covers 14.
4. **Put it together.**
   $$f = \bar C + \bar A\bar D + B\bar D$$
5. **Check it's minimal.** Each group is as large as possible and each covers a cell no other group does, so all three are essential and the result is minimal.

**Answer:** $f = \bar C + \bar A\bar D + B\bar D$.
:::
:::

::: check
kind: boolean
vars: A, B, C, D
answer: ~B & ~D
ops: and, or, not

## Minimize $\sum m(0, 2, 8, 10)$ (inputs A, B, C, D, A as the top bit).

::: right
Right. The four corners: $\bar B\bar D$.
:::

::: misses
- [any] Not yet. The map wraps around.
:::
:::

::: check
kind: boolean
vars: A, B, C, D
answer: ~A & ~C | A & C
ops: and, or, not

## Minimize $\sum m(0, 1, 4, 5, 10, 11, 14, 15)$.

::: right
Right. $\bar A\bar C + AC$: a block of four in the top-left and one in the bottom-right.
:::

::: misses
- [any] Not yet. Look for two groups of four.
:::
:::

::: check
kind: boolean
vars: A, B, C, D
answer: C & D | ~A & ~B
dontcare: 0, 2, 5
ops: and, or, not

## Minimize $\sum m(1, 3, 7, 11, 15) + d(0, 2, 5)$.

::: right
Right. CD plus one more group of four that uses the don't-cares.
:::

::: misses
- [C & D] That leaves minterm 1 uncovered.
- [any] Not yet. Group the column CD = 11 first.
:::
:::

::: check
kind: boolean
vars: A, B, C, D
answer: A | B & D | B & C
dontcare: 10, 11, 12, 13, 14, 15
ops: and, or, not

## A, B, C, D carry a BCD digit (0 to 9, A the top bit), so the codes 10 to 15 never occur. Write a minimal expression that's 1 when the digit is 5 or more.

::: right
Right. $A + BD + BC$: with the impossible codes as don't-cares, A alone covers 8 and 9.
:::

::: misses
- [any] Not yet. Mark 10 to 15 as don't-cares and look for big groups.
:::
:::

::: check
given: k = 1 | 3 | 4
answer: 4 - k
tolerance: 0.1%

## In a four-variable map, how many literals does a group of $2^k$ cells leave in its term, for k = {k}?

::: right
Right. Each doubling removes one variable: {answer}.
:::

::: misses
- [k] That's how many variables the group removes.
- [any] Not yet. Four inputs, minus one for each doubling.
:::
:::

::: check
kind: boolean
vars: A, B, C
answer: ~A | C
ops: and, or, not

## Find a minimal form of $f = \sum m(0, 1, 2, 3, 5, 7)$ by grouping its zeros.

::: right
Right. The zeros are 4 and 6, which group to $A\bar C$, so $\bar f = A\bar C$ and $f = \bar A + C$.
:::

::: misses
- [A & ~C] That's $\bar f$; apply De Morgan.
- [any] Not yet. Group the zeros, then invert.
:::
:::

::: check
kind: choice

## For $f = \sum m(0, 1, 5, 7)$ (three inputs), the prime implicants are $\bar A\bar B$, $\bar BC$ and AC. Which are essential?

- [ ] All three
- [x] $\bar A\bar B$ and AC
- [ ] Only $\bar BC$
- [ ] None

::: misses
- [1] Minterm 1 and minterm 5 are each covered by two prime implicants, so $\bar BC$ isn't needed.
- [3] $\bar BC$ covers only 1 and 5, both of which other prime implicants also cover.
- [4] Minterm 0 is covered only by $\bar A\bar B$, and 7 only by AC.
:::
:::

::: check
kind: boolean
vars: A, B, C, D
answer: ~C | ~A & ~D | B & ~D
ops: and, or, not

## Minimize $\sum m(0, 1, 2, 4, 5, 6, 8, 9, 12, 13, 14)$ (A the top bit).

::: right
Right: $\bar C + \bar A\bar D + B\bar D$.
:::

::: misses
- [any] Not yet. Start with the largest group: every cell with C = 0.
:::
:::

::: check
kind: boolean
vars: A, B, C, D
answer: (A | C) & (B | ~D)
ops: and, or, not

## A function is 0 in rows 0, 1, 3, 4, 5, 9 and 11 (A the top bit). Find its minimal product of sums.

::: right
Right: $(A + C)(B + \bar D)$.
:::

::: misses
- [any] Not yet. Group the 0s instead of the 1s, and write each group as a sum.
:::
:::

::: explain
## Why must a minimal sum of products include every essential prime implicant?

::: model
An essential prime implicant covers at least one 1 of the function that no other prime implicant covers. Any correct sum of products has to cover that 1 with some product term, and in a minimal solution every term can be taken to be a prime implicant, since a smaller group can always be enlarged to a prime one without adding literals. The only prime implicant that covers that 1 is the essential one, so it must be in the solution. Once the essential ones are chosen, only the leftover 1s need a choice.
:::
:::

::: practice

::: check
kind: boolean
vars: A, B, C, D
answer: B
ops: and, or, not

## Minimize $\sum m(4, 5, 6, 7, 12, 13, 14, 15)$.

::: misses
- [any] Two rows of four: a group of eight.
:::
:::

::: check
kind: boolean
vars: A, B, C, D
answer: D
ops: and, or, not

## Minimize $\sum m(1, 3, 5, 7, 9, 11, 13, 15)$.

::: misses
- [any] Every odd minterm: one variable.
:::
:::

::: check
given: n = 2 | 3 | 4
answer: 2^n
tolerance: 0.1%

## How many cells does an {n}-variable Karnaugh map have?

::: misses
- [any] One per truth-table row.
:::
:::
:::
