2
$\begingroup$

I am trying to evaluate

Integrate[
 Integrate[
  Integrate[
   Integrate[
    Boole[x <= y + w + z], {w, 0, x}
    ]
   , {z, 0, x}
   ]
  , {y, 0, x}
  ]
 , {x, 0, 1}
 ]

When I run the code in Mathematica 12.3.1 offline or Wolfram Cloud I get the answer as

$\frac{5}{6}$Integrate`\$\$a\$7051$^3$

The number after the "a" changes every time.

How can I fix this?

Is this a bug?

$\endgroup$
1
  • 2
    $\begingroup$ Yes, it is a bug. Though as others have noted, there are better ways to do the computation, and reasons to expect this way will not work well. If you want to nest the integrals then assumptions about the outer variables should be made apparent to the inner integrals, like this. In[417]:= Integrate[ Integrate[ Integrate[ Integrate[Boole[x <= y + w + z], {w, 0, x}, Assumptions -> {0 < z < x, 0 < y < x, 0 < x < 1}], {z, 0, x}, Assumptions -> {0 < y < x, 0 < x < 1}], {y, 0, x}, Assumptions -> {0 < x < 1}], {x, 0, 1}] Out[417]= 5/24 $\endgroup$ Apr 15 at 15:38

2 Answers 2

6
$\begingroup$

It is enough to use a single Integrate and to set Integrationpart x outer most:

Integrate[Boole[x <= y + w + z], {x, 0, 1}, {w, 0, x} , {z, 0, x} , {y, 0, x} ] 
(*5/24*)

No bug!

$\endgroup$
4
$\begingroup$

In the innermost integral Integrate[ Boole[x <= y + w + z], {w, 0, x}] is purely symbolic since Integrate does not know what is x neither y and z, consequently Boole cannot be evaluated, and at last there is an improper result. What is behind the scene can be noticed acting with Trace on the nested integrals. This seems to be rather an improper usage of Integrate, nonetheless there shouldn't appear such issues.

However if we are going to exploit Boole we have to calculate a multiple integral in an appropriate order:

Integrate[ Boole[x <= y + w + z], {x, 0, 1}, {y, 0, x}, {z, 0, x}, {w, 0, x}]
5/24

If one necessarily needs nested integrals then we have to supersede Boole[x <= y + w + z] with e.g. UnitStep[y + w + z - x] or HeavisideTheta[y + w + z - x]

Integrate[
  Integrate[
    Integrate[
      Integrate[ UnitStep[y + w + z - x], {w, 0, x}],
                                            {z, 0, x}], 
                                            {y, 0, x}], 
                                              {x, 0, 1}]
5/24

Nonetheless it takes much more time to evaluate, on my computer AbsoluteTiming is 15.2524, however using Integrate once it takes 0.864271 while with Boole it is 0.212867, even worse timing with HeavisideTheta. There are instances where HeavisideTheta is more efficient than Boole e.g. Double integral over the region enclosed by several lines

Having said that it is remarkable to notice that the most efficient way seems to be one using ImplicitRegion (since version 10.0 of the system)

AbsoluteTiming[
  IR = ImplicitRegion[ x <= y + w + z && 0 <= x <= 1 && 
                       0 <= y <= x && 0 <= w <= x && 0 <= z <= x, {x, y, w, z}];
  Integrate[1, {x, y, w, z} ∈ IR]]
{0.0102903, 5/24}

This ensures that the newer method if quite reliable unlike at the times when it just had appeared, see e.g. answers in Finding length of intersection of two surfaces.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.