3

If I use TrigFactor, it gives the result in terms of Sin:

In[483]:=
expr := Cos[x] + Sin[x]
TrigFactor[expr]

Out[485]=Sqrt[2]*Sin[Pi/4 + x]

What I want to get is

Sqrt[2]*Cos[-Pi/4 + x]

Using ReplaceAll doesn't help, since it does the replacement, but then converts back to Sin.

In[489]:=
expr := Cos[x] + Sin[x]
TrigFactor[expr] /. Sin[t_] -> Cos[t - Pi/2]

Out[490]=Sqrt[2] Sin[Pi/4 + x]

  • Try e.g.: TrigFactor[expr] /. Sin[Pi/4 + t_] -> HoldForm@Cos[t - Pi/4] – Daniel Huber Nov 28 '21 at 17:20
  • (((expr // TrigFactor) /. Sin[x_] :> Inactive[Cos][x - Pi/2]) // Activate) /. Cos[x_] :> Cos[-x] The last replacement is not necessary if you are satisfied with the negative of the desired argument. – Bob Hanlon Nov 28 '21 at 17:57

2 Answers2

9

Try this:

Simplify[TrigFactor[Cos[x] + Sin[x]], 
 ComplexityFunction -> (Count[{#1}, _Sin, Infinity] &)]

(* Sqrt[2] Cos[1/4 ([Pi] - 4 x)] *)

Have fun!

Alexei Boulbitch
  • 39,397
  • 2
  • 47
  • 96
7

Use RuleDelayed (:>) instead of Rule (->) (see: tutorial/ImmediateAndDelayedDefinitions):

TrigFactor[expr] /. Sin[t_] :> (Cos[t - Pi/2])
 Sqrt[2] Cos[π/4 - x]

Alternatively,

TrigFactor[expr] /. Sin -> (Cos[# - π/2] &)
 Sqrt[2] Cos[π/4 - x]
kglr
  • 394,356
  • 18
  • 477
  • 896