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

Exercise 1.2.4-10

proved in Lean solution written

Rating10
Markersrecommended
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

Evaluate 1.1 mod 11.1 \bmod 1, 0.11 mod 0.10.11 \bmod 0.1 and 0.11 mod (−0.1)0.11 \bmod (-0.1).

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

The definition works for real arguments. Compute the quotient x/yx/y first, then its floor.

Solution

Show the solution

1.1 mod 1=1.1−1⋅⌊1.1⌋=1.1−1=0.11.1 \bmod 1 = 1.1 - 1 \cdot \lfloor 1.1 \rfloor = 1.1 - 1 = 0.1.

0.11 mod 0.1=0.11−0.1⌊1.1⌋=0.11−0.1=0.010.11 \bmod 0.1 = 0.11 - 0.1 \lfloor 1.1 \rfloor = 0.11 - 0.1 = 0.01.

0.11 mod (−0.1)=0.11+0.1⌊−1.1⌋=0.11+0.1(−2)=−0.090.11 \bmod (-0.1) = 0.11 + 0.1 \lfloor -1.1 \rfloor = 0.11 + 0.1(-2) = -0.09.

Check

The first two results lie in [0,y)[0, y) and the third lies in (−0.1,0](-0.1, 0]. Also 0.11−(−0.09)=0.2=(−0.1)(−2)0.11 - (-0.09) = 0.2 = (-0.1)(-2), a multiple of the modulus. In binary floating point the value 0.11/0.10.11 / 0.1 may come out slightly below 1.11.1 or above it, so a computer check should use exact fractions: 11/100 mod 1/10=1/10011/100 \bmod 1/10 = 1/100.

Remarks

The first value is the fractional part of 1.11.1. Exercise 1.2.4-15 shows that the second value is (11 mod 10)/100(11 \bmod 10)/100.

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.