Re: [sage-devel] Re: Addition of zero in the coercion model

2015-03-04 Thread Nicolas M. Thiery
On Sat, Feb 21, 2015 at 08:47:40PM +, Simon King wrote: How should I fix this? By providing a starting point for the summation: sage: sum([myElement]).parent() ModularFormsRing(n=3) over Integer Ring sage: myElement.parent() ModularForms(n=3, k=4, ep=1) over Integer Ring

Re: [sage-devel] Re: Addition of zero in the coercion model

2015-03-04 Thread John Cremona
On 4 March 2015 at 08:11, Nicolas M. Thiery nicolas.thi...@u-psud.fr wrote: On Sat, Feb 21, 2015 at 08:47:40PM +, Simon King wrote: How should I fix this? By providing a starting point for the summation: sage: sum([myElement]).parent() ModularFormsRing(n=3) over Integer Ring

Re: [sage-devel] Re: Addition of zero in the coercion model

2015-02-23 Thread Jonas Jermann
Hi In my case there is a cm.coercion_map(parent(myElement), parent(0)) (line 907) namely the coercions into the modular forms ring. These maps are then used to map both myElement and 0 to the modular forms ring (in contrast to the (vector) space myElement.parent()). Unfortunately the check

Re: [sage-devel] Re: Addition of zero in the coercion model

2015-02-23 Thread Eric Gourgoulhon
Hi, Le dimanche 22 février 2015 21:25:02 UTC+1, Jeroen Demeyer a écrit : On the other, this special case is consistent with the idea of the univeral 0 object proposed by John Cremona. Indeed. In this respect, it is probably safe to use the literal 0 provided one makes sure that it is

[sage-devel] Re: Addition of zero in the coercion model

2015-02-22 Thread Eric Gourgoulhon
Hi Simon, Le dimanche 22 février 2015 00:28:42 UTC+1, Simon King a écrit : Hi Eric, On 2015-02-21, Eric Gourgoulhon egourg...@gmail.com javascript: wrote: It seems that a possible way to have 0 + MyElement work even if ZZ does= =20 not coerce to MyElement.parent() is to have=20

[sage-devel] Re: Addition of zero in the coercion model

2015-02-22 Thread Simon King
Hi Eric, On 2015-02-22, Eric Gourgoulhon egourgoul...@gmail.com wrote: Yes that's conversion, but both 0+x and x+0 works because, I think, of=20 lines 979-990 of=20 sage.structure.coerce.pyx: # Allow coercion of 0 even if no coercion from Z if is_Integer(x) and not x and

Re: [sage-devel] Re: Addition of zero in the coercion model

2015-02-22 Thread John Cremona
On 22 February 2015 at 10:00, Eric Gourgoulhon egourgoul...@gmail.com wrote: Hi Simon, Le dimanche 22 février 2015 00:28:42 UTC+1, Simon King a écrit : Hi Eric, On 2015-02-21, Eric Gourgoulhon egourg...@gmail.com wrote: It seems that a possible way to have 0 + MyElement work even if ZZ

[sage-devel] Re: Addition of zero in the coercion model

2015-02-22 Thread Eric Gourgoulhon
Le dimanche 22 février 2015 15:24:53 UTC+1, Simon King a écrit : Seriously? I didn't know that Sage's coercion model has such special cases. OK, it makes it possible to get a typical usecase with least effort. But my impression is that ultimately such special cases cause a lot more

[sage-devel] Re: Addition of zero in the coercion model

2015-02-22 Thread Simon King
Hi Eric, On 2015-02-22, Eric Gourgoulhon egourgoul...@gmail.com wrote: Note that the function is_Integer used in sage.structure.coerce.pyx is=20 *not* the above one: it is defined in lines 134-139 and it returns True for= is_Integer(int(0)).=20 Seriously? But when the integer zero is treated

Re: [sage-devel] Re: Addition of zero in the coercion model

2015-02-22 Thread Jeroen Demeyer
On 2015-02-22 15:24, Simon King wrote: Seriously? I didn't know that Sage's coercion model has such special cases. OK, it makes it possible to get a typical usecase with least effort. But my impression is that ultimately such special cases cause a lot more confusion than a clear model in the

Re: [sage-devel] Re: Addition of zero in the coercion model

