# Ticket #11309: trac_11309-fix-comparison-of-comparisons.patch

File trac_11309-fix-comparison-of-comparisons.patch, 3.6 KB (added by kini, 8 years ago)
• ## sage/libs/ginac/decl.pxi

```# HG changeset patch
# Date 1308205524 25200
# User Keshav Kini <keshav.kini@gmail.com>
# Parent a916e91ecd31c17b084b3bfb74bedc5f3bde5602
trac #11309: resolve nested symbolic comparisons (e.g. "(x < y) < z") properly

diff --git a/sage/libs/ginac/decl.pxi b/sage/libs/ginac/decl.pxi```
 a GEx collect(GEx s, bint dist) except + GEx diff(GSymbol s, int d)    except + GEx series(GEx s, int order, unsigned options) except + bint is_equal(GEx s)          except + bint is_zero()                except + bint is_polynomial(GEx vars)  except + bint match(GEx pattern, GExList s) except +
• ## sage/symbolic/expression.pyx

`diff --git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx`
 a def __richcmp__(left, right, int op): """ Create a formal symbolic inequality or equality. EXAMPLES:: EXAMPLES:: sage: var('x, y') (x, y) sage: x + 2/3 < y^2 x^3 - y^10 >= x^10 + y sage: x^2 > x x^2 > x Testing trac #11309 which changes the behavior of comparison of comparisons:: sage: (-x + y < 0) in [x - y < 0] False sage: Set([-x + y < 0, x - y < 0]) {-x + y < 0, x - y < 0} sage: (x < y) == (x > y) False sage: (x < 0) < (x < 1) False sage: (x < y) != (y > x) True sage: (x < x) == (x < x) True sage: (y > y) != (y > y) False sage: (x < y) != x True sage: x == (x == x) False """ return (left)._richcmp(right, op) l = left r = right if is_a_relational(l._gobj) or is_a_relational(r._gobj): c = cmp(hash(l), hash(r)) if op == Py_NE: return c != 0 elif op == Py_EQ: return c == 0 # resolve relation immediately if lhs or rhs is already a relation if is_a_relational(l._gobj): if is_a_relational(r._gobj): if l.operator() == r.operator(): e2 = ( l._gobj.lhs().is_equal(r._gobj.lhs()) and l._gobj.rhs().is_equal(r._gobj.rhs()) ) else: e2 = False          # l and r are different relations else: e2 = False              # l is relational but r isn't. if op == Py_EQ: return e2 elif op == Py_NE: return not e2 else: return False elif is_a_relational(r._gobj):  # l isn't relational but r is. if op == Py_EQ: return False elif op == Py_NE: return True else: return False # neither was relational, so we can create a symbolic relation cdef GEx e if op == Py_LT: e = g_lt(l._gobj, r._gobj) elif op == Py_NE: e = g_ne(l._gobj, r._gobj) elif op == Py_GE: e = g_ge(l._gobj, r._gobj) e = g_ge(l._gobj, r._gobj) else: raise TypeError return new_Expression_from_GEx(l._parent, e)