Skip to content

Commit

Permalink
Merge pull request #21223 from MaqOwais/image_correction
Browse files Browse the repository at this point in the history
Fixes (solvers) : Removed Attribute error, type error
  • Loading branch information
smichr committed Apr 5, 2021
2 parents 38b621a + b6985fe commit 7053279
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
17 changes: 8 additions & 9 deletions sympy/solvers/solveset.py
Expand Up @@ -3198,15 +3198,14 @@ def _solve_using_known_values(result, solver):
result = _new_order_result(result, eq)
for res in result:
got_symbol = set() # symbols solved in one iteration
if soln_imageset:
# find the imageset and use its expr.
for key_res, value_res in res.items():
if isinstance(value_res, ImageSet):
res[key_res] = value_res.lamda.expr
original_imageset[key_res] = value_res
dummy_n = value_res.lamda.expr.atoms(Dummy).pop()
(base,) = value_res.base_sets
imgset_yes = (dummy_n, base)
# find the imageset and use its expr.
for key_res, value_res in res.items():
if isinstance(value_res, ImageSet):
res[key_res] = value_res.lamda.expr
original_imageset[key_res] = value_res
dummy_n = value_res.lamda.expr.atoms(Dummy).pop()
(base,) = value_res.base_sets
imgset_yes = (dummy_n, base)
# update eq with everything that is known so far
eq2 = eq.subs(res).expand()
unsolved_syms = _unsolved_syms(eq2, sort=True)
Expand Down
26 changes: 26 additions & 0 deletions sympy/solvers/tests/test_solveset.py
@@ -1,4 +1,5 @@
from sympy.core.containers import Tuple
from sympy.core.compatibility import ordered
from sympy.core.function import (Function, Lambda, nfloat, diff)
from sympy.core.mod import Mod
from sympy.core.numbers import (E, I, Rational, oo, pi)
Expand Down Expand Up @@ -1700,6 +1701,31 @@ def test_solve_nonlinear_trans():
assert nonlinsolve([x**2 - y**2/exp(x)], [x, y]) == soln4


def test_issue_19050():
# test_issue_19050 --> TypeError removed
assert dumeq(nonlinsolve([x + y, sin(y)], [x, y]),
FiniteSet((ImageSet(Lambda(n, -2*n*pi), S.Integers), ImageSet(Lambda(n, 2*n*pi), S.Integers)),\
(ImageSet(Lambda(n, -2*n*pi - pi), S.Integers), ImageSet(Lambda(n, 2*n*pi + pi), S.Integers))))
assert dumeq(nonlinsolve([x + y, sin(y) + cos(y)], [x, y]),
FiniteSet((ImageSet(Lambda(n, -2*n*pi - 3*pi/4), S.Integers), ImageSet(Lambda(n, 2*n*pi + 3*pi/4), S.Integers)), \
(ImageSet(Lambda(n, -2*n*pi - 7*pi/4), S.Integers), ImageSet(Lambda(n, 2*n*pi + 7*pi/4), S.Integers))))


def test_issue_16618():
# AttributeError is removed !
# have to remove the redundancy
_n = Dummy('n')
eqn = [sin(x)*sin(y), cos(x)*cos(y) - 1]
ans = FiniteSet((x, 2*n*pi), (2*n*pi, y), (x, 2*n*pi + pi), (2*n*pi + pi, y),\
(x, 2*_n*pi), (2*_n*pi, y), (x, 2*_n*pi + pi), (2*_n*pi + pi, y))
sol = nonlinsolve(eqn, [x, y])

for i0, j0 in zip(ordered(sol), ordered(ans)):
assert len(i0) == len(j0) == 2
assert all(a.dummy_eq(b) for a, b in zip(i0, j0))
assert len(sol) == len(ans)


def test_issue_5132_1():
system = [sqrt(x**2 + y**2) - sqrt(10), x + y - 4]
assert nonlinsolve(system, [x, y]) == FiniteSet((1, 3), (3, 1))
Expand Down

0 comments on commit 7053279

Please sign in to comment.