Sub topic 13
Five-variable K-maps
This chapter assumes you can already minimize four-variable functions with a Karnaugh map. That means Gray-code axes, groups of 1, 2, 4, 8 and 16 cells, wraparound, and prime and essential prime implicants. It also assumes you know minterm numbering. Here we extend the method to five variables and see where it stops being practical.
Why five variables need a different layout
A K-map works because physically adjacent cells differ in exactly one variable. A flat 2D grid can give every cell four such neighbors, with wraparound. A five-variable function has 32 minterms, and each minterm has five neighbors, one per variable. A flat grid cannot give a cell five neighbors, so the map is built as two stacked four-variable maps. The extra neighbor lives in the other layer.
Layout
Take variables A, B, C, D, E with A as the most significant bit. The minterm number is 16A + 8B + 4C + 2D + E.
- The two layers are A = 0 (minterms 0 to 15) and A = 1 (minterms 16 to 31).
- Inside each layer, rows are BC and columns are DE. Both use Gray order: 00, 01, 11, 10.
- A cell in layer A = 1 has the number of the same position in layer A = 0, plus 16.
Layer A = 0:
| BC \ DE | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 00 | m0 | m1 | m3 | m2 |
| 01 | m4 | m5 | m7 | m6 |
| 11 | m12 | m13 | m15 | m14 |
| 10 | m8 | m9 | m11 | m10 |
Layer A = 1 has the same pattern with every number increased by 16. For example, the top-left cell is m16 and the bottom-right cell is m26.
Adjacency rules
Two cells are adjacent when their minterm numbers differ in exactly one bit. In practice there are two kinds of adjacency:
- Within a layer: the normal four-variable rules, including wraparound from the left edge to the right edge and from the top row to the bottom row.
- Between layers: the cell at the same position in the other layer. These are the pairs mk and m(k+16). Think of the layers as transparent sheets laid on top of each other. A group that spans both sheets must cover the same positions on both.
Some textbooks draw the five-variable map as one 4 × 8 grid, with A splitting the left and right halves. Adjacency then also holds across the mirror lines: a cell is adjacent to its reflection about the center line of each half. This is the same adjacency in a different drawing. Use whichever layout your textbook uses, but stick to one layout for the whole problem.
Group sizes and literals
A group of 2^k cells must be a valid subcube. Every variable that changes inside the group is eliminated.
| Group size | Variables eliminated | Literals in the product term |
|---|---|---|
| 1 | 0 | 5 |
| 2 | 1 | 4 |
| 4 | 2 | 3 |
| 8 | 3 | 2 |
| 16 | 4 | 1 |
| 32 | 5 | 0 (the function is constant 1) |
A group that fits entirely in one layer keeps the literal for A (A' for layer 0, A for layer 1). A group that spans both layers in the same positions drops A.
Worked example
Minimize F(A,B,C,D,E) = Σm(1, 3, 5, 7, 9, 11, 13, 15, 16, 17, 21, 23, 24, 25, 29, 31).
Layer A = 0 (1 marks a minterm in F):
| BC \ DE | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 00 | 0 | 1 | 1 | 0 |
| 01 | 0 | 1 | 1 | 0 |
| 11 | 0 | 1 | 1 | 0 |
| 10 | 0 | 1 | 1 | 0 |
Layer A = 1:
| BC \ DE | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 00 | 1 | 1 | 0 | 0 |
| 01 | 0 | 1 | 1 | 0 |
| 11 | 0 | 1 | 1 | 0 |
| 10 | 1 | 1 | 0 | 0 |
Work through the groups in this order:
- In layer 0, the two middle columns form one group of 8. DE is 01 or 11 there, so E = 1 and the term is A'E.
- m16, m17, m24 and m25 are the top-left and bottom-left cells of layer 1 together with their right neighbors in the same layers' columns 00 and 01. They are joined by the row wraparound. B varies, E varies, and A = 1, C = 0, D = 0. The term is AC'D'.
- m21, m23, m29 and m31 are the four cells with C = 1 and E = 1 in layer 1. A tempting term is ACE. But the same positions (m5, m7, m13, m15) are all 1 in layer 0, so the group extends across layers to 8 cells. A drops out and the term is CE.
- The cells with D = 0 and E = 1 (m1, 5, 9, 13, 17, 21, 25, 29) form another valid 8-cell group, D'E. It is a prime implicant but not essential, because every cell it covers is also covered by A'E, CE or AC'D'.
Essential primes: A'E is the only group covering m3. AC'D' is the only group covering m16. CE is the only group covering m23. Together they cover all 16 minterms, so
F = A'E + CE + AC'D'
This has 7 literals. If you had stopped at the 4-cell group ACE, you would have written 8 literals, which is correct but not minimal.
Check it with code
The tabular method from the Quine-McCluskey chapter works unchanged for five variables. The program below finds all prime implicants (the string order is A B C D E, with - marking an eliminated variable) and checks the minimized expression against the original minterm list.
def combine(a, b):
diff = [i for i, (x, y) in enumerate(zip(a, b)) if x != y]
if len(diff) == 1 and a[diff[0]] != '-' and b[diff[0]] != '-':
i = diff[0]
return a[:i] + '-' + a[i + 1:]
return None
def prime_implicants(minterms, n):
terms = {format(m, f'0{n}b') for m in minterms}
primes = set()
while terms:
used, nxt = set(), set()
for a in terms:
for b in terms:
c = combine(a, b)
if c:
nxt.add(c)
used.update((a, b))
primes |= terms - used
terms = nxt
return sorted(primes)
minterms = [1, 3, 5, 7, 9, 11, 13, 15, 16, 17, 21, 23, 24, 25, 29, 31]
print(prime_implicants(minterms, 5))
def f(a, b, c, d, e):
return int(((not a) and e) or (c and e) or (a and not c and not d))
on = {m for m in range(32) if f(*[(m >> i) & 1 for i in (4, 3, 2, 1, 0)])}
print(on == set(minterms))The first line prints ['---01', '--1-1', '0---1', '1-00-'], which are D'E, CE, A'E and AC'D'. The second prints True.
Common errors
- Grouping different positions across layers. m5 and m22 are not adjacent. Only m5 and m21 are. A cross-layer group must occupy identical positions in both layers.
- Ignoring the layer you are not looking at. A 4-cell group in layer 1 may be half of an 8-cell group. Always check the matching positions in the other layer before you stop expanding.
- Reading the A literal wrongly. A group in one layer only keeps A (layer 1) or A' (layer 0). Forgetting this gives a term that is true for both layers.
- Missing wraparound inside a layer. The left and right columns, and the top and bottom rows, are still adjacent.
- Assuming the minimal cover is unique. Several covers may tie, as with D'E in the example. Counting literals is what decides, and ties are fine.
Don't-cares and product-of-sums work as in four variables. For POS, group the 0s and write each group as a sum with the literals complemented.
When to stop using the map
Five-variable maps are still tractable by hand, but spotting a subcube across two layers is error-prone. GATE questions rarely require more than this, and six-variable maps are almost never asked. If the function has more than about five variables, or the 1s look scattered, use the tabular method instead. For a quick check, find the essential primes first: any minterm that can be covered in only one way fixes a group.
Exercise
List the five minterms adjacent to m10 in a five-variable K-map.
Show answer
m10 = 01010. Flipping each bit in turn gives A: 11010 = m26, B: 00010 = m2, C: 01110 = m14, D: 01000 = m8, E: 01011 = m11. So the neighbors are m2, m8, m11, m14 and m26.
Exercise
Minimize G(A,B,C,D,E) = Σm(0, 2, 8, 10, 16, 18, 24, 26).
Show answer
In binary the minterms are 00000, 00010, 01000, 01010, 10000, 10010, 11000, 11010. A, B and D take both values, while C = 0 and E = 0 in all eight. The eight cells form one group (the four corners of each layer, joined by wraparound and the layer adjacency). G = C'E'.