# Why does Mathematica give an incorrect answer to this multiple integral?

This is not a new problem but I would like to understand why Mathematica gives the result that it does. (Volume of a hypersphere)

In[4]:= Integrate[
Boole[x1^2 + x2^2 + x3^2 + x4^2 + x5^2 + x6^2 < r^2], {x1, -Infinity,
Infinity}, {x2, -Infinity, Infinity}, {x3, -Infinity,
Infinity}, {x4, -Infinity, Infinity}, {x5, -Infinity,
Infinity}, {x6, -Infinity, Infinity}, Assumptions -> {r > 0}]

Out[4]= -(1/6) \[Pi]^3 r^6


A negative answer is obviously incorrect. Replace r^2 by 4

In[3]:= Integrate[
Boole[x1^2 + x2^2 + x3^2 + x4^2 + x5^2 + x6^2 < 4], {x1, -Infinity,
Infinity}, {x2, -Infinity, Infinity}, {x3, -Infinity,
Infinity}, {x4, -Infinity, Infinity}, {x5, -Infinity,
Infinity}, {x6, -Infinity, Infinity}, Assumptions -> {r > 0}]

Out[3]= (32 \[Pi]^3)/3


This is correct.

If we reduce the number of variables, then we obtain a correct answer:

In[5]:= Integrate[
Boole[(x1^2 + x2^2 + x3^2 + x4^2 ) < r^2], {x1, -Infinity,
Infinity}, {x2, -Infinity, Infinity}, {x3, -Infinity,
Infinity}, {x4, -Infinity, Infinity}, Assumptions -> {r > 0}]

Out[5]= (\[Pi]^2 r^4)/2

• This is a known buggy area. If I recall correctly it undersimplifies assumptions somewhere inside due to either internal limitations or time constraints. You might get a better outcome if you first do this (it will influence that former issue): SetSystemOptions["SimplificationOptions"->{"AssumptionsMaxNonlinearVariables"->7}]; – Daniel Lichtblau Apr 26 '13 at 18:48
• At v8.04.0 it gives the correct result what's your version? – Spawn1701D Apr 26 '13 at 19:35
• In 9.0.1 Mathematica also gives a negative answer and then fails to return any answer for the 8 dimensional cases. If memory serves, version 8 gave correct answers up through 6 dimensions and then failed on 7 dimensions. I note that the 9.0.1 answers would be correct if the sign was positive. – TC Jones Apr 26 '13 at 22:33
• Daniel's suggestion is good but the problem remains. – TC Jones Apr 26 '13 at 23:49

As an aside, the multiple integrals can be generalized as

vol[n_Integer?Positive] :=
Module[{x, var},
var = Array[x, n];
Assuming[
{Element[var, Reals], r > 0},
Integrate[
Boole[var.var < r^2],
Sequence @@
Evaluate[
{#, -Infinity, Infinity} & /@ var]] //
Simplify]]

Timing[vol /@ Range[5]]

(* {96.016268, {2*r, Pi*r^2, (4*Pi*r^3)/3, (Pi^2*r^4)/2, (8*Pi^2*r^5)/15}} *)


The timing is somewhat improved by changing the limits
of integration from $\{-\infty ,\infty \}$ to $\{-r, r\}$

vol[n_Integer?Positive] :=
Module[{x, var},
var = Array[x, n];
Assuming[
{Element[var, Reals], r > 0},
Integrate[
Boole[var.var < r^2],
Sequence @@
Evaluate[
{#, -r, r} & /@ var]] //
Simplify]]

Timing[vol /@ Range[5]]

(* {64.282676, {2*r, Pi*r^2, (4*Pi*r^3)/3, (Pi^2*r^4)/2, (8*Pi^2*r^5)/15}} *)


Bob Hanlon