taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Volume P1 · Proof, induction and invariants

Solutions

Draft. This chapter is written and checked by the tools of the project, and a person has not reviewed it yet. Read it with care.

Contents
  1. Solutions to Chapter 1: Logic and quantifiers
  2. Solutions to Chapter 2: Sets, functions and finite counting
  3. Solutions to Chapter 3: Methods of proof
  4. Solutions to Chapter 4: Mathematical induction
  5. Solutions to Chapter 5: Strong induction and well ordering
  6. Solutions to Chapter 6: Recursion and structural induction
  7. Solutions to Chapter 7: Relations and orders

Solutions to Chapter 1: Logic and quantifiers

Section 1.1: Statements and connectives

Exercise 1.1-1. The form P∧¬QP \wedge \neg Q is T only in the row with PP = T and QQ = F. The form ¬(P∨Q)\neg (P \vee Q) is T only in the row with PP = F and QQ = F. In the rows TT, TF, FT, FF the first column is F, T, F, F and the second is F, F, F, T.

Exercise 1.1-2. (a) The hypothesis "33 is even" is F, so the implication is T. (b) The hypothesis is T and the conclusion "33 is odd" is T, so the implication is T. (c) The part 5<75 < 7 is T, so the "or" is T. (d) Both sides are F, since 2+2=42 + 2 = 4 and 3+3=63 + 3 = 6, so the "if and only if" is T.

Exercise 1.1-3. The converse is "if nn is odd, then nn is prime and n>2n > 2". It is false: n=9n = 9 is odd and not prime. The contrapositive is "if nn is even, then nn is not prime or n≤2n \le 2". It is true for all n>1n > 1, since an even nn that is prime is 22. The denial is "nn is prime, n>2n > 2 and nn is even". It is false for every n>1n > 1, since the only even prime is 22. So the original and its contrapositive are true, and the converse and the denial are false.

Exercise 1.1-4. The columns of (P→Q)∧(Q→P)(P \to Q) \wedge (Q \to P) in the rows TT, TF, FT, FF are T, F, F, T, the same as P↔QP \leftrightarrow Q. The column of ¬(P↔Q)\neg (P \leftrightarrow Q) is F, T, T, F. The form P⊕QP \oplus Q is (P∨Q)∧¬(P∧Q)(P \vee Q) \wedge \neg (P \wedge Q), and its column is F, T, T, F. The columns agree.

Exercise 1.1-5. The four rows have one minterm each: TT gives P∧QP \wedge Q, TF gives P∧¬QP \wedge \neg Q, FT gives ¬P∧Q\neg P \wedge Q and FF gives ¬P∧¬Q\neg P \wedge \neg Q. Each of these is T in its own row and F in the other three. A connective that is T in exactly one row equals the minterm of that row. A connective that is T in several rows is the disjunction of the minterms of those rows. The connective that is F in all rows is P∧¬PP \wedge \neg P. So all sixteen come from ¬\neg, ∧\wedge and ∨\vee.

Exercise 1.1-6. P∣PP \mid P is ¬(P∧P)\neg (P \wedge P), which is ¬P\neg P. Since P∣Q=¬(P∧Q)P \mid Q = \neg(P \wedge Q), the form (P∣Q)∣(P∣Q)(P \mid Q) \mid (P \mid Q) is ¬¬(P∧Q)\neg\neg (P \wedge Q), that is P∧QP \wedge Q. For the disjunction use De Morgan: P∨Q≡¬(¬P∧¬Q)=¬P∣¬QP \vee Q \equiv \neg (\neg P \wedge \neg Q) = \neg P \mid \neg Q, and ¬P=P∣P\neg P = P \mid P, so P∨Q≡(P∣P)∣(Q∣Q)P \vee Q \equiv (P \mid P) \mid (Q \mid Q). Check at PP = T, QQ = F: P∣PP \mid P = F, Q∣QQ \mid Q = T, and F ∣\mid T = ¬\neg(F ∧\wedge T) = T, which is the value of P∨QP \vee Q.

Exercise 1.1-7. Write ¬P\neg P as P→⊥P \to \bot. Write P∨QP \vee Q as (P→⊥)→Q(P \to \bot) \to Q: if PP is T, then P→⊥P \to \bot is F and the whole is T. If PP is F, then P→⊥P \to \bot is T, and the whole has the value of QQ. Write P∧QP \wedge Q as (P→(Q→⊥))→⊥(P \to (Q \to \bot)) \to \bot: the inner form P→(Q→⊥)P \to (Q \to \bot) is F exactly when PP is T and QQ is T, so its negation is P∧QP \wedge Q.

Exercise 1.1-8. Let aa, bb, cc be T when AA, BB, CC tell the truth. The sentences give a↔(b≠c)a \leftrightarrow (b \ne c), b↔¬ab \leftrightarrow \neg a and c↔(¬b∨a)c \leftrightarrow (\neg b \vee a). Try the two values of aa. If aa is F, then bb is T. The third sentence gives c↔(F∨F)c \leftrightarrow (\mathrm{F} \vee \mathrm{F}), so cc is F. The first sentence needs a↔(b≠c)a \leftrightarrow (b \ne c), that is F ↔\leftrightarrow T, which is F: a contradiction. If aa is T, then bb is F, and the third sentence gives c↔(T∨T)c \leftrightarrow (\mathrm{T} \vee \mathrm{T}), so cc is T. The first sentence gives T ↔\leftrightarrow (F ≠\ne T), which is T. So AA and CC tell the truth, and BB lies. A table of the eight rows confirms that this row is the only one.

Exercise 1.1-9. If PP is T, then (P→Q)→P(P \to Q) \to P has a T conclusion and is T. If PP is F, then P→QP \to Q is T, so (P→Q)→P(P \to Q) \to P is T →\to F, which is F. So the form is T exactly when PP is T. For QQ equal to a false statement, it says that "if (if PP then false) then PP", that is "if PP is false then PP", is the same as PP. This is the pattern of a proof by contradiction: to prove PP, assume ¬P\neg P and reach PP or a false statement, and then PP is T.

Section 1.2: Logical equivalence and the laws of logic

Exercise 1.2-1. ¬(P→Q)≡¬(¬P∨Q)≡¬¬P∧¬Q≡P∧¬Q\neg (P \to Q) \equiv \neg (\neg P \vee Q) \equiv \neg\neg P \wedge \neg Q \equiv P \wedge \neg Q, by the rule for the implication, the second De Morgan law and double negation. Then ¬(P∧¬Q)≡¬P∨¬¬Q≡¬P∨Q≡P→Q\neg (P \wedge \neg Q) \equiv \neg P \vee \neg\neg Q \equiv \neg P \vee Q \equiv P \to Q, by the first De Morgan law, double negation and the rule for the implication.

Exercise 1.2-2. (a) x<3x < 3 or y≥2y \ge 2. (b) nn is not prime and nn is not a square. (c) a>0a > 0 and a2≤0a^2 \le 0.

Exercise 1.2-3. The implication P→QP \to Q is T in the rows TT, FT, FF, so its DNF is (P∧Q)∨(¬P∧Q)∨(¬P∧¬Q)(P \wedge Q) \vee (\neg P \wedge Q) \vee (\neg P \wedge \neg Q). The form (P→Q)∧(Q→P)(P \to Q) \wedge (Q \to P) is T in the rows TT and FF, so its DNF is (P∧Q)∨(¬P∧¬Q)(P \wedge Q) \vee (\neg P \wedge \neg Q).

Exercise 1.2-4. If PP is F, the form has an F conjunction as its hypothesis and is T. If PP is T, the hypothesis is T ∧\wedge (T→Q\mathrm{T} \to Q), which has the value of QQ, and so the whole is Q→QQ \to Q, which is T. In one line: when PP holds and P→QP \to Q holds, QQ holds.

Exercise 1.2-5. For (P∨Q)∧¬P→Q(P \vee Q) \wedge \neg P \to Q: when the hypothesis is T, ¬P\neg P is T so PP is F, and P∨QP \vee Q is T so QQ is T. For (P→Q)∧¬Q→¬P(P \to Q) \wedge \neg Q \to \neg P: when the hypothesis is T, QQ is F. If PP were T, then P→QP \to Q would be F. So PP is F and ¬P\neg P is T.

Exercise 1.2-6. Second De Morgan law from the first: the first law applied to ¬P\neg P and ¬Q\neg Q gives ¬(¬P∧¬Q)≡¬¬P∨¬¬Q≡P∨Q\neg (\neg P \wedge \neg Q) \equiv \neg\neg P \vee \neg\neg Q \equiv P \vee Q. Negate both sides and use double negation: ¬(P∨Q)≡¬¬(¬P∧¬Q)≡¬P∧¬Q\neg (P \vee Q) \equiv \neg\neg (\neg P \wedge \neg Q) \equiv \neg P \wedge \neg Q. First distributive law from the second and from the De Morgan laws: P∧(Q∨R)≡¬(¬P∨¬(Q∨R))≡¬(¬P∨(¬Q∧¬R))P \wedge (Q \vee R) \equiv \neg (\neg P \vee \neg (Q \vee R)) \equiv \neg (\neg P \vee (\neg Q \wedge \neg R)). The second distributive law turns the inside into (¬P∨¬Q)∧(¬P∨¬R)(\neg P \vee \neg Q) \wedge (\neg P \vee \neg R). The first De Morgan law gives ¬(¬P∨¬Q)∨¬(¬P∨¬R)\neg (\neg P \vee \neg Q) \vee \neg (\neg P \vee \neg R), and the second De Morgan law with double negation gives (P∧Q)∨(P∧R)(P \wedge Q) \vee (P \wedge R).

Exercise 1.2-7. (P→Q)∧(R→Q)≡(¬P∨Q)∧(¬R∨Q)(P \to Q) \wedge (R \to Q) \equiv (\neg P \vee Q) \wedge (\neg R \vee Q). The second distributive law, read from right to left, gives (¬P∧¬R)∨Q(\neg P \wedge \neg R) \vee Q. The second De Morgan law gives ¬(P∨R)∨Q\neg (P \vee R) \vee Q, which is (P∨R)→Q(P \vee R) \to Q. Example: with PP equal to "n>10n > 10", RR equal to "n<−10n < -10" and QQ equal to "n2>100n^2 > 100", the statements "if n>10n > 10 then n2>100n^2 > 100" and "if n<−10n < -10 then n2>100n^2 > 100" together say the same as "if n>10n > 10 or n<−10n < -10, then n2>100n^2 > 100".

Exercise 1.2-8. The eight rows give P↔(Q↔R)P \leftrightarrow (Q \leftrightarrow R) with the values T, F, F, T, F, T, T, F in the order TTT, TTF, TFT, TFF, FTT, FTF, FFT, FFF. The form (P↔Q)↔R(P \leftrightarrow Q) \leftrightarrow R gives T, F, F, T, F, T, T, F in the same order. The columns agree, so ↔\leftrightarrow is associative. The form is T in four of the eight rows, in the rows TTT, TFF, FTF, FFT, which are the rows with an odd number of T values.

Exercise 1.2-9. There are four: P∧QP \wedge Q, PP, QQ and P∨QP \vee Q. Let TT be the column of a form in the rows TT, TF, FT, FF. Every such form is T in the row TT and F in the row FF: the variables PP and QQ have this property, and ∧\wedge and ∨\vee keep it, which is proved by induction on the size of the form. So only the two rows TF and FT are free, and there are at most four columns. The four forms above have the columns (T,F,F,F), (T,T,F,F), (T,F,T,F) and (T,T,T,F) in the order TT, TF, FT, FF with the roles as written, and they are different, so there are exactly four.

Section 1.3: Predicates and quantifiers

Exercise 1.3-1. (a) True: take y=−xy = -x. (b) False: for each yy, the value x=1−yx = 1 - y gives x+y=1≠0x + y = 1 \ne 0. (c) False: x=2x = 2 has no integer yy with 2y=12y = 1. (d) True: x=1x = 1 gives 1⋅y=y1 \cdot y = y for all yy.

Exercise 1.3-2. The denial is "there is an even integer n>2n > 2 that is not the sum of two primes". In symbols, ∃n (n even∧n>2∧∀p ∀q (p,q prime→p+q≠n))\exists n\ (n \text{ even} \wedge n > 2 \wedge \forall p\, \forall q\ (p, q \text{ prime} \to p + q \ne n)). A counterexample is an even n>2n > 2 with no such pair. No one has found one, and it is open whether one exists.

Exercise 1.3-3. (a) ∃k∈ℤ (n=km)\exists k \in \mathbb{Z}\ (n = km). (b) d>0∧∃a (m=ad)∧∃b (n=bd)∧∀e ((e∣m∧e∣n)→e≤d)d > 0 \wedge \exists a\, (m = ad) \wedge \exists b\, (n = bd) \wedge \forall e\ ((e \mid m \wedge e \mid n) \to e \le d), with ee and dd positive integers.

Exercise 1.3-4. Suppose ∀x (P(x)∧Q(x))\forall x\, (P(x) \wedge Q(x)). For each aa, P(a)P(a) holds and Q(a)Q(a) holds. So ∀x P(x)\forall x\, P(x) and ∀x Q(x)\forall x\, Q(x) hold. Conversely, suppose both hold, and let aa be any element. Then P(a)P(a) holds and Q(a)Q(a) holds, so P(a)∧Q(a)P(a) \wedge Q(a) holds. As aa is arbitrary, the left side holds.

Exercise 1.3-5. Suppose ∀x (P(x)→R)\forall x\, (P(x) \to R) and suppose ∃x P(x)\exists x\, P(x) with witness aa. Then P(a)→RP(a) \to R holds, and P(a)P(a) holds, so RR holds. Conversely suppose (∃x P(x))→R(\exists x\, P(x)) \to R and let aa be any element with P(a)P(a). Then ∃x P(x)\exists x\, P(x) holds, so RR holds. If xx is free in RR the rule fails. Take P(x)P(x) equal to "x>5x > 5" and RR equal to "x>3x > 3" over the integers. For every integer aa the statement "a>5→a>3a > 5 \to a > 3" is true, so the left side is true as a statement with xx bound in the first part. The right side (∃x x>5)→x>3(\exists x\, x > 5) \to x > 3 has the free variable xx: its hypothesis is T, and the conclusion is F at x=0x = 0. So the two sides differ in meaning.

