pimath 0.1.36 → 0.1.38
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 +982 -972
- package/dist/pimath.js.map +1 -1
- package/package.json +12 -14
- package/types/algebra/equationSolver.d.ts.map +1 -1
- package/types/algebra/polynom.d.ts.map +1 -1
package/dist/pimath.js
CHANGED
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
function
|
|
2
|
-
const e =
|
|
1
|
+
function le(r) {
|
|
2
|
+
const e = ie(r), t = [];
|
|
3
3
|
let i, s;
|
|
4
4
|
for (; e.length > 0; )
|
|
5
5
|
i = e.shift() ?? 1, s = (e.length > 0 ? e.pop() : +i) ?? 1, t.push([i, s]);
|
|
6
6
|
return t;
|
|
7
7
|
}
|
|
8
|
-
function
|
|
9
|
-
const e =
|
|
10
|
-
return
|
|
8
|
+
function ce(...r) {
|
|
9
|
+
const e = K(...r);
|
|
10
|
+
return r.map((t) => t / e);
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
const e = Math.abs(
|
|
12
|
+
function ie(r) {
|
|
13
|
+
const e = Math.abs(r), t = Math.sqrt(e), i = [];
|
|
14
14
|
for (let s = 1; s <= t; s++)
|
|
15
|
-
|
|
16
|
-
return i.sort(function(s,
|
|
17
|
-
return s -
|
|
15
|
+
r % s === 0 && (i.push(s), i.push(e / s));
|
|
16
|
+
return i.sort(function(s, n) {
|
|
17
|
+
return s - n;
|
|
18
18
|
}), [...new Set(i)];
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
const e = function(s,
|
|
22
|
-
return
|
|
20
|
+
function K(...r) {
|
|
21
|
+
const e = function(s, n) {
|
|
22
|
+
return n === 0 ? s : e(n, s % n);
|
|
23
23
|
};
|
|
24
24
|
let t = 1, i = 2;
|
|
25
|
-
if (
|
|
25
|
+
if (r.length === 0)
|
|
26
26
|
return 1;
|
|
27
|
-
if (
|
|
28
|
-
return
|
|
29
|
-
if (t = e(
|
|
27
|
+
if (r.length === 1)
|
|
28
|
+
return r[0] === 0 ? 1 : r[0];
|
|
29
|
+
if (t = e(r[0], r[1]), t === 1)
|
|
30
30
|
return 1;
|
|
31
|
-
for (i = 2; i <
|
|
31
|
+
for (i = 2; i < r.length && (t = e(t, r[i]), t !== 1); i++)
|
|
32
32
|
;
|
|
33
33
|
return Math.abs(t);
|
|
34
34
|
}
|
|
35
|
-
function
|
|
36
|
-
return
|
|
37
|
-
return Math.abs(e * t /
|
|
35
|
+
function ue(...r) {
|
|
36
|
+
return r.reduce(function(e, t) {
|
|
37
|
+
return Math.abs(e * t / K(e, t));
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
|
-
function
|
|
41
|
-
return +
|
|
40
|
+
function fe(r, e = 3) {
|
|
41
|
+
return +r.toFixed(e);
|
|
42
42
|
}
|
|
43
|
-
function
|
|
44
|
-
if (Number.isSafeInteger(
|
|
43
|
+
function de(r) {
|
|
44
|
+
if (Number.isSafeInteger(r) || r.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 pe(r) {
|
|
49
49
|
const e = [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
|
-
return
|
|
50
|
+
return r === void 0 ? e : e.slice(0, Math.min(e.length, r));
|
|
51
51
|
}
|
|
52
|
-
function
|
|
53
|
-
const t = [], i = e === !0 ? +
|
|
54
|
-
for (let s = 0; s <=
|
|
55
|
-
for (let
|
|
56
|
-
s ** 2 +
|
|
52
|
+
function me(r, e) {
|
|
53
|
+
const t = [], i = e === !0 ? +r : r ** 2;
|
|
54
|
+
for (let s = 0; s <= r; s++)
|
|
55
|
+
for (let n = 0; n <= r; n++)
|
|
56
|
+
s ** 2 + n ** 2 === i && t.push([s, n, r]);
|
|
57
57
|
return t;
|
|
58
58
|
}
|
|
59
|
-
function
|
|
60
|
-
return +`${Math.round(+`${
|
|
59
|
+
function ge(r, e = 2) {
|
|
60
|
+
return +`${Math.round(+`${r}e${e}`)}e-${e}`;
|
|
61
61
|
}
|
|
62
62
|
const E = {
|
|
63
|
-
decompose:
|
|
64
|
-
dividers:
|
|
65
|
-
divideNumbersByGCD:
|
|
66
|
-
gcd:
|
|
67
|
-
lcm:
|
|
68
|
-
numberCorrection:
|
|
69
|
-
periodic:
|
|
70
|
-
primes:
|
|
71
|
-
pythagoreanTripletsWithTarget:
|
|
72
|
-
round:
|
|
63
|
+
decompose: le,
|
|
64
|
+
dividers: ie,
|
|
65
|
+
divideNumbersByGCD: ce,
|
|
66
|
+
gcd: K,
|
|
67
|
+
lcm: ue,
|
|
68
|
+
numberCorrection: fe,
|
|
69
|
+
periodic: de,
|
|
70
|
+
primes: pe,
|
|
71
|
+
pythagoreanTripletsWithTarget: me,
|
|
72
|
+
round: ge
|
|
73
73
|
};
|
|
74
|
-
var
|
|
74
|
+
var we = /* @__PURE__ */ ((r) => (r.frac = "frac", r.dfrac = "dfrac", r.tfrac = "tfrac", r))(we || {});
|
|
75
75
|
class a {
|
|
76
|
-
#
|
|
76
|
+
#i = !1;
|
|
77
77
|
#e = 1;
|
|
78
|
-
#
|
|
78
|
+
#t = 1;
|
|
79
79
|
#s = "frac";
|
|
80
80
|
constructor(e, t) {
|
|
81
81
|
return e !== void 0 && this.parse(e, t), this;
|
|
@@ -89,37 +89,37 @@ class a {
|
|
|
89
89
|
parse = (e, t) => {
|
|
90
90
|
let i;
|
|
91
91
|
if (e === "")
|
|
92
|
-
return this.#
|
|
92
|
+
return this.#t = 0, this.#e = 1, this;
|
|
93
93
|
switch (typeof e) {
|
|
94
94
|
case "string":
|
|
95
|
-
if (i = e.split("/"), i.length > 2 && (this.#
|
|
95
|
+
if (i = e.split("/"), i.length > 2 && (this.#t = NaN), i.map((s) => s === "" || isNaN(Number(s))).includes(!0) && (this.#t = NaN), i.length === 1)
|
|
96
96
|
return this.parse(+i[0]);
|
|
97
|
-
i.length === 2 ? i[1] === "0" ? (this.#
|
|
97
|
+
i.length === 2 ? i[1] === "0" ? (this.#t = NaN, this.#e = 1) : (this.#t = +i[0], this.#e = +i[1]) : (this.#t = NaN, this.#e = 1);
|
|
98
98
|
break;
|
|
99
99
|
case "number":
|
|
100
100
|
if (Number.isSafeInteger(e))
|
|
101
|
-
this.#
|
|
101
|
+
this.#t = +e, t === void 0 || !Number.isSafeInteger(t) ? this.#e = 1 : this.#e = +t;
|
|
102
102
|
else {
|
|
103
|
-
const [, s] = e.toString().split("."),
|
|
104
|
-
t === void 0 ? (this.#
|
|
103
|
+
const [, s] = e.toString().split("."), n = s ? s.length : 0, o = Math.pow(10, n);
|
|
104
|
+
t === void 0 ? (this.#t = e * o, this.#e = o) : Number.isSafeInteger(t) && (this.#t = e * o - Math.floor(e * Math.pow(10, n - t)), this.denominator = o - Math.pow(10, n - t)), this.#t = E.numberCorrection(this.#t), this.#e = E.numberCorrection(this.#e), this.reduce();
|
|
105
105
|
}
|
|
106
106
|
break;
|
|
107
107
|
case "object":
|
|
108
|
-
e instanceof a && (this.#
|
|
108
|
+
e instanceof a && (this.#t = +e.numerator, this.#e = +e.denominator);
|
|
109
109
|
break;
|
|
110
110
|
}
|
|
111
111
|
return this;
|
|
112
112
|
};
|
|
113
113
|
clone = () => {
|
|
114
114
|
const e = new a();
|
|
115
|
-
return e.numerator = +this.#
|
|
115
|
+
return e.numerator = +this.#t, e.denominator = +this.#e, e;
|
|
116
116
|
};
|
|
117
117
|
// Display getter
|
|
118
118
|
get tex() {
|
|
119
|
-
return this.isInfinity() ? `${this.sign() === 1 ? "+" : "-"}\\infty` : this.isExact() ? this.#e === 1 ? `${this.#
|
|
119
|
+
return this.isInfinity() ? `${this.sign() === 1 ? "+" : "-"}\\infty` : this.isExact() ? this.#e === 1 ? `${this.#t}` : this.#t < 0 ? `-\\${this.#s}{ ${-this.#t} }{ ${this.#e} }` : `\\${this.#s}{ ${this.#t} }{ ${this.#e} }` : this.value.toFixed(3);
|
|
120
120
|
}
|
|
121
121
|
get display() {
|
|
122
|
-
return this.isExact() ? this.#e === 1 ? `${this.#
|
|
122
|
+
return this.isExact() ? this.#e === 1 ? `${this.#t}` : `${this.#t}/${this.#e}` : this.value.toFixed(3);
|
|
123
123
|
}
|
|
124
124
|
static average = (...e) => {
|
|
125
125
|
const t = new a().zero();
|
|
@@ -128,11 +128,11 @@ class a {
|
|
|
128
128
|
return t.divide(e.length), t;
|
|
129
129
|
};
|
|
130
130
|
static isFraction(e) {
|
|
131
|
-
if (e instanceof a || typeof e == "number" && !isNaN(e))
|
|
131
|
+
if (e instanceof a || typeof e == "number" && !isNaN(+e))
|
|
132
132
|
return !0;
|
|
133
133
|
if (typeof e == "string") {
|
|
134
134
|
const [t, i] = e.split("/");
|
|
135
|
-
return !isNaN(+t) &&
|
|
135
|
+
return !isNaN(+t) && !isNaN(+i);
|
|
136
136
|
}
|
|
137
137
|
return !1;
|
|
138
138
|
}
|
|
@@ -155,7 +155,7 @@ class a {
|
|
|
155
155
|
return t;
|
|
156
156
|
};
|
|
157
157
|
static sort = (e, t) => {
|
|
158
|
-
const s = e.map((
|
|
158
|
+
const s = e.map((n) => n instanceof a ? n : new a(n)).sort((n, o) => n.value - o.value);
|
|
159
159
|
return t && s.reverse(), s;
|
|
160
160
|
};
|
|
161
161
|
static unique = (e) => {
|
|
@@ -172,16 +172,16 @@ class a {
|
|
|
172
172
|
}
|
|
173
173
|
return t;
|
|
174
174
|
};
|
|
175
|
-
abs = () => (this.#
|
|
175
|
+
abs = () => (this.#t = Math.abs(this.#t), this.#e = Math.abs(this.#e), this);
|
|
176
176
|
add = (e) => {
|
|
177
177
|
if (e instanceof a) {
|
|
178
|
-
const t = this.#
|
|
179
|
-
this.#
|
|
178
|
+
const t = this.#t, i = this.#e;
|
|
179
|
+
this.#t = t * e.denominator + e.numerator * i, this.#e = i * e.denominator;
|
|
180
180
|
} else
|
|
181
181
|
return this.add(new a(e));
|
|
182
182
|
return this.reduce();
|
|
183
183
|
};
|
|
184
|
-
amplify = (e) => (Number.isSafeInteger(e) && (this.#
|
|
184
|
+
amplify = (e) => (Number.isSafeInteger(e) && (this.#t *= e, this.#e *= e), this);
|
|
185
185
|
/**
|
|
186
186
|
* Simple function to determine if it's a fraction
|
|
187
187
|
*/
|
|
@@ -229,73 +229,73 @@ class a {
|
|
|
229
229
|
const t = new a(e);
|
|
230
230
|
if (t.numerator === 0)
|
|
231
231
|
return new a().infinite();
|
|
232
|
-
const i = this.#
|
|
233
|
-
return this.#
|
|
232
|
+
const i = this.#t, s = this.#e;
|
|
233
|
+
return this.#t = i * t.denominator, this.#e = s * t.numerator, this.reduce();
|
|
234
234
|
};
|
|
235
235
|
get frac() {
|
|
236
236
|
return this.#s = "frac", this;
|
|
237
237
|
}
|
|
238
|
-
infinite = () => (this.#
|
|
239
|
-
invalid = () => (this.#
|
|
238
|
+
infinite = () => (this.#t = 1 / 0, this.#e = 1, this);
|
|
239
|
+
invalid = () => (this.#t = NaN, this.#e = 1, this);
|
|
240
240
|
inverse = () => {
|
|
241
|
-
const e = +this.#
|
|
242
|
-
return this.#
|
|
241
|
+
const e = +this.#t;
|
|
242
|
+
return this.#t = +this.#e, this.#e = e, this;
|
|
243
243
|
};
|
|
244
|
-
isApproximative = () => this.#
|
|
244
|
+
isApproximative = () => this.#i || this.#t.toString().length >= 15 && this.#e.toString().length >= 15;
|
|
245
245
|
isEqual = (e) => this.compare(e, "=");
|
|
246
246
|
isEven = () => this.isRelative() && this.value % 2 === 0;
|
|
247
247
|
isExact = () => !this.isApproximative();
|
|
248
248
|
isFinite = () => !this.isInfinity() && !this.isNaN();
|
|
249
249
|
isGeq = (e) => this.compare(e, ">=");
|
|
250
250
|
isGreater = (e) => this.compare(e, ">");
|
|
251
|
-
isInfinity = () => Math.abs(this.#
|
|
251
|
+
isInfinity = () => Math.abs(this.#t) === 1 / 0;
|
|
252
252
|
isInverted = (e) => this.isEqual(new a().one().divide(e.clone()));
|
|
253
253
|
isLeq = (e) => this.compare(e, "<=");
|
|
254
254
|
/* Compare shortcuts */
|
|
255
255
|
isLesser = (e) => this.compare(e, "<");
|
|
256
|
-
isNaN = () => isNaN(this.#
|
|
256
|
+
isNaN = () => isNaN(this.#t);
|
|
257
257
|
isNatural = () => this.isRelative() && this.isPositive();
|
|
258
258
|
isNegative = () => this.sign() === -1;
|
|
259
|
-
isNegativeOne = () => this.#
|
|
259
|
+
isNegativeOne = () => this.#t === -1 && this.#e === 1;
|
|
260
260
|
// ------------------------------------------
|
|
261
261
|
isNotEqual = (e) => this.compare(e, "<>");
|
|
262
|
-
isNotZero = () => this.#
|
|
262
|
+
isNotZero = () => this.#t !== 0;
|
|
263
263
|
isOdd = () => this.isRelative() && this.value % 2 === 1;
|
|
264
|
-
isOne = () => this.#
|
|
264
|
+
isOne = () => this.#t === 1 && this.#e === 1;
|
|
265
265
|
isOpposite = (e) => this.isEqual(e.clone().opposite());
|
|
266
266
|
isPositive = () => this.sign() === 1;
|
|
267
267
|
isRational = () => !this.isRelative();
|
|
268
|
-
isReduced = () => Math.abs(E.gcd(this.#
|
|
268
|
+
isReduced = () => Math.abs(E.gcd(this.#t, this.#e)) === 1;
|
|
269
269
|
isRelative = () => this.clone().reduce().denominator === 1;
|
|
270
|
-
isSquare = () => Math.sqrt(this.#
|
|
270
|
+
isSquare = () => Math.sqrt(this.#t) % 1 === 0 && Math.sqrt(this.#e) % 1 === 0;
|
|
271
271
|
isStrictlyNegative = () => this.value < 0;
|
|
272
272
|
isStrictlyPositive = () => this.value > 0;
|
|
273
273
|
// Mathematical operations specific to fractions
|
|
274
|
-
isZero = () => this.#
|
|
274
|
+
isZero = () => this.#t === 0;
|
|
275
275
|
multiply = (e) => {
|
|
276
276
|
const t = new a(e);
|
|
277
|
-
return this.#
|
|
277
|
+
return this.#t = this.#t * t.numerator, this.#e = this.#e * t.denominator, this.reduce();
|
|
278
278
|
};
|
|
279
279
|
// ------------------------------------------
|
|
280
280
|
get numerator() {
|
|
281
|
-
return this.#
|
|
281
|
+
return this.#t;
|
|
282
282
|
}
|
|
283
283
|
set numerator(e) {
|
|
284
|
-
this.#
|
|
284
|
+
this.#t = e;
|
|
285
285
|
}
|
|
286
|
-
one = () => (this.#
|
|
287
|
-
opposite = () => (this.#
|
|
286
|
+
one = () => (this.#t = 1, this.#e = 1, this);
|
|
287
|
+
opposite = () => (this.#t = -this.#t, this);
|
|
288
288
|
pow = (e) => {
|
|
289
289
|
if (e instanceof a)
|
|
290
290
|
return this.pow(e.value);
|
|
291
291
|
this.reduce(), e < 0 && this.inverse();
|
|
292
|
-
const t = Math.floor(Math.pow(this.#
|
|
293
|
-
return t ** Math.abs(e) === this.#
|
|
292
|
+
const t = Math.floor(Math.pow(this.#t, Math.abs(e))), i = Math.floor(Math.pow(this.#e, Math.abs(e)));
|
|
293
|
+
return t ** Math.abs(e) === this.#t && i ** Math.abs(e) === this.#e ? (this.#t = this.#t ** Math.abs(e), this.#e = this.#e ** Math.abs(e)) : (this.#t = this.#t ** Math.abs(e), this.#e = this.#e ** Math.abs(e)), this;
|
|
294
294
|
};
|
|
295
295
|
// ------------------------------------------
|
|
296
296
|
reduce = () => {
|
|
297
|
-
const e = E.gcd(this.#
|
|
298
|
-
return this.#
|
|
297
|
+
const e = E.gcd(this.#t, this.#e);
|
|
298
|
+
return this.#t = this.#t / e, this.#e = this.#e / e, this.#e < 0 && (this.#e = -this.#e, this.#t = -this.#t), this;
|
|
299
299
|
};
|
|
300
300
|
// ------------------------------------------
|
|
301
301
|
// Getter and setter
|
|
@@ -308,10 +308,10 @@ class a {
|
|
|
308
308
|
throw new Error("The root of a negative number must be odd.");
|
|
309
309
|
const t = this.sign();
|
|
310
310
|
this.abs(), this.reduce();
|
|
311
|
-
const i = Math.floor(Math.pow(this.#
|
|
312
|
-
return this.#
|
|
311
|
+
const i = Math.floor(Math.pow(this.#t, Math.abs(1 / e))), s = Math.floor(Math.pow(this.#e, Math.abs(1 / e)));
|
|
312
|
+
return this.#t = Math.pow(this.#t, Math.abs(1 / e)), this.#e = Math.pow(this.#e, Math.abs(1 / e)), (i !== this.#t || s !== this.#e) && (this.#t = this.#t / this.#e, this.#e = 1, this.#i = !0), this.multiply(t), this;
|
|
313
313
|
};
|
|
314
|
-
sign = () => this.#
|
|
314
|
+
sign = () => this.#t * this.#e >= 0 ? 1 : -1;
|
|
315
315
|
sqrt = () => this.root(2);
|
|
316
316
|
subtract = (e) => e instanceof a ? this.add(e.clone().opposite()) : this.add(-e);
|
|
317
317
|
get texWithSign() {
|
|
@@ -321,27 +321,27 @@ class a {
|
|
|
321
321
|
return this.#s = "tfrac", this;
|
|
322
322
|
}
|
|
323
323
|
get value() {
|
|
324
|
-
const e = this.#
|
|
324
|
+
const e = this.#t / this.#e;
|
|
325
325
|
return e === 0 ? 0 : e;
|
|
326
326
|
}
|
|
327
|
-
zero = () => (this.#
|
|
327
|
+
zero = () => (this.#t = 0, this.#e = 1, this);
|
|
328
328
|
}
|
|
329
|
-
class
|
|
330
|
-
#t;
|
|
331
|
-
#e;
|
|
329
|
+
class j {
|
|
332
330
|
#i;
|
|
331
|
+
#e;
|
|
332
|
+
#t;
|
|
333
333
|
#s;
|
|
334
334
|
constructor(...e) {
|
|
335
|
-
this.#
|
|
335
|
+
this.#i = 1, this.#t = 1, this.#e = 2, this.#s = !0, e.length > 0 && this.parse(e[0], e[1], e[2]);
|
|
336
336
|
}
|
|
337
337
|
// ------------------------------------------
|
|
338
338
|
// Getter and setter
|
|
339
339
|
// ------------------------------------------
|
|
340
340
|
get radical() {
|
|
341
|
-
return this.#
|
|
341
|
+
return this.#i;
|
|
342
342
|
}
|
|
343
343
|
set radical(e) {
|
|
344
|
-
this.#
|
|
344
|
+
this.#i = e;
|
|
345
345
|
}
|
|
346
346
|
get nth() {
|
|
347
347
|
return this.#e;
|
|
@@ -350,58 +350,58 @@ class X {
|
|
|
350
350
|
Number.isSafeInteger(e) && e >= 2 ? this.#e = e : (console.log("Error setting the nth root"), this.#e = 2);
|
|
351
351
|
}
|
|
352
352
|
get coefficient() {
|
|
353
|
-
return this.#
|
|
353
|
+
return this.#t;
|
|
354
354
|
}
|
|
355
355
|
set coefficient(e) {
|
|
356
|
-
this.#
|
|
356
|
+
this.#t = e;
|
|
357
357
|
}
|
|
358
358
|
get tex() {
|
|
359
359
|
let e;
|
|
360
|
-
return this.#
|
|
360
|
+
return this.#t === 1 ? e = "" : this.#t === -1 ? e = "-" : e = this.#t.toString(), this.#i === 1 ? `${this.#t}` : this.#e === 2 ? `${e}\\sqrt{${this.#i}}` : `${e}\\sqrt[${this.#e}]{${this.#i}}`;
|
|
361
361
|
}
|
|
362
362
|
get display() {
|
|
363
363
|
let e;
|
|
364
|
-
return this.#
|
|
364
|
+
return this.#t === 1 ? e = "" : this.#t === -1 ? e = "-" : e = this.#t.toString(), this.#i === 1 ? `${this.#t}` : this.#e === 2 ? `${e}sqrt{${this.#i}}` : `${e}root(${this.#e}){${this.#i}}`;
|
|
365
365
|
}
|
|
366
366
|
get value() {
|
|
367
|
-
return this.#
|
|
367
|
+
return this.#t * Math.pow(this.#i, 1 / this.#e);
|
|
368
368
|
}
|
|
369
369
|
// ------------------------------------------
|
|
370
370
|
// Creation / parsing functions
|
|
371
371
|
// ------------------------------------------
|
|
372
|
-
parse = (e, t, i) => (this.#
|
|
372
|
+
parse = (e, t, i) => (this.#t = i ?? 1, this.#e = t ?? 2, this.#i = e, this.#e % 2 === 0 && this.#i < 0 && (this.#s = !1), this);
|
|
373
373
|
// ------------------------------------------
|
|
374
374
|
// Mathematical operations
|
|
375
375
|
// ------------------------------------------
|
|
376
376
|
reduce = () => {
|
|
377
|
-
let e = Math.floor(Math.pow(this.#
|
|
377
|
+
let e = Math.floor(Math.pow(this.#i, 1 / this.#e));
|
|
378
378
|
for (; e > 1; ) {
|
|
379
|
-
if (this.#
|
|
380
|
-
this.#
|
|
379
|
+
if (this.#i % Math.pow(e, this.#e) === 0) {
|
|
380
|
+
this.#t *= e, this.#i = this.#i / Math.pow(e, this.#e), e = Math.floor(Math.pow(this.#i, 1 / this.#e));
|
|
381
381
|
continue;
|
|
382
382
|
}
|
|
383
383
|
e--;
|
|
384
384
|
}
|
|
385
385
|
return this;
|
|
386
386
|
};
|
|
387
|
-
multiply = (e) => (this.#
|
|
387
|
+
multiply = (e) => (this.#i *= e.radical, this.reduce());
|
|
388
388
|
// ------------------------------------------
|
|
389
389
|
// Help functions
|
|
390
390
|
// ------------------------------------------
|
|
391
|
-
hasRadical = () => !(this.#
|
|
391
|
+
hasRadical = () => !(this.#i === 1 || this.#i === 0 || !this.#s);
|
|
392
392
|
}
|
|
393
|
-
class
|
|
394
|
-
#
|
|
393
|
+
class W {
|
|
394
|
+
#i;
|
|
395
395
|
#e;
|
|
396
396
|
constructor(e, t, i = "x") {
|
|
397
397
|
if (this.#e = i, Object.hasOwn(e, "moveLeft")) {
|
|
398
398
|
const s = e;
|
|
399
|
-
this.#
|
|
399
|
+
this.#i = s.left.clone().subtract(s.right);
|
|
400
400
|
} else
|
|
401
|
-
this.#
|
|
401
|
+
this.#i = e.clone().subtract(t ?? 0);
|
|
402
402
|
}
|
|
403
403
|
solve() {
|
|
404
|
-
const e = this.#
|
|
404
|
+
const e = this.#i.degree().value;
|
|
405
405
|
if (e === 0)
|
|
406
406
|
return [];
|
|
407
407
|
if (e === 1)
|
|
@@ -410,15 +410,15 @@ class J {
|
|
|
410
410
|
return this.#u();
|
|
411
411
|
const { solutions: t, polynom: i } = this.#a();
|
|
412
412
|
return i.degree().isZero() ? t : t.concat(
|
|
413
|
-
this.#
|
|
414
|
-
).sort((s,
|
|
413
|
+
this.#n(i)
|
|
414
|
+
).sort((s, n) => s.value - n.value);
|
|
415
415
|
}
|
|
416
416
|
solveAsCardan() {
|
|
417
|
-
if (this.#
|
|
417
|
+
if (this.#i.degree().value !== 3)
|
|
418
418
|
throw new Error("The equation is not cubic.");
|
|
419
419
|
return this.#c();
|
|
420
420
|
}
|
|
421
|
-
#
|
|
421
|
+
#t(e, t) {
|
|
422
422
|
return {
|
|
423
423
|
variable: this.#e,
|
|
424
424
|
exact: !1,
|
|
@@ -429,7 +429,7 @@ class J {
|
|
|
429
429
|
}
|
|
430
430
|
#s(e) {
|
|
431
431
|
if (e instanceof a && e.isApproximative())
|
|
432
|
-
return this.#
|
|
432
|
+
return this.#t(e.value);
|
|
433
433
|
const t = new a(e);
|
|
434
434
|
return {
|
|
435
435
|
variable: this.#e,
|
|
@@ -439,24 +439,24 @@ class J {
|
|
|
439
439
|
display: t.display
|
|
440
440
|
};
|
|
441
441
|
}
|
|
442
|
-
#
|
|
443
|
-
const t = [], i = e.degree().value, s = e.getCoefficients().map((d) => d.value), [
|
|
442
|
+
#n(e) {
|
|
443
|
+
const t = [], i = e.degree().value, s = e.getCoefficients().map((d) => d.value), [n, ...o] = e.getCoefficients(), h = 2 + Math.max(...o.map((d) => d.value / n.value)), l = this.#o(e, h, 100);
|
|
444
444
|
return this.#h(l, i).forEach((d) => {
|
|
445
445
|
const [m, w] = d;
|
|
446
446
|
if (m === w)
|
|
447
447
|
t.push(this.#s(m));
|
|
448
448
|
else {
|
|
449
|
-
const N = this.#
|
|
450
|
-
N !== null && t.push(this.#
|
|
449
|
+
const N = this.#r(e, s, m, w);
|
|
450
|
+
N !== null && t.push(this.#t(N));
|
|
451
451
|
}
|
|
452
452
|
}), t;
|
|
453
453
|
}
|
|
454
|
-
#
|
|
454
|
+
#r(e, t, i, s, n = 1e-10) {
|
|
455
455
|
let o = e.evaluate(i, !0), h = e.evaluate(s, !0);
|
|
456
456
|
if (o * h > 0)
|
|
457
457
|
return console.log("Pas de racine dans l'intervalle donné"), null;
|
|
458
458
|
let l;
|
|
459
|
-
for (; (s - i) / 2 >
|
|
459
|
+
for (; (s - i) / 2 > n; ) {
|
|
460
460
|
l = (i + s) / 2;
|
|
461
461
|
const c = e.evaluate(l, !0);
|
|
462
462
|
if (c === 0)
|
|
@@ -466,8 +466,8 @@ class J {
|
|
|
466
466
|
return (i + s) / 2;
|
|
467
467
|
}
|
|
468
468
|
#o(e, t, i) {
|
|
469
|
-
const s = [],
|
|
470
|
-
for (let o = -t; o <= t; o +=
|
|
469
|
+
const s = [], n = 2 * t / i;
|
|
470
|
+
for (let o = -t; o <= t; o += n) {
|
|
471
471
|
const h = E.numberCorrection(o);
|
|
472
472
|
s.push(
|
|
473
473
|
{
|
|
@@ -481,22 +481,22 @@ class J {
|
|
|
481
481
|
#h(e, t) {
|
|
482
482
|
const i = [];
|
|
483
483
|
for (let s = 1; s < e.length; s++) {
|
|
484
|
-
const
|
|
485
|
-
if (
|
|
484
|
+
const n = e[s], o = e[s - 1];
|
|
485
|
+
if (n.fx === 0 ? i.push([n.x, n.x]) : n.fx * o.fx < 0 && i.push([o.x, n.x]), i.length === t)
|
|
486
486
|
return i;
|
|
487
487
|
}
|
|
488
488
|
return i;
|
|
489
489
|
}
|
|
490
490
|
#a() {
|
|
491
|
-
const e = this.#
|
|
491
|
+
const e = this.#i.clone(), t = [], i = e.lcmDenominator();
|
|
492
492
|
i !== 1 && e.multiply(i);
|
|
493
|
-
const s = e.monomByDegree().coefficient,
|
|
494
|
-
if (
|
|
493
|
+
const s = e.monomByDegree().coefficient, n = e.monomByDegree(0).coefficient;
|
|
494
|
+
if (n.isZero()) {
|
|
495
495
|
t.push(this.#s(0));
|
|
496
496
|
const m = e.monoms.reduce((N, A) => A.degree().value < N.degree().value ? A : N), w = m.coefficient;
|
|
497
497
|
m.clone().divide(w), e.divide(m);
|
|
498
498
|
}
|
|
499
|
-
const o = E.dividers(s.value), h = E.dividers(
|
|
499
|
+
const o = E.dividers(s.value), h = E.dividers(n.value), l = [];
|
|
500
500
|
for (const m of o)
|
|
501
501
|
for (const w of h) {
|
|
502
502
|
const N = new a(w, m);
|
|
@@ -517,110 +517,114 @@ class J {
|
|
|
517
517
|
}
|
|
518
518
|
if (e.degree().isZero() || e.degree().value > 3)
|
|
519
519
|
return t.sort((m, w) => m.value - w.value), { solutions: t, polynom: e };
|
|
520
|
-
const c = e.clone().zero(), d = new
|
|
520
|
+
const c = e.clone().zero(), d = new W(e, c, this.#e);
|
|
521
521
|
return {
|
|
522
522
|
solutions: t.concat(d.solve()).sort((m, w) => m.value - w.value),
|
|
523
523
|
polynom: c
|
|
524
524
|
};
|
|
525
525
|
}
|
|
526
526
|
#c() {
|
|
527
|
-
const e = this.#
|
|
527
|
+
const e = this.#i, t = e.monomByDegree(3).coefficient, i = e.monomByDegree(2).coefficient, s = e.monomByDegree(1).coefficient, n = e.monomByDegree(0).coefficient, o = i.clone().divide(t), h = s.clone().divide(t), l = n.clone().divide(t), c = h.clone().subtract(o.clone().pow(2).divide(3)), d = l.clone().subtract(o.clone().multiply(h).divide(3)).add(o.clone().pow(3).multiply(2).divide(27)), m = d.clone().opposite(), w = c.clone().opposite().pow(3).divide(27), N = m.clone().pow(2).subtract(w.clone().multiply(4)).opposite();
|
|
528
528
|
if (N.isNegative()) {
|
|
529
|
-
const A = d.clone().opposite().add(N.clone().opposite().sqrt()).divide(2).root(3),
|
|
530
|
-
return [this.#s(
|
|
529
|
+
const A = d.clone().opposite().add(N.clone().opposite().sqrt()).divide(2).root(3), C = d.clone().opposite().subtract(N.clone().opposite().sqrt()).divide(2).root(3), O = A.clone().add(C).subtract(o.clone().divide(3));
|
|
530
|
+
return [this.#s(O)];
|
|
531
531
|
}
|
|
532
532
|
if (N.isZero()) {
|
|
533
|
-
const A = d.clone().opposite().divide(2).root(3),
|
|
534
|
-
return
|
|
535
|
-
this.#s(
|
|
536
|
-
this.#s(
|
|
533
|
+
const A = d.clone().opposite().divide(2).root(3), C = A.clone().opposite().subtract(o.clone().divide(3)), O = A.clone().multiply(2).subtract(o.clone().divide(3));
|
|
534
|
+
return C.isEqual(O) ? [this.#s(C)] : [
|
|
535
|
+
this.#s(O),
|
|
536
|
+
this.#s(C)
|
|
537
537
|
].sort((M, $) => M.value - $.value);
|
|
538
538
|
}
|
|
539
539
|
if (N.isPositive()) {
|
|
540
|
-
const A = [],
|
|
540
|
+
const A = [], C = c.value, O = d.value, M = o.value;
|
|
541
541
|
for (let $ = 0; $ < 3; $++)
|
|
542
|
-
A.push(2 * Math.sqrt(-
|
|
543
|
-
return A.map(($) => this.#
|
|
542
|
+
A.push(2 * Math.sqrt(-C / 3) * Math.cos(Math.acos(3 * O / (2 * C) * Math.sqrt(-3 / C)) / 3 + 2 * Math.PI * $ / 3) - M / 3);
|
|
543
|
+
return A.map(($) => this.#t($)).sort(($, S) => $.value - S.value);
|
|
544
544
|
}
|
|
545
545
|
return [];
|
|
546
546
|
}
|
|
547
547
|
#l() {
|
|
548
|
-
const [e, t] = this.#
|
|
548
|
+
const [e, t] = this.#i.getCoefficients(), i = t.opposite().divide(e);
|
|
549
549
|
return [
|
|
550
550
|
this.#s(i)
|
|
551
551
|
];
|
|
552
552
|
}
|
|
553
553
|
#u() {
|
|
554
|
-
const e = this.#
|
|
554
|
+
const e = this.#i;
|
|
555
555
|
e.monomByDegree().coefficient.isNegative() && e.opposite();
|
|
556
|
-
const [t, i, s] = e.getCoefficients(),
|
|
557
|
-
if (
|
|
556
|
+
const [t, i, s] = e.getCoefficients(), n = i.clone().pow(2).subtract(t.clone().multiply(s).multiply(4));
|
|
557
|
+
if (n.isNegative())
|
|
558
558
|
return [];
|
|
559
|
-
if (
|
|
560
|
-
const o =
|
|
559
|
+
if (n.isSquare()) {
|
|
560
|
+
const o = n.sqrt(), h = i.clone().opposite().subtract(o).divide(t.clone().multiply(2)), l = i.clone().opposite().add(o).divide(t.clone().multiply(2));
|
|
561
561
|
return o.isZero() ? [this.#s(h)] : [
|
|
562
562
|
this.#s(h),
|
|
563
563
|
this.#s(l)
|
|
564
564
|
].sort((c, d) => c.value - d.value);
|
|
565
565
|
}
|
|
566
|
-
return this.#f(t, i,
|
|
566
|
+
return this.#f(t, i, n);
|
|
567
567
|
}
|
|
568
568
|
#f(e, t, i) {
|
|
569
|
-
const s = E.dividers(i.value).filter((
|
|
570
|
-
function
|
|
571
|
-
|
|
569
|
+
const s = E.dividers(i.value).filter((O) => Math.sqrt(O) % 1 === 0).map((O) => Math.sqrt(O)).pop() ?? 1, n = E.gcd(2 * e.value, t.value, s) * (e.isNegative() ? -1 : 1), o = t.clone().divide(n).opposite(), h = e.clone().divide(n).multiply(2), l = Math.abs(s / n), c = `${s === 1 ? "" : l + " "}\\sqrt{ ${i.clone().divide(s ** 2).tex} }`, d = `${s === 1 ? "" : l}sqrt(${i.clone().divide(s ** 2).display})`;
|
|
570
|
+
function m(O, M, $, S) {
|
|
571
|
+
const R = M === "0" ? "" : M, P = $ === "-" || R !== "" ? ` ${$} ` : "";
|
|
572
|
+
return O === "1" ? `${R}${P}${S}` : `\\frac{ ${P}${P}${S} }{ ${O} }`;
|
|
572
573
|
}
|
|
573
|
-
function
|
|
574
|
-
|
|
574
|
+
function w(O, M, $, S) {
|
|
575
|
+
const R = M === "0" ? "" : M, P = $ === "-" || R !== "" ? $ : "";
|
|
576
|
+
return O === "1" ? `${R}${P}${S}` : `(${R}${P}${S})/${O}`;
|
|
575
577
|
}
|
|
576
|
-
const
|
|
578
|
+
const N = i.value ** 0.5, A = (-t.value - N) / (2 * e.value), C = (-t.value + N) / (2 * e.value);
|
|
577
579
|
return [
|
|
578
|
-
this.#
|
|
579
|
-
|
|
580
|
+
this.#t(
|
|
581
|
+
A,
|
|
580
582
|
{
|
|
581
|
-
tex:
|
|
582
|
-
display:
|
|
583
|
+
tex: m(h.tex, o.tex, "-", c),
|
|
584
|
+
display: w(h.display, o.display, "-", d)
|
|
583
585
|
}
|
|
584
586
|
),
|
|
585
|
-
this.#
|
|
586
|
-
|
|
587
|
+
this.#t(
|
|
588
|
+
C,
|
|
587
589
|
{
|
|
588
|
-
tex:
|
|
589
|
-
display:
|
|
590
|
+
tex: m(h.tex, o.tex, "+", c),
|
|
591
|
+
display: w(h.display, o.display, "+", d)
|
|
590
592
|
}
|
|
591
593
|
)
|
|
592
|
-
].sort((
|
|
594
|
+
].sort((O, M) => O.value - M.value);
|
|
593
595
|
}
|
|
594
596
|
}
|
|
595
|
-
|
|
596
|
-
throw TypeError(n);
|
|
597
|
-
}, ke = (n, e, t) => e in n ? Ce(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, ie = (n, e, t) => ke(n, typeof e != "symbol" ? e + "" : e, t), fe = (n, e, t) => e.has(n) || ue("Cannot " + t), O = (n, e, t) => (fe(n, e, "read from private field"), t ? t.call(n) : e.get(n)), j = (n, e, t) => e.has(n) ? ue("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(n) : e.set(n, t), S = (n, e, t, i) => (fe(n, e, "write to private field"), e.set(n, t), t);
|
|
598
|
-
const oe = {
|
|
597
|
+
const J = {
|
|
599
598
|
pi: Math.PI,
|
|
600
599
|
e: Math.exp(1)
|
|
601
600
|
};
|
|
602
|
-
var f = /* @__PURE__ */ ((
|
|
603
|
-
function
|
|
604
|
-
if (
|
|
605
|
-
return
|
|
601
|
+
var f = /* @__PURE__ */ ((r) => (r.VARIABLE = "variable", r.COEFFICIENT = "coefficient", r.OPERATION = "operation", r.CONSTANT = "constant", r.FUNCTION = "function", r.FUNCTION_ARGUMENT = "function-argument", r.MONOM = "monom", r.LEFT_PARENTHESIS = "(", r.RIGHT_PARENTHESIS = ")", r))(f || {}), z = /* @__PURE__ */ ((r) => (r.EXPRESSION = "expression", r.POLYNOM = "polynom", r.SET = "set", r.NUMERIC = "numeric", r))(z || {});
|
|
602
|
+
function ye(r, e) {
|
|
603
|
+
if (r.length <= 1)
|
|
604
|
+
return r;
|
|
606
605
|
const t = Object.keys(e).filter((m) => e[m].type === f.FUNCTION).map((m) => m);
|
|
607
606
|
t.sort((m, w) => w.length - m.length);
|
|
608
|
-
const i = new RegExp(`^(${t.join("|")})\\(`), s = Object.keys(
|
|
607
|
+
const i = new RegExp(`^(${t.join("|")})\\(`), s = Object.keys(J);
|
|
609
608
|
s.sort((m, w) => w.length - m.length);
|
|
610
|
-
const
|
|
609
|
+
const n = new RegExp(`^(${s.join("|")})`), o = /^(\d+(\.\d+)?)/;
|
|
611
610
|
let h = "", l, c, d;
|
|
612
|
-
for (
|
|
613
|
-
if (
|
|
614
|
-
const
|
|
615
|
-
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
611
|
+
for (t.forEach((m) => {
|
|
612
|
+
if (r.includes(m)) {
|
|
613
|
+
const w = new RegExp(`${m}([0-9.]+)`, "g");
|
|
614
|
+
r = r.replaceAll(w, `${m}($1)`);
|
|
615
|
+
}
|
|
616
|
+
}); r.length > 0; ) {
|
|
617
|
+
if (l = c, d = void 0, t.length > 0 && i.exec(r)) {
|
|
618
|
+
const m = t.find((w) => r.startsWith(w));
|
|
619
|
+
m && (d = m + "(", r = r.slice(m.length + 1), c = f.FUNCTION);
|
|
620
|
+
} else if (s.length > 0 && n.exec(r)) {
|
|
621
|
+
const m = s.find((w) => r.startsWith(w));
|
|
622
|
+
m && (d = m, r = r.slice(m.length), c = f.CONSTANT);
|
|
623
|
+
} else if (o.exec(r)) {
|
|
624
|
+
const m = o.exec(r);
|
|
625
|
+
m && (d = m[0], r = r.slice(m[0].length), c = f.COEFFICIENT);
|
|
622
626
|
} else
|
|
623
|
-
switch (d =
|
|
627
|
+
switch (d = r[0], r = r.slice(1), d) {
|
|
624
628
|
case "(":
|
|
625
629
|
c = f.LEFT_PARENTHESIS;
|
|
626
630
|
break;
|
|
@@ -642,20 +646,20 @@ function $e(n, e) {
|
|
|
642
646
|
}
|
|
643
647
|
if (d === void 0 || c === void 0)
|
|
644
648
|
throw new Error("The token is undefined");
|
|
645
|
-
h +=
|
|
649
|
+
h += ve(l, c), h += d;
|
|
646
650
|
}
|
|
647
651
|
return h;
|
|
648
652
|
}
|
|
649
|
-
function
|
|
650
|
-
return
|
|
653
|
+
function ve(r, e) {
|
|
654
|
+
return r === void 0 || r === f.OPERATION || e === f.OPERATION || r === f.LEFT_PARENTHESIS || r === f.FUNCTION || r === f.FUNCTION_ARGUMENT || e === f.RIGHT_PARENTHESIS || e === f.FUNCTION_ARGUMENT ? "" : "*";
|
|
651
655
|
}
|
|
652
|
-
const
|
|
656
|
+
const be = {
|
|
653
657
|
"^": { precedence: 4, associative: "right", type: f.OPERATION },
|
|
654
658
|
"*": { precedence: 3, associative: "left", type: f.OPERATION },
|
|
655
659
|
"/": { precedence: 3, associative: "left", type: f.OPERATION },
|
|
656
660
|
"+": { precedence: 2, associative: "left", type: f.OPERATION },
|
|
657
661
|
"-": { precedence: 2, associative: "left", type: f.OPERATION }
|
|
658
|
-
},
|
|
662
|
+
}, xe = {
|
|
659
663
|
"^": { precedence: 4, associative: "right", type: f.OPERATION },
|
|
660
664
|
"*": { precedence: 3, associative: "left", type: f.OPERATION },
|
|
661
665
|
"/": { precedence: 3, associative: "left", type: f.OPERATION },
|
|
@@ -668,7 +672,7 @@ const Me = {
|
|
|
668
672
|
sqrt: { precedence: 4, associative: "right", type: f.FUNCTION },
|
|
669
673
|
nthrt: { precedence: 4, associative: "right", type: f.FUNCTION },
|
|
670
674
|
",": { precedence: 2, associative: "left", type: f.FUNCTION_ARGUMENT }
|
|
671
|
-
},
|
|
675
|
+
}, Ee = {
|
|
672
676
|
"^": { precedence: 4, associative: "right", type: f.OPERATION },
|
|
673
677
|
"*": { precedence: 3, associative: "left", type: f.OPERATION },
|
|
674
678
|
"/": { precedence: 3, associative: "left", type: f.OPERATION },
|
|
@@ -682,26 +686,30 @@ const Me = {
|
|
|
682
686
|
nthrt: { precedence: 4, associative: "right", type: f.FUNCTION },
|
|
683
687
|
ln: { precedence: 4, associative: "right", type: f.FUNCTION },
|
|
684
688
|
log: { precedence: 4, associative: "right", type: f.FUNCTION }
|
|
685
|
-
},
|
|
689
|
+
}, Ne = {
|
|
686
690
|
"&": { precedence: 3, associative: "left", type: f.OPERATION },
|
|
687
691
|
"|": { precedence: 3, associative: "left", type: f.OPERATION },
|
|
688
692
|
"!": { precedence: 4, associative: "right", type: f.OPERATION },
|
|
689
693
|
"-": { precedence: 2, associative: "left", type: f.OPERATION }
|
|
690
694
|
};
|
|
691
|
-
|
|
692
|
-
|
|
695
|
+
class X {
|
|
696
|
+
#i;
|
|
697
|
+
#e = [];
|
|
698
|
+
#t = {};
|
|
699
|
+
#s = [];
|
|
700
|
+
#n;
|
|
693
701
|
constructor(e) {
|
|
694
|
-
|
|
702
|
+
this.#i = typeof e > "u" ? z.POLYNOM : e, this.tokenConfigInitialization();
|
|
695
703
|
}
|
|
696
704
|
// Getter
|
|
697
705
|
get rpn() {
|
|
698
|
-
return
|
|
706
|
+
return this.#e;
|
|
699
707
|
}
|
|
700
708
|
get rpnToken() {
|
|
701
|
-
return
|
|
709
|
+
return this.#e.map((e) => e.token);
|
|
702
710
|
}
|
|
703
711
|
tokenConfigInitialization() {
|
|
704
|
-
return
|
|
712
|
+
return this.#i === z.SET ? (this.#t = Ne, this.#n = !1) : this.#i === z.NUMERIC ? (this.#t = Ee, this.#n = !0) : this.#i === z.EXPRESSION ? (this.#t = xe, this.#n = !0) : (this.#t = be, this.#n = !0), this.#s = Object.keys(this.#t).sort((e, t) => t.length - e.length), this.#t;
|
|
705
713
|
}
|
|
706
714
|
/**
|
|
707
715
|
* Get the next token to analyse.
|
|
@@ -717,23 +725,23 @@ class _ {
|
|
|
717
725
|
else if (e[t] === ",")
|
|
718
726
|
i = ",", s = f.FUNCTION_ARGUMENT;
|
|
719
727
|
else {
|
|
720
|
-
for (const
|
|
721
|
-
if (e.substring(t, t +
|
|
722
|
-
i +=
|
|
728
|
+
for (const n of this.#s)
|
|
729
|
+
if (e.substring(t, t + n.length) === n) {
|
|
730
|
+
i += n, s = this.#t[n].type;
|
|
723
731
|
break;
|
|
724
732
|
}
|
|
725
|
-
for (const
|
|
726
|
-
if (e.substring(t, t +
|
|
727
|
-
i +=
|
|
733
|
+
for (const n in J)
|
|
734
|
+
if (e.substring(t, t + n.length) === n) {
|
|
735
|
+
i += n, s = f.CONSTANT;
|
|
728
736
|
break;
|
|
729
737
|
}
|
|
730
738
|
if (i === "")
|
|
731
739
|
if (/[0-9.]/.exec(e[t])) {
|
|
732
|
-
const
|
|
733
|
-
i =
|
|
740
|
+
const n = /^([0-9.]+)/.exec(e.substring(t));
|
|
741
|
+
i = n ? n[0] : "", s = f.COEFFICIENT;
|
|
734
742
|
} else if (/[a-zA-Z]/.exec(e[t])) {
|
|
735
|
-
const
|
|
736
|
-
i =
|
|
743
|
+
const n = /^([a-zA-Z])/.exec(e.substring(t));
|
|
744
|
+
i = n ? n[0] : "", s = f.VARIABLE;
|
|
737
745
|
} else
|
|
738
746
|
console.log("Unidentified token", e[t], e, t), i = e[t], s = f.MONOM;
|
|
739
747
|
}
|
|
@@ -749,30 +757,30 @@ class _ {
|
|
|
749
757
|
*/
|
|
750
758
|
parse(e, t) {
|
|
751
759
|
const i = [], s = [];
|
|
752
|
-
let
|
|
753
|
-
(t ??
|
|
760
|
+
let n = "", o = 0, h;
|
|
761
|
+
(t ?? this.#n) && (e = ye(e, this.#t));
|
|
754
762
|
let l = 50, c;
|
|
755
763
|
for (; o < e.length; ) {
|
|
756
764
|
if (l--, l === 0) {
|
|
757
765
|
console.log("SECURITY LEVEL 1 EXIT");
|
|
758
766
|
break;
|
|
759
767
|
}
|
|
760
|
-
switch ([
|
|
768
|
+
switch ([n, o, h] = this.NextToken(e, o), h) {
|
|
761
769
|
case f.MONOM:
|
|
762
770
|
case f.COEFFICIENT:
|
|
763
771
|
case f.VARIABLE:
|
|
764
772
|
case f.CONSTANT:
|
|
765
773
|
i.push({
|
|
766
|
-
token:
|
|
774
|
+
token: n,
|
|
767
775
|
tokenType: h
|
|
768
776
|
});
|
|
769
777
|
break;
|
|
770
778
|
case f.OPERATION:
|
|
771
779
|
if (s.length > 0) {
|
|
772
780
|
let d = s[s.length - 1];
|
|
773
|
-
for (c = 50; d.token in
|
|
774
|
-
(
|
|
775
|
-
|
|
781
|
+
for (c = 50; d.token in this.#t && //either o1 is left-associative and its precedence is less than or equal to that of o2,
|
|
782
|
+
(this.#t[n].associative === "left" && this.#t[n].precedence <= this.#t[d.token].precedence || //or o1 is right associative, and has precedence less than that of o2,
|
|
783
|
+
this.#t[n].associative === "right" && this.#t[n].precedence < this.#t[d.token].precedence); ) {
|
|
776
784
|
if (c--, c === 0) {
|
|
777
785
|
console.log("SECURITY LEVEL 2 OPERATION EXIT");
|
|
778
786
|
break;
|
|
@@ -782,7 +790,7 @@ class _ {
|
|
|
782
790
|
d = s[s.length - 1];
|
|
783
791
|
}
|
|
784
792
|
}
|
|
785
|
-
s.push({ token:
|
|
793
|
+
s.push({ token: n, tokenType: h });
|
|
786
794
|
break;
|
|
787
795
|
case f.FUNCTION_ARGUMENT:
|
|
788
796
|
for (c = 50; s[s.length - 1].token !== "(" && s.length > 0; ) {
|
|
@@ -790,11 +798,11 @@ class _ {
|
|
|
790
798
|
console.log("SECURITY LEVEL 2 FUNCTION ARGUMENT EXIT");
|
|
791
799
|
break;
|
|
792
800
|
}
|
|
793
|
-
i.push(s.pop() ?? { token:
|
|
801
|
+
i.push(s.pop() ?? { token: n, tokenType: h });
|
|
794
802
|
}
|
|
795
803
|
break;
|
|
796
804
|
case f.LEFT_PARENTHESIS:
|
|
797
|
-
s.push({ token:
|
|
805
|
+
s.push({ token: n, tokenType: h }), e[o] === "-" && i.push({ token: "0", tokenType: f.COEFFICIENT });
|
|
798
806
|
break;
|
|
799
807
|
case f.RIGHT_PARENTHESIS:
|
|
800
808
|
for (c = 50; s[s.length - 1].token !== "(" && s.length > 1; ) {
|
|
@@ -802,28 +810,30 @@ class _ {
|
|
|
802
810
|
console.log("SECURITY LEVEL 2 CLOSING PARENTHESIS EXIT");
|
|
803
811
|
break;
|
|
804
812
|
}
|
|
805
|
-
i.push(s.pop() ?? { token:
|
|
813
|
+
i.push(s.pop() ?? { token: n, tokenType: h });
|
|
806
814
|
}
|
|
807
815
|
s.pop();
|
|
808
816
|
break;
|
|
809
817
|
case f.FUNCTION:
|
|
810
|
-
s.push({ token:
|
|
818
|
+
s.push({ token: n, tokenType: h });
|
|
811
819
|
break;
|
|
812
820
|
default:
|
|
813
|
-
throw new Error(`Token type ${
|
|
821
|
+
throw new Error(`Token type ${n} is not handled`);
|
|
814
822
|
}
|
|
815
823
|
}
|
|
816
|
-
return
|
|
824
|
+
return this.#e = i.concat(s.reverse()), this;
|
|
817
825
|
}
|
|
818
826
|
}
|
|
819
|
-
|
|
820
|
-
|
|
827
|
+
class Ae {
|
|
828
|
+
_rpn;
|
|
829
|
+
_expression;
|
|
830
|
+
_isValid;
|
|
821
831
|
constructor(e, t) {
|
|
822
|
-
|
|
832
|
+
this._expression = e;
|
|
823
833
|
try {
|
|
824
|
-
this._rpn = new
|
|
825
|
-
} catch {
|
|
826
|
-
throw this._rpn = null, this._isValid = !1, new Error(`There was a problem parsing: ${e}`);
|
|
834
|
+
this._rpn = new X(z.NUMERIC).parse(e, t).rpn;
|
|
835
|
+
} catch (i) {
|
|
836
|
+
throw this._rpn = null, this._isValid = !1, console.warn(i), new Error(`There was a problem parsing: ${e}`);
|
|
827
837
|
}
|
|
828
838
|
}
|
|
829
839
|
get rpn() {
|
|
@@ -862,33 +872,33 @@ class Re {
|
|
|
862
872
|
else if (i.tokenType === f.VARIABLE && e !== void 0)
|
|
863
873
|
Object.hasOwn(e, i.token) && t.push(+e[i.token]);
|
|
864
874
|
else if (i.tokenType === f.CONSTANT)
|
|
865
|
-
t.push(
|
|
875
|
+
t.push(J[i.token]);
|
|
866
876
|
else if (i.tokenType === f.OPERATION) {
|
|
867
877
|
if (i.token === "*") {
|
|
868
|
-
const s = t.pop(),
|
|
869
|
-
if (
|
|
870
|
-
throw this._isValid = !1, new Error(`The multiplication factors ${
|
|
871
|
-
t.push(
|
|
878
|
+
const s = t.pop(), n = t.pop();
|
|
879
|
+
if (n === void 0 || s === void 0)
|
|
880
|
+
throw this._isValid = !1, new Error(`The multiplication factors ${n ?? "a"} or ${s ?? "b"} are not defined`);
|
|
881
|
+
t.push(n * s);
|
|
872
882
|
} else if (i.token === "/") {
|
|
873
|
-
const s = t.pop(),
|
|
874
|
-
if (
|
|
875
|
-
throw this._isValid = !1, new Error(`The division values ${
|
|
876
|
-
t.push(
|
|
883
|
+
const s = t.pop(), n = t.pop();
|
|
884
|
+
if (n === void 0 || s === void 0)
|
|
885
|
+
throw this._isValid = !1, new Error(`The division values ${n ?? "a"} or ${s ?? "b"} are not defined`);
|
|
886
|
+
t.push(n / s);
|
|
877
887
|
} else if (i.token === "+") {
|
|
878
|
-
const s = t.pop(),
|
|
879
|
-
if (
|
|
880
|
-
throw this._isValid = !1, new Error(`The addition values ${
|
|
881
|
-
t.push(+
|
|
888
|
+
const s = t.pop(), n = t.pop();
|
|
889
|
+
if (n === void 0 || s === void 0)
|
|
890
|
+
throw this._isValid = !1, new Error(`The addition values ${n ?? "a"} or ${s ?? "b"} are not defined`);
|
|
891
|
+
t.push(+n + +s);
|
|
882
892
|
} else if (i.token === "-") {
|
|
883
|
-
const s = t.pop(),
|
|
893
|
+
const s = t.pop(), n = t.pop() ?? 0;
|
|
884
894
|
if (s === void 0)
|
|
885
895
|
throw this._isValid = !1, new Error("The subtraction value b is not defined");
|
|
886
|
-
t.push(
|
|
896
|
+
t.push(n - s);
|
|
887
897
|
} else if (i.token === "^") {
|
|
888
|
-
const s = t.pop(),
|
|
889
|
-
if (
|
|
890
|
-
throw this._isValid = !1, new Error(`The base value ${
|
|
891
|
-
t.push(Math.pow(
|
|
898
|
+
const s = t.pop(), n = t.pop();
|
|
899
|
+
if (n === void 0 || s === void 0)
|
|
900
|
+
throw this._isValid = !1, new Error(`The base value ${n ?? "a"} or exponent ${s ?? "b"} are not defined`);
|
|
901
|
+
t.push(Math.pow(n, s));
|
|
892
902
|
}
|
|
893
903
|
} else if (i.tokenType === f.FUNCTION) {
|
|
894
904
|
const s = t.pop();
|
|
@@ -903,10 +913,10 @@ class Re {
|
|
|
903
913
|
else if (i.token === "sqrt")
|
|
904
914
|
t.push(Math.sqrt(s));
|
|
905
915
|
else if (i.token === "nthrt") {
|
|
906
|
-
const
|
|
907
|
-
if (
|
|
916
|
+
const n = t.pop();
|
|
917
|
+
if (n === void 0)
|
|
908
918
|
throw this._isValid = !1, new Error("The nthrt function requires two parameters");
|
|
909
|
-
s % 2 === 0 &&
|
|
919
|
+
s % 2 === 0 && n < 0 ? t.push(NaN) : t.push((n < 0 ? -1 : 1) * Math.pow(Math.abs(n), 1 / s));
|
|
910
920
|
} else i.token === "ln" ? t.push(Math.log(s)) : i.token === "log" && t.push(Math.log10(s));
|
|
911
921
|
}
|
|
912
922
|
if (t.length === 1)
|
|
@@ -918,10 +928,10 @@ class Re {
|
|
|
918
928
|
}
|
|
919
929
|
}
|
|
920
930
|
class p {
|
|
921
|
-
#
|
|
931
|
+
#i;
|
|
922
932
|
#e;
|
|
923
933
|
constructor(e) {
|
|
924
|
-
return this.#
|
|
934
|
+
return this.#i = new a().zero(), this.#e = {}, e !== void 0 && this.parse(e), this;
|
|
925
935
|
}
|
|
926
936
|
// -----------------------------------------
|
|
927
937
|
/**
|
|
@@ -929,14 +939,14 @@ class p {
|
|
|
929
939
|
* @param inputStr
|
|
930
940
|
*/
|
|
931
941
|
parse(e) {
|
|
932
|
-
return this.#
|
|
942
|
+
return this.#i = new a(), this.#e = {}, typeof e == "string" ? isNaN(Number(e)) ? this.#n(e) : this.#i = new a(Number(e)) : typeof e == "number" ? this.#i = new a(e) : e instanceof a ? this.#i = e.clone() : e instanceof p && (this.#i = e.#i.clone(), this.#t(e)), this;
|
|
933
943
|
}
|
|
934
944
|
/**
|
|
935
945
|
* Clone the current Monom.
|
|
936
946
|
*/
|
|
937
947
|
clone = () => {
|
|
938
948
|
const e = new p();
|
|
939
|
-
e.coefficient = this.#
|
|
949
|
+
e.coefficient = this.#i.clone();
|
|
940
950
|
for (const t in this.#e)
|
|
941
951
|
e.setLetter(t, this.#e[t].clone());
|
|
942
952
|
return e;
|
|
@@ -949,7 +959,7 @@ class p {
|
|
|
949
959
|
const t = Object.keys(this.#e).sort();
|
|
950
960
|
for (const i of t)
|
|
951
961
|
this.#e[i].isNotZero() && (e += i, this.#e[i].isNotEqual(1) && (e += `^{ ${this.#e[i].tfrac.tex} }`));
|
|
952
|
-
return e === "" ? this.#
|
|
962
|
+
return e === "" ? this.#i.value != 0 ? this.#i.frac.tex : "0" : this.#i.value === 1 ? e : this.#i.value === -1 ? `-${e}` : this.#i.value === 0 ? "0" : `${this.#i.frac.tex}${e}`;
|
|
953
963
|
}
|
|
954
964
|
// Display getter
|
|
955
965
|
/**
|
|
@@ -960,19 +970,19 @@ class p {
|
|
|
960
970
|
const t = Object.keys(this.#e).sort();
|
|
961
971
|
for (const i of t)
|
|
962
972
|
this.#e[i].isNotZero() && (e += i, this.#e[i].isNotEqual(1) && (e += `^(${this.#e[i].display})`));
|
|
963
|
-
return e === "" ? this.#
|
|
973
|
+
return e === "" ? this.#i.value != 0 ? this.#i.display : "" : this.#i.value === 1 ? e : this.#i.value === -1 ? `-${e}` : this.#i.value === 0 ? "0" : `${this.#i.display}${e}`;
|
|
964
974
|
}
|
|
965
975
|
static gcd = (...e) => {
|
|
966
|
-
for (const
|
|
967
|
-
if (
|
|
976
|
+
for (const n of e)
|
|
977
|
+
if (n.containsRationalPower())
|
|
968
978
|
return new p().zero();
|
|
969
|
-
const t = new p(), i = E.gcd(...e.map((
|
|
979
|
+
const t = new p(), i = E.gcd(...e.map((n) => n.coefficient.numerator)), s = E.lcm(...e.map((n) => n.coefficient.denominator));
|
|
970
980
|
t.coefficient = new a(i, s).reduce();
|
|
971
|
-
for (const
|
|
981
|
+
for (const n of e) {
|
|
972
982
|
for (const o in t.literal)
|
|
973
|
-
o in
|
|
974
|
-
for (const o in
|
|
975
|
-
!t.hasVariable(o) &&
|
|
983
|
+
o in n.literal || t.literal[o].zero();
|
|
984
|
+
for (const o in n.literal)
|
|
985
|
+
!t.hasVariable(o) && n.literal[o].isStrictlyPositive() ? t.literal[o] = n.literal[o].clone() : t.literal[o] = new a(Math.min(n.literal[o].value, t.literal[o].value));
|
|
976
986
|
}
|
|
977
987
|
return t;
|
|
978
988
|
};
|
|
@@ -993,7 +1003,7 @@ class p {
|
|
|
993
1003
|
add = (...e) => {
|
|
994
1004
|
for (const t of e) {
|
|
995
1005
|
const i = t instanceof p ? t : new p(t);
|
|
996
|
-
this.isSameAs(i) ? (this.isZero() && this.#
|
|
1006
|
+
this.isSameAs(i) ? (this.isZero() && this.#t(i), this.#i.add(i.coefficient)) : console.log("Add monom: " + this.display + " is not similar with ", i.display);
|
|
997
1007
|
}
|
|
998
1008
|
return this;
|
|
999
1009
|
};
|
|
@@ -1002,14 +1012,14 @@ class p {
|
|
|
1002
1012
|
* @returns {Fraction}
|
|
1003
1013
|
*/
|
|
1004
1014
|
get coefficient() {
|
|
1005
|
-
return this.#
|
|
1015
|
+
return this.#i;
|
|
1006
1016
|
}
|
|
1007
1017
|
/**
|
|
1008
1018
|
* Set the coefficient \\(k\\) value of the monom
|
|
1009
1019
|
* @param {Fraction | number | string} F
|
|
1010
1020
|
*/
|
|
1011
1021
|
set coefficient(e) {
|
|
1012
|
-
this.#
|
|
1022
|
+
this.#i = new a(e);
|
|
1013
1023
|
}
|
|
1014
1024
|
containsRationalPower = () => Object.values(this.#e).some((e) => e.isRational());
|
|
1015
1025
|
/**
|
|
@@ -1024,7 +1034,7 @@ class p {
|
|
|
1024
1034
|
derivative = (e) => {
|
|
1025
1035
|
if (e === void 0 && (e = "x"), this.hasVariable(e)) {
|
|
1026
1036
|
const t = this.#e[e].clone(), i = this.clone();
|
|
1027
|
-
return i.#e[e].subtract(1), i.#
|
|
1037
|
+
return i.#e[e].subtract(1), i.#i.multiply(new a(t.clone())), i;
|
|
1028
1038
|
} else
|
|
1029
1039
|
return new p().zero();
|
|
1030
1040
|
};
|
|
@@ -1035,7 +1045,7 @@ class p {
|
|
|
1035
1045
|
divide = (...e) => {
|
|
1036
1046
|
for (const t of e) {
|
|
1037
1047
|
const i = t instanceof p ? t : new p(t);
|
|
1038
|
-
this.#
|
|
1048
|
+
this.#i.divide(i.coefficient);
|
|
1039
1049
|
for (const s in i.literal)
|
|
1040
1050
|
this.#e[s] = this.hasVariable(s) ? this.#e[s].subtract(i.literal[s]) : i.literal[s].clone().opposite(), this.#e[s].isZero() && this.removeVariable(s);
|
|
1041
1051
|
}
|
|
@@ -1055,19 +1065,19 @@ class p {
|
|
|
1055
1065
|
const i = [];
|
|
1056
1066
|
if (t.length > 0 && e.length > 0)
|
|
1057
1067
|
for (const s of e)
|
|
1058
|
-
for (const
|
|
1068
|
+
for (const n of t) {
|
|
1059
1069
|
const o = new p();
|
|
1060
|
-
o.coefficient = new a(s), o.literal =
|
|
1070
|
+
o.coefficient = new a(s), o.literal = n, i.push(o);
|
|
1061
1071
|
}
|
|
1062
1072
|
else if (e.length === 0)
|
|
1063
1073
|
for (const s of t) {
|
|
1064
|
-
const
|
|
1065
|
-
|
|
1074
|
+
const n = new p();
|
|
1075
|
+
n.coefficient = new a().one(), n.literal = s, i.push(n);
|
|
1066
1076
|
}
|
|
1067
1077
|
else
|
|
1068
1078
|
for (const s of e) {
|
|
1069
|
-
const
|
|
1070
|
-
|
|
1079
|
+
const n = new p();
|
|
1080
|
+
n.coefficient = new a(s), i.push(n);
|
|
1071
1081
|
}
|
|
1072
1082
|
return i.length === 0 ? [new p().one()] : i;
|
|
1073
1083
|
}
|
|
@@ -1080,14 +1090,14 @@ class p {
|
|
|
1080
1090
|
if (t === !0) {
|
|
1081
1091
|
if (e instanceof a)
|
|
1082
1092
|
return this.#s(e.value);
|
|
1083
|
-
if (e instanceof
|
|
1093
|
+
if (e instanceof j)
|
|
1084
1094
|
return new a().invalid();
|
|
1085
1095
|
if (typeof e == "number")
|
|
1086
1096
|
return this.#s(e);
|
|
1087
1097
|
if (typeof e == "object") {
|
|
1088
1098
|
const s = {};
|
|
1089
|
-
for (const
|
|
1090
|
-
s[
|
|
1099
|
+
for (const n in e)
|
|
1100
|
+
s[n] = new a(e[n]).value;
|
|
1091
1101
|
return this.#s(s);
|
|
1092
1102
|
}
|
|
1093
1103
|
}
|
|
@@ -1096,14 +1106,14 @@ class p {
|
|
|
1096
1106
|
const s = {};
|
|
1097
1107
|
return s[this.variables[0]] = new a(e), this.evaluate(s);
|
|
1098
1108
|
}
|
|
1099
|
-
if (e instanceof
|
|
1109
|
+
if (e instanceof j)
|
|
1100
1110
|
return new a().invalid();
|
|
1101
1111
|
if (typeof e == "object") {
|
|
1102
1112
|
if (this.variables.length === 0)
|
|
1103
1113
|
return this.coefficient;
|
|
1104
1114
|
for (const s in this.#e) {
|
|
1105
|
-
const
|
|
1106
|
-
i.multiply(
|
|
1115
|
+
const n = new a(e[s]);
|
|
1116
|
+
i.multiply(n.pow(this.#e[s]));
|
|
1107
1117
|
}
|
|
1108
1118
|
}
|
|
1109
1119
|
return i;
|
|
@@ -1119,7 +1129,7 @@ class p {
|
|
|
1119
1129
|
return s.evaluate(t).subtract(s.evaluate(e));
|
|
1120
1130
|
}
|
|
1121
1131
|
inverse = () => {
|
|
1122
|
-
this.#
|
|
1132
|
+
this.#i.opposite();
|
|
1123
1133
|
for (const e in this.#e)
|
|
1124
1134
|
this.#e[e].opposite();
|
|
1125
1135
|
return this;
|
|
@@ -1136,7 +1146,7 @@ class p {
|
|
|
1136
1146
|
* Determine if two monoms are equals
|
|
1137
1147
|
* @param M
|
|
1138
1148
|
*/
|
|
1139
|
-
isEqual = (e) => this.isSameAs(e) && this.#
|
|
1149
|
+
isEqual = (e) => this.isSameAs(e) && this.#i.isEqual(e.coefficient);
|
|
1140
1150
|
isLiteralSquare = () => {
|
|
1141
1151
|
for (const e in this.literal)
|
|
1142
1152
|
if (this.literal[e].isRational() || this.literal[e].isEven())
|
|
@@ -1146,20 +1156,20 @@ class p {
|
|
|
1146
1156
|
/**
|
|
1147
1157
|
* Determine if the monom is one
|
|
1148
1158
|
*/
|
|
1149
|
-
isOne = () => this.#
|
|
1159
|
+
isOne = () => this.#i.value === 1 && this.variables.length === 0;
|
|
1150
1160
|
/**
|
|
1151
1161
|
* Determine if two monoms are similar
|
|
1152
1162
|
* @param M
|
|
1153
1163
|
*/
|
|
1154
1164
|
isSameAs = (e) => {
|
|
1155
|
-
const t = this.variables, i = e.variables, s = t.concat(i.filter((
|
|
1165
|
+
const t = this.variables, i = e.variables, s = t.concat(i.filter((n) => !t.includes(n)));
|
|
1156
1166
|
if (this.isZero() || e.isZero() || t.length === 0 && i.length === 0)
|
|
1157
1167
|
return !0;
|
|
1158
1168
|
if (t.length !== i.length)
|
|
1159
1169
|
return !1;
|
|
1160
1170
|
if (!this.isZero() && !e.isZero()) {
|
|
1161
|
-
for (const
|
|
1162
|
-
if (!this.hasVariable(
|
|
1171
|
+
for (const n of s)
|
|
1172
|
+
if (!this.hasVariable(n) || !e.hasVariable(n) || !this.#e[n].isEqual(e.literal[n]))
|
|
1163
1173
|
return !1;
|
|
1164
1174
|
}
|
|
1165
1175
|
return !0;
|
|
@@ -1168,7 +1178,7 @@ class p {
|
|
|
1168
1178
|
/**
|
|
1169
1179
|
* Determine if the monom is null
|
|
1170
1180
|
*/
|
|
1171
|
-
isZero = () => this.#
|
|
1181
|
+
isZero = () => this.#i.value === 0;
|
|
1172
1182
|
/**
|
|
1173
1183
|
* Get the literal part of \\(x^{n_1}y^{n_2}\\) as dictionary \\[\\begin{array}{ll}x&=n_1\\\\y&=n_2\\end{array}\\]
|
|
1174
1184
|
* @returns {literalType}
|
|
@@ -1213,7 +1223,7 @@ class p {
|
|
|
1213
1223
|
multiply = (...e) => {
|
|
1214
1224
|
for (const t of e) {
|
|
1215
1225
|
const i = t instanceof p ? t : new p(t);
|
|
1216
|
-
this.#
|
|
1226
|
+
this.#i.multiply(i.coefficient);
|
|
1217
1227
|
for (const s in i.literal)
|
|
1218
1228
|
this.hasVariable(s) ? this.#e[s].add(i.literal[s]) : this.#e[s] = i.literal[s].clone();
|
|
1219
1229
|
}
|
|
@@ -1222,25 +1232,25 @@ class p {
|
|
|
1222
1232
|
/**
|
|
1223
1233
|
* Create a one value monom
|
|
1224
1234
|
*/
|
|
1225
|
-
one = () => (this.#
|
|
1235
|
+
one = () => (this.#i = new a().one(), this.#e = {}, this);
|
|
1226
1236
|
/**
|
|
1227
1237
|
* Get the opposite
|
|
1228
1238
|
* Returns a monom.
|
|
1229
1239
|
*/
|
|
1230
|
-
opposite = () => (this.#
|
|
1240
|
+
opposite = () => (this.#i.opposite(), this);
|
|
1231
1241
|
get plotFunction() {
|
|
1232
1242
|
let e = "";
|
|
1233
1243
|
const t = Object.keys(this.#e).sort();
|
|
1234
1244
|
for (const i of t)
|
|
1235
1245
|
this.#e[i].isNotZero() && (e += (e === "" ? "" : "*") + i, this.#e[i].isNotEqual(1) && (e += `^(${this.#e[i].display})`));
|
|
1236
|
-
return e === "" ? this.#
|
|
1246
|
+
return e === "" ? this.#i.value != 0 ? this.#i.display : "" : this.#i.value === 1 ? e : this.#i.value === -1 ? `-${e}` : this.#i.value === 0 ? "0" : `${this.#i.display}*${e}`;
|
|
1237
1247
|
}
|
|
1238
1248
|
/**
|
|
1239
1249
|
* Get the pow of a monom.
|
|
1240
1250
|
* @param nb (number) : Mathematical pow
|
|
1241
1251
|
*/
|
|
1242
1252
|
pow = (e) => {
|
|
1243
|
-
this.#
|
|
1253
|
+
this.#i.pow(e);
|
|
1244
1254
|
for (const t in this.#e)
|
|
1245
1255
|
this.#e[t].multiply(e);
|
|
1246
1256
|
return this;
|
|
@@ -1277,7 +1287,7 @@ class p {
|
|
|
1277
1287
|
*/
|
|
1278
1288
|
sqrt = () => {
|
|
1279
1289
|
if (this.isSquare()) {
|
|
1280
|
-
this.#
|
|
1290
|
+
this.#i.sqrt();
|
|
1281
1291
|
for (const e in this.#e)
|
|
1282
1292
|
this.#e[e].clone().divide(2);
|
|
1283
1293
|
}
|
|
@@ -1290,7 +1300,7 @@ class p {
|
|
|
1290
1300
|
subtract = (...e) => {
|
|
1291
1301
|
for (const t of e) {
|
|
1292
1302
|
const i = t instanceof p ? t : new p(t);
|
|
1293
|
-
this.isSameAs(i) ? (this.isZero() && this.#
|
|
1303
|
+
this.isSameAs(i) ? (this.isZero() && this.#t(i), this.#i.add(i.clone().coefficient.opposite())) : console.log("Subtract: Is not similar: ", i.display);
|
|
1294
1304
|
}
|
|
1295
1305
|
return this;
|
|
1296
1306
|
};
|
|
@@ -1309,8 +1319,8 @@ class p {
|
|
|
1309
1319
|
/**
|
|
1310
1320
|
* Create a zero value monom
|
|
1311
1321
|
*/
|
|
1312
|
-
zero = () => (this.#
|
|
1313
|
-
#
|
|
1322
|
+
zero = () => (this.#i = new a().zero(), this.#e = {}, this);
|
|
1323
|
+
#t(e) {
|
|
1314
1324
|
for (const t in e.literal)
|
|
1315
1325
|
this.#e[t] = e.literal[t].clone();
|
|
1316
1326
|
}
|
|
@@ -1324,7 +1334,7 @@ class p {
|
|
|
1324
1334
|
const i = {};
|
|
1325
1335
|
return i[this.variables[0]] = new a(e).value, this.#s(i);
|
|
1326
1336
|
}
|
|
1327
|
-
if (e instanceof
|
|
1337
|
+
if (e instanceof j)
|
|
1328
1338
|
return NaN;
|
|
1329
1339
|
if (typeof e == "object") {
|
|
1330
1340
|
if (this.variables.length === 0)
|
|
@@ -1336,20 +1346,20 @@ class p {
|
|
|
1336
1346
|
}
|
|
1337
1347
|
return t;
|
|
1338
1348
|
};
|
|
1339
|
-
#
|
|
1340
|
-
const i = new
|
|
1349
|
+
#n = (e) => {
|
|
1350
|
+
const i = new X().parse(e).rpn, s = [];
|
|
1341
1351
|
if (i.length === 0)
|
|
1342
1352
|
return this.zero(), this;
|
|
1343
1353
|
if (i.length === 1) {
|
|
1344
|
-
const
|
|
1345
|
-
return this.one(),
|
|
1354
|
+
const n = i[0];
|
|
1355
|
+
return this.one(), n.tokenType === f.COEFFICIENT ? this.coefficient = new a(n.token) : n.tokenType === f.VARIABLE && this.setLetter(n.token, 1), this;
|
|
1346
1356
|
} else
|
|
1347
|
-
for (const
|
|
1348
|
-
this.#
|
|
1357
|
+
for (const n of i)
|
|
1358
|
+
this.#r(s, n);
|
|
1349
1359
|
return this.one(), this.multiply(s[0]), this;
|
|
1350
1360
|
};
|
|
1351
|
-
#
|
|
1352
|
-
let i, s,
|
|
1361
|
+
#r = (e, t) => {
|
|
1362
|
+
let i, s, n, o, h;
|
|
1353
1363
|
if (t.tokenType === f.COEFFICIENT)
|
|
1354
1364
|
e.push(new p(new a(t.token)));
|
|
1355
1365
|
else if (t.tokenType === f.VARIABLE) {
|
|
@@ -1367,7 +1377,7 @@ class p {
|
|
|
1367
1377
|
s = e.pop() ?? new p().one(), i = e.pop() ?? new p().one(), e.push(i.divide(s));
|
|
1368
1378
|
break;
|
|
1369
1379
|
case "^": {
|
|
1370
|
-
h = e.pop()?.coefficient ?? new a().one(),
|
|
1380
|
+
h = e.pop()?.coefficient ?? new a().one(), n = e.pop() ?? new p().one(), o = n.variables[0], o && n.setLetter(o, h), e.push(n);
|
|
1371
1381
|
break;
|
|
1372
1382
|
}
|
|
1373
1383
|
}
|
|
@@ -1376,44 +1386,44 @@ class p {
|
|
|
1376
1386
|
const i = [];
|
|
1377
1387
|
for (let s = 0; s <= this.literal[t].value; s++)
|
|
1378
1388
|
if (e.length === 0) {
|
|
1379
|
-
const
|
|
1380
|
-
|
|
1389
|
+
const n = {};
|
|
1390
|
+
n[t] = new a(s), i.push(n);
|
|
1381
1391
|
} else
|
|
1382
|
-
for (const
|
|
1392
|
+
for (const n of e) {
|
|
1383
1393
|
const o = {};
|
|
1384
|
-
for (const h in
|
|
1385
|
-
o[h] =
|
|
1394
|
+
for (const h in n)
|
|
1395
|
+
o[h] = n[h];
|
|
1386
1396
|
o[t] = new a(s), i.push(o);
|
|
1387
1397
|
}
|
|
1388
1398
|
return i;
|
|
1389
1399
|
}
|
|
1390
1400
|
}
|
|
1391
|
-
function
|
|
1392
|
-
return e ? `\\left( ${
|
|
1401
|
+
function te(r, e = !0) {
|
|
1402
|
+
return e ? `\\left( ${r} \\right)` : `(${r})`;
|
|
1393
1403
|
}
|
|
1394
|
-
function
|
|
1395
|
-
return
|
|
1404
|
+
function U(r, e, t, i, s) {
|
|
1405
|
+
return r.map((n, o) => n === e ? t : n);
|
|
1396
1406
|
}
|
|
1397
|
-
function
|
|
1407
|
+
function se(r, e) {
|
|
1398
1408
|
if (!Number.isSafeInteger(e))
|
|
1399
1409
|
throw new Error("Can only raise item by an integer");
|
|
1400
1410
|
if (e < 0)
|
|
1401
1411
|
throw new Error("Can only raise item by a positive integer");
|
|
1402
1412
|
if (e === 0)
|
|
1403
|
-
return
|
|
1404
|
-
const t =
|
|
1413
|
+
return r.one();
|
|
1414
|
+
const t = r.clone();
|
|
1405
1415
|
for (let i = 1; i < e; i++)
|
|
1406
|
-
|
|
1407
|
-
return
|
|
1416
|
+
r.multiply(t);
|
|
1417
|
+
return r;
|
|
1408
1418
|
}
|
|
1409
1419
|
class u {
|
|
1410
|
-
#
|
|
1420
|
+
#i = "x";
|
|
1411
1421
|
#e;
|
|
1412
|
-
#
|
|
1422
|
+
#t;
|
|
1413
1423
|
#s;
|
|
1414
|
-
#
|
|
1424
|
+
#n = !1;
|
|
1415
1425
|
constructor(e, ...t) {
|
|
1416
|
-
return this.#
|
|
1426
|
+
return this.#t = [], this.#e = [], this.#s = [], e !== void 0 && this.parse(e, ...t), this;
|
|
1417
1427
|
}
|
|
1418
1428
|
/**
|
|
1419
1429
|
* Parse a string to a polynom.
|
|
@@ -1421,17 +1431,17 @@ class u {
|
|
|
1421
1431
|
* @param values
|
|
1422
1432
|
*/
|
|
1423
1433
|
parse = (e, ...t) => {
|
|
1424
|
-
if (this.#
|
|
1434
|
+
if (this.#t = [], this.#e = [], typeof e == "string")
|
|
1425
1435
|
return this.#g(e, ...t);
|
|
1426
1436
|
if ((typeof e == "number" || e instanceof a || e instanceof p) && t.length === 0)
|
|
1427
|
-
this.#
|
|
1437
|
+
this.#t.push(new p(e));
|
|
1428
1438
|
else if (e instanceof p && t.length > 0)
|
|
1429
|
-
this.#
|
|
1430
|
-
this.#
|
|
1439
|
+
this.#t.push(new p(e)), t.forEach((i) => {
|
|
1440
|
+
this.#t.push(new p(i));
|
|
1431
1441
|
});
|
|
1432
1442
|
else if (e instanceof u)
|
|
1433
1443
|
for (const i of e.monoms)
|
|
1434
|
-
this.#
|
|
1444
|
+
this.#t.push(i.clone());
|
|
1435
1445
|
return this;
|
|
1436
1446
|
};
|
|
1437
1447
|
/**
|
|
@@ -1439,7 +1449,7 @@ class u {
|
|
|
1439
1449
|
*/
|
|
1440
1450
|
clone = () => {
|
|
1441
1451
|
const e = new u(), t = [];
|
|
1442
|
-
for (const i of this.#
|
|
1452
|
+
for (const i of this.#t)
|
|
1443
1453
|
t.push(i.clone());
|
|
1444
1454
|
return e.monoms = t, e;
|
|
1445
1455
|
};
|
|
@@ -1451,29 +1461,29 @@ class u {
|
|
|
1451
1461
|
}
|
|
1452
1462
|
add = (...e) => {
|
|
1453
1463
|
for (const t of e)
|
|
1454
|
-
t instanceof u ? this.#
|
|
1464
|
+
t instanceof u ? this.#t = this.#t.concat(t.monoms) : t instanceof p ? this.#t.push(t.clone()) : typeof t == "number" && Number.isSafeInteger(t) ? this.#t.push(new p(t.toString())) : this.#t.push(new p(t));
|
|
1455
1465
|
return this.reduce();
|
|
1456
1466
|
};
|
|
1457
1467
|
commonMonom = () => {
|
|
1458
1468
|
const e = new p().one(), t = this.gcdNumerator(), i = this.gcdDenominator(), s = this.degree();
|
|
1459
1469
|
e.coefficient = new a(t, i);
|
|
1460
|
-
for (const
|
|
1461
|
-
e.setLetter(
|
|
1462
|
-
for (const o of this.#
|
|
1463
|
-
if (e.setLetter(
|
|
1470
|
+
for (const n of this.variables) {
|
|
1471
|
+
e.setLetter(n, s);
|
|
1472
|
+
for (const o of this.#t)
|
|
1473
|
+
if (e.setLetter(n, a.min(o.degree(n), e.degree(n))), e.degree(n).isZero())
|
|
1464
1474
|
break;
|
|
1465
1475
|
}
|
|
1466
1476
|
return e;
|
|
1467
1477
|
};
|
|
1468
1478
|
degree = (e) => {
|
|
1469
1479
|
let t = new a().zero();
|
|
1470
|
-
for (const i of this.#
|
|
1480
|
+
for (const i of this.#t)
|
|
1471
1481
|
t = a.max(i.degree(e).value, t);
|
|
1472
1482
|
return t;
|
|
1473
1483
|
};
|
|
1474
1484
|
derivative = (e) => {
|
|
1475
1485
|
const t = new u();
|
|
1476
|
-
for (const i of this.#
|
|
1486
|
+
for (const i of this.#t)
|
|
1477
1487
|
t.add(i.derivative(e));
|
|
1478
1488
|
return t.reduce();
|
|
1479
1489
|
};
|
|
@@ -1490,13 +1500,13 @@ class u {
|
|
|
1490
1500
|
{
|
|
1491
1501
|
const { quotient: t, reminder: i } = this.euclidean(e);
|
|
1492
1502
|
if (i.isZero())
|
|
1493
|
-
return this.#
|
|
1503
|
+
return this.#t = t.monoms, this;
|
|
1494
1504
|
}
|
|
1495
1505
|
} else if (typeof e == "string")
|
|
1496
1506
|
return this.divide(new u(e));
|
|
1497
1507
|
throw new Error(`Cannot divide by ${e}`);
|
|
1498
1508
|
};
|
|
1499
|
-
empty = () => (this.#
|
|
1509
|
+
empty = () => (this.#t = [], this);
|
|
1500
1510
|
/**
|
|
1501
1511
|
* Divide the current polynom by another polynom.
|
|
1502
1512
|
* @param P
|
|
@@ -1509,9 +1519,9 @@ class u {
|
|
|
1509
1519
|
quotient: this.clone().divide(e).reduce(),
|
|
1510
1520
|
reminder: new u().zero()
|
|
1511
1521
|
};
|
|
1512
|
-
const
|
|
1522
|
+
const n = e.monomByDegree(void 0, t), o = e.degree(t);
|
|
1513
1523
|
let h, l = this.degree(t).value * 2;
|
|
1514
|
-
for (; s.degree(t).isGeq(o) && l > 0 && (l--, h = s.monomByDegree(void 0, t).clone().divide(
|
|
1524
|
+
for (; s.degree(t).isGeq(o) && l > 0 && (l--, h = s.monomByDegree(void 0, t).clone().divide(n), !(!h.isZero() && (i.add(h), s.subtract(e.clone().multiply(h)).reduce(), h.degree(t).isZero()))); )
|
|
1515
1525
|
;
|
|
1516
1526
|
return i.reduce(), s.reduce(), { quotient: i, reminder: s };
|
|
1517
1527
|
};
|
|
@@ -1519,7 +1529,7 @@ class u {
|
|
|
1519
1529
|
if (t)
|
|
1520
1530
|
return this.#a(e);
|
|
1521
1531
|
const i = new a().zero();
|
|
1522
|
-
return this.#
|
|
1532
|
+
return this.#t.forEach((s) => {
|
|
1523
1533
|
i.add(s.evaluate(e, t));
|
|
1524
1534
|
}), i;
|
|
1525
1535
|
};
|
|
@@ -1536,9 +1546,9 @@ class u {
|
|
|
1536
1546
|
const h = new u(s);
|
|
1537
1547
|
t = [h.clone()], i = i.euclidean(h).quotient;
|
|
1538
1548
|
}
|
|
1539
|
-
let
|
|
1540
|
-
for (;
|
|
1541
|
-
if (
|
|
1549
|
+
let n = i.degree().clone().multiply(2).value, o = 1;
|
|
1550
|
+
for (; n >= 0; )
|
|
1551
|
+
if (n--, i.monoms.length < 2) {
|
|
1542
1552
|
i.isOne() || (t.push(i.clone()), i.one());
|
|
1543
1553
|
break;
|
|
1544
1554
|
} else if (i.degree(e).isOne()) {
|
|
@@ -1562,11 +1572,11 @@ class u {
|
|
|
1562
1572
|
return i.isOne() || t.push(i.clone()), this.#e = t, this.#e;
|
|
1563
1573
|
};
|
|
1564
1574
|
fromCoefficients(...e) {
|
|
1565
|
-
this.#
|
|
1566
|
-
const t = this.#
|
|
1575
|
+
this.#t = [];
|
|
1576
|
+
const t = this.#i ?? "x";
|
|
1567
1577
|
return e.reverse().forEach((i, s) => {
|
|
1568
|
-
const
|
|
1569
|
-
|
|
1578
|
+
const n = new p();
|
|
1579
|
+
n.coefficient = new a(i), n.setLetter(t, s), this.#t.push(n);
|
|
1570
1580
|
}), this.reorder();
|
|
1571
1581
|
}
|
|
1572
1582
|
gcdDenominator = () => E.gcd(...this.getDenominators());
|
|
@@ -1574,30 +1584,30 @@ class u {
|
|
|
1574
1584
|
getCoefficients() {
|
|
1575
1585
|
const e = this.clone().reorder(), t = this.degree().value + 1, i = new Array(t).fill(new a(0));
|
|
1576
1586
|
return e.monoms.forEach((s) => {
|
|
1577
|
-
const
|
|
1578
|
-
i[
|
|
1587
|
+
const n = t - s.degree().value - 1;
|
|
1588
|
+
i[n] = s.coefficient.clone();
|
|
1579
1589
|
}), i;
|
|
1580
1590
|
}
|
|
1581
1591
|
// Next functions are used for for commonMonom, which is used in the factorize method.
|
|
1582
1592
|
getDenominators = () => {
|
|
1583
1593
|
const e = [];
|
|
1584
|
-
for (const t of this.#
|
|
1594
|
+
for (const t of this.#t)
|
|
1585
1595
|
e.push(t.coefficient.denominator);
|
|
1586
1596
|
return e;
|
|
1587
1597
|
};
|
|
1588
1598
|
getNumerators = () => {
|
|
1589
1599
|
const e = [];
|
|
1590
|
-
for (const t of this.#
|
|
1600
|
+
for (const t of this.#t)
|
|
1591
1601
|
e.push(t.coefficient.numerator);
|
|
1592
1602
|
return e;
|
|
1593
1603
|
};
|
|
1594
|
-
getZeroes = () => this.degree().isZero() ? [] : (this.roots = new
|
|
1604
|
+
getZeroes = () => this.degree().isZero() ? [] : (this.roots = new W(this.clone()).solve(), this.roots);
|
|
1595
1605
|
hasVariable(e) {
|
|
1596
1606
|
return this.variables.includes(e);
|
|
1597
1607
|
}
|
|
1598
1608
|
integrate = (e, t, i = "x") => {
|
|
1599
|
-
const s = this.primitive(i),
|
|
1600
|
-
return
|
|
1609
|
+
const s = this.primitive(i), n = {}, o = {};
|
|
1610
|
+
return n[i] = new a(e), o[i] = new a(t), s.evaluate(o).subtract(s.evaluate(n));
|
|
1601
1611
|
};
|
|
1602
1612
|
inverse() {
|
|
1603
1613
|
}
|
|
@@ -1622,14 +1632,14 @@ class u {
|
|
|
1622
1632
|
return t.isZero();
|
|
1623
1633
|
}
|
|
1624
1634
|
};
|
|
1625
|
-
isEqual = (e) => this.#
|
|
1635
|
+
isEqual = (e) => this.#r(e, "=");
|
|
1626
1636
|
get isMultiVariable() {
|
|
1627
|
-
return this.#
|
|
1637
|
+
return this.#t.some((e) => e.variables.length > 1);
|
|
1628
1638
|
}
|
|
1629
1639
|
isOne() {
|
|
1630
|
-
return this.#
|
|
1640
|
+
return this.#t.length === 1 && this.#t[0].coefficient.isOne() && this.degree().isZero();
|
|
1631
1641
|
}
|
|
1632
|
-
isOppositeAt = (e) => this.#
|
|
1642
|
+
isOppositeAt = (e) => this.#r(e.clone().opposite(), "=");
|
|
1633
1643
|
isReduced = (e) => {
|
|
1634
1644
|
if (!this.isDeveloped(e))
|
|
1635
1645
|
return !1;
|
|
@@ -1641,18 +1651,18 @@ class u {
|
|
|
1641
1651
|
return !1;
|
|
1642
1652
|
return !1;
|
|
1643
1653
|
};
|
|
1644
|
-
isSameAs = (e) => this.#
|
|
1654
|
+
isSameAs = (e) => this.#r(e, "same");
|
|
1645
1655
|
isZero() {
|
|
1646
|
-
return this.#
|
|
1656
|
+
return this.#t.length === 1 && this.#t[0].coefficient.isZero() || this.#t.length === 0;
|
|
1647
1657
|
}
|
|
1648
1658
|
lcmDenominator = () => E.lcm(...this.getDenominators());
|
|
1649
1659
|
lcmNumerator = () => E.lcm(...this.getNumerators());
|
|
1650
1660
|
get length() {
|
|
1651
|
-
return this.#
|
|
1661
|
+
return this.#t.length;
|
|
1652
1662
|
}
|
|
1653
1663
|
letters = () => {
|
|
1654
1664
|
let e = /* @__PURE__ */ new Set();
|
|
1655
|
-
for (const t of this.#
|
|
1665
|
+
for (const t of this.#t)
|
|
1656
1666
|
e = /* @__PURE__ */ new Set([...e, ...t.variables]);
|
|
1657
1667
|
return [...e];
|
|
1658
1668
|
};
|
|
@@ -1668,7 +1678,7 @@ class u {
|
|
|
1668
1678
|
if (e === void 0)
|
|
1669
1679
|
return this.monomByDegree(this.degree(t), t);
|
|
1670
1680
|
const i = this.clone().reduce();
|
|
1671
|
-
for (const s of i.#
|
|
1681
|
+
for (const s of i.#t)
|
|
1672
1682
|
if (s.degree(t).isEqual(e))
|
|
1673
1683
|
return s.clone();
|
|
1674
1684
|
return new p().zero();
|
|
@@ -1676,24 +1686,24 @@ class u {
|
|
|
1676
1686
|
// Used in LinearSystem.tex
|
|
1677
1687
|
monomByLetter = (e) => {
|
|
1678
1688
|
const t = this.clone().reduce();
|
|
1679
|
-
for (const i of t.#
|
|
1689
|
+
for (const i of t.#t)
|
|
1680
1690
|
if (i.hasVariable(e))
|
|
1681
1691
|
return i.clone();
|
|
1682
1692
|
return new p().zero();
|
|
1683
1693
|
};
|
|
1684
1694
|
// ------------------------------------------
|
|
1685
1695
|
get monoms() {
|
|
1686
|
-
return this.#
|
|
1696
|
+
return this.#t;
|
|
1687
1697
|
}
|
|
1688
1698
|
set monoms(e) {
|
|
1689
|
-
this.#
|
|
1699
|
+
this.#t = e;
|
|
1690
1700
|
}
|
|
1691
1701
|
monomsByDegree = (e, t) => {
|
|
1692
1702
|
if (e === void 0)
|
|
1693
1703
|
return this.monomsByDegree(this.degree(t));
|
|
1694
1704
|
const i = [], s = this.clone().reduce();
|
|
1695
|
-
for (const
|
|
1696
|
-
|
|
1705
|
+
for (const n of s.#t)
|
|
1706
|
+
n.degree(t).isEqual(e) && i.push(n.clone());
|
|
1697
1707
|
return i;
|
|
1698
1708
|
};
|
|
1699
1709
|
multiply = (e) => {
|
|
@@ -1717,40 +1727,40 @@ class u {
|
|
|
1717
1727
|
get numberOfVars() {
|
|
1718
1728
|
return this.variables.length;
|
|
1719
1729
|
}
|
|
1720
|
-
one = () => (this.#
|
|
1730
|
+
one = () => (this.#t = [], this.#t.push(new p().one()), this);
|
|
1721
1731
|
// ------------------------------------------
|
|
1722
|
-
opposite = () => (this.#
|
|
1732
|
+
opposite = () => (this.#t = this.#t.map((e) => e.opposite()), this);
|
|
1723
1733
|
get plotFunction() {
|
|
1724
1734
|
return this.#l("tex", !1, !1, !0);
|
|
1725
1735
|
}
|
|
1726
|
-
pow = (e) =>
|
|
1736
|
+
pow = (e) => se(this, e).reduce();
|
|
1727
1737
|
primitive = (e) => {
|
|
1728
1738
|
const t = new u();
|
|
1729
|
-
for (const i of this.#
|
|
1739
|
+
for (const i of this.#t)
|
|
1730
1740
|
t.add(i.primitive(e));
|
|
1731
1741
|
return t;
|
|
1732
1742
|
};
|
|
1733
1743
|
reduce = () => {
|
|
1734
1744
|
let e = 0;
|
|
1735
|
-
for (; e < this.#
|
|
1736
|
-
for (let t = e + 1; t < this.#
|
|
1737
|
-
this.#
|
|
1745
|
+
for (; e < this.#t.length; ) {
|
|
1746
|
+
for (let t = e + 1; t < this.#t.length; t++)
|
|
1747
|
+
this.#t[e].isSameAs(this.#t[t]) && (this.#t[e].add(this.#t[t]), this.#t.splice(t, 1), this.#t[e].isZero() && (this.#t[e] = new p().zero()), t--);
|
|
1738
1748
|
e++;
|
|
1739
1749
|
}
|
|
1740
|
-
this.#
|
|
1741
|
-
for (const t of this.#
|
|
1750
|
+
this.#t = this.#t.filter((t) => !t.coefficient.isZero());
|
|
1751
|
+
for (const t of this.#t)
|
|
1742
1752
|
t.coefficient.reduce();
|
|
1743
1753
|
return this.length === 0 ? new u().zero() : this.reorder();
|
|
1744
1754
|
};
|
|
1745
1755
|
reorder = (e = "x", t = !1) => {
|
|
1746
1756
|
const i = this.variables.filter((s) => s !== e);
|
|
1747
|
-
return this.#
|
|
1748
|
-
const o = s.degree(e).value, h =
|
|
1757
|
+
return this.#t.sort(function(s, n) {
|
|
1758
|
+
const o = s.degree(e).value, h = n.degree(e).value;
|
|
1749
1759
|
if (o !== h)
|
|
1750
1760
|
return t ? o - h : h - o;
|
|
1751
1761
|
if (i.length > 0)
|
|
1752
1762
|
for (const l of i) {
|
|
1753
|
-
const c = s.degree(l).value, d =
|
|
1763
|
+
const c = s.degree(l).value, d = n.degree(l).value;
|
|
1754
1764
|
if (c !== d)
|
|
1755
1765
|
return t ? c - d : d - c;
|
|
1756
1766
|
}
|
|
@@ -1765,29 +1775,29 @@ class u {
|
|
|
1765
1775
|
replaceBy = (e, t) => {
|
|
1766
1776
|
let i;
|
|
1767
1777
|
const s = new u().zero();
|
|
1768
|
-
for (const
|
|
1769
|
-
!
|
|
1770
|
-
return this.#
|
|
1778
|
+
for (const n of this.monoms)
|
|
1779
|
+
!n.hasVariable(e) || n.literal[e].isZero() ? s.add(n.clone()) : (i = n.literal[e].clone(), n.removeVariable(e), s.add(t.clone().pow(Math.abs(i.numerator)).multiply(n)));
|
|
1780
|
+
return this.#t = s.reduce().monoms, this;
|
|
1771
1781
|
};
|
|
1772
1782
|
// ------------------------------------------
|
|
1773
1783
|
root() {
|
|
1774
1784
|
throw new Error("Cannot take the root from a polynom");
|
|
1775
1785
|
}
|
|
1776
1786
|
get roots() {
|
|
1777
|
-
return this.#
|
|
1787
|
+
return this.#n ? this.#s : this.getZeroes();
|
|
1778
1788
|
}
|
|
1779
1789
|
set roots(e) {
|
|
1780
|
-
this.#
|
|
1790
|
+
this.#n = !0, this.#s = e;
|
|
1781
1791
|
}
|
|
1782
1792
|
setVariable(e) {
|
|
1783
|
-
return this.#
|
|
1793
|
+
return this.#i = e, this;
|
|
1784
1794
|
}
|
|
1785
1795
|
sqrt() {
|
|
1786
1796
|
throw new Error("Cannot take the square root from a polynom");
|
|
1787
1797
|
}
|
|
1788
1798
|
subtract = (...e) => {
|
|
1789
1799
|
for (const t of e)
|
|
1790
|
-
t instanceof u ? this.add(t.clone().opposite()) : t instanceof p ? this.#
|
|
1800
|
+
t instanceof u ? this.add(t.clone().opposite()) : t instanceof p ? this.#t.push(t.clone().opposite()) : this.#t.push(new p(t).opposite());
|
|
1791
1801
|
return this.reduce();
|
|
1792
1802
|
};
|
|
1793
1803
|
tableOfSigns() {
|
|
@@ -1795,17 +1805,17 @@ class u {
|
|
|
1795
1805
|
let t = new Array(2 * e.length + 1).fill("").map((i, s) => s % 2 === 0 ? "" : "z");
|
|
1796
1806
|
if (t.length === 1) {
|
|
1797
1807
|
const [i] = this.getCoefficients().map((s) => s.value);
|
|
1798
|
-
t =
|
|
1808
|
+
t = U(t, "", i > 0 ? "+" : "-");
|
|
1799
1809
|
} else if (this.degree().isOne()) {
|
|
1800
1810
|
const [i] = this.getCoefficients().map((s) => s.value);
|
|
1801
1811
|
t[0] = i > 0 ? "-" : "+", t[1] = "z", t[2] = i > 0 ? "+" : "-";
|
|
1802
1812
|
} else
|
|
1803
1813
|
[
|
|
1804
1814
|
e[0].value - 1,
|
|
1805
|
-
...e.map((s,
|
|
1806
|
-
].forEach((s,
|
|
1815
|
+
...e.map((s, n) => n === e.length - 1 ? e[n].value + 1 : (e[n].value + e[n + 1].value) / 2)
|
|
1816
|
+
].forEach((s, n) => {
|
|
1807
1817
|
const o = this.evaluate({ x: s }, !0);
|
|
1808
|
-
t[
|
|
1818
|
+
t[n * 2] = o > 0 ? "+" : "-";
|
|
1809
1819
|
});
|
|
1810
1820
|
return { roots: e, signs: t };
|
|
1811
1821
|
}
|
|
@@ -1815,7 +1825,7 @@ class u {
|
|
|
1815
1825
|
}
|
|
1816
1826
|
get variables() {
|
|
1817
1827
|
let e = [];
|
|
1818
|
-
for (const t of this.#
|
|
1828
|
+
for (const t of this.#t)
|
|
1819
1829
|
e = e.concat(t.variables);
|
|
1820
1830
|
return e = [...new Set(e)], e.sort(), e;
|
|
1821
1831
|
}
|
|
@@ -1823,43 +1833,43 @@ class u {
|
|
|
1823
1833
|
* Set the polynom to zero.
|
|
1824
1834
|
* @returns {this}
|
|
1825
1835
|
*/
|
|
1826
|
-
zero = () => (this.#
|
|
1836
|
+
zero = () => (this.#t = [], this.#t.push(new p().zero()), this);
|
|
1827
1837
|
get zeroes() {
|
|
1828
1838
|
return this.getZeroes();
|
|
1829
1839
|
}
|
|
1830
|
-
#
|
|
1840
|
+
#r = (e, t) => {
|
|
1831
1841
|
t ??= "=";
|
|
1832
1842
|
const i = this.clone().reduce().reorder(), s = e.clone().reduce().reorder();
|
|
1833
1843
|
switch (t) {
|
|
1834
1844
|
case "=":
|
|
1835
|
-
return i.length !== s.length || !i.degree().isEqual(s.degree()) ? !1 : i.monoms.every((
|
|
1845
|
+
return i.length !== s.length || !i.degree().isEqual(s.degree()) ? !1 : i.monoms.every((n, o) => n.isEqual(s.monoms[o]));
|
|
1836
1846
|
case "same":
|
|
1837
|
-
return i.length !== s.length || !i.degree().isEqual(s.degree()) ? !1 : i.monoms.every((
|
|
1847
|
+
return i.length !== s.length || !i.degree().isEqual(s.degree()) ? !1 : i.monoms.every((n, o) => n.isSameAs(s.monoms[o]));
|
|
1838
1848
|
default:
|
|
1839
1849
|
return !1;
|
|
1840
1850
|
}
|
|
1841
1851
|
};
|
|
1842
1852
|
#o = (e) => {
|
|
1843
|
-
for (const t of this.#
|
|
1853
|
+
for (const t of this.#t)
|
|
1844
1854
|
t.coefficient.divide(e);
|
|
1845
1855
|
return this;
|
|
1846
1856
|
};
|
|
1847
1857
|
#h = (e) => {
|
|
1848
1858
|
const t = new a(e);
|
|
1849
|
-
for (const i of this.#
|
|
1859
|
+
for (const i of this.#t)
|
|
1850
1860
|
i.coefficient.divide(t);
|
|
1851
1861
|
return this;
|
|
1852
1862
|
};
|
|
1853
1863
|
#a = (e) => {
|
|
1854
1864
|
let t = 0;
|
|
1855
|
-
return this.#
|
|
1865
|
+
return this.#t.forEach((i) => {
|
|
1856
1866
|
t += i.evaluate(e, !0);
|
|
1857
1867
|
}), t;
|
|
1858
1868
|
};
|
|
1859
1869
|
#c = (e) => {
|
|
1860
|
-
let t, i, s,
|
|
1870
|
+
let t, i, s, n, o, h, l, c, d;
|
|
1861
1871
|
if (this.numberOfVars === 1)
|
|
1862
|
-
return s = this.monomByDegree(2, e).coefficient,
|
|
1872
|
+
return s = this.monomByDegree(2, e).coefficient, n = this.monomByDegree(1, e).coefficient, o = this.monomByDegree(0, e).coefficient, h = n.clone().pow(2).subtract(s.clone().multiply(o).multiply(4)), h.isZero() ? (l = n.clone().opposite().divide(s.clone().multiply(2)), t = new u(e).subtract(l.display).multiply(l.denominator), i = new u(e).subtract(l.display).multiply(l.denominator), d = s.divide(l.denominator).divide(l.denominator), d.isOne() ? [t, i] : [new u(d.display), t, i]) : h.isPositive() && h.isSquare() ? (l = n.clone().opposite().add(h.clone().sqrt()).divide(s.clone().multiply(2)), c = n.clone().opposite().subtract(h.clone().sqrt()).divide(s.clone().multiply(2)), d = s.divide(l.denominator).divide(c.denominator), d.isOne() ? [
|
|
1863
1873
|
new u(e).subtract(l.display).multiply(l.denominator),
|
|
1864
1874
|
new u(e).subtract(c.display).multiply(c.denominator)
|
|
1865
1875
|
] : [
|
|
@@ -1867,56 +1877,56 @@ class u {
|
|
|
1867
1877
|
new u(e).subtract(l.display).multiply(l.denominator),
|
|
1868
1878
|
new u(e).subtract(c.display).multiply(c.denominator)
|
|
1869
1879
|
]) : [this.clone()];
|
|
1870
|
-
if (s = this.monomByDegree(2, e),
|
|
1871
|
-
const w = new u("x", s.coefficient,
|
|
1880
|
+
if (s = this.monomByDegree(2, e), n = this.monomByDegree(1, e), o = this.monomByDegree(0, e), s.isLiteralSquare() && o.isLiteralSquare() && n.clone().pow(2).isSameAs(s.clone().multiply(o))) {
|
|
1881
|
+
const w = new u("x", s.coefficient, n.coefficient, o.coefficient).#c("x"), N = [];
|
|
1872
1882
|
let A;
|
|
1873
1883
|
if (w.length >= 2) {
|
|
1874
|
-
for (const
|
|
1875
|
-
|
|
1884
|
+
for (const C of w)
|
|
1885
|
+
C.degree().isZero() ? N.push(C.clone()) : (A = C.clone(), A.monoms[0].literal = s.literalSqrt, A.monoms[1].literal = o.literalSqrt, N.push(A.clone()));
|
|
1876
1886
|
return N;
|
|
1877
1887
|
}
|
|
1878
1888
|
}
|
|
1879
1889
|
return [this.clone()];
|
|
1880
1890
|
};
|
|
1881
1891
|
#l = (e, t, i, s) => {
|
|
1882
|
-
let
|
|
1883
|
-
for (const o of this.#
|
|
1892
|
+
let n = "";
|
|
1893
|
+
for (const o of this.#t) {
|
|
1884
1894
|
if (o.coefficient.value === 0)
|
|
1885
1895
|
continue;
|
|
1886
1896
|
let h;
|
|
1887
|
-
s ? h = o.plotFunction : h = e === "tex" ? o.tex : o.display,
|
|
1897
|
+
s ? h = o.plotFunction : h = e === "tex" ? o.tex : o.display, n += `${o.coefficient.sign() === 1 && (n !== "" || t === !0) ? "+" : ""}${h}`;
|
|
1888
1898
|
}
|
|
1889
|
-
return i === !0 && this.length > 1 && (e === "tex" ?
|
|
1899
|
+
return i === !0 && this.length > 1 && (e === "tex" ? n = `\\left( ${n} \\right)` : n = `(${n})`), n === "" && (n = "0"), n;
|
|
1890
1900
|
};
|
|
1891
1901
|
#u = (e, t, i) => {
|
|
1892
|
-
const s = e.monoms[0].dividers,
|
|
1902
|
+
const s = e.monoms[0].dividers, n = e.monoms[e.monoms.length - 1].dividers, o = [];
|
|
1893
1903
|
return s.forEach((h) => {
|
|
1894
|
-
h.degree(i).isLeq(t) &&
|
|
1904
|
+
h.degree(i).isLeq(t) && n.forEach((l) => {
|
|
1895
1905
|
h.degree(i).isNotEqual(l.degree(i)) && (o.push(new u(h, l)), o.push(new u(h, l.clone().opposite())));
|
|
1896
1906
|
});
|
|
1897
1907
|
}), o;
|
|
1898
1908
|
};
|
|
1899
1909
|
#f = (e) => {
|
|
1900
|
-
for (const t of this.#
|
|
1910
|
+
for (const t of this.#t)
|
|
1901
1911
|
t.coefficient.multiply(e);
|
|
1902
1912
|
return this.reduce();
|
|
1903
1913
|
};
|
|
1904
1914
|
#d = (e) => this.#f(new a(e));
|
|
1905
1915
|
#p = (e) => {
|
|
1906
|
-
for (const t of this.#
|
|
1916
|
+
for (const t of this.#t)
|
|
1907
1917
|
t.multiply(e);
|
|
1908
1918
|
return this.reduce();
|
|
1909
1919
|
};
|
|
1910
1920
|
#m = (e) => {
|
|
1911
1921
|
const t = [];
|
|
1912
|
-
for (const i of this.#
|
|
1922
|
+
for (const i of this.#t)
|
|
1913
1923
|
for (const s of e.monoms)
|
|
1914
1924
|
t.push(p.xMultiply(i, s));
|
|
1915
|
-
return this.#
|
|
1925
|
+
return this.#t = t, this.reduce();
|
|
1916
1926
|
};
|
|
1917
1927
|
#g(e, ...t) {
|
|
1918
1928
|
if (t.length === 0) {
|
|
1919
|
-
if (
|
|
1929
|
+
if (e !== "" && !isNaN(Number(e))) {
|
|
1920
1930
|
this.empty();
|
|
1921
1931
|
const i = new p(Number(e));
|
|
1922
1932
|
return this.add(i), this;
|
|
@@ -1929,16 +1939,16 @@ class u {
|
|
|
1929
1939
|
const s = e.split("");
|
|
1930
1940
|
if (s.length < t.length - 2)
|
|
1931
1941
|
throw new Error("Too many factors for too few variables !");
|
|
1932
|
-
let
|
|
1942
|
+
let n = 0;
|
|
1933
1943
|
for (const o of i) {
|
|
1934
1944
|
const h = new p();
|
|
1935
|
-
h.coefficient = o.clone(), h.literalStr = s[
|
|
1945
|
+
h.coefficient = o.clone(), h.literalStr = s[n] || "", this.add(h), n++;
|
|
1936
1946
|
}
|
|
1937
1947
|
} else {
|
|
1938
1948
|
let s = i.length - 1;
|
|
1939
|
-
for (const
|
|
1949
|
+
for (const n of i) {
|
|
1940
1950
|
const o = new p();
|
|
1941
|
-
o.coefficient =
|
|
1951
|
+
o.coefficient = n.clone(), o.literalStr = `${e}^${s}`, this.add(o), s--;
|
|
1942
1952
|
}
|
|
1943
1953
|
}
|
|
1944
1954
|
return this;
|
|
@@ -1950,11 +1960,11 @@ class u {
|
|
|
1950
1960
|
* @param inputStr
|
|
1951
1961
|
*/
|
|
1952
1962
|
#w = (e) => {
|
|
1953
|
-
const i = new
|
|
1963
|
+
const i = new X().parse(e).rpn;
|
|
1954
1964
|
this.zero();
|
|
1955
1965
|
const s = [];
|
|
1956
|
-
for (const
|
|
1957
|
-
this.#y(s,
|
|
1966
|
+
for (const n of i)
|
|
1967
|
+
this.#y(s, n);
|
|
1958
1968
|
return s.length === 1 && this.add(s[0]), this.reorder();
|
|
1959
1969
|
};
|
|
1960
1970
|
#y = (e, t) => {
|
|
@@ -1987,8 +1997,8 @@ class u {
|
|
|
1987
1997
|
if (i.monoms[0].coefficient.isRelative())
|
|
1988
1998
|
e.push(s.pow(i.monoms[0].coefficient.value));
|
|
1989
1999
|
else if (s.monoms.length === 1 && s.monoms[0].coefficient.isOne()) {
|
|
1990
|
-
for (const
|
|
1991
|
-
s.monoms[0].literal[
|
|
2000
|
+
for (const n in s.monoms[0].literal)
|
|
2001
|
+
s.monoms[0].literal[n].multiply(i.monoms[0].coefficient);
|
|
1992
2002
|
e.push(s);
|
|
1993
2003
|
} else
|
|
1994
2004
|
console.error("Cannot have power with fraction");
|
|
@@ -2010,13 +2020,13 @@ class u {
|
|
|
2010
2020
|
}
|
|
2011
2021
|
class y {
|
|
2012
2022
|
// Left part of the equation
|
|
2013
|
-
#
|
|
2023
|
+
#i;
|
|
2014
2024
|
// Right part of the equation
|
|
2015
2025
|
#e;
|
|
2016
2026
|
// Signe of the equation
|
|
2017
|
-
#
|
|
2027
|
+
#t;
|
|
2018
2028
|
constructor(e, t, i) {
|
|
2019
|
-
if (this.#
|
|
2029
|
+
if (this.#i = new u().zero(), this.#e = new u().zero(), this.#t = "=", e !== void 0 && t === void 0) {
|
|
2020
2030
|
if (e instanceof y)
|
|
2021
2031
|
return e.clone();
|
|
2022
2032
|
typeof e == "string" && this.parse(e);
|
|
@@ -2029,10 +2039,10 @@ class y {
|
|
|
2029
2039
|
if (t === !1)
|
|
2030
2040
|
throw new Error("The equation is not valid (no sign found)");
|
|
2031
2041
|
const i = e.split(t);
|
|
2032
|
-
return this.create(new u(i[0]), new u(i[1]), this.#
|
|
2042
|
+
return this.create(new u(i[0]), new u(i[1]), this.#n(t));
|
|
2033
2043
|
};
|
|
2034
|
-
create = (e, t, i) => (this.#
|
|
2035
|
-
clone = () => new y(this.#
|
|
2044
|
+
create = (e, t, i) => (this.#i = e, this.#e = t, this.#t = this.#n(i ?? "="), this);
|
|
2045
|
+
clone = () => new y(this.#i.clone(), this.#e.clone(), this.#t);
|
|
2036
2046
|
/**
|
|
2037
2047
|
* Add a value to the equation
|
|
2038
2048
|
* if value is an equation, add the left part to the left part of the equation
|
|
@@ -2043,17 +2053,17 @@ class y {
|
|
|
2043
2053
|
*/
|
|
2044
2054
|
add(e) {
|
|
2045
2055
|
if (e instanceof y)
|
|
2046
|
-
return this.#
|
|
2056
|
+
return this.#i.add(e.left), this.#e.add(e.right), this;
|
|
2047
2057
|
if (typeof e == "string" && !y.isEquationString(e))
|
|
2048
2058
|
return this.add(new y(e));
|
|
2049
2059
|
const t = new u(e);
|
|
2050
|
-
return this.#
|
|
2060
|
+
return this.#i.add(t), this.#e.add(t), this;
|
|
2051
2061
|
}
|
|
2052
2062
|
/**
|
|
2053
2063
|
* Get the degree of the equation
|
|
2054
2064
|
* @param letter
|
|
2055
2065
|
*/
|
|
2056
|
-
degree = (e) => a.max(this.#
|
|
2066
|
+
degree = (e) => a.max(this.#i.degree(e), this.#e.degree(e));
|
|
2057
2067
|
/**
|
|
2058
2068
|
* divide an equation by a given value (transformed as a fraction)
|
|
2059
2069
|
*
|
|
@@ -2079,7 +2089,7 @@ class y {
|
|
|
2079
2089
|
* @param asNumeric
|
|
2080
2090
|
*/
|
|
2081
2091
|
evaluate(e, t) {
|
|
2082
|
-
const i = this.#
|
|
2092
|
+
const i = this.#i.evaluate(e, t), s = this.#e.evaluate(e, t);
|
|
2083
2093
|
return t ? i === s : i.isEqual(s);
|
|
2084
2094
|
}
|
|
2085
2095
|
/**
|
|
@@ -2089,7 +2099,7 @@ class y {
|
|
|
2089
2099
|
hasVariable = (e) => this.variables.includes(e);
|
|
2090
2100
|
isEqual(e) {
|
|
2091
2101
|
const t = new y(e);
|
|
2092
|
-
return t.left.isEqual(this.#
|
|
2102
|
+
return t.left.isEqual(this.#i) && t.right.isEqual(this.#e);
|
|
2093
2103
|
}
|
|
2094
2104
|
isLinearTo = (e) => {
|
|
2095
2105
|
const t = e.clone().moveLeft().simplify().left, i = this.clone().moveLeft().simplify().left;
|
|
@@ -2098,7 +2108,7 @@ class y {
|
|
|
2098
2108
|
/**
|
|
2099
2109
|
* Determine if the equation contains more than one letter/variable.
|
|
2100
2110
|
*/
|
|
2101
|
-
isMultiVariable = () => this.#
|
|
2111
|
+
isMultiVariable = () => this.#i.isMultiVariable || this.#e.isMultiVariable;
|
|
2102
2112
|
// -----------------------------------------------
|
|
2103
2113
|
// Equations helpers
|
|
2104
2114
|
isEqualTo = (e) => {
|
|
@@ -2113,79 +2123,79 @@ class y {
|
|
|
2113
2123
|
if (!this.degree(e).isOne() || this.isMultiVariable())
|
|
2114
2124
|
return !1;
|
|
2115
2125
|
let t;
|
|
2116
|
-
this.#
|
|
2117
|
-
const i = [...this.#
|
|
2118
|
-
for (const
|
|
2119
|
-
|
|
2120
|
-
if (this.#
|
|
2126
|
+
this.#i.subtract(this.#e), this.#e.zero();
|
|
2127
|
+
const i = [...this.#i.monoms];
|
|
2128
|
+
for (const n of i)
|
|
2129
|
+
n.hasVariable(e) || (t = n.clone(), this.#i.subtract(t), this.#e.subtract(t));
|
|
2130
|
+
if (this.#i.length !== 1)
|
|
2121
2131
|
return !1;
|
|
2122
|
-
const s = this.#
|
|
2123
|
-
return this.#
|
|
2132
|
+
const s = this.#i.monoms[0].coefficient.clone();
|
|
2133
|
+
return this.#i.divide(s), this.#e.divide(s), this;
|
|
2124
2134
|
};
|
|
2125
2135
|
// -----------------------------------------------
|
|
2126
2136
|
// Equations operations
|
|
2127
2137
|
// -----------------------------------------------
|
|
2128
|
-
letters = () => [.../* @__PURE__ */ new Set([...this.#
|
|
2138
|
+
letters = () => [.../* @__PURE__ */ new Set([...this.#i.letters(), ...this.#e.letters()])];
|
|
2129
2139
|
// -----------------------------------------------
|
|
2130
2140
|
/**
|
|
2131
2141
|
* Reorder will move all monoms containing a letter on the left, all the other on the right.
|
|
2132
2142
|
*/
|
|
2133
|
-
moveLeft = () => (this.#
|
|
2143
|
+
moveLeft = () => (this.#i.subtract(this.#e), this.#e.zero(), this);
|
|
2134
2144
|
/**
|
|
2135
2145
|
* Multiple an equation by a fraction value.
|
|
2136
2146
|
* @param value
|
|
2137
2147
|
*/
|
|
2138
2148
|
multiply = (e) => {
|
|
2139
2149
|
const t = new a(e);
|
|
2140
|
-
return this.#
|
|
2150
|
+
return this.#i.multiply(t), this.#e.multiply(t), this.#t !== "=" && t.sign() === -1 && this.#r(), this;
|
|
2141
2151
|
};
|
|
2142
2152
|
pow(e) {
|
|
2143
|
-
return this.#
|
|
2153
|
+
return this.#i.pow(e), this.#e.pow(e), this;
|
|
2144
2154
|
}
|
|
2145
|
-
opposite = () => (this.#
|
|
2155
|
+
opposite = () => (this.#i = this.#i.opposite(), this.#e = this.#e.opposite(), this);
|
|
2146
2156
|
reduce() {
|
|
2147
|
-
return this.moveLeft(), this.#
|
|
2157
|
+
return this.moveLeft(), this.#i.reduce(), this.simplify(), this.#i.monoms[0].coefficient.isNegative() && this.multiply(-1), this;
|
|
2148
2158
|
}
|
|
2149
|
-
reorder = (e) => (this.#
|
|
2159
|
+
reorder = (e) => (this.#i.subtract(this.#e), this.#e.zero(), this.#i.reorder(), e ? this : (this.#i.monoms.filter((t) => t.degree().isZero()).forEach((t) => {
|
|
2150
2160
|
const i = t.clone();
|
|
2151
|
-
this.#
|
|
2152
|
-
}), this.#
|
|
2161
|
+
this.#i.subtract(i), this.#e.subtract(i);
|
|
2162
|
+
}), this.#i.reorder(), this.#e.reorder(), this));
|
|
2153
2163
|
// ------------------------------------------
|
|
2154
|
-
replaceBy = (e, t) => (this.#
|
|
2164
|
+
replaceBy = (e, t) => (this.#i.replaceBy(e, t), this.#e.replaceBy(e, t), this);
|
|
2155
2165
|
/**
|
|
2156
2166
|
* Multiply by the lcm denominator and divide by the gcm numerators.
|
|
2157
2167
|
*/
|
|
2158
|
-
simplify = () => (this.multiply(E.lcm(...this.#
|
|
2168
|
+
simplify = () => (this.multiply(E.lcm(...this.#i.getDenominators(), ...this.#e.getDenominators())), this.divide(E.gcd(...this.#i.getNumerators(), ...this.#e.getNumerators())), this);
|
|
2159
2169
|
// -----------------------------------------------
|
|
2160
|
-
solve = () => new
|
|
2170
|
+
solve = () => new W(this.clone()).solve();
|
|
2161
2171
|
split() {
|
|
2162
|
-
return [this.#
|
|
2172
|
+
return [this.#i.clone(), this.#e.clone()];
|
|
2163
2173
|
}
|
|
2164
2174
|
subtract(e) {
|
|
2165
2175
|
if (e instanceof y)
|
|
2166
|
-
return this.#
|
|
2176
|
+
return this.#i.subtract(e.left), this.#e.subtract(e.right), this;
|
|
2167
2177
|
if (typeof e == "string" && !y.isEquationString(e))
|
|
2168
2178
|
return this.subtract(new y(e));
|
|
2169
2179
|
const t = new u(e);
|
|
2170
|
-
return this.#
|
|
2180
|
+
return this.#i.subtract(t), this.#e.subtract(t), this;
|
|
2171
2181
|
}
|
|
2172
2182
|
test = (e) => this.left.evaluate(e).isEqual(this.right.evaluate(e));
|
|
2173
2183
|
static isEquationString(e) {
|
|
2174
2184
|
return e.includes("=") || e.includes("<") || e.includes(">") || e.includes("<=") || e.includes(">=");
|
|
2175
2185
|
}
|
|
2176
2186
|
static makeSolutionsUnique(e, t) {
|
|
2177
|
-
const i = [], s = e.filter((
|
|
2178
|
-
return t === !0 && s.sort((
|
|
2187
|
+
const i = [], s = e.filter((n) => i.includes(n.tex) ? !1 : (i.push(n.tex), !0));
|
|
2188
|
+
return t === !0 && s.sort((n, o) => n.value - o.value), s;
|
|
2179
2189
|
}
|
|
2180
2190
|
get display() {
|
|
2181
|
-
return `${this.#
|
|
2191
|
+
return `${this.#i.display}${this.signAsTex}${this.#e.display}`;
|
|
2182
2192
|
}
|
|
2183
2193
|
// Getter and setter
|
|
2184
2194
|
get left() {
|
|
2185
|
-
return this.#
|
|
2195
|
+
return this.#i;
|
|
2186
2196
|
}
|
|
2187
2197
|
set left(e) {
|
|
2188
|
-
this.#
|
|
2198
|
+
this.#i = e;
|
|
2189
2199
|
}
|
|
2190
2200
|
get numberOfVars() {
|
|
2191
2201
|
return this.variables.length;
|
|
@@ -2198,19 +2208,19 @@ class y {
|
|
|
2198
2208
|
}
|
|
2199
2209
|
// ------------------------------------------
|
|
2200
2210
|
get sign() {
|
|
2201
|
-
return this.#
|
|
2211
|
+
return this.#t;
|
|
2202
2212
|
}
|
|
2203
2213
|
set sign(e) {
|
|
2204
|
-
this.#
|
|
2214
|
+
this.#t = this.#n(e);
|
|
2205
2215
|
}
|
|
2206
2216
|
get signAsTex() {
|
|
2207
|
-
return this.#
|
|
2217
|
+
return this.#t === ">=" ? "\\geq" : this.#t === "<=" ? "\\leq" : this.#t;
|
|
2208
2218
|
}
|
|
2209
2219
|
get tex() {
|
|
2210
|
-
return `${this.#
|
|
2220
|
+
return `${this.#i.tex}${this.signAsTex}${this.#e.tex}`;
|
|
2211
2221
|
}
|
|
2212
2222
|
get variables() {
|
|
2213
|
-
return [...new Set(this.#e.variables.concat(this.#
|
|
2223
|
+
return [...new Set(this.#e.variables.concat(this.#i.variables))];
|
|
2214
2224
|
}
|
|
2215
2225
|
#s = (e) => {
|
|
2216
2226
|
if (e.includes("geq"))
|
|
@@ -2235,16 +2245,16 @@ class y {
|
|
|
2235
2245
|
};
|
|
2236
2246
|
// -----------------------------------------------
|
|
2237
2247
|
// Equations solving algorithms
|
|
2238
|
-
#
|
|
2239
|
-
#
|
|
2248
|
+
#n = (e) => e === void 0 ? "=" : e.includes("geq") || e.includes(">=") || e.includes("=>") ? ">=" : e.includes(">") ? ">" : e.includes("leq") || e.includes("<=") || e.includes("=<") ? "<=" : e.includes("<") ? "<" : "=";
|
|
2249
|
+
#r = () => this.#t === "=" ? this : this.#t.includes("<") ? (this.#t.replace("<", ">"), this) : this.#t.includes(">") ? (this.#t.replace(">", "<"), this) : this;
|
|
2240
2250
|
}
|
|
2241
2251
|
class x {
|
|
2242
|
-
#t;
|
|
2243
|
-
#e;
|
|
2244
2252
|
#i;
|
|
2253
|
+
#e;
|
|
2254
|
+
#t;
|
|
2245
2255
|
#s = !1;
|
|
2246
2256
|
constructor(e, t) {
|
|
2247
|
-
return e instanceof x ? (this.#e = e.polynom.clone(), this.#
|
|
2257
|
+
return e instanceof x ? (this.#e = e.polynom.clone(), this.#t = e.power.clone(), t !== void 0 && this.#t.multiply(new a(t))) : e !== void 0 ? (this.#e = new u(e), this.#t = new a(t ?? 1)) : (this.#e = new u(), this.#t = new a(1)), this.#i = 1, this;
|
|
2248
2258
|
}
|
|
2249
2259
|
parse() {
|
|
2250
2260
|
throw new Error("Method not implemented.");
|
|
@@ -2253,17 +2263,17 @@ class x {
|
|
|
2253
2263
|
return new x(this);
|
|
2254
2264
|
}
|
|
2255
2265
|
fromPolynom(e) {
|
|
2256
|
-
return this.#e = new u(e), this.#
|
|
2266
|
+
return this.#e = new u(e), this.#t = new a(1), this;
|
|
2257
2267
|
}
|
|
2258
2268
|
get tex() {
|
|
2259
2269
|
const e = this.power.numerator, t = this.power.denominator;
|
|
2260
2270
|
let i, s;
|
|
2261
|
-
return this.#
|
|
2271
|
+
return this.#i === 0 && t > 1 ? (i = `\\sqrt${t === 2 ? "" : `[ ${t} ]`}{ ${this.polynom.tex} }`, s = e === 1 ? "" : `^{ ${e} }`) : (i = this.#s && this.power.isOne() ? this.polynom.tex : te(this.polynom.tex), s = t === 1 && e === 1 ? "" : `^{ ${this.power.tex} }`), i = `${i}${s}`, this.#i === 0 && e < 0 && (i = `\\frac{ 1 }{ ${i} }`), i;
|
|
2262
2272
|
}
|
|
2263
2273
|
get display() {
|
|
2264
2274
|
const e = this.power.numerator, t = this.power.denominator;
|
|
2265
2275
|
let i, s;
|
|
2266
|
-
return this.#
|
|
2276
|
+
return this.#i === 0 && t > 1 ? (i = `${t === 2 ? "sqrt" : `root(${t})`}(${this.polynom.display})`, s = e === 1 ? "" : `^(${e})`) : (i = this.#s && this.power.isOne() ? this.polynom.display : te(this.polynom.display, !1), s = t === 1 && e === 1 ? "" : `^(${this.power.display})`), i = `${i}${s}`, this.#i === 0 && e < 0 && (i = `1/(${i})`), i;
|
|
2267
2277
|
}
|
|
2268
2278
|
add() {
|
|
2269
2279
|
throw new Error("Adding two factors is not possible");
|
|
@@ -2325,7 +2335,7 @@ class x {
|
|
|
2325
2335
|
throw new Error("The two factors must be the same");
|
|
2326
2336
|
}
|
|
2327
2337
|
one() {
|
|
2328
|
-
return this.#e.one(), this.#
|
|
2338
|
+
return this.#e.one(), this.#t.one(), this;
|
|
2329
2339
|
}
|
|
2330
2340
|
opposite() {
|
|
2331
2341
|
throw new Error("Method not implemented.");
|
|
@@ -2340,10 +2350,10 @@ class x {
|
|
|
2340
2350
|
return this.power.multiply(e), this;
|
|
2341
2351
|
}
|
|
2342
2352
|
get power() {
|
|
2343
|
-
return this.#
|
|
2353
|
+
return this.#t;
|
|
2344
2354
|
}
|
|
2345
2355
|
set power(e) {
|
|
2346
|
-
this.#
|
|
2356
|
+
this.#t = new a(e);
|
|
2347
2357
|
}
|
|
2348
2358
|
primitive() {
|
|
2349
2359
|
throw new Error("Method not implemented.");
|
|
@@ -2362,68 +2372,68 @@ class x {
|
|
|
2362
2372
|
}
|
|
2363
2373
|
tableOfSigns() {
|
|
2364
2374
|
const e = this.power.clone().reduce(), t = this.polynom.tableOfSigns();
|
|
2365
|
-
return e.isStrictlyNegative() && (t.signs =
|
|
2375
|
+
return e.isStrictlyNegative() && (t.signs = U(t.signs, "z", "d")), e.denominator % 2 === 0 ? t.signs = U(t.signs, "-", "h") : e.numerator % 2 === 0 && (t.signs = U(t.signs, "-", "+")), { roots: t.roots, signs: t.signs };
|
|
2366
2376
|
}
|
|
2367
2377
|
get variables() {
|
|
2368
2378
|
return this.polynom.variables;
|
|
2369
2379
|
}
|
|
2370
2380
|
get withPower() {
|
|
2371
|
-
return this.#
|
|
2381
|
+
return this.#i = 1, this;
|
|
2372
2382
|
}
|
|
2373
2383
|
get withRoot() {
|
|
2374
|
-
return this.#
|
|
2384
|
+
return this.#i = 0, this;
|
|
2375
2385
|
}
|
|
2376
2386
|
zero() {
|
|
2377
|
-
return this.#e.zero(), this.#
|
|
2387
|
+
return this.#e.zero(), this.#t.one(), this;
|
|
2378
2388
|
}
|
|
2379
2389
|
}
|
|
2380
|
-
var
|
|
2381
|
-
class
|
|
2382
|
-
#
|
|
2390
|
+
var Z = /* @__PURE__ */ ((r) => (r[r.ROOT = 0] = "ROOT", r[r.POWER = 1] = "POWER", r))(Z || {});
|
|
2391
|
+
class D {
|
|
2392
|
+
#i;
|
|
2383
2393
|
// Determine the letters in the linear system, usually ['x', 'y']
|
|
2384
2394
|
#e;
|
|
2385
2395
|
constructor(...e) {
|
|
2386
|
-
return this.#
|
|
2396
|
+
return this.#i = [], this.#e = [], e.length > 0 && this.parse(...e), this;
|
|
2387
2397
|
}
|
|
2388
|
-
parse = (...e) => (this.#
|
|
2389
|
-
clone = () => new
|
|
2398
|
+
parse = (...e) => (this.#i = e.map((t) => new y(t)), this.#t(), this);
|
|
2399
|
+
clone = () => new D().parse(...this.#i.map((e) => e.clone()));
|
|
2390
2400
|
static fromMatrix(e, t = "xyz") {
|
|
2391
2401
|
const i = e[0].length;
|
|
2392
|
-
if (e.some((
|
|
2402
|
+
if (e.some((n) => n.length !== i))
|
|
2393
2403
|
throw new Error("All rows must have the same number of columns");
|
|
2394
2404
|
const s = t.split("").splice(0, i - 1);
|
|
2395
|
-
return new
|
|
2396
|
-
...e.map((
|
|
2397
|
-
const o = new u(s.join(""), ...
|
|
2405
|
+
return new D(
|
|
2406
|
+
...e.map((n) => {
|
|
2407
|
+
const o = new u(s.join(""), ...n);
|
|
2398
2408
|
return new y(o, 0);
|
|
2399
2409
|
})
|
|
2400
2410
|
);
|
|
2401
2411
|
}
|
|
2402
2412
|
add(e, t) {
|
|
2403
|
-
if (e instanceof
|
|
2413
|
+
if (e instanceof D) {
|
|
2404
2414
|
const i = e.equations.length;
|
|
2405
|
-
if (i !== this.#
|
|
2415
|
+
if (i !== this.#i.length)
|
|
2406
2416
|
throw new Error("The number of equations must be the same");
|
|
2407
2417
|
for (let s = 0; s < i; s++)
|
|
2408
|
-
this.#
|
|
2418
|
+
this.#i[s].add(e.equations[s]);
|
|
2409
2419
|
} else {
|
|
2410
|
-
if (t === void 0 || t < 0 || t >= this.#
|
|
2420
|
+
if (t === void 0 || t < 0 || t >= this.#i.length)
|
|
2411
2421
|
throw new Error("Index out of range");
|
|
2412
2422
|
const i = new y(e);
|
|
2413
|
-
this.#
|
|
2423
|
+
this.#i[t].add(i);
|
|
2414
2424
|
}
|
|
2415
2425
|
return this;
|
|
2416
2426
|
}
|
|
2417
2427
|
buildTex = (e, t) => {
|
|
2418
|
-
let i, s,
|
|
2428
|
+
let i, s, n = [];
|
|
2419
2429
|
const o = [];
|
|
2420
2430
|
for (const l of e)
|
|
2421
|
-
|
|
2422
|
-
|
|
2431
|
+
n = n.concat(l.letters());
|
|
2432
|
+
n = [...new Set(n)], n.sort();
|
|
2423
2433
|
for (let l = 0; l < e.length; l++) {
|
|
2424
2434
|
const c = e[l];
|
|
2425
2435
|
i = [];
|
|
2426
|
-
for (const d of
|
|
2436
|
+
for (const d of n)
|
|
2427
2437
|
s = c.left.monomByLetter(d), i.length === 0 ? i.push(s.isZero() ? "" : s.tex) : i.push(s.isZero() ? "" : (s.coefficient.sign() === 1 ? "+" : "") + s.tex);
|
|
2428
2438
|
if (i.push("="), i.push(c.right.tex), t?.[l] !== void 0) {
|
|
2429
2439
|
i[i.length - 1] = i[i.length - 1] + " \\phantom{\\quad}";
|
|
@@ -2433,20 +2443,20 @@ class Z {
|
|
|
2433
2443
|
o.push(i.join("&"));
|
|
2434
2444
|
}
|
|
2435
2445
|
let h = 0;
|
|
2436
|
-
return t !== void 0 && t.length > 0 && (h = t[0].length), `\\left\\{\\begin{array}{${"r".repeat(
|
|
2446
|
+
return t !== void 0 && t.length > 0 && (h = t[0].length), `\\left\\{\\begin{array}{${"r".repeat(n.length)}cl ${"|l".repeat(h)}}${o.join("\\\\ ")}\\end{array}\\right.`;
|
|
2437
2447
|
};
|
|
2438
2448
|
degree(e) {
|
|
2439
|
-
return a.max(...this.#
|
|
2449
|
+
return a.max(...this.#i.map((t) => t.degree(e)));
|
|
2440
2450
|
}
|
|
2441
2451
|
get display() {
|
|
2442
2452
|
return this.tex + "as display";
|
|
2443
2453
|
}
|
|
2444
2454
|
// ------------------------------------------
|
|
2445
2455
|
get equations() {
|
|
2446
|
-
return this.#
|
|
2456
|
+
return this.#i;
|
|
2447
2457
|
}
|
|
2448
2458
|
set equations(e) {
|
|
2449
|
-
this.#
|
|
2459
|
+
this.#i = e;
|
|
2450
2460
|
}
|
|
2451
2461
|
evaluate(e, t) {
|
|
2452
2462
|
throw new Error("Method not implemented.");
|
|
@@ -2458,33 +2468,33 @@ class Z {
|
|
|
2458
2468
|
return this.equations.every((t, i) => t.isEqual(e.equations[i]));
|
|
2459
2469
|
}
|
|
2460
2470
|
get isSolvable() {
|
|
2461
|
-
return this.variables.length === this.#
|
|
2471
|
+
return this.variables.length === this.#i.length;
|
|
2462
2472
|
}
|
|
2463
2473
|
get matrix() {
|
|
2464
2474
|
return this.#s();
|
|
2465
2475
|
}
|
|
2466
2476
|
mergeEquations = (e, t, i, s) => {
|
|
2467
|
-
const
|
|
2468
|
-
return
|
|
2477
|
+
const n = e.clone().multiply(new a(i)), o = t.clone().multiply(new a(s));
|
|
2478
|
+
return n.left.add(o.left), n.right.add(o.right), n;
|
|
2469
2479
|
};
|
|
2470
2480
|
multiply(e, t) {
|
|
2471
2481
|
if (Array.isArray(e)) {
|
|
2472
|
-
if (e.length !== this.#
|
|
2482
|
+
if (e.length !== this.#i.length)
|
|
2473
2483
|
throw new Error("The number of values must be the same as the number of equations");
|
|
2474
2484
|
for (let i = 0; i < e.length; i++)
|
|
2475
|
-
this.#
|
|
2485
|
+
this.#i[i].multiply(e[i]);
|
|
2476
2486
|
return this;
|
|
2477
2487
|
}
|
|
2478
|
-
if (t === void 0 || t < 0 || t >= this.#
|
|
2488
|
+
if (t === void 0 || t < 0 || t >= this.#i.length)
|
|
2479
2489
|
throw new Error("Index out of range");
|
|
2480
|
-
return this.#
|
|
2490
|
+
return this.#i[t].multiply(e), this;
|
|
2481
2491
|
}
|
|
2482
2492
|
reduce() {
|
|
2483
2493
|
throw new Error("Method not implemented.");
|
|
2484
2494
|
}
|
|
2485
2495
|
// ------------------------------------------
|
|
2486
2496
|
reorder = () => {
|
|
2487
|
-
for (const e of this.#
|
|
2497
|
+
for (const e of this.#i)
|
|
2488
2498
|
e.reorder();
|
|
2489
2499
|
return this;
|
|
2490
2500
|
};
|
|
@@ -2492,17 +2502,17 @@ class Z {
|
|
|
2492
2502
|
return [];
|
|
2493
2503
|
}
|
|
2494
2504
|
solveMatrix = () => {
|
|
2495
|
-
const [e, t] = this.matrix, i = e.map((s,
|
|
2505
|
+
const [e, t] = this.matrix, i = e.map((s, n) => [...s, t[n]]);
|
|
2496
2506
|
for (let s = 0; s < e.length; s++) {
|
|
2497
|
-
let
|
|
2498
|
-
if (
|
|
2507
|
+
let n = i[s][s].clone();
|
|
2508
|
+
if (n.isZero()) {
|
|
2499
2509
|
const o = i.find((h, l) => l > s && !h[s].isZero());
|
|
2500
2510
|
if (o)
|
|
2501
|
-
i[s].forEach((h, l) => h.add(o[l])),
|
|
2511
|
+
i[s].forEach((h, l) => h.add(o[l])), n = i[s][s].clone();
|
|
2502
2512
|
else
|
|
2503
2513
|
throw new Error("Unsolvable...");
|
|
2504
2514
|
}
|
|
2505
|
-
i[s] = i[s].map((o) => o.divide(
|
|
2515
|
+
i[s] = i[s].map((o) => o.divide(n));
|
|
2506
2516
|
for (let o = 0; o < e.length; o++) {
|
|
2507
2517
|
if (o === s)
|
|
2508
2518
|
continue;
|
|
@@ -2516,17 +2526,17 @@ class Z {
|
|
|
2516
2526
|
return i.map((s) => s[s.length - 1]);
|
|
2517
2527
|
};
|
|
2518
2528
|
subtract(e, t) {
|
|
2519
|
-
if (e instanceof
|
|
2529
|
+
if (e instanceof D) {
|
|
2520
2530
|
const i = e.equations.length;
|
|
2521
|
-
if (i !== this.#
|
|
2531
|
+
if (i !== this.#i.length)
|
|
2522
2532
|
throw new Error("The number of equations must be the same");
|
|
2523
2533
|
for (let s = 0; s < i; s++)
|
|
2524
|
-
this.#
|
|
2534
|
+
this.#i[s].subtract(e.equations[s]);
|
|
2525
2535
|
} else {
|
|
2526
|
-
if (t === void 0 || t < 0 || t >= this.#
|
|
2536
|
+
if (t === void 0 || t < 0 || t >= this.#i.length)
|
|
2527
2537
|
throw new Error("Index out of range");
|
|
2528
2538
|
const i = new y(e);
|
|
2529
|
-
this.#
|
|
2539
|
+
this.#i[t].subtract(i);
|
|
2530
2540
|
}
|
|
2531
2541
|
return this;
|
|
2532
2542
|
}
|
|
@@ -2541,36 +2551,36 @@ class Z {
|
|
|
2541
2551
|
const t = typeof e == "string" ? e.split("") : [...e];
|
|
2542
2552
|
t.sort(), this.#e = t;
|
|
2543
2553
|
}
|
|
2544
|
-
#
|
|
2554
|
+
#t = () => (this.#e = this.#i.reduce((e, t) => [.../* @__PURE__ */ new Set([...e, ...t.variables])], []), this.#e.sort(), this);
|
|
2545
2555
|
#s = () => {
|
|
2546
2556
|
const e = [], t = [];
|
|
2547
|
-
for (const i of this.#
|
|
2548
|
-
const s = [],
|
|
2557
|
+
for (const i of this.#i) {
|
|
2558
|
+
const s = [], n = i.clone().reorder();
|
|
2549
2559
|
for (const o of this.variables) {
|
|
2550
|
-
const h =
|
|
2560
|
+
const h = n.left.monomByLetter(o);
|
|
2551
2561
|
s.push(h.coefficient);
|
|
2552
2562
|
}
|
|
2553
|
-
t.push(
|
|
2563
|
+
t.push(n.right.monoms[0].coefficient), e.push(s);
|
|
2554
2564
|
}
|
|
2555
2565
|
return [e, t];
|
|
2556
2566
|
};
|
|
2557
2567
|
}
|
|
2558
|
-
class
|
|
2559
|
-
#
|
|
2568
|
+
class qe {
|
|
2569
|
+
#i;
|
|
2560
2570
|
/**
|
|
2561
2571
|
*
|
|
2562
2572
|
* @param {string} value (optional) Default polynom to parse on class creation
|
|
2563
2573
|
*/
|
|
2564
2574
|
constructor(e) {
|
|
2565
|
-
return this.#
|
|
2575
|
+
return this.#i = [], e !== void 0 && this.parse(e), this;
|
|
2566
2576
|
}
|
|
2567
|
-
parse = (e) => (this.#
|
|
2577
|
+
parse = (e) => (this.#i = new X(z.SET).parse(e).rpn, this);
|
|
2568
2578
|
evaluate(e) {
|
|
2569
2579
|
this.variables.forEach((i) => {
|
|
2570
2580
|
Object.hasOwn(e, i) || (e[i] = !1);
|
|
2571
2581
|
});
|
|
2572
2582
|
const t = [];
|
|
2573
|
-
for (const i of this.#
|
|
2583
|
+
for (const i of this.#i)
|
|
2574
2584
|
if (console.log(i), i.tokenType === "variable")
|
|
2575
2585
|
t.push(e[i.token]);
|
|
2576
2586
|
else if (i.tokenType === "operation")
|
|
@@ -2581,14 +2591,14 @@ class Pe {
|
|
|
2581
2591
|
} else
|
|
2582
2592
|
return !1;
|
|
2583
2593
|
else {
|
|
2584
|
-
const s = t.pop(),
|
|
2585
|
-
if (s !== void 0 &&
|
|
2594
|
+
const s = t.pop(), n = t.pop();
|
|
2595
|
+
if (s !== void 0 && n !== void 0)
|
|
2586
2596
|
switch (i.token) {
|
|
2587
2597
|
case "&":
|
|
2588
|
-
t.push(s &&
|
|
2598
|
+
t.push(s && n);
|
|
2589
2599
|
break;
|
|
2590
2600
|
case "|":
|
|
2591
|
-
t.push(s ||
|
|
2601
|
+
t.push(s || n);
|
|
2592
2602
|
break;
|
|
2593
2603
|
case "-":
|
|
2594
2604
|
return !1;
|
|
@@ -2599,11 +2609,11 @@ class Pe {
|
|
|
2599
2609
|
return t.length === 1 && t[0];
|
|
2600
2610
|
}
|
|
2601
2611
|
get rpn() {
|
|
2602
|
-
return this.#
|
|
2612
|
+
return this.#i;
|
|
2603
2613
|
}
|
|
2604
2614
|
get tex() {
|
|
2605
2615
|
const e = [];
|
|
2606
|
-
for (const t of this.#
|
|
2616
|
+
for (const t of this.#i)
|
|
2607
2617
|
if (t.tokenType === "variable")
|
|
2608
2618
|
e.push(t);
|
|
2609
2619
|
else
|
|
@@ -2636,7 +2646,7 @@ class Pe {
|
|
|
2636
2646
|
return e[0].token;
|
|
2637
2647
|
}
|
|
2638
2648
|
get variables() {
|
|
2639
|
-
return this.#
|
|
2649
|
+
return this.#i.filter((e) => e.tokenType === "variable").map((e) => e.token);
|
|
2640
2650
|
}
|
|
2641
2651
|
vennAB() {
|
|
2642
2652
|
return this.#e(
|
|
@@ -2662,18 +2672,18 @@ class Pe {
|
|
|
2662
2672
|
let s;
|
|
2663
2673
|
if (t === void 0) {
|
|
2664
2674
|
s = /* @__PURE__ */ new Set();
|
|
2665
|
-
for (const
|
|
2675
|
+
for (const n in e)
|
|
2666
2676
|
s = /* @__PURE__ */ new Set([
|
|
2667
2677
|
...s,
|
|
2668
|
-
...e[
|
|
2678
|
+
...e[n] ?? []
|
|
2669
2679
|
]);
|
|
2670
2680
|
} else
|
|
2671
2681
|
s = new Set(t);
|
|
2672
|
-
for (const
|
|
2673
|
-
if (
|
|
2674
|
-
e[
|
|
2682
|
+
for (const n of this.#i)
|
|
2683
|
+
if (n.tokenType === "variable")
|
|
2684
|
+
e[n.token] === void 0 ? i.push(/* @__PURE__ */ new Set()) : i.push(new Set(e[n.token]));
|
|
2675
2685
|
else
|
|
2676
|
-
switch (
|
|
2686
|
+
switch (n.token) {
|
|
2677
2687
|
case "&":
|
|
2678
2688
|
if (i.length >= 2) {
|
|
2679
2689
|
const o = i.pop(), h = i.pop();
|
|
@@ -2703,7 +2713,7 @@ class Pe {
|
|
|
2703
2713
|
}
|
|
2704
2714
|
}
|
|
2705
2715
|
class T {
|
|
2706
|
-
#
|
|
2716
|
+
#i = Z.POWER;
|
|
2707
2717
|
#e = [];
|
|
2708
2718
|
constructor(...e) {
|
|
2709
2719
|
return this.parse(...e), this;
|
|
@@ -2717,30 +2727,30 @@ class T {
|
|
|
2717
2727
|
return new T(...this.#e.map((e) => e.clone()));
|
|
2718
2728
|
}
|
|
2719
2729
|
get tex() {
|
|
2720
|
-
const { num: e, den: t } = this.#
|
|
2730
|
+
const { num: e, den: t } = this.#n();
|
|
2721
2731
|
if (t.length === 0)
|
|
2722
|
-
return e.length === 1 ? e[0].asSingle.tex : e.map((
|
|
2723
|
-
const i = e.length === 1 ? e[0].asSingle.tex : e.map((
|
|
2732
|
+
return e.length === 1 ? e[0].asSingle.tex : e.map((n) => n.tex).join("");
|
|
2733
|
+
const i = e.length === 1 ? e[0].asSingle.tex : e.map((n) => n.tex).join(""), s = t.length === 1 ? t[0].asSingle.tex : t.map((n) => n.tex).join("");
|
|
2724
2734
|
return `\\frac{ ${i} }{ ${s} }`;
|
|
2725
2735
|
}
|
|
2726
2736
|
get display() {
|
|
2727
|
-
const { num: e, den: t } = this.#
|
|
2737
|
+
const { num: e, den: t } = this.#n();
|
|
2728
2738
|
if (t.length === 0)
|
|
2729
2739
|
return e.length === 1 ? e[0].asSingle.display : e.map(
|
|
2730
|
-
(
|
|
2740
|
+
(n, o) => o === 0 && n.polynom.monoms.length === 1 ? n.asSingle.display : n.display
|
|
2731
2741
|
).join("");
|
|
2732
|
-
const i = e.length === 1 ? e[0].asSingle.display : e.map((
|
|
2742
|
+
const i = e.length === 1 ? e[0].asSingle.display : e.map((n) => n.display).join(""), s = t.length === 1 ? t[0].asSingle.display : t.map((n) => n.display).join("");
|
|
2733
2743
|
return `(${i})/(${s})`;
|
|
2734
2744
|
}
|
|
2735
|
-
static #
|
|
2736
|
-
const i =
|
|
2745
|
+
static #t(e, t) {
|
|
2746
|
+
const i = L(e), s = L(t), o = Object.keys(i).filter((h) => Object.hasOwn(s, h)).map((h) => {
|
|
2737
2747
|
const l = i[h].reduce((d, m) => d.add(m.power), new a("0")), c = s[h].reduce((d, m) => d.add(m.power), new a("0"));
|
|
2738
2748
|
return new x(h, a.min(l, c));
|
|
2739
2749
|
});
|
|
2740
2750
|
return new T(...o);
|
|
2741
2751
|
}
|
|
2742
2752
|
static #s(e, t) {
|
|
2743
|
-
const i =
|
|
2753
|
+
const i = L(e), s = L(t), o = [.../* @__PURE__ */ new Set([...Object.keys(i), ...Object.keys(s)])].map((h) => {
|
|
2744
2754
|
const l = Object.hasOwn(i, h) ? i[h].reduce((d, m) => d.add(m.power), new a("0")) : new a(0), c = Object.hasOwn(s, h) ? s[h].reduce((d, m) => d.add(m.power), new a("0")) : new a(0);
|
|
2745
2755
|
return new x(h, a.max(l, c));
|
|
2746
2756
|
});
|
|
@@ -2752,9 +2762,9 @@ class T {
|
|
|
2752
2762
|
if (e.length === 1)
|
|
2753
2763
|
return e[0];
|
|
2754
2764
|
if (e.length === 2)
|
|
2755
|
-
return T.#
|
|
2765
|
+
return T.#t(e[0], e[1]);
|
|
2756
2766
|
let t = e[0];
|
|
2757
|
-
return e.shift(), e.forEach((i) => t = T.#
|
|
2767
|
+
return e.shift(), e.forEach((i) => t = T.#t(t, i)), t;
|
|
2758
2768
|
}
|
|
2759
2769
|
static lcm(...e) {
|
|
2760
2770
|
if (e.length === 0)
|
|
@@ -2773,19 +2783,19 @@ class T {
|
|
|
2773
2783
|
l.multiply(h.clone().divide(i[c]));
|
|
2774
2784
|
}), s = h;
|
|
2775
2785
|
}
|
|
2776
|
-
const
|
|
2777
|
-
...t.map((h) => h.divide(
|
|
2786
|
+
const n = T.gcd(...t), o = new u(0).add(
|
|
2787
|
+
...t.map((h) => h.divide(n).reduce().develop().factors[0].polynom)
|
|
2778
2788
|
).reduce();
|
|
2779
2789
|
return this.#e = [
|
|
2780
|
-
...
|
|
2790
|
+
...n.factors,
|
|
2781
2791
|
new x(o)
|
|
2782
2792
|
], s && this.divide(s), this.#e = this.#e.filter((h) => !h.power.isZero()), this;
|
|
2783
2793
|
}
|
|
2784
2794
|
get asPower() {
|
|
2785
|
-
return this.#
|
|
2795
|
+
return this.#i = Z.POWER, this;
|
|
2786
2796
|
}
|
|
2787
2797
|
get asRoot() {
|
|
2788
|
-
return this.#
|
|
2798
|
+
return this.#i = Z.ROOT, this;
|
|
2789
2799
|
}
|
|
2790
2800
|
degree(e) {
|
|
2791
2801
|
return this.#e.reduce((t, i) => t.add(i.degree(e)), new a("0"));
|
|
@@ -2798,9 +2808,9 @@ class T {
|
|
|
2798
2808
|
derivative() {
|
|
2799
2809
|
const e = [], t = this.#e.length;
|
|
2800
2810
|
for (let s = 0; s < t; s++) {
|
|
2801
|
-
const
|
|
2811
|
+
const n = this.#e.slice(), o = n.splice(s, 1)[0].derivative();
|
|
2802
2812
|
e.push(
|
|
2803
|
-
new T(...
|
|
2813
|
+
new T(...n, ...o)
|
|
2804
2814
|
);
|
|
2805
2815
|
}
|
|
2806
2816
|
e.forEach((s) => s.reduce());
|
|
@@ -2831,8 +2841,8 @@ class T {
|
|
|
2831
2841
|
} else
|
|
2832
2842
|
t.push(o.clone());
|
|
2833
2843
|
});
|
|
2834
|
-
const i = new T(...t), s = i.numerator.reduce(),
|
|
2835
|
-
return s.divide(
|
|
2844
|
+
const i = new T(...t), s = i.numerator.reduce(), n = i.denominator.reduce();
|
|
2845
|
+
return s.divide(n);
|
|
2836
2846
|
}
|
|
2837
2847
|
get factors() {
|
|
2838
2848
|
return this.#e;
|
|
@@ -2855,7 +2865,7 @@ class T {
|
|
|
2855
2865
|
const e = [].concat(...this.#e.map((t) => t.polynom.getZeroes()));
|
|
2856
2866
|
return e.sort((t, i) => t.value - i.value), e.filter(
|
|
2857
2867
|
(t, i, s) => i === s.findIndex(
|
|
2858
|
-
(
|
|
2868
|
+
(n) => n.value === t.value
|
|
2859
2869
|
)
|
|
2860
2870
|
);
|
|
2861
2871
|
}
|
|
@@ -2897,9 +2907,9 @@ class T {
|
|
|
2897
2907
|
throw new Error("Method not implemented.");
|
|
2898
2908
|
}
|
|
2899
2909
|
reduce() {
|
|
2900
|
-
const e =
|
|
2910
|
+
const e = L(this);
|
|
2901
2911
|
return this.#e = Object.values(e).map((t) => {
|
|
2902
|
-
const i = t[0].polynom, s = t.reduce((
|
|
2912
|
+
const i = t[0].polynom, s = t.reduce((n, o) => n.add(o.power), new a("0"));
|
|
2903
2913
|
return new x(i, s.reduce());
|
|
2904
2914
|
}).filter((t) => !t.power.isZero()), this;
|
|
2905
2915
|
}
|
|
@@ -2914,14 +2924,14 @@ class T {
|
|
|
2914
2924
|
*/
|
|
2915
2925
|
sort(e) {
|
|
2916
2926
|
return this.#e.sort((t, i) => {
|
|
2917
|
-
const s = t.power.value,
|
|
2918
|
-
if (s *
|
|
2927
|
+
const s = t.power.value, n = i.power.value;
|
|
2928
|
+
if (s * n < 0)
|
|
2919
2929
|
return -s;
|
|
2920
2930
|
const o = t.polynom.monoms.length, h = i.polynom.monoms.length;
|
|
2921
2931
|
if (o !== h)
|
|
2922
2932
|
return o - h;
|
|
2923
2933
|
const l = t.polynom.degree(e).value, c = i.polynom.degree(e).value;
|
|
2924
|
-
return l !== c ? l - c : s !==
|
|
2934
|
+
return l !== c ? l - c : s !== n ? s - n : t.degree().isLeq(i.degree()) ? -1 : 1;
|
|
2925
2935
|
}), this;
|
|
2926
2936
|
}
|
|
2927
2937
|
sqrt() {
|
|
@@ -2931,35 +2941,35 @@ class T {
|
|
|
2931
2941
|
return this.add(...e.map((t) => t.opposite()));
|
|
2932
2942
|
}
|
|
2933
2943
|
tableOfSigns() {
|
|
2934
|
-
const e = this.getZeroes(), t = e.map((
|
|
2935
|
-
return i.forEach((
|
|
2944
|
+
const e = this.getZeroes(), t = e.map((n) => n.value), i = this.factorize().factors.map((n) => ({ factor: new x(n), ...n.tableOfSigns() }));
|
|
2945
|
+
return i.forEach((n) => {
|
|
2936
2946
|
const o = new Array(2 * e.length + 1).fill("");
|
|
2937
|
-
let h =
|
|
2947
|
+
let h = n.signs.shift(), l = n.roots.shift();
|
|
2938
2948
|
const c = o.map((d, m) => {
|
|
2939
2949
|
if (m % 2 === 0)
|
|
2940
2950
|
return h;
|
|
2941
2951
|
if (l === void 0 || l.value !== t[(m - 1) / 2])
|
|
2942
2952
|
return "t";
|
|
2943
|
-
const w =
|
|
2944
|
-
return h =
|
|
2953
|
+
const w = n.signs.shift();
|
|
2954
|
+
return h = n.signs.shift(), l = n.roots.shift(), w;
|
|
2945
2955
|
});
|
|
2946
|
-
|
|
2947
|
-
}), { signs: i.map((
|
|
2956
|
+
n.roots = e, n.signs = c;
|
|
2957
|
+
}), { signs: i.map((n) => [...n.signs]).reduce((n, o) => n.length === 0 ? o : (o.forEach((h, l) => {
|
|
2948
2958
|
switch (h) {
|
|
2949
2959
|
case "d":
|
|
2950
|
-
|
|
2960
|
+
n[l] = "d";
|
|
2951
2961
|
break;
|
|
2952
2962
|
case "z":
|
|
2953
|
-
|
|
2963
|
+
n[l] = n[l] === "d" ? "d" : "z";
|
|
2954
2964
|
break;
|
|
2955
2965
|
case "h":
|
|
2956
|
-
|
|
2966
|
+
n[l] = "h";
|
|
2957
2967
|
break;
|
|
2958
2968
|
case "-":
|
|
2959
|
-
|
|
2969
|
+
n[l] = n[l] === "h" ? "h" : n[l] === "-" ? "+" : "-";
|
|
2960
2970
|
break;
|
|
2961
2971
|
}
|
|
2962
|
-
}),
|
|
2972
|
+
}), n), []), roots: e, factors: i };
|
|
2963
2973
|
}
|
|
2964
2974
|
get variables() {
|
|
2965
2975
|
return this.#e.reduce((e, t) => e.concat(t.variables), []);
|
|
@@ -2967,24 +2977,24 @@ class T {
|
|
|
2967
2977
|
zero() {
|
|
2968
2978
|
return this.#e = [new x("0", "1")], this;
|
|
2969
2979
|
}
|
|
2970
|
-
#
|
|
2980
|
+
#n() {
|
|
2971
2981
|
let e, t = [];
|
|
2972
|
-
return this.#
|
|
2982
|
+
return this.#i === Z.ROOT ? (e = this.numerator.factors, t = this.denominator.factors) : e = this.#e, e.length === 0 && (e = [new x("1")]), { num: e, den: t };
|
|
2973
2983
|
}
|
|
2974
2984
|
}
|
|
2975
|
-
function
|
|
2976
|
-
const e = new a().one(), t = new a().one(), i =
|
|
2985
|
+
function L(r) {
|
|
2986
|
+
const e = new a().one(), t = new a().one(), i = r.factors.reduce((o, h) => {
|
|
2977
2987
|
if (h.polynom.degree().isZero())
|
|
2978
2988
|
return h.power.isPositive() ? e.multiply(h.polynom.monoms[0].coefficient) : t.multiply(h.polynom.monoms[0].coefficient), o;
|
|
2979
2989
|
const l = h.polynom.display;
|
|
2980
2990
|
return Object.hasOwn(o, l) ? o[l].push(h) : o[l] = [h], o;
|
|
2981
|
-
}, {}), { numerator: s, denominator:
|
|
2982
|
-
return s !== 1 && (i[s.toString()] = [new x(s, 1)]),
|
|
2991
|
+
}, {}), { numerator: s, denominator: n } = e.divide(t).reduce();
|
|
2992
|
+
return s !== 1 && (i[s.toString()] = [new x(s, 1)]), n !== 1 && (i[n.toString()] = [new x(n, -1)]), i;
|
|
2983
2993
|
}
|
|
2984
|
-
class
|
|
2985
|
-
#
|
|
2994
|
+
class I {
|
|
2995
|
+
#i = null;
|
|
2986
2996
|
#e = !0;
|
|
2987
|
-
#
|
|
2997
|
+
#t = [];
|
|
2988
2998
|
constructor(e, t) {
|
|
2989
2999
|
return e && (t = t ?? e, this.fromDimensions(e, t)), this;
|
|
2990
3000
|
}
|
|
@@ -2993,31 +3003,31 @@ class P {
|
|
|
2993
3003
|
}
|
|
2994
3004
|
clone() {
|
|
2995
3005
|
const e = [];
|
|
2996
|
-
return this.#
|
|
3006
|
+
return this.#t.forEach((t) => {
|
|
2997
3007
|
const i = [];
|
|
2998
3008
|
t.forEach((s) => {
|
|
2999
3009
|
i.push(s.clone());
|
|
3000
3010
|
}), e.push(i);
|
|
3001
|
-
}), new
|
|
3011
|
+
}), new I().fromValues(e);
|
|
3002
3012
|
}
|
|
3003
3013
|
get tex() {
|
|
3004
|
-
if (this.#
|
|
3014
|
+
if (this.#t.length === 0)
|
|
3005
3015
|
return "";
|
|
3006
3016
|
const e = this.#e ? "pmatrix" : "bmatrix", t = [
|
|
3007
3017
|
`\\begin{${e}}`,
|
|
3008
3018
|
...this.rows.map(
|
|
3009
|
-
(i) => " " + i.map((s) => this.#
|
|
3019
|
+
(i) => " " + i.map((s) => this.#i !== null && s.value ? +s.value.toFixed(this.#i) : s.tex).join(" & ") + "\\\\"
|
|
3010
3020
|
),
|
|
3011
3021
|
`\\end{${e}}`
|
|
3012
3022
|
].join(`
|
|
3013
3023
|
`);
|
|
3014
|
-
return this.#
|
|
3024
|
+
return this.#i = null, t;
|
|
3015
3025
|
}
|
|
3016
3026
|
get display() {
|
|
3017
|
-
if (this.#
|
|
3027
|
+
if (this.#t.length === 0)
|
|
3018
3028
|
return "";
|
|
3019
|
-
const e = this.#e ? ["(", ")"] : ["[", "]"], t = e[0] + this.map((i) => this.#
|
|
3020
|
-
return this.#
|
|
3029
|
+
const e = this.#e ? ["(", ")"] : ["[", "]"], t = e[0] + this.map((i) => this.#i !== null && i.value ? +i.value.toFixed(this.#i) : i.display).map((i) => `(${i.join(",")})`).join(",") + e[1];
|
|
3030
|
+
return this.#i = null, t;
|
|
3021
3031
|
}
|
|
3022
3032
|
add(e) {
|
|
3023
3033
|
if (!this.canBeAdded(e))
|
|
@@ -3027,14 +3037,14 @@ class P {
|
|
|
3027
3037
|
}), this;
|
|
3028
3038
|
}
|
|
3029
3039
|
aij(e, t) {
|
|
3030
|
-
return e < 0 || e > this.dimension.rows || t < 0 || t > this.dimension.cols ? null : this.#
|
|
3040
|
+
return e < 0 || e > this.dimension.rows || t < 0 || t > this.dimension.cols ? null : this.#t[e][t];
|
|
3031
3041
|
}
|
|
3032
3042
|
get bmatrix() {
|
|
3033
3043
|
return this.#e = !1, this;
|
|
3034
3044
|
}
|
|
3035
3045
|
canBeAdded(e) {
|
|
3036
|
-
const { rows: t, cols: i } = this.dimension, { rows: s, cols:
|
|
3037
|
-
return t === s && i ===
|
|
3046
|
+
const { rows: t, cols: i } = this.dimension, { rows: s, cols: n } = e.dimension;
|
|
3047
|
+
return t === s && i === n;
|
|
3038
3048
|
}
|
|
3039
3049
|
canBeInverted() {
|
|
3040
3050
|
return !(!this.isSquare() || this.determinant().isZero());
|
|
@@ -3044,7 +3054,7 @@ class P {
|
|
|
3044
3054
|
}
|
|
3045
3055
|
characteristic_polynom(e) {
|
|
3046
3056
|
return e ??= "k", this.clone().subtract(
|
|
3047
|
-
new
|
|
3057
|
+
new I(this.dimension.rows).one().multiply(new u(e))
|
|
3048
3058
|
).determinant();
|
|
3049
3059
|
}
|
|
3050
3060
|
cofactor(e, t) {
|
|
@@ -3063,83 +3073,83 @@ class P {
|
|
|
3063
3073
|
if (!this.isSquare())
|
|
3064
3074
|
throw new Error("Matrix is not square");
|
|
3065
3075
|
const e = new u();
|
|
3066
|
-
return this.#
|
|
3076
|
+
return this.#t.length === 1 ? this.#t[0][0].clone() : (this.values[0].forEach((t, i) => {
|
|
3067
3077
|
const s = this.cofactor(0, i);
|
|
3068
3078
|
e.add(t.clone().multiply(s));
|
|
3069
3079
|
}), e);
|
|
3070
3080
|
}
|
|
3071
3081
|
get dimension() {
|
|
3072
3082
|
return {
|
|
3073
|
-
rows: this.#
|
|
3074
|
-
cols: this.#
|
|
3083
|
+
rows: this.#t.length,
|
|
3084
|
+
cols: this.#t[0].length
|
|
3075
3085
|
};
|
|
3076
3086
|
}
|
|
3077
3087
|
flat() {
|
|
3078
|
-
return this.#
|
|
3088
|
+
return this.#t.flat();
|
|
3079
3089
|
}
|
|
3080
3090
|
forEach(e) {
|
|
3081
|
-
this.#
|
|
3082
|
-
t.forEach((s,
|
|
3083
|
-
e(s, i,
|
|
3091
|
+
this.#t.forEach((t, i) => {
|
|
3092
|
+
t.forEach((s, n) => {
|
|
3093
|
+
e(s, i, n);
|
|
3084
3094
|
});
|
|
3085
3095
|
});
|
|
3086
3096
|
}
|
|
3087
3097
|
fromDimensions(e, t) {
|
|
3088
|
-
return this.#
|
|
3098
|
+
return this.#t = Array.from({ length: e }, () => Array.from({ length: t }, () => new u())), this;
|
|
3089
3099
|
}
|
|
3090
3100
|
fromString(e) {
|
|
3091
3101
|
if (e.startsWith("((") && e.endsWith("))"))
|
|
3092
3102
|
return this.fromString(e.substring(1, e.length - 1));
|
|
3093
3103
|
const t = e.split("),(");
|
|
3094
|
-
return this.#
|
|
3104
|
+
return this.#t = t.map((i, s) => s === 0 ? i.substring(1).split(",") : s === t.length - 1 ? i.substring(0, i.length - 1).split(",") : i.split(",")).map(
|
|
3095
3105
|
(i) => i.map((s) => new u(s))
|
|
3096
3106
|
), this;
|
|
3097
3107
|
}
|
|
3098
3108
|
fromValues(e) {
|
|
3099
|
-
this.#
|
|
3109
|
+
this.#t = [];
|
|
3100
3110
|
const t = e[0].length;
|
|
3101
3111
|
if (e.some((i) => i.length !== t))
|
|
3102
3112
|
throw new Error("Each line must be the same length");
|
|
3103
3113
|
return e.forEach((i) => {
|
|
3104
3114
|
const s = [];
|
|
3105
|
-
i.forEach((
|
|
3106
|
-
s.push(new u(
|
|
3107
|
-
}), this.#
|
|
3115
|
+
i.forEach((n) => {
|
|
3116
|
+
s.push(new u(n));
|
|
3117
|
+
}), this.#t.push(s);
|
|
3108
3118
|
}), this;
|
|
3109
3119
|
}
|
|
3110
3120
|
fromVectors(...e) {
|
|
3111
|
-
this.#
|
|
3121
|
+
this.#t = [];
|
|
3112
3122
|
const t = e[0].dimension;
|
|
3113
3123
|
if (e.some((i) => i.dimension !== t))
|
|
3114
3124
|
throw new Error("Each vectors must be the same dimension");
|
|
3115
3125
|
return this.fromDimensions(e[0].dimension, e.length), e.forEach((i, s) => {
|
|
3116
|
-
i.array.forEach((
|
|
3117
|
-
this.#
|
|
3126
|
+
i.array.forEach((n, o) => {
|
|
3127
|
+
this.#t[o][s] = new u(n);
|
|
3118
3128
|
});
|
|
3119
3129
|
}), this;
|
|
3120
3130
|
}
|
|
3121
3131
|
inverse() {
|
|
3122
3132
|
if (!this.canBeInverted())
|
|
3123
3133
|
throw new Error("The matrix cannot be inverted.");
|
|
3124
|
-
const e = new
|
|
3125
|
-
e.forEach((i, s,
|
|
3126
|
-
e.setValue(s,
|
|
3134
|
+
const e = new I().fromDimensions(this.dimension.rows, this.dimension.cols);
|
|
3135
|
+
e.forEach((i, s, n) => {
|
|
3136
|
+
e.setValue(s, n, this.cofactor(s, n));
|
|
3127
3137
|
}), e.transpose();
|
|
3128
3138
|
const t = this.determinant();
|
|
3129
|
-
return e.forEach((i, s,
|
|
3139
|
+
return e.forEach((i, s, n) => this.setValue(s, n, i.divide(t).reduce())), this;
|
|
3130
3140
|
}
|
|
3131
3141
|
isEqual(e) {
|
|
3132
3142
|
if (!this.canBeAdded(e))
|
|
3133
3143
|
return !1;
|
|
3134
3144
|
let t = !0;
|
|
3135
|
-
return this.forEach((i, s,
|
|
3136
|
-
t &&= i.isEqual(e.values[s][
|
|
3145
|
+
return this.forEach((i, s, n) => {
|
|
3146
|
+
t &&= i.isEqual(e.values[s][n]);
|
|
3137
3147
|
}), t;
|
|
3138
3148
|
}
|
|
3139
3149
|
isOne() {
|
|
3140
|
-
for (let e = 0; e < this.#
|
|
3141
|
-
for (let t = 0; t < this.#
|
|
3142
|
-
if (t === e && !this.#
|
|
3150
|
+
for (let e = 0; e < this.#t.length; e++)
|
|
3151
|
+
for (let t = 0; t < this.#t[e].length; t++)
|
|
3152
|
+
if (t === e && !this.#t[e][t].isOne() || t !== e && !this.#t[e][t].isZero())
|
|
3143
3153
|
return !1;
|
|
3144
3154
|
return !0;
|
|
3145
3155
|
}
|
|
@@ -3152,23 +3162,23 @@ class P {
|
|
|
3152
3162
|
map(e) {
|
|
3153
3163
|
const { rows: t, cols: i } = this.dimension, s = Array.from({ length: t }, () => Array.from({ length: i }, () => {
|
|
3154
3164
|
}));
|
|
3155
|
-
return this.#
|
|
3156
|
-
|
|
3165
|
+
return this.#t.forEach((n, o) => {
|
|
3166
|
+
n.forEach((h, l) => {
|
|
3157
3167
|
s[o][l] = e(h, o, l);
|
|
3158
3168
|
});
|
|
3159
3169
|
}), s;
|
|
3160
3170
|
}
|
|
3161
3171
|
multiply(e) {
|
|
3162
|
-
if (e instanceof
|
|
3172
|
+
if (e instanceof I) {
|
|
3163
3173
|
if (!this.canBeMultiplied(e))
|
|
3164
3174
|
throw new Error("Cannot multiply a matrix with incompatibles dimensions");
|
|
3165
|
-
const t = new
|
|
3166
|
-
return t.forEach((i, s,
|
|
3167
|
-
const o = this.rows[s], h = e.cols[
|
|
3175
|
+
const t = new I(this.dimension.rows, e.dimension.cols);
|
|
3176
|
+
return t.forEach((i, s, n) => {
|
|
3177
|
+
const o = this.rows[s], h = e.cols[n], l = new u();
|
|
3168
3178
|
o.forEach((c, d) => {
|
|
3169
3179
|
l.add(c.clone().multiply(h[d]));
|
|
3170
|
-
}), t.setValue(s,
|
|
3171
|
-
}), this.#
|
|
3180
|
+
}), t.setValue(s, n, l);
|
|
3181
|
+
}), this.#t = t.values, this;
|
|
3172
3182
|
}
|
|
3173
3183
|
return this.forEach((t, i, s) => {
|
|
3174
3184
|
this.setValue(i, s, t.multiply(e));
|
|
@@ -3188,19 +3198,19 @@ class P {
|
|
|
3188
3198
|
return this.#e = !0, this;
|
|
3189
3199
|
}
|
|
3190
3200
|
pow(e) {
|
|
3191
|
-
return
|
|
3201
|
+
return se(this, e);
|
|
3192
3202
|
}
|
|
3193
3203
|
reduce() {
|
|
3194
3204
|
throw new Error("Not yet implemented");
|
|
3195
3205
|
}
|
|
3196
3206
|
get rows() {
|
|
3197
|
-
return this.#
|
|
3207
|
+
return this.#t;
|
|
3198
3208
|
}
|
|
3199
3209
|
setValue(e, t, i) {
|
|
3200
|
-
const { rows: s, cols:
|
|
3201
|
-
if (e < 0 || e >= s || t < 0 || t >=
|
|
3202
|
-
throw new Error(`${e}x${t} is out of range (${s}x${
|
|
3203
|
-
return this.#
|
|
3210
|
+
const { rows: s, cols: n } = this.dimension;
|
|
3211
|
+
if (e < 0 || e >= s || t < 0 || t >= n)
|
|
3212
|
+
throw new Error(`${e}x${t} is out of range (${s}x${n})`);
|
|
3213
|
+
return this.#t[e][t] = new u(i), this;
|
|
3204
3214
|
}
|
|
3205
3215
|
subtract(e) {
|
|
3206
3216
|
if (!this.canBeAdded(e))
|
|
@@ -3210,7 +3220,7 @@ class P {
|
|
|
3210
3220
|
}), this;
|
|
3211
3221
|
}
|
|
3212
3222
|
toFixed(e) {
|
|
3213
|
-
return this.#
|
|
3223
|
+
return this.#i = e, this;
|
|
3214
3224
|
}
|
|
3215
3225
|
transpose() {
|
|
3216
3226
|
return this.clone().forEach((t, i, s) => {
|
|
@@ -3218,46 +3228,46 @@ class P {
|
|
|
3218
3228
|
}), this;
|
|
3219
3229
|
}
|
|
3220
3230
|
get values() {
|
|
3221
|
-
return this.#
|
|
3231
|
+
return this.#t;
|
|
3222
3232
|
}
|
|
3223
3233
|
zero() {
|
|
3224
3234
|
return this.forEach((e) => e.zero()), this;
|
|
3225
3235
|
}
|
|
3226
3236
|
}
|
|
3227
|
-
function
|
|
3228
|
-
return
|
|
3237
|
+
function Te(r, e) {
|
|
3238
|
+
return r.dimension === e.dimension && r.array.every(
|
|
3229
3239
|
(t, i) => e.array[i].isEqual(t)
|
|
3230
3240
|
);
|
|
3231
3241
|
}
|
|
3232
|
-
function
|
|
3233
|
-
if (
|
|
3242
|
+
function Oe(r, e) {
|
|
3243
|
+
if (r.dimension !== e.dimension)
|
|
3234
3244
|
return !1;
|
|
3235
|
-
const t = e.array[0].value /
|
|
3236
|
-
return
|
|
3245
|
+
const t = e.array[0].value / r.array[0].value;
|
|
3246
|
+
return r.array.every(
|
|
3237
3247
|
(i, s) => e.array[s].value === i.value * t
|
|
3238
3248
|
);
|
|
3239
3249
|
}
|
|
3240
|
-
function
|
|
3241
|
-
return
|
|
3250
|
+
function Ce(r, e) {
|
|
3251
|
+
return r.dimension !== e.dimension ? new a().invalid() : r.array.reduce(
|
|
3242
3252
|
(t, i, s) => t.add(i.clone().multiply(e.array[s])),
|
|
3243
3253
|
new a(0)
|
|
3244
3254
|
);
|
|
3245
3255
|
}
|
|
3246
|
-
function
|
|
3247
|
-
if (
|
|
3256
|
+
function De(...r) {
|
|
3257
|
+
if (r.some((e) => e.dimension !== r[0].dimension))
|
|
3248
3258
|
throw new Error("All vectors must have the same dimension");
|
|
3249
|
-
if (
|
|
3250
|
-
throw new Error(`The determinant of dimension ${
|
|
3251
|
-
return
|
|
3252
|
-
|
|
3259
|
+
if (r[0].dimension !== r.length)
|
|
3260
|
+
throw new Error(`The determinant of dimension ${r[0].dimension} must have the same number of vectors (${r.length} given)`);
|
|
3261
|
+
return r[0].dimension === 2 ? r[0].array[0].clone().multiply(r[1].array[1]).subtract(r[0].array[1].clone().multiply(r[1].array[0])) : r[0].array[0].clone().multiply(
|
|
3262
|
+
r[1].array[1].clone().multiply(r[2].array[2]).subtract(r[1].array[2].clone().multiply(r[2].array[1]))
|
|
3253
3263
|
).subtract(
|
|
3254
|
-
|
|
3255
|
-
|
|
3264
|
+
r[0].array[1].clone().multiply(
|
|
3265
|
+
r[1].array[0].clone().multiply(r[2].array[2]).subtract(r[1].array[2].clone().multiply(r[2].array[0]))
|
|
3256
3266
|
)
|
|
3257
|
-
).add(
|
|
3267
|
+
).add(r[0].array[2].clone().multiply(r[1].array[0].clone().multiply(r[2].array[1]).subtract(r[1].array[1].clone().multiply(r[2].array[0]))));
|
|
3258
3268
|
}
|
|
3259
3269
|
class g {
|
|
3260
|
-
#
|
|
3270
|
+
#i = [];
|
|
3261
3271
|
#e = !1;
|
|
3262
3272
|
constructor(...e) {
|
|
3263
3273
|
e.length > 0 && this.parse(...e);
|
|
@@ -3266,32 +3276,32 @@ class g {
|
|
|
3266
3276
|
// Getter and setter
|
|
3267
3277
|
// ------------------------------------------
|
|
3268
3278
|
get array() {
|
|
3269
|
-
return this.#
|
|
3279
|
+
return this.#i;
|
|
3270
3280
|
}
|
|
3271
3281
|
set array(e) {
|
|
3272
|
-
this.#
|
|
3282
|
+
this.#i = e;
|
|
3273
3283
|
}
|
|
3274
3284
|
get x() {
|
|
3275
|
-
return this.#
|
|
3285
|
+
return this.#i[0];
|
|
3276
3286
|
}
|
|
3277
3287
|
set x(e) {
|
|
3278
|
-
this.#
|
|
3288
|
+
this.#i[0] = new a(e);
|
|
3279
3289
|
}
|
|
3280
3290
|
get y() {
|
|
3281
|
-
return this.#
|
|
3291
|
+
return this.#i[1];
|
|
3282
3292
|
}
|
|
3283
3293
|
set y(e) {
|
|
3284
|
-
this.#
|
|
3294
|
+
this.#i[1] = new a(e);
|
|
3285
3295
|
}
|
|
3286
3296
|
get z() {
|
|
3287
3297
|
if (this.dimension < 3)
|
|
3288
3298
|
throw new Error("Vector is not 3D");
|
|
3289
|
-
return this.#
|
|
3299
|
+
return this.#i[2];
|
|
3290
3300
|
}
|
|
3291
3301
|
set z(e) {
|
|
3292
3302
|
if (this.dimension < 3)
|
|
3293
3303
|
throw new Error("Vector is not 3D");
|
|
3294
|
-
this.#
|
|
3304
|
+
this.#i[2] = new a(e);
|
|
3295
3305
|
}
|
|
3296
3306
|
get asPoint() {
|
|
3297
3307
|
return this.#e;
|
|
@@ -3315,10 +3325,10 @@ class g {
|
|
|
3315
3325
|
if (e < 2)
|
|
3316
3326
|
throw new Error("Dimension must be at least 2");
|
|
3317
3327
|
if (e < this.dimension)
|
|
3318
|
-
this.#
|
|
3328
|
+
this.#i = this.#i.slice(0, e);
|
|
3319
3329
|
else if (e > this.dimension)
|
|
3320
3330
|
for (let t = this.dimension; t < e; t++)
|
|
3321
|
-
this.#
|
|
3331
|
+
this.#i.push(new a(0));
|
|
3322
3332
|
return this;
|
|
3323
3333
|
}
|
|
3324
3334
|
get dimension() {
|
|
@@ -3354,22 +3364,22 @@ class g {
|
|
|
3354
3364
|
if (t instanceof g && i instanceof g) {
|
|
3355
3365
|
if (t.dimension !== i.dimension)
|
|
3356
3366
|
throw new Error("Vectors must have the same dimension");
|
|
3357
|
-
return this.#
|
|
3367
|
+
return this.#i = i.array.map((s, n) => s.clone().subtract(t.array[n])), this;
|
|
3358
3368
|
}
|
|
3359
3369
|
}
|
|
3360
|
-
return this.#
|
|
3370
|
+
return this.#i = e.map((t) => new a(t)), this;
|
|
3361
3371
|
}
|
|
3362
3372
|
clone() {
|
|
3363
3373
|
const e = new g();
|
|
3364
3374
|
return e.array = this.copy(), e.asPoint = this.asPoint, e;
|
|
3365
3375
|
}
|
|
3366
3376
|
copy() {
|
|
3367
|
-
return this.#
|
|
3377
|
+
return this.#i.map((e) => e.clone());
|
|
3368
3378
|
}
|
|
3369
|
-
zero = () => (this.#
|
|
3379
|
+
zero = () => (this.#i.forEach((e) => e.zero()), this);
|
|
3370
3380
|
one = () => (this.zero(), this.x.one(), this);
|
|
3371
|
-
opposite = () => (this.#
|
|
3372
|
-
add = (e) => (this.#
|
|
3381
|
+
opposite = () => (this.#i.forEach((e) => e.opposite()), this);
|
|
3382
|
+
add = (e) => (this.#i.forEach((t, i) => t.add(e.array[i])), this);
|
|
3373
3383
|
subtract = (e) => this.add(e.clone().opposite());
|
|
3374
3384
|
unit = () => {
|
|
3375
3385
|
const e = this.norm;
|
|
@@ -3385,7 +3395,7 @@ class g {
|
|
|
3385
3395
|
translate(...e) {
|
|
3386
3396
|
return this.array.forEach((t, i) => t.add(e[i])), this;
|
|
3387
3397
|
}
|
|
3388
|
-
dot = (e) =>
|
|
3398
|
+
dot = (e) => Ce(this, e);
|
|
3389
3399
|
cross(e) {
|
|
3390
3400
|
if (this.dimension !== 3 || e.dimension !== 3)
|
|
3391
3401
|
throw new Error("Cross product can only be determined in 3D");
|
|
@@ -3399,7 +3409,7 @@ class g {
|
|
|
3399
3409
|
if (this.dimension >= 3)
|
|
3400
3410
|
throw new Error("Normal vector can only be determined in 2D");
|
|
3401
3411
|
const e = this.x.clone().opposite(), t = this.y.clone();
|
|
3402
|
-
return this.#
|
|
3412
|
+
return this.#i[0] = t, this.#i[1] = e, this;
|
|
3403
3413
|
};
|
|
3404
3414
|
isZero() {
|
|
3405
3415
|
return this.array.every((e) => e.isZero());
|
|
@@ -3407,8 +3417,8 @@ class g {
|
|
|
3407
3417
|
isOne() {
|
|
3408
3418
|
return this.array.every((e, t) => t === 0 ? e.isOne() : e.isZero());
|
|
3409
3419
|
}
|
|
3410
|
-
isEqual = (e) =>
|
|
3411
|
-
isColinearTo = (e) =>
|
|
3420
|
+
isEqual = (e) => Te(this, e);
|
|
3421
|
+
isColinearTo = (e) => Oe(this, e);
|
|
3412
3422
|
isNormalTo = (e) => this.dot(e).isZero();
|
|
3413
3423
|
multiplyByScalar = (e) => {
|
|
3414
3424
|
const t = new a(e);
|
|
@@ -3429,7 +3439,7 @@ class g {
|
|
|
3429
3439
|
fromString = (e) => {
|
|
3430
3440
|
e.startsWith("(") && (e = e.substring(1)), e.endsWith(")") && (e = e.substring(0, e.length - 1));
|
|
3431
3441
|
const t = e.split(/[,;\s]/g).filter((i) => i.trim() !== "");
|
|
3432
|
-
return t.length < 2 ? this : (this.#
|
|
3442
|
+
return t.length < 2 ? this : (this.#i = t.map((i) => new a(i)), this);
|
|
3433
3443
|
};
|
|
3434
3444
|
distanceTo(e) {
|
|
3435
3445
|
const t = new g(this, e);
|
|
@@ -3440,39 +3450,39 @@ class g {
|
|
|
3440
3450
|
};
|
|
3441
3451
|
}
|
|
3442
3452
|
}
|
|
3443
|
-
var
|
|
3444
|
-
function
|
|
3445
|
-
return Math.random() <
|
|
3453
|
+
var B = /* @__PURE__ */ ((r) => (r.None = "none", r.Parallel = "parallel", r.Perpendicular = "perpendicular", r.Tangent = "tangent", r))(B || {}), Q = /* @__PURE__ */ ((r) => (r.None = "none", r.Parallel = "parallel", r.Perpendicular = "perpendicular", r.Tangent = "tangent", r))(Q || {});
|
|
3454
|
+
function ne(r = 0.5) {
|
|
3455
|
+
return Math.random() < r;
|
|
3446
3456
|
}
|
|
3447
|
-
function
|
|
3457
|
+
function k(r, e, t) {
|
|
3448
3458
|
if (e === void 0)
|
|
3449
|
-
return
|
|
3450
|
-
if (
|
|
3451
|
-
return
|
|
3459
|
+
return r >= 0 ? k(0, r) : k(r, 0);
|
|
3460
|
+
if (r === e)
|
|
3461
|
+
return r;
|
|
3452
3462
|
if (t === void 0)
|
|
3453
|
-
return Math.floor(Math.random() * (e -
|
|
3454
|
-
if (Math.abs(e -
|
|
3463
|
+
return Math.floor(Math.random() * (e - r + 1) + r);
|
|
3464
|
+
if (Math.abs(e - r) <= t.length)
|
|
3455
3465
|
throw new Error("The number of excluded values is too high.");
|
|
3456
|
-
let i =
|
|
3466
|
+
let i = k(r, e);
|
|
3457
3467
|
for (; t.includes(i); )
|
|
3458
|
-
i =
|
|
3468
|
+
i = k(r, e);
|
|
3459
3469
|
return i;
|
|
3460
3470
|
}
|
|
3461
|
-
function q(
|
|
3462
|
-
return e === !1 ?
|
|
3471
|
+
function q(r, e) {
|
|
3472
|
+
return e === !1 ? ne() ? k(1, r) : -k(1, r) : k(-r, r);
|
|
3463
3473
|
}
|
|
3464
|
-
function
|
|
3474
|
+
function $e(r) {
|
|
3465
3475
|
let e = E.primes();
|
|
3466
|
-
return
|
|
3476
|
+
return r !== void 0 && (e = e.filter((t) => t < r)), _(e);
|
|
3467
3477
|
}
|
|
3468
|
-
function
|
|
3469
|
-
return e === void 0 && (e = 1),
|
|
3478
|
+
function ke(r, e) {
|
|
3479
|
+
return e === void 0 && (e = 1), r.length <= 0 ? Object.values(r) : re(r).slice(0, e);
|
|
3470
3480
|
}
|
|
3471
|
-
function
|
|
3472
|
-
return
|
|
3481
|
+
function _(r) {
|
|
3482
|
+
return r.length === 0 ? null : r[k(0, r.length - 1)];
|
|
3473
3483
|
}
|
|
3474
|
-
function
|
|
3475
|
-
const e = Object.values(
|
|
3484
|
+
function re(r) {
|
|
3485
|
+
const e = Object.values(r);
|
|
3476
3486
|
for (let t = e.length - 1; t > 0; t--) {
|
|
3477
3487
|
const i = Math.floor(Math.random() * (t + 1)), s = e[t];
|
|
3478
3488
|
e[t] = e[i], e[i] = s;
|
|
@@ -3506,16 +3516,16 @@ class v extends g {
|
|
|
3506
3516
|
}
|
|
3507
3517
|
}
|
|
3508
3518
|
class b {
|
|
3509
|
-
static PARALLEL =
|
|
3519
|
+
static PARALLEL = B.Parallel;
|
|
3510
3520
|
// A line is defined as the canonical form
|
|
3511
|
-
static PERPENDICULAR =
|
|
3512
|
-
#
|
|
3521
|
+
static PERPENDICULAR = B.Perpendicular;
|
|
3522
|
+
#i;
|
|
3513
3523
|
// ax + by + c = 0
|
|
3514
3524
|
#e;
|
|
3515
|
-
#
|
|
3525
|
+
#t;
|
|
3516
3526
|
#s;
|
|
3517
|
-
#r;
|
|
3518
3527
|
#n;
|
|
3528
|
+
#r;
|
|
3519
3529
|
#o = "canonical";
|
|
3520
3530
|
#h;
|
|
3521
3531
|
/**
|
|
@@ -3524,7 +3534,7 @@ class b {
|
|
|
3524
3534
|
* @param values
|
|
3525
3535
|
*/
|
|
3526
3536
|
constructor(...e) {
|
|
3527
|
-
return this.#e = new a().zero(), this.#
|
|
3537
|
+
return this.#e = new a().zero(), this.#t = new a().zero(), this.#s = new a().zero(), this.#i = new g(), this.#n = new g(), this.#r = new g(), this.#h = !0, e.length > 0 && this.parse(...e), this;
|
|
3528
3538
|
}
|
|
3529
3539
|
// ------------------------------------------
|
|
3530
3540
|
/**
|
|
@@ -3557,12 +3567,12 @@ class b {
|
|
|
3557
3567
|
}
|
|
3558
3568
|
if (e.length === 3) {
|
|
3559
3569
|
if (e[0] instanceof g && e[1] instanceof g) {
|
|
3560
|
-
if (e[2] ===
|
|
3570
|
+
if (e[2] === B.Perpendicular)
|
|
3561
3571
|
return this.fromPointAndNormal(e[0], e[1]);
|
|
3562
|
-
if (e[2] ===
|
|
3572
|
+
if (e[2] === B.Parallel)
|
|
3563
3573
|
return this.fromPointAndDirection(e[0], e[1]);
|
|
3564
3574
|
}
|
|
3565
|
-
return e[0] instanceof g && e[1] instanceof b ? e[2] ===
|
|
3575
|
+
return e[0] instanceof g && e[1] instanceof b ? e[2] === B.Parallel || e[2] === null ? this.fromPointAndLine(e[0], e[1], B.Parallel) : this.fromPointAndLine(e[0], e[1], B.Perpendicular) : this.fromCoefficient(
|
|
3566
3576
|
e[0],
|
|
3567
3577
|
e[1],
|
|
3568
3578
|
e[2]
|
|
@@ -3572,7 +3582,7 @@ class b {
|
|
|
3572
3582
|
};
|
|
3573
3583
|
// ------------------------------------------
|
|
3574
3584
|
// Getter and setter
|
|
3575
|
-
clone = () => (this.#e = this.#e.clone(), this.#
|
|
3585
|
+
clone = () => (this.#e = this.#e.clone(), this.#t = this.#t.clone(), this.#s = this.#s.clone(), this.#n = this.#n.clone(), this.#i = this.#i.clone(), this.#r = this.#r.clone(), this);
|
|
3576
3586
|
get tex() {
|
|
3577
3587
|
const e = this.#o;
|
|
3578
3588
|
switch (this.#o = "canonical", e) {
|
|
@@ -3582,10 +3592,10 @@ class b {
|
|
|
3582
3592
|
return this.slope.isInfinity() ? "x=" + this.OA.x.tex : "y=" + new u().parse("x", this.slope, this.height).tex;
|
|
3583
3593
|
case "parametric":
|
|
3584
3594
|
case "system": {
|
|
3585
|
-
const t = this.#
|
|
3586
|
-
return this.#h && t.simplify(), e === "parametric" ? `${g.asTex("x", "y")} = ${g.asTex(this.#
|
|
3587
|
-
x &= ${new u(this.#
|
|
3588
|
-
y &= ${new u(this.#
|
|
3595
|
+
const t = this.#n.clone();
|
|
3596
|
+
return this.#h && t.simplify(), e === "parametric" ? `${g.asTex("x", "y")} = ${g.asTex(this.#i.x.tex, this.#i.y.tex)} + k\\cdot ${g.asTex(t.x.tex, t.y.tex)}` : `\\left\\{\\begin{aligned}
|
|
3597
|
+
x &= ${new u(this.#i.x).add(new p(this.#n.x).multiply(new p("k"))).reorder("k", !0).tex}\\\\
|
|
3598
|
+
y &= ${new u(this.#i.y).add(new p(this.#n.y).multiply(new p("k"))).reorder("k", !0).tex}
|
|
3589
3599
|
\\end{aligned}\\right.`;
|
|
3590
3600
|
}
|
|
3591
3601
|
default: {
|
|
@@ -3602,8 +3612,8 @@ class b {
|
|
|
3602
3612
|
case "mxh":
|
|
3603
3613
|
return this.slope.isInfinity() ? "x=" + this.OA.x.display : "y=" + new u().parse("x", this.slope, this.height).display;
|
|
3604
3614
|
case "parametric": {
|
|
3605
|
-
const t = this.#
|
|
3606
|
-
return this.#h && t.simplify(), `((x,y))=((${this.#
|
|
3615
|
+
const t = this.#n.clone();
|
|
3616
|
+
return this.#h && t.simplify(), `((x,y))=((${this.#i.x.display},${this.#i.y.display}))+k((${t.x.display},${t.y.display}))`;
|
|
3607
3617
|
}
|
|
3608
3618
|
default: {
|
|
3609
3619
|
const t = this.getEquation();
|
|
@@ -3612,10 +3622,10 @@ class b {
|
|
|
3612
3622
|
}
|
|
3613
3623
|
}
|
|
3614
3624
|
get OA() {
|
|
3615
|
-
return this.#
|
|
3625
|
+
return this.#i;
|
|
3616
3626
|
}
|
|
3617
3627
|
set OA(e) {
|
|
3618
|
-
this.#
|
|
3628
|
+
this.#i = e;
|
|
3619
3629
|
}
|
|
3620
3630
|
get a() {
|
|
3621
3631
|
return this.#e;
|
|
@@ -3624,10 +3634,10 @@ class b {
|
|
|
3624
3634
|
this.#e = e;
|
|
3625
3635
|
}
|
|
3626
3636
|
get b() {
|
|
3627
|
-
return this.#
|
|
3637
|
+
return this.#t;
|
|
3628
3638
|
}
|
|
3629
3639
|
set b(e) {
|
|
3630
|
-
this.#
|
|
3640
|
+
this.#t = e;
|
|
3631
3641
|
}
|
|
3632
3642
|
get c() {
|
|
3633
3643
|
return this.#s;
|
|
@@ -3655,40 +3665,40 @@ class b {
|
|
|
3655
3665
|
canonicalAsFloatCoefficient(e) {
|
|
3656
3666
|
e === void 0 && (e = 2);
|
|
3657
3667
|
let t = "";
|
|
3658
|
-
return this.#e.isZero() || (this.#e.isOne() ? t = "x" : this.#e.clone().opposite().isOne() ? t = "-x" : t = this.#e.value.toFixed(e) + "x"), this.#
|
|
3668
|
+
return this.#e.isZero() || (this.#e.isOne() ? t = "x" : this.#e.clone().opposite().isOne() ? t = "-x" : t = this.#e.value.toFixed(e) + "x"), this.#t.isZero() || (this.#t.isPositive() && (t += "+"), t += this.#t.value.toFixed(e) + "y"), this.#s.isZero() || (this.#s.isPositive() && (t += "+"), t += this.#s.value.toFixed(e)), t + "=0";
|
|
3659
3669
|
}
|
|
3660
3670
|
get d() {
|
|
3661
|
-
return this.#
|
|
3671
|
+
return this.#n;
|
|
3662
3672
|
}
|
|
3663
3673
|
set d(e) {
|
|
3664
|
-
this.#
|
|
3674
|
+
this.#n = e;
|
|
3665
3675
|
}
|
|
3666
3676
|
get director() {
|
|
3667
|
-
return this.#
|
|
3677
|
+
return this.#n.clone();
|
|
3668
3678
|
}
|
|
3669
3679
|
distanceTo(e) {
|
|
3670
|
-
const t = e.x.clone().multiply(this.#e).add(e.y.clone().multiply(this.#
|
|
3680
|
+
const t = e.x.clone().multiply(this.#e).add(e.y.clone().multiply(this.#t)).add(this.#s).abs(), i = this.normal.normSquare;
|
|
3671
3681
|
if (i.isZero())
|
|
3672
3682
|
return {
|
|
3673
3683
|
value: NaN,
|
|
3674
3684
|
tex: "Not a line",
|
|
3675
3685
|
fraction: new a().infinite()
|
|
3676
3686
|
};
|
|
3677
|
-
const s = t.value / Math.sqrt(i.value),
|
|
3687
|
+
const s = t.value / Math.sqrt(i.value), n = t.clone().divide(i.clone().sqrt());
|
|
3678
3688
|
return i.isSquare() ? {
|
|
3679
3689
|
value: s,
|
|
3680
|
-
tex:
|
|
3681
|
-
fraction:
|
|
3690
|
+
tex: n.tex,
|
|
3691
|
+
fraction: n
|
|
3682
3692
|
} : {
|
|
3683
3693
|
value: s,
|
|
3684
3694
|
tex: `\\frac{${t.tex}}{\\sqrt{${i.tex}}}`,
|
|
3685
|
-
fraction:
|
|
3695
|
+
fraction: n
|
|
3686
3696
|
};
|
|
3687
3697
|
}
|
|
3688
3698
|
get equation() {
|
|
3689
3699
|
return this.#o = "equation", this;
|
|
3690
3700
|
}
|
|
3691
|
-
fromCoefficient = (e, t, i) => (this.#e = new a(e), this.#
|
|
3701
|
+
fromCoefficient = (e, t, i) => (this.#e = new a(e), this.#t = new a(t), this.#s = new a(i), this.#n = new g(this.#t.clone(), this.#e.clone().opposite()), this.#i = new g(new a().zero(), this.#s.clone()), this.#r = this.#n.clone().normal(), this);
|
|
3692
3702
|
fromEquation = (e) => {
|
|
3693
3703
|
e.reorder(!0);
|
|
3694
3704
|
const t = new Set(e.letters());
|
|
@@ -3706,8 +3716,8 @@ class b {
|
|
|
3706
3716
|
t.y,
|
|
3707
3717
|
t.x.clone().opposite(),
|
|
3708
3718
|
e.x.clone().multiply(t.y).subtract(e.y.clone().multiply(t.x)).opposite()
|
|
3709
|
-
), this.#
|
|
3710
|
-
fromPointAndLine = (e, t, i) => (i === void 0 && (i =
|
|
3719
|
+
), this.#i = e.clone(), this.#n = t.clone(), this.#r = this.#n.clone().normal(), this);
|
|
3720
|
+
fromPointAndLine = (e, t, i) => (i === void 0 && (i = B.Parallel), i === B.Parallel ? this.fromPointAndNormal(e, t.normal) : i === B.Perpendicular ? this.fromPointAndNormal(e, t.director) : this);
|
|
3711
3721
|
fromPointAndNormal = (e, t) => this.fromCoefficient(
|
|
3712
3722
|
t.x,
|
|
3713
3723
|
t.y,
|
|
@@ -3718,7 +3728,7 @@ class b {
|
|
|
3718
3728
|
}
|
|
3719
3729
|
// ------------------------------------------
|
|
3720
3730
|
getEquation() {
|
|
3721
|
-
const e = new y(new u().parse("xy", this.#e, this.#
|
|
3731
|
+
const e = new y(new u().parse("xy", this.#e, this.#t, this.#s), new u("0"));
|
|
3722
3732
|
return this.#h ? e.simplify() : e;
|
|
3723
3733
|
}
|
|
3724
3734
|
getValueAtX = (e) => {
|
|
@@ -3732,7 +3742,7 @@ class b {
|
|
|
3732
3742
|
return t instanceof y ? t.right.evaluate({ y: i }) : new a().invalid();
|
|
3733
3743
|
};
|
|
3734
3744
|
get height() {
|
|
3735
|
-
return this.#s.clone().opposite().divide(this.#
|
|
3745
|
+
return this.#s.clone().opposite().divide(this.#t);
|
|
3736
3746
|
}
|
|
3737
3747
|
hitSegment(e, t) {
|
|
3738
3748
|
const i = this.intersection(
|
|
@@ -3743,7 +3753,7 @@ class b {
|
|
|
3743
3753
|
intersection = (e) => {
|
|
3744
3754
|
const t = new v();
|
|
3745
3755
|
let i = !1, s = !1;
|
|
3746
|
-
return this.#
|
|
3756
|
+
return this.#t.isZero() || e.b.isZero(), this.isParallelTo(e) ? (t.x = new a().invalid(), t.y = new a().invalid(), i = !0) : this.isSameAs(e) ? (t.x = new a().invalid(), t.y = new a().invalid(), s = !0) : (t.x = this.#t.clone().multiply(e.c).subtract(this.#s.clone().multiply(e.b)).divide(this.#e.clone().multiply(e.b).subtract(this.#t.clone().multiply(e.a))), t.y = this.#e.clone().multiply(e.c).subtract(this.#s.clone().multiply(e.a)).divide(this.#t.clone().multiply(e.a).subtract(this.#e.clone().multiply(e.b)))), {
|
|
3747
3757
|
point: t,
|
|
3748
3758
|
hasIntersection: !(i || s),
|
|
3749
3759
|
isParallel: i,
|
|
@@ -3752,7 +3762,7 @@ class b {
|
|
|
3752
3762
|
};
|
|
3753
3763
|
// ------------------------------------------
|
|
3754
3764
|
isOnLine = (e) => this.#e.clone().multiply(e.x).add(
|
|
3755
|
-
this.#
|
|
3765
|
+
this.#t.clone().multiply(e.y)
|
|
3756
3766
|
).add(this.#s).isZero();
|
|
3757
3767
|
isParallelTo = (e) => this.slope.isEqual(e.slope) && this.height.isNotEqual(e.height);
|
|
3758
3768
|
isPerpendicularTo = (e) => this.d.isNormalTo(e.d);
|
|
@@ -3764,10 +3774,10 @@ class b {
|
|
|
3764
3774
|
return this.#o = "mxh", this;
|
|
3765
3775
|
}
|
|
3766
3776
|
get n() {
|
|
3767
|
-
return this.#
|
|
3777
|
+
return this.#r;
|
|
3768
3778
|
}
|
|
3769
3779
|
get normal() {
|
|
3770
|
-
return new g(this.#e, this.#
|
|
3780
|
+
return new g(this.#e, this.#t);
|
|
3771
3781
|
}
|
|
3772
3782
|
get parametric() {
|
|
3773
3783
|
return this.#o = "parametric", this;
|
|
@@ -3780,7 +3790,7 @@ class b {
|
|
|
3780
3790
|
return t;
|
|
3781
3791
|
};
|
|
3782
3792
|
randomPoint = (e) => {
|
|
3783
|
-
const t = this.#
|
|
3793
|
+
const t = this.#n.clone().multiplyByScalar(q(e === void 0 || e <= 1 ? 3 : e, !1)).add(this.#i);
|
|
3784
3794
|
return t.asPoint = !0, t;
|
|
3785
3795
|
};
|
|
3786
3796
|
get reduceBeforeDisplay() {
|
|
@@ -3790,16 +3800,16 @@ class b {
|
|
|
3790
3800
|
this.#h = e;
|
|
3791
3801
|
}
|
|
3792
3802
|
simplify = () => {
|
|
3793
|
-
const e = E.lcm(this.#e.denominator, this.#
|
|
3803
|
+
const e = E.lcm(this.#e.denominator, this.#t.denominator, this.#s.denominator), t = E.gcd(this.#e.numerator, this.#t.numerator, this.#s.numerator);
|
|
3794
3804
|
return this.fromCoefficient(
|
|
3795
3805
|
this.#e.clone().multiply(e).divide(t),
|
|
3796
|
-
this.#
|
|
3806
|
+
this.#t.clone().multiply(e).divide(t),
|
|
3797
3807
|
this.#s.clone().multiply(e).divide(t)
|
|
3798
3808
|
), this;
|
|
3799
3809
|
};
|
|
3800
|
-
simplifyDirection = () => (this.#
|
|
3810
|
+
simplifyDirection = () => (this.#n.simplify(), this);
|
|
3801
3811
|
get slope() {
|
|
3802
|
-
return this.#e.clone().opposite().divide(this.#
|
|
3812
|
+
return this.#e.clone().opposite().divide(this.#t);
|
|
3803
3813
|
}
|
|
3804
3814
|
// ------------------------------------------
|
|
3805
3815
|
// Special functions
|
|
@@ -3807,23 +3817,23 @@ class b {
|
|
|
3807
3817
|
return this.#o = "system", this;
|
|
3808
3818
|
}
|
|
3809
3819
|
}
|
|
3810
|
-
class
|
|
3811
|
-
#t = void 0;
|
|
3812
|
-
#e = void 0;
|
|
3820
|
+
class V {
|
|
3813
3821
|
#i = void 0;
|
|
3822
|
+
#e = void 0;
|
|
3823
|
+
#t = void 0;
|
|
3814
3824
|
constructor(...e) {
|
|
3815
3825
|
e.length > 0 && this.parse(...e);
|
|
3816
3826
|
}
|
|
3817
3827
|
get center() {
|
|
3818
|
-
return this.#
|
|
3828
|
+
return this.#i ?? new v();
|
|
3819
3829
|
}
|
|
3820
3830
|
get squareRadius() {
|
|
3821
3831
|
return this.#e ?? new a(0);
|
|
3822
3832
|
}
|
|
3823
3833
|
get cartesian() {
|
|
3824
|
-
if (this.#
|
|
3834
|
+
if (this.#t === void 0)
|
|
3825
3835
|
throw new Error("Cartesian equation not defined");
|
|
3826
|
-
return this.#
|
|
3836
|
+
return this.#t;
|
|
3827
3837
|
}
|
|
3828
3838
|
get radius() {
|
|
3829
3839
|
return this.#e === void 0 ? { tex: "", display: "", value: 0 } : this.#e.isSquare() ? {
|
|
@@ -3853,34 +3863,34 @@ class W {
|
|
|
3853
3863
|
* @returns {number}
|
|
3854
3864
|
*/
|
|
3855
3865
|
relativePosition = (e) => {
|
|
3856
|
-
if (this.#
|
|
3866
|
+
if (this.#i === void 0 || this.#e === void 0)
|
|
3857
3867
|
throw new Error("Circle not defined");
|
|
3858
|
-
const t = e.distanceTo(this.#
|
|
3868
|
+
const t = e.distanceTo(this.#i), i = Math.sqrt(this.#e.value);
|
|
3859
3869
|
return t.value - i > 1e-10 ? 0 : Math.abs(t.value - i) < 1e-10 ? 1 : 2;
|
|
3860
3870
|
};
|
|
3861
3871
|
lineIntersection = (e) => {
|
|
3862
3872
|
const t = [];
|
|
3863
|
-
if (this.#
|
|
3873
|
+
if (this.#t === void 0)
|
|
3864
3874
|
return [];
|
|
3865
|
-
const i = this.#
|
|
3866
|
-
return s instanceof y &&
|
|
3875
|
+
const i = this.#t.clone(), s = e.getEquation().clone().isolate("x"), n = e.getEquation().clone().isolate("y");
|
|
3876
|
+
return s instanceof y && n instanceof y && (i.replaceBy("y", n.right).simplify(), i.solve()), t;
|
|
3867
3877
|
};
|
|
3868
|
-
tangents = (e) => e instanceof a ? this.#
|
|
3869
|
-
isPointOnCircle = (e) => this.#
|
|
3878
|
+
tangents = (e) => e instanceof a ? this.#r(e) : this.isPointOnCircle(e) ? this.#s(e) : this.#i !== void 0 && this.#i.distanceTo(e).value > this.radius.value ? this.#n(e) : (console.log("No tangents as the point is inside !"), []);
|
|
3879
|
+
isPointOnCircle = (e) => this.#t?.test({ x: e.x, y: e.y }) ?? !1;
|
|
3870
3880
|
getPointsOnCircle = (e) => {
|
|
3871
3881
|
const t = E.pythagoreanTripletsWithTarget(this.squareRadius.value, !0), i = [];
|
|
3872
3882
|
return t.forEach((s) => {
|
|
3873
|
-
for (const
|
|
3883
|
+
for (const n of [[1, 1], [-1, 1], [-1, -1], [1, -1]])
|
|
3874
3884
|
i.push(
|
|
3875
3885
|
new v(
|
|
3876
|
-
this.center.x.clone().add(
|
|
3877
|
-
this.center.y.clone().add(
|
|
3886
|
+
this.center.x.clone().add(n[0] * s[0]),
|
|
3887
|
+
this.center.y.clone().add(n[1] * s[1])
|
|
3878
3888
|
)
|
|
3879
3889
|
);
|
|
3880
3890
|
}), i;
|
|
3881
3891
|
};
|
|
3882
3892
|
clone() {
|
|
3883
|
-
return new
|
|
3893
|
+
return new V(
|
|
3884
3894
|
this.center.clone(),
|
|
3885
3895
|
this.squareRadius.clone(),
|
|
3886
3896
|
!0
|
|
@@ -3891,46 +3901,46 @@ class W {
|
|
|
3891
3901
|
}
|
|
3892
3902
|
#s = (e) => {
|
|
3893
3903
|
const t = new g(this.center, e);
|
|
3894
|
-
return [new b(e, t,
|
|
3904
|
+
return [new b(e, t, B.Perpendicular)];
|
|
3895
3905
|
};
|
|
3896
|
-
#
|
|
3897
|
-
const t = this.center.x.clone().subtract(e.x), i = this.center.y.clone().subtract(e.y), s = new u("x"),
|
|
3898
|
-
return s.multiply(t).subtract(i).pow(2),
|
|
3906
|
+
#n = (e) => {
|
|
3907
|
+
const t = this.center.x.clone().subtract(e.x), i = this.center.y.clone().subtract(e.y), s = new u("x"), n = new u("x^2+1");
|
|
3908
|
+
return s.multiply(t).subtract(i).pow(2), n.multiply(this.squareRadius), new y(s, n).solve().map((l) => {
|
|
3899
3909
|
let c;
|
|
3900
3910
|
const d = new y("y", "x");
|
|
3901
3911
|
return l.exact instanceof a ? (c = e.x.clone().opposite().multiply(l.exact).add(e.y), d.right.multiply(l.exact).add(c)) : (c = e.x.clone().opposite().multiply(l.value).add(e.y), d.right.multiply(l.value).add(c)), new b(d);
|
|
3902
3912
|
});
|
|
3903
3913
|
};
|
|
3904
|
-
#
|
|
3905
|
-
const t = e.numerator, i = -e.denominator, s = this.center.x.clone(),
|
|
3914
|
+
#r = (e) => {
|
|
3915
|
+
const t = e.numerator, i = -e.denominator, s = this.center.x.clone(), n = this.center.y.clone(), o = this.squareRadius.clone().multiply(e.numerator ** 2 + e.denominator ** 2), h = s.clone().multiply(t).opposite().subtract(n.clone().multiply(i)).add(o.clone().sqrt()), l = s.clone().multiply(t).opposite().subtract(n.clone().multiply(i)).subtract(o.clone().sqrt());
|
|
3906
3916
|
return [new b(t, i, h), new b(t, i, l)];
|
|
3907
3917
|
};
|
|
3908
3918
|
#o() {
|
|
3909
|
-
return this.#
|
|
3919
|
+
return this.#i = void 0, this.#e = void 0, this.#t = void 0, this;
|
|
3910
3920
|
}
|
|
3911
3921
|
parse(...e) {
|
|
3912
|
-
return this.#o(), typeof e[0] == "string" ? this.#u(new y(e[0])) : e[0] instanceof y ? this.#u(e[0]) : e[0] instanceof
|
|
3922
|
+
return this.#o(), typeof e[0] == "string" ? this.#u(new y(e[0])) : e[0] instanceof y ? this.#u(e[0]) : e[0] instanceof V ? this.#a(e[0]) : e[0] instanceof v && e.length > 1 && (e[1] instanceof v ? e[2] instanceof v || this.#l(e[0], e[1]) : (e[1] instanceof a || typeof e[1] == "number") && this.#c(e[0], e[1], typeof e[2] == "boolean" ? e[2] : !1)), this.#h(), this;
|
|
3913
3923
|
}
|
|
3914
3924
|
#h() {
|
|
3915
|
-
this.#
|
|
3925
|
+
this.#t = new y(
|
|
3916
3926
|
new u(`(x-(${this.center.x.display}))^2+(y-(${this.center.y.display}))^2`),
|
|
3917
3927
|
new u(this.squareRadius.display)
|
|
3918
3928
|
).moveLeft();
|
|
3919
3929
|
}
|
|
3920
3930
|
#a(e) {
|
|
3921
|
-
return this.#
|
|
3931
|
+
return this.#i = e.center.clone(), this.#e = e.squareRadius.clone(), this.#h(), this;
|
|
3922
3932
|
}
|
|
3923
3933
|
#c(e, t, i) {
|
|
3924
|
-
return this.#
|
|
3934
|
+
return this.#i = e.clone(), i ? this.#e = new a(t) : this.#e = new a(t).pow(2), this;
|
|
3925
3935
|
}
|
|
3926
3936
|
#l(e, t) {
|
|
3927
|
-
return this.#
|
|
3937
|
+
return this.#i = e.clone(), this.#e = new g(this.#i, t).normSquare, this;
|
|
3928
3938
|
}
|
|
3929
3939
|
#u(e) {
|
|
3930
3940
|
if (e.moveLeft(), e.degree("x").value === 2 && e.degree("y").value === 2) {
|
|
3931
3941
|
const t = e.left.monomByDegree(2, "x"), i = e.left.monomByDegree(2, "y");
|
|
3932
|
-
let s,
|
|
3933
|
-
t.coefficient.isEqual(i.coefficient) ? (e.divide(t.coefficient), s = e.left.monomByDegree(1, "x"),
|
|
3942
|
+
let s, n, o;
|
|
3943
|
+
t.coefficient.isEqual(i.coefficient) ? (e.divide(t.coefficient), s = e.left.monomByDegree(1, "x"), n = e.left.monomByDegree(1, "y"), o = e.left.monomByDegree(0), this.#i = new v(s.coefficient.clone().divide(2).opposite(), n.coefficient.clone().divide(2).opposite()), this.#e = o.coefficient.clone().opposite().add(this.#i.x.clone().pow(2)).add(this.#i.y.clone().pow(2))) : (this.#i = void 0, this.#e = void 0);
|
|
3934
3944
|
}
|
|
3935
3945
|
return this;
|
|
3936
3946
|
}
|
|
@@ -3941,24 +3951,24 @@ class W {
|
|
|
3941
3951
|
// return this
|
|
3942
3952
|
// }
|
|
3943
3953
|
}
|
|
3944
|
-
class
|
|
3954
|
+
class Y {
|
|
3945
3955
|
// A line is defined as the canonical form
|
|
3946
|
-
static PERPENDICULAR =
|
|
3947
|
-
static PARALLEL =
|
|
3956
|
+
static PERPENDICULAR = Q.Perpendicular;
|
|
3957
|
+
static PARALLEL = Q.Parallel;
|
|
3948
3958
|
// ax + by + c = 0
|
|
3949
|
-
#
|
|
3959
|
+
#i = new v();
|
|
3950
3960
|
#e = new g();
|
|
3951
3961
|
constructor(e, t) {
|
|
3952
|
-
return this.#
|
|
3962
|
+
return this.#i = e.clone(), this.#e = t.asPoint ? new g(e, t) : t.clone(), this;
|
|
3953
3963
|
}
|
|
3954
3964
|
get OA() {
|
|
3955
|
-
return this.#
|
|
3965
|
+
return this.#i;
|
|
3956
3966
|
}
|
|
3957
3967
|
set OA(e) {
|
|
3958
|
-
this.#
|
|
3968
|
+
this.#i = e;
|
|
3959
3969
|
}
|
|
3960
3970
|
get point() {
|
|
3961
|
-
return this.#
|
|
3971
|
+
return this.#i.clone();
|
|
3962
3972
|
}
|
|
3963
3973
|
get d() {
|
|
3964
3974
|
return this.#e;
|
|
@@ -3968,27 +3978,27 @@ class ee {
|
|
|
3968
3978
|
}
|
|
3969
3979
|
get tex() {
|
|
3970
3980
|
return {
|
|
3971
|
-
parametric: `${g.asTex("x", "y", "z")} = ${g.asTex(this.#
|
|
3981
|
+
parametric: `${g.asTex("x", "y", "z")} = ${g.asTex(this.#i.x.tex, this.#i.y.tex, this.#i.z.tex)} + k\\cdot ${g.asTex(this.#e.x.tex, this.#e.y.tex, this.#e.z.tex)}`,
|
|
3972
3982
|
system: `\\left\\{\\begin{aligned}
|
|
3973
|
-
x &= ${new u(this.#
|
|
3974
|
-
y &= ${new u(this.#
|
|
3975
|
-
z &= ${new u(this.#
|
|
3983
|
+
x &= ${new u(this.#i.x).add(new p(this.#e.x).multiply(new p("k"))).reorder("k", !0).tex}\\\\
|
|
3984
|
+
y &= ${new u(this.#i.y).add(new p(this.#e.y).multiply(new p("k"))).reorder("k", !0).tex}\\\\
|
|
3985
|
+
z &= ${new u(this.#i.z).add(new p(this.#e.z).multiply(new p("k"))).reorder("k", !0).tex}
|
|
3976
3986
|
\\end{aligned}\\right.`,
|
|
3977
|
-
cartesian: `\\frac{ ${new u("x", 1, this.#
|
|
3987
|
+
cartesian: `\\frac{ ${new u("x", 1, this.#i.x.clone().opposite()).tex} }{ ${this.direction.x.tex} } = \\frac{ ${new u("y", 1, this.#i.y.clone().opposite()).tex} }{ ${this.direction.y.tex} } = \\frac{ ${new u("z", 1, this.#i.z.clone().opposite()).tex} }{ ${this.direction.z.tex} }`
|
|
3978
3988
|
};
|
|
3979
3989
|
}
|
|
3980
3990
|
get display() {
|
|
3981
|
-
const e = this.#
|
|
3991
|
+
const e = this.#i.x.display, t = this.#i.y.display, i = this.#i.z.display, s = this.direction.simplify(), n = s.x.display, o = s.y.display, h = s.z.display;
|
|
3982
3992
|
return {
|
|
3983
|
-
parametric: `${g.asDisplay("x", "y", "z")} = ${g.asDisplay(this.#
|
|
3993
|
+
parametric: `${g.asDisplay("x", "y", "z")} = ${g.asDisplay(this.#i.x.display, this.#i.y.display, this.#i.z.display)} + k\\cdot ${g.asDisplay(this.#e.x.display, this.#e.y.display, this.#e.z.display)}`,
|
|
3984
3994
|
system: "",
|
|
3985
|
-
cartesian: `(x-${e})/${
|
|
3995
|
+
cartesian: `(x-${e})/${n} = (y-${t})/${o} = (z-${i})/${h}`
|
|
3986
3996
|
};
|
|
3987
3997
|
}
|
|
3988
3998
|
get direction() {
|
|
3989
3999
|
return this.#e.clone();
|
|
3990
4000
|
}
|
|
3991
|
-
clone = () => (this.#e = this.#e.clone(), this.#
|
|
4001
|
+
clone = () => (this.#e = this.#e.clone(), this.#i = this.#i.clone(), this);
|
|
3992
4002
|
// ------------------------------------------
|
|
3993
4003
|
// Mathematical operations
|
|
3994
4004
|
// ------------------------------------------
|
|
@@ -4012,7 +4022,7 @@ class ee {
|
|
|
4012
4022
|
throw new Error("Method not implemented.");
|
|
4013
4023
|
};
|
|
4014
4024
|
distanceTo(e) {
|
|
4015
|
-
const t = new g(this.#
|
|
4025
|
+
const t = new g(this.#i, e), i = this.direction, s = this.direction.normSquare, n = t.cross(i).normSquare, o = n.clone().divide(s), h = o.clone().sqrt();
|
|
4016
4026
|
return console.log("CROSS", t.cross(i).display), {
|
|
4017
4027
|
value: Math.sqrt(o.value),
|
|
4018
4028
|
fraction: o.clone().sqrt(),
|
|
@@ -4021,7 +4031,7 @@ class ee {
|
|
|
4021
4031
|
}
|
|
4022
4032
|
hitSegment(e, t) {
|
|
4023
4033
|
const i = this.intersection(
|
|
4024
|
-
new
|
|
4034
|
+
new Y(e, t)
|
|
4025
4035
|
);
|
|
4026
4036
|
return i.hasIntersection ? i.point.x.value >= Math.min(e.x.value, t.x.value) && i.point.x.value <= Math.max(e.x.value, t.x.value) && i.point.y.value >= Math.min(e.y.value, t.y.value) && i.point.y.value <= Math.max(e.y.value, t.y.value) && i.point.z.value >= Math.min(e.z.value, t.z.value) && i.point.z.value <= Math.max(e.z.value, t.z.value) : !1;
|
|
4027
4037
|
}
|
|
@@ -4042,7 +4052,7 @@ class ee {
|
|
|
4042
4052
|
// return new Fraction().invalid()
|
|
4043
4053
|
// }
|
|
4044
4054
|
randomPoint = (e = 5) => {
|
|
4045
|
-
const t = this.#
|
|
4055
|
+
const t = this.#i.clone(), i = new a(q(e, !1));
|
|
4046
4056
|
return new v(
|
|
4047
4057
|
t.x.clone().add(this.#e.x.clone().multiply(i)),
|
|
4048
4058
|
t.y.clone().add(this.#e.y.clone().multiply(i)),
|
|
@@ -4050,17 +4060,17 @@ class ee {
|
|
|
4050
4060
|
);
|
|
4051
4061
|
};
|
|
4052
4062
|
}
|
|
4053
|
-
class
|
|
4054
|
-
#
|
|
4063
|
+
class ee {
|
|
4064
|
+
#i = new g(0, 0, 1);
|
|
4055
4065
|
#e = new v(0, 0, 0);
|
|
4056
4066
|
constructor(e) {
|
|
4057
4067
|
return e && this.parse(e), this;
|
|
4058
4068
|
}
|
|
4059
4069
|
get normal() {
|
|
4060
|
-
return this.#
|
|
4070
|
+
return this.#i;
|
|
4061
4071
|
}
|
|
4062
4072
|
set normal(e) {
|
|
4063
|
-
this.#
|
|
4073
|
+
this.#i = e, this.#i.asPoint = !1;
|
|
4064
4074
|
}
|
|
4065
4075
|
get point() {
|
|
4066
4076
|
return this.#e;
|
|
@@ -4069,16 +4079,16 @@ class ae {
|
|
|
4069
4079
|
this.#e = e, this.#e.asPoint = !0;
|
|
4070
4080
|
}
|
|
4071
4081
|
get a() {
|
|
4072
|
-
return this.#
|
|
4082
|
+
return this.#i.x;
|
|
4073
4083
|
}
|
|
4074
4084
|
get b() {
|
|
4075
|
-
return this.#
|
|
4085
|
+
return this.#i.y;
|
|
4076
4086
|
}
|
|
4077
4087
|
get c() {
|
|
4078
|
-
return this.#
|
|
4088
|
+
return this.#i.z;
|
|
4079
4089
|
}
|
|
4080
4090
|
get d() {
|
|
4081
|
-
return this.#
|
|
4091
|
+
return this.#i.dot(this.#e).opposite();
|
|
4082
4092
|
}
|
|
4083
4093
|
get tex() {
|
|
4084
4094
|
return new y(
|
|
@@ -4104,23 +4114,23 @@ class ae {
|
|
|
4104
4114
|
return;
|
|
4105
4115
|
}
|
|
4106
4116
|
if (e.equation) {
|
|
4107
|
-
const t = e.equation.moveLeft().reduce().left, i = t.monomByLetter("x").coefficient, s = t.monomByLetter("y").coefficient,
|
|
4108
|
-
this.normal = new g(i, s,
|
|
4117
|
+
const t = e.equation.moveLeft().reduce().left, i = t.monomByLetter("x").coefficient, s = t.monomByLetter("y").coefficient, n = t.monomByLetter("z").coefficient, o = t.monomByDegree(0).coefficient;
|
|
4118
|
+
this.normal = new g(i, s, n), i.isNotZero() ? this.point = new v(o.clone().divide(i).opposite(), 0, 0) : s.isNotZero() ? this.point = new v(0, o.clone().divide(s).opposite(), 0) : this.point = new v(0, 0, o.clone().divide(n).opposite());
|
|
4109
4119
|
return;
|
|
4110
4120
|
}
|
|
4111
4121
|
if (e.points?.length === 3 && e.points.every((t) => t instanceof g)) {
|
|
4112
|
-
const t = e.points[0], i = e.points[1], s = e.points[2],
|
|
4113
|
-
this.normal =
|
|
4122
|
+
const t = e.points[0], i = e.points[1], s = e.points[2], n = new g(t, i), o = new g(t, s);
|
|
4123
|
+
this.normal = n.cross(o), this.point = t;
|
|
4114
4124
|
return;
|
|
4115
4125
|
}
|
|
4116
4126
|
if (e.coefficients?.length === 4) {
|
|
4117
|
-
const [t, i, s,
|
|
4118
|
-
this.normal = new g(t, i, s), this.point = new v(0, 0, -
|
|
4127
|
+
const [t, i, s, n] = e.coefficients;
|
|
4128
|
+
this.normal = new g(t, i, s), this.point = new v(0, 0, -n);
|
|
4119
4129
|
return;
|
|
4120
4130
|
}
|
|
4121
4131
|
}
|
|
4122
4132
|
angle(e, t, i) {
|
|
4123
|
-
if (e instanceof
|
|
4133
|
+
if (e instanceof ee)
|
|
4124
4134
|
return this.normal.angle(e.normal, t, i);
|
|
4125
4135
|
let s;
|
|
4126
4136
|
if (e instanceof g) {
|
|
@@ -4145,21 +4155,21 @@ class ae {
|
|
|
4145
4155
|
return this.normal.dot(e).add(this.d).isZero();
|
|
4146
4156
|
}
|
|
4147
4157
|
}
|
|
4148
|
-
class
|
|
4149
|
-
#t = new v();
|
|
4150
|
-
#e = new v();
|
|
4158
|
+
class F {
|
|
4151
4159
|
#i = new v();
|
|
4160
|
+
#e = new v();
|
|
4161
|
+
#t = new v();
|
|
4152
4162
|
#s = {
|
|
4153
4163
|
AB: new b(),
|
|
4154
4164
|
AC: new b(),
|
|
4155
4165
|
BC: new b()
|
|
4156
4166
|
};
|
|
4157
|
-
#
|
|
4167
|
+
#n = {
|
|
4158
4168
|
AB: new v(),
|
|
4159
4169
|
AC: new v(),
|
|
4160
4170
|
BC: new v()
|
|
4161
4171
|
};
|
|
4162
|
-
#
|
|
4172
|
+
#r = null;
|
|
4163
4173
|
constructor(...e) {
|
|
4164
4174
|
return e.length > 0 && this.parse(...e), this;
|
|
4165
4175
|
}
|
|
@@ -4167,13 +4177,13 @@ class H {
|
|
|
4167
4177
|
// Getter and setters
|
|
4168
4178
|
// ------------------------------------------
|
|
4169
4179
|
get A() {
|
|
4170
|
-
return this.#
|
|
4180
|
+
return this.#i;
|
|
4171
4181
|
}
|
|
4172
4182
|
get B() {
|
|
4173
4183
|
return this.#e;
|
|
4174
4184
|
}
|
|
4175
4185
|
get C() {
|
|
4176
|
-
return this.#
|
|
4186
|
+
return this.#t;
|
|
4177
4187
|
}
|
|
4178
4188
|
get AB() {
|
|
4179
4189
|
return this.#a("A", "B");
|
|
@@ -4206,7 +4216,7 @@ class H {
|
|
|
4206
4216
|
return this.#s;
|
|
4207
4217
|
}
|
|
4208
4218
|
get remarquables() {
|
|
4209
|
-
return this.#
|
|
4219
|
+
return this.#r;
|
|
4210
4220
|
}
|
|
4211
4221
|
// ------------------------------------------
|
|
4212
4222
|
// Creation / parsing functions
|
|
@@ -4235,35 +4245,35 @@ class H {
|
|
|
4235
4245
|
if (e.every((t) => t instanceof b)) {
|
|
4236
4246
|
const t = e[0].clone(), i = e[1].clone(), s = e[2].clone();
|
|
4237
4247
|
this.#s = { AB: t, BC: i, AC: s };
|
|
4238
|
-
let
|
|
4239
|
-
if (
|
|
4240
|
-
this.#e =
|
|
4248
|
+
let n = t.intersection(i);
|
|
4249
|
+
if (n.hasIntersection)
|
|
4250
|
+
this.#e = n.point.clone();
|
|
4241
4251
|
else
|
|
4242
4252
|
throw new Error("Lines do not intersect !");
|
|
4243
|
-
if (
|
|
4244
|
-
this.#
|
|
4253
|
+
if (n = i.intersection(s), n.hasIntersection)
|
|
4254
|
+
this.#t = n.point.clone();
|
|
4245
4255
|
else
|
|
4246
4256
|
throw new Error("Lines do not intersect !");
|
|
4247
|
-
if (
|
|
4248
|
-
this.#
|
|
4257
|
+
if (n = s.intersection(t), n.hasIntersection)
|
|
4258
|
+
this.#i = n.point.clone();
|
|
4249
4259
|
else
|
|
4250
4260
|
throw new Error("Lines do not intersect !");
|
|
4251
|
-
} else e.every((t) => t instanceof v) && (this.#
|
|
4252
|
-
AB: new b(this.#
|
|
4253
|
-
BC: new b(this.#e, this.#
|
|
4254
|
-
AC: new b(this.#
|
|
4261
|
+
} else e.every((t) => t instanceof v) && (this.#i = e[0].clone(), this.#e = e[1].clone(), this.#t = e[2].clone(), this.#s = {
|
|
4262
|
+
AB: new b(this.#i, this.#e),
|
|
4263
|
+
BC: new b(this.#e, this.#t),
|
|
4264
|
+
AC: new b(this.#i, this.#t)
|
|
4255
4265
|
});
|
|
4256
|
-
} else if (e.length === 1 && e[0] instanceof
|
|
4266
|
+
} else if (e.length === 1 && e[0] instanceof F)
|
|
4257
4267
|
return e[0].clone();
|
|
4258
4268
|
return this.#o(), this;
|
|
4259
4269
|
};
|
|
4260
4270
|
/**
|
|
4261
4271
|
* Clone the Triangle class
|
|
4262
4272
|
*/
|
|
4263
|
-
clone = () => new
|
|
4264
|
-
this.#
|
|
4273
|
+
clone = () => new F(
|
|
4274
|
+
this.#i.clone(),
|
|
4265
4275
|
this.#e.clone(),
|
|
4266
|
-
this.#
|
|
4276
|
+
this.#t.clone()
|
|
4267
4277
|
);
|
|
4268
4278
|
// ------------------------------------------
|
|
4269
4279
|
// Triangle operations and properties
|
|
@@ -4272,11 +4282,11 @@ class H {
|
|
|
4272
4282
|
* Generate the Line object for the three segments of the triangle
|
|
4273
4283
|
*/
|
|
4274
4284
|
#o = () => {
|
|
4275
|
-
this.#
|
|
4276
|
-
AB: new v().middleOf(this.#
|
|
4277
|
-
AC: new v().middleOf(this.#
|
|
4278
|
-
BC: new v().middleOf(this.#e, this.#
|
|
4279
|
-
}, this.#
|
|
4285
|
+
this.#i.asPoint = !0, this.#e.asPoint = !0, this.#t.asPoint = !0, this.#n = {
|
|
4286
|
+
AB: new v().middleOf(this.#i, this.#e),
|
|
4287
|
+
AC: new v().middleOf(this.#i, this.#t),
|
|
4288
|
+
BC: new v().middleOf(this.#e, this.#t)
|
|
4289
|
+
}, this.#r = this.#c();
|
|
4280
4290
|
};
|
|
4281
4291
|
/**
|
|
4282
4292
|
* Get the Vector2D class for the given name
|
|
@@ -4285,13 +4295,13 @@ class H {
|
|
|
4285
4295
|
#h = (e) => {
|
|
4286
4296
|
switch (e.toUpperCase()) {
|
|
4287
4297
|
case "A":
|
|
4288
|
-
return this.#
|
|
4298
|
+
return this.#i;
|
|
4289
4299
|
case "B":
|
|
4290
4300
|
return this.#e;
|
|
4291
4301
|
case "C":
|
|
4292
|
-
return this.#
|
|
4302
|
+
return this.#t;
|
|
4293
4303
|
}
|
|
4294
|
-
return this.#
|
|
4304
|
+
return this.#i;
|
|
4295
4305
|
};
|
|
4296
4306
|
/**
|
|
4297
4307
|
* Get the vector for the segment given by name.
|
|
@@ -4304,28 +4314,28 @@ class H {
|
|
|
4304
4314
|
);
|
|
4305
4315
|
#c = () => {
|
|
4306
4316
|
const e = {
|
|
4307
|
-
A: new b().fromPoints(this.#
|
|
4308
|
-
B: new b().fromPoints(this.#e, this.#
|
|
4309
|
-
C: new b().fromPoints(this.#
|
|
4317
|
+
A: new b().fromPoints(this.#i, this.#n.BC),
|
|
4318
|
+
B: new b().fromPoints(this.#e, this.#n.AC),
|
|
4319
|
+
C: new b().fromPoints(this.#t, this.#n.AB),
|
|
4310
4320
|
intersection: null
|
|
4311
4321
|
}, t = {
|
|
4312
|
-
AB: new b().fromPointAndNormal(this.#
|
|
4313
|
-
AC: new b().fromPointAndNormal(this.#
|
|
4314
|
-
BC: new b().fromPointAndNormal(this.#
|
|
4322
|
+
AB: new b().fromPointAndNormal(this.#n.AB, new g(this.#i, this.#e).normal()),
|
|
4323
|
+
AC: new b().fromPointAndNormal(this.#n.AC, new g(this.#i, this.#t).normal()),
|
|
4324
|
+
BC: new b().fromPointAndNormal(this.#n.BC, new g(this.#e, this.#t).normal()),
|
|
4315
4325
|
intersection: null
|
|
4316
4326
|
}, i = {
|
|
4317
|
-
A: new b().fromPointAndNormal(this.#
|
|
4318
|
-
B: new b().fromPointAndNormal(this.#e, new g(this.#
|
|
4319
|
-
C: new b().fromPointAndNormal(this.#
|
|
4327
|
+
A: new b().fromPointAndNormal(this.#i, new g(this.#e, this.#t).normal()),
|
|
4328
|
+
B: new b().fromPointAndNormal(this.#e, new g(this.#i, this.#t).normal()),
|
|
4329
|
+
C: new b().fromPointAndNormal(this.#t, new g(this.#i, this.#e).normal()),
|
|
4320
4330
|
intersection: null
|
|
4321
|
-
}, s = this.#l("A"),
|
|
4331
|
+
}, s = this.#l("A"), n = this.#l("B"), o = this.#l("C"), h = {
|
|
4322
4332
|
A: s.internal,
|
|
4323
|
-
B:
|
|
4324
|
-
C:
|
|
4333
|
+
B: n.internal,
|
|
4334
|
+
C: n.internal,
|
|
4325
4335
|
intersection: null
|
|
4326
4336
|
}, l = {
|
|
4327
4337
|
A: s.external,
|
|
4328
|
-
B:
|
|
4338
|
+
B: n.external,
|
|
4329
4339
|
C: o.external,
|
|
4330
4340
|
intersection: null
|
|
4331
4341
|
}, c = {
|
|
@@ -4342,34 +4352,34 @@ class H {
|
|
|
4342
4352
|
let i, s;
|
|
4343
4353
|
if (e === "A" ? (i = t.AB, s = t.AC) : e === "B" ? (i = t.AB, s = t.BC) : e === "C" && (i = t.BC, s = t.AC), i === void 0 || s === void 0)
|
|
4344
4354
|
throw new Error(`The point ${e} does not exist`);
|
|
4345
|
-
const
|
|
4355
|
+
const n = i.n.simplify().norm, o = s.n.simplify().norm, h = i.getEquation().multiply(o), l = s.getEquation().multiply(n), c = new b(h.clone().subtract(l).simplify()), d = new b(l.clone().subtract(h).simplify());
|
|
4346
4356
|
return e === "A" ? c.hitSegment(this.B, this.C) ? { internal: c, external: d } : { internal: d, external: c } : e === "B" ? c.hitSegment(this.A, this.C) ? { internal: c, external: d } : { internal: d, external: c } : e === "C" ? c.hitSegment(this.B, this.A) ? { internal: c, external: d } : { internal: d, external: c } : { internal: c, external: d };
|
|
4347
4357
|
};
|
|
4348
4358
|
}
|
|
4349
|
-
var
|
|
4350
|
-
class
|
|
4351
|
-
#t = void 0;
|
|
4352
|
-
#e = void 0;
|
|
4359
|
+
var oe = /* @__PURE__ */ ((r) => (r[r.INTERIOR = 0] = "INTERIOR", r[r.EXTERIOR = 1] = "EXTERIOR", r[r.SECANT = 2] = "SECANT", r[r.TANGENT_INSIDE = 3] = "TANGENT_INSIDE", r[r.TANGENT_OUTSIDE = 4] = "TANGENT_OUTSIDE", r[r.SUPERPOSED = 5] = "SUPERPOSED", r[r.CONCENTRIC = 6] = "CONCENTRIC", r))(oe || {});
|
|
4360
|
+
class Be {
|
|
4353
4361
|
#i = void 0;
|
|
4362
|
+
#e = void 0;
|
|
4363
|
+
#t = void 0;
|
|
4354
4364
|
#s = 1;
|
|
4355
4365
|
constructor(e, t) {
|
|
4356
|
-
return e && t && (this.#
|
|
4366
|
+
return e && t && (this.#i = e, this.#e = new a(t).clone().pow(2), this.#r()), this;
|
|
4357
4367
|
}
|
|
4358
4368
|
fromEquation(e) {
|
|
4359
4369
|
const t = new y(e).moveLeft().reduce(), i = ["x", "y", "z"];
|
|
4360
|
-
if (i.some((
|
|
4370
|
+
if (i.some((n) => t.degree(n).value !== 2))
|
|
4361
4371
|
return this.makeUndefined();
|
|
4362
4372
|
const s = t.left.monomByDegree(2, "x").coefficient;
|
|
4363
|
-
return i.some((
|
|
4373
|
+
return i.some((n) => t.left.monomByDegree(2, n).coefficient.isNotEqual(s)) ? this.makeUndefined() : (this.#i = new v(
|
|
4364
4374
|
t.left.monomByDegree(1, "x").coefficient.clone().opposite().divide(2),
|
|
4365
4375
|
t.left.monomByDegree(1, "y").coefficient.clone().opposite().divide(2),
|
|
4366
4376
|
t.left.monomByDegree(1, "z").coefficient.clone().opposite().divide(2)
|
|
4367
|
-
), this.#e = t.left.monomByDegree(0).coefficient.clone().opposite().add(this.#
|
|
4377
|
+
), this.#e = t.left.monomByDegree(0).coefficient.clone().opposite().add(this.#i.x.clone().pow(2)).add(this.#i.y.clone().pow(2)).add(this.#i.z.clone().pow(2)), this.#r(), this);
|
|
4368
4378
|
}
|
|
4369
4379
|
get center() {
|
|
4370
|
-
if (this.#
|
|
4380
|
+
if (this.#i === void 0)
|
|
4371
4381
|
throw new Error("Sphere3 is undefined");
|
|
4372
|
-
return this.#
|
|
4382
|
+
return this.#i;
|
|
4373
4383
|
}
|
|
4374
4384
|
get squareRadius() {
|
|
4375
4385
|
if (this.#e === void 0)
|
|
@@ -4390,12 +4400,12 @@ class Ue {
|
|
|
4390
4400
|
};
|
|
4391
4401
|
}
|
|
4392
4402
|
get equation() {
|
|
4393
|
-
if (this.#
|
|
4403
|
+
if (this.#t === void 0)
|
|
4394
4404
|
throw new Error("Sphere3 is undefined");
|
|
4395
|
-
return this.#
|
|
4405
|
+
return this.#t;
|
|
4396
4406
|
}
|
|
4397
4407
|
makeUndefined() {
|
|
4398
|
-
return this.#
|
|
4408
|
+
return this.#i = void 0, this.#e = void 0, this.#t = void 0, this;
|
|
4399
4409
|
}
|
|
4400
4410
|
get centerRadius() {
|
|
4401
4411
|
return this.#s = 1, this;
|
|
@@ -4404,30 +4414,30 @@ class Ue {
|
|
|
4404
4414
|
return this.#s = 0, this;
|
|
4405
4415
|
}
|
|
4406
4416
|
get tex() {
|
|
4407
|
-
return this.#
|
|
4417
|
+
return this.#n(!0);
|
|
4408
4418
|
}
|
|
4409
4419
|
get display() {
|
|
4410
|
-
return this.#
|
|
4420
|
+
return this.#n(!1);
|
|
4411
4421
|
}
|
|
4412
|
-
#
|
|
4413
|
-
if (this.#
|
|
4422
|
+
#n = (e) => {
|
|
4423
|
+
if (this.#t === void 0)
|
|
4414
4424
|
throw new Error("Sphere3 is undefined");
|
|
4415
4425
|
if (this.#s === 0)
|
|
4416
|
-
return e ? this.#
|
|
4426
|
+
return e ? this.#t.tex : this.#t.display;
|
|
4417
4427
|
const t = [];
|
|
4418
4428
|
return ["x", "y", "z"].forEach((s) => {
|
|
4419
4429
|
if (this.center[s].isZero())
|
|
4420
4430
|
t.push(`${s}^2`);
|
|
4421
4431
|
else {
|
|
4422
|
-
const
|
|
4432
|
+
const n = new u(s).subtract(this.center[s]);
|
|
4423
4433
|
t.push(
|
|
4424
|
-
e ? `\\(${
|
|
4434
|
+
e ? `\\(${n.tex}\\)^2` : `(${n.display})^2`
|
|
4425
4435
|
);
|
|
4426
4436
|
}
|
|
4427
4437
|
}), t.join("+") + "=" + (e ? this.squareRadius.tex : this.squareRadius.display);
|
|
4428
4438
|
};
|
|
4429
|
-
#
|
|
4430
|
-
this.#
|
|
4439
|
+
#r() {
|
|
4440
|
+
this.#t = new y(
|
|
4431
4441
|
new u("x").subtract(this.center.x).pow(2).add(
|
|
4432
4442
|
new u("y").subtract(this.center.y).pow(2)
|
|
4433
4443
|
).add(
|
|
@@ -4436,18 +4446,18 @@ class Ue {
|
|
|
4436
4446
|
new u(this.squareRadius)
|
|
4437
4447
|
).reduce();
|
|
4438
4448
|
}
|
|
4439
|
-
static RELATIVE_POSITION =
|
|
4449
|
+
static RELATIVE_POSITION = oe;
|
|
4440
4450
|
relativePosition = (e) => {
|
|
4441
4451
|
const t = this.center.distanceTo(e.center).value, i = this.radius.value, s = e.radius.value;
|
|
4442
4452
|
return t > i + s ? 1 : t === i + s ? 4 : t === 0 ? i === s ? 5 : 6 : t === Math.abs(i - s) ? 3 : t < Math.abs(i - s) ? 0 : 2;
|
|
4443
4453
|
};
|
|
4444
|
-
isPointOnSphere = (e) => this.#
|
|
4454
|
+
isPointOnSphere = (e) => this.#t?.test({
|
|
4445
4455
|
x: e.x,
|
|
4446
4456
|
y: e.y,
|
|
4447
4457
|
z: e.z
|
|
4448
4458
|
}) ?? !1;
|
|
4449
4459
|
}
|
|
4450
|
-
function
|
|
4460
|
+
function G(r) {
|
|
4451
4461
|
const e = Object.assign(
|
|
4452
4462
|
{
|
|
4453
4463
|
negative: !0,
|
|
@@ -4456,18 +4466,18 @@ function K(n) {
|
|
|
4456
4466
|
zero: !0,
|
|
4457
4467
|
natural: !1
|
|
4458
4468
|
},
|
|
4459
|
-
|
|
4469
|
+
r
|
|
4460
4470
|
), t = new a();
|
|
4461
|
-
if (e.negative ? t.numerator = q(e.max, e.zero) : t.numerator =
|
|
4471
|
+
if (e.negative ? t.numerator = q(e.max, e.zero) : t.numerator = k(e.zero ? 0 : 1, e.max), e.natural)
|
|
4462
4472
|
t.denominator = 1;
|
|
4463
4473
|
else {
|
|
4464
4474
|
let i = 0;
|
|
4465
4475
|
for (; t.isRelative() && i < 10; )
|
|
4466
|
-
t.denominator =
|
|
4476
|
+
t.denominator = k(1, e.max), i++;
|
|
4467
4477
|
}
|
|
4468
4478
|
return e.reduced ? t.reduce() : t;
|
|
4469
4479
|
}
|
|
4470
|
-
function
|
|
4480
|
+
function he(r) {
|
|
4471
4481
|
const e = Object.assign(
|
|
4472
4482
|
{
|
|
4473
4483
|
letters: "x",
|
|
@@ -4475,9 +4485,9 @@ function we(n) {
|
|
|
4475
4485
|
fraction: !0,
|
|
4476
4486
|
zero: !1
|
|
4477
4487
|
},
|
|
4478
|
-
|
|
4488
|
+
r
|
|
4479
4489
|
), t = new p();
|
|
4480
|
-
if (t.coefficient =
|
|
4490
|
+
if (t.coefficient = G({
|
|
4481
4491
|
zero: e.zero,
|
|
4482
4492
|
reduced: !0,
|
|
4483
4493
|
natural: !e.fraction
|
|
@@ -4485,14 +4495,14 @@ function we(n) {
|
|
|
4485
4495
|
for (const i of e.letters.split(""))
|
|
4486
4496
|
t.setLetter(i, 0);
|
|
4487
4497
|
for (let i = 0; i < e.degree; i++) {
|
|
4488
|
-
const s =
|
|
4498
|
+
const s = _(e.letters.split(""));
|
|
4489
4499
|
t.setLetter(s, t.degree(s).clone().add(1));
|
|
4490
4500
|
}
|
|
4491
4501
|
} else
|
|
4492
4502
|
t.setLetter(e.letters, e.degree);
|
|
4493
4503
|
return t;
|
|
4494
4504
|
}
|
|
4495
|
-
const
|
|
4505
|
+
const Me = {
|
|
4496
4506
|
letters: "x",
|
|
4497
4507
|
degree: 2,
|
|
4498
4508
|
fraction: !1,
|
|
@@ -4503,14 +4513,14 @@ const Fe = {
|
|
|
4503
4513
|
numberOfMonoms: 0,
|
|
4504
4514
|
positive: !0
|
|
4505
4515
|
};
|
|
4506
|
-
function
|
|
4516
|
+
function ae(r) {
|
|
4507
4517
|
const e = Object.assign(
|
|
4508
|
-
|
|
4509
|
-
|
|
4518
|
+
Me,
|
|
4519
|
+
r
|
|
4510
4520
|
), t = new u().empty();
|
|
4511
4521
|
let i;
|
|
4512
4522
|
for (let s = e.degree; s >= 0; s--)
|
|
4513
|
-
i =
|
|
4523
|
+
i = he({
|
|
4514
4524
|
letters: e.letters,
|
|
4515
4525
|
degree: s,
|
|
4516
4526
|
fraction: e.fraction,
|
|
@@ -4518,12 +4528,12 @@ function ye(n) {
|
|
|
4518
4528
|
}), e.unit && e.degree === s && i.coefficient.one(), t.add(i);
|
|
4519
4529
|
if (e.positive && t.monomByDegree().coefficient.isNegative() && t.monomByDegree().coefficient.opposite(), e.numberOfMonoms && e.numberOfMonoms > 0 && e.numberOfMonoms < t.length)
|
|
4520
4530
|
for (; t.length > e.numberOfMonoms; ) {
|
|
4521
|
-
const s =
|
|
4531
|
+
const s = k(1, t.length - 1);
|
|
4522
4532
|
t.monoms.splice(s, 1);
|
|
4523
4533
|
}
|
|
4524
4534
|
return t.reduce();
|
|
4525
4535
|
}
|
|
4526
|
-
function
|
|
4536
|
+
function Se(r) {
|
|
4527
4537
|
const e = Object.assign(
|
|
4528
4538
|
{
|
|
4529
4539
|
letters: "x",
|
|
@@ -4542,10 +4552,10 @@ function Ge(n) {
|
|
|
4542
4552
|
everything: !1
|
|
4543
4553
|
}
|
|
4544
4554
|
},
|
|
4545
|
-
|
|
4555
|
+
r
|
|
4546
4556
|
), t = new u().one();
|
|
4547
4557
|
for (let i = 0; i < e.degree; i++) {
|
|
4548
|
-
const s =
|
|
4558
|
+
const s = ae({
|
|
4549
4559
|
degree: 1,
|
|
4550
4560
|
unit: e.unit,
|
|
4551
4561
|
fraction: e.fraction,
|
|
@@ -4556,7 +4566,7 @@ function Ge(n) {
|
|
|
4556
4566
|
}
|
|
4557
4567
|
return new y(t, 0);
|
|
4558
4568
|
}
|
|
4559
|
-
function
|
|
4569
|
+
function H(r) {
|
|
4560
4570
|
const e = Object.assign(
|
|
4561
4571
|
{
|
|
4562
4572
|
axis: !0,
|
|
@@ -4564,11 +4574,11 @@ function re(n) {
|
|
|
4564
4574
|
max: 10,
|
|
4565
4575
|
quadrant: null
|
|
4566
4576
|
},
|
|
4567
|
-
|
|
4568
|
-
), t = e.axis === "x", i = e.axis === "y", s = e.fraction ?
|
|
4569
|
-
return Number(e.quadrant) === 1 && (s.abs(),
|
|
4577
|
+
r
|
|
4578
|
+
), t = e.axis === "x", i = e.axis === "y", s = e.fraction ? G({ max: e.max, zero: t }) : new a(q(e.max, t)), n = e.fraction ? G({ max: e.max, zero: i }) : new a(q(e.max, i));
|
|
4579
|
+
return Number(e.quadrant) === 1 && (s.abs(), n.abs()), Number(e.quadrant) === 2 && (s.isPositive() && s.opposite(), n.isNegative() && n.opposite()), Number(e.quadrant) === 3 && (s.isPositive() && s.opposite(), n.isPositive() && n.opposite()), Number(e.quadrant) === 4 && (s.isNegative() && s.opposite(), n.isPositive() && n.opposite()), new v(s, n);
|
|
4570
4580
|
}
|
|
4571
|
-
function
|
|
4581
|
+
function Ie(r) {
|
|
4572
4582
|
const e = Object.assign(
|
|
4573
4583
|
{
|
|
4574
4584
|
center: {
|
|
@@ -4577,12 +4587,12 @@ function We(n) {
|
|
|
4577
4587
|
},
|
|
4578
4588
|
pointsOnCircle: 8
|
|
4579
4589
|
},
|
|
4580
|
-
|
|
4581
|
-
), t =
|
|
4590
|
+
r
|
|
4591
|
+
), t = H(e.center);
|
|
4582
4592
|
let i, s;
|
|
4583
|
-
return e.pointsOnCircle === 8 ? (i =
|
|
4593
|
+
return e.pointsOnCircle === 8 ? (i = k(1, 3), s = i ** 2 + (i + 1) ** 2) : s = k(1, 20), new V(t, s, !0);
|
|
4584
4594
|
}
|
|
4585
|
-
function
|
|
4595
|
+
function ze(r) {
|
|
4586
4596
|
const e = Object.assign(
|
|
4587
4597
|
{
|
|
4588
4598
|
A: {
|
|
@@ -4590,7 +4600,7 @@ function Xe(n) {
|
|
|
4590
4600
|
y: q(10)
|
|
4591
4601
|
}
|
|
4592
4602
|
},
|
|
4593
|
-
|
|
4603
|
+
r
|
|
4594
4604
|
), t = new g(
|
|
4595
4605
|
q(10),
|
|
4596
4606
|
q(10)
|
|
@@ -4599,7 +4609,7 @@ function Xe(n) {
|
|
|
4599
4609
|
t.x = q(10), t.y = q(10);
|
|
4600
4610
|
return e.slope === 1 ? t.x.sign() !== t.y.sign() && t.y.opposite() : e.slope === -1 && t.x.sign() !== t.y.sign() && t.y.opposite(), new b().fromPointAndDirection(new g(e.A.x, e.A.y), t);
|
|
4601
4611
|
}
|
|
4602
|
-
function
|
|
4612
|
+
function Re(r) {
|
|
4603
4613
|
const e = Object.assign(
|
|
4604
4614
|
{
|
|
4605
4615
|
A: {
|
|
@@ -4613,85 +4623,85 @@ function Ye(n) {
|
|
|
4613
4623
|
z: q(10)
|
|
4614
4624
|
}
|
|
4615
4625
|
},
|
|
4616
|
-
|
|
4626
|
+
r
|
|
4617
4627
|
), t = new v(e.A.x, e.A.y, e.A.z), i = new g(e.direction.x, e.direction.y, e.direction.z);
|
|
4618
|
-
return new
|
|
4628
|
+
return new Y(t, i);
|
|
4619
4629
|
}
|
|
4620
|
-
const
|
|
4621
|
-
equation: (
|
|
4622
|
-
polynom: (
|
|
4623
|
-
monom: (
|
|
4624
|
-
fraction: (
|
|
4625
|
-
number: (
|
|
4626
|
-
numberSym: (
|
|
4627
|
-
prime: (
|
|
4628
|
-
bool: (
|
|
4629
|
-
array: (
|
|
4630
|
-
item: (
|
|
4631
|
-
shuffle: (
|
|
4632
|
-
line: (
|
|
4633
|
-
line3: (
|
|
4634
|
-
vector: (
|
|
4635
|
-
point: (
|
|
4636
|
-
const e =
|
|
4630
|
+
const Pe = {
|
|
4631
|
+
equation: (r) => Se(r),
|
|
4632
|
+
polynom: (r) => ae(r),
|
|
4633
|
+
monom: (r) => he(r),
|
|
4634
|
+
fraction: (r) => G(r),
|
|
4635
|
+
number: (r, e, t) => k(r, e, t),
|
|
4636
|
+
numberSym: (r, e) => q(r, e),
|
|
4637
|
+
prime: (r) => $e(r),
|
|
4638
|
+
bool: (r) => ne(r),
|
|
4639
|
+
array: (r, e) => ke(r, e),
|
|
4640
|
+
item: (r) => _(r),
|
|
4641
|
+
shuffle: (r) => re(r),
|
|
4642
|
+
line: (r) => ze(r),
|
|
4643
|
+
line3: (r) => Re(r),
|
|
4644
|
+
vector: (r) => H(r),
|
|
4645
|
+
point: (r) => {
|
|
4646
|
+
const e = H(r);
|
|
4637
4647
|
return e.asPoint = !0, e;
|
|
4638
4648
|
},
|
|
4639
|
-
circle: (
|
|
4640
|
-
},
|
|
4649
|
+
circle: (r) => Ie(r)
|
|
4650
|
+
}, Le = {
|
|
4641
4651
|
Numeric: E,
|
|
4642
4652
|
Fraction: a,
|
|
4643
|
-
Root:
|
|
4653
|
+
Root: j,
|
|
4644
4654
|
Monom: p,
|
|
4645
4655
|
Polynom: u,
|
|
4646
4656
|
Equation: y,
|
|
4647
|
-
Matrix:
|
|
4648
|
-
LinearSystem:
|
|
4657
|
+
Matrix: I,
|
|
4658
|
+
LinearSystem: D,
|
|
4649
4659
|
Factor: x,
|
|
4650
4660
|
PolyFactor: T,
|
|
4651
|
-
LogicalSet:
|
|
4652
|
-
Random:
|
|
4661
|
+
LogicalSet: qe,
|
|
4662
|
+
Random: Pe,
|
|
4653
4663
|
Geometry: {
|
|
4654
4664
|
Vector: g,
|
|
4655
4665
|
Point: v,
|
|
4656
4666
|
Line: b,
|
|
4657
|
-
Triangle:
|
|
4658
|
-
Circle:
|
|
4659
|
-
Line3:
|
|
4660
|
-
Plane3:
|
|
4661
|
-
Sphere3:
|
|
4667
|
+
Triangle: F,
|
|
4668
|
+
Circle: V,
|
|
4669
|
+
Line3: Y,
|
|
4670
|
+
Plane3: ee,
|
|
4671
|
+
Sphere3: Be
|
|
4662
4672
|
},
|
|
4663
|
-
NumExp:
|
|
4673
|
+
NumExp: Ae
|
|
4664
4674
|
};
|
|
4665
4675
|
export {
|
|
4666
|
-
|
|
4676
|
+
V as Circle,
|
|
4667
4677
|
y as Equation,
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4678
|
+
W as EquationSolver,
|
|
4679
|
+
Z as FACTOR_DISPLAY,
|
|
4680
|
+
we as FRAC_TYPE,
|
|
4671
4681
|
x as Factor,
|
|
4672
4682
|
a as Fraction,
|
|
4673
4683
|
b as Line,
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4684
|
+
Y as Line3,
|
|
4685
|
+
D as LinearSystem,
|
|
4686
|
+
qe as LogicalSet,
|
|
4687
|
+
I as Matrix,
|
|
4678
4688
|
p as Monom,
|
|
4679
|
-
|
|
4680
|
-
|
|
4689
|
+
j as NthRoot,
|
|
4690
|
+
Ae as NumExp,
|
|
4681
4691
|
E as Numeric,
|
|
4682
|
-
|
|
4692
|
+
ee as Plane3,
|
|
4683
4693
|
v as Point,
|
|
4684
4694
|
T as PolyFactor,
|
|
4685
4695
|
u as Polynom,
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4696
|
+
Pe as Random,
|
|
4697
|
+
oe as SPHERE3_RELATIVE_POSITION,
|
|
4698
|
+
Be as Sphere3,
|
|
4699
|
+
F as Triangle,
|
|
4690
4700
|
g as Vector,
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
|
|
4695
|
-
|
|
4701
|
+
Oe as areVectorsColinears,
|
|
4702
|
+
Te as areVectorsEquals,
|
|
4703
|
+
Le as default,
|
|
4704
|
+
De as determinantFromVectors,
|
|
4705
|
+
Ce as dotProduct
|
|
4696
4706
|
};
|
|
4697
4707
|
//# sourceMappingURL=pimath.js.map
|