mathjs 10.4.3 → 10.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. package/HISTORY.md +15 -0
  2. package/docs/reference/functions/lgamma.md +46 -0
  3. package/docs/reference/functions/pinv.md +44 -0
  4. package/docs/reference/functions/pow.md +8 -2
  5. package/docs/reference/functions.md +2 -0
  6. package/lib/browser/math.js +6 -6
  7. package/lib/browser/math.js.map +1 -1
  8. package/lib/cjs/entry/dependenciesAny/dependenciesDet.generated.js +5 -2
  9. package/lib/cjs/entry/dependenciesAny/dependenciesLgamma.generated.js +23 -0
  10. package/lib/cjs/entry/dependenciesAny/dependenciesPinv.generated.js +53 -0
  11. package/lib/cjs/entry/dependenciesAny/dependenciesPow.generated.js +3 -0
  12. package/lib/cjs/entry/dependenciesAny.generated.js +16 -0
  13. package/lib/cjs/entry/dependenciesNumber/dependenciesLgamma.generated.js +20 -0
  14. package/lib/cjs/entry/dependenciesNumber.generated.js +8 -0
  15. package/lib/cjs/entry/impureFunctionsAny.generated.js +96 -94
  16. package/lib/cjs/entry/impureFunctionsNumber.generated.js +5 -4
  17. package/lib/cjs/entry/pureFunctionsAny.generated.js +215 -193
  18. package/lib/cjs/entry/pureFunctionsNumber.generated.js +14 -10
  19. package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +6 -0
  20. package/lib/cjs/expression/embeddedDocs/function/arithmetic/pow.js +1 -1
  21. package/lib/cjs/expression/embeddedDocs/function/matrix/pinv.js +15 -0
  22. package/lib/cjs/expression/embeddedDocs/function/probability/lgamma.js +15 -0
  23. package/lib/cjs/factoriesAny.js +16 -0
  24. package/lib/cjs/factoriesNumber.js +3 -1
  25. package/lib/cjs/function/arithmetic/pow.js +25 -6
  26. package/lib/cjs/function/matrix/det.js +37 -31
  27. package/lib/cjs/function/matrix/pinv.js +223 -0
  28. package/lib/cjs/function/probability/lgamma.js +146 -0
  29. package/lib/cjs/header.js +2 -2
  30. package/lib/cjs/plain/number/probability.js +43 -3
  31. package/lib/cjs/utils/latex.js +6 -0
  32. package/lib/cjs/utils/number.js +17 -2
  33. package/lib/cjs/version.js +1 -1
  34. package/lib/esm/entry/dependenciesAny/dependenciesDet.generated.js +4 -2
  35. package/lib/esm/entry/dependenciesAny/dependenciesLgamma.generated.js +12 -0
  36. package/lib/esm/entry/dependenciesAny/dependenciesPinv.generated.js +32 -0
  37. package/lib/esm/entry/dependenciesAny/dependenciesPow.generated.js +2 -0
  38. package/lib/esm/entry/dependenciesAny.generated.js +2 -0
  39. package/lib/esm/entry/dependenciesNumber/dependenciesLgamma.generated.js +10 -0
  40. package/lib/esm/entry/dependenciesNumber.generated.js +1 -0
  41. package/lib/esm/entry/impureFunctionsAny.generated.js +90 -88
  42. package/lib/esm/entry/impureFunctionsNumber.generated.js +6 -5
  43. package/lib/esm/entry/pureFunctionsAny.generated.js +179 -159
  44. package/lib/esm/entry/pureFunctionsNumber.generated.js +8 -5
  45. package/lib/esm/expression/embeddedDocs/embeddedDocs.js +4 -0
  46. package/lib/esm/expression/embeddedDocs/function/arithmetic/pow.js +1 -1
  47. package/lib/esm/expression/embeddedDocs/function/matrix/pinv.js +8 -0
  48. package/lib/esm/expression/embeddedDocs/function/probability/lgamma.js +8 -0
  49. package/lib/esm/factoriesAny.js +2 -0
  50. package/lib/esm/factoriesNumber.js +2 -1
  51. package/lib/esm/function/arithmetic/pow.js +25 -6
  52. package/lib/esm/function/matrix/det.js +35 -31
  53. package/lib/esm/function/matrix/pinv.js +205 -0
  54. package/lib/esm/function/probability/lgamma.js +137 -0
  55. package/lib/esm/plain/number/probability.js +33 -1
  56. package/lib/esm/utils/latex.js +6 -0
  57. package/lib/esm/utils/number.js +13 -1
  58. package/lib/esm/version.js +1 -1
  59. package/package.json +7 -7
  60. package/types/index.d.ts +22 -1
  61. package/types/index.ts +10 -0
