# Integrate over implicit 1D region: works for algebraic but not transcendental equation?

QUESTION

How come this works:

NIntegrate[1, {x, y} ∈
ImplicitRegion[{x == y^3, x <= 1, x >= 0}, {x, y}]]


But this fails:

NIntegrate[1, {x, y} ∈
ImplicitRegion[{Sin[Pi x] == y, x <= 1, x >= 0}, {x, y}]]


where we have

ContourPlot[x == y^3, {x, 0, 1}, {y, 0, 1}] and

ContourPlot[Sin[Pi x] == y, {x, 0, 1}, {y, 0, 1}] A related question is this one

• Thinking that Sin[Pi x] == y might be failing because its inverse is multivalued, I tried Exp[x] == y, but it also fails. Yet, Abs[x - .5] == Sqrt[y] works fine, giving the same answer as (x - .5)^2 == y, as it should. – bbgodfrey Feb 4 '15 at 18:24
• @bbgodfrey good point, but on the other hand it is not on the interval I am considering. – chris Feb 4 '15 at 18:26
• Could it be because it can't figure out the dimension of the region? RegionDimension[ ImplicitRegion[Sin[\[Pi] x] == y && x <= 1 && x >= 0, {x, y}]] fails. The same thing works for the first region you tried. NIntegrate would need to know what this is really a 1D integral, not a 2D one, to give a reasonable (non-zero) result. – Szabolcs Feb 4 '15 at 18:47
• @bbgodfrey I doubt it. If we invert the relationship using Reduce that problem goes away yet Mathematica still can't figure out that it's a 1D region. – Szabolcs Feb 4 '15 at 18:56
• I do wonder if this is a bug. I would have thought that even discretization would require figuring out the dimension first. It does produce a 1D-type discretized region after all. Perhaps it's something worth reporting. – Szabolcs Feb 4 '15 at 18:58

reg = ImplicitRegion[{Sin[Pi x] == y, x <= 1, x >= 0}, {x, y}]


This is a 1D region embedded in 2D space. NIntegrate needs to know this to produce a reasonable result. My guess is that it uses RegionDimension, which fails here:

In:= RegionDimension[reg]

During evaluation of In:= RegionDimension::nmet: Unable to compute the dimension of region ImplicitRegion[Sin[π x]==y&&x<=1&&x>=0,{x,y}]. >>

Out= RegionDimension[
ImplicitRegion[Sin[π x] == y && x <= 1 && x >= 0, {x, y}]]


RegionMeasure would be equivalent to your NIntegrate example in this specific case and it also fails.

Mathematica can determine the dimension of the other region just fine:

RegionDimension@
ImplicitRegion[{x == y^3, x <= 1, x >= 0}, {x, y}]
(* 1 *)


We could however discretize the region first:

In:= dreg = DiscretizeRegion[reg]

In:= RegionDimension[dreg]
Out= 1

In:= RegionMeasure[dreg]
Out= 2.30414

In:= NIntegrate[1, {x, y} ∈ dreg]
Out= 2.30414


This works, but the problem is that at the discretization step we lose precision that NIntegrate can never re-gain afterwards.

DiscretizeRegion has several options which can control how and how accurately the discretization is done. I'm not sure which one is the best choice in this case, but MaxCellMeasure would be one.

• Thanks. I did not realize you could discretize also 1D regions. That should do the trick for my problem. – chris Feb 5 '15 at 8:05
• @chris Just keep in mind that the accuracy of the discretization can have a significant effect on the result of the integral. – Szabolcs Feb 5 '15 at 16:27