mathjs 10.6.4 → 11.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (454) hide show
  1. package/HISTORY.md +79 -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/construction/index.js +1 -1
  39. package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +8 -5
  40. package/lib/cjs/expression/embeddedDocs/function/algebra/simplifyConstant.js +15 -0
  41. package/lib/cjs/expression/embeddedDocs/function/algebra/simplifyCore.js +1 -1
  42. package/lib/cjs/expression/node/AccessorNode.js +216 -173
  43. package/lib/cjs/expression/node/ArrayNode.js +206 -160
  44. package/lib/cjs/expression/node/AssignmentNode.js +321 -270
  45. package/lib/cjs/expression/node/BlockNode.js +223 -172
  46. package/lib/cjs/expression/node/ConditionalNode.js +253 -193
  47. package/lib/cjs/expression/node/ConstantNode.js +216 -171
  48. package/lib/cjs/expression/node/FunctionAssignmentNode.js +258 -196
  49. package/lib/cjs/expression/node/FunctionNode.js +456 -416
  50. package/lib/cjs/expression/node/IndexNode.js +256 -210
  51. package/lib/cjs/expression/node/Node.js +411 -378
  52. package/lib/cjs/expression/node/ObjectNode.js +223 -178
  53. package/lib/cjs/expression/node/OperatorNode.js +474 -397
  54. package/lib/cjs/expression/node/ParenthesisNode.js +189 -143
  55. package/lib/cjs/expression/node/RangeNode.js +272 -224
  56. package/lib/cjs/expression/node/RelationalNode.js +246 -195
  57. package/lib/cjs/expression/node/SymbolNode.js +219 -172
  58. package/lib/cjs/expression/node/utils/access.js +1 -1
  59. package/lib/cjs/expression/node/utils/assign.js +1 -1
  60. package/lib/cjs/expression/operators.js +117 -23
  61. package/lib/cjs/expression/parse.js +37 -19
  62. package/lib/cjs/expression/transform/std.transform.js +3 -1
  63. package/lib/cjs/factoriesAny.js +8 -0
  64. package/lib/cjs/factoriesNumber.js +10 -1
  65. package/lib/cjs/function/algebra/decomposition/qr.js +1 -1
  66. package/lib/cjs/function/algebra/derivative.js +25 -33
  67. package/lib/cjs/function/algebra/leafCount.js +0 -3
  68. package/lib/cjs/function/algebra/rationalize.js +78 -108
  69. package/lib/cjs/function/algebra/resolve.js +53 -16
  70. package/lib/cjs/function/algebra/simplify/util.js +1 -1
  71. package/lib/cjs/function/algebra/simplify.js +90 -115
  72. package/lib/cjs/function/algebra/{simplify/simplifyConstant.js → simplifyConstant.js} +44 -10
  73. package/lib/cjs/function/algebra/simplifyCore.js +196 -93
  74. package/lib/cjs/function/algebra/solver/lsolveAll.js +2 -2
  75. package/lib/cjs/function/algebra/solver/usolveAll.js +2 -2
  76. package/lib/cjs/function/algebra/symbolicEqual.js +14 -32
  77. package/lib/cjs/function/arithmetic/abs.js +7 -14
  78. package/lib/cjs/function/arithmetic/add.js +26 -70
  79. package/lib/cjs/function/arithmetic/addScalar.js +17 -9
  80. package/lib/cjs/function/arithmetic/cbrt.js +7 -11
  81. package/lib/cjs/function/arithmetic/ceil.js +50 -40
  82. package/lib/cjs/function/arithmetic/cube.js +5 -10
  83. package/lib/cjs/function/arithmetic/divide.js +7 -7
  84. package/lib/cjs/function/arithmetic/divideScalar.js +4 -18
  85. package/lib/cjs/function/arithmetic/dotDivide.js +22 -65
  86. package/lib/cjs/function/arithmetic/dotMultiply.js +16 -61
  87. package/lib/cjs/function/arithmetic/dotPow.js +30 -63
  88. package/lib/cjs/function/arithmetic/exp.js +8 -12
  89. package/lib/cjs/function/arithmetic/expm1.js +10 -10
  90. package/lib/cjs/function/arithmetic/fix.js +34 -28
  91. package/lib/cjs/function/arithmetic/floor.js +51 -41
  92. package/lib/cjs/function/arithmetic/gcd.js +27 -68
  93. package/lib/cjs/function/arithmetic/hypot.js +9 -5
  94. package/lib/cjs/function/arithmetic/invmod.js +2 -2
  95. package/lib/cjs/function/arithmetic/lcm.js +27 -68
  96. package/lib/cjs/function/arithmetic/log.js +10 -12
  97. package/lib/cjs/function/arithmetic/log10.js +5 -3
  98. package/lib/cjs/function/arithmetic/log1p.js +11 -7
  99. package/lib/cjs/function/arithmetic/log2.js +5 -3
  100. package/lib/cjs/function/arithmetic/mod.js +22 -64
  101. package/lib/cjs/function/arithmetic/multiply.js +40 -35
  102. package/lib/cjs/function/arithmetic/multiplyScalar.js +2 -9
  103. package/lib/cjs/function/arithmetic/norm.js +1 -5
  104. package/lib/cjs/function/arithmetic/nthRoot.js +83 -95
  105. package/lib/cjs/function/arithmetic/nthRoots.js +2 -2
  106. package/lib/cjs/function/arithmetic/round.js +56 -42
  107. package/lib/cjs/function/arithmetic/sign.js +14 -10
  108. package/lib/cjs/function/arithmetic/sqrt.js +5 -9
  109. package/lib/cjs/function/arithmetic/square.js +6 -10
  110. package/lib/cjs/function/arithmetic/subtract.js +44 -100
  111. package/lib/cjs/function/arithmetic/unaryMinus.js +14 -16
  112. package/lib/cjs/function/arithmetic/unaryPlus.js +6 -4
  113. package/lib/cjs/function/bitwise/bitAnd.js +17 -61
  114. package/lib/cjs/function/bitwise/bitNot.js +6 -4
  115. package/lib/cjs/function/bitwise/bitOr.js +16 -60
  116. package/lib/cjs/function/bitwise/bitXor.js +17 -61
  117. package/lib/cjs/function/bitwise/leftShift.js +69 -82
  118. package/lib/cjs/function/bitwise/rightArithShift.js +69 -82
  119. package/lib/cjs/function/bitwise/rightLogShift.js +69 -82
  120. package/lib/cjs/function/bitwise/useMatrixForArrayScalar.js +36 -0
  121. package/lib/cjs/function/complex/arg.js +5 -3
  122. package/lib/cjs/function/complex/conj.js +6 -7
  123. package/lib/cjs/function/complex/im.js +7 -8
  124. package/lib/cjs/function/complex/re.js +6 -10
  125. package/lib/cjs/function/geometry/distance.js +2 -2
  126. package/lib/cjs/function/logical/and.js +74 -80
  127. package/lib/cjs/function/logical/not.js +13 -6
  128. package/lib/cjs/function/logical/or.js +21 -63
  129. package/lib/cjs/function/logical/xor.js +21 -63
  130. package/lib/cjs/function/matrix/diff.js +11 -8
  131. package/lib/cjs/function/matrix/eigs/complexEigs.js +5 -5
  132. package/lib/cjs/function/matrix/fft.js +2 -2
  133. package/lib/cjs/function/matrix/matrixFromColumns.js +1 -1
  134. package/lib/cjs/function/matrix/matrixFromRows.js +1 -1
  135. package/lib/cjs/function/matrix/ones.js +2 -1
  136. package/lib/cjs/function/matrix/rotate.js +5 -5
  137. package/lib/cjs/function/matrix/sqrtm.js +3 -2
  138. package/lib/cjs/function/matrix/transpose.js +47 -48
  139. package/lib/cjs/function/matrix/zeros.js +2 -1
  140. package/lib/cjs/function/probability/factorial.js +5 -3
  141. package/lib/cjs/function/probability/gamma.js +38 -40
  142. package/lib/cjs/function/probability/kldivergence.js +5 -2
  143. package/lib/cjs/function/probability/lgamma.js +30 -30
  144. package/lib/cjs/function/probability/util/seededRNG.js +2 -2
  145. package/lib/cjs/function/relational/compare.js +21 -67
  146. package/lib/cjs/function/relational/compareNatural.js +59 -54
  147. package/lib/cjs/function/relational/compareText.js +10 -43
  148. package/lib/cjs/function/relational/compareUnits.js +24 -0
  149. package/lib/cjs/function/relational/equal.js +19 -80
  150. package/lib/cjs/function/relational/equalScalar.js +7 -9
  151. package/lib/cjs/function/relational/larger.js +21 -67
  152. package/lib/cjs/function/relational/largerEq.js +21 -67
  153. package/lib/cjs/function/relational/smaller.js +21 -67
  154. package/lib/cjs/function/relational/smallerEq.js +21 -67
  155. package/lib/cjs/function/relational/unequal.js +19 -80
  156. package/lib/cjs/function/special/erf.js +5 -3
  157. package/lib/cjs/function/statistics/std.js +11 -2
  158. package/lib/cjs/function/string/format.js +2 -2
  159. package/lib/cjs/function/string/hex.js +1 -2
  160. package/lib/cjs/function/trigonometry/acos.js +4 -8
  161. package/lib/cjs/function/trigonometry/acosh.js +2 -7
  162. package/lib/cjs/function/trigonometry/acot.js +6 -11
  163. package/lib/cjs/function/trigonometry/acoth.js +4 -8
  164. package/lib/cjs/function/trigonometry/acsc.js +6 -11
  165. package/lib/cjs/function/trigonometry/acsch.js +4 -8
  166. package/lib/cjs/function/trigonometry/asec.js +6 -10
  167. package/lib/cjs/function/trigonometry/asech.js +4 -8
  168. package/lib/cjs/function/trigonometry/asin.js +5 -10
  169. package/lib/cjs/function/trigonometry/asinh.js +4 -9
  170. package/lib/cjs/function/trigonometry/atan.js +5 -11
  171. package/lib/cjs/function/trigonometry/atan2.js +25 -63
  172. package/lib/cjs/function/trigonometry/atanh.js +4 -9
  173. package/lib/cjs/function/trigonometry/cos.js +11 -20
  174. package/lib/cjs/function/trigonometry/cosh.js +5 -19
  175. package/lib/cjs/function/trigonometry/cot.js +9 -15
  176. package/lib/cjs/function/trigonometry/coth.js +4 -15
  177. package/lib/cjs/function/trigonometry/csc.js +11 -17
  178. package/lib/cjs/function/trigonometry/csch.js +4 -15
  179. package/lib/cjs/function/trigonometry/sec.js +11 -17
  180. package/lib/cjs/function/trigonometry/sech.js +4 -15
  181. package/lib/cjs/function/trigonometry/sin.js +11 -21
  182. package/lib/cjs/function/trigonometry/sinh.js +5 -20
  183. package/lib/cjs/function/trigonometry/tan.js +11 -21
  184. package/lib/cjs/function/trigonometry/tanh.js +5 -20
  185. package/lib/cjs/function/trigonometry/trigUnit.js +24 -0
  186. package/lib/cjs/function/unit/to.js +7 -41
  187. package/lib/cjs/function/utils/clone.js +1 -1
  188. package/lib/cjs/function/utils/hasNumericValue.js +5 -1
  189. package/lib/cjs/function/utils/isInteger.js +6 -4
  190. package/lib/cjs/function/utils/isNaN.js +1 -1
  191. package/lib/cjs/function/utils/isNegative.js +11 -7
  192. package/lib/cjs/function/utils/isNumeric.js +6 -4
  193. package/lib/cjs/function/utils/isPositive.js +11 -7
  194. package/lib/cjs/function/utils/isPrime.js +5 -3
  195. package/lib/cjs/function/utils/isZero.js +21 -17
  196. package/lib/cjs/function/utils/numeric.js +11 -4
  197. package/lib/cjs/function/utils/typeOf.js +38 -44
  198. package/lib/cjs/header.js +2 -2
  199. package/lib/cjs/plain/bignumber/index.js +1 -1
  200. package/lib/cjs/type/bignumber/BigNumber.js +2 -2
  201. package/lib/cjs/type/bignumber/function/bignumber.js +6 -4
  202. package/lib/cjs/type/boolean.js +7 -5
  203. package/lib/cjs/type/chain/Chain.js +23 -3
  204. package/lib/cjs/type/complex/Complex.js +18 -14
  205. package/lib/cjs/type/complex/function/complex.js +6 -4
  206. package/lib/cjs/type/fraction/Fraction.js +10 -6
  207. package/lib/cjs/type/fraction/function/fraction.js +6 -4
  208. package/lib/cjs/type/matrix/DenseMatrix.js +21 -6
  209. package/lib/cjs/type/matrix/SparseMatrix.js +12 -2
  210. package/lib/cjs/type/matrix/utils/{algorithm01.js → matAlgo01xDSid.js} +4 -4
  211. package/lib/cjs/type/matrix/utils/{algorithm02.js → matAlgo02xDS0.js} +5 -5
  212. package/lib/cjs/type/matrix/utils/{algorithm03.js → matAlgo03xDSf.js} +5 -5
  213. package/lib/cjs/type/matrix/utils/{algorithm04.js → matAlgo04xSidSid.js} +7 -7
  214. package/lib/cjs/type/matrix/utils/{algorithm05.js → matAlgo05xSfSf.js} +5 -5
  215. package/lib/cjs/type/matrix/utils/{algorithm06.js → matAlgo06xS0S0.js} +5 -5
  216. package/lib/cjs/type/matrix/utils/{algorithm07.js → matAlgo07xSSf.js} +5 -5
  217. package/lib/cjs/type/matrix/utils/{algorithm08.js → matAlgo08xS0Sid.js} +6 -6
  218. package/lib/cjs/type/matrix/utils/{algorithm09.js → matAlgo09xS0Sf.js} +5 -5
  219. package/lib/cjs/type/matrix/utils/{algorithm10.js → matAlgo10xSids.js} +5 -5
  220. package/lib/cjs/type/matrix/utils/{algorithm11.js → matAlgo11xS0s.js} +5 -5
  221. package/lib/cjs/type/matrix/utils/{algorithm12.js → matAlgo12xSfs.js} +5 -5
  222. package/lib/cjs/type/matrix/utils/{algorithm13.js → matAlgo13xDD.js} +5 -5
  223. package/lib/cjs/type/matrix/utils/{algorithm14.js → matAlgo14xDs.js} +5 -5
  224. package/lib/cjs/type/matrix/utils/matrixAlgorithmSuite.js +238 -0
  225. package/lib/cjs/type/number.js +6 -4
  226. package/lib/cjs/type/string.js +7 -5
  227. package/lib/cjs/type/unit/Unit.js +98 -45
  228. package/lib/cjs/type/unit/function/createUnit.js +2 -1
  229. package/lib/cjs/type/unit/function/unit.js +14 -5
  230. package/lib/cjs/utils/customs.js +2 -2
  231. package/lib/cjs/utils/emitter.js +1 -1
  232. package/lib/cjs/utils/function.js +2 -2
  233. package/lib/cjs/utils/is.js +27 -25
  234. package/lib/cjs/utils/latex.js +3 -3
  235. package/lib/cjs/utils/lruQueue.js +1 -1
  236. package/lib/cjs/utils/map.js +3 -3
  237. package/lib/cjs/utils/object.js +2 -2
  238. package/lib/cjs/utils/snapshot.js +30 -57
  239. package/lib/cjs/utils/string.js +3 -3
  240. package/lib/cjs/version.js +1 -1
  241. package/lib/esm/core/create.js +2 -1
  242. package/lib/esm/core/function/import.js +2 -12
  243. package/lib/esm/core/function/typed.js +47 -11
  244. package/lib/esm/entry/dependenciesAny/dependenciesChainClass.generated.js +2 -0
  245. package/lib/esm/entry/dependenciesAny/dependenciesKldivergence.generated.js +2 -0
  246. package/lib/esm/entry/dependenciesAny/dependenciesRationalize.generated.js +2 -0
  247. package/lib/esm/entry/dependenciesAny/dependenciesResolve.generated.js +2 -0
  248. package/lib/esm/entry/dependenciesAny/dependenciesSimplify.generated.js +2 -0
  249. package/lib/esm/entry/dependenciesAny/dependenciesSimplifyConstant.generated.js +34 -0
  250. package/lib/esm/entry/dependenciesAny/dependenciesSimplifyCore.generated.js +4 -0
  251. package/lib/esm/entry/dependenciesAny/dependenciesSqrtm.generated.js +2 -0
  252. package/lib/esm/entry/dependenciesAny/dependenciesStd.generated.js +2 -0
  253. package/lib/esm/entry/dependenciesAny/dependenciesStdTransform.generated.js +2 -0
  254. package/lib/esm/entry/dependenciesAny.generated.js +1 -0
  255. package/lib/esm/entry/dependenciesNumber/dependenciesChainClass.generated.js +2 -0
  256. package/lib/esm/entry/dependenciesNumber/dependenciesRationalize.generated.js +2 -0
  257. package/lib/esm/entry/dependenciesNumber/dependenciesResolve.generated.js +2 -0
  258. package/lib/esm/entry/dependenciesNumber/dependenciesSimplify.generated.js +2 -0
  259. package/lib/esm/entry/dependenciesNumber/dependenciesSimplifyConstant.generated.js +30 -0
  260. package/lib/esm/entry/dependenciesNumber/dependenciesSimplifyCore.generated.js +4 -0
  261. package/lib/esm/entry/dependenciesNumber/dependenciesStd.generated.js +2 -0
  262. package/lib/esm/entry/dependenciesNumber/dependenciesStdTransform.generated.js +2 -0
  263. package/lib/esm/entry/dependenciesNumber.generated.js +1 -0
  264. package/lib/esm/entry/impureFunctionsAny.generated.js +73 -48
  265. package/lib/esm/entry/impureFunctionsNumber.generated.js +81 -58
  266. package/lib/esm/entry/pureFunctionsAny.generated.js +39 -36
  267. package/lib/esm/entry/pureFunctionsNumber.generated.js +14 -13
  268. package/lib/esm/expression/embeddedDocs/construction/index.js +1 -1
  269. package/lib/esm/expression/embeddedDocs/embeddedDocs.js +2 -0
  270. package/lib/esm/expression/embeddedDocs/function/algebra/simplifyConstant.js +8 -0
  271. package/lib/esm/expression/embeddedDocs/function/algebra/simplifyCore.js +1 -1
  272. package/lib/esm/expression/node/AccessorNode.js +158 -153
  273. package/lib/esm/expression/node/ArrayNode.js +162 -154
  274. package/lib/esm/expression/node/AssignmentNode.js +257 -245
  275. package/lib/esm/expression/node/BlockNode.js +177 -163
  276. package/lib/esm/expression/node/ConditionalNode.js +197 -174
  277. package/lib/esm/expression/node/ConstantNode.js +171 -163
  278. package/lib/esm/expression/node/FunctionAssignmentNode.js +205 -180
  279. package/lib/esm/expression/node/FunctionNode.js +407 -407
  280. package/lib/esm/expression/node/IndexNode.js +206 -198
  281. package/lib/esm/expression/node/Node.js +325 -325
  282. package/lib/esm/expression/node/ObjectNode.js +166 -157
  283. package/lib/esm/expression/node/OperatorNode.js +414 -377
  284. package/lib/esm/expression/node/ParenthesisNode.js +146 -138
  285. package/lib/esm/expression/node/RangeNode.js +221 -212
  286. package/lib/esm/expression/node/RelationalNode.js +190 -176
  287. package/lib/esm/expression/node/SymbolNode.js +161 -152
  288. package/lib/esm/expression/operators.js +96 -4
  289. package/lib/esm/expression/parse.js +25 -7
  290. package/lib/esm/expression/transform/std.transform.js +3 -1
  291. package/lib/esm/factoriesAny.js +1 -0
  292. package/lib/esm/factoriesNumber.js +1 -0
  293. package/lib/esm/function/algebra/derivative.js +25 -33
  294. package/lib/esm/function/algebra/leafCount.js +0 -3
  295. package/lib/esm/function/algebra/rationalize.js +83 -114
  296. package/lib/esm/function/algebra/resolve.js +25 -16
  297. package/lib/esm/function/algebra/simplify.js +85 -113
  298. package/lib/esm/function/algebra/{simplify/simplifyConstant.js → simplifyConstant.js} +39 -9
  299. package/lib/esm/function/algebra/simplifyCore.js +192 -91
  300. package/lib/esm/function/algebra/symbolicEqual.js +14 -32
  301. package/lib/esm/function/arithmetic/abs.js +3 -16
  302. package/lib/esm/function/arithmetic/add.js +21 -65
  303. package/lib/esm/function/arithmetic/addScalar.js +11 -5
  304. package/lib/esm/function/arithmetic/cbrt.js +7 -10
  305. package/lib/esm/function/arithmetic/ceil.js +25 -25
  306. package/lib/esm/function/arithmetic/cube.js +5 -9
  307. package/lib/esm/function/arithmetic/divide.js +7 -7
  308. package/lib/esm/function/arithmetic/divideScalar.js +2 -19
  309. package/lib/esm/function/arithmetic/dotDivide.js +22 -64
  310. package/lib/esm/function/arithmetic/dotMultiply.js +16 -60
  311. package/lib/esm/function/arithmetic/dotPow.js +30 -62
  312. package/lib/esm/function/arithmetic/exp.js +8 -11
  313. package/lib/esm/function/arithmetic/expm1.js +10 -9
  314. package/lib/esm/function/arithmetic/fix.js +18 -18
  315. package/lib/esm/function/arithmetic/floor.js +26 -26
  316. package/lib/esm/function/arithmetic/gcd.js +26 -70
  317. package/lib/esm/function/arithmetic/hypot.js +7 -6
  318. package/lib/esm/function/arithmetic/invmod.js +1 -1
  319. package/lib/esm/function/arithmetic/lcm.js +26 -70
  320. package/lib/esm/function/arithmetic/log.js +7 -10
  321. package/lib/esm/function/arithmetic/log10.js +1 -3
  322. package/lib/esm/function/arithmetic/log1p.js +4 -6
  323. package/lib/esm/function/arithmetic/log2.js +1 -3
  324. package/lib/esm/function/arithmetic/mod.js +21 -62
  325. package/lib/esm/function/arithmetic/multiply.js +23 -27
  326. package/lib/esm/function/arithmetic/multiplyScalar.js +2 -13
  327. package/lib/esm/function/arithmetic/norm.js +0 -4
  328. package/lib/esm/function/arithmetic/nthRoot.js +41 -76
  329. package/lib/esm/function/arithmetic/nthRoots.js +2 -2
  330. package/lib/esm/function/arithmetic/round.js +26 -28
  331. package/lib/esm/function/arithmetic/sign.js +5 -7
  332. package/lib/esm/function/arithmetic/sqrt.js +5 -8
  333. package/lib/esm/function/arithmetic/square.js +6 -9
  334. package/lib/esm/function/arithmetic/subtract.js +31 -95
  335. package/lib/esm/function/arithmetic/unaryMinus.js +6 -16
  336. package/lib/esm/function/arithmetic/unaryPlus.js +2 -4
  337. package/lib/esm/function/bitwise/bitAnd.js +16 -59
  338. package/lib/esm/function/bitwise/bitNot.js +2 -4
  339. package/lib/esm/function/bitwise/bitOr.js +16 -59
  340. package/lib/esm/function/bitwise/bitXor.js +16 -59
  341. package/lib/esm/function/bitwise/leftShift.js +39 -61
  342. package/lib/esm/function/bitwise/rightArithShift.js +39 -61
  343. package/lib/esm/function/bitwise/rightLogShift.js +39 -61
  344. package/lib/esm/function/bitwise/useMatrixForArrayScalar.js +13 -0
  345. package/lib/esm/function/complex/arg.js +1 -3
  346. package/lib/esm/function/complex/conj.js +3 -12
  347. package/lib/esm/function/complex/im.js +4 -15
  348. package/lib/esm/function/complex/re.js +3 -15
  349. package/lib/esm/function/geometry/distance.js +2 -2
  350. package/lib/esm/function/logical/and.js +35 -57
  351. package/lib/esm/function/logical/not.js +3 -6
  352. package/lib/esm/function/logical/or.js +16 -61
  353. package/lib/esm/function/logical/xor.js +16 -61
  354. package/lib/esm/function/matrix/diff.js +3 -8
  355. package/lib/esm/function/matrix/ones.js +2 -1
  356. package/lib/esm/function/matrix/rotate.js +5 -5
  357. package/lib/esm/function/matrix/sqrtm.js +3 -2
  358. package/lib/esm/function/matrix/transpose.js +47 -50
  359. package/lib/esm/function/matrix/zeros.js +2 -1
  360. package/lib/esm/function/probability/factorial.js +1 -3
  361. package/lib/esm/function/probability/gamma.js +38 -39
  362. package/lib/esm/function/probability/kldivergence.js +3 -2
  363. package/lib/esm/function/probability/lgamma.js +29 -29
  364. package/lib/esm/function/relational/compare.js +21 -67
  365. package/lib/esm/function/relational/compareNatural.js +54 -49
  366. package/lib/esm/function/relational/compareText.js +10 -42
  367. package/lib/esm/function/relational/compareUnits.js +15 -0
  368. package/lib/esm/function/relational/equal.js +19 -79
  369. package/lib/esm/function/relational/equalScalar.js +6 -9
  370. package/lib/esm/function/relational/larger.js +23 -73
  371. package/lib/esm/function/relational/largerEq.js +23 -73
  372. package/lib/esm/function/relational/smaller.js +23 -73
  373. package/lib/esm/function/relational/smallerEq.js +23 -73
  374. package/lib/esm/function/relational/unequal.js +19 -79
  375. package/lib/esm/function/special/erf.js +1 -3
  376. package/lib/esm/function/statistics/std.js +10 -2
  377. package/lib/esm/function/string/format.js +2 -2
  378. package/lib/esm/function/string/hex.js +1 -2
  379. package/lib/esm/function/trigonometry/acos.js +4 -7
  380. package/lib/esm/function/trigonometry/acosh.js +2 -6
  381. package/lib/esm/function/trigonometry/acot.js +6 -10
  382. package/lib/esm/function/trigonometry/acoth.js +4 -7
  383. package/lib/esm/function/trigonometry/acsc.js +6 -10
  384. package/lib/esm/function/trigonometry/acsch.js +4 -7
  385. package/lib/esm/function/trigonometry/asec.js +6 -9
  386. package/lib/esm/function/trigonometry/asech.js +4 -7
  387. package/lib/esm/function/trigonometry/asin.js +5 -9
  388. package/lib/esm/function/trigonometry/asinh.js +4 -8
  389. package/lib/esm/function/trigonometry/atan.js +5 -10
  390. package/lib/esm/function/trigonometry/atan2.js +26 -65
  391. package/lib/esm/function/trigonometry/atanh.js +4 -8
  392. package/lib/esm/function/trigonometry/cos.js +11 -22
  393. package/lib/esm/function/trigonometry/cosh.js +5 -20
  394. package/lib/esm/function/trigonometry/cot.js +10 -20
  395. package/lib/esm/function/trigonometry/coth.js +6 -20
  396. package/lib/esm/function/trigonometry/csc.js +12 -22
  397. package/lib/esm/function/trigonometry/csch.js +6 -20
  398. package/lib/esm/function/trigonometry/sec.js +12 -22
  399. package/lib/esm/function/trigonometry/sech.js +6 -20
  400. package/lib/esm/function/trigonometry/sin.js +11 -23
  401. package/lib/esm/function/trigonometry/sinh.js +5 -21
  402. package/lib/esm/function/trigonometry/tan.js +11 -23
  403. package/lib/esm/function/trigonometry/tanh.js +5 -21
  404. package/lib/esm/function/trigonometry/trigUnit.js +15 -0
  405. package/lib/esm/function/unit/to.js +8 -43
  406. package/lib/esm/function/utils/clone.js +1 -1
  407. package/lib/esm/function/utils/hasNumericValue.js +3 -1
  408. package/lib/esm/function/utils/isInteger.js +2 -4
  409. package/lib/esm/function/utils/isNaN.js +1 -1
  410. package/lib/esm/function/utils/isNegative.js +3 -7
  411. package/lib/esm/function/utils/isNumeric.js +4 -10
  412. package/lib/esm/function/utils/isPositive.js +3 -7
  413. package/lib/esm/function/utils/isPrime.js +1 -3
  414. package/lib/esm/function/utils/isZero.js +13 -17
  415. package/lib/esm/function/utils/numeric.js +11 -4
  416. package/lib/esm/function/utils/typeOf.js +38 -44
  417. package/lib/esm/type/bignumber/function/bignumber.js +1 -3
  418. package/lib/esm/type/boolean.js +1 -3
  419. package/lib/esm/type/chain/Chain.js +23 -3
  420. package/lib/esm/type/complex/Complex.js +4 -0
  421. package/lib/esm/type/complex/function/complex.js +1 -3
  422. package/lib/esm/type/fraction/Fraction.js +4 -0
  423. package/lib/esm/type/fraction/function/fraction.js +1 -3
  424. package/lib/esm/type/matrix/DenseMatrix.js +15 -1
  425. package/lib/esm/type/matrix/SparseMatrix.js +9 -0
  426. package/lib/esm/type/matrix/utils/{algorithm01.js → matAlgo01xDSid.js} +2 -2
  427. package/lib/esm/type/matrix/utils/{algorithm02.js → matAlgo02xDS0.js} +3 -3
  428. package/lib/esm/type/matrix/utils/{algorithm03.js → matAlgo03xDSf.js} +3 -3
  429. package/lib/esm/type/matrix/utils/{algorithm04.js → matAlgo04xSidSid.js} +5 -5
  430. package/lib/esm/type/matrix/utils/{algorithm05.js → matAlgo05xSfSf.js} +3 -3
  431. package/lib/esm/type/matrix/utils/{algorithm06.js → matAlgo06xS0S0.js} +3 -3
  432. package/lib/esm/type/matrix/utils/{algorithm07.js → matAlgo07xSSf.js} +3 -3
  433. package/lib/esm/type/matrix/utils/{algorithm08.js → matAlgo08xS0Sid.js} +4 -4
  434. package/lib/esm/type/matrix/utils/{algorithm09.js → matAlgo09xS0Sf.js} +3 -3
  435. package/lib/esm/type/matrix/utils/{algorithm10.js → matAlgo10xSids.js} +3 -3
  436. package/lib/esm/type/matrix/utils/{algorithm11.js → matAlgo11xS0s.js} +3 -3
  437. package/lib/esm/type/matrix/utils/{algorithm12.js → matAlgo12xSfs.js} +3 -3
  438. package/lib/esm/type/matrix/utils/{algorithm13.js → matAlgo13xDD.js} +3 -3
  439. package/lib/esm/type/matrix/utils/{algorithm14.js → matAlgo14xDs.js} +3 -3
  440. package/lib/esm/type/matrix/utils/matrixAlgorithmSuite.js +168 -0
  441. package/lib/esm/type/number.js +1 -3
  442. package/lib/esm/type/string.js +1 -3
  443. package/lib/esm/type/unit/Unit.js +85 -36
  444. package/lib/esm/type/unit/function/createUnit.js +2 -1
  445. package/lib/esm/type/unit/function/unit.js +10 -5
  446. package/lib/esm/utils/is.js +18 -18
  447. package/lib/esm/utils/snapshot.js +22 -48
  448. package/lib/esm/version.js +1 -1
  449. package/package.json +22 -25
  450. package/types/index.d.ts +211 -180
  451. package/types/index.ts +358 -144
  452. package/types/tsconfig.json +4 -1
  453. package/lib/cjs/utils/polyfills.js +0 -14
  454. package/lib/esm/utils/polyfills.js +0 -12
