Skip to content

Commit 4edae89

Browse files
committed
small fixes to PossibleZeroQ
1 parent 3eaa4ca commit 4edae89

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

mathics/builtin/arithmetic.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,9 +1343,13 @@ class PossibleZeroQ(SympyFunction):
13431343
def apply(self, expr, evaluation):
13441344
"%(name)s[expr_]"
13451345
from sympy.matrices.utilities import _iszero
1346-
13471346
sympy_expr = expr.to_sympy()
13481347
result = _iszero(sympy_expr)
1348+
if result is None:
1349+
# try expanding the expression
1350+
exprexp = Expression("ExpandAll", expr).evaluate(evaluation)
1351+
exprexp = exprexp.to_sympy()
1352+
result = _iszero(exprexp)
13491353
if result is None:
13501354
# Can't get exact answer, so try approximate equal
13511355
numeric_val = Expression("N", expr).evaluate(evaluation)
@@ -1359,7 +1363,6 @@ def apply(self, expr, evaluation):
13591363
if Expression("Simplify", expr).evaluate(evaluation) == Integer(0)
13601364
else SymbolFalse
13611365
)
1362-
13631366
return from_python(result)
13641367

13651368

mathics/core/expression.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,7 +2109,7 @@ def __neg__(self) -> 'Rational':
21092109

21102110
@property
21112111
def is_zero(self) -> bool:
2112-
return self.numerator().is_zero
2112+
return self.numerator().is_zero and not(self.denominator().is_zero)
21132113

21142114

21152115
class Real(Number):
@@ -2259,7 +2259,8 @@ def is_zero(self) -> bool:
22592259
def is_approx_zero(self) -> bool:
22602260
# FIXME: figure out how to hook int $MachinePrecision and
22612261
# what the right definition here would be.
2262-
return abs(self.value) <= 10**-14
2262+
res = abs(self.value) <= 1e-14
2263+
return res
22632264

22642265

22652266
class PrecisionReal(Real):

0 commit comments

Comments
 (0)