mathjs 10.1.1 → 10.2.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.
- package/HISTORY.md +17 -0
- package/docs/expressions/algebra.md +27 -0
- package/docs/reference/functions/abs.md +6 -0
- package/docs/reference/functions/acos.md +6 -0
- package/docs/reference/functions/acosh.md +6 -0
- package/docs/reference/functions/acot.md +6 -0
- package/docs/reference/functions/acoth.md +6 -0
- package/docs/reference/functions/acsc.md +6 -0
- package/docs/reference/functions/acsch.md +6 -0
- package/docs/reference/functions/add.md +6 -0
- package/docs/reference/functions/and.md +6 -0
- package/docs/reference/functions/apply.md +6 -0
- package/docs/reference/functions/arg.md +6 -0
- package/docs/reference/functions/asec.md +6 -0
- package/docs/reference/functions/asech.md +6 -0
- package/docs/reference/functions/asin.md +6 -0
- package/docs/reference/functions/asinh.md +6 -0
- package/docs/reference/functions/atan.md +6 -0
- package/docs/reference/functions/atan2.md +6 -0
- package/docs/reference/functions/atanh.md +6 -0
- package/docs/reference/functions/bellNumbers.md +6 -0
- package/docs/reference/functions/bin.md +6 -0
- package/docs/reference/functions/bitAnd.md +6 -0
- package/docs/reference/functions/bitNot.md +6 -0
- package/docs/reference/functions/bitOr.md +6 -0
- package/docs/reference/functions/bitXor.md +6 -0
- package/docs/reference/functions/catalan.md +6 -0
- package/docs/reference/functions/cbrt.md +6 -0
- package/docs/reference/functions/ceil.md +6 -0
- package/docs/reference/functions/clone.md +6 -0
- package/docs/reference/functions/column.md +6 -0
- package/docs/reference/functions/combinations.md +6 -0
- package/docs/reference/functions/combinationsWithRep.md +6 -0
- package/docs/reference/functions/compare.md +6 -0
- package/docs/reference/functions/compareNatural.md +6 -0
- package/docs/reference/functions/compareText.md +6 -0
- package/docs/reference/functions/compile.md +6 -0
- package/docs/reference/functions/composition.md +6 -0
- package/docs/reference/functions/concat.md +6 -0
- package/docs/reference/functions/conj.md +6 -0
- package/docs/reference/functions/cos.md +6 -0
- package/docs/reference/functions/cosh.md +6 -0
- package/docs/reference/functions/cot.md +6 -0
- package/docs/reference/functions/coth.md +6 -0
- package/docs/reference/functions/count.md +6 -0
- package/docs/reference/functions/cross.md +6 -0
- package/docs/reference/functions/csc.md +6 -0
- package/docs/reference/functions/csch.md +6 -0
- package/docs/reference/functions/ctranspose.md +6 -0
- package/docs/reference/functions/cube.md +6 -0
- package/docs/reference/functions/deepEqual.md +6 -0
- package/docs/reference/functions/derivative.md +6 -0
- package/docs/reference/functions/det.md +6 -0
- package/docs/reference/functions/diag.md +6 -0
- package/docs/reference/functions/diff.md +6 -0
- package/docs/reference/functions/distance.md +6 -0
- package/docs/reference/functions/divide.md +6 -0
- package/docs/reference/functions/dot.md +6 -0
- package/docs/reference/functions/dotDivide.md +6 -0
- package/docs/reference/functions/dotMultiply.md +6 -0
- package/docs/reference/functions/dotPow.md +6 -0
- package/docs/reference/functions/eigs.md +6 -0
- package/docs/reference/functions/equal.md +6 -0
- package/docs/reference/functions/equalText.md +6 -0
- package/docs/reference/functions/erf.md +6 -0
- package/docs/reference/functions/evaluate.md +6 -0
- package/docs/reference/functions/exp.md +6 -0
- package/docs/reference/functions/expm.md +6 -0
- package/docs/reference/functions/expm1.md +6 -0
- package/docs/reference/functions/factorial.md +6 -0
- package/docs/reference/functions/filter.md +6 -0
- package/docs/reference/functions/fix.md +6 -0
- package/docs/reference/functions/flatten.md +6 -0
- package/docs/reference/functions/floor.md +6 -0
- package/docs/reference/functions/forEach.md +6 -0
- package/docs/reference/functions/format.md +6 -0
- package/docs/reference/functions/gamma.md +6 -0
- package/docs/reference/functions/gcd.md +6 -0
- package/docs/reference/functions/getMatrixDataType.md +6 -0
- package/docs/reference/functions/hasNumericValue.md +6 -0
- package/docs/reference/functions/help.md +6 -0
- package/docs/reference/functions/hex.md +6 -0
- package/docs/reference/functions/hypot.md +6 -0
- package/docs/reference/functions/identity.md +6 -0
- package/docs/reference/functions/im.md +6 -0
- package/docs/reference/functions/intersect.md +6 -0
- package/docs/reference/functions/inv.md +6 -0
- package/docs/reference/functions/invmod.md +6 -0
- package/docs/reference/functions/isInteger.md +6 -0
- package/docs/reference/functions/isNaN.md +6 -0
- package/docs/reference/functions/isNegative.md +6 -0
- package/docs/reference/functions/isNumeric.md +6 -0
- package/docs/reference/functions/isPositive.md +6 -0
- package/docs/reference/functions/isPrime.md +6 -0
- package/docs/reference/functions/isZero.md +6 -0
- package/docs/reference/functions/kldivergence.md +6 -0
- package/docs/reference/functions/kron.md +6 -0
- package/docs/reference/functions/larger.md +6 -0
- package/docs/reference/functions/largerEq.md +6 -0
- package/docs/reference/functions/lcm.md +6 -0
- package/docs/reference/functions/leafCount.md +52 -0
- package/docs/reference/functions/leftShift.md +6 -0
- package/docs/reference/functions/log.md +6 -0
- package/docs/reference/functions/log10.md +6 -0
- package/docs/reference/functions/log1p.md +6 -0
- package/docs/reference/functions/log2.md +6 -0
- package/docs/reference/functions/lsolve.md +6 -0
- package/docs/reference/functions/lsolveAll.md +6 -0
- package/docs/reference/functions/lup.md +6 -0
- package/docs/reference/functions/lusolve.md +6 -0
- package/docs/reference/functions/mad.md +6 -0
- package/docs/reference/functions/map.md +6 -0
- package/docs/reference/functions/matrixFromColumns.md +6 -0
- package/docs/reference/functions/matrixFromFunction.md +6 -0
- package/docs/reference/functions/matrixFromRows.md +6 -0
- package/docs/reference/functions/max.md +6 -0
- package/docs/reference/functions/mean.md +6 -0
- package/docs/reference/functions/median.md +6 -0
- package/docs/reference/functions/min.md +6 -0
- package/docs/reference/functions/mod.md +6 -0
- package/docs/reference/functions/mode.md +6 -0
- package/docs/reference/functions/multinomial.md +6 -0
- package/docs/reference/functions/multiply.md +6 -0
- package/docs/reference/functions/norm.md +6 -0
- package/docs/reference/functions/not.md +6 -0
- package/docs/reference/functions/nthRoot.md +6 -0
- package/docs/reference/functions/nthRoots.md +6 -0
- package/docs/reference/functions/numeric.md +6 -0
- package/docs/reference/functions/oct.md +6 -0
- package/docs/reference/functions/ones.md +6 -0
- package/docs/reference/functions/or.md +6 -0
- package/docs/reference/functions/parser.md +6 -0
- package/docs/reference/functions/partitionSelect.md +6 -0
- package/docs/reference/functions/permutations.md +6 -0
- package/docs/reference/functions/pickRandom.md +6 -0
- package/docs/reference/functions/pow.md +6 -0
- package/docs/reference/functions/print.md +6 -0
- package/docs/reference/functions/prod.md +6 -0
- package/docs/reference/functions/qr.md +6 -0
- package/docs/reference/functions/quantileSeq.md +6 -0
- package/docs/reference/functions/random.md +6 -0
- package/docs/reference/functions/randomInt.md +6 -0
- package/docs/reference/functions/range.md +6 -0
- package/docs/reference/functions/rationalize.md +7 -1
- package/docs/reference/functions/re.md +6 -0
- package/docs/reference/functions/reshape.md +7 -0
- package/docs/reference/functions/resize.md +6 -0
- package/docs/reference/functions/resolve.md +46 -0
- package/docs/reference/functions/rightArithShift.md +6 -0
- package/docs/reference/functions/rightLogShift.md +6 -0
- package/docs/reference/functions/rotate.md +6 -0
- package/docs/reference/functions/rotationMatrix.md +6 -0
- package/docs/reference/functions/round.md +6 -0
- package/docs/reference/functions/row.md +6 -0
- package/docs/reference/functions/sec.md +6 -0
- package/docs/reference/functions/sech.md +6 -0
- package/docs/reference/functions/setCartesian.md +6 -0
- package/docs/reference/functions/setDifference.md +6 -0
- package/docs/reference/functions/setDistinct.md +6 -0
- package/docs/reference/functions/setIntersect.md +6 -0
- package/docs/reference/functions/setIsSubset.md +6 -0
- package/docs/reference/functions/setMultiplicity.md +6 -0
- package/docs/reference/functions/setPowerset.md +6 -0
- package/docs/reference/functions/setSize.md +6 -0
- package/docs/reference/functions/setSymDifference.md +6 -0
- package/docs/reference/functions/setUnion.md +6 -0
- package/docs/reference/functions/sign.md +6 -0
- package/docs/reference/functions/simplify.md +43 -6
- package/docs/reference/functions/simplifyCore.md +50 -0
- package/docs/reference/functions/sin.md +6 -0
- package/docs/reference/functions/sinh.md +6 -0
- package/docs/reference/functions/size.md +6 -0
- package/docs/reference/functions/slu.md +6 -0
- package/docs/reference/functions/smaller.md +6 -0
- package/docs/reference/functions/smallerEq.md +6 -0
- package/docs/reference/functions/sort.md +6 -0
- package/docs/reference/functions/sqrt.md +6 -0
- package/docs/reference/functions/sqrtm.md +6 -0
- package/docs/reference/functions/square.md +6 -0
- package/docs/reference/functions/squeeze.md +6 -0
- package/docs/reference/functions/std.md +6 -0
- package/docs/reference/functions/stirlingS2.md +6 -0
- package/docs/reference/functions/subset.md +6 -0
- package/docs/reference/functions/subtract.md +6 -0
- package/docs/reference/functions/sum.md +6 -0
- package/docs/reference/functions/tan.md +6 -0
- package/docs/reference/functions/tanh.md +6 -0
- package/docs/reference/functions/to.md +6 -0
- package/docs/reference/functions/trace.md +6 -0
- package/docs/reference/functions/transpose.md +6 -0
- package/docs/reference/functions/typeOf.md +6 -0
- package/docs/reference/functions/unaryMinus.md +6 -0
- package/docs/reference/functions/unaryPlus.md +6 -0
- package/docs/reference/functions/unequal.md +6 -0
- package/docs/reference/functions/usolve.md +6 -0
- package/docs/reference/functions/usolveAll.md +6 -0
- package/docs/reference/functions/variance.md +6 -0
- package/docs/reference/functions/xgcd.md +6 -0
- package/docs/reference/functions/xor.md +6 -0
- package/docs/reference/functions/zeros.md +6 -0
- package/docs/reference/functions.md +3 -0
- package/lib/browser/math.js +6 -6
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/core/create.js +4 -4
- package/lib/cjs/core/function/import.js +3 -3
- package/lib/cjs/core/function/typed.js +2 -2
- package/lib/cjs/defaultInstance.js +3 -3
- package/lib/cjs/entry/allFactoriesAny.js +1 -1
- package/lib/cjs/entry/allFactoriesNumber.js +1 -1
- package/lib/cjs/entry/configReadonly.js +1 -1
- package/lib/cjs/entry/dependenciesAny/dependenciesLeafCount.generated.js +23 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesRationalize.generated.js +3 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesResolve.generated.js +32 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesSimplify.generated.js +6 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesSimplifyCore.generated.js +65 -0
- package/lib/cjs/entry/dependenciesAny.generated.js +24 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesRationalize.generated.js +3 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesResolve.generated.js +32 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesSimplify.generated.js +6 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesSimplifyCore.generated.js +65 -0
- package/lib/cjs/entry/dependenciesNumber.generated.js +16 -0
- package/lib/cjs/entry/impureFunctionsAny.generated.js +67 -29
- package/lib/cjs/entry/impureFunctionsNumber.generated.js +96 -64
- package/lib/cjs/entry/pureFunctionsAny.generated.js +53 -55
- package/lib/cjs/entry/pureFunctionsNumber.generated.js +46 -48
- package/lib/cjs/expression/Help.js +4 -0
- package/lib/cjs/expression/Parser.js +1 -1
- package/lib/cjs/expression/embeddedDocs/core/typed.js +1 -1
- package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +14 -5
- package/lib/cjs/expression/embeddedDocs/function/algebra/leafCount.js +15 -0
- package/lib/cjs/expression/embeddedDocs/function/algebra/resolve.js +16 -0
- package/lib/cjs/expression/embeddedDocs/function/algebra/simplify.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/algebra/simplifyCore.js +15 -0
- package/lib/cjs/expression/node/FunctionNode.js +7 -7
- package/lib/cjs/expression/node/IndexNode.js +1 -1
- package/lib/cjs/expression/node/Node.js +3 -3
- package/lib/cjs/expression/node/ObjectNode.js +1 -1
- package/lib/cjs/expression/node/utils/access.js +1 -1
- package/lib/cjs/expression/node/utils/assign.js +1 -1
- package/lib/cjs/expression/parse.js +13 -13
- package/lib/cjs/factoriesAny.js +24 -0
- package/lib/cjs/factoriesNumber.js +16 -0
- package/lib/cjs/function/algebra/decomposition/qr.js +1 -1
- package/lib/cjs/function/algebra/leafCount.js +66 -0
- package/lib/cjs/function/algebra/rationalize.js +24 -41
- package/lib/cjs/function/algebra/resolve.js +106 -0
- package/lib/cjs/function/algebra/simplify/simplifyConstant.js +5 -5
- package/lib/cjs/function/algebra/simplify/util.js +171 -33
- package/lib/cjs/function/algebra/simplify.js +554 -207
- package/lib/cjs/function/algebra/{simplify/simplifyCore.js → simplifyCore.js} +67 -43
- package/lib/cjs/function/algebra/solver/lsolveAll.js +2 -2
- package/lib/cjs/function/algebra/solver/usolveAll.js +2 -2
- package/lib/cjs/function/arithmetic/ceil.js +3 -3
- package/lib/cjs/function/arithmetic/floor.js +3 -3
- package/lib/cjs/function/arithmetic/invmod.js +1 -1
- package/lib/cjs/function/arithmetic/norm.js +1 -1
- package/lib/cjs/function/arithmetic/round.js +1 -1
- package/lib/cjs/function/matrix/eigs/complexEigs.js +5 -5
- package/lib/cjs/function/matrix/matrixFromColumns.js +1 -1
- package/lib/cjs/function/matrix/matrixFromRows.js +1 -1
- package/lib/cjs/function/probability/util/seededRNG.js +2 -2
- package/lib/cjs/function/relational/compareNatural.js +6 -6
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/plain/bignumber/index.js +1 -1
- package/lib/cjs/plain/number/combinations.js +18 -6
- package/lib/cjs/type/bignumber/BigNumber.js +2 -2
- package/lib/cjs/type/bignumber/function/bignumber.js +1 -1
- package/lib/cjs/type/boolean.js +2 -2
- package/lib/cjs/type/complex/Complex.js +14 -14
- package/lib/cjs/type/complex/function/complex.js +1 -1
- package/lib/cjs/type/fraction/Fraction.js +6 -6
- package/lib/cjs/type/fraction/function/fraction.js +1 -1
- package/lib/cjs/type/matrix/DenseMatrix.js +5 -5
- package/lib/cjs/type/matrix/SparseMatrix.js +2 -2
- package/lib/cjs/type/number.js +1 -1
- package/lib/cjs/type/string.js +2 -2
- package/lib/cjs/type/unit/Unit.js +8 -8
- package/lib/cjs/utils/customs.js +2 -2
- package/lib/cjs/utils/emitter.js +1 -1
- package/lib/cjs/utils/function.js +2 -2
- package/lib/cjs/utils/is.js +6 -6
- package/lib/cjs/utils/latex.js +3 -3
- package/lib/cjs/utils/lruQueue.js +1 -1
- package/lib/cjs/utils/map.js +3 -3
- package/lib/cjs/utils/object.js +2 -2
- package/lib/cjs/utils/snapshot.js +7 -7
- package/lib/cjs/utils/string.js +2 -2
- package/lib/cjs/version.js +1 -1
- package/lib/esm/entry/dependenciesAny/dependenciesLeafCount.generated.js +12 -0
- package/lib/esm/entry/dependenciesAny/dependenciesRationalize.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesResolve.generated.js +18 -0
- package/lib/esm/entry/dependenciesAny/dependenciesSimplify.generated.js +4 -0
- package/lib/esm/entry/dependenciesAny/dependenciesSimplifyCore.generated.js +40 -0
- package/lib/esm/entry/dependenciesAny.generated.js +3 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesRationalize.generated.js +2 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesResolve.generated.js +18 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesSimplify.generated.js +4 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesSimplifyCore.generated.js +40 -0
- package/lib/esm/entry/dependenciesNumber.generated.js +2 -0
- package/lib/esm/entry/impureFunctionsAny.generated.js +57 -22
- package/lib/esm/entry/impureFunctionsNumber.generated.js +83 -53
- package/lib/esm/entry/pureFunctionsAny.generated.js +42 -42
- package/lib/esm/entry/pureFunctionsNumber.generated.js +32 -32
- package/lib/esm/expression/Help.js +4 -0
- package/lib/esm/expression/embeddedDocs/core/typed.js +1 -1
- package/lib/esm/expression/embeddedDocs/embeddedDocs.js +6 -0
- package/lib/esm/expression/embeddedDocs/function/algebra/leafCount.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/algebra/resolve.js +9 -0
- package/lib/esm/expression/embeddedDocs/function/algebra/simplify.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/algebra/simplifyCore.js +8 -0
- package/lib/esm/factoriesAny.js +3 -0
- package/lib/esm/factoriesNumber.js +2 -0
- package/lib/esm/function/algebra/leafCount.js +59 -0
- package/lib/esm/function/algebra/rationalize.js +24 -40
- package/lib/esm/function/algebra/resolve.js +95 -0
- package/lib/esm/function/algebra/simplify/simplifyConstant.js +3 -3
- package/lib/esm/function/algebra/simplify/util.js +170 -34
- package/lib/esm/function/algebra/simplify.js +549 -202
- package/lib/esm/function/algebra/{simplify/simplifyCore.js → simplifyCore.js} +60 -44
- package/lib/esm/plain/number/combinations.js +18 -6
- package/lib/esm/version.js +1 -1
- package/package.json +15 -10
- package/types/index.d.ts +44 -2
- package/lib/cjs/function/algebra/simplify/resolve.js +0 -76
- package/lib/esm/function/algebra/simplify/resolve.js +0 -67
@@ -1,7 +1,8 @@
|
|
1
|
-
import { isAccessorNode, isArrayNode, isConstantNode, isFunctionNode, isIndexNode, isObjectNode, isOperatorNode
|
2
|
-
import {
|
1
|
+
import { isAccessorNode, isArrayNode, isConstantNode, isFunctionNode, isIndexNode, isObjectNode, isOperatorNode } from '../../utils/is.js';
|
2
|
+
import { createUtil } from './simplify/util.js';
|
3
|
+
import { factory } from '../../utils/factory.js';
|
3
4
|
var name = 'simplifyCore';
|
4
|
-
var dependencies = ['equal', 'isZero', 'add', 'subtract', 'multiply', 'divide', 'pow', 'AccessorNode', 'ArrayNode', 'ConstantNode', 'FunctionNode', 'IndexNode', 'ObjectNode', 'OperatorNode', 'ParenthesisNode'];
|
5
|
+
var dependencies = ['equal', 'isZero', 'add', 'subtract', 'multiply', 'divide', 'pow', 'AccessorNode', 'ArrayNode', 'ConstantNode', 'FunctionNode', 'IndexNode', 'ObjectNode', 'OperatorNode', 'ParenthesisNode', 'SymbolNode'];
|
5
6
|
export var createSimplifyCore = /* #__PURE__ */factory(name, dependencies, _ref => {
|
6
7
|
var {
|
7
8
|
equal,
|
@@ -18,16 +19,19 @@ export var createSimplifyCore = /* #__PURE__ */factory(name, dependencies, _ref
|
|
18
19
|
IndexNode,
|
19
20
|
ObjectNode,
|
20
21
|
OperatorNode,
|
21
|
-
ParenthesisNode
|
22
|
+
ParenthesisNode,
|
23
|
+
SymbolNode
|
22
24
|
} = _ref;
|
23
25
|
var node0 = new ConstantNode(0);
|
24
26
|
var node1 = new ConstantNode(1);
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
var {
|
28
|
+
hasProperty,
|
29
|
+
isCommutative
|
30
|
+
} = createUtil({
|
31
|
+
FunctionNode,
|
32
|
+
OperatorNode,
|
33
|
+
SymbolNode
|
34
|
+
});
|
31
35
|
/**
|
32
36
|
* simplifyCore() performs single pass simplification suitable for
|
33
37
|
* applications requiring ultimate performance. In contrast, simplify()
|
@@ -36,31 +40,53 @@ export var createSimplifyCore = /* #__PURE__ */factory(name, dependencies, _ref
|
|
36
40
|
*
|
37
41
|
* Syntax:
|
38
42
|
*
|
39
|
-
*
|
43
|
+
* simplifyCore(expr)
|
40
44
|
*
|
41
45
|
* Examples:
|
42
46
|
*
|
43
47
|
* const f = math.parse('2 * 1 * x ^ (2 - 1)')
|
44
|
-
* math.
|
45
|
-
* math.simplify('2 * 1 * x ^ (2 - 1)', [math.
|
48
|
+
* math.simpifyCore(f) // Node {2 * x}
|
49
|
+
* math.simplify('2 * 1 * x ^ (2 - 1)', [math.simplifyCore]) // Node {2 * x}
|
46
50
|
*
|
47
51
|
* See also:
|
48
52
|
*
|
49
|
-
* derivative
|
53
|
+
* simplify, resolve, derivative
|
50
54
|
*
|
51
55
|
* @param {Node} node
|
52
56
|
* The expression to be simplified
|
57
|
+
* @param {Object} options
|
58
|
+
* Simplification options, as per simplify()
|
59
|
+
* @return {Node} Returns expression with basic simplifications applied
|
53
60
|
*/
|
54
61
|
|
62
|
+
function simplifyCore(node, options) {
|
63
|
+
var context = options ? options.context : undefined;
|
55
64
|
|
56
|
-
|
57
|
-
|
58
|
-
|
65
|
+
if (hasProperty(node, 'trivial', context)) {
|
66
|
+
// This node does nothing if it has only one argument, so if so,
|
67
|
+
// return that argument simplified
|
68
|
+
if (isFunctionNode(node) && node.args.length === 1) {
|
69
|
+
return simplifyCore(node.args[0], options);
|
70
|
+
} // For other node types, we try the generic methods
|
59
71
|
|
60
|
-
|
61
|
-
|
62
|
-
|
72
|
+
|
73
|
+
var simpChild = false;
|
74
|
+
var childCount = 0;
|
75
|
+
node.forEach(c => {
|
76
|
+
++childCount;
|
77
|
+
|
78
|
+
if (childCount === 1) {
|
79
|
+
simpChild = simplifyCore(c, options);
|
80
|
+
}
|
81
|
+
});
|
82
|
+
|
83
|
+
if (childCount === 1) {
|
84
|
+
return simpChild;
|
63
85
|
}
|
86
|
+
}
|
87
|
+
|
88
|
+
if (isOperatorNode(node) && node.isUnary()) {
|
89
|
+
var a0 = simplifyCore(node.args[0], options);
|
64
90
|
|
65
91
|
if (node.op === '-') {
|
66
92
|
// unary minus
|
@@ -75,9 +101,9 @@ export var createSimplifyCore = /* #__PURE__ */factory(name, dependencies, _ref
|
|
75
101
|
return new OperatorNode(node.op, node.fn, [a0]);
|
76
102
|
}
|
77
103
|
} else if (isOperatorNode(node) && node.isBinary()) {
|
78
|
-
var _a = simplifyCore(node.args[0]);
|
104
|
+
var _a = simplifyCore(node.args[0], options);
|
79
105
|
|
80
|
-
var a1 = simplifyCore(node.args[1]);
|
106
|
+
var a1 = simplifyCore(node.args[1], options);
|
81
107
|
|
82
108
|
if (node.op === '+') {
|
83
109
|
if (isConstantNode(_a)) {
|
@@ -113,7 +139,7 @@ export var createSimplifyCore = /* #__PURE__ */factory(name, dependencies, _ref
|
|
113
139
|
}
|
114
140
|
|
115
141
|
if (isOperatorNode(a1) && a1.isUnary() && a1.op === '-') {
|
116
|
-
return simplifyCore(new OperatorNode('+', 'add', [_a, a1.args[0]]));
|
142
|
+
return simplifyCore(new OperatorNode('+', 'add', [_a, a1.args[0]]), options);
|
117
143
|
}
|
118
144
|
|
119
145
|
return new OperatorNode(node.op, node.fn, [_a, a1]);
|
@@ -134,7 +160,7 @@ export var createSimplifyCore = /* #__PURE__ */factory(name, dependencies, _ref
|
|
134
160
|
return node0;
|
135
161
|
} else if (equal(a1.value, 1)) {
|
136
162
|
return _a;
|
137
|
-
} else if (isOperatorNode(_a) && _a.isBinary() && _a.op === node.op) {
|
163
|
+
} else if (isOperatorNode(_a) && _a.isBinary() && _a.op === node.op && isCommutative(node, context)) {
|
138
164
|
var a00 = _a.args[0];
|
139
165
|
|
140
166
|
if (isConstantNode(a00)) {
|
@@ -143,7 +169,11 @@ export var createSimplifyCore = /* #__PURE__ */factory(name, dependencies, _ref
|
|
143
169
|
}
|
144
170
|
}
|
145
171
|
|
146
|
-
|
172
|
+
if (isCommutative(node, context)) {
|
173
|
+
return new OperatorNode(node.op, node.fn, [a1, _a], node.implicit); // constants on left
|
174
|
+
} else {
|
175
|
+
return new OperatorNode(node.op, node.fn, [_a, a1], node.implicit);
|
176
|
+
}
|
147
177
|
}
|
148
178
|
|
149
179
|
return new OperatorNode(node.op, node.fn, [_a, a1], node.implicit);
|
@@ -179,33 +209,19 @@ export var createSimplifyCore = /* #__PURE__ */factory(name, dependencies, _ref
|
|
179
209
|
|
180
210
|
return new OperatorNode(node.op, node.fn, [_a, a1]);
|
181
211
|
}
|
182
|
-
} else if (isParenthesisNode(node)) {
|
183
|
-
var c = simplifyCore(node.content);
|
184
|
-
|
185
|
-
if (isParenthesisNode(c) || isSymbolNode(c) || isConstantNode(c)) {
|
186
|
-
return c;
|
187
|
-
}
|
188
|
-
|
189
|
-
return new ParenthesisNode(c);
|
190
212
|
} else if (isFunctionNode(node)) {
|
191
|
-
return new FunctionNode(simplifyCore(node.fn),
|
213
|
+
return new FunctionNode(simplifyCore(node.fn), node.args.map(n => simplifyCore(n, options)));
|
192
214
|
} else if (isArrayNode(node)) {
|
193
|
-
return new ArrayNode(
|
215
|
+
return new ArrayNode(node.items.map(n => simplifyCore(n, options)));
|
194
216
|
} else if (isAccessorNode(node)) {
|
195
|
-
|
196
|
-
|
197
|
-
if (isParenthesisNode(obj)) {
|
198
|
-
obj = obj.content;
|
199
|
-
}
|
200
|
-
|
201
|
-
return new AccessorNode(obj, simplifyCore(node.index));
|
217
|
+
return new AccessorNode(simplifyCore(node.object, options), simplifyCore(node.index, options));
|
202
218
|
} else if (isIndexNode(node)) {
|
203
|
-
return new IndexNode(
|
219
|
+
return new IndexNode(node.dimensions.map(n => simplifyCore(n, options)));
|
204
220
|
} else if (isObjectNode(node)) {
|
205
221
|
var newProps = {};
|
206
222
|
|
207
223
|
for (var prop in node.properties) {
|
208
|
-
newProps[prop] = simplifyCore(node.properties[prop]);
|
224
|
+
newProps[prop] = simplifyCore(node.properties[prop], options);
|
209
225
|
}
|
210
226
|
|
211
227
|
return new ObjectNode(newProps);
|
@@ -14,14 +14,26 @@ export function combinationsNumber(n, k) {
|
|
14
14
|
}
|
15
15
|
|
16
16
|
var nMinusk = n - k;
|
17
|
-
var
|
17
|
+
var answer = 1;
|
18
|
+
var firstnumerator = k < nMinusk ? nMinusk + 1 : k + 1;
|
19
|
+
var nextdivisor = 2;
|
20
|
+
var lastdivisor = k < nMinusk ? k : nMinusk; // balance multiplications and divisions to try to keep intermediate values
|
21
|
+
// in exact-integer range as long as possible
|
18
22
|
|
19
|
-
|
20
|
-
|
21
|
-
|
23
|
+
for (var nextnumerator = firstnumerator; nextnumerator <= n; ++nextnumerator) {
|
24
|
+
answer *= nextnumerator;
|
25
|
+
|
26
|
+
while (nextdivisor <= lastdivisor && answer % nextdivisor === 0) {
|
27
|
+
answer /= nextdivisor;
|
28
|
+
++nextdivisor;
|
29
|
+
}
|
30
|
+
} // for big n, k, floating point may have caused weirdness in remainder
|
31
|
+
|
32
|
+
|
33
|
+
if (nextdivisor <= lastdivisor) {
|
34
|
+
answer /= product(nextdivisor, lastdivisor);
|
22
35
|
}
|
23
36
|
|
24
|
-
|
25
|
-
return prodrange / product(1, nMinusk);
|
37
|
+
return answer;
|
26
38
|
}
|
27
39
|
combinationsNumber.signature = 'number, number';
|
package/lib/esm/version.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export var version = '10.
|
1
|
+
export var version = '10.2.0'; // 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.
|
3
|
+
"version": "10.2.0",
|
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,26 +25,27 @@
|
|
25
25
|
"unit"
|
26
26
|
],
|
27
27
|
"dependencies": {
|
28
|
-
"@babel/runtime": "^7.
|
28
|
+
"@babel/runtime": "^7.17.2",
|
29
29
|
"complex.js": "^2.0.15",
|
30
30
|
"decimal.js": "^10.3.1",
|
31
31
|
"escape-latex": "^1.2.0",
|
32
|
-
"fraction.js": "^4.1.
|
32
|
+
"fraction.js": "^4.1.3",
|
33
33
|
"javascript-natural-sort": "^0.7.1",
|
34
34
|
"seedrandom": "^3.0.5",
|
35
35
|
"tiny-emitter": "^2.1.0",
|
36
36
|
"typed-function": "^2.0.0"
|
37
37
|
},
|
38
38
|
"devDependencies": {
|
39
|
-
"@babel/core": "7.
|
39
|
+
"@babel/core": "7.17.5",
|
40
40
|
"@babel/plugin-transform-object-assign": "7.16.7",
|
41
|
-
"@babel/plugin-transform-runtime": "7.
|
41
|
+
"@babel/plugin-transform-runtime": "7.17.0",
|
42
42
|
"@babel/preset-env": "7.16.11",
|
43
|
-
"@babel/register": "7.
|
43
|
+
"@babel/register": "7.17.0",
|
44
|
+
"assert": "2.0.0",
|
44
45
|
"babel-loader": "8.2.3",
|
45
46
|
"benchmark": "2.1.4",
|
46
47
|
"codecov": "3.8.3",
|
47
|
-
"core-js": "3.21.
|
48
|
+
"core-js": "3.21.1",
|
48
49
|
"del": "6.0.0",
|
49
50
|
"dtslint": "4.2.1",
|
50
51
|
"expr-eval": "2.0.2",
|
@@ -54,8 +55,8 @@
|
|
54
55
|
"gulp-babel": "8.0.0",
|
55
56
|
"handlebars": "4.7.7",
|
56
57
|
"istanbul": "0.4.5",
|
57
|
-
"jsep": "1.
|
58
|
-
"karma": "6.3.
|
58
|
+
"jsep": "1.3.0",
|
59
|
+
"karma": "6.3.16",
|
59
60
|
"karma-browserstack-launcher": "1.6.0",
|
60
61
|
"karma-firefox-launcher": "2.1.2",
|
61
62
|
"karma-mocha": "2.0.1",
|
@@ -72,6 +73,7 @@
|
|
72
73
|
"numericjs": "1.2.6",
|
73
74
|
"nyc": "15.1.0",
|
74
75
|
"pad-right": "0.2.2",
|
76
|
+
"process": "0.11.10",
|
75
77
|
"standard": "16.0.4",
|
76
78
|
"sylvester": "0.0.21",
|
77
79
|
"typescript": "4.5.5",
|
@@ -124,7 +126,7 @@
|
|
124
126
|
"CONTRIBUTING.md"
|
125
127
|
],
|
126
128
|
"scripts": {
|
127
|
-
"build": "gulp --gulpfile gulpfile.cjs",
|
129
|
+
"build": "gulp --gulpfile gulpfile.cjs && npm run update-authors",
|
128
130
|
"build-and-test": "npm run build && npm run test:all && npm run lint",
|
129
131
|
"build:clean": "gulp --gulpfile gulpfile.cjs clean",
|
130
132
|
"build:docs": "gulp --gulpfile gulpfile.cjs docs",
|
@@ -161,5 +163,8 @@
|
|
161
163
|
"src": "./src",
|
162
164
|
"test": "./test"
|
163
165
|
},
|
166
|
+
"browserslist": [
|
167
|
+
"IE 11"
|
168
|
+
],
|
164
169
|
"sideEffects": false
|
165
170
|
}
|
package/types/index.d.ts
CHANGED
@@ -575,7 +575,7 @@ declare namespace math {
|
|
575
575
|
* @param unit The unit to be created
|
576
576
|
* @returns The created unit
|
577
577
|
*/
|
578
|
-
unit(value: number | MathArray | Matrix, unit: string): Unit;
|
578
|
+
unit(value: number | MathArray | Matrix | BigNumber, unit: string): Unit;
|
579
579
|
|
580
580
|
/*************************************************************************
|
581
581
|
* Expression functions
|
@@ -1674,6 +1674,19 @@ declare namespace math {
|
|
1674
1674
|
column: number
|
1675
1675
|
): T;
|
1676
1676
|
|
1677
|
+
/**
|
1678
|
+
* Return a rotated matrix.
|
1679
|
+
* @param {Array | Matrix} w Vector to rotate
|
1680
|
+
* @param {number | BigNumber | Complex | Unit} theta Rotation angle
|
1681
|
+
* @param {Array | Matrix} [v] Rotation axis
|
1682
|
+
* @return {Array | Matrix} Multiplication of the rotation matrix and w
|
1683
|
+
*/
|
1684
|
+
rotate<T extends MathArray | Matrix>(
|
1685
|
+
w: T,
|
1686
|
+
theta: number | BigNumber | Complex | Unit,
|
1687
|
+
v?: T
|
1688
|
+
): T;
|
1689
|
+
|
1677
1690
|
/**
|
1678
1691
|
* Calculate the size of a matrix or scalar.
|
1679
1692
|
* @param A matrix
|
@@ -1783,7 +1796,7 @@ declare namespace math {
|
|
1783
1796
|
* @param n A real or complex number
|
1784
1797
|
* @returns The gamma of n
|
1785
1798
|
*/
|
1786
|
-
gamma
|
1799
|
+
gamma<T extends number | BigNumber | Complex | MathArray | Matrix>(n: T): NoLiteralType<T>;
|
1787
1800
|
|
1788
1801
|
/**
|
1789
1802
|
* Calculate the Kullback-Leibler (KL) divergence between two
|
@@ -3121,6 +3134,28 @@ declare namespace math {
|
|
3121
3134
|
fixPrefix?: boolean;
|
3122
3135
|
}
|
3123
3136
|
|
3137
|
+
interface UnitComponent {
|
3138
|
+
power: number;
|
3139
|
+
prefix: string;
|
3140
|
+
unit: {
|
3141
|
+
name: string;
|
3142
|
+
base: {
|
3143
|
+
dimensions: number[];
|
3144
|
+
key: string;
|
3145
|
+
};
|
3146
|
+
prefixes: Record<string, UnitPrefix>;
|
3147
|
+
value: number;
|
3148
|
+
offset: number;
|
3149
|
+
dimensions: number[];
|
3150
|
+
};
|
3151
|
+
}
|
3152
|
+
|
3153
|
+
interface UnitPrefix {
|
3154
|
+
name: string;
|
3155
|
+
value: number;
|
3156
|
+
scientific: boolean;
|
3157
|
+
}
|
3158
|
+
|
3124
3159
|
interface Unit {
|
3125
3160
|
valueOf(): string;
|
3126
3161
|
clone(): Unit;
|
@@ -3139,7 +3174,14 @@ declare namespace math {
|
|
3139
3174
|
toJSON(): MathJSON;
|
3140
3175
|
formatUnits(): string;
|
3141
3176
|
format(options: FormatOptions): string;
|
3177
|
+
simplify(): Unit;
|
3142
3178
|
splitUnit(parts: ReadonlyArray<string | Unit>): Unit[];
|
3179
|
+
|
3180
|
+
units: UnitComponent[];
|
3181
|
+
dimensions: number[];
|
3182
|
+
value: number;
|
3183
|
+
fixPrefix: boolean;
|
3184
|
+
skipAutomaticSimplification: true;
|
3143
3185
|
}
|
3144
3186
|
|
3145
3187
|
interface CreateUnitOptions {
|
@@ -1,76 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.createResolve = void 0;
|
7
|
-
|
8
|
-
var _map = require("../../../utils/map.js");
|
9
|
-
|
10
|
-
var _is = require("../../../utils/is.js");
|
11
|
-
|
12
|
-
var _factory = require("../../../utils/factory.js");
|
13
|
-
|
14
|
-
var name = 'resolve';
|
15
|
-
var dependencies = ['parse', 'FunctionNode', 'OperatorNode', 'ParenthesisNode'];
|
16
|
-
var createResolve = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
|
17
|
-
var parse = _ref.parse,
|
18
|
-
FunctionNode = _ref.FunctionNode,
|
19
|
-
OperatorNode = _ref.OperatorNode,
|
20
|
-
ParenthesisNode = _ref.ParenthesisNode;
|
21
|
-
|
22
|
-
/**
|
23
|
-
* resolve(expr, scope) replaces variable nodes with their scoped values
|
24
|
-
*
|
25
|
-
* Syntax:
|
26
|
-
*
|
27
|
-
* simplify.resolve(expr, scope)
|
28
|
-
*
|
29
|
-
* Examples:
|
30
|
-
*
|
31
|
-
* math.simplify.resolve('x + y', {x:1, y:2}) // Node {1 + 2}
|
32
|
-
* math.simplify.resolve(math.parse('x+y'), {x:1, y:2}) // Node {1 + 2}
|
33
|
-
* math.simplify('x+y', {x:2, y:'x+x'}).toString() // "6"
|
34
|
-
*
|
35
|
-
* @param {Node} node
|
36
|
-
* The expression tree to be simplified
|
37
|
-
* @param {Object} scope with variables to be resolved
|
38
|
-
*/
|
39
|
-
function resolve(node, scope) {
|
40
|
-
if (!scope) {
|
41
|
-
return node;
|
42
|
-
}
|
43
|
-
|
44
|
-
if (!(0, _map.isMap)(scope)) {
|
45
|
-
scope = (0, _map.createMap)(scope);
|
46
|
-
}
|
47
|
-
|
48
|
-
if ((0, _is.isSymbolNode)(node)) {
|
49
|
-
var value = scope.get(node.name);
|
50
|
-
|
51
|
-
if ((0, _is.isNode)(value)) {
|
52
|
-
return resolve(value, scope);
|
53
|
-
} else if (typeof value === 'number') {
|
54
|
-
return parse(String(value));
|
55
|
-
}
|
56
|
-
} else if ((0, _is.isOperatorNode)(node)) {
|
57
|
-
var args = node.args.map(function (arg) {
|
58
|
-
return resolve(arg, scope);
|
59
|
-
});
|
60
|
-
return new OperatorNode(node.op, node.fn, args, node.implicit);
|
61
|
-
} else if ((0, _is.isParenthesisNode)(node)) {
|
62
|
-
return new ParenthesisNode(resolve(node.content, scope));
|
63
|
-
} else if ((0, _is.isFunctionNode)(node)) {
|
64
|
-
var _args = node.args.map(function (arg) {
|
65
|
-
return resolve(arg, scope);
|
66
|
-
});
|
67
|
-
|
68
|
-
return new FunctionNode(node.name, _args);
|
69
|
-
}
|
70
|
-
|
71
|
-
return node;
|
72
|
-
}
|
73
|
-
|
74
|
-
return resolve;
|
75
|
-
});
|
76
|
-
exports.createResolve = createResolve;
|
@@ -1,67 +0,0 @@
|
|
1
|
-
import { createMap, isMap } from '../../../utils/map.js';
|
2
|
-
import { isFunctionNode, isNode, isOperatorNode, isParenthesisNode, isSymbolNode } from '../../../utils/is.js';
|
3
|
-
import { factory } from '../../../utils/factory.js';
|
4
|
-
var name = 'resolve';
|
5
|
-
var dependencies = ['parse', 'FunctionNode', 'OperatorNode', 'ParenthesisNode'];
|
6
|
-
export var createResolve = /* #__PURE__ */factory(name, dependencies, _ref => {
|
7
|
-
var {
|
8
|
-
parse,
|
9
|
-
FunctionNode,
|
10
|
-
OperatorNode,
|
11
|
-
ParenthesisNode
|
12
|
-
} = _ref;
|
13
|
-
|
14
|
-
/**
|
15
|
-
* resolve(expr, scope) replaces variable nodes with their scoped values
|
16
|
-
*
|
17
|
-
* Syntax:
|
18
|
-
*
|
19
|
-
* simplify.resolve(expr, scope)
|
20
|
-
*
|
21
|
-
* Examples:
|
22
|
-
*
|
23
|
-
* math.simplify.resolve('x + y', {x:1, y:2}) // Node {1 + 2}
|
24
|
-
* math.simplify.resolve(math.parse('x+y'), {x:1, y:2}) // Node {1 + 2}
|
25
|
-
* math.simplify('x+y', {x:2, y:'x+x'}).toString() // "6"
|
26
|
-
*
|
27
|
-
* @param {Node} node
|
28
|
-
* The expression tree to be simplified
|
29
|
-
* @param {Object} scope with variables to be resolved
|
30
|
-
*/
|
31
|
-
function resolve(node, scope) {
|
32
|
-
if (!scope) {
|
33
|
-
return node;
|
34
|
-
}
|
35
|
-
|
36
|
-
if (!isMap(scope)) {
|
37
|
-
scope = createMap(scope);
|
38
|
-
}
|
39
|
-
|
40
|
-
if (isSymbolNode(node)) {
|
41
|
-
var value = scope.get(node.name);
|
42
|
-
|
43
|
-
if (isNode(value)) {
|
44
|
-
return resolve(value, scope);
|
45
|
-
} else if (typeof value === 'number') {
|
46
|
-
return parse(String(value));
|
47
|
-
}
|
48
|
-
} else if (isOperatorNode(node)) {
|
49
|
-
var args = node.args.map(function (arg) {
|
50
|
-
return resolve(arg, scope);
|
51
|
-
});
|
52
|
-
return new OperatorNode(node.op, node.fn, args, node.implicit);
|
53
|
-
} else if (isParenthesisNode(node)) {
|
54
|
-
return new ParenthesisNode(resolve(node.content, scope));
|
55
|
-
} else if (isFunctionNode(node)) {
|
56
|
-
var _args = node.args.map(function (arg) {
|
57
|
-
return resolve(arg, scope);
|
58
|
-
});
|
59
|
-
|
60
|
-
return new FunctionNode(node.name, _args);
|
61
|
-
}
|
62
|
-
|
63
|
-
return node;
|
64
|
-
}
|
65
|
-
|
66
|
-
return resolve;
|
67
|
-
});
|