Part 06 / 12

Boolean Algebra Made Simple

Write AND as a times sign, OR as a plus and NOT as a bar, and a sentence like "the alarm sounds if the door is open and the system is armed, or the panic button is pressed" becomes D·S + P, a circuit you can simplify on paper before you build it.

7 sections 1 interactive
§ 6.1

Logic written as algebra

In 1847 an English schoolteacher, George Boole, published a short book arguing that reasoning could be written as algebra. Seven years later he set it out in full in An Investigation of the Laws of Thought. His letters stood for statements that could only be true or false, and his operations combined them. For eighty years it was a tool for logicians. Then, in the mid-1930s, engineers in Japan, the Soviet Union and the United States each showed that circuits of switches follow exactly the same rules, and Claude Shannon’s 1937 master’s thesis at MIT made the idea famous. has been the language of logic design ever since.

It uses three operations, written like this in this series:

Operation Written Read as Gate
AND A·B, or just AB “A and B” AND
OR A + B “A or B” OR
NOT A′, or A with a bar over it “not A” NOT

The signs are borrowed from arithmetic on purpose. With only 0 and 1, AND behaves exactly like multiplication: 1·1 = 1, and anything times 0 is 0. OR behaves like addition, with one exception: 1 + 1 = 1, because “true or true” is simply true. As in arithmetic, AND comes before OR, so D·S + P means (D·S) + P. Brackets work the usual way.

A bar over a letter is the classic way to write NOT, and you will see it on datasheets, as in CLR bar, an active-low clear input; part 10 explains how to read them. A bar is hard to type, so this series also writes NOT as a dash after the letter: A′. A bar or dash over a whole bracket inverts everything inside it: (A·B)′ is NAND.

§ 6.2

A few rules worth knowing

Boolean algebra has many rules, but a handful do most of the work. Each one can be checked by trying A = 0 and A = 1:

Rule In words
A·1 = A ANDing with 1 changes nothing
A·0 = 0 ANDing with 0 always gives 0
A + 0 = A ORing with 0 changes nothing
A + 1 = 1 ORing with 1 always gives 1
A·A = A and A + A = A saying something twice changes nothing
A·A′ = 0 a thing and its opposite are never both true
A + A′ = 1 one of a thing and its opposite is always true
(A′)′ = A two NOTs cancel

Most of the familiar rules of arithmetic still hold: you can swap the order (A·B = B·A), group as you like, and multiply out brackets, A·(B + C) = A·B + A·C. Every rule is a statement about circuits, too. A·1 = A says that an AND gate with one input tied high just passes the other input through; A·0 = 0 says that tying an input low keeps the output low whatever happens, which is how the unused gates in part 3 were silenced.

§ 6.3

De Morgan’s laws

Two rules, named after the British mathematician Augustus De Morgan, who stated them in 1847, are so useful that they deserve their own section:

(A·B)′ = A′ + B′

(A + B)′ = A′·B′

In words: “not (A and B)” is the same as “not A, or not B”. If it is not true that both are pressed, then at least one is not pressed. And “not (A or B)” is the same as “not A and not B”: if neither is pressed, then A is not pressed and B is not pressed.

The circuit version is easier to remember: flip the gate, invert everything. Change AND to OR (or OR to AND), and put a NOT on every input and on the output. A NAND gate, an AND with its output inverted, is therefore the same as an OR gate with both inputs inverted. A NOR is an AND with both inputs inverted.

This trick is behind the most useful idea in part 9. If a NAND is an OR with inverted inputs, then a NAND whose inputs have already been inverted is a plain OR. And a NAND can invert, by tying its two inputs together. So a single 74HC00 can make an OR gate, and, as it turns out, anything else.

§ 6.4

From a sentence to an expression

Real problems arrive as sentences. Take this one:

The alarm sounds if the door is open and the system is armed, or the panic button is pressed.

