Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78233

Re: GCD in Fractions

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.029
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'sufficient': 0.05; 'api': 0.11; 'python': 0.11; "wouldn't": 0.14; '23,': 0.16; 'backwards': 0.16; 'behaviour.': 0.16; 'clear.': 0.16; 'googling': 0.16; 'naming': 0.16; 'rarely': 0.16; 'recently.': 0.16; 'recipes': 0.16; 'renaming': 0.16; 'wrote:': 0.18; 'module': 0.19; 'any,': 0.19; 'stefan': 0.19; 'not,': 0.20; 'solution.': 0.20; 'seems': 0.21; 'case.': 0.24; 'certainly': 0.24; "haven't": 0.24; 'header :In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'generally': 0.29; '(like': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'sep': 0.31; 'probably': 0.32; 'url:python': 0.33; 'actual': 0.34; 'case,': 0.35; 'received:google.com': 0.35; 'acceptable': 0.36; 'url:org': 0.36; 'should': 0.36; 'positive': 0.37; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'expect': 0.39; 'realize': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'read': 0.60; 'easy': 0.60; 'is.': 0.60; 'negative': 0.60; 'url:5': 0.61; 'url:3': 0.61; 'first': 0.61; 'making': 0.63; 'kind': 0.63; 'skip:n 10': 0.64; 'believe': 0.68; 'debate': 0.68; 'obvious': 0.74; 'irrelevant': 0.84; 'convinced': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=H9CcXpgv7Pd3VV+PwzLnjsTOdoatdsjAFGCTw1/aZMk=; b=zjUWQv9Ldg7/senzNEzz3cgOOzu2B7AjTvBOLHgRVdPLApQKHYYlwKj2NVPHiiaHOb 2bGJoNXvdSOYQUWsrR0t0Azt6UPNIsdSDk6/71e5wLkDSQSJ3NncjOhrjF/3+oAy+l2X 2cg8TcGuxrOlAN2MBp5sOySQ8loLlNx3c1MpwIHBlG9Q8tcWBa9uPxxiqqsqaHD7XfiU asD7ZMeEUq1v6l+uBSND39cNcM5jQOlZi5frNpGekF9DVy8sULovfVkFk6wg3DJB5g3B u6DXW5xq9pDvlLY0FXmlRcGjftBJ+oDzPqTsF5VitGOWDJDsyMNXQhdyS15/vJf3rVRZ LzkQ==
X-Received by 10.68.249.101 with SMTP id yt5mr1539428pbc.156.1411493997909; Tue, 23 Sep 2014 10:39:57 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <lvsag4$87t$1@ger.gmane.org>
References <pfGdnaNKbb7-sbzJnZ2dnUVZ8vudnZ2d@brightview.co.uk> <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> <lvs7lq$vrn$1@ger.gmane.org> <lvsag4$87t$1@ger.gmane.org>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Tue, 23 Sep 2014 11:39:17 -0600
Subject Re: GCD in Fractions
To Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.14278.1411494006.18130.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1411494006 news.xs4all.nl 2875 [2001:888:2000:d::a6]:38110
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:78233

Show key headers only | View raw


On Tue, Sep 23, 2014 at 11:26 AM, Stefan Behnel <stefan_ml@behnel.de> 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.
>
> Making a public API private is rarely a good idea. It should be enough in
> this case to document the behaviour.
>
> And, believe it or not, it actually is documented:
>
> https://docs.python.org/3.5/library/fractions.html#fractions.gcd

I don't think documentation is sufficient in this case. This is the
kind of thing though that is easy to forget about if you haven't read
the documentation recently. And with a function like gcd, one
generally wouldn't expect to *need* to read the documentation.

>> Googling for recipes to calculate the gcd using python brings up
>> fractions.gcd as a general answer (like at stackoverflow:
>> http://stackoverflow.com/questions/11175131/code-for-greatest-common-divisor-in-python)
>> and it is not obvious for non-mathematicians to realize that it is NOT a
>> generally acceptable solution.
>
> It is. Certainly for positive numbers, which clearly present the majority
> of use cases. It's definitely the "normal" use case, wouldn't you say?
>
> 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.

I'm not convinced it's all that clear. In addition to Mathworld and
Wikipedia that were already cited, ProofWiki provides an actual proof
that gcd(a, b) = gcd(|a|, |b|), by way of noting that a and |a| have
the same factors.

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

GCD in Fractions blindanagram <noone@nowhere.net> - 2014-09-23 09:16 +0100
  Re: GCD in Fractions Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2014-09-23 13:53 +0200
    Re: GCD in Fractions blindanagram <noone@nowhere.net> - 2014-09-23 13:48 +0100
  Re: GCD in Fractions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-23 22:50 +1000
    Re: GCD in Fractions blindanagram <noone@nowhere.net> - 2014-09-23 15:37 +0100
      Re: GCD in Fractions Chris Angelico <rosuav@gmail.com> - 2014-09-24 00:42 +1000
    Re: GCD in Fractions Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2014-09-23 18:38 +0200
    Re: GCD in Fractions Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-23 11:20 -0600
      Re: GCD in Fractions blindanagram <noone@nowhere.net> - 2014-09-23 18:31 +0100
    Re: GCD in Fractions Stefan Behnel <stefan_ml@behnel.de> - 2014-09-23 19:26 +0200
      Re: GCD in Fractions blindanagram <noone@nowhere.net> - 2014-09-23 18:43 +0100
        Re: GCD in Fractions Stefan Behnel <stefan_ml@behnel.de> - 2014-09-23 19:55 +0200
          Re: GCD in Fractions blindanagram <noone@nowhere.net> - 2014-09-23 22:38 +0100
            Re: GCD in Fractions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-24 21:44 +1000
              Re: GCD in Fractions blindanagram <noone@nowhere.net> - 2014-09-24 14:25 +0100
                Re: GCD in Fractions Stefan Behnel <stefan_ml@behnel.de> - 2014-09-24 18:13 +0200
                Re: GCD in Fractions blindanagram <noone@nowhere.net> - 2014-09-24 18:05 +0100
                Re: GCD in Fractions "Robert E. Beaudoin" <rbeaudoin@comcast.net> - 2014-09-24 19:19 -0400
              Re: GCD in Fractions Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-24 08:26 -0600
              Re: GCD in Fractions random832@fastmail.us - 2014-09-24 12:49 -0400
              Re: GCD in Fractions Terry Reedy <tjreedy@udel.edu> - 2014-09-24 13:42 -0400
              Re: GCD in Fractions Johann Hibschman <jhibschman@gmail.com> - 2014-09-24 14:09 -0400
        Re: GCD in Fractions Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-09-23 20:30 +0100
          Re: GCD in Fractions blindanagram <noone@nowhere.net> - 2014-09-23 22:48 +0100
            Re: GCD in Fractions Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-09-23 23:52 +0100
            Re: GCD in Fractions Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-09-24 11:42 +0100
            Re: GCD in Fractions Mark Dickinson <mdickinson@enthought.com> - 2014-09-24 11:14 +0000
            Re: GCD in Fractions Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-09-24 17:34 +0100
              Re: GCD in Fractions blindanagram <noone@nowhere.net> - 2014-09-24 18:31 +0100
            Re: GCD in Fractions Akira Li <4kir4.1i@gmail.com> - 2014-09-25 14:56 +0400
            Re: GCD in Fractions Chris Angelico <rosuav@gmail.com> - 2014-09-25 21:03 +1000
    Re: GCD in Fractions Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-23 11:39 -0600
    Re: GCD in Fractions Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-23 11:40 -0600
    Re: GCD in Fractions Stefan Behnel <stefan_ml@behnel.de> - 2014-09-23 20:09 +0200
  Re: GCD in Fractions Terry Reedy <tjreedy@udel.edu> - 2014-09-23 15:31 -0400

csiph-web