I have a complex and long piecewise function to integrate, so I have written a Mathematica script that cuts the whole range of integration, evaluates the integrand in each region and then integrates it.
In order to integrate the evaluated function on the right range, I set the integration on the whole original range and I use Boole to define the appropriate region.
Now, it happens that both the integrand and the region depends on other parameters, say a
and b
, so I should get an integral which depends on these, as in the following WORKING example
Assuming[0 < 2 a < 1,
Integrate[
Exp[-t] Boole[(b < 0.5 && a < t < 2 a) || (b > 0.5 &&
0 < t < a)], {t, 0, 1}]]
which gives
$\begin{cases} e^{-2. a} \left(e^a-1.\right) & 0.<a<0.5\land b<0.5 \\ e^{-1. a} \left(e^a-1.\right) & 0.<a<0.5\land b>0.5 \\ 0. & \text{True} \end{cases}$
However, when the range of integration becomes too complex, Mathematica stops to evaluate the integral and give me back an implicit solution. For example, consider the following code
r = (0 < b < 1/
2 && ((0 < a < b &&
b + a < z <
1 && ((z - b < x <= z - a && 0 < y < a) || (z - a < x < z &&
0 < y < z - x))) || (a == b && b + a < z < 1 &&
z - a < x < z && 0 < y < z - x) || (b < a < 1 - b &&
b + a < z < 1 && z - b < x < z && 0 < y < z - x))) || (1/2 <=
b < 1 && 0 < a < 1 - b &&
b + a < z <
1 && ((z - b < x <= z - a && 0 < y < a) || (z - a < x < z &&
0 < y < z - x)))
int = Exp[-0.5 y1^2 y -
2 (y2^2 (z - b - a) + y1^2 (-z + b + x + a))] y1^2 Boole[r]
Integrate[int, {z, a, 1}, {x, a, z}, {y, 0, a}]
The last line gives me $\text{y1}^2 \int _a^1\int _a^z\int _0^a\exp \left(-2 \text{y1}^2 (a+b+x-z)+2 \text{y2}^2 (a+b-z)-0.5 y \text{y1}^2\right) \text{Boole}[...]dydxdz$
The same happens if I isolate intervals with respect to a,b
, as in
r = LogicalExpand[(0 < b <
1/2 && ((0 < a < b &&
b + a < z <
1 && ((z - b < x <= z - a && 0 < y < a) || (z - a < x < z &&
0 < y < z - x))) || (a == b && b + a < z < 1 &&
z - a < x < z && 0 < y < z - x) || (b < a < 1 - b &&
b + a < z < 1 && z - b < x < z && 0 < y < z - x))) || (1/2 <=
b < 1 && 0 < a < 1 - b &&
b + a < z <
1 && ((z - b < x <= z - a && 0 < y < a) || (z - a < x < z &&
0 < y < z - x)))]
s = Reduce[r[[2]], {x, y}]
int = Exp[-0.5 y1^2 y -
2 (y2^2 (z - b - a) + y1^2 (-z + b + x + a))] y1^2 Boole[s]
Integrate[int, {z, a, 1}, {x, a, z}, {y, 0, a}]
or if I split the Integrate
function
Integrate[
Integrate[Integrate[int, {y, 0, a}], {x, a, z}], {z, a, 1}]
Why Mathematica cannot evaluate the integral?