Skip to content

Commit

Permalink
solvers: workaround real_roots() sorting for simple roots
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Feb 4, 2021
1 parent 341f08f commit ae088e8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions diofant/solvers/inequalities.py
Expand Up @@ -206,6 +206,7 @@ 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
13 changes: 13 additions & 0 deletions diofant/tests/solvers/test_inequalities.py
Expand Up @@ -403,3 +403,16 @@ def test_diofantissue_836():

def test_sympyissue_20861():
assert reduce_inequalities([3/x < 0, x >= 2, x >= 7], x) is false


def test_sympyissue_20902():
eq = y/((1 + y)**2)

assert (reduce_inequalities(eq.subs({y: 3*x + 2}).diff(x) > 0) ==
(Integer(-1) < x) & (x < Rational(-1, 3)))
assert (reduce_inequalities(eq.subs({y: 3*x + 3}).diff(x) > 0) ==
(Rational(-4, 3) < x) & (x < Rational(-2, 3)))
assert (reduce_inequalities(eq.subs({y: 3*x + 4}).diff(x) > 0) ==
(Rational(-5, 3) < x) & (x < Integer(-1)))
assert (reduce_inequalities(eq.subs({y: 3*x + 2}).diff(x) > 0) ==
(Integer(-1) < x) & (x < Rational(-1, 3)))
1 change: 1 addition & 0 deletions docs/release/notes-0.13.rst
Expand Up @@ -35,3 +35,4 @@ These Sympy issues also were addressed:

* :sympyissue:`20861`: reduce_inequalities() gives impossible answer
* :sympyissue:`20874`: Port the PRS algorithm to the sparse polynomial implementation
* :sympyissue:`20902`: Incorrect inequality solving: False returned instead of answer

0 comments on commit ae088e8

Please sign in to comment.