# Integrating a real function I get a complex value, while after variable transformation the result is real. Bug?

I have the following integral:

Integrate[1/Sqrt[0.7 + 0.3*(1 + z)^3], {z, 0, ∞}, Assumptions -> z ∈ Reals]

>> -3.36354 - 3.85013 I


The output is complex, although I used reals in the assumptions and I know that it doesn't make sense.

If I use the variable transformation:

$$z=e^{-t} - 1$$

and now integrate this:

Integrate[-Exp[-t]/Sqrt[(0.7 + 0.3*Exp[-3 t])], {t, 0, -∞}]

>> 3.30508


I am wondering why I get in the first case a complex number, but also why I get the real part also wrong.

In this case I know a variable transformation that can help, but I am wondering about other more complicated cases in which I don't know a transformation.

How can I avoid this problem?

• Try Integrate[1/Sqrt[7/10 + 3/10*(1 + z)^3], z] and check the result Oct 14, 2014 at 15:27
• I get this: $\frac{2 \sqrt{-1} \sqrt{7} \sqrt{(-1)^{5/6} \left(\sqrt{-\frac{3}{7}} (z+1)-1\right)} \sqrt{\sqrt{-\frac{3}{7}} (z+1)+\left(-\frac{3}{7}\right)^{2/3} (z+1)^2+1} F\left(\sin ^{-1}\left(\frac{\sqrt{-i (z+1) \sqrt{-\frac{3}{7}}-(-1)^{5/6}}}{\sqrt{3}}\right)|\sqrt{-1}\right)}{3^{7/12} \sqrt{\frac{3}{10} (z+1)^3+\frac{7}{10}}}$ Oct 14, 2014 at 15:31
• Seems like it might be a bug? Oct 14, 2014 at 17:16
• I tried to drill down to the origin of this bug. Define the integrand f[z_] := 1/Sqrt[7/10 + 3/10 (1 + z)^3], then evaluate the indefinite integral int[z_] = Integrate[f[z], z]. Close inspection reveals that int[z] has a discontinuity that shouldn't be there - e.g. compare int[1.6527048] with int[1.6527049]. If you evaluate ContourPlot[Arg[int[x + I y]], {x, -3, 3}, {y, -3, 3}] it shows the context for this discontinuity. It appears that the wrong result is due to Mathematica jumping between different branches of Arg, or something like that ... Oct 15, 2014 at 11:21
• Note that Integrate[1/Sqrt[7/10 + 3/10*(1 + z)^3], {z,0,Infinity}] does not evaluate to anything. Oct 15, 2014 at 12:20

Although the other answers provide correct values, I prefer that by J.M. since it touches the essence of the issue, nonetheless I'm going to provide an exact result with a bit of desirable explanation, therefore it is crucial to mention at first one of the basic elliptic integrals: $$\int_{\infty}^{x}\frac{dt}{\sqrt{4t^3-g_2 t-g_3}}=\wp^{-1}(x;g_2,g_3)$$ that is $$\wp$$ - the Wierstrass elliptic function, i.e is the inverse function to the above elliptic integral expressed as a function of $$x$$, while $$g_2$$ and $$g_3$$ are the Weierstrass invariants. The main problem related to symbolic calculation of elliptic integrals concerns of an appropriate domain of definitions (in the complex plane) of the the elliptic functions and its inverses.
While $$\wp$$ is a doubly periodic in the complex plane, it is defined in the whole complex plane except for a discrete (however infinite) set of the lattice points, therefore we have to deal with $$\wp^{-1}$$ carefully. Here we plot only a finite sector of a lattice:

Graphics[
Point[ Flatten[
Table[n {-1/2, -3/2} + m {Sqrt, 1/Sqrt},
{m, -10, 10}, {n, -10, 10}], 1]]] which one can simply calulate with the Weierstrass half-periods. All those functions are implemented in Mathematica

 ?**Weierstrass** Among them there are new in version 11.2: WeierstrassE1, WeierstrassHalfPeriodW1, WeierstrassInvariantG2, WeierstrassEta1 etc. Unfortunately they (WRI) have not improved various unsatisfactory issues related to calculations of elliptic functions and intgrals.

For quite a similar problem see Why does Integrate declare a convergent integral divergent?

Of course, the integral should be real and that is a mathematical error. However, as there are many similar problematic issues (see e.g. this anser), one should expect the revision of symbolic integration of elliptic functions by WRI rather than a removing a simple bug.

