mathjs 10.6.3 → 11.0.1

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 (451) hide show
  1. package/HISTORY.md +74 -1
  2. package/README.md +1 -1
  3. package/lib/browser/math.js +2 -41
  4. package/lib/browser/math.js.LICENSE.txt +43 -0
  5. package/lib/browser/math.js.map +1 -1
  6. package/lib/cjs/core/create.js +6 -5
  7. package/lib/cjs/core/function/import.js +4 -14
  8. package/lib/cjs/core/function/typed.js +54 -12
  9. package/lib/cjs/defaultInstance.js +3 -3
  10. package/lib/cjs/entry/allFactoriesAny.js +1 -1
  11. package/lib/cjs/entry/allFactoriesNumber.js +1 -1
  12. package/lib/cjs/entry/configReadonly.js +1 -1
  13. package/lib/cjs/entry/dependenciesAny/dependenciesChainClass.generated.js +3 -0
  14. package/lib/cjs/entry/dependenciesAny/dependenciesKldivergence.generated.js +3 -0
  15. package/lib/cjs/entry/dependenciesAny/dependenciesRationalize.generated.js +3 -0
  16. package/lib/cjs/entry/dependenciesAny/dependenciesResolve.generated.js +3 -0
  17. package/lib/cjs/entry/dependenciesAny/dependenciesSimplify.generated.js +3 -0
  18. package/lib/cjs/entry/dependenciesAny/dependenciesSimplifyConstant.generated.js +56 -0
  19. package/lib/cjs/entry/dependenciesAny/dependenciesSimplifyCore.generated.js +6 -0
  20. package/lib/cjs/entry/dependenciesAny/dependenciesSqrtm.generated.js +3 -0
  21. package/lib/cjs/entry/dependenciesAny/dependenciesStd.generated.js +3 -0
  22. package/lib/cjs/entry/dependenciesAny/dependenciesStdTransform.generated.js +3 -0
  23. package/lib/cjs/entry/dependenciesAny.generated.js +8 -0
  24. package/lib/cjs/entry/dependenciesNumber/dependenciesChainClass.generated.js +3 -0
  25. package/lib/cjs/entry/dependenciesNumber/dependenciesRationalize.generated.js +3 -0
  26. package/lib/cjs/entry/dependenciesNumber/dependenciesResolve.generated.js +3 -0
  27. package/lib/cjs/entry/dependenciesNumber/dependenciesSimplify.generated.js +3 -0
  28. package/lib/cjs/entry/dependenciesNumber/dependenciesSimplifyConstant.generated.js +50 -0
  29. package/lib/cjs/entry/dependenciesNumber/dependenciesSimplifyCore.generated.js +6 -0
  30. package/lib/cjs/entry/dependenciesNumber/dependenciesStd.generated.js +3 -0
  31. package/lib/cjs/entry/dependenciesNumber/dependenciesStdTransform.generated.js +3 -0
  32. package/lib/cjs/entry/dependenciesNumber.generated.js +8 -0
  33. package/lib/cjs/entry/impureFunctionsAny.generated.js +87 -61
  34. package/lib/cjs/entry/impureFunctionsNumber.generated.js +93 -69
  35. package/lib/cjs/entry/pureFunctionsAny.generated.js +50 -45
  36. package/lib/cjs/entry/pureFunctionsNumber.generated.js +22 -19
  37. package/lib/cjs/expression/Parser.js +1 -1
  38. package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +8 -5
  39. package/lib/cjs/expression/embeddedDocs/function/algebra/simplifyConstant.js +15 -0
  40. package/lib/cjs/expression/embeddedDocs/function/algebra/simplifyCore.js +1 -1
  41. package/lib/cjs/expression/node/AccessorNode.js +216 -173
  42. package/lib/cjs/expression/node/ArrayNode.js +206 -160
  43. package/lib/cjs/expression/node/AssignmentNode.js +321 -270
  44. package/lib/cjs/expression/node/BlockNode.js +223 -172
  45. package/lib/cjs/expression/node/ConditionalNode.js +253 -193
  46. package/lib/cjs/expression/node/ConstantNode.js +216 -171
  47. package/lib/cjs/expression/node/FunctionAssignmentNode.js +258 -196
  48. package/lib/cjs/expression/node/FunctionNode.js +456 -416
  49. package/lib/cjs/expression/node/IndexNode.js +256 -210
  50. package/lib/cjs/expression/node/Node.js +411 -378
  51. package/lib/cjs/expression/node/ObjectNode.js +223 -178
  52. package/lib/cjs/expression/node/OperatorNode.js +474 -397
  53. package/lib/cjs/expression/node/ParenthesisNode.js +189 -143
  54. package/lib/cjs/expression/node/RangeNode.js +272 -224
  55. package/lib/cjs/expression/node/RelationalNode.js +246 -195
  56. package/lib/cjs/expression/node/SymbolNode.js +219 -172
  57. package/lib/cjs/expression/node/utils/access.js +1 -1
  58. package/lib/cjs/expression/node/utils/assign.js +1 -1
  59. package/lib/cjs/expression/operators.js +117 -23
  60. package/lib/cjs/expression/parse.js +37 -19
  61. package/lib/cjs/expression/transform/std.transform.js +3 -1
  62. package/lib/cjs/factoriesAny.js +8 -0
  63. package/lib/cjs/factoriesNumber.js +10 -1
  64. package/lib/cjs/function/algebra/decomposition/qr.js +1 -1
  65. package/lib/cjs/function/algebra/derivative.js +25 -33
  66. package/lib/cjs/function/algebra/leafCount.js +0 -3
  67. package/lib/cjs/function/algebra/rationalize.js +78 -108
  68. package/lib/cjs/function/algebra/resolve.js +53 -16
  69. package/lib/cjs/function/algebra/simplify/util.js +1 -1
  70. package/lib/cjs/function/algebra/simplify.js +90 -115
  71. package/lib/cjs/function/algebra/{simplify/simplifyConstant.js → simplifyConstant.js} +44 -10
  72. package/lib/cjs/function/algebra/simplifyCore.js +196 -93
  73. package/lib/cjs/function/algebra/solver/lsolveAll.js +2 -2
  74. package/lib/cjs/function/algebra/solver/usolveAll.js +2 -2
  75. package/lib/cjs/function/algebra/symbolicEqual.js +14 -32
  76. package/lib/cjs/function/arithmetic/abs.js +7 -14
  77. package/lib/cjs/function/arithmetic/add.js +26 -70
  78. package/lib/cjs/function/arithmetic/addScalar.js +17 -9
  79. package/lib/cjs/function/arithmetic/cbrt.js +7 -11
  80. package/lib/cjs/function/arithmetic/ceil.js +56 -46
  81. package/lib/cjs/function/arithmetic/cube.js +5 -10
  82. package/lib/cjs/function/arithmetic/divide.js +7 -7
  83. package/lib/cjs/function/arithmetic/divideScalar.js +4 -18
  84. package/lib/cjs/function/arithmetic/dotDivide.js +22 -65
  85. package/lib/cjs/function/arithmetic/dotMultiply.js +16 -61
  86. package/lib/cjs/function/arithmetic/dotPow.js +30 -63
  87. package/lib/cjs/function/arithmetic/exp.js +8 -12
  88. package/lib/cjs/function/arithmetic/expm1.js +10 -10
  89. package/lib/cjs/function/arithmetic/fix.js +34 -28
  90. package/lib/cjs/function/arithmetic/floor.js +57 -47
  91. package/lib/cjs/function/arithmetic/gcd.js +27 -68
  92. package/lib/cjs/function/arithmetic/hypot.js +9 -5
  93. package/lib/cjs/function/arithmetic/invmod.js +2 -2
  94. package/lib/cjs/function/arithmetic/lcm.js +27 -68
  95. package/lib/cjs/function/arithmetic/log.js +10 -12
  96. package/lib/cjs/function/arithmetic/log10.js +5 -3
  97. package/lib/cjs/function/arithmetic/log1p.js +11 -7
  98. package/lib/cjs/function/arithmetic/log2.js +5 -3
  99. package/lib/cjs/function/arithmetic/mod.js +22 -64
  100. package/lib/cjs/function/arithmetic/multiply.js +40 -35
  101. package/lib/cjs/function/arithmetic/multiplyScalar.js +2 -9
  102. package/lib/cjs/function/arithmetic/norm.js +1 -5
  103. package/lib/cjs/function/arithmetic/nthRoot.js +83 -95
  104. package/lib/cjs/function/arithmetic/nthRoots.js +2 -2
  105. package/lib/cjs/function/arithmetic/round.js +56 -42
  106. package/lib/cjs/function/arithmetic/sign.js +14 -10
  107. package/lib/cjs/function/arithmetic/sqrt.js +5 -9
  108. package/lib/cjs/function/arithmetic/square.js +6 -10
  109. package/lib/cjs/function/arithmetic/subtract.js +44 -100
  110. package/lib/cjs/function/arithmetic/unaryMinus.js +14 -16
  111. package/lib/cjs/function/arithmetic/unaryPlus.js +6 -4
  112. package/lib/cjs/function/bitwise/bitAnd.js +17 -61
  113. package/lib/cjs/function/bitwise/bitNot.js +6 -4
  114. package/lib/cjs/function/bitwise/bitOr.js +16 -60
  115. package/lib/cjs/function/bitwise/bitXor.js +17 -61
  116. package/lib/cjs/function/bitwise/leftShift.js +69 -82
  117. package/lib/cjs/function/bitwise/rightArithShift.js +69 -82
  118. package/lib/cjs/function/bitwise/rightLogShift.js +69 -82
  119. package/lib/cjs/function/bitwise/useMatrixForArrayScalar.js +36 -0
  120. package/lib/cjs/function/complex/arg.js +5 -3
  121. package/lib/cjs/function/complex/conj.js +6 -7
  122. package/lib/cjs/function/complex/im.js +7 -8
  123. package/lib/cjs/function/complex/re.js +6 -10
  124. package/lib/cjs/function/geometry/distance.js +2 -2
  125. package/lib/cjs/function/logical/and.js +74 -80
  126. package/lib/cjs/function/logical/not.js +13 -6
  127. package/lib/cjs/function/logical/or.js +21 -63
  128. package/lib/cjs/function/logical/xor.js +21 -63
  129. package/lib/cjs/function/matrix/diff.js +11 -8
  130. package/lib/cjs/function/matrix/eigs/complexEigs.js +5 -5
  131. package/lib/cjs/function/matrix/fft.js +2 -2
  132. package/lib/cjs/function/matrix/matrixFromColumns.js +1 -1
  133. package/lib/cjs/function/matrix/matrixFromRows.js +1 -1
  134. package/lib/cjs/function/matrix/ones.js +2 -1
  135. package/lib/cjs/function/matrix/rotate.js +5 -5
  136. package/lib/cjs/function/matrix/sqrtm.js +3 -2
  137. package/lib/cjs/function/matrix/transpose.js +47 -48
  138. package/lib/cjs/function/matrix/zeros.js +2 -1
  139. package/lib/cjs/function/probability/factorial.js +5 -3
  140. package/lib/cjs/function/probability/gamma.js +38 -40
  141. package/lib/cjs/function/probability/kldivergence.js +5 -2
  142. package/lib/cjs/function/probability/lgamma.js +30 -30
  143. package/lib/cjs/function/probability/util/seededRNG.js +2 -2
  144. package/lib/cjs/function/relational/compare.js +21 -67
  145. package/lib/cjs/function/relational/compareNatural.js +59 -54
  146. package/lib/cjs/function/relational/compareText.js +10 -43
  147. package/lib/cjs/function/relational/compareUnits.js +24 -0
  148. package/lib/cjs/function/relational/equal.js +19 -80
  149. package/lib/cjs/function/relational/equalScalar.js +7 -9
  150. package/lib/cjs/function/relational/larger.js +21 -67
  151. package/lib/cjs/function/relational/largerEq.js +21 -67
  152. package/lib/cjs/function/relational/smaller.js +21 -67
  153. package/lib/cjs/function/relational/smallerEq.js +21 -67
  154. package/lib/cjs/function/relational/unequal.js +19 -80
  155. package/lib/cjs/function/special/erf.js +5 -3
  156. package/lib/cjs/function/statistics/std.js +11 -2
  157. package/lib/cjs/function/string/format.js +2 -2
  158. package/lib/cjs/function/string/hex.js +1 -2
  159. package/lib/cjs/function/trigonometry/acos.js +4 -8
  160. package/lib/cjs/function/trigonometry/acosh.js +2 -7
  161. package/lib/cjs/function/trigonometry/acot.js +6 -11
  162. package/lib/cjs/function/trigonometry/acoth.js +4 -8
  163. package/lib/cjs/function/trigonometry/acsc.js +6 -11
  164. package/lib/cjs/function/trigonometry/acsch.js +4 -8
  165. package/lib/cjs/function/trigonometry/asec.js +6 -10
  166. package/lib/cjs/function/trigonometry/asech.js +4 -8
  167. package/lib/cjs/function/trigonometry/asin.js +5 -10
  168. package/lib/cjs/function/trigonometry/asinh.js +4 -9
  169. package/lib/cjs/function/trigonometry/atan.js +5 -11
  170. package/lib/cjs/function/trigonometry/atan2.js +25 -63
  171. package/lib/cjs/function/trigonometry/atanh.js +4 -9
  172. package/lib/cjs/function/trigonometry/cos.js +11 -20
  173. package/lib/cjs/function/trigonometry/cosh.js +5 -19
  174. package/lib/cjs/function/trigonometry/cot.js +9 -15
  175. package/lib/cjs/function/trigonometry/coth.js +4 -15
  176. package/lib/cjs/function/trigonometry/csc.js +11 -17
  177. package/lib/cjs/function/trigonometry/csch.js +4 -15
  178. package/lib/cjs/function/trigonometry/sec.js +11 -17
  179. package/lib/cjs/function/trigonometry/sech.js +4 -15
  180. package/lib/cjs/function/trigonometry/sin.js +11 -21
  181. package/lib/cjs/function/trigonometry/sinh.js +5 -20
  182. package/lib/cjs/function/trigonometry/tan.js +11 -21
  183. package/lib/cjs/function/trigonometry/tanh.js +5 -20
  184. package/lib/cjs/function/trigonometry/trigUnit.js +24 -0
  185. package/lib/cjs/function/unit/to.js +7 -41
  186. package/lib/cjs/function/utils/clone.js +1 -1
  187. package/lib/cjs/function/utils/hasNumericValue.js +5 -1
  188. package/lib/cjs/function/utils/isInteger.js +6 -4
  189. package/lib/cjs/function/utils/isNaN.js +1 -1
  190. package/lib/cjs/function/utils/isNegative.js +11 -7
  191. package/lib/cjs/function/utils/isNumeric.js +6 -4
  192. package/lib/cjs/function/utils/isPositive.js +11 -7
  193. package/lib/cjs/function/utils/isPrime.js +5 -3
  194. package/lib/cjs/function/utils/isZero.js +21 -17
  195. package/lib/cjs/function/utils/numeric.js +11 -4
  196. package/lib/cjs/function/utils/typeOf.js +38 -44
  197. package/lib/cjs/header.js +2 -2
  198. package/lib/cjs/plain/bignumber/index.js +1 -1
  199. package/lib/cjs/type/bignumber/BigNumber.js +2 -2
  200. package/lib/cjs/type/bignumber/function/bignumber.js +6 -4
  201. package/lib/cjs/type/boolean.js +7 -5
  202. package/lib/cjs/type/chain/Chain.js +23 -3
  203. package/lib/cjs/type/complex/Complex.js +18 -14
  204. package/lib/cjs/type/complex/function/complex.js +6 -4
  205. package/lib/cjs/type/fraction/Fraction.js +10 -6
  206. package/lib/cjs/type/fraction/function/fraction.js +6 -4
  207. package/lib/cjs/type/matrix/DenseMatrix.js +21 -6
  208. package/lib/cjs/type/matrix/SparseMatrix.js +12 -2
  209. package/lib/cjs/type/matrix/utils/{algorithm01.js → matAlgo01xDSid.js} +4 -4
  210. package/lib/cjs/type/matrix/utils/{algorithm02.js → matAlgo02xDS0.js} +5 -5
  211. package/lib/cjs/type/matrix/utils/{algorithm03.js → matAlgo03xDSf.js} +5 -5
  212. package/lib/cjs/type/matrix/utils/{algorithm04.js → matAlgo04xSidSid.js} +7 -7
  213. package/lib/cjs/type/matrix/utils/{algorithm05.js → matAlgo05xSfSf.js} +5 -5
  214. package/lib/cjs/type/matrix/utils/{algorithm06.js → matAlgo06xS0S0.js} +5 -5
  215. package/lib/cjs/type/matrix/utils/{algorithm07.js → matAlgo07xSSf.js} +5 -5
  216. package/lib/cjs/type/matrix/utils/{algorithm08.js → matAlgo08xS0Sid.js} +6 -6
  217. package/lib/cjs/type/matrix/utils/{algorithm09.js → matAlgo09xS0Sf.js} +5 -5
  218. package/lib/cjs/type/matrix/utils/{algorithm10.js → matAlgo10xSids.js} +5 -5
  219. package/lib/cjs/type/matrix/utils/{algorithm11.js → matAlgo11xS0s.js} +5 -5
  220. package/lib/cjs/type/matrix/utils/{algorithm12.js → matAlgo12xSfs.js} +5 -5
  221. package/lib/cjs/type/matrix/utils/{algorithm13.js → matAlgo13xDD.js} +5 -5
  222. package/lib/cjs/type/matrix/utils/{algorithm14.js → matAlgo14xDs.js} +5 -5
  223. package/lib/cjs/type/matrix/utils/matrixAlgorithmSuite.js +238 -0
  224. package/lib/cjs/type/number.js +6 -4
  225. package/lib/cjs/type/string.js +7 -5
  226. package/lib/cjs/type/unit/Unit.js +69 -21
  227. package/lib/cjs/type/unit/function/createUnit.js +2 -1
  228. package/lib/cjs/type/unit/function/unit.js +9 -3
  229. package/lib/cjs/utils/customs.js +2 -2
  230. package/lib/cjs/utils/emitter.js +1 -1
  231. package/lib/cjs/utils/function.js +2 -2
  232. package/lib/cjs/utils/is.js +27 -25
  233. package/lib/cjs/utils/latex.js +3 -3
  234. package/lib/cjs/utils/lruQueue.js +1 -1
  235. package/lib/cjs/utils/map.js +3 -3
  236. package/lib/cjs/utils/object.js +2 -2
  237. package/lib/cjs/utils/snapshot.js +30 -57
  238. package/lib/cjs/utils/string.js +3 -3
  239. package/lib/cjs/version.js +1 -1
  240. package/lib/esm/core/create.js +2 -1
  241. package/lib/esm/core/function/import.js +2 -12
  242. package/lib/esm/core/function/typed.js +47 -11
  243. package/lib/esm/entry/dependenciesAny/dependenciesChainClass.generated.js +2 -0
  244. package/lib/esm/entry/dependenciesAny/dependenciesKldivergence.generated.js +2 -0
  245. package/lib/esm/entry/dependenciesAny/dependenciesRationalize.generated.js +2 -0
  246. package/lib/esm/entry/dependenciesAny/dependenciesResolve.generated.js +2 -0
  247. package/lib/esm/entry/dependenciesAny/dependenciesSimplify.generated.js +2 -0
  248. package/lib/esm/entry/dependenciesAny/dependenciesSimplifyConstant.generated.js +34 -0
  249. package/lib/esm/entry/dependenciesAny/dependenciesSimplifyCore.generated.js +4 -0
  250. package/lib/esm/entry/dependenciesAny/dependenciesSqrtm.generated.js +2 -0
  251. package/lib/esm/entry/dependenciesAny/dependenciesStd.generated.js +2 -0
  252. package/lib/esm/entry/dependenciesAny/dependenciesStdTransform.generated.js +2 -0
  253. package/lib/esm/entry/dependenciesAny.generated.js +1 -0
  254. package/lib/esm/entry/dependenciesNumber/dependenciesChainClass.generated.js +2 -0
  255. package/lib/esm/entry/dependenciesNumber/dependenciesRationalize.generated.js +2 -0
  256. package/lib/esm/entry/dependenciesNumber/dependenciesResolve.generated.js +2 -0
  257. package/lib/esm/entry/dependenciesNumber/dependenciesSimplify.generated.js +2 -0
  258. package/lib/esm/entry/dependenciesNumber/dependenciesSimplifyConstant.generated.js +30 -0
  259. package/lib/esm/entry/dependenciesNumber/dependenciesSimplifyCore.generated.js +4 -0
  260. package/lib/esm/entry/dependenciesNumber/dependenciesStd.generated.js +2 -0
  261. package/lib/esm/entry/dependenciesNumber/dependenciesStdTransform.generated.js +2 -0
  262. package/lib/esm/entry/dependenciesNumber.generated.js +1 -0
  263. package/lib/esm/entry/impureFunctionsAny.generated.js +73 -48
  264. package/lib/esm/entry/impureFunctionsNumber.generated.js +81 -58
  265. package/lib/esm/entry/pureFunctionsAny.generated.js +39 -36
  266. package/lib/esm/entry/pureFunctionsNumber.generated.js +14 -13
  267. package/lib/esm/expression/embeddedDocs/embeddedDocs.js +2 -0
  268. package/lib/esm/expression/embeddedDocs/function/algebra/simplifyConstant.js +8 -0
  269. package/lib/esm/expression/embeddedDocs/function/algebra/simplifyCore.js +1 -1
  270. package/lib/esm/expression/node/AccessorNode.js +158 -153
  271. package/lib/esm/expression/node/ArrayNode.js +162 -154
  272. package/lib/esm/expression/node/AssignmentNode.js +257 -245
  273. package/lib/esm/expression/node/BlockNode.js +177 -163
  274. package/lib/esm/expression/node/ConditionalNode.js +197 -174
  275. package/lib/esm/expression/node/ConstantNode.js +171 -163
  276. package/lib/esm/expression/node/FunctionAssignmentNode.js +205 -180
  277. package/lib/esm/expression/node/FunctionNode.js +407 -407
  278. package/lib/esm/expression/node/IndexNode.js +206 -198
  279. package/lib/esm/expression/node/Node.js +325 -325
  280. package/lib/esm/expression/node/ObjectNode.js +166 -157
  281. package/lib/esm/expression/node/OperatorNode.js +414 -377
  282. package/lib/esm/expression/node/ParenthesisNode.js +146 -138
  283. package/lib/esm/expression/node/RangeNode.js +221 -212
  284. package/lib/esm/expression/node/RelationalNode.js +190 -176
  285. package/lib/esm/expression/node/SymbolNode.js +161 -152
  286. package/lib/esm/expression/operators.js +96 -4
  287. package/lib/esm/expression/parse.js +25 -7
  288. package/lib/esm/expression/transform/std.transform.js +3 -1
  289. package/lib/esm/factoriesAny.js +1 -0
  290. package/lib/esm/factoriesNumber.js +1 -0
  291. package/lib/esm/function/algebra/derivative.js +25 -33
  292. package/lib/esm/function/algebra/leafCount.js +0 -3
  293. package/lib/esm/function/algebra/rationalize.js +83 -114
  294. package/lib/esm/function/algebra/resolve.js +25 -16
  295. package/lib/esm/function/algebra/simplify.js +85 -113
  296. package/lib/esm/function/algebra/{simplify/simplifyConstant.js → simplifyConstant.js} +39 -9
  297. package/lib/esm/function/algebra/simplifyCore.js +192 -91
  298. package/lib/esm/function/algebra/symbolicEqual.js +14 -32
  299. package/lib/esm/function/arithmetic/abs.js +3 -16
  300. package/lib/esm/function/arithmetic/add.js +21 -65
  301. package/lib/esm/function/arithmetic/addScalar.js +11 -5
  302. package/lib/esm/function/arithmetic/cbrt.js +7 -10
  303. package/lib/esm/function/arithmetic/ceil.js +25 -25
  304. package/lib/esm/function/arithmetic/cube.js +5 -9
  305. package/lib/esm/function/arithmetic/divide.js +7 -7
  306. package/lib/esm/function/arithmetic/divideScalar.js +2 -19
  307. package/lib/esm/function/arithmetic/dotDivide.js +22 -64
  308. package/lib/esm/function/arithmetic/dotMultiply.js +16 -60
  309. package/lib/esm/function/arithmetic/dotPow.js +30 -62
  310. package/lib/esm/function/arithmetic/exp.js +8 -11
  311. package/lib/esm/function/arithmetic/expm1.js +10 -9
  312. package/lib/esm/function/arithmetic/fix.js +18 -18
  313. package/lib/esm/function/arithmetic/floor.js +26 -26
  314. package/lib/esm/function/arithmetic/gcd.js +26 -70
  315. package/lib/esm/function/arithmetic/hypot.js +7 -6
  316. package/lib/esm/function/arithmetic/invmod.js +1 -1
  317. package/lib/esm/function/arithmetic/lcm.js +26 -70
  318. package/lib/esm/function/arithmetic/log.js +7 -10
  319. package/lib/esm/function/arithmetic/log10.js +1 -3
  320. package/lib/esm/function/arithmetic/log1p.js +4 -6
  321. package/lib/esm/function/arithmetic/log2.js +1 -3
  322. package/lib/esm/function/arithmetic/mod.js +21 -62
  323. package/lib/esm/function/arithmetic/multiply.js +23 -27
  324. package/lib/esm/function/arithmetic/multiplyScalar.js +2 -13
  325. package/lib/esm/function/arithmetic/norm.js +0 -4
  326. package/lib/esm/function/arithmetic/nthRoot.js +41 -76
  327. package/lib/esm/function/arithmetic/nthRoots.js +2 -2
  328. package/lib/esm/function/arithmetic/round.js +26 -28
  329. package/lib/esm/function/arithmetic/sign.js +5 -7
  330. package/lib/esm/function/arithmetic/sqrt.js +5 -8
  331. package/lib/esm/function/arithmetic/square.js +6 -9
  332. package/lib/esm/function/arithmetic/subtract.js +31 -95
  333. package/lib/esm/function/arithmetic/unaryMinus.js +6 -16
  334. package/lib/esm/function/arithmetic/unaryPlus.js +2 -4
  335. package/lib/esm/function/bitwise/bitAnd.js +16 -59
  336. package/lib/esm/function/bitwise/bitNot.js +2 -4
  337. package/lib/esm/function/bitwise/bitOr.js +16 -59
  338. package/lib/esm/function/bitwise/bitXor.js +16 -59
  339. package/lib/esm/function/bitwise/leftShift.js +39 -61
  340. package/lib/esm/function/bitwise/rightArithShift.js +39 -61
  341. package/lib/esm/function/bitwise/rightLogShift.js +39 -61
  342. package/lib/esm/function/bitwise/useMatrixForArrayScalar.js +13 -0
  343. package/lib/esm/function/complex/arg.js +1 -3
  344. package/lib/esm/function/complex/conj.js +3 -12
  345. package/lib/esm/function/complex/im.js +4 -15
  346. package/lib/esm/function/complex/re.js +3 -15
  347. package/lib/esm/function/geometry/distance.js +2 -2
  348. package/lib/esm/function/logical/and.js +35 -57
  349. package/lib/esm/function/logical/not.js +3 -6
  350. package/lib/esm/function/logical/or.js +16 -61
  351. package/lib/esm/function/logical/xor.js +16 -61
  352. package/lib/esm/function/matrix/diff.js +3 -8
  353. package/lib/esm/function/matrix/ones.js +2 -1
  354. package/lib/esm/function/matrix/rotate.js +5 -5
  355. package/lib/esm/function/matrix/sqrtm.js +3 -2
  356. package/lib/esm/function/matrix/transpose.js +47 -50
  357. package/lib/esm/function/matrix/zeros.js +2 -1
  358. package/lib/esm/function/probability/factorial.js +1 -3
  359. package/lib/esm/function/probability/gamma.js +38 -39
  360. package/lib/esm/function/probability/kldivergence.js +3 -2
  361. package/lib/esm/function/probability/lgamma.js +29 -29
  362. package/lib/esm/function/relational/compare.js +21 -67
  363. package/lib/esm/function/relational/compareNatural.js +54 -49
  364. package/lib/esm/function/relational/compareText.js +10 -42
  365. package/lib/esm/function/relational/compareUnits.js +15 -0
  366. package/lib/esm/function/relational/equal.js +19 -79
  367. package/lib/esm/function/relational/equalScalar.js +6 -9
  368. package/lib/esm/function/relational/larger.js +23 -73
  369. package/lib/esm/function/relational/largerEq.js +23 -73
  370. package/lib/esm/function/relational/smaller.js +23 -73
  371. package/lib/esm/function/relational/smallerEq.js +23 -73
  372. package/lib/esm/function/relational/unequal.js +19 -79
  373. package/lib/esm/function/special/erf.js +1 -3
  374. package/lib/esm/function/statistics/std.js +10 -2
  375. package/lib/esm/function/string/format.js +2 -2
  376. package/lib/esm/function/string/hex.js +1 -2
  377. package/lib/esm/function/trigonometry/acos.js +4 -7
  378. package/lib/esm/function/trigonometry/acosh.js +2 -6
  379. package/lib/esm/function/trigonometry/acot.js +6 -10
  380. package/lib/esm/function/trigonometry/acoth.js +4 -7
  381. package/lib/esm/function/trigonometry/acsc.js +6 -10
  382. package/lib/esm/function/trigonometry/acsch.js +4 -7
  383. package/lib/esm/function/trigonometry/asec.js +6 -9
  384. package/lib/esm/function/trigonometry/asech.js +4 -7
  385. package/lib/esm/function/trigonometry/asin.js +5 -9
  386. package/lib/esm/function/trigonometry/asinh.js +4 -8
  387. package/lib/esm/function/trigonometry/atan.js +5 -10
  388. package/lib/esm/function/trigonometry/atan2.js +26 -65
  389. package/lib/esm/function/trigonometry/atanh.js +4 -8
  390. package/lib/esm/function/trigonometry/cos.js +11 -22
  391. package/lib/esm/function/trigonometry/cosh.js +5 -20
  392. package/lib/esm/function/trigonometry/cot.js +10 -20
  393. package/lib/esm/function/trigonometry/coth.js +6 -20
  394. package/lib/esm/function/trigonometry/csc.js +12 -22
  395. package/lib/esm/function/trigonometry/csch.js +6 -20
  396. package/lib/esm/function/trigonometry/sec.js +12 -22
  397. package/lib/esm/function/trigonometry/sech.js +6 -20
  398. package/lib/esm/function/trigonometry/sin.js +11 -23
  399. package/lib/esm/function/trigonometry/sinh.js +5 -21
  400. package/lib/esm/function/trigonometry/tan.js +11 -23
  401. package/lib/esm/function/trigonometry/tanh.js +5 -21
  402. package/lib/esm/function/trigonometry/trigUnit.js +15 -0
  403. package/lib/esm/function/unit/to.js +8 -43
  404. package/lib/esm/function/utils/clone.js +1 -1
  405. package/lib/esm/function/utils/hasNumericValue.js +3 -1
  406. package/lib/esm/function/utils/isInteger.js +2 -4
  407. package/lib/esm/function/utils/isNaN.js +1 -1
  408. package/lib/esm/function/utils/isNegative.js +3 -7
  409. package/lib/esm/function/utils/isNumeric.js +4 -10
  410. package/lib/esm/function/utils/isPositive.js +3 -7
  411. package/lib/esm/function/utils/isPrime.js +1 -3
  412. package/lib/esm/function/utils/isZero.js +13 -17
  413. package/lib/esm/function/utils/numeric.js +11 -4
  414. package/lib/esm/function/utils/typeOf.js +38 -44
  415. package/lib/esm/type/bignumber/function/bignumber.js +1 -3
  416. package/lib/esm/type/boolean.js +1 -3
  417. package/lib/esm/type/chain/Chain.js +23 -3
  418. package/lib/esm/type/complex/Complex.js +4 -0
  419. package/lib/esm/type/complex/function/complex.js +1 -3
  420. package/lib/esm/type/fraction/Fraction.js +4 -0
  421. package/lib/esm/type/fraction/function/fraction.js +1 -3
  422. package/lib/esm/type/matrix/DenseMatrix.js +15 -1
  423. package/lib/esm/type/matrix/SparseMatrix.js +9 -0
  424. package/lib/esm/type/matrix/utils/{algorithm01.js → matAlgo01xDSid.js} +2 -2
  425. package/lib/esm/type/matrix/utils/{algorithm02.js → matAlgo02xDS0.js} +3 -3
  426. package/lib/esm/type/matrix/utils/{algorithm03.js → matAlgo03xDSf.js} +3 -3
  427. package/lib/esm/type/matrix/utils/{algorithm04.js → matAlgo04xSidSid.js} +5 -5
  428. package/lib/esm/type/matrix/utils/{algorithm05.js → matAlgo05xSfSf.js} +3 -3
  429. package/lib/esm/type/matrix/utils/{algorithm06.js → matAlgo06xS0S0.js} +3 -3
  430. package/lib/esm/type/matrix/utils/{algorithm07.js → matAlgo07xSSf.js} +3 -3
  431. package/lib/esm/type/matrix/utils/{algorithm08.js → matAlgo08xS0Sid.js} +4 -4
  432. package/lib/esm/type/matrix/utils/{algorithm09.js → matAlgo09xS0Sf.js} +3 -3
  433. package/lib/esm/type/matrix/utils/{algorithm10.js → matAlgo10xSids.js} +3 -3
  434. package/lib/esm/type/matrix/utils/{algorithm11.js → matAlgo11xS0s.js} +3 -3
  435. package/lib/esm/type/matrix/utils/{algorithm12.js → matAlgo12xSfs.js} +3 -3
  436. package/lib/esm/type/matrix/utils/{algorithm13.js → matAlgo13xDD.js} +3 -3
  437. package/lib/esm/type/matrix/utils/{algorithm14.js → matAlgo14xDs.js} +3 -3
  438. package/lib/esm/type/matrix/utils/matrixAlgorithmSuite.js +168 -0
  439. package/lib/esm/type/number.js +1 -3
  440. package/lib/esm/type/string.js +1 -3
  441. package/lib/esm/type/unit/Unit.js +61 -13
  442. package/lib/esm/type/unit/function/createUnit.js +2 -1
  443. package/lib/esm/type/unit/function/unit.js +5 -3
  444. package/lib/esm/utils/is.js +18 -18
  445. package/lib/esm/utils/snapshot.js +22 -48
  446. package/lib/esm/version.js +1 -1
  447. package/package.json +21 -24
  448. package/types/index.d.ts +215 -183
  449. package/types/index.ts +358 -144
  450. package/lib/cjs/utils/polyfills.js +0 -14
  451. package/lib/esm/utils/polyfills.js +0 -12
