Boolean algebra provides the ability to work with many interesting functions while often using significantly less space than a truth table. We will informally prove that boolean algebra can describe all boolean functions - this justifies our use of gates since they correspond to the building blocks of boolean algebra.
Boolean expressions have the following grammar.
That is, a boolean expression can be a variable
(representing an input wire), the negation of a boolean expression
(NOT and
), the conjunction of two boolean expressions (AND and
) or the disjunction of two boolean expressions (OR and
). Boolean expressions and circuits are interchangeable though
circuits are generally smaller since they may share common
subexpressions.
Given a truth table for a function (one always exists), we can generate a boolean expression for the same function. We can do so in the following fashion. Each line of the truth table corresponds to a particular assignment of variables. For each assignment with output true (or one), generate an expression that is true for that assignment and no others. For example,
| F | F | F | T | T |
This assignment corresponds to the expression
. After generating all of
these expressions, form the disjunction (OR) of all these
expressions. This disjunction is the same as the function of the truth
table.
We can reason about boolean expressions with the following laws.
| Identity laws |
|
|
| Zero and One laws |
|
|
| Inverse laws |
|
|
| Commutative laws |
|
|
| Associative laws |
|
|
| Distributive laws |
|
|
From the basic laws, two more useful rules called DeMorgan's theorems may be proven.
Using AND, OR and NOT gates, we can construct any function. This is actually more than necessary - using DeMorgan's theorems, we can replace either all the ANDs or all the ORs. We can not get rid of NOT gates or both AND and OR gates. An alternative to getting rid of some of the gates is to replace all of them with a new gate. Such a gate is called universal. Two examples are NAND and NOR gates (NOT AND and NOT OR) - their universality can be demonstrated by using them to create a NOT gate and either an AND or OR gate. In practice, we do not use universal gates and use all three of our normal gates - this keeps our circuits smaller and less complex.