Changes between Version 12 and Version 45 of Ticket #24247
 Timestamp:
 01/04/18 16:41:24 (4 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

Ticket #24247

Property
Status
changed from
new
toneeds_review

Property
Dependencies
changed from
#24248, #24259, #24260
to#24467

Property
Milestone
changed from
sage8.1
tosage8.2

Property
Commit
changed from
0d3aa638f654dbc104ec85887eedfdb13e271589
toc5b1be1372141cf3447ea4c28208b60aeaa3ae03

Property
Status
changed from

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.1 We 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. 2 2 3 To solve this, we essentially do as follows:3 To 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 squareandmultiply algorithm implemented in `generic_power()`. 4 4 5 1. If the arguments have equal parents, call `_pow_`.5 For backward compatibility reasons, we also call this action for elements of `IntegerModRing(m)`. In the future, we may rethink what to do here. 6 6 7 2. If the exponent is "integerlike", call `_pow_int`.7 Apart from this, powering behaves like other binary operators: coercion to a common parent is done if no action is defined. 8 8 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__`.9 Note that the 3argument version of `pow()` is not supported in the coercion model. Only specific types like `Integer` implement it. 10 10 11 Furthermore, the 3argument 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. 11 We also fix various serious bugs in powering for `RDF` such as: 12 {{{ 13 sage: RDF(0) ^ RDF(1) 14 0.0 15 sage: RDF(1) ^ RDF(2) 16 NaN 17 }}}