# How to force Mathematica to integrate only over the domain given by (few) step functions?

Consider the function f[x,y,z,...]*UnitStep[g1[x,y,z,...]]*UnitStep[g2[x,y,z]].

the variables x,y,z… are defined into the ranges $$\{x_{1},x_{2}\},\{y_{1},y_{2}\},...$$, while UnitStep functions cut off the domains where the function f is real.

I need to integrate it over all variables. If I use simple code

NIntegrate[f[x,y,z,...]*UnitStep[g1[x,y,z,...]]*UnitStep[g2[x,y,z]],{x,x1,x2},{y,y1,y2},Method->"MonteCarlo"]


then the result is zero. The reason is that on most of the domain the function f[x,y,z,...]*UnitStep[g1[x,y,z,...]]*UnitStep[g2[x,y,z]] is identically zero due to UnitSteps, and Monte-Carlo method obviously has problems with giving correct value.

Is there a method of evaluation of the integral only in regions defined by UnitStep functions?

• well, don't use Monte Carlo. – AccidentalFourierTransform Oct 6 '18 at 0:05
• Can Reduce[UnitStep[g1[x,y,z,...]]*UnitStep[g2[x,y,z]==1,{x,y,z,...}] give you a sufficiently simple set of bounds for x,y that you can then integrate over that domain? Without the code it is difficult to give any more precise answer – Bill Oct 6 '18 at 0:16
• @AccidentalFourierTransform : any other method does not evaluate the integral. – John Taylor Oct 6 '18 at 8:09
• @Bill : thank you. Do you know how to use the results of Reduce as the integration region? – John Taylor Oct 6 '18 at 8:33
• @Bill : thank you. Do you know how to use the results of Reduce as the integration region without explicit inserting (there is a lot of conditions and it is complicated to insert them)? – John Taylor Oct 6 '18 at 8:40

The following is one approach that might work on your problem. You could replace the UnitStep functions with regions. Mathematica might be able to deal with the integral more effectively.

ℛ = ImplicitRegion[x^2 + y^2 < z^2, {{x, 0, 1}, {y, 0, 1}, {z, 0, 1}}];
NIntegrate[Exp[x]/(1 + y + z), {x, y, z} ∈ ℛ]
(* 0.182439 *)

• He can just use non-Monte-Carlo methods in his original integral computation specification. – Anton Antonov Oct 6 '18 at 14:48
• @AntonAntonov : another methods don't work, probably because of very large time of determination of the region. – John Taylor Oct 6 '18 at 15:16

Alternatively, if you use a non-Monte-Carlo method you get the result quickly without messages.

In:= Block[{xmax = 100, ymax = 100},
NIntegrate[UnitStep[9 - x^2 - y^2], {x, 0, xmax}, {y, 0, ymax}]
]

Out= 7.06858


(Using the integral in the question you linked as "Monte-Carlo having problems".)