# HG changeset patch
# User Timo Kluck <tkluck@infty.nl>
# Date 1344711608 7200
# Node ID 6fefb2e776d7bb17611b0771bacff4ef24b34b42
# Parent 76a1123da8101f514b3c5cde6939cd666ab18ca9
Don't allow coercing for polynomial rings to the symbolic ring
diff git a/sage/rings/polynomial/polynomial_element.pyx b/sage/rings/polynomial/polynomial_element.pyx
a

b


468  468  sage: f(*[2]) # unpacking the list to call normally 
469  469  3*x + 4 
470  470  
471   The following results in an element of the symbolic ring. :: 
 471  The following results in an element of the polynomial ring 
 472  over the symbolic ring in y. :: 
472  473  
473  474  sage: f(x=sqrt(2)) 
474   (y + sqrt(2))*y + sqrt(2) 
 475  y^2 + sqrt(2)*y + sqrt(2) 
475  476  
476  477  :: 
477  478  
… 
… 

937  938  
938  939  def _symbolic_(self, R): 
939  940  """ 
 941  Sage does not allow direct coercion from a polynomial 
 942  ring to the symbolic ring. This is because the variable 
 943  name of a polynomial ring should only be a display name. 
 944  
 945  One can, however, always obtain a symbolic expression 
 946  corresponding to the polynomial by substituting a symbolic 
 947  variable into the polynomial. 
 948  
 949  As an exception, this method does return a value if the 
 950  polynomial is constant (i.e. when it is of degree zero) 
 951  and the constant coefficient can be coerced to the 
 952  symbolic ring. This is because it should be possible to 
 953  coerce constant polynomials to the base field, and the 
 954  base field may be the symbolic ring. 
 955  
940  956  EXAMPLES:: 
941  957  
942   sage: R.<x> = QQ[] 
943   sage: f = x^3 + x 
944   sage: g = f._symbolic_(SR); g 
 958  sage: R.<t> = QQ[] 
 959  sage: f = t^3 + t 
 960  sage: g = f._symbolic_(SR) 
 961  Traceback (most recent call last): 
 962  ... 
 963  TypeError: not a constant polynomial 
 964  sage: x = var('x') 
 965  sage: g = f(x); g 
945  966  (x^2 + 1)*x 
946  967  sage: g(x=2) 
947  968  10 
948  969  
949   sage: g = SR(f) 
950   sage: g(x=2) 
951   10 
952   
953   The polynomial does not have to be over a field of 
954   characteristic 0:: 
955   
956   sage: R.<w> = GF(7)[] 
957   sage: f = SR(2*w^3 + 1); f 
958   2*w^3 + 1 
959   sage: f.variables() 
960   (w,) 
961   """ 
962   d = dict([(repr(g), R.var(g)) for g in self.parent().gens()]) 
963   return self.subs(**d) 
 970  sage: R.<t> = SR[] 
 971  sage: h = (x^2 + 1)*t + 13*x^2; h 
 972  (x^2 + 1)*t + 13*x^2 
 973  sage: SR(h) 
 974  Traceback (most recent call last): 
 975  ... 
 976  TypeError: not a constant polynomial 
 977  sage: SR(h  (x^2 + 1)*t) 
 978  13*x^2 
 979  """ 
 980  if self.degree() > 0: 
 981  raise TypeError("not a constant polynomial") 
 982  return R(self[0]) 
964  983  
965  984  def __invert__(self): 
966  985  """ 
diff git a/sage/symbolic/ring.pyx b/sage/symbolic/ring.pyx
a

b


104  104  sage: SR.coerce(infinity) 
105  105  Infinity 
106  106  sage: SR.has_coerce_map_from(ZZ['t']) 
107   True 
 107  False 
108  108  sage: SR.has_coerce_map_from(ZZ['t,u,v']) 
109   True 
 109  False 
110  110  sage: SR.has_coerce_map_from(Frac(ZZ['t,u,v'])) 
111   True 
 111  False 
112  112  sage: SR.has_coerce_map_from(GF(5)['t']) 
113   True 
 113  False 
114  114  sage: SR.has_coerce_map_from(SR['t']) 
115  115  False 
116  116  sage: SR.has_coerce_map_from(Integers(8)) 
… 
… 

173  173  # sage: QQbar(sqrt(2)) + sqrt(3) 
174  174  # 3.146264369941973? 
175  175  return R not in (RLF, CLF, AA, QQbar) 
176   elif is_PolynomialRing(R) or is_MPolynomialRing(R) or is_FractionField(R): 
 176  elif is_PolynomialRing(R) or is_MPolynomialRing(R): 
 177  return False 
 178  elif is_FractionField(R): 
177  179  base = R.base_ring() 
178  180  return base is not self and self.has_coerce_map_from(base) 
179  181  elif (R is InfinityRing 