5
$\begingroup$

Update 5 Aug 2015 -- Karsten 7. found a minimal example of leaking not involving Manipulate, so the role of Manipulate seems more obscure. See notes 2 and 3 below.

The question, Why don't rules applied inside ContourPlot3D work?, suggests using Evaluate when the equation in ContourPlot3D involves ReplaceAll. But in that case, ReplaceAll was the head of the first argument and ContourPlot3D returned unevaluated. Both these forms, with or without Evaluate work fine.

(* Evaluate: works *)
Clear[f, x, y, z];
f = x^3 + x z^2 - 3 x^2 + y^2 + 2 z^2;
Manipulate[
 ContourPlot3D[
  f == (f + level /. Thread[{x, y, z} -> {2, 0, 0}]) // Evaluate,
  {x, 1, 3}, {y, -1, 1}, {z, -1, 1}, PlotLabel -> {f, {x, y, z}}],
 {{level, 0.}, -1., 1.}]

(* no Evaluate, level init. 0.1: works *)
Clear[f, x, y, z];
f = x^3 + x z^2 - 3 x^2 + y^2 + 2 z^2;
Manipulate[
 ContourPlot3D[f == (f + level /. Thread[{x, y, z} -> {2, 0, 0}]),
  {x, 1, 3}, {y, -1, 1}, {z, -1, 1}, PlotLabel -> {f, {x, y, z}}],
 {{level, 0.1}, -1., 1.}]

They produce, after setting level to 0.1 in the first case, this:

Mathematica graphics

But if I do not use Evaluate and the variable level is initialized to 0. instead of 0.1, the global variables x, y, and z are assigned values. The values are the coordinates of the far corner of the plot domain. This remains through even if the ranges for x, y, or z are changed. Another significant difference is that the plot disappears when the control is active, which does not happen in the other versions.

(* no Evaluate, level init. 0.: 
   {x,y,z} set, control active -> no plot, inactive -> green plot *)
Clear[f, x, y, z];
f = x^3 + x z^2 - 3 x^2 + y^2 + 2 z^2;
Manipulate[
 ContourPlot3D[f == (f + level /. Thread[{x, y, z} -> {2, 0, 0}]),
  {x, 1, 3}, {y, -1, 1}, {z, -1, 1}, PlotLabel -> {f, {x, y, z}}],
 {{level, 0.}, -1., 1.}]

Mathematica graphics

Check x, y, z:

{x, y, z}
(*  {3., 1., 1.}  *)

Why does this happen? I can see how to avoid it. Is there are reason one should expect the values of x etc. to leak out, or is it a bug?

Notes:

  1. I've tested it on V10.2 and V9.0.1, OSX. Both versions give similar results (the coloring is different, of course).

  2. Karsten 7. points out that the symptom of leaking occurs with just ContourPlot3D[1, {x, 0, 1}, {y, 0, 2}, {z, 0, 3}]. However, the leaking does not occur in V9 for this form; instead a error is produced ("Rest::norest: Cannot take the rest of expression {} with length zero.")

  3. The ContourPlot3D commands above when outside of Manipulate do not leak assignment. (I used With[{level = 0.}, ContourPlot3D[...]].) If x, y, and z all have a value, then I get a green plot, unless Evaluate is used, but still no leaking.

  4. The green color is suggestive (of three contours being plotted). But I don't see why three contours should be expected. Perhaps it's because three contours are the default. As a hint, though, I find it obscure.

  5. For the purposes of this question, I wish to ignore what happens when you substitute a minus for Equal, unless it explains what happens in this case. (I think there is a connection, but the cases to keep straight might get unmanageable.)

$\endgroup$
  • 1
    $\begingroup$ The (* no Evaluate, level init. 0.1: works *) example behaves like your last code block after changing level to 0. or some value close to 0. using the Slider or the Step Backward button of the Manipulator, but not when using the InputField or a Label. $\endgroup$ – Karsten 7. Aug 6 '15 at 2:55
  • $\begingroup$ @Karsten7. Oh! You're right. (I thought I checked that, but apparently got lost in the ramification of cases.) Thanks. $\endgroup$ – Michael E2 Aug 6 '15 at 3:14
  • 1
    $\begingroup$ Global values of {x, y, z} get Set in all three examples, if f is undefined. $\endgroup$ – Karsten 7. Aug 6 '15 at 3:29
  • $\begingroup$ ContourPlot3D does even leak outside of Manipulate. For example: ContourPlot3D[1, {x, 1, 3}, {y, -1, 1}, {z, -1, 1}, PlotLabel -> {f, {x, y, z}}]. $\endgroup$ – Karsten 7. Aug 6 '15 at 4:07
  • $\begingroup$ You might also try ContourPlot3D; System`ProtoPlotDump`iContourPlot3D[1, {x, 1, 3}, {y, -1, 1}, {z, -1, 1}, PlotLabel -> {f, {x, y, z}}]. $\endgroup$ – Karsten 7. Aug 6 '15 at 4:50

Your Answer

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

Browse other questions tagged or ask your own question.