Opened 3 years ago

Last modified 3 years ago

#24247 closed enhancement

Implement __pow__ in the coercion model — at Version 12

Reported by: jdemeyer Owned by:
Priority: major Milestone: sage-8.2
Component: coercion Keywords:
Cc: Merged in:
Authors: Jeroen Demeyer Reviewers:
Report Upstream: N/A Work issues:
Branch: u/jdemeyer/implement___pow___in_the_coercion_model (Commits, GitHub, GitLab) Commit: 0d3aa638f654dbc104ec85887eedfdb13e271589
Dependencies: #24248, #24259, #24260 Stopgaps:

Status badges

Description (last modified by jdemeyer)

__pow__ is harder than most other arithmetic coercions because you sometimes want the exponent to be an integer and sometimes you want full coercion.

To solve this, we essentially do as follows:

  1. If the arguments have equal parents, call _pow_.
  1. If the exponent is "integer-like", call _pow_int.
  1. 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__.

Furthermore, the 3-argument version of pow() is not supported in the coercion model. Only specific types like Integer implement it.

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.

Change History (12)

comment:1 Changed 3 years ago by jdemeyer

  • Description modified (diff)

comment:2 Changed 3 years ago by jdemeyer

  • Description modified (diff)

comment:3 Changed 3 years ago by jdemeyer

  • Dependencies changed from #24244 to #24248

comment:4 Changed 3 years ago by jdemeyer

  • Branch set to u/jdemeyer/implement___pow___in_the_coercion_model

comment:5 Changed 3 years ago by git

  • Commit set to a18280f20d1a3a9d87300be699b5efa77ac10d8b

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

9ad8983Fake Integer interface
04235beNew functions integer_check_long() and integer_check_long_py()
ad34554Fix isinstance(x, int) calls in element.pyx
a18280fImplement __pow__ in the coercion model

comment:6 Changed 3 years ago by git

  • Commit changed from a18280f20d1a3a9d87300be699b5efa77ac10d8b to 8b194fb82d37eb5036f36ee37cf6b38bc27e0d30

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

bb114c9Fake Integer interface
4d76bc1New functions integer_check_long() and integer_check_long_py()
9c579c7Fix isinstance(x, int) calls in element.pyx
8b194fbImplement __pow__ in the coercion model

comment:7 Changed 3 years ago by git

  • Commit changed from 8b194fb82d37eb5036f36ee37cf6b38bc27e0d30 to 54eb896167c809daad138588f9bc86b5c5659591

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

54eb896Implement __pow__ in the coercion model

comment:8 Changed 3 years ago by jdemeyer

  • Dependencies changed from #24248 to #24248, #24259

comment:9 Changed 3 years ago by git

  • Commit changed from 54eb896167c809daad138588f9bc86b5c5659591 to 5e031351b06fe41b299b1f2fb74cb294f3489fb1

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

5e03135Implement __pow__ in the coercion model

comment:10 Changed 3 years ago by jdemeyer

  • Dependencies changed from #24248, #24259 to #24248, #24259, #24260

comment:11 Changed 3 years ago by git

  • Commit changed from 5e031351b06fe41b299b1f2fb74cb294f3489fb1 to 0d3aa638f654dbc104ec85887eedfdb13e271589

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

88eaed5Declare Integer.value as array
5c1f43fDeprecate str ^ Integer
70592a8Fix compiler warning
d3db645Merge commit '88eaed585d8159a4a0763e56caaf3a767d4cb2f0'; commit '5c1f43f861165ff975616f60cab37c92d36d10f6'; commit '70592a850d7677928592c022760d6183bd81364f' into t/24247/implement___pow___in_the_coercion_model
0d3aa63Implement __pow__ in the coercion model

comment:12 Changed 3 years ago by jdemeyer

  • Description modified (diff)
Note: See TracTickets for help on using tickets.