Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sorting in RootOf.real_roots() #1117

Merged
merged 3 commits into from Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -329,7 +329,6 @@ def solve_rational_inequalities(eqs):

for interval in global_intervals:
if interval.contains(oo) is true and expr.limit(gen, oo, '-') is false:
print(111)
interval -= FiniteSet(oo)
elif interval.contains(-oo) is true and expr.limit(gen, -oo) is false:
interval -= FiniteSet(-oo)
Expand Down
5 changes: 3 additions & 2 deletions diofant/tests/polys/test_rootoftools.py
Expand Up @@ -335,9 +335,10 @@ def test_RootOf_evalf_caching_bug():

def test_RootOf_real_roots():
assert (x**5 + x + 1).as_poly().real_roots() == [RootOf(x**3 - x**2 + 1, 0)]
assert (x**5 + x + 1).as_poly().real_roots(radicals=False) == [RootOf(
x**3 - x**2 + 1, 0)]
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 - 2)*(x - 1)*(x**2 - 2)).as_poly().real_roots() == [-sqrt(2), 1, sqrt(2), 2]
assert ((x + 1)**3*(3*x + 1)).as_poly().real_roots(multiple=False) == [(-1, 3), (Rational(-1, 3), 1)]


def test_RootOf_all_roots():
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)))
2 changes: 2 additions & 0 deletions docs/release/notes-0.13.rst
Expand Up @@ -34,3 +34,5 @@ for complete list of issues and pull requests involved in this release.
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