Trouble with a simple trig equation and solveset

57 views
Skip to first unread message

Kevin Moore

unread,
Oct 5, 2023, 11:45:49 AM10/5/23
to sympy
Hello - I'm trying to use Sympy Live to debug an issue with a program I'm writing. When I try to use solveset for sin(x)=1/2, I get no solutions. Apparently it thinks there's a tiny complex portion to the solution.

Why am I running into this? Ironically I'm not running into this problem in my own script - maybe it's a version issue?

Kevin



solveset(Eq(sin(x),1/2),x,S.Reals)


solveset(Eq(sin(x),1/2),x,S.Complexes)
{i(i(2nπ+0.523598775598299)1.110223024625161016)nZ}{i(i(2nπ0.523598775598299+π)1.110223024625161016)nZ}

Oscar Benjamin

unread,
Oct 5, 2023, 12:07:53 PM10/5/23
to sy...@googlegroups.com
This is a bug. Can you open an issue with sympy on GitHub?

The correct answer is given if you use exact rational numbers (S(1)/2
or Rational(1, 2)) rather than the float 1/2:

In [6]: solveset(Eq(sin(x), S(1)/2), x, Reals)
Out[6]:
⎧ 5⋅π │ ⎫ ⎧ π │ ⎫
⎨2⋅n⋅π + ─── │ n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─ │ n ∊ ℤ⎬
⎩ 6 │ ⎭ ⎩ 6 │ ⎭

The problem is that solveset solves this in an overly complicated way
using complex numbers even if the domain is reals. Then a small
rounding error makes it look like the solutions are not real.

--
Oscar
> --
> 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 sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/c98b1ad9-133b-484d-860a-00c48a7d339en%40googlegroups.com.

Chris Smith

unread,
Oct 6, 2023, 6:37:34 PM10/6/23
to sympy
Reply all
Reply to author
Forward
0 new messages