To give a clarifying symbolic solution of the problem at hand, let's rewrite the integral symbolically: $$\int_{0}^{\infty} \frac{dz}{\sqrt{\frac{7}{10}+\frac{3}{10}(1+z)^3}}=2\sqrt{\frac{10}{3}} \int_{1}^{\infty} \frac{dt}{\sqrt{\frac{28}{3}+4t^3}}=-2\sqrt{\frac{10}{3}} \int_{\infty}^{1} \frac{dt}{\sqrt{\frac{28}{3}+4t^3}}=\\=-2\sqrt{\frac{10}{3}} \wp^{-1}(1;0,-\frac{28}{3})$$

The last function is the inverse of the Weierstrass elliptic function $$\wp$$, and the integral should be calculated automatically with Mathematica in a symbolic way however it fails. Nonetheless, there are appropriate symbolic tools to verify our reasoning.

N[-2 Sqrt[10/3] InverseWeierstrassP[1, {0, -(28/3)}], 25] // Chop

3.305075828454599464535302

Plot[ WeierstrassP[-Sqrt[(3/40)] t, {0, -(28/3)}] - 1, {t, -20, 20},
PlotRange -> {-5, 20},
Epilog -> {PointSize[0.025], Red, Point[{3.3050758284545996, 0}]}] Let's check it numerically in another way:

t /. FindRoot[ WeierstrassP[-Sqrt[(3/40)] t, {0, -(28/3)}] - 1, {t, 3}]//Chop

3.30508


A hint why there is - 3.85013 I in the earlier version:

N[-2 Sqrt[10/3] InverseWeierstrassP[0, {0, -(28/3)}]]

-2.22287 + 3.85013 I


and from the plot it is clear why the system (unfortunately) fails to find automatically the argument of the inverse function.

GraphicsRow@Table[
ContourPlot[ p[WeierstrassP[-Sqrt[(3/40)] (x + I y), {0, -(28/3)}] - 1] == 0,
{x, -15, 15}, {y, -15, 15}, ContourStyle -> Red],
{p, {Re, Im}}] GraphicsRow@Table[
ContourPlot[ p[WeierstrassP[-Sqrt[(3/40)] (x + I y), {0, -(28/3)}] - 1],
{x, -12, 12}, {y, -12, 12}, ColorFunction -> ColorData["SolarColors"]],
{p, {Re, Im}}] For a more throughout exposition this topic see e.g. Weierstrass Elliptic and Modular Functions, quite a brief one may be found here Weierstrass Elliptic Function.

Edit It is worth to mention that the integral in the symbolic form hadn't been calculated in version 11.2 while since at least the version 12.1 it evaluates correctly

Integrate[ 1/Sqrt[7/10 + 3/10 (z + 1)^3], {z, 0, Infinity}]

1/3 Sqrt[10/7] ((3^(2/3) 7^(1/3) Gamma[1/6] Gamma[4/3])/Sqrt[Pi]
- 3 Hypergeometric2F1[1/3, 1/2, 4/3, -(3/7)])


which is equivalent to the above derivation.

\$Version

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


In v11.2 the integral returns unevaluated

Integrate[1/Sqrt[7/10 + 3/10*(z + 1)^3], {z, 0, Infinity}] Numeric integration works

NIntegrate[1/Sqrt[7/10 + 3/10*(z + 1)^3], {z, 0, Infinity}]

(* 3.30508 *)


Or simplifying the integral by change of variables. Let t == z + 1

Integrate[1/Sqrt[7/10 + 3/10*t^3], {t, 1, Infinity}]

(* 20/3 Hypergeometric2F1[2/3, 1, 7/6, -(7/3)] *)

% // N

(* 3.30508 *)


The integral under consideration is an elliptic integral. A number of you are already familiar with how I keep complaining about suboptimal handling of elliptic integrals in general, so I'll just give the closed form and a pointer to use formula 241.00 in Byrd/Friedman:

With[{y = 1},
N[(1000000/107163)^(1/12) InverseJacobiCN[1 - 42/(7 (3 + Sqrt) + y 583443^(1/6)),
(2 + Sqrt)/4], 20]]
3.3050758284545994645

NIntegrate[1/Sqrt[7/10 + 3/10*t^3], {t, 1, ∞}, WorkingPrecision -> 20]
3.3050758284545994682
`