Skip to content
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

Can't solve sin(x + a) - sin(x) (for a) #10426

Closed
asmeurer opened this issue Jan 19, 2016 · 9 comments · Fixed by #20573
Closed

Can't solve sin(x + a) - sin(x) (for a) #10426

asmeurer opened this issue Jan 19, 2016 · 9 comments · Fixed by #20573
Labels
Easy to Fix This is a good issue for new contributors. Feel free to work on this if no one else has already. solvers.solveset

Comments

@asmeurer
Copy link
Member

In [9]: solveset(sin(x + a) - sin(x), a)
Out[9]: {a | a ∊ ℂ ∧ -sin(x) + sin(a + x) = 0}

In [10]: solveset(sin(x + a) - sin(x), a, domain=S.Reals)
Out[10]:
⎧              ⎛  ⎛   ⅈ⋅(-a - x)    ⅈ⋅(a + x)⎞  ⅈ⋅x    2⋅ⅈ⋅x    ⎞  -ⅈ⋅x    ⎫
⎪            ⅈ⋅⎝- ⎝- ℯ           + ℯ         ⎠⋅ℯ    + ℯ      - 1⎠⋅ℯ        ⎪
⎨a | a ∊ ℝ ∧ ────────────────────────────────────────────────────────── = 0⎬
⎪                                        2                                 ⎪
⎩                                                                          ⎭

In [11]: solve(sin(x + a) - sin(x), a)
Out[11]: [-x + asin(sin(x)), -x - asin(sin(x)) + π]

The solution should be a=2*pi*n. I believe the first solution from solve is equivalent to that.

@MSeeker
Copy link
Contributor

MSeeker commented Jan 20, 2016

For a start, a = 2*pi*n is not the complete solution to the equation. Since sin(x+a) - sin(x) = 2*cos(x+a/2)*sin(a/2), a = 2*pi*n corresponds only to the part of solution where sin(a/2) = 0, whereas cos(x + a/2) = 0 gives a = (2*n + 1) * pi - 2*x.
SymPy seems to give the correct answer if we assume x to be real, but fails if it is a general complex variable. Perhaps this is due to the different implementation of solveset_real and solveset_complex?

>>> x = symbols('x', real=True)
... z = symbols('z')
... a = Dummy('a')
...
>>> solveset(sin(x + a) - sin(x), a, domain=S.Reals)
                  ⎧           ⎛  -2x⎞        ⎫
{2nπ | n} ∪ ⎨2nπ + arg-| n⎬
                  ⎩                             ⎭
>>> solveset(sin(z + a) - sin(z), a, domain=S.Reals)
⎧              ⎛  ⎛   ⋅(-a - z)    ⋅(a + z)⎞  z    2z-z    ⎫
⎪            ⋅⎝--            +          ⎠⋅    +       - 1⎠⋅        ⎪
⎨a | a ∧ ────────────────────────────────────────────────────────── = 0⎬
⎪                                        2                                 ⎪
⎩                                                                          ⎭

Having said that, I believe solveset does needs improvement regarding trigonometric equations. For instance it doesn't know how to solve sin(a/2) = 0:

>>> solveset(sin(a/2), a, domain=S.Reals)
⎧                           -a      ⎫
⎪                           ─────     ⎪
⎪               ⎛ a2       ⎪
⎨            -⋅⎝    - 1⎠⋅          ⎬
⎪a | a ∧ ───────────────────── = 0⎪
⎪                      2              ⎪
⎩                                     ⎭

@asmeurer
Copy link
Member Author

I think you are right. My goal here is specifically to find a solution that does not depend on x, so as to show that sine is periodic. Hence, although the solutions from solve are probably correct (plus 2*pi*n) the second one is not useful as written because it is not easy to see that it doesn't depend on x.

@Shekharrajak
Copy link
Member

solution should be :
a = 4πn, a = 4πn + 2π, a = 4πn + π − 2x, a = 4πn + 3π − 2x
because using this formula :
sin s − sin t = 2cos((s+t)/2)sin((s-t)/2)
we get this 2cos((2x+a)/2)sin(a/2) = 0

@asmeurer
Copy link
Member Author

Getting the solution to reduce to just 2*pi*n would also be helpful (since that would be the period of sine). This is just a matter of getting solveset(sin(x)) to give pi*n instead of 2*pi*n and 2*pi*n + pi.

@oscarbenjamin
Copy link
Collaborator

Currently solveset gives

In [62]: solveset(sin(x + a) - sin(x), a)                                                                                                                     
Out[62]: 
                  ⎧   ⎛  ⎛           ⎛  -2⋅ⅈ⋅x⎞⎞          ⎞        ⎫
{2⋅n⋅π | n ∊ ℤ} ∪ ⎨-ⅈ⋅⎝ⅈ⋅⎝2⋅n⋅π + arg⎝-ℯ      ⎠⎠ + 2⋅im(x)⎠ | n ∊ ℤ⎬
                  ⎩                                                

The first part of that is that the 2*n*pi as requested. I guess that the other part shows that the solution depends on x in some way. For example if x is zero then we should have:

In [63]: solveset(sin(0 + a) - sin(0), a)                                                                                                                     
Out[63]: {2⋅n⋅π | n ∊ ℤ} ∪ {2⋅n⋅π + π | n ∊ ℤ}

which gives a = n*pi. The solutions from solveset matches up with this for zero x

In [64]: solveset(sin(x + a) - sin(x), a).subs(x, 0)                                                                                                          
Out[64]: {2⋅n⋅π | n ∊ ℤ} ∪ {2⋅n⋅π + π | n ∊ ℤ}

It also works for some other values:

In [67]: solveset(sin(1 + a) - sin(1), a).simplify()                                                                                                          
Out[67]: {2⋅n⋅π | n ∊ ℤ} ∪ {2⋅n⋅π - 2 + π | n ∊ ℤ}

In [68]: solveset(sin(x + a) - sin(x), a).subs(x, 1).simplify()                                                                                               
Out[68]: {2⋅n⋅π | n ∊ ℤ} ∪ {2⋅n⋅π - 2 + π | n ∊ ℤ}

I think this is correct so closing.

This can be closed if a test is added for solveset to prevent future regressions.

@oscarbenjamin oscarbenjamin added Easy to Fix This is a good issue for new contributors. Feel free to work on this if no one else has already. and removed solvers solvers.solve labels Mar 8, 2020
@oscarbenjamin
Copy link
Collaborator

A test should also be added for solve

@asmeurer
Copy link
Member Author

asmeurer commented Mar 9, 2020

The original motivation for this was for the periodicity function. It looks like periodicity currently works without making use of solve.

@hyadav2k
Copy link
Contributor

hyadav2k commented Dec 9, 2020

Hi @asmeurer @oscarbenjamin, I would like to know if this issue is resolved or I can add test cases for solveset. Kindly guide me through the process if it's still open.

@oscarbenjamin
Copy link
Collaborator

I think that the solution is correct although potentially it could be simplified. This issue could be closed if the tests were added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Easy to Fix This is a good issue for new contributors. Feel free to work on this if no one else has already. solvers.solveset
Projects
None yet
5 participants