Hi all,

I am currently torturing myself by looking at the coercion model. I saw this line <https://github.com/sagemath/sage/blob/develop/src/sage/structure/coerce_actions.pyx#L235> which I have questions about, in particular about its interaction with Python objects. Take the following code for example:

sage: class Number:
....:     def __init__(self, x): self.x = x
....:     def __repr__(self): return f"Number({self.x})"
....:     def _acted_upon_(self, other, _): return Number(self.x * ZZ(other))
....: a = Number(5)
....: a
....: a * ZZ(3)
....: a * int(3)
Number(5)
Number(15)
<TypeError>

It goes through the coercion model and arrives at the line I linked to, where Y is `ZZ` in the first case and `int` in the second. Then the `int` fails because the `isinstance(Y, Parent)` call fails, whereas the first succeeds.

My question is whether this behaviour is desirable, and whether there is any reason why Sage doesn't also check for actions with Python objects. More directly, will adding a check for say `or (isinstance(Y, type) and Y != type)` directly break anything conceptually?

For a more realistic example, currently multiplying an elliptic curve point by a Python `int` uses a slow binary addition method, whereas multiplying by a Sage `Integer` uses an optimised pari call, due to the behaviour.

--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/7fd704a3-bccf-4ef5-9862-fdce2b9d95b8%40gmail.com.

Reply via email to