mathjs 11.3.3 → 11.5.0
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.
- package/HISTORY.md +25 -0
- package/lib/browser/math.js +1 -1
- package/lib/browser/math.js.LICENSE.txt +2 -2
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/entry/dependenciesAny/dependenciesLyap.generated.js +26 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesPolynomialRoot.generated.js +42 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesSchur.generated.js +30 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesSylvester.generated.js +46 -0
- package/lib/cjs/entry/dependenciesAny.generated.js +28 -0
- package/lib/cjs/entry/impureFunctionsAny.generated.js +21 -17
- package/lib/cjs/entry/pureFunctionsAny.generated.js +100 -48
- package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +8 -0
- package/lib/cjs/expression/embeddedDocs/function/algebra/polynomialRoot.js +15 -0
- package/lib/cjs/expression/embeddedDocs/function/matrix/lyap.js +15 -0
- package/lib/cjs/expression/embeddedDocs/function/matrix/reshape.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/matrix/schur.js +15 -0
- package/lib/cjs/expression/embeddedDocs/function/matrix/sylvester.js +15 -0
- package/lib/cjs/factoriesAny.js +28 -0
- package/lib/cjs/function/algebra/decomposition/schur.js +75 -0
- package/lib/cjs/function/algebra/lyap.js +57 -0
- package/lib/cjs/function/algebra/polynomialRoot.js +139 -0
- package/lib/cjs/function/algebra/simplify/wildcards.js +38 -0
- package/lib/cjs/function/algebra/simplify.js +161 -48
- package/lib/cjs/function/algebra/simplifyConstant.js +29 -12
- package/lib/cjs/function/algebra/sylvester.js +127 -0
- package/lib/cjs/function/matrix/forEach.js +1 -1
- package/lib/cjs/function/matrix/reshape.js +1 -1
- package/lib/cjs/function/string/format.js +24 -24
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/version.js +1 -1
- package/lib/esm/entry/dependenciesAny/dependenciesLyap.generated.js +18 -0
- package/lib/esm/entry/dependenciesAny/dependenciesPolynomialRoot.generated.js +34 -0
- package/lib/esm/entry/dependenciesAny/dependenciesSchur.generated.js +22 -0
- package/lib/esm/entry/dependenciesAny/dependenciesSylvester.generated.js +38 -0
- package/lib/esm/entry/dependenciesAny.generated.js +4 -0
- package/lib/esm/entry/impureFunctionsAny.generated.js +22 -18
- package/lib/esm/entry/pureFunctionsAny.generated.js +87 -39
- package/lib/esm/expression/embeddedDocs/embeddedDocs.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/algebra/polynomialRoot.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/matrix/lyap.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/matrix/reshape.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/matrix/schur.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/matrix/sylvester.js +8 -0
- package/lib/esm/factoriesAny.js +4 -0
- package/lib/esm/function/algebra/decomposition/schur.js +70 -0
- package/lib/esm/function/algebra/lyap.js +52 -0
- package/lib/esm/function/algebra/polynomialRoot.js +122 -0
- package/lib/esm/function/algebra/simplify/wildcards.js +20 -0
- package/lib/esm/function/algebra/simplify.js +162 -49
- package/lib/esm/function/algebra/simplifyConstant.js +29 -12
- package/lib/esm/function/algebra/sylvester.js +118 -0
- package/lib/esm/function/matrix/forEach.js +1 -1
- package/lib/esm/function/matrix/reshape.js +1 -1
- package/lib/esm/function/string/format.js +24 -24
- package/lib/esm/version.js +1 -1
- package/package.json +14 -14
- package/types/index.d.ts +88 -6
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.sylvesterDocs = void 0;
|
7
|
+
var sylvesterDocs = {
|
8
|
+
name: 'sylvester',
|
9
|
+
category: 'Matrix',
|
10
|
+
syntax: ['sylvester(A,B,C)'],
|
11
|
+
description: 'Solves the real-valued Sylvester equation AX+XB=C for X',
|
12
|
+
examples: ['sylvester([[-1, -2], [1, 1]], [[-2, 1], [-1, 2]], [[-3, 2], [3, 0]])', 'sylvester(A,B,C)'],
|
13
|
+
seealso: ['schur', 'lyap']
|
14
|
+
};
|
15
|
+
exports.sylvesterDocs = sylvesterDocs;
|
package/lib/cjs/factoriesAny.js
CHANGED
@@ -1083,6 +1083,12 @@ Object.defineProperty(exports, "createLusolve", {
|
|
1083
1083
|
return _lusolve.createLusolve;
|
1084
1084
|
}
|
1085
1085
|
});
|
1086
|
+
Object.defineProperty(exports, "createLyap", {
|
1087
|
+
enumerable: true,
|
1088
|
+
get: function get() {
|
1089
|
+
return _lyap.createLyap;
|
1090
|
+
}
|
1091
|
+
});
|
1086
1092
|
Object.defineProperty(exports, "createMad", {
|
1087
1093
|
enumerable: true,
|
1088
1094
|
get: function get() {
|
@@ -1431,6 +1437,12 @@ Object.defineProperty(exports, "createPlanckTime", {
|
|
1431
1437
|
return _physicalConstants.createPlanckTime;
|
1432
1438
|
}
|
1433
1439
|
});
|
1440
|
+
Object.defineProperty(exports, "createPolynomialRoot", {
|
1441
|
+
enumerable: true,
|
1442
|
+
get: function get() {
|
1443
|
+
return _polynomialRoot.createPolynomialRoot;
|
1444
|
+
}
|
1445
|
+
});
|
1434
1446
|
Object.defineProperty(exports, "createPow", {
|
1435
1447
|
enumerable: true,
|
1436
1448
|
get: function get() {
|
@@ -1635,6 +1647,12 @@ Object.defineProperty(exports, "createSackurTetrode", {
|
|
1635
1647
|
return _physicalConstants.createSackurTetrode;
|
1636
1648
|
}
|
1637
1649
|
});
|
1650
|
+
Object.defineProperty(exports, "createSchur", {
|
1651
|
+
enumerable: true,
|
1652
|
+
get: function get() {
|
1653
|
+
return _schur.createSchur;
|
1654
|
+
}
|
1655
|
+
});
|
1638
1656
|
Object.defineProperty(exports, "createSec", {
|
1639
1657
|
enumerable: true,
|
1640
1658
|
get: function get() {
|
@@ -1893,6 +1911,12 @@ Object.defineProperty(exports, "createSumTransform", {
|
|
1893
1911
|
return _sumTransform.createSumTransform;
|
1894
1912
|
}
|
1895
1913
|
});
|
1914
|
+
Object.defineProperty(exports, "createSylvester", {
|
1915
|
+
enumerable: true,
|
1916
|
+
get: function get() {
|
1917
|
+
return _sylvester.createSylvester;
|
1918
|
+
}
|
1919
|
+
});
|
1896
1920
|
Object.defineProperty(exports, "createSymbolNode", {
|
1897
1921
|
enumerable: true,
|
1898
1922
|
get: function get() {
|
@@ -2285,6 +2309,7 @@ var _lup = require("./function/algebra/decomposition/lup.js");
|
|
2285
2309
|
var _qr = require("./function/algebra/decomposition/qr.js");
|
2286
2310
|
var _slu = require("./function/algebra/decomposition/slu.js");
|
2287
2311
|
var _lusolve = require("./function/algebra/solver/lusolve.js");
|
2312
|
+
var _polynomialRoot = require("./function/algebra/polynomialRoot.js");
|
2288
2313
|
var _Help = require("./expression/Help.js");
|
2289
2314
|
var _Chain = require("./type/chain/Chain.js");
|
2290
2315
|
var _help = require("./expression/function/help.js");
|
@@ -2295,6 +2320,9 @@ var _pinv = require("./function/matrix/pinv.js");
|
|
2295
2320
|
var _eigs = require("./function/matrix/eigs.js");
|
2296
2321
|
var _expm2 = require("./function/matrix/expm.js");
|
2297
2322
|
var _sqrtm = require("./function/matrix/sqrtm.js");
|
2323
|
+
var _sylvester = require("./function/algebra/sylvester.js");
|
2324
|
+
var _schur = require("./function/algebra/decomposition/schur.js");
|
2325
|
+
var _lyap = require("./function/algebra/lyap.js");
|
2298
2326
|
var _divide = require("./function/arithmetic/divide.js");
|
2299
2327
|
var _distance = require("./function/geometry/distance.js");
|
2300
2328
|
var _intersect = require("./function/geometry/intersect.js");
|
@@ -0,0 +1,75 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.createSchur = void 0;
|
7
|
+
var _factory = require("../../../utils/factory.js");
|
8
|
+
var name = 'schur';
|
9
|
+
var dependencies = ['typed', 'matrix', 'identity', 'multiply', 'qr', 'norm', 'subtract'];
|
10
|
+
var createSchur = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
|
11
|
+
var typed = _ref.typed,
|
12
|
+
matrix = _ref.matrix,
|
13
|
+
identity = _ref.identity,
|
14
|
+
multiply = _ref.multiply,
|
15
|
+
qr = _ref.qr,
|
16
|
+
norm = _ref.norm,
|
17
|
+
subtract = _ref.subtract;
|
18
|
+
/**
|
19
|
+
*
|
20
|
+
* Performs a real Schur decomposition of the real matrix A = UTU' where U is orthogonal
|
21
|
+
* and T is upper quasi-triangular.
|
22
|
+
* https://en.wikipedia.org/wiki/Schur_decomposition
|
23
|
+
*
|
24
|
+
* Syntax:
|
25
|
+
*
|
26
|
+
* math.schur(A)
|
27
|
+
*
|
28
|
+
* Examples:
|
29
|
+
*
|
30
|
+
* const A = [[1, 0], [-4, 3]]
|
31
|
+
* math.schur(A) // returns {T: [[3, 4], [0, 1]], R: [[0, 1], [-1, 0]]}
|
32
|
+
*
|
33
|
+
* See also:
|
34
|
+
*
|
35
|
+
* sylvester, lyap, qr
|
36
|
+
*
|
37
|
+
* @param {Array | Matrix} A Matrix A
|
38
|
+
* @return {{U: Array | Matrix, T: Array | Matrix}} Object containing both matrix U and T of the Schur Decomposition A=UTU'
|
39
|
+
*/
|
40
|
+
return typed(name, {
|
41
|
+
Array: function Array(X) {
|
42
|
+
var r = _schur(matrix(X));
|
43
|
+
return {
|
44
|
+
U: r.U.valueOf(),
|
45
|
+
T: r.T.valueOf()
|
46
|
+
};
|
47
|
+
},
|
48
|
+
Matrix: function Matrix(X) {
|
49
|
+
return _schur(X);
|
50
|
+
}
|
51
|
+
});
|
52
|
+
function _schur(X) {
|
53
|
+
var n = X.size()[0];
|
54
|
+
var A = X;
|
55
|
+
var U = identity(n);
|
56
|
+
var k = 0;
|
57
|
+
var A0;
|
58
|
+
do {
|
59
|
+
A0 = A;
|
60
|
+
var QR = qr(A);
|
61
|
+
var Q = QR.Q;
|
62
|
+
var R = QR.R;
|
63
|
+
A = multiply(R, Q);
|
64
|
+
U = multiply(U, Q);
|
65
|
+
if (k++ > 100) {
|
66
|
+
break;
|
67
|
+
}
|
68
|
+
} while (norm(subtract(A, A0)) > 1e-4);
|
69
|
+
return {
|
70
|
+
U: U,
|
71
|
+
T: A
|
72
|
+
};
|
73
|
+
}
|
74
|
+
});
|
75
|
+
exports.createSchur = createSchur;
|
@@ -0,0 +1,57 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.createLyap = void 0;
|
7
|
+
var _factory = require("../../utils/factory.js");
|
8
|
+
var name = 'lyap';
|
9
|
+
var dependencies = ['typed', 'matrix', 'sylvester', 'multiply', 'transpose'];
|
10
|
+
var createLyap = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
|
11
|
+
var typed = _ref.typed,
|
12
|
+
matrix = _ref.matrix,
|
13
|
+
sylvester = _ref.sylvester,
|
14
|
+
multiply = _ref.multiply,
|
15
|
+
transpose = _ref.transpose;
|
16
|
+
/**
|
17
|
+
*
|
18
|
+
* Solves the Continuous-time Lyapunov equation AP+PA'+Q=0 for P, where
|
19
|
+
* Q is an input matrix. When Q is symmetric, P is also symmetric. Notice
|
20
|
+
* that different equivalent definitions exist for the Continuous-time
|
21
|
+
* Lyapunov equation.
|
22
|
+
* https://en.wikipedia.org/wiki/Lyapunov_equation
|
23
|
+
*
|
24
|
+
* Syntax:
|
25
|
+
*
|
26
|
+
* math.lyap(A, Q)
|
27
|
+
*
|
28
|
+
* Examples:
|
29
|
+
*
|
30
|
+
* const A = [[-2, 0], [1, -4]]
|
31
|
+
* const Q = [[3, 1], [1, 3]]
|
32
|
+
* const P = math.lyap(A, Q)
|
33
|
+
*
|
34
|
+
* See also:
|
35
|
+
*
|
36
|
+
* sylvester, schur
|
37
|
+
*
|
38
|
+
* @param {Matrix | Array} A Matrix A
|
39
|
+
* @param {Matrix | Array} Q Matrix Q
|
40
|
+
* @return {Matrix | Array} Matrix P solution to the Continuous-time Lyapunov equation AP+PA'=Q
|
41
|
+
*/
|
42
|
+
return typed(name, {
|
43
|
+
'Matrix, Matrix': function MatrixMatrix(A, Q) {
|
44
|
+
return sylvester(A, transpose(A), multiply(-1, Q));
|
45
|
+
},
|
46
|
+
'Array, Matrix': function ArrayMatrix(A, Q) {
|
47
|
+
return sylvester(matrix(A), transpose(matrix(A)), multiply(-1, Q));
|
48
|
+
},
|
49
|
+
'Matrix, Array': function MatrixArray(A, Q) {
|
50
|
+
return sylvester(A, transpose(matrix(A)), matrix(multiply(-1, Q)));
|
51
|
+
},
|
52
|
+
'Array, Array': function ArrayArray(A, Q) {
|
53
|
+
return sylvester(matrix(A), transpose(matrix(A)), matrix(multiply(-1, Q))).toArray();
|
54
|
+
}
|
55
|
+
});
|
56
|
+
});
|
57
|
+
exports.createLyap = createLyap;
|
@@ -0,0 +1,139 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports.createPolynomialRoot = void 0;
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
9
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
10
|
+
var _factory = require("../../utils/factory.js");
|
11
|
+
var name = 'polynomialRoot';
|
12
|
+
var dependencies = ['typed', 'isZero', 'equalScalar', 'add', 'subtract', 'multiply', 'divide', 'sqrt', 'unaryMinus', 'cbrt', 'typeOf', 'im', 're'];
|
13
|
+
var createPolynomialRoot = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
|
14
|
+
var typed = _ref.typed,
|
15
|
+
isZero = _ref.isZero,
|
16
|
+
equalScalar = _ref.equalScalar,
|
17
|
+
add = _ref.add,
|
18
|
+
subtract = _ref.subtract,
|
19
|
+
multiply = _ref.multiply,
|
20
|
+
divide = _ref.divide,
|
21
|
+
sqrt = _ref.sqrt,
|
22
|
+
unaryMinus = _ref.unaryMinus,
|
23
|
+
cbrt = _ref.cbrt,
|
24
|
+
typeOf = _ref.typeOf,
|
25
|
+
im = _ref.im,
|
26
|
+
re = _ref.re;
|
27
|
+
/**
|
28
|
+
* Finds the numerical values of the distinct roots of a polynomial with real or complex coefficients.
|
29
|
+
* Currently operates only on linear, quadratic, and cubic polynomials using the standard
|
30
|
+
* formulas for the roots.
|
31
|
+
*
|
32
|
+
* Syntax:
|
33
|
+
*
|
34
|
+
* polynomialRoot(constant, linearCoeff, quadraticCoeff, cubicCoeff)
|
35
|
+
*
|
36
|
+
* Examples:
|
37
|
+
* // linear
|
38
|
+
* math.polynomialRoot(6, 3) // [-2]
|
39
|
+
* math.polynomialRoot(math.complex(6,3), 3) // [-2 - i]
|
40
|
+
* math.polynomialRoot(math.complex(6,3), math.complex(2,1)) // [-3 + 0i]
|
41
|
+
* // quadratic
|
42
|
+
* math.polynomialRoot(2, -3, 1) // [2, 1]
|
43
|
+
* math.polynomialRoot(8, 8, 2) // [-2]
|
44
|
+
* math.polynomialRoot(-2, 0, 1) // [1.4142135623730951, -1.4142135623730951]
|
45
|
+
* math.polynomialRoot(2, -2, 1) // [1 + i, 1 - i]
|
46
|
+
* math.polynomialRoot(math.complex(1,3), math.complex(-3, -2), 1) // [2 + i, 1 + i]
|
47
|
+
* // cubic
|
48
|
+
* math.polynomialRoot(-6, 11, -6, 1) // [1, 3, 2]
|
49
|
+
* math.polynomialRoot(-8, 0, 0, 1) // [-1 - 1.7320508075688774i, 2, -1 + 1.7320508075688774i]
|
50
|
+
* math.polynomialRoot(0, 8, 8, 2) // [0, -2]
|
51
|
+
* math.polynomialRoot(1, 1, 1, 1) // [-1 + 0i, 0 - i, 0 + i]
|
52
|
+
*
|
53
|
+
* See also:
|
54
|
+
* cbrt, sqrt
|
55
|
+
*
|
56
|
+
* @param {... number | Complex} coeffs
|
57
|
+
* The coefficients of the polynomial, starting with with the constant coefficent, followed
|
58
|
+
* by the linear coefficient and subsequent coefficients of increasing powers.
|
59
|
+
* @return {Array} The distinct roots of the polynomial
|
60
|
+
*/
|
61
|
+
|
62
|
+
return typed(name, {
|
63
|
+
'number|Complex, ...number|Complex': function numberComplexNumberComplex(constant, restCoeffs) {
|
64
|
+
var coeffs = [constant].concat((0, _toConsumableArray2["default"])(restCoeffs));
|
65
|
+
while (coeffs.length > 0 && isZero(coeffs[coeffs.length - 1])) {
|
66
|
+
coeffs.pop();
|
67
|
+
}
|
68
|
+
if (coeffs.length < 2) {
|
69
|
+
throw new RangeError("Polynomial [".concat(constant, ", ").concat(restCoeffs, "] must have a non-zero non-constant coefficient"));
|
70
|
+
}
|
71
|
+
switch (coeffs.length) {
|
72
|
+
case 2:
|
73
|
+
// linear
|
74
|
+
return [unaryMinus(divide(coeffs[0], coeffs[1]))];
|
75
|
+
case 3:
|
76
|
+
{
|
77
|
+
// quadratic
|
78
|
+
var _coeffs = (0, _slicedToArray2["default"])(coeffs, 3),
|
79
|
+
c = _coeffs[0],
|
80
|
+
b = _coeffs[1],
|
81
|
+
a = _coeffs[2];
|
82
|
+
var denom = multiply(2, a);
|
83
|
+
var d1 = multiply(b, b);
|
84
|
+
var d2 = multiply(4, a, c);
|
85
|
+
if (equalScalar(d1, d2)) return [divide(unaryMinus(b), denom)];
|
86
|
+
var discriminant = sqrt(subtract(d1, d2));
|
87
|
+
return [divide(subtract(discriminant, b), denom), divide(subtract(unaryMinus(discriminant), b), denom)];
|
88
|
+
}
|
89
|
+
case 4:
|
90
|
+
{
|
91
|
+
// cubic, cf. https://en.wikipedia.org/wiki/Cubic_equation
|
92
|
+
var _coeffs2 = (0, _slicedToArray2["default"])(coeffs, 4),
|
93
|
+
d = _coeffs2[0],
|
94
|
+
_c = _coeffs2[1],
|
95
|
+
_b = _coeffs2[2],
|
96
|
+
_a = _coeffs2[3];
|
97
|
+
var _denom = unaryMinus(multiply(3, _a));
|
98
|
+
var D0_1 = multiply(_b, _b);
|
99
|
+
var D0_2 = multiply(3, _a, _c);
|
100
|
+
var D1_1 = add(multiply(2, _b, _b, _b), multiply(27, _a, _a, d));
|
101
|
+
var D1_2 = multiply(9, _a, _b, _c);
|
102
|
+
if (equalScalar(D0_1, D0_2) && equalScalar(D1_1, D1_2)) {
|
103
|
+
return [divide(_b, _denom)];
|
104
|
+
}
|
105
|
+
var Delta0 = subtract(D0_1, D0_2);
|
106
|
+
var Delta1 = subtract(D1_1, D1_2);
|
107
|
+
var discriminant1 = add(multiply(18, _a, _b, _c, d), multiply(_b, _b, _c, _c));
|
108
|
+
var discriminant2 = add(multiply(4, _b, _b, _b, d), multiply(4, _a, _c, _c, _c), multiply(27, _a, _a, d, d));
|
109
|
+
if (equalScalar(discriminant1, discriminant2)) {
|
110
|
+
return [divide(subtract(multiply(4, _a, _b, _c), add(multiply(9, _a, _a, d), multiply(_b, _b, _b))), multiply(_a, Delta0)),
|
111
|
+
// simple root
|
112
|
+
divide(subtract(multiply(9, _a, d), multiply(_b, _c)), multiply(2, Delta0)) // double root
|
113
|
+
];
|
114
|
+
}
|
115
|
+
// OK, we have three distinct roots
|
116
|
+
var Ccubed;
|
117
|
+
if (equalScalar(D0_1, D0_2)) {
|
118
|
+
Ccubed = Delta1;
|
119
|
+
} else {
|
120
|
+
Ccubed = divide(add(Delta1, sqrt(subtract(multiply(Delta1, Delta1), multiply(4, Delta0, Delta0, Delta0)))), 2);
|
121
|
+
}
|
122
|
+
var allRoots = true;
|
123
|
+
var rawRoots = cbrt(Ccubed, allRoots).toArray().map(function (C) {
|
124
|
+
return divide(add(_b, C, divide(Delta0, C)), _denom);
|
125
|
+
});
|
126
|
+
return rawRoots.map(function (r) {
|
127
|
+
if (typeOf(r) === 'Complex' && equalScalar(re(r), re(r) + im(r))) {
|
128
|
+
return re(r);
|
129
|
+
}
|
130
|
+
return r;
|
131
|
+
});
|
132
|
+
}
|
133
|
+
default:
|
134
|
+
throw new RangeError("only implemented for cubic or lower-order polynomials, not ".concat(coeffs));
|
135
|
+
}
|
136
|
+
}
|
137
|
+
});
|
138
|
+
});
|
139
|
+
exports.createPolynomialRoot = createPolynomialRoot;
|
@@ -0,0 +1,38 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.isConstantExpression = isConstantExpression;
|
7
|
+
Object.defineProperty(exports, "isConstantNode", {
|
8
|
+
enumerable: true,
|
9
|
+
get: function get() {
|
10
|
+
return _is.isConstantNode;
|
11
|
+
}
|
12
|
+
});
|
13
|
+
exports.isNumericNode = isNumericNode;
|
14
|
+
Object.defineProperty(exports, "isVariableNode", {
|
15
|
+
enumerable: true,
|
16
|
+
get: function get() {
|
17
|
+
return _is.isSymbolNode;
|
18
|
+
}
|
19
|
+
});
|
20
|
+
var _is = require("../../../utils/is.js");
|
21
|
+
function isNumericNode(x) {
|
22
|
+
return (0, _is.isConstantNode)(x) || (0, _is.isOperatorNode)(x) && x.isUnary() && (0, _is.isConstantNode)(x.args[0]);
|
23
|
+
}
|
24
|
+
function isConstantExpression(x) {
|
25
|
+
if ((0, _is.isConstantNode)(x)) {
|
26
|
+
// Basic Constant types
|
27
|
+
return true;
|
28
|
+
}
|
29
|
+
if (((0, _is.isFunctionNode)(x) || (0, _is.isOperatorNode)(x)) && x.args.every(isConstantExpression)) {
|
30
|
+
// Can be constant depending on arguments
|
31
|
+
return true;
|
32
|
+
}
|
33
|
+
if ((0, _is.isParenthesisNode)(x) && isConstantExpression(x.content)) {
|
34
|
+
// Parenthesis are transparent
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
return false; // Probably missing some edge cases
|
38
|
+
}
|