(*by Nasser M. Abbasi, version 12/26/13*) sumsReduce[e_, x_] := Module[{e1 = e, p2, h, b, a, head}, p2 = # | Verbatim[Plus][#] &[(_. (h : Sin | Cos)[_]) ..]; head = Replace[e1, {p2 :> h, _ -> False}]; (*parsing is done, now check the result*) If[head === False, e1, e1 = TrigExpand[e1]; b = Last@CoefficientList[e1, Cos[x], 2]; a = Last@CoefficientList[e1, Sin[x], 2]; (*watch out for the atan2. Mathematica uses atan2(x, y) while Wikipedia uses atan2(y,x) *) Sqrt[a^2 + b^2] Sin[x + ArcTan[a, b]] ] ] ClearAll[a, b, c, d, e, f, g, h, x]; sumsReduce[a Cos[x] + b Cos[x + b], x] // TraditionalForm sumsReduce[a Cos[x + b] + c Cos[x + d] + e Cos[x - f], x] // TraditionalForm sumsReduce[a Sin[x + b] + c Sin[x] + e Sin[x - f], x] // TraditionalForm sumsReduce[ a Sin[x + b] + c Sin[x] + e Sin[x - f] + Sin[x - 2 f] + 3 g Sin[x - 2 d], x] // TraditionalForm parms = {a -> 2./3, b -> Pi/4.}; Grid[{ { Grid[{ {expr = HoldForm[a Cos[x] + 2 a Cos[x + b]]; Row[{Style["original ", Bold, 14], ReleaseHold@expr /. parms}]}, {result = sumsReduce[ReleaseHold[expr], x]; Row[{Style["reduced ", Bold, 14], result /. parms}]} }, Alignment -> Left], Plot[result /. parms, {x, -2 Pi, 2 Pi}, Frame -> True, FrameLabel -> {{None, None}, {None, "result"}}], Plot[ReleaseHold[expr] /. parms, {x, -2 Pi, 2 Pi}, Frame -> True, FrameLabel -> {{None, None}, {None, "original"}}] }, { Grid[{ {expr = HoldForm[a Sin[x ] + 2 a Sin[x + b]]; Row[{Style["original ", Bold, 14], ReleaseHold@expr /. parms}]}, {result = sumsReduce[ReleaseHold[expr], x]; Row[{Style["reduced ", Bold, 14], result /. parms}]} }, Alignment -> Left], Plot[result /. parms, {x, -2 Pi, 2 Pi}, Frame -> True, FrameLabel -> {{None, None}, {None, "result"}}], Plot[ReleaseHold[expr] /. parms, {x, -2 Pi, 2 Pi}, Frame -> True, FrameLabel -> {{None, None}, {None, "original"}}] }, { Grid[{ {expr = HoldForm[a Cos[x ] + a Cos[x + b] + 2 a Cos[x + 2 b] + Cos[x + 3 b]]; Row[{Style["original ", Bold, 14], ReleaseHold@expr /. parms}]}, {result = sumsReduce[ReleaseHold[expr], x]; Row[{Style["reduced ", Bold, 14], result /. parms}]} }, Alignment -> Left], Plot[result /. parms, {x, -2 Pi, 2 Pi}, Frame -> True, FrameLabel -> {{None, None}, {None, "result"}}], Plot[ReleaseHold[expr] /. parms, {x, -2 Pi, 2 Pi}, Frame -> True, FrameLabel -> {{None, None}, {None, "original"}}] }, { Grid[{ {expr = HoldForm[a Sin[x] + a Sin[x + b] + 2 a Sin[x + 2 b] + Sin[x + 3 b]]; Row[{Style["original ", Bold, 14], ReleaseHold@expr /. parms}]}, {result = sumsReduce[ReleaseHold[expr], x]; Row[{Style["reduced ", Bold, 14], result /. parms}]} }, Alignment -> Left], Plot[result /. parms, {x, -2 Pi, 2 Pi}, Frame -> True, FrameLabel -> {{None, None}, {None, "result"}}], Plot[ReleaseHold[expr] /. parms, {x, -2 Pi, 2 Pi}, Frame -> True, FrameLabel -> {{None, None}, {None, "original"}}] }, { Grid[{ {expr = HoldForm[a Sin[x] + 2 a Sin[x + 2 b] + 3 a Sin[x + 3 b] + Sin[x - 4 b] - Sin[x - b] + 2 a Sin[x - 5 b]]; Row[{Style["original ", Bold, 14], ReleaseHold@expr /. parms}]}, {result = sumsReduce[ReleaseHold[expr], x]; Row[{Style["reduced ", Bold, 14], result /. parms}]} }, Alignment -> Left], Plot[result /. parms, {x, -2 Pi, 2 Pi}, Frame -> True, FrameLabel -> {{None, None}, {None, "result"}}], Plot[ReleaseHold[expr] /. parms, {x, -2 Pi, 2 Pi}, Frame -> True, FrameLabel -> {{None, None}, {None, "original"}}] }, { Grid[{ {expr = HoldForm[a Sin[x] - 2 a Sin[x - 2 b] + 4 a Sin[x - b/10] + Sin[x - 4 b] - Sin[x - b/2] + 2 a Sin[x - 5 b]]; Row[{Style["original ", Bold, 14], ReleaseHold@expr /. parms}]}, {result = sumsReduce[ReleaseHold[expr], x]; Row[{Style["reduced ", Bold, 14], result /. parms}]} }, Alignment -> Left], Plot[result /. parms, {x, -2 Pi, 2 Pi}, Frame -> True, FrameLabel -> {{None, None}, {None, "result"}}], Plot[ReleaseHold[expr] /. parms, {x, -2 Pi, 2 Pi}, Frame -> True, FrameLabel -> {{None, None}, {None, "original"}}] }, { Grid[{ {expr = HoldForm[a Cos[x] - 2 a Cos[x - 2 b] + 4 a Cos[x - b/10] + Cos[x - 4 b] - Cos[x - b/2] + 2 a Cos[x - 5 b] + Cos[x - 6 b] + 3 a Cos[x + 20 b]]; Row[{Style["original ", Bold, 14], ReleaseHold@expr /. parms}]}, {result = sumsReduce[ReleaseHold[expr], x]; Row[{Style["reduced ", Bold, 14], result /. parms}]} }, Alignment -> Left], Plot[result /. parms, {x, -2 Pi, 2 Pi}, Frame -> True, FrameLabel -> {{None, None}, {None, "result"}}], Plot[ReleaseHold[expr] /. parms, {x, -2 Pi, 2 Pi}, Frame -> True, FrameLabel -> {{None, None}, {None, "original"}}] } }, Frame -> All]