Code_ The Hidden Language of Computer Hardware and Software - Charles Petzold [37]
F x M = 0
Notice that the 1 and 0 symbols sometimes work the same way in Boolean algebra as in conventional algebra. For example, the intersection of all cats and female cats is the class of female cats:
1 x F = F
The intersection of no cats and female cats is the class of no cats:
0 x F = 0
The union of no cats and all female cats is the class of female cats:
0 + F = F
But sometimes the result doesn't look the same as in conventional algebra. For example, the union of all cats and female cats is the class of all cats:
1 + F = 1
This doesn't make much sense in conventional algebra.
Because F is the class of all female cats, and (1 – F) is the class of all cats that aren't female, the union of these two classes is 1:
F + (1 – F) = 1
and the intersection of the two classes is 0:
F x (1 – F) = 0
Historically, this formulation represents an important concept in logic: It's called the Law of Contradiction and indicates that something can't be both itself and the opposite of itself.
Where Boolean algebra really looks different from conventional algebra is in a statement like this:
F x F = F
The statement makes perfect sense in Boolean algebra: The intersection of female cats and female cats is still the class of female cats. But it sure wouldn't look quite right if F referred to a number. Boole considered
X2 = X
to be the single statement that differentiates his algebra from conventional algebra. Another Boolean statement that looks funny in terms of conventional algebra is this:
F + F = F
The union of female cats and female cats is still the class of female cats.
Boolean algebra provides a mathematical method for solving the syllogisms of Aristotle. Let's look at the first two-thirds of that famous syllogism again, but now using gender-neutral language:
All persons are mortal;
Socrates is a person.
We'll use P to represent the class of all persons, M to represent the class of mortal things, and S to represent the class of Socrates. What does it mean to say that "all persons are mortal"? It means that the intersection of the class of all persons and the class of all mortal things is the class of all persons:
P x M = P
It would be wrong to say that P x M = M, because the class of all mortal things includes cats, dogs, and elm trees.
To say, "Socrates is a person," means that the intersection of the class containing Socrates (a very small class) and the class of all persons (a much larger class) is the class containing Socrates:
S x P = S
Because we know from the first equation that P equals (P x M) we can substitute that into the second equation:
S x (P x M) = S
By the associative law, this is the same as
(S x P) x M = S
But we already know that (S x P) equals S, so we can simplify by using this substitution:
S x M = S
And now we're finished. This formula tells us that the intersection of Socrates and the class of all mortal things is S, which means that Socrates is mortal. If we found instead that (S x M) equaled 0, we'd conclude that Socrates wasn't mortal. If we found that (S x M) equaled M, the conclusion would have to be that Socrates was the only mortal thing and everything else was immortal!
Using Boolean algebra might seem like overkill for proving the obvious fact (particularly considering that Socrates proved himself mortal 2400 years ago), but Boolean algebra can also be used to determine whether something satisfies a certain set of criteria. Perhaps one day you walk into a pet shop and say to the salesperson, "I want a male cat, neutered, either white or tan; or a female cat, neutered, any color but white; or I'll take any cat you have as long as it's black." And the salesperson says to you, "So you want a cat from the class of cats represented by the following expression:
(M x N x (W + T)) + (F x N x (1 – W)) + B
Right?" And you say, "Yes! Exactly!"
In verifying that the salesperson is correct, you might want to forgo the concepts of union and intersection and instead switch to the words OR and AND. I'm capitalizing these words because the words normally represent concepts in