Ticket #6111: trac_6111-sympy_oo.patch

File trac_6111-sympy_oo.patch, 1.9 KB (added by mhansen, 10 years ago)
  • sage/symbolic/constants.py

    # HG changeset patch
    # User Mike Hansen <mhansen@gmail.com>
    # Date 1243479394 25200
    # Node ID e081033d4057aa41c523994f64b73cf724d78fc8
    # Parent  23bed85236496fc7269544580f0e02370e006635
    Trac #6111: Fix bool(SR(oo) == sympy.oo) segfault.
    
    diff --git a/sage/symbolic/constants.py b/sage/symbolic/constants.py
    a b  
    276276        from sage.symbolic.pynac import register_symbol
    277277        register_symbol(self.expression(), self._conversions)
    278278
     279    def __eq__(self, other):
     280        """
     281        EXAMPLES::
     282
     283            sage: from sage.symbolic.constants import Constant
     284            sage: p = Constant('p')
     285            sage: s = Constant('s')
     286            sage: p == p
     287            True
     288            sage: p == s
     289            False
     290            sage: p != s
     291            True
     292        """
     293        return (self.__class__ == other.__class__ and
     294                self._name == other._name)
     295
    279296    def __reduce__(self):
    280297        """
    281298        Adds support for pickling constants.
  • sage/symbolic/expression.pyx

    diff --git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx
    a b  
    12631263            False
    12641264            sage: bool(1 + x^2 != 2 + x*x)
    12651265            True
     1266            sage: bool(SR(oo) == SR(oo))
     1267            True
     1268            sage: bool(-SR(oo) == SR(oo))
     1269            False
     1270            sage: bool(-SR(oo) != SR(oo))
     1271            True
    12661272        """
    12671273        if self.is_relational():
     1274            #If both the left hand side and right hand side are wrappers
     1275            #around Sage objects, then we should do the comparison directly
     1276            #with those objects
     1277            if is_a_constant(self._gobj.lhs()) and is_a_constant(self._gobj.rhs()):
     1278                return self.operator()(self.lhs().pyobject(), self.rhs().pyobject())
     1279
    12681280            res = relational_to_bool(self._gobj)
    12691281            if res:
    12701282                return True