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

Exercise 1.2.4-1

proved in Lean solution written

Rating00
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

Find five values of the floor and the ceiling function: one for each of the numbers 1.11.1, −1.1-1.1, −1.1-1.1, 0.999990.99999 and lg⁡35\lg 35.

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 floor of xx is the greatest integer that is at most xx. The ceiling is the least integer that is at least xx. Look at the number line, not at the digits.

Hint 2

For the last value, find the powers of 22 that enclose 3535.

Solution

Show the solution

⌊1.1⌋=1\lfloor 1.1 \rfloor = 1, because 1≤1.1<21 \le 1.1 < 2.

⌈−1.1⌉=−1\lceil -1.1 \rceil = -1, because −2<−1.1≤−1-2 < -1.1 \le -1 and −1-1 is the least integer that is at least −1.1-1.1.

⌊−1.1⌋=−2\lfloor -1.1 \rfloor = -2, because −2≤−1.1<−1-2 \le -1.1 < -1. The floor of a negative number goes down, away from zero.

⌊0.99999⌋=0\lfloor 0.99999 \rfloor = 0, because 0≤0.99999<10 \le 0.99999 < 1.

For ⌊lg⁡35⌋\lfloor \lg 35 \rfloor: 25=32≤35<64=262^5 = 32 \le 35 < 64 = 2^6. Take lg⁡\lg of the chain: 5≤lg⁡35<65 \le \lg 35 < 6. So the floor is 55.

Check

A computer run with exact arithmetic gives (1,−1,−2,0,5)(1, -1, -2, 0, 5). For the last value, lg⁡35=5.129…\lg 35 = 5.129\ldots.

Remarks

The pair ⌊−1.1⌋=−2\lfloor -1.1 \rfloor = -2 and ⌈−1.1⌉=−1\lceil -1.1 \rceil = -1 is the standard trap: many programming languages truncate toward zero and give −1-1 for both. See Exercise 1.2.4-4 for the exact link between the two functions.

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.