1. 2012
    Oct
    03

    Your computer algebra system is out to get you!

    OK, maybe it’s not what you think, the CAS‘s of the world are not going to rise up and enslave us :-P (Not yet, anyway.) But it is always a good idea to view their results with a healthy dose of skepticism, because like any computer program, they have bugs, and every once in a while one can actually mess up your calculation.

    Here’s my example:

    $$\int_0^{2\pi} \cos x\,e^{ik\cos(x - y)}\udc x$$

    Plug this into Mathematica 8.0 and it will tell you that the integral is equal to \(2\pi i J_1(k)\), where \(J_1\) is a Bessel function of the first kind:

    In[1]  := Integrate[Cos[x] Exp[I k Cos[x - y]], {x, 0, 2 Pi}]
    Out[1] := ConditionalExpression[2 I \[Pi] BesselJ[1, k], k \[Element] Reals]
    

    But it’s not! If you shift the integration variable \(x\to x + y\), Mathematica tips its hand and tells you the real answer, \(2\pi i J_1(k)\cos y\):

    In[2]  := Integrate[Cos[x + y] Exp[I k Cos[x]], {x, 0, 2 Pi}]
    Out[2] := 2 Pi I BesselJ[1, k] Cos[y]
    

    You can also do …