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
@@ -152,7 +152,7 @@ var createFunctionNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
152
152
|
var values = evalArgs.map(function (evalArg) {
|
153
153
|
return evalArg(scope, args, context);
|
154
154
|
});
|
155
|
-
return fn.apply(void 0, (0, _toConsumableArray2
|
155
|
+
return fn.apply(void 0, (0, _toConsumableArray2.default)(values));
|
156
156
|
};
|
157
157
|
}
|
158
158
|
}
|
@@ -270,7 +270,7 @@ var createFunctionNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
270
270
|
var customString;
|
271
271
|
var name = this.fn.toString(options);
|
272
272
|
|
273
|
-
if (options && (0, _typeof2
|
273
|
+
if (options && (0, _typeof2.default)(options.handler) === 'object' && (0, _object.hasOwnProperty)(options.handler, name)) {
|
274
274
|
// callback is a map of callback functions
|
275
275
|
customString = options.handler[name](this, options);
|
276
276
|
}
|
@@ -376,7 +376,7 @@ var createFunctionNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
376
376
|
|
377
377
|
if (match[2] === undefined) {
|
378
378
|
// no square brackets
|
379
|
-
switch ((0, _typeof2
|
379
|
+
switch ((0, _typeof2.default)(property)) {
|
380
380
|
case 'string':
|
381
381
|
latex += property;
|
382
382
|
break;
|
@@ -436,7 +436,7 @@ var createFunctionNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
436
436
|
FunctionNode.prototype.toTex = function (options) {
|
437
437
|
var customTex;
|
438
438
|
|
439
|
-
if (options && (0, _typeof2
|
439
|
+
if (options && (0, _typeof2.default)(options.handler) === 'object' && (0, _object.hasOwnProperty)(options.handler, this.name)) {
|
440
440
|
// callback is a map of callback functions
|
441
441
|
customTex = options.handler[this.name](this, options);
|
442
442
|
}
|
@@ -467,14 +467,14 @@ var createFunctionNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
467
467
|
} // toTex property on the function itself
|
468
468
|
|
469
469
|
|
470
|
-
if (math[this.name] && (typeof math[this.name].toTex === 'function' || (0, _typeof2
|
470
|
+
if (math[this.name] && (typeof math[this.name].toTex === 'function' || (0, _typeof2.default)(math[this.name].toTex) === 'object' || typeof math[this.name].toTex === 'string')) {
|
471
471
|
// .toTex is a callback function
|
472
472
|
latexConverter = math[this.name].toTex;
|
473
473
|
}
|
474
474
|
|
475
475
|
var customToTex;
|
476
476
|
|
477
|
-
switch ((0, _typeof2
|
477
|
+
switch ((0, _typeof2.default)(latexConverter)) {
|
478
478
|
case 'function':
|
479
479
|
// a callback function
|
480
480
|
customToTex = latexConverter(this, options);
|
@@ -487,7 +487,7 @@ var createFunctionNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
487
487
|
|
488
488
|
case 'object':
|
489
489
|
// an object with different "converters" for different numbers of arguments
|
490
|
-
switch ((0, _typeof2
|
490
|
+
switch ((0, _typeof2.default)(latexConverter[args.length])) {
|
491
491
|
case 'function':
|
492
492
|
customToTex = latexConverter[args.length](this, options);
|
493
493
|
break;
|
@@ -143,7 +143,7 @@ var createIndexNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies, f
|
|
143
143
|
var dimensions = (0, _array.map)(evalDimensions, function (evalDimension) {
|
144
144
|
return evalDimension(scope, args, context);
|
145
145
|
});
|
146
|
-
return index.apply(void 0, (0, _toConsumableArray2
|
146
|
+
return index.apply(void 0, (0, _toConsumableArray2.default)(dimensions));
|
147
147
|
};
|
148
148
|
};
|
149
149
|
/**
|
@@ -367,8 +367,8 @@ var createNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functi
|
|
367
367
|
|
368
368
|
|
369
369
|
Node.prototype._getCustomString = function (options) {
|
370
|
-
if (options && (0, _typeof2
|
371
|
-
switch ((0, _typeof2
|
370
|
+
if (options && (0, _typeof2.default)(options) === 'object') {
|
371
|
+
switch ((0, _typeof2.default)(options.handler)) {
|
372
372
|
case 'object':
|
373
373
|
case 'undefined':
|
374
374
|
return;
|
@@ -407,7 +407,7 @@ var createNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functi
|
|
407
407
|
|
408
408
|
|
409
409
|
function _validateScope(scope) {
|
410
|
-
for (var _i = 0, _arr = (0, _toConsumableArray2
|
410
|
+
for (var _i = 0, _arr = (0, _toConsumableArray2.default)(_keywords.keywords); _i < _arr.length; _i++) {
|
411
411
|
var symbol = _arr[_i];
|
412
412
|
|
413
413
|
if (scope.has(symbol)) {
|
@@ -38,7 +38,7 @@ var createObjectNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies,
|
|
38
38
|
this.properties = properties || {}; // validate input
|
39
39
|
|
40
40
|
if (properties) {
|
41
|
-
if (!((0, _typeof2
|
41
|
+
if (!((0, _typeof2.default)(properties) === 'object') || !Object.keys(properties).every(function (key) {
|
42
42
|
return (0, _is.isNode)(properties[key]);
|
43
43
|
})) {
|
44
44
|
throw new TypeError('Object containing Nodes expected');
|
@@ -37,7 +37,7 @@ function accessFactory(_ref) {
|
|
37
37
|
} else if (typeof object === 'string') {
|
38
38
|
// TODO: move getStringSubset into a separate util file, use that
|
39
39
|
return subset(object, index);
|
40
|
-
} else if ((0, _typeof2
|
40
|
+
} else if ((0, _typeof2.default)(object) === 'object') {
|
41
41
|
if (!index.isObjectProperty()) {
|
42
42
|
throw new TypeError('Cannot apply a numeric index as object property');
|
43
43
|
}
|
@@ -42,7 +42,7 @@ function assignFactory(_ref) {
|
|
42
42
|
} else if (typeof object === 'string') {
|
43
43
|
// TODO: move setStringSubset into a separate util file, use that
|
44
44
|
return subset(object, index, value);
|
45
|
-
} else if ((0, _typeof2
|
45
|
+
} else if ((0, _typeof2.default)(object) === 'object') {
|
46
46
|
if (!index.isObjectProperty()) {
|
47
47
|
throw TypeError('Cannot apply a numeric index as object property');
|
48
48
|
}
|
@@ -153,16 +153,16 @@ var createParse = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
153
153
|
var NAMED_DELIMITERS = {
|
154
154
|
mod: true,
|
155
155
|
to: true,
|
156
|
-
|
156
|
+
in: true,
|
157
157
|
and: true,
|
158
158
|
xor: true,
|
159
159
|
or: true,
|
160
160
|
not: true
|
161
161
|
};
|
162
162
|
var CONSTANTS = {
|
163
|
-
|
164
|
-
|
165
|
-
|
163
|
+
true: true,
|
164
|
+
false: false,
|
165
|
+
null: null,
|
166
166
|
undefined: undefined
|
167
167
|
};
|
168
168
|
var NUMERIC_CONSTANTS = ['NaN', 'Infinity'];
|
@@ -584,7 +584,7 @@ var createParse = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
584
584
|
|
585
585
|
function parseStart(expression, extraNodes) {
|
586
586
|
var state = initialState();
|
587
|
-
(0, _extends2
|
587
|
+
(0, _extends2.default)(state, {
|
588
588
|
expression: expression,
|
589
589
|
extraNodes: extraNodes
|
590
590
|
});
|
@@ -930,7 +930,7 @@ var createParse = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
930
930
|
node = parseRange(state);
|
931
931
|
var operators = {
|
932
932
|
to: 'to',
|
933
|
-
|
933
|
+
in: 'to' // alias of 'to'
|
934
934
|
|
935
935
|
};
|
936
936
|
|
@@ -1112,30 +1112,30 @@ var createParse = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
1112
1112
|
// Match the "number /" part of the pattern "number / number symbol"
|
1113
1113
|
if (state.token === '/' && (0, _is.isConstantNode)(last)) {
|
1114
1114
|
// Look ahead to see if the next token is a number
|
1115
|
-
tokenStates.push((0, _extends2
|
1115
|
+
tokenStates.push((0, _extends2.default)({}, state));
|
1116
1116
|
getTokenSkipNewline(state); // Match the "number / number" part of the pattern
|
1117
1117
|
|
1118
1118
|
if (state.tokenType === TOKENTYPE.NUMBER) {
|
1119
1119
|
// Look ahead again
|
1120
|
-
tokenStates.push((0, _extends2
|
1120
|
+
tokenStates.push((0, _extends2.default)({}, state));
|
1121
1121
|
getTokenSkipNewline(state); // Match the "symbol" part of the pattern, or a left parenthesis
|
1122
1122
|
|
1123
1123
|
if (state.tokenType === TOKENTYPE.SYMBOL || state.token === '(') {
|
1124
1124
|
// We've matched the pattern "number / number symbol".
|
1125
1125
|
// Rewind once and build the "number / number" node; the symbol will be consumed later
|
1126
|
-
(0, _extends2
|
1126
|
+
(0, _extends2.default)(state, tokenStates.pop());
|
1127
1127
|
tokenStates.pop();
|
1128
1128
|
last = parsePercentage(state);
|
1129
1129
|
node = new OperatorNode('/', 'divide', [node, last]);
|
1130
1130
|
} else {
|
1131
1131
|
// Not a match, so rewind
|
1132
1132
|
tokenStates.pop();
|
1133
|
-
(0, _extends2
|
1133
|
+
(0, _extends2.default)(state, tokenStates.pop());
|
1134
1134
|
break;
|
1135
1135
|
}
|
1136
1136
|
} else {
|
1137
1137
|
// Not a match, so rewind
|
1138
|
-
(0, _extends2
|
1138
|
+
(0, _extends2.default)(state, tokenStates.pop());
|
1139
1139
|
break;
|
1140
1140
|
}
|
1141
1141
|
} else {
|
@@ -1783,7 +1783,7 @@ var createParse = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
1783
1783
|
function createSyntaxError(state, message) {
|
1784
1784
|
var c = col(state);
|
1785
1785
|
var error = new SyntaxError(message + ' (char ' + c + ')');
|
1786
|
-
error
|
1786
|
+
error.char = c;
|
1787
1787
|
return error;
|
1788
1788
|
}
|
1789
1789
|
/**
|
@@ -1798,7 +1798,7 @@ var createParse = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
1798
1798
|
function createError(state, message) {
|
1799
1799
|
var c = col(state);
|
1800
1800
|
var error = new SyntaxError(message + ' (char ' + c + ')');
|
1801
|
-
error
|
1801
|
+
error.char = c;
|
1802
1802
|
return error;
|
1803
1803
|
}
|
1804
1804
|
|
package/lib/cjs/factoriesAny.js
CHANGED
@@ -987,6 +987,12 @@ Object.defineProperty(exports, "createLcm", {
|
|
987
987
|
return _lcm.createLcm;
|
988
988
|
}
|
989
989
|
});
|
990
|
+
Object.defineProperty(exports, "createLeafCount", {
|
991
|
+
enumerable: true,
|
992
|
+
get: function get() {
|
993
|
+
return _leafCount.createLeafCount;
|
994
|
+
}
|
995
|
+
});
|
990
996
|
Object.defineProperty(exports, "createLeftShift", {
|
991
997
|
enumerable: true,
|
992
998
|
get: function get() {
|
@@ -1509,6 +1515,12 @@ Object.defineProperty(exports, "createResize", {
|
|
1509
1515
|
return _resize.createResize;
|
1510
1516
|
}
|
1511
1517
|
});
|
1518
|
+
Object.defineProperty(exports, "createResolve", {
|
1519
|
+
enumerable: true,
|
1520
|
+
get: function get() {
|
1521
|
+
return _resolve.createResolve;
|
1522
|
+
}
|
1523
|
+
});
|
1512
1524
|
Object.defineProperty(exports, "createResultSet", {
|
1513
1525
|
enumerable: true,
|
1514
1526
|
get: function get() {
|
@@ -1677,6 +1689,12 @@ Object.defineProperty(exports, "createSimplify", {
|
|
1677
1689
|
return _simplify.createSimplify;
|
1678
1690
|
}
|
1679
1691
|
});
|
1692
|
+
Object.defineProperty(exports, "createSimplifyCore", {
|
1693
|
+
enumerable: true,
|
1694
|
+
get: function get() {
|
1695
|
+
return _simplifyCore.createSimplifyCore;
|
1696
|
+
}
|
1697
|
+
});
|
1680
1698
|
Object.defineProperty(exports, "createSin", {
|
1681
1699
|
enumerable: true,
|
1682
1700
|
get: function get() {
|
@@ -2494,8 +2512,14 @@ var _catalan = require("./function/combinatorics/catalan.js");
|
|
2494
2512
|
|
2495
2513
|
var _composition = require("./function/combinatorics/composition.js");
|
2496
2514
|
|
2515
|
+
var _leafCount = require("./function/algebra/leafCount.js");
|
2516
|
+
|
2497
2517
|
var _simplify = require("./function/algebra/simplify.js");
|
2498
2518
|
|
2519
|
+
var _simplifyCore = require("./function/algebra/simplifyCore.js");
|
2520
|
+
|
2521
|
+
var _resolve = require("./function/algebra/resolve.js");
|
2522
|
+
|
2499
2523
|
var _derivative = require("./function/algebra/derivative.js");
|
2500
2524
|
|
2501
2525
|
var _rationalize = require("./function/algebra/rationalize.js");
|
@@ -579,6 +579,12 @@ Object.defineProperty(exports, "createReplacer", {
|
|
579
579
|
return _replacer.createReplacer;
|
580
580
|
}
|
581
581
|
});
|
582
|
+
Object.defineProperty(exports, "createResolve", {
|
583
|
+
enumerable: true,
|
584
|
+
get: function get() {
|
585
|
+
return _resolve.createResolve;
|
586
|
+
}
|
587
|
+
});
|
582
588
|
Object.defineProperty(exports, "createResultSet", {
|
583
589
|
enumerable: true,
|
584
590
|
get: function get() {
|
@@ -617,6 +623,12 @@ Object.defineProperty(exports, "createSimplify", {
|
|
617
623
|
return _simplify.createSimplify;
|
618
624
|
}
|
619
625
|
});
|
626
|
+
Object.defineProperty(exports, "createSimplifyCore", {
|
627
|
+
enumerable: true,
|
628
|
+
get: function get() {
|
629
|
+
return _simplifyCore.createSimplifyCore;
|
630
|
+
}
|
631
|
+
});
|
620
632
|
exports.createSinh = exports.createSin = void 0;
|
621
633
|
Object.defineProperty(exports, "createSize", {
|
622
634
|
enumerable: true,
|
@@ -764,8 +776,12 @@ var _help = require("./expression/function/help.js");
|
|
764
776
|
|
765
777
|
var _chain = require("./type/chain/function/chain.js");
|
766
778
|
|
779
|
+
var _resolve = require("./function/algebra/resolve.js");
|
780
|
+
|
767
781
|
var _simplify = require("./function/algebra/simplify.js");
|
768
782
|
|
783
|
+
var _simplifyCore = require("./function/algebra/simplifyCore.js");
|
784
|
+
|
769
785
|
var _derivative = require("./function/algebra/derivative.js");
|
770
786
|
|
771
787
|
var _rationalize = require("./function/algebra/rationalize.js");
|
@@ -73,7 +73,7 @@ var createQr = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function
|
|
73
73
|
* @return {{Q: Array | Matrix, R: Array | Matrix}} Q: the orthogonal
|
74
74
|
* matrix and R: the upper triangular matrix
|
75
75
|
*/
|
76
|
-
return (0, _extends2
|
76
|
+
return (0, _extends2.default)(typed(name, {
|
77
77
|
DenseMatrix: function DenseMatrix(m) {
|
78
78
|
return _denseQR(m);
|
79
79
|
},
|
@@ -0,0 +1,66 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.createLeafCount = void 0;
|
7
|
+
|
8
|
+
var _factory = require("../../utils/factory.js");
|
9
|
+
|
10
|
+
var name = 'leafCount';
|
11
|
+
var dependencies = ['parse', 'typed'];
|
12
|
+
var createLeafCount = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
|
13
|
+
var parse = _ref.parse,
|
14
|
+
typed = _ref.typed;
|
15
|
+
|
16
|
+
// This does the real work, but we don't have to recurse through
|
17
|
+
// a typed call if we separate it out
|
18
|
+
function countLeaves(node) {
|
19
|
+
var count = 0;
|
20
|
+
node.forEach(function (n) {
|
21
|
+
count += countLeaves(n);
|
22
|
+
});
|
23
|
+
return count || 1;
|
24
|
+
}
|
25
|
+
/**
|
26
|
+
* Gives the number of "leaf nodes" in the parse tree of the given expression
|
27
|
+
* A leaf node is one that has no subexpressions, essentially either a
|
28
|
+
* symbol or a constant. Note that `5!` has just one leaf, the '5'; the
|
29
|
+
* unary factorial operator does not add a leaf. On the other hand,
|
30
|
+
* function symbols do add leaves, so `sin(x)/cos(x)` has four leaves.
|
31
|
+
*
|
32
|
+
* The `simplify()` function should generally not increase the `leafCount()`
|
33
|
+
* of an expression, although currently there is no guarantee that it never
|
34
|
+
* does so. In many cases, `simplify()` reduces the leaf count.
|
35
|
+
*
|
36
|
+
* Syntax:
|
37
|
+
*
|
38
|
+
* leafCount(expr)
|
39
|
+
*
|
40
|
+
* Examples:
|
41
|
+
*
|
42
|
+
* math.leafCount('x') // 1
|
43
|
+
* math.leafCount(math.parse('a*d-b*c')) // 4
|
44
|
+
* math.leafCount('[a,b;c,d][0,1]') // 6
|
45
|
+
*
|
46
|
+
* See also:
|
47
|
+
*
|
48
|
+
* simplify
|
49
|
+
*
|
50
|
+
* @param {Node|string} expr The expression to count the leaves of
|
51
|
+
*
|
52
|
+
* @return {number} The number of leaves of `expr`
|
53
|
+
*
|
54
|
+
*/
|
55
|
+
|
56
|
+
|
57
|
+
return typed(name, {
|
58
|
+
string: function string(expr) {
|
59
|
+
return this(parse(expr));
|
60
|
+
},
|
61
|
+
Node: function Node(expr) {
|
62
|
+
return countLeaves(expr);
|
63
|
+
}
|
64
|
+
});
|
65
|
+
});
|
66
|
+
exports.createLeafCount = createLeafCount;
|
@@ -11,10 +11,8 @@ var _factory = require("../../utils/factory.js");
|
|
11
11
|
|
12
12
|
var _simplifyConstant = require("./simplify/simplifyConstant.js");
|
13
13
|
|
14
|
-
var _simplifyCore = require("./simplify/simplifyCore.js");
|
15
|
-
|
16
14
|
var name = 'rationalize';
|
17
|
-
var dependencies = ['config', 'typed', 'equal', 'isZero', 'add', 'subtract', 'multiply', 'divide', 'pow', 'parse', 'simplify', '?bignumber', '?fraction', 'mathWithTransform', 'matrix', 'AccessorNode', 'ArrayNode', 'ConstantNode', 'FunctionNode', 'IndexNode', 'ObjectNode', 'OperatorNode', 'SymbolNode', 'ParenthesisNode'];
|
15
|
+
var dependencies = ['config', 'typed', 'equal', 'isZero', 'add', 'subtract', 'multiply', 'divide', 'pow', 'parse', 'simplifyCore', 'simplify', '?bignumber', '?fraction', 'mathWithTransform', 'matrix', 'AccessorNode', 'ArrayNode', 'ConstantNode', 'FunctionNode', 'IndexNode', 'ObjectNode', 'OperatorNode', 'SymbolNode', 'ParenthesisNode'];
|
18
16
|
var createRationalize = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
|
19
17
|
var config = _ref.config,
|
20
18
|
typed = _ref.typed,
|
@@ -26,6 +24,7 @@ var createRationalize = /* #__PURE__ */(0, _factory.factory)(name, dependencies,
|
|
26
24
|
divide = _ref.divide,
|
27
25
|
pow = _ref.pow,
|
28
26
|
parse = _ref.parse,
|
27
|
+
simplifyCore = _ref.simplifyCore,
|
29
28
|
simplify = _ref.simplify,
|
30
29
|
fraction = _ref.fraction,
|
31
30
|
bignumber = _ref.bignumber,
|
@@ -56,23 +55,6 @@ var createRationalize = /* #__PURE__ */(0, _factory.factory)(name, dependencies,
|
|
56
55
|
OperatorNode: OperatorNode,
|
57
56
|
SymbolNode: SymbolNode
|
58
57
|
});
|
59
|
-
var simplifyCore = (0, _simplifyCore.createSimplifyCore)({
|
60
|
-
equal: equal,
|
61
|
-
isZero: isZero,
|
62
|
-
add: add,
|
63
|
-
subtract: subtract,
|
64
|
-
multiply: multiply,
|
65
|
-
divide: divide,
|
66
|
-
pow: pow,
|
67
|
-
AccessorNode: AccessorNode,
|
68
|
-
ArrayNode: ArrayNode,
|
69
|
-
ConstantNode: ConstantNode,
|
70
|
-
FunctionNode: FunctionNode,
|
71
|
-
IndexNode: IndexNode,
|
72
|
-
ObjectNode: ObjectNode,
|
73
|
-
OperatorNode: OperatorNode,
|
74
|
-
ParenthesisNode: ParenthesisNode
|
75
|
-
});
|
76
58
|
/**
|
77
59
|
* Transform a rationalizable expression in a rational fraction.
|
78
60
|
* If rational fraction is one variable polynomial then converts
|
@@ -116,13 +98,13 @@ var createRationalize = /* #__PURE__ */(0, _factory.factory)(name, dependencies,
|
|
116
98
|
* @param {Object|boolean} optional scope of expression or true for already evaluated rational expression at input
|
117
99
|
* @param {Boolean} detailed optional True if return an object, false if return expression node (default)
|
118
100
|
*
|
119
|
-
* @return {Object | Node} The rational polynomial of `expr` or
|
120
|
-
* {
|
121
|
-
*
|
122
|
-
*
|
123
|
-
*
|
124
|
-
*
|
125
|
-
*
|
101
|
+
* @return {Object | Node} The rational polynomial of `expr` or an object
|
102
|
+
* `{expression, numerator, denominator, variables, coefficients}`, where
|
103
|
+
* `expression` is a `Node` with the node simplified expression,
|
104
|
+
* `numerator` is a `Node` with the simplified numerator of expression,
|
105
|
+
* `denominator` is a `Node` or `boolean` with the simplified denominator or `false` (if there is no denominator),
|
106
|
+
* `variables` is an array with variable names,
|
107
|
+
* and `coefficients` is an array with coefficients of numerator sorted by increased exponent
|
126
108
|
* {Expression Node} node simplified expression
|
127
109
|
*
|
128
110
|
*/
|
@@ -155,6 +137,12 @@ var createRationalize = /* #__PURE__ */(0, _factory.factory)(name, dependencies,
|
|
155
137
|
var polyRet = polynomial(expr, scope, true, setRules.firstRules); // Check if expression is a rationalizable polynomial
|
156
138
|
|
157
139
|
var nVars = polyRet.variables.length;
|
140
|
+
var noExactFractions = {
|
141
|
+
exactFractions: false
|
142
|
+
};
|
143
|
+
var withExactFractions = {
|
144
|
+
exactFractions: true
|
145
|
+
};
|
158
146
|
expr = polyRet.expression;
|
159
147
|
|
160
148
|
if (nVars >= 1) {
|
@@ -165,18 +153,16 @@ var createRationalize = /* #__PURE__ */(0, _factory.factory)(name, dependencies,
|
|
165
153
|
|
166
154
|
var rules;
|
167
155
|
var eDistrDiv = true;
|
168
|
-
var redoInic = false;
|
169
|
-
expr = simplify(expr, setRules.firstRules, {}, {
|
170
|
-
exactFractions: false
|
171
|
-
}); // Apply the initial rules, including succ div rules
|
156
|
+
var redoInic = false; // Apply the initial rules, including succ div rules:
|
172
157
|
|
158
|
+
expr = simplify(expr, setRules.firstRules, {}, noExactFractions);
|
173
159
|
var s;
|
174
160
|
|
175
161
|
while (true) {
|
176
|
-
//
|
162
|
+
// Alternate applying successive division rules and distr.div.rules
|
163
|
+
// until there are no more changes:
|
177
164
|
rules = eDistrDiv ? setRules.distrDivRules : setRules.sucDivRules;
|
178
|
-
expr = simplify(expr, rules);
|
179
|
-
|
165
|
+
expr = simplify(expr, rules, {}, withExactFractions);
|
180
166
|
eDistrDiv = !eDistrDiv; // Swap between Distr.Div and Succ. Div. Rules
|
181
167
|
|
182
168
|
s = expr.toString();
|
@@ -191,14 +177,11 @@ var createRationalize = /* #__PURE__ */(0, _factory.factory)(name, dependencies,
|
|
191
177
|
|
192
178
|
if (redoInic) {
|
193
179
|
// Apply first rules again without succ div rules (if there are changes)
|
194
|
-
expr = simplify(expr, setRules.firstRulesAgain, {},
|
195
|
-
|
196
|
-
|
197
|
-
}
|
180
|
+
expr = simplify(expr, setRules.firstRulesAgain, {}, noExactFractions);
|
181
|
+
} // Apply final rules:
|
182
|
+
|
198
183
|
|
199
|
-
expr = simplify(expr, setRules.finalRules, {},
|
200
|
-
exactFractions: false
|
201
|
-
}); // Apply final rules
|
184
|
+
expr = simplify(expr, setRules.finalRules, {}, noExactFractions);
|
202
185
|
} // NVars >= 1
|
203
186
|
|
204
187
|
|
@@ -0,0 +1,106 @@
|
|
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', 'ConstantNode', 'FunctionNode', 'OperatorNode', 'ParenthesisNode'];
|
16
|
+
var createResolve = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
|
17
|
+
var parse = _ref.parse,
|
18
|
+
ConstantNode = _ref.ConstantNode,
|
19
|
+
FunctionNode = _ref.FunctionNode,
|
20
|
+
OperatorNode = _ref.OperatorNode,
|
21
|
+
ParenthesisNode = _ref.ParenthesisNode;
|
22
|
+
|
23
|
+
/**
|
24
|
+
* resolve(expr, scope) replaces variable nodes with their scoped values
|
25
|
+
*
|
26
|
+
* Syntax:
|
27
|
+
*
|
28
|
+
* resolve(expr, scope)
|
29
|
+
*
|
30
|
+
* Examples:
|
31
|
+
*
|
32
|
+
* math.resolve('x + y', {x:1, y:2}) // Node {1 + 2}
|
33
|
+
* math.resolve(math.parse('x+y'), {x:1, y:2}) // Node {1 + 2}
|
34
|
+
* math.simplify('x+y', {x:2, y:'x+x'}).toString() // "6"
|
35
|
+
*
|
36
|
+
* See also:
|
37
|
+
*
|
38
|
+
* simplify, evaluate
|
39
|
+
*
|
40
|
+
* @param {Node} node
|
41
|
+
* The expression tree to be simplified
|
42
|
+
* @param {Object} scope
|
43
|
+
* Scope specifying variables to be resolved
|
44
|
+
* @return {Node} Returns `node` with variables recursively substituted.
|
45
|
+
* @throws {ReferenceError}
|
46
|
+
* If there is a cyclic dependency among the variables in `scope`,
|
47
|
+
* resolution is impossible and a ReferenceError is thrown.
|
48
|
+
*/
|
49
|
+
function resolve(node, scope) {
|
50
|
+
var within = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Set();
|
51
|
+
|
52
|
+
// note `within`:
|
53
|
+
// `within` is not documented, since it is for internal cycle
|
54
|
+
// detection only
|
55
|
+
if (!scope) {
|
56
|
+
return node;
|
57
|
+
}
|
58
|
+
|
59
|
+
if (!(0, _map.isMap)(scope)) {
|
60
|
+
scope = (0, _map.createMap)(scope);
|
61
|
+
}
|
62
|
+
|
63
|
+
if ((0, _is.isSymbolNode)(node)) {
|
64
|
+
if (within.has(node.name)) {
|
65
|
+
var variables = Array.from(within).join(', ');
|
66
|
+
throw new ReferenceError("recursive loop of variable definitions among {".concat(variables, "}"));
|
67
|
+
}
|
68
|
+
|
69
|
+
var value = scope.get(node.name);
|
70
|
+
|
71
|
+
if ((0, _is.isNode)(value)) {
|
72
|
+
var nextWithin = new Set(within);
|
73
|
+
nextWithin.add(node.name);
|
74
|
+
return resolve(value, scope, nextWithin);
|
75
|
+
} else if (typeof value === 'number') {
|
76
|
+
return parse(String(value));
|
77
|
+
} else if (value !== undefined) {
|
78
|
+
return new ConstantNode(value);
|
79
|
+
} else {
|
80
|
+
return node;
|
81
|
+
}
|
82
|
+
} else if ((0, _is.isOperatorNode)(node)) {
|
83
|
+
var args = node.args.map(function (arg) {
|
84
|
+
return resolve(arg, scope, within);
|
85
|
+
});
|
86
|
+
return new OperatorNode(node.op, node.fn, args, node.implicit);
|
87
|
+
} else if ((0, _is.isParenthesisNode)(node)) {
|
88
|
+
return new ParenthesisNode(resolve(node.content, scope, within));
|
89
|
+
} else if ((0, _is.isFunctionNode)(node)) {
|
90
|
+
var _args = node.args.map(function (arg) {
|
91
|
+
return resolve(arg, scope, within);
|
92
|
+
});
|
93
|
+
|
94
|
+
return new FunctionNode(node.name, _args);
|
95
|
+
} // Otherwise just recursively resolve any children (might also work
|
96
|
+
// for some of the above special cases)
|
97
|
+
|
98
|
+
|
99
|
+
return node.map(function (child) {
|
100
|
+
return resolve(child, scope, within);
|
101
|
+
});
|
102
|
+
}
|
103
|
+
|
104
|
+
return resolve;
|
105
|
+
});
|
106
|
+
exports.createResolve = createResolve;
|
@@ -17,7 +17,7 @@ var _util = require("./util.js");
|
|
17
17
|
|
18
18
|
var _noop = require("../../../utils/noop.js");
|
19
19
|
|
20
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it
|
20
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
21
21
|
|
22
22
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
23
23
|
|
@@ -348,7 +348,7 @@ var createSimplifyConstant = /* #__PURE__ */(0, _factory.factory)(name, dependen
|
|
348
348
|
return node;
|
349
349
|
|
350
350
|
case 'ConstantNode':
|
351
|
-
switch ((0, _typeof2
|
351
|
+
switch ((0, _typeof2.default)(node.value)) {
|
352
352
|
case 'number':
|
353
353
|
return _toNumber(node.value, options);
|
354
354
|
|
@@ -419,13 +419,13 @@ var createSimplifyConstant = /* #__PURE__ */(0, _factory.factory)(name, dependen
|
|
419
419
|
} else {
|
420
420
|
res = makeNode(_args);
|
421
421
|
}
|
422
|
-
} else if (isAssociative(node)) {
|
423
|
-
_args = allChildren(node);
|
422
|
+
} else if (isAssociative(node, options.context)) {
|
423
|
+
_args = allChildren(node, options.context);
|
424
424
|
_args = _args.map(function (arg) {
|
425
425
|
return foldFraction(arg, options);
|
426
426
|
});
|
427
427
|
|
428
|
-
if (isCommutative(fn)) {
|
428
|
+
if (isCommutative(fn, options.context)) {
|
429
429
|
// commutative binary operator
|
430
430
|
var consts = [];
|
431
431
|
var vars = [];
|