Changes between Version 12 and Version 45 of Ticket #24247


Ignore:
Timestamp:
01/04/18 16:41:24 (3 years ago)
Author:
jdemeyer
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #24247

    • Property Status changed from new to needs_review
    • Property Dependencies changed from #24248, #24259, #24260 to #24467
    • Property Milestone changed from sage-8.1 to sage-8.2
    • Property Commit changed from 0d3aa638f654dbc104ec85887eedfdb13e271589 to c5b1be1372141cf3447ea4c28208b60aeaa3ae03
  • Ticket #24247 – Description

    v12 v45  
    1 `__pow__` is harder than most other arithmetic coercions because you sometimes want the exponent to be an integer and sometimes you want full coercion.
     1We implement powering in the coercion model. One important difference between powering and other operators is that the most common use case for powering is powering something to an integer exponent.
    22
    3 To solve this, we essentially do as follows:
     3To deal with this integer powering, we implement an action `IntegerPowAction`. This action calls a special method `_pow_int()` on the element. In other words, `x ^ n` for an integer `n` becomes `x._pow_int(n)`. We also provide a default implementation of `_pow_int` for `MonoidElement` and `RingElement` which uses the square-and-multiply algorithm implemented in `generic_power()`.
    44
    5 1. If the arguments have equal parents, call `_pow_`.
     5For backward compatibility reasons, we also call this action for elements of `IntegerModRing(m)`. In the future, we may rethink what to do here.
    66
    7 2. If the exponent is "integer-like", call `_pow_int`.
     7Apart from this, powering behaves like other binary operators: coercion to a common parent is done if no action is defined.
    88
    9 3. If none of the above applies, do the usual coercion to a common parent. That will call `_pow_` unless the coerced arguments have a custom implementation of `__pow__`.
     9Note that the 3-argument version of `pow()` is not supported in the coercion model. Only specific types like `Integer` implement it.
    1010
    11 Furthermore, the 3-argument version of `pow()` is not supported in the coercion model. Only specific types like `Integer` implement it.
    12 
    13 This is related to Python 3 (see #16072) because this check for an integer needs to be changed in light of the changes to the `int`/`long` types.
     11We also fix various serious bugs in powering for `RDF` such as:
     12{{{
     13sage: RDF(0) ^ RDF(-1)
     140.0
     15sage: RDF(-1) ^ RDF(2)
     16NaN
     17}}}