As I've mentioned in other threads, I'm in the process of refactoring
expand.  One major consequence of my refactoring is that expand()
doesn't try so hard to make everything expand "all the way".

In doing this, I noticed that the expansions of the form sin(n*x) =>
sum of powers of sin(x) and cos(x) is implemented recursively using
the sin(x + y) => sin(x)*cos(y) + sin(y)*cos(x) formula.  Not only is
this very inefficient, but it no longer expands all the way, leading
to results like

In [46]: print sin(3*x).expand(trig=True)
(2*cos(x)**2 - 1)*sin(x) + 2*sin(x)*cos(x)**2

instead of the behavior from master:

>>> print sin(3*x).expand(trig=True)
4*sin(x)*cos(x)**2 - sin(x)

I found the formula
http://en.wikipedia.org/wiki/Trig_identities#Sine.2C_cosine.2C_and_tangent_of_multiple_angles.
 However, this gives a different result:

In [11]: print sin(3*x).expand(trig=True) # My branch
-sin(x)**3 + 3*sin(x)*cos(x)**2

These formulations are equivalent:

In [14]: a = sin(3*x).expand(trig=True)

In [15]: b = 4*sin(x)*cos(x)**2-sin(x)

In [16]: trigsimp(a - b)
Out[16]: 0

And according to WolframAlpha, there is yet a third representation,
3*sin(x) - 4*sin(x)**3.  Which of these would be preferred?  I guess
they are all related by replacing sin(x)**2 with 1 - cos(x)**2 or
cos(x)**2 with 1 - sin(x)**2, which means that for larger n, there are
dozens of different equivalent representations.

Tom, no doubt changing this would affect trigsimp_groebner.  Do you
have any opinion?

If one of the ones other than the way from Wikipedia is preferred,
does anyone know of a formula to generate it non-recursively?

Aaron Meurer

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" 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?hl=en.

Reply via email to