Hi In my case "0 + MyElement" does find a common parent, namely the modular forms _ring_.
So basically in my case "0 + some_element" is the same as "some_element.as_ring_element()", unless the weight of some_element (resp. its parent) is 0 with multiplier 1 in which case ZZ coerces into the space. In any case, it's ok. I can work around these issues. Best Jonas On 21.02.2015 23:44, Eric Gourgoulhon wrote:
Le samedi 21 février 2015 23:09:24 UTC+1, Jonas Jermann a écrit : Hi It's a good idea but it won't work (in fact the _element_constructor_ does accept zero correctly in my case). The coercion framework _first_ tries to find a common parent and _then_ the rest happens. At least in the cases I've tried (free modules as implemented in #15916), if no common parent is found, there is then a conversion of 0 via _element_constructor_, followed by the addition via the _add_ (single underscore) of the module elements. Do I understand correctly that 0 + whatever first calls sage.structure.element.RingElement.__add__, which starts by if have_same_parent(left, right): (line 1570 of sage/structure/element.pyx); if this fails, it performs return coercion_model.bin_op(left, right, add) (line 1579) and the latter shall invoke your parent._element_constructor_ to convert 0 to your zero element. I am not completely sure about this... (this is my understanding why it works in my case). Eric. Best Jonas On 21.02.2015 22:59, Eric Gourgoulhon wrote: > Hi, > > Le samedi 21 février 2015 21:59:05 UTC+1, Jonas Jermann a écrit : > > > The parent is a vector space / module not a ring. Every vector space > contains zero, so in my opinion from a conceptual point of view > adding zero should not change the parent space. > > However since it views 0 as an integer and not as (an element) the zero > subspace (unless we forcefully map it there) it seems hard to change > this behavior. :-( > > > It seems that a possible way to have 0 + MyElement work even if ZZ does > not coerce to MyElement.parent() is to have > MyElement.parent()._element_constructor_ accept 0 (i.e. Integer(0)) as > an argument and return the zero element of your vector space / module > for such an argument. Am I correct? > > Eric. > -- 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 <mailto:sage-devel+unsubscr...@googlegroups.com>. To post to this group, send email to sage-devel@googlegroups.com <mailto: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.
-- 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.