I'm trying to find the best method/algorithm for computing the derivative of a typed mathematical function in Javascript symbolically. Each equation will only have a single variable. I started with a typed expression which is then converted to RPN (reverse polish notation) using Dijkstra's shunting-yard algorithm to convert the infix equation into a postfix one. My next ideas was to use this to create an expression tree, which ends up looking something like this:
Equation: 25x^2 + 61x + 3
RPN: 25 x 2 ^ * 61 x * + 3 +
I looked at what the "solved" expression tree should look like to get an idea of what needed to be done:
Derivative (without simplification): x^(2-1)*2*25+61
I was thinking I could recursively apply the differentiation rules (product, quotient, sum, difference, etc) using a postorder traversal and replace the "nodes" depending on the operator.
However, after looking at the derivative's expression tree, I realized that I couldn't easily apply something like the product rule to a node that still had children (ie. this)
So my primary question is: Are there any known algorithms similar to shunting-yard for efficiently computing symbolic derivatives programmatically?