Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!cbosgd!gatech!seismo!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: net.lang Subject: Re: Integer division: a winner declared Message-ID: <986@brl-smoke.ARPA> Date: Sun, 16-Feb-86 02:56:15 EST Article-I.D.: brl-smok.986 Posted: Sun Feb 16 02:56:15 1986 Date-Received: Tue, 18-Feb-86 04:23:39 EST References: <11610@ucbvax.BERKELEY.EDU> <5100003@ccvaxa> <548@ism780c.UUCP> <1970@peora.UUCP> Reply-To: gwyn@brl.ARPA Organization: /usr/local/lib/news/organization Lines: 47 In article <1970@peora.UUCP> jer@peora.UUCP (J. Eric Roskos) writes: > > Donald Knuth in _Fundamental_Algorithms_ defines a "mod" function > > x mod y = x - y * floor(x/y) if y!=0; x mod 0 = x > > and goes on to show (by dividing the RHS through by y) that > > if y > 0, then 0 <= x mod y < y > if y < 0, then 0 >= x mod y > y > > He goes on to show that x mod y is the same as the remainder when x is > divided by y. Then, finally, he states that "mod" is *not* the same > as the meaning of the word "modulo" in number theory. What he actually said was, "In number theory, the abbreviation `mod' is used in a different but related sense; ..." and then introduces the word "modulo" for what a number theorist would call "mod". All he meant by this was that one can define "modulo" in terms of "mod": We say "x == y (modulo m)" iff (x - y) mod m = 0. Knuth also does not "show that mod is the same as remainder"; he says (for pedagogical reasons) "the quantity x - (x mod y) is an integral multiple of y; and so we may think of x mod y as *the remainder when x is divided by y*." And, indeed, that is a good way to think about the meaning of "x mod y", so long as the exact definition is used in technical work. > So there you have a well known authority in computer science defining > "mod" in the "unpopular" way. However, Knuth's definition runs up against > an immutable obstacle: the Ada Programming Language's definition of the > functions. Ada defines "rem" and division [and remember that Knuth > said "rem"=="mod"] this way: ... Knuth said no such thing. He has defined "mod" as any decent mathematician would, which is NOT the same as "rem" or C's %. > So there you have it. Ada defines "mod" as distinct from "rem", and defines > division (and thus "mod") in the "intuitive" way, contradicting Knuth. Wrong. Ada's "rem" is like C's % with more specific semantics, and its "mod" is like everybody's "mod" (C doesn't have "mod"). I think where you went wrong was in not reading carefully enough. For x mod y, what does y < 0 mean? Nobody has been arguing about that case in this debate; the discussion has centered on what happens when x < 0. "x" != "y".