# What function can transform A*Cos[x]+B*Sin[x] to Q*Sin[x+R] form? [duplicate]

I've tried several functions related to trigonometric transformations, namely TrigFactor, TrigExpand, TrigReduce, as well as FunctionExpand and some others, but none gives me the following result (or similar) which I can verify with FullSimplify:

FullSimplify[ A Cos[x] + B Sin[x] == Sqrt[A^2+B^2] Sin[x+ArcTan[B,A]] ]


Of course, this is not a simplification of the LHS, so it's unreasonable to expect FullSimplify to yield it directly, but maybe I'm missing some more functions, which could directly lead me to expression similar to RHS of the above equality (i.e. containing only one $\sin$ or $\cos$ of shifted $x$ instead of superposition of multiple $\sin$-$\cos$es). Are there any such functions?

• Perhaps this function: CosSin[A_ Cos[x_]+B_ Sin[x_]] := Sqrt[A^2+B^2] Sin[x+ArcTan[B, A]]; {CosSin[3 Cos[y]+4 Sin[y]], CosSin[p Sin[z]+q Cos[z]]}
– Bill
Feb 13, 2016 at 18:01

You can define some new TransformationFunctions and ComplexityFunction for Simplify.

tfun[expr_] :=
expr /. a_ Cos[x_] + b_ Sin[x_] :> Sqrt[a^2 + b^2] Sin[x + ArcTan[b, a]];
cfun[expr_] :=
Plus @@ (Count[expr, #, {0, Infinity}, Heads -> True] & /@ {Sin, Cos});


Then

Simplify[A Cos[x] + B Sin[x], TransformationFunctions -> {Automatic, tfun},
ComplexityFunction -> cfun]
(* -> Sqrt[A^2 + B^2] Sin[x + ArcTan[B, A]] *)