22

Bug introduced in 8.0 or earlier and persisting through 13.2 or later


There is a rather simple integral ($K_0$ is the 0-th order MacDonald function) $$\int_0^\infty e^{-x \cosh\xi}\, d\xi = K_0(x)$$ which mathematica cannot solve. This even though the documentation claims that Integrate can give results in terms of many special functions. In fact it can solve the integral obtained by substituting $r=\cosh \xi$, $$\int_1^\infty \frac{e^{-x r}}{\sqrt{r^2-1}}\,dr=K_0(x).$$ In fact it also failed in solving the more general integral $$\int_0^\infty e^{-x \cosh\xi} \cosh(\alpha \xi)\, d\xi = K_\alpha(x).$$

I am using "8.0 for Mac OS X x86 (64-bit) (October 5, 2011)". Are there more recent or older versions of Mathematica which can solve this class of integrals?


Edit:

I want to stress that this is not an arbitrary integral but can be thought of as a definition of $K_0$ (the corresponding integral $\int_0^{2\pi} \!e^{i x \cos \xi}\,d\xi$ for $J_0$ mathematica handles very well). I am just curious how it can happen that a system as developed as Mathematica cannot handle this "elementary" integral.

Here is the Mathematica code for those who want to test:

Integrate[Exp[-x Cosh[ξ]],{ξ,0,Infinity}]

Now I found a related integral which indeed is a bug in mathematica. If you try to evaluate ($x \in \mathbb{R}$) $$\int_0^\infty \cos(x \sinh \xi)\,d\xi = K_0(|x|)$$ then Mathematica claims that the integral diverges.

bmf
  • 15,157
  • 2
  • 26
  • 63
