Skip to content

Commit

Permalink
Merge pull request #163 from skirpichev/is_comparable
Browse files Browse the repository at this point in the history
Make Basic.is_comparable more conservative for extended_real's
  • Loading branch information
skirpichev committed Jan 4, 2016
2 parents 94720c2 + c971c66 commit 65dcab0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
16 changes: 8 additions & 8 deletions sympy/core/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,8 @@ def is_hypergeometric(self, k):

@property
def is_comparable(self):
"""Return True if self can be computed to a real number
with precision, else False.
"""
Test if self can be computed to a real number with precision.
Examples
========
Expand All @@ -562,15 +562,15 @@ def is_comparable(self):
is_number = self.is_number
if is_number is False:
return False
if is_real and is_number:
return True
n, i = [p.evalf(2) for p in self.as_real_imag()]
n, i = self.as_real_imag()
if not (self.is_Float and self._prec == 1): # workaround for skirpichev/omg#161
n, i = n.evalf(2), i.evalf(2)
if not i.is_Number or not n.is_Number:
return False
if i and i._prec > 1:
if i and (i._prec > 1 or i._prec == -1):
return False
if not i and i._prec == -1:
if n._prec > 1:
if not i and (i._prec > 1 or i._prec == -1):
if n._prec > 1 or n._prec == -1:
return True

@property
Expand Down
7 changes: 6 additions & 1 deletion sympy/core/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from sympy.core.singleton import S, Singleton
from sympy.core.symbol import symbols
from sympy.core.compatibility import default_sort_key
from sympy import sin, Lambda, Q
from sympy import sin, cos, Lambda, Q


b1 = Basic()
Expand Down Expand Up @@ -196,3 +196,8 @@ def test_literal_evalf_is_number_is_zero_is_comparable():
assert i.is_zero
assert i.is_number is False
assert i.evalf(2, strict=False) == 0

# issue sympy/sympy#10272
n = sin(1)**2 + cos(1)**2 - 1
assert n.is_comparable is not True
assert n.n(2).is_comparable is not True

0 comments on commit 65dcab0

Please sign in to comment.