I want to write a Boost-Python program to take a symbolic python function from user and evaluate its derivative in my program.
For example the User provide a python file (Function.py) which defines a function like
F = sin(x)*cos(x).
Then I want to have access to F'(x) (derivative of F(x)) using symbolic differentiation ability of Sympy. I don’t want to use numerical differentiation.
Is there a way to make such a function F'(x) accessible in the C++ using Boost-Python.
I am not a SymPy expert but maybe this can help you:
You can define a Python method like:
You can create an evaluable function f1 as the derivative of f using:
This function f1 can be called from C++ using boost::python. You may create an object to function f1, call the function using the () operator and convert the result to double using extract<>.
Here is an example: