testing for equality in new ring

43 views
Skip to first unread message

Daniel Krenn

unread,
Jun 2, 2019, 11:29:12 PM6/2/19
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

Simon King

unread,
Jun 5, 2019, 4:28:46 AM6/5/19
to sage-...@googlegroups.com
Hi Daniel,

I'd be interested in that topic as well. I do not try to answer your
question myself, because I remember (hopefully correctly) that the
recommended way to do equality testing has changed because of the
switch to Python3.

So, hopefully someone else can chime in...

Best regards,
Simon
Reply all
Reply to author
Forward
0 new messages