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

Exercise 1.2.4-33

proved in Lean solution written

RatingM18
MarkersM (mathematical)
KindK3, find a value: compute a number, a set or a closed form from the written solution
SectionSection 1.2.4 of Volume 1. Companion chapter: Integer functions and elementary number theory

The task

Find the value of ⌊(n+m)/2⌋+⌊(n−m+1)/2⌋\lfloor (n+m)/2 \rfloor + \lfloor (n-m+1)/2 \rfloor and of the same expression with ceilings, for integers mm and nn.

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

Split into two cases by the parity of n+mn + m.

Hint 2

For an integer tt, ⌊t/2⌋=t/2\lfloor t/2 \rfloor = t/2 if tt is even and (t−1)/2(t - 1)/2 if tt is odd. For the ceiling the odd case is (t+1)/2(t + 1)/2.

Solution

Show the solution

Put s=n+ms = n + m and t=n−m+1t = n - m + 1. Then s+t=2n+1s + t = 2n + 1, so ss and tt have opposite parity.

(a) If ss is even, then tt is odd and the sum is s2+t−12=s+t−12=n\dfrac{s}{2} + \dfrac{t - 1}{2} = \dfrac{s + t - 1}{2} = n. If ss is odd, then tt is even and the sum is s−12+t2=s+t−12=n\dfrac{s - 1}{2} + \dfrac{t}{2} = \dfrac{s + t - 1}{2} = n. So the value is nn.

(b) If ss is even, the sum is s2+t+12=2n+22=n+1\dfrac{s}{2} + \dfrac{t + 1}{2} = \dfrac{2n + 2}{2} = n + 1. If ss is odd, it is s+12+t2=n+1\dfrac{s + 1}{2} + \dfrac{t}{2} = n + 1. So the value is n+1n + 1.

For m=0m = 0 this reads ⌊n/2⌋+⌊(n+1)/2⌋=n\lfloor n/2 \rfloor + \lfloor (n+1)/2 \rfloor = n and ⌈n/2⌉+⌈(n+1)/2⌉=n+1\lceil n/2 \rceil + \lceil (n+1)/2 \rceil = n + 1.

Check

Take n=5n = 5, m=2m = 2. Then ⌊7/2⌋+⌊4/2⌋=3+2=5\lfloor 7/2 \rfloor + \lfloor 4/2 \rfloor = 3 + 2 = 5 and ⌈7/2⌉+⌈4/2⌉=4+2=6\lceil 7/2 \rceil + \lceil 4/2 \rceil = 4 + 2 = 6. A run over all −9≤m,n≤9-9 \le m, n \le 9 confirms both values.

Remarks

The first identity for m=0m = 0 is the case n=2n = 2 of Exercise 1.2.4-38 with x=n/2x = n/2. The result of (b) also follows from (a) with nn replaced by −n−1-n-1 and the rule ⌈t⌉=−⌊−t⌋\lceil t \rceil = -\lfloor -t \rfloor.

The book's answer takes another route: one of the two halves is an integer, so the equality case of Exercise 1.2.4-7 applies.

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.