From d8c2efe41df35d7babacbf84ec2c1cd708252775 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Fri, 5 Feb 2021 07:50:46 +0300 Subject: [PATCH] polys: fix sorting of real roots Correct fix of sympy/sympy#20902 --- diofant/polys/rootisolation.py | 2 +- diofant/solvers/inequalities.py | 1 - diofant/tests/polys/test_rootoftools.py | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/diofant/polys/rootisolation.py b/diofant/polys/rootisolation.py index a5d77c35a78..d092673b380 100644 --- a/diofant/polys/rootisolation.py +++ b/diofant/polys/rootisolation.py @@ -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.""" diff --git a/diofant/solvers/inequalities.py b/diofant/solvers/inequalities.py index f3383808275..f53cb639217 100644 --- a/diofant/solvers/inequalities.py +++ b/diofant/solvers/inequalities.py @@ -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: diff --git a/diofant/tests/polys/test_rootoftools.py b/diofant/tests/polys/test_rootoftools.py index e1f1c759988..71fd628686e 100644 --- a/diofant/tests/polys/test_rootoftools.py +++ b/diofant/tests/polys/test_rootoftools.py @@ -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():