# Does ContourPlot3D leak assignments inside Manipulate?

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:

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.}]

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.)

• 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. – Karsten 7. Aug 6 '15 at 2:55
• @Karsten7. Oh! You're right. (I thought I checked that, but apparently got lost in the ramification of cases.) Thanks. – Michael E2 Aug 6 '15 at 3:14
• Global values of {x, y, z} get Set in all three examples, if f is undefined. – Karsten 7. Aug 6 '15 at 3:29
• 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}}]. – Karsten 7. Aug 6 '15 at 4:07
• You might also try ContourPlot3D; SystemProtoPlotDumpiContourPlot3D[1, {x, 1, 3}, {y, -1, 1}, {z, -1, 1}, PlotLabel -> {f, {x, y, z}}]. – Karsten 7. Aug 6 '15 at 4:50