Boolean Algebra
(Content adapted from Critchlow & Eck)
So far we have discussed how to write and interpret propositions. This section deals with manipulating them. For this, we need algebra. Ordinary algebra, of the sort taught in high school, is about manipulating numbers, variables that represent numbers, and operators such as and that apply to numbers. Now, we need an algebra that applies to logical values, propositional variables, and logical operators. The first person to think of logic in terms of algebra was the mathematician, George Boole, who introduced the idea in a book that he published in 1854. The algebra of logic is now called Boolean algebra in his honor.
The algebra of numbers includes a large number of rules for manipulating expressions. The distributive law, for example, says that , where , , and are variables that stand for any numbers or numerical expressions. This law means that whenever you see something of the form in a numerical expression, you can substitute without changing the value of the expression, and vice versa. Note that the equals sign in means "has the same value as, no matter what numerical values , , and have."
Laws
In Boolean algebra, we work with logical values instead of numerical values. There are only two logical values, true and false. We will write these values as and . The symbols and play a similar role in Boolean algebra to the role that constant numbers such as 1 and 3.14159 play in ordinary algebra. Instead of the equals sign, Boolean algebra uses logical equivalence, , which has essentially the same meaning.1 For example, for propositions , , and , the operator in means "has the same value as, no matter what logical values , , and have."
Many of the rules of Boolean algebra are fairly obvious, if you think a bit about what they mean. Even those that are not obvious can be verified easily by using a truth table. Below we list the most important of these laws. You will notice that all these laws, except the first, come in pairs: Each law in the pair can be obtained from the other by interchanging with and with . This cuts down on the number of facts you have to remember.2
Name | Law |
---|---|
Double negation | |
Excluded middle | |
Contradiction | |
Identity laws | |
Idempotent laws | |
Commutative laws | |
Associative laws | |
Distributive laws | |
De Morgan's laws | |
Just as an example, let's verify the first rule in the table, the Law of Double Negation. This law is just the old, basic grammar rule that two negatives make a positive. Although this rule is questionable as it applies to English as it is actually used—no matter what the grammarian says, "I can't get no satisfaction" doesn't really mean "I can get satisfaction"—the validity of the rule in logic can be verified just by computing the two possible cases: when is true and when is false. When is true, then by the definition of the operator, is false. But then, again by the definition of , the value of is true, which is the same as the value of . Similarly, in the case where is false, is also false. Organized into a truth table, this argument takes the rather simple form
true | false | true |
false | true | false |
The fact that the first and last columns are identical shows the logical equivalence of and . The point here is not just that , but also that this logical equivalence is valid because it can be verified computationally based just on the relevant definitions. Its validity does not follow from the fact that "it's obvious" or "it's a well-known rule of grammar." Students often ask "Why do I have to prove something when it's obvious." The point is that logic—and mathematics more generally—is its own little world with its own set of rules. Although this world is related somehow to the real world, when you say that something is obvious (in the real world), you aren't playing by the rules of the world of logic. The real magic of mathematics is that by playing by its rules, you can come up with things that are decidedly not obvious, but that still say something about the real world—often, something interesting and important.
Each of the rules in the figure above can be verified in the same way, by making a truth table to check all the possible cases.
Substitution
It's important to understand that the propositional variables in the laws of Boolean algebra can stand for any propositions, including compound propositions. It is not just true, as the Double Negation Law states, that . It is also true that , that , that , and an infinite number of other statements of the same form. Here, a "statement of the same form" is one that can be obtained by substituting something for in both places where it occurs in . How can I be sure that all these infinitely many statements are valid when all that I've checked is one little two-line truth table? The answer is that any given proposition, , no matter how complicated, has a particular truth value, either true or false. So, the question of the validity of always reduces to one of the two cases I already checked in the truth table. (Note that for this argument to be valid, the same must be substituted for in every position where it occurs.) While this argument may be "obvious," it is not exactly a proof, but for now we will just accept the validity of the following theorem:
Theorem: First Substitution Law
Suppose that is any proposition, and that is a propositional variable. Consider any tautology. If is substituted for in all places where occurs in the tautology, then the result is also a tautology.
Since logical equivalence is defined in terms of tautology, it is also true that when is substituted for in a logical equivalence, the result is again a logical equivalence.3
The First Substitution Law lets you do algebra! For example, you can substitute for in the law of double negation, . This allows you to "simplify" the expression to with confidence that the resulting expression has the same logical value as the expression you started with. (That's what it means for and to be logically equivalent.) You can play similar tricks with all the laws in the table above. Even more important is the Second Substitution Law, which says that you can substitute an expression for a logically equivalent expression, wherever it occurs. Once again, we will accept this as a theorem without trying to prove it here. It is surprisingly hard to put this law into words:
Theorem: Second Substitution Law
Suppose that and are any propositions such that . Suppose that is any compound proposition in which occurs as a subproposition. Let be the proposition that is obtained by substituting for that occurrence of in . Then .
Note that in this case, the theorem does not require to be substituted for every occurrence of in . You are free to substitute for one, two, or as many occurrences of as you like, and the result is still logically equivalent to .
The Second Substitution Law allows us to use the logical equivalence to "simplify" the expression by substituting for . The resulting expression, , or just without the parentheses, is logically equivalent to the original . Once again, we have to be careful about parentheses: The fact that does not allow us to rewrite as . The problem is that means , so that is not a subexpression. So even though in practice we won't always write all the parentheses, you always have to be aware of where the parentheses belong.
The final piece of algebra in Boolean algebra is the observation that we can chain logical equivalences together. That is, from and , it follows that . This is really just a consequence of the Second Substitution Law: The equivalence allows us to substitute for in the statement , giving . (Remember that logical equivalence is defined in terms of a proposition.) This means that we can show that two compound propositions are logically equivalent by finding a chain of logical equivalences that lead from one to the other. For example:
definition of , 2nd Subst. Law | ||
Distributive Law | ||
Law of Contradiction, 2nd Subst. Law | ||
Identity Law |
Each step in the chain has its own justification. In several cases, a substitution law is used without stating as much. In the first line, for example, the definition of is that . The Second Substitution Law allows us to substitute for . In the last line, we implicitly applied the First Substitution Law to the Identity Law, , to obtain .
The chain of equivalences in the above example allows us to conclude that is logically equivalent to . This means that if you were to make a truth table for these two expressions, the truth values in the column for would be identical to those in the column for . We know this without actually making the table. In this case, the table would only be four lines long and easy enough to make. But Boolean algebra can be applied in cases where the number of propositional variables is too large for a truth table to be practical.
Let's do another example. Recall that a compound proposition is a tautology if it is true for all possible combinations of truth values of the propositional variables that it contains. But another way of saying the same thing is that is a tautology if . So, we can prove that a compound proposition, , is a tautology by finding a chain of logical equivalences leading from to . For example:
definition of | ||
DeMorgan's Law, 2nd Subst. Law | ||
Double Negation, 2nd Subst. Law | ||
Associative Law for | ||
Law of Excluded Middle |
From this chain of equivalences, we can conclude that is a tautology.
Now, it takes some practice to look at an expression and see which rules can be applied to it; to see as an application of the law of the excluded middle for example, you need to mentally substitute for in the law as it is stated in the table. Often, there are several rules that apply, and there are no definite guidelines about which one you should try. This is what makes algebra something of an art.
Additional Laws
It is certainly not true that all possible rules of Boolean algebra are given in the figure. For one thing, there are many rules that are easy consequences of the rules that are listed there. For example, although the table asserts only that , it is also true that . This can be checked directly or by a simple calculation:
Commutative Law | ||
Identity Law as given in the table |
Additional rules can be obtained by applying the Commutative Law to other rules in the table, and we will use such rules freely in the future.
Another sort of easy extension can be applied to the Associative Law, . The law is stated for the operator applied to three terms, but it generalizes to four or more terms. For example
by the Associative Law for three terms | ||
by the Associative Law for three terms |
We will, of course, often write this expression as , with no parentheses at all, knowing that wherever we put the parentheses the value is the same.
One other thing that you should keep in mind is that rules can be applied in either direction. The Distributive Law, for example, allows you to distribute the in to get . But it can also be used in reverse to "factor out" a term, as when you start with and factor out the to get .
Understanding the Laws
So far in this section, I have been working with the laws of Boolean algebra without saying much about what they mean or why they are reasonable. Of course, you can apply the laws in calculations without understanding them. But if you want to figure out which calculations to do, you need some understanding. Most of the laws are clear enough with a little thought. For example, if we already know that is false, then will be true when is true and false when is false. That is, has the same logical value as . But that's just what the Identity Law for says. A few of the laws need more discussion.
The Law of the Excluded Middle, , says that given any proposition , at least one of or must be true. Since is true exactly when is false, this is the same as saying that must be either true or false. There is no middle ground.4 The Law of Contradiction, , says that it is not possible for both and to be true. Both of these rules are obvious.
The Distributive Laws cannot be called obvious, but a few examples can show that they are reasonable. Consider the statement, "This card is the ace of spades or clubs." Clearly, this is equivalent to "This card is the ace of spaces or this card is the ace of clubs." But this is just an example of the first distributive law! For, let represent the proposition "This card is an ace," let represent "This card is a spade," and let represent "This card is a club." Then "This card is the ace of spades or clubs" can be translated into logic as , while "This card is the ace of spades or this card is the ace of clubs" becomes . And the distributive law assures us that . The second distributive law tells us, for example, that "This card is either a joker or is the ten of diamonds" is logically equivalent to "This card is either a joker or a ten, and it is either a joker or a diamond." That is, . The distributive laws are powerful tools and you should keep them in mind whenever you are faced with a mixture of and operators.
De Morgan's Laws must also be less than obvious, since people often get them wrong. But they do make sense. When considering , you should ask yourself, how can " and " fail to be true. It will fail to be true if either is false or if is false (or both). That is, is equivalent to . Consider the sentence "A raven is large and black." If a bird is not large and black, then it is not a raven. But what exactly does it mean to be "not (large and black)"? How can you tell whether the assertion "not (large and black)" is true of something? This will be true if it is either not large or not black. (It doesn't have to be both—it could be large and white, it could be small and black.) Similarly, for " or " to fail to be true, both and must be false. That is, is equivalent to . This is De Morgan's second law.
Recalling that is equivalent to , we can apply De Morgan's law to obtain a formula for the negation an implication:
That is, is false exactly when both is true and is false. For example, the negation of "If you have an ace, you win" is "You have an ace, and you don't win." Think of it this way: if you had an ace and you didn't win, then the statement "If you have an ace, you win" was not true.
Exercises
Construct truth tables to demonstrate the validity of each of the distributive laws.
Construct the following truth tables:
- Construct truth tables to demonstrate that is not logically equivalent to .
- Construct truth tables to demonstrate that is not logically equivalent to .
- Construct truth tables to demonstrate the validity of both De Morgan's Laws.
Construct truth tables to demonstrate that is not logically equivalent to any of the following.
Answer
Answer
Answer
Refer back to this section for a formula that is logically equivalent to .
Answer
Just before the exercises it was shown that is equivalent to .
Is logically equivalent to ?
Answer
No, since is equivalent to (either check the truth tables, or expand out both exressions using the definition of and then use the fact that an implication is equivalent to its contrapositive). Instead, is equivalent to (again, check the truth tables or expand the definitions).
In the algebra of numbers, there is a distributive law of multiplication over addition: . What would a distributive law of addition over multiplication look like? Is it a valid law in the algebra of numbers?
Answer
If addition distributed over multiplication, then we would have , but this is not true (for example, take , , and ; then , but ).
The distributive laws given in the table are sometimes called the left distributive laws. The right distributive laws say that and that . Show that the right distributive laws are also valid laws of Boolean algebra. (Note: In practice, both the left and the right distributive laws are referred to simply as the distributive laws, and both can be used freely in proofs.)
Answer
The commutative laws are enough to show that these are also true, since the left and right arguments may be swapped on each of the operations.
Show that for any propositions , , , and . In words, we can say that conjunction distributes over a disjunction of three terms. (Recall that the operator is called conjunction and is called disjunction.) Translate into logic and verify the fact that conjunction distributes over a disjunction of four terms. Argue that, in fact, conjunction distributes over a disjunction of any number of terms.
There are two additional basic laws of logic, involving the two expression and . What are the missing laws? Show that your answers are, in fact, laws.
Answer
The laws are and . These are sometimes called the "annihilation" or "annulment" laws, and they are akin to the property in ordinary algebra.
If you think of as being the disjunction of zero terms, and as the conjunction of zero terms (just as is the sum of zero numbers), then these laws extend the previous exercise to the case of distributing over zero terms.
For each of the following pairs of propositions, show that the two propositions are logically equivalent by finding a chain of equivalences from one to the other. State which definition or law of logic justifies each equivalence in the chain.
For each of the following compound propositions, find a simpler proposition that is logically equivalent. Try to find a proposition that is as simple as possible.
Answer
, or
Answer
Answer
Answer
Answer
Answer
Express the negation of each of the following sentences in natural English:
It is sunny and cold.
Answer
It is not sunny, or it is not cold.
I will have cake or I will have pie.
Answer
I will not have cake and I will not have pie.
If today is Tuesday, this is Belgium.
Answer
Today is Tuesday and this is not Belgium.
If you pass the final exam, you pass the course.
Answer
You pass the final exam but you do not pass the course.
Apply one of the laws of logic to each of the following sentences, and rewrite it as an equivalent sentence. State which law you are applying.
- I will have coffee and cake or pie.
Answer
I will have coffee and cake, or I will have coffee and pie (Distributive).
- He has neither talent nor ambition.
Answer
He does not have talent and he does not have ambition (DeMorgan).
- You can have spam, or you can have spam.
Answer
You can have spam (Idempotence).
- I will have coffee and cake or pie.
Use Boolean algebra to show that the implication operator () is functionally complete, provided the constant is also available (this is not unreasonable in an electronic circuit, where is represented by the ground voltage). That is, show how to define , , and by giving equivalent expressions using only and in addition to the input variables and .
Answer
Since (check the truth table, or expand into and use the identity law), we may use the fact that to conclude that both and are expressible with only and . We already know that these two together are functionally complete, therefore we may convert any boolean expression into one using only and .
- In ordinary algebra, it's easy to be confused by the equals sign, because it has two very different roles. In an identity such as the distributive law, it means "is always equal to." On the other hand, an equation such as is a statement that might or might not be true, depending on the value of . Boolean algebra has two operators, and , that play roles similar to the two roles of the equals sign.↩
- It is also an example of a more general fact known as duality, which asserts that given any tautology that uses only the operators , , and , another tautology can be obtained from it by interchanging with and with . We won't attempt to prove this here.↩
- I've added parentheses around here for technical reasons. Sometimes, the parentheses are necessary to make sure that is evaluated as a whole, so that its final value is used in place of . As an example of what can go wrong, consider . If this is substituted literally for in , without parentheses, the result is . But this expression means , which is not equivalent to .↩
- In propositional logic, this is easily verified with a small truth table. But there is a surprising amount of argument about whether this law is valid in all situations. In the real world, there often seems to be a gray area between truth and falsity. Even in mathematics, there are some people who think there should be a third truth value, one that means something like "unknown" or "not proven." But the mathematicians who think this way tend to be considered a bit odd by most other mathematicians.↩