GCD in Fractions
noone at nowhere.net
Tue Sep 23 23:38:08 CEST 2014
On 23/09/2014 18:55, Stefan Behnel wrote:
> blindanagram schrieb am 23.09.2014 um 19:43:
>> On 23/09/2014 18:26, Stefan Behnel wrote:
>>> Wolfgang Maier schrieb am 23.09.2014 um 18:38:
>>>> While at first I thought this to be a rather irrelevant debate over module
>>>> private vs public naming conventions, I now think the OP is probably right
>>>> and renaming fractions.gcd to fractions._gcd may be a good idea.
>>> For negative numbers, the "expected" behaviour seems to be unclear, so the
>>> current behaviour is just as good as any, so backwards compatibility
>>> concerns clearly win this fight.
>> The expected behaviour is not unclear for anyone who takes the
>> mathematical properties of the GCD seriously. It's a shame that Python
> May I ask how you get from one little function in the well-defined scope of
> a data type module (which is not named "math" or "integers" or "natural" or
> anything like it) to the extrapolation that Python doesn't take
> mathematical properties serious?
Firstly I have to choose between two possibilities:
(a) that the name of the function has been deliberately chosen to imply
that it calculates the mathematical function known as the 'greatest
commmon divisor'; or
(b) that the initials 'gcd' have been chosen by pure chance and the
association between this function and the 'greatest commmon divisor' has
arisen from pure coincidence.
Of these, I find (a) overwhelmingly more likely.
Seccondly (as others here have pointed out), the mathematical properties
of the greatest common divisor are well defined for both positive and
negative integers. But the Python function called gcd doesn't have some
of these properties.
I hence conclude that Python doesn't take the mathematical properties of
the greatest common divisor seriously since it doesn't ensure that its
version of this function has these properties.
More information about the Python-list