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-36

Exercise 1.2.4-36

not stated yet in Lean solution written

RatingM23
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 ∑k=1n⌊k/2⌋=⌊n2/4⌋\sum_{k=1}^n \lfloor k/2 \rfloor = \lfloor n^2/4 \rfloor and find the value of ∑k=1n⌈k/2⌉\sum_{k=1}^n \lceil k/2 \rceil.

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

Induct on nn. The step needs ⌊(n+1)2/4⌋−⌊n2/4⌋=⌊(n+1)/2⌋\lfloor (n+1)^2/4 \rfloor - \lfloor n^2/4 \rfloor = \lfloor (n+1)/2 \rfloor.

Hint 2

For the ceiling, write ⌈k/2⌉\lceil k/2 \rceil as a floor of a shifted argument.

Solution

Show the solution

Floors. For n=0n = 0 both sides are 00. Assume the formula for nn. It is enough to show that ⌊(n+1)2/4⌋−⌊n2/4⌋=⌊(n+1)/2⌋\lfloor (n+1)^2/4 \rfloor - \lfloor n^2/4 \rfloor = \lfloor (n+1)/2 \rfloor.

If n=2jn = 2j is even, then (n+1)2/4=j2+j+14(n+1)^2/4 = j^2 + j + \tfrac14, with floor j2+jj^2 + j, and n2/4=j2n^2/4 = j^2. The difference is j=⌊(2j+1)/2⌋j = \lfloor (2j + 1)/2 \rfloor.

If n=2j+1n = 2j + 1 is odd, then (n+1)2/4=(j+1)2(n+1)^2/4 = (j+1)^2 and n2/4=j2+j+14n^2/4 = j^2 + j + \tfrac14 has floor j2+jj^2 + j. The difference is j+1=⌊(2j+2)/2⌋j + 1 = \lfloor (2j + 2)/2 \rfloor.

So the formula holds for all n≥0n \ge 0. □\square

Ceilings. For an integer kk, ⌈k/2⌉=⌊(k+1)/2⌋\lceil k/2 \rceil = \lfloor (k+1)/2 \rfloor since both equal (k+1)/2(k+1)/2 for odd kk and k/2k/2 for even kk. Hence

∑k=1n⌈k2⌉=∑k=1n⌊k+12⌋=∑i=2n+1⌊i2⌋=⌊(n+1)24⌋−⌊12⌋=⌊(n+1)24⌋.\sum_{k=1}^n \Bigl\lceil \frac k2 \Bigr\rceil = \sum_{k=1}^n \Bigl\lfloor \frac{k+1}{2} \Bigr\rfloor = \sum_{i=2}^{n+1} \Bigl\lfloor \frac i2 \Bigr\rfloor = \Bigl\lfloor \frac{(n+1)^2}{4} \Bigr\rfloor - \Bigl\lfloor \frac12 \Bigr\rfloor = \Bigl\lfloor \frac{(n+1)^2}{4} \Bigr\rfloor.

The third step extends the floor sum to n+1n + 1 terms and removes the term i=1i = 1, which is 00.

Check

For n=5n = 5: ⌊k/2⌋\lfloor k/2 \rfloor gives 0+1+1+2+2=6=⌊25/4⌋0 + 1 + 1 + 2 + 2 = 6 = \lfloor 25/4 \rfloor, and ⌈k/2⌉\lceil k/2 \rceil gives 1+1+2+2+3=9=⌊36/4⌋1 + 1 + 2 + 2 + 3 = 9 = \lfloor 36/4 \rfloor. Both formulas hold for 1≤n<1001 \le n < 100 in a computer run.

Remarks

The two sums add up to n(n+1)/2n(n+1)/2, so ⌊n2/4⌋+⌊(n+1)2/4⌋=n(n+1)/2\lfloor n^2/4 \rfloor + \lfloor (n+1)^2/4 \rfloor = n(n+1)/2 as well. The value ⌊n2/4⌋=⌊n/2⌋⌈n/2⌉\lfloor n^2/4 \rfloor = \lfloor n/2 \rfloor \lceil n/2 \rceil is the largest product of two nonnegative integers with sum nn.

The book's answer takes another route: it pairs the term for kk with the term for n+1−kn + 1 - k and uses Exercise 1.2.4-33.

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.