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 0, x2 + 1 < 2x or x2 - 2x +1 2 x 43. Counterexample: 5 is prime, but 5 + 4 = 9 is not prime. 44, Proof n?—1=(n+ 1)(n— 1) where n— 1 > 1, which is a non-trivial factorization, so the number is not prime. *45. Counterexample: 4? + 4+ 1 = 21 = 3(7), not prime, 46. Counterexample: 9 = 2° + 1, and 9 = (3)(3), so is not prime, 47. Proof: let n= 2k with k > 1. Then 29 | = 22k - 1 = (2k)2- 1 = (2k + (2k - 1) Because k > 1, 2K - 1 > 1 and this is a non-trivial factorization, so 2" - | is not prime. 48, Proof. Let x and y be rational numbers, x = p/q, y= r/s with p, q, r,s integers and 4, 8, #0. Then xy = (p/q)(t/s) = pr/qs, where pr and qs are integers with qs # 0. Thus xy is rational. *49. Proof: Let x and y be rational numbers, x = p/q, y = 1/s with p,q, r, s integers and q, s# 0. Then x + y = p/q + 1/s = (ps + rq)/qs, where ps + rq and qs are integers with qs #0. Thus x-+ yis rational, 50. Counterexample: V2 is irrational but V2 x2 =2, which is rational. 51. Proof by contradiction: Let x be a rational number and y be an irrational number. Assume that x + y =r where r is a rational number. Then y = (-x) +r, which is the sum of two rational numbers. The sum of two rational numbers is rational [Exercise 44], so this is a contradiction, 52, Angle 3 plus Angle 4 sum to 180° by the third fact. Angle 3 plus (Angle 1 and Angle 2) sum to 180° by the first fact. Therefore Angle 4 = Angle 1 plus Angle 2 in size. +53. Angle 6 plus Angle 5 plus the right angle sum to 180° by the first fact. The right angle is 90° by the fourth fact. Therefore Angle 6 plus Angle 5 sum to 90°. Angle 6 is the same size as Angle 3 by the second fact. Therefore Angle 3 plus Angle 5 sum to 90° 54, Assume that Angle 1 and Angle 5 are the same size. As in Exercise 48, Angle 3 plus Angle 5 sum to 90°, Because Angle 1 and Angle 5 are the same size, Angle 3 plus Angle 1 sum to 90°, Also, Angle 3 plus Angle 1 plus Angle 2 sum to 180° by the first Gersting Mathematical Structures for Computer Science Page 45 fact. Therefore 90° plus Angle 2 sum to 180°, or Angle 2= 90°. Angle 2 is a right angle by the fourth fact. 55. The pairs are 1+ 100 = 101 2+99=101 50+51=101 ‘There are 50 such pairs, so the sum is 50(101) = 5050. EXERCISES 2.2 *1, P(1): 4(1)-2=2(1)? or 2=2 true Assume P(k): 2 +6 + 10+... + (4k - 2) = 2k2 Show P(k + 1):2+6+10+.... +[A(k + 1) -2]=2(k + 1)? 2464104... +[4(k+1)-2] left side of P(k + 1) = 2464104... +(4k-2)+ [4k + 1) -2] = 2k2+4(k+1)-2 using P(k) = 22+ 4k +2 = 2(k2+2k+1) = Ak+1)2 right side of P(k + 1) 2, PCI): 2=1(1+1) true ‘Assume P(k): 2+4+6 +... +2k=k(k +1) Show P(k +1): 24446... +2k+ I=(k+DIk+) +1] 244464... +2k4+1) left side of P(k + 1) 244464... 42k +2k +1) K(k +1) +2(k +1) using P(k) = k+)(k+2) factoring k+ DK +1) +1) right side of P(k + 1) *3. P(A): 1=1(2(1)-1) true Assume P(k): 1 +5 +9 +... + (4k -3)=k(2k 1) Show P(k +1); 145494... + [4k +1)-3]=(k+D2k+1)-1] 145494... 4[4k+1)-3] left side of P(k + 1) = 145494... +(4k-3)+ [4k + 1) -3] = k2k-1)+4(k+1)-3 using P(k) 2k2 -k+4k +1 2k2+3k+1 (k+DQk +1) (k+D[2k+ 1) - 1) right side of P(k + 1) Page 46 Mathematical Structures for Computer SeLence Gersting 4. 5. P(1): 1= 1(1 + 1) +296 = 2/6 true Assume P(k); 1 +3 +6+ +key). K(k + (k + 29/6 Show P(k + 1): 14+3 46+... + CADE — Gc nde aye 3y6 143+6+ 9 Re left side of P(k + 1) = 143-464, + KKHD K+ DK +2) 2 = kk + Dk + 26+ (KtDK+2) using P(k) - Kyl i = ce+ne+a[ Eo] factoring = e+ nace] | = (k+l +2, +396 right side of P(k + 1) P(1): 6-2= 1[3(1) +1] Assume P(k): 4+ 10+ 16 + Show P(k + 1): 4+ 10+ 16+... + [6(k + 1) -2]=(k+D[3(k+1)+ 1] 44104164... +[6(k+1)-2] left side of P(k + 1) 4+ 10416 +... + (6k-2) + [6(k +1) -2] KGk +1) + 6(k+1)-2 using P(k) 32 +k + 6k +4 = 3k2+7k+4 (k +1)Gk +4) k+DBK+D +1) right side of P(k + 1) . PCI): $=5(1 + 12 true Assume P(k): 5 +10 +15 +... + 5k =5k(k + 1/2 Show P(k + 1): 5+ 10415 +... +5(k+1)=S(k+ Ik + 2/2 SHIOFISH... #5(K +1) left side of P(k + 1) = S+10+15 +... +5k+5(k+1) = Sk(k+ 1/2 + 5(k +1) using P(k) = say] Eo] factoring = S(k+ Ik +2)/2 right side of P(k + 1) or write 5+10+15+...+5nas 5(1+2+3+... +n) and use the result of Practice 7. Gersting Mathematical Structures for Computer Science Page «7 1. ~ 3 P(1): 12= 1(1 + (2+ 1/6 true Assume P(k): 12 + 22 +... + k2=k(k + (2k + 1/6 Show P(k + 1): 12 +22 +... +(k+ 12 =(k+ Ik + 2)(2(k + 1) + D6 124224. +(k+1)2 left side of P(k + 1) = 124224. +k2+(k+ 12 = k(k+I(2k + 1/6 + (k+1)2 using P(k) = (k+ pf? k +] factoring 2 = kt of 1 shs] 6 = kt of +k *s) _ (K+ k+2)(2k-+3) 6 = (k+ Ik +2)(2k+ 1) + 1/6 right side of P(k + 1) P(1): 13 = 120 + 12/4 true Assume P(k): 3 + 23 +... + k3 = k2(k + 1)2/4 Show P(k + 1): B +23 +... + (k+ 13 =(k +)2%(k +2)2/4 B+23+..+(k+13 left side of P(k + 1) = B+234. 4+ +k +13 = kk + 1/2/44 (k +13 using P(k) = «+ vale ke | factoring = «+ meee) 4 = k+%K+ 224 right side of P(k + 1) PC): 12 = 12-12 + 1y3 true Assume P(k): 12 + 32 +... + (2k - 1)? = (2k - 1)(2k + 1)/3 Show P(k + 1); 12 +324... + [2k +1) - 1]2=(k+DQKk+t1)-DQk+N+ DB 124324... +[2(k+1)-1]2 left side of P(k + 1) = 124324. + (2k- 12 + [2k +1) -1]2 KOR-DCK+D Sook 4y—1P using P() Page 48 Mathematical Structures for Computer Sclence Gersting K@K-DCK+D yo 41? 3 = k+ »[H=2 2k? -k+6k+3 3 +2k “ factoring = @k+1) (2k +1)(2k? +5k +3) 3 = (2k + Ik + 12k +3y3 = kt DQK+1)- NAK+1)+ DB right side of P(k +1) 10. P(1): 14= 101 +1)(2+ NG +3-1/30=23-530 true Assume P(k): 14 +24 +... +k4 = k(k + 1)(2k + 1)(3k2 + 3k - 1)/30 Show P(k + 1): 14+244...+(k+1)4 = (K+ DK + 2k +1) + GK + 1)? +3(k #1) - 9/30 ik + 1)(k + 2)(2k + 3)(3k2 + 9k + 59/30 fl (2k2 + Tk + 6)(3k2 + 9k +5) = Khas + 39k3 + 91k2 + 89k +30) 14 424+. +(k+1)4 left side of P(k + 1) = 144244 +k tk + 4 = kk + 1)(2k +1)(3k2 + 3k - 1/30 + (k + 1)4 using P(k) 2 - = (kt p[eeeenge eon Doaen] factoring = rae + k)(BK2 + 3k- 1) +30(k +193] = eh ont 4+ 63 ~ 22 + 3k3 + 3K2- k-+30(K3 + 3k2 + 3k + 1)) = out +39k3 + 91k2 + 89k + 30) right side of P(k + 1) _ P(I): 13 = 12)(9/6 true Assume P(k): 1-32-44... #k(k +2) =k(k + Ik + 7/6 Show P(k +1): 13+24+ +(k+ I)k+3)=(k+ Ik +2)(2(k + 1) +76 134244 +(k+I)k+3) left side of P(k + 1) = 134244 +k(k+2) + (K+ Ik +3) = k(k + Ik + 16 + (k + 1)(k +3) using P(k) (k+ I)[k(2k + 7) + 6(k + 3/6 (k + I)(2k2 + 13k + 18/6 (k+ Dk +2)2k + 9/6 (k + 1)(k + 2)(2(k + 1) + 79/6 right side of P(k + 1) noon Gersting Mathematical Structures for Computer Science 12. *13, a'-1 PCI): a =2 =! ot a-l Assume P(k); 1+ a+ left side of P(k + 1) * using P(k) a‘ —1+a*(a-1) ani Leal! a 3 right side of P(k + 1) a 1 1 Po: 2 (): lla true 1 k As P(k) Cp ssume P(k) De 1 k+1 show P(k +1); 44.41 _- ke 722-3 (ka p(k+2) +2 Jy. 1 _ 3 (K+ IK +2) 1 left side of P(k + 1) 1:2 2 sot 2-3 K(k+1) (k+I(K+2) 1 k+l’ (kti(k42) using PC) k(k+2)+1 (K+ D(k+2) 242k 41 (ee (k+2) (k+1? (K+ 1(k+2) ke 1 wt = + 2 right side of P(k + 1) Page 49 Page 50 Mathematical Structures for Computer Science Gersting *15, true ot ek " @k-DQk+1) 2k+1 + 1 k+l " (k+)-DQKkK+D+1 '2k+NF1 1 1 ; 33° *Gaapopapr MRsdeofP&e +1) sat 1 +4 3 - Gk D@K+D * Gk+)-DAKHD+ 1 __ using P(k) 2k+1 (2k+1)(2k+3) k(2k+3)41 (2k +(2k+3) 2k? 4+3k+1 (2k+D@k+3) (k+D@k+1) (2k+1DQk+3) k+1 * 3KG3 right side of P(k + 1) PC): 12 = (-1)2(1)(2)/2 true Assume P(k): 12-22 +... + C12 = C1)dQk + 1/2 Show P(k + 1): 12-22 +... + -I)%(k + 1)2 = (17k + I)(k + 29/2 12-2244 (1% +192 left side of P(k + 1) = 12-224 + C12 + IK + 12 = CDE + 1/2 + CK + 2 using P(k) = (CDE +1) + 26k + 12/2 = (DK 2A + 1fk(-1)7! + 2k + IV2 = EDK 2+ DEK + 2k + 2Y2 = DKK + K+ 22 right side of P(k + 1) P(1): 2-3°=3'-1 or2=3-1 true Assume P(k): 2+6+18+ ...+2-3*1=3K-1 Show P(k + 1):2+64+18+ ...+2-3K=3"121 2+6+18+ ...+2-3* left side of P(k + 1) = 2464184. +2-3142.38 = 3k-14+2-3* using P(k) 3.3K-1 3K] right side of P(k + 1) Gereting Mathematical Structures for Computer Setence Page 51 17. PCI): 22 = (2)(1)(2)(2 + 13. or 4 = (2\(6Y/3 true Assume P(k): 22 + 42 +... + (2k)? = 2k(k + 1)(2k + 1/3 Show P(k + 1): 22 +42 +... + [2k + IJ? = 2k + IK + 2)[2k + 1) + 13 224424. +[22k+ 2 left side of P(k + 1) = 224424... + (2k2 + [2k + 2 2k(k + 12k + 13+ [2k +1)? using P(k) 2k + DL k(2k + 1y3 + 2k + 1] 2k + Ifk(2k + 1) + 6(k + V3 2k + 1)[2k2 + 7k + 6Y3 2k + 1)(k + 2)(2k +33 = Ak+ Nk + 2[Ak +1) +1] B right side of P(k + 1) 18. P(1):1-2'=(1 12!" 42 ‘me Assume P(K) 1-2'42-2243-284..-4k-2= (koh +2 Show P(k-+ 1): 1-2'+2-274+3-24..-+(k+1)- 21 = gah 42 12842-2743. 4.0 +(e +1) 2 Ie side of Pk +1) = 1-2842-2743-2 +.--+ke H+ (kt 1) 2 = (k= 121424 kt+1)- 29 using P(k) = Hk 1) +k + +2 factoring put = 2k) +2 Or? right side of P(k + 1) 19. PC): 1-2 =(NQGY3 me Assume P(k): 1-2+2-343-44...+k(K+L D+) Show PQ 1):1-242-343-44.. +(e Ika) = EDS +9, 1-242-343-44... +(k+1(k+2) = left side of P(k + 1) = 1-242-343-44 tk +I ++ Dk +2) a +(k+1)k+2) using P(k) = (k+ IK + 2)[k/3 +1] “ wene+2(S*) right side of P(k + 1) 20. PC) 12.3 = OO we Assume P(k) 1e2.342-3-4b ect k(e# IG 2) = MEADE LAE) Page 52 Mathematical Structures for Computer Science Gersting Show P(k +1): 1-2-3+2-3-4+---+(k+1)k+2)(k +3) _k+ Ik + 2k + 3k +4) 4 1-2-342-3-44.--+(k+ Ik +2K+3) left side of Pk + 1) = 162-342-344. UK + IK + 2)+ (K+ Ik + 2K +3) Hanes) + (k++ 2k +3) using P(k) = K+ K+ K+ af* + ‘| = (kt Ik + 2k + [4] AURA right side of P(k + 1) a1. pay, t=! true . 1-4 3 ml Assume P(k): —— ty 4 ke M “E7710 wo Gk-DGK+D 341 Show P(k +1): 14 4+———__1____-_kl ra a7 ‘a0 " KAD-2]EKADAN 3k +1 1 + —— | ___jeft side of P(k+1) Gk +)-]EK+D+1 ety 14° 4:77:10 Gk-2GK+) G(k+1)—DHEK+1) +1) _ ok 1 . © 3s" Gk+)-DEK+D+D using PO) _ ok 1 Fee” Gk GK 4) _ _kGk+4)41 Gk +DGK+4) _ 3K 4k +1 Gk+DGkK+4) = Gk+Dk+) __k+! right side of Pk + 1) QGk+)Gk+4) 3(k+1)+1 22, P(A): Lel!=2!-Lor1=2-1 true Assume P(k): Tel! +..¢ kk! =(k+ 1)! -1 Show P(k #1): LI! +. (k+ Ik + DI = (k +2)! -1 Gereting Mathematical Structures for Computer Science Page 53 Tl +k + Dk + 1! left side of P(k + 1) Ll +... tkkI+(k+ Dik +)! k+DI-1+k+ D+ D! using P(k) (e+ +k+1)-1 (k+1)k+2)-1 (k+2)!-1 right side of P(k + 1) ¥23.P(1); a= So 8-9) true I-r rt Assume P(k): atar+...tar®! = Show P(k + 1): atart...tar* atar+ +ark left side of P(k + 1) = atart +ark-l+ark oat = asta using P(k) =r 25. a-ar* +ar‘(1-r) right side of P(k + 1) (I): a= Fea) true Assume P(k): a+ (a+d)+ +[a+(k-1)d]= [£] [2a+(k- 1d] Show P(k + 1): a+ (a+d)+ tatnay=[Kt "Yana at(atd)+..4fa+kd] left side of P(k + 1) = at(atd)+ +[a+(k-1)d]+[at+kd] = [Eies+ o-oo using P(k) = [E Jess e- ays Ze Dhark'd-kds 204 2k 2 k(2a+kd) +(2a+kd) 2 - a Dera+kdy right side of P(k + 1) a. Geometric progression with a = 2, r= 5, n= 10, Sum = (2 - 2(5"°))/(1-5) = 4,882,812 Page 54 Mathematical Structures for Computer Science Gersting b. Rewrite with an additional term of 4 in the front: 4+4-74+4- 744-7 +...44-7? Geometric progression with a= 4, r=7,n= 13. Sum=[ (4-4(7)"V(1-7)]-4 (subtract the 4 we added) = 64,592,673,600 c. Rewrite as 1 +(1+6)+(1+2-6) +... +(1+8-6). Arithmetic progression with a=1,d=6,n=9. Sum =(9/2)[2(1) + 8(6)] = 225 d. Rewrite as 12 + (12 +5) + (12+ 2:5) + (12+ 3-5) +... +(12 + 16:5). Arithmetic progression with a= 12, d=5,n=17. Sum =(17/2)[24 + 16(5)] = 884 26. The base case is still P(1) because 1 is the smallest positive odd integer. -2? - PCA): (2)0+(-2)1 = E 2 or 1-2= “4 true ke Assume P(k) where k is odd: (-2)0 + (-2)1 + (-2)2 + ... +2) = be The next odd integer is k +2. Show P(k + 2): (-2)9 + (-2)! + (-2)2 +... + (2) -2)0 + (2)! + (-2)2 +... + C2)? left side of P(k + 2) = (-2)0+ 2) + -2)2 + 0, + 2K + C2) + (2)? ao = EE + ahs (aye? using P(k) pk = +h 2k? because, since k is odd, k +1 is even and k + 2 is odd et 43.2) 3. gk? 142.28! 3.22 3 peg? 3.9? = right side of P(k + 2) 27. P(@): 32> 2(3) +3 or 929 true Assume P(k): k2 > 2k +3 Show P(k + 1): (k + 1)2 2 2(k +1) +3 (k+12 left side of P(k + 1) = k2+2k+1 > (2k+3)+2k+1 using P(k) = 2k+2k+4 > 2k+6+4 because k > 3 Gersting Mathematical Structures for Computer Science Page 95 > 2k+5 = Ak+1)+3 *28, P(2): 22>2+1 ‘Assume P(k): k2 >k +1 Show P(k + 1): (k+ 1)? >k +2 (k+ 1 k2+2k+1 (k+1)+2k+1 3k+2 k+2 vuv 29. P(7): 72 > 5-7 + 10 or 49 > 45 Assume P(k): k2 > Sk + 10 right side of Pk + 1) true left side of P(k + 1) using P(k) right side of P(k + 1) true Show P(k + 1): (k + 1)2 > S(k + 1) + 10= 5k +15 (k+ 12 k24+2k+1 (5k +10) + 2k +1 Tk+ 6k+k+I1 6k +17 Sk +15 vv wivo 30, P(5): 32> 25 Assume P(k): 2K > k2 Show P(k + 1): 2k+1 > (k + 1)2 2k+1 22k 2k2 k2 +42 k2 43k k2+2k+k k24+2k+1 +1? v 4 uv nv 3 P(4): 4! > 42 or 1:2:3-4= 24 >16 Assume P(k): k! > k2 Show P(k + 1): (k + I)! > (k + 1)2 left side of P(k + 1) using P(k) because k > 6 right side of P(k + 1) true left side of P(k + 1) using P(k) by Example 18 because k > 1 right side of P(k + 1) true Page 56 3: 8 #33, 34, 35, k+1! kk +1) kk +1) (k+ Ik +1) (k+1)2 ivy P(7): 7! > 37 or 5040 > 2187 Assume P(k): k! > 3* Show P(k + 1): (k + 1)!>3*? k+D! =kk+1) >3'(k+1) : 230) P(4): 24 <4! or 16 <24 ‘Assume P(k): 2K < kt Show P(k + 1); 2K+1 <(k +1)! k+1 22k 2k! (k+ Dk! (k+1)! WAAW P(I): 2° <1! Assume P(k): 2k-1 4 right side of P(k + 1) true left side of P(k + 1) using P(k) because k= 7 right side of P(k + 1) true left side of P(k + 1) using P(k) because k > 4 right side of P(k + 1) true left side of P(k + 1) using P(k) because k> 1 ork +122 right side of P(k + 1) true left side of P(k + 1) using P(k) Gersting Mathenatical Structures for Computer Science Page 57 < (kt Ik+ DK = + nk right side of P(k + 1) An alternate proof is: n(n —1)(n—2)-+-3-2 «1 1+x2 or 1+2x+x2>1+-x2 true because x > 0 implies 2x > 0 Assume P(k): (1 + x)K > 1 + xk Show P(k + 1): (1+ x)K+1 > 1+ xkt1 (i+ xktl left side of P(k + 1) = (+xk+x) > (+xka+x) using P(k) = Ltxk+x+xkt > 1+xktH because xk +x >0 ay a aa 37. P(1); (3)

0, b > 0, we get aa < ab and then aab < ab. Di positive numbers b and b, we get aoab? at a a

4..+ <2 w Pk + I+ > p< iT 1+ ; +. ooh left side of P(k + 1) = i¢te ete 2 - < 2+ or using P(k) but 2+ 1 is not less than 2. ¥ 1 1 b. P(l): 1+—=2-= (1): 2 2 true 1 1 As: P(k): l+ =+..4+—> sume P(k): 1+ > # Show P(k + 1); Le hte =2 using P(k) 40. Prove that 144414. 23 1 1 P(I): 14-2 14— (+> 2 Assume P(k) 1+ b44 4.44 e14k 23 2 2 show Pk+ 1): 1+t4444 coi ket 23 2 2 left side of P(k + 1) 1 +1 +2 oY these denominators count from 2" up to 2**!, a total of 2°! — 2* = 24(2 — 1) = 2* terms Gersting Mathematical Structures for Computer Setence Page 59 “41, 42, 43 44, using P(k) because each denominator is < 2"! right side of P(k+1) P(1); 23-1=8-1=7and7|7 true Assume P(k): 7| 23k - 1 so 23K - 1 = 7m or 23K = 7m + 1 for some integer m Show P(k + 1): 7|23(k+1) - 1 23(k+1) - | = 23k+3 - | = 23k.23 (7m + 123-1 using P(k) 723m) +8-1 = 7(23m+ 1) where 23m + 1 is an integer, so 7|23(K+1) - 1 P(1):324+7=9+7=16and8|16 true Assume P(k): 8|32K +7 so 32k + 7 = 8m or 32k = 8m - 7 for some integer m Show P(k + 1): 8|32(k+1) +7 32(k+1) +7 = 32k+2 +7 = 32k 32 47 = (8m-7)9+7 using P(k) 8(9m) - 63 + 7 = 8(9m) - 56 8(9m - 7) where 9m - 7 is an integer, so 8|32(K+1) +7 P(I): 7-2=Sand5|5 true Assume P(k): 5| 7k - 2k so 7k - 2k = Sm or 7k = Sm + 2k for some integer m Show P(k + 1): 5| 7k#1 - 2k+1 qkH k+l = 7.7K. 2k+1 = 7(5m + 2k) - 2k+ using P(k) 5(7m) + 2K(7 - 2) = 5(7m+ 2k) where 7m + 2k is an integer, so 5| 7K+1 - 2k+1 P(1): 13-6=7 and 7|7 true Assume P(k): 7| 13 - 6k so 13k - 6K = 7m or 13k = 7m + 6 for some integer m Show P(k + 1): 7] 13K+1 - 6k+1 Page 60 Mathenatical Structures for Computer Science Gersting 13k+1 . gk+1 = 13(13k) - okt] = 13(7m+ 6k) - 6k+1 using P(k) 7(13m) + 6K(13 - 6) 7(13m + 6k) where 13m + 6k is an integer, so 7| 13K*1 - 6k+1 #45, P(1): 2+ (-1)2=2+1=3 and 3/3 true Assume P(k): 3 |2K + (-1)K*1 s0 2k + (-1)+1 = 3m or 2k = 3m - (-1)K*1 for some integer m Show P(k + 1): 3] 2k+1 + (-1yk+2 2+] + (-1)k+2 = 2.9k + (-1)k42 = 23m-(-1)K* + (-1)k+2 using P(k) 3(2m) - 2-1) +1 + -1yk+2 32m) + -DK1C2 +1) 32m) + (-1)K*1 (-3) 3(2m - (-1)K*1) where 2m - (-1)K+1 is an integer, so 3 2K+1 + (-1yk+2 a & P(I); 2541 + 5142 = 26 + 53 = 64 + 125 = 189 =27-7 and 2727-7 true Assume P(k): 27| 25k+1 + 5k+2 go 25k+1 + 5k+2 = 27m or 25k+1 = 27m - $k*2 for some integer m Show P(k + 1): 27] 25(k+1)+1 + s(kH)+2 25(k+1)H 4 5(k+1)+2 = 25k+145 4 sk+3 = 25k+1.254 5k+3 = (27m- 5k+2)25 + skt+3 using P(k) 27(m25) « 5k+2.25 + sk+2.5 27(m25) + Sk+2(5 - 25) 27(m25) + 5k*2(-27) 27(m25 - 5k*2) where m25- Sk*2 is an integer, so 27| 25(k+1)+1 + 5(k+1)+2 P(1); 3442 + 52+] = 36 + 53 = 729 + 125 = 854 =61-14 and 14|61-14 true Assume P(k): 14|34k+2 + 52k+1 go 34k+ 2 + 52k+1 = 14m or 34K42 = 14m - 52k+1 for some integer m Show P(k + 1): 14] 34(k+1)+2 + 52(k+1)+1 4 3 3ACKH)+2 4 52(KH)HL = 34k+2.34 4 52k43 = (lam - S2k+34 + 52k+3 using P(k) = 14(m34) - 52k+1.34 4 52k+1.52 14(m34y - 52k+1 (34. 52) = 14(m34) - 52k+1(g1 - 25) 14(m34) - 52k+1(56) 14(m34 - 4.52k+1) where m34 - 4-52k+] js an integer, so 14 | 34(Kk+1)+2 + 52(KH)+1 Gersting Mathematical Structures for Computer Selence Page 61 48, P(1): 72 + 16-1 = 49 + 15 = 64 and 64/64 true Assume P(k): 64| 72K + 16k - 1 so 72K + 16k - 1 = 64m or 72k = 64m - 16k + 1 for some integer m Show P(k + 1): 64|72k+1) + 16(k + 1)-1 TUk+) + 16(k + 1)-1=72K.72 + 16k + 1)-1 (64m - 16k +1)-72 + 16(k + 1) -1 using P(k) 64(m72) - 16k-72 + 16k + 72 + 16 64(m72) + 16k (1 - 72) + 64 = 64(m72 + 1) + 16k(-48) = 64(m72 + 1 - 12k) where m72 + 1 - [2k is an integer, so 64| 72(K+1) + 16(k + 1) - 1 *49, P(I): 10 +3-43 +5 = 10+ 192+ 5=207=9.23 true Assume P(k): 9| 10K + 3.4K +2 + 5 so 10k + 3.4k+2 + 5 = 9m or 10K = 9m - 3-4k+2- 5 for some integer m Show P(k + 1): 9] 10K+1 + 3.4k+3 +5 1ok+1 + 3.4k+3 + 5 = 10-10k+ 3.4k+3 + 5 = 109m - 3-4k+2 - 5) +3.4k+3 45 using P(k) 9(10m) - 30-4k+2 - 50 + 3-4k+2.4 +5 = 9(10m) - 45 - 3-4k+2(10 - 4) = 9(10m - 5) - 18-4k+2 = 910m - 5 - 2-4k+2) where 10m - 5 - 2-4k+2 is an integer, so 9| 10K+1 + 3.4k+3 +5 50, P(1): 13-1=0 and 3/0 true Assume P(k): 3k3 -k or k3 - k = 3m for some integer n Show P(k + 1): 3(k + 13 -(k +1) (k +13 -(k + 1) = (3 + 3k2 + 3k + 1)-(k +1) = B-k+3(k2 +k) 3m + 3(k2 +k) using P(k) 3(m + k2 +k) where m+ k2 +k is an integer, so 3\(k + 1)3 - (k + 1) 51. P(1): 13 + 2(1) =3 and 3/3 true Assume P(k): 3|k3 + 2k so k3 + 2k = 3m for some integer m Show P(k + 1): 3](k + 1)3 + 2(k + 1) (k+ 13 +2(k +1) =k3 +3k2 43k +1+2k+2 K3 +2k+3(k2+k+1) 3m +3(k2+k+1) using P(k) = 3(m+k2+k+1) where m+k2 +k +1 is an integer, so 3(k + 1)3 + 2(k + 1) Page 62 Mathematical structures for Computer Science Gereting This result also follows directly from Exercise 45: n3 + 2n=n3 - n+ 3n=3m + 3n (by Exercise 45) = 3(m +n) 52. P(1): x! - 1 is divisible by x- 1 true Assume P(k): xk - 1 is divisible by x - 1, so xk - 1 = (x - 1)q(x) for some polynomial q(x), or xK = (x - 1)q(x) +1 Show P(k + 1): xk+1 ..1 is divisible by x -1 xktl 1 =x xk- 1 =x((x-Dq(x) + 1)-1 using P(k) = (x-Dpxq@o] +x-1 = (x-D[xq(x) + 1] where xq(x) + 1 is a polynomial, so x - 1 divides xk! - *53. P(1): cos 0 + i sin @ = cos @ +i sin @ true Assume P(k): (cos 0 +i sin @)K = cos kO +i sin kO Show P(k + 1): (cos 0 +i sin @)K+1 = cos (k+1)0+ i sin (k+1)0 (cos 6 +i sin 8)K+1 = (cos 6 + i sin 8)K(cos 6 + i sin 8) = (cos k +i sin k0)(cos 6 + i sin 8) using P(k) cos k8cos 8 + i sin k6cos 6 +i cos kOsin 8 + i2 sin kOsin cos k8cos 0 - sin k@sin @ + i(sin kOcos @ + cos kOsin 8) " cos (k0 + 8) + i sin (kO +6) 54, P(1): sin@ = 50-8 true sin Assume P(k): sin 9 + sin 30 +. sin (2k - 1) = sale sin Show P(k + 1): sin @ +... + sin 2k + yp = S408 sin sin @ +... + sin (2k+1)0 = sing + + sin (2k 1)8 + sin 2k +18 = anlko te + sin (2k + 1)8 using P(k) sin _ sin’ 0+ sin sin(2k + DO sin ___ sin? kO + sin sin(2k0-+0) sin@ __ sin? k0 + sin 0(sin 2k0 cos0 + cos2k0 sin) sin@ _ Sin? kO +2sin @ sink cosk® cos® + cos2k@ sin” 6 sin® sin? k0 +(cos* kO - sin’ kO) sin? 6 + 2sin @ sin k@ cosk@ cosO sin® Gersting Mathematical Structures for Computer Science Page 63 sin? k@ + cos’ kO sin’ 0 — sin’ kO sin? @ +2sin O sin kO cosk0 cos sind _ sin? kO(1~ sin? @) + cos” k@ sin? 6 +2 sin@ sin k@ cosk® cos0 sind = _ Sin? k@ cos’ 6 +.cos’ k0 sin” @ +2 sin sin k@ cosk0 cos0 sin® _ [sin k@cos0 + cosk@sin0)? sind _ [sin(ko +6) sind = Sin'k+ 0 right side of P(k + 1) sind +55, The statement to be proved is that n(n + 1)(n + 2) is divisible by 3 for n> 1 P(l): 1(1 +1) + 2) = 6 is divisible by 3 true Assume P(k): k(k + I)(k + 2) = 3m for some integer m. Show P(k + 1): (k + I\(k + 2)(k + 3) is divisible by 3 (k + I)(k + 2)(k +3) = (k + Ik + 2)k + (k + INK +293 3m + (k + Ik +2)3 using P(k) 3[m + (k + N(k + 2)] 56, Let n be fixed but arbitrary and show x "x ™=x 2M for all m> 1 Let xd - x = xi*! be equation (1). m=I1: xM.xl= xntl py (1) Assume xl xk = xntk Then x. xk+1 = xn. xk. x by (1) =xmtk. x by the inductive assumption = x+k+ by (1) : anit 58. Trial and error shows that it is not possible to tile a 3 x 3 board. 59. Proof by induction on n. P(1) is true because 1 line divides the plane into 2 regions, and (I? + 1 + 2/2 = 2, Assume that P(k) is true: k lines divide the plane into (k? + k + 2)/2 regions. Show P(k + 1), that k + 1 lines divide the plane into [(k + 1)? + (k + 1) + 2/2 regions. Page 64 Mathematical Structures for Computer Seience Gersting As an illustration, consider what happens when we go from 2 lines to 3. Initially there are 4 regions in the plane (figure a). As we draw the third line, by the time it intersects one of the two original lines, it has split one of the original regions into 2, thus adding one new region (figure b). By the time it hits the second and last line, another region has been added (figure c). And after it leaves the last line, a final new region is added (igure d), @ (b) © @ A new line therefore creates one more region than the number of lines it crosses. ‘When line k + 1 is added, it will cross k lines (since no two lines are parallel and have no common intersection points). Therefore k + 1 new regions are created. The total number of regions is therefore k + 1 more than the number present with k lines, or Heke? bee D4 2H) 4G _ EAP HD +2 +1 2 2 2 60. Proofs by induction on the length of the string. For a string of two characters, the single processed character could be 0 or 1. Ifitis 0, the parity bit stays 0, and the total number of Is is zero, an even number. Ifit is 1, the parity bit switches from 0 to 1, and the total number of Is is two, an even number. Now assume that a string of k characters contains an even number of Is. Ak + I-length string is a k-length string with one new processed character. There are four cases: New character Old parity bit New parity bit 1 0 0 0 2. 0 1 1 3 1 0 1 4. 1 1 0 In cases (1) and (2) no 1s are added, so the total number of Is remains the same as before, an even number. In case (3), the total number of 1s is increased by two, so it is still an even number. In case (4), a | is added and a 1 is removed, so the total number of Is remains the same as before, an even number. *61.P()) is 1= 1 + 1 which is not true. Gereting Mathematical Structures for Computer Science Page 65 62. The brief explanation is that P(k) —> P(k + 1) fails when k = 1. Students find this problem quite difficult, so here is a more detailed discussion. P(1) is obviously true; any set consisting of just one machine has the property that all machines in that set have the same manufacturer. Assume P(k): in ANY set of k computers, all have the same manufacturer. Show P(k + 1): in ANY set of k + 1 computers, all have the same manufacturer. The fallacious argument goes like this: Assume P(k). Now consider any set of k + 1 machines Remove one, leaving a set of k. Then by P(k), all have the same manufacturer (so make them all uppercase X): ‘Now put the one back in and remove a different one, again leaving a set of k machines: Page 66 Mathematical structures for Computer Science Gereting By P(k), these k machines must all have the same manufacturer. Therefore (****) the original Hal (lowercase above) must be uppercase like the rest: and therefore all are made by the same manufacturer. OK, where does this fail? Look at the sentence above with ****, What forces Hal to ‘turn uppercase is the "overlap" — those machines that are not Hal and not the other singled-out machine: = What if there is no overlap, ie., what if Then when you take the other machine there is just Hal and the other machine? out, Hal can be anything at all CO) So this "proof” fails when k + 1 equals 2. In other words, the implication P(1) > P2) does not work. But FOR ALL OTHER CASES, the implication is true. That is, P(2) > P(3), P(3) > P(4), etc, — these are all true. Using the ladder-climbing analogy, wwe can get to the first rung (P(1) is true) and we can get from the 2"! rung to the 3", from the 3" rung to the 4", etc., but we can't get from the 1" rung to the second, so that's the hole. Gersting Mathematical Structures for Computer Science Page 67 63a. Let P(n) be the property that any word composed of a juxtaposition of n subwords has an even number of o's, Then P(1) is true because the only words with 1 subword are the words moon, noon, and soon, all of which have 2 o's. Assume that, P(k) is true and consider P(k+1). For any word composed of k + 1 subwords, break the word into two parts compoased of k subwords and 1 subword. By the inductive hypothesis, the part with k subwords has an even number m of o's. The part with 1 subword has 2 o's. The total number of o's is therefore m + 2, an even number. This verifies P(k + 1) and completes the proof. Let P(n) be the property that any word composed of a juxtaposition of n subwords has an even number of o's. Then P(1) is true because the only words with 1 subword are the words moon, noon, and soon, all of which have 2 o's. Assume that P(t) is true for all r, 1 (Q), where P has r; symbols, 1 4, so that (k + 1) - 22 and by the inductive hypothesis can be written as a sum of 2's and 3's, Adding an additional 2 gives k + 1 as a sum of 2's and 3's 67. P(12), P(13), P(14), and P(15) are true by the equations 12=44+4+4 13=44+4+5 14=54+5+4 15=54+5+5 ‘Now assume that P(r) is true for any r, 12 16, so that (k + 1) - 4 > 12 and by the inductive hypothesis can be written as a sum of 4's and 5's. Adding an additional 4 gives k + 1 as a sum of 4's and S's. 68, P(14), P(15), and P(16) are true by the equations 1 S+3+3 L 34+3+34343 16=8+8 Now assume that P(0) is true for any r, 14 69, so that (k + 1) - 5 > 64 and by the inductive hypothesis can be written as a sum of 5's and 17's. Adding an additional 5 gives k + 1 asa sum of 5's and 17's, 70. Clearly the $20 can be generated. Let P(n) be the statement that $n(10) can be generated using only $20 and $50 bills, and prove P(n) for n > 4. P(4) and P(5) are true by the equations P(4): $40 = $20 + $20 P(S): $50 ‘Now assume that P(r) is true for any r, 4 6, so that (k + 1)-2 > 4 and by the inductive hypothesis, ${(k + 1) ~2](10) can be generated using only $20 and $50 bills. Therefore $(k + 1)(10) can be generated by adding another $20 bill 71. The formula is P(k) = k(k - 1)/2. When k = 1, zero handshakes are performed, and P(1) = (1 - 1/2 =0, Assume P(k) = k(k - 1)/2, and consider a group of k + 1 people. Identify person x and remove him from the group. The remaining group of k people performs (by inductive hypothesis) k(k - 1)/2 handshakes. Ifx shakes hands with each of these k people, all of the handshaking will be done. The number of handshakes is therefore kk - 12 +k=k(k- 1/2 +2K/2 = (k2-k + 2k/2 =(+ky/2 =(k+1)k/2=P(k+1) EXERCISES 2.3 ik Show Q(k +1): finer = Guus)? Jaor = He +25, 41 At loop termination, Page 70 Mathematical Structures for Computer Setence Gersting *2. QQ): in=(o—D! true since j= 1, i= 2 before loop is entered and 1 = 1! Assume Q(k): j, = (i, -D! Show Qk +1): jen = Gi -D! Jaa = hig = Ge - Di =)! Ges —D! At loop termination, j = (i -1)! and i=x +1 soj=x! 3. QO): jy=x* true since j = x, i= 1 before loop is entered Assume Q(k): jy Show Qk +1): gy =x dna dee X= xh xx At loop termination, j= x! and i= y so j=xY 4. QO): x= quy +1, true since q = 0, =x before loop is entered Assume Q(k): x= quy+h Show Q(k +1): X= qua +a Wea + he = (Ge +DY +H Y= GY +H HX At loop termination, x= qy + rand 0 3. F(k +4) =F(k +2) +F(k +3) recurrence relation 2F(k) + F(k - 1) + 2F(k + 1) + Fk) inductive hypothesis 2[F(k) + F(k + 1)] + [Fk - 1) + F()] = 2Fk+2)+Fk+1) recurrence relation true F(8) = 4F(5) + F(2) or 21 true Assume for all r, 1 < sk, F(t + 6) = 4F(r + 3) + F(®) Show that F(k + 7) = 4F(k + 4) + F(k + 1) where k +123 Fk +7) =F(k +5) +F(k + 6) recurrence relation AF(k + 2) + F(k- 1) + 4F(k+3)+F(k) inductive hypothesis ALF (k + 2) + F(k + 3)] + [F(k- 1) + F(K)] = 4F(k +4) + F(k+ 1) recurrence relation 22.n=1: F(1)<2 or 1<2 true n=2: F(2)<22 or 1<4 true Assume for all r, 1 < r< k, F(t) <2 Show that F(k + 1) <2k+] where k+ 123. F(k + 1)=F(k- 1) + F(k) recurrence relation Gersting Mathematical Structures for Computer Science Page 75 < 2kl 42k inductive hypothesis = 21 +2) = 302K 1) < a(ak-ly = 22(ak 1) = 2k+1 2: . n=6: F(6)> ) or 8 > 7,594, true ay n=7: F()> (3) or 13 > 11.39, true ‘Assume for all r, 6 <1- @) Show har FO 1)> (3) wherek +1 2850-126 ae im J -@ 2 t-3)-2 O-O GO 0-2 @G-@ 24a. p? aev5y 1+2V5+5 _6+2V5 _3+V5_ 2 145 = 1425 45 6 F2N5 4S step 2 4 202 2 The proof that 1 + q=q? is similar. b. n=1: FO)=P-4=1 true p-4 2 _ n=2; FQy= BAH O- MPH) _ yg LVS IVS 2 true p-q p-q 2 Assume for all r, 1s sk, F()= 2—* P-q Show that F(k + 1) Pd where k +123. 4 Fk +1) =F(k- 1) +F()= c. Substitute the expressions for p and q into the formula in part b and carry out algebraic manipulations, Page 76 Mathematical Structures for Conputer Sclence Gersting S(0)=1 is odd : S(1)= 1 is odd Assume for all r, 0 6 S(k + 1) = 28(k) + S(k-1) recurrence relation <2[68(k — 2)] + 6S(k - 3) inductive hypothesis = 6[2S(k ~ 2) + S(k- 3)] = 68(k- 1) sy 26.n=0: T(0)< (3) ors true n=1 taps ($) ass true Assume for all r, 0 4 Gersting Mathematical Structures for Computer Science Page 77 L(k + 1) =L(k) + L(k- 1) recurrence relation = F(k) + F(k-2) + F(k- 1) + F(k-3) inductive hypothesis = F(k) + F(k- 1) + F(k-2) + F(k-3) =F(k +1) + F(k-1) 28. No; the next value in the sequence, A(5), equals 4*2° + 1 = 33, which is not a Fibonacci number. *29.Yes, this sequence continues to generate all of the Fibonacci numbers; this is true because of Exercise 16: F(l) + F(2) + ...+ F(n) = F(n + 2) - 1, or 1+F() + FQ) +...+F(n) =F(n +2) 30. No. The next value in the sequence, C(6), is 8, which is in the Fibonacci sequence. eoccee focce odfoce cocde cod ects de But the next value in this sequence, C(7), is 12, which is not in the Fibonacci sequence: eccccce dbeoce ccvcce 31. Yes, this sequence continues to generate all the Fibonacci numbers. To paint an (n+ 1)-story building, there are two cases. If floor n + 1 is painted yellow, then the remaining n floors can be painted in any of D(n) ways. If floor n+ i is pointed blue, then floor n must be painted yellow; the remaining n - 1 floors can be painted in any of D(n- 1) ways. Hence D(n + 1) = D(n) + D(a - 1), which is the formula for the Fibonacci sequence. 32, F(1) = F(2)= 1 because the rabbits do not breed until they are two months old. F(n) = the number of pairs at the end of n months = (the number of pairs at the end ofn - 1 months) + (the number of offspring pairs produced during month n, born to the pairs existing at month n - 2) =F(n- 1) + F(n-2) 33. CQ)= yee =NCQ-) = COCW)+CWCO) =1*14141=2 cos c@)= YCE-NCEC-# = COCE)+CHCH +CQCO) =1*241*142*1=5 Page 78 Mathematical Structures for Conputer ScLence Gersting (4) = V.CE-DCE-H = CONE) + CHCA) +CQVCH)+CO)CO SI*S+142424145*1=14 434. S(I)=a S(n)=1S(n- 1) forn>2 35. S(I)=a S(n)=S(n- 1) +d forn>2 0,000 3A(n- 1) forn>2 37.a. P() = 500 (.1)P(n - 1) forn>2 b 4 38, bande 39.a,b, ¢, f and g *40 a,b, ande 41. a,b, andd *42.1. Any unary predicate in x is a wif. 2. IfP and Q are unary predicate wits in x, so are (P A Q), (P v Q), (P > Q), ), (P einteger> ::= { 49. ::= 0|1|2)3}4|516)718(9 ::= | = +|- ::= || #50, 11=1 nl=n(n-1)! forn>2 SI. m+0 m+n=m+(n-1)+1 forn2 1 a, ifa,>a, a, if a 2 a, ifa, Sa, 52. a. rota.) ={ b. min(a,,a,) { « a, if a, >a, min(a,,...,a,) = min(min(a,,...,a,),2,) forn >2 53. a, A] A An defined as in Section 1.1 ALA AAn=(ALA.. A Ant) A An forn>2 (1) b. Foranynwithn>3 and any p with 1 By' A By’ Assume that By v... VB)! > By' A... AB. Then Biv vBu+y)'= [81 v..V By v Bar 2B] Vv... V Bu) A Busy’ By A... ABR) ABH! = By A... ABgsy! The proof of the other statement is similar. =1 then return 1 else return 3*S(n - 1) end if by equation (1) by equivalence 2b by inductive hypothesis, by equation (1) by equivalence 3a by Exercise 52 by equivalence 3a by inductive hypothesis by Exercise 52 by DeMorgan's Laws by the recursive definition of disjunction by DeMorgan’s Law by inductive hypothesis by Exercise 41 Gersting Mathematical Structures for Computer Science 57. ifn = 1 then return 2 else return S(n - 1)/2 end if *58. ifn = 1 then return 1 else return S(n = 1) + (n- 1) end if 59, ifn=1 then return 2 else return S(n - 1)*S(n - 1) end if 60. ifn=1 then return a else ifn=2 then return b else return S(n - 2) + S(n- 1) end if end if +61, ifn=1 then retum p else if odd(n) then return S(n- 1) +(n- 1)*q else return S(n - 1) = (n= 1)*q end if end if 62, Mystery(n) =n 63. g returns the value 0 if x is not in the list, and the value 10 if x is in the list Page 81 *64. If the list has 1 element or 0 elements, then we are done, else exchange the first and last element in the list and invoke the algorithm on the list minus its first and last elements. 65. If the number is less than 10, the sum is the single digit, else divide the number by 10, and add the remainder to the result of invoking the algorithm on the quotient. 66. Divide a by b. If the remainder r is 0, then ged(a, b) = b, else invoke the algorithm on b and r instead of a and b. Page 82 Mathematical Structures for Computer Science Gersting 67. If the stack contains one disk, move it to the target peg. Otherwise, invoke the algorithm on the top n ~ 1 disks to stack them on order on the third peg, move the bottom disk to the target peg, then invoke the algorithm on the n~ 1 disks to stack them on the target peg. 468.410 -62 5 45-6210 42-6510 6 24510 6.90264 40269 20469 02469 70. New Orleans, Charlotte, Indianapolis 71. eggs, shortening, flour 72. Q: CurrentValue = Q(0): CurrentValueg = 2" true since CurrentValueg = 2 and ig = 2 and 2 = 22-1 Assume Q(k): CurrentValuey, = 2” Show Q(k + 1): CurrentValuey,1 = 2" CurrentValueys.1 = 2*CurrentValuey = 2(2*"') = 2 = 2"! At termination, CurrentValue = 2i-] and i= n+ 1, so CurrentValue = 201-1 = 2n *73. The recurrence relation matches Equation (6) with c= 1 and g(n) = 5. From Equation (8), the solution is S(n) = 5+ 15 =5+(n-1)5=n(5) a 74, The recurrence relation matches Equation (6) with c = 2 and g(n) = 2". From Equation (8), the solution is F(n) = 2°" (2) +) 2°12! = 2" + 72" = 2" +(n=1)2" = 02" ct a 75. The recurrence relation matches Equation (6) with c= 2 and g(n) = 1. From Equation (8), the solution is Tin) = 2°*(1)+ yea) = Pte 4k DeL = 2" =] *76, The recurrence relation matches Equation (6) with = 1 and g(n) =n. From Equation (8), the solution is 1424+3+...¢n= n(n 41/2 Gereting Mathematical Structures for Computer Science Page 83 77. The recurrence relation matches Equation (6) with c= 1 and g(n) = 2n- 1. From Equation (8), the solution is S(n) = 14+ 0 (2i-1) =143+...4(2n-1) =n? a 78. The recurrence relation matches Equation (6) with c = 2 and g(n) = n29. From Equation (8), the solution is P(a) = 2-1) + FA’) =2" + Ho" = 2" +2"Enln +/2—1) = 2"aln +192] *79.F(n) = nF(n - 1) = nf(a - 1)F(n - 2)] = n(n - 1)F(n - 2) = n(n - 1)[(n - 2)F(n - 3)] = n(n - 1)(n - 2)F(n - 3) In general, F(n) = n(n - Dia- 2)..n= (k= 1))F(n-k) When n-k=1,k=n-1 F(n) = n(a - Dn - 2)...€2)F(1) = n(n = 1)(n = 2)...(2)(1) =n! Now prove by induction that F(n) = n! FQ): F)=1=1 true Assume F(k): F(k) =k! Show F(k +1): F(k + 1) =(k+ 1)! Fk + 1)=(k + DF(K)=(k+ Dk! =(k+ 1! 80. S(n) = nS(n - 1) +n! = nf(n- 1)S(n- 2) + (n= 1)! + nl = n(n - 1)S(n - 2) + 2n! = n(n - 1)[(n - 2)S(n - 3) + (n= 2)!] + 2nt = n(n - 1)(n - 2)S(n - 3) + 3n! In general, S(n) = n(n - 1)(n - 2)...(n = (k- 1))S(n - k) + (Kn! When n-k=1,k=n-1, S(n) = n(n - 1)(n - 2)...(2)S(1) + (n= Int = n(n = 1)(n- 2)...2)(1) + (n= nt =nl + (n= In! = n(n!) ‘Now prove by induction that $(n) = n(n!). S(1): SQ) =10)=1 true Assume S(k) = k(k!) Show S(k + 1) =(k + 1)(k + 1)! Sk +1) =(k + I)S(W) + (K+ DI = (kt DEK) + (K+ DI = (Wk +1! + (K+ DI=k+ DEKE D! The recurrence relation is A(n) = 1.5A(n - 1) with a base case A(1) = 1200. This is a linear, first-order recurrence relation with constant coefficients, so Equation (8) applies and gives the solution A(n) = (1.5)""(1200). A(12) = (1.5)''(1200) = 103,797. Page 04 Mathematical Structures for Computer ScLence Gersting *82. The recurrence relation is T(n) 83. 84, 85. 86. 0.95T(n - 1) with a base case T(1) = X. This isa linear, first-order recurrence relation with constant coefficients, so Equation (8) applies and gives the solution T(n) = (0.95)""(X)._At the end of 20 years (the beginning of the 21* year), the amount is T(21) = (0.95)"°(X) = 0.358(X), which is slightly more than one-third the original amount X. The recurrence relation is A(n) = (1.08)A(n - 1) + 100 with a base case of A(1) = 1000. This is a linear, first-order recurrence relation with constant coefficients, so Equation (8) applies and gives the solution A(n) = (1.08)"-1(1000) + 100[1.08-2 + 1.08-3 + + 1,08 + 1] = (1.08)9-1(1000) + 100 [1 - (1.08)"-l [1 - (1.08)] from the formula for the sum of a geometric sequence. At the end of 7 years (the beginning of the 8th year), the account is worth (1.08)7(1000) + 100[1 - (1.08)7}/(1-1.08) which equals $2606.10. The recurrence relation is A(n) = (1.01)A(n ~ 1) - 80 with a base case of A(1) = 5000. This is a linear, first-order recurrence relation with constant coefficients, so Equation (8) applies and gives the solution A(n) = (1.01)-1(5000) -80[1.017-2 + 1019-3 + .. + 1.01 + 1] = (1.01)"-1(5000) — 80[1 - (1.01)-!y[1 — 1.01] from the formula for the sum of a geometric sequence. At the end of 18 months (the beginning of the 19" month), the loan balance remaining is (1.01)!8(5000) - 80[1 — (1.01)!8/(1 - 1.01) which equals $4411.56. The recurrence relation is S(n) = 0.98S(n - 1) - 10,000 with a base case of S(1) = 1,000,000. This is a linear, first-order recurrence relation with constant coefficients, so Equation (8) applies and gives the solution S(n) = (0,98)""(1,000,000) - 10,000{(0.98)"? + (0.98)"* + ... + (0.98) + 1] = (0.98)""(1,000,000) - 10,000[1- (0.98)""/(1 - 0.98) from the formula for the sum of a geometric sequence. At the end of 9 years (the beginning of the 10" year), the population is (0.98)°(1,000,000) - 10000[1-(0.98)"/(1-0.98) which equals 750622, The recurrence relation for the total number of infected machimes each day is T(n) = T(n - 1) + ST(n- 1) - 6"? = 6T(n- 1) - 6? with a base case of T(1) =3 . This is a linear, first-order recurrence relation with constant coefficients, so Equation (8) applies; c= 6 and g(n) = -6"?, By Equation (8), the solution is T(n) = 6°" (3)+ yor 6) @)-dor =6"'(3)-(n-1)6"? *?[6*3-(n-1)] Now setting 6*3 — (n~ 1) equal to 0 and solving for n, the result isn = 19. The virus disappears after 19 days. Gersting Mathematical Structures for Computer SeLence Page 85 87.a, M(1)=1 (one move for one disk) M(n) = 2M(n-1) +1. (restack the top n— 1 disks on the third peg, requiring ‘M(n- 1) disk moves, move the bottom disk to the target peg, restack the n ~ 1 disks on the target peg, which also requires M(n ~ 1) disk moves) b. This is a linear first order recurrence relation with constant coefficients, so Equation (8) applies and gives the solution Min) =2""MQ)+ 2") SDE 24D ee 2? 2" 1-2 =2"-1 c. (2% 1)/(60*60*24*365) is over 500 billion years! *88, The recurrence relation is P(n) = P(n - 1) + n, with P(1) = 1. Equation (8) applies and gives the solution P(n) = 1+ i =14+2+3+...4n=n(n+1)/2. 89, The recurrence relation is P(n) = P(n - 1) + 3n - 2 with P(1) = 1. Equation (8) applies and gives the solution P(n) = 14+ 2-2) =144474104...43n 2 = (n/2)\3n-1) 90. Base step: When n = 1, Equation (8) becomes c9S(1) = S(1) Assume that S(k) = c*'S(1) + )1c*'g(i) Then S(k + 1) = eS(k) + alk + 1) = {ck 'S(1)+ °c*'g(i)}+ g(k +1) 3 x = 8S) +d e*gGi) + a(k +1) = says Sg) a Page 96 Mathematical Structures for Computer Sckence Gersting EXERCISES 2.5 1. The outer loop is executed n times; for each execution of the outer loop, the inner loop is executed n times, so a total of n’ additions is done. 2. On the first pass through the outer loop, the inner loop is executed n times. On the second pass through the outer loop, the inner loop is executed n ~ 1 times, etc. The number of additions is therefore n4(n—1)+(n—2)+...41= anu 3. The algorithm of Example 47 is rewritten here. Assignments occur at the lines marked A and comparisons are done at the line marked C. fori=1tondo low = roster{i).quiz{1] WAL sul roster[i).quiz{1] HA2 for }=2tomdo sum = sum + roster[i].quiz{j] //A3 if roster[i].quiz{j] n then write(‘not found’) else if L{i] =x then vwrite(‘found') else SequentialSearch(L, i+1, n, x) end if end if 5. C(l) Cla) 1 (1 comparison to search a 1-element list) 1+C(n-1) forn>2 (1 comparison against the first element, then however many comparisons are required for the rest of the list) This is a first-order, linear recurrence relation with constant coefficients. By Equation (8) in Section 2.4, the solution is (a) = (1) + FAY) =14 (a= 1 a 6. This is in the form of Equation (1) with c= 1 and g(n) =n. By Equation (6), the solution is eee 34S 2 = 3+ (242 +... 4 DO) a 242° 42! 42 ++ DY aD + DOE =2+2(n)-1=2n+1 *7. This is in the form of Equation (1) with c = 2 and g(n) = 3. By Equation (6), the solution is poe ys $2200) an IP 4 22 4 DYN eID" Mn 4 nD = 4-3 8. This is in the form of Equation (1) with c= 2 and g(n) =n. By Equation (6), the solution is 28" (1) + Fomem (ary =n+ Some =n-+(logn)2"*" = n+ (logn)n = (1+logn)n Page 88 Mathematical Structures for Conputer Science Gersting 9. This is in the form of Equation (1) with c= 2 and g(n) = n2. By Equation (6), the solution is ben kee oor ween 21) + 22)? = nt P2"8"-24 2% st Yn! =ntny 2 a a ‘ ‘ Smt rf2! +2? $004 28") = nfl +242? +224 2] = fem 1] =nfn-2-1] *10.n- 1 compares are always needed - every element after the first must be considered a potential new maximum 11. C1) =0 (no comparisons are required; a 1-element list is already sorted) C(n) = (n- 1) + C(n- 1) (n- 1 compares to find the forn>2 ‘maximum element plus however many compares are required to sort the list minus the last element) 12, This is a first-order, linear recurrence relation with constant coefficients. By Equation (8) of Section 2.4, the solution is (a) = "10+ NUY"'G=1) = 04 NG-=1424...4(0- = 1)n *13. a, the merged list is 1, 4, 5, 6, 8, 9 3 comparisons - 6 vs. 1, 6 vs. 4, and 6 vs. 5 b. the merged list is 1, 2, 3, 4, 5, 8 4 comparisons - 1 vs. 2, 5 vs. 2, 5 vs. 3, Svs. 4 c. the merged list is 0, 1, 2, 3, 4, 7, 8, 9, 10 8 comparisons - 0 vs. 1, 2 vs. 1, 2 vs. 8, 3 vs. 8, 4 vs. 8, 7 vs. 8, 10 vs. 8, 10 vs. 9 14, The maximum number of comparisons takes place when each list runs out of elements at virtually the same time, as in (c) of Exercise 13. In this case, every element that is added to the merged list, except the last one, requires a comparison, so (r +s) - 1 comparisons are done. *15.C(1)=0 (no comparisons are required; a I-element list is already sorted) C(n) = 2C(n/2) + (n- 1) (C(w/2) comparisons are required forn=2M, n>2 for each half, and n- 1 comparisons are required to merge the two sorted halves.) Gersting Mathematical Structures for Computer Science Page 89 16. This is in the form of Equation (1), with ¢= 2 and g(n) =n - 1. By Equation (6), the solution is C40) = (0) + F 2G! 1) =F are 20) F phe Fee = (logn)n = [2%"" + 2"? +... 42°] = (logn)n — (2 ~1]=(logn)n ~[n ~1]=n(logn) ~n +1 17. For selection sort, C(n) = 2°) For mergesort, C(n) = n(log n) -n+ 1 selection sort _mergesort n=4 6 5 n=8 28 17 n=16 120 49 n=32 496 129 18. Position at ‘Number of which x occurs | comparisons 1 1 2 2 3 3 a a Total number of comparisons = 1+ 2+ --- +n=n(n + 1)/2. Each of the n cases is ‘equally likely so divide by n to get an average of (n + 1)/2. 19. Total number of comparisons = (1 +2 + -+- +n) {x in the list] + n [x not in the list] = n(n + 1/2 +n=(n? + 3n)/2._ Each of the n+ 1 cases is equally likely so divide by n+ Ito get an average of (n? + 3n)/2(n + 1). 20. Form=1 F(m + 2)= FG) F(m + 1) = FQ) We need to show that if 1 division is required to find ged(a, b), then a>2andb2>1. If b= 0, then by the Euclidean algorithm, ged(a, 0) = a with 0 divisions required, which does not satisfy m= 1. Hence b > 1 and, because a> b, a2. Assume that if k divisions are required, a > F(k + 2), b> F(k + 1). Show that if k +1 divisions are required, then a > F(k +3), b > F(k +2). The first step of the algorithm in computing ged(a, b) is to divide a by b, so a=qb+r,0 F(k + 2) and r2F(k+1). Thena=qb+r>b+r (q2 1 sincea>b)2F(k +2) + F(k + 1) =F(k +3). *21, From Exercise 20, a= n> F(m +2). By Exercise 23 of Section 2.4, mt mn F(m+2)> @) Therefore (3) 0 x <1 and x > 3, which cannot be satisfied or x-1>Oandx-3<0 x>lLandx <3 l AB+CD-* b. A**B - C*D = ((A**B) - (C*D)) > AB**CD#- c. A*C + B/C +D*B) = ((A*C) + (BIC + (D*B)))) > AC*BCDB*+/+ Page 96 Mathematical Structures for Conputer Science Gereting *36.a.13 b.2 ¢, 28 37. {1} b (panstu} co (qr, w) d@ e {rv} f {uw} 8 (0.9, , v0, 5 ¥), (8,9), (8, 0), (8, v)} he {anv} 38.%a. (1,2,4,5,6,8,9} *b. (4, 5} *e. (2,4) d. (1, 2,3, 4, 5,9} 7 £ {0, 1,3 +h. (0, 1 J. (0,1, 8} 1, {2,3} ), (1, 3), (1, 4), (4, 2), (4, 3), (4, 4), (5, 2), (5, 3), (S, 4), (9, 2), 3), (9, 4)} 39.a. {a} b. {©, {a}, fa, {a}} c. {O, a, {a}, {{a}}, {a {a}} }=S ao e. {a {a}} £ {O, {a {a}}} —-g. {O} 40. a. (Adams, Jefferson, Grant} b. {Washington} c. © 4.aFbTcTdT *42. a. B b Bac c AB d. BOC e. BAC or(BUC) orB'-C 43.2. Ab bAOB c¢, A-B 44.%a.C *. BAD *c AOB d. AnD! e BAD! £COA g. CUD *45. DAR! 46. ONG UR)OV 41. (NUP)OA 48.42, T b. T *c. F (Let A= {I, 2, 3}, B= {1, 3, 5}, S=(I, 2, 3, 4, 5). Then (AOB)' = {2, 4, 5} but A’ o B= (4, 5} 9 (2, 4} = (4}.) aT *e. F (Take A, B, and S as in (c), then A - B = {2}, (B - A)'= {1, 2, 3, 4}.) fT g. F h. F (Order matters in ordered pairs, so if A= {1, 2}, B= (3, 4}, then Bx A=({(3, 1), (3, 2), 4, 1, (4, 2)} and A x B= {(1, 3), (1, 4), (2, 3), (2, 4)}.) iT iT Gersting Mathematical Structures for Computer Sctence Page 97 k, F (Let A= {1,2}, B= (2,3, 4}, C= (1, 3}. Then (A-B) U (B-C)= {1} U {2,4} = (1, 2, 4) but A- C= {2}.) LT 49.44. BCA b AcB d BoA £ A=B 50.a.12 b.9 016 d3 e4 51. Letx © ANB. Thenx eA andx € B, sox A. 52.Letxe A. Thenx ¢ Aorxe Bsoxe AUB. *53, Let C € (A) 7 (B). Then C © P(A) and C € 9(B), from which Cc A and CcB,soCCAN BorCe (An B). Therefore (A) 0 (B) c P(A B). The same argument works in reverse 54, Let C © (A) U 9(B). Then C € P(A) or C € (B), which means C < A or CCB. Incither case, CC AUB, or C € (AUB). 55. Suppose B # ©. Letx ¢ B. Thenx ¢ AUB but x ¢ A-B, which contradicts the equality of AU B and A-B. *56, Suppose AM B #@. Letx ¢ ANB. Thenx ¢ Aand x ¢ Bsox € AUB but x ¢@A-Bandx ¢ B-A,sox¢ (A-B)U (B-A), which contradicts the equality of Au Band (A-B)U(B-A). 57.i) LetCS A. ThenAUC=A. Also, (ANB) UC=CU(ANB)=(CUA)N(CUB)=(AUC)A BUC) =AN@vUC) ii) Assume that (AB) UC =A (BUC) and let x C. Suppose x ¢ A. Then x € (AMB)UC but x ¢ AN (BUC), which is a contradiction, Therefore x € A and CCA, b. {2,4,6,7, 9} c. x €(AUB)-(AMB) xe Aorx eBeox eBorxeA@xeBUA (Ib) x ANB x © Aandx € Bandx « C<>x © A and (x € Band x € C) exe Aandxe BAC)OxEe ANB AC) (3b) x € AN (BUC) exe Aandx € (BUC) x € (ANB) orx e (ANC) x €(ANB)U(ANC) (4b)x € ANS xe AandxeSoxeA xe Axe Aandx eS because ACS>xE ANS (a)x € AUA' > xe Aorx € Al>x S orx € S because ACS, A'CS 9x eS xe S$ (xe Sandx € A) or(x ¢ Sandx ¢ A) 3x Aorxe Aix AUA' (5b) For any x such that x € A A’, it follows that x ¢ A and x € A’, or x belongs to A and x does not belong to A. This is a contradiction, so no x belongs to A> A’, and AN A'=@ 61.a, x € (AUBY 2 (1) *66. The proof is by induction on n. For n=3, (ADU (Az. U Ag) = (ATU Ag) U AG by set identity 2a =A, U AQUA by Equation (1) of the answer to Exercise 65(b) ‘Assume that for n=k and 1 2 Q) 68. The proofis by induction on n. For n=3, (AD) 0 (42.9.3) = (AL AQ) 03 by set identity 2 SAPO AQAAG by Equation (2) of the answer to Exercise 67(b) Assume that forn=k and 1

| w wie xO) w wlwan ala & a alexa [7 @ | DID OAR olawz win zo a7 w a) wl a 7 pattern (4, 2) stack number 3: R B B G G|B/R G R pattern (3, 3) wo mo] 2 ala x CGE 7|7 Ow QQ wz wl = | alZow olawn wma P\> Ow! 17. 4 =64 *18, 26+ 26-10 = 286 19, 4.3-2=24 20. 17-16+24-23 = 824 *21,5-3-4-3= 180 22, 5-4:343-4-3= 96 23, 10-7-3-2-2-2 = 1680 24, 10-7-1-2-2-2410-7-2-2-2-1= 1120 Page 108 Mathematical Structures for Computer Selence Gersting *25.9-10-26-10-10+9+10-26-10-10-10+9-10+26-10- 10-10-10 = 25,974,000 26. ‘hamburger alone) + 2-2-2 (fish sandwich alone) + 5 (beverage alone) + 2-2-2 ( 2-2-2-2-2-2 (hamburger and fish) + 2-2-2-2-5 (hamburger and beverage) + 2:25 2. 2. 2. (fish and beverage) + 2-2-2-2-2-2-2-5 (all three) = 917 #27.5-3=15 28,2-11-6 = 132 29, 9-10-2 = 180 (2 choices, 0 or 5, for the third digit) *30. 900 - 180=720 31. 9-5-3 (middle digit even, third digit 0, 4, or 8) + 9-5-2 (middle digit odd, third digit 2 or 6) = 135 + 90 = 225 32. 225 (numbers divisible by 4) + 9-5-1 (middle digit odd, third digit 0) +9-10-1 (third digit 5) = 225 + 45 + 90 = 360 33. 9-5-1 (middle digit even, third digit 0) = 45 34, 900 - 360 = 540 #35, 2' = 256 36. 2° =64 *37. 1-2” (begin with 0) + 1-2°-1 (begin with 1, end with 0) = 2’ +26 = 192 38, 2-1-2° =27 =128 39, 111-28 =32 40. 8 (one for each digit at which the 0 occurs) 41, 1-1-2 (begin with 10) + 1- + 1-1-1-2° (begin with 000) 2° (begin with 110) + 1-1-1-2° (begin with 010) * +3-2° = 160 42. 2-2-2-2-1-1-1-1=24 = 16 *43. 8 (This is the same problem as Exercise 40.) 44. 256 - 8 (contain exactly one 0) - 1 (contain no 0s) = 247 45.6-6=36 Gersting Mathematical Structures for Computer Science Page 103 *46.6-1=6 47.1-1=1 48, 2 +2 +2 (two ways to get each of 6 & 1, 5 & 2, 4 & 3) +2 (two ways to get 6 & 5)=8 49, 5-5=25 $0.4-5-3-3-2-2=720 ¥51,4-1-3-3-2-2=144 92,1+5-3-3-1 45 53.5+3-+3-+2-2=180 54.4-3-3-3-2 =216 *55, 52-52 = 2704 56. 4-4 =16 57. 12-12 =144 *58.4-4 = 16 ways to get 2 of one kind; there are 13 distinct "kinds", so by the Addition Principle, the answer is 16 + 16 +... + 16 = 13-16 = 208 59, 4-48 (flower king, bird nonking) + 4-48 (bird king, flower nonking) = 384 60. Face value of $ can occur in 4 disjoint ways: flower face value bird face value 1 4 2 3 3 2 4 1 Each has 4-4 ways of occurring, so the total is 4-16 = 64 61. Face value of less than 5 can occur in the disjoint ways shown below: flower face value bird face value 1 1, 2, or 3 2 lor2 3 1 Each has 4-4 ways of occurring, so the total is 6-16 = 96 62, 40-40=1600 Page 110 Mathematical Structures for Computer SeLence Gersting *63. 12-52 (flower face card, any bird card) + 40-12 (flower non-face card, bird face card) 104 or 52-52 (total number of hands - Exercise 55) - 40-40 (hands with no face cards - Exercise 62) = 1104 64. 2704 - 48-48 (total number of hands - hands with no kings) = 400 65, 00111000 11001001 00100001 00001010 66, 0111000 *67. Using the formula Total IP addresses = (# of A netids)(# of A hostids) + (# of B netids)(# of B hostids) + (H of C netids)(# of C hostids) and eliminating the special cases gives (27 - 1)(2™* — 2) + (2"4)(2'®— 2) + (271)(28 - 2) = (127)(16,777,214)+ (16,384)(65,534) + (2,097, 152)(254) = 2,130,706,178 + 1,073,709,056 + 532,676,608 = 3,737,091,842 68. A(1) = 1,300,000 A(n) = 2A(n= 1) forn>2 ‘This is a linear first-order recurrence relation with constant coefficients; the solution is A(n) = 2"A(1) = 2""(1,300,000) 3,737,091,842 = 2"'(1,300,000) 2"! = 3,737,091,842/1,300,000 logo(3737/1.3) + 1 = 12.49 years, so in about 2006 69, 8 outcomes Gersting Mathematical structures for Computer Science Page 111 *70. s RBGRBG RBGRBG ReORBO 33 ways; the outcome that is highlighted is BRGR. 71. A win = left branch, B win= right branch. There are 70 ways; the outcome labeled here would be BBABAB B B KA A \ 72. For m= 2, the result follows from the Multiplication Principle. Assume that for m = k, there are n, ---n, possible outcomes for the sequence of events I tok Let m=k+ 1. Then the sequence of events 1 to k+ 1 consists of the sequence of events | to k followed by event k+ 1. The sequence of events 1 to k has n, possible outcomes by the inductive hypothesis. The sequence 1 tok followed by event k + Ithen has (n, ---n,)n,,, outcomes by the Multiplication Principle, which equals Ay Nyy 73. For m = 2, the result follows from the Addition Principle. Assume that for m =k there are ny + ... + ny possible outcomes from choosing one of these k events Let m=k+ 1. Then choosing one of the k + 1 disjoint events can be thought of as choosing one of the k disjoint events from 1 to k or choosing event k-+ 1. The k disjoint events have ny + ... + ny possible outcomes by the inductive hypothesis, so by the Addition Principle, there are (ny +... + ny) +nk4] =nj +... +nk4+1 possible outcomes. Page 112 Mathematical Structures for Computer Science Gersting TA. a. P(1)=1I (trivial case) P(2)= 1 (only one way to multiply 2 terms) For n> 2, let the last multiplication occur at position k, 1 B) and (Ao C) are disjoint = 189 - (69 + 93) =27 *8. Let A= auto set, B = bike set, C= motorcycle set a. [B-(AUC©)|=|BI- [B 4 (AU C)] by Example 32 Bl - (BO A)YUBOO) BI - (BO Al + BOC|-[BA ANC) =97-(53+7-2)=39 b. |AUBUC|=97 + 83 + 28 - 53 - 14-7 +2 = 136, so 150 - 136 = 14 do not own any of the three, 9. From the Principle of Inclusion and Exclusion, 87= 68 +34+30-19- 11-23 +|ANB OC) s0|ANBOC|=8. 10. No. Letting A, B, and C be the odor, lather, and ingredients sets, the Principle of Inclusion and Exclusion says that the union of the three sets would contain 491 people, yet only 450 were surveyed. 11. [A] 4B] + |C| + [DJ -|AB]-|AAC]-|AADI- [BAC - BaDI-|CAD +AQBOC+ANBOD|+/ANCAD|+/[BOCAD|-|ANBOCoD| 12, The terms in the expansion are equivalent to all of the subsets of (Ay...., An} except for the empty set, Therefore there are 2 - | terms 13, 5 (Use the Pigeonhole Principle, where suits are bins, cards are items) *14.No - there are 13 different denominations (bins), so 12 cards could all be different. 15. 51; there are 50 potential pairs (bins) 16. 3; there are two genders (bins). 17.367 18. Yes - there are 12 bins, so more than 24 items means that at least one bin has more than 2 items. *19. There are 3 pairs - 1 and 6, 2 and 5, 3 and 4 - that add up to 7. Each element in the set belongs to one of these pairs. Apply the Pigeonhole Principle, where the pairs are the bins, and the numbers are the items. Gersting Mathematical structures for Computer science Page 115 20.6 21. This follows from the Pigeonhole Principle, where the n possible remainders (the numbers 0 through n - 1) are the bins. EXERCISES 3.4 1. a 42 b.6720 6.360 d. 2, 91 = 362,880 3. 141 ~87,178,291,000 4, 8! = 40,320; 7!-3= 15,120 (there are only 3 choices for the last character) *5, 51 (total permutations) 3! (arrangement of the 3 R's for each distinguished permutation) = 54=20 6. Seat one person in one chair anywhere in the circle - the position doesn't matter. Choose seats for the remaining 5 people from the remaining 5 positions relative to the first person, which gives 5! = 120 arrangements q *7. PAS, 3) = ais413=2130 8. a (26)3 b. P(26, 3) = 26-25-24 = 15600 9. 19! *10. 21118!) = 2(39,916,800)(40,320) NS men first or women first _-——— | arrange women 1, 11! -C(12, 8)-8! \L select 8 of 12 slots arrange between the men to men fill with women 12. Seat one person in one chair anywhere in the circle — the position doesn't matter. Choose seats for the remaining 18 people from the remaining 18 positions relative to the first person, which gives 18! page 116 Mathematical Structures for Computer Science Gersting 13, Seat one man in one chair anywhere in the circle — the position doesn't matter. Choose seats for the remaining 10 men in positions relative to the first man, which gives 10!. Each woman must be seated to a man’s right, giving 11 locations for women of which 8 must be chosen — C(11,8). Then arrange the 8 women in these 8 chosen locations, giving 8! arrangements of women. The answer is thus 10!-C(11,8)8! n! 14,8, 120 6.36 628 d, —"— * ° (Di! ! 15. Cn, n-1) = aoa =n. The number of ways to select n- 1 objects from n objects is the number of ways to exclude 1 object, C(n, 1) 300! 251275! *16,C(300, 25) = 17. (18, 11) *18.C(17, 5):C(23, 7) = (6188)(245,157) 19. C(21, 4)C(11, 3) *20. C(7, 1) C(14, 1) C4, 1) CS, 1) CQ, 1) - CG, 1) = 7-14-4-5-2:3 = 11,760 21. C(14, 2)-C(21, 4) (2 from manufacturing, 4 from the others) 22. C(3, 1)-C(30, 5) (1 from marketing, 5 from non-accounting and non-marketing) *23. all committees - (none or 1 from manufacturing) = C(35, 6) - [C(21, 6) + C(14, 1)-C(21, 5)] 24, 1-1-1-1-C(48, 1)= 48 (one way to choose the four queens, a pool of 48 left for the 5 card) *25.C(13, 3)-C(13, 2) 26. C(13, 5) 27, 4-C(13, 2)-C(13, 1)-C(13, 1)-C(13, 1) (pick the suit that has 2 cards, select the 2 cards, then select the 1 from each remaining suit) 28, C(12, 5) (select all 5 cards from the 12 face cards) 29. 13-C(4,2)-C(12,3)-C(4,1)-C(4,1)-C(4,1) = 1,098,240 (select the kind for the pair, select the pair of that kind, select the three remaining kinds, select 1 card from each of those kinds) Gersting Mathematical Structures for Computer Science Page 117 *30. ©(13,2)-C(4,2)-C(4,2)-C(4,1) = 123,552 (select the two kinds for the pairs, select the pair of one kind, select the pair of the other kind, select the fifth card from the unused kinds) 31, 13-C(4,3)-C(12,2)-C(4,1)-C(4, 1) = $4,912 (select the kind, select the three of that kind, select two remaining kinds, select the fourth and fifth card from the unused kinds) 32. 10-4-4-4-4-4 = 10.(4)* = 10,240 (there are 10 possible starting points for the sequence, then a choice of | card from each of the four suits for each of the five cards) *33. 4-C(13, 5) = 5,148 (select the suit, then the 5 cards of that suit) 34, 13-C(4,3)-12-C(4,2) =3,744 (select a kind, select three of that kind, select the second kind, select a pair of that kind) 35. 13-C(4,4)-C(48,1) = 624 (select the kind, select the 4 cards of that kind, select the remaining card) 36. 4:10-Ld-deLel 40 (select the suit, select the starting point, select the 5 cards) 37. 4L-L-1-I-1 = 4 (select the suit, select the 5 cards) *38, C(48, 14) 39. C(32, 14) 40. C(16, 8)-C(32, 6) 41. C(43, 14) *42. C(32, 2)-C(16, 12) (Choose the two processors from B, then the remaining 12 modules are assigned to cluster A.) *43. C(12, 4) = 495 44, C(S, 2)-C(7, 2) = (10)(21) = 210 45. C(5, 4) + C(7, 4) =5 +35 = 40 46. C(7, 3)-C(S, 1) + C(7, 4) = 210 47. C(60, 2) *48.C(60, 1) + C(60, 2) 49. C(59, 7) Page 118 Mathematical Structures for Computer Science Gereting 50. C(2, 1)-C(58, 6) *51, C(12, 3) = 220 52. all committees - no independent = C(12, 3) - C(8, 3) = 164 *53. no Democrats + no Republicans - all independents (so as not to count twice) = C(7, 3) + C9, 3) - C(4, 3) = 115 54, all committees - (those without both) = 220 - 115 (from Exercises 47 and 49) = 105 #55, C(14, 6) = 3003 56. all groups - (those without both types) = 3003 - (no bores + no interesting) = 3003 - [C(8, 6) + C(8, 6)] = 3003 - $6 = 2947 57. all - both = C(14, 6) - C(12, 4) = 2508 or neither + exactly one = C(12, 6) + C(2, 1)-C(12, 5) 58. both + neither = C(12, 4) + C(12, 6) = 1419 *59, C(25, 5) - C(23, 5) (all committees - those with neither) (Not 1-C(24, 4) + 1-C(24, 4) this number is too big, it counts some combinations more than once) 60. C(12, 5) - C(10, 5) (all combinations - those without American history or English literature) or C(10,4) + C(10,4) +C(10,3) (history, no English + English, no history + both history and English) (Not 1-C(11, 4) + 1-C(11, 4) - this number is too big, it counts some combinations more than once) 61. C(4, 4}-(36) = 36 L 39 non-clubs - choose the 3 aces 4 aces (Not C(4, 4)-C(12, 1) - this number is too small; one of the aces is already the single club allowed, so the last card can be any non-club, non-ace) Gersting Mathematical Structures for Computer Science Page 119 jack of hearts 2 other jacks 7 | Lother heart 62. CG, 3) (1.2) + 1-€G, 2Y{C(12, 1) - 36] L as choose2 | L__— [Go non-hearts choose 3 non-jack ~ 3 jacks non-heart hearts iacks (Not C(4,3)-C(13,2) - this number is too small, one of the jacks could be a heart) 8! 3121 1 3121 *63.a, b. 121 48 TD ait * 4t2t 12! 51314! 66. 5 distinct characters would result in 5 43-2 code words. Since there are only 10 code words, this number has been divided by 43, which can only be written as 2!-3! Therefore there are two copies of one character and three copies of another. *67.C(7, 5) 68, C(15, 12) 69. C(81, 48) 70. C(26, 12) *71.a. C(8, 6) (choose 6 from 3 with repetitions) b. C(7, 6) (choose 6 from 2 with repetitions) c. C(5, 3) G of the 6 items are fixed, choose the remaining 3 from among 3, with repetitions) Page 120 Mathematical Structures for Computer Science Gereting 72..a. C(10, 8) b. C(7, 5) G of the 8 objects are fixed, choose the remaining 5 from among 3, with repetitions) c. C(9, 8) (choose 8 from 2 with repetitions) d. C(8, 6) (2 of the 8 objects are fixed, choose the remaining 6 from among 3, with repetitions) e. CO, 8) +C(8, 7) + C(7, 6) (zero chocolate chip cookies used - choose 8 from 2 with repetitions) + (one chocolate chip cookie used - choose remaining 7 from among 2 with repetitions) + (two chocolate chip cookies used - choose remaining 6 from among 2 with repetitions) *73.a, C(16, 10) b. C(9, 3) (7 of the 10 assignments are fixed, choose the remaining 3 from among 7, with repetitions) 74.a. C(10, 8) b. C(B, 7) (1 assignment is fixed, choose the remaining 7 from among 2, with repetitions) *75.C(13,10) 76. C(6, 4) (3 assignments are fixed, choose the remaining 4 from among 3, with repetitions) 71. nl(n—=2)!+a(n—1)! _ nlf(n—2)!4(n- 1!) )! (n= 2) (n-1)\(n-2)! (n-1(n-2)! n{(n—2)10+(n—-1))] _ =pen= DI nH Dys nn 78. C(n,)= — nl =C(nn-1) ri(n—r)! (n—r)(n-(n-r))! Whenever r objects are chosen from n, n- r objects are not chosen. Therefore the number of ways to choose r objects out of n is the same as the number of ways to choose n - r objects out of n 79. Clr, 2) + C(n- 1, 2) + (n= 1) = rn, (=n (22 r= =nn=r-1) +r(n-r) r(r- t+r(n-r) 1)+2r(n-r) 2 (ayia! = C(n, 2) Gereting Mathematical Structures for Computer Science Page 121 *80. Consider selecting r elements from a set of n and putting those in bucket A, then selecting k of those r to put in bucket B. The left side multiplies the number of ‘outcomes from those two sequential tasks. Alternatively, we can select k elements from n and place them in bucket B, then r—k elements from the remaining n — k and place them in bucket A. The right side multiplies the number of outcomes from these two sequential tasks. 81. The union of the two sets is a set of size n + m, and there are C(n+ m, r) ways to select r objects from it. Keeping the two sets separate, another way to choose r elements from the union is to choose k objects from one and r ~ k from the other, where 0 Ei,1 x is even, I encourage students to translate that to "an ordered pair is related if the first component (Whatever its name) is even." A function whose action upon the domain elements is described by the equation f(x) = x? is giving a pattern for what to do with its argument (whatever its name), not what to do with ae There are always some misunderstandings about the properties of binary relations. For example, having some ordered pairs of the form (x,x) does not make the relation reflexive. The definition of transitivity does not imply that x, y, and z must be distinct elements. A relation that is not symmetric is not necessarily antisymmetric, And relations can satisfy properties in somewhat trivial ways because of the truth table for the logical connective implication. Indeed, exploring the various properties of binary relations in detail provides a good review of both the implication connective, and the meaning of universal and existential quantifiers. Looking into what it means to fail to be reflexive, for example, introduces the negation of a universally quantified expression, which turns into an existentially quantified negated expression to which DeMorgan's laws can be applied, ete, "What are the properties of a binary relation [or an equivalence relation]?" becomes my opening question for about a week! I also like to assure students, when we first talk about equivalence classes, that they began using equivalence classes in fourth grade, and then I talk about rational numbers and equivalent fractions (Example 14). The material in Sections 4.2 and 4.3 is not central and can be omitted without difficulty. Topological sorting (Section 4.2) is explained as the process of turning a partial ordering into a total ordering. Another approach to this task is mentioned in Section 6.4 as an application of depth-first search. Section 4.3, relational databases, provides a nice application of the ideas of an n-ary relation, practical examples of set operations of union, intersection, and difference and of predicate logic notation (in relational calculus). Students have worked with functions for years, but they still have a surprising amount of trouble with the concepts of one-to-one and onto. I really emphasize how to begin when asked to prove that a function is one-to-one or onto. I make up lots of non- mathematical examples in class and ask whether they are one-to-one and/or onto, such as "S is the set of people in this room, T is the set of shoes in this room, f associates with each person his or her left shoe." Another technique that causes confusion is composition of cycles. Students have some difficulty at first in understanding that this is really composition, i.e., they apply the first cycle to some element and then don't know what to do with the rest of the cycles. Page 132 Mathematical structures for Computer Science Gersting Order of magnitude of functions is important in analysis of algorithms. The text describes the order of magnitude of sequential search and binary search, which were analyzed in Chapter 2; order-of-magnitude analyses will be done on the graph algorithms of Chapter 6. The final section in Chapter 4, on matrices, I leave as a review. Most students have seen this material (although the idea of a Boolean matrix is probably new) and need only look it over to recall the definition of matrix multiplication, EXERCISES 4.1 *1 a (1,3),G,3) b. (4,2), (5, 3) c. (5,0), (2, 2) d. (1, 1), G, 9) 2. a. (1, -1), 3, 3) b. (19, 7), (41, 16) ©. (3, -5), (4, 1/2), (1/2, 13) 4. (1, 3), G, 2) xpy@xo-l . XPyer-2sys2 XPy@xs2-y lL xpyax2tdy2 <4 aese Gereting Mathematical Structures for Computer Science Page 133, 5. “7, 10. pose pegs oe eaoge many-to-many many-to-one one-to-one one-to-many one-to-one many-to-one many-to-many ‘one-to-many 2, 6), G, 17), (0, 0) b. (2, 12) none d. (1, 1), (4,8) reflexive, antisymmetric symmetric symmetric, transitive reflexive, symmetric, transitive symmetric, antisymmetric, transitive reflexive, transitive antisymmetric (because x taller than y and y taller than x is always false, the implication is true), transitive reflexive, symmetric, transitive antisymmetric (false antecedent) antisymmetric, transitive (false antecedent in each case) symmetric reflexive, symmetric, transitive none (not transitive - x p y and y p x does not imply x p x) . Feflexive, transitive reflexive, symmetric, transitive . symmetric transitive reflexive, symmetric, transitive reflexive, symmetric, transitive symmetric reflexive, symmetric, transitive symmetric reflexive, antisymmetric, transitive Page 134 Mathematical Structures for Computer Science Gereting rr 14, (b); the equivalence classes are [0]={..., -9, 6-3, 0, 3, 6,9, ...} oa «, “8, -5, -2, 1, 4, 7, 10, ... } Bl=(..7.-4-125.811,..) (@); the equivalence classes are sets consisting of squares with equal length sides (8; the equivalence classes are sets consisting of strings with the same number of characters (h); the equivalence classes are sets consisting of sets with the same number of elements . For example: a, $= set of all lines in the plane, x p y <> x coincides with y or x is perpendicular to y. Then p is reflexive (x coincides with x) and symmetric (x coincides with y > y coincides with x or x 1 yy 1 x) but not transitive (x 1 y and y 1 z only implies x and z parallel) b. S=set of integers, x py <> x2 x2 < 22) but not symmetric (2 p 3 but not 3 p 2). c. S= set of nonnegative integers, x py x<|y|, Then p is reflexive (x < |x|), but not symmetric (-2 p 3 but not 3 p -2) and not transitive (3 p -4 and -4 p 2 but not 3 p 2). a. yes, yes b. yes, yes ©. no, yes d. no, yes a. reflexive closure = p itself symmetric closure - add (1, 0), (2, 1), (4, 2), (6, 4) transitive closure - add (0, 2), (1, 4), (2, 6), (0, 4), (0, 6), (1, 6) reflexive closure - add (0, 0), (1, 1), (2, 2), (4, 4), (6, 6) symmetric closure = p itself transitive closure - add (0, 0), (1, 1), (2, 2), (4, 4), (6, 6) reflexive closure - add (4, 4), (6, 6) symmetric closure = transitive closure = p itself P is its own closure with respect to all three properties reflexive closure - add (0, 0), (1, 1), (2, 2), (4, 4), 6, 6) symmetric closure = transitive closure = p itself s 2 eo *15. x p* y <> one can fly from x to y (perhaps by multiple hops) on Take-Your-Chance Airlines Gereting Mathematical Structures for Computer Science Page 135 16.*a. p= {(1, 1)} b. p= {(1, 2), 2 1), (1, 3)} c. Assume p is asymmetric and not irreflexive. Then for some x € S, (x, x) € p. But then (x, x) © p and (x, x) € p, which contradicts asymmetry. d. Assume p is irreflexive and transitive but not asymmetric. Then for some x, y €S, (%,y) ep and (y, x) ep. By transitivity, (x, x) ep, which contradicts irreflexivity. €. Assume p is nonempty, symmetric, and transitive. Let (x, y) ep. Then (y, x)

81 p sz and s7 ps1, t] o tz and tz o ty —> sj = sz and t) = tz due to antisymmetry of p and o -> (sj, ty) = (sp, ta). Transitive: (s1, t1) 4 (Sz, t) and (s2, tz) 1 (s3, t3) > 8] p 2 and s2 ps3, ty o tz and tz 6 t3 > 5] ps3 and ty 6 t3 due to transitivity of p and o —> (83,1) 1 (83,t3). 27.a. p' = {(2, 1), G, 2), G, 5), (5, 4)} ._ If pis reflexive, then x p x for all x € S, sox p"' x for all x ¢ S. Let x p'ty. Then y p x and, because p is symmetric, x p y. Therefore y p"' x. Let x ply and y px. Then y p x and x py so, because p is antisymmetric, x = y. Let x ply and yp'z. Thenypxandzpy. By the transitivity of p, zp x and therefore x p” z. Let p be irreflexive. Then for all x ¢ S, (x, x) € p, so for all x ¢ S, (x, x) ep”. g. Letxp''y. Theny p x and, by the asymmetric property of p, (x, y) € ps0 G9) ep". *28. Assume that p is reflexive and transitive on $. Then for all x € S, (x, x) € p, which means (x, x) € p"', so (x, x) € pp" and pop’ is reflexive. Let (x, y) € pvp". Then (x, y) € p and (x, y) ep, which means (x, y) € p and (yx) € p. This implies (y, x) € p" and (y, x) € p, $0 (y, x) € pap! and pop is symmetric. Let (x, y) € pp" and (y, z) € pp". Then (x, y) € pand (x, y) € p™ and (y, 2) € p and (y, z) € p', so that (x, y) € p and (y, x) € p and (y, 2) € p and Gy) € p. Because p is transitive, this means (x, z) € p and (z, x) € p or (x, z) € p and (x, 2) € p', so (x, 2) € pop" and pp"'is transitive. ep aoge 29. a. If(S, p) isa partially ordered set, then p is reflexive, antisymmetric, and transitive. By parts (b), (d), and (e) of Exercise 27, p” is also reflexive, antisymmetric, and transitive on S, so (S, p") is a partially ordered set. Page 138 Mathematical structures for Computer Science Gersting ©. Let (x, y) € p' =X. Then (x, y) € p" and xy. Therefore (y, x) € p. f(y) € p, then, because p is antisymmetric, x = y, a contradiction. So (x, y) € p'. This proves that p"-X cp’. Now let (x, y) € p'. Then not x p y, so by total ordering, y p x and (x y) € p". Ifx=y, then x py by reflexivity of p, a contradiction. Thus (sy) € p"-X, and p'c p"-X. 30.a. Reflexive: X < X because x; = xi, 1 Sisk. Antisymmetric: Let X < Y and Y < X. If X# Y, let m+ 1 be the first index where Xm! # Ym+1. Then Xm+] < Ym+1 and ym+1 < Xm+1 > Xm+1 = Ym+1, 4 contradiction. Transitive: Let X < Y and Y < Z. Then xp << yp for some p P isa tautology. IfP <> Qis a tautology, then P and Q have the same truth values everywhere, so Q <> P is a tautology. IfP <> Q and Q<>R are tautologies, then P, Q, and R have the same truth values everywhere, and P <> Risa tautology. The equivalence classes are sets consisting of wffs with the same truth values everywhere. Reflexive: 1 < m1 because each block of r} is a subset of itself due to reflexivity of set inclusion, Antisymmetry and transitivity also follow from the corresponding set inclusion properties. a. 1 The only way to partition a 1-element set is to use the whole set. b. 5 Using a combinatorial argument, the partitions are all in one block = 1 2 in one block, 1 in another = C(3, 2) =3 each element separate = 1 Total = 5 or by directly counting {a, b, c} {a, b} {c} + {a, c} {b} + {b, c} {a} {a} {b} {c} c. 15 Using a combinatorial argument, the partitions are all in one block = 1 2 in one block, 2 in another = C(4, 2 in one block, 2 in separate blocks = C(4, 2) = 6 each element separate = 1 Total = 15 or by directly counting {a,b ¢, d} {a, b, c} {d} + {a, b, d} {c} + {a, ¢, d} {b} + {b, c, d} {a} {a,,b} {c,d} + {a,,c} {b,,d} + {a,,d} {b,,c} {a, b} {c} {d} + {a, c} {b} (d} + {a, d} {b} (c} + {c, d} {a} {b} + {b, d} {a} {c} + {b, c} {a} {d} {a} {b} {c} (d} *44. a. Partitions of 3 elements into 2 blocks can only be done with 2 elements in one block and 1 in the other, so the answer is the number of ways to select the 2 elements, or C(3, 2) =3. b. Partitions of 4 elements into 2 blocks can be done with 3 elements in one block and 1 in the other (pick the 3 elements out of 4), or two elements in each block (pick 2 elements out of 4 but this determines the other two elements). The answer is C(4, 3) + C(4, 29/2 =7. Gersting Mathematical structures for Computer Science Page 142 45, The number of blocks in a partition can range from 1 (the whole set) to n (a single element in each block). The result follows by the definition of S(n,k) and the Addition Principle. 46. S(n, 1) = 1 because the only partition with 1 block is when the block is the entire set S(n, n) = 1 because the only partition with n blocks is where each block consists of a single element S(n + 1, k + 1) = S(n, k) + (k + 1)S(n, k + 1) because if the set without x is partitioned into k blocks, which can be done in S(n, k) ways, these blocks together with {x} form a partition of the original set with k + 1 blocks. If the set without x is partitioned into k + 1 blocks, which can be done S(n, k + 1) ways, then x can be added to any of these blocks (which can be done k + 1 ways) to give a partition of the original set with k + 1 blocks; by the Multiplication Principle, this can be done (k + 1)S(a, k + 1) ways. These are the only two possibilities, so the result follows from the Addition Principle. *47.a. S(3, 2)=S(2, 1) +28(2,2)=1+21=3 b. S(4, 2)=SQ3, 1) +28(, 2)=1+23=7 48. 1 11 131 716 5 25 1 1 1. 101 +49. S(4,3)=6 50. (5, 3)=25 51. A general term of the sum has the form C(n- 1, KP where 0. (1, 2, 3} where f-! = (4, 1), (2), @ 3) *e. function; one-to- one *£. bijection; h-! : R2 —» R2 where h7l(x, y) = (y-1, x-1) g. function h. function; onto i, not a function (undefined for x = j._ bijection; f-1 : N > N where f~ |, no associated value in R for x <-1) x+1 ifxiseven x-1 if xis odd (note that the function fis its own inverse) k. not a function (no associated value in N for x= y= 0, z= 1) 1. function; one-to-one nodd Gersting Mathematical structures for Conputer Science Page 149, 10. f performs the following mapping: 00 {a} > 10 {b}> 01 {a bJo 1 Thus f maps each of the four elements in the power set of {a, b} to the four binary strings of length two, and is both one-to-one and onto. 11. fis neither one-to-one nor onto. f({a, b}) = f({b, c}) = 2, so fis not one-to-one. There will be no negative numbers in the range of f, so f is not onto. *12. fis neither one-to-one nor onto. f(xy) = flyyy) = 3, $0 fis not one-to-one. For any string s, f(s) 2 0; there are no strings in A* that map to negative values, so fis not onto. 13. fis both one-to-one and onto. If f(s1) = f{s2) then s1 = s2 Gust reverse the strings again and you get back where you started), so fis one-to-one, Given any string s in A*, let y be its reverse. Then fly) = s, so fis onto. 14. fis one-to-one but not onto. If f{s1) = f{s2), then xs; = xs2, which means that s1 = s2, 80 fis one-to-one. Nothing maps to the empty string, so fis not onto. 15. For example, f{x) = I/x 16. For example: a £={(,x), 0»), © y) dy)} b. f= {@ x), ©»), © y), @, 2)} ©. no 17. xis an integer *18. Let k-x>-k-1so [x] =-kand -[-x ]=k. 19, Letn=[x]. Then nis the smallest integer that is greater than or equal to x, s0 n-1 ca(x) = 1 and op(x) = 1 €> ca(x) ca(x) = 1 ©. Ifea(x)= 1, then x € A’ and x € A, so ca(x) If ca(x) = 0, then x ¢ A’ and x € A so ca(x) = cats) 1- cats) d. No, Let S= (1, 2,3}, A= (1, 2}, B= (2,3). Then caus(2) = 1 but ca(2) + ep(2)= 1+ 1. 26.a. 2x b. 2k, 216 27. go f= {(1,6), (2,7), (3,9), (4,9)} *28.a. (g © (5) = a(f(5)) = (6) = 18 b. (Fe gS) = f{a(5)) = £(15) = 16 ©. (go A(x) = B(flx)) = B& +1) = 3K + 1) = 3x43 ©. (Fo f(x) = AAe)) = fx +1) = (K+ 1+ 1 =x+2 £. (g°.g)(x) = g((x)) = g(3x) = 3(3x) = 9x 29.a. 25 b. 1470 (the index doesn't count) c. 9 Gersting Mathematical Structures for Computer Seience Page 151 30.a. gof=12x3 fog =48x3 b. x2-2x+1 fo g=(4x2-1)/2 c. gef= [x] fog= Lx] 31. a. Iff%s1) = A{sp) then g(fls1)) = a(A(s2)) 80 (g © (81) = (B ° (82). Because ge f is ‘one-to-one, sj = $2 and therefore fis one-to-one. b. Foru < U, there exists s € S such that (g f(s) = u, because go f is onto. Thus (f{s)) = u and f(s) is a member of T that is a preimage of u under g, and g is onto. ce. Let $= {1, 2,3}, T= {I, 2, 3, 4}, U={I, 2, 3}, £={(1, D), @, 2), G, 3)}, 8= {C, D, @, 2), G, 3), @, 3)}. Then f ST, g: TU, gis not one-to-one but go f= {(1, 1), (2, 2), G, 3)} is one-to-one. d._ same example as for (c) *32.a. f-lq@)=w2 b. f-l@)=Vx co. f-l(qK)=3x-4 33. a, Assume fhas a left inverse g, and that f{s1) = fls2). Then g(f{s1)) = g(A(s2)) or (g © £)(s1) = (g £)(s2) and ig(s}) = ig(sz), thus s] = sp and fis one-to-one. Now let £ S — T with f one-to-one, We want to define g: T > S. For t ¢ T with t € {(S), define g(t) to be the unique preimage of t under f, For t eT with t ¢ {S), let g(t) be any fixed element of S. Then g: T—> S and for s ¢ S, (g © f(s) = g(A(s)) = a(t) =s, so gef=ig. b. Assume fhas a right inverse g, and let t ¢T. Then t= iq(t) = (fF g)(t) = f(g(t)); g(t) € S, sot € f(S) and fis onto. Now let f S > T with fonto, Then every t ¢ T has at least one preimage in S under f. Define g: T > S by g(t) = a fixed preimage soft. Then (fe g)(t) = f(g(t)) = f(s) =t, sofog =i. ¢. For example: _ fv3 forx=3k kan integer 810) { 0 forx#3k _ Jxv3 forx=3k kaninteger 820) { 1 forx #3k d. gi(x)=2x B2(%) = 2x1 34. £71: TS, gl: UT, soflo gl: US. Forse S, let f(s)=t and g(t) =u. Then } gl ?(goH (=F \@lw)=f-1@)=s. Also foru EU, (Gof > (Fl eg!) (u) = g(f{s)) = g(t) =u. Then (fl © g-l) o(go and (go f) (flo g-) =iy, so flog l=(gofyl, abe d wa ee’) abed b. Git) a (tred “\d ac b abed Cie) 37. Both he(gef) and (heg)ef have domain and codomain A. Forx € A, (ho (gof))(x) = h((g © £)(x)) = h(g(Alx)) = (he g)(A) = ((he g) of (x). *38.a. (1,2, 5,3, 4) b. (1,7, 8)°(2, 4, 6) ©. (1,5,2,4)°(3,6) — d. (2,3) 0 (4,8) (5, 7) 39. a. (1, 6, 4,8, 3, 5,2) b. (1,3) © (2,4) © (5, 13,6) ©. (1,5, 4,3, 2) 40. For example, f: Z —> Z defined by f(x) = x + 1. 123 4 1234 wa (S229 srocamie (1224) "42.034 b. 36 43.0 4b. 4! 44,a, for |S|=2, 2! =2 and 22 - C(2, 1)(1)?=4-2=2 for |S| = 3, 3! = 6 and 33 - C(3, 1)(2)3 + C(3, 2)(1)3 = 27 -3-8 +3 =6 for |S|= 4, 4! = 24 and 44 - C(4, 1)(3)4 + C(4, 2)(2)4 - C4, 3)(1)4 = 256 -4.81+6:16-4=24 Gersting Mathematical Structures for Computer Science Page 153, b. Assume fis onto. If two distinct elements of S map to one element of S, then n - 2 elements are left to map onto n - 1 elements, which cannot be done. Therefore fis one-to-one. Now assume fis one-to-one. Then the n elements of S map to n distinct elements of S; thus every element of S is in the range of f, and fis onto. c. For example, S =N, f: NN given by f{x) = 2x. (0) = 0 d. For example, S=N, f. N->N given by fx) =x-1,x21 *45.a. nM b. nt ca! dnl w1)_ ft 1 yal e afi-3 aot J ]anfZ-Ze-een ‘] < af] =a

You might also like