Daniel Krenn
unread,Jun 2, 2019, 11:29:12 PM6/2/19Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sage-...@googlegroups.com
I have implemented a new ring (parent/element structure) and now want to
do equality testing. I use the code below, which seems to me somehow
canonical for rings and equality testing (using coercions properly).
For short, the difference between self and other is built and then
compared for zero.
Note that there is no meaningful _lt_ etc. in this ring, so I am not
sure if richcmp is to be used here (but I just might be too unskilled
with richcmp).
What is the "best way" to do so? Are there any Sage-built-in shortcuts?
ad shortcuts: for richcmp there is
sage.structure.richcmp.richcmp_by_eq_and_lt.
Best,
Daniel
Here the relevant code of the element:
def __bool__(self):
return bool(self.polynomial) or bool(self.rhs)
__nonzero__ = __bool__
def __eq__(self, other):
if other is None:
return False
try:
return not bool(self - other)
except (TypeError, ValueError):
return False
def __ne__(self, other):
return not self == other