[go: up one dir, main page]

Skip to content

Commit

Permalink
Released v3.20.0
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Jan 14, 2018
1 parent 18f703b commit ad9c81a
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 24 deletions.
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# History

## not yet released, version 3.20.0
## 2018-01-14, version 3.20.0

- Implement support for 3 or more arguments for operators `+` and `*` in
`derivative`. Thanks @HarrySarson. See #1002.
Expand Down
73 changes: 57 additions & 16 deletions dist/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* It features real and complex numbers, units, matrices, a large set of
* mathematical functions, and a flexible expression parser.
*
* @version 3.19.0
* @date 2018-01-06
* @version 3.20.0
* @date 2018-01-14
*
* @license
* Copyright (C) 2013-2018 Jos de Jong <wjosdejong@gmail.com>
Expand Down Expand Up @@ -15361,7 +15361,7 @@ function factory (type, config, load, typed, math) {
newRule.evaluate = parse(rule.evaluate);
}

if (newRule.l.isOperatorNode && isAssociative(newRule.l)) {
if (isAssociative(newRule.l)) {
var makeNode = createMakeNodeFunction(newRule.l);
var expandsym = _getExpandPlaceholderSymbol();
newRule.expanded = {};
Expand Down Expand Up @@ -20976,6 +20976,7 @@ function factory(type, config, load, typed, math) {
var createMakeNodeFunction = util.createMakeNodeFunction;
var ConstantNode = math.expression.node.ConstantNode;
var OperatorNode = math.expression.node.OperatorNode;
var FunctionNode = math.expression.node.FunctionNode;

function simplifyConstant(expr) {
var res = foldFraction(expr);
Expand Down Expand Up @@ -21124,6 +21125,29 @@ function factory(type, config, load, typed, math) {
if (math[node.name] && math[node.name].rawArgs) {
return node;
}

// Process operators as OperatorNode
var operatorFunctions = [ 'add', 'multiply' ];
if (operatorFunctions.indexOf(node.name) === -1) {
var args = node.args.map(foldFraction);

// If all args are numbers
if (!args.some(type.isNode)) {
try {
return _eval(node.name, args);
}
catch (ignoreandcontine) {}
}

// Convert all args to nodes and construct a symbolic function call
args = args.map(function(arg) {
return type.isNode(arg) ? arg : _toNode(arg);
});
return new FunctionNode(node.name, args);
}
else {
// treat as operator
}
/* falls through */
case 'OperatorNode':
var fn = node.fn.toString();
Expand Down Expand Up @@ -21241,7 +21265,7 @@ function factory(type, config, load, typed, math) {


function isCommutative(node, context) {
if (!node.args || node.args.length <=1) {
if (!type.isOperatorNode(node)) {
return true;
}
var name = node.fn.toString();
Expand All @@ -21252,8 +21276,8 @@ function factory(type, config, load, typed, math) {
}

function isAssociative(node, context) {
if (!node.args || node.args.length <=1) {
return true;
if (!type.isOperatorNode(node)) {
return false;
}
var name = node.fn.toString();
if (context && context.hasOwnProperty(name) && context[name].hasOwnProperty('associative')) {
Expand Down Expand Up @@ -21295,7 +21319,7 @@ function factory(type, config, load, typed, math) {
}
};

if (type.isOperatorNode(node) && isAssociative(node)) {
if (isAssociative(node)) {
op = node.op;
findChildren(node);
return children;
Expand Down Expand Up @@ -41189,7 +41213,7 @@ exports.math = true; // request access to the math namespace
/* 193 */
/***/ (function(module, exports) {

module.exports = '3.19.0';
module.exports = '3.20.0';
// Note: This file is automatically generated when building math.js.
// Changes made in this file will be overwritten.

Expand Down Expand Up @@ -47374,6 +47398,10 @@ function factory (type, config, load, typed) {

switch (node.op) {
case '+':
// d/dx(sum(f(x)) = sum(f'(x))
return new OperatorNode(node.op, node.fn, node.args.map(function(arg) {
return _derivative(arg, constNodes);
}));
case '-':
// d/dx(+/-f(x)) = +/-f'(x)
if (node.args.length == 1) {
Expand All @@ -47387,19 +47415,32 @@ function factory (type, config, load, typed) {
]);
case '*':
// d/dx(c*f(x)) = c*f'(x)
if (constNodes[arg1] !== undefined || constNodes[arg2] !== undefined) {
var newArgs = (constNodes[arg1] !== undefined)
? [arg1.clone(), _derivative(arg2, constNodes)]
: [arg2.clone(), _derivative(arg1, constNodes)];
var constantTerms = node.args.filter(function(arg) {
return constNodes[arg] !== undefined;
});

if (constantTerms.length > 0) {
var nonConstantTerms = node.args.filter(function(arg) {
return constNodes[arg] === undefined;
});

var nonConstantNode = nonConstantTerms.length === 1
? nonConstantTerms[0]
: new OperatorNode('*', 'multiply', nonConstantTerms);

var newArgs = constantTerms.concat(_derivative(nonConstantNode, constNodes));

return new OperatorNode('*', 'multiply', newArgs);
}

// Product Rule, d/dx(f(x)*g(x)) = f'(x)*g(x) + f(x)*g'(x)
return new OperatorNode('+', 'add', [
new OperatorNode('*', 'multiply', [_derivative(arg1, constNodes), arg2.clone()]),
new OperatorNode('*', 'multiply', [arg1.clone(), _derivative(arg2, constNodes)])
]);
return new OperatorNode('+', 'add', node.args.map(function(argOuter) {
return new OperatorNode('*', 'multiply', node.args.map(function(argInner) {
return (argInner === argOuter)
? _derivative(argInner, constNodes)
: argInner.clone();
}));
}));
case '/':
// d/dx(f(x) / c) = f'(x) / c
if (constNodes[arg2] !== undefined) {
Expand Down
8 changes: 4 additions & 4 deletions dist/math.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/math.min.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/version.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = '3.19.0';
module.exports = '3.20.0';
// Note: This file is automatically generated when building math.js.
// Changes made in this file will be overwritten.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mathjs",
"version": "3.19.0",
"version": "3.20.0",
"description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with different data types like numbers, big numbers, complex numbers, fractions, units, and matrices.",
"author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
"contributors": [
Expand Down

0 comments on commit ad9c81a

Please sign in to comment.