mathjs 10.2.0 → 10.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. package/HISTORY.md +12 -0
  2. package/docs/expressions/syntax.md +31 -2
  3. package/docs/reference/functions/map.md +22 -5
  4. package/docs/reference/functions/subset.md +10 -2
  5. package/docs/reference/functions/symbolicEqual.md +62 -0
  6. package/docs/reference/functions.md +2 -1
  7. package/lib/browser/math.js +5 -5
  8. package/lib/browser/math.js.map +1 -1
  9. package/lib/cjs/entry/dependenciesAny/dependenciesSymbolicEqual.generated.js +29 -0
  10. package/lib/cjs/entry/dependenciesAny.generated.js +8 -0
  11. package/lib/cjs/entry/impureFunctionsAny.generated.js +16 -8
  12. package/lib/cjs/entry/pureFunctionsAny.generated.js +9 -9
  13. package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +237 -234
  14. package/lib/cjs/expression/embeddedDocs/function/algebra/symbolicEqual.js +15 -0
  15. package/lib/cjs/expression/embeddedDocs/function/matrix/subset.js +2 -2
  16. package/lib/cjs/expression/node/FunctionNode.js +74 -55
  17. package/lib/cjs/factoriesAny.js +8 -0
  18. package/lib/cjs/function/algebra/simplify.js +8 -0
  19. package/lib/cjs/function/algebra/symbolicEqual.js +88 -0
  20. package/lib/cjs/function/matrix/eigs/complexEigs.js +8 -6
  21. package/lib/cjs/function/matrix/map.js +53 -15
  22. package/lib/cjs/function/matrix/subset.js +15 -5
  23. package/lib/cjs/header.js +2 -2
  24. package/lib/cjs/version.js +1 -1
  25. package/lib/esm/entry/dependenciesAny/dependenciesSymbolicEqual.generated.js +16 -0
  26. package/lib/esm/entry/dependenciesAny.generated.js +1 -0
  27. package/lib/esm/entry/impureFunctionsAny.generated.js +16 -9
  28. package/lib/esm/entry/pureFunctionsAny.generated.js +8 -8
  29. package/lib/esm/expression/embeddedDocs/embeddedDocs.js +218 -216
  30. package/lib/esm/expression/embeddedDocs/function/algebra/symbolicEqual.js +8 -0
  31. package/lib/esm/expression/embeddedDocs/function/matrix/subset.js +2 -2
  32. package/lib/esm/expression/node/FunctionNode.js +70 -53
  33. package/lib/esm/factoriesAny.js +1 -0
  34. package/lib/esm/function/algebra/simplify.js +8 -0
  35. package/lib/esm/function/algebra/symbolicEqual.js +80 -0
  36. package/lib/esm/function/matrix/eigs/complexEigs.js +8 -6
  37. package/lib/esm/function/matrix/map.js +53 -15
  38. package/lib/esm/function/matrix/subset.js +15 -5
  39. package/lib/esm/version.js +1 -1
  40. package/package.json +1 -1
  41. package/types/index.d.ts +4 -4
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.symbolicEqualDocs = void 0;
7
+ var symbolicEqualDocs = {
8
+ name: 'symbolicEqual',
9
+ category: 'Algebra',
10
+ syntax: ['symbolicEqual(expr1, expr2)', 'symbolicEqual(expr1, expr2, options)'],
11
+ description: 'Returns true if the difference of the expressions simplifies to 0',
12
+ examples: ['symbolicEqual("x*y","y*x")', 'symbolicEqual("abs(x^2)", "x^2")', 'symbolicEqual("abs(x)", "x", {context: {abs: {trivial: true}}})'],
13
+ seealso: ['simplify', 'evaluate']
14
+ };
15
+ exports.symbolicEqualDocs = symbolicEqualDocs;
@@ -8,8 +8,8 @@ var subsetDocs = {
8
8
  name: 'subset',
9
9
  category: 'Matrix',
10
10
  syntax: ['value(index)', 'value(index) = replacement', 'subset(value, [index])', 'subset(value, [index], replacement)'],
11
- description: 'Get or set a subset of a matrix or string. ' + 'Indexes are one-based. ' + 'Both the ranges lower-bound and upper-bound are included.',
12
- examples: ['d = [1, 2; 3, 4]', 'e = []', 'e[1, 1:2] = [5, 6]', 'e[2, :] = [7, 8]', 'f = d * e', 'f[2, 1]', 'f[:, 1]'],
11
+ description: 'Get or set a subset of the entries of a matrix or ' + 'characters of a string. ' + 'Indexes are one-based. There should be one index specification for ' + 'each dimension of the target. Each specification can be a single ' + 'index, a list of indices, or a range in colon notation `l:u`. ' + 'In a range, both the lower bound l and upper bound u are included; ' + 'and if a bound is omitted it defaults to the most extreme valid value. ' + 'The cartesian product of the indices specified in each dimension ' + 'determines the target of the operation.',
12
+ examples: ['d = [1, 2; 3, 4]', 'e = []', 'e[1, 1:2] = [5, 6]', 'e[2, :] = [7, 8]', 'f = d * e', 'f[2, 1]', 'f[:, 1]', 'f[[1,2], [1,3]] = [9, 10; 11, 12]', 'f'],
13
13
  seealso: ['concat', 'det', 'diag', 'identity', 'inv', 'ones', 'range', 'size', 'squeeze', 'trace', 'transpose', 'zeros']
14
14
  };
15
15
  exports.subsetDocs = subsetDocs;
@@ -97,78 +97,97 @@ var createFunctionNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies
97
97
  });
98
98
 
99
99
  if ((0, _is.isSymbolNode)(this.fn)) {
100
- // we can statically determine whether the function has an rawArgs property
101
100
  var _name = this.fn.name;
102
- var fn = _name in math ? (0, _customs.getSafeProperty)(math, _name) : undefined;
103
- var isRaw = typeof fn === 'function' && fn.rawArgs === true;
104
101
 
105
- var resolveFn = function resolveFn(scope) {
106
- if (scope.has(_name)) {
107
- return scope.get(_name);
108
- }
102
+ if (!argNames[_name]) {
103
+ // we can statically determine whether the function has an rawArgs property
104
+ var fn = _name in math ? (0, _customs.getSafeProperty)(math, _name) : undefined;
105
+ var isRaw = typeof fn === 'function' && fn.rawArgs === true;
109
106
 
110
- if (_name in math) {
111
- return (0, _customs.getSafeProperty)(math, _name);
112
- }
107
+ var resolveFn = function resolveFn(scope) {
108
+ if (scope.has(_name)) {
109
+ return scope.get(_name);
110
+ }
113
111
 
114
- return FunctionNode.onUndefinedFunction(_name);
115
- };
112
+ if (_name in math) {
113
+ return (0, _customs.getSafeProperty)(math, _name);
114
+ }
116
115
 
117
- if (isRaw) {
118
- // pass unevaluated parameters (nodes) to the function
119
- // "raw" evaluation
120
- var rawArgs = this.args;
121
- return function evalFunctionNode(scope, args, context) {
122
- var fn = resolveFn(scope);
123
- return fn(rawArgs, math, (0, _scope.createSubScope)(scope, args), scope);
116
+ return FunctionNode.onUndefinedFunction(_name);
124
117
  };
125
- } else {
126
- // "regular" evaluation
127
- switch (evalArgs.length) {
128
- case 0:
129
- return function evalFunctionNode(scope, args, context) {
130
- var fn = resolveFn(scope);
131
- return fn();
132
- };
133
-
134
- case 1:
135
- return function evalFunctionNode(scope, args, context) {
136
- var fn = resolveFn(scope);
137
- var evalArg0 = evalArgs[0];
138
- return fn(evalArg0(scope, args, context));
139
- };
140
-
141
- case 2:
142
- return function evalFunctionNode(scope, args, context) {
143
- var fn = resolveFn(scope);
144
- var evalArg0 = evalArgs[0];
145
- var evalArg1 = evalArgs[1];
146
- return fn(evalArg0(scope, args, context), evalArg1(scope, args, context));
147
- };
148
-
149
- default:
150
- return function evalFunctionNode(scope, args, context) {
151
- var fn = resolveFn(scope);
152
- var values = evalArgs.map(function (evalArg) {
153
- return evalArg(scope, args, context);
154
- });
155
- return fn.apply(void 0, (0, _toConsumableArray2.default)(values));
156
- };
118
+
119
+ if (isRaw) {
120
+ // pass unevaluated parameters (nodes) to the function
121
+ // "raw" evaluation
122
+ var rawArgs = this.args;
123
+ return function evalFunctionNode(scope, args, context) {
124
+ var fn = resolveFn(scope);
125
+ return fn(rawArgs, math, (0, _scope.createSubScope)(scope, args), scope);
126
+ };
127
+ } else {
128
+ // "regular" evaluation
129
+ switch (evalArgs.length) {
130
+ case 0:
131
+ return function evalFunctionNode(scope, args, context) {
132
+ var fn = resolveFn(scope);
133
+ return fn();
134
+ };
135
+
136
+ case 1:
137
+ return function evalFunctionNode(scope, args, context) {
138
+ var fn = resolveFn(scope);
139
+ var evalArg0 = evalArgs[0];
140
+ return fn(evalArg0(scope, args, context));
141
+ };
142
+
143
+ case 2:
144
+ return function evalFunctionNode(scope, args, context) {
145
+ var fn = resolveFn(scope);
146
+ var evalArg0 = evalArgs[0];
147
+ var evalArg1 = evalArgs[1];
148
+ return fn(evalArg0(scope, args, context), evalArg1(scope, args, context));
149
+ };
150
+
151
+ default:
152
+ return function evalFunctionNode(scope, args, context) {
153
+ var fn = resolveFn(scope);
154
+ var values = evalArgs.map(function (evalArg) {
155
+ return evalArg(scope, args, context);
156
+ });
157
+ return fn.apply(void 0, (0, _toConsumableArray2.default)(values));
158
+ };
159
+ }
157
160
  }
161
+ } else {
162
+ // the function symbol is an argName
163
+ var _rawArgs = this.args;
164
+ return function evalFunctionNode(scope, args, context) {
165
+ var fn = args[_name];
166
+ var isRaw = fn && fn.rawArgs;
167
+
168
+ if (isRaw) {
169
+ return fn(_rawArgs, math, (0, _scope.createSubScope)(scope, args), scope); // "raw" evaluation
170
+ } else {
171
+ var values = evalArgs.map(function (evalArg) {
172
+ return evalArg(scope, args, context);
173
+ });
174
+ return fn.apply(fn, values);
175
+ }
176
+ };
158
177
  }
159
178
  } else if ((0, _is.isAccessorNode)(this.fn) && (0, _is.isIndexNode)(this.fn.index) && this.fn.index.isObjectProperty()) {
160
179
  // execute the function with the right context: the object of the AccessorNode
161
180
  var evalObject = this.fn.object._compile(math, argNames);
162
181
 
163
182
  var prop = this.fn.index.getObjectProperty();
164
- var _rawArgs = this.args;
183
+ var _rawArgs2 = this.args;
165
184
  return function evalFunctionNode(scope, args, context) {
166
185
  var object = evalObject(scope, args, context);
167
186
  (0, _customs.validateSafeMethod)(object, prop);
168
187
  var isRaw = object[prop] && object[prop].rawArgs;
169
188
 
170
189
  if (isRaw) {
171
- return object[prop](_rawArgs, math, (0, _scope.createSubScope)(scope, args), scope); // "raw" evaluation
190
+ return object[prop](_rawArgs2, math, (0, _scope.createSubScope)(scope, args), scope); // "raw" evaluation
172
191
  } else {
173
192
  // "regular" evaluation
174
193
  var values = evalArgs.map(function (evalArg) {
@@ -182,13 +201,13 @@ var createFunctionNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies
182
201
  // we have to dynamically determine whether the function has a rawArgs property
183
202
  var evalFn = this.fn._compile(math, argNames);
184
203
 
185
- var _rawArgs2 = this.args;
204
+ var _rawArgs3 = this.args;
186
205
  return function evalFunctionNode(scope, args, context) {
187
206
  var fn = evalFn(scope, args, context);
188
207
  var isRaw = fn && fn.rawArgs;
189
208
 
190
209
  if (isRaw) {
191
- return fn(_rawArgs2, math, (0, _scope.createSubScope)(scope, args), scope); // "raw" evaluation
210
+ return fn(_rawArgs3, math, (0, _scope.createSubScope)(scope, args), scope); // "raw" evaluation
192
211
  } else {
193
212
  // "regular" evaluation
194
213
  var values = evalArgs.map(function (evalArg) {
@@ -1857,6 +1857,12 @@ Object.defineProperty(exports, "createSymbolNode", {
1857
1857
  return _SymbolNode.createSymbolNode;
1858
1858
  }
1859
1859
  });
1860
+ Object.defineProperty(exports, "createSymbolicEqual", {
1861
+ enumerable: true,
1862
+ get: function get() {
1863
+ return _symbolicEqual.createSymbolicEqual;
1864
+ }
1865
+ });
1860
1866
  Object.defineProperty(exports, "createTan", {
1861
1867
  enumerable: true,
1862
1868
  get: function get() {
@@ -2520,6 +2526,8 @@ var _simplifyCore = require("./function/algebra/simplifyCore.js");
2520
2526
 
2521
2527
  var _resolve = require("./function/algebra/resolve.js");
2522
2528
 
2529
+ var _symbolicEqual = require("./function/algebra/symbolicEqual.js");
2530
+
2523
2531
  var _derivative = require("./function/algebra/derivative.js");
2524
2532
 
2525
2533
  var _rationalize = require("./function/algebra/rationalize.js");
@@ -343,6 +343,14 @@ var createSimplify = /* #__PURE__ */(0, _factory.factory)(name, dependencies, fu
343
343
  total: true
344
344
  }
345
345
  }
346
+ }, {
347
+ s: 'n-n -> 0',
348
+ // partial alternative when we can't always subtract
349
+ assuming: {
350
+ subtract: {
351
+ total: false
352
+ }
353
+ }
346
354
  }, {
347
355
  s: '-(c*v) -> v * (-c)',
348
356
  // make non-constant terms positive
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createSymbolicEqual = void 0;
7
+
8
+ var _is = require("../../utils/is.js");
9
+
10
+ var _factory = require("../../utils/factory.js");
11
+
12
+ var name = 'symbolicEqual';
13
+ var dependencies = ['parse', 'simplify', 'typed', 'OperatorNode'];
14
+ var createSymbolicEqual = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
15
+ var parse = _ref.parse,
16
+ simplify = _ref.simplify,
17
+ typed = _ref.typed,
18
+ OperatorNode = _ref.OperatorNode;
19
+
20
+ /**
21
+ * Attempts to determine if two expressions are symbolically equal, i.e.
22
+ * one is the result of valid algebraic manipulations on the other.
23
+ * Currently, this simply checks if the difference of the two expressions
24
+ * simplifies down to 0. So there are two important caveats:
25
+ * 1. whether two expressions are symbolically equal depends on the
26
+ * manipulations allowed. Therefore, this function takes an optional
27
+ * third argument, which are the options that control the behavior
28
+ * as documented for the `simplify()` function.
29
+ * 2. it is in general intractable to find the minimal simplification of
30
+ * an arbitrarily complicated expression. So while a `true` value
31
+ * of `symbolicEqual` ensures that the two expressions can be manipulated
32
+ * to match each other, a `false` value does not absolutely rule this out.
33
+ *
34
+ * Syntax:
35
+ *
36
+ * symbolicEqual(expr1, expr2)
37
+ * symbolicEqual(expr1, expr2, options)
38
+ *
39
+ * Examples:
40
+ *
41
+ * symbolicEqual('x*y', 'y*x') // true
42
+ * symbolicEqual('x*y', 'y*x', {context: {multiply: {commutative: false}}})
43
+ * //false
44
+ * symbolicEqual('x/y', '(y*x^(-1))^(-1)') // true
45
+ * symbolicEqual('abs(x)','x') // false
46
+ * symbolicEqual('abs(x)','x', simplify.positiveContext) // true
47
+ *
48
+ * See also:
49
+ *
50
+ * simplify, evaluate
51
+ *
52
+ * @param {Node|string} expr1 The first expression to compare
53
+ * @param {Node|string} expr2 The second expression to compare
54
+ * @param {Object} [options] Optional option object, passed to simplify
55
+ * @returns {boolean}
56
+ * Returns true if a valid manipulation making the expressions equal
57
+ * is found.
58
+ */
59
+ return typed(name, {
60
+ 'string, string': function stringString(s1, s2) {
61
+ return this(parse(s1), parse(s2), {});
62
+ },
63
+ 'string, string, Object': function stringStringObject(s1, s2, options) {
64
+ return this(parse(s1), parse(s2), options);
65
+ },
66
+ 'Node, string': function NodeString(e1, s2) {
67
+ return this(e1, parse(s2), {});
68
+ },
69
+ 'Node, string, Object': function NodeStringObject(e1, s2, options) {
70
+ return this(e1, parse(s2), options);
71
+ },
72
+ 'string, Node': function stringNode(s1, e2) {
73
+ return this(parse(s1), e2, {});
74
+ },
75
+ 'string, Node, Object': function stringNodeObject(s1, e2, options) {
76
+ return this(parse(s1), e2, options);
77
+ },
78
+ 'Node, Node': function NodeNode(e1, e2) {
79
+ return this(e1, e2, {});
80
+ },
81
+ 'Node, Node, Object': function NodeNodeObject(e1, e2, options) {
82
+ var diff = new OperatorNode('-', 'subtract', [e1, e2]);
83
+ var simplified = simplify(diff, {}, options);
84
+ return (0, _is.isConstantNode)(simplified) && !simplified.value;
85
+ }
86
+ });
87
+ });
88
+ exports.createSymbolicEqual = createSymbolicEqual;
@@ -100,8 +100,9 @@ function createComplexEigs(_ref) {
100
100
  function balance(arr, N, prec, type, findVectors) {
101
101
  var big = type === 'BigNumber';
102
102
  var cplx = type === 'Complex';
103
- var zero = big ? bignumber(0) : cplx ? complex(0) : 0;
104
- var one = big ? bignumber(1) : cplx ? complex(1) : 1; // base of the floating-point arithmetic
103
+ var realzero = big ? bignumber(0) : 0;
104
+ var one = big ? bignumber(1) : cplx ? complex(1) : 1;
105
+ var realone = big ? bignumber(1) : 1; // base of the floating-point arithmetic
105
106
 
106
107
  var radix = big ? bignumber(10) : 2;
107
108
  var radixSq = multiplyScalar(radix, radix); // the diagonal transformation matrix R
@@ -122,12 +123,13 @@ function createComplexEigs(_ref) {
122
123
  for (var i = 0; i < N; i++) {
123
124
  // compute the taxicab norm of i-th column and row
124
125
  // TODO optimize for complex numbers
125
- var colNorm = zero;
126
- var rowNorm = zero;
126
+ var colNorm = realzero;
127
+ var rowNorm = realzero;
127
128
 
128
129
  for (var j = 0; j < N; j++) {
129
130
  if (i === j) continue;
130
- var c = abs(arr[i][j]);
131
+ var c = abs(arr[i][j]); // should be real
132
+
131
133
  colNorm = addScalar(colNorm, c);
132
134
  rowNorm = addScalar(rowNorm, c);
133
135
  }
@@ -136,7 +138,7 @@ function createComplexEigs(_ref) {
136
138
  // find integer power closest to balancing the matrix
137
139
  // (we want to scale only by integer powers of radix,
138
140
  // so that we don't lose any precision due to round-off)
139
- var f = one;
141
+ var f = realone;
140
142
  var _c = colNorm;
141
143
  var rowDivRadix = divideScalar(rowNorm, radix);
142
144
  var rowMulRadix = multiplyScalar(rowNorm, radix);
@@ -15,8 +15,15 @@ var createMap = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functio
15
15
  var typed = _ref.typed;
16
16
 
17
17
  /**
18
- * Create a new matrix or array with the results of the callback function executed on
19
- * each entry of the matrix/array.
18
+ * Create a new matrix or array with the results of a callback function executed on
19
+ * each entry of a given matrix/array.
20
+ *
21
+ * For each entry of the input, the callback is invoked with three arguments:
22
+ * the value of the entry, the index at which that entry occurs, and the full
23
+ * matrix/array being traversed. Note that because the matrix/array might be
24
+ * multidimensional, the "index" argument is always an array of numbers giving
25
+ * the index in each dimension. This is true even for vectors: the "index"
26
+ * argument is an array of length 1, rather than simply a number.
20
27
  *
21
28
  * Syntax:
22
29
  *
@@ -28,15 +35,25 @@ var createMap = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functio
28
35
  * return value * value
29
36
  * }) // returns [1, 4, 9]
30
37
  *
38
+ * // The calling convention for the callback can cause subtleties:
39
+ * math.map([1, 2, 3], math.format)
40
+ * // throws TypeError: map attempted to call 'format(1,[0])' but argument 2 of type Array does not match expected type number or function or Object or string or boolean
41
+ * // [This happens because `format` _can_ take a second argument,
42
+ * // but its semantics don't match that of the 2nd argument `map` provides]
43
+ *
44
+ * // To avoid this error, use a function that takes exactly the
45
+ * // desired arguments:
46
+ * math.map([1, 2, 3], x => math.format(x)) // returns ['1', '2', '3']
47
+ *
31
48
  * See also:
32
49
  *
33
50
  * filter, forEach, sort
34
51
  *
35
- * @param {Matrix | Array} x The matrix to iterate on.
36
- * @param {Function} callback The callback method is invoked with three
37
- * parameters: the value of the element, the index
38
- * of the element, and the matrix being traversed.
39
- * @return {Matrix | array} Transformed map of x
52
+ * @param {Matrix | Array} x The input to iterate on.
53
+ * @param {Function} callback
54
+ * The function to call (as described above) on each entry of the input
55
+ * @return {Matrix | array}
56
+ * Transformed map of x; always has the same type and shape as x
40
57
  */
41
58
  return typed(name, {
42
59
  'Array, function': _map,
@@ -66,14 +83,35 @@ function _map(array, callback) {
66
83
  return recurse(child, index.concat(i));
67
84
  });
68
85
  } else {
69
- // invoke the callback function with the right number of arguments
70
- if (args === 1) {
71
- return callback(value);
72
- } else if (args === 2) {
73
- return callback(value, index);
74
- } else {
75
- // 3 or -1
76
- return callback(value, index, array);
86
+ try {
87
+ // invoke the callback function with the right number of arguments
88
+ if (args === 1) {
89
+ return callback(value);
90
+ } else if (args === 2) {
91
+ return callback(value, index);
92
+ } else {
93
+ // 3 or -1
94
+ return callback(value, index, array);
95
+ }
96
+ } catch (err) {
97
+ // But maybe the arguments still weren't right
98
+ if (err instanceof TypeError && 'data' in err && err.data.category === 'wrongType') {
99
+ var newmsg = "map attempted to call '".concat(err.data.fn, "(").concat(value);
100
+ var indexString = JSON.stringify(index);
101
+
102
+ if (args === 2) {
103
+ newmsg += ',' + indexString;
104
+ } else if (args !== 1) {
105
+ newmsg += ",".concat(indexString, ",").concat(array);
106
+ }
107
+
108
+ newmsg += ")' but argument ".concat(err.data.index + 1, " of type ");
109
+ newmsg += "".concat(err.data.actual, " does not match expected type ");
110
+ newmsg += err.data.expected.join(' or ');
111
+ throw new TypeError(newmsg);
112
+ }
113
+
114
+ throw err;
77
115
  }
78
116
  }
79
117
  };
@@ -39,16 +39,26 @@ var createSubset = /* #__PURE__ */(0, _factory.factory)(name, dependencies, func
39
39
  *
40
40
  * // replace a subset
41
41
  * const e = []
42
- * const f = math.subset(e, math.index(0, [0, 2]), [5, 6]) // f = [[5, 6]]
42
+ * const f = math.subset(e, math.index(0, [0, 2]), [5, 6]) // f = [[5, 6]] and e = [[5, 0, 6]]
43
43
  * const g = math.subset(f, math.index(1, 1), 7, 0) // g = [[5, 6], [0, 7]]
44
44
  *
45
+ * // get submatrix using ranges
46
+ * const M = [
47
+ * [1,2,3],
48
+ * [4,5,6],
49
+ * [7,8,9]
50
+ * ]
51
+ * math.subset(M, math.index(math.range(0,2), math.range(0,3))) // [[1,2,3],[4,5,6]]
52
+ *
45
53
  * See also:
46
54
  *
47
55
  * size, resize, squeeze, index
48
56
  *
49
57
  * @param {Array | Matrix | string} matrix An array, matrix, or string
50
- * @param {Index} index An index containing ranges for each
51
- * dimension
58
+ * @param {Index} index
59
+ * For each dimension of the target, specifies an index or a list of
60
+ * indices to fetch or set. `subset` uses the cartesian product of
61
+ * the indices specified in each dimension.
52
62
  * @param {*} [replacement] An array, matrix, or scalar.
53
63
  * If provided, the subset is replaced with replacement.
54
64
  * If not provided, the subset is returned
@@ -91,7 +101,7 @@ var createSubset = /* #__PURE__ */(0, _factory.factory)(name, dependencies, func
91
101
  /**
92
102
  * Retrieve a subset of a string
93
103
  * @param {string} str string from which to get a substring
94
- * @param {Index} index An index containing ranges for each dimension
104
+ * @param {Index} index An index or list of indices (character positions)
95
105
  * @returns {string} substring
96
106
  * @private
97
107
  */
@@ -122,7 +132,7 @@ function _getSubstring(str, index) {
122
132
  /**
123
133
  * Replace a substring in a string
124
134
  * @param {string} str string to be replaced
125
- * @param {Index} index An index containing ranges for each dimension
135
+ * @param {Index} index An index or list of indices (character positions)
126
136
  * @param {string} replacement Replacement string
127
137
  * @param {string} [defaultValue] Default value to be uses when resizing
128
138
  * the string. is ' ' by default
package/lib/cjs/header.js CHANGED
@@ -6,8 +6,8 @@
6
6
  * It features real and complex numbers, units, matrices, a large set of
7
7
  * mathematical functions, and a flexible expression parser.
8
8
  *
9
- * @version 10.2.0
10
- * @date 2022-03-01
9
+ * @version 10.3.0
10
+ * @date 2022-03-02
11
11
  *
12
12
  * @license
13
13
  * Copyright (C) 2013-2022 Jos de Jong <wjosdejong@gmail.com>
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.version = void 0;
7
- var version = '10.2.0'; // Note: This file is automatically generated when building math.js.
7
+ var version = '10.3.0'; // Note: This file is automatically generated when building math.js.
8
8
  // Changes made in this file will be overwritten.
9
9
 
10
10
  exports.version = version;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * THIS FILE IS AUTO-GENERATED
3
+ * DON'T MAKE CHANGES HERE
4
+ */
5
+ import { OperatorNodeDependencies } from './dependenciesOperatorNode.generated.js';
6
+ import { parseDependencies } from './dependenciesParse.generated.js';
7
+ import { simplifyDependencies } from './dependenciesSimplify.generated.js';
8
+ import { typedDependencies } from './dependenciesTyped.generated.js';
9
+ import { createSymbolicEqual } from '../../factoriesAny.js';
10
+ export var symbolicEqualDependencies = {
11
+ OperatorNodeDependencies,
12
+ parseDependencies,
13
+ simplifyDependencies,
14
+ typedDependencies,
15
+ createSymbolicEqual
16
+ };
@@ -312,6 +312,7 @@ export { subtractDependencies } from './dependenciesAny/dependenciesSubtract.gen
312
312
  export { sumDependencies } from './dependenciesAny/dependenciesSum.generated.js';
313
313
  export { sumTransformDependencies } from './dependenciesAny/dependenciesSumTransform.generated.js';
314
314
  export { SymbolNodeDependencies } from './dependenciesAny/dependenciesSymbolNode.generated.js';
315
+ export { symbolicEqualDependencies } from './dependenciesAny/dependenciesSymbolicEqual.generated.js';
315
316
  export { tanDependencies } from './dependenciesAny/dependenciesTan.generated.js';
316
317
  export { tanhDependencies } from './dependenciesAny/dependenciesTanh.generated.js';
317
318
  export { tauDependencies } from './dependenciesAny/dependenciesTau.generated.js';
@@ -5,9 +5,9 @@ import _extends from "@babel/runtime/helpers/extends";
5
5
  * DON'T MAKE CHANGES HERE
6
6
  */
7
7
  import { config } from './configReadonly.js';
8
- import { createChainClass, createNode, createObjectNode, createOperatorNode, createParenthesisNode, createRelationalNode, createArrayNode, createBlockNode, createConditionalNode, createConstantNode, createRangeNode, createReviver, createChain, createFunctionAssignmentNode, createAccessorNode, createAssignmentNode, createIndexNode, createSymbolNode, createFunctionNode, createParse, createResolve, createCompile, createEvaluate, createHelpClass, createLeafCount, createParserClass, createParser, createSimplifyCore, createSimplify, createDerivative, createRationalize, createHelp, createFilterTransform, createForEachTransform, createMapTransform, createApplyTransform, createDiffTransform, createIndexTransform, createSubsetTransform, createConcatTransform, createMaxTransform, createMinTransform, createRangeTransform, createRowTransform, createSumTransform, createColumnTransform, createStdTransform, createMeanTransform, createVarianceTransform } from '../factoriesAny.js';
8
+ import { createChainClass, createNode, createObjectNode, createOperatorNode, createParenthesisNode, createRelationalNode, createArrayNode, createBlockNode, createConditionalNode, createConstantNode, createRangeNode, createReviver, createChain, createFunctionAssignmentNode, createAccessorNode, createAssignmentNode, createIndexNode, createSymbolNode, createFunctionNode, createParse, createResolve, createCompile, createEvaluate, createHelpClass, createLeafCount, createParserClass, createParser, createSimplifyCore, createSimplify, createDerivative, createRationalize, createHelp, createSymbolicEqual, createFilterTransform, createForEachTransform, createMapTransform, createApplyTransform, createDiffTransform, createIndexTransform, createSubsetTransform, createConcatTransform, createMaxTransform, createMinTransform, createRangeTransform, createRowTransform, createSumTransform, createColumnTransform, createStdTransform, createVarianceTransform, createMeanTransform } from '../factoriesAny.js';
9
9
  import { BigNumber, Complex, e, _false, fineStructure, Fraction, i, _Infinity, LN10, LOG10E, Matrix, _NaN, _null, phi, Range, ResultSet, SQRT1_2, // eslint-disable-line camelcase
10
- sackurTetrode, tau, _true, version, DenseMatrix, efimovFactor, LN2, pi, replacer, SQRT2, typed, unaryPlus, weakMixingAngle, abs, acos, acot, acsc, addScalar, arg, asech, asinh, atan, atanh, bignumber, bitNot, boolean, clone, combinations, complex, conj, cosh, coth, csc, cube, equalScalar, erf, exp, expm1, filter, forEach, format, getMatrixDataType, hex, im, isInteger, isNegative, isPositive, isZero, LOG2E, log10, log2, map, multiplyScalar, not, number, oct, pickRandom, print, random, re, sec, sign, sin, SparseMatrix, splitUnit, square, string, tan, typeOf, acosh, acsch, apply, asec, bin, combinationsWithRep, cos, csch, isNaN, isPrime, randomInt, sech, sinh, sparse, sqrt, tanh, unaryMinus, acoth, cot, fraction, isNumeric, matrix, matrixFromFunction, mod, nthRoot, numeric, or, prod, reshape, size, smaller, squeeze, subset, subtract, to, transpose, xgcd, zeros, and, bitAnd, bitXor, cbrt, compare, compareText, concat, count, ctranspose, diag, divideScalar, dotDivide, equal, flatten, gcd, hasNumericValue, hypot, ImmutableDenseMatrix, Index, kron, largerEq, leftShift, lsolve, matrixFromColumns, min, mode, nthRoots, ones, partitionSelect, resize, rightArithShift, round, smallerEq, unequal, usolve, xor, add, atan2, bitOr, catalan, compareNatural, deepEqual, diff, dot, equalText, floor, identity, invmod, larger, log, lsolveAll, matrixFromRows, multiply, pow, qr, range, rightLogShift, row, setCartesian, setDistinct, setIsSubset, setPowerset, slu, sum, trace, usolveAll, asin, ceil, column, composition, cross, distance, dotMultiply, FibonacciHeap, fix, gamma, index, lcm, log1p, max, quantileSeq, setDifference, setMultiplicity, setSymDifference, sort, Unit, vacuumImpedance, wienDisplacement, atomicMass, bohrMagneton, boltzmann, conductanceQuantum, createUnit, deuteronMass, dotPow, electricConstant, elementaryCharge, factorial, fermiCoupling, gasConstant, gravity, intersect, inverseConductanceQuantum, klitzing, loschmidt, magneticConstant, molarMass, molarPlanckConstant, neutronMass, nuclearMagneton, permutations, planckConstant, planckMass, planckTime, quantumOfCirculation, reducedPlanckConstant, rydberg, setIntersect, setUnion, Spa, stefanBoltzmann, unit, avogadro, bohrRadius, coulomb, electronMass, faraday, hartreeEnergy, lup, magneticFluxQuantum, molarMassC12, planckCharge, planckTemperature, secondRadiation, speedOfLight, stirlingS2, bellNumbers, det, firstRadiation, molarVolume, protonMass, setSize, thomsonCrossSection, classicalElectronRadius, gravitationConstant, inv, lusolve, sqrtm, divide, expm, kldivergence, mean, median, planckLength, variance, eigs, mad, multinomial, std, norm, rotationMatrix, rotate } from './pureFunctionsAny.generated.js';
10
+ sackurTetrode, tau, _true, version, DenseMatrix, efimovFactor, LN2, pi, replacer, SQRT2, typed, unaryPlus, weakMixingAngle, abs, acos, acot, acsc, addScalar, arg, asech, asinh, atan, atanh, bignumber, bitNot, boolean, clone, combinations, complex, conj, cosh, coth, csc, cube, equalScalar, erf, exp, expm1, filter, forEach, format, getMatrixDataType, hex, im, isInteger, isNegative, isPositive, isZero, LOG2E, log10, log2, map, multiplyScalar, not, number, oct, pickRandom, print, random, re, sec, sign, sin, SparseMatrix, splitUnit, square, string, tan, typeOf, acosh, acsch, apply, asec, bin, combinationsWithRep, cos, csch, isNaN, isPrime, randomInt, sech, sinh, sparse, sqrt, tanh, unaryMinus, acoth, cot, fraction, isNumeric, matrix, matrixFromFunction, mod, nthRoot, numeric, or, prod, reshape, size, smaller, squeeze, subset, subtract, to, transpose, xgcd, zeros, and, bitAnd, bitXor, cbrt, compare, compareText, concat, count, ctranspose, diag, divideScalar, dotDivide, equal, flatten, gcd, hasNumericValue, hypot, ImmutableDenseMatrix, Index, kron, largerEq, leftShift, lsolve, matrixFromColumns, min, mode, nthRoots, ones, partitionSelect, resize, rightArithShift, round, smallerEq, unequal, usolve, xor, add, atan2, bitOr, catalan, compareNatural, deepEqual, diff, dot, equalText, floor, identity, invmod, larger, log, lsolveAll, matrixFromRows, multiply, pow, qr, range, rightLogShift, row, setCartesian, setDistinct, setIsSubset, setPowerset, slu, sum, trace, usolveAll, asin, ceil, column, composition, cross, distance, dotMultiply, FibonacciHeap, fix, gamma, index, lcm, log1p, max, quantileSeq, setDifference, setMultiplicity, setSymDifference, sort, Unit, vacuumImpedance, wienDisplacement, atomicMass, bohrMagneton, boltzmann, conductanceQuantum, createUnit, deuteronMass, dotPow, electricConstant, elementaryCharge, factorial, fermiCoupling, gasConstant, gravity, intersect, inverseConductanceQuantum, klitzing, loschmidt, magneticConstant, molarMass, molarPlanckConstant, neutronMass, nuclearMagneton, permutations, planckConstant, planckMass, planckTime, quantumOfCirculation, reducedPlanckConstant, rydberg, setIntersect, setUnion, Spa, stefanBoltzmann, thomsonCrossSection, avogadro, bohrRadius, coulomb, electronMass, faraday, hartreeEnergy, lup, magneticFluxQuantum, molarMassC12, planckCharge, planckTemperature, secondRadiation, speedOfLight, stirlingS2, unit, bellNumbers, det, firstRadiation, molarVolume, protonMass, setSize, classicalElectronRadius, gravitationConstant, inv, lusolve, sqrtm, divide, expm, kldivergence, mean, median, planckLength, variance, eigs, mad, multinomial, std, norm, rotationMatrix, rotate } from './pureFunctionsAny.generated.js';
11
11
  var math = {}; // NOT pure!
12
12
 
13
13
  var mathWithTransform = {}; // NOT pure!
@@ -223,6 +223,12 @@ export var help = createHelp({
223
223
  mathWithTransform,
224
224
  typed
225
225
  });
226
+ export var symbolicEqual = createSymbolicEqual({
227
+ OperatorNode,
228
+ parse,
229
+ simplify,
230
+ typed
231
+ });
226
232
 
227
233
  _extends(math, {
228
234
  e,
@@ -461,7 +467,7 @@ _extends(math, {
461
467
  setIntersect,
462
468
  setUnion,
463
469
  stefanBoltzmann,
464
- unit,
470
+ thomsonCrossSection,
465
471
  avogadro,
466
472
  bohrRadius,
467
473
  coulomb,
@@ -478,6 +484,7 @@ _extends(math, {
478
484
  secondRadiation,
479
485
  speedOfLight,
480
486
  stirlingS2,
487
+ unit,
481
488
  bellNumbers,
482
489
  compile,
483
490
  det,
@@ -487,7 +494,6 @@ _extends(math, {
487
494
  molarVolume,
488
495
  protonMass,
489
496
  setSize,
490
- thomsonCrossSection,
491
497
  classicalElectronRadius,
492
498
  gravitationConstant,
493
499
  inv,
@@ -510,6 +516,7 @@ _extends(math, {
510
516
  rationalize,
511
517
  std,
512
518
  help,
519
+ symbolicEqual,
513
520
  norm,
514
521
  rotationMatrix,
515
522
  rotate,
@@ -594,11 +601,6 @@ _extends(mathWithTransform, math, {
594
601
  typed,
595
602
  variance
596
603
  }),
597
- mean: createMeanTransform({
598
- add,
599
- divide,
600
- typed
601
- }),
602
604
  variance: createVarianceTransform({
603
605
  add,
604
606
  apply,
@@ -607,6 +609,11 @@ _extends(mathWithTransform, math, {
607
609
  multiply,
608
610
  subtract,
609
611
  typed
612
+ }),
613
+ mean: createMeanTransform({
614
+ add,
615
+ divide,
616
+ typed
610
617
  })
611
618
  });
612
619