Multi-Branching Operators and `derivative` #1002

Closed
opened this Issue Jan 4, 2018 · 2 comments

Projects
None yet
3 participants
Contributor

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 (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?
Collaborator

firepick1 commented Jan 4, 2018

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

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.

Merged

Closed