Digital Logic Fundamentals
Senior 4 · ICT
Digital Logic Fundamentals
Lesson 5 of 5
25 min
In lesson 4 the majority voter came out as : 3 NOT gates, 4 three-input AND gates and a four-input OR gate, 8 gates in all. The same truth table can be produced by : three 2-input AND gates and one OR gate. Half the gates means a cheaper chip, less power and heat, a faster signal (it passes through fewer gates) and fewer parts that can fail. Optimising a circuit means finding the simplest expression with the same truth table. There are two tools: the laws of Boolean algebra, and the Karnaugh map.
Definition
Equivalent expressions: expressions with identical truth tables. Simplification: replacing an expression by an equivalent one with fewer terms and fewer variables per term.
Karnaugh map (K-map): a truth table drawn as a grid in which neighbouring cells differ in exactly one input, so that 1s that can be combined sit next to each other. Its rows and columns follow Gray code order (00, 01, 11, 10), not counting order.
| Law | OR form | AND form |
|---|---|---|
| Identity | ||
| Null (annulment) | ||
| Idempotent | ||
| Complement | ||
| Double negation | ||
| Commutative | ||
| Associative | ||
| Distributive | ||
| Absorption | ||
| Redundancy | ||
| De Morgan | ||
Any law can be proved with a truth table. For De Morgan's AND form, and both give 1, 1, 1, 0 in the rows 00, 01, 10, 11. In words: break the bar and change the sign. De Morgan's laws also show how to build any circuit from NAND gates alone, for example , which is two NANDs feeding a third.
Worked example 1: simplify the majority voter with algebra
Gates: 8 before, 4 after; gate inputs: 19 before (3 + 12 + 4), 9 after (6 + 3).
Worked example 2: a shorter one
Simplify .
By the redundancy law in the form :
Check by truth table: only when , and . Three terms became one NOT and one OR.
Algebra needs the right law at the right moment. A K-map makes the grouping visible.
The same answer as worked example 1, in three loops and no algebra.
Worked example 3: a loop that wraps around
A function is 1 in rows 000, 010, 100 and 110, and 0 elsewhere. On the K-map:
| A \ BC | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 0 | 1 | 0 | 0 | 1 |
| 1 | 1 | 0 | 0 | 1 |
Columns 00 and 10 are neighbours (they differ only in ), because the map wraps from the right edge to the left. One loop of four cells covers all the 1s. Inside it, and both change, and throughout, so Four minterms become a single NOT gate.
Press Run. The program prints both outputs for all 8 input rows and then Equivalent: True. A computer can test equivalence this way for small circuits; for big ones, engineers use optimisation software, but it applies the same laws.
Computer Science Lessons: Karnaugh Maps, Simplify Boolean Expressions. Watch how the cells are ordered, how the loops are drawn, and how each loop is read as a term, then redo the majority-voter map yourself.
Warning
Loops must be rectangles of 1, 2, 4 or 8 cells. A loop of 3 cells, or a diagonal pair, is not allowed: the cells in it do not share a simpler term.
Keep the Gray-code order. Columns in counting order (00, 01, 10, 11) put 01 next to 10, which differ in two bits, and the map gives wrong groups.
De Morgan changes the sign too. is , not .
Tip
Test the answer, not the method. After simplifying, check two or three rows of the original truth table, especially a row where the output is 0. A wrong simplification nearly always fails on one of them.
Practice
Key points
Further reading
Sources and credits
itertools.product: itertools, Python documentation, Python Software Foundation (linked for reference).This lesson adapts CC BY-SA material and is shared under CC BY-SA 4.0.
# Check that the simplified majority voter is equivalent to the original.
from itertools import product
def original(A, B, C):
return (not A and B and C) or (A and not B and C) or (A and B and not C) or (A and B and C)
def simplified(A, B, C):
return (A and B) or (B and C) or (A and C)
for A, B, C in product((0, 1), repeat=3):
print(A, B, C, int(bool(original(A, B, C))), int(bool(simplified(A, B, C))))
same = all(bool(original(*row)) == bool(simplified(*row)) for row in product((0, 1), repeat=3))
print("Equivalent:", same)Quick check
Which expression is equal to NOT(A AND B), by De Morgan's law?