I found these two libraries: - muparser - symbolicc++
The first one is capable of efficient parsing of mathematical expression, so that with minimal wrapping I could make a parser object so that
parser my_parser("1/2 * x^2");
cout<<myparser(2)<<endl;
Would result in it printing 2.0. This is wonderful, but it only works with doubles, right?
The second one implements the Symbolic object so that on example I can do something like:
Symbolic x("x");
Symbolic x2 = x^2;
cout<<df(x2, x)<<endl;
Resulting in 2.0*x. So it is capable of differentiating expressions, which is fine.
What I would need to do is a mix of the two! I need a function to be parsed and then differentiated, so that I could do something like:
cout<<df("1/2 * x^2", "x")<<endl;
And I would like it to print out 2.0*x as well.
Is it possible to do something like this? In principle, if muparser could work on any object, I could simply run an expression on Symbolic objects, and then differentiate them. But I couldn't make something like this work.
So is there any other workaround? I need something that takes an input string with an expression and returns an output string with the derivative of that expression.
Thank you!