package/types/index.d.ts CHANGED
@@ -161,6 +161,10 @@ declare namespace math {
161
161
  isHexDigit(c: string): boolean
162
162
  }
163
163
 
164
+ interface NodeCtor {
165
+ new (): MathNodeCommon
166
+ }
167
+
164
168
  interface AccessorNode extends MathNodeCommon {
165
169
  type: 'AccessorNode'
166
170
  isAccessorNode: true
@@ -434,6 +438,7 @@ declare namespace math {
434
438
  tau: number
435
439
 
436
440
  // Class-like constructors
441
+ Node: NodeCtor
437
442
  AccessorNode: AccessorNodeCtor
438
443
  ArrayNode: ArrayNodeCtor
439
444
  AssignmentNode: AssignmentNodeCtor
@@ -584,7 +589,7 @@ declare namespace math {
584
589
  */
585
590
  createUnit(
586
591
  name: string,
587
- definition?: string | UnitDefinition,
592
+ definition?: string | UnitDefinition | Unit,
588
593
  options?: CreateUnitOptions
589
594
  ): Unit
590
595
  /**
@@ -594,7 +599,7 @@ declare namespace math {
594
599
  * @returns The new unit
595
600
  */
596
601
  createUnit(
597
- units: Record<string, string | UnitDefinition>,
602
+ units: Record<string, string | UnitDefinition | Unit>,
598
603
  options?: CreateUnitOptions
599
604
  ): Unit
600
605
 
@@ -642,7 +647,7 @@ declare namespace math {
642
647
  * @returns The created Matrix
643
648
  */
644
649
  matrix(
645
- data: MathCollection,
650
+ data: MathCollection | string[],
646
651
  format?: 'sparse' | 'dense',
647
652
  dataType?: string
648
653
  ): Matrix
@@ -885,15 +890,26 @@ declare namespace math {
885
890
  */
886
891
  simplify: Simplify
887
892
 
893
+ simplifyConstant(
894
+ expr: MathNode | string,
895
+ options?: SimplifyOptions
896
+ ): MathNode
897
+ simplifyCore(expr: MathNode | string, options?: SimplifyOptions): MathNode
898
+
888
899
  /**
889
900
  * Replaces variable nodes with their scoped values
890
901
  * @param node Tree to replace variable nodes in
891
902
  * @param scope Scope to read/write variables
892
903
  */
893
904
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
894
- resolve(node: MathNode, scope?: Record<string, any>): MathNode
905
+ resolve(node: MathNode | string, scope?: Record<string, any>): MathNode
906
+ resolve(
907
+ node: (MathNode | string)[],
908
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
909
+ scope?: Record<string, any>
910
+ ): MathNode[]
895
911
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
896
- resolve(node: MathNode[], scope?: Record<string, any>): MathNode[]
912
+ resolve(node: Matrix, scope?: Record<string, any>): Matrix
897
913
 
898
914
  /**
899
915
  * Calculate the Sparse Matrix LU decomposition with full pivoting.
@@ -955,8 +971,7 @@ declare namespace math {
955
971
  add(x: MathType, y: MathType): MathType
956
972
 
957
973
  /**
958
- * Calculate the cubic root of a value. For matrices, the function is
959
- * evaluated element wise.
974
+ * Calculate the cubic root of a value.
960
975
  * @param x Value for which to calculate the cubic root.
961
976
  * @param allRoots Optional, false by default. Only applicable when x is
962
977
  * a number or complex number. If true, all complex roots are returned,
@@ -964,10 +979,9 @@ declare namespace math {
964
979
  * @returns Returns the cubic root of x
965
980
  */
966
981
  cbrt(x: number, allRoots?: boolean): number
967
- cbrt(x: BigNumber, allRoots?: boolean): BigNumber
982
+ cbrt(x: BigNumber): BigNumber
968
983
  cbrt(x: Complex, allRoots?: boolean): Complex
969
- cbrt(x: MathArray, allRoots?: boolean): MathArray
970
- cbrt(x: Matrix, allRoots?: boolean): Matrix
984
+ cbrt(x: Unit): Unit
971
985
 
972
986
  // Rounding functions, grouped for similarity, even though it breaks
973
987
  // the alphabetic order among arithmetic functions.
@@ -1037,8 +1051,6 @@ declare namespace math {
1037
1051
  cube(x: BigNumber): BigNumber
1038
1052
  cube(x: Fraction): Fraction
1039
1053
  cube(x: Complex): Complex
1040
- cube(x: MathArray): MathArray
1041
- cube(x: Matrix): Matrix
1042
1054
  cube(x: Unit): Unit
1043
1055
 
1044
1056
  /**
@@ -1088,8 +1100,6 @@ declare namespace math {
1088
1100
  exp(x: number): number
1089
1101
  exp(x: BigNumber): BigNumber
1090
1102
  exp(x: Complex): Complex
1091
- exp(x: MathArray): MathArray
1092
- exp(x: Matrix): Matrix
1093
1103
 
1094
1104
  /**
1095
1105
  * Calculate the value of subtracting 1 from the exponential value. For
@@ -1100,8 +1110,6 @@ declare namespace math {
1100
1110
  expm1(x: number): number
1101
1111
  expm1(x: BigNumber): BigNumber
1102
1112
  expm1(x: Complex): Complex
1103
- expm1(x: MathArray): MathArray
1104
- expm1(x: Matrix): Matrix
1105
1113
 
1106
1114
  /**
1107
1115
  * Calculate the greatest common divisor for two or more values or
@@ -1142,14 +1150,13 @@ declare namespace math {
1142
1150
  lcm(a: Matrix, b: Matrix): Matrix
1143
1151
 
1144
1152
  /**
1145
- * Calculate the logarithm of a value. For matrices, the function is
1146
- * evaluated element wise.
1153
+ * Calculate the logarithm of a value.
1147
1154
  * @param x Value for which to calculate the logarithm.
1148
1155
  * @param base Optional base for the logarithm. If not provided, the
1149
1156
  * natural logarithm of x is calculated. Default value: e.
1150
1157
  * @returns Returns the logarithm of x
1151
1158
  */
1152
- log<T extends number | BigNumber | Complex | MathCollection>(
1159
+ log<T extends number | BigNumber | Complex>(
1153
1160
  x: T,
1154
1161
  base?: number | BigNumber | Complex
1155
1162
  ): NoLiteralType<T>
@@ -1211,9 +1218,13 @@ declare namespace math {
1211
1218
  * @param y The second value to multiply
1212
1219
  * @returns Multiplication of x and y
1213
1220
  */
1214
- multiply<T extends Matrix | MathArray>(x: T, y: MathType): T
1221
+
1222
+ multiply<T extends Matrix>(x: T, y: MathType): Matrix
1223
+ multiply<T extends Matrix>(x: MathType, y: T): Matrix
1224
+
1215
1225
  multiply(x: Unit, y: Unit): Unit
1216
1226
  multiply(x: number, y: number): number
1227
+ multiply(x: MathArray, y: MathArray): MathArray
1217
1228
  multiply(x: MathType, y: MathType): MathType
1218
1229
 
1219
1230
  /**
@@ -1268,21 +1279,19 @@ declare namespace math {
1268
1279
  sign(x: Unit): Unit
1269
1280
 
1270
1281
  /**
1271
- * Calculate the square root of a value. For matrices, the function is
1272
- * evaluated element wise.
1282
+ * Calculate the square root of a value. For matrices, use either
1283
+ * sqrtm for the matrix square root, or map(M, sqrt) to take the
1284
+ * square root element wise.
1273
1285
  * @param x Value for which to calculate the square root
1274
1286
  * @returns Returns the square root of x
1275
1287
  */
1276
- sqrt(x: number): number
1288
+ sqrt(x: number): number | Complex
1277
1289
  sqrt(x: BigNumber): BigNumber
1278
1290
  sqrt(x: Complex): Complex
1279
- sqrt(x: MathArray): MathArray
1280
- sqrt(x: Matrix): Matrix
1281
1291
  sqrt(x: Unit): Unit
1282
1292
 
1283
1293
  /**
1284
- * Compute the square of a value, x * x. For matrices, the function is
1285
- * evaluated element wise.
1294
+ * Compute the square of a value, x * x.
1286
1295
  * @param x Number for which to calculate the square
1287
1296
  * @returns Squared value
1288
1297
  */
@@ -1290,8 +1299,6 @@ declare namespace math {
1290
1299
  square(x: BigNumber): BigNumber
1291
1300
  square(x: Fraction): Fraction
1292
1301
  square(x: Complex): Complex
1293
- square(x: MathArray): MathArray
1294
- square(x: Matrix): Matrix
1295
1302
  square(x: Unit): Unit
1296
1303
 
1297
1304
  /**
@@ -1845,14 +1852,37 @@ declare namespace math {
1845
1852
  * @param format The matrix storage format
1846
1853
  * @returns A matrix filled with ones
1847
1854
  */
1848
- ones(size: number | number[], format?: string): MathCollection
1855
+ ones(
1856
+ size?: number | number[] | BigNumber | BigNumber[],
1857
+ format?: string
1858
+ ): MathCollection
1849
1859
  /**
1850
1860
  * @param m The x dimension of the matrix
1851
- * @param n The y dimension of the amtrix
1861
+ * @param n The y dimension of the matrix
1852
1862
  * @param format The matrix storage format
1853
1863
  * @returns A matrix filled with ones
1854
1864
  */
1855
- ones(m: number, n: number, format?: string): MathCollection
1865
+ ones(
1866
+ m: number | BigNumber,
1867
+ n: number | BigNumber,
1868
+ format?: string
1869
+ ): MathCollection
1870
+ /**
1871
+ * @param m The x dimension of the matrix
1872
+ * @param n The y dimension of the matrix
1873
+ * @param p The z dimension of the matrix
1874
+ * @param format The matrix storage format
1875
+ * @returns A matrix filled with ones
1876
+ */
1877
+ ones(
1878
+ m: number | BigNumber,
1879
+ n: number | BigNumber,
1880
+ p: number | BigNumber,
1881
+ format?: string
1882
+ ): MathCollection
1883
+ /** Actually ones can take an arbitrary number of dimensions before the
1884
+ ** optional format, not sure how to write that in TypeScript
1885
+ **/
1856
1886
 
1857
1887
  /**
1858
1888
  * Partition-based selection of an array or 1D matrix. Will find the kth
@@ -2033,14 +2063,37 @@ declare namespace math {
2033
2063
  * @param format The matrix storage format
2034
2064
  * @returns A matrix filled with zeros
2035
2065
  */
2036
- zeros(size: number | number[], format?: string): MathCollection
2066
+ zeros(
2067
+ size?: number | number[] | BigNumber | BigNumber[],
2068
+ format?: string
2069
+ ): MathCollection
2070
+ /**
2071
+ * @param m The x dimension of the matrix
2072
+ * @param n The y dimension of the matrix
2073
+ * @param format The matrix storage format
2074
+ * @returns A matrix filled with zeros
2075
+ */
2076
+ zeros(
2077
+ m: number | BigNumber,
2078
+ n: number | BigNumber,
2079
+ format?: string
2080
+ ): MathCollection
2037
2081
  /**
2038
2082
  * @param m The x dimension of the matrix
2039
2083
  * @param n The y dimension of the matrix
2084
+ * @param p The z dimension of the matrix
2040
2085
  * @param format The matrix storage format
2041
2086
  * @returns A matrix filled with zeros
2042
2087
  */
2043
- zeros(m: number, n: number, format?: string): MathCollection
2088
+ zeros(
2089
+ m: number | BigNumber,
2090
+ n: number | BigNumber,
2091
+ p: number | BigNumber,
2092
+ format?: string
2093
+ ): MathCollection
2094
+ /** Actually zeros can take any number of dimensions before the
2095
+ ** optional format, not sure how to write that in TypeScript
2096
+ **/
2044
2097
 
2045
2098
  /**
2046
2099
  * Calculate N-dimensional fourier transform
@@ -2087,13 +2140,11 @@ declare namespace math {
2087
2140
  /**
2088
2141
  * Compute the gamma function of a value using Lanczos approximation for
2089
2142
  * small values, and an extended Stirling approximation for large
2090
- * values. For matrices, the function is evaluated element wise.
2143
+ * values.
2091
2144
  * @param n A real or complex number
2092
2145
  * @returns The gamma of n
2093
2146
  */
2094
- gamma<T extends number | BigNumber | Complex | MathCollection>(
2095
- n: T
2096
- ): NoLiteralType<T>
2147
+ gamma<T extends number | BigNumber | Complex>(n: T): NoLiteralType<T>
2097
2148
 
2098
2149
  /**
2099
2150
  * Calculate the Kullback-Leibler (KL) divergence between two
@@ -2649,6 +2700,13 @@ declare namespace math {
2649
2700
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2650
2701
  sum(array: MathCollection): any
2651
2702
 
2703
+ /**
2704
+ * Count the number of elements of a matrix, array or string.
2705
+ * @param x A matrix, array or string.
2706
+ * @returns The number of members passed in parameters
2707
+ */
2708
+ count(x: MathCollection | string): number
2709
+
2652
2710
  /**
2653
2711
  * Compute the cumulative sum of a matrix or a list with values.
2654
2712
  * In case of a (multi dimensional) array or matrix, the cumulative sums
@@ -2765,133 +2823,108 @@ declare namespace math {
2765
2823
  ************************************************************************/
2766
2824
 
2767
2825
  /**
2768
- * Calculate the inverse cosine of a value. For matrices, the function
2769
- * is evaluated element wise.
2826
+ * Calculate the inverse cosine of a value.
2770
2827
  * @param x Function input
2771
2828
  * @returns The arc cosine of x
2772
2829
  */
2773
- acos(x: number): number
2830
+ acos(x: number): number | Complex
2774
2831
  acos(x: BigNumber): BigNumber
2775
2832
  acos(x: Complex): Complex
2776
- acos(x: MathArray): MathArray
2777
- acos(x: Matrix): Matrix
2778
2833
 
2779
2834
  /**
2780
2835
  * Calculate the hyperbolic arccos of a value, defined as acosh(x) =
2781
- * ln(sqrt(x^2 - 1) + x). For matrices, the function is evaluated
2782
- * element wise.
2836
+ * ln(sqrt(x^2 - 1) + x).
2783
2837
  * @param x Function input
2784
2838
  * @returns The hyperbolic arccosine of x
2785
2839
  */
2786
- acosh(x: number): number
2840
+ acosh(x: number): number | Complex
2787
2841
  acosh(x: BigNumber): BigNumber
2788
2842
  acosh(x: Complex): Complex
2789
- acosh(x: MathArray): MathArray
2790
- acosh(x: Matrix): Matrix
2791
2843
 
2792
2844
  /**
2793
- * Calculate the inverse cotangent of a value. For matrices, the
2794
- * function is evaluated element wise.
2845
+ * Calculate the inverse cotangent of a value.
2795
2846
  * @param x Function input
2796
2847
  * @returns The arc cotangent of x
2797
2848
  */
2798
2849
  acot(x: number): number
2799
2850
  acot(x: BigNumber): BigNumber
2800
- acot(x: MathArray): MathArray
2801
- acot(x: Matrix): Matrix
2851
+ acot(x: Complex): Complex
2802
2852
 
2803
2853
  /**
2804
2854
  * Calculate the hyperbolic arccotangent of a value, defined as acoth(x)
2805
- * = (ln((x+1)/x) + ln(x/(x-1))) / 2. For matrices, the function is
2806
- * evaluated element wise.
2855
+ * = (ln((x+1)/x) + ln(x/(x-1))) / 2.
2807
2856
  * @param x Function input
2808
2857
  * @returns The hyperbolic arccotangent of x
2809
2858
  */
2810
2859
  acoth(x: number): number
2811
2860
  acoth(x: BigNumber): BigNumber
2812
- acoth(x: MathArray): MathArray
2813
- acoth(x: Matrix): Matrix
2861
+ acoth(x: Complex): Complex
2814
2862
 
2815
2863
  /**
2816
- * Calculate the inverse cosecant of a value. For matrices, the function
2817
- * is evaluated element wise.
2864
+ * Calculate the inverse cosecant of a value.
2818
2865
  * @param x Function input
2819
2866
  * @returns The arc cosecant of x
2820
2867
  */
2821
- acsc(x: number): number
2868
+ acsc(x: number): number | Complex
2822
2869
  acsc(x: BigNumber): BigNumber
2823
- acsc(x: MathArray): MathArray
2824
- acsc(x: Matrix): Matrix
2870
+ acsc(x: Complex): Complex
2825
2871
 
2826
2872
  /**
2827
2873
  * Calculate the hyperbolic arccosecant of a value, defined as acsch(x)
2828
- * = ln(1/x + sqrt(1/x^2 + 1)). For matrices, the function is evaluated
2829
- * element wise.
2874
+ * = ln(1/x + sqrt(1/x^2 + 1)).
2830
2875
  * @param x Function input
2831
2876
  * @returns The hyperbolic arccosecant of x
2832
2877
  */
2833
2878
  acsch(x: number): number
2834
2879
  acsch(x: BigNumber): BigNumber
2835
- acsch(x: MathArray): MathArray
2836
- acsch(x: Matrix): Matrix
2880
+ acsch(x: Complex): Complex
2837
2881
 
2838
2882
  /**
2839
- * Calculate the inverse secant of a value. For matrices, the function
2840
- * is evaluated element wise.
2883
+ * Calculate the inverse secant of a value.
2841
2884
  * @param x Function input
2842
2885
  * @returns The arc secant of x
2843
2886
  */
2844
- asec(x: number): number
2887
+ asec(x: number): number | Complex
2845
2888
  asec(x: BigNumber): BigNumber
2846
- asec(x: MathArray): MathArray
2847
- asec(x: Matrix): Matrix
2889
+ asec(x: Complex): Complex
2848
2890
 
2849
2891
  /**
2850
2892
  * Calculate the hyperbolic arcsecant of a value, defined as asech(x) =
2851
- * ln(sqrt(1/x^2 - 1) + 1/x). For matrices, the function is evaluated
2852
- * element wise.
2893
+ * ln(sqrt(1/x^2 - 1) + 1/x).
2853
2894
  * @param x Function input
2854
2895
  * @returns The hyperbolic arcsecant of x
2855
2896
  */
2856
- asech(x: number): number
2897
+ asech(x: number): number | Complex
2857
2898
  asech(x: BigNumber): BigNumber
2858
- asech(x: MathArray): MathArray
2859
- asech(x: Matrix): Matrix
2899
+ asech(x: Complex): Complex
2860
2900
 
2861
2901
  /**
2862
- * Calculate the inverse sine of a value. For matrices, the function is
2863
- * evaluated element wise.
2902
+ * Calculate the inverse sine of a value.
2864
2903
  * @param x Function input
2865
2904
  * @returns The arc sine of x
2866
2905
  */
2867
- asin(x: number): number
2906
+ asin(x: number): number | Complex
2868
2907
  asin(x: BigNumber): BigNumber
2869
2908
  asin(x: Complex): Complex
2870
- asin(x: MathArray): MathArray
2871
- asin(x: Matrix): Matrix
2872
2909
 
2873
2910
  /**
2874
2911
  * Calculate the hyperbolic arcsine of a value, defined as asinh(x) =
2875
- * ln(x + sqrt(x^2 + 1)). For matrices, the function is evaluated
2876
- * element wise.
2912
+ * ln(x + sqrt(x^2 + 1)).
2877
2913
  * @param x Function input
2878
2914
  * @returns The hyperbolic arcsine of x
2879
2915
  */
2880
2916
  asinh(x: number): number
2881
2917
  asinh(x: BigNumber): BigNumber
2882
- asinh(x: MathArray): MathArray
2883
- asinh(x: Matrix): Matrix
2918
+ asinh(x: Complex): Complex
2884
2919
 
2885
2920
  /**
2886
- * Calculate the inverse tangent of a value. For matrices, the function
2887
- * is evaluated element wise.
2921
+ * Calculate the inverse tangent of a value.
2888
2922
  * @param x Function input
2889
2923
  * @returns The arc tangent of x
2890
2924
  */
2891
2925
  atan(x: number): number
2892
2926
  atan(x: BigNumber): BigNumber
2893
- atan(x: MathArray): MathArray
2894
- atan(x: Matrix): Matrix
2927
+ atan(x: Complex): Complex
2895
2928
 
2896
2929
  /**
2897
2930
  * Calculate the inverse tangent function with two arguments, y/x. By
@@ -2905,156 +2938,127 @@ declare namespace math {
2905
2938
 
2906
2939
  /**
2907
2940
  * Calculate the hyperbolic arctangent of a value, defined as atanh(x) =
2908
- * ln((1 + x)/(1 - x)) / 2. For matrices, the function is evaluated
2909
- * element wise.
2941
+ * ln((1 + x)/(1 - x)) / 2.
2910
2942
  * @param x Function input
2911
2943
  * @returns The hyperbolic arctangent of x
2912
2944
  */
2913
- atanh(x: number): number
2945
+ atanh(x: number): number | Complex
2914
2946
  atanh(x: BigNumber): BigNumber
2915
- atanh(x: MathArray): MathArray
2916
- atanh(x: Matrix): Matrix
2947
+ atanh(x: Complex): Complex
2917
2948
 
2918
2949
  /**
2919
- * Calculate the cosine of a value. For matrices, the function is
2920
- * evaluated element wise.
2950
+ * Calculate the cosine of a value.
2921
2951
  * @param x Function input
2922
2952
  * @returns The cosine of x
2923
2953
  */
2924
2954
  cos(x: number | Unit): number
2925
2955
  cos(x: BigNumber): BigNumber
2926
2956
  cos(x: Complex): Complex
2927
- cos(x: MathArray): MathArray
2928
- cos(x: Matrix): Matrix
2929
2957
 
2930
2958
  /**
2931
2959
  * Calculate the hyperbolic cosine of a value, defined as cosh(x) = 1/2
2932
- * * (exp(x) + exp(-x)). For matrices, the function is evaluated element
2933
- * wise.
2960
+ * * (exp(x) + exp(-x)).
2934
2961
  * @param x Function input
2935
2962
  * @returns The hyperbolic cosine of x
2936
2963
  */
2937
2964
  cosh(x: number | Unit): number
2938
2965
  cosh(x: BigNumber): BigNumber
2939
2966
  cosh(x: Complex): Complex
2940
- cosh(x: MathArray): MathArray
2941
- cosh(x: Matrix): Matrix
2942
2967
 
2943
2968
  /**
2944
2969
  * Calculate the cotangent of a value. cot(x) is defined as 1 / tan(x).
2945
- * For matrices, the function is evaluated element wise.
2946
2970
  * @param x Function input
2947
2971
  * @returns The cotangent of x
2948
2972
  */
2949
2973
  cot(x: number | Unit): number
2974
+ cot(x: BigNumber): BigNumber
2950
2975
  cot(x: Complex): Complex
2951
- cot(x: MathArray): MathArray
2952
- cot(x: Matrix): Matrix
2953
2976
 
2954
2977
  /**
2955
2978
  * Calculate the hyperbolic cotangent of a value, defined as coth(x) = 1
2956
- * / tanh(x). For matrices, the function is evaluated element wise.
2979
+ * / tanh(x).
2957
2980
  * @param x Function input
2958
2981
  * @returns The hyperbolic cotangent of x
2959
2982
  */
2960
2983
  coth(x: number | Unit): number
2984
+ coth(x: BigNumber): BigNumber
2961
2985
  coth(x: Complex): Complex
2962
- coth(x: MathArray): MathArray
2963
- coth(x: Matrix): Matrix
2964
2986
 
2965
2987
  /**
2966
- * Calculate the cosecant of a value, defined as csc(x) = 1/sin(x). For
2967
- * matrices, the function is evaluated element wise.
2988
+ * Calculate the cosecant of a value, defined as csc(x) = 1/sin(x).
2968
2989
  * @param x Function input
2969
2990
  * @returns The cosecant hof x
2970
2991
  */
2971
2992
  csc(x: number | Unit): number
2993
+ csc(x: BigNumber): BigNumber
2972
2994
  csc(x: Complex): Complex
2973
- csc(x: MathArray): MathArray
2974
- csc(x: Matrix): Matrix
2975
2995
 
2976
2996
  /**
2977
2997
  * Calculate the hyperbolic cosecant of a value, defined as csch(x) = 1
2978
- * / sinh(x). For matrices, the function is evaluated element wise.
2998
+ * / sinh(x).
2979
2999
  * @param x Function input
2980
3000
  * @returns The hyperbolic cosecant of x
2981
3001
  */
2982
3002
  csch(x: number | Unit): number
3003
+ csch(x: BigNumber): BigNumber
2983
3004
  csch(x: Complex): Complex
2984
- csch(x: MathArray): MathArray
2985
- csch(x: Matrix): Matrix
2986
3005
 
2987
3006
  /**
2988
- * Calculate the secant of a value, defined as sec(x) = 1/cos(x). For
2989
- * matrices, the function is evaluated element wise.
3007
+ * Calculate the secant of a value, defined as sec(x) = 1/cos(x).
2990
3008
  * @param x Function input
2991
3009
  * @returns The secant of x
2992
3010
  */
2993
3011
  sec(x: number | Unit): number
3012
+ sec(x: BigNumber): BigNumber
2994
3013
  sec(x: Complex): Complex
2995
- sec(x: MathArray): MathArray
2996
- sec(x: Matrix): Matrix
2997
3014
 
2998
3015
  /**
2999
3016
  * Calculate the hyperbolic secant of a value, defined as sech(x) = 1 /
3000
- * cosh(x). For matrices, the function is evaluated element wise.
3017
+ * cosh(x).
3001
3018
  * @param x Function input
3002
3019
  * @returns The hyperbolic secant of x
3003
3020
  */
3004
3021
  sech(x: number | Unit): number
3022
+ sech(x: BigNumber): BigNumber
3005
3023
  sech(x: Complex): Complex
3006
- sech(x: MathArray): MathArray
3007
- sech(x: Matrix): Matrix
3008
3024
 
3009
3025
  /**
3010
- * Calculate the sine of a value. For matrices, the function is
3011
- * evaluated element wise.
3026
+ * Calculate the sine of a value.
3012
3027
  * @param x Function input
3013
3028
  * @returns The sine of x
3014
3029
  */
3015
3030
  sin(x: number | Unit): number
3016
3031
  sin(x: BigNumber): BigNumber
3017
3032
  sin(x: Complex): Complex
3018
- sin(x: MathArray): MathArray
3019
- sin(x: Matrix): Matrix
3020
3033
 
3021
3034
  /**
3022
3035
  * Calculate the hyperbolic sine of a value, defined as sinh(x) = 1/2 *
3023
- * (exp(x) - exp(-x)). For matrices, the function is evaluated element
3024
- * wise.
3036
+ * (exp(x) - exp(-x)).
3025
3037
  * @param x Function input
3026
3038
  * @returns The hyperbolic sine of x
3027
3039
  */
3028
3040
  sinh(x: number | Unit): number
3029
3041
  sinh(x: BigNumber): BigNumber
3030
3042
  sinh(x: Complex): Complex
3031
- sinh(x: MathArray): MathArray
3032
- sinh(x: Matrix): Matrix
3033
3043
 
3034
3044
  /**
3035
3045
  * Calculate the tangent of a value. tan(x) is equal to sin(x) / cos(x).
3036
- * For matrices, the function is evaluated element wise.
3037
3046
  * @param x Function input
3038
3047
  * @returns The tangent of x
3039
3048
  */
3040
3049
  tan(x: number | Unit): number
3041
3050
  tan(x: BigNumber): BigNumber
3042
3051
  tan(x: Complex): Complex
3043
- tan(x: MathArray): MathArray
3044
- tan(x: Matrix): Matrix
3045
3052
 
3046
3053
  /**
3047
3054
  * Calculate the hyperbolic tangent of a value, defined as tanh(x) =
3048
- * (exp(2 * x) - 1) / (exp(2 * x) + 1). For matrices, the function is
3049
- * evaluated element wise.
3055
+ * (exp(2 * x) - 1) / (exp(2 * x) + 1).
3050
3056
  * @param x Function input
3051
3057
  * @returns The hyperbolic tangent of x
3052
3058
  */
3053
3059
  tanh(x: number | Unit): number
3054
3060
  tanh(x: BigNumber): BigNumber
3055
3061
  tanh(x: Complex): Complex
3056
- tanh(x: MathArray): MathArray
3057
- tanh(x: Matrix): Matrix
3058
3062
 
3059
3063
  /*************************************************************************
3060
3064
  * Unit functions
@@ -3288,10 +3292,12 @@ declare namespace math {
3288
3292
  factories: FactoryFunctionMap,
3289
3293
  config?: ConfigOptions
3290
3294
  ) => MathJsStatic
3291
- factory: <T>(
3295
+ factory: <T, TDeps extends readonly MathJsFunctionName[]>(
3292
3296
  name: string,
3293
- dependencies: MathJsFunctionName[],
3294
- create: (injected: Partial<MathJsStatic>) => T,
3297
+ dependencies: TDeps,
3298
+ create: (
3299
+ injected: Pick<MathJsStatic, Extract<MathJsFunctionName, TDeps[number]>>
3300
+ ) => T,
3295
3301
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3296
3302
  meta?: any
3297
3303
  ) => FactoryFunction<T>
@@ -3759,6 +3765,18 @@ declare namespace math {
3759
3765
  override?: boolean
3760
3766
  }
3761
3767
 
3768
+ type SimplifyContext = Partial<
3769
+ Record<
3770
+ OperatorNodeFn,
3771
+ {
3772
+ trivial: boolean
3773
+ total: boolean
3774
+ commutative: boolean
3775
+ associative: boolean
3776
+ }
3777
+ >
3778
+ >
3779
+
3762
3780
  interface SimplifyOptions {
3763
3781
  /** A boolean which is `true` by default. */
3764
3782
  exactFractions?: boolean
@@ -3768,23 +3786,46 @@ declare namespace math {
3768
3786
  * Default value is 10000.
3769
3787
  */
3770
3788
  fractionsLimit?: number
3789
+ /** A boolean which is `false` by default. */
3790
+ consoleDebug?: boolean
3791
+ /**
3792
+ * gives properties of each operator, which determine what simplifications
3793
+ * are allowed. Properties are commutative, associative, total (whether
3794
+ * the operation is defined for all arguments), and trivial (whether
3795
+ * the operation applied to a single argument leaves that argument
3796
+ * unchanged).
3797
+ */
3798
+ context?: SimplifyContext
3771
3799
  }
3772
3800
 
3773
3801
  type SimplifyRule =
3774
- | { l: string; r: string }
3802
+ | {
3803
+ l: string
3804
+ r: string
3805
+ repeat?: boolean
3806
+ assuming?: SimplifyContext
3807
+ imposeContext?: SimplifyContext
3808
+ }
3809
+ | {
3810
+ s: string
3811
+ repeat?: boolean
3812
+ assuming?: SimplifyContext
3813
+ imposeContext?: SimplifyContext
3814
+ }
3775
3815
  | string
3776
3816
  | ((node: MathNode) => MathNode)
3777
3817
 
3778
3818
  interface Simplify {
3819
+ (expr: MathNode | string): MathNode
3779
3820
  (
3780
3821
  expr: MathNode | string,
3781
- rules?: SimplifyRule[],
3822
+ rules: SimplifyRule[],
3782
3823
  scope?: object,
3783
3824
  options?: SimplifyOptions
3784
3825
  ): MathNode
3785
3826
  (
3786
3827
  expr: MathNode | string,
3787
- scope?: object,
3828
+ scope: object,
3788
3829
  options?: SimplifyOptions
3789
3830
  ): MathNode
3790
3831
 
@@ -4104,7 +4145,7 @@ declare namespace math {
4104
4145
  */
4105
4146
  createUnit(
4106
4147
  this: MathJsChain<string>,
4107
- definition?: string | UnitDefinition,
4148
+ definition?: string | UnitDefinition | Unit,
4108
4149
  options?: CreateUnitOptions
4109
4150
  ): MathJsChain<Unit>
4110
4151
  /**
@@ -4118,7 +4159,7 @@ declare namespace math {
4118
4159
  * 0.
4119
4160
  */
4120
4161
  createUnit(
4121
- this: MathJsChain<Record<string, string | UnitDefinition>>,
4162
+ this: MathJsChain<Record<string, string | UnitDefinition | Unit>>,
4122
4163
  options?: CreateUnitOptions
4123
4164
  ): MathJsChain<Unit>
4124
4165
 
@@ -4369,15 +4410,23 @@ declare namespace math {
4369
4410
  * pass a custom set of rules to the function as second argument. A rule
4370
4411
  * can be specified as an object, string, or function.
4371
4412
  * @param scope Scope to variables
4413
+ * @param options Options to configure the behavior of simplify
4372
4414
  */
4373
4415
  simplify(
4374
4416
  this: MathJsChain<MathNode | string>,
4375
4417
  rules?: SimplifyRule[],
4376
- scope?: object
4418
+ scope?: Map<string, MathType> | object,
4419
+ options?: SimplifyOptions
4377
4420
  ): MathJsChain<MathNode>
4378
4421
 
4379
- // TODO check that this should even be here...
4380
- simplifyCore(expr: MathNode): MathNode
4422
+ simplifyConstant(
4423
+ this: MathJsChain<MathNode | string>,
4424
+ options?: SimplifyOptions
4425
+ ): MathJsChain<MathNode>
4426
+ simplifyCore(
4427
+ this: MathJsChain<MathNode | string>,
4428
+ options?: SimplifyOptions
4429
+ ): MathJsChain<MathNode>
4381
4430
 
4382
4431
  /**
4383
4432
  * Calculate the Sparse Matrix LU decomposition with full pivoting.
@@ -4461,16 +4510,9 @@ declare namespace math {
4461
4510
  * if false (default) the principal root is returned.
4462
4511
  */
4463
4512
  cbrt(this: MathJsChain<number>, allRoots?: boolean): MathJsChain<number>
4464
- cbrt(
4465
- this: MathJsChain<BigNumber>,
4466
- allRoots?: boolean
4467
- ): MathJsChain<BigNumber>
4513
+ cbrt(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4468
4514
  cbrt(this: MathJsChain<Complex>, allRoots?: boolean): MathJsChain<Complex>
4469
- cbrt(
4470
- this: MathJsChain<MathArray>,
4471
- allRoots?: boolean
4472
- ): MathJsChain<MathArray>
4473
- cbrt(this: MathJsChain<Matrix>, allRoots?: boolean): MathJsChain<Matrix>
4515
+ cbrt(this: MathJsChain<Unit>, allRoots?: boolean): MathJsChain<Unit>
4474
4516
 
4475
4517
  // Rounding functions grouped for similarity
4476
4518
 
@@ -4541,8 +4583,6 @@ declare namespace math {
4541
4583
  cube(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4542
4584
  cube(this: MathJsChain<Fraction>): MathJsChain<Fraction>
4543
4585
  cube(this: MathJsChain<Complex>): MathJsChain<Complex>
4544
- cube(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4545
- cube(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4546
4586
  cube(this: MathJsChain<Unit>): MathJsChain<Unit>
4547
4587
 
4548
4588
  /**
@@ -4582,8 +4622,6 @@ declare namespace math {
4582
4622
  exp(this: MathJsChain<number>): MathJsChain<number>
4583
4623
  exp(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4584
4624
  exp(this: MathJsChain<Complex>): MathJsChain<Complex>
4585
- exp(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4586
- exp(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4587
4625
 
4588
4626
  /**
4589
4627
  * Calculate the value of subtracting 1 from the exponential value. For
@@ -4592,8 +4630,6 @@ declare namespace math {
4592
4630
  expm1(this: MathJsChain<number>): MathJsChain<number>
4593
4631
  expm1(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4594
4632
  expm1(this: MathJsChain<Complex>): MathJsChain<Complex>
4595
- expm1(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4596
- expm1(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4597
4633
 
4598
4634
  /**
4599
4635
  * Calculate the greatest common divisor for two or more values or
@@ -4835,6 +4871,21 @@ declare namespace math {
4835
4871
  b: number | BigNumber
4836
4872
  ): MathJsChain<MathArray>
4837
4873
 
4874
+ /**
4875
+ * Count the number of elements of a matrix, array or string.
4876
+ */
4877
+ count(this: MathJsChain<MathCollection>): MathJsChain<number>
4878
+ count(this: MathJsChain<string>): MathJsChain<number>
4879
+
4880
+ /**
4881
+ * Compute the sum of a matrix or a list with values. In case of a
4882
+ * (multi dimensional) array or matrix, the sum of all elements will be
4883
+ * calculated.
4884
+ */
4885
+ sum(
4886
+ this: MathJsChain<Array<number | BigNumber | Fraction>>
4887
+ ): MathJsChain<number>
4888
+ sum(this: MathJsChain<MathCollection>): MathJsChain<number>
4838
4889
  /*************************************************************************
4839
4890
  * Bitwise functions
4840
4891
  ************************************************************************/
@@ -5248,16 +5299,7 @@ declare namespace math {
5248
5299
  * @param format The matrix storage format
5249
5300
  */
5250
5301
  ones(
5251
- this: MathJsChain<number | number[]>,
5252
- format?: string
5253
- ): MathJsChain<MathCollection>
5254
-
5255
- /**
5256
- * @param format The matrix storage format
5257
- */
5258
- ones(
5259
- this: MathJsChain<number>,
5260
- n: number,
5302
+ this: MathJsChain<number | number[] | BigNumber | BigNumber[]>,
5261
5303
  format?: string
5262
5304
  ): MathJsChain<MathCollection>
5263
5305
 
@@ -5396,17 +5438,7 @@ declare namespace math {
5396
5438
  * @returns A matrix filled with zeros
5397
5439
  */
5398
5440
  zeros(
5399
- this: MathJsChain<number | number[]>,
5400
- format?: string
5401
- ): MathJsChain<MathCollection>
5402
-
5403
- /**
5404
- * @param n The y dimension of the matrix
5405
- * @param format The matrix storage format
5406
- */
5407
- zeros(
5408
- this: MathJsChain<number>,
5409
- n: number,
5441
+ this: MathJsChain<number | number[] | BigNumber | BigNumber[]>,
5410
5442
  format?: string
5411
5443
  ): MathJsChain<MathCollection>
5412
5444