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.
Files changed (436) 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 +22 -30
  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 +87 -114
  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 +9 -26
  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 +33 -27
  90. package/lib/cjs/function/arithmetic/floor.js +56 -46
  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 +1 -1
  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 +80 -92
  104. package/lib/cjs/function/arithmetic/round.js +56 -42
  105. package/lib/cjs/function/arithmetic/sign.js +14 -10
  106. package/lib/cjs/function/arithmetic/sqrt.js +5 -9
  107. package/lib/cjs/function/arithmetic/square.js +6 -10
  108. package/lib/cjs/function/arithmetic/subtract.js +44 -100
  109. package/lib/cjs/function/arithmetic/unaryMinus.js +14 -16
  110. package/lib/cjs/function/arithmetic/unaryPlus.js +6 -4
  111. package/lib/cjs/function/bitwise/bitAnd.js +17 -61
  112. package/lib/cjs/function/bitwise/bitNot.js +5 -3
  113. package/lib/cjs/function/bitwise/bitOr.js +16 -60
  114. package/lib/cjs/function/bitwise/bitXor.js +17 -61
  115. package/lib/cjs/function/bitwise/leftShift.js +68 -81
  116. package/lib/cjs/function/bitwise/rightArithShift.js +68 -81
  117. package/lib/cjs/function/bitwise/rightLogShift.js +68 -81
  118. package/lib/cjs/function/bitwise/useMatrixForArrayScalar.js +36 -0
  119. package/lib/cjs/function/complex/arg.js +5 -3
  120. package/lib/cjs/function/complex/conj.js +6 -7
  121. package/lib/cjs/function/complex/im.js +7 -8
  122. package/lib/cjs/function/complex/re.js +6 -10
  123. package/lib/cjs/function/logical/and.js +74 -80
  124. package/lib/cjs/function/logical/not.js +13 -6
  125. package/lib/cjs/function/logical/or.js +21 -63
  126. package/lib/cjs/function/logical/xor.js +21 -63
  127. package/lib/cjs/function/matrix/diff.js +10 -7
  128. package/lib/cjs/function/matrix/eigs/complexEigs.js +5 -5
  129. package/lib/cjs/function/matrix/fft.js +2 -2
  130. package/lib/cjs/function/matrix/matrixFromColumns.js +1 -1
  131. package/lib/cjs/function/matrix/matrixFromRows.js +1 -1
  132. package/lib/cjs/function/matrix/ones.js +2 -1
  133. package/lib/cjs/function/matrix/sqrtm.js +3 -2
  134. package/lib/cjs/function/matrix/transpose.js +47 -48
  135. package/lib/cjs/function/matrix/zeros.js +2 -1
  136. package/lib/cjs/function/probability/factorial.js +5 -3
  137. package/lib/cjs/function/probability/gamma.js +38 -40
  138. package/lib/cjs/function/probability/kldivergence.js +5 -2
  139. package/lib/cjs/function/probability/lgamma.js +30 -30
  140. package/lib/cjs/function/probability/util/seededRNG.js +2 -2
  141. package/lib/cjs/function/relational/compare.js +21 -67
  142. package/lib/cjs/function/relational/compareNatural.js +59 -54
  143. package/lib/cjs/function/relational/compareText.js +10 -43
  144. package/lib/cjs/function/relational/compareUnits.js +24 -0
  145. package/lib/cjs/function/relational/equal.js +19 -80
  146. package/lib/cjs/function/relational/equalScalar.js +7 -9
  147. package/lib/cjs/function/relational/larger.js +21 -67
  148. package/lib/cjs/function/relational/largerEq.js +21 -67
  149. package/lib/cjs/function/relational/smaller.js +21 -67
  150. package/lib/cjs/function/relational/smallerEq.js +21 -67
  151. package/lib/cjs/function/relational/unequal.js +19 -80
  152. package/lib/cjs/function/special/erf.js +5 -3
  153. package/lib/cjs/function/statistics/std.js +11 -2
  154. package/lib/cjs/function/trigonometry/acos.js +4 -8
  155. package/lib/cjs/function/trigonometry/acosh.js +2 -7
  156. package/lib/cjs/function/trigonometry/acot.js +4 -8
  157. package/lib/cjs/function/trigonometry/acoth.js +4 -8
  158. package/lib/cjs/function/trigonometry/acsc.js +4 -8
  159. package/lib/cjs/function/trigonometry/acsch.js +4 -8
  160. package/lib/cjs/function/trigonometry/asec.js +4 -8
  161. package/lib/cjs/function/trigonometry/asech.js +4 -8
  162. package/lib/cjs/function/trigonometry/asin.js +4 -9
  163. package/lib/cjs/function/trigonometry/asinh.js +4 -9
  164. package/lib/cjs/function/trigonometry/atan.js +4 -9
  165. package/lib/cjs/function/trigonometry/atan2.js +24 -62
  166. package/lib/cjs/function/trigonometry/atanh.js +4 -9
  167. package/lib/cjs/function/trigonometry/cos.js +11 -20
  168. package/lib/cjs/function/trigonometry/cosh.js +5 -19
  169. package/lib/cjs/function/trigonometry/cot.js +9 -15
  170. package/lib/cjs/function/trigonometry/coth.js +4 -15
  171. package/lib/cjs/function/trigonometry/csc.js +11 -17
  172. package/lib/cjs/function/trigonometry/csch.js +4 -15
  173. package/lib/cjs/function/trigonometry/sec.js +11 -17
  174. package/lib/cjs/function/trigonometry/sech.js +4 -15
  175. package/lib/cjs/function/trigonometry/sin.js +11 -21
  176. package/lib/cjs/function/trigonometry/sinh.js +5 -20
  177. package/lib/cjs/function/trigonometry/tan.js +11 -21
  178. package/lib/cjs/function/trigonometry/tanh.js +5 -20
  179. package/lib/cjs/function/trigonometry/trigUnit.js +24 -0
  180. package/lib/cjs/function/unit/to.js +7 -41
  181. package/lib/cjs/function/utils/hasNumericValue.js +4 -0
  182. package/lib/cjs/function/utils/isInteger.js +5 -3
  183. package/lib/cjs/function/utils/isNegative.js +10 -6
  184. package/lib/cjs/function/utils/isNumeric.js +5 -3
  185. package/lib/cjs/function/utils/isPositive.js +10 -6
  186. package/lib/cjs/function/utils/isPrime.js +5 -3
  187. package/lib/cjs/function/utils/isZero.js +10 -6
  188. package/lib/cjs/function/utils/numeric.js +11 -4
  189. package/lib/cjs/function/utils/typeOf.js +38 -44
  190. package/lib/cjs/header.js +2 -2
  191. package/lib/cjs/plain/bignumber/index.js +1 -1
  192. package/lib/cjs/type/bignumber/BigNumber.js +2 -2
  193. package/lib/cjs/type/bignumber/function/bignumber.js +6 -4
  194. package/lib/cjs/type/boolean.js +7 -5
  195. package/lib/cjs/type/chain/Chain.js +23 -3
  196. package/lib/cjs/type/complex/Complex.js +18 -14
  197. package/lib/cjs/type/complex/function/complex.js +6 -4
  198. package/lib/cjs/type/fraction/Fraction.js +10 -6
  199. package/lib/cjs/type/fraction/function/fraction.js +6 -4
  200. package/lib/cjs/type/matrix/DenseMatrix.js +21 -6
  201. package/lib/cjs/type/matrix/SparseMatrix.js +12 -2
  202. package/lib/cjs/type/matrix/utils/{algorithm01.js → matAlgo01xDSid.js} +4 -4
  203. package/lib/cjs/type/matrix/utils/{algorithm02.js → matAlgo02xDS0.js} +5 -5
  204. package/lib/cjs/type/matrix/utils/{algorithm03.js → matAlgo03xDSf.js} +5 -5
  205. package/lib/cjs/type/matrix/utils/{algorithm04.js → matAlgo04xSidSid.js} +7 -7
  206. package/lib/cjs/type/matrix/utils/{algorithm05.js → matAlgo05xSfSf.js} +5 -5
  207. package/lib/cjs/type/matrix/utils/{algorithm06.js → matAlgo06xS0S0.js} +5 -5
  208. package/lib/cjs/type/matrix/utils/{algorithm07.js → matAlgo07xSSf.js} +5 -5
  209. package/lib/cjs/type/matrix/utils/{algorithm08.js → matAlgo08xS0Sid.js} +6 -6
  210. package/lib/cjs/type/matrix/utils/{algorithm09.js → matAlgo09xS0Sf.js} +5 -5
  211. package/lib/cjs/type/matrix/utils/{algorithm10.js → matAlgo10xSids.js} +5 -5
  212. package/lib/cjs/type/matrix/utils/{algorithm11.js → matAlgo11xS0s.js} +5 -5
  213. package/lib/cjs/type/matrix/utils/{algorithm12.js → matAlgo12xSfs.js} +5 -5
  214. package/lib/cjs/type/matrix/utils/{algorithm13.js → matAlgo13xDD.js} +5 -5
  215. package/lib/cjs/type/matrix/utils/{algorithm14.js → matAlgo14xDs.js} +5 -5
  216. package/lib/cjs/type/matrix/utils/matrixAlgorithmSuite.js +238 -0
  217. package/lib/cjs/type/number.js +6 -4
  218. package/lib/cjs/type/string.js +7 -5
  219. package/lib/cjs/type/unit/Unit.js +69 -21
  220. package/lib/cjs/type/unit/function/createUnit.js +2 -1
  221. package/lib/cjs/type/unit/function/unit.js +9 -3
  222. package/lib/cjs/utils/customs.js +2 -2
  223. package/lib/cjs/utils/emitter.js +1 -1
  224. package/lib/cjs/utils/function.js +2 -2
  225. package/lib/cjs/utils/is.js +27 -25
  226. package/lib/cjs/utils/latex.js +3 -3
  227. package/lib/cjs/utils/lruQueue.js +1 -1
  228. package/lib/cjs/utils/map.js +3 -3
  229. package/lib/cjs/utils/object.js +2 -2
  230. package/lib/cjs/utils/snapshot.js +30 -57
  231. package/lib/cjs/utils/string.js +3 -3
  232. package/lib/cjs/version.js +1 -1
  233. package/lib/esm/core/create.js +2 -1
  234. package/lib/esm/core/function/import.js +2 -12
  235. package/lib/esm/core/function/typed.js +47 -11
  236. package/lib/esm/entry/dependenciesAny/dependenciesChainClass.generated.js +2 -0
  237. package/lib/esm/entry/dependenciesAny/dependenciesKldivergence.generated.js +2 -0
  238. package/lib/esm/entry/dependenciesAny/dependenciesRationalize.generated.js +2 -0
  239. package/lib/esm/entry/dependenciesAny/dependenciesResolve.generated.js +2 -0
  240. package/lib/esm/entry/dependenciesAny/dependenciesSimplify.generated.js +2 -0
  241. package/lib/esm/entry/dependenciesAny/dependenciesSimplifyConstant.generated.js +34 -0
  242. package/lib/esm/entry/dependenciesAny/dependenciesSimplifyCore.generated.js +4 -0
  243. package/lib/esm/entry/dependenciesAny/dependenciesSqrtm.generated.js +2 -0
  244. package/lib/esm/entry/dependenciesAny/dependenciesStd.generated.js +2 -0
  245. package/lib/esm/entry/dependenciesAny/dependenciesStdTransform.generated.js +2 -0
  246. package/lib/esm/entry/dependenciesAny.generated.js +1 -0
  247. package/lib/esm/entry/dependenciesNumber/dependenciesChainClass.generated.js +2 -0
  248. package/lib/esm/entry/dependenciesNumber/dependenciesRationalize.generated.js +2 -0
  249. package/lib/esm/entry/dependenciesNumber/dependenciesResolve.generated.js +2 -0
  250. package/lib/esm/entry/dependenciesNumber/dependenciesSimplify.generated.js +2 -0
  251. package/lib/esm/entry/dependenciesNumber/dependenciesSimplifyConstant.generated.js +30 -0
  252. package/lib/esm/entry/dependenciesNumber/dependenciesSimplifyCore.generated.js +4 -0
  253. package/lib/esm/entry/dependenciesNumber/dependenciesStd.generated.js +2 -0
  254. package/lib/esm/entry/dependenciesNumber/dependenciesStdTransform.generated.js +2 -0
  255. package/lib/esm/entry/dependenciesNumber.generated.js +1 -0
  256. package/lib/esm/entry/impureFunctionsAny.generated.js +73 -48
  257. package/lib/esm/entry/impureFunctionsNumber.generated.js +81 -58
  258. package/lib/esm/entry/pureFunctionsAny.generated.js +39 -36
  259. package/lib/esm/entry/pureFunctionsNumber.generated.js +14 -13
  260. package/lib/esm/expression/embeddedDocs/embeddedDocs.js +2 -0
  261. package/lib/esm/expression/embeddedDocs/function/algebra/simplifyConstant.js +8 -0
  262. package/lib/esm/expression/embeddedDocs/function/algebra/simplifyCore.js +1 -1
  263. package/lib/esm/expression/node/AccessorNode.js +158 -153
  264. package/lib/esm/expression/node/ArrayNode.js +162 -154
  265. package/lib/esm/expression/node/AssignmentNode.js +257 -245
  266. package/lib/esm/expression/node/BlockNode.js +177 -163
  267. package/lib/esm/expression/node/ConditionalNode.js +197 -174
  268. package/lib/esm/expression/node/ConstantNode.js +171 -163
  269. package/lib/esm/expression/node/FunctionAssignmentNode.js +205 -180
  270. package/lib/esm/expression/node/FunctionNode.js +407 -407
  271. package/lib/esm/expression/node/IndexNode.js +206 -198
  272. package/lib/esm/expression/node/Node.js +325 -325
  273. package/lib/esm/expression/node/ObjectNode.js +166 -157
  274. package/lib/esm/expression/node/OperatorNode.js +414 -377
  275. package/lib/esm/expression/node/ParenthesisNode.js +146 -138
  276. package/lib/esm/expression/node/RangeNode.js +221 -212
  277. package/lib/esm/expression/node/RelationalNode.js +190 -176
  278. package/lib/esm/expression/node/SymbolNode.js +161 -152
  279. package/lib/esm/expression/operators.js +96 -4
  280. package/lib/esm/expression/parse.js +25 -7
  281. package/lib/esm/expression/transform/std.transform.js +3 -1
  282. package/lib/esm/factoriesAny.js +1 -0
  283. package/lib/esm/factoriesNumber.js +1 -0
  284. package/lib/esm/function/algebra/derivative.js +22 -30
  285. package/lib/esm/function/algebra/leafCount.js +0 -3
  286. package/lib/esm/function/algebra/rationalize.js +83 -114
  287. package/lib/esm/function/algebra/resolve.js +25 -16
  288. package/lib/esm/function/algebra/simplify.js +82 -112
  289. package/lib/esm/function/algebra/{simplify/simplifyConstant.js → simplifyConstant.js} +39 -9
  290. package/lib/esm/function/algebra/simplifyCore.js +192 -91
  291. package/lib/esm/function/algebra/symbolicEqual.js +9 -26
  292. package/lib/esm/function/arithmetic/abs.js +3 -16
  293. package/lib/esm/function/arithmetic/add.js +21 -65
  294. package/lib/esm/function/arithmetic/addScalar.js +11 -5
  295. package/lib/esm/function/arithmetic/cbrt.js +7 -10
  296. package/lib/esm/function/arithmetic/ceil.js +25 -25
  297. package/lib/esm/function/arithmetic/cube.js +5 -9
  298. package/lib/esm/function/arithmetic/divide.js +7 -7
  299. package/lib/esm/function/arithmetic/divideScalar.js +2 -19
  300. package/lib/esm/function/arithmetic/dotDivide.js +22 -64
  301. package/lib/esm/function/arithmetic/dotMultiply.js +16 -60
  302. package/lib/esm/function/arithmetic/dotPow.js +30 -62
  303. package/lib/esm/function/arithmetic/exp.js +8 -11
  304. package/lib/esm/function/arithmetic/expm1.js +10 -9
  305. package/lib/esm/function/arithmetic/fix.js +17 -17
  306. package/lib/esm/function/arithmetic/floor.js +25 -25
  307. package/lib/esm/function/arithmetic/gcd.js +26 -70
  308. package/lib/esm/function/arithmetic/hypot.js +7 -6
  309. package/lib/esm/function/arithmetic/lcm.js +26 -70
  310. package/lib/esm/function/arithmetic/log.js +7 -10
  311. package/lib/esm/function/arithmetic/log10.js +1 -3
  312. package/lib/esm/function/arithmetic/log1p.js +4 -6
  313. package/lib/esm/function/arithmetic/log2.js +1 -3
  314. package/lib/esm/function/arithmetic/mod.js +21 -62
  315. package/lib/esm/function/arithmetic/multiply.js +23 -27
  316. package/lib/esm/function/arithmetic/multiplyScalar.js +2 -13
  317. package/lib/esm/function/arithmetic/norm.js +0 -4
  318. package/lib/esm/function/arithmetic/nthRoot.js +38 -73
  319. package/lib/esm/function/arithmetic/round.js +26 -28
  320. package/lib/esm/function/arithmetic/sign.js +5 -7
  321. package/lib/esm/function/arithmetic/sqrt.js +5 -8
  322. package/lib/esm/function/arithmetic/square.js +6 -9
  323. package/lib/esm/function/arithmetic/subtract.js +31 -95
  324. package/lib/esm/function/arithmetic/unaryMinus.js +6 -16
  325. package/lib/esm/function/arithmetic/unaryPlus.js +2 -4
  326. package/lib/esm/function/bitwise/bitAnd.js +16 -59
  327. package/lib/esm/function/bitwise/bitNot.js +1 -3
  328. package/lib/esm/function/bitwise/bitOr.js +16 -59
  329. package/lib/esm/function/bitwise/bitXor.js +16 -59
  330. package/lib/esm/function/bitwise/leftShift.js +38 -60
  331. package/lib/esm/function/bitwise/rightArithShift.js +38 -60
  332. package/lib/esm/function/bitwise/rightLogShift.js +38 -60
  333. package/lib/esm/function/bitwise/useMatrixForArrayScalar.js +13 -0
  334. package/lib/esm/function/complex/arg.js +1 -3
  335. package/lib/esm/function/complex/conj.js +3 -12
  336. package/lib/esm/function/complex/im.js +4 -15
  337. package/lib/esm/function/complex/re.js +3 -15
  338. package/lib/esm/function/logical/and.js +35 -57
  339. package/lib/esm/function/logical/not.js +3 -6
  340. package/lib/esm/function/logical/or.js +16 -61
  341. package/lib/esm/function/logical/xor.js +16 -61
  342. package/lib/esm/function/matrix/diff.js +2 -7
  343. package/lib/esm/function/matrix/ones.js +2 -1
  344. package/lib/esm/function/matrix/sqrtm.js +3 -2
  345. package/lib/esm/function/matrix/transpose.js +47 -50
  346. package/lib/esm/function/matrix/zeros.js +2 -1
  347. package/lib/esm/function/probability/factorial.js +1 -3
  348. package/lib/esm/function/probability/gamma.js +38 -39
  349. package/lib/esm/function/probability/kldivergence.js +3 -2
  350. package/lib/esm/function/probability/lgamma.js +29 -29
  351. package/lib/esm/function/relational/compare.js +21 -67
  352. package/lib/esm/function/relational/compareNatural.js +54 -49
  353. package/lib/esm/function/relational/compareText.js +10 -42
  354. package/lib/esm/function/relational/compareUnits.js +15 -0
  355. package/lib/esm/function/relational/equal.js +19 -79
  356. package/lib/esm/function/relational/equalScalar.js +6 -9
  357. package/lib/esm/function/relational/larger.js +23 -73
  358. package/lib/esm/function/relational/largerEq.js +23 -73
  359. package/lib/esm/function/relational/smaller.js +23 -73
  360. package/lib/esm/function/relational/smallerEq.js +23 -73
  361. package/lib/esm/function/relational/unequal.js +19 -79
  362. package/lib/esm/function/special/erf.js +1 -3
  363. package/lib/esm/function/statistics/std.js +10 -2
  364. package/lib/esm/function/trigonometry/acos.js +4 -7
  365. package/lib/esm/function/trigonometry/acosh.js +2 -6
  366. package/lib/esm/function/trigonometry/acot.js +4 -7
  367. package/lib/esm/function/trigonometry/acoth.js +4 -7
  368. package/lib/esm/function/trigonometry/acsc.js +4 -7
  369. package/lib/esm/function/trigonometry/acsch.js +4 -7
  370. package/lib/esm/function/trigonometry/asec.js +4 -7
  371. package/lib/esm/function/trigonometry/asech.js +4 -7
  372. package/lib/esm/function/trigonometry/asin.js +4 -8
  373. package/lib/esm/function/trigonometry/asinh.js +4 -8
  374. package/lib/esm/function/trigonometry/atan.js +4 -8
  375. package/lib/esm/function/trigonometry/atan2.js +25 -64
  376. package/lib/esm/function/trigonometry/atanh.js +4 -8
  377. package/lib/esm/function/trigonometry/cos.js +11 -22
  378. package/lib/esm/function/trigonometry/cosh.js +5 -20
  379. package/lib/esm/function/trigonometry/cot.js +10 -20
  380. package/lib/esm/function/trigonometry/coth.js +6 -20
  381. package/lib/esm/function/trigonometry/csc.js +12 -22
  382. package/lib/esm/function/trigonometry/csch.js +6 -20
  383. package/lib/esm/function/trigonometry/sec.js +12 -22
  384. package/lib/esm/function/trigonometry/sech.js +6 -20
  385. package/lib/esm/function/trigonometry/sin.js +11 -23
  386. package/lib/esm/function/trigonometry/sinh.js +5 -21
  387. package/lib/esm/function/trigonometry/tan.js +11 -23
  388. package/lib/esm/function/trigonometry/tanh.js +5 -21
  389. package/lib/esm/function/trigonometry/trigUnit.js +15 -0
  390. package/lib/esm/function/unit/to.js +8 -43
  391. package/lib/esm/function/utils/hasNumericValue.js +2 -0
  392. package/lib/esm/function/utils/isInteger.js +1 -3
  393. package/lib/esm/function/utils/isNegative.js +2 -6
  394. package/lib/esm/function/utils/isNumeric.js +3 -9
  395. package/lib/esm/function/utils/isPositive.js +2 -6
  396. package/lib/esm/function/utils/isPrime.js +1 -3
  397. package/lib/esm/function/utils/isZero.js +2 -6
  398. package/lib/esm/function/utils/numeric.js +11 -4
  399. package/lib/esm/function/utils/typeOf.js +38 -44
  400. package/lib/esm/type/bignumber/function/bignumber.js +1 -3
  401. package/lib/esm/type/boolean.js +1 -3
  402. package/lib/esm/type/chain/Chain.js +23 -3
  403. package/lib/esm/type/complex/Complex.js +4 -0
  404. package/lib/esm/type/complex/function/complex.js +1 -3
  405. package/lib/esm/type/fraction/Fraction.js +4 -0
  406. package/lib/esm/type/fraction/function/fraction.js +1 -3
  407. package/lib/esm/type/matrix/DenseMatrix.js +15 -1
  408. package/lib/esm/type/matrix/SparseMatrix.js +9 -0
  409. package/lib/esm/type/matrix/utils/{algorithm01.js → matAlgo01xDSid.js} +2 -2
  410. package/lib/esm/type/matrix/utils/{algorithm02.js → matAlgo02xDS0.js} +3 -3
  411. package/lib/esm/type/matrix/utils/{algorithm03.js → matAlgo03xDSf.js} +3 -3
  412. package/lib/esm/type/matrix/utils/{algorithm04.js → matAlgo04xSidSid.js} +5 -5
  413. package/lib/esm/type/matrix/utils/{algorithm05.js → matAlgo05xSfSf.js} +3 -3
  414. package/lib/esm/type/matrix/utils/{algorithm06.js → matAlgo06xS0S0.js} +3 -3
  415. package/lib/esm/type/matrix/utils/{algorithm07.js → matAlgo07xSSf.js} +3 -3
  416. package/lib/esm/type/matrix/utils/{algorithm08.js → matAlgo08xS0Sid.js} +4 -4
  417. package/lib/esm/type/matrix/utils/{algorithm09.js → matAlgo09xS0Sf.js} +3 -3
  418. package/lib/esm/type/matrix/utils/{algorithm10.js → matAlgo10xSids.js} +3 -3
  419. package/lib/esm/type/matrix/utils/{algorithm11.js → matAlgo11xS0s.js} +3 -3
  420. package/lib/esm/type/matrix/utils/{algorithm12.js → matAlgo12xSfs.js} +3 -3
  421. package/lib/esm/type/matrix/utils/{algorithm13.js → matAlgo13xDD.js} +3 -3
  422. package/lib/esm/type/matrix/utils/{algorithm14.js → matAlgo14xDs.js} +3 -3
  423. package/lib/esm/type/matrix/utils/matrixAlgorithmSuite.js +168 -0
  424. package/lib/esm/type/number.js +1 -3
  425. package/lib/esm/type/string.js +1 -3
  426. package/lib/esm/type/unit/Unit.js +61 -13
  427. package/lib/esm/type/unit/function/createUnit.js +2 -1
  428. package/lib/esm/type/unit/function/unit.js +5 -3
  429. package/lib/esm/utils/is.js +18 -18
  430. package/lib/esm/utils/snapshot.js +22 -48
  431. package/lib/esm/version.js +1 -1
  432. package/package.json +21 -24
  433. package/types/index.d.ts +202 -181
  434. package/types/index.ts +264 -57
  435. package/lib/cjs/utils/polyfills.js +0 -14
  436. package/lib/esm/utils/polyfills.js +0 -12
