Lecture 2

Boolean Algebra

The mathematics behind chip design.

variablesfunctionsrepresentationsequivalenceuniversality
Definition

Boolean Algebra

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.

Values0 and 1
VariablesNames that hold Boolean values
OperationsNOT, AND, OR, and their combinations

Like ordinary algebra, Boolean algebra gives us variables, expressions, identities, and rules for transformation.

Definition

Boolean Variables

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.

Definition

Boolean Functions

A Boolean function operates on inputs that are 0 or 1 and returns an output that is 0 or 1.

Boolean inputsx1, x2, ..., xn
fBoolean rule
Boolean output0 or 1

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

Representing Boolean functions

Truth Tables

A truth table lists the output of a Boolean function for every possible input combination.

xyf
000
011
101
110

Next: Let us examine the standard Boolean functions NOT, AND, and OR.

Standard Boolean function

NOT

NOT returns 1 exactly when its input is 0.

Notationx

ExampleIf doorOpen = 1, then NOT doorOpen = 0.

xx
01
10
Standard Boolean function

AND

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.

xyx · y
000
010
100
111
Standard Boolean function

OR

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.

xyx + y
000
011
101
111

Next: We will combine these operations into expressions and test the resulting functions.

Tutorial 1

Translate a Rule into Boolean Logic

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.

Composition

Boolean Expressions

Boolean expressions combine variables and operations to describe more complex functions.

ANDx · yor simply xy
ORx + y
NOTx

Suppose staff may enter even when the lab is closed:

unlock = validCard · (labOpen + staffOverride)

Parentheses make the intended grouping explicit, just as in arithmetic.

Tutorial 2

Evaluate an Expression from the Inside Out

Let validCard = 1, labOpen = 0, and staffOverride = 1.

validCard · (labOpen + staffOverride)

(0 + 1) = 1, then 1 · 1 = 1. The door unlocks.

Next: Build complete truth tables for increasingly complex expressions.

Exercise 1

Build the Truth Table

Complete the output column for:

f(x,y,z) = x · y + z

AND is evaluated before OR, so this means (x · y) + z.

xyzf
000
001
010
011
100
101
110
111
Exercise 2

Build the Truth Table

Complete the output column for:

f(x,y,z) = x + y · z

The output is immediately 1 whenever x = 0. When x = 1, inspect y · z.

xyzf
000
001
010
011
100
101
110
111
Exercise 3

Build the Truth Table

Complete the output column for:

f(x,y,z) = (x + y) · z

Evaluate the parentheses and the negation before applying AND.

xyzf
000
001
010
011
100
101
110
111

Next: Meet three useful functions built from NOT, AND, and OR.

Derived Boolean functions

NAND, NOR, and XOR

Each function combines operations we already know.

NAND

NOT of AND: it is 0 only when both inputs are 1.

x · y

xyNAND
001
011
101
110

NOR

NOT of OR: it is 1 only when both inputs are 0.

x + y

xyNOR
001
010
100
110

XOR

Exclusive OR: it is 1 exactly when the inputs differ.

x · y + x · y

xyXOR
000
011
101
110

Next: Can every truth table be turned into a Boolean expression?

Canonical representation

Every Boolean Function Can Be Represented by an Expression

A standard construction turns every output-1 row into a term, then combines those terms.

1

For each output-1 row, write the variable for an input of 1 and its negation for an input of 0.

2

AND the literals. Row 010 gives x · y · z.

3

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.

xyzf
0000
0010
0101
0110
1000
1011
1100
1110
OR the two row terms xyz + xyz
Exercise 4

Write the Canonical Expression for XOR

abXOR(a,b)
000
011
101
110

Write one product term for each highlighted row, then OR the terms.

XOR(a,b) = ab + ab

Exercise 5

Write the Canonical Expression for NAND

abNAND(a,b)
001
011
101
110

Write one product term for each highlighted row, then OR the three terms.

NAND(a,b) = a · b + ab + ab

Exercise 6

Write the Canonical Expression for NOR

abNOR(a,b)
001
010
100
110

Only one row has output 1. Write its product term.

NOR(a,b) = a · b

Exercise 7

Write the Canonical Expressions for f, g, and h

xyzfgh
000100
001010
010010
011001
100010
101001
110001
111101

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.

Equivalence

Equivalence of expressions

Two expressions are equivalent if they produce the same output for every possible input.

De Morgan’s law for OR

a + b = a · b

De Morgan’s law for AND

a · b = a + b

Complete the four output columns and compare each pair.

abOR lawAND law
a + ba · ba · ba + b
00
01
10
11

Next: Use truth tables to verify these laws and constructions based on NAND and NOR.

Exercise 8

Are These Pairs Equivalent?

Verify each claim with a truth table. If a pair is not equivalent, find one input where the outputs differ.

A

De Morgan’s law for AND: a · b and a + b

B

De Morgan’s law for OR: a + b and a · b

C

NOT from NAND: NOT(a) and NAND(a,a)

D

AND from NAND: AND(a,b) and NAND(NAND(a,b), NAND(a,b))

E

OR from NAND: OR(a,b) and NAND(NAND(a,a), NAND(b,b))

F

NOT from NOR: NOT(a) and NOR(a,a)

G

OR from NOR: OR(a,b) and NOR(NOR(a,b), NOR(a,b))

H

AND from NOR: AND(a,b) and NOR(NOR(a,a), NOR(b,b))

I

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.

Counting Problems

Here are two counting problems

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.

2ninput combinations
2 choicesfor each output
2(2n)Boolean functions

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.

Reference

Standard Two-Input Boolean 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 0000
AND x · y 0001
OR x + y 0111
XOR xy + xy 0110
NOR x + y 1000
Equivalence x · y + x · y 1001
If x, then y x + y 1101
NAND x · y 1110
Constant 1 1 1111

Next: Can two different expressions describe exactly the same function?

The central result

Universality

A set of operations is universal if it can represent every Boolean function.

Canonical representation AND + OR + NOT

We proved that these three operations can express any Boolean function.

De Morgan’s laws AND + NOT
or OR + NOT

With NOT available, AND can simulate OR, and OR can simulate AND.

One operation NAND alone
or NOR alone

NAND can build NOT and AND; NOR can build NOT and OR.

Why this matters in hardware

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.

Lecture 3 | Chapter 1, Section 1.1.2

Gate Logic

From Boolean functions to physical devices.

Boolean functiongate interfaceimplementationcomposite gate

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.