5

Bug introduced in 9.0 and fixed in 9.0.1


In Mathematica 7 it is very easy to conditionally suppress plotting of individual lines using If:

Plot[{
  If[x^2 < 2, x^2],
  If[Exp[x] > x^2, Exp[x]],
  If[False, x]                (* check recommended by Rahul *)
 },
 {x, -2, 2},
 PlotStyle -> Thick, Frame -> True]

enter image description here

Or more verbosely using Piecewise and Indeterminate:

Plot[{
  Piecewise[{{x^2, x^2 < 2}}, Indeterminate],
  Piecewise[{{Exp[x], Exp[x] > x^2}}, Indeterminate],
  Piecewise[{{x, False}}, Indeterminate]      (* check recommended by Rahul *)
  },
 {x, -2, 2},
 PlotStyle -> Thick, Frame -> True]

enter image description here

It is reported that neither method works in version 9.0.0 (at least on OSX.) Furthermore it is reported that my attempt using ConditionalExpression also fails:

Plot[{
  ConditionalExpression[x^2, x^2 < 2],
  ConditionalExpression[Exp[x], Exp[x] > x^2]
  },
 {x, -2, 2},
 PlotStyle -> Thick, Frame -> True]

Plotting a zero is reported to "work" but that is hardly a solution:

Plot[{
  Piecewise[{{x^2, x^2 < 2}}],
  Piecewise[{{Exp[x], Exp[x] > x^2}}]
  },
 {x, -2, 2},
 PlotStyle -> Thick, Frame -> True]

enter image description here

1. Is this indeed a bug in version 9.0.0?

2. Is there a workaround for the affected systems?

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
  • @Szabolcs Which version are you using? A recent comment indicates this may be a bug in version 9.0.0. – Mr.Wizard May 16 '14 at 17:34
  • 2
    @Szabolcs I agree - it works for me on OSX and version 9.0.1. – Jens May 16 '14 at 17:34
  • @Jens Thanks; it seems it is a bug of limited scope. Could someone with v9.0.0 NOT on OSX give this a try? – Mr.Wizard May 16 '14 at 17:35
  • Too bad, I would have loved the opportunity to bash version 9, since I still prefer version 8 for most things in real life... – Jens May 16 '14 at 17:36
  • 2
    @Mr.Wizard I'm using 9.0.1 (from the version string it's not very clear but 9.0.0 was released in November, and 9.0.1 in January). 9.0.0 had lots of bugs and I think no one should be using it ... there are many examples of bugs fixed in 9.0.1 on this site. – Szabolcs May 16 '14 at 17:36
  • @Szabolcs Thanks for your help. – Mr.Wizard May 16 '14 at 17:37
  • I do wonder if WRI gives free point updates for non-premiere-service users (I don't know) – Szabolcs May 16 '14 at 17:39
  • What I remember -- I'm no longer at home with my Mac laptop to try these out -- is that the problem only appears if there is a function which is Undefined everywhere on the plot, so no line can be drawn for it at all. @Szabolcs, can you try it again plotting, say, {If[x^2 < 2, x^2], If[False, x]}? –  May 16 '14 at 17:39
  • @Rahul Interesting; I shall include that. – Mr.Wizard May 16 '14 at 17:42
  • @RahulNarain You are correct - I just checked on a different computer with version 9.0.0, and with your line included it produces a blank plot. But without that line, the plot seems to work fine even on that version. – Jens May 16 '14 at 17:48
  • 2
    Going by Jens's and Szabolcs's comments it does seem like a bug that was fixed in 9.0.1 then. I didn't know 9.0.0 was so well known to be bug-ridden. –  May 16 '14 at 17:54
  • @Rahul Almost everything tagged with [tag:version-9.0.0] is about bugs introduced in 9.0.0 and fixed in 9.0.1 and you'll find additional examples (both bugs and annoyances) in the chatlogs. – Szabolcs May 16 '14 at 19:00
  • V.9.0.0 was so buggy that WRI offered a free upgrade to V9.0.1 to all V.9.0.0 license holders, not just to Premier Service subscribers. – m_goldberg May 17 '14 at 01:41

2 Answers2

2

Since this bug seems to be tied directly to the appearance of Indeterminate as the only available function value in the plot range, it could perhaps be considered a work-around to replace Indeterminate by another "quantity" that behaves the same way as Indeterminate but doesn't cause the whole display of all other functions to be suppressed.

I tried the following, and it works on version 9.0.0:

Plot[{Piecewise[{{x^2,x^2<2}},Indeterminate],
  Piecewise[{{Exp[x],Exp[x]>x^2}},Indeterminate],
  Piecewise[{{x,False}},I]      (*modified check recommended by Rahul*)},
 {x,-2,2},
 PlotStyle->Thick,Frame->True]

Here, I used the imaginary unit I to produce the same effect as Indeterminate, and the remaining plots do still get displayed.

To make this more general, maybe one can use a replacement rule like this:

Plot[Evaluate[{Piecewise[{{x^2, x^2 < 2}}, Indeterminate], 
    Piecewise[{{Exp[x], Exp[x] > x^2}}, Indeterminate], 
    Piecewise[{{x, False}}, 
     Indeterminate]      (*modified check recommended by Rahul*)} /. 
   Indeterminate -> I], {x, -2, 2}, PlotStyle -> Thick, Frame -> True]
Jens
  • 97,245
  • 7
  • 213
  • 499
0

In my Version 9.0 for Microsoft Windows (64-bit) (November 20, 2012) Release ID 9.0.0.0 (3868239, 384640), Patch level 0,

Plot[{ConditionalExpression[x^2,x^2<2],ConditionalExpression[Exp[x],Exp[x]>x^2]},{x,-2,2},PlotStyle->Thick,Frame->True]  

works normally, but neither

Plot[{If[x^2<2,x^2],If[Exp[x]>x^2,Exp[x]],If[False,x]                (*check recommended by Rahul*)},{x,-2,2},PlotStyle->Thick,Frame->True]  

nor

Plot[{Piecewise[{{x^2,x^2<2}},Indeterminate],Piecewise[{{Exp[x],Exp[x]>x^2}},Indeterminate],Piecewise[{{x,False}},Indeterminate]      (*check recommended by Rahul*)},{x,-2,2},PlotStyle->Thick,Frame->True]

do : only a frame for x=-2 to +2 and y from -1 to +1 get plotted (with x=0 and y=0 line).
Does that make sense?

Wouter
  • 1,343
  • 7
  • 11