@@ -1,3 +1,4 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
1
2
  import { isBigNumber, isComplex, isNode, isUnit, typeOf } from '../../utils/is.js';
2
3
  import { factory } from '../../utils/factory.js';
3
4
  import { getPrecedence } from '../operators.js';
@@ -9,230 +10,252 @@ export var createConditionalNode = /* #__PURE__ */factory(name, dependencies, _r
9
10
  } = _ref;
10
11
 
11
12
  /**
12
- * A lazy evaluating conditional operator: 'condition ? trueExpr : falseExpr'
13
- *
14
- * @param {Node} condition Condition, must result in a boolean
15
- * @param {Node} trueExpr Expression evaluated when condition is true
16
- * @param {Node} falseExpr Expression evaluated when condition is true
17
- *
18
- * @constructor ConditionalNode
19
- * @extends {Node}
13
+ * Test whether a condition is met
14
+ * @param {*} condition
15
+ * @returns {boolean} true if condition is true or non-zero, else false
20
16
  */
21
- function ConditionalNode(condition, trueExpr, falseExpr) {
22
- if (!(this instanceof ConditionalNode)) {
23
- throw new SyntaxError('Constructor must be called with the new operator');
17
+ function testCondition(condition) {
18
+ if (typeof condition === 'number' || typeof condition === 'boolean' || typeof condition === 'string') {
19
+ return !!condition;
24
20
  }
25
21
 
26
- if (!isNode(condition)) throw new TypeError('Parameter condition must be a Node');
27
- if (!isNode(trueExpr)) throw new TypeError('Parameter trueExpr must be a Node');
28
- if (!isNode(falseExpr)) throw new TypeError('Parameter falseExpr must be a Node');
29
- this.condition = condition;
30
- this.trueExpr = trueExpr;
31
- this.falseExpr = falseExpr;
32
- }
33
-
34
- ConditionalNode.prototype = new Node();
35
- ConditionalNode.prototype.type = 'ConditionalNode';
36
- ConditionalNode.prototype.isConditionalNode = true;
37
- /**
38
- * Compile a node into a JavaScript function.
39
- * This basically pre-calculates as much as possible and only leaves open
40
- * calculations which depend on a dynamic scope with variables.
41
- * @param {Object} math Math.js namespace with functions and constants.
42
- * @param {Object} argNames An object with argument names as key and `true`
43
- * as value. Used in the SymbolNode to optimize
44
- * for arguments from user assigned functions
45
- * (see FunctionAssignmentNode) or special symbols
46
- * like `end` (see IndexNode).
47
- * @return {function} Returns a function which can be called like:
48
- * evalNode(scope: Object, args: Object, context: *)
49
- */
50
-
51
- ConditionalNode.prototype._compile = function (math, argNames) {
52
- var evalCondition = this.condition._compile(math, argNames);
53
-
54
- var evalTrueExpr = this.trueExpr._compile(math, argNames);
22
+ if (condition) {
23
+ if (isBigNumber(condition)) {
24
+ return !condition.isZero();
25
+ }
55
26
 
56
- var evalFalseExpr = this.falseExpr._compile(math, argNames);
27
+ if (isComplex(condition)) {
28
+ return !!(condition.re || condition.im);
29
+ }
57
30
 
58
- return function evalConditionalNode(scope, args, context) {
59
- return testCondition(evalCondition(scope, args, context)) ? evalTrueExpr(scope, args, context) : evalFalseExpr(scope, args, context);
60
- };
61
- };
62
- /**
63
- * Execute a callback for each of the child nodes of this node
64
- * @param {function(child: Node, path: string, parent: Node)} callback
65
- */
31
+ if (isUnit(condition)) {
32
+ return !!condition.value;
33
+ }
34
+ }
66
35
 
36
+ if (condition === null || condition === undefined) {
37
+ return false;
38
+ }
67
39
 
68
- ConditionalNode.prototype.forEach = function (callback) {
69
- callback(this.condition, 'condition', this);
70
- callback(this.trueExpr, 'trueExpr', this);
71
- callback(this.falseExpr, 'falseExpr', this);
72
- };
73
- /**
74
- * Create a new ConditionalNode having it's childs be the results of calling
75
- * the provided callback function for each of the childs of the original node.
76
- * @param {function(child: Node, path: string, parent: Node): Node} callback
77
- * @returns {ConditionalNode} Returns a transformed copy of the node
78
- */
40
+ throw new TypeError('Unsupported type of condition "' + typeOf(condition) + '"');
41
+ }
79
42
 
43
+ class ConditionalNode extends Node {
44
+ /**
45
+ * A lazy evaluating conditional operator: 'condition ? trueExpr : falseExpr'
46
+ *
47
+ * @param {Node} condition Condition, must result in a boolean
48
+ * @param {Node} trueExpr Expression evaluated when condition is true
49
+ * @param {Node} falseExpr Expression evaluated when condition is true
50
+ *
51
+ * @constructor ConditionalNode
52
+ * @extends {Node}
53
+ */
54
+ constructor(condition, trueExpr, falseExpr) {
55
+ super();
56
+
57
+ if (!isNode(condition)) {
58
+ throw new TypeError('Parameter condition must be a Node');
59
+ }
80
60
 
81
- ConditionalNode.prototype.map = function (callback) {
82
- return new ConditionalNode(this._ifNode(callback(this.condition, 'condition', this)), this._ifNode(callback(this.trueExpr, 'trueExpr', this)), this._ifNode(callback(this.falseExpr, 'falseExpr', this)));
83
- };
84
- /**
85
- * Create a clone of this node, a shallow copy
86
- * @return {ConditionalNode}
87
- */
61
+ if (!isNode(trueExpr)) {
62
+ throw new TypeError('Parameter trueExpr must be a Node');
63
+ }
88
64
 
65
+ if (!isNode(falseExpr)) {
66
+ throw new TypeError('Parameter falseExpr must be a Node');
67
+ }
89
68
 
90
- ConditionalNode.prototype.clone = function () {
91
- return new ConditionalNode(this.condition, this.trueExpr, this.falseExpr);
92
- };
93
- /**
94
- * Get string representation
95
- * @param {Object} options
96
- * @return {string} str
97
- */
69
+ this.condition = condition;
70
+ this.trueExpr = trueExpr;
71
+ this.falseExpr = falseExpr;
72
+ }
98
73
 
74
+ get type() {
75
+ return name;
76
+ }
99
77
 
100
- ConditionalNode.prototype._toString = function (options) {
101
- var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
102
- var precedence = getPrecedence(this, parenthesis); // Enclose Arguments in parentheses if they are an OperatorNode
103
- // or have lower or equal precedence
104
- // NOTE: enclosing all OperatorNodes in parentheses is a decision
105
- // purely based on aesthetics and readability
78
+ get isConditionalNode() {
79
+ return true;
80
+ }
81
+ /**
82
+ * Compile a node into a JavaScript function.
83
+ * This basically pre-calculates as much as possible and only leaves open
84
+ * calculations which depend on a dynamic scope with variables.
85
+ * @param {Object} math Math.js namespace with functions and constants.
86
+ * @param {Object} argNames An object with argument names as key and `true`
87
+ * as value. Used in the SymbolNode to optimize
88
+ * for arguments from user assigned functions
89
+ * (see FunctionAssignmentNode) or special symbols
90
+ * like `end` (see IndexNode).
91
+ * @return {function} Returns a function which can be called like:
92
+ * evalNode(scope: Object, args: Object, context: *)
93
+ */
94
+
95
+
96
+ _compile(math, argNames) {
97
+ var evalCondition = this.condition._compile(math, argNames);
98
+
99
+ var evalTrueExpr = this.trueExpr._compile(math, argNames);
100
+
101
+ var evalFalseExpr = this.falseExpr._compile(math, argNames);
102
+
103
+ return function evalConditionalNode(scope, args, context) {
104
+ return testCondition(evalCondition(scope, args, context)) ? evalTrueExpr(scope, args, context) : evalFalseExpr(scope, args, context);
105
+ };
106
+ }
107
+ /**
108
+ * Execute a callback for each of the child nodes of this node
109
+ * @param {function(child: Node, path: string, parent: Node)} callback
110
+ */
106
111
 
107
- var condition = this.condition.toString(options);
108
- var conditionPrecedence = getPrecedence(this.condition, parenthesis);
109
112
 
110
- if (parenthesis === 'all' || this.condition.type === 'OperatorNode' || conditionPrecedence !== null && conditionPrecedence <= precedence) {
111
- condition = '(' + condition + ')';
113
+ forEach(callback) {
114
+ callback(this.condition, 'condition', this);
115
+ callback(this.trueExpr, 'trueExpr', this);
116
+ callback(this.falseExpr, 'falseExpr', this);
112
117
  }
118
+ /**
119
+ * Create a new ConditionalNode whose children are the results of calling
120
+ * the provided callback function for each child of the original node.
121
+ * @param {function(child: Node, path: string, parent: Node): Node} callback
122
+ * @returns {ConditionalNode} Returns a transformed copy of the node
123
+ */
113
124
 
114
- var trueExpr = this.trueExpr.toString(options);
115
- var truePrecedence = getPrecedence(this.trueExpr, parenthesis);
116
125
 
117
- if (parenthesis === 'all' || this.trueExpr.type === 'OperatorNode' || truePrecedence !== null && truePrecedence <= precedence) {
118
- trueExpr = '(' + trueExpr + ')';
126
+ map(callback) {
127
+ return new ConditionalNode(this._ifNode(callback(this.condition, 'condition', this)), this._ifNode(callback(this.trueExpr, 'trueExpr', this)), this._ifNode(callback(this.falseExpr, 'falseExpr', this)));
119
128
  }
129
+ /**
130
+ * Create a clone of this node, a shallow copy
131
+ * @return {ConditionalNode}
132
+ */
120
133
 
121
- var falseExpr = this.falseExpr.toString(options);
122
- var falsePrecedence = getPrecedence(this.falseExpr, parenthesis);
123
134
 
124
- if (parenthesis === 'all' || this.falseExpr.type === 'OperatorNode' || falsePrecedence !== null && falsePrecedence <= precedence) {
125
- falseExpr = '(' + falseExpr + ')';
135
+ clone() {
136
+ return new ConditionalNode(this.condition, this.trueExpr, this.falseExpr);
126
137
  }
138
+ /**
139
+ * Get string representation
140
+ * @param {Object} options
141
+ * @return {string} str
142
+ */
127
143
 
128
- return condition + ' ? ' + trueExpr + ' : ' + falseExpr;
129
- };
130
- /**
131
- * Get a JSON representation of the node
132
- * @returns {Object}
133
- */
134
144
 
145
+ _toString(options) {
146
+ var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
147
+ var precedence = getPrecedence(this, parenthesis, options && options.implicit); // Enclose Arguments in parentheses if they are an OperatorNode
148
+ // or have lower or equal precedence
149
+ // NOTE: enclosing all OperatorNodes in parentheses is a decision
150
+ // purely based on aesthetics and readability
135
151
 
136
- ConditionalNode.prototype.toJSON = function () {
137
- return {
138
- mathjs: 'ConditionalNode',
139
- condition: this.condition,
140
- trueExpr: this.trueExpr,
141
- falseExpr: this.falseExpr
142
- };
143
- };
144
- /**
145
- * Instantiate an ConditionalNode from its JSON representation
146
- * @param {Object} json An object structured like
147
- * `{"mathjs": "ConditionalNode", "condition": ..., "trueExpr": ..., "falseExpr": ...}`,
148
- * where mathjs is optional
149
- * @returns {ConditionalNode}
150
- */
152
+ var condition = this.condition.toString(options);
153
+ var conditionPrecedence = getPrecedence(this.condition, parenthesis, options && options.implicit);
151
154
 
155
+ if (parenthesis === 'all' || this.condition.type === 'OperatorNode' || conditionPrecedence !== null && conditionPrecedence <= precedence) {
156
+ condition = '(' + condition + ')';
157
+ }
152
158
 
153
- ConditionalNode.fromJSON = function (json) {
154
- return new ConditionalNode(json.condition, json.trueExpr, json.falseExpr);
155
- };
156
- /**
157
- * Get HTML representation
158
- * @param {Object} options
159
- * @return {string} str
160
- */
159
+ var trueExpr = this.trueExpr.toString(options);
160
+ var truePrecedence = getPrecedence(this.trueExpr, parenthesis, options && options.implicit);
161
161
 
162
+ if (parenthesis === 'all' || this.trueExpr.type === 'OperatorNode' || truePrecedence !== null && truePrecedence <= precedence) {
163
+ trueExpr = '(' + trueExpr + ')';
164
+ }
162
165
 
163
- ConditionalNode.prototype.toHTML = function (options) {
164
- var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
165
- var precedence = getPrecedence(this, parenthesis); // Enclose Arguments in parentheses if they are an OperatorNode
166
- // or have lower or equal precedence
167
- // NOTE: enclosing all OperatorNodes in parentheses is a decision
168
- // purely based on aesthetics and readability
166
+ var falseExpr = this.falseExpr.toString(options);
167
+ var falsePrecedence = getPrecedence(this.falseExpr, parenthesis, options && options.implicit);
169
168
 
170
- var condition = this.condition.toHTML(options);
171
- var conditionPrecedence = getPrecedence(this.condition, parenthesis);
169
+ if (parenthesis === 'all' || this.falseExpr.type === 'OperatorNode' || falsePrecedence !== null && falsePrecedence <= precedence) {
170
+ falseExpr = '(' + falseExpr + ')';
171
+ }
172
172
 
173
- if (parenthesis === 'all' || this.condition.type === 'OperatorNode' || conditionPrecedence !== null && conditionPrecedence <= precedence) {
174
- condition = '<span class="math-parenthesis math-round-parenthesis">(</span>' + condition + '<span class="math-parenthesis math-round-parenthesis">)</span>';
173
+ return condition + ' ? ' + trueExpr + ' : ' + falseExpr;
175
174
  }
176
-
177
- var trueExpr = this.trueExpr.toHTML(options);
178
- var truePrecedence = getPrecedence(this.trueExpr, parenthesis);
179
-
180
- if (parenthesis === 'all' || this.trueExpr.type === 'OperatorNode' || truePrecedence !== null && truePrecedence <= precedence) {
181
- trueExpr = '<span class="math-parenthesis math-round-parenthesis">(</span>' + trueExpr + '<span class="math-parenthesis math-round-parenthesis">)</span>';
175
+ /**
176
+ * Get a JSON representation of the node
177
+ * @returns {Object}
178
+ */
179
+
180
+
181
+ toJSON() {
182
+ return {
183
+ mathjs: name,
184
+ condition: this.condition,
185
+ trueExpr: this.trueExpr,
186
+ falseExpr: this.falseExpr
187
+ };
182
188
  }
183
-
184
- var falseExpr = this.falseExpr.toHTML(options);
185
- var falsePrecedence = getPrecedence(this.falseExpr, parenthesis);
186
-
187
- if (parenthesis === 'all' || this.falseExpr.type === 'OperatorNode' || falsePrecedence !== null && falsePrecedence <= precedence) {
188
- falseExpr = '<span class="math-parenthesis math-round-parenthesis">(</span>' + falseExpr + '<span class="math-parenthesis math-round-parenthesis">)</span>';
189
+ /**
190
+ * Instantiate an ConditionalNode from its JSON representation
191
+ * @param {Object} json
192
+ * An object structured like
193
+ * ```
194
+ * {"mathjs": "ConditionalNode",
195
+ * "condition": ...,
196
+ * "trueExpr": ...,
197
+ * "falseExpr": ...}
198
+ * ```
199
+ * where mathjs is optional
200
+ * @returns {ConditionalNode}
201
+ */
202
+
203
+
204
+ static fromJSON(json) {
205
+ return new ConditionalNode(json.condition, json.trueExpr, json.falseExpr);
189
206
  }
207
+ /**
208
+ * Get HTML representation
209
+ * @param {Object} options
210
+ * @return {string} str
211
+ */
190
212
 
191
- return condition + '<span class="math-operator math-conditional-operator">?</span>' + trueExpr + '<span class="math-operator math-conditional-operator">:</span>' + falseExpr;
192
- };
193
- /**
194
- * Get LaTeX representation
195
- * @param {Object} options
196
- * @return {string} str
197
- */
198
213
 
214
+ toHTML(options) {
215
+ var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
216
+ var precedence = getPrecedence(this, parenthesis, options && options.implicit); // Enclose Arguments in parentheses if they are an OperatorNode
217
+ // or have lower or equal precedence
218
+ // NOTE: enclosing all OperatorNodes in parentheses is a decision
219
+ // purely based on aesthetics and readability
199
220
 
200
- ConditionalNode.prototype._toTex = function (options) {
201
- return '\\begin{cases} {' + this.trueExpr.toTex(options) + '}, &\\quad{\\text{if }\\;' + this.condition.toTex(options) + '}\\\\{' + this.falseExpr.toTex(options) + '}, &\\quad{\\text{otherwise}}\\end{cases}';
202
- };
203
- /**
204
- * Test whether a condition is met
205
- * @param {*} condition
206
- * @returns {boolean} true if condition is true or non-zero, else false
207
- */
221
+ var condition = this.condition.toHTML(options);
222
+ var conditionPrecedence = getPrecedence(this.condition, parenthesis, options && options.implicit);
208
223
 
224
+ if (parenthesis === 'all' || this.condition.type === 'OperatorNode' || conditionPrecedence !== null && conditionPrecedence <= precedence) {
225
+ condition = '<span class="math-parenthesis math-round-parenthesis">(</span>' + condition + '<span class="math-parenthesis math-round-parenthesis">)</span>';
226
+ }
209
227
 
210
- function testCondition(condition) {
211
- if (typeof condition === 'number' || typeof condition === 'boolean' || typeof condition === 'string') {
212
- return !!condition;
213
- }
228
+ var trueExpr = this.trueExpr.toHTML(options);
229
+ var truePrecedence = getPrecedence(this.trueExpr, parenthesis, options && options.implicit);
214
230
 
215
- if (condition) {
216
- if (isBigNumber(condition)) {
217
- return !condition.isZero();
231
+ if (parenthesis === 'all' || this.trueExpr.type === 'OperatorNode' || truePrecedence !== null && truePrecedence <= precedence) {
232
+ trueExpr = '<span class="math-parenthesis math-round-parenthesis">(</span>' + trueExpr + '<span class="math-parenthesis math-round-parenthesis">)</span>';
218
233
  }
219
234
 
220
- if (isComplex(condition)) {
221
- return !!(condition.re || condition.im);
222
- }
235
+ var falseExpr = this.falseExpr.toHTML(options);
236
+ var falsePrecedence = getPrecedence(this.falseExpr, parenthesis, options && options.implicit);
223
237
 
224
- if (isUnit(condition)) {
225
- return !!condition.value;
238
+ if (parenthesis === 'all' || this.falseExpr.type === 'OperatorNode' || falsePrecedence !== null && falsePrecedence <= precedence) {
239
+ falseExpr = '<span class="math-parenthesis math-round-parenthesis">(</span>' + falseExpr + '<span class="math-parenthesis math-round-parenthesis">)</span>';
226
240
  }
241
+
242
+ return condition + '<span class="math-operator math-conditional-operator">?</span>' + trueExpr + '<span class="math-operator math-conditional-operator">:</span>' + falseExpr;
227
243
  }
244
+ /**
245
+ * Get LaTeX representation
246
+ * @param {Object} options
247
+ * @return {string} str
248
+ */
228
249
 
229
- if (condition === null || condition === undefined) {
230
- return false;
250
+
251
+ _toTex(options) {
252
+ return '\\begin{cases} {' + this.trueExpr.toTex(options) + '}, &\\quad{\\text{if }\\;' + this.condition.toTex(options) + '}\\\\{' + this.falseExpr.toTex(options) + '}, &\\quad{\\text{otherwise}}\\end{cases}';
231
253
  }
232
254
 
233
- throw new TypeError('Unsupported type of condition "' + typeOf(condition) + '"');
234
255
  }
235
256
 
257
+ _defineProperty(ConditionalNode, "name", name);
258
+
236
259
  return ConditionalNode;
237
260
  }, {
238
261
  isClass: true,