New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-Branching Operators and `derivative` #1002

joelhoover opened this Issue Jan 4, 2018 · 2 comments


None yet
3 participants

joelhoover commented Jan 4, 2018

It seems like Math.js supports the ability to have OperatorNode (specifically with operator + or *) have more than two children. For example, the following is a valid representation of x * x * x:

var xNode = new math.expression.node.SymbolNode("x");
var mult3 = new math.expression.node.OperatorNode("*", "multiply", [xNode, xNode, xNode]);

Using the above initialization code, we can then process the expression using the standard Math.js functions:

mult3.toString(); // Yields: x * x * x
mult3.eval({x: 2}); // Yields: 8
math.simplify(mult3); // Yields: x ^ 3

However, it seems like derivative has an issue when processing such multi-branching operators:

math.derivative(mult3, "x"); // Yields: 2 * x <=== Should be 3 * x ^ 2

Looking into the code, it seems like the derivative function just assumes that the operators only have one or two arguments ( Is this by design (and thus, are multi-branching operators not really supported), or is this just a bug in the derivative implementation?


This comment has been minimized.


firepick1 commented Jan 4, 2018

Multi-branching ops will also likely mess up simplify. Full support for multi-branch will probably require much effort.


This comment has been minimized.


harrysarson commented Jan 4, 2018

I think this could be solved by rewriting the derivative of sums and products to allow for more than two arguments. This would not increase the complexity of derivative too much I don't think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment