I encountered following situation, this command integrates successfully:

Integrate[E^(-r/2) - E^(-(1/2) r (1 - Cos[f - fp]^2)), {fp, 0, 2*Pi}]

and gives

$-2 e^{-r/2}\pi(-1 + e^{r/4} BesselI[0, r/4])$

while this command fails:

Integrate[E^(-r/2) - E^(-(r/2) + 1/2 r Cos[f - fp]^2), {fp, 0, 2*Pi}]

and is just rewritten as

$\int_0^{2\pi}(e^{-r/2} - e^{-\frac{r}{2} + \frac{1}{2} r Cos[f - fp]^2})dfp$

However, those expressions are exactly the same, the only difference is expanded bracket inside exponent. In fact, I even started doubting myself and decided to check by subtracting integrands from each other:

Simplify[E^(-r/2) -  E^(-(1/2) r (1 - Cos[f - fp]^2)) - (E^(-r/2) -  E^(-(1/2) r + r*Cos[f - fp]^2/2))]

Which predictably yields 0.

Now, my question: Why Mathematica fails to integrate second version? Where is the problem? Did I make an embarrassing error? If problem is in Mathematica, is there a way to predict if simply rewriting expression will let it be solved?

Tested on Mathematica 8.0 and Mathematica 10.0

  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – Michael E2
    Aug 27, 2017 at 21:29
  • $\begingroup$ yes, this is strange. But if you do the indefinite integration, then now both do not integrate and not just the second one. !Mathematica graphics $\endgroup$
    – Nasser
    Aug 27, 2017 at 21:51
  • $\begingroup$ @Nasser That's because 0-order (not sure if using right terminology) modified Bessel function of the first kind in integral representation is an integral with limits from 0 to pi where integrand is Exp(xcos(f)). In first example, Mathematica successfully converts cos^2() into cos() to recover Bessel, but in second case it fails to do so. In fact, it also fails to recover Bessel if I make integrand the following E^(rCos[f - fp]^2). For E^(rCos[- fp]^2) it works again. $\endgroup$
    – M i ech
    Aug 27, 2017 at 22:23
  • $\begingroup$ I think, there must be a typing error. I tested both integrations with MMA Version 8.0 as you did and I get the right answer in both cases. Try and copy and paste your own integrals from this site. $\endgroup$
    – Akku14
    Aug 28, 2017 at 7:25

1 Answer 1


It is an unfortunate fact of life that how you enter an integral can affect how well it is integrated (this is true when using traditional integral tables, too, depending on which template you choose using when your function fits more than one). I can't tell you specifically whats going wrong without spending a lot of time tracing through the code, but evidently the expanded form is matching some template that is taking Integrate in the wrong direction.

As a general rule of thumb, using Simplify before hand will give Integrate a better chance of working. However, it is likely that people can come out with counter examples to that general rule.

  • 3
    $\begingroup$ That happens in calculus class, too! :) $\endgroup$
    – Michael E2
    Aug 30, 2017 at 23:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.