mathjs 10.0.0 → 10.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/HISTORY.md +7 -0
- package/examples/expressions.js +1 -1
- package/lib/browser/math.js +3 -3
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/function/probability/gamma.js +28 -30
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/version.js +1 -1
- package/lib/esm/function/probability/gamma.js +28 -30
- package/lib/esm/version.js +1 -1
- package/package.json +1 -1
@@ -49,44 +49,42 @@ var createGamma = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
49
49
|
Complex: function Complex(n) {
|
50
50
|
if (n.im === 0) {
|
51
51
|
return this(n.re);
|
52
|
-
}
|
52
|
+
} // Lanczos approximation doesn't work well with real part lower than 0.5
|
53
|
+
// So reflection formula is required
|
54
|
+
|
55
|
+
|
56
|
+
if (n.re < 0.5) {
|
57
|
+
// Euler's reflection formula
|
58
|
+
// gamma(1-z) * gamma(z) = PI / sin(PI * z)
|
59
|
+
// real part of Z should not be integer [sin(PI) == 0 -> 1/0 - undefined]
|
60
|
+
// thanks to imperfect sin implementation sin(PI * n) != 0
|
61
|
+
// we can safely use it anyway
|
62
|
+
var _t = new _Complex(1 - n.re, -n.im);
|
63
|
+
|
64
|
+
var r = new _Complex(Math.PI * n.re, Math.PI * n.im);
|
65
|
+
return new _Complex(Math.PI).div(r.sin()).div(this(_t));
|
66
|
+
} // Lanczos approximation
|
67
|
+
// z -= 1
|
68
|
+
|
53
69
|
|
54
|
-
n = new _Complex(n.re - 1, n.im);
|
55
|
-
|
70
|
+
n = new _Complex(n.re - 1, n.im); // x = gammaPval[0]
|
71
|
+
|
72
|
+
var x = new _Complex(_index.gammaP[0], 0); // for (i, gammaPval) in enumerate(gammaP):
|
56
73
|
|
57
74
|
for (var i = 1; i < _index.gammaP.length; ++i) {
|
58
|
-
|
75
|
+
// x += gammaPval / (z + i)
|
76
|
+
var gammaPval = new _Complex(_index.gammaP[i], 0);
|
77
|
+
x = x.add(gammaPval.div(n.add(i)));
|
78
|
+
} // t = z + gammaG + 0.5
|
59
79
|
|
60
|
-
var den = real * real + n.im * n.im;
|
61
80
|
|
62
|
-
|
63
|
-
x.re += _index.gammaP[i] * real / den;
|
64
|
-
x.im += -(_index.gammaP[i] * n.im) / den;
|
65
|
-
} else {
|
66
|
-
x.re = _index.gammaP[i] < 0 ? -Infinity : Infinity;
|
67
|
-
}
|
68
|
-
}
|
81
|
+
var t = new _Complex(n.re + _index.gammaG + 0.5, n.im); // y = sqrt(2 * pi) * t ** (z + 0.5) * exp(-t) * x
|
69
82
|
|
70
|
-
var t = new _Complex(n.re + _index.gammaG + 0.5, n.im);
|
71
83
|
var twoPiSqrt = Math.sqrt(2 * Math.PI);
|
72
|
-
n.
|
73
|
-
var
|
74
|
-
|
75
|
-
if (result.im === 0) {
|
76
|
-
// sqrt(2*PI)*result
|
77
|
-
result.re *= twoPiSqrt;
|
78
|
-
} else if (result.re === 0) {
|
79
|
-
result.im *= twoPiSqrt;
|
80
|
-
} else {
|
81
|
-
result.re *= twoPiSqrt;
|
82
|
-
result.im *= twoPiSqrt;
|
83
|
-
}
|
84
|
-
|
85
|
-
var r = Math.exp(-t.re); // exp(-t)
|
84
|
+
var tpow = t.pow(n.add(0.5));
|
85
|
+
var expt = t.neg().exp(); // y = [x] * [sqrt(2 * pi)] * [t ** (z + 0.5)] * [exp(-t)]
|
86
86
|
|
87
|
-
|
88
|
-
t.im = r * Math.sin(-t.im);
|
89
|
-
return multiplyScalar(multiplyScalar(result, t), x);
|
87
|
+
return x.mul(twoPiSqrt).mul(tpow).mul(expt);
|
90
88
|
},
|
91
89
|
BigNumber: function BigNumber(n) {
|
92
90
|
if (n.isInteger()) {
|
package/lib/cjs/header.js
CHANGED
@@ -6,8 +6,8 @@
|
|
6
6
|
* It features real and complex numbers, units, matrices, a large set of
|
7
7
|
* mathematical functions, and a flexible expression parser.
|
8
8
|
*
|
9
|
-
* @version 10.0.
|
10
|
-
* @date 2021-
|
9
|
+
* @version 10.0.1
|
10
|
+
* @date 2021-12-22
|
11
11
|
*
|
12
12
|
* @license
|
13
13
|
* Copyright (C) 2013-2021 Jos de Jong <wjosdejong@gmail.com>
|
package/lib/cjs/version.js
CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.version = void 0;
|
7
|
-
var version = '10.0.
|
7
|
+
var version = '10.0.1'; // Note: This file is automatically generated when building math.js.
|
8
8
|
// Changes made in this file will be overwritten.
|
9
9
|
|
10
10
|
exports.version = version;
|
@@ -41,44 +41,42 @@ export var createGamma = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
41
41
|
Complex: function Complex(n) {
|
42
42
|
if (n.im === 0) {
|
43
43
|
return this(n.re);
|
44
|
-
}
|
44
|
+
} // Lanczos approximation doesn't work well with real part lower than 0.5
|
45
|
+
// So reflection formula is required
|
46
|
+
|
47
|
+
|
48
|
+
if (n.re < 0.5) {
|
49
|
+
// Euler's reflection formula
|
50
|
+
// gamma(1-z) * gamma(z) = PI / sin(PI * z)
|
51
|
+
// real part of Z should not be integer [sin(PI) == 0 -> 1/0 - undefined]
|
52
|
+
// thanks to imperfect sin implementation sin(PI * n) != 0
|
53
|
+
// we can safely use it anyway
|
54
|
+
var _t = new _Complex(1 - n.re, -n.im);
|
55
|
+
|
56
|
+
var r = new _Complex(Math.PI * n.re, Math.PI * n.im);
|
57
|
+
return new _Complex(Math.PI).div(r.sin()).div(this(_t));
|
58
|
+
} // Lanczos approximation
|
59
|
+
// z -= 1
|
60
|
+
|
45
61
|
|
46
|
-
n = new _Complex(n.re - 1, n.im);
|
47
|
-
|
62
|
+
n = new _Complex(n.re - 1, n.im); // x = gammaPval[0]
|
63
|
+
|
64
|
+
var x = new _Complex(gammaP[0], 0); // for (i, gammaPval) in enumerate(gammaP):
|
48
65
|
|
49
66
|
for (var i = 1; i < gammaP.length; ++i) {
|
50
|
-
|
67
|
+
// x += gammaPval / (z + i)
|
68
|
+
var gammaPval = new _Complex(gammaP[i], 0);
|
69
|
+
x = x.add(gammaPval.div(n.add(i)));
|
70
|
+
} // t = z + gammaG + 0.5
|
51
71
|
|
52
|
-
var den = real * real + n.im * n.im;
|
53
72
|
|
54
|
-
|
55
|
-
x.re += gammaP[i] * real / den;
|
56
|
-
x.im += -(gammaP[i] * n.im) / den;
|
57
|
-
} else {
|
58
|
-
x.re = gammaP[i] < 0 ? -Infinity : Infinity;
|
59
|
-
}
|
60
|
-
}
|
73
|
+
var t = new _Complex(n.re + gammaG + 0.5, n.im); // y = sqrt(2 * pi) * t ** (z + 0.5) * exp(-t) * x
|
61
74
|
|
62
|
-
var t = new _Complex(n.re + gammaG + 0.5, n.im);
|
63
75
|
var twoPiSqrt = Math.sqrt(2 * Math.PI);
|
64
|
-
n.
|
65
|
-
var
|
66
|
-
|
67
|
-
if (result.im === 0) {
|
68
|
-
// sqrt(2*PI)*result
|
69
|
-
result.re *= twoPiSqrt;
|
70
|
-
} else if (result.re === 0) {
|
71
|
-
result.im *= twoPiSqrt;
|
72
|
-
} else {
|
73
|
-
result.re *= twoPiSqrt;
|
74
|
-
result.im *= twoPiSqrt;
|
75
|
-
}
|
76
|
-
|
77
|
-
var r = Math.exp(-t.re); // exp(-t)
|
76
|
+
var tpow = t.pow(n.add(0.5));
|
77
|
+
var expt = t.neg().exp(); // y = [x] * [sqrt(2 * pi)] * [t ** (z + 0.5)] * [exp(-t)]
|
78
78
|
|
79
|
-
|
80
|
-
t.im = r * Math.sin(-t.im);
|
81
|
-
return multiplyScalar(multiplyScalar(result, t), x);
|
79
|
+
return x.mul(twoPiSqrt).mul(tpow).mul(expt);
|
82
80
|
},
|
83
81
|
BigNumber: function BigNumber(n) {
|
84
82
|
if (n.isInteger()) {
|
package/lib/esm/version.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export var version = '10.0.
|
1
|
+
export var version = '10.0.1'; // Note: This file is automatically generated when building math.js.
|
2
2
|
// Changes made in this file will be overwritten.
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "mathjs",
|
3
|
-
"version": "10.0.
|
3
|
+
"version": "10.0.1",
|
4
4
|
"description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with different data types like numbers, big numbers, complex numbers, fractions, units, and matrices.",
|
5
5
|
"author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
|
6
6
|
"homepage": "https://mathjs.org",
|