Trying to solve simple equation results in - TypeError: 'Complement' object is not iterable

68 views
Skip to first unread message

Vassili Leonov

unread,
Aug 15, 2016, 7:43:20 AM8/15/16
to sympy
I'm getting this error with 
>>> sympy.release.__version__
'1.0'

>>> import sympy
>>> v,b = sympy.symbols('v b')
>>> sympy.solveset(v/sympy.sqrt(-v**2 + 1) - b, v)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/base/data/home/apps/s~sympy-live-hrd/46.393464279709602171/sympy/sympy/solvers/solveset.py", line 791, in solveset
    return _solveset(f, symbol, domain, _check=True)
  File "/base/data/home/apps/s~sympy-live-hrd/46.393464279709602171/sympy/sympy/solvers/solveset.py", line 612, in _solveset
    solver)
  File "/base/data/home/apps/s~sympy-live-hrd/46.393464279709602171/sympy/sympy/solvers/solveset.py", line 507, in _solve_radical
    return FiniteSet(*[s for s in result if checksol(f, symbol, s) is True])
TypeError: 'Complement' object is not iterable

Same on my two different installations, same on http://live.sympy.org/

But it solves it fine after trivial transformation:

>>> sympy.solveset(v**2/(-v**2 + 1) - b**2, v)
{-b*sqrt(1/(b**2 + 1)), b*sqrt(1/(b**2 + 1))} \ {-1, 1}

Is this the expected behaviour?
What does the error  "'Complement' object is not iterable" means? Google not saying anything at all on this particular error message.

Thank you for your time and consideration.

Shekhar Prasad Rajak

unread,
Aug 19, 2016, 6:06:34 PM8/19/16
to sympy
Hello,

It is a bug. 

>What does the error  "'Complement' object is not iterable" means? Google not saying anything at all on this particular error messag

Solveset returns solution in Set. So if some values should not be included in solution set, then it uses Complement.

e.g. In second case ans is `{-b*sqrt(1/(b**2 + 1)), b*sqrt(1/(b**2 + 1))} \ {1, -1}`

Here solution set is  `{-b*sqrt(1/(b**2 + 1)), b*sqrt(1/(b**2 + 1))}` and `{1-1}` set is not the part of answer (since it makes denominator of  v/sympy.sqrt(-v**2 + 1)   
equals to zero). Ans this overall solution type is  `sympy.sets.sets.Complement`.

Thanks for sharing it.

--
Shekhar
Reply all
Reply to author
Forward
0 new messages