Karnaugh map
From Free net encyclopedia
The Karnaugh map, also known as a Veitch diagram (K-map or KV-map for short), is a tool to facilitate management of Boolean algebraic expressions. A Karnaugh map is unique in that only one variable changes value between squares, in other words, the rows are columns are ordered according to the principles of Gray code.
Contents |
History and nomenclature
The Karnaugh map was invented in 1953 by Maurice Karnaugh, a telecommunications engineer at Bell Labs.
Usage in boolean logic
Normally, extensive calculations are required to obtain the minimal expression of a Boolean function, but one can use a Karnaugh map instead.
Problem solving uses
- Karnaugh maps make use of the human brain's excellent pattern-matching capability to decide which terms should be combined to get the simplest expression.
- K-maps permit the rapid identification and elimination of potential race hazards, something that boolean equations alone cannot do.
- A Karnaugh map is an excellent aid for simplification of up to six variables, but with more variables it becomes hard even for our brain to discern optimal patterns.
Karnaugh maps also help teach about Boolean functions and minimization.
Example
Consider the following function:
- f(A, B, C, D) = E(4, 8, 9, 10, 11, 12, 14, 15)
The values inside E tell us which rows have output 1.
This function has this truth table:
A B C D f 0. 0 0 0 0 0 1. 0 0 0 1 0 2. 0 0 1 0 0 3. 0 0 1 1 0 4. 0 1 0 0 1 5. 0 1 0 1 0 6. 0 1 1 0 0 7. 0 1 1 1 0 8. 1 0 0 0 1 9. 1 0 0 1 1 10. 1 0 1 0 1 11. 1 0 1 1 1 12. 1 1 0 0 1 13. 1 1 0 1 0 14. 1 1 1 0 1 15. 1 1 1 1 1 |
The input variables can be combined in 16 different ways, so our Karnaugh map has to have 16 positions. The most convenient way to arrange this is in a 4x4 grid.
The binary digits in the map represent the function's output for any given combination of inputs. We write 0 in the upper leftmost corner of the map because f = 0 when A = 0, B = 0, C = 1, D = 0. Similarly we mark the bottom right corner as 1 because A = 1, B = 0, C = 0, D = 0 gives f = 1. Note that the values are ordered in a Gray code, so that precisely one variable flips between any pair of adjacent cells.
After the Karnaugh map has been constructed our next task is to find the minimal terms to use in the final expression. These terms are found by encircling groups of 1's in the map. The encirclings must be rectangular and must have an area that is a positive power of two (i.e. 2, 4, 8, …). The rectangles should be as large as possible without containing any 0's. The optimal encirclings in this map are marked by the green, red and blue lines.
For each of these encirclings we find those variables that have the same state in each of the fields in the encircling. For the first encircling (the red one) we find that:
- The variable A maintains the same state (1) in the whole encircling, therefore it should be included in the term for the red encircling.
- Variable B does not maintain the same state (it shifts from 1 to 0), and should therefore be excluded.
- C does not change.
- D changes.
Thus the first term in the Boolean expression is AC.
For the green encircling we see that A and B maintain the same state, but C and D change. B is 0 and has to be negated before it can be included. Thus the second term is AB'.
In the same way, the blue rectangle gives the term BC'D' and so the whole expression is: AC + AB′+ BC′D′.
The grid is toroidally connected, which means that the rectangles can wrap around edges, so ABD′ is a valid term, although not part of the minimal set.
The inverse of a function is solved in the same way by encircling the 0's instead.
In a Karnaugh map with n variables, a Boolean term mentioning k of them will have a corresponding rectangle of area 2n-k.
Karnaugh maps also allow easy minimisations of functions whose truth tables include "don't care" conditions (that is sets of inputs for which the designer doesn't care what the output is) don't care conditions can be included in a ring to make it larger but do not have to be ringed. They are usually indicated on the map with a hyphen/dash in place of the number.
Race hazards
Karnaugh maps are useful for detecting and eliminating race hazards.
- In the above example, a potential race condition exists when C and D are both 0, A is a 1, and B changes from a 0 to a 1 (moving from the green state to the blue state).
- For this case, the output is defined to remain unchanged at 1, but because this transition is not covered by a specific term in the equation, a potential for a glitch (a momentary transition of the output to 0) exists. This is very easy to spot using a Karnaugh map, because a race condition may exist when moving between any pair of adjacent, but disjointed, regions circled on the map.
Further examples
- A harder possible glitch to spot is if D was 0 and A and B were both 1, with C changing from 0 to 1. In this case the glitch wraps around from the bottom of the map to the top of the map.
Whether these glitches do occur depends on the physical nature of the implementation, and whether we need to worry about it depends on the application.
In this case, an additional term of +AD' would eliminate the potential race hazard, bridging between the green and blue output states or blue and red output states.
The term is redundant in terms of the static logic of the system, but such redundant terms are often needed to assure race-free dynamic performance.
When not to use K-maps
The diagram becomes cluttered and hard to interpret if there are more than two variables on an axis. This argues against the use of Karnaugh maps for expressions with more than four variables. For such expressions, the Quine-McCluskey algorithm, also called the method of prime implicants, should be used.
This algorithm generally finds most of the optimal solutions quickly and easily, but selecting the final prime implicants (after the essential ones are chosen) may still require a brute force approach to get the optimal combination (though this is generally far simpler than trying to brute force the entire problem).
See also
External links
- Karnaugh Maps 101
- Open source Karnaugh Maps minimization software
- Commercial software advertisement for Karnaugh Minimizer
References
- Maurice Karnaugh, The Map Method for Synthesis of Combinational Logic Circuits, Trans. AIEE. part I, 72(9):593-599, November 1953.ar:خريطة كارنو فايتش
de:Karnaugh-Veitch-Diagramm es:Mapa de Karnaugh fr:Table de Karnaugh it:Mappa di Karnaugh he:מפת קרנו nl:Karnaugh-diagram ja:カルノー図 pl:Metoda Karnaugh pt:Mapa de Karnaugh ro:Diagramă Karnaugh sr:Карно мапа sv:Karnaughdiagram zh:卡诺图