# Manipulate Continuously Evaluates

Paring a much more complicated example down I came to an MWE:

Manipulate[
x = {a, a}*# & /@ {{1, 1}, {2, 2}};
x = {1, 0}*# & /@ x;
, {a, 1, 10}
]


runs continuously - the cell bracket is black. The odd thing is:

Manipulate[
x = {a, a}*# & /@ {{1, 1}, {2, 2}};
x = {1, 1}*# & /@ x;
, {a, 1, 10}
]


does NOT run continuously. All I changed here is multiplication done in the second line.

The problem I'm running into is in a more complicated section of code where Manipulate ends up slowing to a crawl. In my complicated example I was able to fix the behavior by calculating each variable in a single line of computation. i.e.

Manipulate[
x = {1, 0}*# & /@ ({a, a}*# & /@ {{1, 1}, {2, 2}});
, {a, 1, 10}
]


Any ideas would be appreciated. I suspect a bug. Mac 10.13.6 MMA ver 12.0.0.0

Manipulate[
x = {a, a}*# & /@ {{1, 1}, {2, 2}};
x = {1, 0}*# & /@ x;
, {a, 1, 10}
]


Then since a=1 initially, then the first line x = {a, a}*# & /@ {{1, 1}, {2, 2}} produces x={{1, 1}, {2, 2}} and then the second line x = {1, 0}*# & /@ x produces x={{1, 0}, {2, 0}}, so x has changed. Because of this, and since you did not specify which symbol to track, then Manipulate reevaluated the expression again. And x changed again, and so on.

But when you had

Manipulate[
x = {a, a}*# & /@ {{1, 1}, {2, 2}};
x = {1, 1}*# & /@ x;
, {a, 1, 10}
]


And since a=1 initially, then first line produces x={{1, 1}, {2, 2}} as before but now the second line gives x={{1, 1}, {2, 2}}, so x did not change. So no need to re evaluate Manipulate expression again.

Solution is to always use tracked symbols option to tell Manipulate explicitly which symbol to track its changes.

Manipulate[
x = {a, a}*# & /@ {{1, 1}, {2, 2}};
x = {1, 0}*# & /@ x;
,
{a, 1, 10},
TrackedSymbols :> {a}]


Now it works OK

The reason the continuous updating happens is that the Manipulate is being re-evaluated each time any of its variables changes. In this case, you have x = (some function of x), and so it continuously updates. A simple fix is:

Manipulate[y = {a, a}*# & /@ {{1, 1}, {2, 2}};
x = {1, 1}*# & /@ y, {a, 1, 10}]


Now it seems stable in all the cases.