diff --git a/src/sage/symbolic/comparison.pyx b/src/sage/symbolic/comparison.pyx index 0802768cd1a..a701b76ca53 100644 --- a/src/sage/symbolic/comparison.pyx +++ b/src/sage/symbolic/comparison.pyx @@ -259,6 +259,8 @@ cpdef int mixed_order(lhs, rhs) except -2: sage: mixed_order(SR(oo), sqrt(2)) 1 """ + if lhs is rhs: + return 0 if not is_Expression(lhs): lhs = SR(lhs) if not is_Expression(rhs): diff --git a/src/sage/symbolic/constants.py b/src/sage/symbolic/constants.py index c651cb217af..044ea8efc86 100644 --- a/src/sage/symbolic/constants.py +++ b/src/sage/symbolic/constants.py @@ -214,13 +214,13 @@ # version 2 or any later version. The full text of the GPL is available at: # http://www.gnu.org/licenses/ ############################################################################### -from __future__ import print_function -from __future__ import absolute_import +from __future__ import print_function, absolute_import import math from functools import partial from sage.rings.infinity import (infinity, minus_infinity, unsigned_infinity) +from sage.structure.richcmp import richcmp_method, op_EQ, op_GE, op_LE constants_table = {} constants_name_table = {} @@ -263,6 +263,7 @@ def unpickle_Constant(class_name, name, conversions, latex, mathml, domain): cls = globals()[class_name] return cls(name=name) +@richcmp_method class Constant(object): def __init__(self, name, conversions=None, latex=None, mathml="", domain='complex'): @@ -292,7 +293,7 @@ def __init__(self, name, conversions=None, latex=None, mathml="", register_symbol(self.expression(), self._conversions) - def __eq__(self, other): + def __richcmp__(self, other, op): """ EXAMPLES:: @@ -306,8 +307,10 @@ def __eq__(self, other): sage: p != s True """ - return (self.__class__ == other.__class__ and - self._name == other._name) + if self.__class__ == other.__class__ and self._name == other._name: + return op in [op_EQ, op_GE, op_LE] + else: + return NotImplemented def __reduce__(self): """