Symbolic integration bug with Mathematica 7?

January 19th, 2009 | Categories: math software, mathematica | Tags:

Someone at my university reported the following Mathematica 7 bug to me and I thought I would share it with all of you in case someone was interested or could offer insight that we don’t have.  Needless to say this has been reported to Wolfram via the official channels and I am sure that it will be sorted out soon.

If you do

Integrate[k^2 (k^2 - 1)/((k^2 - 1)^2 + x^2)^(3/2), {k, 0, Infinity},Assumptions -> x > 0]

you get

EllipticK[(2*x)/(-I + x)]/(2*Sqrt[-1 - I*x])

Which is complex for all x whereas the integrand is purely real.  As a  particular example let us put x=2.  Evaluating numerically:

NIntegrate[k^2 (k^2 - 1)/((k^2 - 1)^2 + 2^2)^(3/2), {k, 0, Infinity}]

gives

0.706094

But if I plug x=2 into the symbolic result given earlier

N[EllipticK[(2*x)/(-I + x)]/(2*Sqrt[-1 - I*x]) /.x->2]

Then I get

-5.35054*10^-17 + 0.568541 I

Which is obvioulsy incorrect.  Would someone with a copy of Maple 12 mind seeing what that makes of this integral please?  Extra kudos to anyone who can do it by hand!

  1. January 20th, 2009 at 08:21
    Reply | Quote | #1

    Hello,

    As our multi-years research based on a failure prediction oracle named
    the VM machine reveals, unfortunately, as of Jan 20, 2009, the current
    commercial computer algebra systems like Maple 12, Mathematica 7 as well
    as the engineering packages like MATLAB 2008b are really crammed full
    with various types of defects, from crashes to hangs to invalid, often
    mathematically ridiculous answers.

    For your general case, Maple 12 returns sophisticated output

    limit(1/2*(-k*((1+I*x)/(1+x^2))^(1/2)+(-(-1-x^2+k^2+I*k^2*x)/(1+x^2))^(1/2)*((1+x^2-k^2+I*k^2*x)/(1+x^2))^(1/2)*EllipticF(k*((1+I*x)/(1+x^2))^(1/2),(-(-1+x^2+2*I*x)/(1+x^2))^(1/2))+2*PIECEWISE([(-signum(-1+I*x))^(1/2)*infinity*(-(-I*signum((1-I*x)^(1/2)*x))^(1/2)+(I*signum((1-I*x)^(1/2)*x))^(1/2))/(I*signum((1-I*x)^(1/2)*x))^(1/2)/(-I*signum((1-I*x)^(1/2)*x))^(1/2), 0 < (1-I*x)^(1/2)],[0, otherwise])*((1+I*x)/(1+x^2))^(1/2)*(k^4-2*k^2+1+x^2)^(1/2)+2*PIECEWISE([signum(1+I*x)^(1/2)*infinity*(-(I*signum((1+I*x)^(1/2)*x))^(1/2)+(-I*signum((1+I*x)^(1/2)*x))^(1/2))/(-I*signum((1+I*x)^(1/2)*x))^(1/2)/(I*signum((1+I*x)^(1/2)*x))^(1/2), 0 < (1+I*x)^(1/2)],[0, otherwise])*((1+I*x)/(1+x^2))^(1/2)*(k^4-2*k^2+1+x^2)^(1/2)+2*PIECEWISE([(-signum(-1+I*x))^(1/2)*infinity*(-(-I*signum((1-I*x)^(1/2)*x))^(1/2)+(I*signum((1-I*x)^(1/2)*x))^(1/2))/(I*signum((1-I*x)^(1/2)*x))^(1/2)/(-I*signum((1-I*x)^(1/2)*x))^(1/2), 0 < -(1-I*x)^(1/2)],[0, otherwise])*((1+I*x)/(1+x^2))^(1/2)*(k^4-2*k^2+1+x^2)^(1/2)+2*PIECEWISE([signum(1+I*x)^(1/2)*infinity*(-(I*signum((1+I*x)^(1/2)*x))^(1/2)+(-I*signum((1+I*x)^(1/2)*x))^(1/2))/(-I*signum((1+I*x)^(1/2)*x))^(1/2)/(I*signum((1+I*x)^(1/2)*x))^(1/2), 0 int(z^2*(z^2 – 1)/((z^2 – 1)^2 + 4)^(3/2), z= 0..infinity);

    1/10*5^(3/4)*EllipticK(1/10*(50+10*5^(1/2))^(1/2))

    > evalf(%);

    .7060937855

    > evalf(Int(z^2*(z^2 – 1)/((z^2 – 1)^2 + 4)^(3/2), z=0..infinity));

    .7060937855

    Cheers,

    Vladimir Bondarenko
    CEO, Mathematical Director

    Cyber Tester Ltd.
    http://www.cybertester.com

    phone: +380-953-866-894
    fax: +380-652-668-356

    3/4 Zadorozhny Str, Simferopol
    Crimea 95047, Ukraine

  2. VolMike
    January 20th, 2009 at 09:12
    Reply | Quote | #2

    Maple 12 computes both symbolic and numeric integrals well.

    > t:=int(k^2* (k^2 – 1)/((k^2 – 1)^2 + x^2)^(3/2),k=0..infinity) assuming x>0; # compute the integral symbolically

    t := 1/2*1/(1+x^2)^(1/4)*EllipticK(1/2*2^(1/2)*(((1+x^2)^(1/2)+1)/(1+x^2)^(1/2))^(1/2))

    > evalf(subs(x=2,t)); # substitute x=2 in symbolic result

    .7060937851

    > int(k^2* (k^2 – 1)/((k^2 – 1)^2 + 2^2)^(3/2),k=0.0..infinity); # compute integral numerically at x=2

    .7060937855

  3. Mike Croucher
    January 20th, 2009 at 11:44
    Reply | Quote | #3

    @VolMike Thanks for that – I really must get a copy of Maple it seems.

    @Vladimir – Thanks also but I wonder why the result you get is so large? Did you include the assumption that x>0?

  4. January 20th, 2009 at 15:30
    Reply | Quote | #4

    “@Vladimir – Thanks also but I wonder why the result you get is so large? Did you include the assumption that x>0?”

    Oooops, woe unto me, there was a typo. My input was “assuming k>0″ while
    it should be “assuming x>0″.

    I confirm the result by VolMike.

    In the given case Maple 12 beats Mathematica 7.

    Why my typo occurred – and I did not spot it?

    Maybe, it’s because of the following. To tell the truth, by and large, as
    long as it is about integration, I got accustomed to see that Mathematica
    7 beats Maple 12.

    But in this case, Maplesoft got even Wolfram Research :)

  5. Mike Croucher
    January 20th, 2009 at 15:48
    Reply | Quote | #5

    No problem Vladimir – we all make mistakes ;)
    Thanks again for your contribution.

  6. Robert Spero
    January 20th, 2009 at 20:08
    Reply | Quote | #6

    Not surprisingly, Mable-based Matlab 7.02 gives the same (correct) result as Maple 12, while mupad based Matlab R2008b returns “Explicit integral could not be found.”

  7. Mike Croucher
    January 21st, 2009 at 16:36
    Reply | Quote | #7

    Hi Robert

    Thanks for the feedback. In this case I think Mupad/MATLAB wins over Mathematica. I’d rather be told that it can’t find a result than be given an incorrect one. Not all gaffs are as obviously wrong as this one.

    Cheers,
    Mike

  8. VolMike
    January 22nd, 2009 at 15:58
    Reply | Quote | #8

    The simple way to avoid (decrease the probability of) such errors is comparing results in CAS’s based on different symbolic (numeric) engines.

Comments are closed.