% is not an operator [was Re: Verbose and flexible args and kwargs syntax]

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Dec 13 22:18:42 EST 2011


On Mon, 12 Dec 2011 09:29:11 -0800, Eelco wrote:

[quoting Jussi Piitulainen <jpiitula at 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:

"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)."

The existence of two potential answers for the remainder is certainly 
correct, but the conclusion that remainder is not a binary operation 
doesn't follow. It is a binary relation. Mathematicians are well able to 
deal with little inconveniences like this, e.g. consider the square root:

    10**2 = 100
    (-10)**2 = 100
    therefore the square root of 100 is ±10

Mathematicians get around this by defining the square root operator √ as 
*only* the principle value of the square root relation, that is, the 
positive root. Hence:

    √100 = 10 only

If you want both roots, you have to explicitly ask for them both: ±√100

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:

>>> 42 % 5
2
>>> -42 % 5
3

>>> 42 % -5
-3
>>> -42 % -5
-2

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.


> They might not be willing to define it, but as soon as we programmers
> do, well, we did.
> 
> Having studied the contemporary philosophy of mathematics, their concern
> is probably that in their minds, mathematics is whatever some dead guy
> said it was, and they dont know of any dead guy ever talking about a
> modulus operation, so therefore it 'does not exist'.

You've studied the contemporary philosophy of mathematics huh?

How about studying some actual mathematics before making such absurd 
pronouncements on the psychology of mathematicians?




-- 
Steven



More information about the Python-list mailing list