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

Exercise 1.2.4-37

not stated yet in Lean solution written

RatingM30
MarkersM (mathematical), recommended
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 that the sum ∑0≤k<n⌊(mk+x)/n⌋\sum_{0 \le k < n} \lfloor (mk + x)/n \rfloor, for integers mm and n>0n > 0 and real xx, equals (m−1)(n−1)/2+(d−1)/2+d⌊x/d⌋(m-1)(n-1)/2 + (d-1)/2 + d\lfloor x/d \rfloor with d=gcd⁡(m,n)d = \gcd(m, n).

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

First treat d=1d = 1. Then the remainders of mkmk modulo nn run through 0,1,…,n−10, 1, \ldots, n-1 in some order.

Hint 2

Write ⌊(mk+x)/n⌋=⌊mk/n⌋+⌊((mk mod n)+x)/n⌋\lfloor (mk + x)/n \rfloor = \lfloor mk/n \rfloor + \lfloor ((mk \bmod n) + x)/n \rfloor and sum each part. Use the formula ∑0≤r<n⌊y+r/n⌋=⌊ny⌋\sum_{0 \le r < n} \lfloor y + r/n \rfloor = \lfloor ny \rfloor (Exercise 1.2.4-38).

Hint 3

For d>1d > 1, split k=j+n′ik = j + n'i with n′=n/dn' = n/d, so that the sum falls into dd copies of a sum with coprime parameters.

Solution

Show the solution

Plan. First the coprime case, then the general case by a reduction.

Case d=1d = 1. Let m⊥nm \perp n. For 0≤k<n0 \le k < n write mk=nqk+rkmk = nq_k + r_k with qk=⌊mk/n⌋q_k = \lfloor mk/n \rfloor and 0≤rk<n0 \le r_k < n. If rk=rk′r_k = r_{k'}, then n∣m(k−k′)n \mid m(k - k'), so n∣k−k′n \mid k - k' by Euclid's lemma, and so k=k′k = k'. Hence k↦rkk \mapsto r_k is one-to-one on nn values in {0,…,n−1}\{0, \ldots, n-1\}, so it is onto: the rkr_k are 0,1,…,n−10, 1, \ldots, n-1 in some order.

The sum of the qkq_k is ∑kqk=∑kmk−rkn=m⋅n(n−1)/2−n(n−1)/2n=(m−1)(n−1)2.\sum_k q_k = \sum_k \frac{mk - r_k}{n} = \frac{m \cdot n(n-1)/2 - n(n-1)/2}{n} = \frac{(m-1)(n-1)}{2}. Since qkq_k is an integer, ⌊(mk+x)/n⌋=qk+⌊(rk+x)/n⌋\lfloor (mk + x)/n \rfloor = q_k + \lfloor (r_k + x)/n \rfloor, and ∑k⌊rk+xn⌋=∑r=0n−1⌊xn+rn⌋=⌊x⌋.\sum_{k} \Bigl\lfloor \frac{r_k + x}{n} \Bigr\rfloor = \sum_{r=0}^{n-1} \Bigl\lfloor \frac xn + \frac rn \Bigr\rfloor = \lfloor x \rfloor. The last step is the formula of Exercise 1.2.4-38 with y=x/ny = x/n. So for d=1d = 1 the sum is (m−1)(n−1)/2+⌊x⌋(m-1)(n-1)/2 + \lfloor x \rfloor, which agrees with the claim for d=1d = 1 (the term (d−1)/2(d-1)/2 is 00).

Case d>1d > 1. Write m=dm′m = dm' and n=dn′n = dn' with m′⊥n′m' \perp n', n′≥1n' \ge 1. Every kk with 0≤k<n0 \le k < n is k=j+n′ik = j + n'i in exactly one way with 0≤j<n′0 \le j < n' and 0≤i<d0 \le i < d. Then mk=mj+dm′n′i=mj+m′ni,mk = mj + dm'n'i = mj + m'ni, so ⌊(mk+x)/n⌋=m′i+⌊(mj+x)/n⌋=m′i+⌊(m′j+x/d)/n′⌋\lfloor (mk + x)/n \rfloor = m'i + \lfloor (mj + x)/n \rfloor = m'i + \lfloor (m'j + x/d)/n' \rfloor, where the last step divides numerator and denominator by dd. Sum over jj first. By the coprime case with x/dx/d in place of xx, ∑0≤j<n′⌊m′j+x/dn′⌋=(m′−1)(n′−1)2+⌊xd⌋.\sum_{0 \le j < n'} \Bigl\lfloor \frac{m'j + x/d}{n'} \Bigr\rfloor = \frac{(m'-1)(n'-1)}{2} + \Bigl\lfloor \frac xd \Bigr\rfloor. Now sum over ii. The term m′im'i adds up to n′m′⋅d(d−1)/2n' m' \cdot d(d-1)/2 over all pairs, and the second part is counted dd times: total=n′m′d(d−1)2+d (m′−1)(n′−1)2+d⌊xd⌋.\text{total} = \frac{n'm'd(d-1)}{2} + d\,\frac{(m'-1)(n'-1)}{2} + d\Bigl\lfloor \frac xd \Bigr\rfloor. The first two terms give d ( dm′n′−m′−n′+1 )2\dfrac{d\,(\,d m'n' - m' - n' + 1\,)}{2}. Using d2m′n′=mnd^2m'n' = mn, dm′=mdm' = m, dn′=ndn' = n, this is mn−m−n+d2=(m−1)(n−1)+d−12\dfrac{mn - m - n + d}{2} = \dfrac{(m-1)(n-1) + d - 1}{2}. So the total is (m−1)(n−1)2+d−12+d⌊xd⌋.□\frac{(m-1)(n-1)}{2} + \frac{d-1}{2} + d\Bigl\lfloor \frac xd \Bigr\rfloor. \qquad\square

The proof does not use m>0m > 0. For m=0m = 0 the parameters are d=nd = n, n′=1n' = 1, m′=0m' = 0, and the sum reduces to the single value ⌊x/n⌋\lfloor x/n \rfloor taken nn times.

Check

Take m=6m = 6, n=4n = 4, x=1.5x = 1.5, so d=2d = 2. The terms ⌊(6k+1.5)/4⌋\lfloor (6k + 1.5)/4 \rfloor for k=0,1,2,3k = 0, 1, 2, 3 are 0,1,3,40, 1, 3, 4, with sum 88. The formula gives 5⋅32+12+2⌊0.75⌋=7.5+0.5+0=8\tfrac{5 \cdot 3}{2} + \tfrac12 + 2 \lfloor 0.75 \rfloor = 7.5 + 0.5 + 0 = 8. A run over −8≤m≤8-8 \le m \le 8, 1≤n≤91 \le n \le 9 and x=i/6x = i/6 for −30≤i<30-30 \le i < 30 shows no exception.

Remarks

For m,n>0m, n > 0 the right side is symmetric in mm and nn, so the sum does not change when mm and nn are swapped. This is the reciprocity discussed in Exercise 1.2.4-45. For x=0x = 0 and m⊥nm \perp n the sum is (m−1)(n−1)/2(m-1)(n-1)/2, which counts the lattice points strictly inside the triangle with corners (0,0)(0,0), (n,0)(n,0), (n,m)(n,m) when m,n>0m, n > 0.

The book's answer takes another route: it subtracts the sum of the fractional parts from the sum without floors and evaluates that sum.

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.