# Integrate yields no answer and crashes kernel

I encountered a problem with Mathematica. The simple command is:

Integrate[
q^2/(q^2 + ks^2) (1 - (1/τ^2 - c^2 q^2) τ^2)/
(1 + 2 (ω^2 - (1/τ^2 - c^2 q^2)) τ^2 +
(ω^2 + (1/τ^2 - c^2 q^2))^2 τ^4),
{q, 0, Infinity},
Assumptions -> {ks > 0, ω > 0, τ > 0, c > 0}]


When I launch this, Mathematica shows "running" for a few seconds and then it produces "beep" sound. No result is shown and all variables are cleared (i.e. the kernel crashed). The funny thing is, when I choose a finite upper limit (I started with 1/c tau instead of infinity), it produces an answer. However, when I rewrite the upper limit to infinity, it crashes the kernel (although the infinity poses no problem for the convergence, as the function falls quickly enough, moreover, the result of integration is usually much simpler with infinite limit than with a finite one).

I run Mathematica 11.1 under Windows 10. I have intel 4790K, nvidia geforce 970 gtx and 16GB of RAM. Isn't that enough to keep kernel from crashing? What should I do to obtain the result (apart from doing it myself via contour integration which I wanted to avoid)? Thank you.

P.S.: I tried that even right after fresh restart of my PC, closing/reopening Mathematica etc. Always the same behaviour.

P.S.2: just for the fun, I usually calculate definite integrals with infinite bounds via contour integration and find out that the actual result is much much simpler than what Mathematica shows (which can be simplified after all). Could the reason be that Mathematica runs out of memory while thinking about showing me that output that takes (for example) 10^5 rows? I'm just speculating.

I run the integrate with semicolon, still crashing.

EDIT: I managed to get it running by substituting alpha = ctau and beta = omegatau. However, this yields an answer with a lot of i's in it a indeed, once I plug in some numerical values, the result has a nonzero imaginary part, which is just wrong - no complex numbers should be involved at all.

• Works for me in M8 and M11.0.1, Windows 10, Intel 6700k 1080 gtx, 32 GB – Bill Watts Nov 23 '17 at 1:01
• The test your P.S.2 question, rerun the code with a semicolon at the end of it. Then the output will be suppressed, and it will not think about how to display it. – QuantumDot Nov 23 '17 at 1:23
• Also runs fine with Version 11.2 on Windows 10. – bbgodfrey Nov 23 '17 at 3:08
• Still crashing kernel even with a semicolon to suppress the output. Can someone copy/paste the output for me please? :O – user16320 Nov 23 '17 at 7:01
• I get a kernel crash when I run this code on V11.2.0 running under OS X 10.10.2. – m_goldberg Nov 23 '17 at 12:08

With Mathematica Version 8.0, I get good result, with no imaginary part.

integrand =
q^2/(q^2 + ks^2) (1 - (1/τ^2 - c^2 q^2) τ^2)/(1 +
2 (ω^2 - (1/τ^2 -
c^2 q^2)) τ^2 + (ω^2 + (1/τ^2 -
c^2 q^2))^2 τ^4);

fs = FullSimplify[
integrand, {ks > 0, ω > 0, τ > 0, c > 0}]

(*    (c^2 q^4)/((ks^2 +
q^2) (4 ω^2 + τ^2 (-c^2 q^2 + ω^2)^2))    *)

int = Integrate[fs, {q, 0, Infinity},
Assumptions -> {ks > 0, ω > 0, τ > 0, c > 0}]

(*    (π (4 c^3 ks^3 τ^(3/2)
Sqrt[-τ + (
2 I)/ω] + ω (4 + τ^2 ω^2) (2 +
I τ ω +
I Sqrt[-2 I - τ ω] Sqrt[2 I - τ ω]) +
c^2 ks^2 τ (τ ω (4 + I τ ω +
I Sqrt[-2 I - τ ω] Sqrt[
2 I - τ ω]) -
2 (2 I +
Sqrt[-2 I - τ ω] Sqrt[
2 I - τ ω]))))/(8 c τ^(3/2)
Sqrt[-τ + (
2 I)/ω] (4 ω^2 + τ^2 (c^2 ks^2 + \
ω^2)^2))    *)

ceRe = FullSimplify[
ComplexExpand[Re[int],
TargetFunctions -> {Re, Im}], {ks > 0, ω > 0, τ > 0,
c > 0}]

(*    (π (4 c^3 ks^3 τ^2 (τ^2 + 4/ω^2)^(1/4) +
2 Sqrt[τ/(
2 + (2 τ ω)/Sqrt[
4 + τ^2 ω^2])] (ω (4 + τ^2 ω^2) \
(τ ω + Sqrt[4 + τ^2 ω^2]) +
c^2 ks^2 τ (-4 + τ ω (τ ω + Sqrt[
4 + τ^2 ω^2])))))/(8 c τ^2 (τ^2 +
4/ω^2)^(
1/4) (4 ω^2 + τ^2 (c^2 ks^2 + ω^2)^2))    *)


Imaginary part is zero.

\$Version

(* "11.2.0 for Mac OS X x86 (64-bit) (September 11, 2017)" *)


Simplify the expression prior to integration.

expr = q^2/(q^2 + ks^2) (1 - (1/τ^2 - c^2 q^2) τ^2)/(1 +
2 (ω^2 - (1/τ^2 -
c^2 q^2)) τ^2 + (ω^2 + (1/τ^2 -
c^2 q^2))^2 τ^4) // Simplify

(* (c^2*q^4)/((ks^2 + q^2)*(c^4*q^4*τ^2 + 4*ω^2 -
2*c^2*q^2*τ^2*ω^2 + τ^2*ω^4)) *)


Use Assuming so that the assumptions are used by all functions that take assumptions.

