NAND
NOT of AND: it is 0 only when both inputs are 1.
x · y
| x | y | NAND |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
The mathematics behind chip design.
An algebra with only two values.
George Boole developed an algebra for reasoning about true and false statements. Digital designers use the same mathematical structure for signals with two logical states.
0 and 1Like ordinary algebra, Boolean algebra gives us variables, expressions, identities, and rules for transformation.
A Boolean variable can hold exactly one of two values: 0 or 1.
A value restricted to two possibilities is called a binary value. We will use 0 and 1, although they may represent distinctions such as false/true, off/on, or closed/open.
doorOpen = 1
armed = 1
correctPin = 0
Once facts are encoded as variables, rules can combine them to produce new Boolean values.
For each variable above, say in words what 0 and 1 mean.
A Boolean function operates on inputs that are 0 or 1 and returns an output that is 0 or 1.
x1, x2, ..., xn0 or 1Computer hardware represents and manipulates binary values. Boolean functions therefore give us a precise language for describing hardware behavior.
Learning to formulate and analyze these functions is the first step toward constructing a computer.
Next: How can we represent a Boolean function precisely?
A truth table lists the output of a Boolean function for every possible input combination.
| x | y | f |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Next: Let us examine the standard Boolean functions NOT, AND, and OR.
NOT returns 1 exactly when its input is 0.
Notationx
ExampleIf doorOpen = 1, then NOT doorOpen = 0.
| x | x |
|---|---|
| 0 | 1 |
| 1 | 0 |
AND returns 1 only when every input is 1.
Notationx · y, or simply xy
ExampleAn ATM dispenses cash if the PIN is correct AND the balance is sufficient.
| x | y | x · y |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
OR returns 1 when at least one input is 1.
Notationx + y
NoteThe result is also 1 when both inputs are 1.
ExampleA phone unlocks with a valid fingerprint OR the correct PIN.
| x | y | x + y |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
Next: We will combine these operations into expressions and test the resulting functions.
A lab door should unlock when a student has a valid ID card and the lab is open.
validCard
labOpen
unlock
Write an expression for unlock. Then test it for all four possible input combinations.
unlock = validCard · labOpen
The output is 1 only when both inputs are 1.
Boolean expressions combine variables and operations to describe more complex functions.
Suppose staff may enter even when the lab is closed:
Parentheses make the intended grouping explicit, just as in arithmetic.
Let validCard = 1, labOpen = 0, and staffOverride = 1.
(0 + 1) = 1, then 1 · 1 = 1. The door unlocks.
Next: Build complete truth tables for increasingly complex expressions.
Complete the output column for:
AND is evaluated before OR, so this means (x · y) + z.
| x | y | z | f |
|---|---|---|---|
| 0 | 0 | 0 | |
| 0 | 0 | 1 | |
| 0 | 1 | 0 | |
| 0 | 1 | 1 | |
| 1 | 0 | 0 | |
| 1 | 0 | 1 | |
| 1 | 1 | 0 | |
| 1 | 1 | 1 |
Complete the output column for:
The output is immediately 1 whenever x = 0. When x = 1, inspect y · z.
| x | y | z | f |
|---|---|---|---|
| 0 | 0 | 0 | |
| 0 | 0 | 1 | |
| 0 | 1 | 0 | |
| 0 | 1 | 1 | |
| 1 | 0 | 0 | |
| 1 | 0 | 1 | |
| 1 | 1 | 0 | |
| 1 | 1 | 1 |
Complete the output column for:
Evaluate the parentheses and the negation before applying AND.
| x | y | z | f |
|---|---|---|---|
| 0 | 0 | 0 | |
| 0 | 0 | 1 | |
| 0 | 1 | 0 | |
| 0 | 1 | 1 | |
| 1 | 0 | 0 | |
| 1 | 0 | 1 | |
| 1 | 1 | 0 | |
| 1 | 1 | 1 |
Next: Meet three useful functions built from NOT, AND, and OR.
Each function combines operations we already know.
NOT of AND: it is 0 only when both inputs are 1.
x · y
| x | y | NAND |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
NOT of OR: it is 1 only when both inputs are 0.
x + y
| x | y | NOR |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
Exclusive OR: it is 1 exactly when the inputs differ.
x · y + x · y
| x | y | XOR |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Next: Can every truth table be turned into a Boolean expression?
A standard construction turns every output-1 row into a term, then combines those terms.
For each output-1 row, write the variable for an input of 1 and its negation for an input of 0.
AND the literals. Row 010 gives x · y · z.
Repeat. Row 101 gives x · y · z.
Verify: The final expression is 1 on rows 010 and 101, and 0 on every other row.
Conclusion: Every Boolean function can be represented using only AND, OR, and NOT. Together, these operations are universal.
Next: Practise this construction on familiar functions.
| x | y | z | f |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 0 |
| a | b | XOR(a,b) |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Write one product term for each highlighted row, then OR the terms.
XOR(a,b) = ab + ab
| a | b | NAND(a,b) |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Write one product term for each highlighted row, then OR the three terms.
NAND(a,b) = a · b + ab + ab
| a | b | NOR(a,b) |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
Only one row has output 1. Write its product term.
NOR(a,b) = a · b
| x | y | z | f | g | h |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 0 | 1 |
| 1 | 0 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 0 | 1 |
| 1 | 1 | 0 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 | 1 |
Use each bold 1 to construct a product term.
f: x · y · z + x · y · z
g: x · y · z + x · y · z + x · y · z
h: x · y · z + x · y · z + x · y · z + x · y · z
Next: Review the standard two-input functions before comparing different expressions for the same function.
Two expressions are equivalent if they produce the same output for every possible input.
a + b = a · b
a · b = a + b
Complete the four output columns and compare each pair.
| a | b | OR law | AND law | ||
|---|---|---|---|---|---|
| a + b | a · b | a · b | a + b | ||
| 0 | 0 | ||||
| 0 | 1 | ||||
| 1 | 0 | ||||
| 1 | 1 | ||||
Next: Use truth tables to verify these laws and constructions based on NAND and NOR.
Verify each claim with a truth table. If a pair is not equivalent, find one input where the outputs differ.
De Morgan’s law for AND: a · b and a + b
De Morgan’s law for OR: a + b and a · b
NOT from NAND: NOT(a) and NAND(a,a)
AND from NAND: AND(a,b) and NAND(NAND(a,b), NAND(a,b))
OR from NAND: OR(a,b) and NAND(NAND(a,a), NAND(b,b))
NOT from NOR: NOT(a) and NOR(a,a)
OR from NOR: OR(a,b) and NOR(NOR(a,b), NOR(a,b))
AND from NOR: AND(a,b) and NOR(NOR(a,a), NOR(b,b))
Counterexample: a + b and a · b
A–H: Equivalent.
I: Not equivalent. For example, when a = 0 and b = 1, OR gives 1 while AND gives 0.
Next: Use these equivalences to identify universal sets of Boolean operations.
How many rows are required for a truth table with n Boolean variables?
How many distinct Boolean functions can be defined using n input variables.
A truth table has 2n rows, and each row has two independent output choices. Therefore there are 2(2n) functions.
For two variables: 2(22) = 24 = 16 functions.
Reveal one representation at a time, or reveal the complete reference.
| Function | Expression | x = 0y = 0 | x = 0y = 1 | x = 1y = 0 | x = 1y = 1 |
|---|---|---|---|---|---|
| Constant 0 | 0 |
0 | 0 | 0 | 0 |
| AND | x · y | 0 | 0 | 0 | 1 |
| OR | x + y | 0 | 1 | 1 | 1 |
| XOR | xy + xy | 0 | 1 | 1 | 0 |
| NOR | x + y | 1 | 0 | 0 | 0 |
| Equivalence | x · y + x · y | 1 | 0 | 0 | 1 |
| If x, then y | x + y | 1 | 1 | 0 | 1 |
| NAND | x · y | 1 | 1 | 1 | 0 |
| Constant 1 | 1 |
1 | 1 | 1 | 1 |
Next: Can two different expressions describe exactly the same function?
A set of operations is universal if it can represent every Boolean function.
We proved that these three operations can express any Boolean function.
With NOT available, AND can simulate OR, and OR can simulate AND.
NAND can build NOT and AND; NOR can build NOT and OR.
Once a physical device implements NAND, many copies of that one device can be wired together to implement any Boolean function. The same is true of NOR.
From Boolean functions to physical devices.
If a gate promises a Boolean function, which internal details can its users safely ignore?
Before we leave: One final counting question about the space of all Boolean functions.