Fabian
  • 1,424
  • 9
  • 17
  • 1
    The integration is with respect to \[Xi] – b.gates.you.know.what Apr 25 '12 at 08:57
  • Oh, my mistake. – Fabian Apr 25 '12 at 09:07
  • I've tested with older versions on Linux now (the oldest we have here is 5.2), and (not surprisingly) they couldn't solve it either. I can't test newer versions because we don't have those. – celtschk Apr 25 '12 at 09:22
  • @Fabian It is known that Integrate behaves improperly, look e.g. here http://mathematica.stackexchange.com/questions/3568/bug-in-integrate-for-mathematica/3571#3571 +1 for perspicacity. – Artes Apr 25 '12 at 09:40
  • 2
    Please include the MMA code for the rest of us to test easily... – tkott Apr 25 '12 at 10:05
  • 3
    @Artes: However this is not an example of Integrate behaving improperly, but an example of Integrate not being able to calculate a given integral. Which may be unfortunate, but as long as it doesn't give an incorrect result, is neither improper behaviour nor a bug. – celtschk Apr 25 '12 at 10:31
  • @celtschk I agree, but the first, since one asks whether Integrate is buggy I presented an example; the second, since it computes the same integral after a pretty simple transformation, if find its behavior not quite proper. – Artes Apr 25 '12 at 11:03
  • @celtschk It is true though that based on what other integrals the system can do, one could easily expect Mma to do this one as well (unless I'm missing something, e.g. a special condition that has to be met for this to be easy to calculate...). So it might very well be a 'bug' in the sense that the people who worked on this part of Integrate intended it to work, but something is going wrong internally. Or maybe not. We'll never know. Of course you're right that it's not the kind of bug that can bite users. – Szabolcs Apr 25 '12 at 13:05
  • @Szabolcs: the condition which has to be met is $\operatorname{Re} x > 0$. However, I do not believe that it is because of this condition that the integral cannot be performed. Mathematica also does not produce a result for the specific case $x=1$. – Fabian Apr 25 '12 at 13:08
  • 1
    @Artes Integrate is one of the most difficult to get right functions, especially when it comes to definite integration. You'll find similar problems in other systems as well. – Szabolcs Apr 25 '12 at 13:09
  • 1
    @Fabian You probably know it, but Integrate[Exp[-x r ]/Sqrt[r^2 - 1], {r, 1, \[Infinity]}] produces in ver.8 ConditionalExpression[BesselK[0, x], Re[x] > 0], while in ver. 7 If[Re[x] > 0, BesselK[0, x], Integrate[E^(-r x)/Sqrt[-1 + r^2], {r, 1, \[Infinity]}, Assumptions -> Re[x] <= 0]] just because ConditionalExpression is new in ver.8. I believe when WRI updated Integrate they did something wrong what you could find in the post which I included earlier. – Artes Apr 25 '12 at 13:59
  • @Szabolcs Yes, though DSolve is even more difficult, Reduce probably too. – Artes Apr 25 '12 at 14:03
  • 4
    Send in this integral as a suggestion to wolfram technical support. The email is support@wolfram.com.

    Let then know you are suggesting that this integral should evaluate to the value you suggested here.

    – Searke Apr 25 '12 at 14:52
  • @Searke: thank you for the suggestion, I will do so. – Fabian Apr 25 '12 at 16:12
  • Possibly related: http://mathematica.stackexchange.com/q/2740/12 – Szabolcs Apr 25 '12 at 16:26

2 Answers2

24

An experimental internal function Integrate`InverseIntegrate helps here, although it's intended more for integrands involving logs. This is what it returns in the development version:

Integrate`InverseIntegrate[Exp[-x Cosh[t]], {t, 0, Infinity}, Assumptions -> Re[x] > 0]
(*  BesselK[0, x]  *)
rm -rf
  • 88,781
  • 21
  • 293
  • 472
Bhuvanesh
  • 440
  • 3
  • 6
  • 2
    This code returns $Failed on my machine (version 8.0.4, Windows 7). – Verbeia Jun 13 '12 at 06:28
  • 1
    Sorry, I should have tested it. This is what it returns in the development version.
    `In[1]:= Integrate\`InverseIntegrate[Exp[-x Cosh[t]], {t, 0, Infinity}, Assumptions -> Re[x] > 0]
    
    Out[1]= BesselK[0, x]`
    
    – Bhuvanesh Jun 20 '12 at 21:03
  • Could you tell me how could I find the file related to "Integrate`InverseIntegrate"? – WateSoyan Apr 12 '15 at 12:58
  • 1
    Integrate`InverseIntegrate is included as part of Mathematica versions 9.0+. It is not possible to load a file and make it work in earlier versions. – Bhuvanesh Apr 14 '15 at 19:55
10

For those who are interested, what Integrate`InverseIntegrate seems to do is to try various substitutions of the form u == g[x], where g[x] is an expression in the integrand. Here is a function that can make such substitutions in an integral.

ClearAll[sub];
SetAttributes[sub, HoldFirst];
sub[Integrate[f_, {x_, a_, b_}, opts___?OptionQ], g_] := 
 Module[{xx, u, inv},
  inv = Simplify[
    InverseFunction[Function[xx, ConditionalExpression[g /. x -> xx, a < xx < b]]][u]
    ];
  Integrate[(f /. x -> inv) * D[inv, u],
    {u,
     Limit[g, x -> 0, Direction -> -1],
     Limit[g, x -> Infinity, Direction -> 1]},
    opts] /; FreeQ[inv, InverseFunction]
  ]

Applied to a couple of the OP's examples:

sub[Integrate[Exp[-x Cosh[r]], {r, 0, Infinity}, Assumptions -> Re[x] > 0], Cosh[r]]
(*  BesselK[0, x]  *)

sub[Integrate[Cos[-x Sinh[t]], {t, 0, Infinity}, Assumptions -> x ∈ Reals], Sinh[t]]
(*  BesselK[0, Abs[x]]  *)

The integrand Exp[-x Cosh[t]] Cosh[a t] seems beyond the reach of this sort of stratagem.

Michael E2
  • 235,386
  • 17
  • 334
  • 747
  • I tested your code (mma 11.0.1): the second expression is evaluated as in your case but the first gives: https://imgur.com/gallery/itE7M. Also the Integral mentioned in http://mathematica.stackexchange.com/questions/128340/integration-with-bessel-function is this way not solvable. – mrz Oct 11 '16 at 12:27
  • @mrz Thanks! I fixed the typo & the code should work. -- And, no, it's no help to your other integral (but that's sort of obvious, since this answer is just showing what Integrate`InverseIntegrate does, and it was already clear that InverseIntegrate didn't work). – Michael E2 Oct 11 '16 at 12:55
  • 1
    @MichaelE2 it might be worthwhile to add that Integrate[Exp[-x Cosh[t]], {t, 0, Infinity}, Assumptions -> Re[x] > 0] fails even in V13.0.0. (+1) for the very nice manual approach for substitutions. – bmf Apr 14 '22 at 04:05