# How am I misusing EvenQ, or, how are EvenQ and (Mod[2,#]==0)& differently evaluated?

While working on a problem, I was using EvenQ in a RegionPlot. I came across this interesting case (simplified here for specificity). I expected to see a bunch of stripes, but got nothing:

RegionPlot[EvenQ[Floor[x]],{x,0,10},{y,0,10}]


However, it was fine if I used Mod to the same effect instead:

RegionPlot[Mod[Floor[x],2]==0,{x,0,10},{y,0,10}]


I also get the correct results if I substitute (Mod[Floor[#],2]==0&) for EvenQ. I also tried a version with Assert[Head[#]==Integer]& included appropriately, and it did not ever raise an error, but the Mathematica evaluation model is still a bit mystical to me in some bits.

• EvenQ[Floor[x]] evaluates to False. Your other examples don't evaluate, so they work when a value is substituted for x. Commented Mar 5, 2017 at 9:05

In version 10.1.0 under Windows:

RegionPlot[EvenQ[Floor[x]], {x, 0, 10}, {y, 0, 10}]


However as Carl Woll comments EvenQ evaluates to False when its argument is symbolic. As a rule *Q functions return True or False at the time of evaluation; they do not remain in an unevaluated form waiting for the argument to be of the right type.

Presumably in the version of Mathematica you are using RegionPlot attempts a symbolic evaluation and therefore fails on EvenQ.

If you prefer the delayed behavior you can use a mediating function with _?NumericQ:

even[n_?NumericQ] := EvenQ[n]

even[x] /. x -> 4

True


Or, theoretically, Evaluated -> False may prevent symbolic evaluation:

RegionPlot[EvenQ[Floor[x]], {x, 0, 10}, {y, 0, 10}, Evaluated -> False]

• It seems the change with RegionPlot is made in version 11, but at least the traditional Plot family is the same as before. Commented Mar 5, 2017 at 12:34