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

Exercise 1.2.4-7

proved in Lean solution written

RatingM15
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 ⌊x⌋+⌊y⌋≤⌊x+y⌋\lfloor x \rfloor + \lfloor y \rfloor \le \lfloor x + y \rfloor, find when equality holds, and give the analogous statement for 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

Split each number into its integer part and its fractional part x mod 1x \bmod 1.

Hint 2

The integer parts can be taken out of the floor. What is left is the floor of a sum of two numbers in [0,1)[0, 1).

Solution

Show the solution

Write x=⌊x⌋+ax = \lfloor x \rfloor + a and y=⌊y⌋+by = \lfloor y \rfloor + b with a=x mod 1a = x \bmod 1 and b=y mod 1b = y \bmod 1, so 0≤a,b<10 \le a, b < 1. Then x+y=⌊x⌋+⌊y⌋+(a+b)x + y = \lfloor x \rfloor + \lfloor y \rfloor + (a + b). An integer can leave the floor, so

⌊x+y⌋=⌊x⌋+⌊y⌋+⌊a+b⌋.\lfloor x + y \rfloor = \lfloor x \rfloor + \lfloor y \rfloor + \lfloor a + b \rfloor.

Since 0≤a+b<20 \le a + b < 2, the last floor is 00 if a+b<1a + b < 1 and 11 if a+b≥1a + b \ge 1. So ⌊x+y⌋≥⌊x⌋+⌊y⌋\lfloor x + y \rfloor \ge \lfloor x \rfloor + \lfloor y \rfloor, with equality if and only if a+b<1a + b < 1, that is x mod 1+y mod 1<1x \bmod 1 + y \bmod 1 < 1.

For ceilings, apply the result to −x-x and −y-y and use ⌈t⌉=−⌊−t⌋\lceil t \rceil = -\lfloor -t \rfloor (Exercise 1.2.4-4). This gives ⌊−x⌋+⌊−y⌋≤⌊−x−y⌋\lfloor -x \rfloor + \lfloor -y \rfloor \le \lfloor -x - y \rfloor, that is −⌈x⌉−⌈y⌉≤−⌈x+y⌉-\lceil x \rceil - \lceil y \rceil \le -\lceil x + y \rceil. So

⌈x+y⌉≤⌈x⌉+⌈y⌉,\lceil x + y \rceil \le \lceil x \rceil + \lceil y \rceil,

with equality if and only if (−x) mod 1+(−y) mod 1<1(-x) \bmod 1 + (-y) \bmod 1 < 1. The inequality goes the other way.

Check

For x=y=0.5x = y = 0.5: ⌊x⌋+⌊y⌋=0<1=⌊1⌋\lfloor x \rfloor + \lfloor y \rfloor = 0 < 1 = \lfloor 1 \rfloor, and 0.5+0.5=10.5 + 0.5 = 1 is not below 11. For x=0.3x = 0.3, y=0.4y = 0.4: both sides are 00, and 0.3+0.4<10.3 + 0.4 < 1. For ceilings with x=y=0.5x = y = 0.5: ⌈1⌉=1<2=⌈x⌉+⌈y⌉\lceil 1 \rceil = 1 < 2 = \lceil x \rceil + \lceil y \rceil, and (−0.5) mod 1=0.5(-0.5) \bmod 1 = 0.5 for both, with sum 11.

Remarks

The floor of a sum is at least the sum of the floors, so the floor is superadditive. The ceiling is subadditive.

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.