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

Exercise 1.2.4-16

proved in Lean solution written

RatingM10
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

Show that for y>0y > 0 the remainder x mod yx \bmod y is the only number zz in [0,y)[0, y) for which (x−z)/y(x - z)/y is an integer.

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

Let k=(x−z)/yk = (x - z)/y. Then x=ky+zx = ky + z. Find ⌊x/y⌋\lfloor x/y \rfloor.

Solution

Show the solution

Put k=(x−z)/yk = (x - z)/y, an integer, so that x/y=k+z/yx/y = k + z/y. Since 0≤z<y0 \le z < y and y>0y > 0, the fraction satisfies 0≤z/y<10 \le z/y < 1. So k≤x/y<k+1k \le x/y < k + 1, and by Exercise 1.2.4-3(e), ⌊x/y⌋=k\lfloor x/y \rfloor = k. Then x mod y=x−y⌊x/y⌋=x−yk=zx \bmod y = x - y\lfloor x/y \rfloor = x - yk = z. □\square

Check

Take x=−7.5x = -7.5 and y=2y = 2. The candidate z=0.5z = 0.5 has (x−z)/y=−4(x - z)/y = -4, an integer, and 0≤0.5<20 \le 0.5 < 2. The definition gives −7.5−2⌊−3.75⌋=−7.5+8=0.5-7.5 - 2\lfloor -3.75 \rfloor = -7.5 + 8 = 0.5. The candidate z=2.5z = 2.5 has an integer quotient −5-5 too, but 2.5≥y2.5 \ge y, so it is not the remainder.

Remarks

The exercise gives the standard way to compute a remainder in a proof: guess a number in the range and show that the difference is a multiple of the modulus. The same proof works for y<0y < 0 with the range y<z≤0y < z \le 0. Exercises 1.2.4-14 and 1.2.4-17 use it.

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.