C7 · Lesson 4 · Boolean algebra and gates
Logic you can wire
George Boole wrote down an algebra of true and false in 1854, eighty years before anyone built a computer. Claude Shannon noticed in 1937 that relay circuits obey exactly that algebra, so you could design switching circuits with equations, simplify the equations, and build fewer switches. Every chip since is designed that way: with gates that compute AND, OR and NOT, and algebra that rearranges them.
Play
- Two switches feed every common gate at once. Click A and B to flip them, and watch the lamps.
- Which gates light for exactly one input being 1? For both? For neither?
- Compare NAND with AND, and XNOR with XOR. What does the bubble on a gate's output do?
Predict
Which expression is the same as ¬(A·B)?
¬A + ¬B. "Not both" is the same as "at least one is false": that's De Morgan's law. Its twin, ¬(A + B) = ¬A·¬B, says "neither" is "both are false". De Morgan's laws let you push NOTs through ANDs and ORs, swapping one for the other, which is how designers turn any logic into NAND gates alone.
Name it
Boolean algebra
The gates, with A·B for AND, A + B for OR, A ⊕ B for XOR and ¬A (or A′) for NOT:
| A | B | A·B | A + B | A ⊕ B | ¬(A·B) | ¬(A + B) |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 |
A bubble on a gate's output means NOT: NAND, NOR, XNOR.
Laws (each also holds with · and + swapped, and 0 and 1 swapped):
- identity: A·1 = A, A + 0 = A; null: A·0 = 0, A + 1 = 1;
- idempotence: A·A = A; complement: A·¬A = 0, A + ¬A = 1;
- absorption: A + A·B = A, A·(A + B) = A;
- distribution: A·(B + C) = A·B + A·C, and also A + B·C = (A + B)·(A + C);
- De Morgan: ¬(A·B) = ¬A + ¬B, ¬(A + B) = ¬A·¬B.
Universal gates. NAND alone can build anything: NOT A = NAND(A, A), AND is NAND followed by NOT, and OR is NAND of the inverted inputs (De Morgan). NOR is universal too. Chips are built mostly from NANDs and NORs because in CMOS they're the simplest gates (lesson 7).
XOR is "one or the other but not both": A ⊕ B = A·¬B + ¬A·B. It's the sum bit of an adder and a parity checker.
Worked example
Simplify algebraically.
Show the solution
- Distribute OR over AND.
- Check it in words. If A is 1 the output is 1 anyway; if A is 0, and the term is just B.
Answer .
Worked example
Write with inversions only on single variables.
Show the solution
- De Morgan on the OR.
- De Morgan on the AND.
Answer .
Worked example
Simplify .
Show the solution
- Spot the redundant term. The term BC is redundant: whenever B and C are both 1, either A is 1, and AB is 1, or A is 0, and is 1.
- Show it algebraically. and each piece is absorbed: ABC into AB and into .
- Drop it. This is the consensus theorem.
- When to keep it. In hardware the "redundant" term isn't always useless: it covers the moment A switches, and lesson 19 adds it back to remove a glitch.
Answer .
Check
Write ¬(A·B) without a NOT applied to anything but a single input.
Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.
Check
Simplify A + A·B.
Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.
Check
Write XOR using only AND, OR and NOT.
Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.
Check
With A = 0 and B = 0, what does a NOR gate output?
Check
Factor A·B + A·C.
Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.
Check
Simplify .
Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.
Check
Write with inversions only on single variables.
Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.
Explain why
Why can any logic function be built from NAND gates alone?
A NAND gate with both inputs tied together is a NOT gate. A NAND followed by a NOT is an AND. And by De Morgan's law, A OR B equals NAND of NOT A and NOT B, so OR is a NAND fed by two NANDs used as inverters. Since NOT, AND and OR can express any truth table (as a sum of products), and each can be made from NANDs, so can any function.
Practice
Keep practicing
4 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.