12
$\begingroup$

For some reason Mathematica cannot evaluate this definite integral:

$Version
(* 10.1.0  for Microsoft Windows (64-bit) (March 24, 2015) *)

Integrate[1/(Sqrt[x] Sqrt[1 - x + x^2]), {x, 1, 2}]
(* Integrate[1/(Sqrt[x] Sqrt[1 - x + x^2]), {x, 1, 2}] *)

although it immediately finds an antiderivative, which allows to evaluate it by manual application of The Fundamental Theorem of Calculus:

Integrate[1/(Sqrt[x] Sqrt[1 - x + x^2]), x]
(* (2 (-1)^(1/6) Sqrt[1 - (-1)^(1/3)/x] Sqrt[1 + (-1)^(2/3)/x] x 
     EllipticF[I ArcSinh[(-1)^(1/3)/Sqrt[x]], (-1)^(2/3)])/Sqrt[1 - x + x^2] *)

FullSimplify[(% /. x -> 2) - (% /. x -> 1)]
(* 2 (-1)^(1/6) (-EllipticF[I ArcSinh[(-1)^(1/3)], (-1)^(2/3)] + 
     EllipticF[I ArcSinh[(-1)^(1/3)/Sqrt[2]], (-1)^(2/3)]) *)

% - NIntegrate[1/(Sqrt[x] Sqrt[1 - x + x^2]), {x, 1, 2}, WorkingPrecision -> 30]
(* 0. 10^-31 + 0. 10^-47 I *)

What could be the reason that Mathematica cannot do it automatically?

$\endgroup$
11
  • 6
    $\begingroup$ It checks for bad points on the integration path. Often when the antiderivative has elliptic functions Integrate hits code that says, in effect, just give up. $\endgroup$ Jun 4, 2015 at 17:44
  • 2
    $\begingroup$ I found this blog post discussing this problem in general. But in this particular case it looks like an algorithm weakness, because there are no discontinuities on the interval $[1,2]$. $\endgroup$ Jun 4, 2015 at 18:03
  • 3
    $\begingroup$ It might be a bug. The basic logic is as I stated though: Integrate checks for patch singularities, and signals a failure in that checking code, so it gives up. I'll have a look at why the failure happens and whether it can be better handled. $\endgroup$ Jun 4, 2015 at 18:45
  • 4
    $\begingroup$ Yes it worked, but the ways in which it did so also caused considerable trouble for other examples. One issue is that the path singularity detection code was unable to handle the antiderivative and so it just let it through. Another was that when a limit could not be extracted the code would blindly plug in the value. Both caused their share of bugs... $\endgroup$ Jun 4, 2015 at 23:15
  • 3
    $\begingroup$ ...such as shows up in this example. Integrate[Sqrt[(2*t)^2 + (4 - 3*t^2)^2], {t, 0, 2}] which was incorrect. The same changes alluded to above made this instead become unevaluated (version 10.0.1 I think). $\endgroup$ Jun 4, 2015 at 23:17

2 Answers 2

6
$\begingroup$

As is well known, and has been discussed extensively in this forum, there may be problems in general with Integrate[] and the fundamental theorem of calculus, mostly due to discontinuities or other singularities in the antiderivative.

But not in this case for version 8:

$Version

(* Out[1]= "8.0 for Microsoft Windows (64-bit) (October 7, 2011)" *)

The integrand is:

f[x_] = 1/(Sqrt[x] Sqrt[1 - x + x^2]);

It is completely harmless in the range of integration.

The symbolic integral in question is easily calculated by Mathematica with the result:

Timing[Integrate[1/(Sqrt[x] Sqrt[1 - x + x^2]), {x, 1, 2}] ]

(*
Out[3]= {3.011, 2 (-1)^(
  1/6) (-EllipticF[I ArcSinh[(-1)^(1/3)], (-1)^(2/3)] + 
    EllipticF[I ArcSinh[(-1)^(1/3)/Sqrt[2]], (-1)^(2/3)])}
*)

% // N

(* Out[4]= {3.011, 0.646172 - 5.55112*10^-17 I} *)

The numeric integral is

NIntegrate[f[x], {x, 1, 2}]

(*
Out[5]= 0.646172
*)

Done.

Finally, let's have a look at the antiderivative:

Integrate[1/(Sqrt[x] Sqrt[1 - x + x^2]), x]

(*
Out[6]= (2 (-1)^(1/6) Sqrt[1 - (-1)^(1/3)/x] Sqrt[
 1 + (-1)^(2/3)/x] x EllipticF[I ArcSinh[(-1)^(1/3)/Sqrt[x]], (-1)^(
  2/3)])/Sqrt[1 - x + x^2]
*)

There is no singularity in the range of integration as can easily be shown by plotting this expression.

I conclude that neither the implicit statement of Vladimir ("What could be the reason that Mathematica cannot do it automatically?") nor the statement of Daniel ("Often when the antiderivative has elliptic functions Integrate hits code that says, in effect, just give up.") is applicable in this case.

EDIT #1

The "regression" (Vladimir's expression in his comment) started earlier. In version 5.2 the integral is done correctly symbolically and even faster than in version 8.

$Version

(* Out[2]=5.2 for Microsoft Windows x86 (64 bit) (June 20, 2005) *)

Timing[Integrate[1/(Sqrt[x] Sqrt[1 - x + x^2]), {x, 1, 2}] ]

(*
Out[4]=
{0.2030*Second, 2*(-1)^(1/6)*(-EllipticF[I*ArcSinh[(-1)^(1/3)], (-1)^(2/3)] + 
    EllipticF[I*ArcSinh[(-1)^(1/3)/Sqrt[2]], (-1)^(2/3)])}
*)
$\endgroup$
6
  • $\begingroup$ Then it looks like a regression from version 8.0 to 10.1.0. $\endgroup$ Jun 4, 2015 at 18:27
  • $\begingroup$ Yes, unfortunately, this "happens" sometimes. I've already had some sad experiences with the transistion from 5.2 to 8. See my EDIT #1. $\endgroup$ Jun 4, 2015 at 18:44
  • 1
    $\begingroup$ Hmph, not particularly happy with the output of Integrate[] myself. It could be a whole lot simpler than it is, but as I've said (grumbled?) a number of times previously, Mathematica's handling of elliptic integrals is quite far from optimal. $\endgroup$ Jun 4, 2015 at 20:20
  • $\begingroup$ As I have shown, things are ok in Version 8. I don't understand what's going on in Wolfram that newer versions can lose "knowledge". $\endgroup$ Jun 4, 2015 at 20:30
  • 2
    $\begingroup$ Bugs are universal. Regressions happen. What bothers me is that Wolfram keeps all this under wraps until someone posts a question here. Then there is an unofficial answer by a company insider. Why does Wolfram not just periodically publish a list of known issues and their status? $\endgroup$ Jun 10, 2015 at 1:47
3
$\begingroup$

Since I complained that the result returned by Mathematica is not as simple as I would like, I might as well post the closed form that I have. I will not write the derivation here, but the procedure is similar to what I did in this math.SE answer:

N[InverseJacobiCN[-1/3, 3/4] - EllipticK[3/4], 20]
   0.64617199330515618196

NIntegrate[1/Sqrt[x (1 - x + x^2)], {x, 1, 2}, WorkingPrecision -> 20]
   0.64617199330515618293
$\endgroup$
9
  • $\begingroup$ Disclaimer: I still don't have a computer with Mathematica, so I had a friend run both snippets for me. But I did derive the closed form with only pen and paper. $\endgroup$ Jun 6, 2015 at 4:12
  • $\begingroup$ You are right, the antiderivative can be expressed as InverseJacobiCN[(1 - x)/(1 + x), 3/4] $\endgroup$ Jun 6, 2015 at 18:11
  • $\begingroup$ @J. M.: thanks for providing the "miraculous" simpler expression. Maybe it is an advantage not to have Mathematica availble. More paper, pencil and brains perhaps ;-) $\endgroup$ Jun 10, 2015 at 12:07
  • $\begingroup$ Dear Herr @Dr. Hintze, thank you for the compliment, but I would say it is less a "miracle" and more a careful reading of Byrd/Friedman. Probably, if Mathematica could do Carlson's integrals, I would not have to resort to trickery. ;) $\endgroup$ Jun 10, 2015 at 12:30
  • $\begingroup$ @J. M. : please enlighten me about Byrd/Friedman and Carlson's integrals. And as for the other point : I noticed that sometimes I jump too fast from paper, pencil and brains to Mathematica ;-) $\endgroup$ Jun 10, 2015 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.