Skip to content

Commit

Permalink
fix comparisons (issue #797) (#975)
Browse files Browse the repository at this point in the history
This PR fixes #797, it is, handles comparisons involving one side with a
numeric expression and the other one with an expression involving
strings.
  • Loading branch information
mmatera authored Aug 3, 2024
1 parent fb29d32 commit b5eeb1c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ Bugs
* ``Switch[]`` involving ``Infinity`` Issue #956
* ``Outer[]`` on ``SparseArray`` Issue #939
* ``ArrayQ[]`` detects ``SparseArray`` PR #947

* Numeric comparisons against expressions involving ``String``s (Issue #797).
Package updates
+++++++++++++++
Expand Down
4 changes: 4 additions & 0 deletions mathics/eval/testing_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def do_cmp(x1, x2) -> Optional[int]:
return None

s1 = x1.to_sympy()
if s1 is None:
return None
s2 = x2.to_sympy()
if s2 is None:
return None

# Use internal comparisons only for Real which is uses
# WL's interpretation of equal (which allows for slop
Expand Down
8 changes: 8 additions & 0 deletions test/builtin/test_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@
("g[a]<g[a]", "g[a] < g[a]", "not comparable expressions (like in WMA)"),
("g[1]<g[1]", "g[1] < g[1]", "not comparable expressions (like in WMA)"),
#
('Wo["x"]>3', "Wo[x] > 3", "isue #797"),
('Wo["x"]<3', "Wo[x] < 3", "isue #797"),
('Wo["x"]==3', "Wo[x] == 3", "isue #797"),
('3>Wo["x"]', "3 > Wo[x]", "isue #797"),
('3<Wo["x"]', "3 < Wo[x]", "isue #797"),
('3==Wo["x"]', "3 == Wo[x]", "isue #797"),
('Wo[f["x"],2]>0', "Wo[f[x], 2] > 0", "isue #797"),
#
# chained compare
("a != a != b", "False", "Strange MMA behavior"),
("a != b != a", "a != b != a", "incomparable values should be unchanged"),
Expand Down

0 comments on commit b5eeb1c

Please sign in to comment.