taocp

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

Exercise · Volume 1 · 1.2.3-20

Exercise 1.2.3-20

proved in Lean solution written

Rating25
Markersrecommended
KindK1, prove: show that a stated fact is true from the written solution
SectionSection 1.2.3 of Volume 1. Companion chapter: Sums and products

The task

(a) Write the pattern 9×1+2=119 \times 1 + 2 = 11, 9×12+3=1119 \times 12 + 3 = 111, 9×123+4=11119 \times 123 + 4 = 1111 with a sum. (b) Generalize to base bb. (c) Prove the formula of (b).

The exact wording is in your copy of the book.

Hints

Open one hint at a time. Try the exercise again after each.

Hint 1

The number with the digits 1,2,…,n1, 2, \ldots, n in base 1010 has the digit n−kn - k at the place 10k10^k, for 0≤k≤n−10 \le k \le n - 1.

Hint 2

In base bb the factor 99 becomes b−1b - 1 and the number 1…11 \ldots 1 becomes ∑kbk\sum_k b^k.

Hint 3

For the proof, multiply the sum by bb and subtract it, with a shift of the index, as for Eq. (14).

Solution

Show the solution

(a) The number 12…n12 \ldots n (for n≤9n \le 9) is ∑k=0n−1(n−k)10k\sum_{k=0}^{n-1} (n-k) 10^k, since the digit at the place 10k10^k is n−kn - k. The number with n+1n + 1 ones is ∑k=0n10k\sum_{k=0}^{n} 10^k. So the pattern is 9∑k=0n−1(n−k) 10k+n+1=∑k=0n10k.9 \sum_{k=0}^{n-1} (n-k)\,10^k + n + 1 = \sum_{k=0}^{n} 10^k.

(b) In base bb the same digits give (b−1)∑k=0n−1(n−k) bk+n+1=∑k=0nbk.(b-1) \sum_{k=0}^{n-1} (n-k)\,b^k + n + 1 = \sum_{k=0}^{n} b^k. This is an identity for all integers bb and n≥0n \ge 0. For n<bn < b the sum ∑(n−k)bk\sum (n-k)b^k is the number written 12…n12\ldots n in base bb.

(c) Let T=∑0≤k≤n−1(n−k)bkT = \sum_{0 \le k \le n-1} (n-k) b^k. Then bT=∑0≤k≤n−1(n−k)bk+1=∑1≤k≤n(n−k+1)bk.bT = \sum_{0 \le k \le n-1} (n-k) b^{k+1} = \sum_{1 \le k \le n} (n-k+1) b^{k}. Subtract TT. The terms with 1≤k≤n−11 \le k \le n - 1 have the coefficient (n−k+1)−(n−k)=1(n - k + 1) - (n - k) = 1. The term k=nk = n appears only in bTbT, with coefficient 11, and the term k=0k = 0 appears only in TT, with coefficient nn: (b−1)T=∑1≤k≤n−1bk+bn−n=∑1≤k≤nbk−n.(b-1)T = \sum_{1 \le k \le n-1} b^k + b^n - n = \sum_{1 \le k \le n} b^k - n. Add n+1n + 1: (b−1)T+n+1=∑1≤k≤nbk+1=∑0≤k≤nbk.□(b-1)T + n + 1 = \sum_{1 \le k \le n} b^k + 1 = \sum_{0 \le k \le n} b^k. \qquad \square (For n=0n = 0 the sum TT is empty and both sides are 11.)

The route through Exercise 1.2.3-16 also works: write T=n∑k<nbk−∑k<nkbkT = n\sum_{k<n} b^k - \sum_{k<n} k b^k, use Eq. (14) and the formula of Exercise 1.2.3-16 with n−1n - 1 in place of nn. The direct way above is shorter.

Check

For b=10b = 10 and n=4n = 4: 9⋅1234+5=111119 \cdot 1234 + 5 = 11111. For n=9n = 9: 9⋅123456789+10=11111111119 \cdot 123456789 + 10 = 1111111111 (ten ones). For b=7b = 7 and n=5n = 5: T=5+4⋅7+3⋅49+2⋅343+1⋅2401=3267T = 5 + 4 \cdot 7 + 3 \cdot 49 + 2 \cdot 343 + 1 \cdot 2401 = 3267, and 6T+6=19608=1+7+49+343+2401+168076T + 6 = 19608 = 1 + 7 + 49 + 343 + 2401 + 16807.

Remarks

The identity holds in every base, but it reads as a pattern of digits only while n<bn < b. In base 1010 the pattern stops being a string of ones at n=10n = 10, where the digit 1010 needs a carry.

This solution is checked, and a person has not reviewed it yet. The source.

In Lean

proved The statement and its proof are in Lean. The kernel accepts the proof, and it uses the standard axioms only.

The status is computed from the Lean build. The node of the map.

Something is wrong? Report it.