There is no best general way to check if any two trigonometric expressions are equal. One can use TrigReduce
, TrigExpand
, TrigFactor
, TrigToExp
, Together
and Apart
(especially with the Trig->True
option), Simplify
, FullSimplify
, etc. All these functions have their advantages and we discuss some of them. For more complicated examples when using Simplify
and FullSimplify
we can encounter problems with timings and/or memory allocation, we give an appropriate example later.
In case of your example I recommend to evaluate TrigReduce
on the difference of the both expressions.
Sometimes you needn't use any simplifications, and quite inevident expressions are simplified automatically by built-in rewrite rules.
First we consider a few examples where no Mathematica functions are needed.
ex 1.
$$\sum_{\small{k = 1}}^{\small{k = m-1}} \;\frac{1}{\sin^{2}(\frac{k\; \pi}{m})} = \frac{m^{2} -1}{3} $$
Sum[ 1/Sin[ k Pi/m]^2, {k, 1, m - 1}]
1/3 (-1 + m^2)
if we set e.g. m = 21
, the above doesn't simplify and we need e.g. FullSimplify
m = 21;
FullSimplify @ Sum[ 1/Sin[ k Pi/m]^2, {k, 1, m - 1}]
440/3
The larger one sets m
, the more time it takes.
Here is another example where we need no simplifications and the result is obtained with help of built-in rewrite rules :
ex 2.
$$\sum_{\small{k = 0}}^{\small{k = m-1}} \; \cos(a + k b) = \frac{\sin(\frac{n b}{2})}{\sin(\frac{b}{2})} \cos(\frac{2 a+(n-1) b}{2})$$
(Sum[ Cos[ a + k b], {k, 0, m - 1}] -
Sin[ (m b)/2]/Sin[ b/2] Cos[ (2 a + (m - 1) b)/2]) /. m -> 137
0
but if we make no substitution we'll need e.g. Simplify
Simplify[ (Sum[ Cos[ a + k b], {k, 0, m - 1}] -
Sin[ (m b)/2]/Sin[ b/2] Cos[ (2 a + (m - 1) b)/2]) ]
0
It works even if we add the option Simplify[ expr, Trig -> False]
.
ex 3.
$$\sum_{\small{k = 0}}^{\small{k = n-2}} \; \tan(\frac{\pi}{2^{n - k}}) = \cot(\frac{\pi}{2^{n}})$$
Here we define e.g.
f[n_] := Sum[2^k Tan[Pi/2^(n - k)], {k, 0, n - 2}] - Cot[Pi/2^n]
In this case the following functions work equally well if we set e.g. n == 15
:
Together[ f[n], Trig -> True] == Simplify[ f[n]] == TrigReduce[ f[n]] == 0
True
however for larger n
we can easily see advantages of various approaches, e.g. for n == 21
we observe that Together[ expr, Trig->True]
is the best, while Simplify
cannot tackle such an expression :
TrigReduce[ f[21]] // AbsoluteTiming
Together[f[21], Trig -> True] // AbsoluteTiming
{0.1404000, 0}
{0.0312000, 0}
while
Simplify[f[21]] // AbsoluteTiming
returns
If we evaluate e.g. f[n]
, where we haven't assigned to n
any value, we get ComplexInfinity
.
At last we consider two simple examples :
ex 4.
expr1 = -1 + 50 Cos[x]^2 - 400 Cos[x]^4 + 1120 Cos[x]^6 - 1280 Cos[x]^8;
expr2 = -512 Cos[x]^10 + Cos[10 x];
In this case one can use
TrigReduce[ expr1 - expr2]
0
as well as one of these
Together[ expr1 - expr2, Trig -> True]
or
Apart[ expr1 - expr2, Trig -> True]
Let's consider your example :
ex 5.
exprA = - 1/15 Cos[4 x] + (1/15 + 6) Cos[x] + 11 Sin[x];
exprB = 1/30 ( 182 Cos[x] - 5 Cos[x] Cos[3 x] + 3 Cos[x] Cos[5 x] + 330 Sin[x]
+ 5 Sin[x] Sin[3 x] + 3 Sin[x] Sin[5 x] );
compare various ways (TrigReduce
and TrigExpand
are optimal here) :
TrigReduce[exprA - exprB] // AbsoluteTiming
TrigExpand[exprA - exprB] // AbsoluteTiming
{0., 0}
{0., 0}
but FullSimplify
and TrigFactor
also work, though are a bit slower :
TrigFactor[exprA - exprB] // AbsoluteTiming
FullSimplify[exprA - exprB] // AbsoluteTiming
{0.0156000, 0}
{0.0312000, 0}
Thus using TrigReduce
seems to be more appropriate for this type of trigonometric expressions. We can observe that timing for is a multiple of 0.0156000
for TrigFactor
and FullSimplify
.