diff --git a/src/function/algebra/derivative.js b/src/function/algebra/derivative.js index 6cce7066f..8f3f95e02 100644 --- a/src/function/algebra/derivative.js +++ b/src/function/algebra/derivative.js @@ -300,6 +300,10 @@ function factory (type, config, load, typed) { ]), constNodes) } break + case 'pow': + constNodes[arg1] = constNodes[node.args[1]] + // Pass to pow operator node parser + return _derivative(new OperatorNode('^', 'pow', [arg0, node.args[1]]), constNodes) case 'exp': // d/dx(e^x) = e^x funcDerivative = new FunctionNode('exp', [arg0.clone()]) @@ -746,7 +750,7 @@ function factory (type, config, load, typed) { */ function funcArgsCheck (node) { // TODO add min, max etc - if ((node.name === 'log' || node.name === 'nthRoot') && node.args.length === 2) { + if ((node.name === 'log' || node.name === 'nthRoot' || node.name === 'pow') && node.args.length === 2) { return } diff --git a/test/function/algebra/derivative.test.js b/test/function/algebra/derivative.test.js index 16f82a589..db3ef6589 100644 --- a/test/function/algebra/derivative.test.js +++ b/test/function/algebra/derivative.test.js @@ -160,6 +160,16 @@ describe('derivative', function () { compareString(derivativeWithoutSimplify('acoth((2x))', 'x'), '-(2 * 1) / (1 - (2 x) ^ 2)') compareString(derivativeWithoutSimplify('abs(2x)', 'x'), '2 * 1 * abs(2 x) / (2 x)') + // See power operator tests above + compareString(derivativeWithoutSimplify('pow(0, 2^x + x^3 + 2)', 'x'), '0') + compareString(derivativeWithoutSimplify('pow(1, 2^x + x^3 + 2)', 'x'), '0') + compareString(derivativeWithoutSimplify('pow(10, 2x + 2)', 'x'), '10 ^ (2 x + 2) * log(10) * (2 * 1 + 0)') + compareString(derivativeWithoutSimplify('pow(x^x^x^x, 0)', 'x'), '0') + compareString(derivativeWithoutSimplify('pow(x + 2, 1)', 'x'), '1 + 0') + compareString(derivativeWithoutSimplify('2 * pow(x, 2)', 'x'), '2 * 2 * 1 * x ^ (2 - 1)') + compareString(derivativeWithoutSimplify('2 * pow(x, -2)', 'x'), '2 * -2 * 1 * x ^ (-2 - 1)') + compareString(derivativeWithoutSimplify('pow(x^3 + x, 5x + 2)', 'x'), '(x ^ 3 + x) ^ (5 x + 2) * ((3 * 1 * x ^ (3 - 1) + 1) * (5 x + 2) / (x ^ 3 + x) + (5 * 1 + 0) * log(x ^ 3 + x))') + compareString(derivativeWithoutSimplify('exp(2x)', 'x'), '2 * 1 * exp(2 x)') })