# Performance boost for definite integration with symbolic limits

In Mathematica, the symbolic definite integration

Integrate[Sqrt[1 - x^2] - (1 - Sqrt[3 + 2 x - x^2]), {x, a, b},
Assumptions -> {a ∈ Reals, b ∈ Reals}] // AbsoluteTiming


Takes 21.987258 seconds on my computer.

In Maple, a similar integration

int(sqrt(1 - x^2) - (sqrt(3 + 2x - x^2)), x = a..b)


takes only 0.087 seconds.

This happens because Mathematica tend to give a mathematically rigorous solution. I did not know this before, and I think it's good to share.

• Thank you for sharing your experience, but I have to say, I feel that this is not a question and your answer is not an answer. Definite integration is not as simple in general as this case might suggest, because the result can depend on the path taken in the complex plane in the presence of branch cuts. It is probably this branch cut handling that takes Mathematica the bulk of the time, although someone with more experience with Integrate could tell you for sure. Additionally, it would be better if you would specify what Maple is doing to evaluate the integral and what result it gives. Feb 14, 2015 at 17:30
• Incidentally, one can see that producing the conditional does not account for the whole time taken by giving the option GenerateConditions -> False. The integration takes about half as long, but is still much slower than if this were the only time-consuming operation. Feb 14, 2015 at 17:44

The output of the Mathematica code is

ConditionalExpression[
1/2 (2 a - a Sqrt[1 - a^2] + Sqrt[3 + 2 a - a^2] - a Sqrt[3 + 2 a - a^2] - 2 b +
b Sqrt[1 - b^2] - Sqrt[3 + 2 b - b^2]+ b Sqrt[3 + 2 b - b^2] + 4 ArcSin[(1 - a)/2]
*Routine clean-up*-ArcSin[a] - 4 ArcSin[(1 - b)/2] + ArcSin[b]),
-1 < b < 1 && ( -1 < a < b || b < a < 1)]


Which gives not only the integral, but also the condition when the result is valid. The latter task took most of the 20 seconds. If you don't care about the condition, or that you know the condition will be met, simply use indefinite integral, and do the subtraction.

F[x_] = Integrate[Sqrt[1 - x^2] - (1 - Sqrt[3 + 2 x - x^2]), x]
F[b] - F[a]


This takes only 0.152009 seconds. Still slower than Maple, but very much acceptable.