id summary reporter owner description type status priority milestone component resolution keywords cc merged author reviewer upstream work_issues branch commit dependencies stopgaps
24247 Implement __pow__ in the coercion model jdemeyer "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.
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 square-and-multiply algorithm implemented in `generic_power()`.
For backward compatibility reasons, we also call this action for elements of `IntegerModRing(m)`. In the future, we may rethink what to do here, see #15709.
Apart from this, powering behaves like other binary operators: coercion to a common parent is done if no action is defined.
Note that the 3-argument version of `pow()` is not supported in the coercion model. Only specific types like `Integer` implement it. See also #5082.
Fixing powering for specific parents is not within the scope of this ticket, except where it was needed to fix doctest failures. For example, we fix various serious bugs in powering for `RDF` such as:
{{{
sage: RDF(0) ^ RDF(-1)
0.0
sage: RDF(-1) ^ RDF(2)
NaN
}}}" enhancement closed major sage-8.2 coercion fixed Jeroen Demeyer Travis Scrimshaw, Vincent Delecroix N/A 74d67006dfbf205f8bd43d25ef2b4eebf695ae66 74d67006dfbf205f8bd43d25ef2b4eebf695ae66 #24467