5
$\begingroup$

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.

$\endgroup$
10
  • $\begingroup$ So should I add the bug tag and report this to WRI? To me, this behavior doesn't seem to be quite ok... $\endgroup$
    – vsht
    Commented Dec 28, 2015 at 18:32
  • $\begingroup$ 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.sstatic.net/SYKrv.png $\endgroup$
    – xzczd
    Commented Dec 29, 2015 at 12:11
  • $\begingroup$ Ok, I've just sent a bug report to WRI with a link to this question. Let's see what they will say. $\endgroup$
    – vsht
    Commented Dec 29, 2015 at 15:20
  • $\begingroup$ It's now CASE:3500395, although the backslide has not been confirmed yet. $\endgroup$
    – vsht
    Commented Dec 29, 2015 at 21:03
  • $\begingroup$ @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. $\endgroup$
    – bbgodfrey
    Commented Dec 30, 2015 at 10:40

2 Answers 2

3
$\begingroup$

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.

Addendum

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

returns with the correct answer after about 70 seconds.

$\endgroup$
3
  • 2
    $\begingroup$ 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? $\endgroup$
    – vsht
    Commented Dec 28, 2015 at 18:30
  • $\begingroup$ @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. $\endgroup$
    – bbgodfrey
    Commented Dec 28, 2015 at 20:33
  • $\begingroup$ @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. $\endgroup$
    – bbgodfrey
    Commented Dec 29, 2015 at 8:59
4
$\begingroup$

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)]}  *)
$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$
    – vsht
    Commented Dec 28, 2015 at 18:32
  • $\begingroup$ @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. $\endgroup$
    – Bob Hanlon
    Commented Dec 28, 2015 at 19:02

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.