### Computer logic (P&P chapter 3)

The basic building block for all computer logic is the electrically-controlled switch.  A switch (such as a light switch) can open or close an electrical circuit (P&P Figure 3.1).  An electically-controlled switch can be opened or closed by an electrical input.  Different technologies have been used to build such switches:
relays (mechanical switches) -- simple but slow (switch in milliseconds)
vacuum tubes (1945-1960) -- much faster (microseconds) but take a lot of power
transistors (1960 - ) -- faster and lower power (P&P section 3.1)
integrated circuits (1970 - ) -- put more and more transistors on a single silicon chip (now, millions)

Switches can be used to build gates which implement the basic logic functions (P&P section 3.2)
• AND gate from a series circuit
• OR gate from a parallel circuit
• NOT gate from a normally-closed switch

### Computer logic:  building combinational circuits from gates (P&P 3.3)

A combinational circuit is a logic circuit in which each output is a Boolean function of its inputs.  Such a circuit can be represented in three ways:
• by a truth table, listing each combination of inputs and the correponding outputs
• by a Boolean formula for each output
• by a circuit diagram, connecting a set of logic gates
A half-adder does binary addition for a single bit.  It has two inputs, x and y, and two outputs, sum and carry.  The truth table for the half-adder is
 x y sum carry 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 1

The Boolean formulas are
sum = (x AND (NOT y)) OR ((NOT x) AND y) = x EXCLUSIVE-OR y
carry = x AND y

We can verify these formulas by computing their value for each combination of inputs, and seeing if they match the listed outputs.  But how can such a formula be systematically produced, starting from the truth table?

The simplest approach is to produce what is called a sum-of-products formula.  The formula consists of a bunch of terms which are connected by ORs.  Each term consists of a bunch of factors, one for each input.  Each factor represents either an input, or a negated input.  There will be one term for each row of the truth table with a "1" output.

In the simple case where there are two inputs, x and y, and one output, we generate the formula as follows:
look only at rows with output = 1
for each such row, build a term as follows:
if x = 0, include (NOT x) in the term
if x = 1, include x in the term
if y = 0, include (NOT y) in the term
if y = 1, include y in the term
AND these factors together to build the term
if there is more than one row with output = 1, OR the corresponding terms together.

This simple procedure doesn't always produce the simplest formula, but it will always produce a correct formula corresponding to the truth table.  The truth table can be used to represent any Boolean function, so this procedure shows that one can compute any Boolean function using only AND, OR, and NOT gates (P&P sec. 3.3.5:  logical completeness).