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,10 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
8
|
exports.createOperatorNode = void 0;
|
|
7
9
|
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
|
|
14
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
|
+
|
|
16
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
17
|
+
|
|
18
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
19
|
+
|
|
20
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
21
|
+
|
|
8
22
|
var _is = require("../../utils/is.js");
|
|
9
23
|
|
|
10
24
|
var _array = require("../../utils/array.js");
|
|
@@ -19,155 +33,39 @@ var _latex = require("../../utils/latex.js");
|
|
|
19
33
|
|
|
20
34
|
var _factory = require("../../utils/factory.js");
|
|
21
35
|
|
|
36
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
37
|
+
|
|
38
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
39
|
+
|
|
22
40
|
var name = 'OperatorNode';
|
|
23
41
|
var dependencies = ['Node'];
|
|
24
42
|
var createOperatorNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
|
|
25
43
|
var Node = _ref.Node;
|
|
26
44
|
|
|
27
45
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* @
|
|
33
|
-
* @param {string} fn Function name, for example 'add'
|
|
34
|
-
* @param {Node[]} args Operator arguments
|
|
35
|
-
* @param {boolean} [implicit] Is this an implicit multiplication?
|
|
36
|
-
* @param {boolean} [isPercentage] Is this an percentage Operation?
|
|
37
|
-
*/
|
|
38
|
-
function OperatorNode(op, fn, args, implicit, isPercentage) {
|
|
39
|
-
if (!(this instanceof OperatorNode)) {
|
|
40
|
-
throw new SyntaxError('Constructor must be called with the new operator');
|
|
41
|
-
} // validate input
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (typeof op !== 'string') {
|
|
45
|
-
throw new TypeError('string expected for parameter "op"');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (typeof fn !== 'string') {
|
|
49
|
-
throw new TypeError('string expected for parameter "fn"');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (!Array.isArray(args) || !args.every(_is.isNode)) {
|
|
53
|
-
throw new TypeError('Array containing Nodes expected for parameter "args"');
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
this.implicit = implicit === true;
|
|
57
|
-
this.isPercentage = isPercentage === true;
|
|
58
|
-
this.op = op;
|
|
59
|
-
this.fn = fn;
|
|
60
|
-
this.args = args || [];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
OperatorNode.prototype = new Node();
|
|
64
|
-
OperatorNode.prototype.type = 'OperatorNode';
|
|
65
|
-
OperatorNode.prototype.isOperatorNode = true;
|
|
66
|
-
/**
|
|
67
|
-
* Compile a node into a JavaScript function.
|
|
68
|
-
* This basically pre-calculates as much as possible and only leaves open
|
|
69
|
-
* calculations which depend on a dynamic scope with variables.
|
|
70
|
-
* @param {Object} math Math.js namespace with functions and constants.
|
|
71
|
-
* @param {Object} argNames An object with argument names as key and `true`
|
|
72
|
-
* as value. Used in the SymbolNode to optimize
|
|
73
|
-
* for arguments from user assigned functions
|
|
74
|
-
* (see FunctionAssignmentNode) or special symbols
|
|
75
|
-
* like `end` (see IndexNode).
|
|
76
|
-
* @return {function} Returns a function which can be called like:
|
|
77
|
-
* evalNode(scope: Object, args: Object, context: *)
|
|
46
|
+
* Returns true if the expression starts with a constant, under
|
|
47
|
+
* the current parenthesization:
|
|
48
|
+
* @param {Node} expression
|
|
49
|
+
* @param {string} parenthesis
|
|
50
|
+
* @return {boolean}
|
|
78
51
|
*/
|
|
52
|
+
function startsWithConstant(expr, parenthesis) {
|
|
53
|
+
var curNode = expr;
|
|
79
54
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (!math[this.fn]) {
|
|
84
|
-
throw new Error('Function ' + this.fn + ' missing in provided namespace "math"');
|
|
85
|
-
} else {
|
|
86
|
-
throw new Error('No access to function "' + this.fn + '"');
|
|
55
|
+
if (parenthesis === 'auto') {
|
|
56
|
+
while ((0, _is.isParenthesisNode)(curNode)) {
|
|
57
|
+
curNode = curNode.content;
|
|
87
58
|
}
|
|
88
59
|
}
|
|
89
60
|
|
|
90
|
-
|
|
91
|
-
var evalArgs = (0, _array.map)(this.args, function (arg) {
|
|
92
|
-
return arg._compile(math, argNames);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
if (evalArgs.length === 1) {
|
|
96
|
-
var evalArg0 = evalArgs[0];
|
|
97
|
-
return function evalOperatorNode(scope, args, context) {
|
|
98
|
-
return fn(evalArg0(scope, args, context));
|
|
99
|
-
};
|
|
100
|
-
} else if (evalArgs.length === 2) {
|
|
101
|
-
var _evalArg = evalArgs[0];
|
|
102
|
-
var evalArg1 = evalArgs[1];
|
|
103
|
-
return function evalOperatorNode(scope, args, context) {
|
|
104
|
-
return fn(_evalArg(scope, args, context), evalArg1(scope, args, context));
|
|
105
|
-
};
|
|
106
|
-
} else {
|
|
107
|
-
return function evalOperatorNode(scope, args, context) {
|
|
108
|
-
return fn.apply(null, (0, _array.map)(evalArgs, function (evalArg) {
|
|
109
|
-
return evalArg(scope, args, context);
|
|
110
|
-
}));
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* Execute a callback for each of the child nodes of this node
|
|
116
|
-
* @param {function(child: Node, path: string, parent: Node)} callback
|
|
117
|
-
*/
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
OperatorNode.prototype.forEach = function (callback) {
|
|
121
|
-
for (var i = 0; i < this.args.length; i++) {
|
|
122
|
-
callback(this.args[i], 'args[' + i + ']', this);
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
/**
|
|
126
|
-
* Create a new OperatorNode having it's childs be the results of calling
|
|
127
|
-
* the provided callback function for each of the childs of the original node.
|
|
128
|
-
* @param {function(child: Node, path: string, parent: Node): Node} callback
|
|
129
|
-
* @returns {OperatorNode} Returns a transformed copy of the node
|
|
130
|
-
*/
|
|
131
|
-
|
|
61
|
+
if ((0, _is.isConstantNode)(curNode)) return true;
|
|
132
62
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
for (var i = 0; i < this.args.length; i++) {
|
|
137
|
-
args[i] = this._ifNode(callback(this.args[i], 'args[' + i + ']', this));
|
|
63
|
+
if ((0, _is.isOperatorNode)(curNode)) {
|
|
64
|
+
return startsWithConstant(curNode.args[0], parenthesis);
|
|
138
65
|
}
|
|
139
66
|
|
|
140
|
-
return
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Create a clone of this node, a shallow copy
|
|
144
|
-
* @return {OperatorNode}
|
|
145
|
-
*/
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
OperatorNode.prototype.clone = function () {
|
|
149
|
-
return new OperatorNode(this.op, this.fn, this.args.slice(0), this.implicit, this.isPercentage);
|
|
150
|
-
};
|
|
151
|
-
/**
|
|
152
|
-
* Check whether this is an unary OperatorNode:
|
|
153
|
-
* has exactly one argument, like `-a`.
|
|
154
|
-
* @return {boolean} Returns true when an unary operator node, false otherwise.
|
|
155
|
-
*/
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
OperatorNode.prototype.isUnary = function () {
|
|
159
|
-
return this.args.length === 1;
|
|
160
|
-
};
|
|
161
|
-
/**
|
|
162
|
-
* Check whether this is a binary OperatorNode:
|
|
163
|
-
* has exactly two arguments, like `a + b`.
|
|
164
|
-
* @return {boolean} Returns true when a binary operator node, false otherwise.
|
|
165
|
-
*/
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
OperatorNode.prototype.isBinary = function () {
|
|
169
|
-
return this.args.length === 2;
|
|
170
|
-
};
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
171
69
|
/**
|
|
172
70
|
* Calculate which parentheses are necessary. Gets an OperatorNode
|
|
173
71
|
* (which is the root of the tree) and an Array of Nodes
|
|
@@ -185,7 +83,7 @@ var createOperatorNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
|
185
83
|
|
|
186
84
|
function calculateNecessaryParentheses(root, parenthesis, implicit, args, latex) {
|
|
187
85
|
// precedence of the root OperatorNode
|
|
188
|
-
var precedence = (0, _operators.getPrecedence)(root, parenthesis);
|
|
86
|
+
var precedence = (0, _operators.getPrecedence)(root, parenthesis, implicit);
|
|
189
87
|
var associativity = (0, _operators.getAssociativity)(root, parenthesis);
|
|
190
88
|
|
|
191
89
|
if (parenthesis === 'all' || args.length > 2 && root.getIdentifier() !== 'OperatorNode:add' && root.getIdentifier() !== 'OperatorNode:multiply') {
|
|
@@ -215,7 +113,7 @@ var createOperatorNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
|
215
113
|
// unary operators
|
|
216
114
|
{
|
|
217
115
|
// precedence of the operand
|
|
218
|
-
var operandPrecedence = (0, _operators.getPrecedence)(args[0], parenthesis); // handle special cases for LaTeX, where some of the parentheses aren't needed
|
|
116
|
+
var operandPrecedence = (0, _operators.getPrecedence)(args[0], parenthesis, implicit, root); // handle special cases for LaTeX, where some of the parentheses aren't needed
|
|
219
117
|
|
|
220
118
|
if (latex && operandPrecedence !== null) {
|
|
221
119
|
var operandIdentifier;
|
|
@@ -264,7 +162,7 @@ var createOperatorNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
|
264
162
|
var lhsParens; // left hand side needs parenthesis?
|
|
265
163
|
// precedence of the left hand side
|
|
266
164
|
|
|
267
|
-
var lhsPrecedence = (0, _operators.getPrecedence)(args[0], parenthesis); // is the root node associative with the left hand side
|
|
165
|
+
var lhsPrecedence = (0, _operators.getPrecedence)(args[0], parenthesis, implicit, root); // is the root node associative with the left hand side
|
|
268
166
|
|
|
269
167
|
var assocWithLhs = (0, _operators.isAssociativeWith)(root, args[0], parenthesis);
|
|
270
168
|
|
|
@@ -287,7 +185,7 @@ var createOperatorNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
|
287
185
|
var rhsParens; // right hand side needs parenthesis?
|
|
288
186
|
// precedence of the right hand side
|
|
289
187
|
|
|
290
|
-
var rhsPrecedence = (0, _operators.getPrecedence)(args[1], parenthesis); // is the root node associative with the right hand side?
|
|
188
|
+
var rhsPrecedence = (0, _operators.getPrecedence)(args[1], parenthesis, implicit, root); // is the root node associative with the right hand side?
|
|
291
189
|
|
|
292
190
|
var assocWithRhs = (0, _operators.isAssociativeWith)(root, args[1], parenthesis);
|
|
293
191
|
|
|
@@ -353,7 +251,7 @@ var createOperatorNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
|
353
251
|
default:
|
|
354
252
|
if (root.getIdentifier() === 'OperatorNode:add' || root.getIdentifier() === 'OperatorNode:multiply') {
|
|
355
253
|
result = args.map(function (arg) {
|
|
356
|
-
var argPrecedence = (0, _operators.getPrecedence)(arg, parenthesis);
|
|
254
|
+
var argPrecedence = (0, _operators.getPrecedence)(arg, parenthesis, implicit, root);
|
|
357
255
|
var assocWithArg = (0, _operators.isAssociativeWith)(root, arg, parenthesis);
|
|
358
256
|
var argAssociativity = (0, _operators.getAssociativity)(arg, parenthesis);
|
|
359
257
|
|
|
@@ -371,328 +269,507 @@ var createOperatorNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
|
371
269
|
}
|
|
372
270
|
|
|
373
271
|
break;
|
|
374
|
-
} //
|
|
375
|
-
//
|
|
376
|
-
//
|
|
377
|
-
|
|
272
|
+
} // Handles an edge case of parentheses with implicit multiplication
|
|
273
|
+
// of ConstantNode.
|
|
274
|
+
// In that case, parenthesize ConstantNodes that follow an unparenthesized
|
|
275
|
+
// expression, even though they normally wouldn't be printed.
|
|
378
276
|
|
|
379
|
-
if (args.length >= 2 && root.getIdentifier() === 'OperatorNode:multiply' && root.implicit && parenthesis === 'auto' && implicit === 'hide') {
|
|
380
|
-
result = args.map(function (arg, index) {
|
|
381
|
-
var isParenthesisNode = arg.getIdentifier() === 'ParenthesisNode';
|
|
382
277
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
278
|
+
if (args.length >= 2 && root.getIdentifier() === 'OperatorNode:multiply' && root.implicit && parenthesis !== 'all' && implicit === 'hide') {
|
|
279
|
+
for (var i = 1; i < result.length; ++i) {
|
|
280
|
+
if (startsWithConstant(args[i], parenthesis) && !result[i - 1] && (parenthesis !== 'keep' || !(0, _is.isParenthesisNode)(args[i - 1]))) {
|
|
281
|
+
result[i] = true;
|
|
386
282
|
}
|
|
387
|
-
|
|
388
|
-
return false;
|
|
389
|
-
});
|
|
283
|
+
}
|
|
390
284
|
}
|
|
391
285
|
|
|
392
286
|
return result;
|
|
393
287
|
}
|
|
394
|
-
/**
|
|
395
|
-
* Get string representation.
|
|
396
|
-
* @param {Object} options
|
|
397
|
-
* @return {string} str
|
|
398
|
-
*/
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
OperatorNode.prototype._toString = function (options) {
|
|
402
|
-
var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
|
|
403
|
-
var implicit = options && options.implicit ? options.implicit : 'hide';
|
|
404
|
-
var args = this.args;
|
|
405
|
-
var parens = calculateNecessaryParentheses(this, parenthesis, implicit, args, false);
|
|
406
288
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
var rhs = args[1].toString(options); // right hand side
|
|
433
|
-
|
|
434
|
-
if (parens[0]) {
|
|
435
|
-
// left hand side in parenthesis?
|
|
436
|
-
lhs = '(' + lhs + ')';
|
|
289
|
+
var OperatorNode = /*#__PURE__*/function (_Node) {
|
|
290
|
+
(0, _inherits2["default"])(OperatorNode, _Node);
|
|
291
|
+
|
|
292
|
+
var _super = _createSuper(OperatorNode);
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* @constructor OperatorNode
|
|
296
|
+
* @extends {Node}
|
|
297
|
+
* An operator with two arguments, like 2+3
|
|
298
|
+
*
|
|
299
|
+
* @param {string} op Operator name, for example '+'
|
|
300
|
+
* @param {string} fn Function name, for example 'add'
|
|
301
|
+
* @param {Node[]} args Operator arguments
|
|
302
|
+
* @param {boolean} [implicit] Is this an implicit multiplication?
|
|
303
|
+
* @param {boolean} [isPercentage] Is this an percentage Operation?
|
|
304
|
+
*/
|
|
305
|
+
function OperatorNode(op, fn, args, implicit, isPercentage) {
|
|
306
|
+
var _this;
|
|
307
|
+
|
|
308
|
+
(0, _classCallCheck2["default"])(this, OperatorNode);
|
|
309
|
+
_this = _super.call(this); // validate input
|
|
310
|
+
|
|
311
|
+
if (typeof op !== 'string') {
|
|
312
|
+
throw new TypeError('string expected for parameter "op"');
|
|
437
313
|
}
|
|
438
314
|
|
|
439
|
-
if (
|
|
440
|
-
|
|
441
|
-
rhs = '(' + rhs + ')';
|
|
315
|
+
if (typeof fn !== 'string') {
|
|
316
|
+
throw new TypeError('string expected for parameter "fn"');
|
|
442
317
|
}
|
|
443
318
|
|
|
444
|
-
if (
|
|
445
|
-
|
|
319
|
+
if (!Array.isArray(args) || !args.every(_is.isNode)) {
|
|
320
|
+
throw new TypeError('Array containing Nodes expected for parameter "args"');
|
|
446
321
|
}
|
|
447
322
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
323
|
+
_this.implicit = implicit === true;
|
|
324
|
+
_this.isPercentage = isPercentage === true;
|
|
325
|
+
_this.op = op;
|
|
326
|
+
_this.fn = fn;
|
|
327
|
+
_this.args = args || [];
|
|
328
|
+
return _this;
|
|
329
|
+
}
|
|
452
330
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
331
|
+
(0, _createClass2["default"])(OperatorNode, [{
|
|
332
|
+
key: "type",
|
|
333
|
+
get: function get() {
|
|
334
|
+
return name;
|
|
335
|
+
}
|
|
336
|
+
}, {
|
|
337
|
+
key: "isOperatorNode",
|
|
338
|
+
get: function get() {
|
|
339
|
+
return true;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Compile a node into a JavaScript function.
|
|
343
|
+
* This basically pre-calculates as much as possible and only leaves open
|
|
344
|
+
* calculations which depend on a dynamic scope with variables.
|
|
345
|
+
* @param {Object} math Math.js namespace with functions and constants.
|
|
346
|
+
* @param {Object} argNames An object with argument names as key and `true`
|
|
347
|
+
* as value. Used in the SymbolNode to optimize
|
|
348
|
+
* for arguments from user assigned functions
|
|
349
|
+
* (see FunctionAssignmentNode) or special symbols
|
|
350
|
+
* like `end` (see IndexNode).
|
|
351
|
+
* @return {function} Returns a function which can be called like:
|
|
352
|
+
* evalNode(scope: Object, args: Object, context: *)
|
|
353
|
+
*/
|
|
354
|
+
|
|
355
|
+
}, {
|
|
356
|
+
key: "_compile",
|
|
357
|
+
value: function _compile(math, argNames) {
|
|
358
|
+
// validate fn
|
|
359
|
+
if (typeof this.fn !== 'string' || !(0, _customs.isSafeMethod)(math, this.fn)) {
|
|
360
|
+
if (!math[this.fn]) {
|
|
361
|
+
throw new Error('Function ' + this.fn + ' missing in provided namespace "math"');
|
|
362
|
+
} else {
|
|
363
|
+
throw new Error('No access to function "' + this.fn + '"');
|
|
364
|
+
}
|
|
456
365
|
}
|
|
457
366
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
367
|
+
var fn = (0, _customs.getSafeProperty)(math, this.fn);
|
|
368
|
+
var evalArgs = (0, _array.map)(this.args, function (arg) {
|
|
369
|
+
return arg._compile(math, argNames);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
if (evalArgs.length === 1) {
|
|
373
|
+
var evalArg0 = evalArgs[0];
|
|
374
|
+
return function evalOperatorNode(scope, args, context) {
|
|
375
|
+
return fn(evalArg0(scope, args, context));
|
|
376
|
+
};
|
|
377
|
+
} else if (evalArgs.length === 2) {
|
|
378
|
+
var _evalArg = evalArgs[0];
|
|
379
|
+
var evalArg1 = evalArgs[1];
|
|
380
|
+
return function evalOperatorNode(scope, args, context) {
|
|
381
|
+
return fn(_evalArg(scope, args, context), evalArg1(scope, args, context));
|
|
382
|
+
};
|
|
383
|
+
} else {
|
|
384
|
+
return function evalOperatorNode(scope, args, context) {
|
|
385
|
+
return fn.apply(null, (0, _array.map)(evalArgs, function (evalArg) {
|
|
386
|
+
return evalArg(scope, args, context);
|
|
387
|
+
}));
|
|
388
|
+
};
|
|
389
|
+
}
|
|
463
390
|
}
|
|
391
|
+
/**
|
|
392
|
+
* Execute a callback for each of the child nodes of this node
|
|
393
|
+
* @param {function(child: Node, path: string, parent: Node)} callback
|
|
394
|
+
*/
|
|
395
|
+
|
|
396
|
+
}, {
|
|
397
|
+
key: "forEach",
|
|
398
|
+
value: function forEach(callback) {
|
|
399
|
+
for (var i = 0; i < this.args.length; i++) {
|
|
400
|
+
callback(this.args[i], 'args[' + i + ']', this);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Create a new OperatorNode whose children are the results of calling
|
|
405
|
+
* the provided callback function for each child of the original node.
|
|
406
|
+
* @param {function(child: Node, path: string, parent: Node): Node} callback
|
|
407
|
+
* @returns {OperatorNode} Returns a transformed copy of the node
|
|
408
|
+
*/
|
|
409
|
+
|
|
410
|
+
}, {
|
|
411
|
+
key: "map",
|
|
412
|
+
value: function map(callback) {
|
|
413
|
+
var args = [];
|
|
414
|
+
|
|
415
|
+
for (var i = 0; i < this.args.length; i++) {
|
|
416
|
+
args[i] = this._ifNode(callback(this.args[i], 'args[' + i + ']', this));
|
|
417
|
+
}
|
|
464
418
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
419
|
+
return new OperatorNode(this.op, this.fn, args, this.implicit, this.isPercentage);
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Create a clone of this node, a shallow copy
|
|
423
|
+
* @return {OperatorNode}
|
|
424
|
+
*/
|
|
425
|
+
|
|
426
|
+
}, {
|
|
427
|
+
key: "clone",
|
|
428
|
+
value: function clone() {
|
|
429
|
+
return new OperatorNode(this.op, this.fn, this.args.slice(0), this.implicit, this.isPercentage);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Check whether this is an unary OperatorNode:
|
|
433
|
+
* has exactly one argument, like `-a`.
|
|
434
|
+
* @return {boolean}
|
|
435
|
+
* Returns true when an unary operator node, false otherwise.
|
|
436
|
+
*/
|
|
437
|
+
|
|
438
|
+
}, {
|
|
439
|
+
key: "isUnary",
|
|
440
|
+
value: function isUnary() {
|
|
441
|
+
return this.args.length === 1;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Check whether this is a binary OperatorNode:
|
|
445
|
+
* has exactly two arguments, like `a + b`.
|
|
446
|
+
* @return {boolean}
|
|
447
|
+
* Returns true when a binary operator node, false otherwise.
|
|
448
|
+
*/
|
|
449
|
+
|
|
450
|
+
}, {
|
|
451
|
+
key: "isBinary",
|
|
452
|
+
value: function isBinary() {
|
|
453
|
+
return this.args.length === 2;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Get string representation.
|
|
457
|
+
* @param {Object} options
|
|
458
|
+
* @return {string} str
|
|
459
|
+
*/
|
|
460
|
+
|
|
461
|
+
}, {
|
|
462
|
+
key: "_toString",
|
|
463
|
+
value: function _toString(options) {
|
|
464
|
+
var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
|
|
465
|
+
var implicit = options && options.implicit ? options.implicit : 'hide';
|
|
466
|
+
var args = this.args;
|
|
467
|
+
var parens = calculateNecessaryParentheses(this, parenthesis, implicit, args, false);
|
|
468
|
+
|
|
469
|
+
if (args.length === 1) {
|
|
470
|
+
// unary operators
|
|
471
|
+
var assoc = (0, _operators.getAssociativity)(this, parenthesis);
|
|
472
|
+
var operand = args[0].toString(options);
|
|
473
|
+
|
|
474
|
+
if (parens[0]) {
|
|
475
|
+
operand = '(' + operand + ')';
|
|
476
|
+
} // for example for "not", we want a space between operand and argument
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
var opIsNamed = /[a-zA-Z]+/.test(this.op);
|
|
480
|
+
|
|
481
|
+
if (assoc === 'right') {
|
|
482
|
+
// prefix operator
|
|
483
|
+
return this.op + (opIsNamed ? ' ' : '') + operand;
|
|
484
|
+
} else if (assoc === 'left') {
|
|
485
|
+
// postfix
|
|
486
|
+
return operand + (opIsNamed ? ' ' : '') + this.op;
|
|
487
|
+
} // fall back to postfix
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
return operand + this.op;
|
|
491
|
+
} else if (args.length === 2) {
|
|
492
|
+
var lhs = args[0].toString(options); // left hand side
|
|
493
|
+
|
|
494
|
+
var rhs = args[1].toString(options); // right hand side
|
|
495
|
+
|
|
496
|
+
if (parens[0]) {
|
|
497
|
+
// left hand side in parenthesis?
|
|
498
|
+
lhs = '(' + lhs + ')';
|
|
499
|
+
}
|
|
476
500
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
fn: this.fn,
|
|
482
|
-
args: this.args,
|
|
483
|
-
implicit: this.implicit,
|
|
484
|
-
isPercentage: this.isPercentage
|
|
485
|
-
};
|
|
486
|
-
};
|
|
487
|
-
/**
|
|
488
|
-
* Instantiate an OperatorNode from its JSON representation
|
|
489
|
-
* @param {Object} json An object structured like
|
|
490
|
-
* `{"mathjs": "OperatorNode", "op": "+", "fn": "add", "args": [...], "implicit": false, "isPercentage":false}`,
|
|
491
|
-
* where mathjs is optional
|
|
492
|
-
* @returns {OperatorNode}
|
|
493
|
-
*/
|
|
501
|
+
if (parens[1]) {
|
|
502
|
+
// right hand side in parenthesis?
|
|
503
|
+
rhs = '(' + rhs + ')';
|
|
504
|
+
}
|
|
494
505
|
|
|
506
|
+
if (this.implicit && this.getIdentifier() === 'OperatorNode:multiply' && implicit === 'hide') {
|
|
507
|
+
return lhs + ' ' + rhs;
|
|
508
|
+
}
|
|
495
509
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
* Get HTML representation.
|
|
501
|
-
* @param {Object} options
|
|
502
|
-
* @return {string} str
|
|
503
|
-
*/
|
|
510
|
+
return lhs + ' ' + this.op + ' ' + rhs;
|
|
511
|
+
} else if (args.length > 2 && (this.getIdentifier() === 'OperatorNode:add' || this.getIdentifier() === 'OperatorNode:multiply')) {
|
|
512
|
+
var stringifiedArgs = args.map(function (arg, index) {
|
|
513
|
+
arg = arg.toString(options);
|
|
504
514
|
|
|
515
|
+
if (parens[index]) {
|
|
516
|
+
// put in parenthesis?
|
|
517
|
+
arg = '(' + arg + ')';
|
|
518
|
+
}
|
|
505
519
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
var implicit = options && options.implicit ? options.implicit : 'hide';
|
|
509
|
-
var args = this.args;
|
|
510
|
-
var parens = calculateNecessaryParentheses(this, parenthesis, implicit, args, false);
|
|
520
|
+
return arg;
|
|
521
|
+
});
|
|
511
522
|
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
var operand = args[0].toHTML(options);
|
|
523
|
+
if (this.implicit && this.getIdentifier() === 'OperatorNode:multiply' && implicit === 'hide') {
|
|
524
|
+
return stringifiedArgs.join(' ');
|
|
525
|
+
}
|
|
516
526
|
|
|
517
|
-
|
|
518
|
-
|
|
527
|
+
return stringifiedArgs.join(' ' + this.op + ' ');
|
|
528
|
+
} else {
|
|
529
|
+
// fallback to formatting as a function call
|
|
530
|
+
return this.fn + '(' + this.args.join(', ') + ')';
|
|
531
|
+
}
|
|
519
532
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
533
|
+
/**
|
|
534
|
+
* Get a JSON representation of the node
|
|
535
|
+
* @returns {Object}
|
|
536
|
+
*/
|
|
537
|
+
|
|
538
|
+
}, {
|
|
539
|
+
key: "toJSON",
|
|
540
|
+
value: function toJSON() {
|
|
541
|
+
return {
|
|
542
|
+
mathjs: name,
|
|
543
|
+
op: this.op,
|
|
544
|
+
fn: this.fn,
|
|
545
|
+
args: this.args,
|
|
546
|
+
implicit: this.implicit,
|
|
547
|
+
isPercentage: this.isPercentage
|
|
548
|
+
};
|
|
527
549
|
}
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
550
|
+
/**
|
|
551
|
+
* Instantiate an OperatorNode from its JSON representation
|
|
552
|
+
* @param {Object} json
|
|
553
|
+
* An object structured like
|
|
554
|
+
* ```
|
|
555
|
+
* {"mathjs": "OperatorNode",
|
|
556
|
+
* "op": "+", "fn": "add", "args": [...],
|
|
557
|
+
* "implicit": false,
|
|
558
|
+
* "isPercentage":false}
|
|
559
|
+
* ```
|
|
560
|
+
* where mathjs is optional
|
|
561
|
+
* @returns {OperatorNode}
|
|
562
|
+
*/
|
|
563
|
+
|
|
564
|
+
}, {
|
|
565
|
+
key: "toHTML",
|
|
566
|
+
value:
|
|
567
|
+
/**
|
|
568
|
+
* Get HTML representation.
|
|
569
|
+
* @param {Object} options
|
|
570
|
+
* @return {string} str
|
|
571
|
+
*/
|
|
572
|
+
function toHTML(options) {
|
|
573
|
+
var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
|
|
574
|
+
var implicit = options && options.implicit ? options.implicit : 'hide';
|
|
575
|
+
var args = this.args;
|
|
576
|
+
var parens = calculateNecessaryParentheses(this, parenthesis, implicit, args, false);
|
|
577
|
+
|
|
578
|
+
if (args.length === 1) {
|
|
579
|
+
// unary operators
|
|
580
|
+
var assoc = (0, _operators.getAssociativity)(this, parenthesis);
|
|
581
|
+
var operand = args[0].toHTML(options);
|
|
582
|
+
|
|
583
|
+
if (parens[0]) {
|
|
584
|
+
operand = '<span class="math-parenthesis math-round-parenthesis">(</span>' + operand + '<span class="math-parenthesis math-round-parenthesis">)</span>';
|
|
585
|
+
}
|
|
531
586
|
|
|
532
|
-
|
|
587
|
+
if (assoc === 'right') {
|
|
588
|
+
// prefix operator
|
|
589
|
+
return '<span class="math-operator math-unary-operator ' + 'math-lefthand-unary-operator">' + (0, _string.escape)(this.op) + '</span>' + operand;
|
|
590
|
+
} else {
|
|
591
|
+
// postfix when assoc === 'left' or undefined
|
|
592
|
+
return operand + '<span class="math-operator math-unary-operator ' + 'math-righthand-unary-operator">' + (0, _string.escape)(this.op) + '</span>';
|
|
593
|
+
}
|
|
594
|
+
} else if (args.length === 2) {
|
|
595
|
+
// binary operatoes
|
|
596
|
+
var lhs = args[0].toHTML(options); // left hand side
|
|
533
597
|
|
|
534
|
-
|
|
535
|
-
// left hand side in parenthesis?
|
|
536
|
-
lhs = '<span class="math-parenthesis math-round-parenthesis">(</span>' + lhs + '<span class="math-parenthesis math-round-parenthesis">)</span>';
|
|
537
|
-
}
|
|
598
|
+
var rhs = args[1].toHTML(options); // right hand side
|
|
538
599
|
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
600
|
+
if (parens[0]) {
|
|
601
|
+
// left hand side in parenthesis?
|
|
602
|
+
lhs = '<span class="math-parenthesis math-round-parenthesis">(</span>' + lhs + '<span class="math-parenthesis math-round-parenthesis">)</span>';
|
|
603
|
+
}
|
|
543
604
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
605
|
+
if (parens[1]) {
|
|
606
|
+
// right hand side in parenthesis?
|
|
607
|
+
rhs = '<span class="math-parenthesis math-round-parenthesis">(</span>' + rhs + '<span class="math-parenthesis math-round-parenthesis">)</span>';
|
|
608
|
+
}
|
|
547
609
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
arg = arg.toHTML(options);
|
|
610
|
+
if (this.implicit && this.getIdentifier() === 'OperatorNode:multiply' && implicit === 'hide') {
|
|
611
|
+
return lhs + '<span class="math-operator math-binary-operator ' + 'math-implicit-binary-operator"></span>' + rhs;
|
|
612
|
+
}
|
|
552
613
|
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
614
|
+
return lhs + '<span class="math-operator math-binary-operator ' + 'math-explicit-binary-operator">' + (0, _string.escape)(this.op) + '</span>' + rhs;
|
|
615
|
+
} else {
|
|
616
|
+
var stringifiedArgs = args.map(function (arg, index) {
|
|
617
|
+
arg = arg.toHTML(options);
|
|
557
618
|
|
|
558
|
-
|
|
559
|
-
|
|
619
|
+
if (parens[index]) {
|
|
620
|
+
// put in parenthesis?
|
|
621
|
+
arg = '<span class="math-parenthesis math-round-parenthesis">(</span>' + arg + '<span class="math-parenthesis math-round-parenthesis">)</span>';
|
|
622
|
+
}
|
|
560
623
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
return stringifiedArgs.join('<span class="math-operator math-binary-operator math-implicit-binary-operator"></span>');
|
|
564
|
-
}
|
|
624
|
+
return arg;
|
|
625
|
+
});
|
|
565
626
|
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
};
|
|
573
|
-
/**
|
|
574
|
-
* Get LaTeX representation
|
|
575
|
-
* @param {Object} options
|
|
576
|
-
* @return {string} str
|
|
577
|
-
*/
|
|
627
|
+
if (args.length > 2 && (this.getIdentifier() === 'OperatorNode:add' || this.getIdentifier() === 'OperatorNode:multiply')) {
|
|
628
|
+
if (this.implicit && this.getIdentifier() === 'OperatorNode:multiply' && implicit === 'hide') {
|
|
629
|
+
return stringifiedArgs.join('<span class="math-operator math-binary-operator ' + 'math-implicit-binary-operator"></span>');
|
|
630
|
+
}
|
|
578
631
|
|
|
632
|
+
return stringifiedArgs.join('<span class="math-operator math-binary-operator ' + 'math-explicit-binary-operator">' + (0, _string.escape)(this.op) + '</span>');
|
|
633
|
+
} else {
|
|
634
|
+
// fallback to formatting as a function call
|
|
635
|
+
return '<span class="math-function">' + (0, _string.escape)(this.fn) + '</span><span class="math-paranthesis math-round-parenthesis">' + '(</span>' + stringifiedArgs.join('<span class="math-separator">,</span>') + '<span class="math-paranthesis math-round-parenthesis">)</span>';
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Get LaTeX representation
|
|
641
|
+
* @param {Object} options
|
|
642
|
+
* @return {string} str
|
|
643
|
+
*/
|
|
644
|
+
|
|
645
|
+
}, {
|
|
646
|
+
key: "_toTex",
|
|
647
|
+
value: function _toTex(options) {
|
|
648
|
+
var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
|
|
649
|
+
var implicit = options && options.implicit ? options.implicit : 'hide';
|
|
650
|
+
var args = this.args;
|
|
651
|
+
var parens = calculateNecessaryParentheses(this, parenthesis, implicit, args, true);
|
|
652
|
+
var op = _latex.latexOperators[this.fn];
|
|
653
|
+
op = typeof op === 'undefined' ? this.op : op; // fall back to using this.op
|
|
654
|
+
|
|
655
|
+
if (args.length === 1) {
|
|
656
|
+
// unary operators
|
|
657
|
+
var assoc = (0, _operators.getAssociativity)(this, parenthesis);
|
|
658
|
+
var operand = args[0].toTex(options);
|
|
659
|
+
|
|
660
|
+
if (parens[0]) {
|
|
661
|
+
operand = "\\left(".concat(operand, "\\right)");
|
|
662
|
+
}
|
|
579
663
|
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
664
|
+
if (assoc === 'right') {
|
|
665
|
+
// prefix operator
|
|
666
|
+
return op + operand;
|
|
667
|
+
} else if (assoc === 'left') {
|
|
668
|
+
// postfix operator
|
|
669
|
+
return operand + op;
|
|
670
|
+
} // fall back to postfix
|
|
587
671
|
|
|
588
|
-
if (args.length === 1) {
|
|
589
|
-
// unary operators
|
|
590
|
-
var assoc = (0, _operators.getAssociativity)(this, parenthesis);
|
|
591
|
-
var operand = args[0].toTex(options);
|
|
592
672
|
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
673
|
+
return operand + op;
|
|
674
|
+
} else if (args.length === 2) {
|
|
675
|
+
// binary operators
|
|
676
|
+
var lhs = args[0]; // left hand side
|
|
596
677
|
|
|
597
|
-
|
|
598
|
-
// prefix operator
|
|
599
|
-
return op + operand;
|
|
600
|
-
} else if (assoc === 'left') {
|
|
601
|
-
// postfix operator
|
|
602
|
-
return operand + op;
|
|
603
|
-
} // fall back to postfix
|
|
678
|
+
var lhsTex = lhs.toTex(options);
|
|
604
679
|
|
|
680
|
+
if (parens[0]) {
|
|
681
|
+
lhsTex = "\\left(".concat(lhsTex, "\\right)");
|
|
682
|
+
}
|
|
605
683
|
|
|
606
|
-
|
|
607
|
-
} else if (args.length === 2) {
|
|
608
|
-
// binary operators
|
|
609
|
-
var lhs = args[0]; // left hand side
|
|
684
|
+
var rhs = args[1]; // right hand side
|
|
610
685
|
|
|
611
|
-
|
|
686
|
+
var rhsTex = rhs.toTex(options);
|
|
612
687
|
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
688
|
+
if (parens[1]) {
|
|
689
|
+
rhsTex = "\\left(".concat(rhsTex, "\\right)");
|
|
690
|
+
} // handle some exceptions (due to the way LaTeX works)
|
|
616
691
|
|
|
617
|
-
var rhs = args[1]; // right hand side
|
|
618
692
|
|
|
619
|
-
|
|
693
|
+
var lhsIdentifier;
|
|
620
694
|
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
695
|
+
if (parenthesis === 'keep') {
|
|
696
|
+
lhsIdentifier = lhs.getIdentifier();
|
|
697
|
+
} else {
|
|
698
|
+
// Ignore ParenthesisNodes if in 'keep' mode
|
|
699
|
+
lhsIdentifier = lhs.getContent().getIdentifier();
|
|
700
|
+
}
|
|
624
701
|
|
|
702
|
+
switch (this.getIdentifier()) {
|
|
703
|
+
case 'OperatorNode:divide':
|
|
704
|
+
// op contains '\\frac' at this point
|
|
705
|
+
return op + '{' + lhsTex + '}' + '{' + rhsTex + '}';
|
|
625
706
|
|
|
626
|
-
|
|
707
|
+
case 'OperatorNode:pow':
|
|
708
|
+
lhsTex = '{' + lhsTex + '}';
|
|
709
|
+
rhsTex = '{' + rhsTex + '}';
|
|
627
710
|
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
} else {
|
|
631
|
-
// Ignore ParenthesisNodes if in 'keep' mode
|
|
632
|
-
lhsIdentifier = lhs.getContent().getIdentifier();
|
|
633
|
-
}
|
|
711
|
+
switch (lhsIdentifier) {
|
|
712
|
+
case 'ConditionalNode': //
|
|
634
713
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
return op + '{' + lhsTex + '}' + '{' + rhsTex + '}';
|
|
714
|
+
case 'OperatorNode:divide':
|
|
715
|
+
lhsTex = "\\left(".concat(lhsTex, "\\right)");
|
|
716
|
+
}
|
|
639
717
|
|
|
640
|
-
|
|
641
|
-
lhsTex = '{' + lhsTex + '}';
|
|
642
|
-
rhsTex = '{' + rhsTex + '}';
|
|
718
|
+
break;
|
|
643
719
|
|
|
644
|
-
|
|
645
|
-
|
|
720
|
+
case 'OperatorNode:multiply':
|
|
721
|
+
if (this.implicit && implicit === 'hide') {
|
|
722
|
+
return lhsTex + '~' + rhsTex;
|
|
723
|
+
}
|
|
646
724
|
|
|
647
|
-
case 'OperatorNode:divide':
|
|
648
|
-
lhsTex = "\\left(".concat(lhsTex, "\\right)");
|
|
649
725
|
}
|
|
650
726
|
|
|
651
|
-
|
|
727
|
+
return lhsTex + op + rhsTex;
|
|
728
|
+
} else if (args.length > 2 && (this.getIdentifier() === 'OperatorNode:add' || this.getIdentifier() === 'OperatorNode:multiply')) {
|
|
729
|
+
var texifiedArgs = args.map(function (arg, index) {
|
|
730
|
+
arg = arg.toTex(options);
|
|
652
731
|
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
}
|
|
732
|
+
if (parens[index]) {
|
|
733
|
+
arg = "\\left(".concat(arg, "\\right)");
|
|
734
|
+
}
|
|
657
735
|
|
|
658
|
-
|
|
736
|
+
return arg;
|
|
737
|
+
});
|
|
659
738
|
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
arg = arg.toTex(options);
|
|
739
|
+
if (this.getIdentifier() === 'OperatorNode:multiply' && this.implicit && implicit === 'hide') {
|
|
740
|
+
return texifiedArgs.join('~');
|
|
741
|
+
}
|
|
664
742
|
|
|
665
|
-
|
|
666
|
-
|
|
743
|
+
return texifiedArgs.join(op);
|
|
744
|
+
} else {
|
|
745
|
+
// fall back to formatting as a function call
|
|
746
|
+
// as this is a fallback, it doesn't use
|
|
747
|
+
// fancy function names
|
|
748
|
+
return '\\mathrm{' + this.fn + '}\\left(' + args.map(function (arg) {
|
|
749
|
+
return arg.toTex(options);
|
|
750
|
+
}).join(',') + '\\right)';
|
|
667
751
|
}
|
|
668
|
-
|
|
669
|
-
return arg;
|
|
670
|
-
});
|
|
671
|
-
|
|
672
|
-
if (this.getIdentifier() === 'OperatorNode:multiply' && this.implicit) {
|
|
673
|
-
return texifiedArgs.join('~');
|
|
674
752
|
}
|
|
753
|
+
/**
|
|
754
|
+
* Get identifier.
|
|
755
|
+
* @return {string}
|
|
756
|
+
*/
|
|
757
|
+
|
|
758
|
+
}, {
|
|
759
|
+
key: "getIdentifier",
|
|
760
|
+
value: function getIdentifier() {
|
|
761
|
+
return this.type + ':' + this.fn;
|
|
762
|
+
}
|
|
763
|
+
}], [{
|
|
764
|
+
key: "fromJSON",
|
|
765
|
+
value: function fromJSON(json) {
|
|
766
|
+
return new OperatorNode(json.op, json.fn, json.args, json.implicit, json.isPercentage);
|
|
767
|
+
}
|
|
768
|
+
}]);
|
|
769
|
+
return OperatorNode;
|
|
770
|
+
}(Node);
|
|
675
771
|
|
|
676
|
-
|
|
677
|
-
} else {
|
|
678
|
-
// fall back to formatting as a function call
|
|
679
|
-
// as this is a fallback, it doesn't use
|
|
680
|
-
// fancy function names
|
|
681
|
-
return '\\mathrm{' + this.fn + '}\\left(' + args.map(function (arg) {
|
|
682
|
-
return arg.toTex(options);
|
|
683
|
-
}).join(',') + '\\right)';
|
|
684
|
-
}
|
|
685
|
-
};
|
|
686
|
-
/**
|
|
687
|
-
* Get identifier.
|
|
688
|
-
* @return {string}
|
|
689
|
-
*/
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
OperatorNode.prototype.getIdentifier = function () {
|
|
693
|
-
return this.type + ':' + this.fn;
|
|
694
|
-
};
|
|
695
|
-
|
|
772
|
+
(0, _defineProperty2["default"])(OperatorNode, "name", name);
|
|
696
773
|
return OperatorNode;
|
|
697
774
|
}, {
|
|
698
775
|
isClass: true,
|