Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Trac #32185: special case constant symbolic relations.
Browse files Browse the repository at this point in the history
The mixed_order() code in sage/symbolic/comparison.pyx uses a bunch
of heuristics to figure out how to compare two things. To compare
(say) x and y, it creates the expression (x - y), and then looks at
what type of thing (x - y) is. In most cases, this seems to work;
however, when x is a symbolic constant and y is zero, the expression
(x - y) reduces to just x, a symbolic constant. The mixed_order()
code is not expecting this, and it fails to compare x.pyobject()
to the integer zero.

To work around this problem, this commit adds an additional check for
whether or not (x - y) is a symbolic constant, and falls through to a
numerical comparison in that case.
  • Loading branch information
orlitzky committed Jul 21, 2021
1 parent cfab03a commit b30ce37
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/sage/symbolic/comparison.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,16 @@ cpdef int mixed_order(lhs, rhs) except -2:
sage: mixed_order(SR(oo), sqrt(2))
1
Ensure that :trac:`32185` is fixed::
sage: mixed_order(pi, 0)
1
sage: mixed_order(golden_ratio, 0)
1
sage: mixed_order(log2, 0)
1
"""
if lhs is rhs:
return 0
Expand Down Expand Up @@ -345,7 +355,7 @@ class _mixed_key(object):
return pynac_result == relational_true

det_ex = self.ex - other.ex
if not has_symbol_or_function((<Expression>rel)._gobj):
if not has_symbol_or_function((<Expression>rel)._gobj) and not det_ex.is_constant():
while hasattr(det_ex, 'pyobject') and isinstance(det_ex, Expression):
try:
det_ex = det_ex.pyobject()
Expand Down

0 comments on commit b30ce37

Please sign in to comment.