On November 2, 2006 11:47 PM Robert Bradshaw wrote:
> 
> On Nov 2, 2006, at 8:28 PM, David Harvey wrote:
> 
> > On Nov 2, 2006, at 11:11 PM, Robert Bradshaw wrote:
> >
> >>> This is much harder. I agree it would be nice, but how would you
> >>> handle something like
> >>>
> >>> sage: R.<x> = ZZ["x"]
> >>> sage: S.<y> = ZZ["y"]
> >>> sage: x*y
> >>>
> >>> ??
> >>>
> >>> David
> >>
> >> Now you could return that as an element of ZZ['x', 'y'], 
> >> but I'm not sure that would be a good idea. (non-common parents
> >> could be good runtime indicators that something could be wrong,
> >> and efficiency could really drop...)
> >
> > Hmmm... it sounds like what you're asking for is the following.
> >
> > If x is in R, and y is in S, and there is a natural coercion from R
> > to T and a natural coercion from S to T, then
> >
> > sage: x * y
> >
> > should be smart enough to coerce both into T, and perform the
> > multiplication there. (I've left out complications involving scalar
> > multiplications...)
> >
> > Also, I guess you want T to be minimal in some sense.
> 
> Yes, that's what I'm saying, though I don't know how feasible it  
> would be in general. In terms of scalar multiplications, that's  
> actually what my original motivation was.
> 
> > One thing I definitely don't like about this is that the
> > multiplication operator has to conjure up a whole new ring.
> > But I guess this already happens for things like this:
> >
> > sage: R.<x> = PolynomialRing(ZZ)
> > sage: (x/2).parent()
> > Fraction Field of Univariate Polynomial Ring in x over Integer Ring
> 
> Yes, it already goes on with division. I think being inefficient
> is better than throwing an error (and for those interested in 
> speed they should be doing everything over the same ring...)
> 
> I have to admit that this specific example bothers me...I can see  
> where it comes from but I _want_ it to be an element of Univariate  
> Polynomial Ring in x over Rational Field, i.e. x/2 = 1/2 * x.
> 

Maybe it is interesting to consider how Axiom handles these
coercions? For example:

sage: x = axiom('x::MPOLY([x],INT)')
sage: x.type()
MultivariatePolynomial([x],Integer)
sage: y = axiom('y::MPOLY([y],INT)')
sage: y.type()
MultivariatePolynomial([y],Integer)
sage: z = x*y
sage: z
  y x
sage: z.type()
MultivariatePolynomial([x],MultivariatePolynomial([y],Integer))
sage: w = axiom('(x*y)::MPOLY([x,y],INT)')
sage: w
  y x
sage: w.type()
MultivariatePolynomial([x,y],Integer)

------

Notice in particular the type of z. Since y is from the Ring
MPOLY([y],INT), Axiom constructs the result as a polynomial
in x over the ring of polynomials in y. Is that crazy or is
that just being rigourously correct? ;) Perhaps Axiom's result
is more "minimal" then what you proposed.

But the result w shows that it is possible to specify a
coercion that does yield the result you expect.

I mention Axiom not because the way it works there is
necessarily the best, but rather because I think Axiom
illustrates fairly well what can happen when you attempt
to produce a general system of coercions. Sometimes the
results are not what you expect.

Regards,
Bill Page.



--~--~---------~--~----~------------~-------~--~----~
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://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to