Exercise 1.3-6. For the empty domain, ∀x P(x)\forall x\, P(x) is T and ∃x P(x)\exists x\, P(x) is F, whatever PP is. Then ∀x (x≠x)\forall x\, (x \ne x) is T and ∃x (x=x)\exists x\, (x = x) is F. The denial laws: ¬∀x P\neg \forall x\, P is F and ∃x ¬P\exists x\, \neg P is F, so they agree. Also ¬∃x P\neg \exists x\, P is T and ∀x ¬P\forall x\, \neg P is T, so they agree.

Exercise 1.3-7. ∃!x P(x)\exists! x\, P(x) is ∃x (P(x)∧∀y (P(y)→y=x))\exists x\, (P(x) \wedge \forall y\, (P(y) \to y = x)). The first conjunct gives P(x)P(x) for some xx, so ∃x P(x)\exists x\, P(x) follows. For ∀x ∃!y (y=2x)\forall x\, \exists! y\, (y = 2x) over ℕ\mathbb{N}: for given xx the number y=2xy = 2x lies in ℕ\mathbb{N} and satisfies the predicate. If y′y' also satisfies it, then y′=2x=yy' = 2x = y. So yy is unique.

Exercise 1.3-8. Each of the four rows of PP must have at least one T, and a row has 24−1=152^4 - 1 = 15 such choices, so ∀x ∃y P\forall x\, \exists y\, P holds for 154=5062515^4 = 50625 predicates. For ∃y ∀x P\exists y\, \forall x\, P some column must be full. By inclusion and exclusion over the set of full columns the count is 4⋅212−6⋅28+4⋅24−1=16384−1536+64−1=149114 \cdot 2^{12} - 6 \cdot 2^8 + 4 \cdot 2^4 - 1 = 16384 - 1536 + 64 - 1 = 14911. A computer count over the 2162^{16} predicates gives the same two numbers.

Exercise 1.3-9. "The sequence has no limit" is ∀L ∃ε>0 ∀N ∃n≥N (∣an−L∣≥ε)\forall L\, \exists \varepsilon > 0\, \forall N\, \exists n \ge N\ (|a_n - L| \ge \varepsilon), obtained from the denial rule applied to ∃L ∀ε>0 ∃N ∀n≥N (∣an−L∣<ε)\exists L\, \forall \varepsilon > 0\, \exists N\, \forall n \ge N\ (|a_n - L| < \varepsilon). For an=(−1)na_n = (-1)^n take ε=1\varepsilon = 1. Given LL, the numbers ∣1−L∣|1 - L| and ∣−1−L∣|-1 - L| add to at least 22, by the triangle inequality, so one of them is at least 11. If it is ∣1−L∣|1 - L|, then for each NN choose an even n≥Nn \ge N, and if it is ∣−1−L∣|-1 - L| choose an odd n≥Nn \ge N. In each case ∣an−L∣≥1|a_n - L| \ge 1.

Exercise 1.3-10. Let S(m,n,k)S(m, n, k) say that the algorithm has stopped after at most kk steps. The statement is ∀m≥1 ∀n≥1 ∃k S(m,n,k)\forall m \ge 1\, \forall n \ge 1\, \exists k\, S(m, n, k). Its denial is ∃m≥1 ∃n≥1 ∀k ¬S(m,n,k)\exists m \ge 1\, \exists n \ge 1\, \forall k\ \neg S(m, n, k): for some inputs the algorithm never stops. The bounded statement is ∃K ∀m≥1 ∀n≥1 S(m,n,K)\exists K\, \forall m \ge 1\, \forall n \ge 1\ S(m, n, K), which has ∃K\exists K in front. It is stronger, and it is false for Algorithm 1.1E: with m=Fk+1m = F_{k+1} and n=Fkn = F_k, the Fibonacci numbers, the division step runs k−1k - 1 times for k≥2k \ge 2 (for k=5k = 5: m=8m = 8, n=5n = 5 gives four runs), and so no single KK works.

Solutions to Chapter 2: Sets, functions and finite counting

Section 2.1: Sets and their operations

Exercise 2.1-1. The first set is {−2,−1,0,1,2}\{-2, -1, 0, 1, 2\}. The power set 𝒫({1,2})\mathcal{P}(\{1, 2\}) is {∅,{1},{2},{1,2}}\{\emptyset, \{1\}, \{2\}, \{1, 2\}\}. The product is {(1,a),(1,b),(2,a),(2,b)}\{(1, a), (1, b), (2, a), (2, b)\}.

Exercise 2.1-2. (a) True: ∅\emptyset is the one element of {∅}\{\emptyset\}. (b) True: the empty set is a subset of every set. (c) False: the elements of {1,2}\{1, 2\} are 11 and 22, and {1}\{1\} is neither. (d) True: 1∈{1,2}1 \in \{1, 2\}. (e) True: {1,2}⊆{1,2}\{1, 2\} \subseteq \{1, 2\}, so it is an element of the power set.

Exercise 2.1-3. For any xx in the universe: x∈A∩B‾x \in \overline{A \cap B} iff ¬(x∈A∧x∈B)\neg (x \in A \wedge x \in B) iff x∉A∨x∉Bx \notin A \vee x \notin B (first law of De Morgan) iff x∈A‾∨x∈B‾x \in \overline{A} \vee x \in \overline{B} iff x∈A‾∪B‾x \in \overline{A} \cup \overline{B}.

Exercise 2.1-4. x∈A∪(B∩C)x \in A \cup (B \cap C) iff x∈A∨(x∈B∧x∈C)x \in A \vee (x \in B \wedge x \in C). The second distributive law of logic turns this into (x∈A∨x∈B)∧(x∈A∨x∈C)(x \in A \vee x \in B) \wedge (x \in A \vee x \in C), which says x∈(A∪B)∩(A∪C)x \in (A \cup B) \cap (A \cup C).

Exercise 2.1-5. Show (1)⇒(2)⇒(3)⇒(1)(1) \Rightarrow (2) \Rightarrow (3) \Rightarrow (1). Suppose A⊆BA \subseteq B. Always B⊆A∪BB \subseteq A \cup B. Also A∪B⊆BA \cup B \subseteq B, since an element of AA is in BB and an element of BB is in BB. So A∪B=BA \cup B = B. Suppose A∪B=BA \cup B = B. Then A∩B=AA \cap B = A: always A∩B⊆AA \cap B \subseteq A, and if x∈Ax \in A then x∈A∪B=Bx \in A \cup B = B, so x∈A∩Bx \in A \cap B. Suppose A∩B=AA \cap B = A. Then each x∈Ax \in A is in A∩BA \cap B, so x∈Bx \in B, and A⊆BA \subseteq B.

Exercise 2.1-6. Let S∈𝒫(A)∪𝒫(B)S \in \mathcal{P}(A) \cup \mathcal{P}(B). Then S⊆AS \subseteq A or S⊆BS \subseteq B. In both cases S⊆A∪BS \subseteq A \cup B. The inclusion is proper for A={1}A = \{1\} and B={2}B = \{2\}: the set {1,2}\{1, 2\} is a subset of A∪BA \cup B, and it is a subset of neither AA nor BB.

Exercise 2.1-7. A△B=∅A \triangle B = \emptyset iff A∖B=∅A \setminus B = \emptyset and B∖A=∅B \setminus A = \emptyset iff A⊆BA \subseteq B and B⊆AB \subseteq A iff A=BA = B. For the second claim take xx. If x∈Ax \in A, then x∈A△(A△B)x \in A \triangle (A \triangle B) iff x∉A△Bx \notin A \triangle B iff x∈Bx \in B, since x∈Ax \in A and x∈A△Bx \in A \triangle B means x∉Bx \notin B. If x∉Ax \notin A, then x∈A△(A△B)x \in A \triangle (A \triangle B) iff x∈A△Bx \in A \triangle B iff x∈Bx \in B. In both cases the condition is x∈Bx \in B.

Exercise 2.1-8. The point (a,b)(a, b) lies in (A×B)∩(C×D)(A \times B) \cap (C \times D) iff a∈Aa \in A, b∈Bb \in B, a∈Ca \in C and b∈Db \in D. This holds iff a∈A∩Ca \in A \cap C and b∈B∩Db \in B \cap D, which says (a,b)∈(A∩C)×(B∩D)(a, b) \in (A \cap C) \times (B \cap D). For the union, take A=B={1}A = B = \{1\} and C=D={2}C = D = \{2\}. The left side is {(1,1),(2,2)}\{(1, 1), (2, 2)\} and the right side is {1,2}×{1,2}\{1, 2\} \times \{1, 2\}, with four elements.

Exercise 2.1-9. Suppose R={x:x∉x}R = \{x : x \notin x\} is a set. Then R∈RR \in R iff R∉RR \notin R, by the definition of RR applied to x=Rx = R. A statement cannot be equivalent to its own denial, so no such set exists.

Section 2.2: Functions

Exercise 2.2-1. x↦x+3x \mapsto x + 3 is injective and surjective: its inverse is y↦y−3y \mapsto y - 3. x↦x2x \mapsto x^2 is neither: f(−1)=f(1)f(-1) = f(1) and 22 is not a square. x↦2xx \mapsto 2x is injective and not surjective, since odd numbers are not values. x↦⌊x/2⌋x \mapsto \lfloor x / 2 \rfloor is surjective, since ⌊2m/2⌋=m\lfloor 2m / 2 \rfloor = m, and not injective, since 00 and 11 both give 00.

Exercise 2.2-2. f({3,8,13})={3}f(\{3, 8, 13\}) = \{3\}, since all three numbers have remainder 33. f−1({0})={0,5,10,15}f^{-1}(\{0\}) = \{0, 5, 10, 15\}.

Exercise 2.2-3. (g∘f)(n)=g(2n)=2n+3(g \circ f)(n) = g(2n) = 2n + 3 and (f∘g)(n)=f(n+3)=2n+6(f \circ g)(n) = f(n + 3) = 2n + 6. For n=0n = 0 they are 33 and 66, so the functions differ.

Exercise 2.2-4. Let ff and gg be surjective, and c∈Cc \in C. There is bb with g(b)=cg(b) = c and aa with f(a)=bf(a) = b, so g(f(a))=cg(f(a)) = c. Two bijections are injective and surjective, and the composition is injective (the theorem of Section 2.2, rule 1) and surjective, so it is bijective. The function f−1∘g−1f^{-1} \circ g^{-1} is a two-sided inverse of g∘fg \circ f: (g∘f)∘(f−1∘g−1)=g∘(f∘f−1)∘g−1=g∘g−1=id(g \circ f) \circ (f^{-1} \circ g^{-1}) = g \circ (f \circ f^{-1}) \circ g^{-1} = g \circ g^{-1} = \mathrm{id}, and in the other order the same. By the uniqueness of the inverse, it is (g∘f)−1(g \circ f)^{-1}.

Exercise 2.2-5. Let f(a)=f(a′)f(a) = f(a'). Then g(f(a))=g(f(a′))g(f(a)) = g(f(a')), so a=a′a = a' since g∘fg \circ f is injective. For an example with gg not injective, take A={1}A = \{1\}, B={1,2}B = \{1, 2\}, C={1}C = \{1\}, f(1)=1f(1) = 1, g(1)=g(2)=1g(1) = g(2) = 1.

