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.

There was a time in<br />

the 70s when ‘mod’<br />

was the fashion.<br />

Maybe the new<br />

mumble function<br />

should be called<br />

‘punk’?<br />

No-l &<br />

‘mumble’.<br />

The remainder, eh?<br />

3.4 ‘MOD’: THE BINARY OPERATION 83<br />

that this would be much less useful. Continuity is not an important aspect<br />

of the mod operation.)<br />

We’ve already seen one special case of mod in disguise, when we wrote x<br />

in terms of its integer and fractional parts, x = 1x1 + {x}. The fractional part<br />

can also be written x mod 1, because we have<br />

x = lxj + x mod 1 .<br />

Notice that parentheses aren’t needed in this <strong>for</strong>mula; we take mod to bind<br />

more tightly than addition or subtraction.<br />

The floor function has been used to define mod, and the ceiling function<br />

hasn’t gotten equal time. We could perhaps use the ceiling to define a mod<br />

analog like<br />

xmumbley = y[x/yl -x;<br />

in our circle analogy this represents the distance the traveler needs to continue,<br />

after going a distance x, to get back to the starting point 0. But of course<br />

we’d need a better name than ‘mumble’. If sufficient applications come along,<br />

an appropriate name will probably suggest itself.<br />

The distributive law is mod’s most important algebraic property: We<br />

have<br />

c(x mod y) = (cx) mod (cy) (3.23)<br />

<strong>for</strong> all real c, x, and y. (Those who like mod to bind less tightly than multiplication<br />

may remove the parentheses from the right side here, too.) It’s easy<br />

to prove this law from definition (3.21), since<br />

c(x mod y ) = c(x - y [x/y] ) = cx - cy [cx/cy] = cx mod cy ,<br />

if cy # 0; and the zero-modulus cases are trivially true. Our four examples<br />

using f5 and f3 illustrate this law twice, with c = -1. An identity like<br />

(3.23) is reassuring, because it gives us reason to believe that ‘mod’ has not<br />

been defined improperly.<br />

In the remainder of this section, we’ll consider an application in which<br />

‘mod’ turns out to be helpful although it doesn’t play a central role. The<br />

problem arises frequently in a variety of situations: We want to partition<br />

n things into m groups as equally as possible.<br />

Suppose, <strong>for</strong> example, that we have n short lines of text that we’d like<br />

to arrange in m columns. For aesthetic reasons, we want the columns to be<br />

arranged in decreasing order of length (actually nonincreasing order); and the<br />

lengths should be approximately the same-no two columns should differ by

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

Saved successfully!

Ooh no, something went wrong!