convert sin(p)+sin(q) to factor



*Jos Simons* simons17 at xs4all.nl
<maxima%40math.utexas.edu?Subject=Re%3A%20%5BMaxima%5D%20%28no%20subject%29&In-Reply-To=%3C029601ccb04b%24adb24900%240916db00%24%40nl%3E>
*Thu Dec 1 11:07:15 CST 201*
------------------------------

How can Maxima  the trigonometric form  sin(p)+sin(q) transform into
2*sin((p+q)/2)*cos((p-q)/2).

 Thanking you in advance for your answer,
 Dr. Joseph Simons

On *Dec 1 2011* 21:12 PM, Aleksas Domarkas wrote:
I create command "c2factor" (convert to factor):

(%i1) c2factor(f,x,y):=block([r],
r:[2*sin((x+y)/2)*cos((x-y)/2),
2*sin((x-y)/2)*cos((x+y)/2),
2*cos((x+y)/2)*cos((x-y)/2),
2*sin((x+y)/2)*sin((x-y)/2)],
r:append(r,-r),
sublist(r,lambda([x],trigrat(f-x)=0)),
if length(%%)>=1 then %%[1] else f )$

 Examples:
(%i2) c2factor(sin(p)+sin(q),p,q);
(%o2) 2*cos((p-q)/2)*sin((q+p)/2)

(%i3) c2factor(cos(p)+cos(q),p,q);
(%o3) 2*cos((p-q)/2)*cos((q+p)/2)

(%i4) c2factor(-cos(13*x)+cos(x),x,13*x);
(%o4) 2*sin(6*x)*sin(7*x)

(%i5) c2factor(sin(13*x)+cos(x),x,13*x);
(%o5) sin(13*x)+cos(x)

 Aleksas Domarkas