-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solveset returns empty set for cos(2x) = 1/2 #20798
Comments
Master gives the same as 1.7.1:
I would use git bisect to identify the commit that broke this. |
You wouldn't happen to know what commit live.sympy.com is running? Checking out the commit tagged Edit: I am testing via |
I see now there are a couple of compounding issues. SymPy live is running the commit with tag Actually the equation is correctly solved by In [1]: solveset(cos(2*x) - S(1)/2, x, Interval(0, 2*pi))
Out[1]:
⎧π 5⋅π 7⋅π 11⋅π⎫
⎨─, ───, ───, ────⎬
⎩6 6 6 6 ⎭ |
Ah. I see. That explains it. Thank you for looking into it. I assume the casting of |
It isn't possible for sympy to control how The issue here then is why
|
sympy/sympy/solvers/solveset.py Lines 626 to 631 in 9e8f62e
The issue lies here, for sympy/sympy/solvers/solveset.py Line 650 in 9e8f62e
Ultimately, |
The problem also happens when solving over the reals: In [27]: solveset(cos(2*x) - 0.5, x, Reals)
Out[27]: ∅ This is because In [28]: solveset(cos(2*x) - 0.5, x, Complexes)
Out[28]:
⎧-ⅈ⋅(ⅈ⋅(2⋅n⋅π - 1.0471975511966) - 1.11022302462516e-16) ⎫ ⎧-ⅈ⋅(ⅈ⋅(2⋅n⋅π + 1.0471975511966) - 1.11022302462516e-16) ⎫
⎨──────────────────────────────────────────────────────── | n ∊ ℤ⎬ ∪ ⎨──────────────────────────────────────────────────────── | n ∊ ℤ⎬
⎩ 2 ⎭ ⎩ 2 ⎭ However because of the use of In [29]: solveset(cos(2*x) - 0.5, x, Complexes) & Reals
Out[29]: ∅
In [31]: solveset(cos(2*x) - 0.5, x, Complexes).args[0].args[0].args[1]
Out[31]:
-ⅈ⋅(ⅈ⋅(2⋅n⋅π - 1.0471975511966) - 1.11022302462516e-16)
────────────────────────────────────────────────────────
2
In [32]: solveset(cos(2*x) - 0.5, x, Complexes).args[0].args[0].args[1].expand()
Out[32]: n⋅π - 0.523598775598299 + 5.55111512312578e-17⋅ⅈ There are several ways that we could address this:
I don't know which is the best approach to take in @gschintgen you have more experience of the |
A few thoughts:
|
Thanks @gschintgen that's very useful.
Yes, I guess that's sort of what I meant by point 2 "Add specific trig handlers" rather than solving with
The only other places that handle trig equations are In [4]: solve(cos(2*x) - 0.5)
Out[4]: [0.523598775598299, 2.61799387799149] I think that The Other similar cases are Poly which generates both real and non-real roots but has a whole load of code for carefully isolating and extracting real roots as separate from non-real roots. The full formulas from In [38]: p = 4*x**3 - 3*x - S.Half
In [39]: Poly(p).nroots()
Out[39]: [-0.766044443118978, -0.17364817766693, 0.939692620785908]
In [40]: real_roots(p)
Out[40]:
⎡ ⎛ 3 ⎞ ⎛ 3 ⎞ ⎛ 3 ⎞⎤
⎣CRootOf⎝8⋅x - 6⋅x - 1, 0⎠, CRootOf⎝8⋅x - 6⋅x - 1, 1⎠, CRootOf⎝8⋅x - 6⋅x - 1, 2⎠⎦
In [42]: [r.n() for r in real_roots(p)]
Out[42]: [-0.766044443118978, -0.17364817766693, 0.939692620785908]
In [41]: [r.n() for r in roots(p)]
Out[41]: [0.939692620785908 - 0.e-22⋅ⅈ, -0.766044443118978 - 0.e-23⋅ⅈ, -0.17364817766693 + 0.e-21⋅ⅈ] The solution then is to use
If you could push that up as it is with a short explanation then I think that would be very helpful if someone else was looking to take this on. It could be a PR or it could just be an issue with the diff posted in or something. A proof of concept is still extremely useful as a starting point if it represents a good approach as opined by someone who has studied the existing code and its limitations carefully. If you don't have time to finish it yourself then the most useful contribution (if you had any time) would be being able to review a PR from someone else if they did manage to finish it off. |
Running in https://live.sympy.org/, where the version seems to be 1.5.1 you get the following:
However, running 1.7.1, you get:
Any idea where to begin looking for a solution?
The text was updated successfully, but these errors were encountered: