A few words about differentiation...

Richard B. Kreckel kreckel at ThEP.Physik.Uni-Mainz.DE
Mon Nov 29 22:19:58 CET 1999


As everybody knows we don't have inert differentiation like Maple has for
instance (lprint(diff(f(x),x)); returns diff(f(x),x) there), we are always
applying the full chain rule, end of story.  :-/ If a function does not
know how to be differentiated it may throw an exception instead, this is
acceptable.  However, when trying to implement differentiation for the
polygamma functions psi(n,x) I ran into a problem with that policy since
differentiating wrt the first argument doesn't make much sense there (it's
normally just an integer parameter).  But when one differentiates wrt x,
what happens is this (function::pdiff is the partial differentiation):
psi(n,x).diff(x) -> pdiff(psi,0)*n.diff(x) + pdiff(psi,1)*x.diff(x)
so differentiation wrt n comes in again through the back door.  I have
worked around this problem by changing function::diff().  In the above
case it would see that n.diff(x).is_zero() and then refrain from trying
to compute pdiff(psi,0).  It seems to work so far.  In ginsh, this allows
me to write:

> diff(psi(1,x),x);
psi(2,x)
> diff(psi(n,x),x);
psi(n+1,x)
> diff(psi(n,x),n);
cannot diff psi(n,x) with respect to n

Any objections?  (It's in CVS, for those of you who have access to it.)
So, once more we can live without inert differentiation, let's see how
long...

On another note: who has implemented atan2::diff() and why didn't it
return something slightly simpler (i.e. x/(x^2+y^2) instead of
1/x/(1+y^2/x^2))?  Is there some reason for this??  Did I break
anything???

Cheers
    -rbk.
-- 
Richard Kreckel
<Richard.Kreckel at Uni-Mainz.DE>
<http://wwwthep.physik.uni-mainz.de/~kreckel/>





More information about the GiNaC-devel mailing list