Four steps turn it into a circuit:

  1. Name the inputs, one letter each. D: the door is open. S: the system is armed. P: the panic button is pressed. Each is 1 when true.
  2. Name the output. Y: the alarm sounds.
  3. Translate the words. “And” becomes ·, “or” becomes +, “not” becomes ′. Use brackets wherever the sentence groups things: D·S + P.
  4. Check the truth table. Go through all eight rows and ask whether each answer makes sense. Door open but not armed, no panic: Y = 0. Good: you can air the house without setting it off.

The fourth step matters, because sentences are ambiguous in a way algebra is not. “The door is open and the system is armed or the panic button is pressed” could also mean D·(S + P): door open, and either armed or panic. Then the panic button would do nothing unless the door was open, which is not what anyone wants from a panic button. The brackets decide.

§ 6.5

Making it smaller

Every gate you leave out is one less to buy, wire and get wrong, so it pays to simplify before you build. Boolean algebra lets you do it on paper, much as you would simplify ordinary algebra. Suppose a porch light should come on

if it is dark and someone is there, or if it is dark and nobody is there.

Written out with D for dark and M for motion, that is D·M + D·M′: four gates, counting the NOT. Take out D, as in arithmetic: D·(M + M′). But M + M′ = 1, because someone either is or is not there, and D·1 = D. So the whole thing is just D: the light comes on when it is dark, with no gates at all. A clumsy rule hid a simple one.

On bigger expressions, guessing which rule to use next gets hard, so designers use methodical techniques. One, the Quine–McCluskey method, named after the logician Willard Quine and the engineer Edward McCluskey, finds every group of 1s in the truth table that can be merged and then picks the fewest groups that cover them all. The result is the simplest sum of products: an OR of ANDs. The instrument below uses it. For four inputs or fewer, many people do the same thing by eye with a grid called a Karnaugh map.

Simplest on paper is not always simplest in chips, though. A ⊕ B is one XOR gate, while its sum of products, A·B′ + A′·B, needs five gates. The instrument shows both counts.

§ 6.6 · interactive

Try it: from expression to circuit

Try it

From expression to circuit

Type an expression, or pick an example. The circuit and the truth table follow as you type. Click a row of the table, or a letter at the top of the circuit, to set the inputs. Then draw the simplified circuit and compare.

Y = D·S + P

DSPY=0
DSPY
000
001
010
011
100
101
110
111
Simplest sum of products

Y = D·S + P

2 gates either way: this is already as simple as a sum of products gets. Counted as two-input gates and NOTs.

Up to four inputs, each a single letter. AB means A·B. Gates are counted as two-input gates and NOTs, the way you would build them from 74HC chips; a NOT around a whole AND, OR or XOR is drawn as a NAND, NOR or XNOR.

§ 6.7

Build it: the alarm

The alarm needs one AND and one OR, so it takes two chips: a 74HC08 for D·S and a 74HC32 to OR the result with P. Each chip gets its own power wires and its own 100 nF capacitor.

  1. Fit the 74HC08 with pin 1 in f14 and the 74HC32 with pin 1 in f24. Power both (a14 and a24 to +, j20 and j30 to −), add a 100 nF capacitor across the top rails beside each pin 14, and tie each chip’s pins 4, 5, 9, 10, 12 and 13 to −.
  2. Three buttons with pull-downs, as in part 4: D across columns 2 and 4, S across 6 and 8, P across 10 and 12, each with its left column wired to + and a 10 kΩ from its right column to −.
  3. D to pin 1 of the AND (h4 to h14), S to pin 2 (g8 to g15), P to pin 2 of the OR (i12 to i25).
  4. The AND’s output, pin 3, to the OR’s pin 1: h16 to h24.
  5. The OR’s output, pin 3, to the LED: g26 to g33, then 330 Ω from h33 to h36, the LED from i36 (long leg) to i37, and j37 to −.
What you should see

Press P alone: the LED lights. Press D alone, or S alone: nothing. Press D and S together: the LED lights. Test all eight combinations against the truth table in the instrument; every row should match.

Writing logic as algebra saves gates. The next part saves frustration: how to read a chip’s pinout and datasheet, so you always know which leg is which.

Sources for this part

Boolean algebra

De Morgan and simplification

Series Logic on a Breadboard
Menu

Gears & Signals · Static site · No trackers