### 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).

A half-adder is fine for adding 1-bit binary numbers.  But if we are adding larger numbers, then for every place except the low-order bit, we have to take into account the carry in coming from the position to the right.  A full adder is a one-bit binary adder with allows for a carry in, so it has 3 inputs:  x, y, and carry-in.

The truth table and circuit diagram for a full adder are shown in P&P, page 62.