I considered the following function:
sin[x_] := Module[{},
Print["x=", x];
Sin[x]
]
in Mathematica. Next, I tried to plot it using:
Plot[sin[t], {t, 0, 2 Pi}]
Surprisingly, the first three lines of output are:
x=0.000128356
x=t
x=1.28228*10^-7
Can someone explain this behavior? In this case it doesn't cause a problem, but in my "real" case it does.
Summary
acl's answer below offers, at its very beginning a solution to the specific problem. In very-short, the reason that this x=t
appears is hidden somewhere in the way Mathematica evaluates the functions. The answers below provide interesting insight into the way it works.
The interested reader should read all the answers and details below, they are invaluable, although might be behind the reach of some of the readers (like, partially, in my case).