mathjs 10.6.2 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HISTORY.md +74 -1
- package/README.md +1 -1
- package/lib/browser/math.js +2 -41
- package/lib/browser/math.js.LICENSE.txt +43 -0
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/core/create.js +6 -5
- package/lib/cjs/core/function/import.js +4 -14
- package/lib/cjs/core/function/typed.js +54 -12
- 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/dependenciesChainClass.generated.js +3 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesKldivergence.generated.js +3 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesRationalize.generated.js +3 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesResolve.generated.js +3 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesSimplify.generated.js +3 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesSimplifyConstant.generated.js +56 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesSimplifyCore.generated.js +6 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesSqrtm.generated.js +3 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesStd.generated.js +3 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesStdTransform.generated.js +3 -0
- package/lib/cjs/entry/dependenciesAny.generated.js +8 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesChainClass.generated.js +3 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesRationalize.generated.js +3 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesResolve.generated.js +3 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesSimplify.generated.js +3 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesSimplifyConstant.generated.js +50 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesSimplifyCore.generated.js +6 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesStd.generated.js +3 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesStdTransform.generated.js +3 -0
- package/lib/cjs/entry/dependenciesNumber.generated.js +8 -0
- package/lib/cjs/entry/impureFunctionsAny.generated.js +87 -61
- package/lib/cjs/entry/impureFunctionsNumber.generated.js +93 -69
- package/lib/cjs/entry/pureFunctionsAny.generated.js +50 -45
- package/lib/cjs/entry/pureFunctionsNumber.generated.js +22 -19
- package/lib/cjs/expression/Parser.js +1 -1
- package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +8 -5
- package/lib/cjs/expression/embeddedDocs/function/algebra/simplifyConstant.js +15 -0
- package/lib/cjs/expression/embeddedDocs/function/algebra/simplifyCore.js +1 -1
- package/lib/cjs/expression/node/AccessorNode.js +216 -173
- package/lib/cjs/expression/node/ArrayNode.js +206 -160
- package/lib/cjs/expression/node/AssignmentNode.js +321 -270
- package/lib/cjs/expression/node/BlockNode.js +223 -172
- package/lib/cjs/expression/node/ConditionalNode.js +253 -193
- package/lib/cjs/expression/node/ConstantNode.js +216 -171
- package/lib/cjs/expression/node/FunctionAssignmentNode.js +258 -196
- package/lib/cjs/expression/node/FunctionNode.js +456 -416
- package/lib/cjs/expression/node/IndexNode.js +256 -210
- package/lib/cjs/expression/node/Node.js +411 -378
- package/lib/cjs/expression/node/ObjectNode.js +223 -178
- package/lib/cjs/expression/node/OperatorNode.js +474 -397
- package/lib/cjs/expression/node/ParenthesisNode.js +189 -143
- package/lib/cjs/expression/node/RangeNode.js +272 -224
- package/lib/cjs/expression/node/RelationalNode.js +246 -195
- package/lib/cjs/expression/node/SymbolNode.js +219 -172
- package/lib/cjs/expression/node/utils/access.js +1 -1
- package/lib/cjs/expression/node/utils/assign.js +1 -1
- package/lib/cjs/expression/operators.js +117 -23
- package/lib/cjs/expression/parse.js +37 -19
- package/lib/cjs/expression/transform/std.transform.js +3 -1
- package/lib/cjs/factoriesAny.js +8 -0
- package/lib/cjs/factoriesNumber.js +10 -1
- package/lib/cjs/function/algebra/decomposition/qr.js +1 -1
- package/lib/cjs/function/algebra/derivative.js +22 -30
- package/lib/cjs/function/algebra/leafCount.js +0 -3
- package/lib/cjs/function/algebra/rationalize.js +78 -108
- package/lib/cjs/function/algebra/resolve.js +53 -16
- package/lib/cjs/function/algebra/simplify/util.js +1 -1
- package/lib/cjs/function/algebra/simplify.js +87 -114
- package/lib/cjs/function/algebra/{simplify/simplifyConstant.js → simplifyConstant.js} +44 -10
- package/lib/cjs/function/algebra/simplifyCore.js +196 -93
- package/lib/cjs/function/algebra/solver/lsolveAll.js +2 -2
- package/lib/cjs/function/algebra/solver/usolveAll.js +2 -2
- package/lib/cjs/function/algebra/symbolicEqual.js +9 -26
- package/lib/cjs/function/arithmetic/abs.js +7 -14
- package/lib/cjs/function/arithmetic/add.js +26 -70
- package/lib/cjs/function/arithmetic/addScalar.js +17 -9
- package/lib/cjs/function/arithmetic/cbrt.js +7 -11
- package/lib/cjs/function/arithmetic/ceil.js +56 -46
- package/lib/cjs/function/arithmetic/cube.js +5 -10
- package/lib/cjs/function/arithmetic/divide.js +7 -7
- package/lib/cjs/function/arithmetic/divideScalar.js +4 -18
- package/lib/cjs/function/arithmetic/dotDivide.js +22 -65
- package/lib/cjs/function/arithmetic/dotMultiply.js +16 -61
- package/lib/cjs/function/arithmetic/dotPow.js +30 -63
- package/lib/cjs/function/arithmetic/exp.js +8 -12
- package/lib/cjs/function/arithmetic/expm1.js +10 -10
- package/lib/cjs/function/arithmetic/fix.js +33 -27
- package/lib/cjs/function/arithmetic/floor.js +56 -46
- package/lib/cjs/function/arithmetic/gcd.js +27 -68
- package/lib/cjs/function/arithmetic/hypot.js +9 -5
- package/lib/cjs/function/arithmetic/invmod.js +1 -1
- package/lib/cjs/function/arithmetic/lcm.js +27 -68
- package/lib/cjs/function/arithmetic/log.js +10 -12
- package/lib/cjs/function/arithmetic/log10.js +5 -3
- package/lib/cjs/function/arithmetic/log1p.js +11 -7
- package/lib/cjs/function/arithmetic/log2.js +5 -3
- package/lib/cjs/function/arithmetic/mod.js +22 -64
- package/lib/cjs/function/arithmetic/multiply.js +40 -35
- package/lib/cjs/function/arithmetic/multiplyScalar.js +2 -9
- package/lib/cjs/function/arithmetic/norm.js +1 -5
- package/lib/cjs/function/arithmetic/nthRoot.js +80 -92
- package/lib/cjs/function/arithmetic/round.js +56 -42
- package/lib/cjs/function/arithmetic/sign.js +14 -10
- package/lib/cjs/function/arithmetic/sqrt.js +5 -9
- package/lib/cjs/function/arithmetic/square.js +6 -10
- package/lib/cjs/function/arithmetic/subtract.js +44 -100
- package/lib/cjs/function/arithmetic/unaryMinus.js +14 -16
- package/lib/cjs/function/arithmetic/unaryPlus.js +6 -4
- package/lib/cjs/function/bitwise/bitAnd.js +17 -61
- package/lib/cjs/function/bitwise/bitNot.js +5 -3
- package/lib/cjs/function/bitwise/bitOr.js +16 -60
- package/lib/cjs/function/bitwise/bitXor.js +17 -61
- package/lib/cjs/function/bitwise/leftShift.js +68 -81
- package/lib/cjs/function/bitwise/rightArithShift.js +68 -81
- package/lib/cjs/function/bitwise/rightLogShift.js +68 -81
- package/lib/cjs/function/bitwise/useMatrixForArrayScalar.js +36 -0
- package/lib/cjs/function/complex/arg.js +5 -3
- package/lib/cjs/function/complex/conj.js +6 -7
- package/lib/cjs/function/complex/im.js +7 -8
- package/lib/cjs/function/complex/re.js +6 -10
- package/lib/cjs/function/logical/and.js +74 -80
- package/lib/cjs/function/logical/not.js +13 -6
- package/lib/cjs/function/logical/or.js +21 -63
- package/lib/cjs/function/logical/xor.js +21 -63
- package/lib/cjs/function/matrix/diff.js +10 -7
- package/lib/cjs/function/matrix/eigs/complexEigs.js +5 -5
- package/lib/cjs/function/matrix/fft.js +2 -2
- package/lib/cjs/function/matrix/matrixFromColumns.js +1 -1
- package/lib/cjs/function/matrix/matrixFromRows.js +1 -1
- package/lib/cjs/function/matrix/ones.js +2 -1
- package/lib/cjs/function/matrix/sqrtm.js +3 -2
- package/lib/cjs/function/matrix/transpose.js +47 -48
- package/lib/cjs/function/matrix/zeros.js +2 -1
- package/lib/cjs/function/probability/factorial.js +5 -3
- package/lib/cjs/function/probability/gamma.js +38 -40
- package/lib/cjs/function/probability/kldivergence.js +5 -2
- package/lib/cjs/function/probability/lgamma.js +30 -30
- package/lib/cjs/function/probability/util/seededRNG.js +2 -2
- package/lib/cjs/function/relational/compare.js +21 -67
- package/lib/cjs/function/relational/compareNatural.js +59 -54
- package/lib/cjs/function/relational/compareText.js +10 -43
- package/lib/cjs/function/relational/compareUnits.js +24 -0
- package/lib/cjs/function/relational/equal.js +19 -80
- package/lib/cjs/function/relational/equalScalar.js +7 -9
- package/lib/cjs/function/relational/larger.js +21 -67
- package/lib/cjs/function/relational/largerEq.js +21 -67
- package/lib/cjs/function/relational/smaller.js +21 -67
- package/lib/cjs/function/relational/smallerEq.js +21 -67
- package/lib/cjs/function/relational/unequal.js +19 -80
- package/lib/cjs/function/special/erf.js +5 -3
- package/lib/cjs/function/statistics/std.js +11 -2
- package/lib/cjs/function/trigonometry/acos.js +4 -8
- package/lib/cjs/function/trigonometry/acosh.js +2 -7
- package/lib/cjs/function/trigonometry/acot.js +4 -8
- package/lib/cjs/function/trigonometry/acoth.js +4 -8
- package/lib/cjs/function/trigonometry/acsc.js +4 -8
- package/lib/cjs/function/trigonometry/acsch.js +4 -8
- package/lib/cjs/function/trigonometry/asec.js +4 -8
- package/lib/cjs/function/trigonometry/asech.js +4 -8
- package/lib/cjs/function/trigonometry/asin.js +4 -9
- package/lib/cjs/function/trigonometry/asinh.js +4 -9
- package/lib/cjs/function/trigonometry/atan.js +4 -9
- package/lib/cjs/function/trigonometry/atan2.js +24 -62
- package/lib/cjs/function/trigonometry/atanh.js +4 -9
- package/lib/cjs/function/trigonometry/cos.js +11 -20
- package/lib/cjs/function/trigonometry/cosh.js +5 -19
- package/lib/cjs/function/trigonometry/cot.js +9 -15
- package/lib/cjs/function/trigonometry/coth.js +4 -15
- package/lib/cjs/function/trigonometry/csc.js +11 -17
- package/lib/cjs/function/trigonometry/csch.js +4 -15
- package/lib/cjs/function/trigonometry/sec.js +11 -17
- package/lib/cjs/function/trigonometry/sech.js +4 -15
- package/lib/cjs/function/trigonometry/sin.js +11 -21
- package/lib/cjs/function/trigonometry/sinh.js +5 -20
- package/lib/cjs/function/trigonometry/tan.js +11 -21
- package/lib/cjs/function/trigonometry/tanh.js +5 -20
- package/lib/cjs/function/trigonometry/trigUnit.js +24 -0
- package/lib/cjs/function/unit/to.js +7 -41
- package/lib/cjs/function/utils/hasNumericValue.js +4 -0
- package/lib/cjs/function/utils/isInteger.js +5 -3
- package/lib/cjs/function/utils/isNegative.js +10 -6
- package/lib/cjs/function/utils/isNumeric.js +5 -3
- package/lib/cjs/function/utils/isPositive.js +10 -6
- package/lib/cjs/function/utils/isPrime.js +5 -3
- package/lib/cjs/function/utils/isZero.js +10 -6
- package/lib/cjs/function/utils/numeric.js +11 -4
- package/lib/cjs/function/utils/typeOf.js +38 -44
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/plain/bignumber/index.js +1 -1
- package/lib/cjs/type/bignumber/BigNumber.js +2 -2
- package/lib/cjs/type/bignumber/function/bignumber.js +6 -4
- package/lib/cjs/type/boolean.js +7 -5
- package/lib/cjs/type/chain/Chain.js +23 -3
- package/lib/cjs/type/complex/Complex.js +18 -14
- package/lib/cjs/type/complex/function/complex.js +6 -4
- package/lib/cjs/type/fraction/Fraction.js +10 -6
- package/lib/cjs/type/fraction/function/fraction.js +6 -4
- package/lib/cjs/type/matrix/DenseMatrix.js +21 -6
- package/lib/cjs/type/matrix/SparseMatrix.js +12 -2
- package/lib/cjs/type/matrix/utils/{algorithm01.js → matAlgo01xDSid.js} +4 -4
- package/lib/cjs/type/matrix/utils/{algorithm02.js → matAlgo02xDS0.js} +5 -5
- package/lib/cjs/type/matrix/utils/{algorithm03.js → matAlgo03xDSf.js} +5 -5
- package/lib/cjs/type/matrix/utils/{algorithm04.js → matAlgo04xSidSid.js} +7 -7
- package/lib/cjs/type/matrix/utils/{algorithm05.js → matAlgo05xSfSf.js} +5 -5
- package/lib/cjs/type/matrix/utils/{algorithm06.js → matAlgo06xS0S0.js} +5 -5
- package/lib/cjs/type/matrix/utils/{algorithm07.js → matAlgo07xSSf.js} +5 -5
- package/lib/cjs/type/matrix/utils/{algorithm08.js → matAlgo08xS0Sid.js} +6 -6
- package/lib/cjs/type/matrix/utils/{algorithm09.js → matAlgo09xS0Sf.js} +5 -5
- package/lib/cjs/type/matrix/utils/{algorithm10.js → matAlgo10xSids.js} +5 -5
- package/lib/cjs/type/matrix/utils/{algorithm11.js → matAlgo11xS0s.js} +5 -5
- package/lib/cjs/type/matrix/utils/{algorithm12.js → matAlgo12xSfs.js} +5 -5
- package/lib/cjs/type/matrix/utils/{algorithm13.js → matAlgo13xDD.js} +5 -5
- package/lib/cjs/type/matrix/utils/{algorithm14.js → matAlgo14xDs.js} +5 -5
- package/lib/cjs/type/matrix/utils/matrixAlgorithmSuite.js +238 -0
- package/lib/cjs/type/number.js +6 -4
- package/lib/cjs/type/string.js +7 -5
- package/lib/cjs/type/unit/Unit.js +69 -21
- package/lib/cjs/type/unit/function/createUnit.js +2 -1
- package/lib/cjs/type/unit/function/unit.js +9 -3
- 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 +27 -25
- 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 +30 -57
- package/lib/cjs/utils/string.js +3 -3
- package/lib/cjs/version.js +1 -1
- package/lib/esm/core/create.js +2 -1
- package/lib/esm/core/function/import.js +2 -12
- package/lib/esm/core/function/typed.js +47 -11
- package/lib/esm/entry/dependenciesAny/dependenciesChainClass.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesKldivergence.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesRationalize.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesResolve.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesSimplify.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesSimplifyConstant.generated.js +34 -0
- package/lib/esm/entry/dependenciesAny/dependenciesSimplifyCore.generated.js +4 -0
- package/lib/esm/entry/dependenciesAny/dependenciesSqrtm.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesStd.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesStdTransform.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny.generated.js +1 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesChainClass.generated.js +2 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesRationalize.generated.js +2 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesResolve.generated.js +2 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesSimplify.generated.js +2 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesSimplifyConstant.generated.js +30 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesSimplifyCore.generated.js +4 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesStd.generated.js +2 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesStdTransform.generated.js +2 -0
- package/lib/esm/entry/dependenciesNumber.generated.js +1 -0
- package/lib/esm/entry/impureFunctionsAny.generated.js +73 -48
- package/lib/esm/entry/impureFunctionsNumber.generated.js +81 -58
- package/lib/esm/entry/pureFunctionsAny.generated.js +39 -36
- package/lib/esm/entry/pureFunctionsNumber.generated.js +14 -13
- package/lib/esm/expression/embeddedDocs/embeddedDocs.js +2 -0
- package/lib/esm/expression/embeddedDocs/function/algebra/simplifyConstant.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/algebra/simplifyCore.js +1 -1
- package/lib/esm/expression/node/AccessorNode.js +158 -153
- package/lib/esm/expression/node/ArrayNode.js +162 -154
- package/lib/esm/expression/node/AssignmentNode.js +257 -245
- package/lib/esm/expression/node/BlockNode.js +177 -163
- package/lib/esm/expression/node/ConditionalNode.js +197 -174
- package/lib/esm/expression/node/ConstantNode.js +171 -163
- package/lib/esm/expression/node/FunctionAssignmentNode.js +205 -180
- package/lib/esm/expression/node/FunctionNode.js +407 -407
- package/lib/esm/expression/node/IndexNode.js +206 -198
- package/lib/esm/expression/node/Node.js +325 -325
- package/lib/esm/expression/node/ObjectNode.js +166 -157
- package/lib/esm/expression/node/OperatorNode.js +414 -377
- package/lib/esm/expression/node/ParenthesisNode.js +146 -138
- package/lib/esm/expression/node/RangeNode.js +221 -212
- package/lib/esm/expression/node/RelationalNode.js +190 -176
- package/lib/esm/expression/node/SymbolNode.js +161 -152
- package/lib/esm/expression/operators.js +96 -4
- package/lib/esm/expression/parse.js +25 -7
- package/lib/esm/expression/transform/std.transform.js +3 -1
- package/lib/esm/factoriesAny.js +1 -0
- package/lib/esm/factoriesNumber.js +1 -0
- package/lib/esm/function/algebra/derivative.js +22 -30
- package/lib/esm/function/algebra/leafCount.js +0 -3
- package/lib/esm/function/algebra/rationalize.js +83 -114
- package/lib/esm/function/algebra/resolve.js +25 -16
- package/lib/esm/function/algebra/simplify.js +82 -112
- package/lib/esm/function/algebra/{simplify/simplifyConstant.js → simplifyConstant.js} +39 -9
- package/lib/esm/function/algebra/simplifyCore.js +192 -91
- package/lib/esm/function/algebra/symbolicEqual.js +9 -26
- package/lib/esm/function/arithmetic/abs.js +3 -16
- package/lib/esm/function/arithmetic/add.js +21 -65
- package/lib/esm/function/arithmetic/addScalar.js +11 -5
- package/lib/esm/function/arithmetic/cbrt.js +7 -10
- package/lib/esm/function/arithmetic/ceil.js +25 -25
- package/lib/esm/function/arithmetic/cube.js +5 -9
- package/lib/esm/function/arithmetic/divide.js +7 -7
- package/lib/esm/function/arithmetic/divideScalar.js +2 -19
- package/lib/esm/function/arithmetic/dotDivide.js +22 -64
- package/lib/esm/function/arithmetic/dotMultiply.js +16 -60
- package/lib/esm/function/arithmetic/dotPow.js +30 -62
- package/lib/esm/function/arithmetic/exp.js +8 -11
- package/lib/esm/function/arithmetic/expm1.js +10 -9
- package/lib/esm/function/arithmetic/fix.js +17 -17
- package/lib/esm/function/arithmetic/floor.js +25 -25
- package/lib/esm/function/arithmetic/gcd.js +26 -70
- package/lib/esm/function/arithmetic/hypot.js +7 -6
- package/lib/esm/function/arithmetic/lcm.js +26 -70
- package/lib/esm/function/arithmetic/log.js +7 -10
- package/lib/esm/function/arithmetic/log10.js +1 -3
- package/lib/esm/function/arithmetic/log1p.js +4 -6
- package/lib/esm/function/arithmetic/log2.js +1 -3
- package/lib/esm/function/arithmetic/mod.js +21 -62
- package/lib/esm/function/arithmetic/multiply.js +23 -27
- package/lib/esm/function/arithmetic/multiplyScalar.js +2 -13
- package/lib/esm/function/arithmetic/norm.js +0 -4
- package/lib/esm/function/arithmetic/nthRoot.js +38 -73
- package/lib/esm/function/arithmetic/round.js +26 -28
- package/lib/esm/function/arithmetic/sign.js +5 -7
- package/lib/esm/function/arithmetic/sqrt.js +5 -8
- package/lib/esm/function/arithmetic/square.js +6 -9
- package/lib/esm/function/arithmetic/subtract.js +31 -95
- package/lib/esm/function/arithmetic/unaryMinus.js +6 -16
- package/lib/esm/function/arithmetic/unaryPlus.js +2 -4
- package/lib/esm/function/bitwise/bitAnd.js +16 -59
- package/lib/esm/function/bitwise/bitNot.js +1 -3
- package/lib/esm/function/bitwise/bitOr.js +16 -59
- package/lib/esm/function/bitwise/bitXor.js +16 -59
- package/lib/esm/function/bitwise/leftShift.js +38 -60
- package/lib/esm/function/bitwise/rightArithShift.js +38 -60
- package/lib/esm/function/bitwise/rightLogShift.js +38 -60
- package/lib/esm/function/bitwise/useMatrixForArrayScalar.js +13 -0
- package/lib/esm/function/complex/arg.js +1 -3
- package/lib/esm/function/complex/conj.js +3 -12
- package/lib/esm/function/complex/im.js +4 -15
- package/lib/esm/function/complex/re.js +3 -15
- package/lib/esm/function/logical/and.js +35 -57
- package/lib/esm/function/logical/not.js +3 -6
- package/lib/esm/function/logical/or.js +16 -61
- package/lib/esm/function/logical/xor.js +16 -61
- package/lib/esm/function/matrix/diff.js +2 -7
- package/lib/esm/function/matrix/ones.js +2 -1
- package/lib/esm/function/matrix/sqrtm.js +3 -2
- package/lib/esm/function/matrix/transpose.js +47 -50
- package/lib/esm/function/matrix/zeros.js +2 -1
- package/lib/esm/function/probability/factorial.js +1 -3
- package/lib/esm/function/probability/gamma.js +38 -39
- package/lib/esm/function/probability/kldivergence.js +3 -2
- package/lib/esm/function/probability/lgamma.js +29 -29
- package/lib/esm/function/relational/compare.js +21 -67
- package/lib/esm/function/relational/compareNatural.js +54 -49
- package/lib/esm/function/relational/compareText.js +10 -42
- package/lib/esm/function/relational/compareUnits.js +15 -0
- package/lib/esm/function/relational/equal.js +19 -79
- package/lib/esm/function/relational/equalScalar.js +6 -9
- package/lib/esm/function/relational/larger.js +23 -73
- package/lib/esm/function/relational/largerEq.js +23 -73
- package/lib/esm/function/relational/smaller.js +23 -73
- package/lib/esm/function/relational/smallerEq.js +23 -73
- package/lib/esm/function/relational/unequal.js +19 -79
- package/lib/esm/function/special/erf.js +1 -3
- package/lib/esm/function/statistics/std.js +10 -2
- package/lib/esm/function/trigonometry/acos.js +4 -7
- package/lib/esm/function/trigonometry/acosh.js +2 -6
- package/lib/esm/function/trigonometry/acot.js +4 -7
- package/lib/esm/function/trigonometry/acoth.js +4 -7
- package/lib/esm/function/trigonometry/acsc.js +4 -7
- package/lib/esm/function/trigonometry/acsch.js +4 -7
- package/lib/esm/function/trigonometry/asec.js +4 -7
- package/lib/esm/function/trigonometry/asech.js +4 -7
- package/lib/esm/function/trigonometry/asin.js +4 -8
- package/lib/esm/function/trigonometry/asinh.js +4 -8
- package/lib/esm/function/trigonometry/atan.js +4 -8
- package/lib/esm/function/trigonometry/atan2.js +25 -64
- package/lib/esm/function/trigonometry/atanh.js +4 -8
- package/lib/esm/function/trigonometry/cos.js +11 -22
- package/lib/esm/function/trigonometry/cosh.js +5 -20
- package/lib/esm/function/trigonometry/cot.js +10 -20
- package/lib/esm/function/trigonometry/coth.js +6 -20
- package/lib/esm/function/trigonometry/csc.js +12 -22
- package/lib/esm/function/trigonometry/csch.js +6 -20
- package/lib/esm/function/trigonometry/sec.js +12 -22
- package/lib/esm/function/trigonometry/sech.js +6 -20
- package/lib/esm/function/trigonometry/sin.js +11 -23
- package/lib/esm/function/trigonometry/sinh.js +5 -21
- package/lib/esm/function/trigonometry/tan.js +11 -23
- package/lib/esm/function/trigonometry/tanh.js +5 -21
- package/lib/esm/function/trigonometry/trigUnit.js +15 -0
- package/lib/esm/function/unit/to.js +8 -43
- package/lib/esm/function/utils/hasNumericValue.js +2 -0
- package/lib/esm/function/utils/isInteger.js +1 -3
- package/lib/esm/function/utils/isNegative.js +2 -6
- package/lib/esm/function/utils/isNumeric.js +3 -9
- package/lib/esm/function/utils/isPositive.js +2 -6
- package/lib/esm/function/utils/isPrime.js +1 -3
- package/lib/esm/function/utils/isZero.js +2 -6
- package/lib/esm/function/utils/numeric.js +11 -4
- package/lib/esm/function/utils/typeOf.js +38 -44
- package/lib/esm/type/bignumber/function/bignumber.js +1 -3
- package/lib/esm/type/boolean.js +1 -3
- package/lib/esm/type/chain/Chain.js +23 -3
- package/lib/esm/type/complex/Complex.js +4 -0
- package/lib/esm/type/complex/function/complex.js +1 -3
- package/lib/esm/type/fraction/Fraction.js +4 -0
- package/lib/esm/type/fraction/function/fraction.js +1 -3
- package/lib/esm/type/matrix/DenseMatrix.js +15 -1
- package/lib/esm/type/matrix/SparseMatrix.js +9 -0
- package/lib/esm/type/matrix/utils/{algorithm01.js → matAlgo01xDSid.js} +2 -2
- package/lib/esm/type/matrix/utils/{algorithm02.js → matAlgo02xDS0.js} +3 -3
- package/lib/esm/type/matrix/utils/{algorithm03.js → matAlgo03xDSf.js} +3 -3
- package/lib/esm/type/matrix/utils/{algorithm04.js → matAlgo04xSidSid.js} +5 -5
- package/lib/esm/type/matrix/utils/{algorithm05.js → matAlgo05xSfSf.js} +3 -3
- package/lib/esm/type/matrix/utils/{algorithm06.js → matAlgo06xS0S0.js} +3 -3
- package/lib/esm/type/matrix/utils/{algorithm07.js → matAlgo07xSSf.js} +3 -3
- package/lib/esm/type/matrix/utils/{algorithm08.js → matAlgo08xS0Sid.js} +4 -4
- package/lib/esm/type/matrix/utils/{algorithm09.js → matAlgo09xS0Sf.js} +3 -3
- package/lib/esm/type/matrix/utils/{algorithm10.js → matAlgo10xSids.js} +3 -3
- package/lib/esm/type/matrix/utils/{algorithm11.js → matAlgo11xS0s.js} +3 -3
- package/lib/esm/type/matrix/utils/{algorithm12.js → matAlgo12xSfs.js} +3 -3
- package/lib/esm/type/matrix/utils/{algorithm13.js → matAlgo13xDD.js} +3 -3
- package/lib/esm/type/matrix/utils/{algorithm14.js → matAlgo14xDs.js} +3 -3
- package/lib/esm/type/matrix/utils/matrixAlgorithmSuite.js +168 -0
- package/lib/esm/type/number.js +1 -3
- package/lib/esm/type/string.js +1 -3
- package/lib/esm/type/unit/Unit.js +61 -13
- package/lib/esm/type/unit/function/createUnit.js +2 -1
- package/lib/esm/type/unit/function/unit.js +5 -3
- package/lib/esm/utils/is.js +18 -18
- package/lib/esm/utils/snapshot.js +22 -48
- package/lib/esm/version.js +1 -1
- package/package.json +21 -24
- package/types/index.d.ts +202 -181
- package/types/index.ts +264 -57
- package/lib/cjs/utils/polyfills.js +0 -14
- package/lib/esm/utils/polyfills.js +0 -12
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
1
2
|
import { isAccessorNode, isFunctionAssignmentNode, isIndexNode, isNode, isSymbolNode } from '../../utils/is.js';
|
|
2
3
|
import { escape, format } from '../../utils/string.js';
|
|
3
4
|
import { hasOwnProperty } from '../../utils/object.js';
|
|
@@ -14,339 +15,10 @@ export var createFunctionNode = /* #__PURE__ */factory(name, dependencies, _ref
|
|
|
14
15
|
SymbolNode
|
|
15
16
|
} = _ref;
|
|
16
17
|
|
|
17
|
-
/**
|
|
18
|
-
* @constructor FunctionNode
|
|
19
|
-
* @extends {./Node}
|
|
20
|
-
* invoke a list with arguments on a node
|
|
21
|
-
* @param {./Node | string} fn Node resolving with a function on which to invoke
|
|
22
|
-
* the arguments, typically a SymboNode or AccessorNode
|
|
23
|
-
* @param {./Node[]} args
|
|
24
|
-
*/
|
|
25
|
-
function FunctionNode(fn, args) {
|
|
26
|
-
if (!(this instanceof FunctionNode)) {
|
|
27
|
-
throw new SyntaxError('Constructor must be called with the new operator');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (typeof fn === 'string') {
|
|
31
|
-
fn = new SymbolNode(fn);
|
|
32
|
-
} // validate input
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (!isNode(fn)) throw new TypeError('Node expected as parameter "fn"');
|
|
36
|
-
|
|
37
|
-
if (!Array.isArray(args) || !args.every(isNode)) {
|
|
38
|
-
throw new TypeError('Array containing Nodes expected for parameter "args"');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
this.fn = fn;
|
|
42
|
-
this.args = args || []; // readonly property name
|
|
43
|
-
|
|
44
|
-
Object.defineProperty(this, 'name', {
|
|
45
|
-
get: function () {
|
|
46
|
-
return this.fn.name || '';
|
|
47
|
-
}.bind(this),
|
|
48
|
-
set: function set() {
|
|
49
|
-
throw new Error('Cannot assign a new name, name is read-only');
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
FunctionNode.prototype = new Node();
|
|
55
|
-
FunctionNode.prototype.type = 'FunctionNode';
|
|
56
|
-
FunctionNode.prototype.isFunctionNode = true;
|
|
57
18
|
/* format to fixed length */
|
|
58
|
-
|
|
59
19
|
var strin = entity => format(entity, {
|
|
60
20
|
truncate: 78
|
|
61
21
|
});
|
|
62
|
-
/**
|
|
63
|
-
* Compile a node into a JavaScript function.
|
|
64
|
-
* This basically pre-calculates as much as possible and only leaves open
|
|
65
|
-
* calculations which depend on a dynamic scope with variables.
|
|
66
|
-
* @param {Object} math Math.js namespace with functions and constants.
|
|
67
|
-
* @param {Object} argNames An object with argument names as key and `true`
|
|
68
|
-
* as value. Used in the SymbolNode to optimize
|
|
69
|
-
* for arguments from user assigned functions
|
|
70
|
-
* (see FunctionAssignmentNode) or special symbols
|
|
71
|
-
* like `end` (see IndexNode).
|
|
72
|
-
* @return {function} Returns a function which can be called like:
|
|
73
|
-
* evalNode(scope: Object, args: Object, context: *)
|
|
74
|
-
*/
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
FunctionNode.prototype._compile = function (math, argNames) {
|
|
78
|
-
if (!(this instanceof FunctionNode)) {
|
|
79
|
-
throw new TypeError('No valid FunctionNode');
|
|
80
|
-
} // compile arguments
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
var evalArgs = this.args.map(arg => arg._compile(math, argNames));
|
|
84
|
-
|
|
85
|
-
if (isSymbolNode(this.fn)) {
|
|
86
|
-
var _name = this.fn.name;
|
|
87
|
-
|
|
88
|
-
if (!argNames[_name]) {
|
|
89
|
-
// we can statically determine whether the function has an rawArgs property
|
|
90
|
-
var fn = _name in math ? getSafeProperty(math, _name) : undefined;
|
|
91
|
-
var isRaw = typeof fn === 'function' && fn.rawArgs === true;
|
|
92
|
-
|
|
93
|
-
var resolveFn = scope => {
|
|
94
|
-
var value;
|
|
95
|
-
|
|
96
|
-
if (scope.has(_name)) {
|
|
97
|
-
value = scope.get(_name);
|
|
98
|
-
} else if (_name in math) {
|
|
99
|
-
value = getSafeProperty(math, _name);
|
|
100
|
-
} else {
|
|
101
|
-
return FunctionNode.onUndefinedFunction(_name);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (typeof value === 'function') {
|
|
105
|
-
return value;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
throw new TypeError("'".concat(_name, "' is not a function; its value is:\n ").concat(strin(value)));
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
if (isRaw) {
|
|
112
|
-
// pass unevaluated parameters (nodes) to the function
|
|
113
|
-
// "raw" evaluation
|
|
114
|
-
var rawArgs = this.args;
|
|
115
|
-
return function evalFunctionNode(scope, args, context) {
|
|
116
|
-
var fn = resolveFn(scope);
|
|
117
|
-
return fn(rawArgs, math, createSubScope(scope, args), scope);
|
|
118
|
-
};
|
|
119
|
-
} else {
|
|
120
|
-
// "regular" evaluation
|
|
121
|
-
switch (evalArgs.length) {
|
|
122
|
-
case 0:
|
|
123
|
-
return function evalFunctionNode(scope, args, context) {
|
|
124
|
-
var fn = resolveFn(scope);
|
|
125
|
-
return fn();
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
case 1:
|
|
129
|
-
return function evalFunctionNode(scope, args, context) {
|
|
130
|
-
var fn = resolveFn(scope);
|
|
131
|
-
var evalArg0 = evalArgs[0];
|
|
132
|
-
return fn(evalArg0(scope, args, context));
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
case 2:
|
|
136
|
-
return function evalFunctionNode(scope, args, context) {
|
|
137
|
-
var fn = resolveFn(scope);
|
|
138
|
-
var evalArg0 = evalArgs[0];
|
|
139
|
-
var evalArg1 = evalArgs[1];
|
|
140
|
-
return fn(evalArg0(scope, args, context), evalArg1(scope, args, context));
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
default:
|
|
144
|
-
return function evalFunctionNode(scope, args, context) {
|
|
145
|
-
var fn = resolveFn(scope);
|
|
146
|
-
var values = evalArgs.map(evalArg => evalArg(scope, args, context));
|
|
147
|
-
return fn(...values);
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
} else {
|
|
152
|
-
// the function symbol is an argName
|
|
153
|
-
var _rawArgs = this.args;
|
|
154
|
-
return function evalFunctionNode(scope, args, context) {
|
|
155
|
-
var fn = args[_name];
|
|
156
|
-
|
|
157
|
-
if (typeof fn !== 'function') {
|
|
158
|
-
throw new TypeError("Argument '".concat(_name, "' was not a function; received: ").concat(strin(fn)));
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (fn.rawArgs) {
|
|
162
|
-
return fn(_rawArgs, math, createSubScope(scope, args), scope); // "raw" evaluation
|
|
163
|
-
} else {
|
|
164
|
-
var values = evalArgs.map(evalArg => evalArg(scope, args, context));
|
|
165
|
-
return fn.apply(fn, values);
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
} else if (isAccessorNode(this.fn) && isIndexNode(this.fn.index) && this.fn.index.isObjectProperty()) {
|
|
170
|
-
// execute the function with the right context: the object of the AccessorNode
|
|
171
|
-
var evalObject = this.fn.object._compile(math, argNames);
|
|
172
|
-
|
|
173
|
-
var prop = this.fn.index.getObjectProperty();
|
|
174
|
-
var _rawArgs2 = this.args;
|
|
175
|
-
return function evalFunctionNode(scope, args, context) {
|
|
176
|
-
var object = evalObject(scope, args, context);
|
|
177
|
-
validateSafeMethod(object, prop);
|
|
178
|
-
var isRaw = object[prop] && object[prop].rawArgs;
|
|
179
|
-
|
|
180
|
-
if (isRaw) {
|
|
181
|
-
return object[prop](_rawArgs2, math, createSubScope(scope, args), scope); // "raw" evaluation
|
|
182
|
-
} else {
|
|
183
|
-
// "regular" evaluation
|
|
184
|
-
var values = evalArgs.map(evalArg => evalArg(scope, args, context));
|
|
185
|
-
return object[prop].apply(object, values);
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
} else {
|
|
189
|
-
// node.fn.isAccessorNode && !node.fn.index.isObjectProperty()
|
|
190
|
-
// we have to dynamically determine whether the function has a rawArgs property
|
|
191
|
-
var fnExpr = this.fn.toString();
|
|
192
|
-
|
|
193
|
-
var evalFn = this.fn._compile(math, argNames);
|
|
194
|
-
|
|
195
|
-
var _rawArgs3 = this.args;
|
|
196
|
-
return function evalFunctionNode(scope, args, context) {
|
|
197
|
-
var fn = evalFn(scope, args, context);
|
|
198
|
-
|
|
199
|
-
if (typeof fn !== 'function') {
|
|
200
|
-
throw new TypeError("Expression '".concat(fnExpr, "' did not evaluate to a function; value is:") + "\n ".concat(strin(fn)));
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (fn.rawArgs) {
|
|
204
|
-
return fn(_rawArgs3, math, createSubScope(scope, args), scope); // "raw" evaluation
|
|
205
|
-
} else {
|
|
206
|
-
// "regular" evaluation
|
|
207
|
-
var values = evalArgs.map(evalArg => evalArg(scope, args, context));
|
|
208
|
-
return fn.apply(fn, values);
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
/**
|
|
214
|
-
* Execute a callback for each of the child nodes of this node
|
|
215
|
-
* @param {function(child: Node, path: string, parent: Node)} callback
|
|
216
|
-
*/
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
FunctionNode.prototype.forEach = function (callback) {
|
|
220
|
-
callback(this.fn, 'fn', this);
|
|
221
|
-
|
|
222
|
-
for (var i = 0; i < this.args.length; i++) {
|
|
223
|
-
callback(this.args[i], 'args[' + i + ']', this);
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
/**
|
|
227
|
-
* Create a new FunctionNode having it's childs be the results of calling
|
|
228
|
-
* the provided callback function for each of the childs of the original node.
|
|
229
|
-
* @param {function(child: Node, path: string, parent: Node): Node} callback
|
|
230
|
-
* @returns {FunctionNode} Returns a transformed copy of the node
|
|
231
|
-
*/
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
FunctionNode.prototype.map = function (callback) {
|
|
235
|
-
var fn = this._ifNode(callback(this.fn, 'fn', this));
|
|
236
|
-
|
|
237
|
-
var args = [];
|
|
238
|
-
|
|
239
|
-
for (var i = 0; i < this.args.length; i++) {
|
|
240
|
-
args[i] = this._ifNode(callback(this.args[i], 'args[' + i + ']', this));
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return new FunctionNode(fn, args);
|
|
244
|
-
};
|
|
245
|
-
/**
|
|
246
|
-
* Create a clone of this node, a shallow copy
|
|
247
|
-
* @return {FunctionNode}
|
|
248
|
-
*/
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
FunctionNode.prototype.clone = function () {
|
|
252
|
-
return new FunctionNode(this.fn, this.args.slice(0));
|
|
253
|
-
};
|
|
254
|
-
/**
|
|
255
|
-
* Throws an error 'Undefined function {name}'
|
|
256
|
-
* @param {string} name
|
|
257
|
-
*/
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
FunctionNode.onUndefinedFunction = function (name) {
|
|
261
|
-
throw new Error('Undefined function ' + name);
|
|
262
|
-
}; // backup Node's toString function
|
|
263
|
-
// @private
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
var nodeToString = FunctionNode.prototype.toString;
|
|
267
|
-
/**
|
|
268
|
-
* Get string representation. (wrapper function)
|
|
269
|
-
* This overrides parts of Node's toString function.
|
|
270
|
-
* If callback is an object containing callbacks, it
|
|
271
|
-
* calls the correct callback for the current node,
|
|
272
|
-
* otherwise it falls back to calling Node's toString
|
|
273
|
-
* function.
|
|
274
|
-
*
|
|
275
|
-
* @param {Object} options
|
|
276
|
-
* @return {string} str
|
|
277
|
-
* @override
|
|
278
|
-
*/
|
|
279
|
-
|
|
280
|
-
FunctionNode.prototype.toString = function (options) {
|
|
281
|
-
var customString;
|
|
282
|
-
var name = this.fn.toString(options);
|
|
283
|
-
|
|
284
|
-
if (options && typeof options.handler === 'object' && hasOwnProperty(options.handler, name)) {
|
|
285
|
-
// callback is a map of callback functions
|
|
286
|
-
customString = options.handler[name](this, options);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (typeof customString !== 'undefined') {
|
|
290
|
-
return customString;
|
|
291
|
-
} // fall back to Node's toString
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
return nodeToString.call(this, options);
|
|
295
|
-
};
|
|
296
|
-
/**
|
|
297
|
-
* Get string representation
|
|
298
|
-
* @param {Object} options
|
|
299
|
-
* @return {string} str
|
|
300
|
-
*/
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
FunctionNode.prototype._toString = function (options) {
|
|
304
|
-
var args = this.args.map(function (arg) {
|
|
305
|
-
return arg.toString(options);
|
|
306
|
-
});
|
|
307
|
-
var fn = isFunctionAssignmentNode(this.fn) ? '(' + this.fn.toString(options) + ')' : this.fn.toString(options); // format the arguments like "add(2, 4.2)"
|
|
308
|
-
|
|
309
|
-
return fn + '(' + args.join(', ') + ')';
|
|
310
|
-
};
|
|
311
|
-
/**
|
|
312
|
-
* Get a JSON representation of the node
|
|
313
|
-
* @returns {Object}
|
|
314
|
-
*/
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
FunctionNode.prototype.toJSON = function () {
|
|
318
|
-
return {
|
|
319
|
-
mathjs: 'FunctionNode',
|
|
320
|
-
fn: this.fn,
|
|
321
|
-
args: this.args
|
|
322
|
-
};
|
|
323
|
-
};
|
|
324
|
-
/**
|
|
325
|
-
* Instantiate an AssignmentNode from its JSON representation
|
|
326
|
-
* @param {Object} json An object structured like
|
|
327
|
-
* `{"mathjs": "FunctionNode", fn: ..., args: ...}`,
|
|
328
|
-
* where mathjs is optional
|
|
329
|
-
* @returns {FunctionNode}
|
|
330
|
-
*/
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
FunctionNode.fromJSON = function (json) {
|
|
334
|
-
return new FunctionNode(json.fn, json.args);
|
|
335
|
-
};
|
|
336
|
-
/**
|
|
337
|
-
* Get HTML representation
|
|
338
|
-
* @param {Object} options
|
|
339
|
-
* @return {string} str
|
|
340
|
-
*/
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
FunctionNode.prototype.toHTML = function (options) {
|
|
344
|
-
var args = this.args.map(function (arg) {
|
|
345
|
-
return arg.toHTML(options);
|
|
346
|
-
}); // format the arguments like "add(2, 4.2)"
|
|
347
|
-
|
|
348
|
-
return '<span class="math-function">' + escape(this.fn) + '</span><span class="math-paranthesis math-round-parenthesis">(</span>' + args.join('<span class="math-separator">,</span>') + '<span class="math-paranthesis math-round-parenthesis">)</span>';
|
|
349
|
-
};
|
|
350
22
|
/*
|
|
351
23
|
* Expand a LaTeX template
|
|
352
24
|
*
|
|
@@ -427,104 +99,432 @@ export var createFunctionNode = /* #__PURE__ */factory(name, dependencies, _ref
|
|
|
427
99
|
latex += template.slice(inputPos); // append rest of the template
|
|
428
100
|
|
|
429
101
|
return latex;
|
|
430
|
-
}
|
|
431
|
-
// @private
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
var nodeToTex = FunctionNode.prototype.toTex;
|
|
435
|
-
/**
|
|
436
|
-
* Get LaTeX representation. (wrapper function)
|
|
437
|
-
* This overrides parts of Node's toTex function.
|
|
438
|
-
* If callback is an object containing callbacks, it
|
|
439
|
-
* calls the correct callback for the current node,
|
|
440
|
-
* otherwise it falls back to calling Node's toTex
|
|
441
|
-
* function.
|
|
442
|
-
*
|
|
443
|
-
* @param {Object} options
|
|
444
|
-
* @return {string}
|
|
445
|
-
*/
|
|
102
|
+
}
|
|
446
103
|
|
|
447
|
-
FunctionNode
|
|
448
|
-
|
|
104
|
+
class FunctionNode extends Node {
|
|
105
|
+
/**
|
|
106
|
+
* @constructor FunctionNode
|
|
107
|
+
* @extends {./Node}
|
|
108
|
+
* invoke a list with arguments on a node
|
|
109
|
+
* @param {./Node | string} fn
|
|
110
|
+
* Item resolving to a function on which to invoke
|
|
111
|
+
* the arguments, typically a SymboNode or AccessorNode
|
|
112
|
+
* @param {./Node[]} args
|
|
113
|
+
*/
|
|
114
|
+
constructor(fn, args) {
|
|
115
|
+
super();
|
|
449
116
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
}
|
|
117
|
+
if (typeof fn === 'string') {
|
|
118
|
+
fn = new SymbolNode(fn);
|
|
119
|
+
} // validate input
|
|
454
120
|
|
|
455
|
-
if (typeof customTex !== 'undefined') {
|
|
456
|
-
return customTex;
|
|
457
|
-
} // fall back to Node's toTex
|
|
458
121
|
|
|
122
|
+
if (!isNode(fn)) throw new TypeError('Node expected as parameter "fn"');
|
|
459
123
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
* Get LaTeX representation
|
|
464
|
-
* @param {Object} options
|
|
465
|
-
* @return {string} str
|
|
466
|
-
*/
|
|
124
|
+
if (!Array.isArray(args) || !args.every(isNode)) {
|
|
125
|
+
throw new TypeError('Array containing Nodes expected for parameter "args"');
|
|
126
|
+
}
|
|
467
127
|
|
|
128
|
+
this.fn = fn;
|
|
129
|
+
this.args = args || [];
|
|
130
|
+
} // readonly property name
|
|
468
131
|
|
|
469
|
-
FunctionNode.prototype._toTex = function (options) {
|
|
470
|
-
var args = this.args.map(function (arg) {
|
|
471
|
-
// get LaTeX of the arguments
|
|
472
|
-
return arg.toTex(options);
|
|
473
|
-
});
|
|
474
|
-
var latexConverter;
|
|
475
132
|
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
}
|
|
133
|
+
get name() {
|
|
134
|
+
return this.fn.name || '';
|
|
135
|
+
}
|
|
479
136
|
|
|
137
|
+
get type() {
|
|
138
|
+
return name;
|
|
139
|
+
}
|
|
480
140
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
latexConverter = math[this.name].toTex;
|
|
141
|
+
get isFunctionNode() {
|
|
142
|
+
return true;
|
|
484
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Compile a node into a JavaScript function.
|
|
146
|
+
* This basically pre-calculates as much as possible and only leaves open
|
|
147
|
+
* calculations which depend on a dynamic scope with variables.
|
|
148
|
+
* @param {Object} math Math.js namespace with functions and constants.
|
|
149
|
+
* @param {Object} argNames An object with argument names as key and `true`
|
|
150
|
+
* as value. Used in the SymbolNode to optimize
|
|
151
|
+
* for arguments from user assigned functions
|
|
152
|
+
* (see FunctionAssignmentNode) or special symbols
|
|
153
|
+
* like `end` (see IndexNode).
|
|
154
|
+
* @return {function} Returns a function which can be called like:
|
|
155
|
+
* evalNode(scope: Object, args: Object, context: *)
|
|
156
|
+
*/
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
_compile(math, argNames) {
|
|
160
|
+
// compile arguments
|
|
161
|
+
var evalArgs = this.args.map(arg => arg._compile(math, argNames));
|
|
162
|
+
|
|
163
|
+
if (isSymbolNode(this.fn)) {
|
|
164
|
+
var _name = this.fn.name;
|
|
165
|
+
|
|
166
|
+
if (!argNames[_name]) {
|
|
167
|
+
// we can statically determine whether the function
|
|
168
|
+
// has the rawArgs property
|
|
169
|
+
var fn = _name in math ? getSafeProperty(math, _name) : undefined;
|
|
170
|
+
var isRaw = typeof fn === 'function' && fn.rawArgs === true;
|
|
171
|
+
|
|
172
|
+
var resolveFn = scope => {
|
|
173
|
+
var value;
|
|
174
|
+
|
|
175
|
+
if (scope.has(_name)) {
|
|
176
|
+
value = scope.get(_name);
|
|
177
|
+
} else if (_name in math) {
|
|
178
|
+
value = getSafeProperty(math, _name);
|
|
179
|
+
} else {
|
|
180
|
+
return FunctionNode.onUndefinedFunction(_name);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (typeof value === 'function') {
|
|
184
|
+
return value;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
throw new TypeError("'".concat(_name, "' is not a function; its value is:\n ").concat(strin(value)));
|
|
188
|
+
};
|
|
485
189
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
190
|
+
if (isRaw) {
|
|
191
|
+
// pass unevaluated parameters (nodes) to the function
|
|
192
|
+
// "raw" evaluation
|
|
193
|
+
var rawArgs = this.args;
|
|
194
|
+
return function evalFunctionNode(scope, args, context) {
|
|
195
|
+
var fn = resolveFn(scope);
|
|
196
|
+
return fn(rawArgs, math, createSubScope(scope, args), scope);
|
|
197
|
+
};
|
|
198
|
+
} else {
|
|
199
|
+
// "regular" evaluation
|
|
200
|
+
switch (evalArgs.length) {
|
|
201
|
+
case 0:
|
|
202
|
+
return function evalFunctionNode(scope, args, context) {
|
|
203
|
+
var fn = resolveFn(scope);
|
|
204
|
+
return fn();
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
case 1:
|
|
208
|
+
return function evalFunctionNode(scope, args, context) {
|
|
209
|
+
var fn = resolveFn(scope);
|
|
210
|
+
var evalArg0 = evalArgs[0];
|
|
211
|
+
return fn(evalArg0(scope, args, context));
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
case 2:
|
|
215
|
+
return function evalFunctionNode(scope, args, context) {
|
|
216
|
+
var fn = resolveFn(scope);
|
|
217
|
+
var evalArg0 = evalArgs[0];
|
|
218
|
+
var evalArg1 = evalArgs[1];
|
|
219
|
+
return fn(evalArg0(scope, args, context), evalArg1(scope, args, context));
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
default:
|
|
223
|
+
return function evalFunctionNode(scope, args, context) {
|
|
224
|
+
var fn = resolveFn(scope);
|
|
225
|
+
var values = evalArgs.map(evalArg => evalArg(scope, args, context));
|
|
226
|
+
return fn(...values);
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
} else {
|
|
231
|
+
// the function symbol is an argName
|
|
232
|
+
var _rawArgs = this.args;
|
|
233
|
+
return function evalFunctionNode(scope, args, context) {
|
|
234
|
+
var fn = args[_name];
|
|
235
|
+
|
|
236
|
+
if (typeof fn !== 'function') {
|
|
237
|
+
throw new TypeError("Argument '".concat(_name, "' was not a function; received: ").concat(strin(fn)));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (fn.rawArgs) {
|
|
241
|
+
// "Raw" evaluation
|
|
242
|
+
return fn(_rawArgs, math, createSubScope(scope, args), scope);
|
|
243
|
+
} else {
|
|
244
|
+
var values = evalArgs.map(evalArg => evalArg(scope, args, context));
|
|
245
|
+
return fn.apply(fn, values);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
509
248
|
}
|
|
249
|
+
} else if (isAccessorNode(this.fn) && isIndexNode(this.fn.index) && this.fn.index.isObjectProperty()) {
|
|
250
|
+
// execute the function with the right context:
|
|
251
|
+
// the object of the AccessorNode
|
|
252
|
+
var evalObject = this.fn.object._compile(math, argNames);
|
|
253
|
+
|
|
254
|
+
var prop = this.fn.index.getObjectProperty();
|
|
255
|
+
var _rawArgs2 = this.args;
|
|
256
|
+
return function evalFunctionNode(scope, args, context) {
|
|
257
|
+
var object = evalObject(scope, args, context);
|
|
258
|
+
validateSafeMethod(object, prop);
|
|
259
|
+
var isRaw = object[prop] && object[prop].rawArgs;
|
|
260
|
+
|
|
261
|
+
if (isRaw) {
|
|
262
|
+
// "Raw" evaluation
|
|
263
|
+
return object[prop](_rawArgs2, math, createSubScope(scope, args), scope);
|
|
264
|
+
} else {
|
|
265
|
+
// "regular" evaluation
|
|
266
|
+
var values = evalArgs.map(evalArg => evalArg(scope, args, context));
|
|
267
|
+
return object[prop].apply(object, values);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
} else {
|
|
271
|
+
// node.fn.isAccessorNode && !node.fn.index.isObjectProperty()
|
|
272
|
+
// we have to dynamically determine whether the function has the
|
|
273
|
+
// rawArgs property
|
|
274
|
+
var fnExpr = this.fn.toString();
|
|
275
|
+
|
|
276
|
+
var evalFn = this.fn._compile(math, argNames);
|
|
277
|
+
|
|
278
|
+
var _rawArgs3 = this.args;
|
|
279
|
+
return function evalFunctionNode(scope, args, context) {
|
|
280
|
+
var fn = evalFn(scope, args, context);
|
|
281
|
+
|
|
282
|
+
if (typeof fn !== 'function') {
|
|
283
|
+
throw new TypeError("Expression '".concat(fnExpr, "' did not evaluate to a function; value is:") + "\n ".concat(strin(fn)));
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (fn.rawArgs) {
|
|
287
|
+
// "Raw" evaluation
|
|
288
|
+
return fn(_rawArgs3, math, createSubScope(scope, args), scope);
|
|
289
|
+
} else {
|
|
290
|
+
// "regular" evaluation
|
|
291
|
+
var values = evalArgs.map(evalArg => evalArg(scope, args, context));
|
|
292
|
+
return fn.apply(fn, values);
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Execute a callback for each of the child nodes of this node
|
|
299
|
+
* @param {function(child: Node, path: string, parent: Node)} callback
|
|
300
|
+
*/
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
forEach(callback) {
|
|
304
|
+
callback(this.fn, 'fn', this);
|
|
305
|
+
|
|
306
|
+
for (var i = 0; i < this.args.length; i++) {
|
|
307
|
+
callback(this.args[i], 'args[' + i + ']', this);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Create a new FunctionNode whose children are the results of calling
|
|
312
|
+
* the provided callback function for each child of the original node.
|
|
313
|
+
* @param {function(child: Node, path: string, parent: Node): Node} callback
|
|
314
|
+
* @returns {FunctionNode} Returns a transformed copy of the node
|
|
315
|
+
*/
|
|
316
|
+
|
|
510
317
|
|
|
318
|
+
map(callback) {
|
|
319
|
+
var fn = this._ifNode(callback(this.fn, 'fn', this));
|
|
320
|
+
|
|
321
|
+
var args = [];
|
|
322
|
+
|
|
323
|
+
for (var i = 0; i < this.args.length; i++) {
|
|
324
|
+
args[i] = this._ifNode(callback(this.args[i], 'args[' + i + ']', this));
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return new FunctionNode(fn, args);
|
|
511
328
|
}
|
|
329
|
+
/**
|
|
330
|
+
* Create a clone of this node, a shallow copy
|
|
331
|
+
* @return {FunctionNode}
|
|
332
|
+
*/
|
|
333
|
+
|
|
512
334
|
|
|
513
|
-
|
|
514
|
-
return
|
|
335
|
+
clone() {
|
|
336
|
+
return new FunctionNode(this.fn, this.args.slice(0));
|
|
515
337
|
}
|
|
338
|
+
/**
|
|
339
|
+
* Throws an error 'Undefined function {name}'
|
|
340
|
+
* @param {string} name
|
|
341
|
+
*/
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Get string representation. (wrapper function)
|
|
346
|
+
* This overrides parts of Node's toString function.
|
|
347
|
+
* If callback is an object containing callbacks, it
|
|
348
|
+
* calls the correct callback for the current node,
|
|
349
|
+
* otherwise it falls back to calling Node's toString
|
|
350
|
+
* function.
|
|
351
|
+
*
|
|
352
|
+
* @param {Object} options
|
|
353
|
+
* @return {string} str
|
|
354
|
+
* @override
|
|
355
|
+
*/
|
|
356
|
+
toString(options) {
|
|
357
|
+
var customString;
|
|
358
|
+
var name = this.fn.toString(options);
|
|
359
|
+
|
|
360
|
+
if (options && typeof options.handler === 'object' && hasOwnProperty(options.handler, name)) {
|
|
361
|
+
// callback is a map of callback functions
|
|
362
|
+
customString = options.handler[name](this, options);
|
|
363
|
+
}
|
|
516
364
|
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
* Get identifier.
|
|
521
|
-
* @return {string}
|
|
522
|
-
*/
|
|
365
|
+
if (typeof customString !== 'undefined') {
|
|
366
|
+
return customString;
|
|
367
|
+
} // fall back to Node's toString
|
|
523
368
|
|
|
524
369
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
370
|
+
return super.toString(options);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Get string representation
|
|
374
|
+
* @param {Object} options
|
|
375
|
+
* @return {string} str
|
|
376
|
+
*/
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
_toString(options) {
|
|
380
|
+
var args = this.args.map(function (arg) {
|
|
381
|
+
return arg.toString(options);
|
|
382
|
+
});
|
|
383
|
+
var fn = isFunctionAssignmentNode(this.fn) ? '(' + this.fn.toString(options) + ')' : this.fn.toString(options); // format the arguments like "add(2, 4.2)"
|
|
384
|
+
|
|
385
|
+
return fn + '(' + args.join(', ') + ')';
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Get a JSON representation of the node
|
|
389
|
+
* @returns {Object}
|
|
390
|
+
*/
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
toJSON() {
|
|
394
|
+
return {
|
|
395
|
+
mathjs: name,
|
|
396
|
+
fn: this.fn,
|
|
397
|
+
args: this.args
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Instantiate an AssignmentNode from its JSON representation
|
|
402
|
+
* @param {Object} json An object structured like
|
|
403
|
+
* `{"mathjs": "FunctionNode", fn: ..., args: ...}`,
|
|
404
|
+
* where mathjs is optional
|
|
405
|
+
* @returns {FunctionNode}
|
|
406
|
+
*/
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Get HTML representation
|
|
411
|
+
* @param {Object} options
|
|
412
|
+
* @return {string} str
|
|
413
|
+
*/
|
|
414
|
+
toHTML(options) {
|
|
415
|
+
var args = this.args.map(function (arg) {
|
|
416
|
+
return arg.toHTML(options);
|
|
417
|
+
}); // format the arguments like "add(2, 4.2)"
|
|
418
|
+
|
|
419
|
+
return '<span class="math-function">' + escape(this.fn) + '</span><span class="math-paranthesis math-round-parenthesis">(</span>' + args.join('<span class="math-separator">,</span>') + '<span class="math-paranthesis math-round-parenthesis">)</span>';
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Get LaTeX representation. (wrapper function)
|
|
423
|
+
* This overrides parts of Node's toTex function.
|
|
424
|
+
* If callback is an object containing callbacks, it
|
|
425
|
+
* calls the correct callback for the current node,
|
|
426
|
+
* otherwise it falls back to calling Node's toTex
|
|
427
|
+
* function.
|
|
428
|
+
*
|
|
429
|
+
* @param {Object} options
|
|
430
|
+
* @return {string}
|
|
431
|
+
*/
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
toTex(options) {
|
|
435
|
+
var customTex;
|
|
436
|
+
|
|
437
|
+
if (options && typeof options.handler === 'object' && hasOwnProperty(options.handler, this.name)) {
|
|
438
|
+
// callback is a map of callback functions
|
|
439
|
+
customTex = options.handler[this.name](this, options);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
if (typeof customTex !== 'undefined') {
|
|
443
|
+
return customTex;
|
|
444
|
+
} // fall back to Node's toTex
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
return super.toTex(options);
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Get LaTeX representation
|
|
451
|
+
* @param {Object} options
|
|
452
|
+
* @return {string} str
|
|
453
|
+
*/
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
_toTex(options) {
|
|
457
|
+
var args = this.args.map(function (arg) {
|
|
458
|
+
// get LaTeX of the arguments
|
|
459
|
+
return arg.toTex(options);
|
|
460
|
+
});
|
|
461
|
+
var latexConverter;
|
|
462
|
+
|
|
463
|
+
if (latexFunctions[this.name]) {
|
|
464
|
+
latexConverter = latexFunctions[this.name];
|
|
465
|
+
} // toTex property on the function itself
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
if (math[this.name] && (typeof math[this.name].toTex === 'function' || typeof math[this.name].toTex === 'object' || typeof math[this.name].toTex === 'string')) {
|
|
469
|
+
// .toTex is a callback function
|
|
470
|
+
latexConverter = math[this.name].toTex;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
var customToTex;
|
|
474
|
+
|
|
475
|
+
switch (typeof latexConverter) {
|
|
476
|
+
case 'function':
|
|
477
|
+
// a callback function
|
|
478
|
+
customToTex = latexConverter(this, options);
|
|
479
|
+
break;
|
|
480
|
+
|
|
481
|
+
case 'string':
|
|
482
|
+
// a template string
|
|
483
|
+
customToTex = expandTemplate(latexConverter, this, options);
|
|
484
|
+
break;
|
|
485
|
+
|
|
486
|
+
case 'object':
|
|
487
|
+
// an object with different "converters" for different
|
|
488
|
+
// numbers of arguments
|
|
489
|
+
switch (typeof latexConverter[args.length]) {
|
|
490
|
+
case 'function':
|
|
491
|
+
customToTex = latexConverter[args.length](this, options);
|
|
492
|
+
break;
|
|
493
|
+
|
|
494
|
+
case 'string':
|
|
495
|
+
customToTex = expandTemplate(latexConverter[args.length], this, options);
|
|
496
|
+
break;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
if (typeof customToTex !== 'undefined') {
|
|
502
|
+
return customToTex;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
return expandTemplate(defaultTemplate, this, options);
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Get identifier.
|
|
509
|
+
* @return {string}
|
|
510
|
+
*/
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
getIdentifier() {
|
|
514
|
+
return this.type + ':' + this.name;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
_defineProperty(FunctionNode, "name", name);
|
|
520
|
+
|
|
521
|
+
_defineProperty(FunctionNode, "onUndefinedFunction", function (name) {
|
|
522
|
+
throw new Error('Undefined function ' + name);
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
_defineProperty(FunctionNode, "fromJSON", function (json) {
|
|
526
|
+
return new FunctionNode(json.fn, json.args);
|
|
527
|
+
});
|
|
528
528
|
|
|
529
529
|
return FunctionNode;
|
|
530
530
|
}, {
|