* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Logic - UNM Computer Science
Meaning (philosophy of language) wikipedia , lookup
Tractatus Logico-Philosophicus wikipedia , lookup
Axiom of reducibility wikipedia , lookup
Foundations of mathematics wikipedia , lookup
Willard Van Orman Quine wikipedia , lookup
Fuzzy logic wikipedia , lookup
History of the function concept wikipedia , lookup
Analytic–synthetic distinction wikipedia , lookup
Lorenzo Peña wikipedia , lookup
Mathematical proof wikipedia , lookup
First-order logic wikipedia , lookup
Propositional formula wikipedia , lookup
Mathematical logic wikipedia , lookup
Modal logic wikipedia , lookup
Jesús Mosterín wikipedia , lookup
Interpretation (logic) wikipedia , lookup
Curry–Howard correspondence wikipedia , lookup
History of logic wikipedia , lookup
Quantum logic wikipedia , lookup
Truth-bearer wikipedia , lookup
Combinatory logic wikipedia , lookup
Propositional calculus wikipedia , lookup
Natural deduction wikipedia , lookup
Intuitionistic logic wikipedia , lookup
Laws of Form wikipedia , lookup
Principia Mathematica wikipedia , lookup
Logic Shuang (Sean) Luan Department of Computer Science University of New Mexico Albuquerque, NM 87131 E-mail: [email protected] 1 What is Logic? Definition 1 Logic is the discipline that studies the method of reasoning. The discipline of logic aims to abstract our thought process and rigorously formalize the rules of inferences. In this course, we study logic to help us form valid arguments and construct correct proofs. However, it would be a mistake to try to convert everything into logic. Instead the correct approach is to think whether the argument we make are logical. The development of proof techniques proceeds the discipline of logic. Proof techniques were developed by ancient Greek mathematicians, and can be traced to as early as the Thales Theorem by Thales, who lives 624BC - 546BC. Logic was first studied by Aristotle (384-322BC), and was formalized in the 19th century by George Boole and Augustus De Morgan, who presented the systematic mathematical treatment of logic. 2 Proposition At the center of logic is the concept of proposition. Definition 2 A proposition is a declarative sentence that is either true or false but not both. The truth value of a proposition is denoted by true (T) or false (F). Notationwise, we usually use lower case letters p, q, r, ... to represent a proposition. The following are propositions: • “The earth is round.” • “Today’s temperature is 70◦ F.” • “2+3 = 4” The following are not propositions: • “Do you speak Spanish?” • “3 − x = 5” 1 In most cases, we use proposition, statement and claim interchangeably. In other words, all of them refer to a declarative sentence that is either true or false but not both. An argument is a sentence aiming to persuade someone to accept a particular conclusion. A proof is a sequence of valid arguments that establish the truth of a proposition. An axiom or postulate is a proposition that is accepted to be true without proof. A theorem is a proposition that has been proven to be true. Theorem is usually reserved for important result. A lemma is a “baby theorem” or “helping theorem”. A corollary is a proposition that follows with little or no proof from a theorem. A scientific law is a proposition based on experimental observations. As a result, a scientific law is only applicable under certain conditions. 3 Logic Connectors If we compare logic to algebra, then propositions are the counterparts of numbers. What is the counterpart of algebraic operators such as addition, subtraction, multiplication, etc? The answer is logic connectors. Yes, we can also perform computation on propositions! How are the logic connectors defined? How is an algebraic operation defined? Observe that an algebraic operation is actually a function. Take the addition for natural numbers for example. Addition between two natural numbers is actually a function from the Cartesian product N × N to N, where the ordered pair (a, b) is mapped to a + b by the addition function. To describe the addition function, one could certainly build a table that describes all possible input and output to the addition function. From our experiences with cardinality, we know that this will be an infinite table with countably number of entries. Input (1, 1) (1, 2) (2, 1) (1, 3) (2, 2) (3, 1) ··· Output 2 3 3 4 4 4 ··· From the above discussion, a logic operator can also be defined just like the addition. It will be a function that can operate on one or more propositions. When defining a logic operator, we can use a table that specifies the outcome of the operation for each possible input values. Such a table that defines a logic operator is called a truth table. However, since proposition only has two possible values, i.e., T (true) or F (false), the truth table for logic connectors are usually not very big. 3.1 Negation Definition 3 The negation of a proposition p is “not p”, and is denoted by ¬p. The truth table for negation is: p T F ¬p F T 2 3.2 Conjunction Definition 4 The conjunction of two propositions p and q is “p and q”, and is denoted by p ∧ p. The truth table for conjunction is: p T T F F 3.3 q T F T F p∧q T F F F Disjunction Definition 5 The disjunction of two propositions p and q is “p or q”, and is denoted by p ∨ q. The truth table for disjunction is: p T T F F 3.4 q T F T F p∨q T T T F Exclusive Or Definition 6 The exclusive or of two propositions p and q is “p or q but not both”, and is denoted by p ⊕ p. The truth table for exclusive or is: p T T F F q T F T F p⊕q F T T F Example 1 Calculate the truth table of the following logic expression: (p ∧ (¬q)) ∨ (q ∧ (¬p)). Solution: p T T F F q T F T F ¬p F F T T ¬q F T F T p ∧ ¬q F T F F q ∧ ¬p F F T F (p ∧ (¬q)) ∨ (q ∧ (¬p)) F T T F 2 Observe that p⊕q and (p ∧ (¬q))∨(q ∧ (¬p)) have the same logical values, thus they are essentially the same logical functions. Note that this actually makes sense. In order to have (p ∧ (¬q))∨(q ∧ (¬p)) evaluate to T, either p ∧ ¬q or q ∧ ¬p is true. In either situation, p and q are going to have different logical values, which is exactly the definition of exclusive or. Definition 7 Two logic expressions are said to be logically equivalent if they have the same truth table. 3 3.5 Implication Definition 8 The implication of two propositions p and q is “if p then q”, and is denoted by p → q. In an implication, the proposition p is called the premise and the proposition q is called the conclusion. The truth table for implication is: p T T F F q T F T F p→q T F T T One confusing aspect of p → q is when p is false, the implication is always true. What does this mean? This means that if you start out with a premise or an assumption that is wrong, then you may end up with anything. For example, the statement “if you are Shaq O’Neil, then I am Michael Jordan” is in fact a logically correct statement. Note that in this case, p =“You are Shaq O’Neil” and q =“I am Michael Jordan”. Since you are not Shaq O’Neil, p = F . From the truth table, the implication is always true. The implication is one of the more difficult logic connectors. Other ways for expressing p → q in English are: • “p implies q.” • “p is sufficient for q.” • “q unless ¬p.” • “p only if q.” • “A necessary condition for p is q.” The best ways to appreciate this is by some real world examples. For example, consider the following situations. p =“Your cumulative is over 90%”, and q =“You will get a final letter grade of A”. Consider the following arguments: • “If your cumulative is over 90%, then you will get a final letter grade A.” • “Your cumulative is 90% implies you will get a final letter grade A.” • “A cumulative of 90% is sufficient for a final letter grade A.” • “Your final letter grade is A unless your cumulative is not over 90%”. Comment: this is to say that the only way your final grade is not A is that you didn’t get a cumulative of over 90%. • “A cumulative of over 90% only if you get a final letter grade A.” Comment: this is to say that if your final letter grade is not A, then your cumulative is not over 90%. • “A necessary condition for a cumulative of over 90% is a final letter grade of A.” Comment: this is to say that a final letter grade of other than “A” is sufficient that your cumulative is less than 90%”. 4 Example 2 Calculate the truth table of q ∨ (¬p). Solution: p T T F F q T F T F ¬p F F T T q ∨ (¬p) T F T T Observe that q ∨ (¬p) is logically equivalent to p → q. This can also serves an explanation of “q unless ¬p”, because the only way for q ∨ ¬p to be false is when q if false and p is true. 2 Definition 9 The contrapositive of p → q is (¬q) → (¬p). Example 3 Calculate the truth table of (¬q) → (¬p). Solution: p T T F F q T F T F ¬q F T F T ¬p F F T T (¬q) → (¬p) T F T T Observe that (¬q) → (¬p) is logically equivalent to p → q. In other words the contrapositive of an implication is logically equivalent to the implication. 2 Definition 10 The converse of p → q is q → p. Example 4 Calculate the truth table of q → p. Solution: p T T F F q T F T F q→p T T F T Observe that q → p is not logically equivalent to p → q. This makes sense. Recall the example p =“a cumulative of ≥ 90%”, and q =“a final letter grade of A”. The implication p → q is “if your cumulative is ≥ 90%, then your final letter grade is A”. The converse of this is “If your final letter grade is A, then your cumulative is ≥ 90%”, which is obviously not true, because the professor may curve and even if your cumulative is not ≥ 90%, your final letter grade may still be A. 2 Definition 11 The inverse of p → q is (¬p) → (¬q). Example 5 Calculate the truth table of (¬q) → (¬p). 5 Solution: p T T F F q T F T F ¬p F F T T ¬q F T F T (¬p) → (¬q) T T F T Observe that (¬p) → (¬q) is not logically equivalent to p → q, but is logically equivalent to the converse, i.e., q → p. Recall the example p =“a cumulative of ≥ 90%”, and q =“a final letter grade of A”. The implication p → q is “if your cumulative is ≥ 90%, then your final letter grade is A”. The inverse of this is “If your cumulative is < 90%, then your final letter grade is not A”, which is obviously not true, because the professor may curve and even if your cumulative is not ≥ 90%, your final letter grade may still be A. 2 3.6 Biconditional Definition 12 The biconditional statement of two propositions p and q is “p if and only if q”, and is denoted by p ↔ q. The truth table of biconditional is: p T T F F q T F T F p↔q T F F T Example 6 Calculate the truth table of (p → q) ∧ (q → p). Solution: p T T F F q T F T F p→q T F T T q→p T T F T (p → q) ∧ (q → p) T F F T (p → q) ∧ (q → p) is logically equivalent to the biconditional statement p ↔ q. 3.7 2 Precedence of Logic Connectors Similar to the algebraic operations, the logic connectors also have precedence or order of operations. The precedence follows the order ¬, ∧, ∨, →, ↔. Example 7 ¬p ∨ q → r ∧ s ↔ t should be evaluated as (((¬p) ∨ q) → (r ∧ s)) ↔ t 4 Propositional Equivalence Using the logic connectors, we can form compound propositions. In this section, we present some special compound propositions and discuss propositional equivalence. 6 4.1 Tautology, Contradiction, and Contingency Definition 13 A compound proposition that is true for all possible values of its propositional variables is called a tautology. Example 8 Determine if p ∧ (p → q) → q is a tautology. Solution: p T T F F q T F T F p→q T F T T p ∧ (p → q) T F F F p ∧ (p → q) → q T T T T Since its values is T for all possible values of p and q, p ∧ (p → q) → q is a tautology. 2 Definition 14 A compound proposition that is false for all possible values of its propositional variables is called a contradiction. Example 9 Determine if p ∧ ¬p is a contradiction. Solution: p T F ¬q F T p ∧ ¬p F F Since its values is F for all possible values of p, p ∧ ¬p is a contradiction. 2 Definition 15 A compound proposition that can be either true or false is called a contingency. 4.2 Logic Equivalence Definition 16 Two compound propositions p and q are called logically equivalent if p ↔ q is a tautology, and is denoted by p ≡ q. Example 10 Determine if the two propositions p and ¬p → F are logically equivalent. Solution: p T F ¬p F T ¬p → F T F p ↔ ¬p → F T T Thus, p ≡ ¬p → F 2 Observe that Example 10 is a way of explaining proof by contradiction. Suppose we want to show a statement p is true. We will assume p is wrong, i.e., ¬p and show that this assumption will lead to a contradiction. Example 11 Determine if the two propositions p → q and (¬q ∧ p) → F are logically equivalent. 7 Solution: p T T F F q T F T F p→q T F T T ¬q F T F T ¬q ∧ p F T F F (¬q ∧ p) → F T F T T p → q ↔ (¬q ∧ p) → F T T T T Since p → q ↔ (¬q ∧ p) → F is a tautology, the two statement are logically equivalent, i.e., p → q ≡ (¬q ∧ p) → F 2 Example 11 is another way to explain the principle behind proof by contradiction. Recall the framework for proof by contradiction. To prove a statement in the form p → q, we will start by assuming the conclusion q is wrong, i.e., ¬q is correct. We will show that this, i.e., ¬q together with the original premise p will lead to a contradiction. Expressed logically, this is exactly (p ∧ ¬q) → F . Example 12 (DeMorgan’s Law) Show that the following are logically equivalent: (a) ¬(p ∧ q) and ¬p ∨ ¬q (b) ¬(p ∨ q) and ¬p ∧ ¬q Proof: p T T F F q T F T F ¬p F F T T ¬q F T F T p ∧ q) T F F F ¬(p ∧ q) F T T T ¬p ∨ ¬q F T T T ¬(p ∧ q) ↔ ¬p ∨ ¬q T T T T Since ¬(p ∧ q) ↔ ¬p ∨ ¬q is a tautology, ¬(p ∧ q) ≡ ¬p ∨ ¬q. Similarly, we can show that ¬(p ∨ q) ≡ ¬p ∧ ¬q. 4.3 2 Common Logic Equivalence There are many logic equivalences. The Table below shows some of the most important ones. Identity Laws Domination Laws Idempotent Laws Double Negation Law Commutative Laws Associative Laws Distributive Laws Absorption Laws Negation Laws p ∧ T ≡ p, p ∨ F ≡ p p ∨ T ≡ T, p ∧ F ≡ F p ∨ p ≡ p, p ∧ p ≡ p ¬¬p ≡ p p ∧ q ≡ q ∧ p, p ∨ q ≡ q ∨ p. (p ∧ q) ∧ r ≡ p ∧ (q ∧ r), (p ∨ q) ∨ r ≡ p ∨ (q ∨ r). p ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r), p ∨ (q ∧ r) ≡ (p ∨ q) ∧ (p ∨ r). p ∨ (p ∧ q) ≡ p, p ∧ (p ∨ q) ≡ p p ∨ ¬p ≡ T , p ∧ ¬p ≡ F . The Table below shows some important logic equivalence involving implications. The right column shows the laws used to derive the logic equivalence in the left column. 8 p → q ≡ ¬p ∨ q p → q ≡ ¬q → ¬p p ∨ q ≡ ¬p → q p ∧ q ≡ ¬(p → ¬q) ¬(p → q) ≡ p ∧ ¬q (p → q) ∧ (p → r) ≡ p → (q ∧ r) (p → r) ∧ (q → r) ≡ (p ∨ q) → r (p → q) ∨ (p → r) ≡ p → (q ∨ r) (p → r) ∨ (q → r) ≡ (p ∧ q) → r Truth Table Contrapositive Double Negation Law DeMorgan’s Law DeMorgan’s Law Distributive Law Distributive Law Distributive Law Distributive Law The Table below shows some important logic equivalence involving biconditional. The right column shows the laws used to derive the logic equivalence in the left column. p ↔ q ≡ (p → q) ∧ (q → p) p ↔ q ≡ ¬p ↔ ¬q p ↔ q ≡ (p ∧ q) ∨ (¬p ∧ ¬q) ¬(p ↔ q) ≡ p ↔ ¬q 5 Truth Truth Truth Truth Table Table Table Table Logic and Digital Circuit One may not realize that the logic we have learnt so far is enough for us to design a digital computer. To demonstrate this, we will show the design of a full adder. 5.1 1 Bit Adder Digital computers use binary representation of numbers. Let’s consider a 1 bit full adder. Figure 1 shows the function of a 1-bit adder. A 1-bit adder is capable of adding two binary bits input a and b and calculate their sum s and carry c. Since the input and output are bits, i.e., 0 and 1, we can also view them as logic variables with F = 0 and T = 1. Thus the function of a 1-bit adder: a 0 0 1 1 b 0 1 0 1 s 0 1 1 0 c 0 0 0 1 can be viewed as a truth table describing s and c: a F F T T b F T F T s F T T F c F F F T Observe that logically, s = a ⊕ b and c = a ∧ b. 9 Figure 1: Illustrating the function of a 1-bit adder. Figure 2: The symbols of some common logic gates. 5.2 Logic Gates Logic gates are essentially symbols for representing logical connectors. In the next section we will show the connection between logic gates and physical devices. Figure 2 shows the symbols of the 3 most fundamental logic gates, the NOT gate, the AND gate, and the OR gate, since all the logic connectors can be represented by combining these three type of logic gates. For example, a⊕b = (a∧¬b)∨(¬a∧b). Figure 3 shows how a 1-bit adder can be realized using logic gates. Most logic design uses NAND gate (see Figure 4) because it is a universal gate and can be used to implement any other logic gates. To see this observe that: • ¬p = ¬p ∧ p • p ∧ q = ¬ (¬ (p ∧ q)) = ¬ (¬ (p ∧ q) ∧ ¬ (p ∧ q)) • p ∨ q = ¬ (¬p ∧ ¬q) = ¬ (¬ (p ∧ p) ∧ ¬ (q ∧ q)) We can implement the 1-bit adder using NAND gate logic. Observe that, a⊕b = (a∧¬b)∨(¬a∧b) = ¬¬(a ∧ ¬b) ∨ (¬a ∧ b) = ¬ (¬(a ∧ ¬b) ∨ ¬(¬a ∧ b)). Further a ∧ ¬(a ∧ b) = a ∧ (¬a ∨ ¬b) = (a ∧ ¬a) ∨ (a ∧ ¬b) = a ∧ ¬b. Thus a ⊕ b = ¬ (¬(a ∧ ¬b) ∨ ¬(¬a ∧ b)) = ¬ (¬(a ∧ ¬(a ∧ b)) ∨ ¬(¬(a ∧ b) ∧ b)) Figure 5 shows the implementation of a 1-bit adder using NAND gates. Observe that compared to 10 Figure 3: The symbols of some common logic gates. Figure 4: The symbols for NAND gate. the implementation in Figure 3, the NAND gate implementation is actually more efficient because it uses 5 logic gates instead of 6. 5.3 1-bit Full Adder and Ripple Adder A goal for designing a 1-bit adder is to use it as a building block for a multiple-bit full adder. In order to do that, we need a 1-bit full adder, which is also capable of handling carry in and carry out. From this regards, the 1-bit adder that we presented in the previous sections is usually referred to as a half adder. Figure 6 shows a 1-bit full adder. It function is described in the truth table: Like the 1-bit half adder, the 1-bit full adder can also be implemented using NAND gate logic. We will not go into the details here. a 0 0 0 0 1 1 1 1 b 0 0 1 1 0 0 1 1 cin 0 1 0 1 0 1 0 1 s 0 1 1 0 1 0 0 1 cout 0 0 0 1 0 1 1 1 With the 1-bit full adder, one can built an adder for arbitrary number of bits. The easiest way to Figure 5: The NAND gate implementation of a 1-bit adder. 11 Figure 6: Illustrating the function of a 1-bit full adder. Figure 7: Illustrating a ripple adder. realize this is to connect a lot of 1-bit full adders sequentially, connect the carry out of a less significant bit to the carry in to the adder for a more significant bit. Figure 7 shows the schematic overview of a ripple adder. 5.4 Transistor Interested readers may wonder how the logic gates implementation can be translated to actual physical circuits. In this section, we will show how a NAND gate can be implemented using transistors. The underlying principle also extends to the more modern CMOS technology. A transistor is a semiconductor device invented in 1947 by William Shockley, John Bardeen, and Walter Brattain at AT&T’s Bell Labs, who later shared the 1956 Nobel Prize in Physics “for their researches on semiconductors and their discovery of the transistor effect”. Generally speaking a transistor has 3 terminals, referred to as base, collector, and emitter (see Figure 8 for illustrations). An important property of a transistor is that the base can act as a switch. When the voltage on base is high, the switch is open and current can flow from collector to the emitter. When the voltage on base is low or close to 0, the switch is turned off and no current can flow from the collector to the emitter. Using the transistor as a switch, we can build NAND gate. Figure 9 shows the implementation of a NAND gate using transistor to transistor logic (TTL). The input of the NAND gate is a and b. The 12 Figure 8: Illustrating a ripple adder. Figure 9: Illustrating a ripple adder. output is c. To understand how this NAND gate work, we first remark that physically, we use a high voltage to represent a logic 1 or T, and a low voltage to represent a logic 0 or F. Observe that when a and b are both 1, i.e., high voltage, then both switches are turned on, essentially making c grounded, i.e., 0. If either a and b are 0, i.e., a low voltage, then there is no current flowing from the VCC to the ground. This keeps c at high voltage, i.e. 1. With the NAND implemented physically, it is not hard to imagine that we can build an entire computer. However, all of these starts out with the logic operations that we have discussed so far. 6 Propositional Functions and Logic Quantifiers Definition 17 A predicate is a function such that when applied to the individual becomes a proposition. Predicates are also referred to as propositional functions. Example 13 P (x) : x ≥ 3 is a predicate. It becomes a proposition when applied to individual values of x. For example, P (4) is “4 ≥ 3”, which is a proposition with logic value T. We can also make predicates a proposition using universal and existential quantifiers. Definition 18 The universal quantification of a predicate P (x) is the proposition: “for every x, P (x) is true”, and is denoted by ∀xP (x). Definition 19 The existential quantification of a predicate P (x) is the proposition: “there exists an x, P (x) is true”, and is denoted by ∃xP (x). Example 14 Let P (x) : x ≥ 3, then: 13 • ∀P (x) is “for all x, x ≥ 3”. ∀P (x) is false. • ∃P (x) is “there exists x, x ≥ 3”. ∃P (x) is true. Propositions involving predicates and quantifiers are logically equivalent if and only if they have the same truth value no matter which predicates are substituted into these statements and which domain of discourse is used for the variables in these propositional functions. Theorem 1 ∀xP (x) ≡ ¬(∃xP (x)) and ∃xP (x) ≡ ¬(∀xP (x)). 7 Rules of Inference We study logic to help us construct arguments. Proofs are essentially valid arguments that establish the truth of a mathematical proposition. In this section we present the rules of inference for constructing valid arguments. 7.1 Argument Definition 20 An argument is a sequence of statements that end with a conclusion. All proceeding statements before the conclusion are called premises. An argument is valid if it is impossible for all the premises to be true and the conclusion is false. Example 15 The following argument is valid: “If you pass discrete math, you can take algorithms.” “You have passed discrete math.” “You can take algorithms.” Observe that if we let p = “you pass discrete math”, q = “you can take algorithms”, then the argument is essentially (p → q) ∧ p → q. In fact all arguments are essentially implications. The conjunction of the premises of the argument forms the premise of the implication. The conclusion forms the conclusion of the implication. In other words, consider an argument with statements p1 , p2 , ..., pn , q. Expressing the argument logically, the argument is the implication p1 ∧ p2 ∧ ... ∧ pn → q. Recall that if the argument is valid, it is impossible for the conclusion r to be false when all the premises p1 , p2 , ...pn are true. On the other hand, observe that for the implication, p1 ∧ p2 ∧ ... ∧ pn → q if any of the p1 , p2 , ...pn is false, their conjunction p1 ∧ p2 ∧ ... ∧ pn is false, resulting the implication to be true. Thus, the implication correspond to a valid argument is in fact a tautology because the implication will always evaluate to true. This is actually one way for verifying if an argument is valid. 7.2 Logical Form The logical form of an English sentence or collection of sentences is the abstraction in logic expressions. The logic expression (p → q) ∧ p → q is the logic form of the sentences from Example 15. The logic form is important because it allows us to analyze the statements from a pure logic perspective. Example 16 Construct the logic form of the following sentences: 14 If the professor travels to a conference, then the lecture will be replaced with an exam. The discrete math lecture is replaced with an exam. Therefore the professor is traveling to a conference. Solution: Let p = “the professor travels to a conference”, and q = “lecture is replaced with an exam”. Then the logic form is (p → q) ∧ q → p. 2 Observe that since discrete math has midterm and final exams. Even if the professor is not traveling, some lectures will be replaced with the exams. Thus the argument is obviously false. What’s interesting here is that the proposition (p → q) ∧ q → p is not a tautology, therefore the argument is not valid. Thus even if we have no idea what the proposition is about, if we have its correct logic abstraction, then we can analyze whether the argument is valid or not. 7.3 Argument Form An argument form is the logic abstraction of an argument. Because of the particular structure of an argument, which consists of a list of premises and followed by a conclusion, we will write the argument form in a manner, where all the proposition involved are listed in a column, whose last entry is the conclusion. To distinguish conclusion from the premises, we include ∴ in front of the conclusion. The general argument form is the following: ∴ p1 p2 ... pn q For Example 16, its argument form is: ∴ p→q q p In most situations, it is rather straightforward to obtain the logic form of an argument. The things can be a little bit tricky when quantifiers are involves. Example 17 Construct the logic form of the following sentences: All whales are mammals. Mammals are warm blooded. Therefore all whales are warm blooded. Solution: Let P (x) : “x is a whale.”, and Q(x) : “x is a mammal”. Then the first sentence “All whales are mammals” is ∀x(P (x) → Q(x)). Similarly, let R(x) : “x is warm blooded”. Then the second sentence is ∀x(Q(x) → R(x)). The third sentence is ∀x(P (x) → R(x)). The argument form is: 15 ∴ ∀x(P (x) → Q(x)) ∀x(Q(x) → R(x)) ∀x(P (x) → R(x)) 2 Example 18 Construct the logic form of the following argument: All computer science students are good at math. I am not good at math. Therefore I am not a computer science student. Solution: Let P (x) : “x is computer science student.”, and Q(x) : “x is good at math”. Then the first sentence “All computer science students are smart” is ∀x(P (x) → Q(x)). So, what is the logic abstraction of “I am not good at math”? Observe that this is essentially saying that when applying the function Q to me, the result is a F, i.e., ¬Q(I). Similarly, the conclusion “I am not a computer science student” is ¬P (I). The argument form is: ∴ ∀x(P (x) → Q(x)) ¬Q(I). ¬P (I). 2 7.4 Rules of Inference From the previous discussion, it is clear that we can determine if an argument is valid by examining its argument form. If the argument form is a tautology, then the argument is valid. It is worthwhile noting that a valid argument doesn’t necessarily imply the argument is correct. For example, in Example 18, the argument is valid. However, the argument is not correct because the assumption that “all computer science students are good at math” is not correct. Even though it is possible to determine if an argument form is valid by writing out its truth tables, this can be cumbersome for argument with a lot of premises. In such situations, it is very helpful to come up with a set of “short cuts” that can help us simplify the argument. These shortcuts are in fact “building blocks” for constructing a valid argument and are called Rules of Inferences. The Table below shows some of the most well-known rules of inference: 16 Name Tautology Modus Ponens p ∧ (p → q) → q Modus Tollens ¬q ∧ (p → q) → ¬p Hypothetical Syllogism (p → q) ∧ (q → r) → (p → r) Disjunctive Syllogism (p ∨ q) ∧ ¬p → q Addition p→p∨q Simplification p∧q →p Conjunction p∧q →p∧q Resolution (p ∨ q) ∧ (¬p ∨ r) → (q ∨ r) Argument Form p p→q ∴ q ¬q p→q ∴ ¬p p→q q→r ∴ p→r p∨q ¬p ∴ q p ∴ p∨q p∧q ∴ p p q ∴ p∧q p∨q ¬p ∨ r ∴ q∨r Example 19 Determine if the following argument form is valid: ∴ ¬p ∧ q r→p ¬r → s s→t t Solution: ∴ ¬p ∧ q ¬p r→p ¬r ¬r → s s s→t t Simplification Modus Tollens Modus Ponens Modus Ponens 2 Example 20 Determine if the following argument form is valid: 17 ∴ p→q ¬p → r r→s ¬q → s Solution: ∴ p→q ¬q → ¬p ¬p → r ¬q → r r→s ¬q → s Logic Equivalence Hypothetical Syllogism Hypothetical Syllogism 2 Example 21 Determine if the following argument form is valid: ∴ (p ∧ q) ∨ r r→s p∨s Solution: ∴ (p ∧ q) ∨ r ¬(p ∧ q) → r r→s ¬(p ∧ q) → s (p ∧ q) ∨ s (p ∨ s) ∧ (q ∨ s) p∨s Logic Equivalence Hypothetical Syllogism Logic Equivalence Logic Equivalence Simplification 2 7.5 Rules of Inference for Quantifiers The table below shows some useful rules of inference for quantifiers. 18 Name Universal Instantiation Universal Generalization Existential Instantiation Existential Generalization Argument Form ∴ ∀xP (x) P (c), c is a particular member of the domain of P . ∴ P (c) for arbitrary c in the domain of P ∀xP (x) ∴ ∃xP (x) P (c), c is a particular member of the domain of P . ∴ P (c), c is a particular member of the domain of P . ∃xP (x) Example 22 Determine if the following argument is valid: All computer science students are smart. Sean is a computer science student. Therefore Sean is smart. Solution: Let P (x) : “x is computer science student.”, and Q(x) : “x is smart”. Then the first sentence “All computer science students are smart” is ∀xP (x) → Q(x). The second sentence “Sean is a computer science student” is P (sean). The third sentence “Sean is smart” is Q(Sean). The argument form is: ∴ ∀x(P (x) → Q(x)) P (Sean). Q(Sean). This is a valid argument. ∴ ∀x(P (x) → Q(x)) P (Sean) → Q(Sean) P (Sean) Q(Sean). Universal Instantiation Modus Ponens 2 8 Logic and Proof We study logic to help us construct valid proofs. In this section, we will show a few examples illustrating how logic can be used to construct proofs. However, as the readers will soon find out, writing mathematical proofs in logic can result in lengthy arguments, and not practical. As we have mentioned 19 before, when proving a mathematical problem, we should use the knowledge gained in this section and think whether our argument is logical rather than trying to convert everything to logic. 8.1 Direct Proof Example 23 Prove if n is odd, then n2 is odd. Proof: Let P (n) = “n is odd”, and Q(n) = “n2 is odd”. Then the theorem is the proposition ∀n(P (n) → Q(n)). Our strategy is to prove that for arbitrary c, P (c) → Q(c). Then we use universal generalization: ∴ P (c) → Q(c) for arbitrary c ∀n(P (n) → Q(n)) to conclude that ∀n(P (n) → Q(n)) is true. P (c) = “c is odd.” For any x, if x is odd, then x = 2k + 1 for some integer k. If c is odd, then c = 2k + 1 for some integer k. c = 2k + 1 2 2 2 2 c = (2k + 1) = 4k + 4k + 1 = 2(2k + 2k) + 1 For any x, if x = 2m + 1 for some integer m, then x is odd. If c2 = 2m + 1 for some integer m, then n2 is odd. Q(c) = “c2 is odd.” Premise Definition Universal Instantiation Modus Ponens Premise/Algebra Definition Universal Instantiation Modus Ponens Thus P (c) → Q(c) is true for arbitrary c. Now from universal generalization, we can conclude that ∀n(P (n) → Q(n)). 2 8.2 Proof by Contrapositive Example 24 If 3n + 2 is odd, then n is odd. Proof: Let P (n) = “3n + 2 is odd” and Q(n) = “n is odd”. Then we are trying to prove ∀n(P (n) → Q(n)). We will use the same strategy and show that P (c) → Q(c) for arbitrary c, and use universal generalization to conclude that ∀n(P (n) → Q(n)) is true. However instead of using direct proof to show that P (c) → Q(c), we will prove its equivalent contrapositive, i.e., ¬Q(c) → ¬P (c) ¬Q(c) = “c is even” for some arbitrary c. For any x, if x is even, then x = 2k for some integer k. If c is even, then c = 2k for some integer k. c = 2k. 3c + 2 = 3 · (2k) + 2 = 6k + 2 = 2(3k + 1) For any x, if x = 2m for some integer m, then x is even. If 3c + 2 = 2m for some integer m, then 3c + 2 is even. ¬P = “3c + 2 is even.” Premise Definition Universal Instantiation Modus Ponens Premise/Algebra Definition Universal Instantiation Modus Ponens Thus we know that ¬Q(c) → ¬P (c) for arbitrary c, which is equivalent to P (c) → Q(c). Using universal generalization, we can conclude ∀n(P (n) → Q(n)). 20 2 8.3 Proof by Counter Example Example 25 Show that the proposition “the square of any odd number is even” is wrong. Proof: Let P (n) = “n is odd” and Q(n) = “n2 is even”. Then we are trying to show that the argument ∀n(P (n) → Q(n)) is false. In other words, we are trying to prove that ¬∀n(P (n) → Q(n)). This is logically equivalent to ∃n¬(P (n) → Q(n)). In other words, if we can find a particular n such that P (n) → Q(n) is wrong, then we are done. This is what we called a counter example. In particular consider n = 3, then n= 9 is not even. 2 8.4 Proof by Contradiction Example 26 √ 2 is irrational. √ Proof: Let p = “ 2 is irrational”. We will use proof by contradiction. Recall that the tautology for √ proof by contradiction is ¬p → F . We will show that ¬p = “ 2 is rational” will lead to a contradiction. √ 2 is rational. √If x is irrational, then√x = for relative prime integers a and b. 2 is irrational, then√ 2 = for relative prime integers a and b. 2 = ab for relatively prime integers a and b. a and b are relatively prime. a2 = 2b2 If x = 2k for some integer k, then x is even. If a2 iseven, then a is even. a2 is even 2 If x is even, then x is even. If a2 is even, then a is even. a is even If x is even, then x = 2k for some integer k. If a is even, then a = 2k for some integer k a = 2k for some integer k a2 = 4k 2 2 2 b2 = a2 = 4k2 = 2k 2 b is even “a and b are relative prime” and “a, b are both even”. a b a b Premise Premise/Definition Universal Instantiation Modus Ponens Simplification Premise/Algebra Definition Universal Instantiation Modus Ponens Theorem Universal Instantiation. Modus Ponens Definition Universal Instantiation Modus Ponens Algebra Algebra Similar to a is even. Conjunction To complete the proof, we need to invoke the following arguments. ¬p → F ¬¬p ∧ F ¬F ¬¬p Premise Logic Equivalence Premise Premise Disjunctive Syllogism 2 21 8.5 Proof by Induction Let the domain D = {n0 , n0 + 1, ...}. Let P (n) = be a predicate with variable n. Then the induction theorem says ∀nP (n) ≡ P (n0 ) ∧ (∀(P (n) → P (n + 1))). To put this in plain English, to show that P (n) is true for all integers n ≥ n0 , we only need to show that “P (n0 ) is true” and “for all n, if P (n) is true then O(n + 1) is true”. The first part “P (n0 ) is true” is called the basis of induction. The second part “for all n, if P (n) is true then P (n + 1) is true” is called the induction step, where the premise “P (n) is true” is called the induction hypothesis. To prove the induction step, we need to use show that “for arbitrary k, if P (k) is true then P (k + 1) s true”. Then use universal generalization to claim the correctness of the induction step. The strong induction theorem says ∀nP (n) ≡ P (n0 ) ∧ (∀P (n0 ) ∧ P (n0 + 1) ∧ ... ∧ P (k)) → P (k + 1)). The difference between strong induction and weak induction is the premise of the induction step. In the strong induction theorem, the premise is P (n0 ) ∧ P (n0 + 1) ∧ ... ∧ P (k). 22