33.0 KB · commit a9602da
The rules of logic specify the meaning of mathematical statements. For instance, these rules help us understand and reason with statements such as "There exists an integer that is not the sum of two squares" and "For every positive integer n, the sum of the positive integers not exceeding n is n(n+1)/2." Logic is the basis of all mathematical reasoning, and of all automated reasoning. It has practical applications to the design of computing machines, to the specification of systems, to artificial intelligence, to computer programming, to programming languages, and to other areas of computer science, as well as to many other fields of study.
To understand mathematics, we must understand what makes up a correct mathematical argument, that is, a proof. Once we prove a mathematical statement is true, we call it a theorem. A collection of theorems on a topic organize what we know about this topic. To learn a mathematical topic, a person needs to actively construct mathematical arguments on this topic, and not just read exposition. Moreover, knowing the proof of a theorem often makes it possible to modify the result to fit new situations.
Everyone knows that proofs are important throughout mathematics, but many people find it surprising how important proofs are in computer science. In fact, proofs are used to verify that computer programs produce the correct output for all possible input values, to show that algorithms always produce the correct result, to establish the security of a system, and to create artificial intelligence. Furthermore, automated reasoning systems have been created to allow computers to construct their own proofs.
In this chapter, we will explain what makes up a correct mathematical argument and introduce tools to construct these arguments. We will develop an arsenal of different proof methods that will enable us to prove many different types of results. After introducing many different methods of proof, we will introduce several strategies for constructing proofs. We will introduce the notion of a conjecture and explain the process of developing mathematics by studying conjectures.
The rules of logic give precise meaning to mathematical statements. These rules are used to distinguish between valid and invalid mathematical arguments. Because a major goal of this book is to teach the reader how to understand and how to construct correct mathematical arguments, we begin our study of discrete mathematics with an introduction to logic.
Besides the importance of logic in understanding mathematical reasoning, logic has numerous applications to computer science. These rules are used in the design of computer circuits, the construction of computer programs, the verification of the correctness of programs, and in many other ways. Furthermore, software systems have been developed for constructing some, but not all, types of proofs automatically. We will discuss these applications of logic in this and later chapters.
Our discussion begins with an introduction to the basic building blocks of logic—propositions. A proposition is a declarative sentence (that is, a sentence that declares a fact) that is either true or false, but not both.
All the following declarative sentences are propositions.
Propositions 1 and 3 are true, whereas 2 and 4 are false. ◀
Some sentences that are not propositions are given in Example 2.
Consider the following sentences.
Sentences 1 and 2 are not propositions because they are not declarative sentences. Sentences 3 and 4 are not propositions because they are neither true nor false. Note that each of sentences 3 and 4 can be turned into a proposition if we assign values to the variables. We will also discuss other ways to turn sentences such as these into propositions in Section 1.4. ◀
We use letters to denote propositional variables (or statement variables), that is, variables that represent propositions, just as letters are used to denote numerical variables.
The conventional letters used for propositional variables are p,q,r,s,…. The truth value of a proposition is true, denoted by T, if it is a true proposition, and the truth value of a proposition is false, denoted by F, if it is a false proposition.
The area of logic that deals with propositions is called the propositional calculus or propositional logic. It was first developed systematically by the Greek philosopher Aristotle more than 2300 years ago.
We now turn our attention to methods for producing new propositions from those that we already have. These methods were discussed by the English mathematician George Boole in 1854 in his book The Laws of Thought. Many mathematical statements are constructed by combining one or more propositions. New propositions, called compound propositions, are formed from existing propositions using logical operators.
Find the negation of the proposition "Michael's PC runs Linux" and express this in simple English.
Solution: The negation is "It is not the case that Michael's PC runs Linux." This negation can be more simply expressed as "Michael's PC does not run Linux." ◀
Find the negation of the proposition "Vandana's smartphone has at least 32GB of memory" and express this in simple English.
Solution: The negation is "It is not the case that Vandana's smartphone has at least 32GB of memory." This negation can also be expressed as "Vandana's smartphone does not have at least 32GB of memory" or even more simply as "Vandana's smartphone has less than 32GB of memory." ◀
| p | ¬p |
|---|---|
| T | F |
| F | T |
Table 1 displays the truth table for the negation of a proposition p. This table has a row for each of the two possible truth values of a proposition p. Each row shows the truth value of ¬p corresponding to the truth value of p for this row.
The negation of a proposition can also be considered the result of the operation of the negation operator on a proposition. The negation operator constructs a new proposition from a single existing proposition. We will now introduce the logical operators that are used to form new propositions from two or more existing propositions. These logical operators are also called connectives.
Table 2 displays the truth table of p∧q. This table has a row for each of the four possible combinations of truth values of p and q. The four rows correspond to the pairs of truth values TT, TF, FT, and FF, where the first truth value in the pair is the truth value of p and the second truth value is the truth value of q.
Note that in logic the word "but" sometimes is used instead of "and" in a conjunction. For example, the statement "The sun is shining, but it is raining" is another way of saying "The sun is shining and it is raining." (In natural language, there is a subtle difference in meaning between "and" and "but"; we will not be concerned with this nuance here.)
Find the conjunction of the propositions p and q where p is the proposition "Rebecca's PC has more than 16 GB free hard disk space" and q is the proposition "The processor in Rebecca's PC runs faster than 1 GHz."
Solution: The conjunction of these propositions, p∧q, is the proposition "Rebecca's PC has more than 16 GB free hard disk space, and the processor in Rebecca's PC runs faster than 1 GHz." This conjunction can be expressed more simply as "Rebecca's PC has more than 16 GB free hard disk space, and its processor runs faster than 1 GHz." For this conjunction to be true, both conditions given must be true. It is false, when one or both of these conditions are false. ◀
Table 3 displays the truth table for p∨q.
| p | q | p∧q |
|---|---|---|
| T | T | T |
| T | F | F |
| F | T | F |
| F | F | F |
| p | q | p∨q |
|---|---|---|
| T | T | T |
| T | F | T |
| F | T | T |
| F | F | F |
The use of the connective or in a disjunction corresponds to one of the two ways the word or is used in English, namely, as an inclusive or. A disjunction is true when at least one of the two propositions is true. For instance, the inclusive or is being used in the statement
"Students who have taken calculus or computer science can take this class."
Here, we mean that students who have taken both calculus and computer science can take the class, as well as the students who have taken only one of the two subjects. On the other hand, we are using the exclusive or when we say
"Students who have taken calculus or computer science, but not both, can enroll in this class."
Here, we mean that students who have taken both calculus and a computer science course cannot take the class. Only those who have taken exactly one of the two courses can take the class.
Similarly, when a menu at a restaurant states, "Soup or salad comes with an entrée," the restaurant almost always means that customers can have either soup or salad, but not both. Hence, this is an exclusive, rather than an inclusive, or.
What is the disjunction of the propositions p and q where p and q are the same propositions as in Example 5?
Solution: The disjunction of p and q, p∨q, is the proposition "Rebecca's PC has at least 16 GB free hard disk space, or the processor in Rebecca's PC runs faster than 1 GHz."
This proposition is true when Rebecca's PC has at least 16 GB free hard disk space, when the PC's processor runs faster than 1 GHz, and when both conditions are true. It is false when both of these conditions are false, that is, when Rebecca's PC has less than 16 GB free hard disk space and the processor in her PC runs at 1 GHz or slower. ◀
As was previously remarked, the use of the connective or in a disjunction corresponds to one of the two ways the word or is used in English, namely, in an inclusive way. Thus, a disjunction is true when at least one of the two propositions in it is true. Sometimes, we use or in an exclusive sense. When the exclusive or is used to connect the propositions p and q, the proposition "p or q (but not both)" is obtained. This proposition is true when p is true and q is false, and when p is false and q is true. It is false when both p and q are false and when both are true.
| p | q | p⊕q |
|---|---|---|
| T | T | F |
| T | F | T |
| F | T | T |
| F | F | F |
| p | q | p→q |
|---|---|---|
| T | T | T |
| T | F | F |
| F | T | T |
| F | F | T |
The truth table for the exclusive or of two propositions is displayed in Table 4.
We will discuss several other important ways in which propositions can be combined.
The statement p→q is called a conditional statement because p→q asserts that q is true on the condition that p holds. A conditional statement is also called an implication.
The truth table for the conditional statement p→q is shown in Table 5. Note that the statement p→q is true when both p and q are true and when p is false (no matter what truth value q has).
Because conditional statements play such an essential role in mathematical reasoning, a variety of terminology is used to express p→q. You will encounter most if not all of the following ways to express this conditional statement:
A useful way to understand the truth value of a conditional statement is to think of an obligation or a contract. For example, the pledge many politicians make when running for office is
"If I am elected, then I will lower taxes."
If the politician is elected, voters would expect this politician to lower taxes. Furthermore, if the politician is not elected, then voters will not have any expectation that this person will lower taxes, although the person may have sufficient influence to cause those in power to lower taxes. It is only when the politician is elected but does not lower taxes that voters can say that the politician has broken the campaign pledge. This last scenario corresponds to the case when p is true but q is false in p→q.
Similarly, consider a statement that a professor might make:
"If you get 100% on the final, then you will get an A."
If you manage to get a 100% on the final, then you would expect to receive an A. If you do not get 100% you may or may not receive an A depending on other factors. However, if you do get 100%, but the professor does not give you an A, you will feel cheated.
Of the various ways to express the conditional statement p→q, the two that seem to cause the most confusion are "p only if q" and "q unless ¬p." Consequently, we will provide some guidance for clearing up this confusion.
To remember that "p only if q" expresses the same thing as "if p, then q," note that "p only if q" says that p cannot be true when q is not true. That is, the statement is false if p is true, but q is false. When p is false, q may be either true or false, because the statement says nothing about the truth value of q. Be careful not to use "q only if p" to express p→q because this is incorrect. To see this, note that the truth values of "q only if p" and p→q are different when p and q have different truth values.
To remember that "q unless ¬p" expresses the same conditional statement as "if p, then q," note that "q unless ¬p" means that if ¬p is false, then q must be true. That is, the statement "q unless ¬p" is false when p is true but q is false, but it is true otherwise. Consequently, "q unless ¬p" and p→q always have the same truth value.
We illustrate the translation between conditional statements and English statements in Example 7.
Let p be the statement "Maria learns discrete mathematics" and q the statement "Maria will find a good job." Express the statement p→q as a statement in English.
Solution: From the definition of conditional statements, we see that when p is the statement "Maria learns discrete mathematics" and q is the statement "Maria will find a good job," p→q represents the statement
"If Maria learns discrete mathematics, then she will find a good job."
There are many other ways to express this conditional statement in English. Among the most natural of these are:
"Maria will find a good job when she learns discrete mathematics." "For Maria to get a good job, it is sufficient for her to learn discrete mathematics." and "Maria will find a good job unless she does not learn discrete mathematics." ◀
Note that the way we have defined conditional statements is more general than the meaning attached to such statements in the English language. For instance, the conditional statement in Example 7 and the statement
"If it is sunny, then we will go to the beach."
are statements used in normal language where there is a relationship between the hypothesis and the conclusion. Further, the first of these statements is true unless Maria learns discrete mathematics, but she does not get a good job, and the second is true unless it is indeed sunny, but we do not go to the beach. On the other hand, the statement
"If Juan has a smartphone, then 2+3=5"
is true from the definition of a conditional statement, because its conclusion is true. (The truth value of the hypothesis does not matter then.) The conditional statement
"If Juan has a smartphone, then 2+3=6"
is true if Juan does not have a smartphone, even though 2+3=6 is false. We would not use these last two conditional statements in natural language (except perhaps in sarcasm), because there is no relationship between the hypothesis and the conclusion in either statement. In mathematical reasoning, we consider conditional statements of a more general sort than we use in English. The mathematical concept of a conditional statement is independent of a cause-and-effect relationship between hypothesis and conclusion. Our definition of a conditional statement specifies its truth values; it is not based on English usage. Propositional language is an artificial language; we only parallel English usage to make it easy to use and remember.
The if-then construction used in many programming languages is different from that used in logic. Most programming languages contain statements such as if p then S, where p is a proposition and S is a program segment (one or more statements to be executed). When execution of a program encounters such a statement, S is executed if p is true, but S is not executed if p is false, as illustrated in Example 8.
What is the value of the variable x after the statement
if 2+2=4 then x:=x+1
if x=0 before this statement is encountered? (The symbol := stands for assignment. The statement x:=x+1 means the assignment of the value of x+1 to x.)
Solution: Because 2+2=4 is true, the assignment statement x:=x+1 is executed. Hence, x has the value 0+1=1 after this statement is encountered. ◀
We can form some new conditional statements starting with a conditional statement p→q. In particular, there are three related conditional statements that occur so often that they have special names.
We will see that of these three conditional statements formed from p→q, only the contrapositive always has the same truth value as p→q.
We first show that the contrapositive, ¬q→¬p, of a conditional statement p→q always has the same truth value as p→q. To see this, note that the contrapositive is false only when ¬p is false and ¬q is true, that is, only when p is true and q is false. We now show that neither the converse, q→p, nor the inverse, ¬p→¬q, has the same truth value as p→q for all possible truth values of p and q. Note that when p is true and q is false, the original conditional statement is false, but the converse and the inverse are both true.
When two compound propositions always have the same truth value we call them equivalent, so that a conditional statement and its contrapositive are equivalent. The converse and the inverse of a conditional statement are also equivalent, as the reader can verify, but neither is equivalent to the original conditional statement. (We will study equivalent propositions in Section 1.3.) Take note that one of the most common logical errors is to assume that the converse or the inverse of a conditional statement is equivalent to this conditional statement.
We illustrate the use of conditional statements in Example 9.
What are the contrapositive, the converse, and the inverse of the conditional statement
"The home team wins whenever it is raining?"
Solution: Because "q whenever p" is one of the ways to express the conditional statement p→q, the original statement can be rewritten as
"If it is raining, then the home team wins."
Consequently, the contrapositive of this conditional statement is "If the home team does not win, then it is not raining."
The converse is "If the home team wins, then it is raining."
The inverse is "If it is not raining, then the home team does not win."
Only the contrapositive is equivalent to the original statement. ◀
We now introduce another way to combine propositions that expresses that two propositions have the same truth value.
The truth table for p↔q is shown in Table 6. Note that the statement p↔q is true when both the conditional statements p→q and q→p are true and is false otherwise. That is why we use the words "if and only if" to express this logical connective and why it is symbolically written by combining the symbols → and ←. There are some other common ways to express p↔q:
The last way of expressing the biconditional statement p↔q uses the abbreviation "iff" for "if and only if." Note that p↔q has exactly the same truth value as (p→q)∧(q→p).
| p | q | p↔q |
|---|---|---|
| T | T | T |
| T | F | F |
| F | T | F |
| F | F | T |
Let p be the statement "You can take the flight," and let q be the statement "You buy a ticket." Then p↔q is the statement
"You can take the flight if and only if you buy a ticket."
This statement is true if p and q are either both true or both false, that is, if you buy a ticket and can take the flight or if you do not buy a ticket and you cannot take the flight. It is false when p and q have opposite truth values, that is, when you do not buy a ticket, but you can take the flight (such as when you get a free trip) and when you buy a ticket but you cannot take the flight (such as when the airline bumps you). ◀
You should be aware that biconditionals are not always explicit in natural language. In particular, the "if and only if" construction used in biconditionals is rarely used in common language. Instead, biconditionals are often expressed using an "if, then" or an "only if" construction. The other part of the "if and only if" is implicit. That is, the converse is implied, but not stated. For example, consider the statement in English "If you finish your meal, then you can have dessert." What is really meant is "You can have dessert if and only if you finish your meal." This last statement is logically equivalent to the two statements "If you finish your meal, then you can have dessert" and "You can have dessert only if you finish your meal." Because of this imprecision in natural language, we need to make an assumption whether a conditional statement in natural language implicitly includes its converse. Because precision is essential in mathematics and in logic, we will always distinguish between the conditional statement p→q and the biconditional statement p↔q.
We have now introduced four important logical connectives—conjunctions, disjunctions, conditional statements, and biconditional statements—as well as negations. We can use these connectives to build up complicated compound propositions involving any number of propositional variables. We can use truth tables to determine the truth values of these compound propositions, as Example 11 illustrates. We use a separate column to find the truth value of each compound expression that occurs in the compound proposition as it is built up. The truth values of the compound proposition for each combination of truth values of the propositional variables in it is found in the final column of the table.
Construct the truth table of the compound proposition (p∨¬q)→(p∧q).
Solution: Because this truth table involves two propositional variables p and q, there are four rows in this truth table, one for each of the pairs of truth values TT, TF, FT, and FF. The first two columns are used for the truth values of p and q, respectively. In the third column we find the truth value of ¬q, needed to find the truth value of p∨¬q, found in the fourth column. The fifth column gives the truth value of p∧q. Finally, the truth value of (p∨¬q)→(p∧q) is found in the last column. The resulting truth table is shown in Table 7.
| p | q | ¬q | p∨¬q | p∧q | (p∨¬q)→(p∧q) |
|---|---|---|---|---|---|
| T | T | F | T | T | T |
| T | F | T | T | F | F |
| F | T | F | F | F | T |
| F | F | T | T | F | F |
◀
We can construct compound propositions using the negation operator and the logical operators defined so far. We will generally use parentheses to specify the order in which logical operators in a compound proposition are to be applied. For instance, (p∨q)∧(¬r) is the conjunction of p∨q and ¬r. However, to reduce the number of parentheses, we specify that the negation operator is applied before all other logical operators. This means that ¬p∧q is the conjunction of ¬p and q, namely, (¬p)∧q, not the negation of the conjunction of p and q, namely ¬(p∧q).
Another general rule of precedence is that the conjunction operator takes precedence over the disjunction operator, so that p∧q∨r means (p∧q)∨r rather than p∧(q∨r). Because this rule may be difficult to remember, we will continue to use parentheses so that the order of the disjunction and conjunction operators is clear.
| Operator | Precedence |
|---|---|
| ¬ | 1 |
| ∧ | 2 |
| ∨ | 3 |
| → | 4 |
| ↔ | 5 |
Finally, it is an accepted rule that the conditional and biconditional operators → and ↔ have lower precedence than the conjunction and disjunction operators, ∧ and ∨. Consequently, p∨q→r is the same as (p∨q)→r. We will use parentheses when the order of the conditional operator and biconditional operator is at issue, although the conditional operator has precedence over the biconditional operator. Table 8 displays the precedence levels of the logical operators, ¬,∧,∨,→, and ↔.
Computers represent information using bits. A bit is a symbol with two possible values, namely, 0 (zero) and 1 (one). This meaning of the word bit comes from binary digit, because zeros and ones are the digits used in binary representations of numbers. The well-known statistician John Tukey introduced this terminology in 1946. A bit can be used to represent a truth value, because there are two truth values, namely, true and false. As is customarily done, we will use a 1 bit to represent true and a 0 bit to represent false. That is, 1 represents T (true), 0 represents F (false). A variable is called a Boolean variable if its value is either true or false. Consequently, a Boolean variable can be represented using a bit.
| Truth Value | Bit |
|---|---|
| T | 1 |
| F | 0 |
Computer bit operations correspond to the logical connectives. By replacing true by a one and false by a zero in the truth tables for the operators ∧, ∨, and ⊕, the tables shown in Table 9 for the corresponding bit operations are obtained. We will also use the notation OR, AND, and XOR for the operators ∨, ∧, and ⊕, as is done in various programming languages.
| x | y | x∨y | x∧y | x⊕y |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 |
Information is often represented using bit strings, which are lists of zeros and ones. When this is done, operations on the bit strings can be used to manipulate this information.
101010011 is a bit string of length nine. ◀
We can extend bit operations to bit strings. We define the bitwise OR, bitwise AND, and bitwise XOR of two strings of the same length to be the strings that have as their bits the OR, AND, and XOR of the corresponding bits in the two strings, respectively. We use the symbols ∨, ∧, and ⊕ to represent the bitwise OR, bitwise AND, and bitwise XOR operations, respectively. We illustrate bitwise operations on bit strings with Example 13.
Find the bitwise OR, bitwise AND, and bitwise XOR of the bit strings 01 1011 0110 and 11 0001 1101. (Here, and throughout this book, bit strings will be split into blocks of four bits to make them easier to read.)
Solution: The bitwise OR, bitwise AND, and bitwise XOR of these strings are obtained by taking the OR, AND, and XOR of the corresponding bits, respectively. This gives us
01 1011 0110
11 0001 1101
------------
11 1011 1111 bitwise OR
01 0001 0100 bitwise AND
10 1010 1011 bitwise XOR
◀