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 { map } from '../../utils/array.js';
|
|
2
3
|
import { getSafeProperty } from '../../utils/customs.js';
|
|
3
4
|
import { factory } from '../../utils/factory.js';
|
|
@@ -11,221 +12,228 @@ export var createIndexNode = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
|
11
12
|
size
|
|
12
13
|
} = _ref;
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
15
|
+
class IndexNode extends Node {
|
|
16
|
+
/**
|
|
17
|
+
* @constructor IndexNode
|
|
18
|
+
* @extends Node
|
|
19
|
+
*
|
|
20
|
+
* Describes a subset of a matrix or an object property.
|
|
21
|
+
* Cannot be used on its own, needs to be used within an AccessorNode or
|
|
22
|
+
* AssignmentNode.
|
|
23
|
+
*
|
|
24
|
+
* @param {Node[]} dimensions
|
|
25
|
+
* @param {boolean} [dotNotation=false]
|
|
26
|
+
* Optional property describing whether this index was written using dot
|
|
27
|
+
* notation like `a.b`, or using bracket notation like `a["b"]`
|
|
28
|
+
* (which is the default). This property is used for string conversion.
|
|
29
|
+
*/
|
|
30
|
+
constructor(dimensions, dotNotation) {
|
|
31
|
+
super();
|
|
32
|
+
this.dimensions = dimensions;
|
|
33
|
+
this.dotNotation = dotNotation || false; // validate input
|
|
34
|
+
|
|
35
|
+
if (!Array.isArray(dimensions) || !dimensions.every(isNode)) {
|
|
36
|
+
throw new TypeError('Array containing Nodes expected for parameter "dimensions"');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (this.dotNotation && !this.isObjectProperty()) {
|
|
40
|
+
throw new Error('dotNotation only applicable for object properties');
|
|
41
|
+
}
|
|
32
42
|
}
|
|
33
43
|
|
|
34
|
-
|
|
35
|
-
|
|
44
|
+
get type() {
|
|
45
|
+
return name;
|
|
46
|
+
}
|
|
36
47
|
|
|
37
|
-
|
|
38
|
-
|
|
48
|
+
get isIndexNode() {
|
|
49
|
+
return true;
|
|
39
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Compile a node into a JavaScript function.
|
|
53
|
+
* This basically pre-calculates as much as possible and only leaves open
|
|
54
|
+
* calculations which depend on a dynamic scope with variables.
|
|
55
|
+
* @param {Object} math Math.js namespace with functions and constants.
|
|
56
|
+
* @param {Object} argNames An object with argument names as key and `true`
|
|
57
|
+
* as value. Used in the SymbolNode to optimize
|
|
58
|
+
* for arguments from user assigned functions
|
|
59
|
+
* (see FunctionAssignmentNode) or special symbols
|
|
60
|
+
* like `end` (see IndexNode).
|
|
61
|
+
* @return {function} Returns a function which can be called like:
|
|
62
|
+
* evalNode(scope: Object, args: Object, context: *)
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
_compile(math, argNames) {
|
|
67
|
+
// TODO: implement support for bignumber (currently bignumbers are silently
|
|
68
|
+
// reduced to numbers when changing the value to zero-based)
|
|
69
|
+
// TODO: Optimization: when the range values are ConstantNodes,
|
|
70
|
+
// we can beforehand resolve the zero-based value
|
|
71
|
+
// optimization for a simple object property
|
|
72
|
+
var evalDimensions = map(this.dimensions, function (dimension, i) {
|
|
73
|
+
var needsEnd = dimension.filter(node => node.isSymbolNode && node.name === 'end').length > 0;
|
|
74
|
+
|
|
75
|
+
if (needsEnd) {
|
|
76
|
+
// SymbolNode 'end' is used inside the index,
|
|
77
|
+
// like in `A[end]` or `A[end - 2]`
|
|
78
|
+
var childArgNames = Object.create(argNames);
|
|
79
|
+
childArgNames.end = true;
|
|
80
|
+
|
|
81
|
+
var _evalDimension = dimension._compile(math, childArgNames);
|
|
82
|
+
|
|
83
|
+
return function evalDimension(scope, args, context) {
|
|
84
|
+
if (!isMatrix(context) && !isArray(context) && !isString(context)) {
|
|
85
|
+
throw new TypeError('Cannot resolve "end": ' + 'context must be a Matrix, Array, or string but is ' + typeOf(context));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
var s = size(context).valueOf();
|
|
89
|
+
var childArgs = Object.create(args);
|
|
90
|
+
childArgs.end = s[i];
|
|
91
|
+
return _evalDimension(scope, childArgs, context);
|
|
92
|
+
};
|
|
93
|
+
} else {
|
|
94
|
+
// SymbolNode `end` not used
|
|
95
|
+
return dimension._compile(math, argNames);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
var index = getSafeProperty(math, 'index');
|
|
99
|
+
return function evalIndexNode(scope, args, context) {
|
|
100
|
+
var dimensions = map(evalDimensions, function (evalDimension) {
|
|
101
|
+
return evalDimension(scope, args, context);
|
|
102
|
+
});
|
|
103
|
+
return index(...dimensions);
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Execute a callback for each of the child nodes of this node
|
|
108
|
+
* @param {function(child: Node, path: string, parent: Node)} callback
|
|
109
|
+
*/
|
|
110
|
+
|
|
40
111
|
|
|
41
|
-
|
|
42
|
-
|
|
112
|
+
forEach(callback) {
|
|
113
|
+
for (var i = 0; i < this.dimensions.length; i++) {
|
|
114
|
+
callback(this.dimensions[i], 'dimensions[' + i + ']', this);
|
|
115
|
+
}
|
|
43
116
|
}
|
|
44
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Create a new IndexNode whose children are the results of calling
|
|
119
|
+
* the provided callback function for each child of the original node.
|
|
120
|
+
* @param {function(child: Node, path: string, parent: Node): Node} callback
|
|
121
|
+
* @returns {IndexNode} Returns a transformed copy of the node
|
|
122
|
+
*/
|
|
45
123
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
* calculations which depend on a dynamic scope with variables.
|
|
53
|
-
* @param {Object} math Math.js namespace with functions and constants.
|
|
54
|
-
* @param {Object} argNames An object with argument names as key and `true`
|
|
55
|
-
* as value. Used in the SymbolNode to optimize
|
|
56
|
-
* for arguments from user assigned functions
|
|
57
|
-
* (see FunctionAssignmentNode) or special symbols
|
|
58
|
-
* like `end` (see IndexNode).
|
|
59
|
-
* @return {function} Returns a function which can be called like:
|
|
60
|
-
* evalNode(scope: Object, args: Object, context: *)
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
IndexNode.prototype._compile = function (math, argNames) {
|
|
64
|
-
// TODO: implement support for bignumber (currently bignumbers are silently
|
|
65
|
-
// reduced to numbers when changing the value to zero-based)
|
|
66
|
-
// TODO: Optimization: when the range values are ConstantNodes,
|
|
67
|
-
// we can beforehand resolve the zero-based value
|
|
68
|
-
// optimization for a simple object property
|
|
69
|
-
var evalDimensions = map(this.dimensions, function (dimension, i) {
|
|
70
|
-
var needsEnd = dimension.filter(node => node.isSymbolNode && node.name === 'end').length > 0;
|
|
71
|
-
|
|
72
|
-
if (needsEnd) {
|
|
73
|
-
// SymbolNode 'end' is used inside the index,
|
|
74
|
-
// like in `A[end]` or `A[end - 2]`
|
|
75
|
-
var childArgNames = Object.create(argNames);
|
|
76
|
-
childArgNames.end = true;
|
|
77
|
-
|
|
78
|
-
var _evalDimension = dimension._compile(math, childArgNames);
|
|
79
|
-
|
|
80
|
-
return function evalDimension(scope, args, context) {
|
|
81
|
-
if (!isMatrix(context) && !isArray(context) && !isString(context)) {
|
|
82
|
-
throw new TypeError('Cannot resolve "end": ' + 'context must be a Matrix, Array, or string but is ' + typeOf(context));
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
var s = size(context).valueOf();
|
|
86
|
-
var childArgs = Object.create(args);
|
|
87
|
-
childArgs.end = s[i];
|
|
88
|
-
return _evalDimension(scope, childArgs, context);
|
|
89
|
-
};
|
|
90
|
-
} else {
|
|
91
|
-
// SymbolNode `end` not used
|
|
92
|
-
return dimension._compile(math, argNames);
|
|
124
|
+
|
|
125
|
+
map(callback) {
|
|
126
|
+
var dimensions = [];
|
|
127
|
+
|
|
128
|
+
for (var i = 0; i < this.dimensions.length; i++) {
|
|
129
|
+
dimensions[i] = this._ifNode(callback(this.dimensions[i], 'dimensions[' + i + ']', this));
|
|
93
130
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return function evalIndexNode(scope, args, context) {
|
|
97
|
-
var dimensions = map(evalDimensions, function (evalDimension) {
|
|
98
|
-
return evalDimension(scope, args, context);
|
|
99
|
-
});
|
|
100
|
-
return index(...dimensions);
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
/**
|
|
104
|
-
* Execute a callback for each of the child nodes of this node
|
|
105
|
-
* @param {function(child: Node, path: string, parent: Node)} callback
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
IndexNode.prototype.forEach = function (callback) {
|
|
110
|
-
for (var i = 0; i < this.dimensions.length; i++) {
|
|
111
|
-
callback(this.dimensions[i], 'dimensions[' + i + ']', this);
|
|
131
|
+
|
|
132
|
+
return new IndexNode(dimensions, this.dotNotation);
|
|
112
133
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
* @param {function(child: Node, path: string, parent: Node): Node} callback
|
|
118
|
-
* @returns {IndexNode} Returns a transformed copy of the node
|
|
119
|
-
*/
|
|
134
|
+
/**
|
|
135
|
+
* Create a clone of this node, a shallow copy
|
|
136
|
+
* @return {IndexNode}
|
|
137
|
+
*/
|
|
120
138
|
|
|
121
139
|
|
|
122
|
-
|
|
123
|
-
|
|
140
|
+
clone() {
|
|
141
|
+
return new IndexNode(this.dimensions.slice(0), this.dotNotation);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Test whether this IndexNode contains a single property name
|
|
145
|
+
* @return {boolean}
|
|
146
|
+
*/
|
|
147
|
+
|
|
124
148
|
|
|
125
|
-
|
|
126
|
-
dimensions
|
|
149
|
+
isObjectProperty() {
|
|
150
|
+
return this.dimensions.length === 1 && isConstantNode(this.dimensions[0]) && typeof this.dimensions[0].value === 'string';
|
|
127
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Returns the property name if IndexNode contains a property.
|
|
154
|
+
* If not, returns null.
|
|
155
|
+
* @return {string | null}
|
|
156
|
+
*/
|
|
128
157
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
* Create a clone of this node, a shallow copy
|
|
133
|
-
* @return {IndexNode}
|
|
134
|
-
*/
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
IndexNode.prototype.clone = function () {
|
|
138
|
-
return new IndexNode(this.dimensions.slice(0), this.dotNotation);
|
|
139
|
-
};
|
|
140
|
-
/**
|
|
141
|
-
* Test whether this IndexNode contains a single property name
|
|
142
|
-
* @return {boolean}
|
|
143
|
-
*/
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
IndexNode.prototype.isObjectProperty = function () {
|
|
147
|
-
return this.dimensions.length === 1 && isConstantNode(this.dimensions[0]) && typeof this.dimensions[0].value === 'string';
|
|
148
|
-
};
|
|
149
|
-
/**
|
|
150
|
-
* Returns the property name if IndexNode contains a property.
|
|
151
|
-
* If not, returns null.
|
|
152
|
-
* @return {string | null}
|
|
153
|
-
*/
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
IndexNode.prototype.getObjectProperty = function () {
|
|
157
|
-
return this.isObjectProperty() ? this.dimensions[0].value : null;
|
|
158
|
-
};
|
|
159
|
-
/**
|
|
160
|
-
* Get string representation
|
|
161
|
-
* @param {Object} options
|
|
162
|
-
* @return {string} str
|
|
163
|
-
*/
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
IndexNode.prototype._toString = function (options) {
|
|
167
|
-
// format the parameters like "[1, 0:5]"
|
|
168
|
-
return this.dotNotation ? '.' + this.getObjectProperty() : '[' + this.dimensions.join(', ') + ']';
|
|
169
|
-
};
|
|
170
|
-
/**
|
|
171
|
-
* Get a JSON representation of the node
|
|
172
|
-
* @returns {Object}
|
|
173
|
-
*/
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
IndexNode.prototype.toJSON = function () {
|
|
177
|
-
return {
|
|
178
|
-
mathjs: 'IndexNode',
|
|
179
|
-
dimensions: this.dimensions,
|
|
180
|
-
dotNotation: this.dotNotation
|
|
181
|
-
};
|
|
182
|
-
};
|
|
183
|
-
/**
|
|
184
|
-
* Instantiate an IndexNode from its JSON representation
|
|
185
|
-
* @param {Object} json An object structured like
|
|
186
|
-
* `{"mathjs": "IndexNode", dimensions: [...], dotNotation: false}`,
|
|
187
|
-
* where mathjs is optional
|
|
188
|
-
* @returns {IndexNode}
|
|
189
|
-
*/
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
IndexNode.fromJSON = function (json) {
|
|
193
|
-
return new IndexNode(json.dimensions, json.dotNotation);
|
|
194
|
-
};
|
|
195
|
-
/**
|
|
196
|
-
* Get HTML representation
|
|
197
|
-
* @param {Object} options
|
|
198
|
-
* @return {string} str
|
|
199
|
-
*/
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
IndexNode.prototype.toHTML = function (options) {
|
|
203
|
-
// format the parameters like "[1, 0:5]"
|
|
204
|
-
var dimensions = [];
|
|
205
|
-
|
|
206
|
-
for (var i = 0; i < this.dimensions.length; i++) {
|
|
207
|
-
dimensions[i] = this.dimensions[i].toHTML();
|
|
158
|
+
|
|
159
|
+
getObjectProperty() {
|
|
160
|
+
return this.isObjectProperty() ? this.dimensions[0].value : null;
|
|
208
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Get string representation
|
|
164
|
+
* @param {Object} options
|
|
165
|
+
* @return {string} str
|
|
166
|
+
*/
|
|
167
|
+
|
|
209
168
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
return '<span class="math-parenthesis math-square-parenthesis">[</span>' + dimensions.join('<span class="math-separator">,</span>') + '<span class="math-parenthesis math-square-parenthesis">]</span>';
|
|
169
|
+
_toString(options) {
|
|
170
|
+
// format the parameters like "[1, 0:5]"
|
|
171
|
+
return this.dotNotation ? '.' + this.getObjectProperty() : '[' + this.dimensions.join(', ') + ']';
|
|
214
172
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
173
|
+
/**
|
|
174
|
+
* Get a JSON representation of the node
|
|
175
|
+
* @returns {Object}
|
|
176
|
+
*/
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
toJSON() {
|
|
180
|
+
return {
|
|
181
|
+
mathjs: name,
|
|
182
|
+
dimensions: this.dimensions,
|
|
183
|
+
dotNotation: this.dotNotation
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Instantiate an IndexNode from its JSON representation
|
|
188
|
+
* @param {Object} json
|
|
189
|
+
* An object structured like
|
|
190
|
+
* `{"mathjs": "IndexNode", dimensions: [...], dotNotation: false}`,
|
|
191
|
+
* where mathjs is optional
|
|
192
|
+
* @returns {IndexNode}
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
static fromJSON(json) {
|
|
197
|
+
return new IndexNode(json.dimensions, json.dotNotation);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Get HTML representation
|
|
201
|
+
* @param {Object} options
|
|
202
|
+
* @return {string} str
|
|
203
|
+
*/
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
toHTML(options) {
|
|
207
|
+
// format the parameters like "[1, 0:5]"
|
|
208
|
+
var dimensions = [];
|
|
209
|
+
|
|
210
|
+
for (var i = 0; i < this.dimensions.length; i++) {
|
|
211
|
+
dimensions[i] = this.dimensions[i].toHTML();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (this.dotNotation) {
|
|
215
|
+
return '<span class="math-operator math-accessor-operator">.</span>' + '<span class="math-symbol math-property">' + escape(this.getObjectProperty()) + '</span>';
|
|
216
|
+
} else {
|
|
217
|
+
return '<span class="math-parenthesis math-square-parenthesis">[</span>' + dimensions.join('<span class="math-separator">,</span>') + '<span class="math-parenthesis math-square-parenthesis">]</span>';
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Get LaTeX representation
|
|
222
|
+
* @param {Object} options
|
|
223
|
+
* @return {string} str
|
|
224
|
+
*/
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
_toTex(options) {
|
|
228
|
+
var dimensions = this.dimensions.map(function (range) {
|
|
229
|
+
return range.toTex(options);
|
|
230
|
+
});
|
|
231
|
+
return this.dotNotation ? '.' + this.getObjectProperty() + '' : '_{' + dimensions.join(',') + '}';
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
_defineProperty(IndexNode, "name", name);
|
|
229
237
|
|
|
230
238
|
return IndexNode;
|
|
231
239
|
}, {
|