Skip to content

Commit 420bbe2

Browse files
author
Release Manager
committed
Trac #34341: Fix bool(expr1 != expr2) for nontrivially equal expressions
As reported on [https://groups.google.com/g/sage-devel/c/rXZeGZjAIdU sage-devel]: {{{ sage: a = x^2 + 2*x + 1 sage: b = (x + 1)^2 sage: c = a != b sage: bool(c) True }}} Note that {{{ sage: bool(c.expand()) False }}} This is due to calling `is_trivial_zero` instead of `is_zero` in the `__bool__` method for symbolic expressions. The fix provided by this ticket is not intended to fix other existing `bool(expr1 != expr2)` issues (e.g. #33698). URL: https://trac.sagemath.org/34341 Reported by: tmonteil Ticket author(s): Thierry Monteil Reviewer(s): Samuel Lelièvre
2 parents 5114e87 + 5ca40a8 commit 420bbe2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/sage/symbolic/expression.pyx

+7-2
Original file line numberDiff line numberDiff line change
@@ -3456,6 +3456,11 @@ cdef class Expression(Expression_abc):
34563456
sage: val = pi - 2286635172367940241408/1029347477390786609545*sqrt(2)
34573457
sage: bool(val>0)
34583458
False
3459+
3460+
Check that :trac:`34341` is fixed::
3461+
3462+
sage: bool(x^2 + 2*x + 1 != (x + 1)^2)
3463+
False
34593464
"""
34603465
if self.is_relational():
34613466
# constants are wrappers around Sage objects, compare directly
@@ -3499,8 +3504,8 @@ cdef class Expression(Expression_abc):
34993504

35003505
# Use interval fields to try and falsify the relation
35013506
if not need_assumptions:
3502-
if pynac_result == relational_notimplemented and self.operator()==operator.ne:
3503-
return not (self.lhs()-self.rhs()).is_trivial_zero()
3507+
if pynac_result == relational_notimplemented and self.operator() == operator.ne:
3508+
return not (self.lhs()-self.rhs()).is_zero()
35043509
res = self.test_relation()
35053510
if res in (True, False):
35063511
return res

0 commit comments

Comments
 (0)