mathjs 10.6.3 → 11.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (451) hide show
  1. package/HISTORY.md +74 -1
  2. package/README.md +1 -1
  3. package/lib/browser/math.js +2 -41
  4. package/lib/browser/math.js.LICENSE.txt +43 -0
  5. package/lib/browser/math.js.map +1 -1
  6. package/lib/cjs/core/create.js +6 -5
  7. package/lib/cjs/core/function/import.js +4 -14
  8. package/lib/cjs/core/function/typed.js +54 -12
  9. package/lib/cjs/defaultInstance.js +3 -3
  10. package/lib/cjs/entry/allFactoriesAny.js +1 -1
  11. package/lib/cjs/entry/allFactoriesNumber.js +1 -1
  12. package/lib/cjs/entry/configReadonly.js +1 -1
  13. package/lib/cjs/entry/dependenciesAny/dependenciesChainClass.generated.js +3 -0
  14. package/lib/cjs/entry/dependenciesAny/dependenciesKldivergence.generated.js +3 -0
  15. package/lib/cjs/entry/dependenciesAny/dependenciesRationalize.generated.js +3 -0
  16. package/lib/cjs/entry/dependenciesAny/dependenciesResolve.generated.js +3 -0
  17. package/lib/cjs/entry/dependenciesAny/dependenciesSimplify.generated.js +3 -0
  18. package/lib/cjs/entry/dependenciesAny/dependenciesSimplifyConstant.generated.js +56 -0
  19. package/lib/cjs/entry/dependenciesAny/dependenciesSimplifyCore.generated.js +6 -0
  20. package/lib/cjs/entry/dependenciesAny/dependenciesSqrtm.generated.js +3 -0
  21. package/lib/cjs/entry/dependenciesAny/dependenciesStd.generated.js +3 -0
  22. package/lib/cjs/entry/dependenciesAny/dependenciesStdTransform.generated.js +3 -0
  23. package/lib/cjs/entry/dependenciesAny.generated.js +8 -0
  24. package/lib/cjs/entry/dependenciesNumber/dependenciesChainClass.generated.js +3 -0
  25. package/lib/cjs/entry/dependenciesNumber/dependenciesRationalize.generated.js +3 -0
  26. package/lib/cjs/entry/dependenciesNumber/dependenciesResolve.generated.js +3 -0
  27. package/lib/cjs/entry/dependenciesNumber/dependenciesSimplify.generated.js +3 -0
  28. package/lib/cjs/entry/dependenciesNumber/dependenciesSimplifyConstant.generated.js +50 -0
  29. package/lib/cjs/entry/dependenciesNumber/dependenciesSimplifyCore.generated.js +6 -0
  30. package/lib/cjs/entry/dependenciesNumber/dependenciesStd.generated.js +3 -0
  31. package/lib/cjs/entry/dependenciesNumber/dependenciesStdTransform.generated.js +3 -0
  32. package/lib/cjs/entry/dependenciesNumber.generated.js +8 -0
  33. package/lib/cjs/entry/impureFunctionsAny.generated.js +87 -61
  34. package/lib/cjs/entry/impureFunctionsNumber.generated.js +93 -69
  35. package/lib/cjs/entry/pureFunctionsAny.generated.js +50 -45
  36. package/lib/cjs/entry/pureFunctionsNumber.generated.js +22 -19
  37. package/lib/cjs/expression/Parser.js +1 -1
  38. package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +8 -5
  39. package/lib/cjs/expression/embeddedDocs/function/algebra/simplifyConstant.js +15 -0
  40. package/lib/cjs/expression/embeddedDocs/function/algebra/simplifyCore.js +1 -1
  41. package/lib/cjs/expression/node/AccessorNode.js +216 -173
  42. package/lib/cjs/expression/node/ArrayNode.js +206 -160
  43. package/lib/cjs/expression/node/AssignmentNode.js +321 -270
  44. package/lib/cjs/expression/node/BlockNode.js +223 -172
  45. package/lib/cjs/expression/node/ConditionalNode.js +253 -193
  46. package/lib/cjs/expression/node/ConstantNode.js +216 -171
  47. package/lib/cjs/expression/node/FunctionAssignmentNode.js +258 -196
  48. package/lib/cjs/expression/node/FunctionNode.js +456 -416
  49. package/lib/cjs/expression/node/IndexNode.js +256 -210
  50. package/lib/cjs/expression/node/Node.js +411 -378
  51. package/lib/cjs/expression/node/ObjectNode.js +223 -178
  52. package/lib/cjs/expression/node/OperatorNode.js +474 -397
  53. package/lib/cjs/expression/node/ParenthesisNode.js +189 -143
  54. package/lib/cjs/expression/node/RangeNode.js +272 -224
  55. package/lib/cjs/expression/node/RelationalNode.js +246 -195
  56. package/lib/cjs/expression/node/SymbolNode.js +219 -172
  57. package/lib/cjs/expression/node/utils/access.js +1 -1
  58. package/lib/cjs/expression/node/utils/assign.js +1 -1
  59. package/lib/cjs/expression/operators.js +117 -23
  60. package/lib/cjs/expression/parse.js +37 -19
  61. package/lib/cjs/expression/transform/std.transform.js +3 -1
  62. package/lib/cjs/factoriesAny.js +8 -0
  63. package/lib/cjs/factoriesNumber.js +10 -1
  64. package/lib/cjs/function/algebra/decomposition/qr.js +1 -1
  65. package/lib/cjs/function/algebra/derivative.js +25 -33
  66. package/lib/cjs/function/algebra/leafCount.js +0 -3
  67. package/lib/cjs/function/algebra/rationalize.js +78 -108
  68. package/lib/cjs/function/algebra/resolve.js +53 -16
  69. package/lib/cjs/function/algebra/simplify/util.js +1 -1
  70. package/lib/cjs/function/algebra/simplify.js +90 -115
  71. package/lib/cjs/function/algebra/{simplify/simplifyConstant.js → simplifyConstant.js} +44 -10
  72. package/lib/cjs/function/algebra/simplifyCore.js +196 -93
  73. package/lib/cjs/function/algebra/solver/lsolveAll.js +2 -2
  74. package/lib/cjs/function/algebra/solver/usolveAll.js +2 -2
  75. package/lib/cjs/function/algebra/symbolicEqual.js +14 -32
  76. package/lib/cjs/function/arithmetic/abs.js +7 -14
  77. package/lib/cjs/function/arithmetic/add.js +26 -70
  78. package/lib/cjs/function/arithmetic/addScalar.js +17 -9
  79. package/lib/cjs/function/arithmetic/cbrt.js +7 -11
  80. package/lib/cjs/function/arithmetic/ceil.js +56 -46
  81. package/lib/cjs/function/arithmetic/cube.js +5 -10
  82. package/lib/cjs/function/arithmetic/divide.js +7 -7
  83. package/lib/cjs/function/arithmetic/divideScalar.js +4 -18
  84. package/lib/cjs/function/arithmetic/dotDivide.js +22 -65
  85. package/lib/cjs/function/arithmetic/dotMultiply.js +16 -61
  86. package/lib/cjs/function/arithmetic/dotPow.js +30 -63
  87. package/lib/cjs/function/arithmetic/exp.js +8 -12
  88. package/lib/cjs/function/arithmetic/expm1.js +10 -10
  89. package/lib/cjs/function/arithmetic/fix.js +34 -28
  90. package/lib/cjs/function/arithmetic/floor.js +57 -47
  91. package/lib/cjs/function/arithmetic/gcd.js +27 -68
  92. package/lib/cjs/function/arithmetic/hypot.js +9 -5
  93. package/lib/cjs/function/arithmetic/invmod.js +2 -2
  94. package/lib/cjs/function/arithmetic/lcm.js +27 -68
  95. package/lib/cjs/function/arithmetic/log.js +10 -12
  96. package/lib/cjs/function/arithmetic/log10.js +5 -3
  97. package/lib/cjs/function/arithmetic/log1p.js +11 -7
  98. package/lib/cjs/function/arithmetic/log2.js +5 -3
  99. package/lib/cjs/function/arithmetic/mod.js +22 -64
  100. package/lib/cjs/function/arithmetic/multiply.js +40 -35
  101. package/lib/cjs/function/arithmetic/multiplyScalar.js +2 -9
  102. package/lib/cjs/function/arithmetic/norm.js +1 -5
  103. package/lib/cjs/function/arithmetic/nthRoot.js +83 -95
  104. package/lib/cjs/function/arithmetic/nthRoots.js +2 -2
  105. package/lib/cjs/function/arithmetic/round.js +56 -42
  106. package/lib/cjs/function/arithmetic/sign.js +14 -10
  107. package/lib/cjs/function/arithmetic/sqrt.js +5 -9
  108. package/lib/cjs/function/arithmetic/square.js +6 -10
  109. package/lib/cjs/function/arithmetic/subtract.js +44 -100
  110. package/lib/cjs/function/arithmetic/unaryMinus.js +14 -16
  111. package/lib/cjs/function/arithmetic/unaryPlus.js +6 -4
  112. package/lib/cjs/function/bitwise/bitAnd.js +17 -61
  113. package/lib/cjs/function/bitwise/bitNot.js +6 -4
  114. package/lib/cjs/function/bitwise/bitOr.js +16 -60
  115. package/lib/cjs/function/bitwise/bitXor.js +17 -61
  116. package/lib/cjs/function/bitwise/leftShift.js +69 -82
  117. package/lib/cjs/function/bitwise/rightArithShift.js +69 -82
  118. package/lib/cjs/function/bitwise/rightLogShift.js +69 -82
  119. package/lib/cjs/function/bitwise/useMatrixForArrayScalar.js +36 -0
  120. package/lib/cjs/function/complex/arg.js +5 -3
  121. package/lib/cjs/function/complex/conj.js +6 -7
  122. package/lib/cjs/function/complex/im.js +7 -8
  123. package/lib/cjs/function/complex/re.js +6 -10
  124. package/lib/cjs/function/geometry/distance.js +2 -2
  125. package/lib/cjs/function/logical/and.js +74 -80
  126. package/lib/cjs/function/logical/not.js +13 -6
  127. package/lib/cjs/function/logical/or.js +21 -63
  128. package/lib/cjs/function/logical/xor.js +21 -63
  129. package/lib/cjs/function/matrix/diff.js +11 -8
  130. package/lib/cjs/function/matrix/eigs/complexEigs.js +5 -5
  131. package/lib/cjs/function/matrix/fft.js +2 -2
  132. package/lib/cjs/function/matrix/matrixFromColumns.js +1 -1
  133. package/lib/cjs/function/matrix/matrixFromRows.js +1 -1
  134. package/lib/cjs/function/matrix/ones.js +2 -1
  135. package/lib/cjs/function/matrix/rotate.js +5 -5
  136. package/lib/cjs/function/matrix/sqrtm.js +3 -2
  137. package/lib/cjs/function/matrix/transpose.js +47 -48
  138. package/lib/cjs/function/matrix/zeros.js +2 -1
  139. package/lib/cjs/function/probability/factorial.js +5 -3
  140. package/lib/cjs/function/probability/gamma.js +38 -40
  141. package/lib/cjs/function/probability/kldivergence.js +5 -2
  142. package/lib/cjs/function/probability/lgamma.js +30 -30
  143. package/lib/cjs/function/probability/util/seededRNG.js +2 -2
  144. package/lib/cjs/function/relational/compare.js +21 -67
  145. package/lib/cjs/function/relational/compareNatural.js +59 -54
  146. package/lib/cjs/function/relational/compareText.js +10 -43
  147. package/lib/cjs/function/relational/compareUnits.js +24 -0
  148. package/lib/cjs/function/relational/equal.js +19 -80
  149. package/lib/cjs/function/relational/equalScalar.js +7 -9
  150. package/lib/cjs/function/relational/larger.js +21 -67
  151. package/lib/cjs/function/relational/largerEq.js +21 -67
  152. package/lib/cjs/function/relational/smaller.js +21 -67
  153. package/lib/cjs/function/relational/smallerEq.js +21 -67
  154. package/lib/cjs/function/relational/unequal.js +19 -80
  155. package/lib/cjs/function/special/erf.js +5 -3
  156. package/lib/cjs/function/statistics/std.js +11 -2
  157. package/lib/cjs/function/string/format.js +2 -2
  158. package/lib/cjs/function/string/hex.js +1 -2
  159. package/lib/cjs/function/trigonometry/acos.js +4 -8
  160. package/lib/cjs/function/trigonometry/acosh.js +2 -7
  161. package/lib/cjs/function/trigonometry/acot.js +6 -11
  162. package/lib/cjs/function/trigonometry/acoth.js +4 -8
  163. package/lib/cjs/function/trigonometry/acsc.js +6 -11
  164. package/lib/cjs/function/trigonometry/acsch.js +4 -8
  165. package/lib/cjs/function/trigonometry/asec.js +6 -10
  166. package/lib/cjs/function/trigonometry/asech.js +4 -8
  167. package/lib/cjs/function/trigonometry/asin.js +5 -10
  168. package/lib/cjs/function/trigonometry/asinh.js +4 -9
  169. package/lib/cjs/function/trigonometry/atan.js +5 -11
  170. package/lib/cjs/function/trigonometry/atan2.js +25 -63
  171. package/lib/cjs/function/trigonometry/atanh.js +4 -9
  172. package/lib/cjs/function/trigonometry/cos.js +11 -20
  173. package/lib/cjs/function/trigonometry/cosh.js +5 -19
  174. package/lib/cjs/function/trigonometry/cot.js +9 -15
  175. package/lib/cjs/function/trigonometry/coth.js +4 -15
  176. package/lib/cjs/function/trigonometry/csc.js +11 -17
  177. package/lib/cjs/function/trigonometry/csch.js +4 -15
  178. package/lib/cjs/function/trigonometry/sec.js +11 -17
  179. package/lib/cjs/function/trigonometry/sech.js +4 -15
  180. package/lib/cjs/function/trigonometry/sin.js +11 -21
  181. package/lib/cjs/function/trigonometry/sinh.js +5 -20
  182. package/lib/cjs/function/trigonometry/tan.js +11 -21
  183. package/lib/cjs/function/trigonometry/tanh.js +5 -20
  184. package/lib/cjs/function/trigonometry/trigUnit.js +24 -0
  185. package/lib/cjs/function/unit/to.js +7 -41
  186. package/lib/cjs/function/utils/clone.js +1 -1
  187. package/lib/cjs/function/utils/hasNumericValue.js +5 -1
  188. package/lib/cjs/function/utils/isInteger.js +6 -4
  189. package/lib/cjs/function/utils/isNaN.js +1 -1
  190. package/lib/cjs/function/utils/isNegative.js +11 -7
  191. package/lib/cjs/function/utils/isNumeric.js +6 -4
  192. package/lib/cjs/function/utils/isPositive.js +11 -7
  193. package/lib/cjs/function/utils/isPrime.js +5 -3
  194. package/lib/cjs/function/utils/isZero.js +21 -17
  195. package/lib/cjs/function/utils/numeric.js +11 -4
  196. package/lib/cjs/function/utils/typeOf.js +38 -44
  197. package/lib/cjs/header.js +2 -2
  198. package/lib/cjs/plain/bignumber/index.js +1 -1
  199. package/lib/cjs/type/bignumber/BigNumber.js +2 -2
  200. package/lib/cjs/type/bignumber/function/bignumber.js +6 -4
  201. package/lib/cjs/type/boolean.js +7 -5
  202. package/lib/cjs/type/chain/Chain.js +23 -3
  203. package/lib/cjs/type/complex/Complex.js +18 -14
  204. package/lib/cjs/type/complex/function/complex.js +6 -4
  205. package/lib/cjs/type/fraction/Fraction.js +10 -6
  206. package/lib/cjs/type/fraction/function/fraction.js +6 -4
  207. package/lib/cjs/type/matrix/DenseMatrix.js +21 -6
  208. package/lib/cjs/type/matrix/SparseMatrix.js +12 -2
  209. package/lib/cjs/type/matrix/utils/{algorithm01.js → matAlgo01xDSid.js} +4 -4
  210. package/lib/cjs/type/matrix/utils/{algorithm02.js → matAlgo02xDS0.js} +5 -5
  211. package/lib/cjs/type/matrix/utils/{algorithm03.js → matAlgo03xDSf.js} +5 -5
  212. package/lib/cjs/type/matrix/utils/{algorithm04.js → matAlgo04xSidSid.js} +7 -7
  213. package/lib/cjs/type/matrix/utils/{algorithm05.js → matAlgo05xSfSf.js} +5 -5
  214. package/lib/cjs/type/matrix/utils/{algorithm06.js → matAlgo06xS0S0.js} +5 -5
  215. package/lib/cjs/type/matrix/utils/{algorithm07.js → matAlgo07xSSf.js} +5 -5
  216. package/lib/cjs/type/matrix/utils/{algorithm08.js → matAlgo08xS0Sid.js} +6 -6
  217. package/lib/cjs/type/matrix/utils/{algorithm09.js → matAlgo09xS0Sf.js} +5 -5
  218. package/lib/cjs/type/matrix/utils/{algorithm10.js → matAlgo10xSids.js} +5 -5
  219. package/lib/cjs/type/matrix/utils/{algorithm11.js → matAlgo11xS0s.js} +5 -5
  220. package/lib/cjs/type/matrix/utils/{algorithm12.js → matAlgo12xSfs.js} +5 -5
  221. package/lib/cjs/type/matrix/utils/{algorithm13.js → matAlgo13xDD.js} +5 -5
  222. package/lib/cjs/type/matrix/utils/{algorithm14.js → matAlgo14xDs.js} +5 -5
  223. package/lib/cjs/type/matrix/utils/matrixAlgorithmSuite.js +238 -0
  224. package/lib/cjs/type/number.js +6 -4
  225. package/lib/cjs/type/string.js +7 -5
  226. package/lib/cjs/type/unit/Unit.js +69 -21
  227. package/lib/cjs/type/unit/function/createUnit.js +2 -1
  228. package/lib/cjs/type/unit/function/unit.js +9 -3
  229. package/lib/cjs/utils/customs.js +2 -2
  230. package/lib/cjs/utils/emitter.js +1 -1
  231. package/lib/cjs/utils/function.js +2 -2
  232. package/lib/cjs/utils/is.js +27 -25
  233. package/lib/cjs/utils/latex.js +3 -3
  234. package/lib/cjs/utils/lruQueue.js +1 -1
  235. package/lib/cjs/utils/map.js +3 -3
  236. package/lib/cjs/utils/object.js +2 -2
  237. package/lib/cjs/utils/snapshot.js +30 -57
  238. package/lib/cjs/utils/string.js +3 -3
  239. package/lib/cjs/version.js +1 -1
  240. package/lib/esm/core/create.js +2 -1
  241. package/lib/esm/core/function/import.js +2 -12
  242. package/lib/esm/core/function/typed.js +47 -11
  243. package/lib/esm/entry/dependenciesAny/dependenciesChainClass.generated.js +2 -0
  244. package/lib/esm/entry/dependenciesAny/dependenciesKldivergence.generated.js +2 -0
  245. package/lib/esm/entry/dependenciesAny/dependenciesRationalize.generated.js +2 -0
  246. package/lib/esm/entry/dependenciesAny/dependenciesResolve.generated.js +2 -0
  247. package/lib/esm/entry/dependenciesAny/dependenciesSimplify.generated.js +2 -0
  248. package/lib/esm/entry/dependenciesAny/dependenciesSimplifyConstant.generated.js +34 -0
  249. package/lib/esm/entry/dependenciesAny/dependenciesSimplifyCore.generated.js +4 -0
  250. package/lib/esm/entry/dependenciesAny/dependenciesSqrtm.generated.js +2 -0
  251. package/lib/esm/entry/dependenciesAny/dependenciesStd.generated.js +2 -0
  252. package/lib/esm/entry/dependenciesAny/dependenciesStdTransform.generated.js +2 -0
  253. package/lib/esm/entry/dependenciesAny.generated.js +1 -0
  254. package/lib/esm/entry/dependenciesNumber/dependenciesChainClass.generated.js +2 -0
  255. package/lib/esm/entry/dependenciesNumber/dependenciesRationalize.generated.js +2 -0
  256. package/lib/esm/entry/dependenciesNumber/dependenciesResolve.generated.js +2 -0
  257. package/lib/esm/entry/dependenciesNumber/dependenciesSimplify.generated.js +2 -0
  258. package/lib/esm/entry/dependenciesNumber/dependenciesSimplifyConstant.generated.js +30 -0
  259. package/lib/esm/entry/dependenciesNumber/dependenciesSimplifyCore.generated.js +4 -0
  260. package/lib/esm/entry/dependenciesNumber/dependenciesStd.generated.js +2 -0
  261. package/lib/esm/entry/dependenciesNumber/dependenciesStdTransform.generated.js +2 -0
  262. package/lib/esm/entry/dependenciesNumber.generated.js +1 -0
  263. package/lib/esm/entry/impureFunctionsAny.generated.js +73 -48
  264. package/lib/esm/entry/impureFunctionsNumber.generated.js +81 -58
  265. package/lib/esm/entry/pureFunctionsAny.generated.js +39 -36
  266. package/lib/esm/entry/pureFunctionsNumber.generated.js +14 -13
  267. package/lib/esm/expression/embeddedDocs/embeddedDocs.js +2 -0
  268. package/lib/esm/expression/embeddedDocs/function/algebra/simplifyConstant.js +8 -0
  269. package/lib/esm/expression/embeddedDocs/function/algebra/simplifyCore.js +1 -1
  270. package/lib/esm/expression/node/AccessorNode.js +158 -153
  271. package/lib/esm/expression/node/ArrayNode.js +162 -154
  272. package/lib/esm/expression/node/AssignmentNode.js +257 -245
  273. package/lib/esm/expression/node/BlockNode.js +177 -163
  274. package/lib/esm/expression/node/ConditionalNode.js +197 -174
  275. package/lib/esm/expression/node/ConstantNode.js +171 -163
  276. package/lib/esm/expression/node/FunctionAssignmentNode.js +205 -180
  277. package/lib/esm/expression/node/FunctionNode.js +407 -407
  278. package/lib/esm/expression/node/IndexNode.js +206 -198
  279. package/lib/esm/expression/node/Node.js +325 -325
  280. package/lib/esm/expression/node/ObjectNode.js +166 -157
  281. package/lib/esm/expression/node/OperatorNode.js +414 -377
  282. package/lib/esm/expression/node/ParenthesisNode.js +146 -138
  283. package/lib/esm/expression/node/RangeNode.js +221 -212
  284. package/lib/esm/expression/node/RelationalNode.js +190 -176
  285. package/lib/esm/expression/node/SymbolNode.js +161 -152
  286. package/lib/esm/expression/operators.js +96 -4
  287. package/lib/esm/expression/parse.js +25 -7
  288. package/lib/esm/expression/transform/std.transform.js +3 -1
  289. package/lib/esm/factoriesAny.js +1 -0
  290. package/lib/esm/factoriesNumber.js +1 -0
  291. package/lib/esm/function/algebra/derivative.js +25 -33
  292. package/lib/esm/function/algebra/leafCount.js +0 -3
  293. package/lib/esm/function/algebra/rationalize.js +83 -114
  294. package/lib/esm/function/algebra/resolve.js +25 -16
  295. package/lib/esm/function/algebra/simplify.js +85 -113
  296. package/lib/esm/function/algebra/{simplify/simplifyConstant.js → simplifyConstant.js} +39 -9
  297. package/lib/esm/function/algebra/simplifyCore.js +192 -91
  298. package/lib/esm/function/algebra/symbolicEqual.js +14 -32
  299. package/lib/esm/function/arithmetic/abs.js +3 -16
  300. package/lib/esm/function/arithmetic/add.js +21 -65
  301. package/lib/esm/function/arithmetic/addScalar.js +11 -5
  302. package/lib/esm/function/arithmetic/cbrt.js +7 -10
  303. package/lib/esm/function/arithmetic/ceil.js +25 -25
  304. package/lib/esm/function/arithmetic/cube.js +5 -9
  305. package/lib/esm/function/arithmetic/divide.js +7 -7
  306. package/lib/esm/function/arithmetic/divideScalar.js +2 -19
  307. package/lib/esm/function/arithmetic/dotDivide.js +22 -64
  308. package/lib/esm/function/arithmetic/dotMultiply.js +16 -60
  309. package/lib/esm/function/arithmetic/dotPow.js +30 -62
  310. package/lib/esm/function/arithmetic/exp.js +8 -11
  311. package/lib/esm/function/arithmetic/expm1.js +10 -9
  312. package/lib/esm/function/arithmetic/fix.js +18 -18
  313. package/lib/esm/function/arithmetic/floor.js +26 -26
  314. package/lib/esm/function/arithmetic/gcd.js +26 -70
  315. package/lib/esm/function/arithmetic/hypot.js +7 -6
  316. package/lib/esm/function/arithmetic/invmod.js +1 -1
  317. package/lib/esm/function/arithmetic/lcm.js +26 -70
  318. package/lib/esm/function/arithmetic/log.js +7 -10
  319. package/lib/esm/function/arithmetic/log10.js +1 -3
  320. package/lib/esm/function/arithmetic/log1p.js +4 -6
  321. package/lib/esm/function/arithmetic/log2.js +1 -3
  322. package/lib/esm/function/arithmetic/mod.js +21 -62
  323. package/lib/esm/function/arithmetic/multiply.js +23 -27
  324. package/lib/esm/function/arithmetic/multiplyScalar.js +2 -13
  325. package/lib/esm/function/arithmetic/norm.js +0 -4
  326. package/lib/esm/function/arithmetic/nthRoot.js +41 -76
  327. package/lib/esm/function/arithmetic/nthRoots.js +2 -2
  328. package/lib/esm/function/arithmetic/round.js +26 -28
  329. package/lib/esm/function/arithmetic/sign.js +5 -7
  330. package/lib/esm/function/arithmetic/sqrt.js +5 -8
  331. package/lib/esm/function/arithmetic/square.js +6 -9
  332. package/lib/esm/function/arithmetic/subtract.js +31 -95
  333. package/lib/esm/function/arithmetic/unaryMinus.js +6 -16
  334. package/lib/esm/function/arithmetic/unaryPlus.js +2 -4
  335. package/lib/esm/function/bitwise/bitAnd.js +16 -59
  336. package/lib/esm/function/bitwise/bitNot.js +2 -4
  337. package/lib/esm/function/bitwise/bitOr.js +16 -59
  338. package/lib/esm/function/bitwise/bitXor.js +16 -59
  339. package/lib/esm/function/bitwise/leftShift.js +39 -61
  340. package/lib/esm/function/bitwise/rightArithShift.js +39 -61
  341. package/lib/esm/function/bitwise/rightLogShift.js +39 -61
  342. package/lib/esm/function/bitwise/useMatrixForArrayScalar.js +13 -0
  343. package/lib/esm/function/complex/arg.js +1 -3
  344. package/lib/esm/function/complex/conj.js +3 -12
  345. package/lib/esm/function/complex/im.js +4 -15
  346. package/lib/esm/function/complex/re.js +3 -15
  347. package/lib/esm/function/geometry/distance.js +2 -2
  348. package/lib/esm/function/logical/and.js +35 -57
  349. package/lib/esm/function/logical/not.js +3 -6
  350. package/lib/esm/function/logical/or.js +16 -61
  351. package/lib/esm/function/logical/xor.js +16 -61
  352. package/lib/esm/function/matrix/diff.js +3 -8
  353. package/lib/esm/function/matrix/ones.js +2 -1
  354. package/lib/esm/function/matrix/rotate.js +5 -5
  355. package/lib/esm/function/matrix/sqrtm.js +3 -2
  356. package/lib/esm/function/matrix/transpose.js +47 -50
  357. package/lib/esm/function/matrix/zeros.js +2 -1
  358. package/lib/esm/function/probability/factorial.js +1 -3
  359. package/lib/esm/function/probability/gamma.js +38 -39
  360. package/lib/esm/function/probability/kldivergence.js +3 -2
  361. package/lib/esm/function/probability/lgamma.js +29 -29
  362. package/lib/esm/function/relational/compare.js +21 -67
  363. package/lib/esm/function/relational/compareNatural.js +54 -49
  364. package/lib/esm/function/relational/compareText.js +10 -42
  365. package/lib/esm/function/relational/compareUnits.js +15 -0
  366. package/lib/esm/function/relational/equal.js +19 -79
  367. package/lib/esm/function/relational/equalScalar.js +6 -9
  368. package/lib/esm/function/relational/larger.js +23 -73
  369. package/lib/esm/function/relational/largerEq.js +23 -73
  370. package/lib/esm/function/relational/smaller.js +23 -73
  371. package/lib/esm/function/relational/smallerEq.js +23 -73
  372. package/lib/esm/function/relational/unequal.js +19 -79
  373. package/lib/esm/function/special/erf.js +1 -3
  374. package/lib/esm/function/statistics/std.js +10 -2
  375. package/lib/esm/function/string/format.js +2 -2
  376. package/lib/esm/function/string/hex.js +1 -2
  377. package/lib/esm/function/trigonometry/acos.js +4 -7
  378. package/lib/esm/function/trigonometry/acosh.js +2 -6
  379. package/lib/esm/function/trigonometry/acot.js +6 -10
  380. package/lib/esm/function/trigonometry/acoth.js +4 -7
  381. package/lib/esm/function/trigonometry/acsc.js +6 -10
  382. package/lib/esm/function/trigonometry/acsch.js +4 -7
  383. package/lib/esm/function/trigonometry/asec.js +6 -9
  384. package/lib/esm/function/trigonometry/asech.js +4 -7
  385. package/lib/esm/function/trigonometry/asin.js +5 -9
  386. package/lib/esm/function/trigonometry/asinh.js +4 -8
  387. package/lib/esm/function/trigonometry/atan.js +5 -10
  388. package/lib/esm/function/trigonometry/atan2.js +26 -65
  389. package/lib/esm/function/trigonometry/atanh.js +4 -8
  390. package/lib/esm/function/trigonometry/cos.js +11 -22
  391. package/lib/esm/function/trigonometry/cosh.js +5 -20
  392. package/lib/esm/function/trigonometry/cot.js +10 -20
  393. package/lib/esm/function/trigonometry/coth.js +6 -20
  394. package/lib/esm/function/trigonometry/csc.js +12 -22
  395. package/lib/esm/function/trigonometry/csch.js +6 -20
  396. package/lib/esm/function/trigonometry/sec.js +12 -22
  397. package/lib/esm/function/trigonometry/sech.js +6 -20
  398. package/lib/esm/function/trigonometry/sin.js +11 -23
  399. package/lib/esm/function/trigonometry/sinh.js +5 -21
  400. package/lib/esm/function/trigonometry/tan.js +11 -23
  401. package/lib/esm/function/trigonometry/tanh.js +5 -21
  402. package/lib/esm/function/trigonometry/trigUnit.js +15 -0
  403. package/lib/esm/function/unit/to.js +8 -43
  404. package/lib/esm/function/utils/clone.js +1 -1
  405. package/lib/esm/function/utils/hasNumericValue.js +3 -1
  406. package/lib/esm/function/utils/isInteger.js +2 -4
  407. package/lib/esm/function/utils/isNaN.js +1 -1
  408. package/lib/esm/function/utils/isNegative.js +3 -7
  409. package/lib/esm/function/utils/isNumeric.js +4 -10
  410. package/lib/esm/function/utils/isPositive.js +3 -7
  411. package/lib/esm/function/utils/isPrime.js +1 -3
  412. package/lib/esm/function/utils/isZero.js +13 -17
  413. package/lib/esm/function/utils/numeric.js +11 -4
  414. package/lib/esm/function/utils/typeOf.js +38 -44
  415. package/lib/esm/type/bignumber/function/bignumber.js +1 -3
  416. package/lib/esm/type/boolean.js +1 -3
  417. package/lib/esm/type/chain/Chain.js +23 -3
  418. package/lib/esm/type/complex/Complex.js +4 -0
  419. package/lib/esm/type/complex/function/complex.js +1 -3
  420. package/lib/esm/type/fraction/Fraction.js +4 -0
  421. package/lib/esm/type/fraction/function/fraction.js +1 -3
  422. package/lib/esm/type/matrix/DenseMatrix.js +15 -1
  423. package/lib/esm/type/matrix/SparseMatrix.js +9 -0
  424. package/lib/esm/type/matrix/utils/{algorithm01.js → matAlgo01xDSid.js} +2 -2
  425. package/lib/esm/type/matrix/utils/{algorithm02.js → matAlgo02xDS0.js} +3 -3
  426. package/lib/esm/type/matrix/utils/{algorithm03.js → matAlgo03xDSf.js} +3 -3
  427. package/lib/esm/type/matrix/utils/{algorithm04.js → matAlgo04xSidSid.js} +5 -5
  428. package/lib/esm/type/matrix/utils/{algorithm05.js → matAlgo05xSfSf.js} +3 -3
  429. package/lib/esm/type/matrix/utils/{algorithm06.js → matAlgo06xS0S0.js} +3 -3
  430. package/lib/esm/type/matrix/utils/{algorithm07.js → matAlgo07xSSf.js} +3 -3
  431. package/lib/esm/type/matrix/utils/{algorithm08.js → matAlgo08xS0Sid.js} +4 -4
  432. package/lib/esm/type/matrix/utils/{algorithm09.js → matAlgo09xS0Sf.js} +3 -3
  433. package/lib/esm/type/matrix/utils/{algorithm10.js → matAlgo10xSids.js} +3 -3
  434. package/lib/esm/type/matrix/utils/{algorithm11.js → matAlgo11xS0s.js} +3 -3
  435. package/lib/esm/type/matrix/utils/{algorithm12.js → matAlgo12xSfs.js} +3 -3
  436. package/lib/esm/type/matrix/utils/{algorithm13.js → matAlgo13xDD.js} +3 -3
  437. package/lib/esm/type/matrix/utils/{algorithm14.js → matAlgo14xDs.js} +3 -3
  438. package/lib/esm/type/matrix/utils/matrixAlgorithmSuite.js +168 -0
  439. package/lib/esm/type/number.js +1 -3
  440. package/lib/esm/type/string.js +1 -3
  441. package/lib/esm/type/unit/Unit.js +61 -13
  442. package/lib/esm/type/unit/function/createUnit.js +2 -1
  443. package/lib/esm/type/unit/function/unit.js +5 -3
  444. package/lib/esm/utils/is.js +18 -18
  445. package/lib/esm/utils/snapshot.js +22 -48
  446. package/lib/esm/version.js +1 -1
  447. package/package.json +21 -24
  448. package/types/index.d.ts +215 -183
  449. package/types/index.ts +358 -144
  450. package/lib/cjs/utils/polyfills.js +0 -14
  451. 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
