# Efficient application of the fundamental theorem of calculus

How can the following definite integral be computed with Mathematica?

$$-\frac14\int_1^{\infty}\!\!\frac{\sqrt{-4 x^4-4 x^2 z-(y^2+z)^2}}{x (x^2+z)}\theta\!\left(-4 x^4-4 x^2 z-(y^2+z)^2\right)\mathrm{d}x \text{ with y,z\in\mathbb{R}}.$$

Warning: hard, easy to loose time...

For the brave ones I provide some details. It is a simple matter to find the antiderivative (1). However, it is hard to substitute the limits automatically (compare 2 and 3 with 5). Below, I outline the procedure that I've tried and that may eventually lead to the analytic result. However, it is too cumbersome.

## 1. The indefinite integral

The indefinite integral can be computed using the Rubi, the Rule-based Integrator:

Get["Rubi"]

v=Int[-(1/(4 x (x^2+z))) Sqrt[-4 x^4-4 x^2 z-(y^2+z)^2] ,x]

(* 1/4 ArcTan[(2 x^2+z)/Sqrt[-4 x^4-4 x^2 z-(y^2+z)^2]]
-((y^2+z) ArcTan[(2 x^2 z+2 z^2-(y^2+z)^2)/((y^2+z) Sqrt[-4 x^4-4 x^2 z-(y^2+z)^2])])/(8 z)
-((y^2+z) ArcTan[(2 x^2 z+(y^2+z)^2)/((y^2+z) Sqrt[-4 x^4-4 x^2 z-(y^2+z)^2])])/(8 z) *)


MA can also compute this integral, however, the result is longer. The added benefit of Ruby is that the antiderivative is continuous in the required interval. This is very important because it allows to use the fundamental theorem of calculus.

## 2. Determination of limits for $$0\le x<\infty$$

Let us assume for the moment that the lower integration limit is 0 not 1, and let $$y>0$$. This case is easier to handle.

Assuming[y∈Reals&&z∈Reals,Reduce[((-2 x^2+2 x y-y^2-z>0&&2 x^2+2 x y+y^2+z>0)||(-2 x^2+2 x y-y^2-z<0&&2 x^2+2 x y+y^2+z<0))&&0<x&&y>0,x]]

(* y>0 && ((z<=-y^2         && -(y/2)+1/2 Sqrt[-y^2-2 z]<x<y/2+1/2 Sqrt[-y^2-2 z])||
(-y^2<z<-(y^2/2) && y/2-1/2 Sqrt[-y^2-2 z]<x<y/2+1/2 Sqrt[-y^2-2 z])) *)


## 3. A by hand substitution

Using $$\lim_{x\rightarrow\pm\infty}\arctan(x)=\pm\frac{\pi}2,$$ a simple result can be obtained

f=Piecewise[{{π/4-(π (y^2+z))/(4 z),z<=-y^2},{π/4+(π (y^2+z))/(4 z),-y^2<z<-(y^2/2)}}]


It is desirable that MA can do these limits automatically. However, it seems not capable to determine that the expression under the square root is positive even given the needed assumptions. A simpler question is how to implement the limits with assumptions in MA?

## 4. Plot the result

 Block[{y=3},Plot[{f,NIntegrate[-(1/(4 x (x^2+z))) Sqrt[-4 x^4-4 x^2 z-(y^2+z)^2] HeavisideTheta[-4 x^4-4 x^2 z-(y^2+z)^2] ,{x,1,∞}]},{z,-30,0}]]


Analytical result is different from the numerical one, and it is clear why—the integral should be in the $$1\le x<\infty$$ limits.

## 5. Setting the limits right ($$1\le x<\infty$$) and the actual problem

Assuming[y∈Reals&&z∈Reals,Reduce[((-2 x^2+2 x y-y^2-z>0&&2 x^2+2 x y+y^2+z>0)||(-2 x^2+2 x y-y^2-z<0&&2 x^2+2 x y+y^2+z<0))&&1<x&&y>0,x]]

(* (0<y<1&&   ((z<=-2-2 y-y^2&&-(y/2)+1/2 Sqrt[-y^2-2 z]<x<y/2+1/2 Sqrt[-y^2-2 z])||
(-2-2 y-y^2<z<-2+2 y-y^2&&1<x<y/2+1/2 Sqrt[-y^2-2 z])))||
(1<=y<=2&& ((z<-2-2 y-y^2&&-(y/2)+1/2 Sqrt[-y^2-2 z]<x<y/2+1/2 Sqrt[-y^2-2 z])||
(-2-2 y-y^2<=z<-2+2 y-y^2&&1<x<y/2+1/2 Sqrt[-y^2-2 z])))||
(y>2&&     ((z<-2-2 y-y^2&&-(y/2)+1/2 Sqrt[-y^2-2 z]<x<y/2+1/2 Sqrt[-y^2-2 z])||
(-2-2 y-y^2<=z<=-2+2 y-y^2&&1<x<y/2+1/2 Sqrt[-y^2-2 z])||
(-2+2 y-y^2<z<-(y^2/2)&&y/2-1/2 Sqrt[-y^2-2 z]<x<y/2+1/2 Sqrt[-y^2-2 z]))) *)
`

Now the route is clear: one just needs to go case by case and evaluate the antiderivative at the respective limits. The antiderivative is continuous, which greatly simplifies the problem. Yet, it is not for human hands. Therefore the harder question: how can these limits be computed analytically with MA given the antiderivative and the 7 cases above?