Comment #8 on issue 2949 by [email protected]: trig functions do not return
exact results for half angles
http://code.google.com/p/sympy/issues/detail?id=2949
I ran into a problem evaluating cos(pi/12) the other day, and came accross
this issue when trying to determine how best to proceed. I've never
contributed to an
opensource project before, and figured this issue might be a good place to
get started since I know my math. I've updated some code in
sympy/functions/elementary/trigonometric.py to handle some of the needed
calcualtions, up to cos(pi/17). Only a small amount of code is really
needed.
In [1]: cos(pi/12)
Out[1]:
___________
╱ ___
╱ ╲╱ 3 1
╱ ───── + ─
╲╱ 4 2
In [2]: cos(pi/5)
Out[2]:
___
1 ╲╱ 5
─ + ─────
4 4
In [3]: cos(3*pi/5)
Out[3]:
___
╲╱ 5 1
- ───── + ─
4 4
In [4]: cos(2*pi/12)
Out[4]:
___
╲╱ 3
─────
2
In [5]: sin(pi/12)
Out[5]:
_____________
╱ ___
╱ ╲╱ 3 1
╱ - ───── + ─
╲╱ 4 2
In [6]: cos(pi/17)
Out[6]:
_______________________________________________________________________
╱ ⎛
_____________________________
╱ ⎜ _______________ ╱ ⎛
_____________
╱ ____ ___ ⎜ ╱ ____ ╱ ___ ⎜ ╱ ____
╱ ╲╱ 17 ╲╱ 2 ⋅⎝╲╱ - ╲╱ 17 + 17 + ╲╱ ╲╱ 2 ⋅⎝- 8⋅╲╱ ╲╱ 17 + 17
╱ ────── +
─────────────────────────────────────────────────────────────
╲╱ 32 32
___________________________________________________________
____________________________________________________⎞
_______________⎞ ⎟
⎛ ____⎞ ╱ ____ ⎟ ____ ⎟
+ ⎝-1 + ╲╱ 17 ⎠⋅╲╱ - ╲╱ 17 + 17 ⎠ + 6⋅╲╱ 17 + 34 ⎠ 15
───────────────────────────────────────────────────── + ──
32
It's unclear to me what the default behavior should be, though. How badly
you want the algebraic form of a given cos(a pi) calculation really
seems to depend on context.
Also, I'm curious what the general feeling is on caching results. There
are some simple but slow implementations (like using Chebyshev polynomials)
that could easily be adequate if we cache all the results ahead of time
for future reference.
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en.