Use expr.rewrite(cos), as in In [22]: print a.rewrite(cos) 3**(1/2)*(I*sin(k_1/4) + cos(k_1/4))/45 + 3**(1/2)*(-I*sin(k_1/4) + cos(k_1/4))/45 + 3**(1/2)*(-I*sin(I*(I*k_1/4 - I*k_2*3**(1/2)/4)) + cos(I*(I*k_1/4 - I*k_2*3**(1/2)/4)))/45 + 3**(1/2)*(-I*sin(I*(-I*k_1/4 + I*k_2*3**(1/2)/4)) + cos(I*(-I*k_1/4 + I*k_2*3**(1/2)/4)))/45 + 3**(1/2)*(-I*sin(I*(I*k_1/8 + I*k_2*3**(1/2)/8)) + cos(I*(I*k_1/8 + I*k_2*3**(1/2)/8)))/45 + 3**(1/2)*(I*sin(-I*(-I*k_1/8 - I*k_2*3**(1/2)/8)) + cos(-I*(-I*k_1/8 - I*k_2*3**(1/2)/8)))/45
You could then use expand() to simplify things. Aaron Meurer On Mar 31, 2010, at 9:18 AM, Colin wrote: > Dear list, > I have expressions coming from my calculation of the type: > > (1/45)*3**(1/2)*exp(-1/4*I*k_1 + (1/4)*I*k_2*3**(1/2)) + > (1/45)*3**(1/2)*exp(-1/8*I*k_1 - 1/8*I*k_2*3**(1/2)) + > (1/45)*3**(1/2)*exp((1/4)*I*k_1 - 1/4*I*k_2*3**(1/2)) + > (1/45)*3**(1/2)*exp((1/8)*I*k_1 + (1/8)*I*k_2*3**(1/2)) + > (1/45)*3**(1/2)*exp(-1/4*I*k_1) + (1/45)*3**(1/2)*exp((1/4)*I*k_1) > > where k_1,k_2 are real numbers. What is the best way to automatically > rewrite this as a weighted sum of cosines? > > all the best > --Colin > > -- > 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. > -- 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.
