On 21/09/2019 11:44, Simon King wrote:
Hi!
Let R be a ring that is an F-vector space, for some field F.
Let x,y be elements of R and c be an element of F.
If I understand correctly, in order to implement x/y, one should provide
a single underscore method x._div_. But what should one provide for x/c?
It seems that the default behaviour is to replace x/c by x*(~c), but
for efficiency I don't want that c is inverted in F before letting it
act on x.
Moreover, in my use case, R is not an integral domain (thus, has no fraction
field), and actually I don't want division in R at all. So, what do I
need to do in order to make x/y NOT work (and fail with a TypeError)?
In the above situation, is it recommended to override double underscore
__div__? Then what about Py3? Would it then be needed to override
__div__, __truediv__ and __floordiv__?
I don't know exactly what happens in Sage, except that the file
src/sage/structure/element.pyx is relevant. In general, for Python 2+3
compatibility it might help to have
from __future__ import division
at the top of your files, and then "a/b" uses __truediv__ in both Python
versions. You do not have to also implement __floordiv__ if "a//b" is
not needed (see
https://docs.python.org/2/reference/datamodel.html#object.__div__).
Best regards,
Simon
Regards,
TB
--
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/5f72fb41-b1b5-7a94-ecc9-62ceb41a23f0%40gmail.com.