









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The basics of propositional logic, focusing on the use of truth tables to determine the truth values of propositions and the meaning of logical operators such as 'not', 'and', 'or', and 'implies'. It also covers the concept of propositional variables and their relationship with Boolean variables.
Typology: Essays (university)
1 / 16
This page cannot be seen from the preview
Don't miss anything!










In English, we can modify, combine, and relate propositions with words such as “not,” “and,” “or,” “implies,” and “if-then.” For example, we can combine three propositions into one like this:
If all humans are mortal and all Greeks are human, then all Greeks are mortal.
For the next while, we won’t be much concerned with the internals of propositions— whether they involve mathematics or Greek mortality—but rather with how propo- sitions are combined and related. So, we’ll frequently use variables such as P and Q in place of specific propositions such as “All humans are mortal” and “ 2 C 3 D 5 .” The understanding is that these propositional variables, like propositions, can take on only the values T (true) and F (false). Propositional variables are also called Boolean variables after their inventor, the nineteenth century mathematician George—you guessed it—Boole.
Mathematicians use the words NOT , AND , and OR for operations that change or combine propositions. The precise mathematical meaning of these special words can be specified by truth tables. For example, if P is a proposition, then so is “ NOT.P /,” and the truth value of the proposition “ NOT.P /” is determined by the truth value of P according to the following truth table:
P NOT.P / T F F T
The first row of the table indicates that when proposition P is true, the proposition “ NOT.P /” is false. The second line indicates that when P is false, “ NOT.P /” is true. This is probably what you would expect. In general, a truth table indicates the true/false value of a proposition for each possible set of truth values for the variables. For example, the truth table for the proposition “P AND Q” has four lines, since there are four settings of truth values for the two variables: P Q P AND Q T T T T F F F T F F F F
3.1. Propositions from Propositions 43
According to this table, the proposition “P AND Q” is true only when P and Q are both true. This is probably the way you ordinarily think about the word “and.” There is a subtlety in the truth table for “P OR Q”:
P Q P OR Q T T T T F T F T T F F F
The first row of this table says that “P OR Q” is true even if both P and Q are true. This isn’t always the intended meaning of “or” in everyday speech, but this is the standard definition in mathematical writing. So if a mathematician says, “You may have cake, or you may have ice cream,” he means that you could have both. If you want to exclude the possibility of having both cake and ice cream, you should combine them with the exclusive-or operation, XOR :
P Q P XOR Q T T F T F T F T T F F F
The combining operation with the least intuitive technical meaning is “implies.” Here is its truth table, with the lines labeled so we can refer to them later.
P Q P IMPLIES Q T T T (tt) T F F (tf) F T T (ft) F F T (ff)
The truth table for implications can be summarized in words as follows:
An implication is true exactly when the if-part is false or the then-part is true.
This sentence is worth remembering; a large fraction of all mathematical statements are of the if-then form! Let’s experiment with this definition. For example, is the following proposition true or false?
3.2. Propositional Logic in Computer Programs 45
For example, suppose only conditions C 2 and C 5 are true, and the system indeed takes the specified actions A 2 and A 5. This means that in this case the system is behaving according to specification, and accordingly we want the formula (3.1) to come out true. Now the implications C 2 IMPLIES A 2 and C 5 IMPLIES A 5 are both true because both their hypotheses and their conclusions are true. But in order for (3.1) to be true, we need all the other implications with the false hypotheses Ci for i ¤ 2; 5 to be true. This is exactly what the rule for implications with false hypotheses accomplishes.
Mathematicians commonly join propositions in one additional way that doesn’t arise in ordinary speech. The proposition “P if and only if Q” asserts that P and Q have the same truth value. Either both are true or both are false.
P Q P IFF Q T T T T F F F T F F F T
For example, the following if-and-only-if statement is true for every real number x: x^2 4 0 IFF jxj 2: For some values of x, both inequalities are true. For other values of x, neither inequality is true. In every case, however, the IFF^ proposition as a whole is true.
Propositions and logical connectives arise all the time in computer programs. For example, consider the following snippet, which could be either C, C++, or Java:
if ( x > 0 || (x <= 0 && y > 100) ) :: : (further instructions)
Java uses the symbol || for “ OR ,” and the symbol && for “ AND .” The further instructions are carried out only if the proposition following the word if is true. On closer inspection, this big expression is built from two simpler propositions.
46 Chapter 3 Logical Formulas
Let A be the proposition that x > 0, and let B be the proposition that y > 100. Then we can rewrite the condition as
A OR .NOT.A/ AND B/: (3.2)
A truth table calculation reveals that the more complicated expression 3.2 always has the same truth value as A OR B: (3.3) We begin with a table with just the truth values of A and B: A B A OR .NOT.A/ AND B/ A OR B T T T F F T F F These values are enough to fill in two more columns: A B A OR .NOT.A/ AND B/ A OR B
Now we have the values needed to fill in the AND column: A B A OR .NOT.A/ AND B/ A OR B
and this provides the values needed to fill in the remaining column for the first OR : A B A OR .NOT.A/ AND B/ A OR B
Expressions whose truth values always match are called equivalent. Since the two emphasized columns of truth values of the two expressions are the same, they are
48 Chapter 3 Logical Formulas
English Symbolic Notation NOT.P / :P (alternatively, P ) P AND Q P ^ Q P OR Q P _ Q P IMPLIES Q P ! Q if P then Q P ! Q P IFF Q P! Q P XOR Q P ˚ Q
For example, using this notation, “If P AND NOT.Q/, then R” would be written:
.P ^ Q/ ! R:
The mathematical notation is concise but cryptic. Words such as “ AND ” and “ OR ” are easier to remember and won’t get confused with operations on numbers. We will often use P as an abbreviation for NOT.P /, but aside from that, we mostly stick to the words—except when formulas would otherwise run off the page.
Do these two sentences say the same thing?
If I am hungry, then I am grumpy. If I am not grumpy, then I am not hungry.
We can settle the issue by recasting both sentences in terms of propositional logic. Let P be the proposition “I am hungry” and Q be “I am grumpy.” The first sentence says “P IMPLIES Q” and the second says “ NOT.Q/ IMPLIES NOT.P /.” Once more, we can compare these two statements in a truth table:
P Q .P IMPLIES Q/ .NOT.Q/ IMPLIES NOT.P //
Sure enough, the highlighted columns showing the truth values of these two state- ments are the same. A statement of the form “ NOT.Q/ IMPLIES NOT.P /” is called
3.3. Equivalence and Validity 49
the contrapositive of the implication “P IMPLIES Q.” The truth table shows that an implication and its contrapositive are equivalent—they are just different ways of saying the same thing. In contrast, the converse of “P IMPLIES Q” is the statement “Q IMPLIES P .” The converse to our example is:
If I am grumpy, then I am hungry.
This sounds like a rather different contention, and a truth table confirms this suspi- cion: P Q P IMPLIES Q Q IMPLIES P
Now the highlighted columns differ in the second and third row, confirming that an implication is generally not equivalent to its converse. One final relationship: an implication and its converse together are equivalent to an iff statement, specifically, to these two statements together. For example,
If I am grumpy then I am hungry, and if I am hungry then I am grumpy.
are equivalent to the single statement:
I am grumpy iff I am hungry.
Once again, we can verify this with a truth table.
P Q .P IMPLIES Q/ AND .Q IMPLIES P / P IFF Q
The fourth column giving the truth values of
.P IMPLIES Q/ AND .Q IMPLIES P /
is the same as the sixth column giving the truth values of P IFF Q, which confirms that the AND of the implications is equivalent to the IFF statement.
3.4. The Algebra of Propositions 51
You can read a disjunctive form for any propositional formula directly from its truth table. For example, the formula
A AND .B OR C / (3.5)
has truth table: A B C A AND .B OR C / T T T T T T F T T F T T T F F F F T T F F T F F F F T F F F F F
The formula (3.5) is true in the first row when A, B, and C are all true, that is, where A AND B AND C is true. It is also true in the second row where A AND B AND C is true, and in the third row when A AND B AND C is true, and that’s all. So (3.5) is true exactly when
.A AND B AND C / OR .A AND B AND C / OR .A AND B AND C / (3.6)
is true.
Theorem 3.4.1. [Distributive Law of AND over OR]
A AND .B OR C / is equivalent to .A AND B/ OR .A AND C /:
Theorem 3.4.1 is called a distributive law because of its resemblance to the dis- tributivity of products over sums in arithmetic. Similarly, we have (Problem 3.10):
Theorem 3.4.2. [Distributive Law of OR over AND]
A OR .B AND C / is equivalent to .A OR B/ AND .A OR C /:
Note the contrast between Theorem 3.4.2 and arithmetic, where sums do not distribute over products. The expression (3.6) is a disjunctive form where each AND -term is an AND of every one of the variables or their negations in turn. An expression of this form is called a disjunctive normal form (DNF). A DNF formula can often be simplified into a smaller disjunctive form. For example, the DNF (3.6) further simplifies to the equivalent disjunctive form (3.4) above.
52 Chapter 3 Logical Formulas
Applying the same reasoning to the F entries of a truth table yields a conjunctive form for any formula—an AND of OR -terms in which the OR -terms are OR ’s only of variables or their negations. For example, formula (3.5) is false in the fourth row of its truth table (3.4.1) where A is T, B is F and C is F. But this is exactly the one row where .A OR B OR C / is F! Likewise, the (3.5) is false in the fifth row which is exactly where .A OR B OR C / is F. This means that (3.5) will be F whenever the AND of these two OR -terms is false. Continuing in this way with the OR -terms corresponding to the remaining three rows where (3.5) is false, we get a conjunctive normal form (CNF) that is equivalent to (3.5), namely,
.A OR B OR C / AND .A OR B OR C / AND .A OR B OR C /AND .A OR B OR C / AND .A OR B OR C /
The methods above can be applied to any truth table, which implies
Theorem 3.4.3. Every propositional formula is equivalent to both a disjunctive normal form and a conjunctive normal form.
A check of equivalence or validity by truth table runs out of steam pretty quickly: a proposition with n variables has a truth table with 2 n^ lines, so the effort required to check a proposition grows exponentially with the number of variables. For a proposition with just 30 variables, that’s already over a billion lines to check! An alternative approach that sometimes helps is to use algebra to prove equiv- alence. A lot of different operators may appear in a propositional formula, so a useful first step is to get rid of all but three: AND , OR , and NOT. This is easy because each of the operators is equivalent to a simple formula using only these three. For example, A IMPLIES B is equivalent to NOT.A/ OR B. Formulas using only AND , OR , and NOT for the remaining operators are left to Problem 3.13. We list below a bunch of equivalence axioms with the symbol “! ” between equivalent formulas. These axioms are important because they are all that’s needed to prove every possible equivalence. We’ll start with some equivalences for AND ’s that look like the familiar ones for multiplication of numbers:
A AND B! B AND A (commutativity of AND ) (3.7) .A AND B/ AND C! A AND .B AND C / (associativity of AND ) (3.8) T AND A! A (identity for AND ) F AND A! F (zero for AND )
54 Chapter 3 Logical Formulas
Using distributivity over both AND ’s we get ..A AND A/ OR .B AND A// OR ..A AND C / OR .B AND C //: By the way, we’ve implicitly used commutativity (3.7) here to justify distributing over an AND from the right. Now applying idempotence to remove the duplicate occurrence of A we get .A OR .B AND A// OR ..A AND C / OR .B AND C //: Associativity now allows dropping the parentheses around the terms being OR ’d to yield the following disjunctive form for (3.13): A OR .B AND A/ OR .A AND C / OR .B AND C /: (3.15) The last step is to turn each of these AND -terms into a disjunctive normal form with all three variables A, B, and C. We’ll illustrate how to do this for the second AND -term .B AND A/. This term needs to mention C to be in normal form. To introduce C , we use validity for OR and identity for AND to conclude that .B AND A/! .B AND A/ AND .C OR C /: Now distributing .B AND A/ over the OR yields the disjunctive normal form .B AND A AND C / OR .B AND A AND C /: Doing the same thing to the other AND -terms in (3.15) finally gives a disjunctive normal form for (3.5): .A AND B AND C / OR .A AND B AND C / OR .A AND B AND C / OR .A AND B AND C / OR .B AND A AND C / OR .B AND A AND C / OR .A AND C AND B/ OR .A AND C AND B/ OR .B AND C AND A/ OR .B AND C AND A/: Using commutativity to sort the term and OR -idempotence to remove duplicates, finally yields a unique sorted DNF: .A AND B AND C / OR .A AND B AND C / OR .A AND B AND C / OR .A AND B AND C / OR .A AND B AND C /: This example illustrates a strategy for applying these equivalences to convert any formula into disjunctive normal form, and conversion to conjunctive normal form works similarly, which explains:
3.5. The SAT Problem 55
Theorem 3.4.4. Any propositional formula can be transformed into disjunctive normal form or a conjunctive normal form using the equivalences listed above. What has this got to do with equivalence? That’s easy: to prove that two for- mulas are equivalent, convert them both to disjunctive normal form over the set of variables that appear in the terms. Then use commutativity to sort the variables and AND -terms so they all appear in some standard order. We claim the formulas are equivalent iff they have the same sorted disjunctive normal form. This is obvious if they do have the same disjunctive normal form. But conversely, the way we read off a disjunctive normal form from a truth table shows that two different sorted DNF’s over the same set of variables correspond to different truth tables and hence to inequivalent formulas. This proves Theorem 3.4.5 (Completeness of the propositional equivalence axioms). Two propo- sitional formula are equivalent iff they can be proved equivalent using the equiva- lence axioms listed above.
The benefit of the axioms is that they leave room for ingeniously applying them to prove equivalences with less effort than the truth table method. Theorem 3.4. then adds the reassurance that the axioms are guaranteed to prove every equiva- lence, which is a great punchline for this section. But we don’t want to mislead you: it’s important to realize that using the strategy we gave for applying the ax- ioms involves essentially the same effort it would take to construct truth tables, and there is no guarantee that applying the axioms will generally be any easier than using truth tables.
Determining whether or not a more complicated proposition is satisfiable is not so easy. How about this one?
.P OR Q OR R/ AND .P OR Q/ AND .P OR R/ AND .R OR Q/
The general problem of deciding whether a proposition is satisfiable is called SAT. One approach to SAT is to construct a truth table and check whether or not a T ever appears, but as with testing validity, this approach quickly bogs down for formulas with many variables because truth tables grow exponentially with the number of variables. Is there a more efficient solution to SAT? In particular, is there some brilliant procedure that determines SAT in a number of steps that grows polynomially—like
MIT OpenCourseWare https://ocw.mit.edu
Spring 201 5
For information about citing these materials or our Terms of Use, visit: https://ocw.mit.edu/terms.