#813: forced coercion vs. automatic coercion
--------------------------------+-------------------------------------------
   Reporter:  nbruin            |          Owner:  roed      
       Type:  defect            |         Status:  new       
   Priority:  major             |      Milestone:  sage-4.7.1
  Component:  basic arithmetic  |       Keywords:            
Work_issues:                    |       Upstream:  N/A       
   Reviewer:                    |         Author:            
     Merged:                    |   Dependencies:            
--------------------------------+-------------------------------------------
Changes (by SimonKing):

  * upstream:  => N/A


Comment:

 I accidentally came accross this stone age ticket.

 For the record: Current behaviour as of sage-4.7.rc2 is
 {{{
 sage: P1.<x>=QQ[]
 sage: L=P1.fraction_field()
 sage: x=L(x)
 sage: P2.<y>=P1[]
 sage:
 sage: f=x+y
 sage:
 sage: P3.<x,y>=QQ[]
 sage:
 sage: P3(f)
 x + y
 sage:
 sage: 0*P3.0+f
 ---------------------------------------------------------------------------
 TypeError                                 Traceback (most recent call
 last)

 /home/king/<ipython console> in <module>()

 /mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-
 packages/sage/structure/element.so in
 sage.structure.element.RingElement.__add__
 (sage/structure/element.c:11959)()

 /mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-
 packages/sage/structure/coerce.so in
 sage.structure.coerce.CoercionModel_cache_maps.bin_op
 (sage/structure/coerce.c:7382)()

 TypeError: unsupported operand parent(s) for '+': 'Multivariate Polynomial
 Ring in x, y over Rational Field' and 'Univariate Polynomial Ring in y
 over Fraction Field of Univariate Polynomial Ring in x over Rational
 Field'
 sage: f.parent()
 Univariate Polynomial Ring in y over Fraction Field of Univariate
 Polynomial Ring in x over Rational Field
 sage: P3
 Multivariate Polynomial Ring in x, y over Rational Field
 }}}

 The question thus is: Should there be a coercion from P3 to the parent of
 f? Then one should implement it. Otherwise, the ticket should be closed as
 invalid.

 Let fP be the parent of f, hence, the polynomial ring in y over the
 fraction field of the polynomial ring in x over the rationals.

 There ''is'' a coercion to fP from the polyomial ring in y over the
 polynomial ring in x over the rationals:
 {{{
 sage: from sage.structure.element import get_coercion_model
 sage: cm = get_coercion_model()
 sage: fP = f.parent()
 sage: cm.explain(fP, QQ[x][y])
 Coercion on right operand via
     Conversion map:
       From: Univariate Polynomial Ring in y over Univariate Polynomial
 Ring in x over Rational Field
       To:   Univariate Polynomial Ring in y over Fraction Field of
 Univariate Polynomial Ring in x over Rational Field
 Arithmetic performed after coercions.
 Result lives in Univariate Polynomial Ring in y over Fraction Field of
 Univariate Polynomial Ring in x over Rational Field
 Univariate Polynomial Ring in y over Fraction Field of Univariate
 Polynomial Ring in x over Rational Field
 }}}

 However, there is no such coercion from the bivariate polynomial ring in x
 and y over the rationals:
 {{{
 sage: cm.explain(fP, QQ[x,y])
 Will try _r_action and _l_action
 Unknown result parent.
 }}}

 I think there should be such coercion! What do you think? I guess I'll
 also ask sage-devel.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/813#comment:6>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to