|
8 | 8 |
|
9 | 9 | from mathics.builtin.base import BinaryOperator, Builtin, SympyFunction |
10 | 10 | from mathics.core.expression import (Complex, Expression, Integer, Number, |
11 | | - String, Symbol) |
| 11 | + Real, String, Symbol) |
12 | 12 | from mathics.core.numbers import dps |
13 | 13 |
|
14 | 14 |
|
@@ -324,25 +324,28 @@ def do_cmp(x1, x2): |
324 | 324 | ): |
325 | 325 | return None |
326 | 326 |
|
327 | | - # rely on sympy for better comparisons |
328 | 327 | s1 = x1.to_sympy() |
329 | 328 | s2 = x2.to_sympy() |
330 | 329 |
|
331 | | - # this might seem like poorly written code at first glance, but |
332 | | - # the equality comparison is required for it to function properly. |
333 | | - # Sympy comparisons might not return sometimes, and will raise |
334 | | - # an error in that case if not compared to True/False. |
| 330 | + # use internal comparisons only for Reals |
| 331 | + # and use sympy for everything else |
| 332 | + if s1.is_Float and s2.is_Float: |
| 333 | + if x1 == x2: |
| 334 | + return 0 |
| 335 | + if x1 < x2: |
| 336 | + return -1 |
| 337 | + return 1 |
335 | 338 |
|
336 | | - eq = sympy.Equality(s1, s2) |
| 339 | + # we don't want to compare anything that |
| 340 | + # cannot be represented as a numeric value |
| 341 | + if s1.is_number and s2.is_number: |
| 342 | + if s1 == s2: |
| 343 | + return 0 |
| 344 | + if s1 < s2: |
| 345 | + return -1 |
| 346 | + return 1 |
337 | 347 |
|
338 | | - if eq == True: |
339 | | - return 0 |
340 | | - elif eq != False: |
341 | | - return None |
342 | | - |
343 | | - if sympy.StrictLessThan(s1, s2) == True: |
344 | | - return -1 |
345 | | - return 1 |
| 348 | + return None |
346 | 349 |
|
347 | 350 |
|
348 | 351 | class SympyComparison(SympyFunction): |
@@ -766,7 +769,7 @@ class Min(_MinMax): |
766 | 769 | <dd>returns the expression with the lowest value among the $e_i$. |
767 | 770 | </dl> |
768 | 771 |
|
769 | | - Minimum of a series of numbers: |
| 772 | + Minimum of a series of values: |
770 | 773 | >> Min[4, -8, 1] |
771 | 774 | = -8 |
772 | 775 | >> Min[E - Pi, Pi, E + Pi, 2 E] |
|
0 commit comments