# Ticket #13360: trac_13360_no_coercion_from_polynomials_to_expressions_002.patch

File trac_13360_no_coercion_from_polynomials_to_expressions_002.patch, 3.9 KB (added by tkluck, 9 years ago)
• ## sage/rings/polynomial/multi_polynomial.pyx

```# HG changeset patch
# User Timo Kluck <tkluck@infty.nl>
# Date 1344716789 -7200
# Node ID a1c853a480034b655f359b4cb1677c23c636d4fa
# Parent  e58146704baf3ed374aa5d7f45187ff7e00ff0ce
Remove coercion to SR for multi-variate polynomials

diff --git a/sage/rings/polynomial/multi_polynomial.pyx b/sage/rings/polynomial/multi_polynomial.pyx```
 a def _symbolic_(self, R): """ Sage does not allow direct coercion from a polynomial ring to the symbolic ring. This is because the variable name of a polynomial ring should only be a display name. One can, however, always obtain a symbolic expression corresponding to the polynomial by substituting a symbolic variable into the polynomial. As an exception, this method does return a value if the polynomial is constant (i.e. when it is of degree zero) and the constant coefficient can be coerced to the symbolic ring. This is because it should be possible to convert constant polynomials to the base field, and the base field may be the symbolic ring. EXAMPLES:: sage: R. = QQ[] sage: f = x^3 + y sage: g = f._symbolic_(SR); g Traceback (most recent call last): ... TypeError: not a constant polynomial sage: x,y = var('x,y') sage: g = f(x,y); g x^3 + y sage: g(x=2,y=2) 10 sage: g = SR(f) sage: g(x=2,y=2) 10 sage: R. = SR[] sage: h = (x^2 + 1)*t + x*s + 13*x^2; h (x^2 + 1)*t + x*s + 13*x^2 sage: SR(h) Traceback (most recent call last): ... TypeError: not a constant polynomial sage: SR(h - (x^2 + 1)*t - x*s) 13*x^2 """ d = dict([(repr(g), R.var(g)) for g in self.parent().gens()]) return self.subs(**d) if self.degree() > 0: raise TypeError("not a constant polynomial") return R(self.constant_coefficient()) def _polynomial_(self, R): var = R.variable_name() :: sage: R. = NumberField(symbolic_expression(x^2+3)  ,'a')['x,y'] sage: t = var('t') sage: R. = NumberField(t^2 + 3 ,'a')['x,y'] sage: f = (1/17)*x^19 + (1/6)*y - (2/3)*x + 1/3; f 1/17*x^19 - 2/3*x + 1/6*y + 1/3 sage: f.denominator() :: sage: R. = NumberField(symbolic_expression(x^2+3)  ,'a')['x,y'] sage: t = var('t') sage: R. = NumberField(t^2 + 3 ,'a')['x,y'] sage: f = (1/17)*y^19 - (2/3)*x + 1/3; f 1/17*y^19 - 2/3*x + 1/3 sage: f.numerator()
• ## sage/rings/polynomial/polynomial_element.pyx

`diff --git a/sage/rings/polynomial/polynomial_element.pyx b/sage/rings/polynomial/polynomial_element.pyx`
 a polynomial is constant (i.e. when it is of degree zero) and the constant coefficient can be coerced to the symbolic ring. This is because it should be possible to coerce constant polynomials to the base field, and the convert constant polynomials to the base field, and the base field may be the symbolic ring. EXAMPLES::
• ## sage/symbolic/ring.pyx

`diff --git a/sage/symbolic/ring.pyx b/sage/symbolic/ring.pyx`
 a return True elif isinstance(R, (Maxima, PariInstance)): return False else: return False def _element_constructor_(self, x): """