09.12.2012 Views

Concrete mathematics : a foundation for computer science

Concrete mathematics : a foundation for computer science

Concrete mathematics : a foundation for computer science

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

70 INTEGER FUNCTIONS<br />

same inequality with floor or with ceiling; but we need to think twice be<strong>for</strong>e<br />

deciding which of the two is appropriate.<br />

The difference between. x and 1x1 is called the fractional part of x, and<br />

it arises often enough in applications to deserve its own notation:<br />

{x} = x - lx] . (3.8)<br />

We sometimes call Lx] the integer part of x, since x = 1x1 + {x}. If a real<br />

number x can be written in the <strong>for</strong>m x = n + 8, where n is an integer and<br />

0 < 8 + {y}J.<br />

And since 0 < {x} + {y} < 2, we find that sometimes lx + y] is 1x1 + [y],<br />

otherwise it’s 1x1 + [y] + 1.<br />

3.2 FLOOR/CEILING APPLICATIONS<br />

We’ve now seen the basic tools <strong>for</strong> handling floors and ceilings. Let’s<br />

put them to use, starting with an easy problem: What’s [lg351? (We use ‘lg’<br />

to denote the base-2 logarithm.) Well, since 25 < 35 6 26, we can take logs<br />

to get 5 < lg35 6 6; so (3.5(c)) tells us that [lg35] = 6.<br />

Note that the number 35 is six bits long when written in radix 2 notation:<br />

35 = (100011)~. Is it always true that [lgnl is the length of n written in<br />

binary? Not quite. We also need six bits to write 32 = (100000)2. So [lgnl<br />

is the wrong answer to the problem. (It fails only when n is a power of 2,<br />

but that’s infinitely many failures.) We can find a correct answer by realizing<br />

that it takes m bits to write each number n such that 2”-’ 6 n < 2m; thus<br />

&(a)) tells us that m - 1 = LlgnJ, so m = 1lgn.J + 1. That is, we need<br />

\lgnJ t 1 bits to express n in binary, <strong>for</strong> all n > 0. Alternatively, a similar<br />

derivation yields the answer [lg(n t 1 )I; this <strong>for</strong>mula holds <strong>for</strong> n = 0 as well,<br />

if we’re willing to say that it takes zero bits to write n = 0 in binary.<br />

Let’s look next at expressions with several floors or ceilings. What is<br />

[lxJl? Easy-smce 1x1 is an integer, [lx]] is just 1x1. So is any other expression<br />

with an innermost 1x1 surrounded by any number of floors or ceilings.<br />

Here’s a tougher problem: Prove or disprove the assertion<br />

[JI;TII = lJ;;I, real x 3 0. (3.9)<br />

Equality obviously holds wh.en x is an integer, because x = 1x1. And there’s<br />

equality in the special cases 7c = 3.14159. . . , e = 2.71828. . . , and @ =<br />

(1 +&)/2 = 1.61803..., because we get 1 = 1. Our failure to find a counterexample<br />

suggests that equality holds in general, so let’s try to prove it.<br />

Hmmm. We’d better<br />

not write {x}<br />

<strong>for</strong> the fractional<br />

part when it could<br />

be confused with<br />

the set containing x<br />

as its only element.<br />

The second case<br />

occurs if and only<br />

if there’s a “carry”<br />

at the position of<br />

the decimal point,<br />

when the fractional<br />

parts {x} and {y}<br />

are added together.<br />

[Of course 7-c, e,<br />

and 4 are the<br />

obvious first real<br />

numbers to try,<br />

aren’t they?)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!