4
$\begingroup$

Why the following two codes plot different graphs?

Plot[Floor[x], {x, -5, 5}]
Plot[Floor[x] /. a -> b, {x, -5, 5}]

graphs where the second plot has joins

a and b did not have any assigned value.

It is same for Floor, Ceiling, Round and IntegerPart... all are stepwise function. But for example we have another stepwise function PrimePi and the graphs are same for both cases.

What is wrong with Mathematica? Notice that "/. a -> b" does nothing at all, you can replace it with anything as long the "/." is there.

$\endgroup$
  • 1
    $\begingroup$ This is determined by the Exclusions option. The function you plot has 2 new variables so it doesn't know what not to plot. $\endgroup$ – Carl Lange Nov 26 '18 at 19:02
  • $\begingroup$ It is not because of variables a and b. You can also have this: Plot[Floor[x] /. (1 -> 1), {x, -5, 5}] $\endgroup$ – azerbajdzan Nov 26 '18 at 19:04
  • $\begingroup$ Definitely it has something to do with Exclusions, but all stepwise functions should behave the same when plotted. Why is PrimePi treated different than Floor? $\endgroup$ – azerbajdzan Nov 26 '18 at 19:08
  • $\begingroup$ You're right; that's definitely an interesting corner case! $\endgroup$ – Carl Lange Nov 26 '18 at 19:20
  • 1
    $\begingroup$ It may have to do with the HoldAll attribute of Plot. Plot[Evaluate[func[x] /. a -> b], {x, -5, 5}] plots the same as Plot[Floor[x], {x, -5, 5}]. Presumably, the HoldAll prevents the automatic application of the Exclusions with the exception of the PrimePi case. $\endgroup$ – Bob Hanlon Nov 26 '18 at 19:50
6
$\begingroup$

The exclusions mechanism avoids inputs that appear to be "programmatic", which includes the following general categories (and a few others):

  • numeric solvers: NIntegrate, FindMinimum, NDSolve, ...
  • looping constructs: Map, Table, While, Nest, ...
  • assignments: Set, Increment, ...
  • replacements: Replace, ReplaceAll, ...
  • "functions": CompiledFunction, InterpolatingFunction, ...
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.