mathjs 11.4.0 → 11.5.1
Sign up to get free protection for your applications and to get access to all the features.
- package/HISTORY.md +29 -0
- package/NOTICE +1 -1
- package/README.md +2 -2
- package/bin/cli.js +1 -1
- package/lib/browser/math.js +1 -1
- package/lib/browser/math.js.LICENSE.txt +3 -3
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/expression/embeddedDocs/function/arithmetic/invmod.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/arithmetic/pow.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/matrix/matrixFromColumns.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/matrix/matrixFromFunction.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/matrix/matrixFromRows.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/matrix/reshape.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/matrix/rotate.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/probability/lgamma.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/statistics/max.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/statistics/mean.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/statistics/min.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/statistics/std.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/statistics/sum.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/statistics/variance.js +1 -1
- package/lib/cjs/function/algebra/simplify.js +58 -5
- package/lib/cjs/function/matrix/reshape.js +1 -1
- package/lib/cjs/function/statistics/max.js +2 -2
- package/lib/cjs/function/statistics/mean.js +2 -2
- package/lib/cjs/function/statistics/min.js +2 -2
- package/lib/cjs/function/statistics/mode.js +1 -1
- package/lib/cjs/function/statistics/prod.js +1 -1
- package/lib/cjs/function/statistics/quantileSeq.js +1 -1
- package/lib/cjs/function/statistics/sum.js +3 -2
- package/lib/cjs/function/statistics/variance.js +1 -1
- package/lib/cjs/function/string/format.js +24 -24
- package/lib/cjs/header.js +3 -3
- package/lib/cjs/version.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/arithmetic/invmod.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/arithmetic/pow.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/matrix/matrixFromColumns.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/matrix/matrixFromFunction.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/matrix/matrixFromRows.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/matrix/reshape.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/matrix/rotate.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/probability/lgamma.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/statistics/max.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/statistics/mean.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/statistics/min.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/statistics/std.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/statistics/sum.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/statistics/variance.js +1 -1
- package/lib/esm/function/algebra/simplify.js +58 -5
- package/lib/esm/function/matrix/reshape.js +1 -1
- package/lib/esm/function/statistics/max.js +2 -2
- package/lib/esm/function/statistics/mean.js +2 -2
- package/lib/esm/function/statistics/min.js +2 -2
- package/lib/esm/function/statistics/mode.js +1 -1
- package/lib/esm/function/statistics/prod.js +1 -1
- package/lib/esm/function/statistics/quantileSeq.js +1 -1
- package/lib/esm/function/statistics/sum.js +3 -2
- package/lib/esm/function/statistics/variance.js +1 -1
- package/lib/esm/function/string/format.js +24 -24
- package/lib/esm/header.js +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +21 -23
- package/types/index.d.ts +71 -10
@@ -9,7 +9,7 @@ var invmodDocs = {
|
|
9
9
|
category: 'Arithmetic',
|
10
10
|
syntax: ['invmod(a, b)'],
|
11
11
|
description: 'Calculate the (modular) multiplicative inverse of a modulo b. Solution to the equation ax ≣ 1 (mod b)',
|
12
|
-
examples: ['invmod(8, 12)=NaN', 'invmod(7, 13)=2', '
|
12
|
+
examples: ['invmod(8, 12)=NaN', 'invmod(7, 13)=2', 'invmod(15151, 15122)=10429'],
|
13
13
|
seealso: ['gcd', 'xgcd']
|
14
14
|
};
|
15
15
|
exports.invmodDocs = invmodDocs;
|
@@ -9,7 +9,7 @@ var powDocs = {
|
|
9
9
|
category: 'Operators',
|
10
10
|
syntax: ['x ^ y', 'pow(x, y)'],
|
11
11
|
description: 'Calculates the power of x to y, x^y.',
|
12
|
-
examples: ['2^3', '2*2*2', '1 + e ^ (pi * i)', '
|
12
|
+
examples: ['2^3', '2*2*2', '1 + e ^ (pi * i)', 'pow([[1, 2], [4, 3]], 2)', 'pow([[1, 2], [4, 3]], -1)'],
|
13
13
|
seealso: ['multiply', 'nthRoot', 'nthRoots', 'sqrt']
|
14
14
|
};
|
15
15
|
exports.powDocs = powDocs;
|
@@ -7,7 +7,7 @@ exports.matrixFromColumnsDocs = void 0;
|
|
7
7
|
var matrixFromColumnsDocs = {
|
8
8
|
name: 'matrixFromColumns',
|
9
9
|
category: 'Matrix',
|
10
|
-
syntax: ['
|
10
|
+
syntax: ['matrixFromColumns(...arr)', 'matrixFromColumns(row1, row2)', 'matrixFromColumns(row1, row2, row3)'],
|
11
11
|
description: 'Create a dense matrix from vectors as individual columns.',
|
12
12
|
examples: ['matrixFromColumns([1, 2, 3], [[4],[5],[6]])'],
|
13
13
|
seealso: ['matrix', 'matrixFromRows', 'matrixFromFunction', 'zeros']
|
@@ -7,7 +7,7 @@ exports.matrixFromFunctionDocs = void 0;
|
|
7
7
|
var matrixFromFunctionDocs = {
|
8
8
|
name: 'matrixFromFunction',
|
9
9
|
category: 'Matrix',
|
10
|
-
syntax: ['
|
10
|
+
syntax: ['matrixFromFunction(size, fn)', 'matrixFromFunction(size, fn, format)', 'matrixFromFunction(size, fn, format, datatype)', 'matrixFromFunction(size, format, fn)', 'matrixFromFunction(size, format, datatype, fn)'],
|
11
11
|
description: 'Create a matrix by evaluating a generating function at each index.',
|
12
12
|
examples: ['f(I) = I[1] - I[2]', 'matrixFromFunction([3,3], f)', 'g(I) = I[1] - I[2] == 1 ? 4 : 0', 'matrixFromFunction([100, 100], "sparse", g)', 'matrixFromFunction([5], random)'],
|
13
13
|
seealso: ['matrix', 'matrixFromRows', 'matrixFromColumns', 'zeros']
|
@@ -7,7 +7,7 @@ exports.matrixFromRowsDocs = void 0;
|
|
7
7
|
var matrixFromRowsDocs = {
|
8
8
|
name: 'matrixFromRows',
|
9
9
|
category: 'Matrix',
|
10
|
-
syntax: ['
|
10
|
+
syntax: ['matrixFromRows(...arr)', 'matrixFromRows(row1, row2)', 'matrixFromRows(row1, row2, row3)'],
|
11
11
|
description: 'Create a dense matrix from vectors as individual rows.',
|
12
12
|
examples: ['matrixFromRows([1, 2, 3], [[4],[5],[6]])'],
|
13
13
|
seealso: ['matrix', 'matrixFromColumns', 'matrixFromFunction', 'zeros']
|
@@ -9,7 +9,7 @@ var reshapeDocs = {
|
|
9
9
|
category: 'Matrix',
|
10
10
|
syntax: ['reshape(x, sizes)'],
|
11
11
|
description: 'Reshape a multi dimensional array to fit the specified dimensions.',
|
12
|
-
examples: ['reshape([1, 2, 3, 4, 5, 6], [2, 3])', 'reshape([[1, 2], [3, 4]], [1, 4])', 'reshape([[1, 2], [3, 4]], [4])'],
|
12
|
+
examples: ['reshape([1, 2, 3, 4, 5, 6], [2, 3])', 'reshape([[1, 2], [3, 4]], [1, 4])', 'reshape([[1, 2], [3, 4]], [4])', 'reshape([1, 2, 3, 4], [-1, 2])'],
|
13
13
|
seealso: ['size', 'squeeze', 'resize']
|
14
14
|
};
|
15
15
|
exports.reshapeDocs = reshapeDocs;
|
@@ -9,7 +9,7 @@ var rotateDocs = {
|
|
9
9
|
category: 'Matrix',
|
10
10
|
syntax: ['rotate(w, theta)', 'rotate(w, theta, v)'],
|
11
11
|
description: 'Returns a 2-D rotation matrix (2x2) for a given angle (in radians). ' + 'Returns a 2-D rotation matrix (3x3) of a given angle (in radians) around given axis.',
|
12
|
-
examples: ['rotate([1, 0],
|
12
|
+
examples: ['rotate([1, 0], pi / 2)', 'rotate(matrix([1, 0]), unit("35deg"))', 'rotate([1, 0, 0], unit("90deg"), [0, 0, 1])', 'rotate(matrix([1, 0, 0]), unit("90deg"), matrix([0, 0, 1]))'],
|
13
13
|
seealso: ['matrix', 'rotationMatrix']
|
14
14
|
};
|
15
15
|
exports.rotateDocs = rotateDocs;
|
@@ -9,7 +9,7 @@ var lgammaDocs = {
|
|
9
9
|
category: 'Probability',
|
10
10
|
syntax: ['lgamma(n)'],
|
11
11
|
description: 'Logarithm of the gamma function for real, positive numbers and complex numbers, ' + 'using Lanczos approximation for numbers and Stirling series for complex numbers.',
|
12
|
-
examples: ['lgamma(4)', 'lgamma(1/2)', 'lgamma(
|
12
|
+
examples: ['lgamma(4)', 'lgamma(1/2)', 'lgamma(i)', 'lgamma(complex(1.1, 2))'],
|
13
13
|
seealso: ['gamma']
|
14
14
|
};
|
15
15
|
exports.lgammaDocs = lgammaDocs;
|
@@ -7,7 +7,7 @@ exports.maxDocs = void 0;
|
|
7
7
|
var maxDocs = {
|
8
8
|
name: 'max',
|
9
9
|
category: 'Statistics',
|
10
|
-
syntax: ['max(a, b, c, ...)', 'max(A)', 'max(A,
|
10
|
+
syntax: ['max(a, b, c, ...)', 'max(A)', 'max(A, dimension)'],
|
11
11
|
description: 'Compute the maximum value of a list of values.',
|
12
12
|
examples: ['max(2, 3, 4, 1)', 'max([2, 3, 4, 1])', 'max([2, 5; 4, 3])', 'max([2, 5; 4, 3], 1)', 'max([2, 5; 4, 3], 2)', 'max(2.7, 7.1, -4.5, 2.0, 4.1)', 'min(2.7, 7.1, -4.5, 2.0, 4.1)'],
|
13
13
|
seealso: ['mean', 'median', 'min', 'prod', 'std', 'sum', 'variance']
|
@@ -7,7 +7,7 @@ exports.meanDocs = void 0;
|
|
7
7
|
var meanDocs = {
|
8
8
|
name: 'mean',
|
9
9
|
category: 'Statistics',
|
10
|
-
syntax: ['mean(a, b, c, ...)', 'mean(A)', 'mean(A,
|
10
|
+
syntax: ['mean(a, b, c, ...)', 'mean(A)', 'mean(A, dimension)'],
|
11
11
|
description: 'Compute the arithmetic mean of a list of values.',
|
12
12
|
examples: ['mean(2, 3, 4, 1)', 'mean([2, 3, 4, 1])', 'mean([2, 5; 4, 3])', 'mean([2, 5; 4, 3], 1)', 'mean([2, 5; 4, 3], 2)', 'mean([1.0, 2.7, 3.2, 4.0])'],
|
13
13
|
seealso: ['max', 'median', 'min', 'prod', 'std', 'sum', 'variance']
|
@@ -7,7 +7,7 @@ exports.minDocs = void 0;
|
|
7
7
|
var minDocs = {
|
8
8
|
name: 'min',
|
9
9
|
category: 'Statistics',
|
10
|
-
syntax: ['min(a, b, c, ...)', 'min(A)', 'min(A,
|
10
|
+
syntax: ['min(a, b, c, ...)', 'min(A)', 'min(A, dimension)'],
|
11
11
|
description: 'Compute the minimum value of a list of values.',
|
12
12
|
examples: ['min(2, 3, 4, 1)', 'min([2, 3, 4, 1])', 'min([2, 5; 4, 3])', 'min([2, 5; 4, 3], 1)', 'min([2, 5; 4, 3], 2)', 'min(2.7, 7.1, -4.5, 2.0, 4.1)', 'max(2.7, 7.1, -4.5, 2.0, 4.1)'],
|
13
13
|
seealso: ['max', 'mean', 'median', 'prod', 'std', 'sum', 'variance']
|
@@ -7,7 +7,7 @@ exports.stdDocs = void 0;
|
|
7
7
|
var stdDocs = {
|
8
8
|
name: 'std',
|
9
9
|
category: 'Statistics',
|
10
|
-
syntax: ['std(a, b, c, ...)', 'std(A)', 'std(A, normalization)'],
|
10
|
+
syntax: ['std(a, b, c, ...)', 'std(A)', 'std(A, dimension)', 'std(A, normalization)', 'std(A, dimension, normalization)'],
|
11
11
|
description: 'Compute the standard deviation of all values, defined as std(A) = sqrt(variance(A)). Optional parameter normalization can be "unbiased" (default), "uncorrected", or "biased".',
|
12
12
|
examples: ['std(2, 4, 6)', 'std([2, 4, 6, 8])', 'std([2, 4, 6, 8], "uncorrected")', 'std([2, 4, 6, 8], "biased")', 'std([1, 2, 3; 4, 5, 6])'],
|
13
13
|
seealso: ['max', 'mean', 'min', 'median', 'prod', 'sum', 'variance']
|
@@ -7,7 +7,7 @@ exports.sumDocs = void 0;
|
|
7
7
|
var sumDocs = {
|
8
8
|
name: 'sum',
|
9
9
|
category: 'Statistics',
|
10
|
-
syntax: ['sum(a, b, c, ...)', 'sum(A)'],
|
10
|
+
syntax: ['sum(a, b, c, ...)', 'sum(A)', 'sum(A, dimension)'],
|
11
11
|
description: 'Compute the sum of all values.',
|
12
12
|
examples: ['sum(2, 3, 4, 1)', 'sum([2, 3, 4, 1])', 'sum([2, 5; 4, 3])'],
|
13
13
|
seealso: ['max', 'mean', 'median', 'min', 'prod', 'std', 'sum', 'variance']
|
@@ -7,7 +7,7 @@ exports.varianceDocs = void 0;
|
|
7
7
|
var varianceDocs = {
|
8
8
|
name: 'variance',
|
9
9
|
category: 'Statistics',
|
10
|
-
syntax: ['variance(a, b, c, ...)', 'variance(A)', 'variance(A, normalization)'],
|
10
|
+
syntax: ['variance(a, b, c, ...)', 'variance(A)', 'variance(A, dimension)', 'variance(A, normalization)', 'variance(A, dimension, normalization)'],
|
11
11
|
description: 'Compute the variance of all values. Optional parameter normalization can be "unbiased" (default), "uncorrected", or "biased".',
|
12
12
|
examples: ['variance(2, 4, 6)', 'variance([2, 4, 6, 8])', 'variance([2, 4, 6, 8], "uncorrected")', 'variance([2, 4, 6, 8], "biased")', 'variance([1, 2, 3; 4, 5, 6])'],
|
13
13
|
seealso: ['max', 'mean', 'min', 'median', 'min', 'prod', 'std', 'sum']
|
@@ -421,9 +421,17 @@ var createSimplify = /* #__PURE__ */(0, _factory.factory)(name, dependencies, fu
|
|
421
421
|
}, {
|
422
422
|
l: 'n3^(-n4)*n1 + n3^n5 * n2',
|
423
423
|
r: 'n3^(-n4)*(n1 + n3^(n4+n5)*n2)'
|
424
|
-
},
|
424
|
+
},
|
425
|
+
// noncommutative additional cases (term collection & factoring)
|
426
|
+
{
|
425
427
|
s: 'n*vd + vd -> (n+1)*vd',
|
426
|
-
|
428
|
+
assuming: {
|
429
|
+
multiply: {
|
430
|
+
commutative: false
|
431
|
+
}
|
432
|
+
}
|
433
|
+
}, {
|
434
|
+
s: 'vd + n*vd -> (1+n)*vd',
|
427
435
|
assuming: {
|
428
436
|
multiply: {
|
429
437
|
commutative: false
|
@@ -436,6 +444,16 @@ var createSimplify = /* #__PURE__ */(0, _factory.factory)(name, dependencies, fu
|
|
436
444
|
commutative: false
|
437
445
|
}
|
438
446
|
}
|
447
|
+
}, {
|
448
|
+
s: 'n^n1 * n -> n^(n1+1)',
|
449
|
+
assuming: {
|
450
|
+
divide: {
|
451
|
+
total: true
|
452
|
+
},
|
453
|
+
multiply: {
|
454
|
+
commutative: false
|
455
|
+
}
|
456
|
+
}
|
439
457
|
}, {
|
440
458
|
s: 'n1*n3^(-n4) + n2 * n3 -> (n1 + n2*n3^(n4 + 1))*n3^(-n4)',
|
441
459
|
assuming: {
|
@@ -460,6 +478,13 @@ var createSimplify = /* #__PURE__ */(0, _factory.factory)(name, dependencies, fu
|
|
460
478
|
commutative: false
|
461
479
|
}
|
462
480
|
}
|
481
|
+
}, {
|
482
|
+
s: 'cd + cd*n -> cd*(1+n)',
|
483
|
+
assuming: {
|
484
|
+
multiply: {
|
485
|
+
commutative: false
|
486
|
+
}
|
487
|
+
}
|
463
488
|
}, simplifyConstant,
|
464
489
|
// Second: before returning expressions to "standard form"
|
465
490
|
|
@@ -616,15 +641,33 @@ var createSimplify = /* #__PURE__ */(0, _factory.factory)(name, dependencies, fu
|
|
616
641
|
newRule.evaluate = parse(ruleObject.evaluate);
|
617
642
|
}
|
618
643
|
if (isAssociative(newRule.l, context)) {
|
644
|
+
var nonCommutative = !isCommutative(newRule.l, context);
|
645
|
+
var leftExpandsym;
|
646
|
+
// Gen. the LHS placeholder used in this NC-context specific expansion rules
|
647
|
+
if (nonCommutative) leftExpandsym = _getExpandPlaceholderSymbol();
|
619
648
|
var makeNode = createMakeNodeFunction(newRule.l);
|
620
649
|
var expandsym = _getExpandPlaceholderSymbol();
|
621
650
|
newRule.expanded = {};
|
622
|
-
newRule.expanded.l = makeNode([newRule.l
|
651
|
+
newRule.expanded.l = makeNode([newRule.l, expandsym]);
|
623
652
|
// Push the expandsym into the deepest possible branch.
|
624
653
|
// This helps to match the newRule against nodes returned from getSplits() later on.
|
625
654
|
flatten(newRule.expanded.l, context);
|
626
655
|
unflattenr(newRule.expanded.l, context);
|
627
656
|
newRule.expanded.r = makeNode([newRule.r, expandsym]);
|
657
|
+
|
658
|
+
// In and for a non-commutative context, attempting with yet additional expansion rules makes
|
659
|
+
// way for more matches cases of multi-arg expressions; such that associative rules (such as
|
660
|
+
// 'n*n -> n^2') can be applied to exprs. such as 'a * b * b' and 'a * b * b * a'.
|
661
|
+
if (nonCommutative) {
|
662
|
+
// 'Non-commutative' 1: LHS (placeholder) only
|
663
|
+
newRule.expandedNC1 = {};
|
664
|
+
newRule.expandedNC1.l = makeNode([leftExpandsym, newRule.l]);
|
665
|
+
newRule.expandedNC1.r = makeNode([leftExpandsym, newRule.r]);
|
666
|
+
// 'Non-commutative' 2: farmost LHS and RHS placeholders
|
667
|
+
newRule.expandedNC2 = {};
|
668
|
+
newRule.expandedNC2.l = makeNode([leftExpandsym, newRule.expanded.l]);
|
669
|
+
newRule.expandedNC2.r = makeNode([leftExpandsym, newRule.expanded.r]);
|
670
|
+
}
|
628
671
|
}
|
629
672
|
return newRule;
|
630
673
|
}
|
@@ -830,6 +873,16 @@ var createSimplify = /* #__PURE__ */(0, _factory.factory)(name, dependencies, fu
|
|
830
873
|
repl = rule.expanded.r;
|
831
874
|
matches = _ruleMatch(rule.expanded.l, res, mergedContext)[0];
|
832
875
|
}
|
876
|
+
// Additional, non-commutative context expansion-rules
|
877
|
+
if (!matches && rule.expandedNC1) {
|
878
|
+
repl = rule.expandedNC1.r;
|
879
|
+
matches = _ruleMatch(rule.expandedNC1.l, res, mergedContext)[0];
|
880
|
+
if (!matches) {
|
881
|
+
// Existence of NC1 implies NC2
|
882
|
+
repl = rule.expandedNC2.r;
|
883
|
+
matches = _ruleMatch(rule.expandedNC2.l, res, mergedContext)[0];
|
884
|
+
}
|
885
|
+
}
|
833
886
|
if (matches) {
|
834
887
|
// const before = res.toString({parenthesis: 'all'})
|
835
888
|
|
@@ -1047,8 +1100,8 @@ var createSimplify = /* #__PURE__ */(0, _factory.factory)(name, dependencies, fu
|
|
1047
1100
|
res = mergeChildMatches(childMatches);
|
1048
1101
|
} else if (node.args.length >= 2 && rule.args.length === 2) {
|
1049
1102
|
// node is flattened, rule is not
|
1050
|
-
// Associative operators/functions can be split in different ways so we check if the rule
|
1051
|
-
// them and return their union.
|
1103
|
+
// Associative operators/functions can be split in different ways so we check if the rule
|
1104
|
+
// matches for each of them and return their union.
|
1052
1105
|
var splits = getSplits(node, context);
|
1053
1106
|
var splitMatches = [];
|
1054
1107
|
for (var _i3 = 0; _i3 < splits.length; _i3++) {
|
@@ -53,7 +53,7 @@ var createReshape = /* #__PURE__ */(0, _factory.factory)(name, dependencies, fun
|
|
53
53
|
*/
|
54
54
|
return typed(name, {
|
55
55
|
'Matrix, Array': function MatrixArray(x, sizes) {
|
56
|
-
return x.reshape(sizes);
|
56
|
+
return x.reshape(sizes, true);
|
57
57
|
},
|
58
58
|
'Array, Array': function ArrayArray(x, sizes) {
|
59
59
|
sizes.forEach(function (size) {
|
@@ -16,7 +16,7 @@ var createMax = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functio
|
|
16
16
|
larger = _ref.larger;
|
17
17
|
/**
|
18
18
|
* Compute the maximum value of a matrix or a list with values.
|
19
|
-
* In case of a
|
19
|
+
* In case of a multidimensional array, the maximum of the flattened array
|
20
20
|
* will be calculated. When `dim` is provided, the maximum over the selected
|
21
21
|
* dimension will be calculated. Parameter `dim` is zero-based.
|
22
22
|
*
|
@@ -24,7 +24,7 @@ var createMax = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functio
|
|
24
24
|
*
|
25
25
|
* math.max(a, b, c, ...)
|
26
26
|
* math.max(A)
|
27
|
-
* math.max(A,
|
27
|
+
* math.max(A, dimension)
|
28
28
|
*
|
29
29
|
* Examples:
|
30
30
|
*
|
@@ -16,7 +16,7 @@ var createMean = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functi
|
|
16
16
|
divide = _ref.divide;
|
17
17
|
/**
|
18
18
|
* Compute the mean value of matrix or a list with values.
|
19
|
-
* In case of a
|
19
|
+
* In case of a multidimensional array, the mean of the flattened array
|
20
20
|
* will be calculated. When `dim` is provided, the maximum over the selected
|
21
21
|
* dimension will be calculated. Parameter `dim` is zero-based.
|
22
22
|
*
|
@@ -24,7 +24,7 @@ var createMean = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functi
|
|
24
24
|
*
|
25
25
|
* math.mean(a, b, c, ...)
|
26
26
|
* math.mean(A)
|
27
|
-
* math.mean(A,
|
27
|
+
* math.mean(A, dimension)
|
28
28
|
*
|
29
29
|
* Examples:
|
30
30
|
*
|
@@ -16,7 +16,7 @@ var createMin = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functio
|
|
16
16
|
smaller = _ref.smaller;
|
17
17
|
/**
|
18
18
|
* Compute the minimum value of a matrix or a list of values.
|
19
|
-
* In case of a
|
19
|
+
* In case of a multidimensional array, the minimum of the flattened array
|
20
20
|
* will be calculated. When `dim` is provided, the minimum over the selected
|
21
21
|
* dimension will be calculated. Parameter `dim` is zero-based.
|
22
22
|
*
|
@@ -24,7 +24,7 @@ var createMin = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functio
|
|
24
24
|
*
|
25
25
|
* math.min(a, b, c, ...)
|
26
26
|
* math.min(A)
|
27
|
-
* math.min(A,
|
27
|
+
* math.min(A, dimension)
|
28
28
|
*
|
29
29
|
* Examples:
|
30
30
|
*
|
@@ -14,7 +14,7 @@ var createMode = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functi
|
|
14
14
|
isNumeric = _ref.isNumeric;
|
15
15
|
/**
|
16
16
|
* Computes the mode of a set of numbers or a list with values(numbers or characters).
|
17
|
-
* If there are
|
17
|
+
* If there are multiple modes, it returns a list of those values.
|
18
18
|
*
|
19
19
|
* Syntax:
|
20
20
|
*
|
@@ -16,7 +16,7 @@ var createProd = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functi
|
|
16
16
|
numeric = _ref.numeric;
|
17
17
|
/**
|
18
18
|
* Compute the product of a matrix or a list with values.
|
19
|
-
* In case of a
|
19
|
+
* In case of a multidimensional array or matrix, the sum of all
|
20
20
|
* elements will be calculated.
|
21
21
|
*
|
22
22
|
* Syntax:
|
@@ -22,7 +22,7 @@ var createQuantileSeq = /* #__PURE__ */(0, _factory.factory)(name, dependencies,
|
|
22
22
|
* Supported types of sequence values are: Number, BigNumber, Unit
|
23
23
|
* Supported types of probability are: Number, BigNumber
|
24
24
|
*
|
25
|
-
* In case of a
|
25
|
+
* In case of a multidimensional array or matrix, the prob order quantile
|
26
26
|
* of all elements will be calculated.
|
27
27
|
*
|
28
28
|
* Syntax:
|
@@ -16,13 +16,14 @@ var createSum = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functio
|
|
16
16
|
numeric = _ref.numeric;
|
17
17
|
/**
|
18
18
|
* Compute the sum of a matrix or a list with values.
|
19
|
-
* In case of a
|
19
|
+
* In case of a multidimensional array or matrix, the sum of all
|
20
20
|
* elements will be calculated.
|
21
21
|
*
|
22
22
|
* Syntax:
|
23
23
|
*
|
24
24
|
* math.sum(a, b, c, ...)
|
25
25
|
* math.sum(A)
|
26
|
+
* math.sum(A, dimension)
|
26
27
|
*
|
27
28
|
* Examples:
|
28
29
|
*
|
@@ -34,7 +35,7 @@ var createSum = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functio
|
|
34
35
|
*
|
35
36
|
* mean, median, min, max, prod, std, variance, cumsum
|
36
37
|
*
|
37
|
-
* @param {... *} args A single matrix or
|
38
|
+
* @param {... *} args A single matrix or multiple scalar values
|
38
39
|
* @return {*} The sum of all values
|
39
40
|
*/
|
40
41
|
return typed(name, {
|
@@ -21,7 +21,7 @@ var createVariance = /* #__PURE__ */(0, _factory.factory)(name, dependencies, fu
|
|
21
21
|
isNaN = _ref.isNaN;
|
22
22
|
/**
|
23
23
|
* Compute the variance of a matrix or a list with values.
|
24
|
-
* In case of a
|
24
|
+
* In case of a multidimensional array or matrix, the variance over all
|
25
25
|
* elements will be calculated.
|
26
26
|
*
|
27
27
|
* Additionally, it is possible to compute the variance along the rows
|
@@ -28,53 +28,53 @@ var createFormat = /* #__PURE__ */(0, _factory.factory)(name, dependencies, func
|
|
28
28
|
* An object with formatting options. Available options:
|
29
29
|
* - `notation: string`
|
30
30
|
* Number notation. Choose from:
|
31
|
-
* - 'fixed'
|
31
|
+
* - `'fixed'`
|
32
32
|
* Always use regular number notation.
|
33
|
-
* For example '123.40' and '14000000'
|
34
|
-
* - 'exponential'
|
33
|
+
* For example `'123.40'` and `'14000000'`
|
34
|
+
* - `'exponential'`
|
35
35
|
* Always use exponential notation.
|
36
|
-
* For example '1.234e+2' and '1.4e+7'
|
37
|
-
* - 'engineering'
|
36
|
+
* For example `'1.234e+2'` and `'1.4e+7'`
|
37
|
+
* - `'engineering'`
|
38
38
|
* Always use engineering notation: always have exponential notation,
|
39
|
-
* and select the exponent to be a multiple of 3
|
40
|
-
* For example '123.4e+0' and '14.0e+6'
|
41
|
-
* - 'auto' (default)
|
39
|
+
* and select the exponent to be a multiple of `3`.
|
40
|
+
* For example `'123.4e+0'` and `'14.0e+6'`
|
41
|
+
* - `'auto'` (default)
|
42
42
|
* Regular number notation for numbers having an absolute value between
|
43
43
|
* `lower` and `upper` bounds, and uses exponential notation elsewhere.
|
44
44
|
* Lower bound is included, upper bound is excluded.
|
45
|
-
* For example '123.4' and '1.4e7'
|
46
|
-
* - 'bin'
|
45
|
+
* For example `'123.4'` and `'1.4e7'`.
|
46
|
+
* - `'bin'`, `'oct'`, or `'hex'`
|
47
47
|
* Format the number using binary, octal, or hexadecimal notation.
|
48
|
-
* For example '0b1101' and '0x10fe'
|
48
|
+
* For example `'0b1101'` and `'0x10fe'`.
|
49
49
|
* - `wordSize: number`
|
50
50
|
* The word size in bits to use for formatting in binary, octal, or
|
51
|
-
* hexadecimal notation. To be used only with 'bin'
|
52
|
-
* values for
|
51
|
+
* hexadecimal notation. To be used only with `'bin'`, `'oct'`, or `'hex'`
|
52
|
+
* values for `notation` option. When this option is defined the value
|
53
53
|
* is formatted as a signed twos complement integer of the given word
|
54
54
|
* size and the size suffix is appended to the output.
|
55
|
-
* For example format(-1, {notation: 'hex', wordSize: 8}) === '0xffi8'
|
55
|
+
* For example `format(-1, {notation: 'hex', wordSize: 8}) === '0xffi8'`.
|
56
56
|
* Default value is undefined.
|
57
57
|
* - `precision: number`
|
58
58
|
* Limit the number of digits of the formatted value.
|
59
|
-
* For regular numbers, must be a number between 0 and 16
|
59
|
+
* For regular numbers, must be a number between `0` and `16`.
|
60
60
|
* For bignumbers, the maximum depends on the configured precision,
|
61
61
|
* see function `config()`.
|
62
|
-
* In case of notations 'exponential'
|
63
|
-
* defines the total number of significant digits returned.
|
64
|
-
* In case of notation 'fixed'
|
62
|
+
* In case of notations `'exponential'`, `'engineering'`, and `'auto'`,
|
63
|
+
* `precision` defines the total number of significant digits returned.
|
64
|
+
* In case of notation `'fixed'`, `precision` defines the number of
|
65
65
|
* significant digits after the decimal point.
|
66
66
|
* `precision` is undefined by default.
|
67
67
|
* - `lowerExp: number`
|
68
68
|
* Exponent determining the lower boundary for formatting a value with
|
69
|
-
* an exponent when `notation='auto`. Default value is `-3`.
|
69
|
+
* an exponent when `notation='auto'`. Default value is `-3`.
|
70
70
|
* - `upperExp: number`
|
71
71
|
* Exponent determining the upper boundary for formatting a value with
|
72
|
-
* an exponent when `notation='auto`. Default value is `5`.
|
73
|
-
* - `fraction: string`. Available values: 'ratio' (default) or 'decimal'
|
74
|
-
* For example `format(fraction(1, 3))` will output '1/3' when 'ratio'
|
75
|
-
* configured, and will output `0.(3)` when 'decimal' is configured.
|
72
|
+
* an exponent when `notation='auto'`. Default value is `5`.
|
73
|
+
* - `fraction: string`. Available values: `'ratio'` (default) or `'decimal'`.
|
74
|
+
* For example `format(fraction(1, 3))` will output `'1/3'` when `'ratio'`
|
75
|
+
* is configured, and will output `'0.(3)'` when `'decimal'` is configured.
|
76
76
|
* - `truncate: number`. Specifies the maximum allowed length of the
|
77
|
-
* returned string. If it
|
77
|
+
* returned string. If it had been longer, the excess characters
|
78
78
|
* are deleted and replaced with `'...'`.
|
79
79
|
* - `callback: function`
|
80
80
|
* A custom formatting function, invoked for all numeric elements in `value`,
|
package/lib/cjs/header.js
CHANGED
@@ -6,11 +6,11 @@
|
|
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 11.
|
10
|
-
* @date
|
9
|
+
* @version 11.5.1
|
10
|
+
* @date 2023-01-31
|
11
11
|
*
|
12
12
|
* @license
|
13
|
-
* Copyright (C) 2013-
|
13
|
+
* Copyright (C) 2013-2023 Jos de Jong <wjosdejong@gmail.com>
|
14
14
|
*
|
15
15
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
16
16
|
* use this file except in compliance with the License. You may obtain a copy
|
package/lib/cjs/version.js
CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.version = void 0;
|
7
|
-
var version = '11.
|
7
|
+
var version = '11.5.1';
|
8
8
|
// Note: This file is automatically generated when building math.js.
|
9
9
|
// Changes made in this file will be overwritten.
|
10
10
|
exports.version = version;
|
@@ -3,6 +3,6 @@ export var invmodDocs = {
|
|
3
3
|
category: 'Arithmetic',
|
4
4
|
syntax: ['invmod(a, b)'],
|
5
5
|
description: 'Calculate the (modular) multiplicative inverse of a modulo b. Solution to the equation ax ≣ 1 (mod b)',
|
6
|
-
examples: ['invmod(8, 12)=NaN', 'invmod(7, 13)=2', '
|
6
|
+
examples: ['invmod(8, 12)=NaN', 'invmod(7, 13)=2', 'invmod(15151, 15122)=10429'],
|
7
7
|
seealso: ['gcd', 'xgcd']
|
8
8
|
};
|
@@ -3,6 +3,6 @@ export var powDocs = {
|
|
3
3
|
category: 'Operators',
|
4
4
|
syntax: ['x ^ y', 'pow(x, y)'],
|
5
5
|
description: 'Calculates the power of x to y, x^y.',
|
6
|
-
examples: ['2^3', '2*2*2', '1 + e ^ (pi * i)', '
|
6
|
+
examples: ['2^3', '2*2*2', '1 + e ^ (pi * i)', 'pow([[1, 2], [4, 3]], 2)', 'pow([[1, 2], [4, 3]], -1)'],
|
7
7
|
seealso: ['multiply', 'nthRoot', 'nthRoots', 'sqrt']
|
8
8
|
};
|
@@ -1,7 +1,7 @@
|
|
1
1
|
export var matrixFromColumnsDocs = {
|
2
2
|
name: 'matrixFromColumns',
|
3
3
|
category: 'Matrix',
|
4
|
-
syntax: ['
|
4
|
+
syntax: ['matrixFromColumns(...arr)', 'matrixFromColumns(row1, row2)', 'matrixFromColumns(row1, row2, row3)'],
|
5
5
|
description: 'Create a dense matrix from vectors as individual columns.',
|
6
6
|
examples: ['matrixFromColumns([1, 2, 3], [[4],[5],[6]])'],
|
7
7
|
seealso: ['matrix', 'matrixFromRows', 'matrixFromFunction', 'zeros']
|
@@ -1,7 +1,7 @@
|
|
1
1
|
export var matrixFromFunctionDocs = {
|
2
2
|
name: 'matrixFromFunction',
|
3
3
|
category: 'Matrix',
|
4
|
-
syntax: ['
|
4
|
+
syntax: ['matrixFromFunction(size, fn)', 'matrixFromFunction(size, fn, format)', 'matrixFromFunction(size, fn, format, datatype)', 'matrixFromFunction(size, format, fn)', 'matrixFromFunction(size, format, datatype, fn)'],
|
5
5
|
description: 'Create a matrix by evaluating a generating function at each index.',
|
6
6
|
examples: ['f(I) = I[1] - I[2]', 'matrixFromFunction([3,3], f)', 'g(I) = I[1] - I[2] == 1 ? 4 : 0', 'matrixFromFunction([100, 100], "sparse", g)', 'matrixFromFunction([5], random)'],
|
7
7
|
seealso: ['matrix', 'matrixFromRows', 'matrixFromColumns', 'zeros']
|
@@ -1,7 +1,7 @@
|
|
1
1
|
export var matrixFromRowsDocs = {
|
2
2
|
name: 'matrixFromRows',
|
3
3
|
category: 'Matrix',
|
4
|
-
syntax: ['
|
4
|
+
syntax: ['matrixFromRows(...arr)', 'matrixFromRows(row1, row2)', 'matrixFromRows(row1, row2, row3)'],
|
5
5
|
description: 'Create a dense matrix from vectors as individual rows.',
|
6
6
|
examples: ['matrixFromRows([1, 2, 3], [[4],[5],[6]])'],
|
7
7
|
seealso: ['matrix', 'matrixFromColumns', 'matrixFromFunction', 'zeros']
|
@@ -3,6 +3,6 @@ export var reshapeDocs = {
|
|
3
3
|
category: 'Matrix',
|
4
4
|
syntax: ['reshape(x, sizes)'],
|
5
5
|
description: 'Reshape a multi dimensional array to fit the specified dimensions.',
|
6
|
-
examples: ['reshape([1, 2, 3, 4, 5, 6], [2, 3])', 'reshape([[1, 2], [3, 4]], [1, 4])', 'reshape([[1, 2], [3, 4]], [4])'],
|
6
|
+
examples: ['reshape([1, 2, 3, 4, 5, 6], [2, 3])', 'reshape([[1, 2], [3, 4]], [1, 4])', 'reshape([[1, 2], [3, 4]], [4])', 'reshape([1, 2, 3, 4], [-1, 2])'],
|
7
7
|
seealso: ['size', 'squeeze', 'resize']
|
8
8
|
};
|
@@ -3,6 +3,6 @@ export var rotateDocs = {
|
|
3
3
|
category: 'Matrix',
|
4
4
|
syntax: ['rotate(w, theta)', 'rotate(w, theta, v)'],
|
5
5
|
description: 'Returns a 2-D rotation matrix (2x2) for a given angle (in radians). ' + 'Returns a 2-D rotation matrix (3x3) of a given angle (in radians) around given axis.',
|
6
|
-
examples: ['rotate([1, 0],
|
6
|
+
examples: ['rotate([1, 0], pi / 2)', 'rotate(matrix([1, 0]), unit("35deg"))', 'rotate([1, 0, 0], unit("90deg"), [0, 0, 1])', 'rotate(matrix([1, 0, 0]), unit("90deg"), matrix([0, 0, 1]))'],
|
7
7
|
seealso: ['matrix', 'rotationMatrix']
|
8
8
|
};
|
@@ -3,6 +3,6 @@ export var lgammaDocs = {
|
|
3
3
|
category: 'Probability',
|
4
4
|
syntax: ['lgamma(n)'],
|
5
5
|
description: 'Logarithm of the gamma function for real, positive numbers and complex numbers, ' + 'using Lanczos approximation for numbers and Stirling series for complex numbers.',
|
6
|
-
examples: ['lgamma(4)', 'lgamma(1/2)', 'lgamma(
|
6
|
+
examples: ['lgamma(4)', 'lgamma(1/2)', 'lgamma(i)', 'lgamma(complex(1.1, 2))'],
|
7
7
|
seealso: ['gamma']
|
8
8
|
};
|
@@ -1,7 +1,7 @@
|
|
1
1
|
export var maxDocs = {
|
2
2
|
name: 'max',
|
3
3
|
category: 'Statistics',
|
4
|
-
syntax: ['max(a, b, c, ...)', 'max(A)', 'max(A,
|
4
|
+
syntax: ['max(a, b, c, ...)', 'max(A)', 'max(A, dimension)'],
|
5
5
|
description: 'Compute the maximum value of a list of values.',
|
6
6
|
examples: ['max(2, 3, 4, 1)', 'max([2, 3, 4, 1])', 'max([2, 5; 4, 3])', 'max([2, 5; 4, 3], 1)', 'max([2, 5; 4, 3], 2)', 'max(2.7, 7.1, -4.5, 2.0, 4.1)', 'min(2.7, 7.1, -4.5, 2.0, 4.1)'],
|
7
7
|
seealso: ['mean', 'median', 'min', 'prod', 'std', 'sum', 'variance']
|
@@ -1,7 +1,7 @@
|
|
1
1
|
export var meanDocs = {
|
2
2
|
name: 'mean',
|
3
3
|
category: 'Statistics',
|
4
|
-
syntax: ['mean(a, b, c, ...)', 'mean(A)', 'mean(A,
|
4
|
+
syntax: ['mean(a, b, c, ...)', 'mean(A)', 'mean(A, dimension)'],
|
5
5
|
description: 'Compute the arithmetic mean of a list of values.',
|
6
6
|
examples: ['mean(2, 3, 4, 1)', 'mean([2, 3, 4, 1])', 'mean([2, 5; 4, 3])', 'mean([2, 5; 4, 3], 1)', 'mean([2, 5; 4, 3], 2)', 'mean([1.0, 2.7, 3.2, 4.0])'],
|
7
7
|
seealso: ['max', 'median', 'min', 'prod', 'std', 'sum', 'variance']
|
@@ -1,7 +1,7 @@
|
|
1
1
|
export var minDocs = {
|
2
2
|
name: 'min',
|
3
3
|
category: 'Statistics',
|
4
|
-
syntax: ['min(a, b, c, ...)', 'min(A)', 'min(A,
|
4
|
+
syntax: ['min(a, b, c, ...)', 'min(A)', 'min(A, dimension)'],
|
5
5
|
description: 'Compute the minimum value of a list of values.',
|
6
6
|
examples: ['min(2, 3, 4, 1)', 'min([2, 3, 4, 1])', 'min([2, 5; 4, 3])', 'min([2, 5; 4, 3], 1)', 'min([2, 5; 4, 3], 2)', 'min(2.7, 7.1, -4.5, 2.0, 4.1)', 'max(2.7, 7.1, -4.5, 2.0, 4.1)'],
|
7
7
|
seealso: ['max', 'mean', 'median', 'prod', 'std', 'sum', 'variance']
|
@@ -1,7 +1,7 @@
|
|
1
1
|
export var stdDocs = {
|
2
2
|
name: 'std',
|
3
3
|
category: 'Statistics',
|
4
|
-
syntax: ['std(a, b, c, ...)', 'std(A)', 'std(A, normalization)'],
|
4
|
+
syntax: ['std(a, b, c, ...)', 'std(A)', 'std(A, dimension)', 'std(A, normalization)', 'std(A, dimension, normalization)'],
|
5
5
|
description: 'Compute the standard deviation of all values, defined as std(A) = sqrt(variance(A)). Optional parameter normalization can be "unbiased" (default), "uncorrected", or "biased".',
|
6
6
|
examples: ['std(2, 4, 6)', 'std([2, 4, 6, 8])', 'std([2, 4, 6, 8], "uncorrected")', 'std([2, 4, 6, 8], "biased")', 'std([1, 2, 3; 4, 5, 6])'],
|
7
7
|
seealso: ['max', 'mean', 'min', 'median', 'prod', 'sum', 'variance']
|