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.4-42

Exercise 1.2.4-42

not stated yet in Lean solution written

RatingM24
MarkersM (mathematical)
KindK1, prove: show that a stated fact is true from the written solution
SectionSection 1.2.4 of Volume 1. Companion chapter: Integer functions and elementary number theory

The task

Prove the summation by parts formula ∑k=1nak=nan−∑k=1n−1k(ak+1−ak)\sum_{k=1}^n a_k = na_n - \sum_{k=1}^{n-1} k(a_{k+1} - a_k), and use it to find ∑k=1n⌊log⁡bk⌋\sum_{k=1}^n \lfloor \log_b k \rfloor for an integer base b≥2b \ge 2.

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

For (a), expand ∑k(ak+1−ak)\sum k(a_{k+1} - a_k) into two sums and shift the index in one of them.

Hint 2

For (b), take ak=⌊log⁡bk⌋a_k = \lfloor \log_b k \rfloor. The difference ak+1−aka_{k+1} - a_k is 00 or 11. When is it 11?

Solution

Show the solution

(a) Split the sum and shift the index in the first part: ∑k=1n−1k(ak+1−ak)=∑k=2n(k−1)ak−∑k=1n−1kak=(n−1)an+∑k=2n−1((k−1)−k)ak−a1=(n−1)an−∑k=1n−1ak.\sum_{k=1}^{n-1} k(a_{k+1} - a_k) = \sum_{k=2}^{n}(k-1)a_k - \sum_{k=1}^{n-1}ka_k = (n-1)a_n + \sum_{k=2}^{n-1}\bigl((k-1) - k\bigr)a_k - a_1 = (n-1)a_n - \sum_{k=1}^{n-1}a_k. Hence ∑k=1n−1ak=(n−1)an−∑k=1n−1k(ak+1−ak)\sum_{k=1}^{n-1}a_k = (n-1)a_n - \sum_{k=1}^{n-1}k(a_{k+1} - a_k). Add ana_n to both sides. □\square

(b) Let ak=⌊log⁡bk⌋a_k = \lfloor \log_b k \rfloor and m=⌊log⁡bn⌋m = \lfloor \log_b n \rfloor. Then ak+1≥aka_{k+1} \ge a_k. Since k+1≤2k≤bkk + 1 \le 2k \le bk, it follows that log⁡b(k+1)≤log⁡bk+1\log_b(k+1) \le \log_b k + 1, so ak+1−ak≤1a_{k+1} - a_k \le 1. The difference is 11 exactly when an integer power of bb lies in (k,k+1](k, k+1], that is, when k+1=bjk + 1 = b^j for an integer j≥1j \ge 1.

For 1≤k≤n−11 \le k \le n - 1 this happens for k=bj−1k = b^j - 1 with bj≤nb^j \le n, that is, 1≤j≤m1 \le j \le m. So by (a) ∑k=1nak=nan−∑j=1m(bj−1)=nm−(bm+1−bb−1−m)=(n+1)m−bm+1−bb−1.\sum_{k=1}^n a_k = na_n - \sum_{j=1}^m (b^j - 1) = nm - \Bigl(\frac{b^{m+1} - b}{b - 1} - m\Bigr) = (n+1)m - \frac{b^{m+1} - b}{b - 1}. This is the claim. □\square

Check

Take b=2b = 2, n=10n = 10: ⌊log⁡2k⌋\lfloor \log_2 k \rfloor for k=1,…,10k = 1, \ldots, 10 is 0,1,1,2,2,2,2,3,3,30, 1, 1, 2, 2, 2, 2, 3, 3, 3 with sum 1919. Here m=3m = 3 and the formula gives 11⋅3−(16−2)/1=33−14=1911 \cdot 3 - (16 - 2)/1 = 33 - 14 = 19. For n=1n = 1 the formula gives 00. A run over 2≤b≤62 \le b \le 6 and 1≤n<3001 \le n < 300 shows no exception.

Remarks

The same method gives the sum in Exercise 1.2.4-43. Since kk has ⌊log⁡bk⌋+1\lfloor \log_b k \rfloor + 1 digits in base bb, the sum in (b) plus nn is the number of digits needed to write 1,…,n1, \ldots, n in base bb.

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

In Lean

not stated yet The exercise is not stated in Lean yet.

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

Something is wrong? Report it.