You are on page 1of 289
Gersting Mathematical Structures for Computer Science Page 3 CHAPTER 1: Formal Logic Chapter 1 is an introduction to formal logic and some of its implications for computer science, Formal logic is nothing more than a systematization of much of what we do daily when we communicate in natural language and when we draw conclusions using informal reasoning. It is certainly the basis for scientific thinking and reasoning, Because of its formalization, many students seem to find logic a difficult topic. ‘You can point out to the students, however, that this very formality actually relieves them of the burden of undirected creative thinking! There are certain patterns and rules that must be followed in constructing formal proofs, which serve to channel and limit the possible steps to be taken at any time, Students face similar constraints in following the rules of syntax of a programming language; in fact, they are so much more constrained in formal logic that their task is even simpler than in programming. Pointing this out to the students (who have usually experienced some success in programming tasks by this time) can serve as a morale-builder. Or you can also note the similarities to standard high school geometry, but you are on less firm ground here because some students hated their high school geometry class! At any rate, they need some reassurance that symbolism itself is not all that formidable and, by its constraining nature, is actually helpful. I usually point out that one of the purposes of symbolism is to strip away meaning in order to concentrate on form alone, and thus help ensure that we are "pure in heart" in our thinking processes. Students find this a bemusing idea, but they generally see the point. Of course, natural language statements must first be translated into symbolic form, and it is this part of the chapter that is most fun to teach. It points up how sloppy we tend to be in our natural language statements. (See "John loves only Mary," “John only loves Mary," and "Only John loves Mary" in Section 1.3.) One would think that students for whom English is a second language would have more difficulties than native English speakers with this type of translation exercise, but that doesn't seem to be the case - they all have to work at this, but they also enjoy it. Students often come back later and tell me that after this course, they never take words and sentences at face value again! Propositional logic is covered is Sections 1.1 and 1.2, while predicate logic is discussed in Sections 1.3 and 1.4. Sections 1.5 and 1.6 give some direct applications of formal systems to computer science; Section 1.5 is a brief introduction to logic programming and Section 1.6 introduces proof of correctness. The discrete structures course is too often seen as a collection of disjointed topics, so it behooves us as instructors to emphasize the connecting threads whenever possible. The notations of formal logic will be used throughout the book to clarify definitions. Logical reasoning, although not always formal, is the basis for much of the rest of the work in this course and will also stand the students in good stead in many other computer science courses, Page ¢ Mathematical Structures for Computer Science Gersting Answers that are starred also appear at the back of the textbook. EXERCISES 1.1 41, 2. 3. “4, @ © © O aTbT «TdF aTbF oF dF eTfiF g Tht a. antecedent: — sufficient water consequent: healthy plant growth b. antecedent: further technological advances consequent: increased availability of information c. antecedent: — errors will be introduced consequent: there is a modification of the program d. antecedent: fuel savings consequent: good insulation or storm windows throughout a land3 b2 64 *a. The food is good but the service is poor. *b. The food is poor and so is the service. c. Either the food is poor or the service is poor, but the price is low. d. Either the food is good or the service is excellent. The price is high but either the food is poor or the service is poor. 2 Either the processor is slow or the printer is fast. The processor is slow and the printer is fast. The processor is fast but so is the printer. |. Either the processor is slow or the printer is fast, but the file is not damaged The file is not damaged, the processor is fast, and the printer is not slow. The printer is slow and the file is not damaged. meaoge AaB AABVO) B>(AAC) A>@'vC) AIC > B'vO)] eaooe BaD AaD D>@vo Bad D>Cc esaore Gersting Mathematical Structures for Computer Science Page 5 10. UL a. Violets are blue or sugar is sour. Violets are not blue or, if roses are red, then sugar is sweet. Sugar is sweet and roses are not red, if and only if violets are blue. Sugar is sweet, and roses are not red if and only if violets are blue. If it is false that both violets are blue and sugar is sour, then roses are red. Roses are red, or violets are blue and sugar is sour. Roses are red or violets are blue, and sugar is sour. Rmeaos .a. A: prices go up; B: housing will be plentiful; C: housing will be expensive [A>BAC]A(C >B) b. A: going to bed; B: going swimming; C: changing clothes [(AvB) > C]A(C>By c. A: itwill rain; B: it will snow (AVB)A(AABY d. A: Janet wins; B: Janet loses; C: Janet will be tired (AvB)>C . A: Janet wins; B: Janet loses, C: Janet will be tired Av(@®>C) H: horse is fresh; K: knight will win; A: armor is strong a HK b. K +(HAA) c KH d KoA e. (AVH)>K a AST b. T> (AaB) c. E>T d ASE e. Eo (AvT) Tautology Mathematical structures for Computer Science Gerating page 6 Babee ee (Av C)> (By) BREE ERE gq >| a ¢ q 4 9g >| al <| g q z 9g 5 a 5 a |e tas sae te a (hh e hmmm Nepean s g 9 g >| >| < ARR Ree 2 x| 3 g rm me gQ@eee Jere q ARR Rh ey <| ge <| k <| 5| Bl meee 4 QR RR eee 4] a eI | a <| Bie RR mmm hrm +——— ty < 4 qeeee deb me 4 Jeereeeee Q=RPR Yeeee YREREPERE, @ QeeREeEee geeee Meee AER REE Ss a 4ERPRRR Ree QeRPee gdeeae PREP REE Eg | Of ee ARee eee ee BRE HR BRR Re BRR Ree ey yy By vClAv(BvC)| (AvB)vCe Av(BvC) v Hee ey BRE RHR fa fo fa fy te a ef Fe Be Fy BRB REE be fe fy fy bee eee ee Hee meee BI C\AvBI(Av BERR Ree BICIAABI(AAB)ACIBACIAA (BAC) (AAB)AC@ Aa (BAC) FERRE ee qe RRR Ree #15, 224 = 216 2a. BERR EEE 2b. PRR meme Mathematical Structures for Computer Science Gersting Page 8 AVBAC (Av B)a(AvC) sé BRR Eee AABVO)e BER RRR BH eRe Be ye BRR RE ey BA fa tay a fe BRR Ree ae ty BaClAv(BAO)| AvBlAvC (AvB)A(Av guw dae Be b, 3b. ABI CIB v ClAa(Bv CO) AABIAACI(AAB) v (An ©) (AAB)v (AAC) BRR RR eee BERR eRe wee 5) a 4] >| qe 4 3 Maken Tene >| Seis g 4 4 ae | BREE RE Feeeeeee 4 s q < Beeee eee Ceeeeeee Ope ee afeeee alee PREP REE BFeePERee See dew Bee eee g é 3 2 a é < Gereting Mathematical Structures for Computer Science Page 9 BI (Av B)' A’ e. HAYA BI (Av BY @ A'AB' B F T F T mt aD mea aie ot 4a St BI (AaB) Haas aD moa Haan sana ao iy aad > alk Av Al Av Ao T T Fl oF T A'v Bi (A AB) @ A'vB' T BAA 18. a. (AAB) AC AAB'AC) @AA(CAB) (AAC) AB b.(AVB)A(AVB) @ AV BAB) OAVIGA c. AV(BAA)< (AVB)A(AVA) @ (AVB)ALG@AVB d. (AABY' vB (A'v (BY) VB< (A'vB) vB) @ A'v(BVB)@A'VB @ AA(AABY @ An (A'v BY) @ Ad (A'VB) @ (AAA) v(AAB) © 0V(AAB)@(AAB)VOG@AAB *19. dogs AND NOT retrievers 20. “oil paintings” AND (VanGogh OR REMBRANDT) AND NOT Vermeer 21. (novels OR plays) AND AIDS 22. 1.0, 2.4, 7.2, 5.3 23. For example: (A OR B) AND NOT (A AND B) AND NOT C 24. The conditional expression has the form (Av B)'v (A' AB). (A v BY'v (A! B) <> (A ABI) v (A! » B) (De Morgan's Laws) © AA B'v B) B, therefore (A> Bye (A' v By 2 (Ay AB oO AaB The negated statement is "Sam passed his bar exam but he will not get the job." 26.*a, Assign BA(A>B) tne A false From the second assignment, A is true. From the first assignment, B' is true (so B is false), and A — B is true. If A — B is true and A is true, then B is true. B is thus both true and false, and [B'« (A —> B)] > A'is a tautology. b. Assign (ASB) AA true B false From the first assignment, A is true and A -» Bis true, If A —» Bis true and Ais true, then B is true. B is thus both true and false, and [(A > B) - A] —> Bisa tautology. c. Assign (AVB) a A true B false From the first assignment, A'is true (and A is false), and Av Bistrue. IfAv B is true and A is false, then B is true. B is thus both true and false, and (AvB) AA! Bisa tautology. d. Assign (A AB) AB! true A false Gereting Mathematical Structures for Computer Science Page 11 27. a. . PisAAA' . PisAVA' QisAAA' 28.a. 29.a. 30. a. From the first assignment, A.» Bis true, If A.A Bis true, then Ais true. A is thus both true and false, and (A » B) A B' -> A is a tautology. PisAVA' QisBvB' B E rt maa eels aah Bl AvBIA'B!A'ABI(A'A BYJAVBO (A'ABY Tit] T [FlFl F T T tlF| v |F\T] F T T F\t| T |T\F] F T T F\F] F |T|T| T F T AJBIB'A AB! (AAB)'|A>B |A>Be@(AABY Title] F T T T TIF Ir | T F F T FIT|F | F T T T F\F|r| F T T T A /Bis equivalent to (A'v B'Y BIA ABI AYB'/A'vB'I(A'v BY AAB @ (A'vBY’ tt] T [FlF] F T T TF, F |F iT] T F T FT| F TIF] T F T FF] F |T|T] T F T A Bis equivalent to A'vB BIA>B A'/A'vBIA >Be A'vB tt} TlFl T T TF| F|F| F T F/T] T]T] T T FF] Tt] tl T T Page 12 Mathematical Structures for Computer Science Gersting 31. b. AABis equivalent to (A — B') AABBIA~ B'l(A>B')'|An BO (A->BY tlt] T JF] F T T TIF} F |t T F T F{t] F |t| T F T FlF| F |t| T F T Av Bis equivalent to A’ > B AIBIA vBIA'LA’ tlt] 1 TlF| T Fit] T FlF| F (AA By has the value F when A and B have the values T. However, any statement using only > and v will have the value T when A and B are both T. *32.A AB is equivalent to (A[B)|(AIB) 34, BAB! AIBI (AIB)(AIB)| A.A B <> (AIB)|(AIB) tlt] T[F T T TIF] F | T F T FIT] F | T F T FIF| F | T F T A’is equivalent to AJA A'LAIA| A'e AIA TFL F/T Flri rl Aa Bis equivalent to (At A) 4 (BL B) AIBJA ABIALAIBLBI(ALA)L (BL B) AABoo (AL A)L BIB) tlt} tT] F /F T T TIF} F | F | T F T Flt] F | T |F F T FlF] F | Tt | T F T A’ is equivalent to ALA AJA ALAI A‘ ALA TIE | F T Fit] T a. In order for A“ B to be true, we would want to know that both parts are true; if one part has an unknown truth value then it is unknown whether this is the case. In order for A vB to be true, we would want at least one part to be true; if one part is false and the other part has an unknown truth value, then it is unknown whether this is the case. Finally, if the truth value of A is unknown, then the truth value of A'is also unknown, Gersting Mathematical Structures for Computer Science Page 13, 35, 36. 37. 38. 39. *c, min(0.12, 0.93) = b. @YAN=TAN=N c. NAF=F d. (N)'v®!=NvT=T a. IfAhas a truth value of x, 0 B, where A stands for "I am a truth-teller" and B stands for "Meredith is a truth-teller." If Merlyn is a liar then statement A is false; therefore statement A —> B is true, but Merlyn, as a liar, would not have said a true statement. Therefore Merlyn must be a truth-teller. Then the statement he makes, AB, must be true, and statement A is true as well. Therefore statement B must be true, and Meredith is a truth-teller. So both Merlyn and Meredith are truth-tellers, Rothwold's statement is of the form A vB, where A stands for "I am a liar" and B stands for "Grymlin is a truth-teller." If Rothwold is a liar, then his statement A v B is false, and the statement (A v B)' must be true. By De Morgan's laws, A’ and B' must both be true. But A'is the statement that Rothwold is a truth-teller, which is not true. Therefore Rothwold must be a truth-teller, and his statement Av B is true. Statement A, however, is false because it says that Rothwold is a liar. So statement B must be true, and Grymilin is a truth-teller. Both are truth-tellers, EXERCISES 1.2 *1 (M>F)AF>M' -mt 2. (B>A)AB>A -mp 3. SALSL -sim 4. (SR)A(R>B) > (SB) -hs Page 14 Mathematical Structures for Computer Science Gersting 5. 6. *7, *10.1. #13, The hypotheses have the form (C > P) A P'. By mt, the conclusion is C’; the car was not involved in the hit-and-run. The hypotheses have the form (W v L) A (W > F). No conclusion can be made (note that W v L does not mean that you have W). The hypotheses have the form (B > P) A P. Only P, you will be paid tomorrow, can be concluded, using simplification. (B cannot be concluded.) . The hypotheses have the form GT a (G—>R). By mp, the conclusion is R, we need to rake the leaves. LA hyp 2. B>C hyp 3. B hyp (deduction method) 4c 2, 3, mp 5. AAC 1,4, con 1 A> v0 be 2 he np 4. BAC 2, 3, co 5. (BYC) 4, De Morgan 6 AY 1,5, mt 1A hyp 2. B hyp 3. B>(AvC) hyp 4, AvC 2,3, mp 5. (AVC 4dn 6 AoC 5, imp 7.C€ 1,6, mp A'A(B>A)>B LA hyp 2. BOA hyp. 3. BY 1,2, mt (A>B)A[A>6>0]>(A>0) 1. A3B hyp 2. A+(B>O)hyp 3A hyp 4B 1,3, mp 5. BoC 2,3, mp 6 Cc 4, 5, mp Gersting Mathematical Structures for Computer Science 14. (C+D) >C]> [(C>D) >D)} 1. (C->D)—>C hyp 2. C+D hyp 3. 1, 2, mp 4. D 2,3, mp *15. A'A(AVB) 9B 1 AY hyp 2, AVB hyp 3. (AYVB 2,dn 4, AB 3, imp 5. B 4, mp 16. [A> BPOINAYD) AB>D>O) A>(>O)hyp 2 AvD hyp 3. B hyp 4D hyp 5. DivA 2, comm 6. D>A 5, imp 1A 4,6, mp 8 BOC 1,7, mp 9c 3, 8, mp 17. (A' 9B) ABA(A>C)>C 1. ASB hyp 2B hyp 3. ABC hyp 4. By 2, dn 5. (AY 1, 4, mt 6A 3, dn 7.C€ 3, 6, mp 18, ASBAB OC >DIAA> BO) >(A>D) . AWB hyp 2 B-> (CD) hyp 3. ASB Oh» 4. hyp 5 B 1, 4, mp 6. B>C 3, 4, mp 7C€ 5, 6, mp 8, C>D 2, 5, mp 9. D 8, 9, mp Page 15, Page 16 Mathematical structures for Computer Science Gersting 19. [A> B30] > [B>(A>O)] 1, a >B>0) tp 2. 3. a ne (using deduction method again) 4. B>C 1,3, mp 5. 2,4, mp 20. (AAB) > (AB)! 1. AAB hyp 2. (AY ABY Ida 3. (A'VBY 2, De Morgan 4. (A>BY 3, imp 421. PVQAP>Q 1. PvQ hyp 2? hyp 3. PYVQ Ldn 4. PQ 3, imp 5. Q 2,4, mp 22. PQ >(Q>P) 1. P>Q hyp 2. Q hyp 3. PY 1,2, mt 23.(Y>P)>P>Q 1 QoP hyp 2, P hyp 3. ey 2,dn 4. Qy 1,3, mt 5. Q 4, dn 24, P>PAP LP hyp 2.P hyp Gust writing it again) 3. PAP 1, 2, co 25.PvP—>P 1 PPP Exercise 24 2. P>@vPy 1, De Morgan 3. [P'>@vPy]> (PvP) >P] Exercise 23 4, PvP>P 2,3, mp 26. [P AQ) +R] > [P>(Q>R)] 1. e AQAR hyp 2 hyp 3 Q iP (using deduction method again) 4. PAQ con 5.R 1,4, mp Gersting Mathematical Structures for Computer science *27.PAP'>Q LP hyp 2P hyp 3. PvQ I, add 4. QvP 3, comm 5. Q)'vP 4,dn 6. Q—>P 5, imp 7. QY 2, 6, mt 8. Q 7, dn 28. PA(QVR)>@AQV @aR) Rewriting the conclusion, the argument is PAQVR)>(PAQ)'V PAR) by dn or PAQVR)>[PAQ>PrR)] by imp LP hyp 2. QvR hyp 3. @AQ’ hyp 4, Pv 3, De Morgan 5. QvPt 4, comm 6. Q>P 5, imp 7. ey 1, dn 8. Q 6,7, mt 9. RvQ 2, comm 10.(RYVQ — 9,dn 1L.R'>Q 10, imp 12. (Ry 8, 11, mt 13.R 12, dn 14.PAR 1, 13, con 29. Pv (QAR) > PVQAPVR) Prove PvVQAR)>PvQ® Rewriting the conclusion, the argument is PY(QAR)>(@YVQ__ bydn or PVQAR)>P>Q __ byimp PVQAR) hyp Pp hyp PV QAR) I, dn Page 17 QaR Q 1 2. 3 4. P'+(QAR) 3, imp 5. 6. 2, 4, mp 5, sim The proof for Pv (QAR) > PVR) is similar. Page 18 Mathematical Structures for Computer Science Gersting 30. A'> (A> B) LAY hyp 2A hyp 3. B 1,2, inc 31, Po QaP>Q >Q 1. P>Q hyp 2. P+Q hyp 3. Q>P' 1, cont 4. Q>Q 2,3, hs 5. Q)vQ imp 6 QvQ 5, dn 7.Q 6, self 32. (A’ +B) A(A>C) >> 0) 1 ASB hyp 2. A>C hyp 3. B hyp 4. BoA 1, cont 5c 2,4, hs 33. (A' > B) A(B > C) (C+D) > (A' > D) 1 AB hyp 2. B>C hyp 3. CoD hyp 4. AC 1,2, hs 5. AD -3,4,hs MAVBAASOABC)>€ AvB hyp 2 A>C hyp 3. BoC hyp 4. (AYVB Ldn 5. AB 4, imp 6 AOC 3,5, hs 7. AOA >O) 2, 5, con 8 Exercise 31 35, WIZ)AK SYA 9 KW aV>Z9 Wow 1 Y¥oz' hyp 2. YoZ hyp 3. Y hyp 4. Z 1,3, mp 5. Z 2,3, mp 6W 4, 5, ine Gereting *36. (AABY' A(CAAYA(CABY' >A! 37. 38. 1. (AABY hyp 2, (CAA) hyp 3. (CABY hyp 4. A'vB 1, De Morgan 5. BVA! 4, comm 6. B>A’ 5, imp 7. (C)vA 2, De Morgan 8 CA’ 7, imp 9. C'v(BY 3, De Morgan 10.(BYv C11, comm 1.BIoC 10, imp 12. BIA 8, 11, hs 13.(B>A)AB'> A) 6, 12, con 14,4 Exercise 31 Pv QAR) AR VS) AST) >(T>P) 1. PV(QAR)_ hyp 2. Rvs hyp 3. SoT hyp 4.7 hyp 5. (Ty 4, dn 6s 3, 5, mt 7. SvR’ 2, comm 8 (SYvR 7,dn 9. SR 8. imp 10.R' 6, 9, mp ILRVvQ 10, add 12.QvR' 11, comm 13.QAR) 12, De Morgan 14.(QAR)vP 1, comm 15.P 13, 14, ds The argument is (E> Q) A (EVB) AQ >B A proof sequence is: 1. EQ hyp 2. EVB hyp 3. Q hyp 4. Q>E cont 5. EB 3, 4, mp 6. @)vB 2,dn 7. BB 6, imp 8B 5,7,mp Mathematical structures for Computer Science Page 19 Page 20 Mathematical Structures for Computer Sotence Gereting 39. The argument is [J > E) AJ > ©] > J > Ero) A proof sequence is 1 JE hyp 2. I3C hyp 3.3 hyp 4.5 1,3, mp 5.C 2,3, mp 6. EAC 4, 5, con 40. The argument is [(C 4 W') A (Rv S') > W)] > (CAS) A proof sequence is: 1 Caw hyp 41 2. (RVS) > W hyp 3 Ww 1, sim 4. W>(RvS)! 2, cont 5. Rvs) 3,4, mp 6. R'A(S 5, De Morgan 7. RAS 6, dn 8S 7, sim 9c 1, sim 10.CAS 8, 9, con . The argument is [(A > $) A (Av C) AS] A proof sequence is: 1, A>S hyp 2. AvC hyp 3. Ss! hyp 4A 1,3, mt 5. 2,4, ds *42. The argument is [(R 4 (F' v N)) AN'A (A' > F)] > (AAR) A proof sequence is: 1. RA@VN) hyp 2N hyp 3. AOF hyp 4k 1, sim 5. FVN 1, sim 6 NvF 5, comm LF 2,6, ds 8. F(A)’ 3, cont 9. (AN 7,8, mp 10.A 9, dn 1. AAR 4, 10, con Gersting Mathematical structures for Computer Science 43, The argument is (R > U)' a (Pv BY > UAB 44, "45, Page 21 A proof sequence is: 1, (RU) hyp 2, PvBY hyp 3. (Rv Us Limp 4. (RYAU 3, De Morgan 5. RAU! 4, dn 6. P'A(BYY 2, De Morgan 7. PAB 6, dn 8 U 5, sim 9B 7, sim 10.U'AB 8, 9, con The argument is (J vL) > C)AT A(C> TF A proof sequence is: 1. GvL)>C_ hyp 27 hyp 3, C>T hyp 4.T3>C 3, cont 5. Cc 2, 4, mp 6. C->GvLy 1, cont 7. OvLy 5, 6, mp 8 TAL’ 7, De Morgan 97 8, sim aAl > T T T F T T T T F T F F F T F T b. AF BIO) GASB VOSA VB VC) (A'VB)VC = (AAB)' VC (AB) >C By part (a) (or (b)), [PL AP2 A.A Pp] > (RS) 2 PA PZA ».. APaA R)S which says to take each of P), P3, ..., Py, Ras hypotheses and deduce S. Page 22 Mathematical Structures for Computer Science 46. Let I= my client is innocent K = the knife was in the drawer J= Jason Pritchard saw the knife O = the knife was there on October 10 H_= the hammer was in the barn Then the argument is [@K) AB VDAOSNAOF KAW) AH] 31 A proof sequence is: Gersting 1 P>K hyp 2. Kv hyp 3. OF hyp 4, O>(KAH) hyp 5. H hyp 6. Hv’ 5, add 7. (aK) 6, De Morgan 8. (KAH) 7, comm 9. KAH>0! 4, cont 10. 0° 8, 9, mp wT 3, 10, mp 12.Jv K! 2, comm 13.K 11, 12, ds 14.K'> 0) 1, cont 15. (I 13, 14, mp 16.1 15, dn EXERCISES 1.3 LaTbFoaFda T 2.%a, true (pick y=0) *b. true (pick y=0) *c. true (pick y=-x) +d. false (no one y works for all x's) e. false (may have x= y) £ true (pick y=-x) g. true (pick x=2, y=4) h. false (may have x= 0) aF bT ¢T dF eT s *a._ true: domain is the integers, A(x) is "x is even", B(x) is "x is odd” false: domain is the positive integers, A(x) is "x > 0", B(x) is "x 21" Gersting Mathematical Structures for Computer Solence Page 23 b. true: domain is the collection of lines in the plane, P(x, y) is "x is parallel to y" false: domain is the integers, P(x, y) is "x 0", B(x) is "x > 0" false: domain is the integers, A(x) is "x > 0", B(x) is "x is even" . scope of (Vx) is P(x) > Q(y); y is a free variable . scope of (3x) is A(x) A (¥y)B(y); scope of (Vy) is B(y); no free variables scope of (3x) is (Vy)P(x, y) A Q(x, y); scope of (y) is P(x, y); y is a free variable scope of (3x) is (3y)[A(x, y) A B(y, z) > A(a, 2)}; scope of (2y) is A(x, y) ABQ, 2) > AC@, 2); zis a free variable eaoge Some parts of Exercises 6-9 have multiple equivalent answers. a ¥a. (Vx(D(%) > SR) *b. GxD&) A (ROO) oF [(V¥x)D&) > RO)T *e. (Vx)[D(x) 4 Sx) > R@)'] d. GD)» S@&) AR®)] 2. (¥x)[D(X) > (SQ) A RG)']_ oF (Wx)[D(X) A SO) ARO) (¥x)[D@) A SX) > DX) ARO] (Wx)D@&) > (S00) S(M) > (V¥x)(D&) > Sx), RM) AR) Gx)(D&) A R&) > (V¥x(D&) > SO) (Wx)(BO) > RO) - [(Vx)(B(X) > S(x))]!' or Gx)(BER) A [SED]') (Wx)(SQ%) > R&) I. xB) a RON) Gx)BX) A RO) A (Wx)(S) > [ROD (Wx)(BQX) A R(X) > SQ) . (7x)(B(X) A R(x) > S(~)) = this is the same statement as (f) . (Vx)(S(x) > ROX) > (Vx)(BEX) > R&) GHPO) A (VT) > Fox, y) . (Vx)(POX) > GyT() A F(x, y)) [OVx)(VyMPO) A TY) > F(x, y))T' oF Ax) Sy (PQ) 0 TY) A FGs, yy) or [(Vx)(PQ) > (Vy)(TYY) > F&% y))] x0WOD) A L(x) 0 CQ) re me FR meaoge ese 6. (HWS) > LOX) A CCX) te, GxILO) A (MAG ¥) > IG) oF GN(VY)ILE) A (AG y) > IO) Page 24 d. me ® 10.4a, *b. me crv re me ae ses meaoge 8g 13.¥a *b. ©. d. e. f Mathematical Structures for Computer Science Gereting (Hx)LTEx) > (Wy(AGs, y) > IG))] oF CVX)CVY)T®) > (AG y) > JQY))] oF (Yx(VYIIO) A AG, ¥) > JQ)] - (Vx)(VYNT) A AG, ¥)) > JOO] (¥x)(IWOX) A LOD] > Gy) A AG y)) or (YA) Gy)IWH) A LO] > DO) 0 AG y)) » AxW(x) 0 (Vy)ILQ) > (AG y))'D) or GxNCWOD) A (V¥)L AG y) > LY)'D oF GVW) A IL) > (AG yD (VCO) AF)" CIPO) A C¥yNSOs y) > FON] oF GNCWYIIPO) A (SC) > FOI] (vx)(y MEP) A SE, 99] > COO) (YF) > GyN(CO) A SE, ¥)] oF CREWE > (CO) A SOs, y))] or, if there is some one Corvette, (Ax)[C(x) a (Vy)(F(y) > S(y, x))] B)PE) A (WYNICO) > (SE, WD oF BIEHYNPE) A ICC) > (SEX, YD GBIEVNCE) A FO) A SCX, 9) > (URIEWYNCE) FOV) —> SEX, 9) (XB) > (Vy)F(Y) > L(x, y)] o (¥x)(Vy)LBOO) A FY) > Ls, y)] . EX[BO) A (VFO) > Lox y))] (Vx) [B(x) > GyFQ) A L(x, y))] (Wx)[B) > (VLG y))' > FO) (Wy)LFO) > (Vx)(L(x, y) > BOX)] or (y)CVX)F) A LO, y)) > BOD] (¥x)[BO) > (Vy)(LO, y) > FO) [GX[BOd (VLE y) > FO))IT oF (VX)[BO) > Gy)(LOx y) A FQ))T Gx[BOs) » Gy)FO) 4 L(x, y))] or Gx)Gy)[B&) 4 Fy) ALG, y)] (GB) a (Wy)LG, y) > FO) (Wx)[BO) > GyFY) ALG y))'] (WX)[BOX) > (VY)FO) > LG y))9] or (¥XI(VYBED A FO) > LGx y))'1 [GX)BO) a (Yy)FO) > LO yIIT or (WBE) > Gy)(FO) ALO y))] . (Vx)(S(X) > L0) . Gx)(M(x) 4 [SO] (XL) > MOO) Gx(S&) 4 MQ) (ex)(Vy) (SX) A M(y) > BC, y)) GYMG) A (VSG) > BO y)) (YxNCVY)(MG) 4 BEX, y) > SX) John is handsome and Kathy loves John all men are handsome all women love only handsome men a handsome man loves Kathy some pretty woman loves only handsome men John loves all pretty women 14.4.2 b.3 63 dl Gersting Mathematical Structures for Computer Science Page 25 15. a. No web site features audio. b. Some web site does not have *c. Some web site has neither audio nor video. d. Every web site has either audio or video. e. Some web site does not have text and also either doesn't have audio or doesn't have dio or does not have video. video. 16.a. There is a nonstudent who eats pizza. b. Some student does not eat pizza. c. Every student eats some non-pizza item. 17.a. Every farmer grows something besides corn. b. Some farmer does not grow corn, c. Someone besides a farmer grows corn 18. a. both sides are true exactly when A(x, y) holds for all x, y pairs 19.*a, domain is the integers, A(x) is "x is even", 20. b. both sides are true exactly when some x, y pair satisfies the property A(x, y) *c. if there is a single x that is in relation P to ally, then for every y an x exists (this same x) that is in relation P to y ‘a has property A, then something in the domain has property A e. ifany member of the domain that has property A also has property B, then if all members of the domain have property A, all have property B B(x) is "x is odd" b. domain is the integers, P(x,y) is "x + y = 0"; for every x there is a y (y= -x) such that x + y = 0 but there is no single integer x that gives 0 when added to every integer y c. domain is the positive integers, P(x) is "x > 4", Q(x) is "x >2". Then every positive integer greater than 4 is greater than 2, so (Vx)(P(x) > Q(x)) is true, There exists a positive integer greater than 4, but not all positive integers are greater than 2, so (x)P(%) > (Vx) QQ) is false 4, domain is the integers, A(x) is "x is even". Then (\/x)(A(x))'is false - it is not the case that every integer is odd (not even ) - but ((Vx)A(x))'is true since it is false that every integer is even. a. valid: there is an x in the domain with property A says itis false that everything in the domain fails to have property A. b. not valid: domain is the integers, P(x) is "x is even", Q(x) is "x is prime". Because there are prime integers, (3x)Q(x) and therefore (‘/x)P(x) v @x)Q(x) is true. But it is false that every integer is even or prime, so the implication is false. c. valid: A true for all objects in the domain means itis false that there is some object in the domain for which A is not true. d. valid: suppose that for every member of the domain, either P(x) or Q(x) is true. If there is some member of the domain for which Q is true, then (2y)Q(y) is true. Otherwise all members of the domain have property P and (\/x)P(x) is true. In either case, (Vx)P(x) v Gy)Q(y) is true. Page 26 Mathematical Structures for Computer Science Gersting EXERCISES 1.4 1. The conclusion is that pansies are plants. The hypotheses have the form (x)(F(%) > P(%)) A F(p). By universal instantiation, F(p) -» P(p), then by modus ponens, P(p). *2. The conclusion is that pansies are red. The hypotheses have the form (¥x)[F(%) > (ROX) v P(®)] A F() A [P(p)].. By universal instantiation, F(p) + (R(p) v P(p)), then by modus ponens, R(p) v P(p), and finally by disjunctive syllogism, R(p). 3. The conclusion is that some flowers are small. The hypotheses have the form (BNEG) A P(R)) A (WX)(F(%) A P(X) -> S(X)). By existential and universal instantiation (in that order), F(a) P(a) and F(a) P(a) —» S(a), so by modus ponens, S(a). Combining F(a) and S(a) and using existential generalization results in GNF) A SQ). 4, No conclusion is possible. Just because pansies are flowers, it does not make them cither red or purple. The hypotheses have the form (2x)(F(x) R(S)), (2x)(F() A P(%)), F(p). But existential instantiation does not allow us to use p in removing the existential quantifiers, so we can say nothing further about pansies. 5. The conclusion is that some flowers are weeds. The hypotheses have the form Gx(FX) A POX) A TQ), (Vx)(FOX) A TOx) > BOX), and (¥x)(F(x) A B(x) > WOX)). By existential and universal instantiation (in that order), F(a) A P(a) 0 T(a), F(a) A T(a) > B(a), and F(a) A B(a) > W(a). Simplification gives F(a) A T(a) which, using modus ponens, gives B(a). Combining F(a) with B(a) and using modus ponens results in W(a). Combining F(a) and W(a) and using existential generalization results in GNFO) 4 WOO) 6. 1. Hyp 2. Lei 3. hyp 4, 3,ui 5. 2,4,mp 6. 5,eg 7. 1. hyp 2. hyp 3. Lei 4. Qui 5. 3,4, mp 6. 5,eg *8. a, The domain is the set of integers, P(x, y) is "x y", for every integer x, there is some integer that is larger and there is some integer that is smaller. But it is false that for every integer x there is some one integer that is both larger and smaller than x. Gereting Mathematical Structures for Conputer Science Page 27 b. To get to step 2, ei was performed on two different existential quantifiers, neither of which was in front with the whole rest of the wf as its scope. Also, both existential quantifiers were removed at once, with the same constant a substituted for the variable in each case; this should be done in two steps, and the second ‘would then have to introduce a new constant not previously used in the proof. And at step 3, the existential quantifier was not inserted at the front of the wf. 9. a. domain is the integers, Q(x, y) is "x (x)[P) A Q)] 1 (Wx)POX) hyp 2. Ax)QAx) hyp. 3. Qa) ei 4. Pa) Lui 5. Pla) A Qa) 3,4, con 6. GNPH)AQAQ*)) 5, e8 12. Gx)Gy)P y) > Gy)Gx)P( y) 1. Gx)Gy)P(, y) hyp 2. Gy)P@y) lei 3. P(a,b) 2,¢ 4, Gx)P(%, b) 3, eg 5. Gy)Gx)PO y) 4, eg 13. (Vx)(Vy)Q(% y) > CVy)CVXIQU, y) 1. (Vx)(Vy)QQy) hyp 2. (Wy)QAx, y) lui 3. Q&x,y) 2, ui 4. (Wx)Q(x, y) 3, ug (x not free in (Vx)(Vy)Q(x, y)) 5. (VYVIQG y) 4, ug (y not free in (Vx)(Vy)Q(x, y)) 14, (Vx)PQ) A GOLPO > Gx)Q) 1. (Wx)P() hyp 2. Gr[Pool hyp 3. [P@l 2,¢ 4. Pla) Lui 5. Qa) 3,4, ine 6. Gx) S,eg Page 28 Mathematical Structures for Computer Science Gersting "15. Can AB(x)] > GX)A(S) A GX)BQX) *1 s 20. 21. ~ GAG) ABO) — hyp 2 A@) A Ba) Lei 3. Ala) 2, sim 4. Ba) 2, sim 5. (x)AQ) 3, eg 6. Gx)BQx) 4, eg 7. GA) A @x)BQX)_ 5, 6, con Using an equivalence to rewrite the conclusion, we want to prove Gx)(RO) v SX) > (GORE) )' > GX)S@)] 1. GRO) VS) hyp 2. Ra) v S(a) Lei 3. (GOR) hyp 4. (#x(ROO)’ 3, neg 5. R@)y 4, ui 6 S(@) 2,5, ds 7. @xS(x) 6,eg (WX)PO) > Qx)] 1(VX)P(X) > (¥X)QO0)] 1, (¥x)P@) > QC] hyp 2. (Vx)P(x) hyp 3. P(x) > Ax) Lui 4, P(x) Qui 5. Q(x) 3,4, mp 6. (x) Q(x) 5,ug [(¥x)POX) — (¥x)QO)]} > (VX)IP) > QO] Domain is the integers, P(x) is "x <3" and Q(x) is "x <2." (The left side is true because (Vx)P(x) is false, but the right side is false.) EXPY) y) > (VYIENAS y) 1. Gx(Vy)Qx, y) hyp 2. (Vy)Q@, y) lei 3. Q@y) 2, ui 4. Gx)Q, y) 3, eg 5. (Vy)Ax)QGx y) 4,ug (YX)POX) v GN)QH) > (VX)IPOS) ¥ QQ] Domain is the integers, P(x) is "x <5" and Q(x) is "x is even." WAlAG), > BX] > [GX)A®) > Gx)BQ)] (Wx)(AQ) > BOX) hyp 2 @NAq) hyp 3. A@) 2,¢i 4, A(@) > Bia) Lui 5. Ba) 3,4, mp 6. (x)B(x) 5, eg Gereting Mathematical Structures for Computer Science Page 29 22. (WyNQx, y) > P(X)] > [Gy)Q& y) > P(S)] 23, 2. & 25. (Yy)(QG, y) > PO) hyp L 2. Gy) y) hyp 3. Qa) 2, ei 4. Q(x, a) > P(x) Lui 5. P(x) 3,4, mp [P@®) > Gy) y)] > GyY)P&) > A y] 1, PQ) > Gy)Q y)_ hyp 2. P(x) temporary hyp 3. Gy)QG, y) 1,2, mp 4. Qa) 3, ei 5. P(X) > Qs, a) temporary hyp discharged 6. Gy)(P) > Q& y) 5, eg GPR) > Q)] A (VQ) > ROD] A (VHP) > GRO) 1, Gx[PO%) > Q)]_— hyp 2. (VyQy) > ROD] hyp 3. (Wx)P(%) hyp 4. P(a) > Qa) Lei 5. Pla) 3, ui 6. Qa) 4,5, mp 7. Aa) > Rea) 2,ui 8. Ria) 6,7, mp 9. GxX)ROX) 8, eg a A proof sequence is: 1. (Wx)(M(x) > PG) 2. (vx)(S(x) > M@®)) 3. M(x) > P(x) 4. S(x) > M(x) 5. S(x) > Ps) 6. (Wx)(S%) > P(X) b. 1. (Vx)(M(x) > [PO)]). 2. (Wx)(S(QX) > MQ) 3. M(x) > [PQ] 4. S(x) > M(x) 5. S(x) > [P@]' 6. (Wx)(S&) > [PODT) (Yx)OM(X) — POX) A (VX)(SX) > MQ) > (VX)(S(X) > PO) hyp hyp Lui 2,ui 3, 4hs 5, ug . (Wx)(M(x) — [PQ)I) A (Vx)(SO) > MQ) > (¥x)(SE) > [PONT hyp hyp Lui 2, ui 3,4, hs 5, ug Page 30 Mathematical Structures for Computer Science Gersting ©. CYx)(M(X) > POX) A Gx(SQ) 0 me) > Gx)(SO0) A PQ) 1. (Vx)(M(x) > PQ) - Ax)(S(x) A MQ) . S(a) A M(a) M@a) M(a) —> P(a) Pla) Sa) . Sa) A Pla) . Gx )(S(x) A PQ) ~PeIrauaen- mp 2,¢ 3, sim 1, ui 4,5, mp 3, sim 6, 7, con 8, eg 4. (Yx\M(X) > [PODT)A Gx(S@) A > > x)(SO9 A [PODT) 1. (Vx)(M@) > [PQ]! 2. Gx(S(x) 0 MOO) 3. S(a) \M(@) 4. M@) > [P@]’ 5. Ma) 6 7. 8. S(a) A[P(@)I' 9. GxY(S@) » [PO)]) 26. The argument is: GxPQ) A FOO] 4 (VYFO) > SQ) > GXIPO9) 0 SOD] A proof sequence is: 1. GxP@) AF) hyp 2. (Wy)FQ) > SQ] hyp 3. P(a) a F(a) lei 4. F(a) > S(a) 2, ui 5. F(a) 3, sim 6. S(@) 4, 5, mp 7. Pla) 3, sim 8. P(a) A S(a) 6, 7, con 9. xP) A SQ] 8.eg *27 The argument is: (Vx) (WyICO) A AW) > BG y)] A C68) 0 Ax(S@) 4 (BG, XI) > GNIACOT A proof sequence is: 1. (Wx) (Vy)ICG) 4 AY) > BE y)]_ hyp 2. C(s) hyp 3. (Vy)[C(s) 4 AG) > Bis, y)] Lui 4. Gx\(S(%) a {BGs, x)]') hyp 5. S(a) A (BG, a] 4, i 6. C(s) A A(@) > BGs, a) 3,ui 7. [BGs, a)]' 6, sim Gereting 8. [C(s) A AQ] 9. [CS] v {A@] 10. [[C(s)]T 11. [A@]' 12. Gx[AGO]' 28. The argument is: Mathematical Structures for Computer Science Page 31 6,7, mt 8, De Morgan 2, dn 9, 10, ds 11, eg GAG) 4 (NOD) A (VXGE) > NOD) A (VXG(®) V COX) > GAG) 0 COD) A proof sequence is: 1. @x(A@) A (NOX) 2. Ala) (N@))' (Wx)(G®) > NGO) . G(a) > N(a) . (N@)' > G@) Wa) (G@) (Vx)(GO®) v C(x) 9. G@v Cla) 10. C(a) 11. A(@) 12. A@) A C@) 13. Gx (AQ) A COX) *29. The argument is: ePrAAWAw hyp Lei hyp 3, ui 4, cont 2, sim 5,6, mp hyp 8, ui 7,9, ds 2, sim 11, 12, con 13, eg (¥X)EMEX) 168) v GO) A C¥R)(GEH) ALEX) > FO)) 0 CG)’ A LG) > (OMG) > FO] A proof sequence is: 1. (Wx)(M(®) > 1G) v GOO) 2. (Wx)\(G(x) A L(x) > F(x) . MG) > 1G) v G@) GO AL@ > FO MG) I@) v G@) ag) GO) . LG) 10. G@) ALG) 11. FG) PeErIaAwaw hyp hyp Lui 2,ui hyp 3, 5, mp hyp 6,7, ds hyp 8, 9, con 4,10, mp Page 32 Mathematical Structures for Computer Sctence Gersting 0 30, 31. 32, The argument is: GMO) 4 (VYIRGs y)) 4 (x)(VyRO ¥) > TEx, y)) > GM) A (¥y)TOs y)) A proof sequence is: 1. Gx)(M@) a (Vy)RG y)) hyp 2. M(a) A (Vy)R(, y) Lei 3. M@a) . 2, sim 4. (Vx\(VyR( y) > T(x, y)) hyp 5. (WyXRG@ y) > T@ y) 4,ui 6. (a, y) > Tl, y) 5, ui 7. (vy)R(@, y)) 2, sim 8, R@y) 7, ui 9. T(, y) 6, 8, mp 10. (Vy)T(a, y) 8, ug 11. M@) A (vy)T@, y) 3,9, con 12. Gx)(M(x) (Vy)TO, y)) 10, eg The argument is: (¥x)(COX) > Gy) WO y)) 0 (VX)(Vy)(WOs ¥) > Sx, y)) A C(m) > Gy)S(m. y) A proof sequence is: 1. (Wx)(C(X) > Gy) WO y))_ hyp 2. C(m) > Gy) Wim, y) 1, ui 3. C(m) hyp 4. Gy)W(m, y) 2,3, mp 5. (Wx)(Vy)(W(%, y) — Sx, y)) hyp 6. (vy)(W(m, y) > S(m, y)) 5, ui 7. W(m, a) 4,¢i 8. W(m, a) > S(m, a) 6, ui 9. S(m, a) 7,8, mp 10. (Ay)S(m, y) 9, eg The argument is: CHx)(Vy)(AG) 0 SOx, ¥)) > DEY) 0 Gx)GyM(AGD A S&, y)) > Gx)DEO) A proof sequence is: 1. (Wx)(Vy)(AG) A SC, y)) > DY) hyp 2. Gx)Gy(A) A S(x, y)) hyp 3. Gy(AQ@) A S@ y) 2, ¢ 4, A(a) A Sf, b) 3, ei 5. (¥y(A@) ASQ y)) DG) ui 6. (AQ@) Sf, b)) > Db) 5, ui 7. Do) 4, 6, mp 8 Gx)Dj) Teg Gersting Mathematical structures for Computer Science Page 33 33. [GXYPOOIT (VH[PO)IT _ neg, using [P@d)]' for AG) [Gx POOTT < (¥x)PO0). dn [CVx)PODT' <> ((Gx)[P@)]T)' cont (each direction) [(vx) PONT <> GxPOOT dn 34. a3 b. 5c. 2(anevenprime number) d. 2 ((-1)2=1) e. 11 (211-1 =2047=23*89) EXERCISES 1.5 1 no 2 yes *3. fish 4. rabbit 5. fox deer 6. fish little-fish fish raccoon fox deer deer *7. herbivore(x) if eat(x, y) and plant(y) 8. little-fish rabbit deer a. Anita b. Mike Kim c. Judith Sam Mike Kim Joan Hamal Enrique Jefferson 10. For example, capitoK(north-dakota, bismark) capitol(california, sacramento) capitoK(hawaii, honolulu) capitol(pennsylvania, harrisburg) Page 34 Mathematical Structures for Computer Science capitol(florida, tallahassee) capitol(new-york, albany) big(sacramento) Big(honolulu) Big(albany) small(bismark) small(harrisburg) small{tallahassee) eastern(pennsylvania) eastern( florida) eastern(new-york) western(north-dakota) western( california) western(hawaii) . which(x: small(x)) whieh(x: capitol(x, y) and small(y)) which(x: eastern(x) and capitol(x, y) and big(y)) cosmopolitan(x) if big(x) and capitol(y, x) and western(y) . which(x: cosmopolitan(x)) paoge *11. a. is(author-of{mark-twain, hound-of-the-baskervilles)) . which(x: author-of{faulkner, x)) .nonfiction-author(x) if author-oftx, y) and not(fiction(y)) |. which(x: nonfiction-author(x)) aegp 12. a. father-of(x, y) if parent-oflx, y) and male(x) daughter-ofix, y) if parent-ofly, x) and female(x) ancestor-ofx, y) if parent-ofx, y) ancestor-of{x, y) if parent-of{x, 2) and ancestor-oftz, y) ds . which(x: small(x) and part-oftx, y)) which(y: small(x) and part-oftx, y) and big(y)) . component-of(x, y) if part-oftx, y) component-oflx, y) if part-ofx, 2) and component-of{z, y) ese EXERCISES 1.6 #1, x+1=y-lorx=y-2 2. Ix>y, orx>y/2 Gersting Gersting Mathematical Structures for Computer Science Page 35 3. Working backwards from the postcondition using the assignment rule, {x+3=4} x+3 {2y=8 or y=4} y=2ty {y=8} The first assertion, x + 3 = 4, is equivalent to the precondition x= 1. The assignment rule, applied twice, proves the program segment correct. 4. Working backwards from the postcondition using the assignment rule, {x+2>2} y=x+2 {y+1>3 or y>2} z=ytl {z>3} The first assertion, x + 2 > 2, is equivalent to the precondition x > 0. The assignment tule, applied twice, proves the program segment correct. *5. The desired postcondition is y = x(x - 1). Working back from the postcondition, using the assignment rule, gives {x(x - 1) = x(x - I} x-1 x(x-1)} xty {y=x(x- D} Because the precondition is always true, so is each subsequent assertion, including the postcondition. 6. The desired postcondition is y = 2x + 1. Working back from the postcondition, using the assignment rule, gives (x+x=2x) y fy ty=2x} yayty {y+ 1=2x+1 or y=2x} y=ytl {y=2x+1) Because the precondition is always true, so is each subsequent assertion, including the postcondition. Page 36 Mathematical Structures for Computer Science Gersting *7. The two implications to prove are {y=Oand y<5}y=y+1 {y=1} and {y=Oand y2 5} y=5 {y=1} The first implication holds because fy=O}y=ytl {y=} is true by the assignment rule, and the second is true because the antecedent is false. The program segment is correct by the conditional rule. 8. The two implications to prove are {x=7and x <0} y=x {y= 14} and {x=7 and x >0) y=2*x {y= 14} The first is true because the antecedent is false, and the second is true because {x= 7} y =2*x {y= 14} holds by the assignment rule, The program segment is correct by the conditional rule, 9. The desired postcondition follows from the definition of minimum: (x y and min = y). The two implications to prove are or (x > y and min = y)} ) or (x >y and min = y)} {xy and x y} min=y {(x y and x=y) Because the second disjunct is false, this is equivalent to (x y and y= y) which is equivalent to (x > y) or (x #y and x > y) The program segment is correct by the conditional rule. 10. The desired postcondition follows from the definition of absolute value for a nonzero number: (x > 0 and abs = x) or (x <0 and abs =-x), The two implications to prove are Gersting Mathematical Structures for Computer Science Page 37 {x-#0 and x 20} abs=x {(x> O and abs {x #0 and x <0} abs =-x {(x> 0 and abs ) or (x <0 and abs Using the assignment rule on the first implication gives the precondition (x> Oand x=x) or (x <0 and x=-x) Because the second disjunct is false, this is equivalent to (x > 0 and x= x) or (x > 0) or (x # 0 and x > 0), ‘Using the assignment rule on the second implication gives the precondition (x>0 and -x =x) or (x <0 and ~ x) which is equivalent to (x <0) or (x # 0 and x <0). The program segment is correct by the conditional rule. 11. For the top section of the program, we can work backwards from the postcondition using the assignment rule twice: {z+1=4 or 2=3) x=z+1; {x+2=6 or x=4} y=x+2; {y= 6} which agrees with the given precondition. For the bottom section of the program, we use the conditional rule to prove {y= 6} if (y>0) zeytl, else z= 2, {2=7} One implication is {y=6ay>0} z=y+l (2=7} which is true by the assignment rule, The other implication is {y=6 Ay<0}z=2+y {z=7} which is true because the antecedent is false. Page 38 Mathematical structures for Computer Science Gersting CHAPTER 2: Proofs, Recursion, and Analysis of Algorithms The most oft-heard refrain in teaching this class is "I can't do proofs." What this means is not that the student cannot "do" a proof but that he or she lacks the organizational skills to go about setting up the attempt. Are the definitions well understood? Is the given hypothesis in mind? Is the desired conclusion in mind? As I try to point out, if you don't know what you have and you don't know where you're going, you can't hope to get from here to there (think of a proof as building a bridge from one side of a river to the other). I sometimes have the student write the hypothesis at the top of the page, and the conclusion at the bottom. Then we list all the properties (ammunition) we can draw from the hypothesis - this is where truly understanding the definitions comes in. This process alone often allows the student to complete the proof without any further help, using a direct proof. If not, we repeat the process looking at the contrapositive, If the desired result is to show that something is not true, I point out that this is a 99% clue to use a proof by contradiction, The first section of this chapter is intended to catalog the options - exhaustive proof (which only applies under certain circumstances), direct proof, proof by contraposition, and proof by contradiction. Proof by mathematical induction (Section 2.2) is a special case. Even though students have usually seen induction before, they view an inductive proof with extreme suspicion. It is difficult to get them to accept the inductive assumption, as they tend to think that this is equivalent to assuming what they want to prove. Here is where the emphasis on formal logic in the previous chapter is helpful; looking at the structure of the principle of mathematical induction as a (major) implication one of whose antecedents is also a (minor) implication seems to help. They are then more willing to accept the inductive assumption as merely the antecedent of this minor implication. Once students are comfortable with the first principle of induction, the second principle of induction goes pretty well. One must take pains to point out conditions under which the second principle is more useful, even though the two principles are provably equivalent. At any rate, students need to do lots of inductive proofs, and not always just summation formulas, so ve provided many exercises in this section. Proof of correctness using loop invariants (Section 2.3) is a nice application of induction that ties in well with Section 1.6. Recursion requires the same leap of faith as induction, An interesting exercise to introduce recursion is to ask a group of students to line up facing the class, and ask the student on the left end to tell how many students are standing to his or her right. This person almost always steps out of line and counts (an iterative solution). Then ask the same student what information he or she would need from the person on the right to figure out the answer without stepping out of line, and ask the student on the right end if he or she has a simple way to answer this question, Then start from the right end (zero persons on my right - all [ had to do was look) and progress to the left (if person on my right tells me x persons are on his or her right, then x + 1 are on my right) until the problem is once again solved. Section 2.4 emphasizes the variety of things that are recursively defined - sequences, sets, operations, and algorithms. Recurrence relations, introduced in Section 2.4, are also discussed in Section 2.5 in the context of analysis of algorithms (order of magnitude discussions will come in Chapter 4.) Gersting Mathematical Steuctures for Conputer Science Page 39 EXERCISES 2.1 “1 +5. Converse: Healthy plant growth implies sufficient water. Contrapositive: If there is not healthy plant growth, then there is not sufficient water. Converse: Increased availability of information implies further technological advances. Contrapositive: If there is not increased availability of information, then there are no further technological advances. Converse: If there is a modification of the program then errors will be introduced Contrapositive: No modification of the program implies that errors will not be introduced. Converse: Good insulation or storm windows throughout implies fuel savings. Contrapositive: Poor insulation and some windows not storm windows implies no fuel savings. P' + Qs the contrapositive of the converse Q-> P, so the inverse and the converse are equivalent. For example: a. anonsquare rectangle . 0 c. a short, blue-eyed redhead d. a redhead who is short a, Half of this statement is true. Ifn is an odd integer, n = 2k + 1 for some integer k Then 3n + 5 = 3(2k + 1) + 5 = 6k + 8 = 2(3k + 4), which is an even integer. However, the converse is false. Consider the even integer 6. If 3n + 5 = 6, then 3n = 1 and n= 1/3, which is not an integer at all, much less an odd integer. See Exercise 18. b. Half of this statement is true, Ifn is an even integer, n= 2k for some integer k Then 3n + 2 = 3(2k) + 2 = 6k + 2 = 2(3k + 1), which is an even integer. However, the converse is false. Consider the even integer 10. If 3n + 2 = 10, then 3n = 8 and n= 8/3, which is not an integer at all, much less an even integer. See Exercise 19. 25 =52=9+ 16=324 42 100 10)2 = 36 + 64 = 62 + 82 169 = (13)2 = 25 + 144 = 52 + (12)2 4= 8= 2+2 343 3+5 5+5 5+7 Page 40 Mathematical Structures for Conputer SeLence Gersting 10, “LL 12. 13. 14 *15, 16. 17. 18. 19. n_[al [2 1 ii [2 2 [2 [4 3 [6 [8 n_[w [2 2 4 3 8 4 [16 [16 Let x= 2m, y= 2n, where m and n are integers. Then x + y=2m+2n=2(m +n), where m-+ nis an integer, so x + y is even Let x = 2m, y = 2n for integers m and n, and assume that x + y is odd, Then x + 2m + 2n= 2k + 1 for some integer k or 2(m +n - k) = 1 where m +n - kis an integer. This is a contradiction since 1 is not even, Let x= 2m+ 1, y= 2n+ 1, where m and n are integers. Then x + y =(2m+ 1) + (2n+ 1) =2m + 2n+2=2(m+n+ 1), where m+n + 1 is an integer, so x +y is even, Let x = 2m and y = 2n + 1, where m and n are integers. Then x + y= (2m) + (2n + 1) = (2m+ 2n) + 1 = 2(m +n) +1, where m +n is an integer, so x + y is odd. For two consecutive integers, one is even and one is odd. The product of an even integer and an odd integer is even by the proof of Example 9. Let n be an integer. Then n+ n? = n?+n=n(n+ 1), which is even by Exercise 13. Let x = 2m where m is an integer. Then x2 = (2m)? = 4m2, where m? is an integer, so x2 is divisible by 4. 3(n? + 2n + 3)-2n2= 3n2 +6n+9-2n? =n2+6n+9=(n+3)2 The contrapositive is: ifx +1 <0, thenx <0. If x+1<0, thenx<-1<0,sox<0 and therefore x < 0. If nis odd, then n= 2k + I for some integer k. Then 3n +5 = 3(2k +1) +5= 6k +8. For the converse, if 3n + 5 = 6k + 8 for some integer k, then 3n = 6k + 3 or 3n = 3(2k + 1) and n= 2k + 1 for some integer k, so n is an odd integer. If nis even, then n= 2k for some integer k. Then 3n + 2 = 3(2k) +2= 6k +2. For the converse, if 3n + 2 = 6k +2 for some integer k, then 3n = 6k and n = 2k for some integer k, so n is an even integer. Gersting Mathematical steuctures for computer Sctence rage 41 *20.1fx 0 (definition of <) (v+xy-x) >0 (factoring) (y+x) Oand (y-x)>0 But it cannot be that (y + x) <0 because y and x are both positive, therefore (y + x) > 0 and y - x > Oand y>x. 21, Let x2 + 2x - 3 =0 and assume that x= 2. Then 22 +2(2)-3=0 or 4+4-3=0 or 5=0 This is a contradiction, so x # 2. 22. Let x be a prime number with x = 2k, where k is an integer. Then both 2 and k divide x. Because x is prime, x is divisible only by itself and 1, so x= 2 and k= 1. Therefore x= 2. *23. Let x and y be divisible by n. Then x= kyn and y= kgn, where ky and kg are integers, and x+y =kyn-+ kpn = (ky + kg)n, where ky +k is an integer. Therefore x + y is divisible by n. 24, Proof by contraposition: if one of two integers is divisible by an integer n, then so is their product. Let x= kn where k is an integer. Then xy = (kn)y = (ky)n where ky is an integer. Therefore the product xy is divisible by n 25.n+ (n+ 1) +(n+2)=3n+3=3(n+ 1) *26. Let x= 2n+1. Then x2 = (2n + 1)? = 4n2 + 4n+ 1 =4n(n+ 1) +1. But n(n+ 1) is even (Exercise 13), so n(n+ 1) = 2k for some integer k. Therefore x2 =4(2k) + 1 = 8k + 1. 27. n3 - (n-1)3 = n3 - [n3 - 3n?2 + 3n- 1] = 3n2 - 3n + 1 =3n(n- 1) +1. Then n(n- 1) is even by Exercise 11, and 3n(n - 1) is even by the proof of Example 9, thus 3n(n- 1) +1 is odd. vage 42 Mathematical Structures for Computer Sclence Gersting 28. Proof by contradiction: assume that m2 + n 2 = k2 where m and n are odd integers and k isan integer. By Exercise 26, m2 = 8ky + 1 and n2 = 8kz + I for integers ky and kp, Therefore (ky + 1) + (8kz +1) =k2, or 2[4ky + 4k + 1] =k2. Then 2 divides k2, so 2 divides k, hence 4 is a factor of k?, which can be written as 4x. Therefore 2[4k] + 4kp +1] = 4x or 4ky + 4kq +1 =2x. This is a contradiction because 4ky + 4ky + 1 is odd while 2x is even, *29, m2n2 = (mn)2 30, Proof by cases, depending on whether x and y are positive, negative, or zero (it turns out to be a little neater to dispose of the zero case separately.) Case 1: x= 0 ory=0. Subcase a: x= 0, Then |x| =0, xy = 0, and jxy|= 0. Therefore [xy|= 0 = Oy] = [xly) Subcase b: y= 0. Similar to Subcase a. Case 2: x>0,y>0. Then |x|=x, ly|=y. Also, xy > 0 and [xy|=xy. Therefore fxy|= xy = [allyl -xy. Therefore [xy] Case 3: x <0, y>0. Then |x| =-x, ly|=y. Also, xy <0 and [xy = oxy = Cx)y = kxllyl Case 4: x>0,y <0. Then jx|=x, ly|=-y. Also, xy <0 and [xy] =-xy. Therefore Ixy] = xy =x(-y) = bly] Case 5: x<0,y <0. Then |x| =-x, ly|=-y. Also, xy > 0 and |xy| = xy. Therefore [xy| = xy = OX)C¥) = belly 31. Proof by cases, depending on whether x and y are negative. Case 1: x20, y20. Then |x| =x, lyl=y. Also, x+y > Oand fx +y|=x+ty. Therefore jx + y= x+y =x] + Iyl. Case 2: x20, y <0. Then |x| =x, ly|=-y. Subcase a: x+y20. Then |x +y|=x-+y. Therefore [x +yl=x+y

You might also like