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

Axiom does this in two different ways, depending on whether the
code is interpreted or compiled. 

Interpreted code does the lookup dynamically and looks at the domains.
Domains (types) can export a coerce operation that will coerce things
from other types into the current type, e.g.

  Polynomial(Integer) exports two coerce operations:
    coerce : Symbol -> Polynomial(Integer)
    coerce : Integer -> Polynomial(Integer)

and the interpreter can automatically use these to lift the input
types to the Polynomial type. Searching for and using these coerce
operations take time in the interpreter. Thus,

  1 + x

finds 9 plus operations that do not apply and one that can apply which
allows the interpreter to automatically coerce 
  1 -> Polynomial(Integer)
  x -> Polynomial(Integer)

and Polynomial(Integer) has a plus operation
  +(POLY(INT),POLY(INT)) -> POLY(INT)

so the result gets automatically coerced to Polynomial(Integer).


The other way occurs during compiles. The compiler requires you
to specify the types explicitly so it can lay down fast code.
At runtime, compiled code does a hardcoded index into the vector
that implements the Domain type to invoke the proper function.

Of course, Sage uses Python so compiling for speed isn't possible.

So allowing classes to export coerce operations that can be 
automatically applied by the interpreter is effective, if not
the most efficient method. Classes are the only place that can
encapsulate the "special case knowledge" necessary to do the
coercions. If the coercions are all buried in some external,
general purpose coercion routine with special case knowledge then,
by design, this routine needs to know everything about everything.
This makes it impossible to add new classes that "just work".

Tim

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