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

Challenging trig expression for solve/simplify #13754

Open
asmeurer opened this issue Dec 17, 2017 · 6 comments
Open

Challenging trig expression for solve/simplify #13754

asmeurer opened this issue Dec 17, 2017 · 6 comments

Comments

@asmeurer
Copy link
Member

Take the following

>>> expr = -1 + (cos(pi*(2*n - 2)/(2*n)) + 1)*(cos(pi*(2*n - 4)/(2*(n - 1))) + 1)/((-cos(pi*(2*n - 2)/(2*n)) + 1)*(-cos(pi*(2*n - 4)/(2*(n - 1))) + 1))
>>> pprint(expr)
       ⎛   ⎛π⋅(2⋅n - 2)⎞    ⎞ ⎛   ⎛π⋅(2⋅n - 4)⎞    ⎞
       ⎜cos⎜───────────⎟ + 1⎟⋅⎜cos⎜───────────⎟ + 1⎟
       ⎝   ⎝    2⋅n    ⎠    ⎠ ⎝   ⎝  2⋅n - 2  ⎠    ⎠
-1 + ─────────────────────────────────────────────────
     ⎛     ⎛π⋅(2⋅n - 2)⎞    ⎞ ⎛     ⎛π⋅(2⋅n - 4)⎞    ⎞
     ⎜- cos⎜───────────⎟ + 1⎟⋅⎜- cos⎜───────────⎟ + 1⎟
     ⎝     ⎝    2⋅n    ⎠    ⎠ ⎝     ⎝  2⋅n - 2  ⎠    ⎠

The goal is to solve the expression for n.

The solution is GoldenRatio. simplify has a hard time simplifying this when plugged in, either in GoldenRatio form or (sqrt(5) - 1)/2 form. I was able to manually simplify it

>>> simplify(expr.subs(n, GoldenRatio).subs(1/GoldenRatio, GoldenRatio - 1)).subs(GoldenRatio - 1, 1/GoldenRatio)
0

There are probably other complex solutions as well.

I'm not able to get this from solve or solveset. solveset gets close when given the simplified version:

>>> pprint(solveset(simplify(expr)))
⎧               ⎛π⎞      ⎛ π⋅n ⎞    ⎫   ⎧               ⎛π⎞    ⎛ π⋅n ⎞      ⎛π⎞      ⎛ π⋅n ⎞        ⎫
⎨n | n ∊ ℂ ∧ cos⎜─⎟ - cos⎜─────⎟ = 0⎬ \ ⎨n | n ∊ ℂ ∧ cos⎜─⎟⋅cos⎜─────⎟ - cos⎜─⎟ + cos⎜─────⎟ - 1 = 0⎬
⎩               ⎝n⎠      ⎝n - 1⎠    ⎭   ⎩               ⎝n⎠    ⎝n - 1⎠      ⎝n⎠      ⎝n - 1⎠        ⎭

You can get the golden ratio with

>>> solveset(pi/n - pi*n/(n - 1) + 2*pi)
{1/2 + sqrt(5)/2, -sqrt(5)/2 + 1/2}
@smichr
Copy link
Member

smichr commented Dec 21, 2017

The following should be able to be solved for n, but I can't check it here:

simplify(expr.rewrite(tan).subs(n,(1/z+2)/2).expand()).subs(z,1/(2*n-2))

@asmeurer
Copy link
Member Author

That simplifies it a great deal but solve/solevset still can't handle it.

@smichr
Copy link
Member

smichr commented Dec 21, 2017

can't handle it.

What are you getting? I get

>>> solve(expr)
[1/2 + sqrt(5)/2, -sqrt(5)/2 + 1/2, -sqrt(5)/2 + 3/2, sqrt(5)/2 + 3/2]

@asmeurer
Copy link
Member Author

I get [], both for the original expr and the version simplified from your comment.

@jksuom
Copy link
Member

jksuom commented Dec 21, 2017

In [1]: expr = -1 + (cos(pi*(2*n - 2)/(2*n)) + 1)*(cos(pi*(2*n - 4)/(2*(n - 1))) + 1)/((-cos(pi*(2*n - 2)/(2*n)) + 1)*(-cos(pi*(2*n - 4)/(2*(n - 1))) + 1))

In [2]: solve(expr)
Out[2]: []

In [3]: n = Symbol('n')

In [4]: expr = -1 + (cos(pi*(2*n - 2)/(2*n)) + 1)*(cos(pi*(2*n - 4)/(2*(n - 1))) + 1)/((-cos(pi*(2*n - 2)/(2*n)) + 1)*(-cos(pi*(2*n - 4)/(2*(n - 1))) + 1))

In [5]: solve(expr)
Out[5]: 
⎡1   √5    √5   1    √5   3  √5   3⎤
⎢─ + ──, - ── + ─, - ── + ─, ── + ─⎥
⎣2   2     2    2    2    2  2    2⎦

@asmeurer
Copy link
Member Author

Oh crap, n is an integer by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants