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 type(yp) is not type:
>             try:
>                 return yp(0), y
>             except Exception:
>                 self._record_exception()
>
>         if is_Integer(y) and not y and type(xp) is not type:
>             try:
>                 return x, xp(0)
>             except Exception:
>                 self._record_exception()
> ...
> so that both x+0 and 0+x works:

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 spirit of "arithmetics across
parents relies on coercion morphisms, which are canonical morphisms in
suitable categories, and the composition of coercion morphisms is a
coercion morphism".

Note this:
  sage: from sage.rings.integer import is_Integer
  sage: is_Integer(int(0))
  False

I guess that explains why "0+x+y" works on the command line but not in a
python module, and why "sum([x,y])" doesn't work either.

Best regards,
Simon


-- 
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