Assuming[{ks > 0, ω > 0, τ > 0, c > 0},
Integrate[expr, {q, 0, Infinity}] //
ComplexExpand[#, TargetFunctions -> {Re, Im}] & // Simplify]

(* (Pi*(τ^2*Sqrt[ω]*(4 + τ^2*ω^2)^(1/4)*
(c^2*
ks^2*(-4 + τ^2*ω^2) + ω^2*(4 + \
τ^2*ω^2))*
Cos[(1/2)*ArcTan[2/(τ*ω)]] +
2*(c^3*ks^3*Sqrt[τ^5*(4 + τ^2*ω^2)] +
τ*ω^(3/2)*(4 + τ^2*ω^2)^(1/4)*
(4 + 2*c^2*ks^2*τ^2 + τ^2*ω^2)*
Sin[(1/2)*ArcTan[2/(τ*ω)]])))/
(4*c*τ^(5/2)*Sqrt[4 + τ^2*ω^2]*(c^4*ks^4*τ^2 +
4*ω^2 + 2*c^2*ks^2*τ^2*ω^2 + τ^2*ω^4)) *)

• Behaviour is still the same - the simplified integrant is nice, the Integrate routine just doesn't like it. – user16320 Nov 23 '17 at 16:43

Too long for comment. The output in version 11.2 on Windows 10 is $$\frac{\pi \left(4 c^3 \text{ks}^3 \tau ^2 \sqrt{-\tau \omega -2 i} \sqrt{-\tau \omega +2 i}+c^2 \text{ks}^2 \tau \omega \left(i \tau ^{5/2} \omega ^{3/2} \left(\sqrt{-\tau \omega -2 i}-\sqrt{-\tau \omega +2 i}\right)+4 \tau ^{3/2} \sqrt{\omega (-\tau \omega +2 i)}+4 \tau \omega \sqrt{-\frac{\tau (\tau \omega +2 i)}{\omega }}+4 i \sqrt{\frac{\tau (-\tau \omega +2 i)}{\omega }}-4 i \sqrt{-\frac{\tau (\tau \omega +2 i)}{\omega }}\right)+\omega ^2 \left(\tau ^2 \omega ^2+4\right) \left(-i \tau ^{3/2} \sqrt{\omega (-\tau \omega +2 i)}+i \tau \omega \sqrt{-\frac{\tau (\tau \omega +2 i)}{\omega }}+2 \sqrt{\frac{\tau (-\tau \omega +2 i)}{\omega }}+2 \sqrt{-\frac{\tau (\tau \omega +2 i)}{\omega }}\right)\right)}{8 c \tau ^2 \sqrt{-\tau \omega -2 i} \sqrt{-\tau \omega +2 i} \left(c^4 \text{ks}^4 \tau ^2+2 c^2 \text{ks}^2 \tau ^2 \omega ^2+\tau ^2 \omega ^4+4 \omega ^2\right)}$$

(π (4 c^3 ks^3 τ^2 Sqrt[-2 I - τ ω] Sqrt[
2 I - τ ω] + ω^2 (4 + τ^2 ω^2) \
(2 Sqrt[(τ (2 I - τ ω))/ω] -
I τ^(3/2) Sqrt[ω (2 I - τ ω)] +
2 Sqrt[-((τ (2 I + τ ω))/ω)] +
I τ ω Sqrt[-((τ (2 I + τ ω))/\
ω)]) +
c^2 ks^2 τ ω (4 I Sqrt[(τ (2 I - τ \
ω))/ω] +
4 τ^(3/2) Sqrt[ω (2 I - τ ω)] -
4 I Sqrt[-((τ (2 I + τ ω))/ω)] +
4 τ ω Sqrt[-((τ (2 I + τ ω))/\
ω)] +
I τ^(5/2) ω^(
3/2) (Sqrt[-2 I - τ ω] - Sqrt[
2 I - τ ω]))))/(8 c τ^2 Sqrt[-2 I - \
τ ω] Sqrt[
2 I - τ ω] (c^4 ks^4 τ^2 + 4 ω^2 +
2 c^2 ks^2 τ^2 ω^2 + τ^2 ω^4))


Addition 2. In fact, the imaginary part is zero up to

FullSimplify[ ComplexExpand[ Im[(π (4 c^3 ks^3 τ^2
Sqrt[-2 I - τ ω] Sqrt[
2 I - τ ω] + ω^2 (4 + τ^2 \
ω^2) (2 Sqrt[(τ (2 I - τ ω))/ω] -
I τ^(3/2) Sqrt[ω (2 I - τ ω)] +
2 Sqrt[-((τ (2 I + τ ω))/ω)] +
I τ ω Sqrt[-((τ (2 I + τ ω))/\
ω)]) + c^2 ks^2 τ ω (4 I Sqrt[(τ (2 I - τ \
ω))/ω] +  4 τ^(3/2) Sqrt[ω (2 I - τ ω)] -
4 I Sqrt[-((τ (2 I + τ ω))/ω)] +
4 τ ω Sqrt[-((τ (2 I + τ ω))/\
ω)] +
I τ^(5/2) ω^(
3/2) (Sqrt[-2 I - τ ω] - Sqrt[
2 I - τ ω]))))/(8 c τ^2 Sqrt[-2 I - \
τ ω] Sqrt[
2 I - τ ω] (c^4 ks^4 τ^2 + 4 ω^2 +
2 c^2 ks^2 τ^2 ω^2 + τ^2 ω^4))],
TargetFunctions -> {Re, Im}], {ks > 0, ω > 0, τ > 0, c > 0}]


0

• Thank you. Would you paste a code of it, please, so I can copy it? – user16320 Nov 23 '17 at 8:25
• @user16320: Yes, I added that as input form. – user64494 Nov 23 '17 at 8:51