On 7/20/07, sen1 at math.msu.edu <sen1 at math.msu.edu> wrote:
> This brings up a question I have had for some time.
>
> What are the differences (if any) among the following
>
> g(x):= ''(diff(f(x),x));
Evaluates diff(f(x),x) at the time of *defining* g. So if the
definition of f changes later, the definition of g will not reflect
that.
> g(u):= subst(x=u, diff(f(x),x));
Differentiates f at the time of *execution* of g, and substitutes a
given value. If f is redefined after g is defined, the new definition
of f will be used.
> g(u):= ev(diff(f(x),x), u = x);
I think you mean ... x=u. This will only work if u is a variable
name, since ev will substitute the value of u into both the x of f(x)
and the x of x (the variable to differentiate by). This is rarely what
you want. You also get into the mess that is ev, so that other
surprising things may happen.
By the way, all of these depend on x not having a value. To use a
dummy variable inside a function like this, it is more prudent to
quote it or make it local, e.g.
g(u):= subst( 'x=u, diff(f('x),'x));
or
g(u):= block([],local(x), subst(x=u, diff(f(x),x)) );
This is all rather messy, because Maxima really is set up to work with
expressions more than with functions. The subst approach is probably
the cleanest, but I concede that it is verbose and clumsy. The ''()
construction is handy, but the idea is subtle and hard to explain to
new users, I think.
-s