Karnaugh Maps and Two-Level Minimization
In questa pagina 8
Simplifying with algebra needs insight and no algorithm guarantees the simplest form. The Karnaugh map is a graphical method that reliably gives a minimal sum of products (or, dually, a minimal product of sums). It works well up to 4 variables; synthesis tools use similar principles for larger functions.
How a map is built
The map has one cell per truth-table row, i.e. per minterm (Canonical Forms - Minterms, Maxterms, SOP and POSA minterm is a product containing every variable exactly once and is 1 on a single truth-table row; a maxterm is the dual sum and is 0 on a single row; with n variables there are 2^n of each and the complement of minterm i is maxterm i. Canonical SOP = sum of minterms of rows with F=1; canonical POS = product of maxterms of rows with F=0. They come mechanically from the truth table but are redundant, so they are the starting point for minimization. SOP and POS are two-level circuits.Canonical Forms - Minterms, Maxterms, SOP and POS →). Variables are spread over rows and columns, with combinations in Gray code (, not ), so neighbouring cells differ in one variable (Hamming distance ).
The map is wrapped around: left edge adjacent to right edge, top to bottom (cylinder with 3 variables, torus with 4). E.g. the four corners of a 4-variable map are all adjacent. Cell numbering (minterm index):
| 00 | 01 | 11 | 10 | |
|---|---|---|---|---|
| 0 | 0 | 1 | 3 | 2 |
| 1 | 4 | 5 | 7 | 6 |
| 00 | 01 | 11 | 10 | |
|---|---|---|---|---|
| 00 | 0 | 1 | 3 | 2 |
| 01 | 4 | 5 | 7 | 6 |
| 11 | 12 | 13 | 15 | 14 |
| 10 | 8 | 9 | 11 | 10 |
Put 1 in the cells of the function minterms.
Why grouping simplifies
Two adjacent cells differ in one variable; if both are 1 that variable disappears, by adjacency : and give .
A rectangular group of cells (1, 2, 4, 8, 16) of 1s eliminates variables; its product contains only the variables that do not change inside the group, direct if 1, negated if 0.
Cells (4 variables): constants , , group .
Implicants and cover
- Implicant: product for which the function is 1 whenever the product is 1 (a group of 1s).
- Prime implicant (PI): implicant not contained in a larger one (maximal group).
- Essential prime implicant (EPI): PI that is the only one covering at least one minterm; it is in every cover.
- Cover: set of implicants covering all 1s. Goal: minimum cover = all EPIs plus the fewest other PIs covering the remaining minterms.
Procedure. (1) Fill the map. (2) Find the PIs: largest rectangles of adjacent 1s, using wrapped edges. (3) Find the EPIs: 1s covered by one PI only. (4) Cover remaining 1s with few other PIs (equivalent choices mean the minimal form is not unique). (5) Write the sum of the group products and verify on some rows.
Worked examples
Two variables. : groups () and (), both essential: .
Three variables with a choice. :
| 00 | 01 | 11 | 10 | |
|---|---|---|---|---|
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 1 | 0 | 1 |
PIs: ; ; (adjacent across the edge); . Essential: (only cover of ) and (only cover of ). Cell can be covered by either of the other two: both with 3 products and 6 literals. Check: cell gives , cell () gives .
Four variables, three essentials. :
| 00 | 01 | 11 | 10 | |
|---|---|---|---|---|
| 00 | 0 | 1 | 1 | 0 |
| 01 | 1 | 1 | 1 | 1 |
| 11 | 1 | 1 | 1 | 0 |
| 10 | 0 | 1 | 1 | 0 |
Columns (8 cells): ; cells : ; row : . All essential ( only by ; only by ; only by ): , against 11 four-literal minterms.
Four variables, essentials plus completion. :
| 00 | 01 | 11 | 10 | |
|---|---|---|---|---|
| 00 | 1 | 1 | 0 | 1 |
| 01 | 0 | 1 | 1 | 1 |
| 11 | 0 | 0 | 0 | 1 |
| 10 | 1 | 1 | 0 | 1 |
Column (cells ): ; wrapped square : ; both essential. Cells remain: group gives . .
If two covers have the same products and literals both are minimal; for gate input cost compare the totals.
Product of sums (POS)
The SOP groups the 1s. The POS is obtained by grouping the 0s, i.e. working on : (1) group the zeros like the ones, getting a minimal SOP of ; (2) complement with De Morgan: for each group write a sum of the variables that do not change, direct if 0 in the group, negated if 1; (3) is the product of these sums.
A zero group giving for becomes the sum .
Example: :
| 00 | 01 | 11 | 10 | |
|---|---|---|---|---|
| 00 | 1 | 1 | 1 | 0 |
| 01 | 1 | 0 | 0 | 0 |
| 11 | 1 | 1 | 1 | 0 |
| 10 | 0 | 0 | 0 | 0 |
Zero groups (all essential): ( for , sum ); (, sum ); (, sum ). The minimal SOP has 4 products of 3 literals (12 literals); the POS has 3 sums and 7 literals: here the POS is much more compact because the zeros are fewer and better grouped. Work on the phase (1 or 0) with fewer cells and larger groups. Check: cell gives , cell gives , so .
Don't care conditions
The function may be not completely specified: for some inputs the output is indifferent, because the combination cannot occur (e.g. codes - at a BCD input, Binary Codes - BCD, ASCII, Unicode, Parity and GrayAn n-bit code distinguishes 2^n elements. BCD encodes each decimal digit on 4 bits (1010 to 1111 unused; it differs from the plain binary of the number). ASCII uses 7 bits for 128 characters; Unicode UTF-8 uses 1 to 4 bytes and is ASCII compatible. A parity bit detects errors on an odd number of bits. Hamming distance is the number of differing bits. Gray code makes consecutive numbers differ by one bit and is built by reflection or with g_i = b_i xor b_(i+1).Binary Codes - BCD, ASCII, Unicode, Parity and Gray →) or the result does not matter. An X is written in the table and map.
An X may be used as 1 or as 0, whichever enlarges the groups. An X inside a group counts as 1 (and is not covered explicitly); one left out counts as 0; never make a group of only Xs; covering Xs is not mandatory; an X does not make a group essential (EPIs are defined on the 1s only).
Example: BCD digit, for ; rows - are don't care.
| 00 | 01 | 11 | 10 | |
|---|---|---|---|---|
| 00 | 0 | 1 | 1 | 1 |
| 01 | 0 | 1 | 1 | 0 |
| 11 | X | X | X | X |
| 10 | 0 | 0 | X | X |
Cells : (no X used); cells : (uses the Xs of and ). (2 products, 4 literals); treating Xs as 0 would need (5 literals). In POS: zeros in cells ; groups (sum ), (sum ), rows and (sum ): , equivalent to the SOP on valid combinations (on the Xs the two may differ, which is fine).
XOR and parity functions
The 3-variable XOR (odd parity, 1 if the number of 1s is odd) is , with a checkerboard map:
| 00 | 01 | 11 | 10 | |
|---|---|---|---|---|
| 0 | 0 | 1 | 0 | 1 |
| 1 | 1 | 0 | 1 | 0 |
No 1 is adjacent to another (minterms at Hamming distance 2), so there are no groups larger than one cell: the minimal SOP equals the canonical one (4 products of 3 literals) and does not simplify. Use XOR gates: with two gates. The same holds for 4 variables (checkerboard of 8 odd minterms) and for the even-parity function (replace XOR with XNOR). This function is the sum bit of a full adder (Binary Adders and SubtractorsHalf adder: S = X xor Y, C = XY. Full adder with carry in Z: S = X xor Y xor Z, C = XY + XZ + YZ = G + PZ with P = X xor Y, G = XY; two half adders and an OR. The n-bit ripple carry adder chains n full adders, so delay grows linearly with n. Adder-subtractor: XOR of each B bit with a control S, which is also the carry in, computes A+B or A+not B+1 = A-B. The 2-bit multiplier uses 4 ANDs and 2 half adders.Binary Adders and Subtractors →).
Common mistakes
- Ordering cells in binary instead of Gray.
- Ignoring the wrapped edges.
- Groups whose size is not a power of 2 or not rectangular; non-maximal groups (useless literals).
- Wrong literal sign: direct if 1 in the whole group, negated if 0 (reversed for POS zero groups).
- Groups of Xs not linked to any 1; treating Xs as mandatory.
- Trying to group a checkerboard map.
Versione ripasso
- Map: one cell per minterm, rows/columns in Gray code (); edges wrap around; up to 4 variables. 4-variable indices: / / / .
- Group of ones: eliminates variables (); keep constant variables, direct if 1, negated if 0. Cells .
- Implicant, prime (maximal), essential (unique cover of some minterm); minimum cover = all EPIs + fewest other PIs.
- Procedure: fill, find PIs, find EPIs, cover the rest, write the SOP, verify.
- Examples: ; (or for the last term); ; .
- POS: group the 0s; each group gives a sum, variables direct if 0, negated if 1; = product. (7 literals vs 12 for the SOP). Use the phase with fewer cells.
- Don't care (X): use as 1 or 0 to enlarge groups; no groups of only X; not mandatory; never makes a group essential. BCD "": ; POS (equal on valid inputs).
- XOR/parity: , checkerboard, no groups: do not simplify, use XOR gates; parity via XNOR; it is the full-adder sum bit.
- Mistakes: binary-ordered cells; ignored wrapped edges; group sizes not powers of 2; non-maximal groups; wrong signs (POS reversed); groups of only X; grouping a checkerboard.