The simple command x=0;Dynamic[x=x+1]

• To: mathgroup at smc.vnet.net
• Subject: [mg124787] The simple command x=0;Dynamic[x=x+1]
• From: Fred Simons <f.h.simons at tue.nl>
• Date: Tue, 7 Feb 2012 04:00:15 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com

```For a long time I thought that the result of the command x=0;
Dynamic[x=x+1] was easy to explain: at each update the value of x
changes, so it will be updated again, and so on, so we see a fastly
increasing counter. Now I start realizing that it is not that trivial.
At least there are some features that puzzle me and I hope someone can
come up with an explanation.

The first line of the next commands creates something like a clock. The
second line gives the command that I am trying to understand. It shows
that the value of x increases with a speed of about 600 per second (on
my computer, this is system dependent!), instead of the speed of about
20 that I would expect, since updating takes place at about that rate.
Why is it so fast? We are not reading an infinite loop (I think); when x
has a value, execution of the command x=x+1 is not a problem.

n=0;Dynamic[n=n+1, TrackedSymbols->{}, UpdateInterval->1]
x=0; Dynamic[x=x+1]

Remove the above output and have a look at the following, where we have
two identical constructions, with different variables. The speed now
slows down to about 400 per second.

n=0;Dynamic[n=n+1, TrackedSymbols->{}, UpdateInterval->1]
x=0; Dynamic[x=x+1, SynchronousUpdating->True]
y=0; Dynamic[y=y+1, SynchronousUpdating->True]

Again remove the output. In the next commands we set one of the two
dynamics to queued updating. The effect is remarkable. It slows down the
synchronized dynamics to a speed of about 100 per second. Moreover, for
some or other reason the synchronized dynamics seems to be exactly twice
as fast as the queued one, with a speed of 50 per second.

n=0; Dynamic[n=n+1, TrackedSymbols->{}, UpdateInterval->1]
x=0; Dynamic[x=x+1, SynchronousUpdating->True]
y=0; Dynamic[y=y+1, SynchronousUpdating->False]

Finally, when both are queued, the speed of both decreases to about 30
per second:

n=0; Dynamic[n=n+1, TrackedSymbols->{}, UpdateInterval->1]
x=0; Dynamic[x=x+1, SynchronousUpdating->False]
y=0; Dynamic[y=y+1, SynchronousUpdating->False]

But in all cases, the speed is higher than the refresh rate. Very likely
I overlook something simple, but at the moment I have only a very vague
idea what could be going on here.

All comment on this behaviour is highly appreciated.

Many thanks in advance and kind regards,

Fred Simons
Eindhoven University of Technology

```

• Prev by Date: Re: Mathematica question
• Next by Date: need to find polyhedrons with less than a 24 vertex array in PolyhedronData[]
• Previous by thread: Re: recursion won't work for some reason
• Next by thread: Re: The simple command x=0;Dynamic[x=x+1]