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

On 2019-06-03, Daniel Krenn <kr...@aon.at> wrote:
> 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
>

-- 
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 post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/qd7ufk%245dbi%241%40blaine.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to