package/HISTORY.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # History
2
2
 
3
+ # 2022-04-19, version 10.5.0
4
+
5
+ - Implement #1563: function `pinv`, Moore–Penrose inverse (#2521).
6
+ Thanks @HanchaiN.
7
+ - Optimize function `det` for integers by switching to the Bareiss algorithm:
8
+ no more round-off errors for integer input (#2516). Thanks @HanchaiN.
9
+ - Implement #2463: allow negative integer powers of invertible square matrices
10
+ (#2517). Thanks @HanchaiN.
11
+ - Implement the `lgamma` function (defined as log(gamma(z))) for number and
12
+ Complex types. Supersedes #320. (#2417). Thanks @yifanwww.
13
+ - Fix #2523: update to the latest complex.js to improve `sin(z)` for small
14
+ `im(z)` (#2525). Thanks @gwhitney.
15
+ - Fix #2526: update TypeScript definition of `ceil` (#2531). Thanks @simlaticak
16
+ - Change mocha reporter to 'dot' to avoid excessively long log files. (#2520)
17
+
3
18
 
4
19
  # 2022-04-08, version 10.4.3
5
20
 
@@ -0,0 +1,46 @@
1
+ <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
+
3
+ # Function lgamma
4
+
5
+ Logarithm of the gamma function for real, positive numbers and complex numbers,
6
+ using Lanczos approximation for numbers and Stirling series for complex numbers.
7
+
8
+
9
+ ## Syntax
10
+
11
+ ```js
12
+ math.lgamma(n)
13
+ ```
14
+
15
+ ### Parameters
16
+
17
+ Parameter | Type | Description
18
+ --------- | ---- | -----------
19
+ `n` | number &#124; Complex | A real or complex number
20
+
21
+ ### Returns
22
+
23
+ Type | Description
24
+ ---- | -----------
25
+ number &#124; Complex | The log gamma of `n`
26
+
27
+
28
+ ### Throws
29
+
30
+ Type | Description
31
+ ---- | -----------
32
+
33
+
34
+ ## Examples
35
+
36
+ ```js
37
+ math.lgamma(5) // returns 3.178053830347945
38
+ math.lgamma(0) // returns Infinity
39
+ math.lgamma(-0.5) // returns NaN
40
+ math.lgamma(math.i) // returns -0.6509231993018536 - 1.8724366472624294i
41
+ ```
42
+
43
+
44
+ ## See also
45
+
46
+ [gamma](gamma.md)
@@ -0,0 +1,44 @@
1
+ <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
+
3
+ # Function pinv
4
+
5
+ Calculate the Moore–Penrose inverse of a matrix.
6
+
7
+
8
+ ## Syntax
9
+
10
+ ```js
11
+ math.pinv(x)
12
+ ```
13
+
14
+ ### Parameters
15
+
16
+ Parameter | Type | Description
17
+ --------- | ---- | -----------
18
+ `x` | number &#124; Complex &#124; Array &#124; Matrix | Matrix to be inversed
19
+
20
+ ### Returns
21
+
22
+ Type | Description
23
+ ---- | -----------
24
+ number &#124; Complex &#124; Array &#124; Matrix | The inverse of `x`.
25
+
26
+
27
+ ### Throws
28
+
29
+ Type | Description
30
+ ---- | -----------
31
+
32
+
33
+ ## Examples
34
+
35
+ ```js
36
+ math.pinv([[1, 2], [3, 4]]) // returns [[-2, 1], [1.5, -0.5]]
37
+ math.pinv([[1, 0], [0, 1], [0, 1]]) // returns [[1, 0, 0], [0, 0.5, 0.5]]
38
+ math.pinv(4) // returns 0.25
39
+ ```
40
+
41
+
42
+ ## See also
43
+
44
+ [inv](inv.md)
@@ -3,8 +3,11 @@
3
3
  # Function pow
4
4
 
5
5
  Calculates the power of x to y, `x ^ y`.
6
- Matrix exponentiation is supported for square matrices `x`, and positive
7
- integer exponents `y`.
6
+
7
+ Matrix exponentiation is supported for square matrices `x` and integers `y`:
8
+ when `y` is nonnegative, `x` may be any square matrix; and when `y` is
9
+ negative, `x` must be invertible, and then this function returns
10
+ inv(x)^(-y).
8
11
 
9
12
  For cubic roots of negative numbers, the function returns the principal
10
13
  root by default. In order to let the function return the real root,
@@ -48,6 +51,9 @@ math.pow(a, 2) // returns Complex -5 + 12i
48
51
 
49
52
  const b = [[1, 2], [4, 3]]
50
53
  math.pow(b, 2) // returns Array [[9, 8], [16, 17]]
54
+
55
+ const c = [[1, 2], [4, 3]]
56
+ math.pow(c, -1) // returns Array [[-0.6, 0.4], [0.8, -0.2]]
51
57
  ```
52
58
 
53
59
 
@@ -144,6 +144,7 @@ Function | Description
144
144
  [math.matrixFromRows(...arr)](functions/matrixFromRows.md) | Create a dense matrix from vectors as individual rows.
145
145
  [math.ones(m,&nbsp;n,&nbsp;p,&nbsp;...)](functions/ones.md) | Create a matrix filled with ones.
146
146
  [math.partitionSelect(x,&nbsp;k)](functions/partitionSelect.md) | Partition-based selection of an array or 1D matrix.
147
+ [math.pinv(x)](functions/pinv.md) | Calculate the Moore–Penrose inverse of a matrix.
147
148
  [math.range(start,&nbsp;end&nbsp;[,&nbsp;step])](functions/range.md) | Create an array from a range.
148
149
  [math.reshape(x,&nbsp;sizes)](functions/reshape.md) | Reshape a multi dimensional array to fit the specified dimensions.
149
150
  [math.resize(x,&nbsp;size&nbsp;[,&nbsp;defaultValue])](functions/resize.md) | Resize a matrix.
@@ -168,6 +169,7 @@ Function | Description
168
169
  [math.factorial(n)](functions/factorial.md) | Compute the factorial of a value Factorial only supports an integer value as argument.
169
170
  [math.gamma(n)](functions/gamma.md) | Compute the gamma function of a value using Lanczos approximation for small values, and an extended Stirling approximation for large values.
170
171
  [math.kldivergence(x,&nbsp;y)](functions/kldivergence.md) | Calculate the Kullback-Leibler (KL) divergence between two distributions.
172
+ [math.lgamma(n)](functions/lgamma.md) | Logarithm of the gamma function for real, positive numbers and complex numbers, using Lanczos approximation for numbers and Stirling series for complex numbers.
171
173
  [math.multinomial(a)](functions/multinomial.md) | Multinomial Coefficients compute the number of ways of picking a1, a2, .
172
174
  [math.permutations(n&nbsp;[,&nbsp;k])](functions/permutations.md) | Compute the number of ways of obtaining an ordered subset of `k` elements from a set of `n` elements.
173
175
  [math.pickRandom(array)](functions/pickRandom.md) | Random pick one or more values from a one dimensional array.