pimath 0.2.5 → 0.2.6
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/dist/pimath.js +430 -389
- package/dist/pimath.js.map +1 -1
- package/package.json +1 -1
- package/src/algebra/factor.ts +46 -4
- package/src/algebra/polyFactor.ts +34 -18
- package/src/helpers.ts +27 -0
- package/types/algebra/factor.d.ts +2 -0
- package/types/algebra/factor.d.ts.map +1 -1
- package/types/algebra/polyFactor.d.ts +2 -1
- package/types/algebra/polyFactor.d.ts.map +1 -1
- package/types/helpers.d.ts +1 -0
- package/types/helpers.d.ts.map +1 -1
package/dist/pimath.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
function
|
|
2
|
-
const t =
|
|
1
|
+
function ft(n) {
|
|
2
|
+
const t = rt(n), e = [];
|
|
3
3
|
let i, s;
|
|
4
4
|
for (; t.length > 0; )
|
|
5
5
|
i = t.shift() ?? 1, s = (t.length > 0 ? t.pop() : +i) ?? 1, e.push([i, s]);
|
|
6
6
|
return e;
|
|
7
7
|
}
|
|
8
|
-
function
|
|
9
|
-
const t =
|
|
8
|
+
function dt(...n) {
|
|
9
|
+
const t = _(...n);
|
|
10
10
|
return n.map((e) => e / t);
|
|
11
11
|
}
|
|
12
|
-
function
|
|
12
|
+
function rt(n) {
|
|
13
13
|
const t = Math.abs(n), e = Math.sqrt(t), i = [];
|
|
14
14
|
for (let s = 1; s <= e; s++)
|
|
15
15
|
n % s === 0 && (i.push(s), i.push(t / s));
|
|
@@ -17,7 +17,7 @@ function st(n) {
|
|
|
17
17
|
return s - r;
|
|
18
18
|
}), [...new Set(i)];
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function _(...n) {
|
|
21
21
|
const t = function(s, r) {
|
|
22
22
|
return isNaN(s) || isNaN(r) ? NaN : r === 0 ? s : s === 0 ? r : t(r, s % r);
|
|
23
23
|
};
|
|
@@ -32,34 +32,34 @@ function J(...n) {
|
|
|
32
32
|
;
|
|
33
33
|
return Math.abs(e);
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function pt(...n) {
|
|
36
36
|
return n.reduce(function(t, e) {
|
|
37
|
-
return Math.abs(t * e /
|
|
37
|
+
return Math.abs(t * e / _(t, e));
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
|
-
function
|
|
40
|
+
function mt(n, t = 3) {
|
|
41
41
|
return +n.toFixed(t);
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function gt(n) {
|
|
44
44
|
if (Number.isSafeInteger(n) || n.toString().split(".")[0].length < 10)
|
|
45
45
|
return 0;
|
|
46
46
|
throw new Error("Periodic value: Not implemented yet");
|
|
47
47
|
}
|
|
48
|
-
function
|
|
48
|
+
function wt(n) {
|
|
49
49
|
const t = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919, 7927, 7933, 7937, 7949, 7951, 7963, 7993, 8009, 8011, 8017, 8039, 8053, 8059, 8069, 8081, 8087, 8089, 8093, 8101, 8111, 8117, 8123, 8147, 8161, 8167, 8171, 8179, 8191, 8209, 8219, 8221, 8231, 8233, 8237, 8243, 8263, 8269, 8273, 8287, 8291, 8293, 8297, 8311, 8317, 8329, 8353, 8363, 8369, 8377, 8387, 8389, 8419, 8423, 8429, 8431, 8443, 8447, 8461, 8467, 8501, 8513, 8521, 8527, 8537, 8539, 8543, 8563, 8573, 8581, 8597, 8599, 8609, 8623, 8627, 8629, 8641, 8647, 8663, 8669, 8677, 8681, 8689, 8693, 8699, 8707, 8713, 8719, 8731, 8737, 8741, 8747, 8753, 8761, 8779, 8783, 8803, 8807, 8819, 8821, 8831, 8837, 8839, 8849, 8861, 8863, 8867, 8887, 8893, 8923, 8929, 8933, 8941, 8951, 8963, 8969, 8971, 8999, 9001, 9007, 9011, 9013, 9029, 9041, 9043, 9049, 9059, 9067, 9091, 9103, 9109, 9127, 9133, 9137, 9151, 9157, 9161, 9173, 9181, 9187, 9199, 9203, 9209, 9221, 9227, 9239, 9241, 9257, 9277, 9281, 9283, 9293, 9311, 9319, 9323, 9337, 9341, 9343, 9349, 9371, 9377, 9391, 9397, 9403, 9413, 9419, 9421, 9431, 9433, 9437, 9439, 9461, 9463, 9467, 9473, 9479, 9491, 9497, 9511, 9521, 9533, 9539, 9547, 9551, 9587, 9601, 9613, 9619, 9623, 9629, 9631, 9643, 9649, 9661, 9677, 9679, 9689, 9697, 9719, 9721, 9733, 9739, 9743, 9749, 9767, 9769, 9781, 9787, 9791, 9803, 9811, 9817, 9829, 9833, 9839, 9851, 9857, 9859, 9871, 9883, 9887, 9901, 9907, 9923, 9929, 9931, 9941, 9949, 9967, 9973];
|
|
50
50
|
return n === void 0 ? t : t.slice(0, Math.min(t.length, n));
|
|
51
51
|
}
|
|
52
|
-
function
|
|
52
|
+
function yt(n, t) {
|
|
53
53
|
const e = [], i = t === !0 ? +n : n ** 2;
|
|
54
54
|
for (let s = 0; s <= n; s++)
|
|
55
55
|
for (let r = 0; r <= n; r++)
|
|
56
56
|
s ** 2 + r ** 2 === i && e.push([s, r, n]);
|
|
57
57
|
return e;
|
|
58
58
|
}
|
|
59
|
-
function
|
|
59
|
+
function vt(n, t = 2) {
|
|
60
60
|
return +`${Math.round(+`${n}e${t}`)}e-${t}`;
|
|
61
61
|
}
|
|
62
|
-
function
|
|
62
|
+
function xt(n, t) {
|
|
63
63
|
let e = Math.floor(Math.pow(n, 1 / t));
|
|
64
64
|
const i = n, s = 1;
|
|
65
65
|
for (; e > 1; ) {
|
|
@@ -70,20 +70,20 @@ function vt(n, t) {
|
|
|
70
70
|
}
|
|
71
71
|
return s;
|
|
72
72
|
}
|
|
73
|
-
const
|
|
74
|
-
decompose:
|
|
75
|
-
dividers:
|
|
76
|
-
divideNumbersByGCD:
|
|
77
|
-
gcd:
|
|
78
|
-
lcm:
|
|
79
|
-
numberCorrection:
|
|
80
|
-
periodic:
|
|
81
|
-
primes:
|
|
82
|
-
pythagoreanTripletsWithTarget:
|
|
83
|
-
round:
|
|
84
|
-
greatestPower:
|
|
73
|
+
const b = {
|
|
74
|
+
decompose: ft,
|
|
75
|
+
dividers: rt,
|
|
76
|
+
divideNumbersByGCD: dt,
|
|
77
|
+
gcd: _,
|
|
78
|
+
lcm: pt,
|
|
79
|
+
numberCorrection: mt,
|
|
80
|
+
periodic: gt,
|
|
81
|
+
primes: wt,
|
|
82
|
+
pythagoreanTripletsWithTarget: yt,
|
|
83
|
+
round: vt,
|
|
84
|
+
greatestPower: xt
|
|
85
85
|
};
|
|
86
|
-
var
|
|
86
|
+
var bt = /* @__PURE__ */ ((n) => (n.frac = "frac", n.dfrac = "dfrac", n.tfrac = "tfrac", n))(bt || {});
|
|
87
87
|
class h {
|
|
88
88
|
#t = 1;
|
|
89
89
|
#e = 3;
|
|
@@ -156,7 +156,7 @@ class h {
|
|
|
156
156
|
return e && s.reverse(), s;
|
|
157
157
|
};
|
|
158
158
|
static toSameDenominateur(...t) {
|
|
159
|
-
const e = t.map((s) => new h(s)), i =
|
|
159
|
+
const e = t.map((s) => new h(s)), i = b.lcm(...e.map((s) => s.denominator));
|
|
160
160
|
return e.forEach((s) => s.amplify(i / s.denominator)), e;
|
|
161
161
|
}
|
|
162
162
|
static unique = (t) => {
|
|
@@ -244,7 +244,7 @@ class h {
|
|
|
244
244
|
if (Number.isSafeInteger(t))
|
|
245
245
|
return this.#s = t, this.#t = 1, this.#i = !0, this;
|
|
246
246
|
const [, e] = t.toString().split("."), i = e ? e.length : 0, s = Math.pow(10, i);
|
|
247
|
-
return this.#s = t * s, this.#t = s, this.#s =
|
|
247
|
+
return this.#s = t * s, this.#t = s, this.#s = b.numberCorrection(this.#s), this.#t = b.numberCorrection(this.#t), this.reduce(), this.#i = i < 10, this;
|
|
248
248
|
}
|
|
249
249
|
fromNumbers(t, e) {
|
|
250
250
|
return Number.isSafeInteger(t) && Number.isSafeInteger(e) ? (this.#s = t, this.#t = e, this.#i = !0, this) : this.fromNumber(t / e);
|
|
@@ -285,7 +285,7 @@ class h {
|
|
|
285
285
|
isOne = () => this.#s === 1 && this.#t === 1;
|
|
286
286
|
isPositive = () => this.sign() === 1;
|
|
287
287
|
isRational = () => this.exact && !this.isRelative();
|
|
288
|
-
isReduced = () => Math.abs(
|
|
288
|
+
isReduced = () => Math.abs(b.gcd(this.#s, this.#t)) === 1;
|
|
289
289
|
isRelative = () => this.exact && this.clone().reduce().denominator === 1;
|
|
290
290
|
isSquare = () => Math.sqrt(this.#s) % 1 === 0 && Math.sqrt(this.#t) % 1 === 0;
|
|
291
291
|
isStrictlyNegative = () => this.value < 0;
|
|
@@ -316,7 +316,7 @@ class h {
|
|
|
316
316
|
return r === i && o === s ? (this.#s = r, this.#t = o) : (this.#s = i / s, this.#t = 1, this.exact = !1), this;
|
|
317
317
|
};
|
|
318
318
|
reduce = () => {
|
|
319
|
-
const t =
|
|
319
|
+
const t = b.gcd(this.#s, this.#t);
|
|
320
320
|
return this.#s = this.#s / t, this.#t = this.#t / t, this.#t < 0 && (this.#t = -this.#t, this.#s = -this.#s), this;
|
|
321
321
|
};
|
|
322
322
|
root = (t) => {
|
|
@@ -349,7 +349,7 @@ class h {
|
|
|
349
349
|
}
|
|
350
350
|
zero = () => this.fromNumber(0);
|
|
351
351
|
}
|
|
352
|
-
function
|
|
352
|
+
function st(n, t = !0) {
|
|
353
353
|
return t ? `\\left( ${n} \\right)` : `(${n})`;
|
|
354
354
|
}
|
|
355
355
|
function Q(n) {
|
|
@@ -358,6 +358,17 @@ function Q(n) {
|
|
|
358
358
|
function j(n, t, e, i, s) {
|
|
359
359
|
return n.map((r, o) => r === t ? e : r);
|
|
360
360
|
}
|
|
361
|
+
function H(n, t) {
|
|
362
|
+
if (t.length !== 1)
|
|
363
|
+
throw new Error(`splitChar must be a single character, got: "${t}"`);
|
|
364
|
+
let e = 0, i = 0;
|
|
365
|
+
const s = [];
|
|
366
|
+
for (let r = 0; r < n.length; r++) {
|
|
367
|
+
const o = n[r];
|
|
368
|
+
o === "(" ? e++ : o === ")" ? e-- : o === t && e === 0 && (s.push(n.substring(i, r)), i = r + 1);
|
|
369
|
+
}
|
|
370
|
+
return s.push(n.substring(i)), s;
|
|
371
|
+
}
|
|
361
372
|
class T {
|
|
362
373
|
#t;
|
|
363
374
|
#e;
|
|
@@ -464,7 +475,7 @@ class T {
|
|
|
464
475
|
}
|
|
465
476
|
pow(t) {
|
|
466
477
|
this.factor.pow(t);
|
|
467
|
-
const e =
|
|
478
|
+
const e = b.gcd(this.index, t);
|
|
468
479
|
return this.index = this.index / e, this.radical.pow(t / e), this;
|
|
469
480
|
}
|
|
470
481
|
get radical() {
|
|
@@ -478,7 +489,7 @@ class T {
|
|
|
478
489
|
const e = this.radical.denominator;
|
|
479
490
|
this.radical.denominator = 1, this.radical.numerator *= e, this.factor.divide(e);
|
|
480
491
|
}
|
|
481
|
-
const t =
|
|
492
|
+
const t = b.greatestPower(this.radical.value, this.index);
|
|
482
493
|
return this.factor.multiply(Math.pow(t, 1 / this.index)), this.radical.divide(t), this;
|
|
483
494
|
}
|
|
484
495
|
root(t) {
|
|
@@ -492,7 +503,7 @@ class T {
|
|
|
492
503
|
return this.add(e.opposite());
|
|
493
504
|
}
|
|
494
505
|
get value() {
|
|
495
|
-
return
|
|
506
|
+
return b.numberCorrection(this.factor.value * Math.pow(this.radical.value, 1 / this.index));
|
|
496
507
|
}
|
|
497
508
|
get withSign() {
|
|
498
509
|
return this.#s = !0, this;
|
|
@@ -568,8 +579,8 @@ class C {
|
|
|
568
579
|
if (a.isNegative())
|
|
569
580
|
return [];
|
|
570
581
|
if (a.isSquare()) {
|
|
571
|
-
const m = a.sqrt(), d = r.clone().opposite().subtract(m).divide(s.clone().multiply(2)),
|
|
572
|
-
return m.isZero() ? [C.fromFraction(d)] : [C.fromFraction(d), C.fromFraction(
|
|
582
|
+
const m = a.sqrt(), d = r.clone().opposite().subtract(m).divide(s.clone().multiply(2)), v = r.clone().opposite().add(m).divide(s.clone().multiply(2));
|
|
583
|
+
return m.isZero() ? [C.fromFraction(d)] : [C.fromFraction(d), C.fromFraction(v)];
|
|
573
584
|
}
|
|
574
585
|
const c = new C();
|
|
575
586
|
c.fraction = r.clone().opposite().divide(s).divide(2), c.root = new T().from(2, a, s.clone().multiply(2).inverse().opposite()), c.setExact(!1);
|
|
@@ -619,11 +630,11 @@ class C {
|
|
|
619
630
|
t !== void 0 && (this.#o = t);
|
|
620
631
|
}
|
|
621
632
|
}
|
|
622
|
-
class
|
|
633
|
+
class jt {
|
|
623
634
|
#t;
|
|
624
635
|
#e;
|
|
625
636
|
constructor(t) {
|
|
626
|
-
t instanceof N || t instanceof
|
|
637
|
+
t instanceof N || t instanceof y ? this.#t = new N(t) : this.#t = new N().fromPolynom(t), this.#e = this.#t.getRoots();
|
|
627
638
|
}
|
|
628
639
|
get fx() {
|
|
629
640
|
return this.#t;
|
|
@@ -689,8 +700,8 @@ class R {
|
|
|
689
700
|
if (m === d)
|
|
690
701
|
e.push(this.#r(m));
|
|
691
702
|
else {
|
|
692
|
-
const
|
|
693
|
-
|
|
703
|
+
const v = this.#o(t, m, d);
|
|
704
|
+
v !== null && e.push(this.#s(v));
|
|
694
705
|
}
|
|
695
706
|
}), e;
|
|
696
707
|
}
|
|
@@ -711,7 +722,7 @@ class R {
|
|
|
711
722
|
#a(t, e, i) {
|
|
712
723
|
const s = [], r = 2 * e / i;
|
|
713
724
|
for (let o = -e; o <= e; o += r) {
|
|
714
|
-
const a =
|
|
725
|
+
const a = b.numberCorrection(o);
|
|
715
726
|
s.push(
|
|
716
727
|
{
|
|
717
728
|
x: a,
|
|
@@ -736,13 +747,13 @@ class R {
|
|
|
736
747
|
const s = t.monomByDegree().coefficient, r = t.monomByDegree(0).coefficient;
|
|
737
748
|
if (r.isZero()) {
|
|
738
749
|
e.push(this.#r(0));
|
|
739
|
-
const d = t.monoms.reduce((q, $) => $.degree().value < q.degree().value ? $ : q),
|
|
740
|
-
d.clone().divide(
|
|
750
|
+
const d = t.monoms.reduce((q, $) => $.degree().value < q.degree().value ? $ : q), v = d.coefficient;
|
|
751
|
+
d.clone().divide(v), t.divide(d);
|
|
741
752
|
}
|
|
742
|
-
const o =
|
|
753
|
+
const o = b.dividers(s.value), a = b.dividers(r.value), c = [];
|
|
743
754
|
for (const d of o)
|
|
744
|
-
for (const
|
|
745
|
-
const q = new h(
|
|
755
|
+
for (const v of a) {
|
|
756
|
+
const q = new h(v, d);
|
|
746
757
|
c.find(($) => $.value === q.value) || (c.push(q.clone()), c.push(q.opposite().clone()));
|
|
747
758
|
}
|
|
748
759
|
c.forEach((d) => {
|
|
@@ -751,20 +762,20 @@ class R {
|
|
|
751
762
|
for (const d of e) {
|
|
752
763
|
if (d.isZero())
|
|
753
764
|
continue;
|
|
754
|
-
const
|
|
755
|
-
for (d.count = 0; t.isDividableBy(
|
|
756
|
-
t.divide(
|
|
765
|
+
const v = t.clone().fromCoefficients(d.fraction.denominator, -d.fraction.numerator);
|
|
766
|
+
for (d.count = 0; t.isDividableBy(v); )
|
|
767
|
+
t.divide(v), d.count++;
|
|
757
768
|
}
|
|
758
769
|
if (t.degree().isZero() || t.degree().value > 3)
|
|
759
|
-
return e.sort((d,
|
|
770
|
+
return e.sort((d, v) => d.value - v.value), { solutions: e, reminder: t };
|
|
760
771
|
const f = t.clone().zero(), m = new R(t, f, this.#i);
|
|
761
772
|
return {
|
|
762
|
-
solutions: e.concat(m.solve()).sort((d,
|
|
773
|
+
solutions: e.concat(m.solve()).sort((d, v) => d.value - v.value),
|
|
763
774
|
reminder: f
|
|
764
775
|
};
|
|
765
776
|
}
|
|
766
777
|
#h() {
|
|
767
|
-
const t = this.#e, e = t.monomByDegree(3).coefficient, i = t.monomByDegree(2).coefficient, s = t.monomByDegree(1).coefficient, r = t.monomByDegree(0).coefficient, o = i.clone().divide(e), a = s.clone().divide(e), c = r.clone().divide(e), f = a.clone().subtract(o.clone().pow(2).divide(3)), m = c.clone().subtract(o.clone().multiply(a).divide(3)).add(o.clone().pow(3).multiply(2).divide(27)), d = m.clone().opposite(),
|
|
778
|
+
const t = this.#e, e = t.monomByDegree(3).coefficient, i = t.monomByDegree(2).coefficient, s = t.monomByDegree(1).coefficient, r = t.monomByDegree(0).coefficient, o = i.clone().divide(e), a = s.clone().divide(e), c = r.clone().divide(e), f = a.clone().subtract(o.clone().pow(2).divide(3)), m = c.clone().subtract(o.clone().multiply(a).divide(3)).add(o.clone().pow(3).multiply(2).divide(27)), d = m.clone().opposite(), v = f.clone().opposite().pow(3).divide(27), q = d.clone().pow(2).subtract(v.clone().multiply(4)).opposite();
|
|
768
779
|
if (q.isNegative()) {
|
|
769
780
|
const $ = m.clone().opposite().add(q.clone().opposite().sqrt()).divide(2).root(3), k = m.clone().opposite().subtract(q.clone().opposite().sqrt()).divide(2).root(3), I = $.clone().add(k).subtract(o.clone().divide(3));
|
|
770
781
|
return [this.#r(I)];
|
|
@@ -780,7 +791,7 @@ class R {
|
|
|
780
791
|
const $ = [], k = f.value, I = m.value, Y = o.value;
|
|
781
792
|
for (let M = 0; M < 3; M++)
|
|
782
793
|
$.push(2 * Math.sqrt(-k / 3) * Math.cos(Math.acos(3 * I / (2 * k) * Math.sqrt(-3 / k)) / 3 + 2 * Math.PI * M / 3) - Y / 3);
|
|
783
|
-
return $.map((M) => this.#s(M)).sort((M,
|
|
794
|
+
return $.map((M) => this.#s(M)).sort((M, ut) => M.value - ut.value);
|
|
784
795
|
}
|
|
785
796
|
return [];
|
|
786
797
|
}
|
|
@@ -816,103 +827,103 @@ class R {
|
|
|
816
827
|
return o.fraction = e.clone().opposite().divide(s.clone()), o.root.radical = i.clone(), o.root.factor = new h().one().divide(s.clone()).opposite(), o.exact = !0, [r, o].sort((a, c) => a.value - c.value);
|
|
817
828
|
}
|
|
818
829
|
}
|
|
819
|
-
const
|
|
830
|
+
const tt = {
|
|
820
831
|
pi: Math.PI,
|
|
821
832
|
e: Math.exp(1)
|
|
822
833
|
};
|
|
823
|
-
var
|
|
824
|
-
function
|
|
834
|
+
var u = /* @__PURE__ */ ((n) => (n.VARIABLE = "variable", n.COEFFICIENT = "coefficient", n.OPERATION = "operation", n.CONSTANT = "constant", n.FUNCTION = "function", n.FUNCTION_ARGUMENT = "function-argument", n.MONOM = "monom", n.LEFT_PARENTHESIS = "(", n.RIGHT_PARENTHESIS = ")", n))(u || {}), S = /* @__PURE__ */ ((n) => (n.EXPRESSION = "expression", n.POLYNOM = "polynom", n.SET = "set", n.NUMERIC = "numeric", n))(S || {});
|
|
835
|
+
function Et(n, t) {
|
|
825
836
|
if (n.length <= 1)
|
|
826
837
|
return n;
|
|
827
|
-
const e = Object.keys(t).filter((d) => t[d].type ===
|
|
828
|
-
e.sort((d,
|
|
829
|
-
const i = new RegExp(`^(${e.join("|")})\\(`), s = Object.keys(
|
|
830
|
-
s.sort((d,
|
|
838
|
+
const e = Object.keys(t).filter((d) => t[d].type === u.FUNCTION).map((d) => d);
|
|
839
|
+
e.sort((d, v) => v.length - d.length);
|
|
840
|
+
const i = new RegExp(`^(${e.join("|")})\\(`), s = Object.keys(tt);
|
|
841
|
+
s.sort((d, v) => v.length - d.length);
|
|
831
842
|
const r = new RegExp(`^(${s.join("|")})`), o = /^(\d+(\.\d+)?)/;
|
|
832
843
|
let a = "", c, f, m;
|
|
833
844
|
for (e.forEach((d) => {
|
|
834
845
|
if (n.includes(d)) {
|
|
835
|
-
const
|
|
836
|
-
n = n.replaceAll(
|
|
846
|
+
const v = new RegExp(`${d}([0-9.]+)`, "g");
|
|
847
|
+
n = n.replaceAll(v, `${d}($1)`);
|
|
837
848
|
}
|
|
838
849
|
}); n.length > 0; ) {
|
|
839
850
|
if (c = f, m = void 0, e.length > 0 && i.exec(n)) {
|
|
840
|
-
const d = e.find((
|
|
841
|
-
d && (m = d + "(", n = n.slice(d.length + 1), f =
|
|
851
|
+
const d = e.find((v) => n.startsWith(v));
|
|
852
|
+
d && (m = d + "(", n = n.slice(d.length + 1), f = u.FUNCTION);
|
|
842
853
|
} else if (s.length > 0 && r.exec(n)) {
|
|
843
|
-
const d = s.find((
|
|
844
|
-
d && (m = d, n = n.slice(d.length), f =
|
|
854
|
+
const d = s.find((v) => n.startsWith(v));
|
|
855
|
+
d && (m = d, n = n.slice(d.length), f = u.CONSTANT);
|
|
845
856
|
} else if (o.exec(n)) {
|
|
846
857
|
const d = o.exec(n);
|
|
847
|
-
d && (m = d[0], n = n.slice(d[0].length), f =
|
|
858
|
+
d && (m = d[0], n = n.slice(d[0].length), f = u.COEFFICIENT);
|
|
848
859
|
} else
|
|
849
860
|
switch (m = n[0], n = n.slice(1), m) {
|
|
850
861
|
case "(":
|
|
851
|
-
f =
|
|
862
|
+
f = u.LEFT_PARENTHESIS;
|
|
852
863
|
break;
|
|
853
864
|
case ")":
|
|
854
|
-
f =
|
|
865
|
+
f = u.RIGHT_PARENTHESIS;
|
|
855
866
|
break;
|
|
856
867
|
case ",":
|
|
857
|
-
f =
|
|
868
|
+
f = u.FUNCTION_ARGUMENT;
|
|
858
869
|
break;
|
|
859
870
|
case "+":
|
|
860
871
|
case "-":
|
|
861
872
|
case "*":
|
|
862
873
|
case "/":
|
|
863
874
|
case "^":
|
|
864
|
-
f =
|
|
875
|
+
f = u.OPERATION;
|
|
865
876
|
break;
|
|
866
877
|
default:
|
|
867
|
-
f =
|
|
878
|
+
f = u.VARIABLE;
|
|
868
879
|
}
|
|
869
880
|
if (m === void 0 || f === void 0)
|
|
870
881
|
throw new Error("The token is undefined");
|
|
871
|
-
a +=
|
|
882
|
+
a += Nt(c, f), a += m;
|
|
872
883
|
}
|
|
873
884
|
return a;
|
|
874
885
|
}
|
|
875
|
-
function
|
|
876
|
-
return n === void 0 || n ===
|
|
886
|
+
function Nt(n, t) {
|
|
887
|
+
return n === void 0 || n === u.OPERATION || t === u.OPERATION || n === u.LEFT_PARENTHESIS || n === u.FUNCTION || n === u.FUNCTION_ARGUMENT || t === u.RIGHT_PARENTHESIS || t === u.FUNCTION_ARGUMENT ? "" : "*";
|
|
877
888
|
}
|
|
878
|
-
const
|
|
879
|
-
"^": { precedence: 4, associative: "right", type:
|
|
880
|
-
"*": { precedence: 3, associative: "left", type:
|
|
881
|
-
"/": { precedence: 3, associative: "left", type:
|
|
882
|
-
"+": { precedence: 2, associative: "left", type:
|
|
883
|
-
"-": { precedence: 2, associative: "left", type:
|
|
884
|
-
}, At = {
|
|
885
|
-
"^": { precedence: 4, associative: "right", type: l.OPERATION },
|
|
886
|
-
"*": { precedence: 3, associative: "left", type: l.OPERATION },
|
|
887
|
-
"/": { precedence: 3, associative: "left", type: l.OPERATION },
|
|
888
|
-
"+": { precedence: 2, associative: "left", type: l.OPERATION },
|
|
889
|
-
"-": { precedence: 2, associative: "left", type: l.OPERATION },
|
|
890
|
-
"%": { precedence: 3, associative: "right", type: l.OPERATION },
|
|
891
|
-
sin: { precedence: 4, associative: "right", type: l.FUNCTION },
|
|
892
|
-
cos: { precedence: 4, associative: "right", type: l.FUNCTION },
|
|
893
|
-
tan: { precedence: 4, associative: "right", type: l.FUNCTION },
|
|
894
|
-
sqrt: { precedence: 4, associative: "right", type: l.FUNCTION },
|
|
895
|
-
nthrt: { precedence: 4, associative: "right", type: l.FUNCTION },
|
|
896
|
-
",": { precedence: 2, associative: "left", type: l.FUNCTION_ARGUMENT }
|
|
889
|
+
const At = {
|
|
890
|
+
"^": { precedence: 4, associative: "right", type: u.OPERATION },
|
|
891
|
+
"*": { precedence: 3, associative: "left", type: u.OPERATION },
|
|
892
|
+
"/": { precedence: 3, associative: "left", type: u.OPERATION },
|
|
893
|
+
"+": { precedence: 2, associative: "left", type: u.OPERATION },
|
|
894
|
+
"-": { precedence: 2, associative: "left", type: u.OPERATION }
|
|
897
895
|
}, Tt = {
|
|
898
|
-
"^": { precedence: 4, associative: "right", type:
|
|
899
|
-
"*": { precedence: 3, associative: "left", type:
|
|
900
|
-
"/": { precedence: 3, associative: "left", type:
|
|
901
|
-
"+": { precedence: 2, associative: "left", type:
|
|
902
|
-
"-": { precedence: 2, associative: "left", type:
|
|
903
|
-
"%": { precedence: 3, associative: "right", type:
|
|
904
|
-
sin: { precedence: 4, associative: "right", type:
|
|
905
|
-
cos: { precedence: 4, associative: "right", type:
|
|
906
|
-
tan: { precedence: 4, associative: "right", type:
|
|
907
|
-
sqrt: { precedence: 4, associative: "right", type:
|
|
908
|
-
nthrt: { precedence: 4, associative: "right", type:
|
|
909
|
-
|
|
910
|
-
log: { precedence: 4, associative: "right", type: l.FUNCTION }
|
|
896
|
+
"^": { precedence: 4, associative: "right", type: u.OPERATION },
|
|
897
|
+
"*": { precedence: 3, associative: "left", type: u.OPERATION },
|
|
898
|
+
"/": { precedence: 3, associative: "left", type: u.OPERATION },
|
|
899
|
+
"+": { precedence: 2, associative: "left", type: u.OPERATION },
|
|
900
|
+
"-": { precedence: 2, associative: "left", type: u.OPERATION },
|
|
901
|
+
"%": { precedence: 3, associative: "right", type: u.OPERATION },
|
|
902
|
+
sin: { precedence: 4, associative: "right", type: u.FUNCTION },
|
|
903
|
+
cos: { precedence: 4, associative: "right", type: u.FUNCTION },
|
|
904
|
+
tan: { precedence: 4, associative: "right", type: u.FUNCTION },
|
|
905
|
+
sqrt: { precedence: 4, associative: "right", type: u.FUNCTION },
|
|
906
|
+
nthrt: { precedence: 4, associative: "right", type: u.FUNCTION },
|
|
907
|
+
",": { precedence: 2, associative: "left", type: u.FUNCTION_ARGUMENT }
|
|
911
908
|
}, Ot = {
|
|
912
|
-
"
|
|
913
|
-
"
|
|
914
|
-
"
|
|
915
|
-
"
|
|
909
|
+
"^": { precedence: 4, associative: "right", type: u.OPERATION },
|
|
910
|
+
"*": { precedence: 3, associative: "left", type: u.OPERATION },
|
|
911
|
+
"/": { precedence: 3, associative: "left", type: u.OPERATION },
|
|
912
|
+
"+": { precedence: 2, associative: "left", type: u.OPERATION },
|
|
913
|
+
"-": { precedence: 2, associative: "left", type: u.OPERATION },
|
|
914
|
+
"%": { precedence: 3, associative: "right", type: u.OPERATION },
|
|
915
|
+
sin: { precedence: 4, associative: "right", type: u.FUNCTION },
|
|
916
|
+
cos: { precedence: 4, associative: "right", type: u.FUNCTION },
|
|
917
|
+
tan: { precedence: 4, associative: "right", type: u.FUNCTION },
|
|
918
|
+
sqrt: { precedence: 4, associative: "right", type: u.FUNCTION },
|
|
919
|
+
nthrt: { precedence: 4, associative: "right", type: u.FUNCTION },
|
|
920
|
+
ln: { precedence: 4, associative: "right", type: u.FUNCTION },
|
|
921
|
+
log: { precedence: 4, associative: "right", type: u.FUNCTION }
|
|
922
|
+
}, Ct = {
|
|
923
|
+
"&": { precedence: 3, associative: "left", type: u.OPERATION },
|
|
924
|
+
"|": { precedence: 3, associative: "left", type: u.OPERATION },
|
|
925
|
+
"!": { precedence: 4, associative: "right", type: u.OPERATION },
|
|
926
|
+
"-": { precedence: 2, associative: "left", type: u.OPERATION }
|
|
916
927
|
};
|
|
917
928
|
class G {
|
|
918
929
|
#t;
|
|
@@ -931,7 +942,7 @@ class G {
|
|
|
931
942
|
return this.#e.map((t) => t.token);
|
|
932
943
|
}
|
|
933
944
|
tokenConfigInitialization() {
|
|
934
|
-
return this.#t === S.SET ? (this.#i =
|
|
945
|
+
return this.#t === S.SET ? (this.#i = Ct, this.#r = !1) : this.#t === S.NUMERIC ? (this.#i = Ot, this.#r = !0) : this.#t === S.EXPRESSION ? (this.#i = Tt, this.#r = !0) : (this.#i = At, this.#r = !0), this.#s = Object.keys(this.#i).sort((t, e) => e.length - t.length), this.#i;
|
|
935
946
|
}
|
|
936
947
|
/**
|
|
937
948
|
* Get the next token to analyse.
|
|
@@ -941,31 +952,31 @@ class G {
|
|
|
941
952
|
NextToken(t, e) {
|
|
942
953
|
let i, s;
|
|
943
954
|
if (i = "", s = void 0, t[e] === "(")
|
|
944
|
-
i = "(", s =
|
|
955
|
+
i = "(", s = u.LEFT_PARENTHESIS;
|
|
945
956
|
else if (t[e] === ")")
|
|
946
|
-
i = ")", s =
|
|
957
|
+
i = ")", s = u.RIGHT_PARENTHESIS;
|
|
947
958
|
else if (t[e] === ",")
|
|
948
|
-
i = ",", s =
|
|
959
|
+
i = ",", s = u.FUNCTION_ARGUMENT;
|
|
949
960
|
else {
|
|
950
961
|
for (const r of this.#s)
|
|
951
962
|
if (t.substring(e, e + r.length) === r) {
|
|
952
963
|
i += r, s = this.#i[r].type;
|
|
953
964
|
break;
|
|
954
965
|
}
|
|
955
|
-
for (const r in
|
|
966
|
+
for (const r in tt)
|
|
956
967
|
if (t.substring(e, e + r.length) === r) {
|
|
957
|
-
i += r, s =
|
|
968
|
+
i += r, s = u.CONSTANT;
|
|
958
969
|
break;
|
|
959
970
|
}
|
|
960
971
|
if (i === "")
|
|
961
972
|
if (/[0-9.]/.exec(t[e])) {
|
|
962
973
|
const r = /^([0-9.]+)/.exec(t.substring(e));
|
|
963
|
-
i = r ? r[0] : "", s =
|
|
974
|
+
i = r ? r[0] : "", s = u.COEFFICIENT;
|
|
964
975
|
} else if (/[a-zA-Z]/.exec(t[e])) {
|
|
965
976
|
const r = /^([a-zA-Z])/.exec(t.substring(e));
|
|
966
|
-
i = r ? r[0] : "", s =
|
|
977
|
+
i = r ? r[0] : "", s = u.VARIABLE;
|
|
967
978
|
} else
|
|
968
|
-
console.log("Unidentified token", t[e], t, e), i = t[e], s =
|
|
979
|
+
console.log("Unidentified token", t[e], t, e), i = t[e], s = u.MONOM;
|
|
969
980
|
}
|
|
970
981
|
if (s === void 0)
|
|
971
982
|
throw new Error(`Token type is undefined for token ${i}`);
|
|
@@ -980,7 +991,7 @@ class G {
|
|
|
980
991
|
parse(t, e) {
|
|
981
992
|
const i = [], s = [];
|
|
982
993
|
let r = "", o = 0, a;
|
|
983
|
-
(e ?? this.#r) && (t =
|
|
994
|
+
(e ?? this.#r) && (t = Et(t, this.#i));
|
|
984
995
|
let c = 50, f;
|
|
985
996
|
for (; o < t.length; ) {
|
|
986
997
|
if (c--, c === 0) {
|
|
@@ -988,16 +999,16 @@ class G {
|
|
|
988
999
|
break;
|
|
989
1000
|
}
|
|
990
1001
|
switch ([r, o, a] = this.NextToken(t, o), a) {
|
|
991
|
-
case
|
|
992
|
-
case
|
|
993
|
-
case
|
|
994
|
-
case
|
|
1002
|
+
case u.MONOM:
|
|
1003
|
+
case u.COEFFICIENT:
|
|
1004
|
+
case u.VARIABLE:
|
|
1005
|
+
case u.CONSTANT:
|
|
995
1006
|
i.push({
|
|
996
1007
|
token: r,
|
|
997
1008
|
tokenType: a
|
|
998
1009
|
});
|
|
999
1010
|
break;
|
|
1000
|
-
case
|
|
1011
|
+
case u.OPERATION:
|
|
1001
1012
|
if (s.length > 0) {
|
|
1002
1013
|
let m = s[s.length - 1];
|
|
1003
1014
|
for (f = 50; m.token in this.#i && //either o1 is left-associative and its precedence is less than or equal to that of o2,
|
|
@@ -1007,14 +1018,14 @@ class G {
|
|
|
1007
1018
|
console.log("SECURITY LEVEL 2 OPERATION EXIT");
|
|
1008
1019
|
break;
|
|
1009
1020
|
}
|
|
1010
|
-
if (i.push(s.pop() ?? { token: "", tokenType:
|
|
1021
|
+
if (i.push(s.pop() ?? { token: "", tokenType: u.OPERATION }), s.length === 0)
|
|
1011
1022
|
break;
|
|
1012
1023
|
m = s[s.length - 1];
|
|
1013
1024
|
}
|
|
1014
1025
|
}
|
|
1015
1026
|
s.push({ token: r, tokenType: a });
|
|
1016
1027
|
break;
|
|
1017
|
-
case
|
|
1028
|
+
case u.FUNCTION_ARGUMENT:
|
|
1018
1029
|
for (f = 50; s[s.length - 1].token !== "(" && s.length > 0; ) {
|
|
1019
1030
|
if (f--, f === 0) {
|
|
1020
1031
|
console.log("SECURITY LEVEL 2 FUNCTION ARGUMENT EXIT");
|
|
@@ -1023,10 +1034,10 @@ class G {
|
|
|
1023
1034
|
i.push(s.pop() ?? { token: r, tokenType: a });
|
|
1024
1035
|
}
|
|
1025
1036
|
break;
|
|
1026
|
-
case
|
|
1027
|
-
s.push({ token: r, tokenType: a }), t[o] === "-" && i.push({ token: "0", tokenType:
|
|
1037
|
+
case u.LEFT_PARENTHESIS:
|
|
1038
|
+
s.push({ token: r, tokenType: a }), t[o] === "-" && i.push({ token: "0", tokenType: u.COEFFICIENT });
|
|
1028
1039
|
break;
|
|
1029
|
-
case
|
|
1040
|
+
case u.RIGHT_PARENTHESIS:
|
|
1030
1041
|
for (f = 50; s[s.length - 1].token !== "(" && s.length > 1; ) {
|
|
1031
1042
|
if (f--, f === 0) {
|
|
1032
1043
|
console.log("SECURITY LEVEL 2 CLOSING PARENTHESIS EXIT");
|
|
@@ -1036,7 +1047,7 @@ class G {
|
|
|
1036
1047
|
}
|
|
1037
1048
|
s.pop();
|
|
1038
1049
|
break;
|
|
1039
|
-
case
|
|
1050
|
+
case u.FUNCTION:
|
|
1040
1051
|
s.push({ token: r, tokenType: a });
|
|
1041
1052
|
break;
|
|
1042
1053
|
default:
|
|
@@ -1046,7 +1057,7 @@ class G {
|
|
|
1046
1057
|
return this.#e = i.concat(s.reverse()), this;
|
|
1047
1058
|
}
|
|
1048
1059
|
}
|
|
1049
|
-
class
|
|
1060
|
+
class qt {
|
|
1050
1061
|
_rpn;
|
|
1051
1062
|
_expression;
|
|
1052
1063
|
_isValid;
|
|
@@ -1082,7 +1093,7 @@ class Ct {
|
|
|
1082
1093
|
return this._isValid = !1, 0;
|
|
1083
1094
|
this._isValid = !0;
|
|
1084
1095
|
for (const i of this._rpn)
|
|
1085
|
-
if (i.tokenType ===
|
|
1096
|
+
if (i.tokenType === u.COEFFICIENT)
|
|
1086
1097
|
if (!isNaN(+i.token))
|
|
1087
1098
|
e.push(+i.token);
|
|
1088
1099
|
else {
|
|
@@ -1091,11 +1102,11 @@ class Ct {
|
|
|
1091
1102
|
throw this._isValid = !1, new Error("This coefficient is not a fraction");
|
|
1092
1103
|
e.push(+s[0] / +s[1]);
|
|
1093
1104
|
}
|
|
1094
|
-
else if (i.tokenType ===
|
|
1105
|
+
else if (i.tokenType === u.VARIABLE && t !== void 0)
|
|
1095
1106
|
Object.hasOwn(t, i.token) && e.push(+t[i.token]);
|
|
1096
|
-
else if (i.tokenType ===
|
|
1097
|
-
e.push(
|
|
1098
|
-
else if (i.tokenType ===
|
|
1107
|
+
else if (i.tokenType === u.CONSTANT)
|
|
1108
|
+
e.push(tt[i.token]);
|
|
1109
|
+
else if (i.tokenType === u.OPERATION) {
|
|
1099
1110
|
if (i.token === "*") {
|
|
1100
1111
|
const s = e.pop(), r = e.pop();
|
|
1101
1112
|
if (r === void 0 || s === void 0)
|
|
@@ -1122,7 +1133,7 @@ class Ct {
|
|
|
1122
1133
|
throw this._isValid = !1, new Error(`The base value ${r ?? "a"} or exponent ${s ?? "b"} are not defined`);
|
|
1123
1134
|
e.push(Math.pow(r, s));
|
|
1124
1135
|
}
|
|
1125
|
-
} else if (i.tokenType ===
|
|
1136
|
+
} else if (i.tokenType === u.FUNCTION) {
|
|
1126
1137
|
const s = e.pop();
|
|
1127
1138
|
if (s === void 0)
|
|
1128
1139
|
throw this._isValid = !1, new Error(`The parameters for ${i.token} is not defined`);
|
|
@@ -1190,7 +1201,7 @@ class p {
|
|
|
1190
1201
|
for (const r of t)
|
|
1191
1202
|
if (r.containsRationalPower())
|
|
1192
1203
|
return new p().zero();
|
|
1193
|
-
const e = new p(), i =
|
|
1204
|
+
const e = new p(), i = b.gcd(...t.map((r) => r.coefficient.numerator)), s = b.lcm(...t.map((r) => r.coefficient.denominator));
|
|
1194
1205
|
e.coefficient = new h(i, s).reduce();
|
|
1195
1206
|
for (const r of t) {
|
|
1196
1207
|
for (const o in e.literal)
|
|
@@ -1275,7 +1286,7 @@ class p {
|
|
|
1275
1286
|
return [this.clone()];
|
|
1276
1287
|
if (this.coefficient.numerator > 1e6)
|
|
1277
1288
|
return [this.clone()];
|
|
1278
|
-
const t =
|
|
1289
|
+
const t = b.dividers(Math.abs(this.coefficient.numerator));
|
|
1279
1290
|
let e = [];
|
|
1280
1291
|
for (const s in this.literal)
|
|
1281
1292
|
e = this.#n(e, s);
|
|
@@ -1568,12 +1579,12 @@ class p {
|
|
|
1568
1579
|
}
|
|
1569
1580
|
#o = (t, e) => {
|
|
1570
1581
|
let i, s, r, o, a;
|
|
1571
|
-
if (e.tokenType ===
|
|
1582
|
+
if (e.tokenType === u.COEFFICIENT)
|
|
1572
1583
|
t.push(new p(new h(e.token)));
|
|
1573
|
-
else if (e.tokenType ===
|
|
1584
|
+
else if (e.tokenType === u.VARIABLE) {
|
|
1574
1585
|
const c = new p().one();
|
|
1575
1586
|
c.setLetter(e.token, 1), t.push(c.clone());
|
|
1576
|
-
} else if (e.tokenType ===
|
|
1587
|
+
} else if (e.tokenType === u.OPERATION)
|
|
1577
1588
|
switch (e.token) {
|
|
1578
1589
|
case "-":
|
|
1579
1590
|
s = t.pop() ?? new p().zero(), i = t.pop() ?? new p().zero(), t.push(i.subtract(s));
|
|
@@ -1596,14 +1607,14 @@ class p {
|
|
|
1596
1607
|
return this.zero(), this;
|
|
1597
1608
|
if (i.length === 1) {
|
|
1598
1609
|
const r = i[0];
|
|
1599
|
-
return this.one(), r.tokenType ===
|
|
1610
|
+
return this.one(), r.tokenType === u.COEFFICIENT ? this.coefficient = new h(r.token) : r.tokenType === u.VARIABLE && this.setLetter(r.token, 1), this;
|
|
1600
1611
|
} else
|
|
1601
1612
|
for (const r of i)
|
|
1602
1613
|
this.#o(s, r);
|
|
1603
1614
|
return this.one(), this.multiply(s[0]), this;
|
|
1604
1615
|
};
|
|
1605
1616
|
}
|
|
1606
|
-
function
|
|
1617
|
+
function nt(n, t) {
|
|
1607
1618
|
if (!Number.isSafeInteger(t))
|
|
1608
1619
|
throw new Error("Can only raise item by an integer");
|
|
1609
1620
|
if (t < 0)
|
|
@@ -1615,7 +1626,7 @@ function rt(n, t) {
|
|
|
1615
1626
|
n.multiply(e);
|
|
1616
1627
|
return n;
|
|
1617
1628
|
}
|
|
1618
|
-
class
|
|
1629
|
+
class l {
|
|
1619
1630
|
#t = "x";
|
|
1620
1631
|
#e;
|
|
1621
1632
|
#i;
|
|
@@ -1638,7 +1649,7 @@ class u {
|
|
|
1638
1649
|
this.#i.push(new p(t)), e.forEach((i) => {
|
|
1639
1650
|
this.#i.push(new p(i));
|
|
1640
1651
|
});
|
|
1641
|
-
else if (t instanceof
|
|
1652
|
+
else if (t instanceof l)
|
|
1642
1653
|
for (const i of t.monoms)
|
|
1643
1654
|
this.#i.push(i.clone());
|
|
1644
1655
|
return this;
|
|
@@ -1647,7 +1658,7 @@ class u {
|
|
|
1647
1658
|
* Clone the polynom
|
|
1648
1659
|
*/
|
|
1649
1660
|
clone() {
|
|
1650
|
-
const t = new
|
|
1661
|
+
const t = new l(), e = [];
|
|
1651
1662
|
t.#t = this.#t;
|
|
1652
1663
|
for (const i of this.#i)
|
|
1653
1664
|
e.push(i.clone());
|
|
@@ -1660,14 +1671,14 @@ class u {
|
|
|
1660
1671
|
return this.#l();
|
|
1661
1672
|
}
|
|
1662
1673
|
static xMultiply(...t) {
|
|
1663
|
-
const e = new
|
|
1674
|
+
const e = new l().one();
|
|
1664
1675
|
return t.forEach((i) => {
|
|
1665
1676
|
e.multiply(i);
|
|
1666
1677
|
}), e;
|
|
1667
1678
|
}
|
|
1668
1679
|
add(...t) {
|
|
1669
1680
|
for (const e of t)
|
|
1670
|
-
e instanceof
|
|
1681
|
+
e instanceof l ? this.#i = this.#i.concat(e.monoms.map((i) => i.clone())) : e instanceof p ? this.#i.push(e.clone()) : typeof e == "number" && Number.isSafeInteger(e) ? this.#i.push(new p(e.toString())) : this.#i.push(new p(e));
|
|
1671
1682
|
return this.reduce();
|
|
1672
1683
|
}
|
|
1673
1684
|
commonMonom() {
|
|
@@ -1688,7 +1699,7 @@ class u {
|
|
|
1688
1699
|
return e;
|
|
1689
1700
|
}
|
|
1690
1701
|
derivative(t) {
|
|
1691
|
-
const e = new
|
|
1702
|
+
const e = new l();
|
|
1692
1703
|
for (const i of this.#i)
|
|
1693
1704
|
e.add(i.derivative(t));
|
|
1694
1705
|
return e.reduce();
|
|
@@ -1699,8 +1710,8 @@ class u {
|
|
|
1699
1710
|
if (typeof t == "number" && Number.isSafeInteger(t))
|
|
1700
1711
|
return this.#a(t);
|
|
1701
1712
|
if (t instanceof p)
|
|
1702
|
-
return this.divide(new
|
|
1703
|
-
if (t instanceof
|
|
1713
|
+
return this.divide(new l(t));
|
|
1714
|
+
if (t instanceof l) {
|
|
1704
1715
|
if (t.monoms.length === 1 && t.variables.length === 0)
|
|
1705
1716
|
return this.#o(t.monoms[0].coefficient);
|
|
1706
1717
|
{
|
|
@@ -1709,7 +1720,7 @@ class u {
|
|
|
1709
1720
|
return this.#i = e.monoms, this.#h(), this;
|
|
1710
1721
|
}
|
|
1711
1722
|
} else if (typeof t == "string")
|
|
1712
|
-
return this.divide(new
|
|
1723
|
+
return this.divide(new l(t));
|
|
1713
1724
|
throw new Error(`Cannot divide by ${t}`);
|
|
1714
1725
|
}
|
|
1715
1726
|
empty() {
|
|
@@ -1721,11 +1732,11 @@ class u {
|
|
|
1721
1732
|
* returns {quotient: Polynom, reminder: Polynom}
|
|
1722
1733
|
*/
|
|
1723
1734
|
euclidean(t) {
|
|
1724
|
-
const e = t.variables[0], i = new
|
|
1735
|
+
const e = t.variables[0], i = new l().zero(), s = this.clone().reorder(e);
|
|
1725
1736
|
if (t.variables.length === 0)
|
|
1726
1737
|
return {
|
|
1727
1738
|
quotient: this.clone().divide(t).reduce(),
|
|
1728
|
-
reminder: new
|
|
1739
|
+
reminder: new l().zero()
|
|
1729
1740
|
};
|
|
1730
1741
|
if (!this.degree(e).isNatural() || !t.degree(e).isNatural())
|
|
1731
1742
|
throw new Error("Euclidean division requires integer degrees");
|
|
@@ -1753,16 +1764,16 @@ class u {
|
|
|
1753
1764
|
this.#e = [];
|
|
1754
1765
|
let e = this.clone().reorder();
|
|
1755
1766
|
const i = e.commonMonom();
|
|
1756
|
-
e.monomByDegree().coefficient.isStrictlyNegative() && i.opposite(), i.isOne() || (this.#e.push(new
|
|
1767
|
+
e.monomByDegree().coefficient.isStrictlyNegative() && i.opposite(), i.isOne() || (this.#e.push(new l(i)), e = e.euclidean(this.#e[0]).quotient);
|
|
1757
1768
|
const s = new R(e).solve();
|
|
1758
1769
|
if (s.length === 0)
|
|
1759
1770
|
return this.#e.length === 0 ? this.#e = [this.clone()] : this.#e.push(e), this.#e;
|
|
1760
1771
|
if (s.forEach((o) => {
|
|
1761
1772
|
if (o.exact && o.root.isZero())
|
|
1762
1773
|
for (let a = 0; a < o.count; a++)
|
|
1763
|
-
o.fraction.isRational() ? this.#e.push(new
|
|
1774
|
+
o.fraction.isRational() ? this.#e.push(new l().fromCoefficients(o.fraction.denominator, -o.fraction.numerator)) : this.#e.push(new l().fromCoefficients(1, o.fraction.clone().opposite()));
|
|
1764
1775
|
}), this.#e.map((o) => o.degree().value).reduce((o, a) => o + a, 0) < this.degree().value) {
|
|
1765
|
-
const o =
|
|
1776
|
+
const o = l.xMultiply(...this.#e);
|
|
1766
1777
|
this.#e.push(this.clone().divide(o));
|
|
1767
1778
|
}
|
|
1768
1779
|
return this.#e;
|
|
@@ -1779,10 +1790,10 @@ class u {
|
|
|
1779
1790
|
}), this.#h(), this.reorder();
|
|
1780
1791
|
}
|
|
1781
1792
|
gcdDenominator() {
|
|
1782
|
-
return
|
|
1793
|
+
return b.gcd(...this.getDenominators());
|
|
1783
1794
|
}
|
|
1784
1795
|
gcdNumerator() {
|
|
1785
|
-
return
|
|
1796
|
+
return b.gcd(...this.getNumerators());
|
|
1786
1797
|
}
|
|
1787
1798
|
getCoefficients() {
|
|
1788
1799
|
if (!this.degree().isNatural())
|
|
@@ -1824,7 +1835,7 @@ class u {
|
|
|
1824
1835
|
if (i.includes("(") || i.includes(")"))
|
|
1825
1836
|
return !1;
|
|
1826
1837
|
try {
|
|
1827
|
-
e = new
|
|
1838
|
+
e = new l(t);
|
|
1828
1839
|
} catch {
|
|
1829
1840
|
return !1;
|
|
1830
1841
|
}
|
|
@@ -1858,10 +1869,10 @@ class u {
|
|
|
1858
1869
|
return this.#i.length === 1 && this.#i[0].coefficient.isZero() || this.#i.length === 0;
|
|
1859
1870
|
}
|
|
1860
1871
|
lcmDenominator() {
|
|
1861
|
-
return
|
|
1872
|
+
return b.lcm(...this.getDenominators());
|
|
1862
1873
|
}
|
|
1863
1874
|
lcmNumerator() {
|
|
1864
|
-
return
|
|
1875
|
+
return b.lcm(...this.getNumerators());
|
|
1865
1876
|
}
|
|
1866
1877
|
get length() {
|
|
1867
1878
|
return this.#i.length;
|
|
@@ -1908,7 +1919,7 @@ class u {
|
|
|
1908
1919
|
return i;
|
|
1909
1920
|
}
|
|
1910
1921
|
multiply(t) {
|
|
1911
|
-
if (t instanceof
|
|
1922
|
+
if (t instanceof l)
|
|
1912
1923
|
return this.#p(t);
|
|
1913
1924
|
if (t instanceof h)
|
|
1914
1925
|
return this.#u(t);
|
|
@@ -1939,10 +1950,10 @@ class u {
|
|
|
1939
1950
|
return this.#l("tex", !1, !1, !0);
|
|
1940
1951
|
}
|
|
1941
1952
|
pow(t) {
|
|
1942
|
-
return
|
|
1953
|
+
return nt(this, t).reduce();
|
|
1943
1954
|
}
|
|
1944
1955
|
primitive(t) {
|
|
1945
|
-
const e = new
|
|
1956
|
+
const e = new l();
|
|
1946
1957
|
for (const i of this.#i)
|
|
1947
1958
|
e.add(i.primitive(t));
|
|
1948
1959
|
return e;
|
|
@@ -1981,7 +1992,7 @@ class u {
|
|
|
1981
1992
|
*/
|
|
1982
1993
|
replaceBy(t, e) {
|
|
1983
1994
|
let i;
|
|
1984
|
-
const s = new
|
|
1995
|
+
const s = new l().zero();
|
|
1985
1996
|
for (const r of this.monoms)
|
|
1986
1997
|
if (!r.hasVariable(t) || r.literal[t].isZero())
|
|
1987
1998
|
s.add(r.clone());
|
|
@@ -2010,7 +2021,7 @@ class u {
|
|
|
2010
2021
|
}
|
|
2011
2022
|
subtract(...t) {
|
|
2012
2023
|
for (const e of t)
|
|
2013
|
-
e instanceof
|
|
2024
|
+
e instanceof l ? this.add(e.clone().opposite()) : e instanceof p ? this.#i.push(e.clone().opposite()) : this.#i.push(new p(e).opposite());
|
|
2014
2025
|
return this.reduce();
|
|
2015
2026
|
}
|
|
2016
2027
|
tableOfSigns() {
|
|
@@ -2144,15 +2155,15 @@ class u {
|
|
|
2144
2155
|
}
|
|
2145
2156
|
#g(t, e) {
|
|
2146
2157
|
switch (e.tokenType) {
|
|
2147
|
-
case
|
|
2148
|
-
t.push(new
|
|
2158
|
+
case u.COEFFICIENT:
|
|
2159
|
+
t.push(new l(e.token));
|
|
2149
2160
|
break;
|
|
2150
|
-
case
|
|
2151
|
-
t.push(new
|
|
2161
|
+
case u.VARIABLE:
|
|
2162
|
+
t.push(new l().add(new p(e.token)));
|
|
2152
2163
|
break;
|
|
2153
|
-
case
|
|
2164
|
+
case u.CONSTANT:
|
|
2154
2165
|
throw new Error("Unsupported CONSTANT token in Polynom parser");
|
|
2155
|
-
case
|
|
2166
|
+
case u.OPERATION:
|
|
2156
2167
|
if (t.length >= 2) {
|
|
2157
2168
|
const i = t.pop(), s = t.pop();
|
|
2158
2169
|
if (s === void 0 || i === void 0)
|
|
@@ -2185,9 +2196,9 @@ class u {
|
|
|
2185
2196
|
} else
|
|
2186
2197
|
throw new Error("Error parsing the polynom");
|
|
2187
2198
|
break;
|
|
2188
|
-
case
|
|
2199
|
+
case u.MONOM:
|
|
2189
2200
|
throw new Error("Unexpected MONOM token in polynom parser");
|
|
2190
|
-
case
|
|
2201
|
+
case u.FUNCTION:
|
|
2191
2202
|
throw new Error(`Unsupported function token "${e.token}" in polynom parser`);
|
|
2192
2203
|
}
|
|
2193
2204
|
}
|
|
@@ -2204,7 +2215,7 @@ class u {
|
|
|
2204
2215
|
return s.length === 1 && this.add(s[0]), this.reorder();
|
|
2205
2216
|
}
|
|
2206
2217
|
}
|
|
2207
|
-
class
|
|
2218
|
+
class x {
|
|
2208
2219
|
// Left part of the equation
|
|
2209
2220
|
#t;
|
|
2210
2221
|
// Right part of the equation
|
|
@@ -2212,11 +2223,11 @@ class v {
|
|
|
2212
2223
|
// Signe of the equation
|
|
2213
2224
|
#i;
|
|
2214
2225
|
constructor(t, e, i) {
|
|
2215
|
-
if (this.#t = new
|
|
2216
|
-
if (t instanceof
|
|
2226
|
+
if (this.#t = new l().zero(), this.#e = new l().zero(), this.#i = "=", t !== void 0 && e === void 0) {
|
|
2227
|
+
if (t instanceof x)
|
|
2217
2228
|
return t.clone();
|
|
2218
2229
|
typeof t == "string" && this.parse(t);
|
|
2219
|
-
} else t !== void 0 && e !== void 0 && (this.left = new
|
|
2230
|
+
} else t !== void 0 && e !== void 0 && (this.left = new l(t), this.right = new l(e));
|
|
2220
2231
|
return i !== void 0 && (this.sign = i), this;
|
|
2221
2232
|
}
|
|
2222
2233
|
// ------------------------------------------
|
|
@@ -2225,9 +2236,9 @@ class v {
|
|
|
2225
2236
|
if (e === !1)
|
|
2226
2237
|
throw new Error("The equation is not valid (no sign found)");
|
|
2227
2238
|
const i = t.split(e);
|
|
2228
|
-
return this.create(new
|
|
2239
|
+
return this.create(new l(i[0]), new l(i[1]), this.#r(e));
|
|
2229
2240
|
};
|
|
2230
|
-
clone = () => new
|
|
2241
|
+
clone = () => new x(this.#t.clone(), this.#e.clone(), this.#i);
|
|
2231
2242
|
get tex() {
|
|
2232
2243
|
return `${this.#t.tex}${this.signAsTex}${this.#e.tex}`;
|
|
2233
2244
|
}
|
|
@@ -2250,11 +2261,11 @@ class v {
|
|
|
2250
2261
|
* @param value | Polynom | Monom | Fraction | string | monom
|
|
2251
2262
|
*/
|
|
2252
2263
|
add(t) {
|
|
2253
|
-
if (t instanceof
|
|
2264
|
+
if (t instanceof x)
|
|
2254
2265
|
return this.#t.add(t.left), this.#e.add(t.right), this;
|
|
2255
|
-
if (typeof t == "string" && !
|
|
2256
|
-
return this.add(new
|
|
2257
|
-
const e = new
|
|
2266
|
+
if (typeof t == "string" && !x.isEquationString(t))
|
|
2267
|
+
return this.add(new x(t));
|
|
2268
|
+
const e = new l(t);
|
|
2258
2269
|
return this.#t.add(e), this.#e.add(e), this;
|
|
2259
2270
|
}
|
|
2260
2271
|
create = (t, e, i) => (this.#t = t, this.#e = e, this.#i = this.#r(i ?? "="), this);
|
|
@@ -2298,7 +2309,7 @@ class v {
|
|
|
2298
2309
|
*/
|
|
2299
2310
|
hasVariable = (t) => this.variables.includes(t);
|
|
2300
2311
|
isEqual(t) {
|
|
2301
|
-
const e = new
|
|
2312
|
+
const e = new x(t);
|
|
2302
2313
|
return e.left.isEqual(this.#t) && e.right.isEqual(this.#e);
|
|
2303
2314
|
}
|
|
2304
2315
|
// -----------------------------------------------
|
|
@@ -2390,18 +2401,18 @@ class v {
|
|
|
2390
2401
|
/**
|
|
2391
2402
|
* Multiply by the lcm denominator and divide by the gcm numerators.
|
|
2392
2403
|
*/
|
|
2393
|
-
simplify = () => (this.multiply(
|
|
2404
|
+
simplify = () => (this.multiply(b.lcm(...this.#t.getDenominators(), ...this.#e.getDenominators())), this.divide(b.gcd(...this.#t.getNumerators(), ...this.#e.getNumerators())), this);
|
|
2394
2405
|
// -----------------------------------------------
|
|
2395
2406
|
solve = () => new R(this.clone()).solve();
|
|
2396
2407
|
split() {
|
|
2397
2408
|
return [this.#t.clone(), this.#e.clone()];
|
|
2398
2409
|
}
|
|
2399
2410
|
subtract(t) {
|
|
2400
|
-
if (t instanceof
|
|
2411
|
+
if (t instanceof x)
|
|
2401
2412
|
return this.#t.subtract(t.left), this.#e.subtract(t.right), this;
|
|
2402
|
-
if (typeof t == "string" && !
|
|
2403
|
-
return this.subtract(new
|
|
2404
|
-
const e = new
|
|
2413
|
+
if (typeof t == "string" && !x.isEquationString(t))
|
|
2414
|
+
return this.subtract(new x(t));
|
|
2415
|
+
const e = new l(t);
|
|
2405
2416
|
return this.#t.subtract(e), this.#e.subtract(e), this;
|
|
2406
2417
|
}
|
|
2407
2418
|
test = (t) => this.left.evaluate(t).isEqual(this.right.evaluate(t));
|
|
@@ -2434,29 +2445,29 @@ class v {
|
|
|
2434
2445
|
#r = (t) => t === void 0 ? "=" : t.includes("geq") || t.includes(">=") || t.includes("=>") ? ">=" : t.includes(">") ? ">" : t.includes("leq") || t.includes("<=") || t.includes("=<") ? "<=" : t.includes("<") ? "<" : "=";
|
|
2435
2446
|
#n = () => this.#i === "=" ? this : this.#i.includes("<") ? (this.#i.replace("<", ">"), this) : this.#i.includes(">") ? (this.#i.replace(">", "<"), this) : this;
|
|
2436
2447
|
}
|
|
2437
|
-
class
|
|
2448
|
+
class y {
|
|
2438
2449
|
#t;
|
|
2439
2450
|
#e;
|
|
2440
2451
|
#i;
|
|
2441
2452
|
#s = !1;
|
|
2442
2453
|
constructor(t, e) {
|
|
2443
|
-
return t instanceof
|
|
2454
|
+
return t instanceof y ? (this.#e = t.polynom.clone(), this.#i = t.power.clone(), e !== void 0 && this.#i.multiply(new h(e))) : t !== void 0 ? (this.#e = new l(t), this.#i = new h(e ?? 1)) : (this.#e = new l(), this.#i = new h(1)), this.#t = 1, this;
|
|
2444
2455
|
}
|
|
2445
2456
|
parse() {
|
|
2446
2457
|
throw new Error("Method not implemented.");
|
|
2447
2458
|
}
|
|
2448
2459
|
clone() {
|
|
2449
|
-
return new
|
|
2460
|
+
return new y(this);
|
|
2450
2461
|
}
|
|
2451
2462
|
get tex() {
|
|
2452
2463
|
const t = this.power.numerator, e = this.power.denominator;
|
|
2453
2464
|
let i, s;
|
|
2454
|
-
return this.#t === 0 && e > 1 ? (i = `\\sqrt${e === 2 ? "" : `[ ${e} ]`}{ ${this.polynom.tex} }`, s = t === 1 ? "" : `^{ ${t} }`) : (i = this.#s && this.power.isOne() ? this.polynom.tex :
|
|
2465
|
+
return this.#t === 0 && e > 1 ? (i = `\\sqrt${e === 2 ? "" : `[ ${e} ]`}{ ${this.polynom.tex} }`, s = t === 1 ? "" : `^{ ${t} }`) : (i = this.#s && this.power.isOne() ? this.polynom.tex : st(this.polynom.tex), s = e === 1 && t === 1 ? "" : `^{ ${this.power.tex} }`), i = `${i}${s}`, this.#t === 0 && t < 0 && (i = `\\frac{ 1 }{ ${i} }`), i;
|
|
2455
2466
|
}
|
|
2456
2467
|
get display() {
|
|
2457
2468
|
const t = this.power.numerator, e = this.power.denominator;
|
|
2458
2469
|
let i, s;
|
|
2459
|
-
return this.#t === 0 && e > 1 ? (i = `${e === 2 ? "sqrt" : `root(${e})`}(${this.polynom.display})`, s = t === 1 ? "" : `^(${t})`) : (i = this.#s && this.power.isOne() ? this.polynom.display :
|
|
2470
|
+
return this.#t === 0 && e > 1 ? (i = `${e === 2 ? "sqrt" : `root(${e})`}(${this.polynom.display})`, s = t === 1 ? "" : `^(${t})`) : (i = this.#s && this.power.isOne() ? this.polynom.display : st(this.polynom.display, !1), s = e === 1 && t === 1 ? "" : `^(${this.power.display})`), i = `${i}${s}`, this.#t === 0 && t < 0 && (i = `1/(${i})`), i;
|
|
2460
2471
|
}
|
|
2461
2472
|
add() {
|
|
2462
2473
|
throw new Error("Adding two factors is not possible");
|
|
@@ -2468,10 +2479,10 @@ class b {
|
|
|
2468
2479
|
return this.polynom.degree(t).multiply(this.power);
|
|
2469
2480
|
}
|
|
2470
2481
|
derivative() {
|
|
2471
|
-
return this.power.isZero() ? [new
|
|
2472
|
-
new
|
|
2473
|
-
new
|
|
2474
|
-
new
|
|
2482
|
+
return this.power.isZero() ? [new y("0")] : this.power.isOne() ? [new y(this.polynom.clone().derivative())] : [
|
|
2483
|
+
new y(this.power.clone()),
|
|
2484
|
+
new y(this.polynom.clone().derivative()),
|
|
2485
|
+
new y(this.polynom.clone(), this.power.clone().subtract(1))
|
|
2475
2486
|
];
|
|
2476
2487
|
}
|
|
2477
2488
|
develop() {
|
|
@@ -2480,9 +2491,9 @@ class b {
|
|
|
2480
2491
|
throw new Error("The power must be a natural number");
|
|
2481
2492
|
}
|
|
2482
2493
|
divide(t) {
|
|
2483
|
-
if (t instanceof
|
|
2494
|
+
if (t instanceof y && this.isSameAs(t))
|
|
2484
2495
|
return this.power.subtract(t.power), this;
|
|
2485
|
-
const e = new
|
|
2496
|
+
const e = new l(t);
|
|
2486
2497
|
if (this.isSameAs(e))
|
|
2487
2498
|
return this.power.subtract(1), this;
|
|
2488
2499
|
throw new Error("The two factors must be the same");
|
|
@@ -2491,7 +2502,7 @@ class b {
|
|
|
2491
2502
|
return e ? this.polynom.evaluate(t, !0) ** this.power.value : this.polynom.evaluate(t).pow(this.power);
|
|
2492
2503
|
}
|
|
2493
2504
|
fromPolynom(t) {
|
|
2494
|
-
return this.#e = new
|
|
2505
|
+
return this.#e = new l(t), this.#i = new h(1), this;
|
|
2495
2506
|
}
|
|
2496
2507
|
hasVariable(t) {
|
|
2497
2508
|
return this.polynom.hasVariable(t);
|
|
@@ -2507,15 +2518,15 @@ class b {
|
|
|
2507
2518
|
}
|
|
2508
2519
|
isSameAs(t) {
|
|
2509
2520
|
let e;
|
|
2510
|
-
return t instanceof
|
|
2521
|
+
return t instanceof y ? e = t.polynom : t instanceof l ? e = t : e = new l(t), this.polynom.isEqual(e);
|
|
2511
2522
|
}
|
|
2512
2523
|
isZero() {
|
|
2513
2524
|
return this.polynom.isZero();
|
|
2514
2525
|
}
|
|
2515
2526
|
multiply(t) {
|
|
2516
|
-
if (t instanceof
|
|
2527
|
+
if (t instanceof y && this.isSameAs(t))
|
|
2517
2528
|
return this.power.add(t.power), this;
|
|
2518
|
-
const e = new
|
|
2529
|
+
const e = new l(t);
|
|
2519
2530
|
if (this.isSameAs(e))
|
|
2520
2531
|
return this.power.add(1), this;
|
|
2521
2532
|
throw new Error("The two factors must be the same");
|
|
@@ -2572,17 +2583,39 @@ class b {
|
|
|
2572
2583
|
zero() {
|
|
2573
2584
|
return this.#e.zero(), this.#i.one(), this;
|
|
2574
2585
|
}
|
|
2586
|
+
static checkParseAsFactors(t) {
|
|
2587
|
+
const e = H(t, "+");
|
|
2588
|
+
if (e[0] === "" && e.shift(), e.length > 1) return !1;
|
|
2589
|
+
const i = H(t, "-");
|
|
2590
|
+
return i[0] === "" && i.shift(), !(i.length > 1);
|
|
2591
|
+
}
|
|
2592
|
+
static factorsFromString(t, e = !0) {
|
|
2593
|
+
if (!y.checkParseAsFactors(t))
|
|
2594
|
+
return [new y(t, e ? 1 : -1)];
|
|
2595
|
+
const i = e ? 1 : -1, s = [], r = /\(([^)]+)\)(?:\^(-?[0-9]+(?:\/[0-9]+)?|\(-?[0-9]+(?:\/[0-9]+)?\)))?|([^(]+)/g;
|
|
2596
|
+
for (const o of t.matchAll(r))
|
|
2597
|
+
if (o[1] !== void 0) {
|
|
2598
|
+
const a = (o[2] ?? "1").replace(/[()]/g, "");
|
|
2599
|
+
s.push(
|
|
2600
|
+
new y(
|
|
2601
|
+
new l(o[1]),
|
|
2602
|
+
new h(a).multiply(i)
|
|
2603
|
+
)
|
|
2604
|
+
);
|
|
2605
|
+
} else o[3]?.trim() && s.push(new y(new l(o[3].trim()), new h(i)));
|
|
2606
|
+
return s;
|
|
2607
|
+
}
|
|
2575
2608
|
}
|
|
2576
2609
|
var D = /* @__PURE__ */ ((n) => (n[n.ROOT = 0] = "ROOT", n[n.POWER = 1] = "POWER", n))(D || {});
|
|
2577
|
-
class
|
|
2610
|
+
class P {
|
|
2578
2611
|
#t;
|
|
2579
2612
|
// Determine the letters in the linear asSystem, usually ['x', 'y']
|
|
2580
2613
|
#e;
|
|
2581
2614
|
constructor(...t) {
|
|
2582
2615
|
return this.#t = [], this.#e = [], t.length > 0 && this.parse(...t), this;
|
|
2583
2616
|
}
|
|
2584
|
-
parse = (...t) => (this.#t = t.map((e) => new
|
|
2585
|
-
clone = () => new
|
|
2617
|
+
parse = (...t) => (this.#t = t.map((e) => new x(e)), this.#i(), this);
|
|
2618
|
+
clone = () => new P().parse(...this.#t.map((t) => t.clone()));
|
|
2586
2619
|
get tex() {
|
|
2587
2620
|
const t = this.clone().reorder();
|
|
2588
2621
|
return this.buildTex(t.equations);
|
|
@@ -2595,10 +2628,10 @@ class z {
|
|
|
2595
2628
|
if (t.some((r) => r.length !== i))
|
|
2596
2629
|
throw new Error("All rows must have the same number of columns");
|
|
2597
2630
|
const s = e.split("").splice(0, i - 1);
|
|
2598
|
-
return new
|
|
2631
|
+
return new P(
|
|
2599
2632
|
...t.map((r) => {
|
|
2600
|
-
const o = new
|
|
2601
|
-
return new
|
|
2633
|
+
const o = new l(s.join(""), ...r);
|
|
2634
|
+
return new x(o, 0);
|
|
2602
2635
|
})
|
|
2603
2636
|
);
|
|
2604
2637
|
}
|
|
@@ -2609,7 +2642,7 @@ class z {
|
|
|
2609
2642
|
return `\\left( ${t.map((e) => e.tex).join(" ; ")} \\right)`;
|
|
2610
2643
|
}
|
|
2611
2644
|
add(t, e) {
|
|
2612
|
-
if (t instanceof
|
|
2645
|
+
if (t instanceof P) {
|
|
2613
2646
|
const i = t.equations.length;
|
|
2614
2647
|
if (i !== this.#t.length)
|
|
2615
2648
|
throw new Error("The number of equations must be the same");
|
|
@@ -2618,7 +2651,7 @@ class z {
|
|
|
2618
2651
|
} else {
|
|
2619
2652
|
if (e === void 0 || e < 0 || e >= this.#t.length)
|
|
2620
2653
|
throw new Error("Index out of range");
|
|
2621
|
-
const i = new
|
|
2654
|
+
const i = new x(t);
|
|
2622
2655
|
this.#t[e].add(i);
|
|
2623
2656
|
}
|
|
2624
2657
|
return this;
|
|
@@ -2722,7 +2755,7 @@ class z {
|
|
|
2722
2755
|
const e = [], i = this.equations.map((s) => s.left.monomByLetter(t).coefficient.value);
|
|
2723
2756
|
return i.forEach((s, r) => {
|
|
2724
2757
|
for (let o = r + 1; o < i.length; o++) {
|
|
2725
|
-
const a =
|
|
2758
|
+
const a = b.lcm(s, i[o]), c = s < 0 ? -1 : 1;
|
|
2726
2759
|
e.push([
|
|
2727
2760
|
{
|
|
2728
2761
|
id: r,
|
|
@@ -2737,7 +2770,7 @@ class z {
|
|
|
2737
2770
|
}), e.sort((s, r) => Math.abs(s[0].factor) + Math.abs(s[1].factor) - (Math.abs(r[0].factor) + Math.abs(r[1].factor)));
|
|
2738
2771
|
}
|
|
2739
2772
|
subtract(t, e) {
|
|
2740
|
-
if (t instanceof
|
|
2773
|
+
if (t instanceof P) {
|
|
2741
2774
|
const i = t.equations.length;
|
|
2742
2775
|
if (i !== this.#t.length)
|
|
2743
2776
|
throw new Error("The number of equations must be the same");
|
|
@@ -2746,7 +2779,7 @@ class z {
|
|
|
2746
2779
|
} else {
|
|
2747
2780
|
if (e === void 0 || e < 0 || e >= this.#t.length)
|
|
2748
2781
|
throw new Error("Index out of range");
|
|
2749
|
-
const i = new
|
|
2782
|
+
const i = new x(t);
|
|
2750
2783
|
this.#t[e].subtract(i);
|
|
2751
2784
|
}
|
|
2752
2785
|
return this;
|
|
@@ -2782,7 +2815,7 @@ class z {
|
|
|
2782
2815
|
}), e);
|
|
2783
2816
|
}
|
|
2784
2817
|
}
|
|
2785
|
-
class
|
|
2818
|
+
class $t {
|
|
2786
2819
|
#t;
|
|
2787
2820
|
/**
|
|
2788
2821
|
*
|
|
@@ -2937,7 +2970,7 @@ class N {
|
|
|
2937
2970
|
}
|
|
2938
2971
|
parse(...t) {
|
|
2939
2972
|
return this.#e = [], t.length === 0 ? this : (t.forEach((e) => {
|
|
2940
|
-
e instanceof N ? this.#e.push(...e.factors.map((i) => i.clone())) : this.#e.push(new
|
|
2973
|
+
e instanceof N ? this.#e.push(...e.factors.map((i) => i.clone())) : this.#e.push(new y(e));
|
|
2941
2974
|
}), this);
|
|
2942
2975
|
}
|
|
2943
2976
|
clone() {
|
|
@@ -2962,14 +2995,14 @@ class N {
|
|
|
2962
2995
|
static #i(t, e) {
|
|
2963
2996
|
const i = Z(t), s = Z(e), o = Object.keys(i).filter((a) => Object.hasOwn(s, a)).map((a) => {
|
|
2964
2997
|
const c = i[a].reduce((m, d) => m.add(d.power), new h("0")), f = s[a].reduce((m, d) => m.add(d.power), new h("0"));
|
|
2965
|
-
return new
|
|
2998
|
+
return new y(a, h.min(c, f));
|
|
2966
2999
|
});
|
|
2967
3000
|
return new N(...o);
|
|
2968
3001
|
}
|
|
2969
3002
|
static #s(t, e) {
|
|
2970
3003
|
const i = Z(t), s = Z(e), o = [.../* @__PURE__ */ new Set([...Object.keys(i), ...Object.keys(s)])].map((a) => {
|
|
2971
3004
|
const c = Object.hasOwn(i, a) ? i[a].reduce((m, d) => m.add(d.power), new h("0")) : new h(0), f = Object.hasOwn(s, a) ? s[a].reduce((m, d) => m.add(d.power), new h("0")) : new h(0);
|
|
2972
|
-
return new
|
|
3005
|
+
return new y(a, h.max(c, f));
|
|
2973
3006
|
});
|
|
2974
3007
|
return new N(...o);
|
|
2975
3008
|
}
|
|
@@ -3000,12 +3033,12 @@ class N {
|
|
|
3000
3033
|
c.multiply(a.clone().divide(i[f]));
|
|
3001
3034
|
}), s = a;
|
|
3002
3035
|
}
|
|
3003
|
-
const r = N.gcd(...e), o = new
|
|
3036
|
+
const r = N.gcd(...e), o = new l(0).add(
|
|
3004
3037
|
...e.map((a) => a.divide(r).reduce().develop().factors[0].polynom)
|
|
3005
3038
|
).reduce();
|
|
3006
3039
|
return this.#e = [
|
|
3007
3040
|
...r.factors,
|
|
3008
|
-
new
|
|
3041
|
+
new y(o)
|
|
3009
3042
|
], s && this.divide(s), this.#e = this.#e.filter((a) => !a.power.isZero()), this;
|
|
3010
3043
|
}
|
|
3011
3044
|
get asPower() {
|
|
@@ -3035,7 +3068,7 @@ class N {
|
|
|
3035
3068
|
return i !== void 0 && (this.#e = i.factors), this.add(...t);
|
|
3036
3069
|
}
|
|
3037
3070
|
develop() {
|
|
3038
|
-
const t = new
|
|
3071
|
+
const t = new l("1"), e = new l("1");
|
|
3039
3072
|
return this.numerator.factors.forEach((i) => {
|
|
3040
3073
|
t.multiply(i.develop());
|
|
3041
3074
|
}), this.denominator.factors.forEach((i) => {
|
|
@@ -3054,7 +3087,7 @@ class N {
|
|
|
3054
3087
|
const a = o.polynom.factorize(t);
|
|
3055
3088
|
if (a.length > 1) {
|
|
3056
3089
|
const c = o.power.clone();
|
|
3057
|
-
e.push(...a.map((f) => new
|
|
3090
|
+
e.push(...a.map((f) => new y(f, c)));
|
|
3058
3091
|
} else
|
|
3059
3092
|
e.push(o.clone());
|
|
3060
3093
|
});
|
|
@@ -3068,16 +3101,24 @@ class N {
|
|
|
3068
3101
|
this.#e = t;
|
|
3069
3102
|
}
|
|
3070
3103
|
fromPolynom(t, e) {
|
|
3071
|
-
if (this.#e = [new
|
|
3072
|
-
const i = new
|
|
3073
|
-
if (i.isOne())
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
throw new Error("Cannot divide by zero");
|
|
3077
|
-
this.#e.push(new b(i, -1));
|
|
3104
|
+
if (this.#e = [new y(new l(t))], e) {
|
|
3105
|
+
const i = new l(e);
|
|
3106
|
+
if (i.isOne()) return this;
|
|
3107
|
+
if (i.isZero()) throw new Error("Cannot divide by zero");
|
|
3108
|
+
this.#e.push(new y(i, -1));
|
|
3078
3109
|
}
|
|
3079
3110
|
return this;
|
|
3080
3111
|
}
|
|
3112
|
+
fromString(t) {
|
|
3113
|
+
this.#e = [];
|
|
3114
|
+
const [e, ...i] = H(t, "/");
|
|
3115
|
+
if (e === "") throw new Error("Parsing a PolyFactor from a string requires a numerator");
|
|
3116
|
+
if (i.length > 1) throw new Error('Parsing a PolyFactor from a string only allows max one signe "/"');
|
|
3117
|
+
return i.length === 0 ? this.#e = y.factorsFromString(e, !0) : this.#e = [
|
|
3118
|
+
...y.factorsFromString(e, !0),
|
|
3119
|
+
...y.factorsFromString(i[0], !1)
|
|
3120
|
+
], this;
|
|
3121
|
+
}
|
|
3081
3122
|
/**
|
|
3082
3123
|
* Get the roots of the PolyFactor.
|
|
3083
3124
|
*/
|
|
@@ -3117,11 +3158,11 @@ class N {
|
|
|
3117
3158
|
return new N(...this.#e.filter((t) => t.power.isPositive()));
|
|
3118
3159
|
}
|
|
3119
3160
|
one() {
|
|
3120
|
-
return this.#e = [new
|
|
3161
|
+
return this.#e = [new y("1", "1")], this;
|
|
3121
3162
|
}
|
|
3122
3163
|
opposite() {
|
|
3123
3164
|
const t = this.#e.findIndex((e) => e.display === "(-1)");
|
|
3124
|
-
return t >= 0 ? this.#e.splice(t, 1) : this.#e.push(new
|
|
3165
|
+
return t >= 0 ? this.#e.splice(t, 1) : this.#e.push(new y("-1", "1")), this;
|
|
3125
3166
|
}
|
|
3126
3167
|
pow(t) {
|
|
3127
3168
|
return this.#e = this.#e.map((e) => e.pow(t)), this;
|
|
@@ -3133,7 +3174,7 @@ class N {
|
|
|
3133
3174
|
const t = Z(this);
|
|
3134
3175
|
return this.#e = Object.values(t).map((e) => {
|
|
3135
3176
|
const i = e[0].polynom, s = e.reduce((r, o) => r.add(o.power), new h("0"));
|
|
3136
|
-
return new
|
|
3177
|
+
return new y(i, s.reduce());
|
|
3137
3178
|
}).filter((e) => !e.power.isZero()), this;
|
|
3138
3179
|
}
|
|
3139
3180
|
root(t) {
|
|
@@ -3164,17 +3205,17 @@ class N {
|
|
|
3164
3205
|
return this.add(...t.map((e) => e.opposite()));
|
|
3165
3206
|
}
|
|
3166
3207
|
tableOfSigns() {
|
|
3167
|
-
const t = this.getZeroes(), e = t.map((r) => r.value), i = this.factorize().factors.map((r) => ({ factor: new
|
|
3208
|
+
const t = this.getZeroes(), e = t.map((r) => r.value), i = this.factorize().factors.map((r) => ({ factor: new y(r), ...r.tableOfSigns() }));
|
|
3168
3209
|
return i.forEach((r) => {
|
|
3169
3210
|
const o = new Array(2 * t.length + 1).fill("");
|
|
3170
3211
|
let a = r.signs.shift(), c = r.roots.shift();
|
|
3171
3212
|
const f = o.map((m, d) => {
|
|
3172
3213
|
if (d % 2 === 0)
|
|
3173
3214
|
return a;
|
|
3174
|
-
if (c
|
|
3215
|
+
if (c?.value !== e[(d - 1) / 2])
|
|
3175
3216
|
return "t";
|
|
3176
|
-
const
|
|
3177
|
-
return a = r.signs.shift(), c = r.roots.shift(),
|
|
3217
|
+
const v = r.signs.shift();
|
|
3218
|
+
return a = r.signs.shift(), c = r.roots.shift(), v;
|
|
3178
3219
|
});
|
|
3179
3220
|
r.roots = t, r.signs = f;
|
|
3180
3221
|
}), { signs: i.map((r) => [...r.signs]).reduce((r, o) => r.length === 0 ? o : (o.forEach((a, c) => {
|
|
@@ -3198,11 +3239,11 @@ class N {
|
|
|
3198
3239
|
return this.#e.reduce((t, e) => t.concat(e.variables), []);
|
|
3199
3240
|
}
|
|
3200
3241
|
zero() {
|
|
3201
|
-
return this.#e = [new
|
|
3242
|
+
return this.#e = [new y("0", "1")], this;
|
|
3202
3243
|
}
|
|
3203
3244
|
#r() {
|
|
3204
3245
|
let t, e = [];
|
|
3205
|
-
return this.#t === D.ROOT ? (t = this.numerator.factors, e = this.denominator.factors) : t = this.#e, t.length === 0 && (t = [new
|
|
3246
|
+
return this.#t === D.ROOT ? (t = this.numerator.factors, e = this.denominator.factors) : t = this.#e, t.length === 0 && (t = [new y("1")]), { num: t, den: e };
|
|
3206
3247
|
}
|
|
3207
3248
|
}
|
|
3208
3249
|
function Z(n) {
|
|
@@ -3212,7 +3253,7 @@ function Z(n) {
|
|
|
3212
3253
|
const c = a.polynom.display;
|
|
3213
3254
|
return Object.hasOwn(o, c) ? o[c].push(a) : o[c] = [a], o;
|
|
3214
3255
|
}, {}), { numerator: s, denominator: r } = t.divide(e).reduce();
|
|
3215
|
-
return s !== 1 && (i[s.toString()] = [new
|
|
3256
|
+
return s !== 1 && (i[s.toString()] = [new y(s, 1)]), r !== 1 && (i[r.toString()] = [new y(r, -1)]), i;
|
|
3216
3257
|
}
|
|
3217
3258
|
class B {
|
|
3218
3259
|
#t = null;
|
|
@@ -3277,7 +3318,7 @@ class B {
|
|
|
3277
3318
|
}
|
|
3278
3319
|
characteristic_polynom(t) {
|
|
3279
3320
|
return t ??= "k", this.clone().subtract(
|
|
3280
|
-
new B(this.dimension.rows).one().multiply(new
|
|
3321
|
+
new B(this.dimension.rows).one().multiply(new l(t))
|
|
3281
3322
|
).determinant();
|
|
3282
3323
|
}
|
|
3283
3324
|
cofactor(t, e) {
|
|
@@ -3287,7 +3328,7 @@ class B {
|
|
|
3287
3328
|
}), i.determinant().multiply((-1) ** (t + e));
|
|
3288
3329
|
}
|
|
3289
3330
|
get cols() {
|
|
3290
|
-
const t = Array.from({ length: this.dimension.cols }, () => Array.from({ length: this.dimension.rows }, () => new
|
|
3331
|
+
const t = Array.from({ length: this.dimension.cols }, () => Array.from({ length: this.dimension.rows }, () => new l()));
|
|
3291
3332
|
return this.forEach((e, i, s) => {
|
|
3292
3333
|
t[s][i] = e;
|
|
3293
3334
|
}), t;
|
|
@@ -3295,7 +3336,7 @@ class B {
|
|
|
3295
3336
|
determinant() {
|
|
3296
3337
|
if (!this.isSquare())
|
|
3297
3338
|
throw new Error("Matrix is not square");
|
|
3298
|
-
const t = new
|
|
3339
|
+
const t = new l();
|
|
3299
3340
|
return this.#i.length === 1 ? this.#i[0][0].clone() : (this.values[0].forEach((e, i) => {
|
|
3300
3341
|
const s = this.cofactor(0, i);
|
|
3301
3342
|
t.add(e.clone().multiply(s));
|
|
@@ -3318,14 +3359,14 @@ class B {
|
|
|
3318
3359
|
});
|
|
3319
3360
|
}
|
|
3320
3361
|
fromDimensions(t, e) {
|
|
3321
|
-
return this.#i = Array.from({ length: t }, () => Array.from({ length: e }, () => new
|
|
3362
|
+
return this.#i = Array.from({ length: t }, () => Array.from({ length: e }, () => new l())), this;
|
|
3322
3363
|
}
|
|
3323
3364
|
fromString(t) {
|
|
3324
3365
|
if (t.startsWith("((") && t.endsWith("))"))
|
|
3325
3366
|
return this.fromString(t.substring(1, t.length - 1));
|
|
3326
3367
|
const e = t.split("),(");
|
|
3327
3368
|
return this.#i = e.map((i, s) => s === 0 ? i.substring(1).split(",") : s === e.length - 1 ? i.substring(0, i.length - 1).split(",") : i.split(",")).map(
|
|
3328
|
-
(i) => i.map((s) => new
|
|
3369
|
+
(i) => i.map((s) => new l(s))
|
|
3329
3370
|
), this;
|
|
3330
3371
|
}
|
|
3331
3372
|
fromValues(t) {
|
|
@@ -3336,7 +3377,7 @@ class B {
|
|
|
3336
3377
|
return t.forEach((i) => {
|
|
3337
3378
|
const s = [];
|
|
3338
3379
|
i.forEach((r) => {
|
|
3339
|
-
s.push(new
|
|
3380
|
+
s.push(new l(r));
|
|
3340
3381
|
}), this.#i.push(s);
|
|
3341
3382
|
}), this;
|
|
3342
3383
|
}
|
|
@@ -3347,7 +3388,7 @@ class B {
|
|
|
3347
3388
|
throw new Error("Each vectors must be the same dimension");
|
|
3348
3389
|
return this.fromDimensions(t[0].dimension, t.length), t.forEach((i, s) => {
|
|
3349
3390
|
i.array.forEach((r, o) => {
|
|
3350
|
-
this.#i[o][s] = new
|
|
3391
|
+
this.#i[o][s] = new l(r);
|
|
3351
3392
|
});
|
|
3352
3393
|
}), this;
|
|
3353
3394
|
}
|
|
@@ -3397,7 +3438,7 @@ class B {
|
|
|
3397
3438
|
throw new Error("Cannot multiply a matrix with incompatibles dimensions");
|
|
3398
3439
|
const e = new B(this.dimension.rows, t.dimension.cols);
|
|
3399
3440
|
return e.forEach((i, s, r) => {
|
|
3400
|
-
const o = this.rows[s], a = t.cols[r], c = new
|
|
3441
|
+
const o = this.rows[s], a = t.cols[r], c = new l();
|
|
3401
3442
|
o.forEach((f, m) => {
|
|
3402
3443
|
c.add(f.clone().multiply(a[m]));
|
|
3403
3444
|
}), e.setValue(s, r, c);
|
|
@@ -3421,7 +3462,7 @@ class B {
|
|
|
3421
3462
|
return this.#e = !0, this;
|
|
3422
3463
|
}
|
|
3423
3464
|
pow(t) {
|
|
3424
|
-
return
|
|
3465
|
+
return nt(this, t);
|
|
3425
3466
|
}
|
|
3426
3467
|
reduce() {
|
|
3427
3468
|
throw new Error("Not yet implemented");
|
|
@@ -3433,7 +3474,7 @@ class B {
|
|
|
3433
3474
|
const { rows: s, cols: r } = this.dimension;
|
|
3434
3475
|
if (t < 0 || t >= s || e < 0 || e >= r)
|
|
3435
3476
|
throw new Error(`${t}x${e} is out of range (${s}x${r})`);
|
|
3436
|
-
return this.#i[t][e] = new
|
|
3477
|
+
return this.#i[t][e] = new l(i), this;
|
|
3437
3478
|
}
|
|
3438
3479
|
subtract(t) {
|
|
3439
3480
|
if (!this.canBeAdded(t))
|
|
@@ -3457,12 +3498,12 @@ class B {
|
|
|
3457
3498
|
return this.forEach((t) => t.zero()), this;
|
|
3458
3499
|
}
|
|
3459
3500
|
}
|
|
3460
|
-
function
|
|
3501
|
+
function kt(n, t) {
|
|
3461
3502
|
return n.dimension === t.dimension && n.array.every(
|
|
3462
3503
|
(e, i) => t.array[i].isEqual(e)
|
|
3463
3504
|
);
|
|
3464
3505
|
}
|
|
3465
|
-
function
|
|
3506
|
+
function Mt(n, t) {
|
|
3466
3507
|
if (n.dimension !== t.dimension)
|
|
3467
3508
|
return !1;
|
|
3468
3509
|
const e = t.array[0].value / n.array[0].value;
|
|
@@ -3470,13 +3511,13 @@ function kt(n, t) {
|
|
|
3470
3511
|
(i, s) => t.array[s].value === i.value * e
|
|
3471
3512
|
);
|
|
3472
3513
|
}
|
|
3473
|
-
function
|
|
3514
|
+
function Bt(n, t) {
|
|
3474
3515
|
return n.dimension !== t.dimension ? new h().invalid() : n.array.reduce(
|
|
3475
3516
|
(e, i, s) => e.add(i.clone().multiply(t.array[s])),
|
|
3476
3517
|
new h(0)
|
|
3477
3518
|
);
|
|
3478
3519
|
}
|
|
3479
|
-
function
|
|
3520
|
+
function Ft(...n) {
|
|
3480
3521
|
if (n.some((t) => t.dimension !== n[0].dimension))
|
|
3481
3522
|
throw new Error("All vectors must have the same dimension");
|
|
3482
3523
|
if (n[0].dimension !== n.length)
|
|
@@ -3489,7 +3530,7 @@ function jt(...n) {
|
|
|
3489
3530
|
)
|
|
3490
3531
|
).add(n[0].array[2].clone().multiply(n[1].array[0].clone().multiply(n[2].array[1]).subtract(n[1].array[1].clone().multiply(n[2].array[0]))));
|
|
3491
3532
|
}
|
|
3492
|
-
class
|
|
3533
|
+
class z {
|
|
3493
3534
|
#t = [];
|
|
3494
3535
|
#e;
|
|
3495
3536
|
constructor(...t) {
|
|
@@ -3552,13 +3593,13 @@ class P {
|
|
|
3552
3593
|
}
|
|
3553
3594
|
zero = () => (this.#t.forEach((t) => t.zero()), this.#e?.(), this);
|
|
3554
3595
|
}
|
|
3555
|
-
class w extends
|
|
3596
|
+
class w extends z {
|
|
3556
3597
|
constructor(...t) {
|
|
3557
3598
|
super(), t.length > 0 && this.parse(...t);
|
|
3558
3599
|
}
|
|
3559
3600
|
parse(...t) {
|
|
3560
3601
|
if (t.length === 1) {
|
|
3561
|
-
if (t[0] instanceof
|
|
3602
|
+
if (t[0] instanceof z)
|
|
3562
3603
|
return this.array = t[0].copy(), this;
|
|
3563
3604
|
if (typeof t[0] == "string")
|
|
3564
3605
|
return this.fromString(t[0]), this;
|
|
@@ -3605,7 +3646,7 @@ class w extends P {
|
|
|
3605
3646
|
}), this;
|
|
3606
3647
|
}
|
|
3607
3648
|
}
|
|
3608
|
-
class g extends
|
|
3649
|
+
class g extends z {
|
|
3609
3650
|
constructor(...t) {
|
|
3610
3651
|
return super(), t.length > 0 && this.parse(...t), this;
|
|
3611
3652
|
}
|
|
@@ -3615,7 +3656,7 @@ class g extends P {
|
|
|
3615
3656
|
if (t.length === 0)
|
|
3616
3657
|
throw new Error("Invalid value");
|
|
3617
3658
|
if (t.length === 1) {
|
|
3618
|
-
if (t[0] instanceof
|
|
3659
|
+
if (t[0] instanceof z)
|
|
3619
3660
|
return this.array = t[0].copy(), this;
|
|
3620
3661
|
if (typeof t[0] == "string")
|
|
3621
3662
|
return this.fromString(t[0]);
|
|
@@ -3623,7 +3664,7 @@ class g extends P {
|
|
|
3623
3664
|
}
|
|
3624
3665
|
if (t.length === 2) {
|
|
3625
3666
|
const [e, i] = t;
|
|
3626
|
-
if (e instanceof
|
|
3667
|
+
if (e instanceof z && i instanceof z) {
|
|
3627
3668
|
if (e.dimension !== i.dimension)
|
|
3628
3669
|
throw new Error("Vectors must have the same dimension");
|
|
3629
3670
|
return this.array = i.array.map((s, r) => s.clone().subtract(e.array[r])), this;
|
|
@@ -3663,12 +3704,12 @@ class g extends P {
|
|
|
3663
3704
|
// ------------------------------------------
|
|
3664
3705
|
// Creation / parsing functions
|
|
3665
3706
|
divideByScalar = (t) => this.multiplyByScalar(new h(t).inverse());
|
|
3666
|
-
dot = (t) =>
|
|
3707
|
+
dot = (t) => Bt(this, t);
|
|
3667
3708
|
fromString(t) {
|
|
3668
3709
|
return t.startsWith("((") && t.endsWith("))") ? super.fromString(t.slice(1, -1)) : super.fromString(t);
|
|
3669
3710
|
}
|
|
3670
|
-
isColinearTo = (t) =>
|
|
3671
|
-
isEqual = (t) =>
|
|
3711
|
+
isColinearTo = (t) => Mt(this, t);
|
|
3712
|
+
isEqual = (t) => kt(this, t);
|
|
3672
3713
|
isNormalTo = (t) => this.dot(t).isZero();
|
|
3673
3714
|
// ------------------------------------------
|
|
3674
3715
|
get isNull() {
|
|
@@ -3699,7 +3740,7 @@ class g extends P {
|
|
|
3699
3740
|
one = () => (this.zero(), this.x.one(), this);
|
|
3700
3741
|
opposite = () => (this.array.forEach((t) => t.opposite()), this);
|
|
3701
3742
|
simplify = () => {
|
|
3702
|
-
const t =
|
|
3743
|
+
const t = b.lcm(...this.array.map((i) => i.denominator)), e = b.gcd(...this.array.map((i) => i.numerator));
|
|
3703
3744
|
return this.multiplyByScalar(new h(t, e)), this.x.isNegative() && this.opposite(), this;
|
|
3704
3745
|
};
|
|
3705
3746
|
subtract = (t) => this.add(t.clone().opposite());
|
|
@@ -3711,8 +3752,8 @@ class g extends P {
|
|
|
3711
3752
|
return t === 0 ? this : this.divideByScalar(t);
|
|
3712
3753
|
};
|
|
3713
3754
|
}
|
|
3714
|
-
var V = /* @__PURE__ */ ((n) => (n.None = "none", n.Parallel = "parallel", n.Perpendicular = "perpendicular", n.Tangent = "tangent", n))(V || {}),
|
|
3715
|
-
function
|
|
3755
|
+
var V = /* @__PURE__ */ ((n) => (n.None = "none", n.Parallel = "parallel", n.Perpendicular = "perpendicular", n.Tangent = "tangent", n))(V || {}), K = /* @__PURE__ */ ((n) => (n.None = "none", n.Parallel = "parallel", n.Perpendicular = "perpendicular", n.Tangent = "tangent", n))(K || {});
|
|
3756
|
+
function ot(n = 0.5) {
|
|
3716
3757
|
return Math.random() < n;
|
|
3717
3758
|
}
|
|
3718
3759
|
function O(n, t, e) {
|
|
@@ -3730,23 +3771,23 @@ function O(n, t, e) {
|
|
|
3730
3771
|
return i;
|
|
3731
3772
|
}
|
|
3732
3773
|
function A(n, t) {
|
|
3733
|
-
return t === !1 ?
|
|
3774
|
+
return t === !1 ? ot() ? O(1, n) : -O(1, n) : O(-n, n);
|
|
3734
3775
|
}
|
|
3735
|
-
function
|
|
3736
|
-
const e =
|
|
3776
|
+
function St(n, t) {
|
|
3777
|
+
const e = b.pythagoreanTripletsWithTarget(n).filter((i) => t === !0 || !i.includes(0));
|
|
3737
3778
|
return e.length === 0 ? null : W(e);
|
|
3738
3779
|
}
|
|
3739
|
-
function
|
|
3740
|
-
let t =
|
|
3780
|
+
function It(n) {
|
|
3781
|
+
let t = b.primes();
|
|
3741
3782
|
return n !== void 0 && (t = t.filter((e) => e < n)), W(t);
|
|
3742
3783
|
}
|
|
3743
|
-
function
|
|
3744
|
-
return t === void 0 && (t = 1), n.length <= 0 ? Object.values(n) :
|
|
3784
|
+
function Pt(n, t) {
|
|
3785
|
+
return t === void 0 && (t = 1), n.length <= 0 ? Object.values(n) : ht(n).slice(0, t);
|
|
3745
3786
|
}
|
|
3746
3787
|
function W(n) {
|
|
3747
3788
|
return n.length === 0 ? null : n[O(0, n.length - 1)];
|
|
3748
3789
|
}
|
|
3749
|
-
function
|
|
3790
|
+
function ht(n) {
|
|
3750
3791
|
const t = Object.values(n);
|
|
3751
3792
|
for (let e = t.length - 1; e > 0; e--) {
|
|
3752
3793
|
const i = Math.floor(Math.random() * (e + 1)), s = t[e];
|
|
@@ -3786,11 +3827,11 @@ class E {
|
|
|
3786
3827
|
if (t.length === 1) {
|
|
3787
3828
|
if (t[0] instanceof E)
|
|
3788
3829
|
return this.fromCoefficient(t[0].a, t[0].b, t[0].c);
|
|
3789
|
-
if (t[0] instanceof
|
|
3830
|
+
if (t[0] instanceof x)
|
|
3790
3831
|
return this.fromEquation(t[0]);
|
|
3791
3832
|
if (typeof t[0] == "string")
|
|
3792
3833
|
try {
|
|
3793
|
-
const e = new
|
|
3834
|
+
const e = new x(t[0]);
|
|
3794
3835
|
return this.parse(e);
|
|
3795
3836
|
} catch (e) {
|
|
3796
3837
|
return console.warn(e), this;
|
|
@@ -3817,13 +3858,13 @@ class E {
|
|
|
3817
3858
|
case 0:
|
|
3818
3859
|
return this.getEquation().reorder().tex;
|
|
3819
3860
|
case 2:
|
|
3820
|
-
return this.slope.isInfinity() ? "x=" + this.OA.x.tex : "y=" + new
|
|
3861
|
+
return this.slope.isInfinity() ? "x=" + this.OA.x.tex : "y=" + new l().parse("x", this.slope, this.height).tex;
|
|
3821
3862
|
case 3:
|
|
3822
3863
|
case 4: {
|
|
3823
3864
|
const e = this.d.clone().simplify();
|
|
3824
3865
|
return t === 3 ? `${g.asTex("x", "y")} = ${g.asTex(this.#t.x.tex, this.#t.y.tex)} + k\\cdot ${g.asTex(e.x.tex, e.y.tex)}` : `\\left\\{\\begin{aligned}
|
|
3825
|
-
x &= ${new
|
|
3826
|
-
y &= ${new
|
|
3866
|
+
x &= ${new l(this.#t.x).add(new p(e.x).multiply(new p("k"))).reorder("k", !0).tex}\\\\
|
|
3867
|
+
y &= ${new l(this.#t.y).add(new p(e.y).multiply(new p("k"))).reorder("k", !0).tex}
|
|
3827
3868
|
\\end{aligned}\\right.`;
|
|
3828
3869
|
}
|
|
3829
3870
|
default: {
|
|
@@ -3838,13 +3879,13 @@ class E {
|
|
|
3838
3879
|
case 0:
|
|
3839
3880
|
return this.getEquation().reorder().display;
|
|
3840
3881
|
case 2:
|
|
3841
|
-
return this.slope.isInfinity() ? "x=" + this.OA.x.display : "y=" + new
|
|
3882
|
+
return this.slope.isInfinity() ? "x=" + this.OA.x.display : "y=" + new l().parse("x", this.slope, this.height).display;
|
|
3842
3883
|
case 3: {
|
|
3843
3884
|
const e = this.d.clone().simplify();
|
|
3844
3885
|
return `((x,y))=((${this.#t.x.display},${this.#t.y.display}))+k((${e.x.display},${e.y.display}))`;
|
|
3845
3886
|
}
|
|
3846
3887
|
case 4: {
|
|
3847
|
-
const e = this.d.clone().simplify(), i = new
|
|
3888
|
+
const e = this.d.clone().simplify(), i = new l(this.#t.x).add(new p(e.x).multiply(new p("k"))).reorder("k", !0), s = new l(this.#t.y).add(new p(e.y).multiply(new p("k"))).reorder("k", !0);
|
|
3848
3889
|
return `{(x,=,${i.display}),(y,=,${s.display}):}`;
|
|
3849
3890
|
}
|
|
3850
3891
|
default: {
|
|
@@ -3913,7 +3954,7 @@ class E {
|
|
|
3913
3954
|
}
|
|
3914
3955
|
fromCoefficient(t, e, i) {
|
|
3915
3956
|
this.#e = new h(t), this.#i = new h(e), this.#s = new h(i);
|
|
3916
|
-
const s = [this.#e, this.#i, this.#s].every((o) => o.exact) ?
|
|
3957
|
+
const s = [this.#e, this.#i, this.#s].every((o) => o.exact) ? b.lcm(this.#e.denominator, this.#i.denominator, this.#s.denominator) : 1;
|
|
3917
3958
|
if (s > 1 && (this.#e.multiply(s).reduce(), this.#i.multiply(s).reduce(), this.#s.multiply(s).reduce()), this.#i.isZero())
|
|
3918
3959
|
return this.#t = new g(this.#s.clone().divide(this.#e).opposite(), 0), this;
|
|
3919
3960
|
for (let o = 0; o < this.#i.value; o++) {
|
|
@@ -3961,15 +4002,15 @@ class E {
|
|
|
3961
4002
|
}
|
|
3962
4003
|
// ------------------------------------------
|
|
3963
4004
|
getEquation() {
|
|
3964
|
-
return new
|
|
4005
|
+
return new x(new l().parse("xy", this.#e, this.#i, this.#s), new l("0")).simplify();
|
|
3965
4006
|
}
|
|
3966
4007
|
getValueAtX = (t) => {
|
|
3967
4008
|
const e = this.getEquation().isolate("y"), i = new h(t);
|
|
3968
|
-
return e instanceof
|
|
4009
|
+
return e instanceof x ? e.right.evaluate({ x: i }) : new h().invalid();
|
|
3969
4010
|
};
|
|
3970
4011
|
getValueAtY = (t) => {
|
|
3971
4012
|
const e = this.getEquation().isolate("x"), i = new h(t);
|
|
3972
|
-
return e instanceof
|
|
4013
|
+
return e instanceof x ? e.right.evaluate({ y: i }) : new h().invalid();
|
|
3973
4014
|
};
|
|
3974
4015
|
get height() {
|
|
3975
4016
|
return this.#s.clone().opposite().divide(this.#i);
|
|
@@ -4021,7 +4062,7 @@ class E {
|
|
|
4021
4062
|
return new w(e);
|
|
4022
4063
|
};
|
|
4023
4064
|
simplify = () => {
|
|
4024
|
-
const t =
|
|
4065
|
+
const t = b.lcm(this.#e.denominator, this.#i.denominator, this.#s.denominator), e = b.gcd(this.#e.numerator, this.#i.numerator, this.#s.numerator);
|
|
4025
4066
|
return this.fromCoefficient(
|
|
4026
4067
|
this.#e.clone().multiply(t).divide(e),
|
|
4027
4068
|
this.#i.clone().multiply(t).divide(e),
|
|
@@ -4264,7 +4305,7 @@ class L {
|
|
|
4264
4305
|
}
|
|
4265
4306
|
#c(t, e, i) {
|
|
4266
4307
|
const s = (e ** 2 + i ** 2 - t ** 2) / (2 * e * i);
|
|
4267
|
-
return this.#n ? Math.acos(s) :
|
|
4308
|
+
return this.#n ? Math.acos(s) : b.numberCorrection(Math.acos(s) * 180 / Math.PI);
|
|
4268
4309
|
}
|
|
4269
4310
|
/**
|
|
4270
4311
|
* Get the Point class for the given name
|
|
@@ -4300,7 +4341,7 @@ class U {
|
|
|
4300
4341
|
t.length > 0 && this.parse(...t);
|
|
4301
4342
|
}
|
|
4302
4343
|
parse(...t) {
|
|
4303
|
-
return typeof t[0] == "string" ? this.fromString(t[0]) : t[0] instanceof
|
|
4344
|
+
return typeof t[0] == "string" ? this.fromString(t[0]) : t[0] instanceof x ? this.fromEquation(t[0]) : t[0] instanceof U ? this.copy(t[0]) : t.length === 2 && t[0] instanceof w && t[1] instanceof w ? this.fromCenterPoint(t[0], t[1]) : t.length >= 2 && t[0] instanceof w && (t[1] instanceof h || typeof t[1] == "number") ? this.fromCenterRadius(
|
|
4304
4345
|
t[0],
|
|
4305
4346
|
t[1],
|
|
4306
4347
|
typeof t[2] == "boolean" ? t[2] : !1
|
|
@@ -4338,7 +4379,7 @@ class U {
|
|
|
4338
4379
|
return this.#t ?? new w();
|
|
4339
4380
|
}
|
|
4340
4381
|
get equation() {
|
|
4341
|
-
return this.#e?.clone() ?? new
|
|
4382
|
+
return this.#e?.clone() ?? new x("0=0");
|
|
4342
4383
|
}
|
|
4343
4384
|
fromCenterPoint(t, e) {
|
|
4344
4385
|
return this.#t = t.clone(), this.#s = new g(this.#t, e).normSquare, this.#r(), this;
|
|
@@ -4367,10 +4408,10 @@ class U {
|
|
|
4367
4408
|
);
|
|
4368
4409
|
}
|
|
4369
4410
|
fromString(t) {
|
|
4370
|
-
return this.fromEquation(new
|
|
4411
|
+
return this.fromEquation(new x(t));
|
|
4371
4412
|
}
|
|
4372
4413
|
getPointsOnCircle() {
|
|
4373
|
-
const t =
|
|
4414
|
+
const t = b.pythagoreanTripletsWithTarget(this.squareRadius.value, !0), e = [];
|
|
4374
4415
|
return t.forEach((i) => {
|
|
4375
4416
|
for (const s of [[1, 1], [-1, 1], [-1, -1], [1, -1]]) {
|
|
4376
4417
|
const r = this.center.x.clone().add(s[0] * i[0]), o = this.center.y.clone().add(s[1] * i[1]);
|
|
@@ -4401,7 +4442,7 @@ class U {
|
|
|
4401
4442
|
return [
|
|
4402
4443
|
new w(f.x, f.y),
|
|
4403
4444
|
new w(m.x, m.y)
|
|
4404
|
-
].sort((d,
|
|
4445
|
+
].sort((d, v) => i.x.isZero() ? i.y.isPositive() ? d.y.value - v.y.value : v.y.value - d.y.value : i.x.isPositive() ? d.x.value - v.x.value : v.x.value - d.x.value);
|
|
4405
4446
|
}
|
|
4406
4447
|
get radius() {
|
|
4407
4448
|
return new T().from(2, this.#s ?? 0);
|
|
@@ -4425,9 +4466,9 @@ class U {
|
|
|
4425
4466
|
}
|
|
4426
4467
|
tangents = (t) => t instanceof h ? this.#c(t) : this.isPointOnCircle(t) ? this.#o(t) : this.#t !== null && this.#t.distanceTo(t).value > this.radius.value ? this.#a(t) : [];
|
|
4427
4468
|
#r() {
|
|
4428
|
-
this.#e = new
|
|
4429
|
-
new
|
|
4430
|
-
new
|
|
4469
|
+
this.#e = new x(
|
|
4470
|
+
new l(`(x-(${this.center.x.display}))^2+(y-(${this.center.y.display}))^2`),
|
|
4471
|
+
new l(this.squareRadius.display)
|
|
4431
4472
|
).moveLeft();
|
|
4432
4473
|
}
|
|
4433
4474
|
#n() {
|
|
@@ -4438,10 +4479,10 @@ class U {
|
|
|
4438
4479
|
return [new E().fromPointAndNormal(t, e)];
|
|
4439
4480
|
};
|
|
4440
4481
|
#a = (t) => {
|
|
4441
|
-
const e = this.center.x.clone().subtract(t.x), i = this.center.y.clone().subtract(t.y), s = new
|
|
4442
|
-
return s.multiply(e).subtract(i).pow(2), r.multiply(this.squareRadius), new
|
|
4482
|
+
const e = this.center.x.clone().subtract(t.x), i = this.center.y.clone().subtract(t.y), s = new l("x"), r = new l("x^2+1");
|
|
4483
|
+
return s.multiply(e).subtract(i).pow(2), r.multiply(this.squareRadius), new x(s, r).solve().map((c) => {
|
|
4443
4484
|
let f;
|
|
4444
|
-
const m = new
|
|
4485
|
+
const m = new x("y", "x");
|
|
4445
4486
|
return c.exact ? (f = t.x.clone().opposite().multiply(c.fraction).add(t.y), m.right.multiply(c.fraction).add(f)) : (f = t.x.clone().opposite().multiply(c.value).add(t.y), m.right.multiply(c.value).add(f)), new E(m);
|
|
4446
4487
|
});
|
|
4447
4488
|
};
|
|
@@ -4451,9 +4492,9 @@ class U {
|
|
|
4451
4492
|
};
|
|
4452
4493
|
}
|
|
4453
4494
|
class X {
|
|
4454
|
-
static PARALLEL =
|
|
4495
|
+
static PARALLEL = K.Parallel;
|
|
4455
4496
|
// A line is defined as the canonical form
|
|
4456
|
-
static PERPENDICULAR =
|
|
4497
|
+
static PERPENDICULAR = K.Perpendicular;
|
|
4457
4498
|
// ax + by + c = 0
|
|
4458
4499
|
#t = new w();
|
|
4459
4500
|
#e = new g();
|
|
@@ -4465,11 +4506,11 @@ class X {
|
|
|
4465
4506
|
return {
|
|
4466
4507
|
parametric: `${g.asTex("x", "y", "z")} = ${g.asTex(this.#t.x.tex, this.#t.y.tex, this.#t.z.tex)} + k\\cdot ${g.asTex(this.#e.x.tex, this.#e.y.tex, this.#e.z.tex)}`,
|
|
4467
4508
|
system: `\\left\\{\\begin{aligned}
|
|
4468
|
-
x &= ${new
|
|
4469
|
-
y &= ${new
|
|
4470
|
-
z &= ${new
|
|
4509
|
+
x &= ${new l(this.#t.x).add(new p(this.#e.x).multiply(new p("k"))).reorder("k", !0).tex}\\\\
|
|
4510
|
+
y &= ${new l(this.#t.y).add(new p(this.#e.y).multiply(new p("k"))).reorder("k", !0).tex}\\\\
|
|
4511
|
+
z &= ${new l(this.#t.z).add(new p(this.#e.z).multiply(new p("k"))).reorder("k", !0).tex}
|
|
4471
4512
|
\\end{aligned}\\right.`,
|
|
4472
|
-
cartesian: `\\frac{ ${new
|
|
4513
|
+
cartesian: `\\frac{ ${new l("x", 1, this.#t.x.clone().opposite()).tex} }{ ${this.direction.x.tex} } = \\frac{ ${new l("y", 1, this.#t.y.clone().opposite()).tex} }{ ${this.direction.y.tex} } = \\frac{ ${new l("z", 1, this.#t.z.clone().opposite()).tex} }{ ${this.direction.z.tex} }`
|
|
4473
4514
|
};
|
|
4474
4515
|
}
|
|
4475
4516
|
get display() {
|
|
@@ -4559,7 +4600,7 @@ class X {
|
|
|
4559
4600
|
throw new Error("Method not implemented.");
|
|
4560
4601
|
};
|
|
4561
4602
|
}
|
|
4562
|
-
class
|
|
4603
|
+
class et {
|
|
4563
4604
|
#t = new g(0, 0, 1);
|
|
4564
4605
|
#e = new w(0, 0, 0);
|
|
4565
4606
|
constructor(t) {
|
|
@@ -4593,22 +4634,22 @@ class tt {
|
|
|
4593
4634
|
}
|
|
4594
4635
|
}
|
|
4595
4636
|
get tex() {
|
|
4596
|
-
return new
|
|
4597
|
-
new
|
|
4598
|
-
new
|
|
4637
|
+
return new x(
|
|
4638
|
+
new l("xyz", this.a, this.b, this.c, this.d),
|
|
4639
|
+
new l(0)
|
|
4599
4640
|
).reduce().tex;
|
|
4600
4641
|
}
|
|
4601
4642
|
get display() {
|
|
4602
|
-
return new
|
|
4603
|
-
new
|
|
4604
|
-
new
|
|
4643
|
+
return new x(
|
|
4644
|
+
new l("xyz", this.a, this.b, this.c, this.d),
|
|
4645
|
+
new l(0)
|
|
4605
4646
|
).reduce().display;
|
|
4606
4647
|
}
|
|
4607
4648
|
get a() {
|
|
4608
4649
|
return this.#t.x;
|
|
4609
4650
|
}
|
|
4610
4651
|
angle(t, e, i) {
|
|
4611
|
-
if (t instanceof
|
|
4652
|
+
if (t instanceof et)
|
|
4612
4653
|
return this.normal.angle(t.normal, e, i);
|
|
4613
4654
|
let s;
|
|
4614
4655
|
if (t instanceof g) {
|
|
@@ -4656,7 +4697,7 @@ class tt {
|
|
|
4656
4697
|
this.#e = new w(t);
|
|
4657
4698
|
}
|
|
4658
4699
|
}
|
|
4659
|
-
var
|
|
4700
|
+
var at = /* @__PURE__ */ ((n) => (n[n.INTERIOR = 0] = "INTERIOR", n[n.EXTERIOR = 1] = "EXTERIOR", n[n.SECANT = 2] = "SECANT", n[n.TANGENT_INSIDE = 3] = "TANGENT_INSIDE", n[n.TANGENT_OUTSIDE = 4] = "TANGENT_OUTSIDE", n[n.SUPERPOSED = 5] = "SUPERPOSED", n[n.CONCENTRIC = 6] = "CONCENTRIC", n))(at || {});
|
|
4660
4701
|
class zt {
|
|
4661
4702
|
#t = void 0;
|
|
4662
4703
|
#e = void 0;
|
|
@@ -4666,7 +4707,7 @@ class zt {
|
|
|
4666
4707
|
return t && e && (this.#t = t, this.#e = new h(e).clone().pow(2), this.#n()), this;
|
|
4667
4708
|
}
|
|
4668
4709
|
fromEquation(t) {
|
|
4669
|
-
const e = new
|
|
4710
|
+
const e = new x(t).moveLeft().reduce(), i = ["x", "y", "z"];
|
|
4670
4711
|
if (i.some((r) => e.degree(r).value !== 2))
|
|
4671
4712
|
return this.makeUndefined();
|
|
4672
4713
|
const s = e.left.monomByDegree(2, "x").coefficient;
|
|
@@ -4729,7 +4770,7 @@ class zt {
|
|
|
4729
4770
|
if (this.center[s].isZero())
|
|
4730
4771
|
e.push(`${s}^2`);
|
|
4731
4772
|
else {
|
|
4732
|
-
const r = new
|
|
4773
|
+
const r = new l(s).subtract(this.center[s]);
|
|
4733
4774
|
e.push(
|
|
4734
4775
|
t ? `\\(${r.tex}\\)^2` : `(${r.display})^2`
|
|
4735
4776
|
);
|
|
@@ -4737,16 +4778,16 @@ class zt {
|
|
|
4737
4778
|
}), e.join("+") + "=" + (t ? this.squareRadius.tex : this.squareRadius.display);
|
|
4738
4779
|
};
|
|
4739
4780
|
#n() {
|
|
4740
|
-
this.#i = new
|
|
4741
|
-
new
|
|
4742
|
-
new
|
|
4781
|
+
this.#i = new x(
|
|
4782
|
+
new l("x").subtract(this.center.x).pow(2).add(
|
|
4783
|
+
new l("y").subtract(this.center.y).pow(2)
|
|
4743
4784
|
).add(
|
|
4744
|
-
new
|
|
4785
|
+
new l("z").subtract(this.center.z).pow(2)
|
|
4745
4786
|
),
|
|
4746
|
-
new
|
|
4787
|
+
new l(this.squareRadius)
|
|
4747
4788
|
).reduce();
|
|
4748
4789
|
}
|
|
4749
|
-
static RELATIVE_POSITION =
|
|
4790
|
+
static RELATIVE_POSITION = at;
|
|
4750
4791
|
relativePosition = (t) => {
|
|
4751
4792
|
const e = this.center.distanceTo(t.center).value, i = this.radius.value, s = t.radius.value;
|
|
4752
4793
|
return e > i + s ? 1 : e === i + s ? 4 : e === 0 ? i === s ? 5 : 6 : e === Math.abs(i - s) ? 3 : e < Math.abs(i - s) ? 0 : 2;
|
|
@@ -4777,7 +4818,7 @@ function F(n) {
|
|
|
4777
4818
|
}
|
|
4778
4819
|
return t.reduced ? e.reduce() : e;
|
|
4779
4820
|
}
|
|
4780
|
-
function
|
|
4821
|
+
function ct(n) {
|
|
4781
4822
|
const t = Object.assign(
|
|
4782
4823
|
{
|
|
4783
4824
|
letters: "x",
|
|
@@ -4802,7 +4843,7 @@ function at(n) {
|
|
|
4802
4843
|
e.setLetter(t.letters, t.degree);
|
|
4803
4844
|
return e;
|
|
4804
4845
|
}
|
|
4805
|
-
const
|
|
4846
|
+
const lt = {
|
|
4806
4847
|
letters: "x",
|
|
4807
4848
|
degree: 2,
|
|
4808
4849
|
fraction: !1,
|
|
@@ -4814,18 +4855,18 @@ const ct = {
|
|
|
4814
4855
|
commonConstant: !1,
|
|
4815
4856
|
positive: !0
|
|
4816
4857
|
};
|
|
4817
|
-
function
|
|
4858
|
+
function it(n) {
|
|
4818
4859
|
const t = Object.assign(
|
|
4819
4860
|
{},
|
|
4820
|
-
|
|
4861
|
+
lt,
|
|
4821
4862
|
n
|
|
4822
4863
|
);
|
|
4823
|
-
if (t.factorable) return
|
|
4824
|
-
const e = new
|
|
4864
|
+
if (t.factorable) return Rt(t);
|
|
4865
|
+
const e = new l().empty();
|
|
4825
4866
|
let i;
|
|
4826
4867
|
const s = t.degree ?? 2;
|
|
4827
4868
|
for (let r = s; r >= 0; r--)
|
|
4828
|
-
i =
|
|
4869
|
+
i = ct({
|
|
4829
4870
|
letters: t.letters,
|
|
4830
4871
|
degree: r,
|
|
4831
4872
|
fraction: t.fraction,
|
|
@@ -4838,22 +4879,22 @@ function et(n) {
|
|
|
4838
4879
|
}
|
|
4839
4880
|
return e.reduce();
|
|
4840
4881
|
}
|
|
4841
|
-
function
|
|
4882
|
+
function Rt(n) {
|
|
4842
4883
|
const t = Object.assign(
|
|
4843
|
-
|
|
4884
|
+
lt,
|
|
4844
4885
|
n
|
|
4845
4886
|
), e = { ...t };
|
|
4846
4887
|
e.degree = 1, e.factorable = !1;
|
|
4847
4888
|
const i = [], s = t.degree ?? 2;
|
|
4848
4889
|
for (; i.length < s; )
|
|
4849
|
-
i.push(
|
|
4890
|
+
i.push(it(e));
|
|
4850
4891
|
if (n?.commonConstant !== !1) {
|
|
4851
4892
|
let r = A(10, !1);
|
|
4852
|
-
n?.commonConstant === !0 && (r === 1 || r === -1) && (r *= O(2, 5)), r !== 1 && r !== -1 && i.unshift(new
|
|
4893
|
+
n?.commonConstant === !0 && (r === 1 || r === -1) && (r *= O(2, 5)), r !== 1 && r !== -1 && i.unshift(new l(r));
|
|
4853
4894
|
}
|
|
4854
|
-
return
|
|
4895
|
+
return l.xMultiply(...i);
|
|
4855
4896
|
}
|
|
4856
|
-
function
|
|
4897
|
+
function Zt(n) {
|
|
4857
4898
|
const t = Object.assign(
|
|
4858
4899
|
{
|
|
4859
4900
|
letters: "x",
|
|
@@ -4873,9 +4914,9 @@ function Rt(n) {
|
|
|
4873
4914
|
}
|
|
4874
4915
|
},
|
|
4875
4916
|
n
|
|
4876
|
-
), e = new
|
|
4917
|
+
), e = new l().one();
|
|
4877
4918
|
for (let i = 0; i < t.degree; i++) {
|
|
4878
|
-
const s =
|
|
4919
|
+
const s = it({
|
|
4879
4920
|
degree: 1,
|
|
4880
4921
|
unit: t.unit,
|
|
4881
4922
|
fraction: t.fraction,
|
|
@@ -4884,9 +4925,9 @@ function Rt(n) {
|
|
|
4884
4925
|
});
|
|
4885
4926
|
e.multiply(s);
|
|
4886
4927
|
}
|
|
4887
|
-
return new
|
|
4928
|
+
return new x(e, 0);
|
|
4888
4929
|
}
|
|
4889
|
-
function
|
|
4930
|
+
function J(n) {
|
|
4890
4931
|
const t = Object.assign(
|
|
4891
4932
|
{
|
|
4892
4933
|
axis: !0,
|
|
@@ -4898,7 +4939,7 @@ function K(n) {
|
|
|
4898
4939
|
), e = t.axis === "x", i = t.axis === "y", s = t.fraction ? F({ max: t.max, zero: e }) : new h(A(t.max, e)), r = t.fraction ? F({ max: t.max, zero: i }) : new h(A(t.max, i));
|
|
4899
4940
|
return Number(t.quadrant) === 1 && (s.abs(), r.abs()), Number(t.quadrant) === 2 && (s.isPositive() && s.opposite(), r.isNegative() && r.opposite()), Number(t.quadrant) === 3 && (s.isPositive() && s.opposite(), r.isPositive() && r.opposite()), Number(t.quadrant) === 4 && (s.isNegative() && s.opposite(), r.isPositive() && r.opposite()), new w(s, r);
|
|
4900
4941
|
}
|
|
4901
|
-
function
|
|
4942
|
+
function Dt(n) {
|
|
4902
4943
|
const t = Object.assign(
|
|
4903
4944
|
{
|
|
4904
4945
|
center: {
|
|
@@ -4908,11 +4949,11 @@ function Zt(n) {
|
|
|
4908
4949
|
pointsOnCircle: 8
|
|
4909
4950
|
},
|
|
4910
4951
|
n
|
|
4911
|
-
), e =
|
|
4952
|
+
), e = J(t.center);
|
|
4912
4953
|
let i, s;
|
|
4913
4954
|
return t.pointsOnCircle === 8 ? (i = O(1, 3), s = i ** 2 + (i + 1) ** 2) : s = O(1, 20), new U(e, s, !0);
|
|
4914
4955
|
}
|
|
4915
|
-
function
|
|
4956
|
+
function Vt(n) {
|
|
4916
4957
|
const t = Object.assign(
|
|
4917
4958
|
{
|
|
4918
4959
|
A: {
|
|
@@ -4926,7 +4967,7 @@ function Dt(n) {
|
|
|
4926
4967
|
e.x = A(10, t.allow?.vertical ?? !0), e.y = A(10, t.allow?.horizontal ?? !0);
|
|
4927
4968
|
return t.slope === 1 ? e.x.sign() !== e.y.sign() && e.y.opposite() : t.slope === -1 && e.x.sign() !== e.y.sign() && e.y.opposite(), new E().fromPointAndDirection(new g(t.A.x, t.A.y), e);
|
|
4928
4969
|
}
|
|
4929
|
-
function
|
|
4970
|
+
function Lt(n) {
|
|
4930
4971
|
const t = Object.assign(
|
|
4931
4972
|
{
|
|
4932
4973
|
A: {
|
|
@@ -4944,37 +4985,37 @@ function Vt(n) {
|
|
|
4944
4985
|
), e = new w(t.A.x, t.A.y, t.A.z), i = new g(t.direction.x, t.direction.y, t.direction.z);
|
|
4945
4986
|
return new X(e, i);
|
|
4946
4987
|
}
|
|
4947
|
-
const
|
|
4948
|
-
equation: (n) =>
|
|
4949
|
-
polynom: (n) =>
|
|
4950
|
-
monom: (n) =>
|
|
4988
|
+
const Ut = {
|
|
4989
|
+
equation: (n) => Zt(n),
|
|
4990
|
+
polynom: (n) => it(n),
|
|
4991
|
+
monom: (n) => ct(n),
|
|
4951
4992
|
fraction: (n) => F(n),
|
|
4952
4993
|
number: (n, t, e) => O(n, t, e),
|
|
4953
4994
|
numberSym: (n, t) => A(n, t),
|
|
4954
|
-
prime: (n) =>
|
|
4955
|
-
triplet: (n, t) =>
|
|
4956
|
-
bool: (n) =>
|
|
4957
|
-
array: (n, t) =>
|
|
4995
|
+
prime: (n) => It(n),
|
|
4996
|
+
triplet: (n, t) => St(n, t),
|
|
4997
|
+
bool: (n) => ot(n),
|
|
4998
|
+
array: (n, t) => Pt(n, t),
|
|
4958
4999
|
item: (n) => W(n),
|
|
4959
|
-
shuffle: (n) =>
|
|
4960
|
-
line: (n) =>
|
|
4961
|
-
line3: (n) =>
|
|
4962
|
-
vector: (n) =>
|
|
4963
|
-
point: (n) => new w(
|
|
4964
|
-
circle: (n) =>
|
|
4965
|
-
},
|
|
4966
|
-
Numeric:
|
|
5000
|
+
shuffle: (n) => ht(n),
|
|
5001
|
+
line: (n) => Vt(n),
|
|
5002
|
+
line3: (n) => Lt(n),
|
|
5003
|
+
vector: (n) => J(n),
|
|
5004
|
+
point: (n) => new w(J(n)),
|
|
5005
|
+
circle: (n) => Dt(n)
|
|
5006
|
+
}, Gt = {
|
|
5007
|
+
Numeric: b,
|
|
4967
5008
|
Fraction: h,
|
|
4968
5009
|
Root: T,
|
|
4969
5010
|
Monom: p,
|
|
4970
|
-
Polynom:
|
|
4971
|
-
Equation:
|
|
5011
|
+
Polynom: l,
|
|
5012
|
+
Equation: x,
|
|
4972
5013
|
Matrix: B,
|
|
4973
|
-
LinearSystem:
|
|
4974
|
-
Factor:
|
|
5014
|
+
LinearSystem: P,
|
|
5015
|
+
Factor: y,
|
|
4975
5016
|
PolyFactor: N,
|
|
4976
|
-
LogicalSet:
|
|
4977
|
-
Random:
|
|
5017
|
+
LogicalSet: $t,
|
|
5018
|
+
Random: Ut,
|
|
4978
5019
|
Geometry: {
|
|
4979
5020
|
Vector: g,
|
|
4980
5021
|
Point: w,
|
|
@@ -4982,43 +5023,43 @@ const Lt = {
|
|
|
4982
5023
|
Triangle: L,
|
|
4983
5024
|
Circle: U,
|
|
4984
5025
|
Line3: X,
|
|
4985
|
-
Plane3:
|
|
5026
|
+
Plane3: et,
|
|
4986
5027
|
Sphere3: zt
|
|
4987
5028
|
},
|
|
4988
|
-
NumExp:
|
|
5029
|
+
NumExp: qt
|
|
4989
5030
|
};
|
|
4990
5031
|
export {
|
|
4991
5032
|
U as Circle,
|
|
4992
|
-
|
|
5033
|
+
x as Equation,
|
|
4993
5034
|
R as EquationSolver,
|
|
4994
5035
|
D as FACTOR_DISPLAY,
|
|
4995
|
-
|
|
4996
|
-
|
|
5036
|
+
bt as FRAC_TYPE,
|
|
5037
|
+
y as Factor,
|
|
4997
5038
|
h as Fraction,
|
|
4998
5039
|
E as Line,
|
|
4999
5040
|
X as Line3,
|
|
5000
|
-
|
|
5001
|
-
|
|
5041
|
+
P as LinearSystem,
|
|
5042
|
+
$t as LogicalSet,
|
|
5002
5043
|
B as Matrix,
|
|
5003
5044
|
p as Monom,
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5045
|
+
qt as NumExp,
|
|
5046
|
+
b as Numeric,
|
|
5047
|
+
et as Plane3,
|
|
5007
5048
|
w as Point,
|
|
5008
5049
|
N as PolyFactor,
|
|
5009
|
-
|
|
5010
|
-
|
|
5050
|
+
l as Polynom,
|
|
5051
|
+
Ut as Random,
|
|
5011
5052
|
T as Root,
|
|
5012
|
-
|
|
5053
|
+
at as SPHERE3_RELATIVE_POSITION,
|
|
5013
5054
|
C as Solution,
|
|
5014
5055
|
zt as Sphere3,
|
|
5015
|
-
|
|
5056
|
+
jt as TableOfSigns,
|
|
5016
5057
|
L as Triangle,
|
|
5017
5058
|
g as Vector,
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5059
|
+
Mt as areVectorsColinears,
|
|
5060
|
+
kt as areVectorsEquals,
|
|
5061
|
+
Gt as default,
|
|
5062
|
+
Ft as determinantFromVectors,
|
|
5063
|
+
Bt as dotProduct
|
|
5023
5064
|
};
|
|
5024
5065
|
//# sourceMappingURL=pimath.js.map
|