3.1.14Boolean Algebra & Logic Gates

Universal gates (NAND - NOR completeness)

1,661 words8 min readdifficulty · medium1 backlinks

WHAT / WHY / HOW

WHAT — "Functional completeness" means a set of gates can express any truth table. The classic complete set is {AND,OR,NOT}\{\text{AND}, \text{OR}, \text{NOT}\}. If a single gate can reproduce all three of these, that gate alone is complete = universal.

WHY does one gate suffice? Because AND/OR/NOT are themselves built from more primitive operations, and both NAND and NOR already contain a NOT inside them. Once you have NOT for free, you can un-invert your way to AND and OR.

HOW — Strategy: show NAND (or NOR) can make NOT, AND, OR. Since {AND,OR,NOT}\{AND, OR, NOT\} is known complete, that transitively proves the single gate is complete.


Definitions


Deriving everything from NAND (first principles)

Let \uparrow denote NAND, so AB=ABA \uparrow B = \overline{A B}.

Step 1 — NOT from NAND

Tie both inputs together: set B=AB = A. AA=AA=AA \uparrow A = \overline{A\cdot A} = \overline{A}

Why this step? AA=AA\cdot A = A (idempotence), so AA=A\overline{A\cdot A}=\overline{A}. We now own inversion.

Step 2 — AND from NAND

NAND already gives AB\overline{AB}; we just invert it using our Step-1 NOT: (AB)=(AB)(AB)=AB=AB\overline{(A\uparrow B)} = (A\uparrow B)\uparrow(A\uparrow B) = \overline{\overline{AB}} = AB

Why this step? Double negation cancels: AB=AB\overline{\overline{AB}}=AB. So AND = NAND followed by a NAND-inverter (2 NANDs).

Step 3 — OR from NAND (De Morgan is the key)

De Morgan: A+B=ABA + B = \overline{\overline{A}\cdot\overline{B}}. That right side is exactly a NAND of the two inverted inputs: A+B=AB=(AA)(BB)A + B = \overline{\overline A \cdot \overline B} = (A\uparrow A)\uparrow(B\uparrow B)

Why this step? Invert each input (Step 1 uses one NAND each = 2 gates), then NAND those together (1 gate). OR = 3 NANDs.

Since we produced NOT, AND, OR — NAND is universal.


Deriving everything from NOR (the dual)

Let \downarrow denote NOR, so AB=A+BA\downarrow B=\overline{A+B}. By duality every NAND result flips AND↔OR:

Function From NOR
NOT AA=A+A=AA\downarrow A=\overline{A+A}=\overline A
OR (AB)(AB)=A+B=A+B(A\downarrow B)\downarrow(A\downarrow B)=\overline{\overline{A+B}}=A+B
AND (AA)(BB)=A+B=AB(A\downarrow A)\downarrow(B\downarrow B)=\overline{\overline A+\overline B}=AB

Why the swap? NOR bunches inputs with OR-then-invert, so its cheap operation is OR (2 gates) while AND needs 3 gates — the mirror image of NAND.

Figure — Universal gates (NAND - NOR completeness)

Worked examples


Common mistakes


Recall Feynman: explain to a 12-year-old

Imagine you have only one kind of LEGO brick, but it's a magic brick that says "NOT both." With enough of these magic bricks snapped together, you can build any toy machine — a calculator, a game, anything. You never need a different brick. The trick: the magic brick already knows how to say "no" (invert), and once you can say "no," you can rebuild all the other bricks (AND, OR, NOT) out of it. NAND and NOR are those magic bricks.


Active-recall flashcards

#flashcards/hardware

What makes a gate "universal"?
You can build every Boolean function (i.e. reproduce NOT, AND, OR) using only that gate.
Which single gates are universal?
NAND and NOR.
How do you make NOT from a NAND?
Tie both inputs together: AA=AA\uparrow A=\overline A.
How do you make AND from NANDs, and how many?
NAND the inputs then invert the result; 2 NANDs: (AB)(AB)=AB(A\uparrow B)\uparrow(A\uparrow B)=AB.
How do you make OR from NANDs, and how many?
Invert each input, then NAND them; 3 NANDs: (AA)(BB)=A+B(A\uparrow A)\uparrow(B\uparrow B)=A+B.
Why can't AND alone be universal?
AND is monotonic and can't invert (produce NOT); a universal gate must include inversion.
Which Boolean identity is central to OR-from-NAND?
De Morgan: A+B=ABA+B=\overline{\overline A\cdot\overline B}.
How many NAND gates for XOR?
4.
For NOR, which of AND/OR is cheaper (fewer gates)?
OR is cheaper (2 NORs); AND needs 3 NORs — mirror of NAND.
Formula for NAND and NOR?
AB\overline{AB} and A+B\overline{A+B}.

Connections

  • Boolean Algebra & Logic Gates
  • De Morgan's Laws — the engine behind OR/AND conversions
  • Truth Tables — how to verify each construction
  • Logic Gate Symbols
  • Combinational Circuits — where universal gates get assembled (adders, MUX)
  • CMOS Transistors — why NAND/NOR are the cheapest to fabricate physically
  • Duality Principle — explains the NAND↔NOR mirror

Concept Map

means

classic complete set

contains

contains

tie inputs

invert output

De Morgan

rebuild

rebuild

rebuild

transitively proves

is

by duality is

benefit

Universal gate

Functionally complete

AND OR NOT

NAND = not A.B

Built-in NOT

NOR = not A+B

NOT from 1 gate

AND from 2 gates

OR from 3 gates

One cheap standard part

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Universal gate ka matlab hai ek aisa single gate jisse aap koi bhi Boolean function bana sakte ho. NAND aur NOR dono universal hain. Iska practical fayda ye hai ki factory ko sirf ek hi type ka chip banana padta hai — sasta, standard, aur usi se pura CPU, memory, adder sab ban jaata hai.

Kaam kaise karta hai? Dhyaan do — NAND ke andar pehle se hi ek NOT chhupa hua hota hai (AB\overline{AB}). Agar dono input same kar do (AAA\uparrow A), toh A\overline{A} mil jaata hai, matlab NOT free me. Ek baar NOT mil gaya, toh AND banao NAND ko invert karke (2 gates), aur OR banao De Morgan se — dono input pehle invert karo phir NAND karo (3 gates). Jab NOT, AND, OR teeno ban gaye, toh proof complete: NAND universal hai. NOR ke liye bilkul ulta — OR sasta (2 gate), AND mehnga (3 gate), duality ki wajah se.

Sabse common galti: log sochte hain AND ya OR bhi universal hain. Nahi! AND/OR invert nahi kar sakte (monotonic hain) — jab tak gate me NOT nahi hoga, universal nahi ho sakta. Isliye sirf NAND/NOR hi jaadu ki brick hain. Exam me yaad rakho: OR-from-NAND me pehle inputs invert karna De Morgan ke wajah se zaroori hai, warna answer galat aayega.

Go deeper — visual, from zero

Test yourself — Boolean Algebra & Logic Gates

Connections