mathjs 10.5.2 → 10.6.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 (329) hide show
  1. package/HISTORY.md +28 -0
  2. package/lib/browser/math.js +6 -5
  3. package/lib/browser/math.js.map +1 -1
  4. package/lib/cjs/entry/dependenciesAny/dependenciesFft.generated.js +41 -0
  5. package/lib/cjs/entry/dependenciesAny/dependenciesIfft.generated.js +29 -0
  6. package/lib/cjs/entry/dependenciesAny.generated.js +16 -0
  7. package/lib/cjs/entry/impureFunctionsAny.generated.js +66 -64
  8. package/lib/cjs/entry/pureFunctionsAny.generated.js +189 -171
  9. package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +6 -0
  10. package/lib/cjs/expression/embeddedDocs/function/matrix/fft.js +15 -0
  11. package/lib/cjs/expression/embeddedDocs/function/matrix/ifft.js +15 -0
  12. package/lib/cjs/factoriesAny.js +16 -0
  13. package/lib/cjs/function/algebra/derivative.js +1 -1
  14. package/lib/cjs/function/matrix/fft.js +128 -0
  15. package/lib/cjs/function/matrix/ifft.js +49 -0
  16. package/lib/cjs/header.js +2 -2
  17. package/lib/cjs/version.js +1 -1
  18. package/lib/esm/entry/dependenciesAny/dependenciesFft.generated.js +24 -0
  19. package/lib/esm/entry/dependenciesAny/dependenciesIfft.generated.js +16 -0
  20. package/lib/esm/entry/dependenciesAny.generated.js +2 -0
  21. package/lib/esm/entry/impureFunctionsAny.generated.js +63 -61
  22. package/lib/esm/entry/pureFunctionsAny.generated.js +161 -145
  23. package/lib/esm/expression/embeddedDocs/embeddedDocs.js +4 -0
  24. package/lib/esm/expression/embeddedDocs/function/matrix/fft.js +8 -0
  25. package/lib/esm/expression/embeddedDocs/function/matrix/ifft.js +8 -0
  26. package/lib/esm/factoriesAny.js +2 -0
  27. package/lib/esm/function/algebra/derivative.js +1 -1
  28. package/lib/esm/function/matrix/fft.js +104 -0
  29. package/lib/esm/function/matrix/ifft.js +38 -0
  30. package/lib/esm/version.js +1 -1
  31. package/package.json +22 -24
  32. package/types/index.d.ts +1052 -283
  33. package/types/index.ts +711 -7
  34. package/docs/command_line_interface.md +0 -87
  35. package/docs/core/chaining.md +0 -41
  36. package/docs/core/configuration.md +0 -144
  37. package/docs/core/extension.md +0 -263
  38. package/docs/core/index.md +0 -21
  39. package/docs/core/serialization.md +0 -50
  40. package/docs/custom_bundling.md +0 -116
  41. package/docs/datatypes/bignumbers.md +0 -102
  42. package/docs/datatypes/complex_numbers.md +0 -168
  43. package/docs/datatypes/fractions.md +0 -75
  44. package/docs/datatypes/index.md +0 -67
  45. package/docs/datatypes/matrices.md +0 -375
  46. package/docs/datatypes/numbers.md +0 -106
  47. package/docs/datatypes/units.md +0 -444
  48. package/docs/expressions/algebra.md +0 -110
  49. package/docs/expressions/customization.md +0 -379
  50. package/docs/expressions/expression_trees.md +0 -710
  51. package/docs/expressions/html_classes.md +0 -38
  52. package/docs/expressions/index.md +0 -21
  53. package/docs/expressions/parsing.md +0 -224
  54. package/docs/expressions/security.md +0 -89
  55. package/docs/expressions/syntax.md +0 -706
  56. package/docs/getting_started.md +0 -124
  57. package/docs/index.md +0 -39
  58. package/docs/reference/classes/densematrix.md +0 -247
  59. package/docs/reference/classes/fibonacciheap.md +0 -70
  60. package/docs/reference/classes/matrixindex.md +0 -133
  61. package/docs/reference/classes/matrixrange.md +0 -158
  62. package/docs/reference/classes/resultset.md +0 -47
  63. package/docs/reference/classes/sparsematrix.md +0 -245
  64. package/docs/reference/classes/unit.md +0 -242
  65. package/docs/reference/classes.md +0 -86
  66. package/docs/reference/constants.md +0 -29
  67. package/docs/reference/functions/abs.md +0 -46
  68. package/docs/reference/functions/acos.md +0 -49
  69. package/docs/reference/functions/acosh.md +0 -47
  70. package/docs/reference/functions/acot.md +0 -48
  71. package/docs/reference/functions/acoth.md +0 -46
  72. package/docs/reference/functions/acsc.md +0 -49
  73. package/docs/reference/functions/acsch.md +0 -46
  74. package/docs/reference/functions/add.md +0 -59
  75. package/docs/reference/functions/and.md +0 -53
  76. package/docs/reference/functions/apply.md +0 -56
  77. package/docs/reference/functions/arg.md +0 -53
  78. package/docs/reference/functions/asec.md +0 -49
  79. package/docs/reference/functions/asech.md +0 -46
  80. package/docs/reference/functions/asin.md +0 -49
  81. package/docs/reference/functions/asinh.md +0 -46
  82. package/docs/reference/functions/atan.md +0 -49
  83. package/docs/reference/functions/atan2.md +0 -56
  84. package/docs/reference/functions/atanh.md +0 -46
  85. package/docs/reference/functions/bellNumbers.md +0 -45
  86. package/docs/reference/functions/bignumber.md +0 -47
  87. package/docs/reference/functions/bin.md +0 -45
  88. package/docs/reference/functions/bitAnd.md +0 -51
  89. package/docs/reference/functions/bitNot.md +0 -51
  90. package/docs/reference/functions/bitOr.md +0 -52
  91. package/docs/reference/functions/bitXor.md +0 -51
  92. package/docs/reference/functions/boolean.md +0 -50
  93. package/docs/reference/functions/catalan.md +0 -45
  94. package/docs/reference/functions/cbrt.md +0 -60
  95. package/docs/reference/functions/ceil.md +0 -63
  96. package/docs/reference/functions/chain.md +0 -54
  97. package/docs/reference/functions/clone.md +0 -43
  98. package/docs/reference/functions/column.md +0 -45
  99. package/docs/reference/functions/combinations.md +0 -49
  100. package/docs/reference/functions/combinationsWithRep.md +0 -49
  101. package/docs/reference/functions/compare.md +0 -67
  102. package/docs/reference/functions/compareNatural.md +0 -92
  103. package/docs/reference/functions/compareText.md +0 -54
  104. package/docs/reference/functions/compile.md +0 -56
  105. package/docs/reference/functions/complex.md +0 -17
  106. package/docs/reference/functions/composition.md +0 -46
  107. package/docs/reference/functions/concat.md +0 -56
  108. package/docs/reference/functions/config.md +0 -44
  109. package/docs/reference/functions/conj.md +0 -50
  110. package/docs/reference/functions/cos.md +0 -51
  111. package/docs/reference/functions/cosh.md +0 -46
  112. package/docs/reference/functions/cot.md +0 -47
  113. package/docs/reference/functions/coth.md +0 -49
  114. package/docs/reference/functions/count.md +0 -45
  115. package/docs/reference/functions/createUnit.md +0 -52
  116. package/docs/reference/functions/cross.md +0 -58
  117. package/docs/reference/functions/csc.md +0 -47
  118. package/docs/reference/functions/csch.md +0 -49
  119. package/docs/reference/functions/ctranspose.md +0 -50
  120. package/docs/reference/functions/cube.md +0 -51
  121. package/docs/reference/functions/cumsum.md +0 -57
  122. package/docs/reference/functions/deepEqual.md +0 -53
  123. package/docs/reference/functions/derivative.md +0 -61
  124. package/docs/reference/functions/det.md +0 -49
  125. package/docs/reference/functions/diag.md +0 -61
  126. package/docs/reference/functions/diff.md +0 -70
  127. package/docs/reference/functions/distance.md +0 -80
  128. package/docs/reference/functions/divide.md +0 -55
  129. package/docs/reference/functions/dot.md +0 -48
  130. package/docs/reference/functions/dotDivide.md +0 -52
  131. package/docs/reference/functions/dotMultiply.md +0 -52
  132. package/docs/reference/functions/dotPow.md +0 -49
  133. package/docs/reference/functions/eigs.md +0 -54
  134. package/docs/reference/functions/equal.md +0 -75
  135. package/docs/reference/functions/equalText.md +0 -53
  136. package/docs/reference/functions/erf.md +0 -49
  137. package/docs/reference/functions/evaluate.md +0 -56
  138. package/docs/reference/functions/exp.md +0 -54
  139. package/docs/reference/functions/expm.md +0 -49
  140. package/docs/reference/functions/expm1.md +0 -54
  141. package/docs/reference/functions/factorial.md +0 -49
  142. package/docs/reference/functions/fft.md +0 -35
  143. package/docs/reference/functions/filter.md +0 -50
  144. package/docs/reference/functions/fix.md +0 -62
  145. package/docs/reference/functions/flatten.md +0 -46
  146. package/docs/reference/functions/floor.md +0 -66
  147. package/docs/reference/functions/forEach.md +0 -41
  148. package/docs/reference/functions/format.md +0 -127
  149. package/docs/reference/functions/fraction.md +0 -45
  150. package/docs/reference/functions/gamma.md +0 -49
  151. package/docs/reference/functions/gcd.md +0 -50
  152. package/docs/reference/functions/getMatrixDataType.md +0 -59
  153. package/docs/reference/functions/hasNumericValue.md +0 -55
  154. package/docs/reference/functions/help.md +0 -42
  155. package/docs/reference/functions/hex.md +0 -45
  156. package/docs/reference/functions/hypot.md +0 -51
  157. package/docs/reference/functions/identity.md +0 -57
  158. package/docs/reference/functions/ifft.md +0 -35
  159. package/docs/reference/functions/im.md +0 -53
  160. package/docs/reference/functions/import.md +0 -68
  161. package/docs/reference/functions/index.md +0 -55
  162. package/docs/reference/functions/intersect.md +0 -50
  163. package/docs/reference/functions/inv.md +0 -45
  164. package/docs/reference/functions/invmod.md +0 -47
  165. package/docs/reference/functions/isInteger.md +0 -55
  166. package/docs/reference/functions/isNaN.md +0 -56
  167. package/docs/reference/functions/isNegative.md +0 -55
  168. package/docs/reference/functions/isNumeric.md +0 -55
  169. package/docs/reference/functions/isPositive.md +0 -57
  170. package/docs/reference/functions/isPrime.md +0 -54
  171. package/docs/reference/functions/isZero.md +0 -59
  172. package/docs/reference/functions/kldivergence.md +0 -41
  173. package/docs/reference/functions/kron.md +0 -53
  174. package/docs/reference/functions/larger.md +0 -60
  175. package/docs/reference/functions/largerEq.md +0 -56
  176. package/docs/reference/functions/lcm.md +0 -54
  177. package/docs/reference/functions/leafCount.md +0 -52
  178. package/docs/reference/functions/leftShift.md +0 -52
  179. package/docs/reference/functions/lgamma.md +0 -46
  180. package/docs/reference/functions/log.md +0 -57
  181. package/docs/reference/functions/log10.md +0 -50
  182. package/docs/reference/functions/log1p.md +0 -54
  183. package/docs/reference/functions/log2.md +0 -50
  184. package/docs/reference/functions/lsolve.md +0 -51
  185. package/docs/reference/functions/lsolveAll.md +0 -51
  186. package/docs/reference/functions/lup.md +0 -52
  187. package/docs/reference/functions/lusolve.md +0 -59
  188. package/docs/reference/functions/mad.md +0 -50
  189. package/docs/reference/functions/map.md +0 -65
  190. package/docs/reference/functions/matrix.md +0 -56
  191. package/docs/reference/functions/matrixFromColumns.md +0 -49
  192. package/docs/reference/functions/matrixFromFunction.md +0 -54
  193. package/docs/reference/functions/matrixFromRows.md +0 -49
  194. package/docs/reference/functions/max.md +0 -61
  195. package/docs/reference/functions/mean.md +0 -57
  196. package/docs/reference/functions/median.md +0 -57
  197. package/docs/reference/functions/min.md +0 -61
  198. package/docs/reference/functions/mod.md +0 -59
  199. package/docs/reference/functions/mode.md +0 -50
  200. package/docs/reference/functions/multinomial.md +0 -46
  201. package/docs/reference/functions/multiply.md +0 -60
  202. package/docs/reference/functions/norm.md +0 -59
  203. package/docs/reference/functions/not.md +0 -50
  204. package/docs/reference/functions/nthRoot.md +0 -53
  205. package/docs/reference/functions/nthRoots.md +0 -58
  206. package/docs/reference/functions/number.md +0 -49
  207. package/docs/reference/functions/numeric.md +0 -52
  208. package/docs/reference/functions/oct.md +0 -45
  209. package/docs/reference/functions/ones.md +0 -59
  210. package/docs/reference/functions/or.md +0 -53
  211. package/docs/reference/functions/parse.md +0 -56
  212. package/docs/reference/functions/parser.md +0 -70
  213. package/docs/reference/functions/partitionSelect.md +0 -53
  214. package/docs/reference/functions/permutations.md +0 -51
  215. package/docs/reference/functions/pickRandom.md +0 -59
  216. package/docs/reference/functions/pinv.md +0 -44
  217. package/docs/reference/functions/pow.md +0 -65
  218. package/docs/reference/functions/print.md +0 -64
  219. package/docs/reference/functions/prod.md +0 -55
  220. package/docs/reference/functions/qr.md +0 -65
  221. package/docs/reference/functions/quantileSeq.md +0 -62
  222. package/docs/reference/functions/random.md +0 -54
  223. package/docs/reference/functions/randomInt.md +0 -53
  224. package/docs/reference/functions/range.md +0 -70
  225. package/docs/reference/functions/rationalize.md +0 -68
  226. package/docs/reference/functions/re.md +0 -53
  227. package/docs/reference/functions/reshape.md +0 -60
  228. package/docs/reference/functions/resize.md +0 -51
  229. package/docs/reference/functions/resolve.md +0 -46
  230. package/docs/reference/functions/rightArithShift.md +0 -52
  231. package/docs/reference/functions/rightLogShift.md +0 -52
  232. package/docs/reference/functions/rotate.md +0 -53
  233. package/docs/reference/functions/rotationMatrix.md +0 -57
  234. package/docs/reference/functions/round.md +0 -61
  235. package/docs/reference/functions/row.md +0 -45
  236. package/docs/reference/functions/sec.md +0 -47
  237. package/docs/reference/functions/sech.md +0 -49
  238. package/docs/reference/functions/setCartesian.md +0 -49
  239. package/docs/reference/functions/setDifference.md +0 -47
  240. package/docs/reference/functions/setDistinct.md +0 -43
  241. package/docs/reference/functions/setIntersect.md +0 -46
  242. package/docs/reference/functions/setIsSubset.md +0 -47
  243. package/docs/reference/functions/setMultiplicity.md +0 -46
  244. package/docs/reference/functions/setPowerset.md +0 -43
  245. package/docs/reference/functions/setSize.md +0 -47
  246. package/docs/reference/functions/setSymDifference.md +0 -47
  247. package/docs/reference/functions/setUnion.md +0 -46
  248. package/docs/reference/functions/sign.md +0 -52
  249. package/docs/reference/functions/simplify.md +0 -130
  250. package/docs/reference/functions/simplifyConstant.md +0 -52
  251. package/docs/reference/functions/simplifyCore.md +0 -50
  252. package/docs/reference/functions/sin.md +0 -51
  253. package/docs/reference/functions/sinh.md +0 -46
  254. package/docs/reference/functions/size.md +0 -50
  255. package/docs/reference/functions/slu.md +0 -57
  256. package/docs/reference/functions/smaller.md +0 -60
  257. package/docs/reference/functions/smallerEq.md +0 -56
  258. package/docs/reference/functions/sort.md +0 -56
  259. package/docs/reference/functions/sparse.md +0 -51
  260. package/docs/reference/functions/splitUnit.md +0 -37
  261. package/docs/reference/functions/sqrt.md +0 -50
  262. package/docs/reference/functions/sqrtm.md +0 -46
  263. package/docs/reference/functions/square.md +0 -51
  264. package/docs/reference/functions/squeeze.md +0 -53
  265. package/docs/reference/functions/std.md +0 -76
  266. package/docs/reference/functions/stirlingS2.md +0 -52
  267. package/docs/reference/functions/string.md +0 -49
  268. package/docs/reference/functions/subset.md +0 -65
  269. package/docs/reference/functions/subtract.md +0 -54
  270. package/docs/reference/functions/sum.md +0 -54
  271. package/docs/reference/functions/symbolicEqual.md +0 -62
  272. package/docs/reference/functions/tan.md +0 -49
  273. package/docs/reference/functions/tanh.md +0 -50
  274. package/docs/reference/functions/to.md +0 -47
  275. package/docs/reference/functions/trace.md +0 -50
  276. package/docs/reference/functions/transpose.md +0 -49
  277. package/docs/reference/functions/typeOf.md +0 -81
  278. package/docs/reference/functions/typed.md +0 -56
  279. package/docs/reference/functions/unaryMinus.md +0 -49
  280. package/docs/reference/functions/unaryPlus.md +0 -48
  281. package/docs/reference/functions/unequal.md +0 -74
  282. package/docs/reference/functions/unit.md +0 -48
  283. package/docs/reference/functions/usolve.md +0 -51
  284. package/docs/reference/functions/usolveAll.md +0 -51
  285. package/docs/reference/functions/variance.md +0 -78
  286. package/docs/reference/functions/xgcd.md +0 -47
  287. package/docs/reference/functions/xor.md +0 -53
  288. package/docs/reference/functions/zeros.md +0 -57
  289. package/docs/reference/functions.md +0 -297
  290. package/docs/reference/index.md +0 -5
  291. package/examples/advanced/convert_fraction_to_bignumber.js +0 -59
  292. package/examples/advanced/custom_argument_parsing.js +0 -98
  293. package/examples/advanced/custom_datatype.js +0 -56
  294. package/examples/advanced/custom_evaluate_using_factories.js +0 -19
  295. package/examples/advanced/custom_evaluate_using_import.js +0 -18
  296. package/examples/advanced/custom_loading.js +0 -33
  297. package/examples/advanced/custom_relational_functions.js +0 -62
  298. package/examples/advanced/custom_scope_objects.js +0 -115
  299. package/examples/advanced/expression_trees.js +0 -55
  300. package/examples/advanced/function_transform.js +0 -50
  301. package/examples/advanced/more_secure_eval.js +0 -36
  302. package/examples/advanced/use_bigint.js +0 -43
  303. package/examples/advanced/web_server/math_worker.js +0 -24
  304. package/examples/advanced/web_server/server.js +0 -80
  305. package/examples/algebra.js +0 -34
  306. package/examples/basic_usage.js +0 -49
  307. package/examples/bignumbers.js +0 -52
  308. package/examples/browser/angle_configuration.html +0 -134
  309. package/examples/browser/basic_usage.html +0 -39
  310. package/examples/browser/currency_conversion.html +0 -125
  311. package/examples/browser/custom_separators.html +0 -81
  312. package/examples/browser/plot.html +0 -78
  313. package/examples/browser/pretty_printing_with_mathjax.html +0 -122
  314. package/examples/browser/printing_html.html +0 -170
  315. package/examples/browser/requirejs_loading.html +0 -20
  316. package/examples/browser/rocket_trajectory_optimization.html +0 -301
  317. package/examples/browser/webworkers/webworkers.html +0 -80
  318. package/examples/browser/webworkers/worker.js +0 -28
  319. package/examples/chaining.js +0 -56
  320. package/examples/complex_numbers.js +0 -67
  321. package/examples/expressions.js +0 -188
  322. package/examples/fractions.js +0 -74
  323. package/examples/import.js +0 -95
  324. package/examples/matrices.js +0 -101
  325. package/examples/objects.js +0 -35
  326. package/examples/package.json +0 -3
  327. package/examples/serialization.js +0 -16
  328. package/examples/sparse_matrices.js +0 -19
  329. package/examples/units.js +0 -108
