mathjs 9.4.5 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/HISTORY.md +35 -0
  2. package/bin/cli.js +0 -0
  3. package/docs/expressions/syntax.md +46 -43
  4. package/docs/reference/functions/format.md +5 -2
  5. package/docs/reference/functions/parser.md +4 -4
  6. package/docs/reference/functions/setCartesian.md +3 -1
  7. package/lib/browser/math.js +5 -5
  8. package/lib/browser/math.js.map +1 -1
  9. package/lib/cjs/constants.js +1 -1
  10. package/lib/cjs/core/function/config.js +1 -1
  11. package/lib/cjs/core/function/import.js +2 -1
  12. package/lib/cjs/entry/dependenciesAny/dependenciesParserClass.generated.js +2 -2
  13. package/lib/cjs/entry/dependenciesAny.generated.js +999 -999
  14. package/lib/cjs/entry/dependenciesNumber/dependenciesParserClass.generated.js +2 -2
  15. package/lib/cjs/entry/dependenciesNumber.generated.js +581 -581
  16. package/lib/cjs/entry/impureFunctionsAny.generated.js +314 -313
  17. package/lib/cjs/entry/impureFunctionsNumber.generated.js +223 -222
  18. package/lib/cjs/entry/mainAny.js +8 -8
  19. package/lib/cjs/entry/mainNumber.js +8 -8
  20. package/lib/cjs/entry/pureFunctionsAny.generated.js +1100 -1100
  21. package/lib/cjs/entry/pureFunctionsNumber.generated.js +375 -375
  22. package/lib/cjs/entry/typeChecks.js +12 -12
  23. package/lib/cjs/expression/Parser.js +6 -5
  24. package/lib/cjs/expression/embeddedDocs/function/set/setCartesian.js +1 -1
  25. package/lib/cjs/expression/function/parser.js +4 -4
  26. package/lib/cjs/expression/node/OperatorNode.js +9 -6
  27. package/lib/cjs/expression/operators.js +1 -1
  28. package/lib/cjs/expression/parse.js +42 -6
  29. package/lib/cjs/factoriesAny.js +660 -660
  30. package/lib/cjs/factoriesNumber.js +268 -237
  31. package/lib/cjs/function/set/setCartesian.js +3 -1
  32. package/lib/cjs/function/string/format.js +5 -2
  33. package/lib/cjs/header.js +2 -2
  34. package/lib/cjs/plain/bignumber/arithmetic.js +2 -2
  35. package/lib/cjs/plain/number/arithmetic.js +10 -10
  36. package/lib/cjs/plain/number/constants.js +1 -1
  37. package/lib/cjs/plain/number/logical.js +1 -1
  38. package/lib/cjs/plain/number/probability.js +2 -1
  39. package/lib/cjs/plain/number/trigonometry.js +1 -1
  40. package/lib/cjs/plain/number/utils.js +1 -1
  41. package/lib/cjs/type/unit/physicalConstants.js +1 -1
  42. package/lib/cjs/utils/array.js +14 -14
  43. package/lib/cjs/utils/bignumber/bitwise.js +1 -1
  44. package/lib/cjs/utils/customs.js +5 -5
  45. package/lib/cjs/utils/factory.js +3 -3
  46. package/lib/cjs/utils/function.js +1 -1
  47. package/lib/cjs/utils/is.js +23 -23
  48. package/lib/cjs/utils/latex.js +2 -1
  49. package/lib/cjs/utils/map.js +3 -3
  50. package/lib/cjs/utils/noop.js +1 -1
  51. package/lib/cjs/utils/number.js +10 -6
  52. package/lib/cjs/utils/object.js +8 -8
  53. package/lib/cjs/utils/snapshot.js +1 -1
  54. package/lib/cjs/utils/string.js +2 -2
  55. package/lib/cjs/version.js +1 -1
  56. package/lib/esm/core/function/import.js +2 -1
  57. package/lib/esm/entry/dependenciesAny/dependenciesParserClass.generated.js +2 -2
  58. package/lib/esm/entry/dependenciesAny.generated.js +270 -270
  59. package/lib/esm/entry/dependenciesNumber/dependenciesParserClass.generated.js +2 -2
  60. package/lib/esm/entry/dependenciesNumber.generated.js +163 -163
  61. package/lib/esm/entry/impureFunctionsAny.generated.js +301 -301
  62. package/lib/esm/entry/impureFunctionsNumber.generated.js +211 -211
  63. package/lib/esm/entry/pureFunctionsAny.generated.js +816 -816
  64. package/lib/esm/entry/pureFunctionsNumber.generated.js +234 -234
  65. package/lib/esm/expression/Parser.js +6 -5
  66. package/lib/esm/expression/embeddedDocs/function/set/setCartesian.js +1 -1
  67. package/lib/esm/expression/function/parser.js +4 -4
  68. package/lib/esm/expression/node/OperatorNode.js +9 -6
  69. package/lib/esm/expression/parse.js +42 -6
  70. package/lib/esm/function/set/setCartesian.js +3 -1
  71. package/lib/esm/function/string/format.js +5 -2
  72. package/lib/esm/version.js +1 -1
  73. package/package.json +16 -16
  74. package/types/index.d.ts +281 -77
