TactivergeLite

Lite / Building Machines That Respond / Week 16

Everything from NAND

If you could only manufacture one kind of gate, could you still build a whole computer? Engineers found the answer is yes, twice.

About 35 min · 3 goals · Checked by automated tests · Full interactive version

Why should I care?

NAND gates are simple to make with transistors, so whole chips (and early computers) have been built almost entirely from them. Showing that everything can be made from one gate is also your first real piece of computer architecture: building bigger blocks from smaller ones.

Predict

What does a NAND gate do if you connect both of its inputs to the same signal A?

  1. Always outputs 0
  2. Outputs A
  3. Outputs NOT A
  4. Always outputs 1
Guess first, then reveal

With both inputs equal, A · A = A, so NAND gives ¬(A · A) = ¬A. One NAND with tied inputs is a NOT gate.

Discover

Do Level 2 of the virtual computer: wire NOT from one NAND, XOR from at most four NANDs, and a half adder from at most two gates. Read the live truth table after every wire you add, and keep notes on which NAND does which job.

What the interactive shows (text version)

In the virtual computer's circuit builder, a NAND with both inputs joined acts as NOT. Four NANDs make XOR: the first NAND feeds two more, each also fed by one input, and a last NAND combines them. A half adder uses XOR for the sum and AND for the carry. The live truth table confirms each row.

You can also open the interactive on the full site when you have a faster connection.

Watch (optional)

Watch for: Watch for how a transistor acts as a voltage-controlled switch. That switch is all a NAND gate needs.

Follows doped silicon into a transistor, the switch that every logic gate is built from.

“How a transistor works” by Ben Eater (opens YouTube; streaming video uses a lot of data)

The video is optional. Everything you need is in this lesson's text.

Understand

NOT and AND

NOT A = NAND(A, A). A AND B = NOT(NAND(A, B)), which is two NANDs: one NAND, then a NAND with its inputs tied as a NOT.

OR via De Morgan

De Morgan says A + B = ¬(¬A · ¬B), which is NAND(¬A, ¬B). So OR takes three NANDs: two as NOTs on the inputs, and one to combine them.

XOR in four

Let g1 = NAND(A, B). Then g2 = NAND(A, g1), g3 = NAND(B, g1), and Y = NAND(g2, g3) = A ⊕ B. Check row 11: g1 = 0, g2 = 1, g3 = 1, Y = 0. Row 10: g1 = 1, g2 = 0, g3 = 1, Y = 1.

Why one gate type helps

A factory that makes one well-tested cell can tile it millions of times. Designers still use many gate types today, but the fact that NAND (or NOR) is universal shows how little you need to compute anything.

Explain it another way

Intuitive

It is like having only one Lego brick shape and discovering you can still build every model, just with more bricks.

Technical

A gate set is functionally complete if every Boolean function can be expressed with it. {NAND} and {NOR} are each complete; {AND, OR} is not, because it cannot produce NOT.

Mathematical

Gate counts with NAND only: NOT 1, AND 2, OR 3, XOR 4. A half adder needs XOR (4) + AND (2) = 6 NANDs if built naively, or 5 if the AND reuses g1 with one extra NAND as its NOT.

Applied

Some flash memory is called 'NAND flash' after the way its memory cells are strung together like transistors in a NAND gate. In CMOS chips, NAND and NOR are among the smallest gates to make.

Worked example 1

Show that NAND(NAND(A, A), NAND(B, B)) is A OR B.

NAND(A, A) = ¬A and NAND(B, B) = ¬B. NAND(¬A, ¬B) = ¬(¬A · ¬B) = A + B by De Morgan. Three NANDs make OR.

Common mix-ups

Practice

Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.

Practice 1. How do you make NOT from a single NAND?

gates

gates

Practice 4. In the four-NAND XOR, with A = 1 and B = 1, what is g1 = NAND(A, B)?

Practice 6. Why can't AND and OR gates alone build every logic function?

Apply it

In BUILD 008 Level 2, complete all three circuits within the gate limits. Then, on paper, design AND from NOR gates only and check it with a truth table.

Reflect

What does it tell you about computers that one simple switch pattern, repeated, is enough to compute anything?

Write your answer on paper or in your own notes. Lite never stores what you write.

← Module check: simplifying logicHalf adders and full adders →