Logic We have been studying numbers, where we had Objects: numbers Operations: +, Properties: a + b = b + a, ab = ba, a + 0 = a, a 1 = a Now we study logic, where the objects are statements. Definition A statement is a sentence that can be either true or false. It is possible to make sentences that are neither true nor false. Here are two: Where is the train station? Have some of these eggs. The first sentence is a question and the second is a command; it doesn’t make sense for these to be true or false. These are not statements. But some sentences are definitely true or false. For example: The earth is flat is FALSE Dogs usually have four legs is TRUE Pigs have wings is FALSE Red is a color is TRUE These sentences are statements. In logic we also have operations; ways of combining the objects. We can combine two statements by using the operation AND, like so: red is a color AND dogs usually have four legs. For this combined statement you are asked to believe two statements (the pieces of the combination; one is red is a color, the other is dogs usually have four legs). To believe the combined statement, both pieces must be true. In this case, both pieces indeed are true, so the combined statement is also true. But the combined statement red is a color AND pigs have wings would be false, since one of the pieces (pigs have wings) is false. Also, a combination of two false statements, such as pigs have wings AND the earth is flat is definitely a false statement since both pieces are false.. The way true and false statements combine using an AND is summarized in the following table. AND FALSE TRUE FALSE FALSE FALSE TRUE FALSE TRUE To save time writing, sometimes we just use a single letter (a variable) to stand for the whole statement. We might let a stand for the earth is flat and b stand for red is a color in which case we could say that a AND b is FALSE (since a is false). To save even more time writing, we sometimes use the symbol 0 to stand for FALSE and the symbol 1 to stand for TRUE, in which case we would rewrite the above as a AND b = 0 In this notation, the combination table for AND looks like AND 0 1 0 0 0 1 0 1 Compare this table with the binary multiplication from the last section: 0 1 0 0 0 1 0 1 and we can see that the two tables are the same. This despite the fact that the objects are completely different (in one case the objects are statements, in the other, numbers). This similarity prompts us to the notation ab to mean a AND b, leaving out the symbol for the operation as we do when multiplying. This notation goes back to George Boole (1815-1864). Another operation in logic is OR. We can combine two statements using an OR like so: red is a color OR pigs have wings Here, to believe the combined statement, we have to believe one piece or the other (or both). Since the first piece (red is a color) is true we can believe the whole combined statement, even though the second piece (pigs have wings) is false. Similarly red is a color OR dogs usually have four legs is true because both pieces are true, but pigs have wings OR the earth is flat is false since both pieces are false. The way true and false (which we’ll write as 0 and 1) statements combine using an OR is summarized in the following table: OR 0 1 0 0 1 1 1 1 If we compare this table with the table for binary addition from the last section + 0 1 0 0 1 1 1 0 We see that the two tables are almost the same. They are not exactly the same because for addition 1 + 1 = 0 along with a carry. This closeness prompts us to use the notation a + b to mean a OR b. This notation also goes back to George Boole. As we shall see shortly, using Boole’s notation for AND and OR is convenient because it allows us to use our intuition for how numbers combine to understand how logical statements combine. The third common operation in logic is NOT. In English we usually insert the word NOT into the middle of a sentence, like so red is NOT a color and this has the effect of turning a true statement (red is a color) into a false statement. Similarly using a NOT in the earth is NOT flat changes a false statement (the earth is flat) into a true statement. So NOT changes a true statement into a false statement and a false into a true. We can think of NOT as affecting the entire statement, so it might make sense to write it like this NOT (red is a color) where the NOT affects the entire statement in parentheses. Boole’s notation gets this idea across by using a to mean NOT a. By the way, NOT is a different type of operation than any we’ve seen so far. Usually an operation combines two objects, but NOT only affects one object. It is a so-called unary operation. To summarize, these are the three basic operation of logic: In words a AND b a OR b NOT a In symbols ab a+b a Using this symbolism it is possible to write down quite complicated combined statements (or logical expressions). For example, ab + cb means (a AND b) OR NOT (c AND b) Note the careful use of parentheses to indicate which pairs of statements are being combined by the operation. To decide if a logical expression like ab + cb is true or false, we need to know if the statements a, b, and c are true or false. Example If statement a is true, statement b is false, and the statement c is true, is the logical expression ab + cb true or false? Answer Let’s use 0 to symbolize false and 1 symbolize true. So we have a=1 b=0 c=1 We evaluate the expression by breaking it down into smaller expression: ab, cb, and cb . Evaluating these smaller expressions: If a = 1 and b = 0 then ab = 0. (That is, if a is TRUE and b is FALSE then a AND b is FALSE.) If c = 1 and b = 0 then cb = 0. (For similar reasons.) If cb = 0 then cb = 1. (NOT changes a FALSE to a TRUE.) If ab = 0 and cb = 1 then ab + cb = 1 (Since 0 OR 1 is 1.) So the answer is that ab + cb is true. Now suppose we didn’t know whether each of a, b, and c were true or false. We could still decide when the logical expression is true and when it is false – we just need to try all the possibilities for 0 and 1 for each of a, b, and c. This process is called analyzing the logical expression. To do this systematically we use what in logic is called a truth table. We make a table listing all the true/false possibilities for a, b, and c, with a column for the truth value of the expression: a 0 0 0 0 1 1 1 1 b 0 0 1 1 0 0 1 1 c 0 1 0 1 0 1 0 1 ab + cb Note that to generate all the possible combinations of true and false (that is, 1 and 0) for a, b, and c in a systematic way we have used the order of symbols that we already learned from binary counting (000 is 0, 001 is 1, 010 is 2, etc.). Altogether in our table there are 8 rows (since we go from 000 to 111, which is 0 to 7 in binary, we have 23 rows). Now although we only care about the truth values of the logical expression ab + cb (the last column) it’s helpful to break the expression down into smaller expressions and create columns for each of these, which we’ll call helper columns. So our table looks like a 0 0 0 0 1 1 1 1 b 0 0 1 1 0 0 1 1 c 0 1 0 1 0 1 0 1 ab cb cb ab + cb Now we fill in each column in turn. For the first helper column, the one for ab, we want to know when a AND b is true. This can only happen when both a and b are true, so we look at the column under a and the column under b for rows where both are 1. This only happens in the last two rows. So write a 1 in the last two rows of the helper column for ab. For every other row under ab we write a 0. So we have a 0 0 0 0 1 1 1 1 b 0 0 1 1 0 0 1 1 c 0 1 0 1 0 1 0 1 ab 0 0 0 0 0 0 1 1 cb cb ab + cb Similarly, in the helper column for cb we look for rows where both c and b are both 1. This only happens for the fourth and last rows, we write 1’s under cb in those rows and write zeros for the other rows under cb. So now we have a 0 0 0 0 1 1 1 1 b 0 0 1 1 0 0 1 1 c 0 1 0 1 0 1 0 1 ab 0 0 0 0 0 0 1 1 cb 0 0 0 1 0 0 0 1 cb ab + cb The helper column for cb requires that we look at NOT (cb). Now NOT just changes true to false and false to true, so we just have to look at the column for cb and change 1’s to 0’s and 0’s to 1’s. We get a b c ab cb ab + cb cb 0 0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 0 1 0 1 1 0 1 0 1 0 0 0 0 1 1 0 1 0 0 1 1 1 0 1 0 1 1 1 1 1 1 0 Finally, we can analyze the logical expression itself. The expression ab + cb means ab OR cb . If we combine two statements with an OR the combined statement will be true unless both the pieces are false. So we look at the helper columns for ab and cb to find rows where both ab and cb are 0, writing a 0 in the last column whenever this happens. This only happens for the fourth row. Every other row results in a 1. a 0 0 0 0 1 1 1 1 b 0 0 1 1 0 0 1 1 c 0 1 0 1 0 1 0 1 ab 0 0 0 0 0 0 1 1 cb 0 0 0 1 0 0 0 1 cb 1 1 1 0 1 1 1 0 ab + cb 1 1 1 0 1 1 1 1 This truth table tells us that the logical expression ab + cb will always be true unless a = 0, b = 1, and c = 1 (that is, when a is false and b and c are true). The truth table completely describes how the logical expression will behave when we set each of a, b, and c to either 0 or 1. Here are a couple more examples: Example Analyze the logical expression ( a b) c . Answer The notation ( a b) c means (a OR b) AND NOT c. We break the expression down into smaller pieces a + b and c . Again we have three basic statements a, b, and c so we again have 23 = 8 rows of possible combinations of 0’s and 1’s. The a + b column will have a 0 only in rows where both a and b are 0. The c column is just the opposite of the c column. The last column will have 1’s only where both a + b and c have 1’s. So we have a 0 0 0 0 1 1 1 1 b 0 0 1 1 0 0 1 1 c 0 1 0 1 0 1 0 1 a+b 0 0 1 1 1 1 1 1 c 1 0 1 0 1 0 1 0 ( a b) c 0 0 1 0 1 0 1 0 Example Analyze the logical expression ab + c d . Answer Here we have four basic variables a, b, c, and d so we have 24 = 16 possible combinations of 0’s and 1’s. Again we generate all of these combinations by binary counting. We choose our helper columns (ab, c + d, and c d ) and evaluate helper columns to get the following table: a 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 b 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 c 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 d 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 ab 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 c+d 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 cd 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 ab + c d 1 0 0 0 1 0 0 0 1 0 0 0 1 1 1 1 We have seen how to combine the three basic operations of logic – AND, OR, NOT – into more complicated logical expressions and how to analyze the behavior of a logical expression. In the next section, we’ll study some properties of these operations.