Skip to content

Commit

Permalink
closes sympy#22058
Browse files Browse the repository at this point in the history
Since Poly can handle symbolic coefficients, it is not necessary
to remove powers in them with unrad: passing the variable of
interest will allow a lower order polynomial to be solved.
e.g. unrad(sqrt(t)*x, x) is unchanged while unrad(sqrt(t)*x) is t*x**2

Also, only explicitly check solutions of FiniteSet.
  • Loading branch information
smichr committed Sep 10, 2021
1 parent 9cb75ab commit bf9b489
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions sympy/solvers/solveset.py
Expand Up @@ -862,7 +862,7 @@ def _solve_radical(f, unradf, symbol, solveset_solver):
result = Union(*[imageset(Lambda(y, g_y), f_y_sols)
for g_y in g_y_s])

if isinstance(result, (Complement, ConditionSet)):
if not isinstance(result, FiniteSet):
solution_set = result
else:
f_set = [] # solutions for FiniteSet
Expand Down Expand Up @@ -1067,7 +1067,7 @@ def _solveset(f, symbol, domain, _check=False):
elif isinstance(rhs_s, FiniteSet):
for equation in [lhs - rhs for rhs in rhs_s]:
if equation == f:
u = unrad(f)
u = unrad(f, symbol)
if u:
result += _solve_radical(equation, u,
symbol,
Expand Down Expand Up @@ -3448,7 +3448,7 @@ def _separate_poly_nonpoly(system, symbols):
if isinstance(eq, Equality):
eq = eq.rewrite(Add)
# try to remove sqrt and rational power
without_radicals = unrad(simplify(eq))
without_radicals = unrad(simplify(eq), *symbols)
if without_radicals:
eq_unrad, cov = without_radicals
if not cov:
Expand Down
6 changes: 6 additions & 0 deletions sympy/solvers/tests/test_solveset.py
Expand Up @@ -3064,3 +3064,9 @@ def test_issue_19144():
def test_issue_19814():
assert nonlinsolve([ 2**m - 2**(2*n), 4*2**m - 2**(4*n)], m, n
) == FiniteSet((log(2**(2*n))/log(2), S.Complexes))


def test_issue_22058():
sol = solveset(-sqrt(t)*x**2 + 2*x + sqrt(t), x, S.Reals)
# doesn't fail (and following numerical check)
assert sol.xreplace({t: 1}) == {1 - sqrt(2), 1 + sqrt(2)}, sol.xreplace({t: 1})

0 comments on commit bf9b489

Please sign in to comment.