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

solveset with piecewise: issue 19718 #19986

Merged
merged 2 commits into from Aug 31, 2020
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
5 changes: 4 additions & 1 deletion sympy/solvers/solveset.py
Expand Up @@ -969,6 +969,10 @@ def _solveset(f, symbol, domain, _check=False):
given symbol."""
# _check controls whether the answer is checked or not
from sympy.simplify.simplify import signsimp
from sympy.logic.boolalg import BooleanTrue

if isinstance(f, BooleanTrue):
return domain
Copy link
Member

@czgdp1807 czgdp1807 Aug 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line isn't covered by the tests according to this report. Can you please add some tests covering this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean something like this?

    f = BooleanTrue()
    assert solveset(f, x, domain=Interval(-3, 10)) == Interval(-3, 10)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This should work.


orig_f = f
if f.is_Mul:
Expand Down Expand Up @@ -1008,7 +1012,6 @@ def _solveset(f, symbol, domain, _check=False):
a = f.args[0]
result = solveset_real(a > 0, symbol)
elif f.is_Piecewise:
result = EmptySet
expr_set_pairs = f.as_expr_set_pairs(domain)
for (expr, in_set) in expr_set_pairs:
if in_set.is_Relational:
Expand Down
8 changes: 8 additions & 0 deletions sympy/solvers/tests/test_solveset.py
Expand Up @@ -694,6 +694,14 @@ def test_piecewise_solveset():

assert solveset(Piecewise((x - 1, Ne(x, I)), (x, True)), x) == FiniteSet(1)

# issue 19718
g = Piecewise((1, x > 10), (0, True))
assert solveset(g > 0, x, S.Reals) == Interval.open(10, oo)

from sympy.logic.boolalg import BooleanTrue
f = BooleanTrue()
assert solveset(f, x, domain=Interval(-3, 10)) == Interval(-3, 10)


def test_solveset_complex_polynomial():
assert solveset_complex(a*x**2 + b*x + c, x) == \
Expand Down