GCD in Fractions
Stefan Behnel
stefan_ml at behnel.de
Wed Sep 24 18:13:23 CEST 2014
blindanagram schrieb am 24.09.2014 um 15:25:
> On 24/09/2014 12:44, Steven D'Aprano wrote:
>
>> blindanagram wrote:
> [snip]
>> - Mathworld says that GCD of two negative numbers is a negative number;
>>
>> - but Mathematica says that GCD of two negative numbers is a positive;
>>
>> - Wikipedia agrees with Mathematica and disagrees with Mathworld;
>
> After looking at these (and several other) on-line mathematical sites, I
> realised that I would have to go back to long standing mathemmatical
> references to find how the gcd is defined by those that explicitly cover
> the greatest common divisor for negative integers (I did this before
> raising the issue here).
>
> All four that I have so far looked at have definitions that lead to
> gcd(a, b) for integers being equal to gcd(|a|, |b|). I hope to visit a
> University library shortly to review more. Does anyone know of such a
> reference that uses a definition that conflicts with gcd(a, b) for
> integers being equal to gcd(|a|, |b|)?
Steven has already given sources that suggest that the result of gcd()
should be positive. Just like he gave sources that suggest the opposite.
So, the question is not how or where to find even more sources, or to
decide which of those sources is "more right" than the others, the question
is whether such a shaky ground is a reasonable foundation for breaking
other people's code.
We have an open tracker ticket now on changing *something* about the
current situation. Let's just add some new functionality somewhere if
people really want it (as in "need it for their code", not just "want it
for purity reasons" or "sleep better when they know it's out there"), but
please, everyone, stop complaining about "fractions.gcd" not catering for
your needs. It does what it's there for, even if the name is more public or
more generic than you might want. There are other ways to fix the actual
problem and move on.
Stefan
More information about the Python-list
mailing list