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

Exercise 1.2.4-35

not stated yet in Lean solution written

RatingM20
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

Show that ⌊(x+m)/n⌋=⌊(⌊x⌋+m)/n⌋\lfloor (x+m)/n \rfloor = \lfloor (\lfloor x \rfloor + m)/n \rfloor for integers mm and n>0n > 0 and real xx, and decide whether the same holds with ceilings.

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

Two integers are equal if, for each integer NN, one is at least NN exactly when the other is.

Hint 2

Use the rule ⌊y⌋≥N  ⟺  y≥N\lfloor y \rfloor \ge N \iff y \ge N for an integer NN, and the rule x≥A  ⟺  ⌊x⌋≥Ax \ge A \iff \lfloor x \rfloor \ge A for an integer AA.

Solution

Show the solution

Let NN be any integer. Then

⌊x+mn⌋≥N  ⟺  x+mn≥N  ⟺  x≥nN−m  ⟺  ⌊x⌋≥nN−m  ⟺  ⌊x⌋+mn≥N  ⟺  ⌊⌊x⌋+mn⌋≥N.\Bigl\lfloor \frac{x + m}{n} \Bigr\rfloor \ge N \iff \frac{x+m}{n} \ge N \iff x \ge nN - m \iff \lfloor x \rfloor \ge nN - m \iff \frac{\lfloor x \rfloor + m}{n} \ge N \iff \Bigl\lfloor \frac{\lfloor x \rfloor + m}{n} \Bigr\rfloor \ge N.

The first and last steps use ⌊y⌋≥N  ⟺  y≥N\lfloor y \rfloor \ge N \iff y \ge N for integer NN. The third step uses x≥A  ⟺  ⌊x⌋≥Ax \ge A \iff \lfloor x \rfloor \ge A for the integer A=nN−mA = nN - m. The second and fourth steps use n>0n > 0.

The two integers ⌊(x+m)/n⌋\lfloor (x+m)/n \rfloor and ⌊(⌊x⌋+m)/n⌋\lfloor (\lfloor x \rfloor + m)/n \rfloor have the same set of integers NN below or at them, so they are equal. □\square

The ceiling. The analogous result holds: ⌈(x+m)/n⌉=⌈(⌈x⌉+m)/n⌉\lceil (x+m)/n \rceil = \lceil (\lceil x \rceil + m)/n \rceil. The proof is the same with the rules ⌈y⌉≤N  ⟺  y≤N\lceil y \rceil \le N \iff y \le N and x≤A  ⟺  ⌈x⌉≤Ax \le A \iff \lceil x \rceil \le A for integers NN and AA.

Check

Take x=7.5x = 7.5, m=3m = 3, n=4n = 4. Then ⌊10.5/4⌋=2\lfloor 10.5/4 \rfloor = 2 and ⌊10/4⌋=2\lfloor 10/4 \rfloor = 2. For the ceiling, ⌈10.5/4⌉=3\lceil 10.5/4 \rceil = 3 and ⌈11/4⌉=3\lceil 11/4 \rceil = 3. A run over x=i/7x = i/7 for −60≤i<60-60 \le i < 60, −5≤m≤5-5 \le m \le 5, 1≤n≤61 \le n \le 6 confirms both identities.

Remarks

The case m=0m = 0 says that ⌊x/n⌋=⌊⌊x⌋/n⌋\lfloor x/n \rfloor = \lfloor \lfloor x \rfloor / n \rfloor: dividing by an integer and then taking the floor needs only the integer part of xx. The proof of Exercise 1.2.4-34 uses the same idea: the test x≥Ax \ge A for an integer AA sees only ⌊x⌋\lfloor x \rfloor.

The book's answer takes another route: it traps the left side between two values with a chain of inequalities and then applies Exercise 1.2.4-3.

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.