C74 of 57
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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)?

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:

ABA·BA + BA ⊕ B¬(A·B)¬(A + B)
0000011
0101110
1001110
1111000

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 A+A¯B algebraically.

Show the solution
  1. Distribute OR over AND. A+A¯B=(A+A¯)(A+B)=1⋅(A+B)=A+B
  2. Check it in words. If A is 1 the output is 1 anyway; if A is 0, A¯=1 and the term is just B.

Answer A+A¯B=A+B.

Worked example

Write AB+C¯ with inversions only on single variables.

Show the solution
  1. De Morgan on the OR. AB+C¯=AB¯⋅C¯
  2. De Morgan on the AND. AB¯⋅C¯=(A¯+B¯)C¯

Answer AB+C¯=(A¯+B¯)C¯.

Worked example

Simplify AB+A¯C+BC.

Show the solution
  1. 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 A¯C is 1.
  2. Show it algebraically. BC=BC(A+A¯)=ABC+A¯BC and each piece is absorbed: ABC into AB and A¯BC into A¯C.
  3. Drop it. AB+A¯C+BC=AB+A¯C This is the consensus theorem.
  4. 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 AB+A¯C+BC=AB+A¯C.

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 AB+A¯C+BC.

Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.

Check

Write A(B+C)¯ 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?

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.