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


Groups > comp.lang.python > #26956

Re: in-place exponentiation incongruities

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'argument': 0.04; 'guido': 0.05; 'level,': 0.07; 'suppose': 0.07; 'variant': 0.07; 'python': 0.09; 'argument,': 0.09; 'modulo': 0.09; 'mutable': 0.09; 'parameter.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terry': 0.09; 'extension': 0.13; 'argument.': 0.16; 'binary,': 0.16; 'in- place': 0.16; 'message-id:@dough.gmane.org': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:skip:e 10': 0.16; 'third,': 0.16; 'wrote:': 0.17; 'documented': 0.17; 'jan': 0.18; '>>>': 0.18; 'code.': 0.20; 'bit': 0.21; 'latter': 0.22; 'struct': 0.22; 'subject:skip:i 10': 0.22; 'defined': 0.22; 'class.': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'in.': 0.27; 'header:X-Complaints-To:1': 0.28; 'arguments.': 0.29; 'cases.': 0.29; 'coded': 0.29; 'consistency': 0.29; 'existence': 0.29; 'steven': 0.29; 'manual': 0.29; 'points': 0.29; 'probably': 0.29; "skip:' 10": 0.30; 'function': 0.30; 'implement': 0.32; 'true.': 0.33; 'to:addr:python-list': 0.33; 'operations': 0.33; 'version': 0.34; 'done': 0.34; 'third': 0.34; 'needed': 0.35; 'received:org': 0.36; 'really': 0.36; 'but': 0.36; 'method': 0.36; 'why': 0.37; '(for': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'planning': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'subject:-': 0.40; 'header:Received:5': 0.40; 'matter': 0.61; 'provide': 0.62; 'ever': 0.63; 'skip:n 10': 0.63; 'believe': 0.69; 'special': 0.73; 'power': 0.74; 'received:fios.verizon.net': 0.84; 'struct.': 0.84; 'mistake': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: in-place exponentiation incongruities
Date Sun, 12 Aug 2012 17:53:46 -0400
References <a0d2c349-6792-4c80-8aa5-af13dbaac039@googlegroups.com> <502730da$0$29983$c3e8da3$5496439d@news.astraweb.com> <5bc4e58c-c587-46c3-93cc-95dea97d89e8@googlegroups.com> <50278d6b$0$29978$c3e8da3$5496439d@news.astraweb.com> <3118027d-0c13-425e-a874-4593b608cf45@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120713 Thunderbird/14.0
In-Reply-To <3118027d-0c13-425e-a874-4593b608cf45@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3212.1344808442.4697.python-list@python.org> (permalink)
Lines 46
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1344808442 news.xs4all.nl 6842 [2001:888:2000:d::a6]:45518
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:26956

Show key headers only | View raw


On 8/12/2012 7:55 AM, Giacomo Alzetta wrote:

> What I mean is: when you implement a new type as a C extension you
> have to provide special methods through the NumberMethods struct. In
> this struct both the power and in-place power operations have three
> arguments.

I am not really sure why the latter is true. Probably 'consistency' at 
the special method level, with __pow__. As Steven points out, it is not 
needed to implement normal Python code.

This is one area of Python where the design is a bit messy. I believe 
the very existence of __ipow__ is a matter of consistency than of known 
use cases. Guido was not sure which __ixxx__ would ever be needed (for 
mutable objects), so he just put them all in.

At the Python level, both __pow__ and __ipow__ are also documented in 
the manual as having an optional, third, modulo parameter. __rpow__ is 
defined as binary, but that is a mistake

 >>> int.__rpow__(3, 5, 4)
1


> Now, suppose I implement the three argument variant of the
> in-place power in a class.

Are you actually planning to do this, or is this purely theoretical?

> No user would be able to call my C
> function with a non-None third argument,

Not true. Whether the function is coded in Python or C
cls.__ipow__(base, exp, mod) # or
base.__ipow__(exp, mod)

> while he would be able to
> call the normal version with the third argument.

That can also be done directly
 >>> int.__pow__(5, 3,  4)
1

-- 
Terry Jan Reedy

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


Thread

in-place exponentiation incongruities Giacomo Alzetta <giacomo.alzetta@gmail.com> - 2012-08-11 09:54 -0700
  Re: in-place exponentiation incongruities Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-12 04:28 +0000
    Re: in-place exponentiation incongruities Giacomo Alzetta <giacomo.alzetta@gmail.com> - 2012-08-12 00:14 -0700
      Re: in-place exponentiation incongruities Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-12 11:03 +0000
        Re: in-place exponentiation incongruities Giacomo Alzetta <giacomo.alzetta@gmail.com> - 2012-08-12 04:55 -0700
          Re: in-place exponentiation incongruities Terry Reedy <tjreedy@udel.edu> - 2012-08-12 17:53 -0400
            Re: in-place exponentiation incongruities Giacomo Alzetta <giacomo.alzetta@gmail.com> - 2012-08-14 00:14 -0700
            Re: in-place exponentiation incongruities Giacomo Alzetta <giacomo.alzetta@gmail.com> - 2012-08-14 00:14 -0700

csiph-web