# Why does this triple integral take so long?

How can I compute this triple integral?

$$I=\underset{V}{\iiint}\frac{(y-1)^3}{x^2+y^2+z^2+1}\,\mathrm dx\,\mathrm dy\,\mathrm dz\qquad V\begin{cases}x^2+y^2+z^2\le 4\\x\ge 0\end{cases}$$

I tried this but it has been running for a long time and not return result yet.

Integrate[
Boole[0 <= x^2 + y^2 + z^2 <= 4]*((y - 1)^3/(x^2 + y^2 + z^2 + 1)), {x, 0, 2}, {y, -2,
2}, {z, -2, 2}]

• NIntegrate will give a numerical value (-16.755...) Apr 16 at 20:26
• @mikado that seems right. Someone got -16π/3, why is it hard for Mathematica to get the exact result?
– hana
Apr 16 at 20:29
• @hana If I had to guess (and I would be), because "work over this prism and then test membership in a hemisphere" is harder to work with than "work over this sphere and then test membership in a hemisphere", and that the latter likely makes Mathematica more likely to try certain methods (e.g. it knows a sphere is relevant from the domain specification, so will try spherical coordinates etc.). The domain as a prism doesn't lead it to realize a sphere is present, as that's been coded into the function rather than the domain, so it doesn't try those methods. But, again: just a guess. Apr 17 at 11:53

Integrate[
Boole[x >= 0]*((y - 1)^3/(x^2 + y^2 + z^2 + 1)), {x, y,
z} ∈ Ball[{0, 0, 0}, 2]]


-((16 π)/3)

• In theory, Integrate[(y - 1)^3/(x^2 + y^2 + z^2 + 1), {x, y, z} ∈ RegionIntersection[HalfSpace[{-1, 0, 0}, {0, 0, 0}], Ball[{0, 0, 0}, 2]]] should work just as well, but this version is quite a bit slower than the one in this answer. Jun 10 at 14:34

Changing to spherical polar coordinates gives an answer that agrees numerically

π Integrate[(r^2 Cos[θ] (r Sin[θ] - 1)^3)/(r^2 + 1), {r, 0, 2}, {θ, -π/2, π/2}]
(* -((16 π)/3) *)


But doesn't explain why Mathematica struggles with the Cartesian formulation.

• Using the coordinate transformation functionality of Mathematica: ff = Simplify[((y - 1)^3/(x^2 + y^2 + z^2 + 1) /. Thread[{x, y, z} -> CoordinateTransform["Spherical" -> "Cartesian", {r, φ, θ}]]) CoordinateTransformData["Spherical" -> "Cartesian", "MappingJacobianDeterminant", {r, φ, θ}]]; Integrate[ff, {r, 0, 2}, {φ, 0, π}, {θ, -π/2, π/2}] Jun 10 at 14:49
• Although I did not try, version 13.1 has IntegrateChangeVariables as can be checked from this page Oct 11 at 19:40