Skip to content

Commit

Permalink
polys: fix sorting of real roots
Browse files Browse the repository at this point in the history
Correct fix of sympy/sympy#20902
  • Loading branch information
skirpichev committed Feb 5, 2021
1 parent ae088e8 commit d8c2efe
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion diofant/polys/rootisolation.py
Expand Up @@ -859,7 +859,7 @@ def as_tuple(self):

def is_disjoint(self, other):
"""Return ``True`` if two isolation intervals are disjoint."""
return self.b <= other.a or other.b <= self.a
return self.b < other.a or other.b < self.a

def refine(self):
"""Perform one step of real root refinement algorithm."""
Expand Down
1 change: 0 additions & 1 deletion diofant/solvers/inequalities.py
Expand Up @@ -206,7 +206,6 @@ def solve_poly_inequality(poly, rel):
raise NotImplementedError(f"Couldn't determine truth value of {t}")

reals, intervals = poly.real_roots(multiple=False), []
reals = sorted(reals, key=lambda r: r[0])

if rel == '==':
for root, _ in reals:
Expand Down
1 change: 1 addition & 0 deletions diofant/tests/polys/test_rootoftools.py
Expand Up @@ -338,6 +338,7 @@ def test_RootOf_real_roots():
assert (x**5 + x + 1).as_poly().real_roots(radicals=False) == [RootOf(
x**3 - x**2 + 1, 0)]
assert (x**7 - 0.1*x + 1).as_poly(x).real_roots() == [RootOf(10*x**7 - x + 10, 0)]
assert (x**4 - 3*x**3 + 6*x - 4).as_poly().real_roots() == [-sqrt(2), 1, sqrt(2), 2]


def test_RootOf_all_roots():
Expand Down

0 comments on commit d8c2efe

Please sign in to comment.