package/types/index.d.ts CHANGED
@@ -478,6 +478,12 @@ declare namespace math {
478
478
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
479
479
  reviver(): (key: any, value: any) => any
480
480
 
481
+ /**
482
+ * Returns replacer function that can be used as replacer in JSON.stringify function.
483
+ */
484
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
485
+ replacer(): (key: any, value: any) => any
486
+
481
487
  /*************************************************************************
482
488
  * Core functions
483
489
  ************************************************************************/
@@ -589,7 +595,7 @@ declare namespace math {
589
595
  */
590
596
  createUnit(
591
597
  name: string,
592
- definition?: string | UnitDefinition,
598
+ definition?: string | UnitDefinition | Unit,
593
599
  options?: CreateUnitOptions
594
600
  ): Unit
595
601
  /**
@@ -599,7 +605,7 @@ declare namespace math {
599
605
  * @returns The new unit
600
606
  */
601
607
  createUnit(
602
- units: Record<string, string | UnitDefinition>,
608
+ units: Record<string, string | UnitDefinition | Unit>,
603
609
  options?: CreateUnitOptions
604
610
  ): Unit
605
611
 
@@ -647,7 +653,7 @@ declare namespace math {
647
653
  * @returns The created Matrix
648
654
  */
649
655
  matrix(
650
- data: MathCollection,
656
+ data: MathCollection | string[],
651
657
  format?: 'sparse' | 'dense',
652
658
  dataType?: string
653
659
  ): Matrix
@@ -890,15 +896,26 @@ declare namespace math {
890
896
  */
891
897
  simplify: Simplify
892
898
 
899
+ simplifyConstant(
900
+ expr: MathNode | string,
901
+ options?: SimplifyOptions
902
+ ): MathNode
903
+ simplifyCore(expr: MathNode | string, options?: SimplifyOptions): MathNode
904
+
893
905
  /**
894
906
  * Replaces variable nodes with their scoped values
895
907
  * @param node Tree to replace variable nodes in
896
908
  * @param scope Scope to read/write variables
897
909
  */
898
910
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
899
- resolve(node: MathNode, scope?: Record<string, any>): MathNode
911
+ resolve(node: MathNode | string, scope?: Record<string, any>): MathNode
912
+ resolve(
913
+ node: (MathNode | string)[],
914
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
915
+ scope?: Record<string, any>
916
+ ): MathNode[]
900
917
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
901
- resolve(node: MathNode[], scope?: Record<string, any>): MathNode[]
918
+ resolve(node: Matrix, scope?: Record<string, any>): Matrix
902
919
 
903
920
  /**
904
921
  * Calculate the Sparse Matrix LU decomposition with full pivoting.
@@ -960,8 +977,7 @@ declare namespace math {
960
977
  add(x: MathType, y: MathType): MathType
961
978
 
962
979
  /**
963
- * Calculate the cubic root of a value. For matrices, the function is
964
- * evaluated element wise.
980
+ * Calculate the cubic root of a value.
965
981
  * @param x Value for which to calculate the cubic root.
966
982
  * @param allRoots Optional, false by default. Only applicable when x is
967
983
  * a number or complex number. If true, all complex roots are returned,
@@ -969,10 +985,9 @@ declare namespace math {
969
985
  * @returns Returns the cubic root of x
970
986
  */
971
987
  cbrt(x: number, allRoots?: boolean): number
972
- cbrt(x: BigNumber, allRoots?: boolean): BigNumber
988
+ cbrt(x: BigNumber): BigNumber
973
989
  cbrt(x: Complex, allRoots?: boolean): Complex
974
- cbrt(x: MathArray, allRoots?: boolean): MathArray
975
- cbrt(x: Matrix, allRoots?: boolean): Matrix
990
+ cbrt(x: Unit): Unit
976
991
 
977
992
  // Rounding functions, grouped for similarity, even though it breaks
978
993
  // the alphabetic order among arithmetic functions.
@@ -1042,8 +1057,6 @@ declare namespace math {
1042
1057
  cube(x: BigNumber): BigNumber
1043
1058
  cube(x: Fraction): Fraction
1044
1059
  cube(x: Complex): Complex
1045
- cube(x: MathArray): MathArray
1046
- cube(x: Matrix): Matrix
1047
1060
  cube(x: Unit): Unit
1048
1061
 
1049
1062
  /**
@@ -1093,8 +1106,6 @@ declare namespace math {
1093
1106
  exp(x: number): number
1094
1107
  exp(x: BigNumber): BigNumber
1095
1108
  exp(x: Complex): Complex
1096
- exp(x: MathArray): MathArray
1097
- exp(x: Matrix): Matrix
1098
1109
 
1099
1110
  /**
1100
1111
  * Calculate the value of subtracting 1 from the exponential value. For
@@ -1105,8 +1116,6 @@ declare namespace math {
1105
1116
  expm1(x: number): number
1106
1117
  expm1(x: BigNumber): BigNumber
1107
1118
  expm1(x: Complex): Complex
1108
- expm1(x: MathArray): MathArray
1109
- expm1(x: Matrix): Matrix
1110
1119
 
1111
1120
  /**
1112
1121
  * Calculate the greatest common divisor for two or more values or
@@ -1147,14 +1156,13 @@ declare namespace math {
1147
1156
  lcm(a: Matrix, b: Matrix): Matrix
1148
1157
 
1149
1158
  /**
1150
- * Calculate the logarithm of a value. For matrices, the function is
1151
- * evaluated element wise.
1159
+ * Calculate the logarithm of a value.
1152
1160
  * @param x Value for which to calculate the logarithm.
1153
1161
  * @param base Optional base for the logarithm. If not provided, the
1154
1162
  * natural logarithm of x is calculated. Default value: e.
1155
1163
  * @returns Returns the logarithm of x
1156
1164
  */
1157
- log<T extends number | BigNumber | Complex | MathCollection>(
1165
+ log<T extends number | BigNumber | Complex>(
1158
1166
  x: T,
1159
1167
  base?: number | BigNumber | Complex
1160
1168
  ): NoLiteralType<T>
@@ -1216,9 +1224,13 @@ declare namespace math {
1216
1224
  * @param y The second value to multiply
1217
1225
  * @returns Multiplication of x and y
1218
1226
  */
1219
- multiply<T extends Matrix | MathArray>(x: T, y: MathType): T
1227
+
1228
+ multiply<T extends Matrix>(x: T, y: MathType): Matrix
1229
+ multiply<T extends Matrix>(x: MathType, y: T): Matrix
1230
+
1220
1231
  multiply(x: Unit, y: Unit): Unit
1221
1232
  multiply(x: number, y: number): number
1233
+ multiply(x: MathArray, y: MathArray): MathArray
1222
1234
  multiply(x: MathType, y: MathType): MathType
1223
1235
 
1224
1236
  /**
@@ -1273,21 +1285,19 @@ declare namespace math {
1273
1285
  sign(x: Unit): Unit
1274
1286
 
1275
1287
  /**
1276
- * Calculate the square root of a value. For matrices, the function is
1277
- * evaluated element wise.
1288
+ * Calculate the square root of a value. For matrices, use either
1289
+ * sqrtm for the matrix square root, or map(M, sqrt) to take the
1290
+ * square root element wise.
1278
1291
  * @param x Value for which to calculate the square root
1279
1292
  * @returns Returns the square root of x
1280
1293
  */
1281
- sqrt(x: number): number
1294
+ sqrt(x: number): number | Complex
1282
1295
  sqrt(x: BigNumber): BigNumber
1283
1296
  sqrt(x: Complex): Complex
1284
- sqrt(x: MathArray): MathArray
1285
- sqrt(x: Matrix): Matrix
1286
1297
  sqrt(x: Unit): Unit
1287
1298
 
1288
1299
  /**
1289
- * Compute the square of a value, x * x. For matrices, the function is
1290
- * evaluated element wise.
1300
+ * Compute the square of a value, x * x.
1291
1301
  * @param x Number for which to calculate the square
1292
1302
  * @returns Squared value
1293
1303
  */
@@ -1295,8 +1305,6 @@ declare namespace math {
1295
1305
  square(x: BigNumber): BigNumber
1296
1306
  square(x: Fraction): Fraction
1297
1307
  square(x: Complex): Complex
1298
- square(x: MathArray): MathArray
1299
- square(x: Matrix): Matrix
1300
1308
  square(x: Unit): Unit
1301
1309
 
1302
1310
  /**
@@ -1850,14 +1858,37 @@ declare namespace math {
1850
1858
  * @param format The matrix storage format
1851
1859
  * @returns A matrix filled with ones
1852
1860
  */
1853
- ones(size: number | number[], format?: string): MathCollection
1861
+ ones(
1862
+ size?: number | number[] | BigNumber | BigNumber[],
1863
+ format?: string
1864
+ ): MathCollection
1854
1865
  /**
1855
1866
  * @param m The x dimension of the matrix
1856
- * @param n The y dimension of the amtrix
1867
+ * @param n The y dimension of the matrix
1857
1868
  * @param format The matrix storage format
1858
1869
  * @returns A matrix filled with ones
1859
1870
  */
1860
- ones(m: number, n: number, format?: string): MathCollection
1871
+ ones(
1872
+ m: number | BigNumber,
1873
+ n: number | BigNumber,
1874
+ format?: string
1875
+ ): MathCollection
1876
+ /**
1877
+ * @param m The x dimension of the matrix
1878
+ * @param n The y dimension of the matrix
1879
+ * @param p The z dimension of the matrix
1880
+ * @param format The matrix storage format
1881
+ * @returns A matrix filled with ones
1882
+ */
1883
+ ones(
1884
+ m: number | BigNumber,
1885
+ n: number | BigNumber,
1886
+ p: number | BigNumber,
1887
+ format?: string
1888
+ ): MathCollection
1889
+ /** Actually ones can take an arbitrary number of dimensions before the
1890
+ ** optional format, not sure how to write that in TypeScript
1891
+ **/
1861
1892
 
1862
1893
  /**
1863
1894
  * Partition-based selection of an array or 1D matrix. Will find the kth
@@ -2038,14 +2069,37 @@ declare namespace math {
2038
2069
  * @param format The matrix storage format
2039
2070
  * @returns A matrix filled with zeros
2040
2071
  */
2041
- zeros(size: number | number[], format?: string): MathCollection
2072
+ zeros(
2073
+ size?: number | number[] | BigNumber | BigNumber[],
2074
+ format?: string
2075
+ ): MathCollection
2042
2076
  /**
2043
2077
  * @param m The x dimension of the matrix
2044
2078
  * @param n The y dimension of the matrix
2045
2079
  * @param format The matrix storage format
2046
2080
  * @returns A matrix filled with zeros
2047
2081
  */
2048
- zeros(m: number, n: number, format?: string): MathCollection
2082
+ zeros(
2083
+ m: number | BigNumber,
2084
+ n: number | BigNumber,
2085
+ format?: string
2086
+ ): MathCollection
2087
+ /**
2088
+ * @param m The x dimension of the matrix
2089
+ * @param n The y dimension of the matrix
2090
+ * @param p The z dimension of the matrix
2091
+ * @param format The matrix storage format
2092
+ * @returns A matrix filled with zeros
2093
+ */
2094
+ zeros(
2095
+ m: number | BigNumber,
2096
+ n: number | BigNumber,
2097
+ p: number | BigNumber,
2098
+ format?: string
2099
+ ): MathCollection
2100
+ /** Actually zeros can take any number of dimensions before the
2101
+ ** optional format, not sure how to write that in TypeScript
2102
+ **/
2049
2103
 
2050
2104
  /**
2051
2105
  * Calculate N-dimensional fourier transform
@@ -2092,13 +2146,11 @@ declare namespace math {
2092
2146
  /**
2093
2147
  * Compute the gamma function of a value using Lanczos approximation for
2094
2148
  * small values, and an extended Stirling approximation for large
2095
- * values. For matrices, the function is evaluated element wise.
2149
+ * values.
2096
2150
  * @param n A real or complex number
2097
2151
  * @returns The gamma of n
2098
2152
  */
2099
- gamma<T extends number | BigNumber | Complex | MathCollection>(
2100
- n: T
2101
- ): NoLiteralType<T>
2153
+ gamma<T extends number | BigNumber | Complex>(n: T): NoLiteralType<T>
2102
2154
 
2103
2155
  /**
2104
2156
  * Calculate the Kullback-Leibler (KL) divergence between two
@@ -2654,6 +2706,13 @@ declare namespace math {
2654
2706
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2655
2707
  sum(array: MathCollection): any
2656
2708
 
2709
+ /**
2710
+ * Count the number of elements of a matrix, array or string.
2711
+ * @param x A matrix, array or string.
2712
+ * @returns The number of members passed in parameters
2713
+ */
2714
+ count(x: MathCollection | string): number
2715
+
2657
2716
  /**
2658
2717
  * Compute the cumulative sum of a matrix or a list with values.
2659
2718
  * In case of a (multi dimensional) array or matrix, the cumulative sums
@@ -2770,133 +2829,108 @@ declare namespace math {
2770
2829
  ************************************************************************/
2771
2830
 
2772
2831
  /**
2773
- * Calculate the inverse cosine of a value. For matrices, the function
2774
- * is evaluated element wise.
2832
+ * Calculate the inverse cosine of a value.
2775
2833
  * @param x Function input
2776
2834
  * @returns The arc cosine of x
2777
2835
  */
2778
- acos(x: number): number
2836
+ acos(x: number): number | Complex
2779
2837
  acos(x: BigNumber): BigNumber
2780
2838
  acos(x: Complex): Complex
2781
- acos(x: MathArray): MathArray
2782
- acos(x: Matrix): Matrix
2783
2839
 
2784
2840
  /**
2785
2841
  * Calculate the hyperbolic arccos of a value, defined as acosh(x) =
2786
- * ln(sqrt(x^2 - 1) + x). For matrices, the function is evaluated
2787
- * element wise.
2842
+ * ln(sqrt(x^2 - 1) + x).
2788
2843
  * @param x Function input
2789
2844
  * @returns The hyperbolic arccosine of x
2790
2845
  */
2791
- acosh(x: number): number
2846
+ acosh(x: number): number | Complex
2792
2847
  acosh(x: BigNumber): BigNumber
2793
2848
  acosh(x: Complex): Complex
2794
- acosh(x: MathArray): MathArray
2795
- acosh(x: Matrix): Matrix
2796
2849
 
2797
2850
  /**
2798
- * Calculate the inverse cotangent of a value. For matrices, the
2799
- * function is evaluated element wise.
2851
+ * Calculate the inverse cotangent of a value.
2800
2852
  * @param x Function input
2801
2853
  * @returns The arc cotangent of x
2802
2854
  */
2803
2855
  acot(x: number): number
2804
2856
  acot(x: BigNumber): BigNumber
2805
- acot(x: MathArray): MathArray
2806
- acot(x: Matrix): Matrix
2857
+ acot(x: Complex): Complex
2807
2858
 
2808
2859
  /**
2809
2860
  * Calculate the hyperbolic arccotangent of a value, defined as acoth(x)
2810
- * = (ln((x+1)/x) + ln(x/(x-1))) / 2. For matrices, the function is
2811
- * evaluated element wise.
2861
+ * = (ln((x+1)/x) + ln(x/(x-1))) / 2.
2812
2862
  * @param x Function input
2813
2863
  * @returns The hyperbolic arccotangent of x
2814
2864
  */
2815
2865
  acoth(x: number): number
2816
2866
  acoth(x: BigNumber): BigNumber
2817
- acoth(x: MathArray): MathArray
2818
- acoth(x: Matrix): Matrix
2867
+ acoth(x: Complex): Complex
2819
2868
 
2820
2869
  /**
2821
- * Calculate the inverse cosecant of a value. For matrices, the function
2822
- * is evaluated element wise.
2870
+ * Calculate the inverse cosecant of a value.
2823
2871
  * @param x Function input
2824
2872
  * @returns The arc cosecant of x
2825
2873
  */
2826
- acsc(x: number): number
2874
+ acsc(x: number): number | Complex
2827
2875
  acsc(x: BigNumber): BigNumber
2828
- acsc(x: MathArray): MathArray
2829
- acsc(x: Matrix): Matrix
2876
+ acsc(x: Complex): Complex
2830
2877
 
2831
2878
  /**
2832
2879
  * Calculate the hyperbolic arccosecant of a value, defined as acsch(x)
2833
- * = ln(1/x + sqrt(1/x^2 + 1)). For matrices, the function is evaluated
2834
- * element wise.
2880
+ * = ln(1/x + sqrt(1/x^2 + 1)).
2835
2881
  * @param x Function input
2836
2882
  * @returns The hyperbolic arccosecant of x
2837
2883
  */
2838
2884
  acsch(x: number): number
2839
2885
  acsch(x: BigNumber): BigNumber
2840
- acsch(x: MathArray): MathArray
2841
- acsch(x: Matrix): Matrix
2886
+ acsch(x: Complex): Complex
2842
2887
 
2843
2888
  /**
2844
- * Calculate the inverse secant of a value. For matrices, the function
2845
- * is evaluated element wise.
2889
+ * Calculate the inverse secant of a value.
2846
2890
  * @param x Function input
2847
2891
  * @returns The arc secant of x
2848
2892
  */
2849
- asec(x: number): number
2893
+ asec(x: number): number | Complex
2850
2894
  asec(x: BigNumber): BigNumber
2851
- asec(x: MathArray): MathArray
2852
- asec(x: Matrix): Matrix
2895
+ asec(x: Complex): Complex
2853
2896
 
2854
2897
  /**
2855
2898
  * Calculate the hyperbolic arcsecant of a value, defined as asech(x) =
2856
- * ln(sqrt(1/x^2 - 1) + 1/x). For matrices, the function is evaluated
2857
- * element wise.
2899
+ * ln(sqrt(1/x^2 - 1) + 1/x).
2858
2900
  * @param x Function input
2859
2901
  * @returns The hyperbolic arcsecant of x
2860
2902
  */
2861
- asech(x: number): number
2903
+ asech(x: number): number | Complex
2862
2904
  asech(x: BigNumber): BigNumber
2863
- asech(x: MathArray): MathArray
2864
- asech(x: Matrix): Matrix
2905
+ asech(x: Complex): Complex
2865
2906
 
2866
2907
  /**
2867
- * Calculate the inverse sine of a value. For matrices, the function is
2868
- * evaluated element wise.
2908
+ * Calculate the inverse sine of a value.
2869
2909
  * @param x Function input
2870
2910
  * @returns The arc sine of x
2871
2911
  */
2872
- asin(x: number): number
2912
+ asin(x: number): number | Complex
2873
2913
  asin(x: BigNumber): BigNumber
2874
2914
  asin(x: Complex): Complex
2875
- asin(x: MathArray): MathArray
2876
- asin(x: Matrix): Matrix
2877
2915
 
2878
2916
  /**
2879
2917
  * Calculate the hyperbolic arcsine of a value, defined as asinh(x) =
2880
- * ln(x + sqrt(x^2 + 1)). For matrices, the function is evaluated
2881
- * element wise.
2918
+ * ln(x + sqrt(x^2 + 1)).
2882
2919
  * @param x Function input
2883
2920
  * @returns The hyperbolic arcsine of x
2884
2921
  */
2885
2922
  asinh(x: number): number
2886
2923
  asinh(x: BigNumber): BigNumber
2887
- asinh(x: MathArray): MathArray
2888
- asinh(x: Matrix): Matrix
2924
+ asinh(x: Complex): Complex
2889
2925
 
2890
2926
  /**
2891
- * Calculate the inverse tangent of a value. For matrices, the function
2892
- * is evaluated element wise.
2927
+ * Calculate the inverse tangent of a value.
2893
2928
  * @param x Function input
2894
2929
  * @returns The arc tangent of x
2895
2930
  */
2896
2931
  atan(x: number): number
2897
2932
  atan(x: BigNumber): BigNumber
2898
- atan(x: MathArray): MathArray
2899
- atan(x: Matrix): Matrix
2933
+ atan(x: Complex): Complex
2900
2934
 
2901
2935
  /**
2902
2936
  * Calculate the inverse tangent function with two arguments, y/x. By
@@ -2910,156 +2944,127 @@ declare namespace math {
2910
2944
 
2911
2945
  /**
2912
2946
  * Calculate the hyperbolic arctangent of a value, defined as atanh(x) =
2913
- * ln((1 + x)/(1 - x)) / 2. For matrices, the function is evaluated
2914
- * element wise.
2947
+ * ln((1 + x)/(1 - x)) / 2.
2915
2948
  * @param x Function input
2916
2949
  * @returns The hyperbolic arctangent of x
2917
2950
  */
2918
- atanh(x: number): number
2951
+ atanh(x: number): number | Complex
2919
2952
  atanh(x: BigNumber): BigNumber
2920
- atanh(x: MathArray): MathArray
2921
- atanh(x: Matrix): Matrix
2953
+ atanh(x: Complex): Complex
2922
2954
 
2923
2955
  /**
2924
- * Calculate the cosine of a value. For matrices, the function is
2925
- * evaluated element wise.
2956
+ * Calculate the cosine of a value.
2926
2957
  * @param x Function input
2927
2958
  * @returns The cosine of x
2928
2959
  */
2929
2960
  cos(x: number | Unit): number
2930
2961
  cos(x: BigNumber): BigNumber
2931
2962
  cos(x: Complex): Complex
2932
- cos(x: MathArray): MathArray
2933
- cos(x: Matrix): Matrix
2934
2963
 
2935
2964
  /**
2936
2965
  * Calculate the hyperbolic cosine of a value, defined as cosh(x) = 1/2
2937
- * * (exp(x) + exp(-x)). For matrices, the function is evaluated element
2938
- * wise.
2966
+ * * (exp(x) + exp(-x)).
2939
2967
  * @param x Function input
2940
2968
  * @returns The hyperbolic cosine of x
2941
2969
  */
2942
2970
  cosh(x: number | Unit): number
2943
2971
  cosh(x: BigNumber): BigNumber
2944
2972
  cosh(x: Complex): Complex
2945
- cosh(x: MathArray): MathArray
2946
- cosh(x: Matrix): Matrix
2947
2973
 
2948
2974
  /**
2949
2975
  * Calculate the cotangent of a value. cot(x) is defined as 1 / tan(x).
2950
- * For matrices, the function is evaluated element wise.
2951
2976
  * @param x Function input
2952
2977
  * @returns The cotangent of x
2953
2978
  */
2954
2979
  cot(x: number | Unit): number
2980
+ cot(x: BigNumber): BigNumber
2955
2981
  cot(x: Complex): Complex
2956
- cot(x: MathArray): MathArray
2957
- cot(x: Matrix): Matrix
2958
2982
 
2959
2983
  /**
2960
2984
  * Calculate the hyperbolic cotangent of a value, defined as coth(x) = 1
2961
- * / tanh(x). For matrices, the function is evaluated element wise.
2985
+ * / tanh(x).
2962
2986
  * @param x Function input
2963
2987
  * @returns The hyperbolic cotangent of x
2964
2988
  */
2965
2989
  coth(x: number | Unit): number
2990
+ coth(x: BigNumber): BigNumber
2966
2991
  coth(x: Complex): Complex
2967
- coth(x: MathArray): MathArray
2968
- coth(x: Matrix): Matrix
2969
2992
 
2970
2993
  /**
2971
- * Calculate the cosecant of a value, defined as csc(x) = 1/sin(x). For
2972
- * matrices, the function is evaluated element wise.
2994
+ * Calculate the cosecant of a value, defined as csc(x) = 1/sin(x).
2973
2995
  * @param x Function input
2974
2996
  * @returns The cosecant hof x
2975
2997
  */
2976
2998
  csc(x: number | Unit): number
2999
+ csc(x: BigNumber): BigNumber
2977
3000
  csc(x: Complex): Complex
2978
- csc(x: MathArray): MathArray
2979
- csc(x: Matrix): Matrix
2980
3001
 
2981
3002
  /**
2982
3003
  * Calculate the hyperbolic cosecant of a value, defined as csch(x) = 1
2983
- * / sinh(x). For matrices, the function is evaluated element wise.
3004
+ * / sinh(x).
2984
3005
  * @param x Function input
2985
3006
  * @returns The hyperbolic cosecant of x
2986
3007
  */
2987
3008
  csch(x: number | Unit): number
3009
+ csch(x: BigNumber): BigNumber
2988
3010
  csch(x: Complex): Complex
2989
- csch(x: MathArray): MathArray
2990
- csch(x: Matrix): Matrix
2991
3011
 
2992
3012
  /**
2993
- * Calculate the secant of a value, defined as sec(x) = 1/cos(x). For
2994
- * matrices, the function is evaluated element wise.
3013
+ * Calculate the secant of a value, defined as sec(x) = 1/cos(x).
2995
3014
  * @param x Function input
2996
3015
  * @returns The secant of x
2997
3016
  */
2998
3017
  sec(x: number | Unit): number
3018
+ sec(x: BigNumber): BigNumber
2999
3019
  sec(x: Complex): Complex
3000
- sec(x: MathArray): MathArray
3001
- sec(x: Matrix): Matrix
3002
3020
 
3003
3021
  /**
3004
3022
  * Calculate the hyperbolic secant of a value, defined as sech(x) = 1 /
3005
- * cosh(x). For matrices, the function is evaluated element wise.
3023
+ * cosh(x).
3006
3024
  * @param x Function input
3007
3025
  * @returns The hyperbolic secant of x
3008
3026
  */
3009
3027
  sech(x: number | Unit): number
3028
+ sech(x: BigNumber): BigNumber
3010
3029
  sech(x: Complex): Complex
3011
- sech(x: MathArray): MathArray
3012
- sech(x: Matrix): Matrix
3013
3030
 
3014
3031
  /**
3015
- * Calculate the sine of a value. For matrices, the function is
3016
- * evaluated element wise.
3032
+ * Calculate the sine of a value.
3017
3033
  * @param x Function input
3018
3034
  * @returns The sine of x
3019
3035
  */
3020
3036
  sin(x: number | Unit): number
3021
3037
  sin(x: BigNumber): BigNumber
3022
3038
  sin(x: Complex): Complex
3023
- sin(x: MathArray): MathArray
3024
- sin(x: Matrix): Matrix
3025
3039
 
3026
3040
  /**
3027
3041
  * Calculate the hyperbolic sine of a value, defined as sinh(x) = 1/2 *
3028
- * (exp(x) - exp(-x)). For matrices, the function is evaluated element
3029
- * wise.
3042
+ * (exp(x) - exp(-x)).
3030
3043
  * @param x Function input
3031
3044
  * @returns The hyperbolic sine of x
3032
3045
  */
3033
3046
  sinh(x: number | Unit): number
3034
3047
  sinh(x: BigNumber): BigNumber
3035
3048
  sinh(x: Complex): Complex
3036
- sinh(x: MathArray): MathArray
3037
- sinh(x: Matrix): Matrix
3038
3049
 
3039
3050
  /**
3040
3051
  * Calculate the tangent of a value. tan(x) is equal to sin(x) / cos(x).
3041
- * For matrices, the function is evaluated element wise.
3042
3052
  * @param x Function input
3043
3053
  * @returns The tangent of x
3044
3054
  */
3045
3055
  tan(x: number | Unit): number
3046
3056
  tan(x: BigNumber): BigNumber
3047
3057
  tan(x: Complex): Complex
3048
- tan(x: MathArray): MathArray
3049
- tan(x: Matrix): Matrix
3050
3058
 
3051
3059
  /**
3052
3060
  * Calculate the hyperbolic tangent of a value, defined as tanh(x) =
3053
- * (exp(2 * x) - 1) / (exp(2 * x) + 1). For matrices, the function is
3054
- * evaluated element wise.
3061
+ * (exp(2 * x) - 1) / (exp(2 * x) + 1).
3055
3062
  * @param x Function input
3056
3063
  * @returns The hyperbolic tangent of x
3057
3064
  */
3058
3065
  tanh(x: number | Unit): number
3059
3066
  tanh(x: BigNumber): BigNumber
3060
3067
  tanh(x: Complex): Complex
3061
- tanh(x: MathArray): MathArray
3062
- tanh(x: Matrix): Matrix
3063
3068
 
3064
3069
  /*************************************************************************
3065
3070
  * Unit functions
@@ -3766,6 +3771,18 @@ declare namespace math {
3766
3771
  override?: boolean
3767
3772
  }
3768
3773
 
3774
+ type SimplifyContext = Partial<
3775
+ Record<
3776
+ OperatorNodeFn,
3777
+ {
3778
+ trivial: boolean
3779
+ total: boolean
3780
+ commutative: boolean
3781
+ associative: boolean
3782
+ }
3783
+ >
3784
+ >
3785
+
3769
3786
  interface SimplifyOptions {
3770
3787
  /** A boolean which is `true` by default. */
3771
3788
  exactFractions?: boolean
@@ -3775,23 +3792,46 @@ declare namespace math {
3775
3792
  * Default value is 10000.
3776
3793
  */
3777
3794
  fractionsLimit?: number
3795
+ /** A boolean which is `false` by default. */
3796
+ consoleDebug?: boolean
3797
+ /**
3798
+ * gives properties of each operator, which determine what simplifications
3799
+ * are allowed. Properties are commutative, associative, total (whether
3800
+ * the operation is defined for all arguments), and trivial (whether
3801
+ * the operation applied to a single argument leaves that argument
3802
+ * unchanged).
3803
+ */
3804
+ context?: SimplifyContext
3778
3805
  }
3779
3806
 
3780
3807
  type SimplifyRule =
3781
- | { l: string; r: string }
3808
+ | {
3809
+ l: string
3810
+ r: string
3811
+ repeat?: boolean
3812
+ assuming?: SimplifyContext
3813
+ imposeContext?: SimplifyContext
3814
+ }
3815
+ | {
3816
+ s: string
3817
+ repeat?: boolean
3818
+ assuming?: SimplifyContext
3819
+ imposeContext?: SimplifyContext
3820
+ }
3782
3821
  | string
3783
3822
  | ((node: MathNode) => MathNode)
3784
3823
 
3785
3824
  interface Simplify {
3825
+ (expr: MathNode | string): MathNode
3786
3826
  (
3787
3827
  expr: MathNode | string,
3788
- rules?: SimplifyRule[],
3828
+ rules: SimplifyRule[],
3789
3829
  scope?: object,
3790
3830
  options?: SimplifyOptions
3791
3831
  ): MathNode
3792
3832
  (
3793
3833
  expr: MathNode | string,
3794
- scope?: object,
3834
+ scope: object,
3795
3835
  options?: SimplifyOptions
3796
3836
  ): MathNode
3797
3837
 
@@ -4111,7 +4151,7 @@ declare namespace math {
4111
4151
  */
4112
4152
  createUnit(
4113
4153
  this: MathJsChain<string>,
4114
- definition?: string | UnitDefinition,
4154
+ definition?: string | UnitDefinition | Unit,
4115
4155
  options?: CreateUnitOptions
4116
4156
  ): MathJsChain<Unit>
4117
4157
  /**
@@ -4125,7 +4165,7 @@ declare namespace math {
4125
4165
  * 0.
4126
4166
  */
4127
4167
  createUnit(
4128
- this: MathJsChain<Record<string, string | UnitDefinition>>,
4168
+ this: MathJsChain<Record<string, string | UnitDefinition | Unit>>,
4129
4169
  options?: CreateUnitOptions
4130
4170
  ): MathJsChain<Unit>
4131
4171
 
@@ -4376,15 +4416,23 @@ declare namespace math {
4376
4416
  * pass a custom set of rules to the function as second argument. A rule
4377
4417
  * can be specified as an object, string, or function.
4378
4418
  * @param scope Scope to variables
4419
+ * @param options Options to configure the behavior of simplify
4379
4420
  */
4380
4421
  simplify(
4381
4422
  this: MathJsChain<MathNode | string>,
4382
4423
  rules?: SimplifyRule[],
4383
- scope?: object
4424
+ scope?: Map<string, MathType> | object,
4425
+ options?: SimplifyOptions
4384
4426
  ): MathJsChain<MathNode>
4385
4427
 
4386
- // TODO check that this should even be here...
4387
- simplifyCore(expr: MathNode): MathNode
4428
+ simplifyConstant(
4429
+ this: MathJsChain<MathNode | string>,
4430
+ options?: SimplifyOptions
4431
+ ): MathJsChain<MathNode>
4432
+ simplifyCore(
4433
+ this: MathJsChain<MathNode | string>,
4434
+ options?: SimplifyOptions
4435
+ ): MathJsChain<MathNode>
4388
4436
 
4389
4437
  /**
4390
4438
  * Calculate the Sparse Matrix LU decomposition with full pivoting.
@@ -4468,16 +4516,9 @@ declare namespace math {
4468
4516
  * if false (default) the principal root is returned.
4469
4517
  */
4470
4518
  cbrt(this: MathJsChain<number>, allRoots?: boolean): MathJsChain<number>
4471
- cbrt(
4472
- this: MathJsChain<BigNumber>,
4473
- allRoots?: boolean
4474
- ): MathJsChain<BigNumber>
4519
+ cbrt(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4475
4520
  cbrt(this: MathJsChain<Complex>, allRoots?: boolean): MathJsChain<Complex>
4476
- cbrt(
4477
- this: MathJsChain<MathArray>,
4478
- allRoots?: boolean
4479
- ): MathJsChain<MathArray>
4480
- cbrt(this: MathJsChain<Matrix>, allRoots?: boolean): MathJsChain<Matrix>
4521
+ cbrt(this: MathJsChain<Unit>, allRoots?: boolean): MathJsChain<Unit>
4481
4522
 
4482
4523
  // Rounding functions grouped for similarity
4483
4524
 
@@ -4548,8 +4589,6 @@ declare namespace math {
4548
4589
  cube(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4549
4590
  cube(this: MathJsChain<Fraction>): MathJsChain<Fraction>
4550
4591
  cube(this: MathJsChain<Complex>): MathJsChain<Complex>
4551
- cube(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4552
- cube(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4553
4592
  cube(this: MathJsChain<Unit>): MathJsChain<Unit>
4554
4593
 
4555
4594
  /**
@@ -4589,8 +4628,6 @@ declare namespace math {
4589
4628
  exp(this: MathJsChain<number>): MathJsChain<number>
4590
4629
  exp(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4591
4630
  exp(this: MathJsChain<Complex>): MathJsChain<Complex>
4592
- exp(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4593
- exp(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4594
4631
 
4595
4632
  /**
4596
4633
  * Calculate the value of subtracting 1 from the exponential value. For
@@ -4599,8 +4636,6 @@ declare namespace math {
4599
4636
  expm1(this: MathJsChain<number>): MathJsChain<number>
4600
4637
  expm1(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4601
4638
  expm1(this: MathJsChain<Complex>): MathJsChain<Complex>
4602
- expm1(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4603
- expm1(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4604
4639
 
4605
4640
  /**
4606
4641
  * Calculate the greatest common divisor for two or more values or
@@ -4842,6 +4877,21 @@ declare namespace math {
4842
4877
  b: number | BigNumber
4843
4878
  ): MathJsChain<MathArray>
4844
4879
 
4880
+ /**
4881
+ * Count the number of elements of a matrix, array or string.
4882
+ */
4883
+ count(this: MathJsChain<MathCollection>): MathJsChain<number>
4884
+ count(this: MathJsChain<string>): MathJsChain<number>
4885
+
4886
+ /**
4887
+ * Compute the sum of a matrix or a list with values. In case of a
4888
+ * (multi dimensional) array or matrix, the sum of all elements will be
4889
+ * calculated.
4890
+ */
4891
+ sum(
4892
+ this: MathJsChain<Array<number | BigNumber | Fraction>>
4893
+ ): MathJsChain<number>
4894
+ sum(this: MathJsChain<MathCollection>): MathJsChain<number>
4845
4895
  /*************************************************************************
4846
4896
  * Bitwise functions
4847
4897
  ************************************************************************/
@@ -5255,16 +5305,7 @@ declare namespace math {
5255
5305
  * @param format The matrix storage format
5256
5306
  */
5257
5307
  ones(
5258
- this: MathJsChain<number | number[]>,
5259
- format?: string
5260
- ): MathJsChain<MathCollection>
5261
-
5262
- /**
5263
- * @param format The matrix storage format
5264
- */
5265
- ones(
5266
- this: MathJsChain<number>,
5267
- n: number,
5308
+ this: MathJsChain<number | number[] | BigNumber | BigNumber[]>,
5268
5309
  format?: string
5269
5310
  ): MathJsChain<MathCollection>
5270
5311
 
@@ -5403,17 +5444,7 @@ declare namespace math {
5403
5444
  * @returns A matrix filled with zeros
5404
5445
  */
5405
5446
  zeros(
5406
- this: MathJsChain<number | number[]>,
5407
- format?: string
5408
- ): MathJsChain<MathCollection>
5409
-
5410
- /**
5411
- * @param n The y dimension of the matrix
5412
- * @param format The matrix storage format
5413
- */
5414
- zeros(
5415
- this: MathJsChain<number>,
5416
- n: number,
5447
+ this: MathJsChain<number | number[] | BigNumber | BigNumber[]>,
5417
5448
  format?: string
5418
5449
  ): MathJsChain<MathCollection>
5419
5450