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 b  
    156156
    157157    def _symbolic_(self, R):
    158158        """
     159        Sage does not allow direct coercion from a polynomial
     160        ring to the symbolic ring. This is because the variable
     161        name of a polynomial ring should only be a display name.
     162       
     163        One can, however, always obtain a symbolic expression
     164        corresponding to the polynomial by substituting a symbolic
     165        variable into the polynomial.
     166
     167        As an exception, this method does return a value if the
     168        polynomial is constant (i.e. when it is of degree zero)
     169        and the constant coefficient can be coerced to the
     170        symbolic ring. This is because it should be possible to
     171        convert constant polynomials to the base field, and the
     172        base field may be the symbolic ring.
     173
    159174        EXAMPLES::
    160175
    161176            sage: R.<x,y> = QQ[]
    162177            sage: f = x^3 + y
    163178            sage: g = f._symbolic_(SR); g
     179            Traceback (most recent call last):
     180            ...
     181            TypeError: not a constant polynomial
     182            sage: x,y = var('x,y')
     183            sage: g = f(x,y); g
    164184            x^3 + y
    165185            sage: g(x=2,y=2)
    166186            10
    167187
    168             sage: g = SR(f)
    169             sage: g(x=2,y=2)
    170             10
     188            sage: R.<t,s> = SR[]
     189            sage: h = (x^2 + 1)*t + x*s + 13*x^2; h
     190            (x^2 + 1)*t + x*s + 13*x^2
     191            sage: SR(h)
     192            Traceback (most recent call last):
     193            ...
     194            TypeError: not a constant polynomial
     195            sage: SR(h - (x^2 + 1)*t - x*s)
     196            13*x^2
    171197        """
    172         d = dict([(repr(g), R.var(g)) for g in self.parent().gens()])
    173         return self.subs(**d)
     198        if self.degree() > 0:
     199            raise TypeError("not a constant polynomial")
     200        return R(self.constant_coefficient())
    174201
    175202    def _polynomial_(self, R):
    176203        var = R.variable_name()
     
    12321259
    12331260        ::
    12341261
    1235             sage: R.<x,y> = NumberField(symbolic_expression(x^2+3)  ,'a')['x,y']
     1262            sage: t = var('t')
     1263            sage: R.<x,y> = NumberField(t^2 + 3 ,'a')['x,y']
    12361264            sage: f = (1/17)*x^19 + (1/6)*y - (2/3)*x + 1/3; f
    12371265            1/17*x^19 - 2/3*x + 1/6*y + 1/3
    12381266            sage: f.denominator()
     
    13111339
    13121340        ::
    13131341
    1314             sage: R.<x,y> = NumberField(symbolic_expression(x^2+3)  ,'a')['x,y']
     1342            sage: t = var('t')
     1343            sage: R.<x,y> = NumberField(t^2 + 3 ,'a')['x,y']
    13151344            sage: f = (1/17)*y^19 - (2/3)*x + 1/3; f
    13161345            1/17*y^19 - 2/3*x + 1/3
    13171346            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 b  
    950950        polynomial is constant (i.e. when it is of degree zero)
    951951        and the constant coefficient can be coerced to the
    952952        symbolic ring. This is because it should be possible to
    953         coerce constant polynomials to the base field, and the
     953        convert constant polynomials to the base field, and the
    954954        base field may be the symbolic ring.
    955955
    956956        EXAMPLES::
  • sage/symbolic/ring.pyx

    diff --git a/sage/symbolic/ring.pyx b/sage/symbolic/ring.pyx
    a b  
    184184                return True
    185185            elif isinstance(R, (Maxima, PariInstance)):
    186186                return False
     187            else:
     188                return False
    187189
    188190    def _element_constructor_(self, x):
    189191        """