# Between Expand and TrigExpand

Consider a simple trigonometric expression below :

(cos(x)+2)^6+(sin(y)+1)^4


Now following outputs were obtained from Mathematica 10

Expand[((1 + Sin[y])^2)^2 + ((2 + Cos[x])^3)^2]

65 + 192 Cos[x] + 240 Cos[x]^2 + 160 Cos[x]^3 + 60 Cos[x]^4 +
12 Cos[x]^5 + Cos[x]^6 + 4 Sin[y] + 6 Sin[y]^2 + 4 Sin[y]^3 +
Sin[y]^4


Hence, as expected Expand multiplied out the products and positive integral powers in the highest level of the expression giving the above result.

However

TrigExpand[((1 + Sin[y])^2)^2 + ((2 + Cos[x])^3)^2]

3379/16 + (639 Cos[x])/2 + (4815 Cos[x]^2)/32 + (175 Cos[x]^3)/4 + (
123 Cos[x]^4)/16 + (3 Cos[x]^5)/4 + Cos[x]^6/32 - (7 Cos[y]^2)/2 +
Cos[y]^4/8 - (4815 Sin[x]^2)/32 - 525/4 Cos[x] Sin[x]^2 -
369/8 Cos[x]^2 Sin[x]^2 - 15/2 Cos[x]^3 Sin[x]^2 -
15/32 Cos[x]^4 Sin[x]^2 + (123 Sin[x]^4)/16 + 15/4 Cos[x] Sin[x]^4 +
15/32 Cos[x]^2 Sin[x]^4 - Sin[x]^6/32 + 7 Sin[y] -
3 Cos[y]^2 Sin[y] + (7 Sin[y]^2)/2 - 3/4 Cos[y]^2 Sin[y]^2 +
Sin[y]^3 + Sin[y]^4/8


Mathematica documentation states the following about TrigExpand :

TrigExpand splits up sums and integer multiples that appear in arguments of trigonometric functions, and then expands out products of trigonometric functions into sums of powers, using trigonometric identities when possible.

However

1. There were no products of trigonometric functions in the input above.
2. The final output contains products of trigonometric functions.

What is the reason for this behavior?

• Try Simplify on TrigExpand and see what happens. Commented Sep 13, 2016 at 18:05
• 1/32 (6758 + 10224 Cos[x] + 4815 Cos[2 x] + 1400 Cos[3 x] + 246 Cos[4 x] + 24 Cos[5 x] + Cos[6 x] - 112 Cos[2 y] + 4 Cos[4 y] + 224 Sin[y] - 32 Sin[3 y]) FullSimplify returns the same result as Simplify Commented Sep 13, 2016 at 18:06
• Now note that in the first expression (the one with only Expand) you have powers of trigs, e.g. Cos[x]^6. In the second (TrigExpand), after Simplyfying it, there are harmonics, e.g. Cos[6 x]. So, TrigExpand does exactly what the docs say. Consider also a simpler example: Expand[Sin[x]^2 + Cos[x]^2] and TrigExpand[Sin[x]^2 + Cos[x]^2], as well as the first two examples for Simplify in the docs. Commented Sep 13, 2016 at 18:11
• When TrigExpand encounters the input expression, and expands the exponents, it should see the output which Expand gives. At that moment there are no multiple angles (e.g 6x) in the argument of the trigonometric functions. So, ideally shouldn't it stop there ? What does it innovate to bring about a harmonic representation ? This begs the question, that does TrigExpand try to use identities to force a harmonic representation of an expression before producing the expansion and giving the final result ? Unfortunately, these intricacies are mentioned nowhere in my knowledge. Commented Sep 13, 2016 at 18:23
• From your own post: "using trigonometric identities when possible".Simplifying, Expand works on polynomials, TrigExpnd uses trig properties. One can make Expand work on trigs by adding Trig -> True (also from the docs). Commented Sep 13, 2016 at 18:28

## 1 Answer

Let's name the two possibilities:

a = Expand[((1 + Sin[y])^2)^2 + ((2 + Cos[x])^3)^2]


65 + 192 Cos[x] + 240 Cos[x]^2 + 160 Cos[x]^3 + 60 Cos[x]^4 + 12 Cos[x]^5 + Cos[x]^6 + 4 Sin[y] + 6 Sin[y]^2 + 4 Sin[y]^3 + Sin[y]^4

b = TrigExpand[((1 + Sin[y])^2)^2 + ((2 + Cos[x])^3)^2]


3379/16 + (639 Cos[x])/2 + (4815 Cos[x]^2)/32 + (175 Cos[x]^3)/4 + ( 123 Cos[x]^4)/16 + (3 Cos[x]^5)/4 + Cos[x]^6/32 - (7 Cos[y]^2)/2 + Cos[y]^4/8 - (4815 Sin[x]^2)/32 - 525/4 Cos[x] Sin[x]^2 - 369/8 Cos[x]^2 Sin[x]^2 - 15/2 Cos[x]^3 Sin[x]^2 - 15/32 Cos[x]^4 Sin[x]^2 + (123 Sin[x]^4)/16 + 15/4 Cos[x] Sin[x]^4 + 15/32 Cos[x]^2 Sin[x]^4 - Sin[x]^6/32 + 7 Sin[y] - 3 Cos[y]^2 Sin[y] + (7 Sin[y]^2)/2 - 3/4 Cos[y]^2 Sin[y]^2 + Sin[y]^3 + Sin[y]^4/8

b has a rather unappealing form, so let's Simplify it:

Simplify@b


1/32 (6758 + 10224 Cos[x] + 4815 Cos[2 x] + 1400 Cos[3 x] + 246 Cos[4 x] + 24 Cos[5 x] + Cos[6 x] - 112 Cos[2 y] + 4 Cos[4 y] + 224 Sin[y] - 32 Sin[3 y])

Note that a contains only powers, e.g. Cos[x]^6 of trigonometric functions (trigs for short). That is consistent with what Expand does, being in most cases working on polynomial or polynomial-type expressions. On the other hand, b contains harmonics, e.g. Cos[6 x]. This is also consistent with the documentation, which states

TrigExpand splits up sums and integer multiples that appear in arguments of trigonometric functions, and then expands out products of trigonometric functions into sums of powers, using trigonometric identities when possible.

This is well illustrated with a very simple example:

Expand[Sin[x]^2 + Cos[x]^2]


Cos[x]^2 + Sin[x]^2

TrigExpand[Sin[x]^2 + Cos[x]^2]


1

One can make Expand work on trigs in a way TrigExpand does by adding Trig -> True, i.e.

Expand[((1 + Sin[y])^2)^2 + ((2 + Cos[x])^3)^2, Trig -> True]