# Slow integration of trigonometric expression speeds up after TrigReduce

I'm trying to integrate a trigonometric expression as

Integrate[Cos[2 t] Cos[3 t] Cos[4 t] Cos[5 t] Sin[2 t] Sin[3 t], {t, 0, 2 Pi}]


The final results is correct (which is 0), but it takes a very long time (about 1100 seconds), and it returns some output messages such as:

N::meprec :  Internal precision limit $MaxExtraPrecision = 50. reached while evaluating -\[Pi]+10 ArcTan[Sqrt[10-2 Power[<<2>>]]/(5+Sqrt)]. N::meprec : Internal precision limit$MaxExtraPrecision = 50. reached while evaluating -\[Pi]+10 ArcTan[Sqrt[10-2 Power[<<2>>]]/(5+Sqrt)].
LessEqual::meprec :  Internal precision limit \$MaxExtraPrecision = 50. reached while evaluating -(1/5) Abs[-\[Pi]+10 ArcTan[Sqrt[Plus[<<2>>]]/Plus[<<2>>]]].
PossibleZeroQ::ztest1 :  Unable to decide whether numeric quantity -(\[Pi]/5)+I (Log[1-(I Sqrt[Plus[<<2>>]])/Plus[<<2>>]]-Log[1+I Power[<<2>>] Power[<<2>>]]) is equal to zero. Assuming it is.


In the end, I used TrigReduce to process this expression first then Integrate it (and got the result very fast).

But I am curious why the original version takes so long.

• You're asking about internal workings. Try Trace[Integrate[ Cos[2 t] Cos[3 t] Cos[4 t] Cos[5 t] Sin[2 t] Sin[3 t], {t, 0, 2 Pi}], _PossibleZeroQ, TraceInternal -> True] to see what's causing the warning. Determining whether something is zero can be difficult. It may or may not have to do with the problem. Aug 9 at 14:59
• @Michael E2 the TraceInternal output is really hard to read, and I'm not sure I can find the reason from it, anyway thanks for the help (^_^) Aug 9 at 15:56

Simplification of the integrand leads to (removable) singularities:

Cos[2 t] Cos[3 t] Cos[4 t] Cos[5 t] Sin[2 t] Sin[3 t] // Simplify
(*  1/16 Csc[5 t] Sin[6 t] Sin[8 t] Sin[10 t]  *)


That leads to checking convergence, which I guess takes a long time.

You can turn off some of the checking, and Integrate[] takes somewhere between 0.2 and 4 seconds, depending on what's been loaded and computed already.

Integrate[
Cos[2 t] Cos[3 t] Cos[4 t] Cos[5 t] Sin[2 t] Sin[3 t],
{t, 0, 2 Pi},
GenerateConditions -> False]
(*  0  *)


You can see that the original Integrate[] obtains the antiderivative fairly quickly and then output stops, from which I inferred it was dealing with the singularities (see How much time should one give Mathematica for an integral evaluation? for some debugging techniques):

Block[{IntegrateQuickLookUpDumpdbgPrintQT = Print},
Integrate[
Cos[2 t] Cos[3 t] Cos[4 t] Cos[5 t] Sin[2 t] Sin[3 t],
{t, 0, 2 Pi}]
]
(* output contains Csc[5 t] Sin[6 t] Sin[8 t] Sin[10 t] *)


I aborted the computation, so I don't know what happens if you wait 1100 seconds....

• Thanks for help (^_^)  Integrate[ Cos[2 t] Cos[3 t] Cos[4 t] Cos[5 t] Sin[2 t] Sin[3 t], {t, 0, 2 Pi}, GenerateConditions -> False]  this code still needs a long time, and I aborted it after a minute wait. The debugging techniques is really helpfull, I think I need to take a good look at it, so that to figure out what happened during the points process Aug 9 at 15:45
• @Ji'anLi You're welcome. I would say that anything that takes 1100 sec. on a modern computer is doing a lot. The answer I linked shows how to get more information, but I would expect the output to be hundreds of pages. Most of the output will be impossible to understand without being familiar with the internal code. I'm not, and I wouldn't look into this any farther. I'd be satisfied with finding the Csc[5 t] factor above and thinking that's leading to difficulties. Aug 9 at 15:59
• @Ji'anLi Also, I'm using V13.1. Integrate[] is updated probably in every new version of Mathematica. If you're using a different version, it might explain why the GenerateConditions -> False` version takes more than a few seconds. Aug 9 at 16:05