# How to modify NIntegrate code below so that it gives the most accurate/reliable numerical result?

Imagine that I have two conditions con1 and con2 over the two-dimensional domain $$x,y\in[-2,2]$$. I want to compute the area of the union of these two conditions i.e. the region $$(con1 )\cup(con2)$$. I can use the two methods given below

con1 = ImplicitRegion[x + y < 1 && x - y < 1, {{x, -2, 2}, {y, -2, 2}}];
con2 = ImplicitRegion[x + y > 0 && x - y > 0, {{x, -2, 2}, {y, -2, 2}}];

method1 =Integrate[1, {x, y} \[Element] RegionUnion[con1, con2]]
(*23/2*)

con1 = (NIntegrate[
Boole[  x + y < 1 && x - y < 1], {x, -2, 2}, {y, -2, 2},
Method -> "MonteCarlo", MaxRecursion -> 20,
PrecisionGoal -> 10] // FullSimplify);
con2 = (NIntegrate[
Boole[  x + y > 0 && x - y > 0], {x, -2, 2}, {y, -2, 2},
Method -> "MonteCarlo", MaxRecursion -> 20,
PrecisionGoal -> 10] // FullSimplify);

method2 = con1 + con2
(*11.9218*)


My question: The first method gives an exact answer which is $$23/2=11.5$$. How can I modify the precision of the second code (I have to use the second code since the first code does not work for the real conditions I have) so that I can get the most accurate/reliable numerical result which should be very close to $$11.5$$?

• Have you considered that the regions overlap?: RegionPlot[{x + y < 1 && x - y < 1, x + y > 0 && x - y > 0}, {x, -2, 2}, {y, -2, 2}]. Otherwise, if you get rid of all the options to NIntegrate, then the NIntegrate integrals are computed highly accurately. May 19 at 23:57
• Try NIntegrate[ Boole[(x + y < 1 && x - y < 1) || (x + y > 0 && x - y > 0)], {x, -2, 2}, {y, -2, 2}] for an equivalent formulation of Integrate over the union. May 19 at 23:58
• @MichaelE2 Thanks; then, do you mean that NIntegrate without any precision options (such as MaxRecursion , PrecisionGoal  and Method) gives the highest accurate result? May 20 at 8:03
• I meant it gives a very highly accurate result. The error of the NIntegrate in my comment is 2 ulp (one bit in the next to last place), a relative error of about $3\times10^{-16}$. The error of the NIntegrate in my answer is zero, which is more accurate, obviously. (Side remark: the Monte Carlo method is used when only a few digits of accuracy and nothing else works. It is a last resort.) May 20 at 15:48

NIntegrate[
(*  11.5  *)

I'd say the original question was a simple mistake, but using the Exclusions` option is not obvious and yields the most accurate answer possible in this case.