# Speed up RegionPlot

I want to plot a system of equalities and inequalities. I used a combination of ImplicitRegion and RegionPlot (since RegionPlot cannot plot lines or points). But this method is very slow than using only the RegionPlot. Can this be improved?

Or is there any other alternate to plot a system of equalities and inequalities?

RegionPlot[x^2 + y^3 < 2 && x + y < 1, {x, -2, 2}, {y, -2, 2}]; // AbsoluteTiming

(*{0.146477,Null}*)

RegionPlot[x^2 + y^3 < 2 && x + y == 1, {x, -2, 2}, {y, -2, 2}]; // AbsoluteTiming

(*{0.0746052,Null}*)

reg1 := ImplicitRegion[x^2 + y^3 < 2 && x + y < 1, {x, y}]
reg2 := ImplicitRegion[x^2 + y^3 < 2 && x + y == 1, {x, y}]

RegionPlot[reg1]; // AbsoluteTiming

(*{0.875837,Null}*)

RegionPlot[reg2]; // AbsoluteTiming

(*{0.405988,Null}*)


(I dont always know the solution range)

UPDATE I learnt from the comments that one of the reason for RegionPlot[ImplicitRegion[]] to be slower compared to RegionPlot is the necessity to find the region bounds in the former. So I tried to find the bounds using RegionBounds and apply in RegionPlot. However this combo is slower compared to using RegionPlot directly on the ImplicitRegion

Also, the third case in the example code I posted may work faster in many of your machines (then I believe the first case with only RegionPlot will be much faster in you machine). My question is a general way to speed up the working of RegionPlot[ImplicitRegion[]] when compared to RegionPlot. If that is impossible, I want to know if there is any other way to plot this? (For example, depending on the RegionDimension, choose RegionPlot or ContorPlot. Though this approach also involves the knowledge of the bounds)

• They do different things, which you can observe by comparing DiscretizeGraphics@RegionPlot[<inequality>] with the output of RegionPlot[reg1] etc. – Michael E2 Mar 2 '16 at 2:57
• @MichaelE2 I want to plot system of equalities and inequalities faster. Is there any way to do it? – Prashanth Mar 3 '16 at 0:14
• Do you mean like the first two examples, or you want something faster? – Michael E2 Mar 3 '16 at 1:41
• @MichaelE2 I need the third example to work faster like the first one (the second example does not work. So dont consider its timing) – Prashanth Mar 3 '16 at 6:15
• RegionPlot[RegionMember[reg1, {x, y}], {x, -2, 2}, {y, -2, 2}]? You save time by (I think) not computing the boundary. Note the difference in output though. I'm not sure if that's what you want. If you want the boundary computed automatically, it's going to take extra time to do it -- I don't think there's a way around it. – Michael E2 Mar 3 '16 at 12:50

I'm not completely sure what you are looking for, but this option seems fast enough:

With[{a = 1},
RegionPlot[{x^2 + y^3 < 2, x^2 + y^3 < 2 && x + y == a},
{x, -2, 2}, {y, -(-2 - a), -(2 - a)},
BoundaryStyle -> Directive[Thickness[0.02]]]] // AbsoluteTiming


Edit 2 Following @JasonB comments we may add PlotRange without Show, so plotting range and domains are different now. Therefore if you do not know where the solution is you may set xmin and xmax as large as you wish and adjust the range accordingly (note that sometimes one has to correct option PlotPoints to make the line x + y = a visible).

With[{a = 1, xmin = -3, xmax = 5, range = 4},
RegionPlot[{x^2 + y^3 < 2, x^2 + y^3 < 2 && x + y == a},
{x, xmin, xmax}, {y, -(xmin - a), -(xmax - a)}, PlotPoints -> 10,
PlotRange -> {{-range, range}, {-range, range}}]]


• This is really weird, I'd even call it a minor bug. You don't need the With to get the plot to work, but it will only work with the right plot range. Just check out this: {RegionPlot[{x^2 + y^3 < 2 && x + y == 1}, {x, -2, 2}, {y, -2, 3}], RegionPlot[{x^2 + y^3 < 2 && x + y == 1}, {x, -2, 2}, {y, -2, 2}], RegionPlot[{x^2 + y^3 < 2 && x + y == 1}, {x, -2, 2}, {y, -1, 3}]} – Jason B. Mar 8 '16 at 10:41
• @JasonB, you will be surprised but I'm aware of this and made a just for conveniece - i.e. if one wants to change equality to, say, x + y == 2 or smth. I also do not think that it is a bug. It is just internal logic of RegionPlot, whatever strange. – garej Mar 8 '16 at 11:01
• And I would absolutely still call that strange internal logic of RegionPlot buggy. I would expect RegionPlot to work for all 3 of the plot ranges I wrote above, and the fact that it doesn't means that RegionPlot is doing something wrong. Nowhere in the documentation does it state that if you want to plot a one-dimensional region, you are restricted to a certain range around that region. – Jason B. Mar 8 '16 at 11:08
• Moreover, what if the user wants to make a region plot that shows both of these regions, like your first plot above, with a plot range of {{-2, 2}, {-2, 2}}? The workaround here won't allow that. They would need to make two plots and combine them with Show, like Show[ RegionPlot[x^2 + y^3 < 2 && x + y < 1, {x, -2, 2}, {y, -2, 2}], RegionPlot[{x^2 + y^3 < 2 && x + y == 1}, {x, -2, 2}, {y, -1, 3}, BoundaryStyle -> Red] ] – Jason B. Mar 8 '16 at 11:12
• Agreed, if you add , PlotRange -> {{-2, 2}, {-2, 2}} to that, it would seem to give what OP wants, and only takes 0.15 seconds on my machine. I really like the region functionality, and I know it's new, so it has room for improvement. – Jason B. Mar 8 '16 at 11:27