package/types/index.d.ts CHANGED
@@ -276,25 +276,67 @@ declare namespace math {
276
276
  new (properties: Record<string, MathNode>): ObjectNode
277
277
  }
278
278
 
279
- interface OperatorNode extends MathNodeCommon {
279
+ type OperatorNodeMap = {
280
+ xor: 'xor'
281
+ and: 'and'
282
+ bitOr: '|'
283
+ bitXor: '^|'
284
+ bitAnd: '&'
285
+ equal: '=='
286
+ unequal: '!='
287
+ smaller: '<'
288
+ larger: '>'
289
+ smallerEq: '<='
290
+ leftShift: '<<'
291
+ rightArithShift: '>>'
292
+ rightLogShift: '>>>'
293
+ to: 'to'
294
+ add: '+'
295
+ subtract: '-'
296
+ multiply: '*'
297
+ divide: '/'
298
+ dotMultiply: '.*'
299
+ dotDivide: './'
300
+ mod: 'mod'
301
+ unaryPlus: '+'
302
+ unaryMinus: '-'
303
+ bitNot: '~'
304
+ not: 'not'
305
+ pow: '^'
306
+ dotPow: '.^'
307
+ factorial: '!'
308
+ }
309
+
310
+ type OperatorNodeOp = OperatorNodeMap[keyof OperatorNodeMap]
311
+ type OperatorNodeFn = keyof OperatorNodeMap
312
+
313
+ interface OperatorNode<
314
+ TOp extends OperatorNodeMap[TFn] = never,
315
+ TFn extends OperatorNodeFn = never,
316
+ TArgs extends MathNode[] = MathNode[]
317
+ > extends MathNodeCommon {
280
318
  type: 'OperatorNode'
281
319
  isOperatorNode: true
282
- op: string
283
- fn: string
284
- args: MathNode[]
320
+ op: TOp
321
+ fn: TFn
322
+ args: TArgs
285
323
  implicit: boolean
286
324
  isUnary(): boolean
287
325
  isBinary(): boolean
288
326
  }
289
- interface OperatorNodeCtor {
290
- new (
291
- op: string,
292
- fn: string,
293
- args: MathNode[],
327
+
328
+ interface OperatorNodeCtor extends MathNodeCommon {
329
+ new <
330
+ TOp extends OperatorNodeMap[TFn],
331
+ TFn extends OperatorNodeFn,
332
+ TArgs extends MathNode[]
333
+ >(
334
+ op: TOp,
335
+ fn: TFn,
336
+ args: TArgs,
294
337
  implicit?: boolean
295
- ): OperatorNode
338
+ ): OperatorNode<TOp, TFn, TArgs>
296
339
  }
297
-
298
340
  interface ParenthesisNode extends MathNodeCommon {
299
341
  type: 'ParenthesisNode'
300
342
  isParenthesisNode: true
@@ -345,7 +387,7 @@ declare namespace math {
345
387
  | FunctionNode
346
388
  | IndexNode
347
389
  | ObjectNode
348
- | OperatorNode
390
+ | OperatorNode<OperatorNodeOp, OperatorNodeFn>
349
391
  | ParenthesisNode
350
392
  | RangeNode
351
393
  | RelationalNode
@@ -353,6 +395,26 @@ declare namespace math {
353
395
 
354
396
  type MathJsFunctionName = keyof MathJsStatic
355
397
 
398
+ interface LUDecomposition {
399
+ L: MathCollection
400
+ U: MathCollection
401
+ p: number[]
402
+ }
403
+
404
+ interface SLUDecomposition extends LUDecomposition {
405
+ q: number[]
406
+ }
407
+
408
+ interface QRDecomposition {
409
+ Q: MathCollection
410
+ R: MathCollection
411
+ }
412
+
413
+ interface FractionDefinition {
414
+ a: number
415
+ b: number
416
+ }
417
+
356
418
  interface MathJsStatic extends FactoryDependencies {
357
419
  e: number
358
420
  pi: number
@@ -468,9 +530,8 @@ declare namespace math {
468
530
  * @param x A value of any type
469
531
  * @returns The boolean value
470
532
  */
471
- boolean(
472
- x: string | number | boolean | MathCollection | null
473
- ): boolean | MathCollection
533
+ boolean(x: string | number | boolean | null): boolean
534
+ boolean(x: MathCollection): MathCollection
474
535
 
475
536
  /**
476
537
  * Wrap any value in a chain, allowing to perform chained operations on
@@ -486,7 +547,7 @@ declare namespace math {
486
547
  * @returns The created chain
487
548
  */
488
549
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
489
- chain(value?: any): MathJsChain
550
+ chain<TValue>(value?: TValue): MathJsChain<TValue>
490
551
 
491
552
  /**
492
553
  * Create a complex value or convert a value to a complex value.
@@ -540,9 +601,10 @@ declare namespace math {
540
601
  * fraction
541
602
  * @returns Returns a fraction
542
603
  */
543
- fraction(value: number | string | BigNumber | Fraction | object): Fraction
544
- fraction(values: MathArray): MathArray
545
- fraction(values: Matrix): Matrix
604
+ fraction(
605
+ value: number | string | BigNumber | Fraction | FractionDefinition
606
+ ): Fraction
607
+ fraction(values: MathCollection): MathCollection
546
608
  /**
547
609
  * @param numerator Argument specifying the numerator of the fraction
548
610
  * @param denominator Argument specifying the denominator of the
@@ -589,16 +651,9 @@ declare namespace math {
589
651
  * @returns The created number
590
652
  */
591
653
  number(
592
- value?:
593
- | string
594
- | number
595
- | BigNumber
596
- | Fraction
597
- | boolean
598
- | MathCollection
599
- | Unit
600
- | null
601
- ): number | MathCollection
654
+ value?: string | number | BigNumber | Fraction | boolean | Unit | null
655
+ ): number
656
+ number(value?: MathCollection): number | MathCollection
602
657
  /**
603
658
  * @param value Value to be converted
604
659
  * @param valuelessUnit A valueless unit, used to convert a unit to a
@@ -633,7 +688,8 @@ declare namespace math {
633
688
  * @param value A value to convert to a string
634
689
  * @returns The created string
635
690
  */
636
- string(value: MathType | null): string | MathCollection
691
+ string(value: MathNumericType | string | Unit | null): string
692
+ string(value: MathCollection): MathCollection
637
693
 
638
694
  /**
639
695
  * Create a unit. Depending on the passed arguments, the function will
@@ -653,7 +709,8 @@ declare namespace math {
653
709
  * @param unit The unit to be created
654
710
  * @returns The created unit
655
711
  */
656
- unit(value: number | MathCollection | BigNumber, unit: string): Unit
712
+ unit(value: number | BigNumber, unit: string): Unit
713
+ unit(value: MathCollection, unit: string): Unit[]
657
714
 
658
715
  /*************************************************************************
659
716
  * Expression functions
@@ -672,6 +729,7 @@ declare namespace math {
672
729
  */
673
730
  compile(exprs: MathExpression[]): EvalFunction[]
674
731
 
732
+ // TODO properly type this
675
733
  /**
676
734
  * Evaluate an expression.
677
735
  * @param expr The expression to be evaluated
@@ -679,10 +737,15 @@ declare namespace math {
679
737
  * @returns The result of the expression
680
738
  */
681
739
  evaluate(
682
- expr: MathExpression | MathExpression[] | Matrix,
740
+ expr: MathExpression | Matrix,
683
741
  scope?: object
684
742
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
685
743
  ): any
744
+ evaluate(
745
+ expr: MathExpression[],
746
+ scope?: object
747
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
748
+ ): any[]
686
749
 
687
750
  /**
688
751
  * Retrieve help on a function or data type. Help files are retrieved
@@ -729,7 +792,8 @@ declare namespace math {
729
792
  * @param b A column vector with the b values
730
793
  * @returns A column vector with the linear system solution (x)
731
794
  */
732
- lsolve(L: Matrix | MathArray, b: Matrix | MathArray): Matrix | MathArray
795
+ lsolve(L: Matrix, b: Matrix | MathArray): Matrix
796
+ lsolve(L: MathArray, b: Matrix | MathArray): MathArray
733
797
 
734
798
  /**
735
799
  * Calculate the Matrix LU decomposition with partial pivoting. Matrix A
@@ -740,11 +804,7 @@ declare namespace math {
740
804
  * @returns The lower triangular matrix, the upper triangular matrix and
741
805
  * the permutation matrix.
742
806
  */
743
- lup(A?: Matrix | MathArray): {
744
- L: MathCollection
745
- U: MathCollection
746
- P: number[]
747
- }
807
+ lup(A?: Matrix | MathArray): LUDecomposition
748
808
 
749
809
  /**
750
810
  * Solves the linear system A * x = b where A is an [n x n] matrix and b
@@ -759,11 +819,18 @@ declare namespace math {
759
819
  * b
760
820
  */
761
821
  lusolve(
762
- A: Matrix | MathArray | number,
822
+ A: Matrix,
763
823
  b: Matrix | MathArray,
764
824
  order?: number,
765
825
  threshold?: number
766
- ): Matrix | MathArray
826
+ ): Matrix
827
+
828
+ lusolve(
829
+ A: MathArray,
830
+ b: Matrix | MathArray,
831
+ order?: number,
832
+ threshold?: number
833
+ ): MathArray
767
834
 
768
835
  /**
769
836
  * Calculate the Matrix QR decomposition. Matrix A is decomposed in two
@@ -773,7 +840,7 @@ declare namespace math {
773
840
  * decomposition.
774
841
  * @returns Q: the orthogonal matrix and R: the upper triangular matrix
775
842
  */
776
- qr(A: Matrix | MathArray): { Q: MathCollection; R: MathCollection }
843
+ qr(A: Matrix | MathArray): QRDecomposition
777
844
 
778
845
  rationalize(
779
846
  expr: MathNode | string,
@@ -844,7 +911,7 @@ declare namespace math {
844
911
  * @returns The lower triangular matrix, the upper triangular matrix and
845
912
  * the permutation vectors.
846
913
  */
847
- slu(A: Matrix, order: number, threshold: number): object
914
+ slu(A: Matrix, order: number, threshold: number): SLUDecomposition
848
915
 
849
916
  /**
850
917
  * Solves the linear equation system by backward substitution. Matrix
@@ -853,7 +920,8 @@ declare namespace math {
853
920
  * @param b A column vector with the b values
854
921
  * @returns A column vector with the linear system solution (x)
855
922
  */
856
- usolve(U: Matrix | MathArray, b: Matrix | MathArray): Matrix | MathArray
923
+ usolve(U: Matrix, b: Matrix | MathArray): Matrix
924
+ usolve(U: MathArray, b: Matrix | MathArray): MathArray
857
925
 
858
926
  /*************************************************************************
859
927
  * Arithmetic functions
@@ -894,11 +962,9 @@ declare namespace math {
894
962
  */
895
963
  cbrt(x: number, allRoots?: boolean): number
896
964
  cbrt(x: BigNumber, allRoots?: boolean): BigNumber
897
- cbrt(x: Fraction, allRoots?: boolean): Fraction
898
965
  cbrt(x: Complex, allRoots?: boolean): Complex
899
966
  cbrt(x: MathArray, allRoots?: boolean): MathArray
900
967
  cbrt(x: Matrix, allRoots?: boolean): Matrix
901
- cbrt(x: Unit, allRoots?: boolean): Unit
902
968
 
903
969
  // Rounding functions, grouped for similarity, even though it breaks
904
970
  // the alphabetic order among arithmetic functions.
@@ -1456,9 +1522,9 @@ declare namespace math {
1456
1522
  * @param x A complex number or array with complex numbers
1457
1523
  * @returns The imaginary part of x
1458
1524
  */
1459
- im(
1460
- x: number | BigNumber | Complex | MathCollection
1461
- ): number | BigNumber | MathCollection
1525
+ im(x: MathJsChain<number | Complex>): MathJsChain<number>
1526
+ im(x: MathJsChain<BigNumber>): MathJsChain<BigNumber>
1527
+ im(x: MathJsChain<MathCollection>): MathJsChain<MathCollection>
1462
1528
 
1463
1529
  /**
1464
1530
  * Get the real part of a complex number. For a complex number a + bi,
@@ -1467,9 +1533,9 @@ declare namespace math {
1467
1533
  * @param x A complex number or array of complex numbers
1468
1534
  * @returns The real part of x
1469
1535
  */
1470
- re(
1471
- x: number | BigNumber | Complex | MathCollection
1472
- ): number | BigNumber | MathCollection
1536
+ re(x: MathJsChain<number | Complex>): MathJsChain<number>
1537
+ re(x: MathJsChain<BigNumber>): MathJsChain<BigNumber>
1538
+ re(x: MathJsChain<MathCollection>): MathJsChain<MathCollection>
1473
1539
 
1474
1540
  /*************************************************************************
1475
1541
  * Geometry functions
@@ -1973,6 +2039,20 @@ declare namespace math {
1973
2039
  */
1974
2040
  zeros(m: number, n: number, format?: string): MathCollection
1975
2041
 
2042
+ /**
2043
+ * Calculate N-dimensional fourier transform
2044
+ * @param {Array | Matrix} arr An array or matrix
2045
+ * @return {Array | Matrix} N-dimensional fourier transformation of the array
2046
+ */
2047
+ fft<T extends MathCollection>(arr: T): T
2048
+
2049
+ /**
2050
+ * Calculate N-dimensional inverse fourier transform
2051
+ * @param {Array | Matrix} arr An array or matrix
2052
+ * @return {Array | Matrix} N-dimensional fourier transformation of the array
2053
+ */
2054
+ ifft<T extends MathCollection>(arr: T): T
2055
+
1976
2056
  /*************************************************************************
1977
2057
  * Probability functions
1978
2058
  ************************************************************************/
@@ -2596,6 +2676,7 @@ declare namespace math {
2596
2676
  * @returns The variance
2597
2677
  */
2598
2678
  variance(...args: Array<number | BigNumber | Fraction>): number
2679
+
2599
2680
  /**
2600
2681
  * Compute the variance of a matrix or a list with values. In case of a
2601
2682
  * (multi dimensional) array or matrix, the variance over all elements
@@ -3056,7 +3137,9 @@ declare namespace math {
3056
3137
 
3057
3138
  isObjectNode(x: unknown): x is ObjectNode
3058
3139
 
3059
- isOperatorNode(x: unknown): x is OperatorNode
3140
+ isOperatorNode(
3141
+ x: unknown
3142
+ ): x is OperatorNode<OperatorNodeOp, OperatorNodeFn>
3060
3143
 
3061
3144
  isParenthesisNode(x: unknown): x is ParenthesisNode
3062
3145
 
@@ -3064,7 +3147,7 @@ declare namespace math {
3064
3147
 
3065
3148
  isSymbolNode(x: unknown): x is SymbolNode
3066
3149
 
3067
- isChain(x: unknown): x is MathJsChain
3150
+ isChain(x: unknown): x is MathJsChain<unknown>
3068
3151
 
3069
3152
  /*************************************************************************
3070
3153
  * Functions -> Utils
@@ -3076,7 +3159,7 @@ declare namespace math {
3076
3159
  * @returns A clone of object x
3077
3160
  */
3078
3161
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3079
- clone(x: any): any
3162
+ clone<TType>(x: TType): TType
3080
3163
 
3081
3164
  /**
3082
3165
  * Test whether a value is an numeric value. In case of a string,
@@ -3746,12 +3829,12 @@ declare namespace math {
3746
3829
  * Create a shallow clone of the node. The node itself is cloned, its
3747
3830
  * childs are not cloned.
3748
3831
  */
3749
- clone(): MathNode
3832
+ clone(): this
3750
3833
  /**
3751
3834
  * Create a deep clone of the node. Both the node as well as all its
3752
3835
  * childs are cloned recursively.
3753
3836
  */
3754
- cloneDeep(): MathNode
3837
+ cloneDeep(): this
3755
3838
  /**
3756
3839
  * Compile an expression into optimized JavaScript code. compile returns
3757
3840
  * an object with a function evaluate([scope]) to evaluate. Example:
@@ -3977,9 +4060,9 @@ declare namespace math {
3977
4060
  randomSeed?: string | null
3978
4061
  }
3979
4062
 
3980
- interface MathJsChain {
4063
+ interface MathJsChain<TValue> {
3981
4064
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3982
- done(): any
4065
+ done(): TValue
3983
4066
 
3984
4067
  /*************************************************************************
3985
4068
  * Construction functions
@@ -3990,7 +4073,12 @@ declare namespace math {
3990
4073
  * When a matrix is provided, all elements will be converted to
3991
4074
  * BigNumber.
3992
4075
  */
3993
- bignumber(): MathJsChain
4076
+ bignumber(
4077
+ this: MathJsChain<
4078
+ number | string | Fraction | BigNumber | boolean | Fraction | null
4079
+ >
4080
+ ): MathJsChain<BigNumber>
4081
+ bignumber<T extends MathCollection>(this: MathJsChain<T>): MathJsChain<T>
3994
4082
 
3995
4083
  /**
3996
4084
  * Create a boolean or convert a string or number to a boolean. In case
@@ -3998,14 +4086,21 @@ declare namespace math {
3998
4086
  * of zero. Strings can be 'true' or 'false', or can contain a number.
3999
4087
  * When value is a matrix, all elements will be converted to boolean.
4000
4088
  */
4001
- boolean(): MathJsChain
4089
+ boolean(
4090
+ this: MathJsChain<string | number | boolean | null>
4091
+ ): MathJsChain<boolean>
4092
+ boolean(this: MathJsChain<MathCollection>): MathJsChain<MathCollection>
4002
4093
 
4003
4094
  /**
4004
4095
  * Create a complex value or convert a value to a complex value.
4005
4096
  * @param im Argument specifying the imaginary part of the complex
4006
4097
  * number
4007
4098
  */
4008
- complex(im?: number): MathJsChain
4099
+ complex(
4100
+ this: MathJsChain<Complex | string | PolarCoordinates>,
4101
+ im?: number
4102
+ ): MathJsChain<Complex>
4103
+ complex(this: MathJsChain<MathCollection>): MathJsChain<MathCollection>
4009
4104
 
4010
4105
  /**
4011
4106
  * Create a user-defined unit and register it with the Unit type.
@@ -4020,9 +4115,10 @@ declare namespace math {
4020
4115
  * 0.
4021
4116
  */
4022
4117
  createUnit(
4118
+ this: MathJsChain<string>,
4023
4119
  definition?: string | UnitDefinition,
4024
4120
  options?: CreateUnitOptions
4025
- ): MathJsChain
4121
+ ): MathJsChain<Unit>
4026
4122
  /**
4027
4123
  * Create a user-defined unit and register it with the Unit type.
4028
4124
  * @param options (optional) An object containing any of the following
@@ -4033,21 +4129,31 @@ declare namespace math {
4033
4129
  * the unit. For example, the offset for celsius is 273.15. Default is
4034
4130
  * 0.
4035
4131
  */
4036
- createUnit(options?: CreateUnitOptions): MathJsChain
4132
+ createUnit(
4133
+ this: MathJsChain<Record<string, string | UnitDefinition>>,
4134
+ options?: CreateUnitOptions
4135
+ ): MathJsChain<Unit>
4037
4136
 
4038
4137
  /**
4039
4138
  * Create a fraction convert a value to a fraction.
4040
4139
  * @param denominator Argument specifying the denominator of the
4041
4140
  * fraction
4042
4141
  */
4043
- fraction(denominator?: number | string | MathCollection): MathJsChain
4142
+ fraction(
4143
+ this: MathJsChain<
4144
+ number | string | BigNumber | Fraction | FractionDefinition
4145
+ >,
4146
+ denominator?: number
4147
+ ): MathJsChain<Fraction>
4148
+ fraction(this: MathJsChain<MathCollection>): MathJsChain<MathCollection>
4044
4149
 
4045
4150
  /**
4046
4151
  * Create an index. An Index can store ranges having start, step, and
4047
4152
  * end for multiple dimensions. Matrix.get, Matrix.set, and math.subset
4048
4153
  * accept an Index as input.
4049
4154
  */
4050
- index(): MathJsChain
4155
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4156
+ index(this: MathJsChain<any[]>): MathJsChain<Index>
4051
4157
 
4052
4158
  /**
4053
4159
  * Create a Matrix. The function creates a new math.type.Matrix object
@@ -4055,7 +4161,11 @@ declare namespace math {
4055
4161
  * in the matrix, like getting the size and getting or setting values in
4056
4162
  * the matrix. Supported storage formats are 'dense' and 'sparse'.
4057
4163
  */
4058
- matrix(format?: 'sparse' | 'dense', dataType?: string): MathJsChain
4164
+ matrix(
4165
+ this: MathJsChain<MathCollection>,
4166
+ format?: 'sparse' | 'dense',
4167
+ dataType?: string
4168
+ ): MathJsChain<Matrix>
4059
4169
 
4060
4170
  /**
4061
4171
  * Create a number or convert a string, boolean, or unit to a number.
@@ -4063,7 +4173,16 @@ declare namespace math {
4063
4173
  * @param valuelessUnit A valueless unit, used to convert a unit to a
4064
4174
  * number
4065
4175
  */
4066
- number(valuelessUnit?: Unit | string): MathJsChain
4176
+ number(
4177
+ this: MathJsChain<
4178
+ string | number | BigNumber | Fraction | boolean | Unit | null
4179
+ >,
4180
+ valuelessUnit?: Unit | string
4181
+ ): MathJsChain<number>
4182
+ number(
4183
+ this: MathJsChain<MathCollection>,
4184
+ valuelessUnit?: Unit | string
4185
+ ): MathJsChain<MathCollection>
4067
4186
 
4068
4187
  /**
4069
4188
  * Create a Sparse Matrix. The function creates a new math.type.Matrix
@@ -4072,20 +4191,26 @@ declare namespace math {
4072
4191
  * values in the matrix.
4073
4192
  * @param dataType Sparse Matrix data type
4074
4193
  */
4075
- sparse(dataType?: string): MathJsChain
4194
+ sparse(
4195
+ this: MathJsChain<MathCollection>,
4196
+ dataType?: string
4197
+ ): MathJsChain<Matrix>
4076
4198
 
4077
4199
  /**
4078
4200
  * Split a unit in an array of units whose sum is equal to the original
4079
4201
  * unit.
4080
4202
  * @param parts An array of strings or valueless units
4081
4203
  */
4082
- splitUnit(parts: Unit[]): MathJsChain
4204
+ splitUnit(this: MathJsChain<Unit>, parts: Unit[]): MathJsChain<Unit[]>
4083
4205
 
4084
4206
  /**
4085
4207
  * Create a string or convert any object into a string. Elements of
4086
4208
  * Arrays and Matrices are processed element wise.
4087
4209
  */
4088
- string(): MathJsChain
4210
+ string(
4211
+ this: MathJsChain<MathNumericType | string | Unit | null>
4212
+ ): MathJsChain<string>
4213
+ string(this: MathJsChain<MathCollection>): MathJsChain<MathCollection>
4089
4214
 
4090
4215
  /**
4091
4216
  * Create a unit. Depending on the passed arguments, the function will
@@ -4093,7 +4218,13 @@ declare namespace math {
4093
4218
  * provided, all elements will be converted to units.
4094
4219
  * @param unit The unit to be created
4095
4220
  */
4096
- unit(unit?: string): MathJsChain
4221
+ unit(this: MathJsChain<string>, unit?: string): MathJsChain<Unit>
4222
+ unit(this: MathJsChain<Unit>, unit?: string): MathJsChain<Unit>
4223
+ unit(
4224
+ this: MathJsChain<number | BigNumber>,
4225
+ unit?: string
4226
+ ): MathJsChain<Unit>
4227
+ unit(this: MathJsChain<MathCollection>, unit?: string): MathJsChain<Unit[]>
4097
4228
 
4098
4229
  /*************************************************************************
4099
4230
  * Expression functions
@@ -4103,45 +4234,64 @@ declare namespace math {
4103
4234
  * Parse and compile an expression. Returns a an object with a function
4104
4235
  * evaluate([scope]) to evaluate the compiled expression.
4105
4236
  */
4106
- compile(): MathJsChain
4237
+ compile(this: MathJsChain<MathExpression>): MathJsChain<EvalFunction>
4107
4238
 
4239
+ // TODO properly type this
4108
4240
  /**
4109
4241
  * Evaluate an expression.
4110
4242
  * @param scope Scope to read/write variables
4111
4243
  */
4112
- evaluate(scope?: object): MathJsChain
4244
+ evaluate(
4245
+ this: MathJsChain<MathExpression | Matrix>,
4246
+ scope?: object
4247
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4248
+ ): MathJsChain<any>
4249
+ evaluate(
4250
+ this: MathJsChain<MathExpression[]>,
4251
+ scope?: object
4252
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4253
+ ): MathJsChain<any[]>
4113
4254
 
4114
4255
  /**
4115
4256
  * Retrieve help on a function or data type. Help files are retrieved
4116
4257
  * from the documentation in math.expression.docs.
4117
4258
  */
4118
- help(): MathJsChain
4259
+ help(this: MathJsChain<unknown>): MathJsChain<unknown>
4119
4260
 
4120
- /**
4121
- * Parse an expression. Returns a node tree, which can be evaluated by
4122
- * invoking node.evaluate();
4123
- * @param options Available options: nodes - a set of custome nodes
4124
- */
4125
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4126
- parse(options?: any): MathJsChain
4127
4261
  /**
4128
4262
  * @param options Available options: nodes - a set of custome nodes
4129
4263
  */
4130
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4131
- parse(options?: any): MathJsChain
4264
+ parse(
4265
+ this: MathJsChain<MathExpression[]>,
4266
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4267
+ options?: any
4268
+ ): MathJsChain<MathNode[]>
4132
4269
 
4133
4270
  /**
4134
- * Create a parser. The function creates a new math.expression.Parser
4135
- * object.
4271
+ * Parse an expression. Returns a node tree, which can be evaluated by
4272
+ * invoking node.evaluate();
4273
+ * @param options Available options: nodes - a set of custome nodes
4136
4274
  */
4137
- parser(): MathJsChain
4275
+ parse(
4276
+ this: MathJsChain<MathExpression>,
4277
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4278
+ options?: any
4279
+ ): MathJsChain<MathNode>
4138
4280
 
4139
4281
  /**
4140
4282
  * Replaces variable nodes with their scoped values
4141
4283
  * @param scope Scope to read/write variables
4142
4284
  */
4143
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4144
- resolve(scope?: Record<string, any>): MathJsChain
4285
+ resolve(
4286
+ this: MathJsChain<MathNode>,
4287
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4288
+ scope?: Record<string, any>
4289
+ ): MathJsChain<MathNode>
4290
+ resolve(
4291
+ this: MathJsChain<MathNode[]>,
4292
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4293
+ scope?: Record<string, any>
4294
+ ): MathJsChain<MathNode[]>
4145
4295
 
4146
4296
  /*************************************************************************
4147
4297
  * Algebra functions
@@ -4152,23 +4302,31 @@ declare namespace math {
4152
4302
  * by default. When false, output will not be simplified.
4153
4303
  */
4154
4304
  derivative(
4305
+ this: MathJsChain<MathNode | string>,
4155
4306
  variable: MathNode | string,
4156
4307
  options?: { simplify: boolean }
4157
- ): MathJsChain
4308
+ ): MathJsChain<MathNode>
4158
4309
 
4159
4310
  /**
4160
4311
  * Solves the linear equation system by forwards substitution. Matrix
4161
4312
  * must be a lower triangular matrix.
4162
4313
  * @param b A column vector with the b values
4163
4314
  */
4164
- lsolve(b: Matrix | MathArray): MathJsChain
4315
+ lsolve(
4316
+ this: MathJsChain<Matrix>,
4317
+ b: Matrix | MathArray
4318
+ ): MathJsChain<Matrix>
4319
+ lsolve(
4320
+ this: MathJsChain<MathArray>,
4321
+ b: Matrix | MathArray
4322
+ ): MathJsChain<MathArray>
4165
4323
 
4166
4324
  /**
4167
4325
  * Calculate the Matrix LU decomposition with partial pivoting. Matrix A
4168
4326
  * is decomposed in two matrices (L, U) and a row permutation vector p
4169
4327
  * where A[p,:] = L * U
4170
4328
  */
4171
- lup(): MathJsChain
4329
+ lup(this: MathJsChain<Matrix | MathArray>): MathJsChain<LUDecomposition>
4172
4330
 
4173
4331
  /**
4174
4332
  * Solves the linear system A * x = b where A is an [n x n] matrix and b
@@ -4180,17 +4338,25 @@ declare namespace math {
4180
4338
  * see slu for details. Matrix must be a SparseMatrix.
4181
4339
  */
4182
4340
  lusolve(
4341
+ this: MathJsChain<Matrix>,
4342
+ b: Matrix | MathArray,
4343
+ order?: number,
4344
+ threshold?: number
4345
+ ): MathJsChain<Matrix>
4346
+
4347
+ lusolve(
4348
+ this: MathJsChain<MathArray>,
4183
4349
  b: Matrix | MathArray,
4184
4350
  order?: number,
4185
4351
  threshold?: number
4186
- ): MathJsChain
4352
+ ): MathJsChain<MathArray>
4187
4353
 
4188
4354
  /**
4189
4355
  * Calculate the Matrix QR decomposition. Matrix A is decomposed in two
4190
4356
  * matrices (Q, R) where Q is an orthogonal matrix and R is an upper
4191
4357
  * triangular matrix.
4192
4358
  */
4193
- qr(): MathJsChain
4359
+ qr(this: MathJsChain<Matrix | MathArray>): MathJsChain<QRDecomposition>
4194
4360
 
4195
4361
  /**
4196
4362
  * Transform a rationalizable expression in a rational fraction. If
@@ -4202,7 +4368,11 @@ declare namespace math {
4202
4368
  * @param detailed optional True if return an object, false if return
4203
4369
  * expression node (default)
4204
4370
  */
4205
- rationalize(optional?: object | boolean, detailed?: boolean): MathJsChain
4371
+ rationalize(
4372
+ this: MathJsChain<MathNode | string>,
4373
+ optional?: object | boolean,
4374
+ detailed?: boolean
4375
+ ): MathJsChain<MathNode>
4206
4376
 
4207
4377
  /**
4208
4378
  * Simplify an expression tree.
@@ -4212,8 +4382,13 @@ declare namespace math {
4212
4382
  * can be specified as an object, string, or function.
4213
4383
  * @param scope Scope to variables
4214
4384
  */
4215
- simplify(rules?: SimplifyRule[], scope?: object): MathJsChain
4385
+ simplify(
4386
+ this: MathJsChain<MathNode | string>,
4387
+ rules?: SimplifyRule[],
4388
+ scope?: object
4389
+ ): MathJsChain<MathNode>
4216
4390
 
4391
+ // TODO check that this should even be here...
4217
4392
  simplifyCore(expr: MathNode): MathNode
4218
4393
 
4219
4394
  /**
@@ -4231,14 +4406,25 @@ declare namespace math {
4231
4406
  * with more than 10*sqr(columns) entries.
4232
4407
  * @param threshold Partial pivoting threshold (1 for partial pivoting)
4233
4408
  */
4234
- slu(order: number, threshold: number): MathJsChain
4409
+ slu(
4410
+ this: MathJsChain<Matrix>,
4411
+ order: number,
4412
+ threshold: number
4413
+ ): MathJsChain<SLUDecomposition>
4235
4414
 
4236
4415
  /**
4237
4416
  * Solves the linear equation system by backward substitution. Matrix
4238
4417
  * must be an upper triangular matrix. U * x = b
4239
4418
  * @param b A column vector with the b values
4240
4419
  */
4241
- usolve(b: Matrix | MathArray): MathJsChain
4420
+ usolve(
4421
+ this: MathJsChain<Matrix>,
4422
+ b: Matrix | MathArray
4423
+ ): MathJsChain<Matrix>
4424
+ usolve(
4425
+ this: MathJsChain<MathArray>,
4426
+ b: Matrix | MathArray
4427
+ ): MathJsChain<MathArray>
4242
4428
 
4243
4429
  /*************************************************************************
4244
4430
  * Arithmetic functions
@@ -4248,14 +4434,21 @@ declare namespace math {
4248
4434
  * Calculate the absolute value of a number. For matrices, the function
4249
4435
  * is evaluated element wise.
4250
4436
  */
4251
- abs(): MathJsChain
4437
+ abs(this: MathJsChain<number>): MathJsChain<number>
4438
+ abs(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4439
+ abs(this: MathJsChain<Fraction>): MathJsChain<Fraction>
4440
+ abs(this: MathJsChain<Complex>): MathJsChain<Complex>
4441
+ abs(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4442
+ abs(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4443
+ abs(this: MathJsChain<Unit>): MathJsChain<Unit>
4252
4444
 
4253
4445
  /**
4254
4446
  * Add two values, x + y. For matrices, the function is evaluated
4255
4447
  * element wise.
4256
4448
  * @param y Second value to add
4257
4449
  */
4258
- add(y: MathType): MathJsChain
4450
+ add<T extends MathType>(this: MathJsChain<T>, y: T): MathJsChain<T>
4451
+ add(this: MathJsChain<MathType>, y: MathType): MathJsChain<MathType>
4259
4452
 
4260
4453
  /**
4261
4454
  * Apply a function that maps an array to a scalar along a given axis of the
@@ -4266,10 +4459,11 @@ declare namespace math {
4266
4459
  * array or 1-d matrix as an input and return a number.
4267
4460
  * @returns The residual matrix with the function applied over some dimension.
4268
4461
  */
4269
- apply(
4462
+ apply<T extends MathCollection>(
4463
+ this: MathJsChain<T>,
4270
4464
  dim: number,
4271
4465
  callback: (array: Array<MathType> | Matrix) => number
4272
- ): MathJsChain
4466
+ ): MathJsChain<T>
4273
4467
 
4274
4468
  /**
4275
4469
  * Calculate the cubic root of a value. For matrices, the function is
@@ -4278,7 +4472,17 @@ declare namespace math {
4278
4472
  * a number or complex number. If true, all complex roots are returned,
4279
4473
  * if false (default) the principal root is returned.
4280
4474
  */
4281
- cbrt(allRoots?: boolean): MathJsChain
4475
+ cbrt(this: MathJsChain<number>, allRoots?: boolean): MathJsChain<number>
4476
+ cbrt(
4477
+ this: MathJsChain<BigNumber>,
4478
+ allRoots?: boolean
4479
+ ): MathJsChain<BigNumber>
4480
+ cbrt(this: MathJsChain<Complex>, allRoots?: boolean): MathJsChain<Complex>
4481
+ cbrt(
4482
+ this: MathJsChain<MathArray>,
4483
+ allRoots?: boolean
4484
+ ): MathJsChain<MathArray>
4485
+ cbrt(this: MathJsChain<Matrix>, allRoots?: boolean): MathJsChain<Matrix>
4282
4486
 
4283
4487
  // Rounding functions grouped for similarity
4284
4488
 
@@ -4288,28 +4492,56 @@ declare namespace math {
4288
4492
  * function is evaluated element wise.
4289
4493
  * @param n Number of decimals Default value: 0.
4290
4494
  */
4291
- ceil(n?: number | BigNumber | MathCollection): MathJsChain
4495
+ ceil(
4496
+ this: MathJsChain<MathNumericType>,
4497
+ n?: number | BigNumber | MathCollection
4498
+ ): MathJsChain<MathNumericType>
4499
+ ceil(
4500
+ this: MathJsChain<MathCollection>,
4501
+ n?: number | BigNumber | MathCollection
4502
+ ): MathJsChain<MathCollection>
4292
4503
 
4293
4504
  /**
4294
4505
  * Round a value towards zero. For matrices, the function is evaluated
4295
4506
  * element wise.
4296
4507
  * @param n Number of decimals Default value: 0.
4297
4508
  */
4298
- fix(n?: number | BigNumber | MathCollection): MathJsChain
4509
+ fix(
4510
+ this: MathJsChain<MathNumericType>,
4511
+ n?: number | BigNumber | MathCollection
4512
+ ): MathJsChain<MathNumericType>
4513
+ fix(
4514
+ this: MathJsChain<MathCollection>,
4515
+ n?: number | BigNumber | MathCollection
4516
+ ): MathJsChain<MathCollection>
4299
4517
 
4300
4518
  /**
4301
4519
  * Round a value towards minus infinity. For matrices, the function is
4302
4520
  * evaluated element wise.
4303
4521
  * @param n Number of decimals Default value: 0.
4304
4522
  */
4305
- floor(n?: number | BigNumber | MathCollection): MathJsChain
4523
+ floor(
4524
+ this: MathJsChain<MathNumericType>,
4525
+ n?: number | BigNumber | MathCollection
4526
+ ): MathJsChain<MathNumericType>
4527
+ floor(
4528
+ this: MathJsChain<MathCollection>,
4529
+ n?: number | BigNumber | MathCollection
4530
+ ): MathJsChain<MathCollection>
4306
4531
 
4307
4532
  /**
4308
4533
  * Round a value towards the nearest integer. For matrices, the function
4309
4534
  * is evaluated element wise.
4310
4535
  * @param n Number of decimals Default value: 0.
4311
4536
  */
4312
- round(n?: number | BigNumber | MathCollection): MathJsChain
4537
+ round(
4538
+ this: MathJsChain<MathNumericType>,
4539
+ n?: number | BigNumber | MathCollection
4540
+ ): MathJsChain<MathNumericType>
4541
+ round(
4542
+ this: MathJsChain<MathCollection>,
4543
+ n?: number | BigNumber | MathCollection
4544
+ ): MathJsChain<MathCollection>
4313
4545
 
4314
4546
  // End of rounding group
4315
4547
 
@@ -4317,52 +4549,79 @@ declare namespace math {
4317
4549
  * Compute the cube of a value, x * x * x. For matrices, the function is
4318
4550
  * evaluated element wise.
4319
4551
  */
4320
- cube(): MathJsChain
4552
+ cube(this: MathJsChain<number>): MathJsChain<number>
4553
+ cube(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4554
+ cube(this: MathJsChain<Fraction>): MathJsChain<Fraction>
4555
+ cube(this: MathJsChain<Complex>): MathJsChain<Complex>
4556
+ cube(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4557
+ cube(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4558
+ cube(this: MathJsChain<Unit>): MathJsChain<Unit>
4321
4559
 
4322
4560
  /**
4323
4561
  * Divide two values, x / y. To divide matrices, x is multiplied with
4324
4562
  * the inverse of y: x * inv(y).
4325
4563
  * @param y Denominator
4326
4564
  */
4327
- divide(y: MathType): MathJsChain
4565
+ divide(this: MathJsChain<Unit>, y: Unit): MathJsChain<Unit | number>
4566
+ divide(this: MathJsChain<Unit>, y: number): MathJsChain<Unit>
4567
+ divide(this: MathJsChain<number>, y: number): MathJsChain<number>
4568
+ divide(this: MathJsChain<MathType>, y: MathType): MathJsChain<MathType>
4328
4569
 
4329
4570
  /**
4330
4571
  * Divide two matrices element wise. The function accepts both matrices
4331
4572
  * and scalar values.
4332
4573
  * @param y Denominator
4333
4574
  */
4334
- dotDivide(y: MathType): MathJsChain
4575
+ dotDivide(this: MathJsChain<MathType>, y: MathType): MathJsChain<MathType>
4335
4576
 
4336
4577
  /**
4337
4578
  * Multiply two matrices element wise. The function accepts both
4338
4579
  * matrices and scalar values.
4339
4580
  * @param y Right hand value
4340
4581
  */
4341
- dotMultiply(y: MathType): MathJsChain
4582
+ dotMultiply(this: MathJsChain<MathType>, y: MathType): MathJsChain<MathType>
4342
4583
 
4343
4584
  /**
4344
4585
  * Calculates the power of x to y element wise.
4345
4586
  * @param y The exponent
4346
4587
  */
4347
- dotPow(y: MathType): MathJsChain
4588
+ dotPow(this: MathJsChain<MathType>, y: MathType): MathJsChain<MathType>
4348
4589
 
4349
4590
  /**
4350
4591
  * Calculate the exponent of a value. For matrices, the function is
4351
4592
  * evaluated element wise.
4352
4593
  */
4353
- exp(): MathJsChain
4594
+ exp(this: MathJsChain<number>): MathJsChain<number>
4595
+ exp(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4596
+ exp(this: MathJsChain<Complex>): MathJsChain<Complex>
4597
+ exp(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4598
+ exp(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4354
4599
 
4355
4600
  /**
4356
4601
  * Calculate the value of subtracting 1 from the exponential value. For
4357
4602
  * matrices, the function is evaluated element wise.
4358
4603
  */
4359
- expm1(): MathJsChain
4604
+ expm1(this: MathJsChain<number>): MathJsChain<number>
4605
+ expm1(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4606
+ expm1(this: MathJsChain<Complex>): MathJsChain<Complex>
4607
+ expm1(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4608
+ expm1(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4360
4609
 
4361
4610
  /**
4362
4611
  * Calculate the greatest common divisor for two or more values or
4363
4612
  * arrays. For matrices, the function is evaluated element wise.
4364
4613
  */
4365
- gcd(): MathJsChain
4614
+ gcd(this: MathJsChain<number[]>, ...args: number[]): MathJsChain<number>
4615
+ gcd(
4616
+ this: MathJsChain<BigNumber[]>,
4617
+ ...args: BigNumber[]
4618
+ ): MathJsChain<BigNumber>
4619
+ gcd(this: MathJsChain<Complex[]>, ...args: Fraction[]): MathJsChain<Complex>
4620
+ gcd(
4621
+ this: MathJsChain<MathArray[]>,
4622
+ ...args: MathArray[]
4623
+ ): MathJsChain<MathArray>
4624
+ gcd(this: MathJsChain<Matrix[]>, ...args: Matrix[]): MathJsChain<Matrix>
4366
4625
 
4367
4626
  /**
4368
4627
  * Calculate the hypotenusa of a list with values. The hypotenusa is
@@ -4370,7 +4629,8 @@ declare namespace math {
4370
4629
  * matrix input, the hypotenusa is calculated for all values in the
4371
4630
  * matrix.
4372
4631
  */
4373
- hypot(): MathJsChain
4632
+ hypot(this: MathJsChain<number[]>): MathJsChain<number>
4633
+ hypot(this: MathJsChain<BigNumber[]>): MathJsChain<BigNumber>
4374
4634
 
4375
4635
  /**
4376
4636
  * Calculate the least common multiple for two or more values or arrays.
@@ -4378,7 +4638,10 @@ declare namespace math {
4378
4638
  * the function is evaluated element wise.
4379
4639
  * @param b An integer number
4380
4640
  */
4381
- lcm(b: number | BigNumber | MathCollection): MathJsChain
4641
+ lcm(this: MathJsChain<number>, b: number): MathJsChain<number>
4642
+ lcm(this: MathJsChain<BigNumber>, b: BigNumber): MathJsChain<BigNumber>
4643
+ lcm(this: MathJsChain<MathArray>, b: MathArray): MathJsChain<MathArray>
4644
+ lcm(this: MathJsChain<Matrix>, b: Matrix): MathJsChain<Matrix>
4382
4645
 
4383
4646
  /**
4384
4647
  * Calculate the logarithm of a value. For matrices, the function is
@@ -4386,24 +4649,58 @@ declare namespace math {
4386
4649
  * @param base Optional base for the logarithm. If not provided, the
4387
4650
  * natural logarithm of x is calculated. Default value: e.
4388
4651
  */
4389
- log(base?: number | BigNumber | Complex): MathJsChain
4652
+ log<T extends number | BigNumber | Complex | MathCollection>(
4653
+ this: MathJsChain<T>,
4654
+ base?: number | BigNumber | Complex
4655
+ ): MathJsChain<NoLiteralType<T>>
4390
4656
 
4391
4657
  /**
4392
4658
  * Calculate the 10-base of a value. This is the same as calculating
4393
4659
  * log(x, 10). For matrices, the function is evaluated element wise.
4394
4660
  */
4395
- log10(): MathJsChain
4661
+
4662
+ log10(this: MathJsChain<number>): MathJsChain<number>
4663
+ log10(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4664
+ log10(this: MathJsChain<Complex>): MathJsChain<Complex>
4665
+ log10(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4666
+ log10(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4396
4667
 
4397
4668
  /**
4398
4669
  * Calculate the logarithm of a value+1. For matrices, the function is
4399
4670
  * evaluated element wise.
4400
4671
  */
4401
- log1p(base?: number | BigNumber | Complex): MathJsChain
4672
+ log1p(
4673
+ this: MathJsChain<number>,
4674
+ base?: number | BigNumber | Complex
4675
+ ): MathJsChain<number>
4676
+ log1p(
4677
+ this: MathJsChain<BigNumber>,
4678
+ base?: number | BigNumber | Complex
4679
+ ): MathJsChain<BigNumber>
4680
+ log1p(
4681
+ this: MathJsChain<Complex>,
4682
+ base?: number | BigNumber | Complex
4683
+ ): MathJsChain<Complex>
4684
+ log1p(
4685
+ this: MathJsChain<MathArray>,
4686
+ base?: number | BigNumber | Complex
4687
+ ): MathJsChain<MathArray>
4688
+ log1p(
4689
+ this: MathJsChain<Matrix>,
4690
+ base?: number | BigNumber | Complex
4691
+ ): MathJsChain<Matrix>
4692
+
4402
4693
  /**
4403
4694
  * Calculate the 2-base of a value. This is the same as calculating
4404
4695
  * log(x, 2). For matrices, the function is evaluated element wise.
4405
4696
  */
4406
- log2(): MathJsChain
4697
+
4698
+ log2(this: MathJsChain<number>): MathJsChain<number>
4699
+ log2(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4700
+ log2(this: MathJsChain<Complex>): MathJsChain<Complex>
4701
+ log2(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4702
+ log2(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4703
+
4407
4704
  /**
4408
4705
  * Calculates the modulus, the remainder of an integer division. For
4409
4706
  * matrices, the function is evaluated element wise. The modulus is
@@ -4411,14 +4708,23 @@ declare namespace math {
4411
4708
  * @see http://en.wikipedia.org/wiki/Modulo_operation.
4412
4709
  * @param y Divisor
4413
4710
  */
4414
- mod(y: number | BigNumber | Fraction | MathCollection): MathJsChain
4711
+ mod<T extends number | BigNumber | Fraction | MathCollection>(
4712
+ this: MathJsChain<T>,
4713
+ y: number | BigNumber | Fraction | MathCollection
4714
+ ): MathJsChain<NoLiteralType<T>>
4415
4715
 
4416
4716
  /**
4417
4717
  * Multiply two values, x * y. The result is squeezed. For matrices, the
4418
4718
  * matrix product is calculated.
4419
4719
  * @param y The second value to multiply
4420
4720
  */
4421
- multiply(y: MathType): MathJsChain
4721
+ multiply<T extends Matrix | MathArray>(
4722
+ this: MathJsChain<T>,
4723
+ y: MathType
4724
+ ): MathJsChain<T>
4725
+ multiply(this: MathJsChain<Unit>, y: Unit): MathJsChain<Unit>
4726
+ multiply(this: MathJsChain<number>, y: number): MathJsChain<number>
4727
+ multiply(this: MathJsChain<MathType>, y: MathType): MathJsChain<MathType>
4422
4728
 
4423
4729
  /**
4424
4730
  * Calculate the norm of a number, vector or matrix. The second
@@ -4427,7 +4733,10 @@ declare namespace math {
4427
4733
  * -Infinity. Supported strings are: 'inf', '-inf', and 'fro' (The
4428
4734
  * Frobenius norm) Default value: 2.
4429
4735
  */
4430
- norm(p?: number | BigNumber | string): MathJsChain
4736
+ norm(
4737
+ this: MathJsChain<number | BigNumber | Complex | MathCollection>,
4738
+ p?: number | BigNumber | string
4739
+ ): MathJsChain<number | BigNumber>
4431
4740
 
4432
4741
  /**
4433
4742
  * Calculate the nth root of a value. The principal nth root of a
@@ -4435,14 +4744,20 @@ declare namespace math {
4435
4744
  * x^root = A For matrices, the function is evaluated element wise.
4436
4745
  * @param root The root. Default value: 2.
4437
4746
  */
4438
- nthRoot(root?: number | BigNumber): MathJsChain
4747
+ nthRoot(
4748
+ this: MathJsChain<number | BigNumber | MathCollection | Complex>,
4749
+ root?: number | BigNumber
4750
+ ): MathJsChain<number | Complex | MathCollection>
4439
4751
 
4440
4752
  /**
4441
4753
  * Calculates the power of x to y, x ^ y. Matrix exponentiation is
4442
4754
  * supported for square matrices x, and positive integer exponents y.
4443
4755
  * @param y The exponent
4444
4756
  */
4445
- pow(y: number | BigNumber): MathJsChain
4757
+ pow(
4758
+ this: MathJsChain<MathType>,
4759
+ y: number | BigNumber | Complex
4760
+ ): MathJsChain<MathType>
4446
4761
 
4447
4762
  /**
4448
4763
  * Compute the sign of a value. The sign of a value x is: 1 when x > 1
@@ -4451,26 +4766,46 @@ declare namespace math {
4451
4766
  * @param x The number for which to determine the sign
4452
4767
  * @returns The sign of x
4453
4768
  */
4454
- sign(x: number | BigNumber): MathJsChain
4769
+ sign(this: MathJsChain<number>): MathJsChain<number>
4770
+ sign(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4771
+ sign(this: MathJsChain<Fraction>): MathJsChain<Fraction>
4772
+ sign(this: MathJsChain<Complex>): MathJsChain<Complex>
4773
+ sign(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4774
+ sign(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4775
+ sign(this: MathJsChain<Unit>): MathJsChain<Unit>
4455
4776
 
4456
4777
  /**
4457
4778
  * Calculate the square root of a value. For matrices, the function is
4458
4779
  * evaluated element wise.
4459
4780
  */
4460
- sqrt(): MathJsChain
4781
+
4782
+ sqrt(this: MathJsChain<number>): MathJsChain<number>
4783
+ sqrt(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4784
+ sqrt(this: MathJsChain<Complex>): MathJsChain<Complex>
4785
+ sqrt(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4786
+ sqrt(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4787
+ sqrt(this: MathJsChain<Unit>): MathJsChain<Unit>
4461
4788
 
4462
4789
  /**
4463
4790
  * Compute the square of a value, x * x. For matrices, the function is
4464
4791
  * evaluated element wise.
4465
4792
  */
4466
- square(): MathJsChain
4793
+
4794
+ square(this: MathJsChain<number>): MathJsChain<number>
4795
+ square(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4796
+ square(this: MathJsChain<Fraction>): MathJsChain<Fraction>
4797
+ square(this: MathJsChain<Complex>): MathJsChain<Complex>
4798
+ square(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4799
+ square(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4800
+ square(this: MathJsChain<Unit>): MathJsChain<Unit>
4467
4801
 
4468
4802
  /**
4469
4803
  * Subtract two values, x - y. For matrices, the function is evaluated
4470
4804
  * element wise.
4471
4805
  * @param y Value to subtract from x
4472
4806
  */
4473
- subtract(y: MathType): MathJsChain
4807
+ subtract<T extends MathType>(this: MathJsChain<T>, y: T): MathJsChain<T>
4808
+ subtract(this: MathJsChain<MathType>, y: MathType): MathJsChain<MathType>
4474
4809
 
4475
4810
  /**
4476
4811
  * Inverse the sign of a value, apply a unary minus operation. For
@@ -4478,21 +4813,39 @@ declare namespace math {
4478
4813
  * strings will be converted to a number. For complex numbers, both real
4479
4814
  * and complex value are inverted.
4480
4815
  */
4481
- unaryMinus(): MathJsChain
4816
+
4817
+ unaryMinus(this: MathJsChain<number>): MathJsChain<number>
4818
+ unaryMinus(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4819
+ unaryMinus(this: MathJsChain<Fraction>): MathJsChain<Fraction>
4820
+ unaryMinus(this: MathJsChain<Complex>): MathJsChain<Complex>
4821
+ unaryMinus(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4822
+ unaryMinus(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4823
+ unaryMinus(this: MathJsChain<Unit>): MathJsChain<Unit>
4482
4824
 
4483
4825
  /**
4484
4826
  * Unary plus operation. Boolean values and strings will be converted to
4485
4827
  * a number, numeric values will be returned as is. For matrices, the
4486
4828
  * function is evaluated element wise.
4487
4829
  */
4488
- unaryPlus(): MathJsChain
4830
+
4831
+ unaryPlus(this: MathJsChain<number>): MathJsChain<number>
4832
+ unaryPlus(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4833
+ unaryPlus(this: MathJsChain<Fraction>): MathJsChain<Fraction>
4834
+ unaryPlus(this: MathJsChain<string>): MathJsChain<string>
4835
+ unaryPlus(this: MathJsChain<Complex>): MathJsChain<Complex>
4836
+ unaryPlus(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4837
+ unaryPlus(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4838
+ unaryPlus(this: MathJsChain<Unit>): MathJsChain<Unit>
4489
4839
 
4490
4840
  /**
4491
4841
  * Calculate the extended greatest common divisor for two values. See
4492
4842
  * http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm.
4493
4843
  * @param b An integer number
4494
4844
  */
4495
- xgcd(b: number | BigNumber): MathJsChain
4845
+ xgcd(
4846
+ this: MathJsChain<number | BigNumber>,
4847
+ b: number | BigNumber
4848
+ ): MathJsChain<MathArray>
4496
4849
 
4497
4850
  /*************************************************************************
4498
4851
  * Bitwise functions
@@ -4503,14 +4856,21 @@ declare namespace math {
4503
4856
  * evaluated element wise.
4504
4857
  * @param y Second value to and
4505
4858
  */
4506
- bitAnd(y: number | BigNumber | MathCollection): MathJsChain
4859
+ bitAnd<T extends number | BigNumber | MathCollection>(
4860
+ this: MathJsChain<T>,
4861
+ y: number | BigNumber | MathCollection
4862
+ ): MathJsChain<NoLiteralType<T>>
4507
4863
 
4508
4864
  /**
4509
4865
  * Bitwise NOT value, ~x. For matrices, the function is evaluated
4510
4866
  * element wise. For units, the function is evaluated on the best prefix
4511
4867
  * base.
4512
4868
  */
4513
- bitNot(): MathJsChain
4869
+
4870
+ bitNot(this: MathJsChain<number>): MathJsChain<number>
4871
+ bitNot(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4872
+ bitNot(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4873
+ bitNot(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4514
4874
 
4515
4875
  /**
4516
4876
  * Bitwise OR two values, x | y. For matrices, the function is evaluated
@@ -4518,14 +4878,20 @@ declare namespace math {
4518
4878
  * print base.
4519
4879
  * @param y Second value to or
4520
4880
  */
4521
- bitOr(y: number | BigNumber | MathCollection): MathJsChain
4881
+ bitOr(this: MathJsChain<number>, y: number): MathJsChain<number>
4882
+ bitOr(this: MathJsChain<BigNumber>, y: BigNumber): MathJsChain<BigNumber>
4883
+ bitOr(this: MathJsChain<MathArray>, y: MathArray): MathJsChain<MathArray>
4884
+ bitOr(this: MathJsChain<Matrix>, y: Matrix): MathJsChain<Matrix>
4522
4885
 
4523
4886
  /**
4524
4887
  * Bitwise XOR two values, x ^ y. For matrices, the function is
4525
4888
  * evaluated element wise.
4526
4889
  * @param y Second value to xor
4527
4890
  */
4528
- bitXor(y: number | BigNumber | MathCollection): MathJsChain
4891
+ bitXor<T extends number | BigNumber | MathCollection>(
4892
+ this: MathJsChain<T>,
4893
+ y: number | BigNumber | MathCollection
4894
+ ): MathJsChain<NoLiteralType<T>>
4529
4895
 
4530
4896
  /**
4531
4897
  * Bitwise left logical shift of a value x by y number of bits, x << y.
@@ -4533,7 +4899,10 @@ declare namespace math {
4533
4899
  * function is evaluated on the best prefix base.
4534
4900
  * @param y Amount of shifts
4535
4901
  */
4536
- leftShift(y: number | BigNumber): MathJsChain
4902
+ leftShift<T extends number | BigNumber | MathCollection>(
4903
+ this: MathJsChain<T>,
4904
+ y: number | BigNumber
4905
+ ): MathJsChain<NoLiteralType<T>>
4537
4906
 
4538
4907
  /**
4539
4908
  * Bitwise right arithmetic shift of a value x by y number of bits, x >>
@@ -4541,7 +4910,10 @@ declare namespace math {
4541
4910
  * the function is evaluated on the best prefix base.
4542
4911
  * @param y Amount of shifts
4543
4912
  */
4544
- rightArithShift(y: number | BigNumber): MathJsChain
4913
+ rightArithShift<T extends number | BigNumber | MathCollection>(
4914
+ this: MathJsChain<T>,
4915
+ y: number | BigNumber
4916
+ ): MathJsChain<NoLiteralType<T>>
4545
4917
 
4546
4918
  /**
4547
4919
  * Bitwise right logical shift of value x by y number of bits, x >>> y.
@@ -4549,7 +4921,10 @@ declare namespace math {
4549
4921
  * function is evaluated on the best prefix base.
4550
4922
  * @param y Amount of shifts
4551
4923
  */
4552
- rightLogShift(y: number): MathJsChain
4924
+ rightLogShift<T extends number | MathCollection>(
4925
+ this: MathJsChain<T>,
4926
+ y: number
4927
+ ): MathJsChain<NoLiteralType<T>>
4553
4928
 
4554
4929
  /*************************************************************************
4555
4930
  * Combinatorics functions
@@ -4561,21 +4936,28 @@ declare namespace math {
4561
4936
  * takes integer arguments. The following condition must be enforced: n
4562
4937
  * >= 0
4563
4938
  */
4564
- bellNumbers(): MathJsChain
4939
+
4940
+ bellNumbers(this: MathJsChain<number>): MathJsChain<number>
4941
+ bellNumbers(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4565
4942
 
4566
4943
  /**
4567
4944
  * The Catalan Numbers enumerate combinatorial structures of many
4568
4945
  * different types. catalan only takes integer arguments. The following
4569
4946
  * condition must be enforced: n >= 0
4570
4947
  */
4571
- catalan(): MathJsChain
4948
+
4949
+ catalan(this: MathJsChain<number>): MathJsChain<number>
4950
+ catalan(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4572
4951
 
4573
4952
  /**
4574
4953
  * The composition counts of n into k parts. Composition only takes
4575
4954
  * integer arguments. The following condition must be enforced: k <= n.
4576
4955
  * @param k Number of objects in the subset
4577
4956
  */
4578
- composition(k: number | BigNumber): MathJsChain
4957
+ composition<T extends number | BigNumber>(
4958
+ this: MathJsChain<T>,
4959
+ k: number | BigNumber
4960
+ ): MathJsChain<NoLiteralType<T>>
4579
4961
 
4580
4962
  /**
4581
4963
  * The Stirling numbers of the second kind, counts the number of ways to
@@ -4585,7 +4967,10 @@ declare namespace math {
4585
4967
  * 1
4586
4968
  * @param k Number of objects in the subset
4587
4969
  */
4588
- stirlingS2(k: number | BigNumber): MathJsChain
4970
+ stirlingS2<T extends number | BigNumber>(
4971
+ this: MathJsChain<T>,
4972
+ k: number | BigNumber
4973
+ ): MathJsChain<NoLiteralType<T>>
4589
4974
 
4590
4975
  /*************************************************************************
4591
4976
  * Complex functions
@@ -4596,28 +4981,38 @@ declare namespace math {
4596
4981
  * the argument is computed as atan2(b, a). For matrices, the function
4597
4982
  * is evaluated element wise.
4598
4983
  */
4599
- arg(): MathJsChain
4984
+
4985
+ arg(this: MathJsChain<number | Complex>): MathJsChain<number>
4986
+ arg(this: MathJsChain<BigNumber | Complex>): MathJsChain<BigNumber>
4987
+ arg(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4988
+ arg(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4600
4989
 
4601
4990
  /**
4602
4991
  * Compute the complex conjugate of a complex value. If x = a+bi, the
4603
4992
  * complex conjugate of x is a - bi. For matrices, the function is
4604
4993
  * evaluated element wise.
4605
4994
  */
4606
- conj(): MathJsChain
4995
+ conj<T extends number | BigNumber | Complex | MathCollection>(
4996
+ this: MathJsChain<T>
4997
+ ): MathJsChain<NoLiteralType<T>>
4607
4998
 
4608
4999
  /**
4609
5000
  * Get the imaginary part of a complex number. For a complex number a +
4610
5001
  * bi, the function returns b. For matrices, the function is evaluated
4611
5002
  * element wise.
4612
5003
  */
4613
- im(): MathJsChain
5004
+ im(this: MathJsChain<number | Complex>): MathJsChain<number>
5005
+ im(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
5006
+ im(this: MathJsChain<MathCollection>): MathJsChain<MathCollection>
4614
5007
 
4615
5008
  /**
4616
5009
  * Get the real part of a complex number. For a complex number a + bi,
4617
5010
  * the function returns a. For matrices, the function is evaluated
4618
5011
  * element wise.
4619
5012
  */
4620
- re(): MathJsChain
5013
+ re(this: MathJsChain<number | Complex>): MathJsChain<number>
5014
+ re(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
5015
+ re(this: MathJsChain<MathCollection>): MathJsChain<MathCollection>
4621
5016
 
4622
5017
  /*************************************************************************
4623
5018
  * Geometry functions
@@ -4633,7 +5028,10 @@ declare namespace math {
4633
5028
  * c)
4634
5029
  * @param y Coordinates of the second point
4635
5030
  */
4636
- distance(y: MathCollection | object): MathJsChain
5031
+ distance(
5032
+ this: MathJsChain<MathCollection | object>,
5033
+ y: MathCollection | object
5034
+ ): MathJsChain<number | BigNumber>
4637
5035
 
4638
5036
  /**
4639
5037
  * Calculates the point of intersection of two lines in two or three
@@ -4649,10 +5047,11 @@ declare namespace math {
4649
5047
  * the calculation is for line and plane
4650
5048
  */
4651
5049
  intersect(
5050
+ this: MathJsChain<MathCollection>,
4652
5051
  x: MathCollection,
4653
5052
  y: MathCollection,
4654
5053
  z: MathCollection
4655
- ): MathJsChain
5054
+ ): MathJsChain<MathArray>
4656
5055
 
4657
5056
  /*************************************************************************
4658
5057
  * Logical functions
@@ -4664,13 +5063,18 @@ declare namespace math {
4664
5063
  * element wise.
4665
5064
  * @param y Second value to and
4666
5065
  */
4667
- and(y: number | BigNumber | Complex | Unit | MathCollection): MathJsChain
5066
+ and(
5067
+ this: MathJsChain<number | BigNumber | Complex | Unit | MathCollection>,
5068
+ y: number | BigNumber | Complex | Unit | MathCollection
5069
+ ): MathJsChain<boolean | MathCollection>
4668
5070
 
4669
5071
  /**
4670
5072
  * Logical not. Flips boolean value of a given parameter. For matrices,
4671
5073
  * the function is evaluated element wise.
4672
5074
  */
4673
- not(): MathJsChain
5075
+ not(
5076
+ this: MathJsChain<number | BigNumber | Complex | Unit | MathCollection>
5077
+ ): MathJsChain<boolean | MathCollection>
4674
5078
 
4675
5079
  /**
4676
5080
  * Logical or. Test if at least one value is defined with a
@@ -4678,7 +5082,10 @@ declare namespace math {
4678
5082
  * element wise.
4679
5083
  * @param y Second value to or
4680
5084
  */
4681
- or(y: number | BigNumber | Complex | Unit | MathCollection): MathJsChain
5085
+ or(
5086
+ this: MathJsChain<number | BigNumber | Complex | Unit | MathCollection>,
5087
+ y: number | BigNumber | Complex | Unit | MathCollection
5088
+ ): MathJsChain<boolean | MathCollection>
4682
5089
 
4683
5090
  /**
4684
5091
  * Logical xor. Test whether one and only one value is defined with a
@@ -4686,7 +5093,10 @@ declare namespace math {
4686
5093
  * element wise.
4687
5094
  * @param y Second value to xor
4688
5095
  */
4689
- xor(y: number | BigNumber | Complex | Unit | MathCollection): MathJsChain
5096
+ xor(
5097
+ this: MathJsChain<number | BigNumber | Complex | Unit | MathCollection>,
5098
+ y: number | BigNumber | Complex | Unit | MathCollection
5099
+ ): MathJsChain<boolean | MathCollection>
4690
5100
 
4691
5101
  /*************************************************************************
4692
5102
  * Matrix functions
@@ -4697,7 +5107,10 @@ declare namespace math {
4697
5107
  * dimension over which to concatenate the matrices. By default the last
4698
5108
  * dimension of the matrices.
4699
5109
  */
4700
- concat(): MathJsChain
5110
+
5111
+ concat(
5112
+ this: MathJsChain<Array<MathCollection | number | BigNumber>>
5113
+ ): MathJsChain<MathCollection>
4701
5114
 
4702
5115
  /**
4703
5116
  * Calculate the cross product for two vectors in three dimensional
@@ -4706,12 +5119,16 @@ declare namespace math {
4706
5119
  * * b2 - a2 * b1 ]
4707
5120
  * @param y Second vector
4708
5121
  */
4709
- cross(y: MathCollection): MathJsChain
5122
+ cross(
5123
+ this: MathJsChain<MathCollection>,
5124
+ y: MathCollection
5125
+ ): MathJsChain<Matrix | MathArray>
4710
5126
 
4711
5127
  /**
4712
5128
  * Calculate the determinant of a matrix.
4713
5129
  */
4714
- det(): MathJsChain
5130
+
5131
+ det(this: MathJsChain<MathCollection>): MathJsChain<number>
4715
5132
 
4716
5133
  /**
4717
5134
  * Create a diagonal matrix or retrieve the diagonal of a matrix. When x
@@ -4724,8 +5141,15 @@ declare namespace math {
4724
5141
  * retrieved. Default value: 0.
4725
5142
  * @param format The matrix storage format. Default value: 'dense'.
4726
5143
  */
4727
- diag(format?: string): MathJsChain
4728
- diag(k: number | BigNumber, format?: string): MathJsChain
5144
+ diag(
5145
+ this: MathJsChain<MathCollection>,
5146
+ format?: string
5147
+ ): MathJsChain<Matrix>
5148
+ diag(
5149
+ this: MathJsChain<MathCollection>,
5150
+ k: number | BigNumber,
5151
+ format?: string
5152
+ ): MathJsChain<Matrix | MathArray>
4729
5153
 
4730
5154
  /**
4731
5155
  * Calculate the dot product of two vectors. The dot product of A = [a1,
@@ -4733,7 +5157,10 @@ declare namespace math {
4733
5157
  * B) = a1 * b1 + a2 * b2 + a3 * b3 + ... + an * bn
4734
5158
  * @param y Second vector
4735
5159
  */
4736
- dot(y: MathCollection): MathJsChain
5160
+ dot(
5161
+ this: MathJsChain<MathCollection>,
5162
+ y: MathCollection
5163
+ ): MathJsChain<number>
4737
5164
 
4738
5165
  /**
4739
5166
  * Compute the matrix exponential, expm(A) = e^A. The matrix must be
@@ -4742,52 +5169,77 @@ declare namespace math {
4742
5169
  * approximant with scaling and squaring; see “Nineteen Dubious Ways to
4743
5170
  * Compute the Exponential of a Matrix,” by Moler and Van Loan.
4744
5171
  */
4745
- expm(): MathJsChain
5172
+
5173
+ expm(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4746
5174
 
4747
5175
  /**
4748
5176
  * Create a 2-dimensional identity matrix with size m x n or n x n. The
4749
5177
  * matrix has ones on the diagonal and zeros elsewhere.
4750
5178
  * @param format The Matrix storage format
4751
5179
  */
4752
- identity(format?: string): MathJsChain
5180
+ identity(
5181
+ this: MathJsChain<number | number[] | Matrix | MathArray>,
5182
+ format?: string
5183
+ ): MathJsChain<Matrix | MathArray | number>
5184
+
4753
5185
  /**
4754
5186
  * @param n The y dimension for the matrix
4755
5187
  * @param format The Matrix storage format
4756
5188
  */
4757
- identity(n: number, format?: string): MathJsChain
5189
+ identity(
5190
+ this: MathJsChain<number>,
5191
+ n: number,
5192
+ format?: string
5193
+ ): MathJsChain<Matrix | MathArray | number>
4758
5194
 
4759
5195
  /**
4760
5196
  * Filter the items in an array or one dimensional matrix.
4761
5197
  */
4762
5198
  filter(
4763
- test: // eslint-disable-next-line @typescript-eslint/no-explicit-any
4764
- ((value: any, index: any, matrix: Matrix | MathArray) => boolean) | RegExp
4765
- ): MathJsChain
5199
+ this: MathJsChain<Matrix | MathArray | string[]>,
5200
+ test:
5201
+ | ((
5202
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5203
+ value: any,
5204
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5205
+ index: any,
5206
+ matrix: Matrix | MathArray | string[]
5207
+ ) => boolean)
5208
+ | RegExp
5209
+ ): MathJsChain<Matrix | MathArray>
4766
5210
 
4767
5211
  /**
4768
5212
  * Flatten a multi dimensional matrix into a single dimensional matrix.
4769
5213
  */
4770
- flatten(): MathJsChain
5214
+
5215
+ flatten<T extends MathCollection>(x: MathJsChain<T>): MathJsChain<T>
4771
5216
 
4772
5217
  /**
4773
5218
  * Iterate over all elements of a matrix/array, and executes the given
4774
5219
  * callback function.
4775
5220
  */
4776
- forEach(
5221
+ forEach<T extends Matrix | MathArray>(
5222
+ this: MathJsChain<T>,
4777
5223
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4778
- callback: (value: any, index: any, matrix: Matrix | MathArray) => void
4779
- ): MathJsChain
5224
+ callback: (value: any, index: any, matrix: T) => void
5225
+ ): MathJsChain<T>
4780
5226
 
4781
5227
  /**
4782
5228
  * Calculate the inverse of a square matrix.
4783
5229
  */
4784
- inv(): MathJsChain
5230
+
5231
+ inv<T extends number | Complex | MathCollection>(
5232
+ this: MathJsChain<T>
5233
+ ): MathJsChain<NoLiteralType<T>>
4785
5234
 
4786
5235
  /**
4787
5236
  * Calculate the kronecker product of two matrices or vectors
4788
5237
  * @param y Second vector
4789
5238
  */
4790
- kron(y: Matrix | MathArray): MathJsChain
5239
+ kron(
5240
+ this: MathJsChain<Matrix | MathArray>,
5241
+ y: Matrix | MathArray
5242
+ ): MathJsChain<Matrix>
4791
5243
 
4792
5244
  /**
4793
5245
  * Iterate over all elements of a matrix/array, and executes the given
@@ -4796,26 +5248,31 @@ declare namespace math {
4796
5248
  * parameters: the value of the element, the index of the element, and
4797
5249
  * the Matrix/array being traversed.
4798
5250
  */
4799
- map(
4800
- callback: (
4801
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4802
- value: any,
4803
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4804
- index: any,
4805
- matrix: Matrix | MathArray
4806
- ) => Matrix | MathArray
4807
- ): MathJsChain
5251
+ map<T extends Matrix | MathArray>(
5252
+ this: MathJsChain<T>,
5253
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5254
+ callback: (value: any, index: any, matrix: T) => MathType | string
5255
+ ): MathJsChain<T>
4808
5256
 
4809
5257
  /**
4810
5258
  * Create a matrix filled with ones. The created matrix can have one or
4811
5259
  * multiple dimensions.
4812
5260
  * @param format The matrix storage format
4813
5261
  */
4814
- ones(format?: string): MathJsChain
5262
+ ones(
5263
+ this: MathJsChain<number | number[]>,
5264
+ format?: string
5265
+ ): MathJsChain<MathCollection>
5266
+
4815
5267
  /**
4816
5268
  * @param format The matrix storage format
4817
5269
  */
4818
- ones(n: number, format?: string): MathJsChain
5270
+ ones(
5271
+ this: MathJsChain<number>,
5272
+ n: number,
5273
+ format?: string
5274
+ ): MathJsChain<MathCollection>
5275
+
4819
5276
  /**
4820
5277
  * Partition-based selection of an array or 1D matrix. Will find the kth
4821
5278
  * smallest value, and mutates the input array. Uses Quickselect.
@@ -4825,10 +5282,11 @@ declare namespace math {
4825
5282
  * and 0 when a == b. Default value: 'asc'.
4826
5283
  */
4827
5284
  partitionSelect(
5285
+ this: MathJsChain<MathCollection>,
4828
5286
  k: number,
4829
5287
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4830
5288
  compare?: 'asc' | 'desc' | ((a: any, b: any) => number)
4831
- ): MathJsChain
5289
+ ): MathJsChain<MathCollection>
4832
5290
 
4833
5291
  /**
4834
5292
  * Create an array from a range. By default, the range end is excluded.
@@ -4839,20 +5297,28 @@ declare namespace math {
4839
5297
  * @param includeEnd: Option to specify whether to include the end or
4840
5298
  * not. False by default
4841
5299
  */
4842
- range(includeEnd?: boolean): Matrix
4843
- range(end: number | BigNumber, includeEnd?: boolean): MathJsChain
5300
+ range(this: MathJsChain<string>, includeEnd?: boolean): MathJsChain<Matrix>
4844
5301
  range(
5302
+ this: MathJsChain<number | BigNumber>,
5303
+ end: number | BigNumber,
5304
+ includeEnd?: boolean
5305
+ ): MathJsChain<Matrix>
5306
+ range(
5307
+ this: MathJsChain<number | BigNumber>,
4845
5308
  end: number | BigNumber,
4846
5309
  step: number | BigNumber,
4847
5310
  includeEnd?: boolean
4848
- ): MathJsChain
5311
+ ): MathJsChain<Matrix>
4849
5312
 
4850
5313
  /**
4851
5314
  * Reshape a multi dimensional array to fit the specified dimensions
4852
5315
  * @param sizes One dimensional array with integral sizes for each
4853
5316
  * dimension
4854
5317
  */
4855
- reshape(sizes: number[]): MathJsChain
5318
+ reshape<T extends MathCollection>(
5319
+ this: MathJsChain<T>,
5320
+ sizes: number[]
5321
+ ): MathJsChain<T>
4856
5322
 
4857
5323
  /**
4858
5324
  * Resize a matrix
@@ -4860,12 +5326,20 @@ declare namespace math {
4860
5326
  * @param defaultValue Zero by default, except in case of a string, in
4861
5327
  * that case defaultValue = ' ' Default value: 0.
4862
5328
  */
4863
- resize(size: MathCollection, defaultValue?: number | string): MathJsChain
5329
+ resize<T extends MathCollection>(
5330
+ this: MathJsChain<T>,
5331
+ size: MathCollection,
5332
+ defaultValue?: number | string
5333
+ ): MathJsChain<T>
4864
5334
 
4865
5335
  /**
4866
5336
  * Calculate the size of a matrix or scalar.
4867
5337
  */
4868
- size(): MathJsChain
5338
+ size(
5339
+ this: MathJsChain<
5340
+ boolean | number | Complex | Unit | string | MathCollection
5341
+ >
5342
+ ): MathJsChain<MathCollection>
4869
5343
 
4870
5344
  /**
4871
5345
  * Sort the items in a matrix
@@ -4873,22 +5347,25 @@ declare namespace math {
4873
5347
  * is called as compare(a, b), and must return 1 when a > b, -1 when a <
4874
5348
  * b, and 0 when a == b. Default value: ‘asc’
4875
5349
  */
4876
- sort(
5350
+ sort<T extends Matrix | MathArray>(
5351
+ this: MathJsChain<T>,
4877
5352
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4878
5353
  compare: ((a: any, b: any) => number) | 'asc' | 'desc' | 'natural'
4879
- ): MathJsChain
5354
+ ): MathJsChain<T>
4880
5355
 
4881
5356
  /**
4882
5357
  * Calculate the principal square root of a square matrix. The principal
4883
5358
  * square root matrix X of another matrix A is such that X * X = A.
4884
5359
  */
4885
- sqrtm(): MathJsChain
5360
+
5361
+ sqrtm<T extends MathCollection>(A: MathJsChain<T>): MathJsChain<T>
4886
5362
 
4887
5363
  /**
4888
5364
  * Squeeze a matrix, remove inner and outer singleton dimensions from a
4889
5365
  * matrix.
4890
5366
  */
4891
- squeeze(): MathJsChain
5367
+
5368
+ squeeze<T extends MathCollection>(x: MathJsChain<T>): MathJsChain<T>
4892
5369
 
4893
5370
  /**
4894
5371
  * Get or set a subset of a matrix or string.
@@ -4901,19 +5378,28 @@ declare namespace math {
4901
5378
  * undefined. Default value: undefined.
4902
5379
  */
4903
5380
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4904
- subset(index: Index, replacement?: any, defaultValue?: any): MathJsChain
5381
+ subset<T extends MathCollection | string>(
5382
+ this: MathJsChain<T>,
5383
+ index: Index,
5384
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5385
+ replacement?: any,
5386
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5387
+ defaultValue?: any
5388
+ ): MathJsChain<T>
4905
5389
 
4906
5390
  /**
4907
5391
  * Calculate the trace of a matrix: the sum of the elements on the main
4908
5392
  * diagonal of a square matrix.
4909
5393
  */
4910
- trace(): MathJsChain
5394
+
5395
+ trace(this: MathJsChain<MathCollection>): MathJsChain<number>
4911
5396
 
4912
5397
  /**
4913
5398
  * Transpose a matrix. All values of the matrix are reflected over its
4914
5399
  * main diagonal. Only two dimensional matrices are supported.
4915
5400
  */
4916
- transpose(): MathJsChain
5401
+
5402
+ transpose<T extends MathCollection>(x: MathJsChain<T>): MathJsChain<T>
4917
5403
 
4918
5404
  /**
4919
5405
  * Create a matrix filled with zeros. The created matrix can have one or
@@ -4921,12 +5407,20 @@ declare namespace math {
4921
5407
  * @param format The matrix storage format
4922
5408
  * @returns A matrix filled with zeros
4923
5409
  */
4924
- zeros(format?: string): MathJsChain
5410
+ zeros(
5411
+ this: MathJsChain<number | number[]>,
5412
+ format?: string
5413
+ ): MathJsChain<MathCollection>
5414
+
4925
5415
  /**
4926
5416
  * @param n The y dimension of the matrix
4927
5417
  * @param format The matrix storage format
4928
5418
  */
4929
- zeros(n: number, format?: string): MathJsChain
5419
+ zeros(
5420
+ this: MathJsChain<number>,
5421
+ n: number,
5422
+ format?: string
5423
+ ): MathJsChain<MathCollection>
4930
5424
 
4931
5425
  /*************************************************************************
4932
5426
  * Probability functions
@@ -4938,28 +5432,40 @@ declare namespace math {
4938
5432
  * following condition must be enforced: k <= n.
4939
5433
  * @param k Number of objects in the subset
4940
5434
  */
4941
- combinations(k: number | BigNumber): MathJsChain
5435
+ combinations<T extends number | BigNumber>(
5436
+ n: MathJsChain<T>,
5437
+ k: number | BigNumber
5438
+ ): MathJsChain<NoLiteralType<T>>
4942
5439
 
4943
5440
  /**
4944
5441
  * Compute the factorial of a value Factorial only supports an integer
4945
5442
  * value as argument. For matrices, the function is evaluated element
4946
5443
  * wise.
4947
5444
  */
4948
- factorial(): MathJsChain
5445
+
5446
+ factorial<T extends number | BigNumber | MathCollection>(
5447
+ n: MathJsChain<T>
5448
+ ): MathJsChain<NoLiteralType<T>>
4949
5449
 
4950
5450
  /**
4951
5451
  * Compute the gamma function of a value using Lanczos approximation for
4952
5452
  * small values, and an extended Stirling approximation for large
4953
5453
  * values. For matrices, the function is evaluated element wise.
4954
5454
  */
4955
- gamma(): MathJsChain
5455
+
5456
+ gamma<T extends number | BigNumber | Complex | MathCollection>(
5457
+ n: MathJsChain<T>
5458
+ ): MathJsChain<NoLiteralType<T>>
4956
5459
 
4957
5460
  /**
4958
5461
  * Calculate the Kullback-Leibler (KL) divergence between two
4959
5462
  * distributions
4960
5463
  * @param p Second vector
4961
5464
  */
4962
- kldivergence(p: MathCollection): MathJsChain
5465
+ kldivergence(
5466
+ this: MathJsChain<MathCollection>,
5467
+ p: MathCollection
5468
+ ): MathJsChain<number>
4963
5469
 
4964
5470
  /**
4965
5471
  * Multinomial Coefficients compute the number of ways of picking a1,
@@ -4967,7 +5473,10 @@ declare namespace math {
4967
5473
  * takes one array of integers as an argument. The following condition
4968
5474
  * must be enforced: every ai <= 0
4969
5475
  */
4970
- multinomial(): MathJsChain
5476
+
5477
+ multinomial<T extends number | BigNumber>(
5478
+ a: MathJsChain<T[]>
5479
+ ): MathJsChain<NoLiteralType<T>>
4971
5480
 
4972
5481
  /**
4973
5482
  * Compute the number of ways of obtaining an ordered subset of k
@@ -4975,7 +5484,10 @@ declare namespace math {
4975
5484
  * arguments. The following condition must be enforced: k <= n.
4976
5485
  * @param k The number of objects in the subset
4977
5486
  */
4978
- permutations(k?: number | BigNumber): MathJsChain
5487
+ permutations<T extends number | BigNumber>(
5488
+ n: MathJsChain<T>,
5489
+ k?: number | BigNumber
5490
+ ): MathJsChain<NoLiteralType<T>>
4979
5491
 
4980
5492
  /**
4981
5493
  * Random pick a value from a one dimensional array. Array element is
@@ -4983,7 +5495,11 @@ declare namespace math {
4983
5495
  * @param number An int or float
4984
5496
  * @param weights An array of ints or floats
4985
5497
  */
4986
- pickRandom(number?: number, weights?: number[]): MathJsChain
5498
+ pickRandom(
5499
+ array: MathJsChain<number[]>,
5500
+ number?: number,
5501
+ weights?: number[]
5502
+ ): MathJsChain<number | number[]>
4987
5503
 
4988
5504
  /**
4989
5505
  * Return a random number larger or equal to min and smaller than max
@@ -4991,9 +5507,14 @@ declare namespace math {
4991
5507
  * @param min Minimum boundary for the random value, included
4992
5508
  * @param max Maximum boundary for the random value, excluded
4993
5509
  */
4994
- random(max?: number): MathJsChain
5510
+ random(this: MathJsChain<number>, max?: number): MathJsChain<number>
5511
+
4995
5512
  // tslint:disable-next-line unified-signatures
4996
- random(min: number, max: number): MathJsChain
5513
+ random<T extends MathCollection>(
5514
+ this: MathJsChain<T>,
5515
+ min?: number,
5516
+ max?: number
5517
+ ): MathJsChain<T>
4997
5518
 
4998
5519
  /**
4999
5520
  * Return a random integer number larger or equal to min and smaller
@@ -5001,9 +5522,20 @@ declare namespace math {
5001
5522
  * @param min Minimum boundary for the random value, included
5002
5523
  * @param max Maximum boundary for the random value, excluded
5003
5524
  */
5004
- randomInt(max?: number): MathJsChain
5525
+ randomInt<T extends MathCollection>(
5526
+ this: MathJsChain<T>,
5527
+ max?: number
5528
+ ): MathJsChain<T>
5529
+ randomInt<T extends MathCollection>(
5530
+ this: MathJsChain<T>,
5531
+ max?: number
5532
+ ): MathJsChain<T>
5005
5533
  // tslint:disable-next-line unified-signatures
5006
- randomInt(min: number, max: number): MathJsChain
5534
+ randomInt<T extends MathCollection>(
5535
+ this: MathJsChain<T>,
5536
+ min: number,
5537
+ max: number
5538
+ ): MathJsChain<T>
5007
5539
 
5008
5540
  /*************************************************************************
5009
5541
  * Relational functions
@@ -5017,7 +5549,10 @@ declare namespace math {
5017
5549
  * For matrices, the function is evaluated element wise.
5018
5550
  * @param y Second value to compare
5019
5551
  */
5020
- compare(y: MathType | string): MathJsChain
5552
+ compare(
5553
+ this: MathJsChain<MathType | string>,
5554
+ y: MathType | string
5555
+ ): MathJsChain<number | BigNumber | Fraction | MathCollection>
5021
5556
 
5022
5557
  /**
5023
5558
  * Compare two values of any type in a deterministic, natural way. For
@@ -5027,7 +5562,7 @@ declare namespace math {
5027
5562
  * @param y Second value to compare
5028
5563
  */
5029
5564
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5030
- compareNatural(y: any): MathJsChain
5565
+ compareNatural(this: MathJsChain<any>, y: any): MathJsChain<number>
5031
5566
 
5032
5567
  /**
5033
5568
  * Compare two strings lexically. Comparison is case sensitive. Returns
@@ -5035,14 +5570,22 @@ declare namespace math {
5035
5570
  * function is evaluated element wise.
5036
5571
  * @param y Second string to compare
5037
5572
  */
5038
- compareText(y: string | MathCollection): MathJsChain
5573
+ compareText(
5574
+ this: MathJsChain<string | MathCollection>,
5575
+ y: string | MathCollection
5576
+ ): MathJsChain<number | MathCollection>
5039
5577
 
5040
5578
  /**
5041
5579
  * Test element wise whether two matrices are equal. The function
5042
5580
  * accepts both matrices and scalar values.
5043
5581
  * @param y Second amtrix to compare
5044
5582
  */
5045
- deepEqual(y: MathType): MathJsChain
5583
+ deepEqual(
5584
+ this: MathJsChain<MathType>,
5585
+ y: MathType
5586
+ ): MathJsChain<
5587
+ number | BigNumber | Fraction | Complex | Unit | MathCollection
5588
+ >
5046
5589
 
5047
5590
  /**
5048
5591
  * Test whether two values are equal.
@@ -5056,14 +5599,20 @@ declare namespace math {
5056
5599
  * else, and undefined is only equal to undefined and nothing else.
5057
5600
  * @param y Second value to compare
5058
5601
  */
5059
- equal(y: MathType | string): MathJsChain
5602
+ equal(
5603
+ this: MathJsChain<MathType | string>,
5604
+ y: MathType | string
5605
+ ): MathJsChain<boolean | MathCollection>
5060
5606
 
5061
5607
  /**
5062
5608
  * Check equality of two strings. Comparison is case sensitive. For
5063
5609
  * matrices, the function is evaluated element wise.
5064
5610
  * @param y Second string to compare
5065
5611
  */
5066
- equalText(y: string | MathCollection): MathJsChain
5612
+ equalText(
5613
+ this: MathJsChain<string | MathCollection>,
5614
+ y: string | MathCollection
5615
+ ): MathJsChain<number | MathCollection>
5067
5616
 
5068
5617
  /**
5069
5618
  * Test whether value x is larger than y. The function returns true when
@@ -5073,7 +5622,10 @@ declare namespace math {
5073
5622
  * function is evaluated element wise.
5074
5623
  * @param y Second value to compare
5075
5624
  */
5076
- larger(y: MathType | string): MathJsChain
5625
+ larger(
5626
+ this: MathJsChain<MathType | string>,
5627
+ y: MathType | string
5628
+ ): MathJsChain<boolean | MathCollection>
5077
5629
 
5078
5630
  /**
5079
5631
  * Test whether value x is larger or equal to y. The function returns
@@ -5083,7 +5635,10 @@ declare namespace math {
5083
5635
  * the function is evaluated element wise.
5084
5636
  * @param y Second value to vcompare
5085
5637
  */
5086
- largerEq(y: MathType | string): MathJsChain
5638
+ largerEq(
5639
+ this: MathJsChain<MathType | string>,
5640
+ y: MathType | string
5641
+ ): MathJsChain<boolean | MathCollection>
5087
5642
 
5088
5643
  /**
5089
5644
  * Test whether value x is smaller than y. The function returns true
@@ -5093,7 +5648,10 @@ declare namespace math {
5093
5648
  * the function is evaluated element wise.
5094
5649
  * @param y Second value to vcompare
5095
5650
  */
5096
- smaller(y: MathType | string): MathJsChain
5651
+ smaller(
5652
+ this: MathJsChain<MathType | string>,
5653
+ y: MathType | string
5654
+ ): MathJsChain<boolean | MathCollection>
5097
5655
 
5098
5656
  /**
5099
5657
  * Test whether value x is smaller or equal to y. The function returns
@@ -5103,7 +5661,10 @@ declare namespace math {
5103
5661
  * matrices, the function is evaluated element wise.
5104
5662
  * @param y Second value to compare
5105
5663
  */
5106
- smallerEq(y: MathType | string): MathJsChain
5664
+ smallerEq(
5665
+ this: MathJsChain<MathType | string>,
5666
+ y: MathType | string
5667
+ ): MathJsChain<boolean | MathCollection>
5107
5668
 
5108
5669
  /**
5109
5670
  * Test whether two values are unequal. The function tests whether the
@@ -5116,7 +5677,10 @@ declare namespace math {
5116
5677
  * undefined is unequal with everything except undefined.
5117
5678
  * @param y Second value to vcompare
5118
5679
  */
5119
- unequal(y: MathType | string): MathJsChain
5680
+ unequal(
5681
+ this: MathJsChain<MathType | string>,
5682
+ y: MathType | string
5683
+ ): MathJsChain<boolean | MathCollection>
5120
5684
 
5121
5685
  /*************************************************************************
5122
5686
  * Set functions
@@ -5128,7 +5692,10 @@ declare namespace math {
5128
5692
  * will be sorted in ascending order before the operation.
5129
5693
  * @param a2 A (multi)set
5130
5694
  */
5131
- setCartesian(a2: MathCollection): MathJsChain
5695
+ setCartesian<T extends MathCollection>(
5696
+ this: MathJsChain<T>,
5697
+ a2: MathCollection
5698
+ ): MathJsChain<T>
5132
5699
 
5133
5700
  /**
5134
5701
  * Create the difference of two (multi)sets: every element of set1, that
@@ -5136,20 +5703,27 @@ declare namespace math {
5136
5703
  * to single-dimension arrays before the operation
5137
5704
  * @param a2 A (multi)set
5138
5705
  */
5139
- setDifference(a2: MathCollection): MathJsChain
5706
+ setDifference<T extends MathCollection>(
5707
+ this: MathJsChain<T>,
5708
+ a2: MathCollection
5709
+ ): MathJsChain<T>
5140
5710
 
5141
5711
  /**
5142
5712
  * Collect the distinct elements of a multiset. A multi-dimension array
5143
5713
  * will be converted to a single-dimension array before the operation.
5144
5714
  */
5145
- setDistinct(): MathJsChain
5715
+
5716
+ setDistinct<T extends MathCollection>(a: MathJsChain<T>): MathJsChain<T>
5146
5717
 
5147
5718
  /**
5148
5719
  * Create the intersection of two (multi)sets. Multi-dimension arrays
5149
5720
  * will be converted to single-dimension arrays before the operation.
5150
5721
  * @param a2 A (multi)set
5151
5722
  */
5152
- setIntersect(a2: MathCollection): MathJsChain
5723
+ setIntersect<T extends MathCollection>(
5724
+ this: MathJsChain<T>,
5725
+ a2: MathCollection
5726
+ ): MathJsChain<T>
5153
5727
 
5154
5728
  /**
5155
5729
  * Check whether a (multi)set is a subset of another (multi)set. (Every
@@ -5157,7 +5731,10 @@ declare namespace math {
5157
5731
  * be converted to single-dimension arrays before the operation.
5158
5732
  * @param a2 A (multi)set
5159
5733
  */
5160
- setIsSubset(a2: MathCollection): MathJsChain
5734
+ setIsSubset(
5735
+ this: MathJsChain<MathCollection>,
5736
+ a2: MathCollection
5737
+ ): MathJsChain<boolean>
5161
5738
 
5162
5739
  /**
5163
5740
  * Count the multiplicity of an element in a multiset. A multi-dimension
@@ -5165,21 +5742,26 @@ declare namespace math {
5165
5742
  * operation.
5166
5743
  * @param a A multiset
5167
5744
  */
5168
- setMultiplicity(a: MathCollection): MathJsChain
5745
+ setMultiplicity(
5746
+ e: MathJsChain<number | BigNumber | Fraction | Complex>,
5747
+ a: MathCollection
5748
+ ): MathJsChain<number>
5169
5749
 
5170
5750
  /**
5171
5751
  * Create the powerset of a (multi)set. (The powerset contains very
5172
5752
  * possible subsets of a (multi)set.) A multi-dimension array will be
5173
5753
  * converted to a single-dimension array before the operation.
5174
5754
  */
5175
- setPowerset(): MathJsChain
5755
+
5756
+ setPowerset<T extends MathCollection>(a: MathJsChain<T>): MathJsChain<T>
5176
5757
 
5177
5758
  /**
5178
5759
  * Count the number of elements of a (multi)set. When a second parameter
5179
5760
  * is ‘true’, count only the unique values. A multi-dimension array will
5180
5761
  * be converted to a single-dimension array before the operation.
5181
5762
  */
5182
- setSize(): MathJsChain
5763
+
5764
+ setSize(this: MathJsChain<MathCollection>): MathJsChain<number>
5183
5765
 
5184
5766
  /**
5185
5767
  * Create the symmetric difference of two (multi)sets. Multi-dimension
@@ -5187,14 +5769,20 @@ declare namespace math {
5187
5769
  * operation.
5188
5770
  * @param a2 A (multi)set
5189
5771
  */
5190
- setSymDifference(a2: MathCollection): MathJsChain
5772
+ setSymDifference<T extends MathCollection>(
5773
+ this: MathJsChain<T>,
5774
+ a2: MathCollection
5775
+ ): MathJsChain<T>
5191
5776
 
5192
5777
  /**
5193
5778
  * Create the union of two (multi)sets. Multi-dimension arrays will be
5194
5779
  * converted to single-dimension arrays before the operation.
5195
5780
  * @param a2 A (multi)set
5196
5781
  */
5197
- setUnion(a2: MathCollection): MathJsChain
5782
+ setUnion<T extends MathCollection>(
5783
+ this: MathJsChain<T>,
5784
+ a2: MathCollection
5785
+ ): MathJsChain<T>
5198
5786
 
5199
5787
  /*************************************************************************
5200
5788
  * Special functions
@@ -5204,7 +5792,9 @@ declare namespace math {
5204
5792
  * Compute the erf function of a value using a rational Chebyshev
5205
5793
  * approximations for different intervals of x.
5206
5794
  */
5207
- erf(): MathJsChain
5795
+ erf<T extends number | MathCollection>(
5796
+ this: MathJsChain<T>
5797
+ ): MathJsChain<NoLiteralType<T>>
5208
5798
 
5209
5799
  /*************************************************************************
5210
5800
  * Statistics functions
@@ -5215,7 +5805,8 @@ declare namespace math {
5215
5805
  * values. The median absolute deviation is defined as the median of the
5216
5806
  * absolute deviations from the median.
5217
5807
  */
5218
- mad(): MathJsChain
5808
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5809
+ mad(this: MathJsChain<MathCollection>): MathJsChain<any>
5219
5810
 
5220
5811
  /**
5221
5812
  * Compute the maximum value of a matrix or a list with values. In case
@@ -5224,7 +5815,11 @@ declare namespace math {
5224
5815
  * dimension will be calculated. Parameter dim is zero-based.
5225
5816
  * @param dim The maximum over the selected dimension
5226
5817
  */
5227
- max(dim?: number): MathJsChain
5818
+
5819
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5820
+ max(this: MathJsChain<MathType[]>, dim?: number): MathJsChain<any>
5821
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5822
+ max(this: MathJsChain<MathCollection>, dim?: number): MathJsChain<any>
5228
5823
 
5229
5824
  /**
5230
5825
  * Compute the mean value of matrix or a list with values. In case of a
@@ -5233,7 +5828,10 @@ declare namespace math {
5233
5828
  * dimension will be calculated. Parameter dim is zero-based.
5234
5829
  * @param dim The mean over the selected dimension
5235
5830
  */
5236
- mean(dim?: number): MathJsChain
5831
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5832
+ mean(this: MathJsChain<MathType[]>, dim?: number): MathJsChain<any>
5833
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5834
+ mean(this: MathJsChain<MathCollection>, dim?: number): MathJsChain<any>
5237
5835
 
5238
5836
  /**
5239
5837
  * Compute the median of a matrix or a list with values. The values are
@@ -5243,7 +5841,10 @@ declare namespace math {
5243
5841
  * dimensional) array or matrix, the median of all elements will be
5244
5842
  * calculated.
5245
5843
  */
5246
- median(): MathJsChain
5844
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5845
+ median(this: MathJsChain<MathType[]>, dim?: number): MathJsChain<any>
5846
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5847
+ median(this: MathJsChain<MathCollection>, dim?: number): MathJsChain<any>
5247
5848
 
5248
5849
  /**
5249
5850
  * Compute the maximum value of a matrix or a list of values. In case of
@@ -5252,21 +5853,26 @@ declare namespace math {
5252
5853
  * dimension will be calculated. Parameter dim is zero-based.
5253
5854
  * @param dim The minimum over the selected dimension
5254
5855
  */
5255
- min(dim?: number): MathJsChain
5856
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5857
+ min(this: MathJsChain<MathType[]>): MathJsChain<MathType[]>
5858
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5859
+ min(this: MathJsChain<MathCollection>, dim?: number): MathJsChain<any>
5256
5860
 
5257
5861
  /**
5258
5862
  * Computes the mode of a set of numbers or a list with values(numbers
5259
5863
  * or characters). If there are more than one modes, it returns a list
5260
5864
  * of those values.
5261
5865
  */
5262
- mode(): MathJsChain
5866
+
5867
+ mode(this: MathJsChain<MathType[]>): MathJsChain<MathType[]>
5263
5868
 
5264
5869
  /**
5265
5870
  * Compute the product of a matrix or a list with values. In case of a
5266
5871
  * (multi dimensional) array or matrix, the sum of all elements will be
5267
5872
  * calculated.
5268
5873
  */
5269
- prod(): MathJsChain
5874
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5875
+ prod(this: MathJsChain<MathType[]>): MathJsChain<any>
5270
5876
 
5271
5877
  /**
5272
5878
  * Compute the prob order quantile of a matrix or a list with values.
@@ -5281,9 +5887,11 @@ declare namespace math {
5281
5887
  * @param sorted =false is data sorted in ascending order
5282
5888
  */
5283
5889
  quantileSeq(
5890
+ A: MathJsChain<MathCollection>,
5284
5891
  prob: number | BigNumber | MathArray,
5285
5892
  sorted?: boolean
5286
- ): MathJsChain
5893
+ ): MathJsChain<number | BigNumber | Unit | MathArray>
5894
+
5287
5895
  /**
5288
5896
  * Compute the standard deviation of a matrix or a list with values. The
5289
5897
  * standard deviations is defined as the square root of the variance:
@@ -5301,9 +5909,11 @@ declare namespace math {
5301
5909
  * @returns The standard deviation
5302
5910
  */
5303
5911
  std(
5912
+ this: MathJsChain<number[]>,
5304
5913
  dim?: number,
5305
5914
  normalization?: 'unbiased' | 'uncorrected' | 'biased'
5306
- ): MathJsChain
5915
+ ): MathJsChain<number>
5916
+
5307
5917
  /**
5308
5918
  * Compute the standard deviation of a matrix or a list with values. The
5309
5919
  * standard deviations is defined as the square root of the variance:
@@ -5319,14 +5929,22 @@ declare namespace math {
5319
5929
  * ‘unbiased’.
5320
5930
  * @returns The standard deviation
5321
5931
  */
5322
- std(normalization: 'unbiased' | 'uncorrected' | 'biased'): MathJsChain
5932
+ std(
5933
+ this: MathJsChain<MathCollection>,
5934
+ dimension?: number,
5935
+ normalization?: 'unbiased' | 'uncorrected' | 'biased'
5936
+ ): MathJsChain<number[]>
5323
5937
 
5324
5938
  /**
5325
5939
  * Compute the sum of a matrix or a list with values. In case of a
5326
5940
  * (multi dimensional) array or matrix, the sum of all elements will be
5327
5941
  * calculated.
5328
5942
  */
5329
- sum(): MathJsChain
5943
+ std(
5944
+ this: MathJsChain<MathCollection>,
5945
+ normalization: 'unbiased' | 'uncorrected' | 'biased'
5946
+ ): MathJsChain<number>
5947
+
5330
5948
  /**
5331
5949
  * Compute the variance of a matrix or a list with values. In case of a
5332
5950
  * (multi dimensional) array or matrix, the variance over all elements
@@ -5345,9 +5963,9 @@ declare namespace math {
5345
5963
  * @returns The variance
5346
5964
  */
5347
5965
  variance(
5348
- dim?: number,
5349
- normalization?: 'unbiased' | 'uncorrected' | 'biased'
5350
- ): MathJsChain
5966
+ this: MathJsChain<Array<Array<number | BigNumber | Fraction>>>
5967
+ ): MathJsChain<number>
5968
+
5351
5969
  /**
5352
5970
  * Compute the variance of a matrix or a list with values. In case of a
5353
5971
  * (multi dimensional) array or matrix, the variance over all elements
@@ -5364,7 +5982,16 @@ declare namespace math {
5364
5982
  * Default value: ‘unbiased’.
5365
5983
  * @returns The variance
5366
5984
  */
5367
- variance(normalization: 'unbiased' | 'uncorrected' | 'biased'): MathJsChain
5985
+ variance(
5986
+ this: MathJsChain<MathCollection>,
5987
+ dimension?: number,
5988
+ normalization?: 'unbiased' | 'uncorrected' | 'biased'
5989
+ ): MathJsChain<number[]>
5990
+
5991
+ variance(
5992
+ this: MathJsChain<MathCollection>,
5993
+ normalization: 'unbiased' | 'uncorrected' | 'biased'
5994
+ ): MathJsChain<number>
5368
5995
 
5369
5996
  /*************************************************************************
5370
5997
  * String functions
@@ -5382,13 +6009,15 @@ declare namespace math {
5382
6009
  * @see http://mathjs.org/docs/reference/functions/format.html
5383
6010
  */
5384
6011
  format(
6012
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6013
+ this: MathJsChain<any>,
5385
6014
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5386
6015
  value: any,
5387
6016
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5388
6017
  options?: FormatOptions | number | ((item: any) => string),
5389
6018
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5390
6019
  callback?: (value: any) => string
5391
- ): MathJsChain
6020
+ ): MathJsChain<string>
5392
6021
 
5393
6022
  /**
5394
6023
  * Interpolate values into a string template.
@@ -5400,11 +6029,12 @@ declare namespace math {
5400
6029
  * numbers. See function math.format for a description of all options.
5401
6030
  */
5402
6031
  print(
6032
+ this: MathJsChain<string>,
5403
6033
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5404
6034
  values: any,
5405
6035
  precision?: number,
5406
6036
  options?: number | object
5407
- ): MathJsChain
6037
+ ): MathJsChain<string>
5408
6038
 
5409
6039
  /*************************************************************************
5410
6040
  * Trigonometry functions
@@ -5414,161 +6044,271 @@ declare namespace math {
5414
6044
  * Calculate the inverse cosine of a value. For matrices, the function
5415
6045
  * is evaluated element wise.
5416
6046
  */
5417
- acos(): MathJsChain
6047
+
6048
+ acos(this: MathJsChain<number>): MathJsChain<number>
6049
+ acos(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6050
+ acos(this: MathJsChain<Complex>): MathJsChain<Complex>
6051
+ acos(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6052
+ acos(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5418
6053
 
5419
6054
  /**
5420
6055
  * Calculate the hyperbolic arccos of a value, defined as acosh(x) =
5421
6056
  * ln(sqrt(x^2 - 1) + x). For matrices, the function is evaluated
5422
6057
  * element wise.
5423
6058
  */
5424
- acosh(): MathJsChain
6059
+
6060
+ acosh(this: MathJsChain<number>): MathJsChain<number>
6061
+ acosh(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6062
+ acosh(this: MathJsChain<Complex>): MathJsChain<Complex>
6063
+ acosh(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6064
+ acosh(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5425
6065
 
5426
6066
  /**
5427
6067
  * Calculate the inverse cotangent of a value. For matrices, the
5428
6068
  * function is evaluated element wise.
5429
6069
  */
5430
- acot(): MathJsChain
6070
+
6071
+ acot(this: MathJsChain<number>): MathJsChain<number>
6072
+ acot(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6073
+ acot(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6074
+ acot(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5431
6075
 
5432
6076
  /**
5433
6077
  * Calculate the hyperbolic arccotangent of a value, defined as acoth(x)
5434
6078
  * = (ln((x+1)/x) + ln(x/(x-1))) / 2. For matrices, the function is
5435
6079
  * evaluated element wise.
5436
6080
  */
5437
- acoth(): MathJsChain
6081
+
6082
+ acoth(this: MathJsChain<number>): MathJsChain<number>
6083
+ acoth(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6084
+ acoth(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6085
+ acoth(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5438
6086
 
5439
6087
  /**
5440
6088
  * Calculate the inverse cosecant of a value. For matrices, the function
5441
6089
  * is evaluated element wise.
5442
6090
  */
5443
- acsc(): MathJsChain
6091
+
6092
+ acsc(this: MathJsChain<number>): MathJsChain<number>
6093
+ acsc(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6094
+ acsc(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6095
+ acsc(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5444
6096
 
5445
6097
  /**
5446
6098
  * Calculate the hyperbolic arccosecant of a value, defined as acsch(x)
5447
6099
  * = ln(1/x + sqrt(1/x^2 + 1)). For matrices, the function is evaluated
5448
6100
  * element wise.
5449
6101
  */
5450
- acsch(): MathJsChain
6102
+
6103
+ acsch(this: MathJsChain<number>): MathJsChain<number>
6104
+ acsch(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6105
+ acsch(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6106
+ acsch(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5451
6107
 
5452
6108
  /**
5453
6109
  * Calculate the inverse secant of a value. For matrices, the function
5454
6110
  * is evaluated element wise.
5455
6111
  */
5456
- asec(): MathJsChain
6112
+
6113
+ asec(this: MathJsChain<number>): MathJsChain<number>
6114
+ asec(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6115
+ asec(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6116
+ asec(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5457
6117
 
5458
6118
  /**
5459
6119
  * Calculate the hyperbolic arcsecant of a value, defined as asech(x) =
5460
6120
  * ln(sqrt(1/x^2 - 1) + 1/x). For matrices, the function is evaluated
5461
6121
  * element wise.
5462
6122
  */
5463
- asech(): MathJsChain
6123
+
6124
+ asech(this: MathJsChain<number>): MathJsChain<number>
6125
+ asech(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6126
+ asech(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6127
+ asech(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5464
6128
 
5465
6129
  /**
5466
6130
  * Calculate the inverse sine of a value. For matrices, the function is
5467
6131
  * evaluated element wise.
5468
6132
  */
5469
- asin(): MathJsChain
6133
+
6134
+ asin(this: MathJsChain<number>): MathJsChain<number>
6135
+ asin(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6136
+ asin(this: MathJsChain<Complex>): MathJsChain<Complex>
6137
+ asin(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6138
+ asin(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5470
6139
 
5471
6140
  /**
5472
6141
  * Calculate the hyperbolic arcsine of a value, defined as asinh(x) =
5473
6142
  * ln(x + sqrt(x^2 + 1)). For matrices, the function is evaluated
5474
6143
  * element wise.
5475
6144
  */
5476
- asinh(): MathJsChain
6145
+
6146
+ asinh(this: MathJsChain<number>): MathJsChain<number>
6147
+ asinh(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6148
+ asinh(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6149
+ asinh(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5477
6150
 
5478
6151
  /**
5479
6152
  * Calculate the inverse tangent of a value. For matrices, the function
5480
6153
  * is evaluated element wise.
5481
6154
  */
5482
- atan(): MathJsChain
6155
+
6156
+ atan(this: MathJsChain<number>): MathJsChain<number>
6157
+ atan(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6158
+ atan(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6159
+ atan(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5483
6160
 
5484
6161
  /**
5485
6162
  * Calculate the inverse tangent function with two arguments, y/x. By
5486
6163
  * providing two arguments, the right quadrant of the computed angle can
5487
6164
  * be determined. For matrices, the function is evaluated element wise.
5488
6165
  */
5489
- atan2(): MathJsChain
6166
+
6167
+ atan2(this: MathJsChain<number>, x: number): MathJsChain<number>
6168
+ atan2(
6169
+ this: MathJsChain<MathCollection>,
6170
+ x: MathCollection
6171
+ ): MathJsChain<MathCollection>
5490
6172
 
5491
6173
  /**
5492
6174
  * Calculate the hyperbolic arctangent of a value, defined as atanh(x) =
5493
6175
  * ln((1 + x)/(1 - x)) / 2. For matrices, the function is evaluated
5494
6176
  * element wise.
5495
6177
  */
5496
- atanh(): MathJsChain
6178
+
6179
+ atanh(this: MathJsChain<number>): MathJsChain<number>
6180
+ atanh(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6181
+ atanh(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6182
+ atanh(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5497
6183
 
5498
6184
  /**
5499
6185
  * Calculate the cosine of a value. For matrices, the function is
5500
6186
  * evaluated element wise.
5501
6187
  */
5502
- cos(): MathJsChain
6188
+
6189
+ cos(this: MathJsChain<number | Unit>): MathJsChain<number>
6190
+ cos(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6191
+ cos(this: MathJsChain<Complex>): MathJsChain<Complex>
6192
+ cos(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6193
+ cos(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5503
6194
 
5504
6195
  /**
5505
6196
  * Calculate the hyperbolic cosine of a value, defined as cosh(x) = 1/2
5506
6197
  * * (exp(x) + exp(-x)). For matrices, the function is evaluated element
5507
6198
  * wise.
5508
6199
  */
5509
- cosh(): MathJsChain
6200
+
6201
+ cosh(this: MathJsChain<number | Unit>): MathJsChain<number>
6202
+ cosh(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6203
+ cosh(this: MathJsChain<Complex>): MathJsChain<Complex>
6204
+ cosh(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6205
+ cosh(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5510
6206
 
5511
6207
  /**
5512
6208
  * Calculate the cotangent of a value. cot(x) is defined as 1 / tan(x).
5513
6209
  * For matrices, the function is evaluated element wise.
5514
6210
  */
5515
- cot(): MathJsChain
6211
+
6212
+ cot(this: MathJsChain<number | Unit>): MathJsChain<number>
6213
+ cot(this: MathJsChain<Complex>): MathJsChain<Complex>
6214
+ cot(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6215
+ cot(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5516
6216
 
5517
6217
  /**
5518
6218
  * Calculate the hyperbolic cotangent of a value, defined as coth(x) = 1
5519
6219
  * / tanh(x). For matrices, the function is evaluated element wise.
5520
6220
  */
5521
- coth(): MathJsChain
6221
+
6222
+ coth(this: MathJsChain<number | Unit>): MathJsChain<number>
6223
+ coth(this: MathJsChain<Complex>): MathJsChain<Complex>
6224
+ coth(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6225
+ coth(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5522
6226
 
5523
6227
  /**
5524
6228
  * Calculate the cosecant of a value, defined as csc(x) = 1/sin(x). For
5525
6229
  * matrices, the function is evaluated element wise.
5526
6230
  */
5527
- csc(): MathJsChain
6231
+
6232
+ csc(this: MathJsChain<number | Unit>): MathJsChain<number>
6233
+ csc(this: MathJsChain<Complex>): MathJsChain<Complex>
6234
+ csc(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6235
+ csc(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5528
6236
 
5529
6237
  /**
5530
6238
  * Calculate the hyperbolic cosecant of a value, defined as csch(x) = 1
5531
6239
  * / sinh(x). For matrices, the function is evaluated element wise.
5532
6240
  */
5533
- csch(): MathJsChain
6241
+
6242
+ csch(this: MathJsChain<number | Unit>): MathJsChain<number>
6243
+ csch(this: MathJsChain<Complex>): MathJsChain<Complex>
6244
+ csch(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6245
+ csch(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5534
6246
 
5535
6247
  /**
5536
6248
  * Calculate the secant of a value, defined as sec(x) = 1/cos(x). For
5537
6249
  * matrices, the function is evaluated element wise.
5538
6250
  */
5539
- sec(): MathJsChain
6251
+
6252
+ sec(this: MathJsChain<number | Unit>): MathJsChain<number>
6253
+ sec(this: MathJsChain<Complex>): MathJsChain<Complex>
6254
+ sec(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6255
+ sec(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5540
6256
 
5541
6257
  /**
5542
6258
  * Calculate the hyperbolic secant of a value, defined as sech(x) = 1 /
5543
6259
  * cosh(x). For matrices, the function is evaluated element wise.
5544
6260
  */
5545
- sech(): MathJsChain
6261
+
6262
+ sech(this: MathJsChain<number | Unit>): MathJsChain<number>
6263
+ sech(this: MathJsChain<Complex>): MathJsChain<Complex>
6264
+ sech(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6265
+ sech(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5546
6266
 
5547
6267
  /**
5548
6268
  * Calculate the sine of a value. For matrices, the function is
5549
6269
  * evaluated element wise.
5550
6270
  */
5551
- sin(): MathJsChain
6271
+
6272
+ sin(this: MathJsChain<number | Unit>): MathJsChain<number>
6273
+ sin(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6274
+ sin(this: MathJsChain<Complex>): MathJsChain<Complex>
6275
+ sin(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6276
+ sin(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5552
6277
 
5553
6278
  /**
5554
6279
  * Calculate the hyperbolic sine of a value, defined as sinh(x) = 1/2 *
5555
6280
  * (exp(x) - exp(-x)). For matrices, the function is evaluated element
5556
6281
  * wise.
5557
6282
  */
5558
- sinh(): MathJsChain
6283
+
6284
+ sinh(this: MathJsChain<number | Unit>): MathJsChain<number>
6285
+ sinh(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6286
+ sinh(this: MathJsChain<Complex>): MathJsChain<Complex>
6287
+ sinh(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6288
+ sinh(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5559
6289
 
5560
6290
  /**
5561
6291
  * Calculate the tangent of a value. tan(x) is equal to sin(x) / cos(x).
5562
6292
  * For matrices, the function is evaluated element wise.
5563
6293
  */
5564
- tan(): MathJsChain
6294
+
6295
+ tan(this: MathJsChain<number | Unit>): MathJsChain<number>
6296
+ tan(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6297
+ tan(this: MathJsChain<Complex>): MathJsChain<Complex>
6298
+ tan(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6299
+ tan(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5565
6300
 
5566
6301
  /**
5567
6302
  * Calculate the hyperbolic tangent of a value, defined as tanh(x) =
5568
6303
  * (exp(2 * x) - 1) / (exp(2 * x) + 1). For matrices, the function is
5569
6304
  * evaluated element wise.
5570
6305
  */
5571
- tanh(): MathJsChain
6306
+
6307
+ tanh(this: MathJsChain<number | Unit>): MathJsChain<number>
6308
+ tanh(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6309
+ tanh(this: MathJsChain<Complex>): MathJsChain<Complex>
6310
+ tanh(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6311
+ tanh(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5572
6312
 
5573
6313
  /*************************************************************************
5574
6314
  * Unit functions
@@ -5580,7 +6320,10 @@ declare namespace math {
5580
6320
  * @param unit New unit. Can be a string like "cm" or a unit without
5581
6321
  * value.
5582
6322
  */
5583
- to(unit: Unit | string): MathJsChain
6323
+ to(
6324
+ this: MathJsChain<Unit | MathCollection>,
6325
+ unit: Unit | string
6326
+ ): MathJsChain<Unit | MathCollection>
5584
6327
 
5585
6328
  /*************************************************************************
5586
6329
  * Utils functions
@@ -5589,60 +6332,86 @@ declare namespace math {
5589
6332
  /**
5590
6333
  * Clone an object.
5591
6334
  */
5592
- clone(): MathJsChain
6335
+
6336
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6337
+ clone<TValue>(this: MathJsChain<TValue>): MathJsChain<TValue>
5593
6338
 
5594
6339
  /**
5595
6340
  * Test whether a value is an integer number. The function supports
5596
6341
  * number, BigNumber, and Fraction. The function is evaluated
5597
6342
  * element-wise in case of Array or Matrix input.
5598
6343
  */
5599
- isInteger(): MathJsChain
6344
+
6345
+ isInteger(
6346
+ this: MathJsChain<number | BigNumber | Fraction | MathCollection>
6347
+ ): MathJsChain<boolean>
5600
6348
 
5601
6349
  /**
5602
6350
  * Test whether a value is NaN (not a number). The function supports
5603
6351
  * types number, BigNumber, Fraction, Unit and Complex. The function is
5604
6352
  * evaluated element-wise in case of Array or Matrix input.
5605
6353
  */
5606
- isNaN(): MathJsChain
6354
+
6355
+ isNaN(
6356
+ this: MathJsChain<number | BigNumber | Fraction | MathCollection | Unit>
6357
+ ): MathJsChain<boolean>
5607
6358
 
5608
6359
  /**
5609
6360
  * Test whether a value is negative: smaller than zero. The function
5610
6361
  * supports types number, BigNumber, Fraction, and Unit. The function is
5611
6362
  * evaluated element-wise in case of Array or Matrix input.
5612
6363
  */
5613
- isNegative(): MathJsChain
6364
+
6365
+ isNegative(
6366
+ this: MathJsChain<number | BigNumber | Fraction | MathCollection | Unit>
6367
+ ): MathJsChain<boolean>
5614
6368
 
5615
6369
  /**
5616
6370
  * Test whether a value is an numeric value. The function is evaluated
5617
6371
  * element-wise in case of Array or Matrix input.
5618
6372
  */
5619
- isNumeric(): MathJsChain
6373
+
6374
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6375
+ isNumeric(this: MathJsChain<any>): MathJsChain<boolean>
5620
6376
 
5621
6377
  /**
5622
6378
  * Test whether a value is positive: larger than zero. The function
5623
6379
  * supports types number, BigNumber, Fraction, and Unit. The function is
5624
6380
  * evaluated element-wise in case of Array or Matrix input.
5625
6381
  */
5626
- isPositive(): MathJsChain
6382
+
6383
+ isPositive(
6384
+ this: MathJsChain<number | BigNumber | Fraction | MathCollection | Unit>
6385
+ ): MathJsChain<boolean>
5627
6386
 
5628
6387
  /**
5629
6388
  * Test whether a value is prime: has no divisors other than itself and
5630
6389
  * one. The function supports type number, bignumber. The function is
5631
6390
  * evaluated element-wise in case of Array or Matrix input.
5632
6391
  */
5633
- isPrime(): MathJsChain
6392
+
6393
+ isPrime(
6394
+ this: MathJsChain<number | BigNumber | MathCollection>
6395
+ ): MathJsChain<boolean>
5634
6396
 
5635
6397
  /**
5636
6398
  * Test whether a value is zero. The function can check for zero for
5637
6399
  * types number, BigNumber, Fraction, Complex, and Unit. The function is
5638
6400
  * evaluated element-wise in case of Array or Matrix input.
5639
6401
  */
5640
- isZero(): MathJsChain
6402
+
6403
+ isZero(
6404
+ this: MathJsChain<
6405
+ number | BigNumber | Fraction | MathCollection | Unit | Complex
6406
+ >
6407
+ ): MathJsChain<boolean>
5641
6408
 
5642
6409
  /**
5643
6410
  * Determine the type of a variable.
5644
6411
  */
5645
- typeOf(): MathJsChain
6412
+
6413
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6414
+ typeOf(this: MathJsChain<any>): MathJsChain<string>
5646
6415
  }
5647
6416
 
5648
6417
  interface ImportOptions {