package/types/index.d.ts CHANGED
@@ -5,10 +5,10 @@ export as namespace math;
5
5
  export = math;
6
6
 
7
7
  type NoLiteralType<T> =
8
- T extends number ? number :
9
- T extends string ? string :
10
- T extends boolean ? boolean :
11
- T;
8
+ T extends number ? number :
9
+ T extends string ? string :
10
+ T extends boolean ? boolean :
11
+ T;
12
12
 
13
13
  declare namespace math {
14
14
  type MathArray = number[] | number[][];
@@ -21,7 +21,7 @@ declare namespace math {
21
21
  interface FactoryFunctionMap {
22
22
  [key: string]: FactoryFunction<any> | FactoryFunctionMap;
23
23
  }
24
-
24
+
25
25
 
26
26
  /** Available options for parse */
27
27
  interface ParseOptions {
@@ -156,6 +156,168 @@ declare namespace math {
156
156
  isHexDigit(c: string): boolean;
157
157
  }
158
158
 
159
+ interface AccessorNode extends MathNodeCommon {
160
+ type: 'AccessorNode';
161
+ isAccessorNode: true;
162
+ object: MathNode;
163
+ index: IndexNode;
164
+ name: string;
165
+ }
166
+ interface AccessorNodeCtor {
167
+ new(object: MathNode, index: IndexNode): AccessorNode;
168
+ }
169
+
170
+ interface ArrayNode extends MathNodeCommon {
171
+ type: 'ArrayNode';
172
+ isArrayNode: true;
173
+ items: MathNode[];
174
+ }
175
+ interface ArrayNodeCtor {
176
+ new(items: MathNode[]): ArrayNode;
177
+ }
178
+
179
+ interface AssignmentNode extends MathNodeCommon {
180
+ type: 'AssignmentNode';
181
+ isAssignmentNode: true;
182
+ object: SymbolNode | AccessorNode;
183
+ index: IndexNode | null;
184
+ value: MathNode;
185
+ name: string;
186
+ }
187
+ interface AssignmentNodeCtor {
188
+ new(object: SymbolNode, value: MathNode): AssignmentNode;
189
+ new(object: SymbolNode | AccessorNode, index: IndexNode, value: MathNode): AssignmentNode;
190
+ }
191
+
192
+ interface BlockNode extends MathNodeCommon {
193
+ type: 'BlockNode';
194
+ isBlockNode: true;
195
+ blocks: Array<{node: MathNode, visible: boolean}>;
196
+ }
197
+ interface BlockNodeCtor {
198
+ new(arr: Array<{node: MathNode} | {node: MathNode, visible: boolean}>): BlockNode;
199
+ }
200
+
201
+ interface ConditionalNode extends MathNodeCommon {
202
+ type: 'ConditionalNode';
203
+ isConditionalNode: boolean;
204
+ condition: MathNode;
205
+ trueExpr: MathNode;
206
+ falseExpr: MathNode;
207
+ }
208
+ interface ConditionalNodeCtor {
209
+ new(condition: MathNode, trueExpr: MathNode, falseExpr: MathNode): ConditionalNode;
210
+ }
211
+
212
+ interface ConstantNode extends MathNodeCommon {
213
+ type: 'ConstantNode';
214
+ isConstantNode: true;
215
+ value: any;
216
+ }
217
+
218
+ interface ConstantNodeCtor {
219
+ new(constant: number): ConstantNode;
220
+ }
221
+
222
+ interface FunctionAssignmentNode extends MathNodeCommon {
223
+ type: 'FunctionAssignmentNode';
224
+ isFunctionAssignmentNode: true;
225
+ name: string;
226
+ params: string[];
227
+ expr: MathNode;
228
+ }
229
+ interface FunctionAssignmentNodeCtor {
230
+ new(name: string, params: string[], expr: MathNode): FunctionAssignmentNode;
231
+ }
232
+
233
+ interface FunctionNode extends MathNodeCommon {
234
+ type: 'FunctionNode';
235
+ isFunctionNode: true;
236
+ fn: SymbolNode;
237
+ args: MathNode[];
238
+ }
239
+ interface FunctionNodeCtor {
240
+ new(fn: MathNode | string, args: MathNode[]): FunctionNode;
241
+ }
242
+
243
+ interface IndexNode extends MathNodeCommon {
244
+ type: 'IndexNode';
245
+ isIndexNode: true;
246
+ dimensions: MathNode[];
247
+ dotNotation: boolean;
248
+ }
249
+ interface IndexNodeCtor {
250
+ new(dimensions: MathNode[]): IndexNode;
251
+ new(dimensions: MathNode[], dotNotation: boolean): IndexNode;
252
+ }
253
+
254
+ interface ObjectNode extends MathNodeCommon {
255
+ type: 'ObjectNode';
256
+ isObjectNode: true;
257
+ properties: Record<string, MathNode>;
258
+ }
259
+ interface ObjectNodeCtor {
260
+ new(properties: Record<string, MathNode>): ObjectNode;
261
+ }
262
+
263
+ interface OperatorNode extends MathNodeCommon {
264
+ type: 'OperatorNode';
265
+ isOperatorNode: true;
266
+ op: string;
267
+ fn: string;
268
+ args: MathNode[];
269
+ implicit: boolean;
270
+ isUnary(): boolean;
271
+ isBinary(): boolean;
272
+ }
273
+ interface OperatorNodeCtor {
274
+ new(op: string, fn: string, args: MathNode[], implicit?: boolean): OperatorNode;
275
+ }
276
+
277
+ interface ParenthesisNode extends MathNodeCommon {
278
+ type: 'ParenthesisNode';
279
+ isParenthesisNode: true;
280
+ content: MathNode;
281
+ }
282
+ interface ParenthesisNodeCtor {
283
+ new(content: MathNode): ParenthesisNode;
284
+ }
285
+
286
+ interface RangeNode extends MathNodeCommon {
287
+ type: 'RangeNode';
288
+ isRangeNode: true;
289
+ start: MathNode;
290
+ end: MathNode;
291
+ step: MathNode | null;
292
+ }
293
+ interface RangeNodeCtor {
294
+ new(start: MathNode, end: MathNode, step?: MathNode): RangeNode;
295
+ }
296
+
297
+ interface RelationalNode extends MathNodeCommon {
298
+ type: 'RelationalNode';
299
+ isRelationalNode: true;
300
+ conditionals: string[];
301
+ params: MathNode[];
302
+ }
303
+ interface RelationalNodeCtor {
304
+ new(conditionals: string[], params: MathNode[]): RelationalNode;
305
+ }
306
+
307
+ interface SymbolNode extends MathNodeCommon {
308
+ type: 'SymbolNode';
309
+ isSymbolNode: true;
310
+ name: string;
311
+ }
312
+ interface SymbolNodeCtor {
313
+ new(name: string): SymbolNode;
314
+ }
315
+
316
+ type MathNode = AccessorNode | ArrayNode | AssignmentNode | BlockNode | ConditionalNode | ConstantNode |
317
+ FunctionAssignmentNode | FunctionNode | IndexNode | ObjectNode | OperatorNode | ParenthesisNode | RangeNode |
318
+ RelationalNode | SymbolNode;
319
+
320
+
159
321
  type MathJsFunctionName = keyof MathJsStatic;
160
322
 
161
323
  interface MathJsStatic extends FactoryDependencies {
@@ -173,6 +335,23 @@ declare namespace math {
173
335
  SQRT2: number;
174
336
  tau: number;
175
337
 
338
+ // Class-like constructors
339
+ AccessorNode: AccessorNodeCtor;
340
+ ArrayNode: ArrayNodeCtor;
341
+ AssignmentNode: AssignmentNodeCtor;
342
+ BlockNode: BlockNodeCtor;
343
+ ConditionalNode: ConditionalNodeCtor;
344
+ ConstantNode: ConstantNodeCtor;
345
+ FunctionAssignmentNode: FunctionAssignmentNodeCtor;
346
+ FunctionNode: FunctionNodeCtor;
347
+ IndexNode: IndexNodeCtor;
348
+ ObjectNode: ObjectNodeCtor;
349
+ OperatorNode: OperatorNodeCtor;
350
+ ParenthesisNode: ParenthesisNodeCtor;
351
+ RangeNode: RangeNodeCtor;
352
+ RelationalNode: RelationalNodeCtor;
353
+ SymbolNode: SymbolNodeCtor;
354
+
176
355
  /**
177
356
  * If null were to be included in this interface, it would be
178
357
  * auto-suggested as an import in VSCode. This causes issues because
@@ -310,8 +489,8 @@ declare namespace math {
310
489
  * @returns Returns a fraction
311
490
  */
312
491
  fraction(
313
- numerator: number | string | MathArray | Matrix,
314
- denominator?: number | string | MathArray | Matrix
492
+ numerator: number | string | MathArray | Matrix,
493
+ denominator?: number | string | MathArray | Matrix
315
494
  ): Fraction | MathArray | Matrix;
316
495
 
317
496
  /**
@@ -500,6 +679,7 @@ declare namespace math {
500
679
  */
501
680
  qr(A: Matrix | MathArray): { Q: MathArray | Matrix; R: MathArray | Matrix };
502
681
 
682
+ rationalize(expr: MathNode | string, optional?: object | boolean, detailed?: false): MathNode;
503
683
  /**
504
684
  * Transform a rationalizable expression in a rational fraction. If
505
685
  * rational fraction is one variable polynomial then converts the
@@ -513,11 +693,11 @@ declare namespace math {
513
693
  * @returns The rational polynomial of expr
514
694
  */
515
695
  rationalize(
516
- expr: MathNode | string,
517
- optional?: object | boolean,
518
- detailed?: true
696
+ expr: MathNode | string,
697
+ optional?: object | boolean,
698
+ detailed?: true
519
699
  ): { expression: MathNode | string; variables: string[]; coefficients: MathType[] };
520
- rationalize(expr: MathNode | string, optional?: object | boolean, detailed?: false): MathNode;
700
+
521
701
 
522
702
  /**
523
703
  * Simplify an expression tree.
@@ -530,13 +710,7 @@ declare namespace math {
530
710
  * @param [options] (optional) An object with simplify options
531
711
  * @returns Returns the simplified form of expr
532
712
  */
533
- simplify(
534
- expr: MathNode | string,
535
- rules?: Array<{ l: string; r: string } | string | ((node: MathNode) => MathNode)>,
536
- scope?: object,
537
- options?: SimplifyOptions,
538
- ): MathNode;
539
- simplify(expr: MathNode | string, scope?: object, options?: SimplifyOptions): MathNode;
713
+ simplify: Simplify;
540
714
 
541
715
  /**
542
716
  * Calculate the Sparse Matrix LU decomposition with full pivoting.
@@ -649,6 +823,7 @@ declare namespace math {
649
823
  * @returns Quotient, x / y
650
824
  */
651
825
  divide(x: Unit, y: Unit): Unit | number;
826
+ divide(x: Unit, y: number): Unit;
652
827
  divide(x: number, y: number): number;
653
828
  divide(x: MathType, y: MathType): MathType;
654
829
 
@@ -728,17 +903,17 @@ declare namespace math {
728
903
  floor(x: MathArray): MathArray;
729
904
  floor(x: Matrix): Matrix;
730
905
 
731
- /**
906
+ /**
732
907
  * Round a value towards minus infinity. For matrices, the function is
733
908
  * evaluated element wise.
734
909
  * @param x Number to be rounded
735
910
  * @param n Number of decimals Default value: 0.
736
911
  * @returns Rounded value
737
912
  */
738
- floor(
913
+ floor(
739
914
  x: number | BigNumber | Fraction | Complex | MathArray | Matrix,
740
915
  n: number | BigNumber | MathArray
741
- ): number | BigNumber | Fraction | Complex | MathArray | Matrix;
916
+ ): number | BigNumber | Fraction | Complex | MathArray | Matrix;
742
917
 
743
918
  /**
744
919
  * Calculate the greatest common divisor for two or more values or
@@ -834,8 +1009,8 @@ declare namespace math {
834
1009
  * @returns Returns the remainder of x divided by y
835
1010
  */
836
1011
  mod<T extends number | BigNumber | Fraction | MathArray | Matrix>(
837
- x: T,
838
- y: number | BigNumber | Fraction | MathArray | Matrix
1012
+ x: T,
1013
+ y: number | BigNumber | Fraction | MathArray | Matrix
839
1014
  ): NoLiteralType<T>;
840
1015
 
841
1016
  /**
@@ -888,8 +1063,8 @@ declare namespace math {
888
1063
  * @returns Rounded value of x
889
1064
  */
890
1065
  round<T extends number | BigNumber | Fraction | Complex | MathArray | Matrix>(
891
- x: T,
892
- n?: number | BigNumber | MathArray
1066
+ x: T,
1067
+ n?: number | BigNumber | MathArray
893
1068
  ): NoLiteralType<T>;
894
1069
 
895
1070
  /**
@@ -941,6 +1116,8 @@ declare namespace math {
941
1116
  * @param y Value to subtract from x
942
1117
  * @returns Subtraction of x and y
943
1118
  */
1119
+ subtract(x: number, y: number): number;
1120
+ subtract(x: Unit, y: Unit): Unit;
944
1121
  subtract(x: MathType, y: MathType): MathType;
945
1122
 
946
1123
  /**
@@ -1201,8 +1378,8 @@ declare namespace math {
1201
1378
  * nonzero/nonempty value.
1202
1379
  */
1203
1380
  and(
1204
- x: number | BigNumber | Complex | Unit | MathArray | Matrix,
1205
- y: number | BigNumber | Complex | Unit | MathArray | Matrix
1381
+ x: number | BigNumber | Complex | Unit | MathArray | Matrix,
1382
+ y: number | BigNumber | Complex | Unit | MathArray | Matrix
1206
1383
  ): boolean | MathArray | Matrix;
1207
1384
 
1208
1385
  /**
@@ -1223,8 +1400,8 @@ declare namespace math {
1223
1400
  * nonzero/nonempty value.
1224
1401
  */
1225
1402
  or(
1226
- x: number | BigNumber | Complex | Unit | MathArray | Matrix,
1227
- y: number | BigNumber | Complex | Unit | MathArray | Matrix
1403
+ x: number | BigNumber | Complex | Unit | MathArray | Matrix,
1404
+ y: number | BigNumber | Complex | Unit | MathArray | Matrix
1228
1405
  ): boolean | MathArray | Matrix;
1229
1406
 
1230
1407
  /**
@@ -1237,14 +1414,27 @@ declare namespace math {
1237
1414
  * nonzero/nonempty value.
1238
1415
  */
1239
1416
  xor(
1240
- x: number | BigNumber | Complex | Unit | MathArray | Matrix,
1241
- y: number | BigNumber | Complex | Unit | MathArray | Matrix
1417
+ x: number | BigNumber | Complex | Unit | MathArray | Matrix,
1418
+ y: number | BigNumber | Complex | Unit | MathArray | Matrix
1242
1419
  ): boolean | MathArray | Matrix;
1243
1420
 
1244
1421
  /*************************************************************************
1245
1422
  * Matrix functions
1246
1423
  ************************************************************************/
1247
1424
 
1425
+ /**
1426
+ * Apply a function that maps an array to a scalar along a given axis of a
1427
+ * matrix or array. Returns a new matrix or array with one less dimension
1428
+ * than the input.
1429
+ * @param array The input Matrix
1430
+ * @param dim The dimension along which the callback is applied
1431
+ * @param callback The callback function that is applied. This Function should take an
1432
+ * array or 1-d matrix as an input and return a number.
1433
+ * @returns The residual matrix with the function applied over some dimension.
1434
+ */
1435
+ apply<T extends MathArray | Matrix>(array: T, dim: number, callback: (array: MathArray | Matrix) => number): T
1436
+
1437
+
1248
1438
  /**
1249
1439
  * Concatenate two or more matrices. dim: number is a zero-based
1250
1440
  * dimension over which to concatenate the matrices. By default the last
@@ -1312,7 +1502,7 @@ declare namespace math {
1312
1502
  * @param prec Precision, default value: 1e-15
1313
1503
  * @returns Object containing an array of eigenvalues and a matrix with eigenvectors as columns.
1314
1504
  */
1315
- eigs(x: MathArray | Matrix, prec?:number|BigNumber): {values: MathArray | Matrix, vectors: MathArray | Matrix}
1505
+ eigs(x: MathArray | Matrix, prec?:number|BigNumber): {values: MathArray | Matrix, vectors: MathArray | Matrix}
1316
1506
 
1317
1507
  /**
1318
1508
  * Compute the matrix exponential, expm(A) = e^A. The matrix must be
@@ -1351,8 +1541,8 @@ declare namespace math {
1351
1541
  * traversed. The function must return a boolean.
1352
1542
  */
1353
1543
  filter(
1354
- x: Matrix | MathArray | string[],
1355
- test: ((value: any, index: any, matrix: Matrix | MathArray | string[]) => boolean) | RegExp
1544
+ x: Matrix | MathArray | string[],
1545
+ test: ((value: any, index: any, matrix: Matrix | MathArray | string[]) => boolean) | RegExp
1356
1546
  ): Matrix | MathArray;
1357
1547
 
1358
1548
  /**
@@ -1808,8 +1998,8 @@ declare namespace math {
1808
1998
 
1809
1999
  /**
1810
2000
  * Create the cartesian product of two (multi)sets. Multi-dimension
1811
- * arrays will be converted to single-dimension arrays before the
1812
- * operation.
2001
+ * arrays will be converted to single-dimension arrays and the values
2002
+ * will be sorted in ascending order before the operation.
1813
2003
  * @param a1 A (multi)set
1814
2004
  * @param a2 A (multi)set
1815
2005
  * @returns The cartesian product of two (multi)sets
@@ -2429,15 +2619,15 @@ declare namespace math {
2429
2619
  */
2430
2620
  clone(x: any): any;
2431
2621
 
2432
- /**
2622
+ /**
2433
2623
  * Test whether a value is an numeric value. In case of a string,
2434
- * true is returned if the string contains a numeric value.
2624
+ * true is returned if the string contains a numeric value.
2435
2625
  * @param x Value to be tested
2436
2626
  * @returns Returns true when x is a number, BigNumber, Fraction, Boolean, or a String containing number.
2437
2627
  * Returns false for other types.
2438
2628
  * Throws an error in case of unknown types.
2439
2629
  */
2440
- hasNumericValue(x: any ): boolean| boolean[];
2630
+ hasNumericValue(x: any ): boolean| boolean[];
2441
2631
 
2442
2632
  /**
2443
2633
  * Test whether a value is an integer number. The function supports
@@ -2540,12 +2730,12 @@ declare namespace math {
2540
2730
  * Factory and Dependencies
2541
2731
  ************************************************************************/
2542
2732
  interface FactoryDependencies {
2543
- create: (factories: FactoryFunctionMap, config?: ConfigOptions) => Partial<MathJsStatic>;
2733
+ create: (factories: FactoryFunctionMap, config?: ConfigOptions) => MathJsStatic;
2544
2734
  factory: <T>(
2545
- name: string,
2546
- dependencies: MathJsFunctionName[],
2547
- create: (injected: Partial<MathJsStatic>) => T,
2548
- meta?: any
2735
+ name: string,
2736
+ dependencies: MathJsFunctionName[],
2737
+ create: (injected: Partial<MathJsStatic>) => T,
2738
+ meta?: any
2549
2739
  ) => FactoryFunction<T>;
2550
2740
  all: FactoryFunctionMap;
2551
2741
 
@@ -2879,6 +3069,7 @@ declare namespace math {
2879
3069
  create(data: MathArray, datatype?: string): void;
2880
3070
  density(): number;
2881
3071
  subset(index: Index, replacement?: any, defaultValue?: any): Matrix;
3072
+ apply(dim: number, callback: (array: MathArray | Matrix) => number): Matrix | MathArray;
2882
3073
  get(index: number[]): any;
2883
3074
  set(index: number[], value: any, defaultValue?: number | string): Matrix;
2884
3075
  resize(size: MathArray | Matrix, defaultValue?: number | string): Matrix;
@@ -2941,14 +3132,14 @@ declare namespace math {
2941
3132
  pow(unit: Unit): Unit;
2942
3133
  abs(unit: Unit): Unit;
2943
3134
  to(unit: string): Unit;
2944
- toNumber(unit: string): number;
2945
- toNumeric(unit: string): number | Fraction | BigNumber;
3135
+ toNumber(unit?: string): number;
3136
+ toNumeric(unit?: string): number | Fraction | BigNumber;
2946
3137
  toSI(): Unit;
2947
3138
  toString(): string;
2948
3139
  toJSON(): MathJSON;
2949
3140
  formatUnits(): string;
2950
3141
  format(options: FormatOptions): string;
2951
- splitUnit(parts: ReadonlyArray<string | Unit>): Unit[];
3142
+ splitUnit(parts: ReadonlyArray<string | Unit>): Unit[];
2952
3143
  }
2953
3144
 
2954
3145
  interface CreateUnitOptions {
@@ -2969,6 +3160,26 @@ declare namespace math {
2969
3160
  fractionsLimit?: number;
2970
3161
  }
2971
3162
 
3163
+ type SimplifyRule = { l: string; r: string } | string | ((node: MathNode) => MathNode);
3164
+
3165
+ interface Simplify {
3166
+ (
3167
+ expr: MathNode | string,
3168
+ rules?: SimplifyRule[],
3169
+ scope?: object,
3170
+ options?: SimplifyOptions,
3171
+ ): MathNode;
3172
+ (
3173
+ expr: MathNode | string,
3174
+ scope?: object,
3175
+ options?: SimplifyOptions,
3176
+ ): MathNode;
3177
+
3178
+ rules: SimplifyRule[];
3179
+
3180
+ simplifyCore(expr: MathNode): MathNode;
3181
+ }
3182
+
2972
3183
  interface UnitDefinition {
2973
3184
  definition?: string | Unit;
2974
3185
  prefixes?: string;
@@ -2982,32 +3193,14 @@ declare namespace math {
2982
3193
  evaluate(scope?: any): any;
2983
3194
  }
2984
3195
 
2985
- interface MathNode {
2986
- isNode: boolean;
2987
- isAccessorNode?: boolean;
2988
- isArrayNode?: boolean;
2989
- isAssignmentNode?: boolean;
2990
- isBlockNode?: boolean;
2991
- isConditionalNode?: boolean;
2992
- isConstantNode?: boolean;
2993
- isFunctionAssignmentNode?: boolean;
2994
- isFunctionNode?: boolean;
2995
- isIndexNode?: boolean;
2996
- isObjectNode?: boolean;
2997
- isOperatorNode?: boolean;
2998
- isParenthesisNode?: boolean;
2999
- isRangeNode?: boolean;
3000
- isRelationalNode?: boolean;
3001
- isSymbolNode?: boolean;
3196
+ interface MathNodeCommon {
3197
+ isNode: true;
3198
+ comment: string;
3199
+ type: 'AccessorNode' | 'ArrayNode' | 'AssignmentNode' | 'BlockNode' | 'ConditionalNode' | 'ConstantNode' |
3200
+ 'FunctionAssignmentNode' | 'FunctionNode' | 'IndexNode' | 'ObjectNode' | 'OperatorNode' | 'ParenthesisNode' |
3201
+ 'RangeNode' | 'RelationalNode' | 'SymbolNode';
3202
+
3002
3203
  isUpdateNode?: boolean;
3003
- comment?: string;
3004
- content?: MathNode;
3005
- op?: string;
3006
- fn?: string;
3007
- args?: MathNode[];
3008
- type: string;
3009
- name?: string;
3010
- value?: any;
3011
3204
 
3012
3205
  /**
3013
3206
  * Create a shallow clone of the node. The node itself is cloned, its
@@ -3082,7 +3275,7 @@ declare namespace math {
3082
3275
  /**
3083
3276
  * Get a HTML representation of the parsed expression.
3084
3277
  */
3085
- toHtml(options?: object): string;
3278
+ toHTML(options?: object): string;
3086
3279
 
3087
3280
  /**
3088
3281
  * Get a string representation of the parsed expression. This is not
@@ -3155,7 +3348,7 @@ declare namespace math {
3155
3348
  }
3156
3349
 
3157
3350
  interface Parser {
3158
- evaluate(expr: string): any;
3351
+ evaluate(expr: string | string[]): any;
3159
3352
  get(variable: string): any;
3160
3353
  getAll(): { [key: string]: any };
3161
3354
  set: (variable: string, value: any) => void;
@@ -3445,7 +3638,7 @@ declare namespace math {
3445
3638
  * can be specified as an object, string, or function.
3446
3639
  * @param scope Scope to variables
3447
3640
  */
3448
- simplify(rules?: Array<{ l: string; r: string } | string | ((node: MathNode) => MathNode)>, scope?: object): MathJsChain;
3641
+ simplify(rules?: SimplifyRule[], scope?: object): MathJsChain;
3449
3642
 
3450
3643
  /**
3451
3644
  * Calculate the Sparse Matrix LU decomposition with full pivoting.
@@ -3488,6 +3681,17 @@ declare namespace math {
3488
3681
  */
3489
3682
  add(y: MathType): MathJsChain;
3490
3683
 
3684
+ /**
3685
+ * Apply a function that maps an array to a scalar along a given axis of the
3686
+ * matrix or array. Returns a new matrix or array with one less dimension
3687
+ * than the input.
3688
+ * @param dim The dimension along which the callback is applied
3689
+ * @param callback The callback function that is applied. This Function should take an
3690
+ * array or 1-d matrix as an input and return a number.
3691
+ * @returns The residual matrix with the function applied over some dimension.
3692
+ */
3693
+ apply(dim: number, callback: (array: Array<MathType> | Matrix) => number): MathJsChain;
3694
+
3491
3695
  /**
3492
3696
  * Calculate the cubic root of a value. For matrices, the function is
3493
3697
  * evaluated element wise.
@@ -4303,8 +4507,8 @@ declare namespace math {
4303
4507
 
4304
4508
  /**
4305
4509
  * Create the cartesian product of two (multi)sets. Multi-dimension
4306
- * arrays will be converted to single-dimension arrays before the
4307
- * operation.
4510
+ * arrays will be converted to single-dimension arrays and the values
4511
+ * will be sorted in ascending order before the operation.
4308
4512
  * @param a2 A (multi)set
4309
4513
  */
4310
4514
  setCartesian(a2: MathArray | Matrix): MathJsChain;