On Jun 3, 2008, at 12:22 PM, Henryk Trappmann wrote:

> On 31 Mai, 15:59, "William Stein" <[EMAIL PROTECTED]> wrote:
>> At a bare minimum there is never a canonical (automatic)
>> coercion from elements of R to elements of S unless that coercion
>> is defined (as a homomorphism) on all of R.
>
> I dont want to be heretical by why is it so important that coercion is
> totally defined?
>
> Considering all the current discussion, I get the impression that
> allowing partial coercion would solve much of the arising problems
> nearly without effort.
>
> SR can be easily partially coerced to any number system. Just try to
> evaluate the SR term in that number system. Either it succeeds for
> example
> log(2) or sqrt(2) directly translates to RR by log(RR(2)) and
> sqrt(RR(2)) or it fails, for example RR(x) or RR(1)/RR(0).
>
> While sqrt(RR(-2)) is somehow mixed, depending on the sign of the
> argument sqrt returns either something of a complex or a real field.
> Which is quite desirable. So that means if one would try to coerce
> from SR to RR it can happen that the result is a CC, what however
> would perfectly fit, i.e. would perfectly be what one expects when one
> writes: sqrt(-2)*1.0.
>
> I hope everyone agrees that the above two (but at least the above
> first) paragraph(s) is what one would expect/desire.
>
> Then for coercion would only matter the exactness of a structure and
> the subset relation. The general rule would be: If there one structure
> is less exact then coerce to this structure. If we have two structures
> with equal exactness coerce to the substructure if possible, in doubt
> coerce to the superstructure.
>
> This would also solve the performance and representation issue. As
> long as no coercing takes places just compute in whatever Ring you
> want. But if it comes to coercion/evaluation/decision it may take
> somewhat longer (what also would be what I expect).

This is a good question, and has been extensively discussed before,  
but I will try and justify it a bit here. In Sage there are two kinds  
of conversions from one ring to another: casting and coercion. If I  
have an element a in S, and I want to view it as an element in R, I  
can write R(a). This should work whenever it's possible to make sense  
of a in R. Coercion, on the other hand, is implicit and thus should  
be fairly conservative. To reduce ambiguity, it should also go  
exactly one direction (unless, perhaps, there is a canonical  
isomorphism). It makes more sense for there to be a coercion RR -> SR  
than the other way around, so that when one writes "sqrt(x) * 2.4" it  
tries to give a result in SR rather than an error due to failure to  
give a result in RR.

I'm not sure how allowing partial coercions would help the situation.  
The problems are (1) given a and b in different rings, how to quickly  
find a' and b' so that a' + b' makes sense and dispatch to that  
operation and (2) whether or not sqrt(2) should start out as a SR  
object, or something more specific the same way integers and  
rationals do, and then coerced down to SR if need be.

- Robert


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to