PEP 238 (revised)

Stephen Horne steve at lurking.demon.co.uk
Sun Aug 5 14:56:21 EDT 2001


I should perhaps make it clear that this is a combined reply to all
those who are still quoted here. I am fully aware that Andre Koenig
did not write everything I am replying to, so please don't reply to me
to tell me so.


On Fri, 27 Jul 2001 17:52:45 GMT, Andrew Koenig <ark at research.att.com>
wrote:

>David> In article <cp4rrz5onj.fsf at cj20424-a.reston1.va.home.com>,
>David>  Guido van Rossum <guido at python.org> wrote:
>
>>> Here's a completely revised version of PEP 238.  It contains a long
>>> motivational section, a clear specification of what will happen, and a
>>> discussion of rejected alternatives, a list of open issues, a Q-and-A
>>> section etc..  I hope it answers most questions that have been raised
>>> about this issue.  I'd be happy to revise it if there are still things
>>> unclear.
>
>David> I agree with the previous poster who said to use "quotient" instead of 
>David> "floor division".

This seems much better to me than 'correct division'. I'm not sure
that 'quotient' implies integer results, however. I was sufficiently
uncertain to go looking for old books, in fact. After blowing the dust
off, I found...

Penguin dictionary of mathematics : 'The result of dividing one number
or polynomial by another'.

Collins Gem Basic Facts, Mathematics : 'The quotient is the result
obtained when a division is performed'.

The collins book illustrated with an integer division with a
remainder, but neither stated it. Even if quotients go with
remainders, that only implies limited precision - not necessarily
integers. e.g.

  To one decimal place, 0.2 ÷ 0.3 = 0.0 (remainder 0.2)

In the books I think of as currently useful (eg Advanced Engineering
Mathematics 7th edition, Erwin Kreyszig) it's hardly surprising that
all I found was a couple of brief references to complex division and
the quotient rule for differentiation. What was interesting, however,
was that both of these uses of quotient were in non-integer contexts.

The most interesting quote I found was the following, however...

"""
In any division process where the dividend is not a multiple of the
divisor, there will be a remainder involved.
"""

This seems to imply type. If you are working in the set of reals (or
rationals, or complex numbers), then any divisor other than zero can
be multiplied by some definite value to exactly recreate the dividend.
This is not true for division of integers, nor for division of
polynomials - nor strictly for floats or fixed point numbers.

Of course no single book is definitive of any field, but I did look in
quite a few. It pretty much reflects my previous statement that there
is no single definition of division in mathematics, yet there is no
need for type-specific notations (although additional notations may be
useful in some specialist fields).

The only basic pattern I see is that the following identity is
expected to hold...

  (quotient * divisor) + remainder == dividend

When dealing with a type (a set of numbers or whatever) where exact
division is achievable, the remainder becomes redundant.

In short, the term 'quotient' seems a very good mathematical term for
the division operator we have now - all the definitions I can find in
books of mathematics imply that the result is sensitive to the types
of the arguments.

The term 'ratio' seems to be consistently defined along the lines of
'a method of comparing two numbers measured in similar units by
considering the quotient of the two quantities'. This actually
surprised me, as of course ratios are usually expressed in terms such
as '2:3' - which implies, but does not contain, the quotient. Ratios
for me are simply an alternate notation for rationals.

In any case, explicitly narrowing the definitions of a selection of
words to suit a particular distinction in a particular field is quite
common in mathematics and elsewhere, so doing it here is at the very
least a continuation of a fine tradition and yet another example of
how human language is also sensitive to the context in which it is
used. And it is not insulting.

Referring to 'division in the domain of the arguments type unless that
type happens to be integers' (a rather odd type, to say the least) as
'correct' division *is* insulting to anyone who happens to disagree
with the claim that that form of division is somehow inherently better
than simple 'division in the domain of the arguments type'.

>And I disagree.  "Quotient" suggests to me truncation toward zero,
>rather than truncation toward -infinity.

As for rounding toward zero rather than -infinity, that fits with my
typical expectations as well but it's a case of which simplified
identities (ie excluding the remainder) do you want to preserve when
exact division is not possible.

For me, -(a/b) == (-a)/b is an *obvious* identity to preserve - but
that does not necessarily mean it works well in a programming context.
Rounding to -inf may be much more practical, though I find most
integer division rarely involves negative values which makes it a bit
of a non-issue.




More information about the Python-list mailing list