Code_ The Hidden Language of Computer Hardware and Software - Charles Petzold [38]
The + (previously known as a union) now means OR.
The x (previously known as an intersection) now means AND.
The 1 – (previously the universe without something) now means NOT.
So the expression can also be written like this:
(M AND N AND (W OR T)) OR (F AND N AND (NOT W)) OR B
This is very nearly what you said. Notice how the parentheses clarify your intentions. You want a cat from one of three classes:
(M AND N AND (W OR T))
OR
(F AND N AND (NOT W))
OR
B
With this formula written down, the salesperson can perform something called a Boolean test. Without making a big fuss about it, I've subtly shifted to a somewhat different form of Boolean algebra. In this form of Boolean algebra, letters no longer refer to classes. Instead, the letters can now be assigned numbers. The catch is that they can be assigned only the number 0 or 1. The numeral 1 means Yes, True, this particular cat satisfies these criteria. The numeral 0 means No, False, this cat doesn't satisfy these criteria.
First the salesperson brings out an unneutered tan male. Here's the expression of acceptable cats:
(M x N x (W + T)) + (F x N x (1 – W)) + B
and here's how it looks with 0s and 1s substituted:
(1 x 0 x (0 + 1)) + (0 x 0 x (1 – 0)) + 0
Notice that the only symbols assigned 1s are M and T because the cat is male and tan.
What we must do now is simplify this expression. If it simplifies to 1, the cat satisfies your criteria; if it simplifies to 0, the cat doesn't. While we're simplifying the expression, keep in mind that we're not really adding and multiplying, although generally we can pretend that we are. Most of the same rules apply when + means OR and x means AND. (Sometimes in modern texts the symbols ^ and ν are used for AND and OR instead of x and +. But here's where the + and x signs perhaps make the most sense.)
When the x sign means AND, the possible results are
0 x 0 = 0
0 x 1 = 0
1 x 0 = 0
1 x 1 = 1
In other words, the result is 1 only if both the left operand AND the right operand are 1. This operation works exactly the same way as regular multiplication, and it can be summarized in a little table, similar to the way the addition and multiplication tables were shown in Chapter 8:
AND
0
1
0
0
0
1
0
1
When the + sign means OR, the possible results are
0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 1
The result is 1 if either the left operand OR the right operand is 1. This operation produces results very similar to those of regular addition, except that in this case 1 + 1 equals 1. The OR operation can be summarized in another little table:
OR
0
1
0
0
1
1
1
1
We're ready to use these tables to calculate the result of the expression
(1 x 0 x 1) + (0 x 0 x 1) + 0 = 0 + 0 + 0 = 0
The result 0 means No, False, this kitty won't do.
Next the salesperson brings out a neutered white female. The original expression was
(M x N x (W + T)) + (F x N x (1 – W)) + B
Substitute the 0s and 1s again:
(0 x 1 x (1 + 0)) + (1 x 1 x (1 – 1)) + 0
And simplify it:
(0 x 1 x 1) + (1 x 1 x 0) + 0 = 0 + 0 + 0 = 0
And another poor kitten must be rejected.
Next the salesperson brings out a neutered gray female. (Gray qualifies as an "other" color—not white or black or tan.) Here's the expression:
(0 x 1 x (0 + 0)) + (1 x 1 x (1 – 0)) + 0
Now simplify it:
(0 x 1 x 0) + (1 x 1 x 1) + 0 = 0 + 1 + 0 = 1
The final result 1 means Yes, True, a kitten has found a home. (And it was the cutest one too!)
Later that evening, when the kitten is curled up sleeping in your lap, you wonder whether you could have wired some switches and a lightbulb to help you determine whether particular kittens satisfied your criteria. (Yes,