Hello World! An Invitation to Computer Science
Lecture Slides: From Boolean Expressions to Circuits
Thursday, February 28, 2008
- AND, OR, NOT applied like arithmetic operations
- Boolean logic is everywhere
- 1-bit addition is logic
Sum-of-products algorithm
Any Boolean-valued function can be described by truth table
without meaning, we can (mindlessly) extract logic formula
- for each true output, generate product term (AND)
- combine products in a sum (OR)
Example: exclusive or
inputs output
x y f product terms
---------------------------------------------
F F F
F T T (NOT x) AND y
T F T x AND (NOT y)
T T F
f(x,y) = ((NOT x) AND y) OR (x AND (NOT y))
Example: half-adder
inputs outputs
a b c s c terms s terms
--------------------------------------------
0 0 0 0
0 1 0 1 (NOT a) AND b
1 0 0 1 a AND (NOT b)
1 1 1 0 a AND b
sum = a XOR b
carry = a AND b
Principle v. practice
- in principle,
we can represent any Boolean function this way
- we can easily represent addition of small numbers
- But does the idea scale?
not in practice
truth tables, and, therefore circuits get too large
Insight can help
- two 1-bit full adders → full 2-bit adder
- n 1-bit full adders → n-bit adder
- this idea ("ripple-carry adder") does scale!
How far can we go?
- if we can add, we can multiply
- and, likewise, we can represent all of arithmetic
- this is a successful model of computation
- same ideas apply to all modern computers
- blindingly fast calculation
no magic, no intelligence to be found
Example: 1-bit greater-than
inputs output
a b g product terms
---------------------------------------------
0 0 0
0 1 0
1 0 1 a AND (NOT b)
1 1 0
g(a,b) = a AND (NOT b)
Two-out-of-three example
details