[sage-devel] Difference between conversion and coercion?

2011-04-01 Thread Simon King
Hi!

I hope sage-devel is the right place to ask a very basic question on
the coercion model.

sage.structure.parent.Parent has methods register_conversion and
register_coercion. What is the difference between conversion and
coercion? I see that there are different caches for the two. In what
situation is a coercion used, and in what situation a conversion?

BTW, I think a method that tells whether there is already a conversion
resp. a coercion from a ring R is cached, would be quite handy. I
could not find such method (returning R in self._coerce_from_hash
resp. R in  in self._convert_from_hash). Is there anything, or shall
I implement it myself?

Best regards,
Simon

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


Re: [sage-devel] Difference between conversion and coercion?

2011-04-01 Thread Robert Bradshaw
On Thu, Mar 31, 2011 at 11:25 PM, Simon King simon.k...@uni-jena.de wrote:
 Hi!

 I hope sage-devel is the right place to ask a very basic question on
 the coercion model.

 sage.structure.parent.Parent has methods register_conversion and
 register_coercion. What is the difference between conversion and
 coercion? I see that there are different caches for the two. In what
 situation is a coercion used, and in what situation a conversion?

A conversion is like a cast, which tries to make the object if it
makes sense at all. This is useful, for example, during construction.
E.g. there's a conversion QQ - ZZ, list - QQ[x], or even str - ZZ.
They are invoked with __call__. Coercions are the set of conversions
that happen automatically and implicitly, e.g. during arithmetic. We
don't want to support str + ZZ, and ZZ coerces to QQ but not the other
way around.

 BTW, I think a method that tells whether there is already a conversion
 resp. a coercion from a ring R is cached, would be quite handy. I
 could not find such method (returning R in self._coerce_from_hash
 resp. R in  in self._convert_from_hash). Is there anything, or shall
 I implement it myself?

No, I don't think there's anything like that yet.

- Robert

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org