5

I'm having trouble understanding why the following RegionPlot code produces results:

pred[x_, y_] := 
 0 < x <= 0.5 ∧ EvenQ@Floor[(y - 0.05)/0.1] ∨ 
  0.5 < x < 1 ∧ EvenQ@Floor[y/0.1]
RegionPlot[pred[x, y], {x, 0, 1}, {y, 0, 1}, 
 PlotRange -> {{0, 1}, {0, 1}}, PlotPoints -> 100]

Mathematica graphics

while this code using ImplicitRegion produces an empty region:

Ω1 = 
 ImplicitRegion[
  0 < x <= 0.5 ∧ EvenQ@Floor[(y - 0.05)/0.1] ∨ 
   0.5 < x < 1 ∧ EvenQ@Floor[y/0.1], {{x, 0, 1}, {y, 0, 1}}]
RegionPlot[
 RegionMember[Ω1, {x, y}], {x, 0, 1}, {y, 0, 1}, 
 PlotRange -> {{0, 1}, {0, 1}}, PlotPoints -> 100]

Mathematica graphics

It appears related to the use of EvenQ. So a possible workaround might be replacing with Mod[#,2]==0&.

Jason B.
  • 68,381
  • 3
  • 139
  • 286
unlikely
  • 7,103
  • 20
  • 52
  • Did you try it with Mod[#,2]==0&? Wondering about the "might". Also, region functionality should be getting a significant update in V10.0.2, which seems to be out (I don't have access yet). I can confirm this problem exists in V10.0.1. – Michael E2 Dec 11 '14 at 18:15
  • 1
    ImplicitRegion evaluates EvenQ on symbolic input, which returns False, since an expression with a symbol is not an even integral. – Michael E2 Dec 11 '14 at 18:20
  • @MichaelE2 yes, I tried, and Mod is fine. About the "might": I'm not fluent in english and I accepted a suggested edit of my original post. If this behavior is by design I'll go for Mod, thanks. – unlikely Dec 11 '14 at 21:30
  • @MichaelE2 - as seen in this code snippet, using Mod isn't a perfect solution. It still produces an ImplicitRegion that isn't plottable directly. Further, what attribute does EvenQ have that Equal does not, such that Equal[x, 3] remains unevaluated while EvenQ[x] gives False? – Jason B. Jan 05 '16 at 13:58
  • @JasonB Usually, and perhaps always, system functions that end in Q will always return True or False. AFAIK, this is done programmatically (not through Attributes per se, if that's what you meant by attributes). For example, if you wanted an EqualQ, you could use TrueQ@ Equal[x, 3], which would return False if Equal[x, 3] does not evaluate to True. (This Q property means, for instance, that you can count If evaluating one of its next two arguments and so forth.) – Michael E2 Jan 05 '16 at 14:44
  • @JasonB Regions are still not completely done, it seems (but I'm still on 10.3.0). Adding {x, y} \[Element] Reals to your pred allows DiscretizeRegion[\[CapitalOmega]] to work (but still not RegionPlot). One issue seems to be that y == 1 contains a boundary of a segment that lies above y == 1. If you change the ImplicitRegion to {y, 0, 0.999} and add the {x, y} \[Element] Reals, RegionPlot works. -- You can also add the condition 0 <= y < 1 to pred. – Michael E2 Jan 05 '16 at 14:53

0 Answers0