[GiNaC-devel] Implicit derivation of functions (re-submission)

Richard B. Kreckel kreckel at in.terlu.de
Wed Dec 31 19:41:11 CET 2014


Dear Vladimir,

On 10/29/2014 11:25 AM, Vladimir V. Kisil wrote:
> 	I am resending the patch for implicit derivation of
>   functions. Quote from the previous submission:
> http://www.ginac.de/pipermail/ginac-devel/2013-November/002053.html
> 
> "   I wish to propose another GiNaC extension. Consider function
>   abs(). Since it can be presented as abs(z)=sqrt(z*z.conjugate()), the
>   derivative of abs(f) may be calculated as
> 
>   (abs(f))'=(f'*f.conjugate()+f*f'.conjugate())/2/abs(f)
> 
>   However, this formula cannot be packed into the present GiNaC code,
>   since it only knows about the chain rule. Thus, the patch adds a
>   possibility to define derivatives of functions in some general
>   expression. In particular, the above derivative of abs() is
>   defined. Example:
> 
>   cout << abs(log(z)).diff(z) << endl;
>   // (before) -> D[0](abs)(log(z))*z^(-1)
>   // (now) -> 1/2*(z^(-1)*conjugate(log(z))+log(z)*conjugate(z)^(-1))*abs(log(z))^(-1)
> "
>  This issue independently appeared in this discussion:
> http://www.ginac.de/pipermail/ginac-devel/2014-April/002106.html
> 
>   If it is not included in the core code, then a user need to redefine
>   the entire GiNaC function class to have this feature.

Thanks a lot for re-submitting this interesting patch about implicit
derivatives! I've had a close look at it now.

It is interesting because the problem it solves does indeed seem to be
somewhat universal.

In hindsight it may have been a mistake to teach every function its
formal derivative only and perform the chain rule in function::derivative().

Your proposal is to have two ways to implement a function's derivative:
1) by registering the existing derivative_func (pure formal derivative)
2) or your new impl_derivative_func (smart derivative, has to care about
chain rule)

I wonder if there is a way to make this more uniform. What do you think?

Even if there is no way to improve the uniformity of derivatives, your
patch has three (very minor) problems which should be fixed before
committing: The method should be documented in the tutorial, there ought
to be a test case, and there should really be an impl_derivative_func
for the Order function instead of handling this as another special case
in function::derivative().

Best wishes
    -richard.
-- 
Richard B. Kreckel
<http://in.terlu.de/~kreckel/>


More information about the GiNaC-devel mailing list