2015-02-21 Thread Jonas Jermann
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. Best Jonas On 21.02.2015 22:59, Eric Gourgoulhon wrote: Hi, Le samedi 21 février

Re: [sage-devel] Re: Addition of zero in the coercion model

2015-02-21 Thread Eric Gourgoulhon
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

[sage-devel] Re: Addition of zero in the coercion model

2015-02-21 Thread Simon King
Hi Eric, On 2015-02-21, Eric Gourgoulhon egourgoul...@gmail.com wrote: It seems that a possible way to have 0 + MyElement work even if ZZ does= =20 not coerce to MyElement.parent() is to have=20 MyElement.parent()._element_constructor_ accept 0 (i.e. Integer(0)) as an= =20 argument and return

Re: [sage-devel] Re: Addition of zero in the coercion model

2015-02-21 Thread Jonas Jermann
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.

Re: [sage-devel] Re: Addition of zero in the coercion model

2015-02-21 Thread Eric Gourgoulhon
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

[sage-devel] Re: Addition of zero in the coercion model

2015-02-21 Thread Simon King
Hi Jonas, On 2015-02-21, Jonas Jermann jjerma...@gmail.com wrote: ZZ does not coerce into myElement.parent() so I end up in a much larger space than myElement.parent(). However I would prefer if adding zero didn't change the parent space. If ZZ does not coerce into the parent of your element,

[sage-devel] Re: Addition of zero in the coercion model

2015-02-21 Thread Simon King
On 2015-02-21, Simon King simon.k...@uni-jena.de wrote: If ZZ does not coerce into the parent of your element, then the parent is not a (unitary) ring. PS: And if it is not a ring, then many things don't work as smoothly as they should. For example, if P is a commutative additive group with an

Re: [sage-devel] Re: Addition of zero in the coercion model

2015-02-21 Thread Jonas Jermann
Hi Simon On 21.02.2015 21:47, Simon King wrote: Hi Jonas, On 2015-02-21, Jonas Jermann jjerma...@gmail.com wrote: ZZ does not coerce into myElement.parent() so I end up in a much larger space than myElement.parent(). However I would prefer if adding zero didn't change the parent space. If

Re: [sage-devel] Re: Addition of zero in the coercion model

2015-02-21 Thread Jonas Jermann
Hi On 21.02.2015 21:57, Simon King wrote: On 2015-02-21, Simon King simon.k...@uni-jena.de wrote: If ZZ does not coerce into the parent of your element, then the parent is not a (unitary) ring. PS: And if it is not a ring, then many things don't work as smoothly as they should. For example,

[sage-devel] Re: Addition of zero in the coercion model

2015-02-21 Thread Nils Bruin
On Saturday, February 21, 2015 at 12:57:44 PM UTC-8, Simon King wrote: I.e., if P is a commutative additive group, then P.coerce_map_from(ZZ) should return a morphism in the category of commutative additive groups. Then, x+0 should work (because the coercion map is a morphism in the

[sage-devel] Re: Addition of zero in the coercion model

2015-02-21 Thread Simon King
Hi Jonas, On 2015-02-21, Jonas Jermann jjerma...@gmail.com wrote: I'm confused. Why does the additive group of ZZ coerce into P? Oops, you are right. You can map ZZ onto an additive subgroup of P, but that would be not canonical and hence not a coercion. Anyway, Sage's coercion model works on

Re: [sage-devel] Re: Addition of zero in the coercion model

2015-02-21 Thread Jonas Jermann
Hi On 21.02.2015 22:13, Nils Bruin wrote: On Saturday, February 21, 2015 at 12:57:44 PM UTC-8, Simon King wrote: I.e., if P is a commutative additive group, then P.coerce_map_from(ZZ) should return a morphism in the category of commutative additive groups. Then, x+0 should

[sage-devel] Re: Addition of zero in the coercion model

2015-02-21 Thread Simon King
Hi Nils, On 2015-02-21, Nils Bruin nbr...@sfu.ca wrote: I'm not so sure. How does x+3 make unambiguous sense? If there is a coercion then (by definition of coercion in contrast to conversion) it is unique. We can map ZZ onto any cyclic subgroup. Yes, but at most one map is a coercion. On