Hey,
 

> > I'm writing code for a new ring and my element is derived from 
> > RingElement and the parent has category Rings. 
> > Where can I find the code used by __eq__ ? (I searched now for some 
> > while, but wasn't able to find it). In particular I'm interested in the 
> > part which uses the coercion model. 
>
> See src/structure/element.pyx. You need to look for __cmp__ and 
> __richcmp__; the use of __eq__, __neq__, __le__ etc is deprecated in 
> Sage, if I understand correctly. 
>
>
   No, the opposite. the rich comparisons __eq__, __lt__, etc. are what 
should be used in place of __cmp__ in order to be more python3 compliant 
(as __cmp__ is deprecated in python3). In cython, I believe we must use 
__richcmp__ (which merges the rich comparisons into 1 function).
 

> In any case, you should have a look at the *comments* in element.pyx (I 
> am afraid it is not docstrings...), which give some useful hints. 
>
> In particular, you can see that if your derived class is a *Python* class, 
> then you should just implement __cmp__, and then the coercion framework 
> will (or should...) automatically make sure that the input of your __cmp__ 
> method will always belong to the same parent. 
> But if your derived class is a *Cython* class, then, you *must* copy the 
> __cmp__ code and the __richcmp__ code from sage.structure.element, and 
> then provide methods _cmp_c_impl and/or _richcmp_c_impl. Otherwise, 
> the coercion model will not work. 
>
> There should also be some advice in the thematic tutorials. 
>

   If you implement with 2 underscores, then you bypass the (generic) 
coercion implementation. You'd want to implement with a single underscore 
to ensure common parents (i.e. _richcm_ or _cmp_).

Best,
Travis
 

-- 
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 http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to