On Thu, Sep 16, 2010 at 4:38 PM, Mateusz Paprocki <matt...@gmail.com> wrote: > Hi, > > On Thu, Sep 16, 2010 at 04:30:41PM -0700, Ondrej Certik wrote: >> Hi, >> >> today I have discovered (by accident), that you can very easily >> generate all the sin/cos multiple angle formulas, like: >> >> sin(2*x) = 2*cos(x)*sin(x) >> sin(3*x) = -(1 - 4*cos(x)**2)*sin(x) >> sin(4*x) = (-4*cos(x) + 8*cos(x)**3)*sin(x) >> cos(2*x) = -1 + 2*cos(x)**2 >> cos(3*x) = -3*cos(x) + 4*cos(x)**3 >> cos(4*x) = 1 - 8*cos(x)**2 + 8*cos(x)**4 >> cos(5*x) = 5*cos(x) - 20*cos(x)**3 + 16*cos(x)**5 >> >> so I wrote it up here: >> >> http://theoretical-physics.net/dev/src/math/trig.html#multiple-argument-formulas >> >> I put there sympy code to generate the formulas too, it's very simple. >> One just uses Chebyshev polynomials of the first and second kind. >> >> The algorithm works for half angle formulas too (see the link), but >> unfortunately sympy can't generate the representation of U_1/2 or >> T_1/2 (because it's not a polynomial anymore, one gets some square >> roots in there). Mathematica can do it though. >> > > We should implement this in expand(expr, trig=True), which is currently > painfully slow in this case.
Indeed: In [1]: %time a = sin(40*x).expand(trig=True) CPU times: user 1.00 s, sys: 0.00 s, total: 1.00 s Wall time: 0.99 s In [1]: %time a = chebyshevt(40, cos(x)) CPU times: user 0.45 s, sys: 0.00 s, total: 0.45 s Wall time: 0.45 s In [1]: %time a = chebyshevt_poly(40, cos(x)) CPU times: user 0.01 s, sys: 0.00 s, total: 0.01 s Wall time: 0.00 s So one should use chebyshevt_poly(), which is pretty much instant. Ondrej -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sy...@googlegroups.com. To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.