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 (https://github.com/josdejong/mathjs/blob/master/lib/function/algebra/derivative.js#L570-L596). Is this by design (and thus, are multi-branching operators not really supported), or is this just a bug in the derivative implementation?
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 ofx * x * x:Using the above initialization code, we can then process the expression using the standard Math.js functions:
However, it seems like
derivativehas an issue when processing such multi-branching operators:Looking into the code, it seems like the
derivativefunction just assumes that the operators only have one or two arguments (https://github.com/josdejong/mathjs/blob/master/lib/function/algebra/derivative.js#L570-L596). Is this by design (and thus, are multi-branching operators not really supported), or is this just a bug in thederivativeimplementation?