Steven D'Aprano writes: > On Mon, 12 Dec 2011 09:29:11 -0800, Eelco wrote: > > [quoting Jussi Piitulainen <jpiit...@ling.helsinki.fi>] > >> They recognize modular arithmetic but for some reason insist that > >> there is no such _binary operation_. But as I said, I don't > >> understand their concern. (Except the related concern about some > >> programming languages, not Python, where the remainder does not > >> behave well with respect to division.) > > I've never come across this, and frankly I find it implausible that > *actual* mathematicians would say that. Likely you are > misunderstanding a technical argument about remainder being a > relation rather than a bijunction. The argument would go something > like this:
(For 'bijunction', read 'function'.) I'm not misunderstanding any argument. There was no argument. There was a blanket pronouncement that _in mathematics_ mod is not a binary operator. I should learn to challenge such pronouncements and ask what the problem is. Maybe next time. But you are right that I don't know how actual mathematicians these people are. I'm not a mathematician. I don't know where to draw the line. A Finnish actual mathematician stated a similar prejudice towards mod as a binary operator in a Finnish group. I asked him what is wrong with Knuth's definition (remainder after flooring division), and I think he conceded that it's not wrong. Number theorists just choose to work with congruence relations. I have no problem with that. He had experience with students who confused congruences modulo some modulus with a binary operation, and mixed up their notations because of that. That is a reason to be suspicious, but it is a confusion on the part of the students. Graham, Knuth, Patashnik contrast the two concepts explicitly, no confusion there. And I know that there are many ways to define division and remainder so that x div y + x rem y = x. Boute's paper cited in [1] advocates a different one and discusses others. [1] <http://en.wikipedia.org/wiki/Modulo_operation> But I think the argument "there are several such functions, therefore, _in mathematics_, there is no such function" is its own caricature. > "Remainder is not uniquely defined. For example, the division of -42 > by -5 can be written as either: > > 9*-5 + 3 = -42 > 8*-5 + -2 = -42 > > so the remainder is either 3 or -2. Hence remainder is not a bijection > (1:1 function)." Is someone saying that _division_ is not defined because -42 div -5 is somehow both 9 and 8? Hm, yes, I see that someone might. The two operations, div and rem, need to be defined together. (There is no way to make remainder a bijection. You mean it is not a function if it is looked at in a particular way.) [The square root was relevant but I snipped it.] > Similarly, we can sensibly define the remainder or modulus operator > to consistently return a non-negative remainder, or to do what > Python does, which is to return a remainder with the same sign as > the divisor: ... > There may be practical or logical reasons for preferring one over > the other, but either choice would make remainder a bijection. One > might even define two separate functions/operators, one for each > behaviour. Scheme is adopting flooring division, ceiling-ing division, rounding division, truncating division, centering division, and the Euclidean division advocated by Boute, and the corresponding remainders. There is no better way to bring home to a programmer the points that there are different ways to define these, and they come as div _and_ rem. -- http://mail.python.org/mailman/listinfo/python-list