The issue is that the second and third solution give None, which means
it doesn't know (there's really no good reason for this, but you
generally have to look out for that).  Really, those solutions should
be complex.

The attribute you want is is_real.

Another thing you can do is to set x to be real. If you do that, solve
will filter out the solutions automatically

In [52]: x = Symbol('x', real=True)

In [53]: print(solve(x**3 - 4, x))
[2**(2/3)]

Aaron Meurer

On Sat, Nov 2, 2013 at 10:17 AM, Alexander Birukov <[email protected]> wrote:
> Hello everyone. I have another question, and as topic name says: how can I
> sort return of solve, so complex numbers wont be in anymore?
>
> I've seached in flags for it, but no luck, and then I've played with .is_*
> attributes and got something wierd(?):
>
> sols = solve(x**3 - 4)
> sols = [sol for sol in sols if sol.is_complex]
>
> sols before filtering:
> [2**(2/3), -2**(2/3)/2 - 2**(2/3)*sqrt(3)*I/2, -2**(2/3)/2 +
> 2**(2/3)*sqrt(3)*I/2]
>
> after:
> 2**(2/3)
>
> Question is why and does that code always gives me what I want? (Just
> confused about why is_complex returns True for real, and False for exactly
> complex number).
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sympy.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to