# Symbolic integration of SphericalBesselJ

Backslide introduced in v10 and persisting through v10.3.1.

Consider the following integral

AbsoluteTiming[
Integrate[k^(n) SphericalBesselJ[l, R*k], {k, 0, ∞},
Assumptions -> {l > 0, R > 0}]]


On my machine Mathematica 10.3.1 (Linux version) can do it in roughly 20 seconds

{19.7088,
ConditionalExpression[(
Sqrt[π] 2^(n - 1) R^(-n - 1) Gamma[1/2 (l + n + 1)])/Gamma[
1/2 (l - n + 2)], Re(n) < 1 ∧ l + Re(n) > -1]}


Since for my purpose n is an integer, one would think that specifying this condition in the assumptions will make it easier for Mathematica to solve the integral. Right? Apparently not! For

AbsoluteTiming[
Integrate[k^(n) SphericalBesselJ[l, R*k], {k, 0, ∞},
Assumptions -> {l > 0, R > 0, n ∈ Integers}]]


I obtained

{69.0534,
Integrate[k^n SphericalBesselJ[l,k R], {k, 0,  ∞},
Assumptions -> {l > 0, R > 0, n ∈ \!$$\* TagBox["\[DoubleStruckCapitalZ]", Function[{}, Integers]]$$}]}


i.e. now Mathematica failed to solve my integral. Is this a bug or I'm missing something about Assumptions for symbolic integration?

EDIT (3.01.2016): According to WRI this is not a bug/backslide but merely a timing issue. As pointed out by @bbgodfrey, one can avoid this behavior by using Integrate together with TimeConstrained.

• So should I add the bug tag and report this to WRI? To me, this behavior doesn't seem to be quite ok... – vsht Dec 28 '15 at 18:32
• I think this should be called a backslide. In v9.0.1 both of the 2 samples give the correct result (The latter is still slower though ): i.stack.imgur.com/SYKrv.png – xzczd Dec 29 '15 at 12:11
• Ok, I've just sent a bug report to WRI with a link to this question. Let's see what they will say. – vsht Dec 29 '15 at 15:20
• It's now CASE:3500395, although the backslide has not been confirmed yet. – vsht Dec 29 '15 at 21:03
• @vsht I am not sure that timing out a bit sooner constitutes a bug. Please see the most recent edit to my answer. Best wishes. – bbgodfrey Dec 30 '15 at 10:40

There are many possible variants of Assumptions here, including

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞},
Assumptions -> {l > 0, R > 0, n ∈ Reals}]]
(* {4.00979075897103, ConditionalExpression[
(2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2],
n < 1 && l + n > -1]} *)


or

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞},
Assumptions -> {l > 0, R > 0, -1 - l < n < 1}]]
(* {11.002235487576527,
(2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2]} *)


or

AbsoluteTiming[Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞},
Assumptions -> {l > 0, R > 0, (n | l) ∈ Integers}]]
(* {4.107987620241559, ConditionalExpression[
(2^(-1 + n)*Sqrt[Pi]*R^(-1 - n)*Gamma[(1 + l + n)/2])/Gamma[(2 + l - n)/2],
n <= 0 && l + n >= 0]} *)


All works sometimes and not others. The latter two seem faster and more reliable, however.

A work-around is to run the same Integrate two or three times in succession. I have posted a question about this strange behavior, in the hope of gaining more insight.

Solution

From comments made on the question referenced above, it has become apparent that Integrate times out after 60 seconds when attempting to do many of the integrals above when called the first time. The solution is to give it more time. For instance,

TimeConstrained[
Integrate[k^n SphericalBesselJ[l, R*k], {k, 0, ∞},
Assumptions -> {l > 0, R > 0, n ∈ Integers}], 120] // AbsoluteTiming


• Strange, your first example fails for me in the same way as when n is an integer. Do you also have version 10.3.1? – vsht Dec 28 '15 at 18:30
• @vsht Stranger yet, with a fresh session of Mathematica (10.3.0 on Windows 10, 64 bit) which instances return unevaluated depends on the order in which these instances are evaluated! I need to give this more thought. – bbgodfrey Dec 28 '15 at 20:33
• @vsht I ran many different sets of Assumptions and found that the order in which they are run, as well as how many times a particular one is run, affects which return evaluated. I have added a not particularly satisfying work-around to my answer and also posted a new question illustrating some of the erratic results. – bbgodfrey Dec 29 '15 at 8:59

The problem arises in trying to determine the conditions for which the integral is defined. Using GenerateConditions -> False provides a solution with the additional assumption and is much faster.

AbsoluteTiming[
Assuming[{l > 0, R > 0, Element[n, Integers]},
Integrate[
k^n SphericalBesselJ[l, R*k],
{k, 0, ∞}, GenerateConditions -> False]]]

(*  {0.364262, (2^(-1 + n)*Sqrt[Pi]*
R^(-1 - n)*Gamma[
(1/2)*(1 + l + n)])/
Gamma[(1/2)*(2 + l - n)]}  *)

• True, but I actually find GenerateConditions quite useful, since when working with special functions one often gets results that are correct only in a limited range of the input parameters. – vsht Dec 28 '15 at 18:32
• @vsht - I agree in general that GenerateConditions -> True is preferred; however, in this specific case (i.e., including the additional assumption) the choice was between GenerateConditions -> False and an unevaluated expression. – Bob Hanlon Dec 28 '15 at 19:02