# Using Compiled Function in Implicit Region

I am looking for a way to speed up code and thus would like to use a compiled function in an ImplicitRegion. Here is an example of a region that can be plotted normally, but fails when I try to use a compiled function. Is there a way to make this work?

RegionPlot3D[
ImplicitRegion[-x  y z > 0, {{x, -5, 5}, {y, -5, 5}, {z, -5, 5}}]]
(*works*)

TEST=Compile[{{x, _Real}, {y, _Real}, {z, _Real}}, -x  y z];
RegionPlot3D[
ImplicitRegion[TEST > 0, {{x, -5, 5}, {y, -5, 5}, {z, -5, 5}}]]
(*fails*)

• Have you tried RegionPlot3D[ ImplicitRegion[TEST[x,y,z] > 0, {{x, -5, 5}, {y, -5, 5}, {z, -5, 5}}]]? – dr.blochwave Jul 24 '15 at 13:44
• If you are unhappy with the warning message try this cf = Compile[{{x, _Real}, {y, _Real}, {z, _Real}}, -x y z]; TEST[x_?NumericQ, y_?NumericQ, z_?NumericQ] := cf[x, y, z]; RegionPlot3D[ ImplicitRegion[ TEST[x, y, z] > 0, {{x, -5, 5}, {y, -5, 5}, {z, -5, 5}}]] – PlatoManiac Jul 24 '15 at 13:45
• Doesn't RegionPlot3D compile its function anyway? – Michael E2 Jul 24 '15 at 14:36
• @MichaelE2 I'm not sure. I don't see anything about that on the documentation page, but you might be right – BenP1192 Jul 24 '15 at 14:40
• A lot of computationally intense functions do automatically compile in appropriate circumstances. Check the timings RegionPlot3D[ImplicitRegion[-x y z > 0, {{x, -5, 5}, {y, -5, 5}, {z, -5, 5}}]] // RepeatedTiming etc. I found this original plot was slightly faster than blockwave's compiled version. – Michael E2 Jul 24 '15 at 14:45

TEST = Compile[{{x, _Real}, {y, _Real}, {z, _Real}}, -x y z];

The second function, TESTfn, is necessary to ensure you only pass numeric (and not symbolic) arguments to the compiled function, see for example Using a compiled function inside NIntegrate gives "CompiledFunction::cfsa" message. 