Exercise 2.2-6. Suppose ff is not injective. There are a≠a′a \ne a' with f(a)=f(a′)f(a) = f(a'). Take S={a}S = \{a\} and S′={a′}S' = \{a'\}. Then S∩S′=∅S \cap S' = \emptyset, so f(S∩S′)=∅f(S \cap S') = \emptyset, but f(S)∩f(S′)={f(a)}≠∅f(S) \cap f(S') = \{f(a)\} \ne \emptyset. So equality for all SS and S′S' fails. By contraposition, equality for all pairs implies that ff is injective.

Exercise 2.2-7. For a∈Aa \in A: a∈f−1(T‾)a \in f^{-1}(\overline{T}) iff f(a)∈B∖Tf(a) \in B \setminus T iff f(a)∉Tf(a) \notin T iff a∉f−1(T)a \notin f^{-1}(T) iff a∈f−1(T)‾a \in \overline{f^{-1}(T)}. The step from f(a)∈Bf(a) \in B is clear, since every f(a)f(a) is in BB.

Exercise 2.2-8. From y=5x+1y = 5x + 1 get 5x=y−15x = y - 1. Since 5⋅3=15≡1(mod7)5 \cdot 3 = 15 \equiv 1 \pmod 7, multiplication by 33 undoes multiplication by 55, so x=3(y−1) mod 7x = 3(y - 1) \bmod 7. The inverse is g(y)=3(y−1) mod 7g(y) = 3(y - 1) \bmod 7. Check: f(2)=11 mod 7=4f(2) = 11 \bmod 7 = 4 and g(4)=9 mod 7=2g(4) = 9 \bmod 7 = 2. For general aa: if a=0a = 0 the function is constant 11 and is not injective. If a∈{1,…,6}a \in \{1, \dots, 6\}, then aa has an inverse a′a' modulo 77: the pairs are 1⋅11 \cdot 1, 2⋅42 \cdot 4, 3⋅53 \cdot 5, 4⋅24 \cdot 2, 5⋅35 \cdot 3, 6⋅66 \cdot 6, with the product ≡1\equiv 1 in each case. Then x=a′(y−1) mod 7x = a'(y - 1) \bmod 7 is an inverse function, so ff is bijective. The list is a∈{1,2,3,4,5,6}a \in \{1, 2, 3, 4, 5, 6\}.

Exercise 2.2-9. Let D={a∈A:a∉f(a)}D = \{a \in A : a \notin f(a)\}, a subset of AA. Suppose D=f(d)D = f(d) for some d∈Ad \in A. Then d∈Dd \in D iff d∉f(d)d \notin f(d) by the definition of DD, and f(d)=Df(d) = D, so d∈Dd \in D iff d∉Dd \notin D. This is a contradiction. So DD is not a value of ff, and ff is not surjective.

Section 2.3: Finite sets and counting

Exercise 2.3-1. There are 28=2562^8 = 256 subsets. The subsets with at most one element are the empty set and the 88 singletons, so 99. The map of subsets to bit strings is a bijection, so 99 bit strings of length 88 have at most one 11.

Exercise 2.3-2. There are ⌊200/3⌋=66\lfloor 200 / 3 \rfloor = 66 multiples of 33, 2828 multiples of 77 and 99 multiples of 2121. By inclusion and exclusion 66+28−9=8566 + 28 - 9 = 85 are multiples of 33 or 77. The other 200−85=115200 - 85 = 115 are multiples of neither.

Exercise 2.3-3. There are 26⋅25⋅24=1560026 \cdot 25 \cdot 24 = 15600 ways to choose three different letters in order, and 10310^3 choices of digits. The product rule gives 15,600,00015{,}600{,}000.

Exercise 2.3-4. The sets A∖BA \setminus B and A∩BA \cap B are disjoint and their union is AA. By the sum rule ∣A∣=∣A∖B∣+∣A∩B∣|A| = |A \setminus B| + |A \cap B|.

Exercise 2.3-5. The union has 40+35+30−15−12−10+5=7340 + 35 + 30 - 15 - 12 - 10 + 5 = 73 students. So 80−73=780 - 73 = 7 take none of the three.

Exercise 2.3-6. Use the four boxes {1,8}\{1, 8\}, {2,7}\{2, 7\}, {3,6}\{3, 6\} and {4,5}\{4, 5\}. Five chosen numbers are mapped to four boxes. Two of them are in one box, and they are different numbers, so they are the two numbers of the box, with sum 99.

Exercise 2.3-7. Map each integer to its remainder modulo nn. There are n+1n + 1 integers and nn remainders, so two integers have the same remainder, and their difference is a multiple of nn. For the second claim, form six classes of remainders modulo 1010: {0}\{0\}, {1,9}\{1, 9\}, {2,8}\{2, 8\}, {3,7}\{3, 7\}, {4,6}\{4, 6\} and {5}\{5\}. Seven integers go to six classes, so two share a class. If their remainders are equal, the difference is a multiple of 1010. If they are rr and 10−r10 - r, the sum is a multiple of 1010.

Exercise 2.3-8. Cut the square into nine unit squares. Ten points go to nine squares, so two points lie in the same unit square. Two points of a closed unit square are at distance at most its diagonal, 2\sqrt 2.

Exercise 2.3-9. A function onto a 22-set {u,v}\{u, v\} is a function that is not constant. There are 2n2^n functions and 22 constant ones, so 2n−22^n - 2 surjections (for n≥1n \ge 1). For a 33-set, the functions that miss a given element number 2n2^n, those that miss two given elements number 11, and those that miss all three number 00 for n≥1n \ge 1. Inclusion and exclusion gives 3n−3⋅2n+3⋅1−03^n - 3 \cdot 2^n + 3 \cdot 1 - 0. For n=3n = 3 this is 27−24+3=627 - 24 + 3 = 6, which is 3!3!, the number of bijections from a 33-set onto a 33-set. Every surjection between sets of equal size is a bijection by Exercise 10.

Exercise 2.3-10. Let ∣A∣=n|A| = n. If ff is injective, then ff is a bijection from AA onto f(A)f(A), so ∣f(A)∣=n|f(A)| = n. The sets f(A)f(A) and A∖f(A)A \setminus f(A) are disjoint with union AA, so ∣A∖f(A)∣=0|A \setminus f(A)| = 0 and f(A)=Af(A) = A. Conversely let ff be surjective and suppose f(a)=f(a′)f(a) = f(a') with a≠a′a \ne a'. Then ff still maps A′=A∖{a′}A' = A \setminus \{a'\} onto AA, since the value f(a′)f(a') is also the value f(a)f(a). Choose for each b∈Ab \in A one element g(b)∈A′g(b) \in A' with f(g(b))=bf(g(b)) = b. The function gg is injective, since f∘gf \circ g is the identity. But ∣A′∣=n−1<n|A'| = n - 1 < n, which contradicts the pigeonhole principle. On ℕ\mathbb{N}, the function n↦n+1n \mapsto n + 1 is injective and not surjective, and n↦⌊n/2⌋n \mapsto \lfloor n / 2 \rfloor is surjective and not injective.

Solutions to Chapter 3: Methods of proof

Section 3.1: Direct proof

Exercise 3.1-1. Let a=2ka = 2k be even and b=2m+1b = 2m + 1 be odd. Then a+b=2(k+m)+1a + b = 2(k + m) + 1, which is odd.

Exercise 3.1-2. Let b=aub = au and c=avc = av. Then b+c=a(u+v)b + c = a(u + v), so a∣b+ca \mid b + c. Also bc=b⋅av=a(bv)bc = b \cdot av = a(bv), so a∣bca \mid bc.

Exercise 3.1-3. If n=2kn = 2k, then 3n2+n=12k2+2k=2(6k2+k)3n^2 + n = 12k^2 + 2k = 2(6k^2 + k). If n=2k+1n = 2k + 1, then 3n2+n=3(4k2+4k+1)+2k+1=12k2+14k+4=2(6k2+7k+2)3n^2 + n = 3(4k^2 + 4k + 1) + 2k + 1 = 12k^2 + 14k + 4 = 2(6k^2 + 7k + 2). Both are even.

Exercise 3.1-4. If x≤yx \le y, then max⁡=y\max = y and ∣x−y∣=y−x|x - y| = y - x, so the right side is (x+y+y−x)/2=y(x + y + y - x)/2 = y. If x>yx > y, then max⁡=x\max = x and ∣x−y∣=x−y|x - y| = x - y, so the right side is (x+y+x−y)/2=x(x + y + x - y)/2 = x.

Exercise 3.1-5. If n=2kn = 2k then n2=4k2n^2 = 4k^2 has remainder 00. If n=2k+1n = 2k + 1 then n2=4(k2+k)+1n^2 = 4(k^2 + k) + 1 has remainder 11. A sum a2+b2a^2 + b^2 has remainder 00, 11 or 22, never 33. The number 20232023 has remainder 33 (since 2020=4⋅5052020 = 4 \cdot 505), so it is not a sum of two squares.

Exercise 3.1-6. Of three consecutive integers n−1n - 1, nn, n+1n + 1, at least one is even, since the parities alternate. Exactly one is a multiple of 33, since the remainders mod 33 of consecutive integers are three different values in a cycle. So the product has the factors 22 and 33. As 22 and 33 have no common factor, 66 divides the product: if 2∣m2 \mid m and 3∣m3 \mid m, write m=2tm = 2t; then 3∣2t3 \mid 2t, so 3∣3t−2t=t3 \mid 3t - 2t = t, and 6∣m6 \mid m.

Exercise 3.1-7. (x2+y2)/2−xy=(x−y)2/2≥0(x^2 + y^2)/2 - xy = (x - y)^2/2 \ge 0. For x,y≥0x, y \ge 0 apply this to x\sqrt x and y\sqrt y: xy=xy≤(x+y)/2\sqrt{xy} = \sqrt x \sqrt y \le (x + y)/2.

Exercise 3.1-8. Let b=acb = ac and a=bda = bd with positive integers cc and dd. Then a=acda = acd, so cd=1cd = 1 since a>0a > 0. Positive integers with product 11 are both 11, so b=ab = a.

Exercise 3.1-9. For n=0,…,39n = 0, \dots, 39 the numbers 41,43,47,53,…41, 43, 47, 53, \dots are prime (a computer check). For n=40n = 40 the value is 1681=4121681 = 41^2. A proof by the method of the section must give an argument for every nn. A finite list of cases is not such an argument, and it is the form of a direct proof that rules out this use.

Exercise 3.1-10. If n=3kn = 3k, then 3∣n3 \mid n. If n=3k+1n = 3k + 1, then n−1=3kn - 1 = 3k. If n=3k+2n = 3k + 2, then n+1=3(k+1)n + 1 = 3(k + 1). In each case one of the factors of n3−n=(n−1)n(n+1)n^3 - n = (n - 1) n (n + 1) is a multiple of 33. The product of three consecutive integers is divisible by 66 (Exercise 3.1-6), so n3−nn^3 - n is divisible by 66.

Section 3.2: Indirect proof

Exercise 3.2-1. Suppose nn is odd, n=2k+1n = 2k + 1. Then 3n+2=6k+5=2(3k+2)+13n + 2 = 6k + 5 = 2(3k + 2) + 1 is odd. This is the contrapositive.

Exercise 3.2-2. Suppose nn is the largest integer. Then n+1n + 1 is an integer and n+1>nn + 1 > n, which contradicts the choice of nn.

Exercise 3.2-3. If 3∤p3 \nmid p, then p=3k+1p = 3k + 1 or p=3k+2p = 3k + 2, and p2=9k2+6k+1p^2 = 9k^2 + 6k + 1 or p2=9k2+12k+4p^2 = 9k^2 + 12k + 4, with remainder 11 in both cases. So 3∣p23 \mid p^2 implies 3∣p3 \mid p. Suppose 3=p/q\sqrt 3 = p/q in lowest terms. Then p2=3q2p^2 = 3q^2, so 3∣p3 \mid p, p=3kp = 3k, and 9k2=3q29k^2 = 3q^2 gives q2=3k2q^2 = 3k^2, so 3∣q3 \mid q. Both are multiples of 33, a contradiction.

Exercise 3.2-4. Suppose rxrx is rational, rx=u/vrx = u/v. Since r=s/tr = s/t with s≠0s \ne 0, x=(rx)/r=ut/(vs)x = (rx)/r = ut/(vs) is rational. This contradicts the choice of xx.

Exercise 3.2-5. Suppose x2−y2=2x^2 - y^2 = 2. Then (x−y)(x+y)=2(x - y)(x + y) = 2 with x−yx - y and x+yx + y of the same parity, because their difference is 2y2y. If both are odd, the product is odd. If both are even, the product is a multiple of 44. Neither gives 22. The same argument shows that x2−y2=4k+2x^2 - y^2 = 4k + 2 has no solution for any kk: the product is 22 more than a multiple of 44, so it is even but not a multiple of 44.

Exercise 3.2-6. Suppose log⁡102=p/q\log_{10} 2 = p/q with positive integers pp and qq (the number is positive). Then 10p=2q10^p = 2^q, that is, 2p5p=2q2^p 5^p = 2^q. If p≤qp \le q, divide by 2p2^p to get 5p=2q−p5^p = 2^{q - p}. The left side is odd and larger than 11, so q−p=0q - p = 0 is needed for oddness, and then 5p=15^p = 1, which is false for p≥1p \ge 1. If p>qp > q, divide by 2q2^q to get 2p−q5p=12^{p - q} 5^p = 1, which is false since the left side is larger than 11.

Exercise 3.2-7. Let N=n!+1≥3N = n! + 1 \ge 3, and let qq be its smallest divisor larger than 11. The number qq is a prime. Suppose q≤nq \le n. Then q∣n!q \mid n! and q∣Nq \mid N, so q∣N−n!=1q \mid N - n! = 1, which is false. So q>nq > n.

Exercise 3.2-8. Let ab=e=baab = e = ba and ac=e=caac = e = ca. Then b=be=b(ac)=(ba)c=ec=cb = be = b(ac) = (ba)c = ec = c.

Exercise 3.2-9. Suppose 6=p/q\sqrt 6 = p/q in lowest terms. Then p2=6q2p^2 = 6q^2, so p2p^2 is even and pp is even, p=2kp = 2k. Then 4k2=6q24k^2 = 6q^2 and 2k2=3q22k^2 = 3q^2. If qq were odd, 3q23q^2 would be odd, but 2k22k^2 is even. So qq is even, which contradicts the lowest terms. For the sum, suppose r=2+3r = \sqrt 2 + \sqrt 3 is rational. Then r2=5+26r^2 = 5 + 2\sqrt 6, so 6=(r2−5)/2\sqrt 6 = (r^2 - 5)/2 is rational. This contradicts the first part.

Exercise 3.2-10. Suppose aa and bb are both odd. Then a2a^2 and b2b^2 have remainder 11 mod 44, so a2+b2a^2 + b^2 has remainder 22. A square has remainder 00 or 11 mod 44 (Exercise 3.1-5), so a2+b2≠c2a^2 + b^2 \ne c^2. This is a contradiction. So at least one of aa and bb is even.

Section 3.3: Writing proofs and common errors

Exercise 3.3-1. If x≥0x \ge 0 then ∣x∣=x|x| = x. If x<0x < 0 then ∣x∣=−x>0>x|x| = -x > 0 > x. For the product, if x,y≥0x, y \ge 0 then xy≥0xy \ge 0 and ∣xy∣=xy=∣x∣∣y∣|xy| = xy = |x||y|. If x≥0>yx \ge 0 > y then xy≤0xy \le 0, so ∣xy∣=−xy=x(−y)=∣x∣∣y∣|xy| = -xy = x(-y) = |x||y|. The case x<0≤yx < 0 \le y is the same by symmetry. If x,y<0x, y < 0 then xy>0xy > 0 and ∣xy∣=xy=(−x)(−y)=∣x∣∣y∣|xy| = xy = (-x)(-y) = |x||y|.

Exercise 3.3-2. If n=2kn = 2k then n2+n=2(2k2+k)n^2 + n = 2(2k^2 + k). If n=2k+1n = 2k + 1 then n+1=2(k+1)n + 1 = 2(k + 1) and n2+n=n(n+1)n^2 + n = n(n + 1) is even. For n3−n=(n−1)n(n+1)n^3 - n = (n - 1) n (n + 1) one of the three factors is a multiple of 33: the remainders of n−1n - 1, nn, n+1n + 1 mod 33 are three consecutive values of a cycle, and one of them is 00.

Exercise 3.3-3. The error is the step "divide by a−ba - b", since a−b=0a - b = 0. A false proof of 0=10 = 1: let x=0x = 0. Then x⋅1=x⋅0x \cdot 1 = x \cdot 0, and "dividing by xx" gives 1=01 = 0. The same error is in another form.

Exercise 3.3-4. The claim is unchanged by the exchange of aa and bb, so wlog a≤ba \le b. Then max⁡(a,b)=b\max(a, b) = b and ∣a−b∣=b−a|a - b| = b - a, so (a+b+∣a−b∣)/2=(a+b+b−a)/2=b(a + b + |a - b|)/2 = (a + b + b - a)/2 = b.

Exercise 3.3-5. (a) a=6a = 6, b=2b = 2, c=3c = 3: 6∣66 \mid 6, but 6∤26 \nmid 2 and 6∤36 \nmid 3. (b) n=−1n = -1: n2=1>−1=nn^2 = 1 > -1 = n, but n≯1n \not> 1. (c) a=1a = 1, b=−1b = -1: a2=b2a^2 = b^2 and a≠ba \ne b.

Exercise 3.3-6. (i) implies (iii): if n=2kn = 2k then n2=4k2n^2 = 4k^2. (iii) implies (ii): a multiple of 44 is a multiple of 22. (ii) implies (i): if nn is odd then n2n^2 is odd (parity theorem), which is the contrapositive. The cycle proves all three equivalent.

Exercise 3.3-7. The step divides by xx, and xx may be 00. The claim is false: x=0x = 0 satisfies x2=xx^2 = x and x≠1x \ne 1. The correct statement is x=0x = 0 or x=1x = 1, by x(x−1)=0x(x - 1) = 0.

Exercise 3.3-8. For n=40n = 40 the value is 1681=41⋅411681 = 41 \cdot 41, and for n=0,…,39n = 0, \dots, 39 the value is prime, as a computer check shows, so 4040 is the smallest. The values n≤100n \le 100 with a composite value are 40,41,44,49,56,65,76,81,82,84,87,89,91,9640, 41, 44, 49, 56, 65, 76, 81, 82, 84, 87, 89, 91, 96, which is 1414 values.

Exercise 3.3-9. If aa and bb are both even, a=2ka = 2k, b=2mb = 2m, then a+b=2(k+m)a + b = 2(k + m). If both are odd, a=2k+1a = 2k + 1, b=2m+1b = 2m + 1, then a+b=2(k+m+1)a + b = 2(k + m + 1). If one is even and one is odd, the sum is odd (Exercise 3.1-1). The three cases cover all pairs. So a+ba + b is even iff aa and bb have the same parity.

Exercise 3.3-10. In the integers, the first sentence is true (y=x+1y = x + 1) and the second is false (there is no largest integer). In the interval [0,1][0, 1] of the reals, both are false: for x=1x = 1 there is no y>1y > 1 in the interval, and for each yy the element x=yx = y gives y>xy > x false. The error is a swap of the quantifiers: the yy of the first sentence depends on xx, and the second needs one yy for all xx.

Solutions to Chapter 4: Mathematical induction

Section 4.1: The principle of induction

Exercise 4.1-1. Base: 1=1⋅2/21 = 1 \cdot 2/2. Step: k(k+1)/2+(k+1)=(k+1)(k+2)/2k(k + 1)/2 + (k + 1) = (k + 1)(k + 2)/2. For n=100n = 100 the sum is 100⋅101/2=5050100 \cdot 101/2 = 5050.

Exercise 4.1-2. Base: 2=1⋅22 = 1 \cdot 2. Step: k(k+1)+2(k+1)=(k+1)(k+2)k(k + 1) + 2(k + 1) = (k + 1)(k + 2).

Exercise 4.1-3. Base: 40−1=04^0 - 1 = 0. Step: if 4k−1=3m4^k - 1 = 3m, then 4k+1−1=4(3m+1)−1=3(4m+1)4^{k+1} - 1 = 4(3m + 1) - 1 = 3(4m + 1). For 6n6^n: 60−1=06^0 - 1 = 0, and if 6k−1=5m6^k - 1 = 5m then 6k+1−1=6(5m+1)−1=5(6m+1)6^{k+1} - 1 = 6(5m + 1) - 1 = 5(6m + 1).

Exercise 4.1-4. Base: 1=21−11 = 2^1 - 1. Step: 2k+1−1+2k+1=2k+2−12^{k+1} - 1 + 2^{k+1} = 2^{k+2} - 1. A complete binary tree with levels 00 to 99 has 1+2+⋯+29=210−1=10231 + 2 + \cdots + 2^9 = 2^{10} - 1 = 1023 nodes.

Exercise 4.1-5. Base: 20=1≥12^0 = 1 \ge 1. Step: 2k+1=2⋅2k≥2k+2≥k+22^{k+1} = 2 \cdot 2^k \ge 2k + 2 \ge k + 2. For the factorial, base 1!=1≥201! = 1 \ge 2^0. Step: (k+1)!=(k+1)k!≥2⋅2k−1=2k(k + 1)! = (k + 1) k! \ge 2 \cdot 2^{k-1} = 2^k, since k+1≥2k + 1 \ge 2.

Exercise 4.1-6. Base: 1⋅2=2=0⋅4+21 \cdot 2 = 2 = 0 \cdot 4 + 2. Step: (k−1)2k+1+2+(k+1)2k+1=2k⋅2k+1+2=k2k+2+2(k - 1)2^{k+1} + 2 + (k + 1)2^{k+1} = 2k \cdot 2^{k+1} + 2 = k 2^{k+2} + 2, which is the formula for k+1k + 1.

Exercise 4.1-7. Base: 2=1⋅2⋅3/32 = 1 \cdot 2 \cdot 3/3. Step: k(k+1)(k+2)/3+(k+1)(k+2)=(k+1)(k+2)(k+3)/3k(k + 1)(k + 2)/3 + (k + 1)(k + 2) = (k + 1)(k + 2)(k + 3)/3.

Exercise 4.1-8. Base: 80−1=08^0 - 1 = 0. Step: 8k+1−1=8(8k−1)+78^{k+1} - 1 = 8(8^k - 1) + 7, a sum of two multiples of 77. For n3−nn^3 - n: n=0n = 0 gives 00. Step: (k+1)3−(k+1)=(k3−k)+3k(k+1)(k + 1)^3 - (k + 1) = (k^3 - k) + 3k(k + 1). The product k(k+1)k(k + 1) is even, so 3k(k+1)3k(k + 1) is a multiple of 66, and k3−kk^3 - k is a multiple of 66 by the hypothesis.

Exercise 4.1-9. The proof is in the text: (1+x)k+1≥(1+x)(1+kx)=1+(k+1)x+kx2≥1+(k+1)x(1 + x)^{k+1} \ge (1 + x)(1 + kx) = 1 + (k + 1)x + kx^2 \ge 1 + (k + 1)x, where the first step multiplies the hypothesis by 1+x≥01 + x \ge 0. For x=−4x = -4 and n=3n = 3: (1+x)3=−27<−11=1+3x(1 + x)^3 = -27 < -11 = 1 + 3x. The step fails because 1+x=−3<01 + x = -3 < 0 reverses the inequality when it is multiplied.

Exercise 4.1-10. The step claims that 3⋅2k+30≤2k+1+103 \cdot 2^k + 30 \le 2^{k+1} + 10. This is 2k+20≤02^k + 20 \le 0, which is false for every kk. So the step is wrong. The claim holds for n=0,1,2n = 0, 1, 2 (1<111 < 11, 3<123 < 12, 9<149 < 14) and fails at n=3n = 3, where 27>1827 > 18.

Section 4.2: Stronger claims and recurrences

Exercise 4.2-1. F13=233F_{13} = 233 and F14=377F_{14} = 377. Also F15=610F_{15} = 610, and F15F13−F142=142130−142129=1=(−1)14F_{15} F_{13} - F_{14}^2 = 142130 - 142129 = 1 = (-1)^{14}.

Exercise 4.2-2. Base: 1/2=1−1/21/2 = 1 - 1/2. Step: 1−1/(k+1)+1/((k+1)(k+2))=1−1/(k+2)1 - 1/(k + 1) + 1/((k + 1)(k + 2)) = 1 - 1/(k + 2). For n=99n = 99 the sum is 1−1/100=99/1001 - 1/100 = 99/100.

Exercise 4.2-3. Base: 1=1⋅2⋅3/61 = 1 \cdot 2 \cdot 3/6. Step: k(k+1)(2k+1)/6+(k+1)2=(k+1)(2k2+k+6k+6)/6=(k+1)(2k2+7k+6)/6=(k+1)(k+2)(2k+3)/6k(k + 1)(2k + 1)/6 + (k + 1)^2 = (k + 1)(2k^2 + k + 6k + 6)/6 = (k + 1)(2k^2 + 7k + 6)/6 = (k + 1)(k + 2)(2k + 3)/6, which is the formula for k+1k + 1.

Exercise 4.2-4. Base: F1=1=F2F_1 = 1 = F_2. Step: F2k+F2k+1=F2k+2F_{2k} + F_{2k+1} = F_{2k+2}, and F2k+1F_{2k+1} is the new term F2(k+1)−1F_{2(k+1)-1}.

Exercise 4.2-5. Base cases: F1=1≤1F_1 = 1 \le 1 and F2=1≤5/3F_2 = 1 \le 5/3. Step: assume the bound for kk and k+1k + 1. Then Fk+2≤(5/3)k+(5/3)k−1=(5/3)k−1⋅8/3F_{k+2} \le (5/3)^k + (5/3)^{k-1} = (5/3)^{k-1} \cdot 8/3, and 8/3=24/9≤25/9=(5/3)28/3 = 24/9 \le 25/9 = (5/3)^2. So Fk+2≤(5/3)k+1F_{k+2} \le (5/3)^{k+1}.

Exercise 4.2-6. The values are 2,3,5,9,172, 3, 5, 9, 17, which suggest an=2n+1a_n = 2^n + 1. Base: a0=2a_0 = 2 and a1=3a_1 = 3. Step: 3(2k+1+1)−2(2k+1)=6⋅2k−2⋅2k+3−2=2k+2+13(2^{k+1} + 1) - 2(2^k + 1) = 6 \cdot 2^k - 2 \cdot 2^k + 3 - 2 = 2^{k+2} + 1.

Exercise 4.2-7. The proof of the identity is in the text. If dd divides Fn+1F_{n+1} and FnF_n, then dd divides Fn+1Fn−1−Fn2=(−1)nF_{n+1}F_{n-1} - F_n^2 = (-1)^n, so d=1d = 1 (for d>0d > 0).

Exercise 4.2-8. Fix m≥1m \ge 1 and induct on nn with two base cases. For n=0n = 0: Fm=FmF1+Fm−1F0F_m = F_m F_1 + F_{m-1} F_0. For n=1n = 1: Fm+1=FmF2+Fm−1F1=Fm+Fm−1F_{m+1} = F_m F_2 + F_{m-1} F_1 = F_m + F_{m-1}. Step: assume the identity for nn and for n+1n + 1. Add the two equations Fm+n+1=FmFn+2+Fm−1Fn+1F_{m+n+1} = F_m F_{n+2} + F_{m-1} F_{n+1} and Fm+n=FmFn+1+Fm−1FnF_{m+n} = F_m F_{n+1} + F_{m-1} F_n to get Fm+n+2=Fm(Fn+2+Fn+1)+Fm−1(Fn+1+Fn)=FmFn+3+Fm−1Fn+2F_{m+n+2} = F_m (F_{n+2} + F_{n+1}) + F_{m-1}(F_{n+1} + F_n) = F_m F_{n+3} + F_{m-1} F_{n+2}, the identity for n+2n + 2.

Exercise 4.2-9. The claim and proof are in the text. The claim "the sum is less than 22" does not go by induction: from the hypothesis that the sum up to kk is less than 22 one gets only that the sum up to k+1k + 1 is less than 2+1/(k+1)22 + 1/(k + 1)^2, and the step does not give a bound by 22. The stronger claim gives the room 1/k1/k that the new term needs.

Exercise 4.2-10. The proof for F3nF_{3n} is in the text. For the identity: Fn+4=Fn+3+Fn+2=2Fn+2+Fn+1=2(Fn+1+Fn)+Fn+1=3Fn+1+2FnF_{n+4} = F_{n+3} + F_{n+2} = 2F_{n+2} + F_{n+1} = 2(F_{n+1} + F_n) + F_{n+1} = 3F_{n+1} + 2F_n. With n=4mn = 4m: F4m+4=3F4m+1+2F4mF_{4m+4} = 3F_{4m+1} + 2F_{4m}. By induction on mm, 3∣F4m3 \mid F_{4m}: the base is F0=0F_0 = 0, and if 3∣F4m3 \mid F_{4m} then both terms are multiples of 33.

Section 4.3: Induction on other quantities

Exercise 4.3-1. The proof is in the text. The subsets of {1,…,8}\{1, \dots, 8\} with an even number of elements correspond one-to-one with those with an odd number, by adding or removing the element 11. So half of the 28=2562^8 = 256 subsets are even: 128128.

Exercise 4.3-2. The pairs: the count follows from the handshake example with nn people. For a convex polygon with nn sides, each pair of vertices is a side or a diagonal, and there are nn sides, so the diagonals number n(n−1)/2−n=n(n−3)/2n(n - 1)/2 - n = n(n - 3)/2. For n=6n = 6 this is 99.

Exercise 4.3-3. After the passes 11 to 55 the pairs (s,t)(s, t) are (1,3)(1, 3), (4,5)(4, 5), (9,7)(9, 7), (16,9)(16, 9), (25,11)(25, 11).

Exercise 4.3-4. Base: x=1=20x = 1 = 2^0. Step: x=2kx = 2^k becomes 2⋅2k=2k+12 \cdot 2^k = 2^{k+1}. The body x←x+xx \gets x + x gives x+x=2xx + x = 2x, so it is the same statement.

Exercise 4.3-5. The proof is in the text. For 2020 lines the greatest number of regions is (400+20+2)/2=211(400 + 20 + 2)/2 = 211.

Exercise 4.3-6. Base: for n=1n = 1 the integers are 1,…,91, \dots, 9, and 9⋅100=99 \cdot 10^0 = 9. Step: each integer of k+1k + 1 digits is an integer of kk digits followed by a digit 00 to 99, and the correspondence is one-to-one. So the count is 10⋅9⋅10k−1=9⋅10k10 \cdot 9 \cdot 10^{k-1} = 9 \cdot 10^k.

Exercise 4.3-7. The proof is in the text. The number 123456789123456789 has the digit sum 4545, a multiple of 99. The number 10485761048576 has the digit sum 1+0+4+8+5+7+6=311 + 0 + 4 + 8 + 5 + 7 + 6 = 31, and 31=3⋅9+431 = 3 \cdot 9 + 4, so the remainder is 44. This agrees with 26=64≡12^6 = 64 \equiv 1 and 220=218⋅4≡42^{20} = 2^{18} \cdot 4 \equiv 4.

Exercise 4.3-8. Base: with one player there are 00 matches. Step: let there be k+1≥2k + 1 \ge 2 players. Play one match. The loser leaves, and kk players remain. By the hypothesis the rest of the tournament has k−1k - 1 matches, so the total is 1+(k−1)=k=(k+1)−11 + (k - 1) = k = (k + 1) - 1.

Exercise 4.3-9. A board of side 33 has 9−1=89 - 1 = 8 cells and a board of side 66 has 36−1=3536 - 1 = 35 cells after the removal, and neither number is a multiple of 33. Pieces of three cells cannot cover them. For the side 44, number the rows and columns 11 to 44 and remove the cell (1,1)(1, 1). The center piece covers (2,3)(2, 3), (3,2)(3, 2) and (3,3)(3, 3). The four quadrants are each a 2×22 \times 2 square minus one cell, and each is one piece: {(1,2),(2,1),(2,2)}\{(1, 2), (2, 1), (2, 2)\}, {(1,3),(1,4),(2,4)}\{(1, 3), (1, 4), (2, 4)\}, {(3,1),(4,1),(4,2)}\{(3, 1), (4, 1), (4, 2)\} and {(3,4),(4,3),(4,4)}\{(3, 4), (4, 3), (4, 4)\}. The count is 5=(16−1)/35 = (16 - 1)/3.

Exercise 4.3-10. The step fails for k=1k = 1, going from one person to two. The two groups of k=1k = 1 person that are obtained by removing one person each share no person, so the argument that the groups share a person does not hold. The step is valid for k≥2k \ge 2, and the base n=1n = 1 does not lead to n=2n = 2.

Solutions to Chapter 5: Strong induction and well ordering

Section 5.1: Strong induction

Exercise 5.1-1. Base cases: 12=3⋅412 = 3 \cdot 4, 13=2⋅4+513 = 2 \cdot 4 + 5, 14=4+2⋅514 = 4 + 2 \cdot 5, 15=3⋅515 = 3 \cdot 5. Step: for k≥16k \ge 16 the amount k−4≥12k - 4 \ge 12 is payable by the hypothesis, and one more stamp of 44 pays kk. The amounts 1,2,3,6,7,111, 2, 3, 6, 7, 11 cannot be paid, and a check of the amounts up to 1111 shows no others.

Exercise 5.1-2. Base cases: 12=4⋅312 = 4 \cdot 3, 13=2⋅3+713 = 2 \cdot 3 + 7, 14=2⋅714 = 2 \cdot 7. Step: for k≥15k \ge 15 the amount k−3≥12k - 3 \ge 12 is payable, and a stamp of 33 pays kk. The amounts that cannot be paid are 1,2,4,5,8,111, 2, 4, 5, 8, 11.

Exercise 5.1-3. The proof is in the text. For 7575 the largest power is 6464, then 75−64=1175 - 64 = 11 with the largest power 88, then 3=2+13 = 2 + 1. So 75=64+8+2+175 = 64 + 8 + 2 + 1.

Exercise 5.1-4. The proof is in the text. The least prime divisor of 20232023 is 77, since 2023=7⋅2892023 = 7 \cdot 289 and 22, 33, 55 do not divide it. The least prime divisor of 3003130031 is 5959, since 30031=59⋅50930031 = 59 \cdot 509 and no smaller prime divides it.

Exercise 5.1-5. The proof is in the text. 1001=7⋅11⋅131001 = 7 \cdot 11 \cdot 13 and 1024=2101024 = 2^{10}, ten factors of 22.

Exercise 5.1-6. The proof is in the text. For n=1000n = 1000, 29=512≤1000<1024=2102^9 = 512 \le 1000 < 1024 = 2^{10}, so ⌊log⁡21000⌋=9\lfloor \log_2 1000 \rfloor = 9 and T(1000)=10T(1000) = 10. As a check, the sequence 1000,500,250,125,62,31,15,7,3,11000, 500, 250, 125, 62, 31, 15, 7, 3, 1 has ten terms.

Exercise 5.1-7. The proof is in the text. For 100100 the largest Fibonacci number at most 100100 is F11=89F_{11} = 89, then 1111 has the largest F6=8F_6 = 8, then 3=F43 = F_4. So 100=89+8+3100 = 89 + 8 + 3.

Exercise 5.1-8. Let n=p1⋯ptn = p_1 \cdots p_t be a product of tt primes. Each pi≥2p_i \ge 2, so n≥2tn \ge 2^t (an induction on tt: the case t=1t = 1 is p1≥2p_1 \ge 2, and multiplying by one more factor of at least 22 doubles the bound). So t≤log⁡2nt \le \log_2 n. For n=1024n = 1024, t=10t = 10 and the bound is attained.

Exercise 5.1-9. For strong from weak, let Q(n)Q(n) say that P(j)P(j) holds for all a≤j≤na \le j \le n, with Q(a−1)Q(a - 1) true and empty. A step Q(k)→Q(k+1)Q(k) \to Q(k + 1) is the strong hypothesis for k+1k + 1, so weak induction proves Q(n)Q(n) for all n≥a−1n \ge a - 1 and hence P(n)P(n) for n≥an \ge a. For weak from strong, suppose P(a)P(a) and P(k)→P(k+1)P(k) \to P(k + 1) for k≥ak \ge a. Let k≥ak \ge a and assume P(j)P(j) for all a≤j<ka \le j < k. If k=ak = a, then P(k)P(k) is the base. If k>ak > a, then P(k−1)P(k - 1) holds, and the step gives P(k)P(k).

Exercise 5.1-10. The step writes kk as (k−2)+2(k - 2) + 2, and it uses the hypothesis for k−2k - 2, which needs 2≤k−22 \le k - 2, that is, k≥4k \ge 4. For k=2k = 2 the number k−2=0k - 2 = 0 is not in the range of the claim, and for k=3k = 3 the number k−2=1k - 2 = 1 is not in the range. So the cases k=2k = 2 and k=3k = 3 fail, and 33 is a counterexample to the claim.

Section 5.2: Well ordering

Exercise 5.2-1. The set ℤ\mathbb Z of integers has no least element, since n−1<nn - 1 < n. The set ℚ\mathbb Q of rational numbers has none, for the same reason. The set {1/n:n≥1}\{1/n : n \ge 1\} of positive rationals is bounded below by 00 and has no least element, since 1/(n+1)<1/n1/(n + 1) < 1/n.

Exercise 5.2-2. 100=14⋅7+2100 = 14 \cdot 7 + 2. −100=(−15)⋅7+5-100 = (-15) \cdot 7 + 5, since −15⋅7=−105-15 \cdot 7 = -105. 0=0⋅5+00 = 0 \cdot 5 + 0. 3=0⋅5+33 = 0 \cdot 5 + 3. So the pairs (q,r)(q, r) are (14,2)(14, 2), (−15,5)(-15, 5), (0,0)(0, 0) and (0,3)(0, 3).

Exercise 5.2-3. Suppose the claim is false, and let mm be the least nn with n≥2nn \ge 2^n. Since 0<10 < 1, m≥1m \ge 1. The number m−1m - 1 is smaller than mm, so m−1<2m−1m - 1 < 2^{m-1}, which gives m≤2m−1m \le 2^{m-1}. Then 2m=2⋅2m−1≥2m≥m+1>m2^m = 2 \cdot 2^{m-1} \ge 2m \ge m + 1 > m, contrary to m≥2mm \ge 2^m.

Exercise 5.2-4. Let a=qb+r=q′b+r′a = qb + r = q'b + r' with 0≤r,r′<b0 \le r, r' < b. Then (q−q′)b=r′−r(q - q')b = r' - r and ∣r′−r∣<b|r' - r| < b. A multiple of bb of absolute value below bb is 00, so q=q′q = q' and r=r′r = r'. If only ∣r∣<b|r| < b is required, then 7=1⋅5+2=2⋅5+(−3)7 = 1 \cdot 5 + 2 = 2 \cdot 5 + (-3) gives two pairs.

Exercise 5.2-5. Let SS be a set of natural numbers with no least element, and let P(n)P(n) be "n∉Sn \notin S". Let kk be a natural number and assume P(j)P(j) for all j<kj < k. If k∈Sk \in S, then kk would be a least element of SS, since no smaller number is in SS. So k∉Sk \notin S. By strong induction no number is in SS, so SS is empty. Hence a nonempty set has a least element.

Exercise 5.2-6. Suppose some integer nn has 0<n<10 < n < 1. The set of such integers is nonempty and has a least element mm. Then 0<m2<m0 < m^2 < m, since 0<m<10 < m < 1, so m2m^2 is an integer with 0<m2<10 < m^2 < 1 and m2<mm^2 < m. This contradicts the choice of mm.

Exercise 5.2-7. Suppose 3\sqrt 3 is rational. Then the set SS of positive integers qq with q3q\sqrt 3 an integer is nonempty. Let qq be its least element and p=q3p = q\sqrt 3. Since 1<3<21 < \sqrt 3 < 2, q<p<2qq < p < 2q. Let q′=p−qq' = p - q, so 0<q′<q0 < q' < q. Then q′3=3q−pq'\sqrt 3 = 3q - p is an integer, so q′∈Sq' \in S, which contradicts the choice of qq.

Exercise 5.2-8. Let SS be nonempty with s≤Bs \le B for all s∈Ss \in S. The set T={B−s:s∈S}T = \{B - s : s \in S\} is a nonempty set of natural numbers. Let B−s∗B - s^* be its least element. For s∈Ss \in S, B−s∗≤B−sB - s^* \le B - s gives s≤s∗s \le s^*. So s∗s^* is the greatest element of SS.

Exercise 5.2-9. Let s0=ms_0 = m, s1=ns_1 = n and si+1=si−1 mod sis_{i+1} = s_{i-1} \bmod s_i, with s1≤s0s_1 \le s_0 and si+1>0s_{i+1} > 0. The remainders s2,s3,…s_2, s_3, \dots decrease since si+1<sis_{i+1} < s_i. Now si+2=si mod si+1s_{i+2} = s_i \bmod s_{i+1}. If si+1≤si/2s_{i+1} \le s_i/2, then si+2<si+1≤si/2s_{i+2} < s_{i+1} \le s_i/2. If si+1>si/2s_{i+1} > s_i/2, then si=1⋅si+1+(si−si+1)s_i = 1 \cdot s_{i+1} + (s_i - s_{i+1}) with 0≤si−si+1<si+10 \le s_i - s_{i+1} < s_{i+1}, so the remainder is si−si+1<si/2s_i - s_{i+1} < s_i/2. In both cases si+2<si/2s_{i+2} < s_i/2. So the number of divisions is at most about 2log⁡2n2 \log_2 n.

Exercise 5.2-10. Suppose some natural number is not in SS. The set of such numbers is nonempty, so it has a least element cc. Since 0∈S0 \in S, c≠0c \ne 0. All of 0,…,c−10, \dots, c - 1 are in SS by the choice of cc, so c=(c−1)+1∈Sc = (c - 1) + 1 \in S by the property of SS. This is a contradiction.

Section 5.3: The greatest common divisor and Euclid's algorithm

Exercise 5.3-1. For (544,119)(544, 119): 544=4⋅119+68544 = 4 \cdot 119 + 68, 119=1⋅68+51119 = 1 \cdot 68 + 51, 68=1⋅51+1768 = 1 \cdot 51 + 17, 51=3⋅17+051 = 3 \cdot 17 + 0. The answer is 1717 in four divisions. For (2024,1024)(2024, 1024): 2024=1⋅1024+10002024 = 1 \cdot 1024 + 1000, 1024=1⋅1000+241024 = 1 \cdot 1000 + 24, 1000=41⋅24+161000 = 41 \cdot 24 + 16, 24=1⋅16+824 = 1 \cdot 16 + 8, 16=2⋅8+016 = 2 \cdot 8 + 0. The answer is 88 in five divisions.

Exercise 5.3-2. 240=5⋅46+10240 = 5 \cdot 46 + 10, 46=4⋅10+646 = 4 \cdot 10 + 6, 10=1⋅6+410 = 1 \cdot 6 + 4, 6=1⋅4+26 = 1 \cdot 4 + 2, 4=2⋅2+04 = 2 \cdot 2 + 0. The gcd is 22. Going back: 2=6−4=6−(10−6)=2⋅6−10=2(46−4⋅10)−10=2⋅46−9⋅10=2⋅46−9(240−5⋅46)=47⋅46−9⋅2402 = 6 - 4 = 6 - (10 - 6) = 2 \cdot 6 - 10 = 2(46 - 4 \cdot 10) - 10 = 2 \cdot 46 - 9 \cdot 10 = 2 \cdot 46 - 9(240 - 5 \cdot 46) = 47 \cdot 46 - 9 \cdot 240. So x=−9x = -9 and y=47y = 47. Check: −2160+2162=2-2160 + 2162 = 2.

Exercise 5.3-3. Let m=qn+rm = qn + r. A common divisor dd of mm and nn divides m−qn=rm - qn = r, so it is a common divisor of nn and rr. A common divisor of nn and rr divides qn+r=mqn + r = m. The two sets of common divisors are equal, so their greatest elements are equal.

Exercise 5.3-4. From 17⋅11+31⋅(−6)=187−186=117 \cdot 11 + 31 \cdot (-6) = 187 - 186 = 1 the inverse of 1717 modulo 3131 is 1111. For 55 modulo 1212: 5⋅5=25=2⋅12+15 \cdot 5 = 25 = 2 \cdot 12 + 1, so the inverse is 55.

Exercise 5.3-5. By the proof of Bezout's identity, gcd⁡(a,b)\gcd(a, b) is the least positive number of the form ax+byax + by. The least positive number of the form kax+kby=k(ax+by)kax + kby = k(ax + by) is kk times that. So gcd⁡(ka,kb)=kgcd⁡(a,b)\gcd(ka, kb) = k \gcd(a, b).

Exercise 5.3-6. This is the first part of Euclid's lemma. Let ax+by=1ax + by = 1. Then c=acx+bcyc = acx + bcy, and aa divides both terms, since a∣bca \mid bc. So a∣ca \mid c.

Exercise 5.3-7. Let mx+ny=1mx + ny = 1 and mx′+n′y′=1mx' + n'y' = 1. Multiplying, 1=m(xmx′+xn′y′+nyx′)+nn′(yy′)1 = m(xmx' + xn'y' + nyx') + nn'(yy'). So 11 is a combination of mm and nn′nn', and every common divisor of mm and nn′nn' divides 11. Hence gcd⁡(m,nn′)=1\gcd(m, nn') = 1.

Exercise 5.3-8. By the key lemma, gcd⁡(Fk+1,Fk)=gcd⁡(Fk,Fk−1)=⋯=gcd⁡(F2,F1)=gcd⁡(1,1)=1\gcd(F_{k+1}, F_k) = \gcd(F_k, F_{k-1}) = \cdots = \gcd(F_2, F_1) = \gcd(1, 1) = 1. For the divisions, induct on k≥2k \ge 2. For k=2k = 2: F3=2=2⋅1+0F_3 = 2 = 2 \cdot 1 + 0, one division, =k−1= k - 1. Step: for the pair (Fk+2,Fk+1)(F_{k+2}, F_{k+1}) with k≥2k \ge 2, Fk+2=1⋅Fk+1+FkF_{k+2} = 1 \cdot F_{k+1} + F_k with 0<Fk<Fk+10 < F_k < F_{k+1}, so the first division gives remainder FkF_k, and the algorithm continues on (Fk+1,Fk)(F_{k+1}, F_k), which takes k−1k - 1 divisions. The total is k=(k+1)−1k = (k + 1) - 1.

Exercise 5.3-9. Claim: if n=p1⋯ps=q1⋯qtn = p_1 \cdots p_s = q_1 \cdots q_t with all pip_i and qjq_j prime, then s=ts = t and after a reordering pi=qip_i = q_i. Strong induction on n≥2n \ge 2. The prime p1p_1 divides q1⋯qtq_1 \cdots q_t. By Euclid's lemma (applied t−1t - 1 times, by induction on the number of factors) p1∣qjp_1 \mid q_j for some jj, and then p1=qjp_1 = q_j since qjq_j is prime and p1≥2p_1 \ge 2. Reorder so that j=1j = 1 and cancel: n/p1=p2⋯ps=q2⋯qtn/p_1 = p_2 \cdots p_s = q_2 \cdots q_t. If n/p1=1n/p_1 = 1, both products are empty and s=t=1s = t = 1. Otherwise n/p1<nn/p_1 < n is at least 22 and the hypothesis gives s−1=t−1s - 1 = t - 1 and the same primes after a reordering.

Exercise 5.3-10. The first part is the corollary of the text. For 15x+21y=915x + 21y = 9: gcd⁡(15,21)=3\gcd(15, 21) = 3 divides 99, so there are solutions. Dividing by 33, 5x+7y=35x + 7y = 3. A solution is x=2x = 2, y=−1y = -1, since 10−7=310 - 7 = 3. If (x,y)(x, y) is any solution, then 5(x−2)=−7(y+1)5(x - 2) = -7(y + 1), so 7∣5(x−2)7 \mid 5(x - 2), and 7∣x−27 \mid x - 2 by Euclid's lemma. So x=2+7tx = 2 + 7t and y=−1−5ty = -1 - 5t for an integer tt, and these are solutions for each tt. Check with t=1t = 1: 15⋅9+21⋅(−6)=135−126=915 \cdot 9 + 21 \cdot (-6) = 135 - 126 = 9.

Solutions to Chapter 6: Recursion and structural induction

Section 6.1: Recursive definitions

Exercise 6.1-1. The factorials for n=0,…,8n = 0, \dots, 8 are 1,1,2,6,24,120,720,5040,403201, 1, 2, 6, 24, 120, 720, 5040, 40320. The powers 2n2^n are 1,2,4,8,16,32,64,128,2561, 2, 4, 8, 16, 32, 64, 128, 256, each twice the one before.

Exercise 6.1-2. S(0)=0S(0) = 0 and S(n+1)=S(n)+(n+1)S(n + 1) = S(n) + (n + 1). Base: S(0)=0=0⋅1/2S(0) = 0 = 0 \cdot 1/2. Step: S(k+1)=k(k+1)/2+(k+1)=(k+1)(k+2)/2S(k + 1) = k(k + 1)/2 + (k + 1) = (k + 1)(k + 2)/2.

Exercise 6.1-3. d(n)=1d(n) = 1 for 1≤n≤91 \le n \le 9 and d(n)=1+d(⌊n/10⌋)d(n) = 1 + d(\lfloor n/10 \rfloor) for n≥10n \ge 10. Then d(2024)=1+d(202)=2+d(20)=3+d(2)=4d(2024) = 1 + d(202) = 2 + d(20) = 3 + d(2) = 4, and d(106)=7d(10^6) = 7 by the same chain through 105,…,10,110^5, \dots, 10, 1.

Exercise 6.1-4. Let s(n)=ns(n) = n for n≤9n \le 9 and s(n)=s(⌊n/10⌋)+(n mod 10)s(n) = s(\lfloor n/10 \rfloor) + (n \bmod 10) for n≥10n \ge 10. Strong induction on nn: for n≤9n \le 9, s(n)=ns(n) = n. For n≥10n \ge 10 write n=10q+tn = 10q + t with t=n mod 10t = n \bmod 10 and q<nq < n. By the hypothesis s(q)≡qs(q) \equiv q, and s(n)=s(q)+t≡q+t≡10q+t=n(mod9)s(n) = s(q) + t \equiv q + t \equiv 10q + t = n \pmod 9, since 10≡110 \equiv 1. For 220=10485762^{20} = 1048576 the digit sum is 1+0+4+8+5+7+6=311 + 0 + 4 + 8 + 5 + 7 + 6 = 31.

Exercise 6.1-5. The values are 1,3,7,15,311, 3, 7, 15, 31, so an=2n+1−1a_n = 2^{n+1} - 1. Base: a0=1=21−1a_0 = 1 = 2^1 - 1. Step: ak+1=2(2k+1−1)+1=2k+2−1a_{k+1} = 2(2^{k+1} - 1) + 1 = 2^{k+2} - 1.

Exercise 6.1-6. The proof is in the text. For n=20n = 20 the number of calls is 2F21−1=2⋅10946−1=218912F_{21} - 1 = 2 \cdot 10946 - 1 = 21891.

Exercise 6.1-7. Both give f(0)=1f(0) = 1 and f(1)=2f(1) = 2. At n=2n = 2 the first gives 44 and the second gives 33. So they differ first at n=2n = 2. The first defines 2n2^n and the second n+1n + 1.

Exercise 6.1-8. Let FF and F′F' satisfy the rules. Claim: F(n)=F′(n)F(n) = F'(n) for all nn. By strong induction. For n=0n = 0 and n=1n = 1 both are given. For n≥2n \ge 2, F(n)=F(n−1)+F(n−2)=F′(n−1)+F′(n−2)=F′(n)F(n) = F(n - 1) + F(n - 2) = F'(n - 1) + F'(n - 2) = F'(n), using the hypothesis for n−1n - 1 and n−2n - 2.

Exercise 6.1-9. For n>0n > 0 the remainder m mod nm \bmod n is in {0,…,n−1}\{0, \dots, n - 1\}, so the second argument of the call is smaller than nn. A decreasing chain of natural numbers is finite (well ordering), so the recursion ends at n=0n = 0. For (2024,1024)(2024, 1024): gcd⁡(2024,1024)=gcd⁡(1024,1000)=gcd⁡(1000,24)=gcd⁡(24,16)=gcd⁡(16,8)=gcd⁡(8,0)=8\gcd(2024, 1024) = \gcd(1024, 1000) = \gcd(1000, 24) = \gcd(24, 16) = \gcd(16, 8) = \gcd(8, 0) = 8.

Exercise 6.1-10. A(1,0)=A(0,1)=2A(1, 0) = A(0, 1) = 2 and A(1,n+1)=A(0,A(1,n))=A(1,n)+1A(1, n + 1) = A(0, A(1, n)) = A(1, n) + 1, so A(1,n)=n+2A(1, n) = n + 2 by induction. A(2,0)=A(1,1)=3A(2, 0) = A(1, 1) = 3 and A(2,n+1)=A(1,A(2,n))=A(2,n)+2A(2, n + 1) = A(1, A(2, n)) = A(2, n) + 2, so A(2,n)=2n+3A(2, n) = 2n + 3 by induction.

Section 6.2: Lists and trees

Exercise 6.2-1. app([1,2],[3,4])=[1,2,3,4]\mathrm{app}([1, 2], [3, 4]) = [1, 2, 3, 4], rev([1,2,3,4])=[4,3,2,1]\mathrm{rev}([1, 2, 3, 4]) = [4, 3, 2, 1] and len([5,6,7])=3\mathrm{len}([5, 6, 7]) = 3.

Exercise 6.2-2. The proof is in the text: structural induction on xx, with app(nil,nil)=nil\mathrm{app}(\mathrm{nil}, \mathrm{nil}) = \mathrm{nil} and app(cons(a,x),nil)=cons(a,app(x,nil))=cons(a,x)\mathrm{app}(\mathrm{cons}(a, x), \mathrm{nil}) = \mathrm{cons}(a, \mathrm{app}(x, \mathrm{nil})) = \mathrm{cons}(a, x).

Exercise 6.2-3. For x=nilx = \mathrm{nil} both sides are app(y,z)\mathrm{app}(y, z). For cons(a,x)\mathrm{cons}(a, x) the left side is cons(a,app(app(x,y),z))\mathrm{cons}(a, \mathrm{app}(\mathrm{app}(x, y), z)) and the right side is cons(a,app(x,app(y,z)))\mathrm{cons}(a, \mathrm{app}(x, \mathrm{app}(y, z))). They agree by the hypothesis for xx.

Exercise 6.2-4. For nil\mathrm{nil}: len(app(nil,y))=len(y)=0+len(y)\mathrm{len}(\mathrm{app}(\mathrm{nil}, y)) = \mathrm{len}(y) = 0 + \mathrm{len}(y). For cons(a,x)\mathrm{cons}(a, x): len(cons(a,app(x,y)))=1+len(x)+len(y)=len(cons(a,x))+len(y)\mathrm{len}(\mathrm{cons}(a, \mathrm{app}(x, y))) = 1 + \mathrm{len}(x) + \mathrm{len}(y) = \mathrm{len}(\mathrm{cons}(a, x)) + \mathrm{len}(y). For the reverse: len(rev(x))=len(x)\mathrm{len}(\mathrm{rev}(x)) = \mathrm{len}(x), by induction: len(rev(nil))=0\mathrm{len}(\mathrm{rev}(\mathrm{nil})) = 0, and len(rev(cons(a,x)))=len(app(rev(x),[a]))=len(x)+1\mathrm{len}(\mathrm{rev}(\mathrm{cons}(a, x))) = \mathrm{len}(\mathrm{app}(\mathrm{rev}(x), [a])) = \mathrm{len}(x) + 1 by the law just shown and the hypothesis.

Exercise 6.2-5. The nodes are ℓ+i\ell + i, and ℓ=i+1\ell = i + 1 gives 2i+12i + 1. A tree with 5050 leaves has i=49i = 49 internal nodes and 9999 nodes in all.

Exercise 6.2-6. The proofs of laws 4 and 5 are in the text. They use law 1 (app(x,nil)=x\mathrm{app}(x, \mathrm{nil}) = x) and law 2 (associativity). As a check, with x=[1,2]x = [1, 2] and y=[3]y = [3]: rev(app(x,y))=rev([1,2,3])=[3,2,1]\mathrm{rev}(\mathrm{app}(x, y)) = \mathrm{rev}([1, 2, 3]) = [3, 2, 1] and app(rev(y),rev(x))=app([3],[2,1])=[3,2,1]\mathrm{app}(\mathrm{rev}(y), \mathrm{rev}(x)) = \mathrm{app}([3], [2, 1]) = [3, 2, 1].

Exercise 6.2-7. The leaves are at most 2h2^h by the theorem of the text. The nodes are 2ℓ−1≤2h+1−12\ell - 1 \le 2^{h+1} - 1, since the nodes are ℓ+i=2ℓ−1\ell + i = 2\ell - 1.

Exercise 6.2-8. Claim: rv(x,y)=app(rev(x),y)\mathrm{rv}(x, y) = \mathrm{app}(\mathrm{rev}(x), y) for all lists yy, by induction on xx (the hypothesis is for all yy). For nil\mathrm{nil}: rv(nil,y)=y=app(nil,y)\mathrm{rv}(\mathrm{nil}, y) = y = \mathrm{app}(\mathrm{nil}, y). For cons(a,x)\mathrm{cons}(a, x): rv(cons(a,x),y)=rv(x,cons(a,y))=app(rev(x),cons(a,y))\mathrm{rv}(\mathrm{cons}(a, x), y) = \mathrm{rv}(x, \mathrm{cons}(a, y)) = \mathrm{app}(\mathrm{rev}(x), \mathrm{cons}(a, y)) by the hypothesis applied to the list cons(a,y)\mathrm{cons}(a, y). On the other side, app(rev(cons(a,x)),y)=app(app(rev(x),[a]),y)=app(rev(x),app([a],y))=app(rev(x),cons(a,y))\mathrm{app}(\mathrm{rev}(\mathrm{cons}(a, x)), y) = \mathrm{app}(\mathrm{app}(\mathrm{rev}(x), [a]), y) = \mathrm{app}(\mathrm{rev}(x), \mathrm{app}([a], y)) = \mathrm{app}(\mathrm{rev}(x), \mathrm{cons}(a, y)) by law 2. Then rv(x,nil)=app(rev(x),nil)=rev(x)\mathrm{rv}(x, \mathrm{nil}) = \mathrm{app}(\mathrm{rev}(x), \mathrm{nil}) = \mathrm{rev}(x) by law 1.

Exercise 6.2-9. The five trees with 33 internal nodes, all with 44 leaves, are node(∙,node(∙,node(∙,∙)))\mathrm{node}(\bullet, \mathrm{node}(\bullet, \mathrm{node}(\bullet, \bullet))) of height 33; node(∙,node(node(∙,∙),∙))\mathrm{node}(\bullet, \mathrm{node}(\mathrm{node}(\bullet, \bullet), \bullet)) of height 33; node(node(∙,∙),node(∙,∙))\mathrm{node}(\mathrm{node}(\bullet, \bullet), \mathrm{node}(\bullet, \bullet)) of height 22; node(node(∙,node(∙,∙)),∙)\mathrm{node}(\mathrm{node}(\bullet, \mathrm{node}(\bullet, \bullet)), \bullet) of height 33; node(node(node(∙,∙),∙),∙)\mathrm{node}(\mathrm{node}(\mathrm{node}(\bullet, \bullet), \bullet), \bullet) of height 33. The number of trees is the Catalan number 55.

Exercise 6.2-10. Structural induction on the definition of SS. The empty string has 00 brackets of each kind and no nonempty initial segment. For (u)v(u)v with uu and vv in SS, the numbers of left and right brackets are 1+Lu+Lv1 + L_u + L_v and 1+Ru+Rv1 + R_u + R_v, equal by the hypothesis. An initial segment of (u)v(u)v is the empty string, or (( followed by an initial segment pp of uu (the excess of left brackets is 11 plus that of pp, so at least 11), or (u)(u) followed by an initial segment qq of vv (the excess is 00 plus that of qq, so at least 00). In all cases the left brackets are at least as many as the right ones.

Section 6.3: Recursive algorithms

Exercise 6.3-1. pw(2,10)=pw(2,5)2\mathrm{pw}(2, 10) = \mathrm{pw}(2, 5)^2, pw(2,5)=2⋅pw(2,4)\mathrm{pw}(2, 5) = 2 \cdot \mathrm{pw}(2, 4), pw(2,4)=pw(2,2)2\mathrm{pw}(2, 4) = \mathrm{pw}(2, 2)^2, pw(2,2)=pw(2,1)2\mathrm{pw}(2, 2) = \mathrm{pw}(2, 1)^2, pw(2,1)=2⋅pw(2,0)=2\mathrm{pw}(2, 1) = 2 \cdot \mathrm{pw}(2, 0) = 2. The values going back are 2,4,16,32,10242, 4, 16, 32, 1024, with 55 multiplications, and ⌊log⁡210⌋+ν(10)=3+2=5\lfloor \log_2 10 \rfloor + \nu(10) = 3 + 2 = 5.

Exercise 6.3-2. The moves from (from, to) for H(3,a,b,c)\mathrm{H}(3, a, b, c) are (a,b),(a,c),(b,c),(a,b),(c,a),(c,b),(a,b)(a, b), (a, c), (b, c), (a, b), (c, a), (c, b), (a, b). The first three move two disks to cc, the fourth moves the largest to bb, and the last three move the two disks onto it.

Exercise 6.3-3. H(0)=0H(0) = 0 and H(n)=2H(n−1)+1H(n) = 2H(n - 1) + 1 give H(n)=2n−1H(n) = 2^n - 1: base 0=20−10 = 2^0 - 1, step 2(2k−1)+1=2k+1−12(2^k - 1) + 1 = 2^{k+1} - 1. For n=64n = 64 the number is 264−1=184467440737095516152^{64} - 1 = 18446744073709551615. At one move per second this is about 5.85⋅10115.85 \cdot 10^{11} years, nearly 585585 billion years.

Exercise 6.3-4. Let c(n)c(n) be the number of ways. The last step is of 11 (before it n−1n - 1 steps) or of 22 (before it n−2n - 2 steps), so c(n)=c(n−1)+c(n−2)c(n) = c(n - 1) + c(n - 2) for n≥2n \ge 2, with c(0)=c(1)=1c(0) = c(1) = 1. These are F1F_1 and F2F_2 with the same recurrence, so c(n)=Fn+1c(n) = F_{n+1} by strong induction. For n=10n = 10 the count is F11=89F_{11} = 89.

Exercise 6.3-5. At the start r⋅be=1⋅xnr \cdot b^e = 1 \cdot x^n. In a pass, if ee is even, rbe=r(b⋅b)e/2r b^e = r (b \cdot b)^{e/2}. If ee is odd, rbe=(rb)(b⋅b)(e−1)/2r b^e = (rb)(b \cdot b)^{(e-1)/2} and ⌊e/2⌋=(e−1)/2\lfloor e/2 \rfloor = (e - 1)/2. So the invariant holds after each pass. For x=2x = 2 and n=13n = 13 the values (r,b,e)(r, b, e) after the passes are (2,4,6)(2, 4, 6), (2,16,3)(2, 16, 3), (32,256,1)(32, 256, 1), (8192,65536,0)(8192, 65536, 0), and 8192=2138192 = 2^{13}.

Exercise 6.3-6. The proof of the formula is in the text. For n≤100n \le 100 the greatest count is 1212, at n=95=10111112n = 95 = 1011111_2 (⌊log⁡295⌋=6\lfloor \log_2 95 \rfloor = 6 and ν(95)=6\nu(95) = 6). No other n≤100n \le 100 gives 1212.

Exercise 6.3-7. The proof is in the text: C(n)≤C(⌊n/2⌋)+1C(n) \le C(\lfloor n/2 \rfloor) + 1 with C(0)=0C(0) = 0. If 2m≤n<2m+12^m \le n < 2^{m+1} with m≥1m \ge 1, then ⌊n/2⌋<2m\lfloor n/2 \rfloor < 2^m, so C(⌊n/2⌋)≤mC(\lfloor n/2 \rfloor) \le m by the hypothesis (and for m=0m = 0 the array has one key and one comparison). So C(n)≤m+1=⌊log⁡2n⌋+1C(n) \le m + 1 = \lfloor \log_2 n \rfloor + 1.

Exercise 6.3-8. Claim: if xx and yy are sorted, then mg(x,y)\mathrm{mg}(x, y) is sorted and has the same elements as app(x,y)\mathrm{app}(x, y) (counted with multiplicity). Induction on len(x)+len(y)\mathrm{len}(x) + \mathrm{len}(y). If xx or yy is nil\mathrm{nil}, the result is the other list. Otherwise let a≤ba \le b. The result is cons(a,mg(x′,y))\mathrm{cons}(a, \mathrm{mg}(x', y)) and x′x' and yy are sorted with smaller total length, so mg(x′,y)\mathrm{mg}(x', y) is sorted with the elements of x′x' and yy. The element aa is at most every element of x′x' (since xx is sorted) and at most every element of yy (since a≤b≤a \le b \le each of them). So cons(a,⋅)\mathrm{cons}(a, \cdot) is sorted, and its elements are those of xx and yy. The case a>ba > b is symmetric.

Exercise 6.3-9. By strong induction on nn. For n=0n = 0, E(m,0)=m=gcd⁡(m,0)\mathrm{E}(m, 0) = m = \gcd(m, 0). For n≥1n \ge 1, E(m,n)=E(n,m mod n)\mathrm{E}(m, n) = \mathrm{E}(n, m \bmod n) with m mod n<nm \bmod n < n, which by the hypothesis is gcd⁡(n,m mod n)=gcd⁡(m,n)\gcd(n, m \bmod n) = \gcd(m, n) by the key lemma of Section 5.3. For the calls, let K(n)K(n) be the greatest number of calls with second argument nn. Then K(0)=1K(0) = 1 and K(n)≤1+K(r)K(n) \le 1 + K(r) with r≤n−1r \le n - 1, and the claim K(n)≤n+1K(n) \le n + 1 follows by induction. For (89,55)(89, 55) the calls are on (89,55),(55,34),(34,21),(21,13),(13,8),(8,5),(5,3),(3,2),(2,1),(1,0)(89, 55), (55, 34), (34, 21), (21, 13), (13, 8), (8, 5), (5, 3), (3, 2), (2, 1), (1, 0), which is 1010 calls, far below 5656.

Exercise 6.3-10. Let a solution have NN moves, and let the largest disk move k≥1k \ge 1 times. Before the first move of the largest disk the other n−1n - 1 disks are on the third peg, which takes at least 2n−1−12^{n-1} - 1 moves. After the last move they are on the third peg again (the one that is not the source or the target of that move) and must be moved onto the largest disk at the target, which takes at least 2n−1−12^{n-1} - 1 moves. So N≥2(2n−1−1)+k=2n−2+kN \ge 2(2^{n-1} - 1) + k = 2^n - 2 + k. If N=2n−1N = 2^n - 1 then k=1k = 1, so the largest disk moves exactly once, and the moves before and after are shortest solutions for n−1n - 1 disks. By induction on nn these are unique, so the shortest solution is unique.

Solutions to Chapter 7: Relations and orders

Section 7.1: Relations and equivalence relations

Exercise 7.1-1. The relation "a∣ba \mid b" on the positive integers is reflexive, antisymmetric and transitive, and it is not symmetric (1∣21 \mid 2 but 2∤12 \nmid 1). On the nonzero integers it is reflexive and transitive. It is not symmetric, and it is not antisymmetric either, since 2∣−22 \mid -2 and −2∣2-2 \mid 2 while 2≠−22 \ne -2. The relation << on the reals is transitive. It is not reflexive, not symmetric, and it is antisymmetric only in the empty sense: a<ba < b and b<ab < a never hold together, so the condition of antisymmetry has no case to check.

Exercise 7.1-2. The pairs are (1,k)(1, k) for k=1,…,6k = 1, \dots, 6 (six pairs), (2,2),(2,4),(2,6)(2, 2), (2, 4), (2, 6) (three), (3,3),(3,6)(3, 3), (3, 6) (two), and (4,4)(4, 4), (5,5)(5, 5), (6,6)(6, 6) (three). The total is 6+3+2+3=146 + 3 + 2 + 3 = 14.

Exercise 7.1-3. Reflexive: n∣a−a=0n \mid a - a = 0. Symmetric: if n∣a−bn \mid a - b then n∣−(a−b)=b−an \mid -(a - b) = b - a. Transitive: if n∣a−bn \mid a - b and n∣b−cn \mid b - c, then nn divides the sum a−ca - c. For n=4n = 4 the classes are [0]={…,−4,0,4,8,… }[0] = \{\dots, -4, 0, 4, 8, \dots\}, [1]={…,−3,1,5,9,… }[1] = \{\dots, -3, 1, 5, 9, \dots\}, [2]={…,−2,2,6,… }[2] = \{\dots, -2, 2, 6, \dots\} and [3]={…,−1,3,7,… }[3] = \{\dots, -1, 3, 7, \dots\}.

Exercise 7.1-4. A relation on {1,2,3}\{1, 2, 3\} is a subset of the 99 pairs. A reflexive one contains the 33 pairs (i,i)(i, i), and each of the other 66 pairs is free, so there are 26=642^6 = 64. A symmetric one is fixed by its choice on the 33 diagonal pairs and on the 33 unordered pairs {i,j}\{i, j\} with i≠ji \ne j, so there are 23+3=642^{3+3} = 64. A reflexive and symmetric one has the diagonal fixed, so there are 23=82^3 = 8.

Exercise 7.1-5. By the definition of the text, R∘R={(a,c):there is b with aRb and bRc}R \circ R = \{(a, c) : \text{there is } b \text{ with } a \mathrel{R} b \text{ and } b \mathrel{R} c\}. Let RR be transitive and let (a,c)∈R∘R(a, c) \in R \circ R. Then aRbRca \mathrel{R} b \mathrel{R} c for some bb, so aRca \mathrel{R} c and (a,c)∈R(a, c) \in R. Conversely let R∘R⊆RR \circ R \subseteq R, and let aRba \mathrel{R} b and bRcb \mathrel{R} c. Then (a,c)∈R∘R⊆R(a, c) \in R \circ R \subseteq R.

Exercise 7.1-6. An equivalence relation on a set is the same as a partition of it. The partitions of {1,2,3}\{1, 2, 3\} are {1,2,3}\{1, 2, 3\}; {1},{2,3}\{1\}, \{2, 3\}; {2},{1,3}\{2\}, \{1, 3\}; {3},{1,2}\{3\}, \{1, 2\}; and {1},{2},{3}\{1\}, \{2\}, \{3\}. There are 55, the Bell number B3B_3.

Exercise 7.1-7. The relation R+R^+ contains RR (paths of length 11). It is transitive: a path from aa to bb followed by a path from bb to cc is a path from aa to cc. Let SS be transitive with R⊆SR \subseteq S. By induction on the length kk of a path a=x0R⋯Rxk=ba = x_0 \mathrel{R} \cdots \mathrel{R} x_k = b, the pair (a,b)(a, b) is in SS: for k=1k = 1 it is in R⊆SR \subseteq S, and for k+1k + 1 the pair (a,xk)(a, x_k) is in SS by the hypothesis and (xk,b)∈R⊆S(x_k, b) \in R \subseteq S, so (a,b)∈S(a, b) \in S by transitivity. So R+⊆SR^+ \subseteq S. For the given RR, the element 11 reaches 2,3,42, 3, 4 (by 1→2→3→41 \to 2 \to 3 \to 4). Each of 2,3,42, 3, 4 reaches 2,3,42, 3, 4 by the cycle 2→3→4→22 \to 3 \to 4 \to 2. So R+R^+ has 3+3⋅3=123 + 3 \cdot 3 = 12 pairs: (1,j)(1, j) and (i,j)(i, j) for i,j∈{2,3,4}i, j \in \{2, 3, 4\}.

Exercise 7.1-8. Reflexive: a−a=0∈ℤa - a = 0 \in \mathbb Z. Symmetric: b−a=−(a−b)b - a = -(a - b). Transitive: a−c=(a−b)+(b−c)a - c = (a - b) + (b - c). The class of aa is a+ℤ={a+k:k∈ℤ}a + \mathbb Z = \{a + k : k \in \mathbb Z\}. Each class has exactly one element in the interval [0,1)[0, 1), namely the fractional part of aa, so the classes correspond to the points of [0,1)[0, 1).

Exercise 7.1-9. Let a≡a′a \equiv a' and b≡b′(modn)b \equiv b' \pmod n. Then ab−a′b′=a(b−b′)+b′(a−a′)ab - a'b' = a(b - b') + b'(a - a') is a multiple of nn, so [ab]=[a′b′][ab] = [a'b'] and the rule does not depend on the choice of the representatives. The table for n=4n = 4, with the row for [a][a] and the column for [b][b], is

[0][0] [1][1] [2][2] [3][3]
[0][0] [0][0] [0][0] [0][0] [0][0]
[1][1] [0][0] [1][1] [2][2] [3][3]
[2][2] [0][0] [2][2] [0][0] [2][2]
[3][3] [0][0] [3][3] [2][2] [1][1]

Exercise 7.1-10. The relation ∼\sim is reflexive since RR is, and symmetric by its definition. If a∼ba \sim b and b∼cb \sim c, then aRbRca \mathrel{R} b \mathrel{R} c and cRbRac \mathrel{R} b \mathrel{R} a, so a∼ca \sim c by transitivity of RR. On the classes define [a]≤[b][a] \le [b] iff aRba \mathrel{R} b. This does not depend on the representatives: if a∼a′a \sim a', b∼b′b \sim b' and aRba \mathrel{R} b, then a′RaRbRb′a' \mathrel{R} a \mathrel{R} b \mathrel{R} b', so a′Rb′a' \mathrel{R} b'. It is reflexive and transitive as RR is. It is antisymmetric: [a]≤[b][a] \le [b] and [b]≤[a][b] \le [a] mean aRba \mathrel{R} b and bRab \mathrel{R} a, that is a∼ba \sim b, so [a]=[b][a] = [b].

Section 7.2: Partial orders and total orders

Exercise 7.2-1. Divisibility on the positive integers is a partial order and not total (22 and 33 are not comparable). The relation ≤\le on the reals is a total order. Inclusion on the subsets of {1,2}\{1, 2\} is a partial order and not total, since {1}\{1\} and {2}\{2\} are not comparable. The relation << on the integers is not a partial order, since it is not reflexive. It is a strict order.

Exercise 7.2-2. The covering pairs of the divisors of 1212 are (1,2)(1, 2), (1,3)(1, 3), (2,4)(2, 4), (2,6)(2, 6), (3,6)(3, 6), (4,12)(4, 12) and (6,12)(6, 12). In the set {2,3,4,6}\{2, 3, 4, 6\} the minimal elements are 22 and 33, since no other element of the set divides them. The maximal elements are 44 and 66, since 1212 is not in the set and no element of the set is a proper multiple of them.

Exercise 7.2-3. The usual order 1,2,…,101, 2, \dots, 10 is a linear extension, since a∣ba \mid b implies a≤ba \le b. Another is 1,2,4,8,3,6,9,5,10,71, 2, 4, 8, 3, 6, 9, 5, 10, 7, in which each number comes after its divisors.

Exercise 7.2-4. Let mm be least in SS. If s≺ms \prec m for some s∈Ss \in S, then m⪯sm \preceq s by leastness and s⪯ms \preceq m, so s=ms = m by antisymmetry, which contradicts s≺ms \prec m. So mm is minimal. If m′m' is also least, then m⪯m′m \preceq m' and m′⪯mm' \preceq m, so m=m′m = m'. In {2,3,4,6}\{2, 3, 4, 6\} under divisibility, 22 is minimal and not least, since 2∤32 \nmid 3.

Exercise 7.2-5. Let AA be nonempty and finite. Take a1∈Aa_1 \in A. If a1a_1 is not maximal, there is a2a_2 with a1≺a2a_1 \prec a_2, and so on. By transitivity ai≺aja_i \prec a_j for i<ji < j, so the aia_i are all different, and the process stops in a finite set. The last element is maximal.

Exercise 7.2-6. The constraints are a≺ba \prec b, a≺ca \prec c, b≺db \prec d, c≺dc \prec d, d≺ed \prec e and c≺fc \prec f. Only aa is minimal, so the list starts with aa. The elements b,c,d,eb, c, d, e must appear in an order where bb and cc come before dd and dd before ee, which gives the two base orders bcdebcde and cbdecbde. The element ff goes anywhere after cc. In bcdebcde there are 33 places after cc, and in cbdecbde there are 44. The total is 3+4=73 + 4 = 7 orders: abcdefabcdef, abcdfeabcdfe, abcfdeabcfde, acbdefacbdef, acbdfeacbdfe, acbfdeacbfde and acfbdeacfbde.

Exercise 7.2-7. Let (a,b)⪯lex(a′,b′)(a, b) \preceq_{\mathrm{lex}} (a', b') and (a′,b′)⪯lex(a′′,b′′)(a', b') \preceq_{\mathrm{lex}} (a'', b''). If a≺a′a \prec a' or a′≺a′′a' \prec a'', then a≺a′′a \prec a'' (using a⪯a′⪯a′′a \preceq a' \preceq a'' with one step strict, by transitivity and antisymmetry), so the first pair is below the third. Otherwise a=a′=a′′a = a' = a'', and b⪯b′⪯b′′b \preceq b' \preceq b'' gives b⪯b′′b \preceq b''.

Exercise 7.2-8. For each element xx let h(x)h(x) be the number of elements in a longest chain that has xx as its largest element. Then 1≤h(x)≤c1 \le h(x) \le c. If x≺yx \prec y, a longest chain that ends at xx extends by yy, so h(y)≥h(x)+1h(y) \ge h(x) + 1. So two elements with the same value of hh are not comparable, and each set Hk={x:h(x)=k}H_k = \{x : h(x) = k\} is an antichain. The nn elements fall into at most cc sets H1,…,HcH_1, \dots, H_c, so by the pigeonhole principle one of them has at least n/cn / c elements.

Exercise 7.2-9. Let RR be irreflexive and transitive. A cycle a1Ra2R⋯RakRa1a_1 \mathrel{R} a_2 \mathrel{R} \cdots \mathrel{R} a_k \mathrel{R} a_1 gives a1Ra1a_1 \mathrel{R} a_1 by transitivity, contrary to irreflexivity, so there is no cycle. Such a relation is also asymmetric (if aRba \mathrel{R} b and bRab \mathrel{R} a then aRaa \mathrel{R} a), and so RR together with equality is a partial order. For the second claim, let RR be the relation "must precede" on a finite set. If RR has a total order << that extends it, a cycle would give a1<a1a_1 < a_1, so there is no cycle. Conversely, let RR have no cycle. Then R+R^+ is transitive and irreflexive (a pair aR+aa \mathrel{R^+} a is a cycle). The relation "aR+ba \mathrel{R^+} b or a=ba = b" is reflexive and transitive, and antisymmetric, since aR+ba \mathrel{R^+} b and bR+ab \mathrel{R^+} a would give aR+aa \mathrel{R^+} a. So it is a partial order, and by the linear extension theorem it extends to a total order, which also extends RR.

Exercise 7.2-10. The constraints are a≺ca \prec c, b≺cb \prec c, b≺db \prec d. A computer count gives 55 orders: abcdabcd, abdcabdc, bacdbacd, badcbadc, bdacbdac. The check by hand: if aa is first then bb is next (the elements c,dc, d need bb), and then c,dc, d in either order, which gives 22. If bb is first, the remaining a,c,da, c, d with a≺ca \prec c have 33 orders (acdacd, adcadc, dacdac), so 33 orders. The total is 55. For nn elements with no relations every list is allowed, so there are n!n! linear extensions.

Section 7.3: Well-founded relations and termination

Exercise 7.3-1. A relation is well-founded iff it has no infinite descending chain. For "<<" on ℕ\mathbb N, a chain a0>a1>⋯a_0 > a_1 > \cdots cannot be infinite, so it is well-founded. For ">>" on ℕ\mathbb N a descending chain is a sequence with ai+1>aia_{i+1} > a_i, such as 0,1,2,…0, 1, 2, \dots, so it is not well-founded. For "<<" on the non-negative reals it is not well-founded, because of 1>1/2>1/4>⋯1 > 1/2 > 1/4 > \cdots. The relation "proper divisor" is well-founded, since a proper divisor of a positive integer is smaller, so a chain is a descending chain of ℕ\mathbb N.

Exercise 7.3-2. Let S⊆AS \subseteq A with the relation restricted to SS. An infinite descending chain in SS is an infinite descending chain in AA, which does not exist.

Exercise 7.3-3. The loop is: while n>0n > 0, replace nn by n−3n - 3 or by n−1n - 1. The measure is μ(n)=max⁡(n,0)∈ℕ\mu(n) = \max(n, 0) \in \mathbb N. In a pass n≥1n \ge 1, and the new value is at most n−1n - 1, so μ\mu of the new value is at most n−1<n=μ(n)n - 1 < n = \mu(n). A sequence of passes would be an infinite descending chain in ℕ\mathbb N, which does not exist. So the loop ends.

Exercise 7.3-4. A(2,2)=A(1,A(2,1))A(2, 2) = A(1, A(2, 1)) and A(2,1)=A(1,A(2,0))=A(1,3)=5A(2, 1) = A(1, A(2, 0)) = A(1, 3) = 5, so A(2,2)=A(1,5)=7A(2, 2) = A(1, 5) = 7, which is 2⋅2+32 \cdot 2 + 3. For A(3,2)=A(2,A(3,1))A(3, 2) = A(2, A(3, 1)) with A(3,1)=A(2,A(3,0))=A(2,5)=13A(3, 1) = A(2, A(3, 0)) = A(2, 5) = 13, so A(3,2)=A(2,13)=29A(3, 2) = A(2, 13) = 29, which is 25−32^5 - 3.

Exercise 7.3-5. First, A(1,0)=A(0,1)=2A(1, 0) = A(0, 1) = 2, and A(1,n+1)=A(0,A(1,n))=A(1,n)+1A(1, n + 1) = A(0, A(1, n)) = A(1, n) + 1, so by induction A(1,n)=n+2A(1, n) = n + 2. Next, A(2,0)=A(1,1)=3A(2, 0) = A(1, 1) = 3, and A(2,n+1)=A(1,A(2,n))=A(2,n)+2A(2, n + 1) = A(1, A(2, n)) = A(2, n) + 2, so by induction A(2,n)=2n+3A(2, n) = 2n + 3.

Exercise 7.3-6. If xx is a proper prefix of yy, then len(x)<len(y)\mathrm{len}(x) < \mathrm{len}(y). A descending chain would give an infinite descending chain of lengths in ℕ\mathbb N, so there is none. The same holds for proper suffixes. (In general, if a map μ\mu into a well-founded set has b≺a  ⟹  μ(b)<μ(a)b \prec a \implies \mu(b) < \mu(a), then ≺\prec is well-founded.)

Exercise 7.3-7. Write A×B×CA \times B \times C as (A×B)×C(A \times B) \times C. The lexicographic order on (A×B)×C(A \times B) \times C is well-founded by the theorem for two sets, applied to the well-founded sets A×BA \times B (by the same theorem) and CC. It agrees with the lexicographic order on triples: ((a,b),c)((a, b), c) is below ((a′,b′),c′)((a', b'), c') iff (a,b)(a, b) is lexicographically below (a′,b′)(a', b'), or the pairs are equal and c≺c′c \prec c', which is the condition on triples.

Exercise 7.3-8. For A(3,n)A(3, n): A(3,0)=A(2,1)=5=23−3A(3, 0) = A(2, 1) = 5 = 2^3 - 3, and A(3,n+1)=A(2,A(3,n))=2A(3,n)+3=2(2n+3−3)+3=2n+4−3A(3, n + 1) = A(2, A(3, n)) = 2 A(3, n) + 3 = 2(2^{n+3} - 3) + 3 = 2^{n+4} - 3. For the bound A(m,n)>nA(m, n) > n, use induction on the pair (m,n)(m, n) in the lexicographic order, which is well-founded. If m=0m = 0, A(0,n)=n+1>nA(0, n) = n + 1 > n. If m≥1m \ge 1 and n=0n = 0, A(m,0)=A(m−1,1)>1>0A(m, 0) = A(m - 1, 1) > 1 > 0 by the hypothesis on (m−1,1)(m - 1, 1). If m≥1m \ge 1 and n≥1n \ge 1, let k=A(m,n−1)k = A(m, n - 1). By the hypothesis on (m,n−1)(m, n - 1), k>n−1k > n - 1, so k≥nk \ge n. By the hypothesis on (m−1,k)(m - 1, k), A(m,n)=A(m−1,k)>k≥nA(m, n) = A(m - 1, k) > k \ge n.

Exercise 7.3-9. A step from (a,b)(a, b) goes to (a,b−1)(a, b - 1) or to (a−1,c)(a - 1, c), and both are smaller than (a,b)(a, b) in the lexicographic order on ℕ×ℕ\mathbb N \times \mathbb N, which is well-founded. So every run is finite. From (1,0)(1, 0) the only step is to (0,c)(0, c) for a cc that the step chooses, and then cc more steps follow. A run of the length 1+c1 + c exists for each natural cc, so no bound that depends on the start alone exists.

Exercise 7.3-10. If ≺\prec is well-founded, induction holds by the theorem of the text. Conversely, suppose that induction holds for every property. Let P(a)P(a) say that no infinite descending chain starts at aa. Let aa be such that P(b)P(b) holds for all b≺ab \prec a. An infinite descending chain a=a0≻a1≻⋯a = a_0 \succ a_1 \succ \cdots would have a1≺aa_1 \prec a with a chain that starts at a1a_1, which contradicts P(a1)P(a_1). So P(a)P(a) holds. By induction P(a)P(a) holds for all aa, so there is no infinite descending chain, and ≺\prec is well-founded.

This chapter has a full solution of each exercise of the volume, one file per chapter. Exercise c.sc.s-kk is the exercise number kk of Section ss of Chapter cc. Try an exercise for some time before reading its solution. A solution gives the steps that a reader at the level of the rating needs, and many solutions end with a check on small cases.

The source of this page. Something is wrong? Report it.