Skip to content

Commit 5c32053

Browse files
committed
Handle expressions not representable by SymPy
1 parent 4449a5b commit 5c32053

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

mathics/builtin/comparison.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,10 @@ def do_cmp(x1, x2) -> Optional[int]:
510510
s1 = x1.to_sympy()
511511
s2 = x2.to_sympy()
512512

513+
# return None if expression cannot be handled by SymPy
514+
if s1 is None or s2 is None:
515+
return None
516+
513517
# Use internal comparisons only for Real which is uses
514518
# WL's interpretation of equal (which allows for slop
515519
# in the least significant digit of precision), and use

mathics/builtin/numbers/algebra.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,9 @@ def apply(self, expr, var, evaluation):
418418

419419
expr_sympy = expr.to_sympy()
420420
var_sympy = var.to_sympy()
421+
# If the expression cannot be handled by Sympy, just return it.
421422
if expr_sympy is None or var_sympy is None:
422-
return None
423+
return expr
423424

424425
try:
425426
result = sympy.apart(expr_sympy, var_sympy)
@@ -1392,8 +1393,9 @@ def apply(self, expr, evaluation):
13921393
"Factor[expr_]"
13931394

13941395
expr_sympy = expr.to_sympy()
1396+
# If the expression cannot be handled by Sympy, just return it.
13951397
if expr_sympy is None:
1396-
return None
1398+
return expr
13971399

13981400
try:
13991401
return from_sympy(sympy_factor(expr_sympy))

0 commit comments

Comments
 (0)