Subject: Re: [boost] [math] Does any one interesting in calculating derivative for a expression automatically?
From: Dongfei Yin (yin.dongfei_at_[hidden])
Date: 2009-03-06 08:09:48
The basic theory is same, but to do it at compile time, it can not
be as simple as run time.
CppAD do it during run time. type in run time is not so important as
It can be done not only by operator overloading, but also by
template specializing. As I say,
when you get d(_x * _x, _x), that is a functor, then you want d(d(_x *
_x, _x), _x), you see that there is no chance for operator to do anything,
that means the result of d(_x * _x, _x) should be simplified before
d(d(_x * _x, _x), _x) by template secializeing.
Another example, Define hypersphere<N> as (pi^(N/2)*r^N) / gamma(N/2
+ 1), suppose N is known at compile time,if all the type are under
control, think about (double_<pi>^(int_<N>/2)*var(r)^int_<N> /
gamma(int_<N)>/2 + 1), all the type can be
controlled, then N/2 can be calculated during compile time. by
if just using operator overloading, it can only be done during run time.
you can not overload operator+(int, int) (just a example, actually, it
can be optimized by compiler automatically).
> While not strictly the same, there are all sorts of C++ based packages
> out there for doing this kind of thing. The approach taken is
> 'automatic differentiation', and it basically works by applying the
> chain rule to every individual step in a sequence of operations. One
> approach to doing this is through operator overloading, and replacing
> the underlying 'double' class with something that maintains the
> appropriate state. There are already some nice open source packages out
> there for doing this. More info:
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk