mathjs 10.1.0 → 10.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -138,11 +138,14 @@ var createSimplify = /* #__PURE__ */(0, _factory.factory)(name, dependencies, fu
138
138
  * - [Symbolic computation - Simplification (Wikipedia)](https://en.wikipedia.org/wiki/Symbolic_computation#Simplification)
139
139
  *
140
140
  * An optional `options` argument can be passed as last argument of `simplify`.
141
- * There is currently one option available:
142
- * - `exactFractions`: a boolean which is `true` by default.
143
- * - `fractionsLimit`: when `exactFractions` is true, a fraction will be returned
144
- * only when both numerator and denominator are smaller than `fractionsLimit`.
145
- * Default value is 10000.
141
+ * Currently available options (defaults in parentheses):
142
+ * - `consoleDebug` (false): whether to write the expression being simplified
143
+ and any changes to it, along with the rule responsible, to console
144
+ * - `exactFractions` (true): whether to try to convert all constants to
145
+ exact rational numbers.
146
+ * - `fractionsLimit` (10000): when `exactFractions` is true, constants will
147
+ be expressed as fractions only when both numerator and denominator
148
+ are smaller than `fractionsLimit`.
146
149
  *
147
150
  * Syntax:
148
151
  *
@@ -213,6 +216,7 @@ var createSimplify = /* #__PURE__ */(0, _factory.factory)(name, dependencies, fu
213
216
  return this(expr, rules, (0, _map.createMap)(scope), options);
214
217
  },
215
218
  'Node, Array, Map, Object': function NodeArrayMapObject(expr, rules, scope, options) {
219
+ var debug = options.consoleDebug;
216
220
  rules = _buildRules(rules);
217
221
  var res = resolve(expr, scope);
218
222
  res = removeParens(res);
@@ -225,12 +229,33 @@ var createSimplify = /* #__PURE__ */(0, _factory.factory)(name, dependencies, fu
225
229
  visited[str] = true;
226
230
  _lastsym = 0; // counter for placeholder symbols
227
231
 
232
+ var laststr = str;
233
+ if (debug) console.log('Working on: ', str);
234
+
228
235
  for (var i = 0; i < rules.length; i++) {
236
+ var rulestr = '';
237
+
229
238
  if (typeof rules[i] === 'function') {
230
239
  res = rules[i](res, options);
240
+ if (debug) rulestr = rules[i].name;
231
241
  } else {
232
242
  flatten(res);
233
243
  res = applyRule(res, rules[i]);
244
+
245
+ if (debug) {
246
+ rulestr = "".concat(rules[i].l.toString(), " -> ").concat(rules[i].r.toString());
247
+ }
248
+ }
249
+
250
+ if (debug) {
251
+ var newstr = res.toString({
252
+ parenthesis: 'all'
253
+ });
254
+
255
+ if (newstr !== laststr) {
256
+ console.log('Applying', rulestr, 'produced', newstr);
257
+ laststr = newstr;
258
+ }
234
259
  }
235
260
 
236
261
  unflattenl(res); // using left-heavy binary tree here since custom rule functions may expect it
@@ -314,18 +339,7 @@ var createSimplify = /* #__PURE__ */(0, _factory.factory)(name, dependencies, fu
314
339
  {
315
340
  l: 'n/n1',
316
341
  r: 'n*n1^-1'
317
- }, // remove parenthesis in the case of negating a quantity
318
- {
319
- l: 'n1 + (n2 + n3)*(-1)',
320
- r: 'n1 + n2*(-1) + n3*(-1)'
321
- }, // subsume resulting -1 into constants where possible
322
- {
323
- l: '(-1) * c',
324
- r: '-c'
325
- }, {
326
- l: '(-1) * (-c)',
327
- r: 'c'
328
- }, // expand nested exponentiation
342
+ }, simplifyConstant, // expand nested exponentiation
329
343
  {
330
344
  l: '(n ^ n1) ^ n2',
331
345
  r: 'n ^ (n1 * n2)'
@@ -357,11 +371,19 @@ var createSimplify = /* #__PURE__ */(0, _factory.factory)(name, dependencies, fu
357
371
  {
358
372
  l: 'n*c + c',
359
373
  r: '(n+1)*c'
360
- }, simplifyConstant, {
374
+ }, // remove parenthesis in the case of negating a quantity
375
+ // (It might seem this rule should precede collecting like terms,
376
+ // but putting it after gives another chance of noticing like terms,
377
+ // and any new like terms produced by this will be collected
378
+ // on the next pass through all the rules.)
379
+ {
380
+ l: 'n1 + (n2 + n3)*(-1)',
381
+ r: 'n1 + n2*(-1) + n3*(-1)'
382
+ }, // make factors positive (and undo 'make non-constant terms positive')
383
+ {
361
384
  l: '(-n)*n1',
362
385
  r: '-(n*n1)'
363
- }, // make factors positive (and undo 'make non-constant terms positive')
364
- // final ordering of constants
386
+ }, // final ordering of constants
365
387
  {
366
388
  l: 'c+v',
367
389
  r: 'v+c',
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.1.0
10
- * @date 2022-01-15
9
+ * @version 10.1.1
10
+ * @date 2022-02-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.1.0'; // Note: This file is automatically generated when building math.js.
7
+ var version = '10.1.1'; // 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;
@@ -121,11 +121,14 @@ export var createSimplify = /* #__PURE__ */factory(name, dependencies, _ref => {
121
121
  * - [Symbolic computation - Simplification (Wikipedia)](https://en.wikipedia.org/wiki/Symbolic_computation#Simplification)
122
122
  *
123
123
  * An optional `options` argument can be passed as last argument of `simplify`.
124
- * There is currently one option available:
125
- * - `exactFractions`: a boolean which is `true` by default.
126
- * - `fractionsLimit`: when `exactFractions` is true, a fraction will be returned
127
- * only when both numerator and denominator are smaller than `fractionsLimit`.
128
- * Default value is 10000.
124
+ * Currently available options (defaults in parentheses):
125
+ * - `consoleDebug` (false): whether to write the expression being simplified
126
+ and any changes to it, along with the rule responsible, to console
127
+ * - `exactFractions` (true): whether to try to convert all constants to
128
+ exact rational numbers.
129
+ * - `fractionsLimit` (10000): when `exactFractions` is true, constants will
130
+ be expressed as fractions only when both numerator and denominator
131
+ are smaller than `fractionsLimit`.
129
132
  *
130
133
  * Syntax:
131
134
  *
@@ -195,6 +198,7 @@ export var createSimplify = /* #__PURE__ */factory(name, dependencies, _ref => {
195
198
  return this(expr, rules, createMap(scope), options);
196
199
  },
197
200
  'Node, Array, Map, Object': function NodeArrayMapObject(expr, rules, scope, options) {
201
+ var debug = options.consoleDebug;
198
202
  rules = _buildRules(rules);
199
203
  var res = resolve(expr, scope);
200
204
  res = removeParens(res);
@@ -207,12 +211,33 @@ export var createSimplify = /* #__PURE__ */factory(name, dependencies, _ref => {
207
211
  visited[str] = true;
208
212
  _lastsym = 0; // counter for placeholder symbols
209
213
 
214
+ var laststr = str;
215
+ if (debug) console.log('Working on: ', str);
216
+
210
217
  for (var i = 0; i < rules.length; i++) {
218
+ var rulestr = '';
219
+
211
220
  if (typeof rules[i] === 'function') {
212
221
  res = rules[i](res, options);
222
+ if (debug) rulestr = rules[i].name;
213
223
  } else {
214
224
  flatten(res);
215
225
  res = applyRule(res, rules[i]);
226
+
227
+ if (debug) {
228
+ rulestr = "".concat(rules[i].l.toString(), " -> ").concat(rules[i].r.toString());
229
+ }
230
+ }
231
+
232
+ if (debug) {
233
+ var newstr = res.toString({
234
+ parenthesis: 'all'
235
+ });
236
+
237
+ if (newstr !== laststr) {
238
+ console.log('Applying', rulestr, 'produced', newstr);
239
+ laststr = newstr;
240
+ }
216
241
  }
217
242
 
218
243
  unflattenl(res); // using left-heavy binary tree here since custom rule functions may expect it
@@ -296,18 +321,7 @@ export var createSimplify = /* #__PURE__ */factory(name, dependencies, _ref => {
296
321
  {
297
322
  l: 'n/n1',
298
323
  r: 'n*n1^-1'
299
- }, // remove parenthesis in the case of negating a quantity
300
- {
301
- l: 'n1 + (n2 + n3)*(-1)',
302
- r: 'n1 + n2*(-1) + n3*(-1)'
303
- }, // subsume resulting -1 into constants where possible
304
- {
305
- l: '(-1) * c',
306
- r: '-c'
307
- }, {
308
- l: '(-1) * (-c)',
309
- r: 'c'
310
- }, // expand nested exponentiation
324
+ }, simplifyConstant, // expand nested exponentiation
311
325
  {
312
326
  l: '(n ^ n1) ^ n2',
313
327
  r: 'n ^ (n1 * n2)'
@@ -339,11 +353,19 @@ export var createSimplify = /* #__PURE__ */factory(name, dependencies, _ref => {
339
353
  {
340
354
  l: 'n*c + c',
341
355
  r: '(n+1)*c'
342
- }, simplifyConstant, {
356
+ }, // remove parenthesis in the case of negating a quantity
357
+ // (It might seem this rule should precede collecting like terms,
358
+ // but putting it after gives another chance of noticing like terms,
359
+ // and any new like terms produced by this will be collected
360
+ // on the next pass through all the rules.)
361
+ {
362
+ l: 'n1 + (n2 + n3)*(-1)',
363
+ r: 'n1 + n2*(-1) + n3*(-1)'
364
+ }, // make factors positive (and undo 'make non-constant terms positive')
365
+ {
343
366
  l: '(-n)*n1',
344
367
  r: '-(n*n1)'
345
- }, // make factors positive (and undo 'make non-constant terms positive')
346
- // final ordering of constants
368
+ }, // final ordering of constants
347
369
  {
348
370
  l: 'c+v',
349
371
  r: 'v+c',
@@ -1,2 +1,2 @@
1
- export var version = '10.1.0'; // Note: This file is automatically generated when building math.js.
1
+ export var version = '10.1.1'; // Note: This file is automatically generated when building math.js.
2
2
  // Changes made in this file will be overwritten.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mathjs",
3
- "version": "10.1.0",
3
+ "version": "10.1.1",
4
4
  "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.",
5
5
  "author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
6
6
  "homepage": "https://mathjs.org",
@@ -25,7 +25,7 @@
25
25
  "unit"
26
26
  ],
27
27
  "dependencies": {
28
- "@babel/runtime": "^7.16.5",
28
+ "@babel/runtime": "^7.16.7",
29
29
  "complex.js": "^2.0.15",
30
30
  "decimal.js": "^10.3.1",
31
31
  "escape-latex": "^1.2.0",
@@ -36,32 +36,32 @@
36
36
  "typed-function": "^2.0.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@babel/core": "7.16.5",
40
- "@babel/plugin-transform-object-assign": "7.16.5",
41
- "@babel/plugin-transform-runtime": "7.16.5",
42
- "@babel/preset-env": "7.16.5",
43
- "@babel/register": "7.16.5",
39
+ "@babel/core": "7.16.12",
40
+ "@babel/plugin-transform-object-assign": "7.16.7",
41
+ "@babel/plugin-transform-runtime": "7.16.10",
42
+ "@babel/preset-env": "7.16.11",
43
+ "@babel/register": "7.16.9",
44
44
  "babel-loader": "8.2.3",
45
45
  "benchmark": "2.1.4",
46
46
  "codecov": "3.8.3",
47
- "core-js": "3.20.1",
47
+ "core-js": "3.21.0",
48
48
  "del": "6.0.0",
49
49
  "dtslint": "4.2.1",
50
50
  "expr-eval": "2.0.2",
51
- "fancy-log": "1.3.3",
51
+ "fancy-log": "2.0.0",
52
52
  "glob": "7.2.0",
53
53
  "gulp": "4.0.2",
54
54
  "gulp-babel": "8.0.0",
55
55
  "handlebars": "4.7.7",
56
56
  "istanbul": "0.4.5",
57
57
  "jsep": "1.2.0",
58
- "karma": "6.3.9",
58
+ "karma": "6.3.13",
59
59
  "karma-browserstack-launcher": "1.6.0",
60
60
  "karma-firefox-launcher": "2.1.2",
61
61
  "karma-mocha": "2.0.1",
62
62
  "karma-mocha-reporter": "2.2.5",
63
63
  "karma-webpack": "4.0.2",
64
- "math-expression-evaluator": "1.3.8",
64
+ "math-expression-evaluator": "1.3.14",
65
65
  "mkdirp": "1.0.4",
66
66
  "mocha": "8.4.0",
67
67
  "ndarray": "1.0.19",
@@ -74,7 +74,7 @@
74
74
  "pad-right": "0.2.2",
75
75
  "standard": "16.0.4",
76
76
  "sylvester": "0.0.21",
77
- "typescript": "4.5.4",
77
+ "typescript": "4.5.5",
78
78
  "webpack": "4.46.0",
79
79
  "zeros": "1.0.0"
80
80
  },
package/types/index.d.ts CHANGED
@@ -3409,11 +3409,11 @@ declare namespace math {
3409
3409
 
3410
3410
  interface ConfigOptions {
3411
3411
  epsilon?: number;
3412
- matrix?: string;
3413
- number?: string;
3412
+ matrix?: 'Matrix' | 'Array';
3413
+ number?: 'number' | 'BigNumber' | 'Fraction';
3414
3414
  precision?: number;
3415
- parenthesis?: string;
3416
- randomSeed?: string;
3415
+ predictable?: boolean;
3416
+ randomSeed?: string | null;
3417
3417
  }
3418
3418
 
3419
3419
  interface MathJsJson {