3
$\begingroup$

Consider this simplified code:

Manipulate[Ceiling[c - w/2], {c, Floor[w/2], 200}, {w, 1, 2, 1}]

It gives me a manipulator, in which I see the following content:

Ceiling[-(1/2) + 0]

But when I copy-paste it into a cell, I get this (after transforming to InputForm):

Ceiling[-1/2 + Dynamic[Floor[w$$/2], ImageSizeCache -> {87.8, {19.3, 28.66}}]]

Apparently, w$$ is a custom-generated name for w by Manipulate. But why isn't it actually evaluated for display? And how do I force final result to appear in the window?

$\endgroup$
  • $\begingroup$ You can specify an initial value, this forces immediate evaluation: Manipulate[ Ceiling[c - w/2], {{c, 1, "c"}, Floor[w/2], 200}, {w, 1, 2, 1}] $\endgroup$ – Feyre Dec 11 '16 at 16:44
  • $\begingroup$ @Feyre yes I'm aware of it, but I'd like to know what happens in the case I presented. Also, if I supply the default value, it should be the left border of the range, and I can't do it with expression depending on w for the same reason as why this doesn't work. $\endgroup$ – Ruslan Dec 11 '16 at 16:52
  • $\begingroup$ Feyre shows the correct way to fix this - just assign a starting value. The Manipulate assigns a temporary variable that needs to be set in order to evaluate the expression. So the answer to your question is: to force the final result to appear in the window, you need to initialize w. This is done exactly as Feyre shows. $\endgroup$ – bill s Dec 11 '16 at 17:03
3
$\begingroup$

I will assume Advanced Dynamic Functionality and Advanced Manipulate Functionality (and their introductory siblings) have been read. In particular the notions that Manipulate creates a DynamicModule, which is an inert piece of code that comes to life only when it is displayed by the Front End; and further, every time it is displayed by the Front End, a new instance is created, with new localized variables etc.

In

Manipulate[Ceiling[c - w/2], {c, Floor[w/2], 200}, {w, 1, 2, 1}]

the variable declaration

{c, Floor[w/2], 200}

initializes c to the expression Floor[w/2] with an uninitialized DynamicModule variable represented by w in the code, but in keeping with such variables, it is coded as the symbol w$$. inside the code Manipulate generates. Since w is a Manipulate variable, Manipulate adds a Dynamic wrapper to it. It does this automatically (and perhaps undocumentedly), and it usually is just what the user wanted (but didn't know was necessary).

The symbol w$$ is instantiated when the FE creates an instance of the DynamicModule (that is created by Manipulate), and the name is changed to a localized symbol such as FE`w$$1379 in the FE` context and with a module number appended.

When the expression Ceiling[c - w/2] is displayed inside a Dynamic in the front end, the current values of the localized w and c are shown. They are not subtracted because until you move the slider, c is the expression Dynamic[Floor[w/2]] and not a number. When you copy the expression from the displayed Manipulate, you usually get the values as displayed inside the Dynamic[] that wraps the body of the Manipulate. In this case though, what is inside the Ceiling[] is Dynamic[Floor[w/2]] - w/2 and Dynamic is HoldAll. So what Mathematica decides to copy, is the value of the second w/2 but the whole Dynamic[] expression for the first term. The Dynamic[] code is copied as Dynamic[w$$/2], which is the InputForm and not the temporary, active, Front-End form.

$\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.