Bug introduced in 8.0 or earlier and fixed in 9.0.0

I integrate

Integrate[Exp[I Cos[b - c]] Cos[b], {b, 0, 2 Pi}]

Mathematica gives:

2 I Pi BesselJ[1, 1]

Which is indepedent on $c$. However, the result is NOT independent on $c$.

The numerical value of what Mathematica gives is 0. + 2.76492 I while

NIntegrate[Exp[I Cos[b - 0.5]] Cos[b], {b, 0, 2 Pi}]


1.16655*10^-10 + 2.42645 I

Certainly not the same. If we multiply the value Mathematica gives with $\cos(0.5)$ the result is the same. What is wrong?


2 Answers 2


Looks like a bug that ran off in the development version of Mathematica.

In[1]:= Integrate[Exp[I Cos[b - c]] Cos[b], {b, 0, 2 Pi}]//InputForm

Out[1]//InputForm= (2*I)*Pi*BesselJ[1, 1]*Cos[c]

In[2]:= %/.c->.5

Out[2]= 0. + 2.42645 I
  • 2
    $\begingroup$ @JonasTeuwen he's referring to the fact that the bug no longer shows up in the development version, i.e. a version that hasn't been released to the public, yet. $\endgroup$
    – rcollyer
    Commented Mar 8, 2012 at 19:55
  • 5
    $\begingroup$ Numeric checks like the one you did seem like a good way to go about the checking process. $\endgroup$ Commented Mar 8, 2012 at 20:13
  • 3
    $\begingroup$ Right... That implies that I have to check a few hundred of them with many parameters :-). Of course, any program can have a bug, but it still is very annoying. $\endgroup$
    – JT_NL
    Commented Mar 8, 2012 at 20:17
  • 3
    $\begingroup$ @Rolf Would you prefer that we not comment on bugs? That's the only alternative to what I did, as you are well aware. $\endgroup$ Commented Mar 10, 2012 at 20:43
  • 7
    $\begingroup$ @Daniel I find all the feedback about bugs encouraging. Even though your answer doesn't fix the problem here and now, it is good to see that these problems get paid attention to and that fixes are on the way. I'd appreciate if WRI people kept commenting on bugs in public like this. $\endgroup$
    – Szabolcs
    Commented Mar 11, 2012 at 21:08

This bug appears to have been known for over a year now! See the mathGroup archive


To explain why I consider these bugs to be equivalent, I'll re-write the two integrals using the integration variable x. In the present question, we have $$I_1(c)=\int_0^{2\pi}\exp(i\cos(x-c))\cos x\,dx$$

On the other hand, the MathGroup post I linked here considers the integral $$I_2(c)=\int_{-\pi}^{\pi}\exp(i\cos(x-c))\exp(ix-ic)\,dx$$ where I specialized to the case giving the same Bessel argument in the result. Pulling out the constant factor, using the periodicity of the integrand and making a substitution of variables, one finds $$I_2(c)=e^{-ic}\left[I_1(c)+i\, I_1(c-\frac{\pi}{2})\right]$$

Therefore, if Wolfram fixed the bug in the calculation of $I_2$ but still gets an incorrect result for $I_1$, that fix was itself incorrect. This argument generalizes to integer Bessel indices other than 1 (which is what this question has).

Finally, the question is whether it is a bug fix to return the integrals unevaluated. I would argue that because these are such ubiquitous integrals, Mathematica should definitely know what to do with them. But I may not have all the information as to why this bug is so hard to fix... I just wanted to briefly clarify my thinking in case anyone cares.

  • $\begingroup$ They actually seem to be opposites in some sense, so I doubt it's the same bug. $\endgroup$ Commented Mar 8, 2012 at 22:08
  • $\begingroup$ No - it's the exact same thing. $\endgroup$
    – Jens
    Commented Mar 8, 2012 at 22:11
  • $\begingroup$ Jonas is getting <constant>*<BesselJ> instead of an expected <constant>*<BesselJ><f[otherVariable]>. The MathGroup poster is getting <constant>*<BesselJ><f[otherVariable]> instead of <constant>*<BesselJ>. They may be related, but that's enough to classify them as separate bugs in my book. $\endgroup$ Commented Mar 8, 2012 at 22:21
  • $\begingroup$ The fix to one was to disable it from giving any result. This may be why the other will in a future release give the correct result. But its not as simple one change causing BOTH to give a correct result. $\endgroup$ Commented Mar 9, 2012 at 16:01
  • $\begingroup$ @DanielLichtblau Not sure if you noticed the edit here. Could you comment on this? $\endgroup$ Commented Mar 12, 2012 at 0:10

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.