mathjs 10.6.4 → 11.0.0

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