How to get diff to yield result in terms of original function



> I wonder if there's a way to get something like
> 
>   f(x) := exp(g(x))$
>   diff(f(x), x);
> 
> to yield f(x)*'diff(g(x),x).
...
> Is there a flag to tell diff to express derivatives of
> exponentials in terms of the original function or expression? 

You are misunderstanding how functions work in Maxima.  Maxima supports
mathematical functions, and it supports programming functions, both
using the same syntax, but they are quite different.  Mathematical
functions are simplified, programming functions are evaluated.

     sin(0) => 0                   -- simplification
     factor(x^2-1) => (x-1)*(x+1)  -- evaluation

If a function has not been defined, it is a mathematical function:

     g(y-1) => y-1

One can write and manipulate equations involving mathematical functions:

     g(x)=x^3

This is an equation like any other, and has no global effects.  In
particular, it is perfectly possible to write inconsistent equations,
and g(x) can appear on both the left and the right hand side of
equations:

     [ g(x)=0, g(x)=x, g(x)=g(x)+1 ]

Just because you have previously written g(x)=x^3 does NOT mean that
these expressions are equivalent to [ x^3=0, x^3=x, x^3=x^3+1 ].

If on the other hand a function has been defined, it is a programming
function:

     f(x) := x^3
     f(y-1) => (y-1)^3

The connection between the expressions "f(y)" and "(y-1)^3" is that when
you evaluate the first, you get the second.  Once the value x^3 has been
returned, there is *no memory* of where it came from, no connection to
the programming function 'f'.

It *is* also possible to treat a programming function as a mathematical
function using the noun form mechanism:

     'f(y-1) => 'f(y-1)

But when it is being treated as a mathematical function in this way,
there is no connection to the formula "x^3".  I suppose various
mechanisms could be designed, but off the top of my head, I am not sure
what they would be.

So diff cannot possibly do what you are asking it to do, since diff
never even sees 'f(x)' -- all it sees is 'exp(g(x))', and it has no clue
that this is related to f(x).

You can however get the results you want using gradef, though there are
some tricks there, too:

   /* do not define the functions f and g */
   /*  but tell Maxima about their derivatives */
   gradef(f(x),f(x)*g1(x))
   gradef(g(x),g1(x))
   /* can't use 'diff(g(x),x) here (bug 873301), so g1 is a workaround
*/

Now you can define the explicit form of f as a *separate* function:

   explicit_f(x):= exp(g(x))

and only substitute f selectively for explicit_f, when and where it is
useful.

Does this solve your problem?

       -s