- * @constructor OperatorNode
29
- * @extends {Node}
30
- * An operator with two arguments, like 2+3
31
- *
32
- * @param {string} op Operator name, for example '+'
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
- OperatorNode.prototype._compile = function (math, argNames) {
81
- // validate fn
82
- if (typeof this.fn !== 'string' || !(0, _customs.isSafeMethod)(math, this.fn)) {
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
- var fn = (0, _customs.getSafeProperty)(math, this.fn);
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
- OperatorNode.prototype.map = function (callback) {
134
- var args = [];
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 new OperatorNode(this.op, this.fn, args, this.implicit, this.isPercentage);
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
- } // handles an edge case of 'auto' parentheses with implicit multiplication of ConstantNode
375
- // In that case print parentheses for ParenthesisNodes even though they normally wouldn't be
376
- // printed.
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
- if (result[index] || isParenthesisNode) {
384
- // put in parenthesis?
385
- return true;
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
- if (args.length === 1) {
408
- // unary operators
409
- var assoc = (0, _operators.getAssociativity)(this, parenthesis);
410
- var operand = args[0].toString(options);
411
-
412
- if (parens[0]) {
413
- operand = '(' + operand + ')';
414
- } // for example for "not", we want a space between operand and argument
415
-
416
-
417
- var opIsNamed = /[a-zA-Z]+/.test(this.op);
418
-
419
- if (assoc === 'right') {
420
- // prefix operator
421
- return this.op + (opIsNamed ? ' ' : '') + operand;
422
- } else if (assoc === 'left') {
423
- // postfix
424
- return operand + (opIsNamed ? ' ' : '') + this.op;
425
- } // fall back to postfix
426
-
427
-
428
- return operand + this.op;
429
- } else if (args.length === 2) {
430
- var lhs = args[0].toString(options); // left hand side
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 (parens[1]) {
440
- // right hand side in parenthesis?
441
- rhs = '(' + rhs + ')';
315
+ if (typeof fn !== 'string') {
316
+ throw new TypeError('string expected for parameter "fn"');
442
317
  }
443
318
 
444
- if (this.implicit && this.getIdentifier() === 'OperatorNode:multiply' && implicit === 'hide') {
445
- return lhs + ' ' + rhs;
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
- return lhs + ' ' + this.op + ' ' + rhs;
449
- } else if (args.length > 2 && (this.getIdentifier() === 'OperatorNode:add' || this.getIdentifier() === 'OperatorNode:multiply')) {
450
- var stringifiedArgs = args.map(function (arg, index) {
451
- arg = arg.toString(options);
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
- if (parens[index]) {
454
- // put in parenthesis?
455
- arg = '(' + arg + ')';
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
- return arg;
459
- });
460
-
461
- if (this.implicit && this.getIdentifier() === 'OperatorNode:multiply' && implicit === 'hide') {
462
- return stringifiedArgs.join(' ');
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
- return stringifiedArgs.join(' ' + this.op + ' ');
466
- } else {
467
- // fallback to formatting as a function call
468
- return this.fn + '(' + this.args.join(', ') + ')';
469
- }
470
- };
471
- /**
472
- * Get a JSON representation of the node
473
- * @returns {Object}
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
- OperatorNode.prototype.toJSON = function () {
478
- return {
479
- mathjs: 'OperatorNode',
480
- op: this.op,
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
- OperatorNode.fromJSON = function (json) {
497
- return new OperatorNode(json.op, json.fn, json.args, json.implicit, json.isPercentage);
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
- OperatorNode.prototype.toHTML = function (options) {
507
- var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
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
- if (args.length === 1) {
513
- // unary operators
514
- var assoc = (0, _operators.getAssociativity)(this, parenthesis);
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
- if (parens[0]) {
518
- operand = '<span class="math-parenthesis math-round-parenthesis">(</span>' + operand + '<span class="math-parenthesis math-round-parenthesis">)</span>';
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
- if (assoc === 'right') {
522
- // prefix operator
523
- return '<span class="math-operator math-unary-operator math-lefthand-unary-operator">' + (0, _string.escape)(this.op) + '</span>' + operand;
524
- } else {
525
- // postfix when assoc === 'left' or undefined
526
- return operand + '<span class="math-operator math-unary-operator math-righthand-unary-operator">' + (0, _string.escape)(this.op) + '</span>';
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
- } else if (args.length === 2) {
529
- // binary operatoes
530
- var lhs = args[0].toHTML(options); // left hand side
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
- var rhs = args[1].toHTML(options); // right hand side
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
- if (parens[0]) {
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
- if (parens[1]) {
540
- // right hand side in parenthesis?
541
- rhs = '<span class="math-parenthesis math-round-parenthesis">(</span>' + rhs + '<span class="math-parenthesis math-round-parenthesis">)</span>';
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
- if (this.implicit && this.getIdentifier() === 'OperatorNode:multiply' && implicit === 'hide') {
545
- return lhs + '<span class="math-operator math-binary-operator math-implicit-binary-operator"></span>' + rhs;
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
- return lhs + '<span class="math-operator math-binary-operator math-explicit-binary-operator">' + (0, _string.escape)(this.op) + '</span>' + rhs;
549
- } else {
550
- var stringifiedArgs = args.map(function (arg, index) {
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
- if (parens[index]) {
554
- // put in parenthesis?
555
- arg = '<span class="math-parenthesis math-round-parenthesis">(</span>' + arg + '<span class="math-parenthesis math-round-parenthesis">)</span>';
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
- return arg;
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
- if (args.length > 2 && (this.getIdentifier() === 'OperatorNode:add' || this.getIdentifier() === 'OperatorNode:multiply')) {
562
- if (this.implicit && this.getIdentifier() === 'OperatorNode:multiply' && implicit === 'hide') {
563
- return stringifiedArgs.join('<span class="math-operator math-binary-operator math-implicit-binary-operator"></span>');
564
- }
624
+ return arg;
625
+ });
565
626
 
566
- return stringifiedArgs.join('<span class="math-operator math-binary-operator math-explicit-binary-operator">' + (0, _string.escape)(this.op) + '</span>');
567
- } else {
568
- // fallback to formatting as a function call
569
- 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>';
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
- OperatorNode.prototype._toTex = function (options) {
581
- var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
582
- var implicit = options && options.implicit ? options.implicit : 'hide';
583
- var args = this.args;
584
- var parens = calculateNecessaryParentheses(this, parenthesis, implicit, args, true);
585
- var op = _latex.latexOperators[this.fn];
586
- op = typeof op === 'undefined' ? this.op : op; // fall back to using this.op
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
- if (parens[0]) {
594
- operand = "\\left(".concat(operand, "\\right)");
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
- if (assoc === 'right') {
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
- return operand + op;
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
- var lhsTex = lhs.toTex(options);
686
+ var rhsTex = rhs.toTex(options);
612
687
 
613
- if (parens[0]) {
614
- lhsTex = "\\left(".concat(lhsTex, "\\right)");
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
- var rhsTex = rhs.toTex(options);
693
+ var lhsIdentifier;
620
694
 
621
- if (parens[1]) {
622
- rhsTex = "\\left(".concat(rhsTex, "\\right)");
623
- } // handle some exceptions (due to the way LaTeX works)
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
- var lhsIdentifier;
707
+ case 'OperatorNode:pow':
708
+ lhsTex = '{' + lhsTex + '}';
709
+ rhsTex = '{' + rhsTex + '}';
627
710
 
628
- if (parenthesis === 'keep') {
629
- lhsIdentifier = lhs.getIdentifier();
630
- } else {
631
- // Ignore ParenthesisNodes if in 'keep' mode
632
- lhsIdentifier = lhs.getContent().getIdentifier();
633
- }
711
+ switch (lhsIdentifier) {
712
+ case 'ConditionalNode': //
634
713
 
635
- switch (this.getIdentifier()) {
636
- case 'OperatorNode:divide':
637
- // op contains '\\frac' at this point
638
- return op + '{' + lhsTex + '}' + '{' + rhsTex + '}';
714
+ case 'OperatorNode:divide':
715
+ lhsTex = "\\left(".concat(lhsTex, "\\right)");
716
+ }
639
717
 
640
- case 'OperatorNode:pow':
641
- lhsTex = '{' + lhsTex + '}';
642
- rhsTex = '{' + rhsTex + '}';
718
+ break;
643
719
 
644
- switch (lhsIdentifier) {
645
- case 'ConditionalNode': //
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
- break;
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
- case 'OperatorNode:multiply':
654
- if (this.implicit && implicit === 'hide') {
655
- return lhsTex + '~' + rhsTex;
656
- }
732
+ if (parens[index]) {
733
+ arg = "\\left(".concat(arg, "\\right)");
734
+ }
657
735
 
658
- }
736
+ return arg;
737
+ });
659
738
 
660
- return lhsTex + op + rhsTex;
661
- } else if (args.length > 2 && (this.getIdentifier() === 'OperatorNode:add' || this.getIdentifier() === 'OperatorNode:multiply')) {
662
- var texifiedArgs = args.map(function (arg, index) {
663
- arg = arg.toTex(options);
739
+ if (this.getIdentifier() === 'OperatorNode:multiply' && this.implicit && implicit === 'hide') {
740
+ return texifiedArgs.join('~');
741
+ }
664
742
 
665
- if (parens[index]) {
666
- arg = "\\left(".concat(arg, "\\right)");
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
- return texifiedArgs.join(op);
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,