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

Exercise 1.2.4-15

proved in Lean solution written

Rating10
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 distributive law z(x mod y)=(zx) mod (zy)z(x \bmod y) = (zx) \bmod (zy) for real xx, yy, zz.

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

Write both sides with the definition of the remainder.

Hint 2

Treat y=0y = 0 and z=0z = 0 on their own. For the rest, the quotient zx/(zy)zx/(zy) is x/yx/y.

Solution

Show the solution

Case y=0y = 0. Then zy=0zy = 0, and the left side is zxzx and the right side is (zx) mod 0=zx(zx) \bmod 0 = zx.

Case z=0z = 0. Then both sides are 00, since 0 mod 0=00 \bmod 0 = 0.

Case y≠0y \ne 0 and z≠0z \ne 0. The quotient (zx)/(zy)(zx)/(zy) equals x/yx/y, so its floor is the same. Then

(zx) mod (zy)=zx−zy⌊zxzy⌋=z(x−y⌊xy⌋)=z(x mod y).□(zx) \bmod (zy) = zx - zy \Bigl\lfloor \frac{zx}{zy} \Bigr\rfloor = z \Bigl( x - y \Bigl\lfloor \frac{x}{y} \Bigr\rfloor \Bigr) = z (x \bmod y). \qquad \square

Check

z=3z = 3, x=7x = 7, y=4y = 4: 3(7 mod 4)=93 (7 \bmod 4) = 9, and 21 mod 12=921 \bmod 12 = 9. With a negative z=−2z = -2: −2(7 mod 4)=−6-2 (7 \bmod 4) = -6, and −14 mod −8=−14+8⋅1=−6-14 \bmod -8 = -14 + 8 \cdot 1 = -6 (the quotient 7/47/4 has floor 11).

Remarks

Law C follows at once. For integers, a≡b(modm)a \equiv b \pmod m means a mod m=b mod ma \bmod m = b \bmod m. Multiply by n≠0n \ne 0 and use this law: an mod mn=bn mod mnan \bmod mn = bn \bmod mn. For the converse, divide by nn.

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.