Discrete and Combinatorial Mathematics R. P. Grimaldi, 5th edition, 2004 Chapter 2 Fundamentals of Logic 1 Logic Logic = the study of correct reasoning Use of logic In mathematics: to prove theorems In computer science: to prove that programs do what they are supposed to do 2 Propositions (命題) A proposition or statement (陳述) is a declarative sentence that may be assigned a ‘true’ or ‘false’ value, but not both. This value is the truth value of the proposition. Propositions: “1+2=3”, “Peter is a programmer”, “It is snowing”. Not Propositions: “Is 1+2=3?”, “What a beautiful evening!”, “The number x is an integer”. Also Propositions: “There exists no ghost”. 3 True or False, That’s All The proposition “There exists no ghost” is on equal footing with the “1+2=3” proposition. The only thing that matters is the fact that a proposition is ‘True’ or ‘False’. Because of this, we will often label our propositions simply p,q, etc. Sometimes we use 0 for False and 1 for True. Things become interesting if we combine propositions… 4 Connectives (連接詞) If p and q are propositions, new compound propositions (複合命題) can be formed by using connectives. Most common connectives: Conjunction AND Disjunction OR Exclusive disjunction OR Negation NOT Implication Biconditional Symbol ^ (且) Symbol v (或) Symbol v (互斥或) Symbol (非) Symbol (則,蘊含) Symbol (若且唯若) The truth values of compound propositions can be described by truth tables (真值表). 5 Truth table of conjunction Truth table of conjunction: p 1 1 q 1 0 p^q 1 0 0 0 1 0 0 0 p ^ q is true only when both p and q are true. Example: p = "Tigers are animals", q = "Lions are plants" p ^ q = "Tigers are animals and Lions are plants" 6 Truth table of disjunction The truth table of disjunction: p 1 1 q 1 0 pvq 1 1 0 0 1 0 1 0 p q is false only when both p and q are false Example: p = "John is a programmer", q = "Mary is a lawyer" p v q = "John is a programmer or Mary is a lawyer" 7 Exclusive disjunction “Either p or q” (but not both), in symbols p q p 1 1 0 q 1 0 1 pvq 0 1 1 0 0 0 p q is true only when p is true and q is false, or p is false and q is true. Example: p = "John is programmer, q = "Mary is a lawyer“ p v q = "Either John is a programmer or Mary is a lawyer but not both." 8 Negation Negation of p: in symbols p p p 1 0 0 1 p is false when p is true, p is true when p is false. Example: p = "John is a programmer“ p = "It is not true that John is a programmer" 9 More compound propositions Let p, q, r be primitive propositions (簡單命題). We can form other compound propositions, such as (pq)^r p(q^r) ( p)( q) (pq)^( r) and many others… 10 Example: truth table of (pq)^r p q r (p q) ^ r 1 1 1 1 1 1 0 0 1 0 1 1 1 0 0 0 0 1 1 1 0 1 0 0 0 0 1 0 0 0 0 0 11 Implication A conditional proposition (條件命題) is of the form “p implies q”, denoted by p q, where p is the hypothesis (前提) and q is the conclusion (結論). Also “If p then q”.“p is sufficient for q”, “p is a sufficient condition (充分條件) for q”, “q is necessary for p”, “q is a necessary condition (必要 條件) for p”, “p only if q”. Example: p = " John is a programmer " q = " Mary is a lawyer " p q = “If John is a programmer then Mary is a lawyer" 12 Truth table of p q p q pq 1 1 1 1 0 0 0 1 1 0 0 1 p q is true when both p and q are true or when p is false 13 Biconditional The biconditional proposition (雙向命題) is of the form “p if and only if q” or “ p iff q ” (若且唯若), denoted by p q. p q pq 1 1 1 1 0 0 0 1 0 0 0 1 p q is true when both p q and q p are true. Example: p = " John is a programmer " q = " Mary is a lawyer " p q = “John is a programmer iff Mary is a lawyer" 14 Logical equivalence (邏輯等價) Two propositions are said to be logically equivalent () if their truth tables are identical. Example: p q p q p q pq pq 1 1 1 0 1 0 1 0 0 0 1 0 1 1 1 1 15 Biconditional vs. Equivalence Don’t confuse the equivalence with the biconditional (only the biconditional has a truth table). For example: p p is a proposition, a statement within logic, p p is mathematically correct, … about logic. p p is a False, p p is incorrect Hence pp (pp), and so on. 16 Converse The converse of p q is q p p 1 1 q 1 0 pq 1 0 qp 1 1 0 0 1 0 1 1 0 1 These two propositions are not logically equivalent 17 Contrapositive (對換句) The contrapositive of the proposition p q is q p. p 1 q 1 pq 1 qp 1 1 0 0 1 0 1 0 1 0 0 1 1 They are logically equivalent. 18 Tautology (恆真命題) A proposition is a tautology (T0) if its truth table contains only true values for every case. p q ppvq 1 1 1 1 0 1 0 1 1 0 0 1 19 Contradiction (矛盾命題) A proposition is a contradiction (F0) if its truth table contains only false values for every case. p p ^ ( p) 1 0 0 0 20 Example Pay attention to the phrase “logically”: “2 = 3–1” is not a tautology, but “2=1 or 21” is; “1+1=3” is not a contradiction, but “1=1 and 11” is. As with equivalence: look at the truth tables. 21 Proving Things in Logic The standard approach is to use truth tables. If we deal with n simple propositions p1,…,pn, our truth table will have size at least 2n. This becomes a substantial disadvantage if n is big. Sometimes there is a much more efficient way to prove equivalences. First, look at some very simple equivalences… 22 The Laws of Logic 1) 2) 3) 4) 5) Double negation law: (雙否定定律) De Morgan’s laws: (De Morgan 定律) Commutative laws: (交換律) Associative laws: (結合律) Distributive laws: (分配律) p p (pq) pq, (pq) pq pq qp and pq qp p(qr) (pq)r, p(qr) (pq)r p(qr) (pq)(pr), p(qr) (pq)(pr) 23 The Laws of Logic (Cont.) Idempotent laws: (冪等定律) 7) Identity laws: (恆等定律) 8) Inverse laws: (逆定律) 9) Domination laws: (支配律) 10) Absorption laws: (吸收律) 6) pp p, pp p pFalse p, pTrue p pp True, pp False pTrue True, pFalse False p(pq) p, p(pq) p 24 Proving Equivalences Prove (p q ) (p q) p. (p q ) (p q) (p q ) (p q) (p q ) (p q) p (q q) p F0 p [DeMorgan’s Law] [Double Negation] [Distributive Law] [Inverse Law] [Identity Law] # 25 Simplify Statements Simplify “(p q r) (p t q) (p t r)”. (p q r) (p t q) (p t r) p [(q r) (t q) (t r)] [Distributive Law] p [(q r) (t r) (t q )] [Commutative Law] p [((q t) r) (t q )] [Distributive Law] p [((q t) r) (t q )] [Double Negation] p [((q t) r) (t q )] [DeMorgan’s Law] p [(t q ) ((q t) r)] [Commutative Law] p [((t q ) (q t)) ((t q ) r)] [Distributive Law] p [F0 ((t q ) r)] [s s F0 s] p [(t q ) r] [F0 is the identity for ] 26 Simplify Statements (Cont.) p [(t q ) r] p [(t q ) r] p [(t q ) r] p [r (t q )] [DeMorgan’s Law] [Double Negation] [Commutative Law] Hence (p q r) (p t q) (p t r) p [r (t q )]. # 27 Valid arguments (有效論證) Deductive reasoning(演繹推導): the process of reaching a conclusion q from a sequence of propositions p1, p2, …, pn. The propositions p1, p2, …, pn are called premises or hypothesis. The proposition q that is logically obtained through the process is called the conclusion. 28 Rules of inference 1. Modus ponens (肯定前件式) pq p Therefore, q Example: Insects have six legs. Beetles are insects. Therefore beetles have six legs. 29 Rules of inference (Cont.) 2. Modus tollens (否定後件式) pq ~q Therefore, ~p Example: Insects have six legs. Spiders have eight legs. Therefore spiders are not insects. 30 Rules of inference (Cont.) 3. Rule of disjunctive amplification p Therefore, p q 5. Rule of conjunction p q Therefore, p ^ q 4. Rule of conjunctive simplification p^q Therefore, p 31 Rules of inference (Cont.) 6. Law of the syllogism (三段論法) pq qr Therefore, p r Example: 72 is divisible by 6. 6 is divisible by 3. Therefore 72 is divisible by 3. 32 Rules of inference (Cont.) 7. Rule of disjunctive syllogism (析取三段論法) pq p Therefore, q Example: John is studying or sleeping. John is not studying. Therefore John is sleeping. 33 Rules of inference (Cont.) 8. Rule of contradiction (矛盾證法) p F0 Therefore, p If we want to establish the validity of the argument (p1 p2 … pn) q, we can establish the validity of the logically equivalent argument (p1 p2 … pn q ) F0. 34 Example Demonstrate the validity of the argument ((p r) (p q) (q s)) (r s) (1) p r (2) r p (3) p q (4) r q (Law of the Syllogism) (5) q s (6) Therefore r s (Law of the Syllogism) 35 Example Demonstrate the validity of the argument (((p q) (r s)) (r t) (t)) p (1) r t (2) t (3) r (4) r s (5) (r s) (6) (p q) (r s) (7) (p q) (8) p q (9) Therefore p (Rule of disjunctive syllogism) (Rule of disjunctive amplification) (De Morgan’s law) (Rule of disjunctive syllogism) (De Morgan’s law) (Rule of conjunctive simplification) 36 Quantifiers (量詞) A propositional function (命題函數) or open statement P(x) is a statement involving a variable x. For example: P(x): 2x is an even integer, where x is an element of a set D. 37 Domain of a Propositional Function In the propositional function P(x): “2x is an even integer”, the domain or universe D of P(x) must be defined, for instance D = {integers}.D is the set where the x's come from. 38 For every and for some Most statements in mathematics and computer science use terms such as for every and for some. For example: For every triangle T, the sum of the angles of T is 180 degrees. For every integer n, n is less than p, for some prime number p. 39 Universal quantifier One can write P(x) for every x in a domain D In symbols: x P(x) “” is called the universal quantifier (通用量詞). The statement x P(x) is True if P(x) is true for every x D False if P(x) is not true for some x D Example: Let P(n) be the propositional function n2 + 2n is an odd integer n D = {all integers} P(n) is True only when n is an odd integer, False if n is an even integer. 40 Existential quantifier For some x D, P(x) is true if there exists an element x in the domain D for which P(x) is true. In symbols: x, P(x) “” is called the existential quantifier (存在量詞). 41 Counterexample The universal statement x P(x) is false if x D such that P(x) is false. The value x that makes P(x) false is called a counterexample to the statement x P(x). Example: P(x) = "every x is a prime number", for every integer x. But if x = 4 (an integer) this x is not a primer number. Then 4 is a counterexample to P(x) being true. 42 Generalized De Morgan’s Laws If P(x) is a propositional function, then each pair of propositions in a) and b) below have the same truth values: a) ~(x P(x)) and x: ~P(x) "It is not true that for every x, P(x) holds" is equivalent to "There exists an x for which P(x) is not true“ b) ~(x P(x)) and x: ~P(x) "It is not true that there exists an x for which P(x) is true" is equivalent to "For all x, P(x) is not true" 43 Rules of inference for quantified statements 1. Universal instantiation xD, P(x) dD Therefore P(d) 3. Existential instantiation x D, P(x) Therefore P(d) for some d D 2. Universal generalization 4. Existential generalization P(d) for some d D P(d) for any d D Therefore xD, P(x) Therefore xD, P(x) 44 Equivalences and Implications for quantified statements For a prescribed universe and any open statements P(x) and q(x) in the variable x: x [p(x) q(x)] [x p(x) x q(x)] x [p(x) q(x)] [x p(x) x q(x)] x [p(x) q(x)] [x p(x) x q(x)] [x p(x) x q(x)] x [p(x) q(x)] 45 Demonstrate Universally Quantified Statement In order to prove the universally quantified statement x P(x) is true It is not enough to show P(x) true for some x D You must show P(x) is true for every x D In order to prove the universally quantified statement x P(x) is false It is enough to exhibit some x D for which P(x) is false This x is called the counterexample to the statement x P(x) is true 46 Axioms (公設) An axiom is a proposition accepted as true without proof within the mathematical system. There are many examples of axioms in mathematics: Example: In Euclidean geometry the following are axioms Given two distinct points, there is exactly one line that contains them. Given a line and a point not on the line, there is exactly one line through the point which is parallel to the line. 47 Theorems (定理) A theorem is a proposition of the form p q which must be shown to be true by a sequence of logical steps that assume that p is true, and use definitions, axioms and previously proven theorems. 48 Lemmas and corollaries A lemma (輔助定理) is a small theorem which is used to prove a bigger theorem. A corollary (引理) is a theorem that can be proven to be a logical consequence of another theorem. Example from Euclidean geometry: "If the three sides of a triangle have equal length, then its angles also have equal measure." 49 Types of proof A proof is a logical argument that consists of a series of steps using propositions in such a way that the truth of the theorem is established. Direct proof Indirect proof 50 Direct proof Direct proof: p q A direct method of attack that assumes the truth of proposition p, axioms and proven theorems so that the truth of proposition q is obtained. Example: For all real numbers d, d1, d2, and x, if d=min{d1,d2} and xd, then xd1 and xd2. Proof. From the definition of min, it follows that dd1 and dd2. From xd and dd1, we may derive xd1 by the transitive property of . From xd and dd2, we may derive xd2 by the same property. Therefore, xd1 and xd2. # 51 Indirect proof The method of proof by contradiction of a theorem p q consists of the following steps: 1. Assume p is true and q is false 2. Show that ~p is also true. 3. Then we have that p ^ (~p) is true. 4. But this is impossible, since the statement p ^ (~p) is always false. There is a contradiction! 5. So, q cannot be false and therefore it is true. Or show that the contrapositive (~q)(~p) is true. Since (~q) (~p) is logically equivalent to p q, then the theorem is proved. 52 Example of Indirect proof For all real numbers x and y, if x+y2, then either x1 or y1. Proof. Assume that x + y 2, x < 1 and y < 1. Then it follows that x + y < 1 + 1 = 2. It contradicts to the assumption x + y 2. Thus, we conclude that x1 or y1. # 53 Brainstorm 騎士在旅途中遇見四個人,來自兩個不同家族 F1 和 F2。在這四人的談話中,如果是關於與自 己同家族所說的話,則是真話;否則是謊話。 四人A,B,C,D的對話如下: A: B屬於F1家族。 B: C屬於F1家族。 C: D屬於F2家族。 D: A屬於F2家族。 問題: 誰屬於F1家族?誰屬於F2家族? 54