Symbolic differentiation using boost proto

165 Views Asked by At

I am trying to build an EDSL that can handle symbolic differentiation. I'm having trouble when it comes to function.

struct Derivative
: or_<
    when<
        terminal<unknown>
        , boost::mpl::int_<1>()
    >
    , when<
        terminal<_>
        , boost::mpl::int_<0>()
    >
    , proto::when<
        proto::function<proto::literal<function<1> >, Derivative>
        , proto::_make_function(proto::_left, Derivative(proto::_right))
    >
    , proto::when<
        proto::function<proto::literal<function<2> >, Derivative>
        , proto::_make_function(proto::_left, Derivative(proto::_right))
    >
    , otherwise<_>
> {};

In the last to parts of this struct, I capture functions separately because I want to be able to pass something other than proto::_left as the function to be applied.

Eg. proto::literal<function<2> > corresponds to the tanh function and my context will evaluate this as tanh. But when I see tanh in my expression that I want the derivative of, in my Derivative structure, I want to be able to say

proto::when<
  proto::function<proto::literal<function<2> >, Derivative>
  , proto::_make_function(proto::literal<function<7> >, Derivative(proto::_right))
>

proto::literal<function<7> > corresponds to gradient of tanh.

When I attempt to this this, my code does not compile.

How can I correctly do this?

0

There are 0 best solutions below