# Why Mathematica cannot apply The Fundamental Theorem of Calculus automatically?

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], (-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? • 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. – Daniel Lichtblau Jun 4 '15 at 17:44 • 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]$. – Vladimir Reshetnikov Jun 4 '15 at 18:03 • 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. – Daniel Lichtblau Jun 4 '15 at 18:45 • 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... – Daniel Lichtblau Jun 4 '15 at 23:15 • ...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). – Daniel Lichtblau Jun 4 '15 at 23:17 ## 2 Answers 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= "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.011, 2 (-1)^(
1/6) (-EllipticF[I ArcSinh[(-1)^(1/3)], (-1)^(2/3)] +
EllipticF[I ArcSinh[(-1)^(1/3)/Sqrt], (-1)^(2/3)])}
*)

% // N

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


The numeric integral is

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

(*
Out= 0.646172
*)


Done.

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

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

(*
Out= (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=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=
{0.2030*Second, 2*(-1)^(1/6)*(-EllipticF[I*ArcSinh[(-1)^(1/3)], (-1)^(2/3)] +
EllipticF[I*ArcSinh[(-1)^(1/3)/Sqrt], (-1)^(2/3)])}
*)

• Then it looks like a regression from version 8.0 to 10.1.0. – Vladimir Reshetnikov Jun 4 '15 at 18:27
• Yes, unfortunately, this "happens" sometimes. I've already had some sad experiences with the transistion from 5.2 to 8. See my EDIT #1. – Dr. Wolfgang Hintze Jun 4 '15 at 18:44
• 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. – J. M.'s technical difficulties Jun 4 '15 at 20:20
• 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". – Dr. Wolfgang Hintze Jun 4 '15 at 20:30
• 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? – Ralph Dratman Jun 10 '15 at 1:47

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

• 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. – J. M.'s technical difficulties Jun 6 '15 at 4:12
• You are right, the antiderivative can be expressed as InverseJacobiCN[(1 - x)/(1 + x), 3/4] – Vladimir Reshetnikov Jun 6 '15 at 18:11
• @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 ;-) – Dr. Wolfgang Hintze Jun 10 '15 at 12:07
• 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. ;) – J. M.'s technical difficulties Jun 10 '15 at 12:30
• @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 ;-) – Dr. Wolfgang Hintze Jun 10 '15 at 15:32