pimath 0.1.23 → 0.1.25
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/README.md +4 -7
- package/dist/algebra/factor.d.ts +4 -3
- package/dist/algebra/monom.d.ts +0 -1
- package/dist/algebra/polyFactor.d.ts +14 -7
- package/dist/algebra/polynom.d.ts +6 -4
- package/dist/geometry/triangle.d.ts +0 -1
- package/dist/pimath.interface.d.ts +2 -5
- package/dist/pimath.js +1226 -1105
- package/dist/pimath.js.map +1 -1
- package/package.json +1 -1
package/dist/pimath.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var Li = Object.defineProperty;
|
|
2
|
+
var gi = (o) => {
|
|
3
3
|
throw TypeError(o);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var a = (o, e, t) =>
|
|
7
|
-
var s = (o, e, t) => (
|
|
8
|
-
function
|
|
9
|
-
const e =
|
|
5
|
+
var Vi = (o, e, t) => e in o ? Li(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
6
|
+
var a = (o, e, t) => Vi(o, typeof e != "symbol" ? e + "" : e, t), _t = (o, e, t) => e.has(o) || gi("Cannot " + t);
|
|
7
|
+
var s = (o, e, t) => (_t(o, e, "read from private field"), t ? t.call(o) : e.get(o)), m = (o, e, t) => e.has(o) ? gi("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(o) : e.set(o, t), h = (o, e, t, i) => (_t(o, e, "write to private field"), i ? i.call(o, t) : e.set(o, t), t), A = (o, e, t) => (_t(o, e, "access private method"), t);
|
|
8
|
+
function Di(o) {
|
|
9
|
+
const e = wi(o), t = [];
|
|
10
10
|
let i, n;
|
|
11
11
|
for (; e.length > 0; )
|
|
12
12
|
i = e.shift() ?? 1, n = (e.length > 0 ? e.pop() : +i) ?? 1, t.push([i, n]);
|
|
13
13
|
return t;
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
const e =
|
|
15
|
+
function Zi(...o) {
|
|
16
|
+
const e = ui(...o);
|
|
17
17
|
return o.map((t) => t / e);
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function wi(o) {
|
|
20
20
|
const e = Math.abs(o), t = Math.sqrt(e), i = [];
|
|
21
21
|
for (let n = 1; n <= t; n++)
|
|
22
22
|
o % n === 0 && (i.push(n), i.push(e / n));
|
|
@@ -24,7 +24,7 @@ function vi(o) {
|
|
|
24
24
|
return n - r;
|
|
25
25
|
}), [...new Set(i)];
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function ui(...o) {
|
|
28
28
|
const e = function(n, r) {
|
|
29
29
|
return r === 0 ? n : e(r, n % r);
|
|
30
30
|
};
|
|
@@ -39,52 +39,52 @@ function fi(...o) {
|
|
|
39
39
|
;
|
|
40
40
|
return Math.abs(t);
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function Fi(...o) {
|
|
43
43
|
return o.reduce(function(e, t) {
|
|
44
|
-
return Math.abs(e * t /
|
|
44
|
+
return Math.abs(e * t / ui(e, t));
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
|
-
function
|
|
47
|
+
function ji(o, e = 3) {
|
|
48
48
|
return +o.toFixed(e);
|
|
49
49
|
}
|
|
50
|
-
function
|
|
50
|
+
function Ui(o) {
|
|
51
51
|
if (Number.isSafeInteger(o) || o.toString().split(".")[0].length < 10)
|
|
52
52
|
return 0;
|
|
53
53
|
throw new Error("Periodic value: Not implemented yet");
|
|
54
54
|
}
|
|
55
|
-
function
|
|
55
|
+
function Wi(o) {
|
|
56
56
|
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];
|
|
57
57
|
return o === void 0 ? e : e.slice(0, Math.min(e.length, o));
|
|
58
58
|
}
|
|
59
|
-
function
|
|
59
|
+
function Gi(o, e) {
|
|
60
60
|
const t = [], i = e === !0 ? +o : o ** 2;
|
|
61
61
|
for (let n = 0; n <= o; n++)
|
|
62
62
|
for (let r = 0; r <= o; r++)
|
|
63
63
|
n ** 2 + r ** 2 === i && t.push([n, r, o]);
|
|
64
64
|
return t;
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function Hi(o, e = 2) {
|
|
67
67
|
return +`${Math.round(+`${o}e${e}`)}e-${e}`;
|
|
68
68
|
}
|
|
69
|
-
const
|
|
70
|
-
decompose:
|
|
71
|
-
dividers:
|
|
72
|
-
divideNumbersByGCD:
|
|
73
|
-
gcd:
|
|
74
|
-
lcm:
|
|
75
|
-
numberCorrection:
|
|
76
|
-
periodic:
|
|
77
|
-
primes:
|
|
78
|
-
pythagoreanTripletsWithTarget:
|
|
79
|
-
round:
|
|
69
|
+
const U = {
|
|
70
|
+
decompose: Di,
|
|
71
|
+
dividers: wi,
|
|
72
|
+
divideNumbersByGCD: Zi,
|
|
73
|
+
gcd: ui,
|
|
74
|
+
lcm: Fi,
|
|
75
|
+
numberCorrection: ji,
|
|
76
|
+
periodic: Ui,
|
|
77
|
+
primes: Wi,
|
|
78
|
+
pythagoreanTripletsWithTarget: Gi,
|
|
79
|
+
round: Hi
|
|
80
80
|
};
|
|
81
|
-
var
|
|
82
|
-
const
|
|
81
|
+
var ut, x, v, Re;
|
|
82
|
+
const P = class P {
|
|
83
83
|
constructor(e, t) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
m(this, ut, !1);
|
|
85
|
+
m(this, x, 1);
|
|
86
|
+
m(this, v, 1);
|
|
87
|
+
m(this, Re, "frac");
|
|
88
88
|
// ------------------------------------------
|
|
89
89
|
/**
|
|
90
90
|
* Parse the value to get the numerator and denominator
|
|
@@ -94,7 +94,7 @@ const $ = class $ {
|
|
|
94
94
|
a(this, "parse", (e, t) => {
|
|
95
95
|
let i;
|
|
96
96
|
if (e === "")
|
|
97
|
-
return h(this,
|
|
97
|
+
return h(this, v, 0), h(this, x, 1), this;
|
|
98
98
|
switch (typeof e) {
|
|
99
99
|
case "string":
|
|
100
100
|
if (i = e.split("/"), i.length > 2)
|
|
@@ -103,37 +103,36 @@ const $ = class $ {
|
|
|
103
103
|
throw new Error(`The given value is not a valid fraction (${e})`);
|
|
104
104
|
if (i.length === 1)
|
|
105
105
|
return this.parse(+i[0]);
|
|
106
|
-
i.length === 2 ? i[1] === "0" ? (h(this,
|
|
106
|
+
i.length === 2 ? i[1] === "0" ? (h(this, v, NaN), h(this, x, 1)) : (h(this, v, +i[0]), h(this, x, +i[1])) : (h(this, v, NaN), h(this, x, 1));
|
|
107
107
|
break;
|
|
108
108
|
case "number":
|
|
109
109
|
if (Number.isSafeInteger(e))
|
|
110
|
-
h(this,
|
|
110
|
+
h(this, v, +e), t === void 0 || !Number.isSafeInteger(t) ? h(this, x, 1) : h(this, x, +t);
|
|
111
111
|
else {
|
|
112
112
|
const [, n] = e.toString().split("."), r = n ? n.length : 0;
|
|
113
|
-
t === void 0 ? (h(this,
|
|
113
|
+
t === void 0 ? (h(this, v, e * Math.pow(10, r)), h(this, x, Math.pow(10, r))) : Number.isSafeInteger(t) && (h(this, v, e * Math.pow(10, r) - Math.floor(e * Math.pow(10, r - t))), this.denominator = Math.pow(10, r) - Math.pow(10, r - t)), this.reduce();
|
|
114
114
|
}
|
|
115
115
|
break;
|
|
116
116
|
case "object":
|
|
117
|
-
e instanceof
|
|
117
|
+
e instanceof P && (h(this, v, +e.numerator), h(this, x, +e.denominator));
|
|
118
118
|
break;
|
|
119
119
|
}
|
|
120
120
|
return this;
|
|
121
121
|
});
|
|
122
122
|
a(this, "clone", () => {
|
|
123
|
-
const e = new
|
|
124
|
-
return e.numerator = +s(this,
|
|
123
|
+
const e = new P();
|
|
124
|
+
return e.numerator = +s(this, v), e.denominator = +s(this, x), e;
|
|
125
125
|
});
|
|
126
|
-
a(this, "abs", () => (h(this,
|
|
126
|
+
a(this, "abs", () => (h(this, v, Math.abs(s(this, v))), h(this, x, Math.abs(s(this, x))), this));
|
|
127
127
|
a(this, "add", (e) => {
|
|
128
|
-
if (e instanceof
|
|
129
|
-
const t = s(this,
|
|
130
|
-
h(this,
|
|
128
|
+
if (e instanceof P) {
|
|
129
|
+
const t = s(this, v), i = s(this, x);
|
|
130
|
+
h(this, v, t * e.denominator + e.numerator * i), h(this, x, i * e.denominator);
|
|
131
131
|
} else
|
|
132
|
-
return this.add(new
|
|
132
|
+
return this.add(new P(e));
|
|
133
133
|
return this.reduce();
|
|
134
134
|
});
|
|
135
|
-
a(this, "amplify", (e) => (Number.isSafeInteger(e) && (h(this,
|
|
136
|
-
// TODO: The rest of the functions are not used or unnecessary ?
|
|
135
|
+
a(this, "amplify", (e) => (Number.isSafeInteger(e) && (h(this, v, s(this, v) * e), h(this, x, s(this, x) * e)), this));
|
|
137
136
|
/**
|
|
138
137
|
* Simple function to determine if it's a fraction
|
|
139
138
|
*/
|
|
@@ -147,7 +146,7 @@ const $ = class $ {
|
|
|
147
146
|
a(this, "compare", (e, t) => {
|
|
148
147
|
t === void 0 && (t = "=");
|
|
149
148
|
let i;
|
|
150
|
-
switch (e instanceof
|
|
149
|
+
switch (e instanceof P ? i = e.clone() : i = new P(e), t) {
|
|
151
150
|
case ">":
|
|
152
151
|
return this.value > i.value;
|
|
153
152
|
case ">=":
|
|
@@ -169,66 +168,66 @@ const $ = class $ {
|
|
|
169
168
|
}
|
|
170
169
|
});
|
|
171
170
|
a(this, "divide", (e) => {
|
|
172
|
-
const t = new
|
|
171
|
+
const t = new P(e);
|
|
173
172
|
if (t.numerator === 0)
|
|
174
|
-
return new
|
|
175
|
-
const i = +s(this,
|
|
176
|
-
return h(this,
|
|
173
|
+
return new P().infinite();
|
|
174
|
+
const i = +s(this, v), n = +s(this, x);
|
|
175
|
+
return h(this, v, i * t.denominator), h(this, x, n * t.numerator), this.reduce();
|
|
177
176
|
});
|
|
178
|
-
a(this, "infinite", () => (h(this,
|
|
179
|
-
a(this, "invalid", () => (h(this,
|
|
177
|
+
a(this, "infinite", () => (h(this, v, 1 / 0), h(this, x, 1), this));
|
|
178
|
+
a(this, "invalid", () => (h(this, v, NaN), h(this, x, 1), this));
|
|
180
179
|
a(this, "inverse", () => {
|
|
181
|
-
const e = +s(this,
|
|
182
|
-
return h(this,
|
|
180
|
+
const e = +s(this, v);
|
|
181
|
+
return h(this, v, +s(this, x)), h(this, x, e), this;
|
|
183
182
|
});
|
|
184
|
-
a(this, "isApproximative", () => s(this,
|
|
183
|
+
a(this, "isApproximative", () => s(this, ut) || s(this, v).toString().length >= 15 && s(this, x).toString().length >= 15);
|
|
185
184
|
a(this, "isEqual", (e) => this.compare(e, "="));
|
|
186
185
|
a(this, "isEven", () => this.isRelative() && this.value % 2 === 0);
|
|
187
186
|
a(this, "isExact", () => !this.isApproximative());
|
|
188
187
|
a(this, "isFinite", () => !this.isInfinity() && !this.isNaN());
|
|
189
188
|
a(this, "isGeq", (e) => this.compare(e, ">="));
|
|
190
189
|
a(this, "isGreater", (e) => this.compare(e, ">"));
|
|
191
|
-
a(this, "isInfinity", () => Math.abs(s(this,
|
|
192
|
-
a(this, "isInverted", (e) => this.isEqual(new
|
|
190
|
+
a(this, "isInfinity", () => Math.abs(s(this, v)) === 1 / 0);
|
|
191
|
+
a(this, "isInverted", (e) => this.isEqual(new P().one().divide(e.clone())));
|
|
193
192
|
a(this, "isLeq", (e) => this.compare(e, "<="));
|
|
194
193
|
/* Compare shortcuts */
|
|
195
194
|
a(this, "isLesser", (e) => this.compare(e, "<"));
|
|
196
|
-
a(this, "isNaN", () => isNaN(s(this,
|
|
195
|
+
a(this, "isNaN", () => isNaN(s(this, v)));
|
|
197
196
|
a(this, "isNatural", () => this.isRelative() && this.isPositive());
|
|
198
197
|
a(this, "isNegative", () => this.sign() === -1);
|
|
199
|
-
a(this, "isNegativeOne", () => s(this,
|
|
198
|
+
a(this, "isNegativeOne", () => s(this, v) === -1 && s(this, x) === 1);
|
|
200
199
|
a(this, "isNotEqual", (e) => this.compare(e, "<>"));
|
|
201
200
|
// ------------------------------------------
|
|
202
|
-
a(this, "isNotZero", () => s(this,
|
|
201
|
+
a(this, "isNotZero", () => s(this, v) !== 0);
|
|
203
202
|
a(this, "isOdd", () => this.isRelative() && this.value % 2 === 1);
|
|
204
|
-
a(this, "isOne", () => s(this,
|
|
203
|
+
a(this, "isOne", () => s(this, v) === 1 && s(this, x) === 1);
|
|
205
204
|
a(this, "isOpposite", (e) => this.isEqual(e.clone().opposite()));
|
|
206
205
|
a(this, "isPositive", () => this.sign() === 1);
|
|
207
206
|
a(this, "isRational", () => !this.isRelative());
|
|
208
|
-
a(this, "isReduced", () => Math.abs(
|
|
207
|
+
a(this, "isReduced", () => Math.abs(U.gcd(s(this, v), s(this, x))) === 1);
|
|
209
208
|
a(this, "isRelative", () => this.clone().reduce().denominator === 1);
|
|
210
|
-
a(this, "isSquare", () => Math.sqrt(s(this,
|
|
209
|
+
a(this, "isSquare", () => Math.sqrt(s(this, v)) % 1 === 0 && Math.sqrt(s(this, x)) % 1 === 0);
|
|
211
210
|
a(this, "isStrictlyNegative", () => this.value < 0);
|
|
212
211
|
a(this, "isStrictlyPositive", () => this.value > 0);
|
|
213
212
|
// Mathematical operations specific to fractions
|
|
214
|
-
a(this, "isZero", () => s(this,
|
|
213
|
+
a(this, "isZero", () => s(this, v) === 0);
|
|
215
214
|
a(this, "multiply", (e) => {
|
|
216
|
-
const t = new
|
|
217
|
-
return h(this,
|
|
215
|
+
const t = new P(e);
|
|
216
|
+
return h(this, v, s(this, v) * t.numerator), h(this, x, s(this, x) * t.denominator), this.reduce();
|
|
218
217
|
});
|
|
219
|
-
a(this, "one", () => (h(this,
|
|
220
|
-
a(this, "opposite", () => (h(this,
|
|
218
|
+
a(this, "one", () => (h(this, v, 1), h(this, x, 1), this));
|
|
219
|
+
a(this, "opposite", () => (h(this, v, -s(this, v)), this));
|
|
221
220
|
a(this, "pow", (e) => {
|
|
222
|
-
if (e instanceof
|
|
221
|
+
if (e instanceof P)
|
|
223
222
|
return this.pow(e.value);
|
|
224
223
|
this.reduce(), e < 0 && this.inverse();
|
|
225
|
-
const t = Math.floor(Math.pow(s(this,
|
|
226
|
-
return t ** Math.abs(e) === s(this,
|
|
224
|
+
const t = Math.floor(Math.pow(s(this, v), Math.abs(e))), i = Math.floor(Math.pow(s(this, x), Math.abs(e)));
|
|
225
|
+
return t ** Math.abs(e) === s(this, v) && i ** Math.abs(e) === s(this, x) ? (h(this, v, s(this, v) ** Math.abs(e)), h(this, x, s(this, x) ** Math.abs(e))) : (h(this, v, s(this, v) ** Math.abs(e)), h(this, x, s(this, x) ** Math.abs(e))), this;
|
|
227
226
|
});
|
|
228
227
|
// ------------------------------------------
|
|
229
228
|
a(this, "reduce", () => {
|
|
230
|
-
const e =
|
|
231
|
-
return h(this,
|
|
229
|
+
const e = U.gcd(s(this, v), s(this, x));
|
|
230
|
+
return h(this, v, s(this, v) / e), h(this, x, s(this, x) / e), s(this, x) < 0 && (h(this, x, -s(this, x)), h(this, v, -s(this, v))), this;
|
|
232
231
|
});
|
|
233
232
|
a(this, "root", (e) => {
|
|
234
233
|
if (e === 0)
|
|
@@ -239,111 +238,111 @@ const $ = class $ {
|
|
|
239
238
|
throw new Error("The root of a negative number must be odd.");
|
|
240
239
|
const t = this.sign();
|
|
241
240
|
this.abs(), this.reduce();
|
|
242
|
-
const i = Math.floor(Math.pow(s(this,
|
|
243
|
-
return h(this,
|
|
241
|
+
const i = Math.floor(Math.pow(s(this, v), Math.abs(1 / e))), n = Math.floor(Math.pow(s(this, x), Math.abs(1 / e)));
|
|
242
|
+
return h(this, v, Math.pow(s(this, v), Math.abs(1 / e))), h(this, x, Math.pow(s(this, x), Math.abs(1 / e))), (i !== s(this, v) || n !== s(this, x)) && (h(this, v, s(this, v) / s(this, x)), h(this, x, 1), h(this, ut, !0)), this.multiply(t), this;
|
|
244
243
|
});
|
|
245
244
|
// ------------------------------------------
|
|
246
245
|
// Getter and setter
|
|
247
|
-
a(this, "sign", () => s(this,
|
|
246
|
+
a(this, "sign", () => s(this, v) * s(this, x) >= 0 ? 1 : -1);
|
|
248
247
|
a(this, "sqrt", () => this.root(2));
|
|
249
|
-
a(this, "subtract", (e) => e instanceof
|
|
250
|
-
a(this, "zero", () => (h(this,
|
|
248
|
+
a(this, "subtract", (e) => e instanceof P ? this.add(e.clone().opposite()) : this.add(-e));
|
|
249
|
+
a(this, "zero", () => (h(this, v, 0), h(this, x, 1), this));
|
|
251
250
|
return e !== void 0 && this.parse(e, t), this;
|
|
252
251
|
}
|
|
253
252
|
get denominator() {
|
|
254
|
-
return s(this,
|
|
253
|
+
return s(this, x);
|
|
255
254
|
}
|
|
256
255
|
set denominator(e) {
|
|
257
|
-
h(this,
|
|
256
|
+
h(this, x, e);
|
|
258
257
|
}
|
|
259
258
|
get dfrac() {
|
|
260
|
-
return h(this,
|
|
259
|
+
return h(this, Re, "dfrac"), this;
|
|
261
260
|
}
|
|
262
261
|
get display() {
|
|
263
|
-
return this.isExact() ? s(this,
|
|
262
|
+
return this.isExact() ? s(this, x) === 1 ? `${s(this, v)}` : `${s(this, v)}/${s(this, x)}` : this.value.toFixed(3);
|
|
264
263
|
}
|
|
265
264
|
get frac() {
|
|
266
|
-
return h(this,
|
|
265
|
+
return h(this, Re, "frac"), this;
|
|
267
266
|
}
|
|
268
267
|
// ------------------------------------------
|
|
269
268
|
get numerator() {
|
|
270
|
-
return s(this,
|
|
269
|
+
return s(this, v);
|
|
271
270
|
}
|
|
272
271
|
set numerator(e) {
|
|
273
|
-
h(this,
|
|
272
|
+
h(this, v, e);
|
|
274
273
|
}
|
|
275
274
|
// Display getter
|
|
276
275
|
get tex() {
|
|
277
|
-
return this.isInfinity() ? `${this.sign() === 1 ? "+" : "-"}\\infty` : this.isExact() ? s(this,
|
|
276
|
+
return this.isInfinity() ? `${this.sign() === 1 ? "+" : "-"}\\infty` : this.isExact() ? s(this, x) === 1 ? `${s(this, v)}` : s(this, v) < 0 ? `-\\${s(this, Re)}{ ${-s(this, v)} }{ ${s(this, x)} }` : `\\${s(this, Re)}{ ${s(this, v)} }{ ${s(this, x)} }` : this.value.toFixed(3);
|
|
278
277
|
}
|
|
279
278
|
get texWithSign() {
|
|
280
279
|
return this.isPositive() ? `+${this.tex}` : this.tex;
|
|
281
280
|
}
|
|
282
281
|
get tfrac() {
|
|
283
|
-
return h(this,
|
|
282
|
+
return h(this, Re, "tfrac"), this;
|
|
284
283
|
}
|
|
285
284
|
get value() {
|
|
286
|
-
const e = s(this,
|
|
285
|
+
const e = s(this, v) / s(this, x);
|
|
287
286
|
return e === 0 ? 0 : e;
|
|
288
287
|
}
|
|
289
288
|
};
|
|
290
|
-
|
|
291
|
-
const t = new
|
|
289
|
+
ut = new WeakMap(), x = new WeakMap(), v = new WeakMap(), Re = new WeakMap(), a(P, "average", (...e) => {
|
|
290
|
+
const t = new P().zero();
|
|
292
291
|
for (const i of e)
|
|
293
292
|
t.add(i);
|
|
294
293
|
return t.divide(e.length), t;
|
|
295
|
-
}), a(
|
|
296
|
-
let t = new
|
|
294
|
+
}), a(P, "max", (...e) => {
|
|
295
|
+
let t = new P(e[0]);
|
|
297
296
|
for (const i of e) {
|
|
298
|
-
const n = new
|
|
297
|
+
const n = new P(i);
|
|
299
298
|
n.isGreater(t) && (t = n.clone());
|
|
300
299
|
}
|
|
301
300
|
return t;
|
|
302
|
-
}), a(
|
|
303
|
-
let t = new
|
|
301
|
+
}), a(P, "min", (...e) => {
|
|
302
|
+
let t = new P(e[0]);
|
|
304
303
|
for (const i of e) {
|
|
305
|
-
const n = new
|
|
304
|
+
const n = new P(i);
|
|
306
305
|
n.isLesser(t) && (t = n.clone());
|
|
307
306
|
}
|
|
308
307
|
return t;
|
|
309
|
-
}), a(
|
|
310
|
-
const n = e.map((r) => r instanceof
|
|
308
|
+
}), a(P, "sort", (e, t) => {
|
|
309
|
+
const n = e.map((r) => r instanceof P ? r : new P(r)).sort((r, l) => r.value - l.value);
|
|
311
310
|
return t && n.reverse(), n;
|
|
312
311
|
}), // ------------------------------------------
|
|
313
312
|
// Compare functions
|
|
314
|
-
a(
|
|
313
|
+
a(P, "unique", (e) => {
|
|
315
314
|
const t = {}, i = [];
|
|
316
315
|
return e.forEach((n) => {
|
|
317
|
-
n instanceof
|
|
316
|
+
n instanceof P || (n = new P(n)), t[n.clone().reduce().tex] || (i.push(n.clone()), t[n.tex] = !0);
|
|
318
317
|
}), i;
|
|
319
|
-
}), a(
|
|
320
|
-
const t = new
|
|
318
|
+
}), a(P, "xMultiply", (...e) => {
|
|
319
|
+
const t = new P();
|
|
321
320
|
for (const i of e) {
|
|
322
|
-
const n = new
|
|
321
|
+
const n = new P(i);
|
|
323
322
|
t.numerator = t.numerator * n.numerator, t.denominator = t.denominator * n.denominator;
|
|
324
323
|
}
|
|
325
324
|
return t;
|
|
326
325
|
});
|
|
327
|
-
let u =
|
|
328
|
-
var Z,
|
|
326
|
+
let u = P;
|
|
327
|
+
var Z, ie, ne, Ye;
|
|
329
328
|
class vt {
|
|
330
329
|
constructor(...e) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
330
|
+
m(this, Z);
|
|
331
|
+
m(this, ie);
|
|
332
|
+
m(this, ne);
|
|
333
|
+
m(this, Ye);
|
|
335
334
|
// ------------------------------------------
|
|
336
335
|
// Creation / parsing functions
|
|
337
336
|
// ------------------------------------------
|
|
338
|
-
a(this, "parse", (e, t, i) => (h(this,
|
|
337
|
+
a(this, "parse", (e, t, i) => (h(this, ne, i ?? 1), h(this, ie, t ?? 2), h(this, Z, e), s(this, ie) % 2 === 0 && s(this, Z) < 0 && h(this, Ye, !1), this));
|
|
339
338
|
// ------------------------------------------
|
|
340
339
|
// Mathematical operations
|
|
341
340
|
// ------------------------------------------
|
|
342
341
|
a(this, "reduce", () => {
|
|
343
|
-
let e = Math.floor(Math.pow(s(this, Z), 1 / s(this,
|
|
342
|
+
let e = Math.floor(Math.pow(s(this, Z), 1 / s(this, ie)));
|
|
344
343
|
for (; e > 1; ) {
|
|
345
|
-
if (s(this, Z) % Math.pow(e, s(this,
|
|
346
|
-
h(this,
|
|
344
|
+
if (s(this, Z) % Math.pow(e, s(this, ie)) === 0) {
|
|
345
|
+
h(this, ne, s(this, ne) * e), h(this, Z, s(this, Z) / Math.pow(e, s(this, ie))), e = Math.floor(Math.pow(s(this, Z), 1 / s(this, ie)));
|
|
347
346
|
continue;
|
|
348
347
|
}
|
|
349
348
|
e--;
|
|
@@ -354,8 +353,8 @@ class vt {
|
|
|
354
353
|
// ------------------------------------------
|
|
355
354
|
// Help functions
|
|
356
355
|
// ------------------------------------------
|
|
357
|
-
a(this, "hasRadical", () => !(s(this, Z) === 1 || s(this, Z) === 0 || !s(this,
|
|
358
|
-
h(this, Z, 1), h(this,
|
|
356
|
+
a(this, "hasRadical", () => !(s(this, Z) === 1 || s(this, Z) === 0 || !s(this, Ye)));
|
|
357
|
+
h(this, Z, 1), h(this, ne, 1), h(this, ie, 2), h(this, Ye, !0), e.length > 0 && this.parse(e[0], e[1], e[2]);
|
|
359
358
|
}
|
|
360
359
|
// ------------------------------------------
|
|
361
360
|
// Getter and setter
|
|
@@ -367,274 +366,315 @@ class vt {
|
|
|
367
366
|
h(this, Z, e);
|
|
368
367
|
}
|
|
369
368
|
get nth() {
|
|
370
|
-
return s(this,
|
|
369
|
+
return s(this, ie);
|
|
371
370
|
}
|
|
372
371
|
set nth(e) {
|
|
373
|
-
Number.isSafeInteger(e) && e >= 2 ? h(this,
|
|
372
|
+
Number.isSafeInteger(e) && e >= 2 ? h(this, ie, e) : (console.log("Error setting the nth root"), h(this, ie, 2));
|
|
374
373
|
}
|
|
375
374
|
get coefficient() {
|
|
376
|
-
return s(this,
|
|
375
|
+
return s(this, ne);
|
|
377
376
|
}
|
|
378
377
|
set coefficient(e) {
|
|
379
|
-
h(this,
|
|
378
|
+
h(this, ne, e);
|
|
380
379
|
}
|
|
381
380
|
get tex() {
|
|
382
381
|
let e;
|
|
383
|
-
return s(this,
|
|
382
|
+
return s(this, ne) === 1 ? e = "" : s(this, ne) === -1 ? e = "-" : e = s(this, ne).toString(), s(this, Z) === 1 ? `${s(this, ne)}` : s(this, ie) === 2 ? `${e}\\sqrt{${s(this, Z)}}` : `${e}\\sqrt[${s(this, ie)}]{${s(this, Z)}}`;
|
|
384
383
|
}
|
|
385
384
|
get display() {
|
|
386
385
|
let e;
|
|
387
|
-
return s(this,
|
|
386
|
+
return s(this, ne) === 1 ? e = "" : s(this, ne) === -1 ? e = "-" : e = s(this, ne).toString(), s(this, Z) === 1 ? `${s(this, ne)}` : s(this, ie) === 2 ? `${e}sqrt{${s(this, Z)}}` : `${e}root(${s(this, ie)}){${s(this, Z)}}`;
|
|
388
387
|
}
|
|
389
388
|
get value() {
|
|
390
|
-
return s(this,
|
|
389
|
+
return s(this, ne) * Math.pow(s(this, Z), 1 / s(this, ie));
|
|
391
390
|
}
|
|
392
391
|
}
|
|
393
|
-
Z = new WeakMap(),
|
|
394
|
-
var
|
|
395
|
-
const
|
|
392
|
+
Z = new WeakMap(), ie = new WeakMap(), ne = new WeakMap(), Ye = new WeakMap();
|
|
393
|
+
var K, Fe, C, Ge, ge, vi, bi, xi, Ei, Ni, Ai, Ti;
|
|
394
|
+
const pi = class pi {
|
|
396
395
|
constructor(e, t, i = "x") {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
if (h(this,
|
|
396
|
+
m(this, C);
|
|
397
|
+
m(this, K);
|
|
398
|
+
m(this, Fe);
|
|
399
|
+
if (h(this, Fe, i), Object.hasOwn(e, "moveLeft")) {
|
|
401
400
|
const n = e;
|
|
402
|
-
h(this,
|
|
401
|
+
h(this, K, n.left.clone().subtract(n.right));
|
|
403
402
|
} else
|
|
404
|
-
h(this,
|
|
403
|
+
h(this, K, e.clone().subtract(t ?? 0));
|
|
405
404
|
}
|
|
406
405
|
solve() {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
if (e
|
|
413
|
-
return
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
throw new Error("The equation degree is too high.");
|
|
406
|
+
const e = s(this, K).degree().value;
|
|
407
|
+
if (e === 0)
|
|
408
|
+
return [];
|
|
409
|
+
if (e === 1)
|
|
410
|
+
return A(this, C, Ni).call(this);
|
|
411
|
+
if (e === 2)
|
|
412
|
+
return A(this, C, Ai).call(this);
|
|
413
|
+
const t = A(this, C, xi).call(this);
|
|
414
|
+
return t.length > 0 ? t : A(this, C, vi).call(this);
|
|
417
415
|
}
|
|
418
416
|
solveAsCardan() {
|
|
419
|
-
if (s(this,
|
|
417
|
+
if (s(this, K).degree().value !== 3)
|
|
420
418
|
throw new Error("The equation is not cubic.");
|
|
421
|
-
return
|
|
419
|
+
return A(this, C, Ei).call(this);
|
|
422
420
|
}
|
|
423
421
|
};
|
|
424
|
-
|
|
422
|
+
K = new WeakMap(), Fe = new WeakMap(), C = new WeakSet(), Ge = function(e, t) {
|
|
425
423
|
return {
|
|
426
|
-
variable: s(this,
|
|
424
|
+
variable: s(this, Fe),
|
|
427
425
|
exact: !1,
|
|
428
426
|
value: +e.toFixed(10),
|
|
429
427
|
tex: (t == null ? void 0 : t.tex) ?? "",
|
|
430
428
|
display: (t == null ? void 0 : t.display) ?? ""
|
|
431
429
|
};
|
|
432
|
-
},
|
|
430
|
+
}, ge = function(e) {
|
|
433
431
|
if (e instanceof u && e.isApproximative())
|
|
434
|
-
return
|
|
432
|
+
return A(this, C, Ge).call(this, e.value);
|
|
435
433
|
const t = new u(e);
|
|
436
434
|
return {
|
|
437
|
-
variable: s(this,
|
|
435
|
+
variable: s(this, Fe),
|
|
438
436
|
exact: t,
|
|
439
437
|
value: t.value,
|
|
440
438
|
tex: t.tex,
|
|
441
439
|
display: t.display
|
|
442
440
|
};
|
|
443
|
-
},
|
|
444
|
-
|
|
441
|
+
}, vi = function() {
|
|
442
|
+
const e = [];
|
|
443
|
+
s(this, K).degree().value;
|
|
444
|
+
const t = s(this, K).getCoefficients().map((p) => p.value), [i, ...n] = s(this, K).getCoefficients(), r = 1 + Math.max(...n.map((p) => p.value / i.value)), c = 2 * r / 100, f = [];
|
|
445
|
+
for (let p = -r; p <= r; p += c) {
|
|
446
|
+
const w = U.numberCorrection(p);
|
|
447
|
+
f.push(
|
|
448
|
+
{
|
|
449
|
+
x: w,
|
|
450
|
+
fx: s(this, K).evaluate(w, !0)
|
|
451
|
+
}
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
f.sort((p, w) => p.x - w.x);
|
|
455
|
+
const d = [];
|
|
456
|
+
return f.forEach((p, w) => {
|
|
457
|
+
w > 0 && (p.fx === 0 ? d.push([p.x, p.x]) : f[w - 1].fx * p.fx < 0 && d.push([
|
|
458
|
+
f[w - 1].x,
|
|
459
|
+
p.x
|
|
460
|
+
]));
|
|
461
|
+
}), d.forEach((p) => {
|
|
462
|
+
const [w, V] = p;
|
|
463
|
+
if (w === V)
|
|
464
|
+
e.push(A(this, C, ge).call(this, w));
|
|
465
|
+
else {
|
|
466
|
+
const ce = A(this, C, bi).call(this, t, w, V);
|
|
467
|
+
ce !== null && e.push(A(this, C, Ge).call(this, ce));
|
|
468
|
+
}
|
|
469
|
+
}), e;
|
|
470
|
+
}, bi = function(e, t, i, n = 1e-10) {
|
|
471
|
+
let r = s(this, K).evaluate(t, !0), l = s(this, K).evaluate(i, !0);
|
|
472
|
+
if (r * l > 0)
|
|
473
|
+
return console.log("Pas de racine dans l'intervalle donné"), null;
|
|
474
|
+
let c;
|
|
475
|
+
for (; (i - t) / 2 > n; ) {
|
|
476
|
+
c = (t + i) / 2;
|
|
477
|
+
const f = s(this, K).evaluate(c, !0);
|
|
478
|
+
if (f === 0)
|
|
479
|
+
return c;
|
|
480
|
+
r * f < 0 ? (i = c, l = f) : (t = c, r = f);
|
|
481
|
+
}
|
|
482
|
+
return (t + i) / 2;
|
|
483
|
+
}, xi = function() {
|
|
484
|
+
let e = s(this, K).clone(), t = [];
|
|
445
485
|
const i = e.lcmDenominator();
|
|
446
486
|
i !== 1 && e.multiply(i);
|
|
447
487
|
const n = e.monomByDegree().coefficient;
|
|
448
488
|
let r = e.monomByDegree(0).coefficient;
|
|
449
489
|
for (; r.isZero(); )
|
|
450
|
-
t.length === 0 && t.push(
|
|
451
|
-
const l =
|
|
452
|
-
for (const
|
|
453
|
-
for (const
|
|
454
|
-
const
|
|
455
|
-
e.evaluate(
|
|
490
|
+
t.length === 0 && t.push(A(this, C, ge).call(this, 0)), e = e.divide("x"), r = e.monomByDegree(0).coefficient;
|
|
491
|
+
const l = U.dividers(n.value), c = U.dividers(r.value);
|
|
492
|
+
for (const d of l)
|
|
493
|
+
for (const p of c) {
|
|
494
|
+
const w = new u(p, d);
|
|
495
|
+
e.evaluate(w).isZero() && !t.find((V) => V.value === w.value) && t.push(A(this, C, ge).call(this, w)), w.opposite(), e.evaluate(w).isZero() && !t.find((V) => V.value === w.value) && t.push(A(this, C, ge).call(this, w));
|
|
456
496
|
}
|
|
457
|
-
for (const
|
|
458
|
-
if (
|
|
497
|
+
for (const d of t) {
|
|
498
|
+
if (d.exact !== !1 && d.exact.isZero())
|
|
459
499
|
continue;
|
|
460
|
-
const
|
|
461
|
-
for (; e.isDividableBy(
|
|
462
|
-
e = e.divide(
|
|
500
|
+
const p = s(this, K).clone().parse("x", d.exact.denominator, -d.exact.numerator);
|
|
501
|
+
for (; e.isDividableBy(p); )
|
|
502
|
+
e = e.divide(p);
|
|
463
503
|
}
|
|
464
504
|
if (e.degree().isZero())
|
|
465
|
-
return t.sort((
|
|
505
|
+
return t.sort((d, p) => d.value - p.value);
|
|
466
506
|
if (e.degree().value > 3)
|
|
467
507
|
return [];
|
|
468
|
-
const
|
|
469
|
-
return t = t.concat(
|
|
470
|
-
},
|
|
471
|
-
const e = s(this,
|
|
472
|
-
if (
|
|
473
|
-
const
|
|
474
|
-
return [
|
|
475
|
-
}
|
|
476
|
-
if (
|
|
477
|
-
const
|
|
478
|
-
return
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
].sort((me,
|
|
482
|
-
}
|
|
483
|
-
if (
|
|
484
|
-
const
|
|
485
|
-
for (let
|
|
486
|
-
|
|
487
|
-
return
|
|
508
|
+
const f = new pi(e, e.clone().parse("0"), s(this, Fe));
|
|
509
|
+
return t = t.concat(f.solve()), t.sort((d, p) => d.value - p.value);
|
|
510
|
+
}, Ei = function() {
|
|
511
|
+
const e = s(this, K), t = e.monomByDegree(3).coefficient, i = e.monomByDegree(2).coefficient, n = e.monomByDegree(1).coefficient, r = e.monomByDegree(0).coefficient, l = i.clone().divide(t), c = n.clone().divide(t), f = r.clone().divide(t), d = c.clone().subtract(l.clone().pow(2).divide(3)), p = f.clone().subtract(l.clone().multiply(c).divide(3)).add(l.clone().pow(3).multiply(2).divide(27)), w = p.clone().opposite(), V = d.clone().opposite().pow(3).divide(27), ce = w.clone().pow(2).subtract(V.clone().multiply(4)).opposite();
|
|
512
|
+
if (ce.isNegative()) {
|
|
513
|
+
const ue = p.clone().opposite().add(ce.clone().opposite().sqrt()).divide(2).root(3), fe = p.clone().opposite().subtract(ce.clone().opposite().sqrt()).divide(2).root(3), ye = ue.clone().add(fe).subtract(l.clone().divide(3));
|
|
514
|
+
return [A(this, C, ge).call(this, ye)];
|
|
515
|
+
}
|
|
516
|
+
if (ce.isZero()) {
|
|
517
|
+
const ue = p.clone().opposite().divide(2).root(3), fe = ue.clone().opposite().subtract(l.clone().divide(3)), ye = ue.clone().multiply(2).subtract(l.clone().divide(3));
|
|
518
|
+
return fe.isEqual(ye) ? [A(this, C, ge).call(this, fe)] : [
|
|
519
|
+
A(this, C, ge).call(this, ye),
|
|
520
|
+
A(this, C, ge).call(this, fe)
|
|
521
|
+
].sort((me, de) => me.value - de.value);
|
|
522
|
+
}
|
|
523
|
+
if (ce.isPositive()) {
|
|
524
|
+
const ue = [], fe = d.value, ye = p.value, me = l.value;
|
|
525
|
+
for (let de = 0; de < 3; de++)
|
|
526
|
+
ue.push(2 * Math.sqrt(-fe / 3) * Math.cos(Math.acos(3 * ye / (2 * fe) * Math.sqrt(-3 / fe)) / 3 + 2 * Math.PI * de / 3) - me / 3);
|
|
527
|
+
return ue.map((de) => A(this, C, Ge).call(this, de)).sort((de, rt) => de.value - rt.value);
|
|
488
528
|
}
|
|
489
529
|
return [];
|
|
490
|
-
},
|
|
491
|
-
const e = s(this,
|
|
530
|
+
}, Ni = function() {
|
|
531
|
+
const [e, t] = s(this, K).getCoefficients(), i = t.opposite().divide(e);
|
|
492
532
|
return [
|
|
493
|
-
|
|
533
|
+
A(this, C, ge).call(this, i)
|
|
494
534
|
];
|
|
495
|
-
},
|
|
496
|
-
const e = s(this,
|
|
535
|
+
}, Ai = function() {
|
|
536
|
+
const e = s(this, K), [t, i, n] = e.getCoefficients(), r = i.clone().pow(2).subtract(t.clone().multiply(n).multiply(4));
|
|
497
537
|
if (r.isNegative())
|
|
498
538
|
return [];
|
|
499
539
|
if (r.isSquare()) {
|
|
500
|
-
const l = r.sqrt(), c = i.clone().opposite().add(l).divide(t.clone().multiply(2)),
|
|
501
|
-
return l.isZero() ? [
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
].sort((
|
|
505
|
-
}
|
|
506
|
-
return
|
|
507
|
-
},
|
|
508
|
-
const n =
|
|
509
|
-
function V(me,
|
|
510
|
-
return `\\frac{ ${
|
|
511
|
-
}
|
|
512
|
-
function
|
|
513
|
-
return `(${
|
|
514
|
-
}
|
|
515
|
-
const
|
|
540
|
+
const l = r.sqrt(), c = i.clone().opposite().add(l).divide(t.clone().multiply(2)), f = i.clone().opposite().subtract(l).divide(t.clone().multiply(2));
|
|
541
|
+
return l.isZero() ? [A(this, C, ge).call(this, c)] : [
|
|
542
|
+
A(this, C, ge).call(this, c),
|
|
543
|
+
A(this, C, ge).call(this, f)
|
|
544
|
+
].sort((d, p) => d.value - p.value);
|
|
545
|
+
}
|
|
546
|
+
return A(this, C, Ti).call(this, t, i, r);
|
|
547
|
+
}, Ti = function(e, t, i) {
|
|
548
|
+
const n = U.dividers(i.value).filter((me) => Math.sqrt(me) % 1 === 0).map((me) => Math.sqrt(me)).pop() ?? 1, r = U.gcd(2 * e.value, t.value, n) * (e.isNegative() ? -1 : 1), l = t.clone().divide(r).opposite(), c = e.clone().divide(r).multiply(2), f = i.clone().divide(n ** 2), d = Math.abs(n / r), p = n === 1 ? "-" : `-${d} `, w = n === 1 ? "+" : `+${d} `;
|
|
549
|
+
function V(me, de, rt, Jt) {
|
|
550
|
+
return `\\frac{ ${de} ${rt}\\sqrt{ ${Jt} } }{ ${me} }`;
|
|
551
|
+
}
|
|
552
|
+
function ce(me, de, rt, Jt) {
|
|
553
|
+
return `(${de}${rt}sqrt(${Jt}))/${me}`;
|
|
554
|
+
}
|
|
555
|
+
const ue = i.value ** 0.5, fe = (-t.value - ue) / (2 * e.value), ye = (-t.value + ue) / (2 * e.value);
|
|
516
556
|
return [
|
|
517
|
-
|
|
518
|
-
tex: V(c.tex, l.tex,
|
|
519
|
-
display:
|
|
557
|
+
A(this, C, Ge).call(this, fe, {
|
|
558
|
+
tex: V(c.tex, l.tex, p.toString(), f.tex),
|
|
559
|
+
display: ce(c.display, l.display, p.toString(), f.display)
|
|
520
560
|
}),
|
|
521
|
-
|
|
522
|
-
tex: V(c.tex, l.tex,
|
|
523
|
-
display:
|
|
561
|
+
A(this, C, Ge).call(this, ye, {
|
|
562
|
+
tex: V(c.tex, l.tex, w.toString(), f.tex),
|
|
563
|
+
display: ce(c.display, l.display, w.toString(), f.display)
|
|
524
564
|
})
|
|
525
|
-
].sort((me,
|
|
565
|
+
].sort((me, de) => me.value - de.value);
|
|
526
566
|
};
|
|
527
|
-
let
|
|
528
|
-
var
|
|
567
|
+
let At = pi;
|
|
568
|
+
var Xi = Object.defineProperty, Oi = (o) => {
|
|
529
569
|
throw TypeError(o);
|
|
530
|
-
},
|
|
531
|
-
const
|
|
570
|
+
}, Yi = (o, e, t) => e in o ? Xi(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t, ei = (o, e, t) => Yi(o, typeof e != "symbol" ? e + "" : e, t), qi = (o, e, t) => e.has(o) || Oi("Cannot " + t), te = (o, e, t) => (qi(o, e, "read from private field"), t ? t.call(o) : e.get(o)), ot = (o, e, t) => e.has(o) ? Oi("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(o) : e.set(o, t), Ee = (o, e, t, i) => (qi(o, e, "write to private field"), e.set(o, t), t);
|
|
571
|
+
const fi = {
|
|
532
572
|
pi: Math.PI,
|
|
533
573
|
e: Math.exp(1)
|
|
534
574
|
};
|
|
535
|
-
var
|
|
536
|
-
function
|
|
575
|
+
var g = /* @__PURE__ */ ((o) => (o.VARIABLE = "variable", o.COEFFICIENT = "coefficient", o.OPERATION = "operation", o.CONSTANT = "constant", o.FUNCTION = "function", o.FUNCTION_ARGUMENT = "function-argument", o.MONOM = "monom", o.LEFT_PARENTHESIS = "(", o.RIGHT_PARENTHESIS = ")", o))(g || {}), Ze = /* @__PURE__ */ ((o) => (o.EXPRESSION = "expression", o.POLYNOM = "polynom", o.SET = "set", o.NUMERIC = "numeric", o))(Ze || {});
|
|
576
|
+
function Qi(o, e) {
|
|
537
577
|
if (o.length <= 1)
|
|
538
578
|
return o;
|
|
539
|
-
const t = Object.keys(e).filter((
|
|
540
|
-
t.sort((
|
|
541
|
-
const i = new RegExp(`^(${t.join("|")})\\(`), n = Object.keys(
|
|
542
|
-
n.sort((
|
|
579
|
+
const t = Object.keys(e).filter((w) => e[w].type === g.FUNCTION).map((w) => w);
|
|
580
|
+
t.sort((w, V) => V.length - w.length);
|
|
581
|
+
const i = new RegExp(`^(${t.join("|")})\\(`), n = Object.keys(fi);
|
|
582
|
+
n.sort((w, V) => V.length - w.length);
|
|
543
583
|
const r = new RegExp(`^(${n.join("|")})`), l = /^(\d+(\.\d+)?)/;
|
|
544
|
-
let c = "",
|
|
584
|
+
let c = "", f, d, p;
|
|
545
585
|
for (; o.length > 0; ) {
|
|
546
|
-
if (
|
|
547
|
-
const
|
|
548
|
-
|
|
586
|
+
if (f = d, p = void 0, t.length > 0 && i.exec(o)) {
|
|
587
|
+
const w = t.find((V) => o.startsWith(V));
|
|
588
|
+
w && (p = w + "(", o = o.slice(w.length + 1), d = g.FUNCTION);
|
|
549
589
|
} else if (n.length > 0 && r.exec(o)) {
|
|
550
|
-
const
|
|
551
|
-
|
|
590
|
+
const w = n.find((V) => o.startsWith(V));
|
|
591
|
+
w && (p = w, o = o.slice(w.length), d = g.CONSTANT);
|
|
552
592
|
} else if (l.exec(o)) {
|
|
553
|
-
const
|
|
554
|
-
|
|
593
|
+
const w = l.exec(o);
|
|
594
|
+
w && (p = w[0], o = o.slice(w[0].length), d = g.COEFFICIENT);
|
|
555
595
|
} else
|
|
556
|
-
switch (
|
|
596
|
+
switch (p = o[0], o = o.slice(1), p) {
|
|
557
597
|
case "(":
|
|
558
|
-
|
|
598
|
+
d = g.LEFT_PARENTHESIS;
|
|
559
599
|
break;
|
|
560
600
|
case ")":
|
|
561
|
-
|
|
601
|
+
d = g.RIGHT_PARENTHESIS;
|
|
562
602
|
break;
|
|
563
603
|
case ",":
|
|
564
|
-
|
|
604
|
+
d = g.FUNCTION_ARGUMENT;
|
|
565
605
|
break;
|
|
566
606
|
case "+":
|
|
567
607
|
case "-":
|
|
568
608
|
case "*":
|
|
569
609
|
case "/":
|
|
570
610
|
case "^":
|
|
571
|
-
|
|
611
|
+
d = g.OPERATION;
|
|
572
612
|
break;
|
|
573
613
|
default:
|
|
574
|
-
|
|
614
|
+
d = g.VARIABLE;
|
|
575
615
|
}
|
|
576
|
-
if (
|
|
616
|
+
if (p === void 0 || d === void 0)
|
|
577
617
|
throw new Error("The token is undefined");
|
|
578
|
-
c +=
|
|
618
|
+
c += Ki(f, d), c += p;
|
|
579
619
|
}
|
|
580
620
|
return c;
|
|
581
621
|
}
|
|
582
|
-
function
|
|
583
|
-
return o === void 0 || o ===
|
|
622
|
+
function Ki(o, e) {
|
|
623
|
+
return o === void 0 || o === g.OPERATION || e === g.OPERATION || o === g.LEFT_PARENTHESIS || o === g.FUNCTION || o === g.FUNCTION_ARGUMENT || e === g.RIGHT_PARENTHESIS || e === g.FUNCTION_ARGUMENT ? "" : "*";
|
|
584
624
|
}
|
|
585
|
-
const
|
|
586
|
-
"^": { precedence: 4, associative: "right", type:
|
|
587
|
-
"*": { precedence: 3, associative: "left", type:
|
|
588
|
-
"/": { precedence: 3, associative: "left", type:
|
|
589
|
-
"+": { precedence: 2, associative: "left", type:
|
|
590
|
-
"-": { precedence: 2, associative: "left", type:
|
|
591
|
-
},
|
|
592
|
-
"^": { precedence: 4, associative: "right", type:
|
|
593
|
-
"*": { precedence: 3, associative: "left", type:
|
|
594
|
-
"/": { precedence: 3, associative: "left", type:
|
|
595
|
-
"+": { precedence: 2, associative: "left", type:
|
|
596
|
-
"-": { precedence: 2, associative: "left", type:
|
|
597
|
-
"%": { precedence: 3, associative: "right", type:
|
|
598
|
-
sin: { precedence: 4, associative: "right", type:
|
|
599
|
-
cos: { precedence: 4, associative: "right", type:
|
|
600
|
-
tan: { precedence: 4, associative: "right", type:
|
|
601
|
-
sqrt: { precedence: 4, associative: "right", type:
|
|
602
|
-
nthrt: { precedence: 4, associative: "right", type:
|
|
603
|
-
",": { precedence: 2, associative: "left", type:
|
|
604
|
-
},
|
|
605
|
-
"^": { precedence: 4, associative: "right", type:
|
|
606
|
-
"*": { precedence: 3, associative: "left", type:
|
|
607
|
-
"/": { precedence: 3, associative: "left", type:
|
|
608
|
-
"+": { precedence: 2, associative: "left", type:
|
|
609
|
-
"-": { precedence: 2, associative: "left", type:
|
|
610
|
-
"%": { precedence: 3, associative: "right", type:
|
|
611
|
-
sin: { precedence: 4, associative: "right", type:
|
|
612
|
-
cos: { precedence: 4, associative: "right", type:
|
|
613
|
-
tan: { precedence: 4, associative: "right", type:
|
|
614
|
-
sqrt: { precedence: 4, associative: "right", type:
|
|
615
|
-
nthrt: { precedence: 4, associative: "right", type:
|
|
616
|
-
ln: { precedence: 4, associative: "right", type:
|
|
617
|
-
log: { precedence: 4, associative: "right", type:
|
|
618
|
-
},
|
|
619
|
-
"&": { precedence: 3, associative: "left", type:
|
|
620
|
-
"|": { precedence: 3, associative: "left", type:
|
|
621
|
-
"!": { precedence: 4, associative: "right", type:
|
|
622
|
-
"-": { precedence: 2, associative: "left", type:
|
|
625
|
+
const Ji = {
|
|
626
|
+
"^": { precedence: 4, associative: "right", type: g.OPERATION },
|
|
627
|
+
"*": { precedence: 3, associative: "left", type: g.OPERATION },
|
|
628
|
+
"/": { precedence: 3, associative: "left", type: g.OPERATION },
|
|
629
|
+
"+": { precedence: 2, associative: "left", type: g.OPERATION },
|
|
630
|
+
"-": { precedence: 2, associative: "left", type: g.OPERATION }
|
|
631
|
+
}, _i = {
|
|
632
|
+
"^": { precedence: 4, associative: "right", type: g.OPERATION },
|
|
633
|
+
"*": { precedence: 3, associative: "left", type: g.OPERATION },
|
|
634
|
+
"/": { precedence: 3, associative: "left", type: g.OPERATION },
|
|
635
|
+
"+": { precedence: 2, associative: "left", type: g.OPERATION },
|
|
636
|
+
"-": { precedence: 2, associative: "left", type: g.OPERATION },
|
|
637
|
+
"%": { precedence: 3, associative: "right", type: g.OPERATION },
|
|
638
|
+
sin: { precedence: 4, associative: "right", type: g.FUNCTION },
|
|
639
|
+
cos: { precedence: 4, associative: "right", type: g.FUNCTION },
|
|
640
|
+
tan: { precedence: 4, associative: "right", type: g.FUNCTION },
|
|
641
|
+
sqrt: { precedence: 4, associative: "right", type: g.FUNCTION },
|
|
642
|
+
nthrt: { precedence: 4, associative: "right", type: g.FUNCTION },
|
|
643
|
+
",": { precedence: 2, associative: "left", type: g.FUNCTION_ARGUMENT }
|
|
644
|
+
}, es = {
|
|
645
|
+
"^": { precedence: 4, associative: "right", type: g.OPERATION },
|
|
646
|
+
"*": { precedence: 3, associative: "left", type: g.OPERATION },
|
|
647
|
+
"/": { precedence: 3, associative: "left", type: g.OPERATION },
|
|
648
|
+
"+": { precedence: 2, associative: "left", type: g.OPERATION },
|
|
649
|
+
"-": { precedence: 2, associative: "left", type: g.OPERATION },
|
|
650
|
+
"%": { precedence: 3, associative: "right", type: g.OPERATION },
|
|
651
|
+
sin: { precedence: 4, associative: "right", type: g.FUNCTION },
|
|
652
|
+
cos: { precedence: 4, associative: "right", type: g.FUNCTION },
|
|
653
|
+
tan: { precedence: 4, associative: "right", type: g.FUNCTION },
|
|
654
|
+
sqrt: { precedence: 4, associative: "right", type: g.FUNCTION },
|
|
655
|
+
nthrt: { precedence: 4, associative: "right", type: g.FUNCTION },
|
|
656
|
+
ln: { precedence: 4, associative: "right", type: g.FUNCTION },
|
|
657
|
+
log: { precedence: 4, associative: "right", type: g.FUNCTION }
|
|
658
|
+
}, ts = {
|
|
659
|
+
"&": { precedence: 3, associative: "left", type: g.OPERATION },
|
|
660
|
+
"|": { precedence: 3, associative: "left", type: g.OPERATION },
|
|
661
|
+
"!": { precedence: 4, associative: "right", type: g.OPERATION },
|
|
662
|
+
"-": { precedence: 2, associative: "left", type: g.OPERATION }
|
|
623
663
|
};
|
|
624
|
-
var
|
|
625
|
-
class
|
|
664
|
+
var He, at, se, bt, Ve;
|
|
665
|
+
class Kt {
|
|
626
666
|
constructor(e) {
|
|
627
|
-
|
|
667
|
+
ot(this, He), ot(this, at, []), ot(this, se, {}), ot(this, bt, []), ot(this, Ve), Ee(this, He, typeof e > "u" ? Ze.POLYNOM : e), this.tokenConfigInitialization();
|
|
628
668
|
}
|
|
629
669
|
// Getter
|
|
630
670
|
get rpn() {
|
|
631
|
-
return
|
|
671
|
+
return te(this, at);
|
|
632
672
|
}
|
|
633
673
|
get rpnToken() {
|
|
634
|
-
return
|
|
674
|
+
return te(this, at).map((e) => e.token);
|
|
635
675
|
}
|
|
636
676
|
tokenConfigInitialization() {
|
|
637
|
-
return
|
|
677
|
+
return te(this, He) === Ze.SET ? (Ee(this, se, ts), Ee(this, Ve, !1)) : te(this, He) === Ze.NUMERIC ? (Ee(this, se, es), Ee(this, Ve, !0)) : te(this, He) === Ze.EXPRESSION ? (Ee(this, se, _i), Ee(this, Ve, !0)) : (Ee(this, se, Ji), Ee(this, Ve, !0)), Ee(this, bt, Object.keys(te(this, se)).sort((e, t) => t.length - e.length)), te(this, se);
|
|
638
678
|
}
|
|
639
679
|
/**
|
|
640
680
|
* Get the next token to analyse.
|
|
@@ -644,31 +684,31 @@ class Qt {
|
|
|
644
684
|
NextToken(e, t) {
|
|
645
685
|
let i, n;
|
|
646
686
|
if (i = "", n = void 0, e[t] === "(")
|
|
647
|
-
i = "(", n =
|
|
687
|
+
i = "(", n = g.LEFT_PARENTHESIS;
|
|
648
688
|
else if (e[t] === ")")
|
|
649
|
-
i = ")", n =
|
|
689
|
+
i = ")", n = g.RIGHT_PARENTHESIS;
|
|
650
690
|
else if (e[t] === ",")
|
|
651
|
-
i = ",", n =
|
|
691
|
+
i = ",", n = g.FUNCTION_ARGUMENT;
|
|
652
692
|
else {
|
|
653
|
-
for (const r of
|
|
693
|
+
for (const r of te(this, bt))
|
|
654
694
|
if (e.substring(t, t + r.length) === r) {
|
|
655
|
-
i += r, n =
|
|
695
|
+
i += r, n = te(this, se)[r].type;
|
|
656
696
|
break;
|
|
657
697
|
}
|
|
658
|
-
for (const r in
|
|
698
|
+
for (const r in fi)
|
|
659
699
|
if (e.substring(t, t + r.length) === r) {
|
|
660
|
-
i += r, n =
|
|
700
|
+
i += r, n = g.CONSTANT;
|
|
661
701
|
break;
|
|
662
702
|
}
|
|
663
703
|
if (i === "")
|
|
664
704
|
if (/[0-9.]/.exec(e[t])) {
|
|
665
705
|
const r = /^([0-9.]+)/.exec(e.substring(t));
|
|
666
|
-
i = r ? r[0] : "", n =
|
|
706
|
+
i = r ? r[0] : "", n = g.COEFFICIENT;
|
|
667
707
|
} else if (/[a-zA-Z]/.exec(e[t])) {
|
|
668
708
|
const r = /^([a-zA-Z])/.exec(e.substring(t));
|
|
669
|
-
i = r ? r[0] : "", n =
|
|
709
|
+
i = r ? r[0] : "", n = g.VARIABLE;
|
|
670
710
|
} else
|
|
671
|
-
console.log("Unidentified token", e[t], e, t), i = e[t], n =
|
|
711
|
+
console.log("Unidentified token", e[t], e, t), i = e[t], n = g.MONOM;
|
|
672
712
|
}
|
|
673
713
|
if (n === void 0)
|
|
674
714
|
throw new Error(`Token type is undefined for token ${i}`);
|
|
@@ -683,56 +723,56 @@ class Qt {
|
|
|
683
723
|
parse(e, t) {
|
|
684
724
|
const i = [], n = [];
|
|
685
725
|
let r = "", l = 0, c;
|
|
686
|
-
(t ??
|
|
687
|
-
const
|
|
688
|
-
let
|
|
726
|
+
(t ?? te(this, Ve)) && (e = Qi(e, te(this, se)));
|
|
727
|
+
const f = 50;
|
|
728
|
+
let d = 50, p;
|
|
689
729
|
for (; l < e.length; ) {
|
|
690
|
-
if (
|
|
730
|
+
if (d--, d === 0) {
|
|
691
731
|
console.log("SECURITY LEVEL 1 EXIT");
|
|
692
732
|
break;
|
|
693
733
|
}
|
|
694
734
|
switch ([r, l, c] = this.NextToken(e, l), c) {
|
|
695
|
-
case
|
|
696
|
-
case
|
|
697
|
-
case
|
|
698
|
-
case
|
|
735
|
+
case g.MONOM:
|
|
736
|
+
case g.COEFFICIENT:
|
|
737
|
+
case g.VARIABLE:
|
|
738
|
+
case g.CONSTANT:
|
|
699
739
|
i.push({
|
|
700
740
|
token: r,
|
|
701
741
|
tokenType: c
|
|
702
742
|
});
|
|
703
743
|
break;
|
|
704
|
-
case
|
|
744
|
+
case g.OPERATION:
|
|
705
745
|
if (n.length > 0) {
|
|
706
|
-
let
|
|
707
|
-
for (
|
|
708
|
-
(
|
|
709
|
-
|
|
710
|
-
if (
|
|
746
|
+
let w = n[n.length - 1];
|
|
747
|
+
for (p = +f; w.token in te(this, se) && //either o1 is left-associative and its precedence is less than or equal to that of o2,
|
|
748
|
+
(te(this, se)[r].associative === "left" && te(this, se)[r].precedence <= te(this, se)[w.token].precedence || //or o1 is right associative, and has precedence less than that of o2,
|
|
749
|
+
te(this, se)[r].associative === "right" && te(this, se)[r].precedence < te(this, se)[w.token].precedence); ) {
|
|
750
|
+
if (p--, p === 0) {
|
|
711
751
|
console.log("SECURITY LEVEL 2 OPERATION EXIT");
|
|
712
752
|
break;
|
|
713
753
|
}
|
|
714
|
-
if (i.push(n.pop() ?? { token: "", tokenType:
|
|
754
|
+
if (i.push(n.pop() ?? { token: "", tokenType: g.OPERATION }), n.length === 0)
|
|
715
755
|
break;
|
|
716
|
-
|
|
756
|
+
w = n[n.length - 1];
|
|
717
757
|
}
|
|
718
758
|
}
|
|
719
759
|
n.push({ token: r, tokenType: c });
|
|
720
760
|
break;
|
|
721
|
-
case
|
|
722
|
-
for (
|
|
723
|
-
if (
|
|
761
|
+
case g.FUNCTION_ARGUMENT:
|
|
762
|
+
for (p = +f; n[n.length - 1].token !== "(" && n.length > 0; ) {
|
|
763
|
+
if (p--, p === 0) {
|
|
724
764
|
console.log("SECURITY LEVEL 2 FUNCTION ARGUMENT EXIT");
|
|
725
765
|
break;
|
|
726
766
|
}
|
|
727
767
|
i.push(n.pop() ?? { token: r, tokenType: c });
|
|
728
768
|
}
|
|
729
769
|
break;
|
|
730
|
-
case
|
|
731
|
-
n.push({ token: r, tokenType: c }), e[l] === "-" && i.push({ token: "0", tokenType:
|
|
770
|
+
case g.LEFT_PARENTHESIS:
|
|
771
|
+
n.push({ token: r, tokenType: c }), e[l] === "-" && i.push({ token: "0", tokenType: g.COEFFICIENT });
|
|
732
772
|
break;
|
|
733
|
-
case
|
|
734
|
-
for (
|
|
735
|
-
if (
|
|
773
|
+
case g.RIGHT_PARENTHESIS:
|
|
774
|
+
for (p = +f; n[n.length - 1].token !== "(" && n.length > 1; ) {
|
|
775
|
+
if (p--, p === 0) {
|
|
736
776
|
console.log("SECURITY LEVEL 2 CLOSING PARENTHESIS EXIT");
|
|
737
777
|
break;
|
|
738
778
|
}
|
|
@@ -740,22 +780,22 @@ class Qt {
|
|
|
740
780
|
}
|
|
741
781
|
n.pop();
|
|
742
782
|
break;
|
|
743
|
-
case
|
|
783
|
+
case g.FUNCTION:
|
|
744
784
|
n.push({ token: r, tokenType: c });
|
|
745
785
|
break;
|
|
746
786
|
default:
|
|
747
787
|
throw new Error(`Token type ${r} is not handled`);
|
|
748
788
|
}
|
|
749
789
|
}
|
|
750
|
-
return
|
|
790
|
+
return Ee(this, at, i.concat(n.reverse())), this;
|
|
751
791
|
}
|
|
752
792
|
}
|
|
753
|
-
|
|
754
|
-
class
|
|
793
|
+
He = /* @__PURE__ */ new WeakMap(), at = /* @__PURE__ */ new WeakMap(), se = /* @__PURE__ */ new WeakMap(), bt = /* @__PURE__ */ new WeakMap(), Ve = /* @__PURE__ */ new WeakMap();
|
|
794
|
+
class is {
|
|
755
795
|
constructor(e, t) {
|
|
756
|
-
|
|
796
|
+
ei(this, "_rpn"), ei(this, "_expression"), ei(this, "_isValid"), this._expression = e;
|
|
757
797
|
try {
|
|
758
|
-
this._rpn = new
|
|
798
|
+
this._rpn = new Kt(Ze.NUMERIC).parse(e, t).rpn;
|
|
759
799
|
} catch {
|
|
760
800
|
throw this._rpn = null, this._isValid = !1, new Error(`There was a problem parsing: ${e}`);
|
|
761
801
|
}
|
|
@@ -784,7 +824,7 @@ class _i {
|
|
|
784
824
|
return this._isValid = !1, 0;
|
|
785
825
|
this._isValid = !0;
|
|
786
826
|
for (const i of this._rpn)
|
|
787
|
-
if (i.tokenType ===
|
|
827
|
+
if (i.tokenType === g.COEFFICIENT)
|
|
788
828
|
if (!isNaN(+i.token))
|
|
789
829
|
t.push(+i.token);
|
|
790
830
|
else {
|
|
@@ -793,11 +833,11 @@ class _i {
|
|
|
793
833
|
throw this._isValid = !1, new Error("This coefficient is not a fraction");
|
|
794
834
|
t.push(+n[0] / +n[1]);
|
|
795
835
|
}
|
|
796
|
-
else if (i.tokenType ===
|
|
836
|
+
else if (i.tokenType === g.VARIABLE && e !== void 0)
|
|
797
837
|
Object.hasOwn(e, i.token) && t.push(+e[i.token]);
|
|
798
|
-
else if (i.tokenType ===
|
|
799
|
-
t.push(
|
|
800
|
-
else if (i.tokenType ===
|
|
838
|
+
else if (i.tokenType === g.CONSTANT)
|
|
839
|
+
t.push(fi[i.token]);
|
|
840
|
+
else if (i.tokenType === g.OPERATION) {
|
|
801
841
|
if (i.token === "*") {
|
|
802
842
|
const n = t.pop(), r = t.pop();
|
|
803
843
|
if (r === void 0 || n === void 0)
|
|
@@ -824,7 +864,7 @@ class _i {
|
|
|
824
864
|
throw this._isValid = !1, new Error(`The base value ${r ?? "a"} or exponent ${n ?? "b"} are not defined`);
|
|
825
865
|
t.push(Math.pow(r, n));
|
|
826
866
|
}
|
|
827
|
-
} else if (i.tokenType ===
|
|
867
|
+
} else if (i.tokenType === g.FUNCTION) {
|
|
828
868
|
const n = t.pop();
|
|
829
869
|
if (n === void 0)
|
|
830
870
|
throw this._isValid = !1, new Error(`The parameters for ${i.token} is not defined`);
|
|
@@ -851,20 +891,20 @@ class _i {
|
|
|
851
891
|
return +e.toFixed(t);
|
|
852
892
|
}
|
|
853
893
|
}
|
|
854
|
-
var T,
|
|
894
|
+
var T, b, Qe, xt, ze, Mt, kt;
|
|
855
895
|
const I = class I {
|
|
856
896
|
constructor(e) {
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
897
|
+
m(this, Qe);
|
|
898
|
+
m(this, T);
|
|
899
|
+
m(this, b);
|
|
860
900
|
/**
|
|
861
901
|
* Clone the current Monom.
|
|
862
902
|
*/
|
|
863
903
|
a(this, "clone", () => {
|
|
864
904
|
const e = new I();
|
|
865
905
|
e.coefficient = s(this, T).clone();
|
|
866
|
-
for (const t in s(this,
|
|
867
|
-
e.setLetter(t, s(this,
|
|
906
|
+
for (const t in s(this, b))
|
|
907
|
+
e.setLetter(t, s(this, b)[t].clone());
|
|
868
908
|
return e;
|
|
869
909
|
});
|
|
870
910
|
/**
|
|
@@ -874,24 +914,24 @@ const I = class I {
|
|
|
874
914
|
a(this, "add", (...e) => {
|
|
875
915
|
for (const t of e) {
|
|
876
916
|
const i = t instanceof I ? t : new I(t);
|
|
877
|
-
this.isSameAs(i) ? (this.isZero() &&
|
|
917
|
+
this.isSameAs(i) ? (this.isZero() && A(this, Qe, xt).call(this, i), s(this, T).add(i.coefficient)) : console.log("Add monom: " + this.display + " is not similar with ", i.display);
|
|
878
918
|
}
|
|
879
919
|
return this;
|
|
880
920
|
});
|
|
881
|
-
a(this, "containsRationalPower", () => Object.values(s(this,
|
|
921
|
+
a(this, "containsRationalPower", () => Object.values(s(this, b)).some((e) => e.isRational()));
|
|
882
922
|
/**
|
|
883
923
|
* Get the degree of a monom. If no setLetter is given, the result will be the global degree.
|
|
884
924
|
* @param letter (string) Letter to get to degree (power)
|
|
885
925
|
*/
|
|
886
|
-
a(this, "degree", (e) => this.variables.length === 0 ? new u().zero() : e === void 0 ? Object.values(s(this,
|
|
926
|
+
a(this, "degree", (e) => this.variables.length === 0 ? new u().zero() : e === void 0 ? Object.values(s(this, b)).reduce((t, i) => t.clone().add(i)) : this.hasVariable(e) ? s(this, b)[e].clone() : new u().zero());
|
|
887
927
|
/**
|
|
888
928
|
* Derivative the monom
|
|
889
929
|
* @param letter
|
|
890
930
|
*/
|
|
891
931
|
a(this, "derivative", (e) => {
|
|
892
932
|
if (e === void 0 && (e = "x"), this.hasVariable(e)) {
|
|
893
|
-
const t = s(this,
|
|
894
|
-
return s(i,
|
|
933
|
+
const t = s(this, b)[e].clone(), i = this.clone();
|
|
934
|
+
return s(i, b)[e].subtract(1), s(i, T).multiply(new u(t.clone())), i;
|
|
895
935
|
} else
|
|
896
936
|
return new I().zero();
|
|
897
937
|
});
|
|
@@ -904,7 +944,7 @@ const I = class I {
|
|
|
904
944
|
const i = t instanceof I ? t : new I(t);
|
|
905
945
|
s(this, T).divide(i.coefficient);
|
|
906
946
|
for (const n in i.literal)
|
|
907
|
-
s(this,
|
|
947
|
+
s(this, b)[n] = this.hasVariable(n) ? s(this, b)[n].subtract(i.literal[n]) : i.literal[n].clone().opposite(), s(this, b)[n].isZero() && this.removeVariable(n);
|
|
908
948
|
}
|
|
909
949
|
return this;
|
|
910
950
|
});
|
|
@@ -916,16 +956,16 @@ const I = class I {
|
|
|
916
956
|
a(this, "evaluate", (e, t) => {
|
|
917
957
|
if (t === !0) {
|
|
918
958
|
if (e instanceof u)
|
|
919
|
-
return s(this,
|
|
959
|
+
return s(this, ze).call(this, e.value);
|
|
920
960
|
if (e instanceof vt)
|
|
921
961
|
return new u().invalid();
|
|
922
962
|
if (typeof e == "number")
|
|
923
|
-
return s(this,
|
|
963
|
+
return s(this, ze).call(this, e);
|
|
924
964
|
if (typeof e == "object") {
|
|
925
965
|
const n = {};
|
|
926
966
|
for (const r in e)
|
|
927
967
|
n[r] = new u(e[r]).value;
|
|
928
|
-
return s(this,
|
|
968
|
+
return s(this, ze).call(this, n);
|
|
929
969
|
}
|
|
930
970
|
}
|
|
931
971
|
const i = this.coefficient.clone();
|
|
@@ -938,9 +978,9 @@ const I = class I {
|
|
|
938
978
|
if (typeof e == "object") {
|
|
939
979
|
if (this.variables.length === 0)
|
|
940
980
|
return this.coefficient;
|
|
941
|
-
for (const n in s(this,
|
|
981
|
+
for (const n in s(this, b)) {
|
|
942
982
|
const r = new u(e[n]);
|
|
943
|
-
i.multiply(r.pow(s(this,
|
|
983
|
+
i.multiply(r.pow(s(this, b)[n]));
|
|
944
984
|
}
|
|
945
985
|
}
|
|
946
986
|
return i;
|
|
@@ -950,11 +990,11 @@ const I = class I {
|
|
|
950
990
|
* Determine if a monom contains a setLetter in it's literal part
|
|
951
991
|
* @param letter
|
|
952
992
|
*/
|
|
953
|
-
a(this, "hasVariable", (e) => Object.hasOwn(s(this,
|
|
993
|
+
a(this, "hasVariable", (e) => Object.hasOwn(s(this, b), e ?? "x"));
|
|
954
994
|
a(this, "inverse", () => {
|
|
955
995
|
s(this, T).opposite();
|
|
956
|
-
for (const e in s(this,
|
|
957
|
-
s(this,
|
|
996
|
+
for (const e in s(this, b))
|
|
997
|
+
s(this, b)[e].opposite();
|
|
958
998
|
return this;
|
|
959
999
|
});
|
|
960
1000
|
a(this, "isDivisible", (e) => {
|
|
@@ -992,7 +1032,7 @@ const I = class I {
|
|
|
992
1032
|
return !1;
|
|
993
1033
|
if (!this.isZero() && !e.isZero()) {
|
|
994
1034
|
for (const r of n)
|
|
995
|
-
if (!this.hasVariable(r) || !e.hasVariable(r) || !s(this,
|
|
1035
|
+
if (!this.hasVariable(r) || !e.hasVariable(r) || !s(this, b)[r].isEqual(e.literal[r]))
|
|
996
1036
|
return !1;
|
|
997
1037
|
}
|
|
998
1038
|
return !0;
|
|
@@ -1011,14 +1051,14 @@ const I = class I {
|
|
|
1011
1051
|
const i = t instanceof I ? t : new I(t);
|
|
1012
1052
|
s(this, T).multiply(i.coefficient);
|
|
1013
1053
|
for (const n in i.literal)
|
|
1014
|
-
this.hasVariable(n) ? s(this,
|
|
1054
|
+
this.hasVariable(n) ? s(this, b)[n].add(i.literal[n]) : s(this, b)[n] = i.literal[n].clone();
|
|
1015
1055
|
}
|
|
1016
1056
|
return this;
|
|
1017
1057
|
});
|
|
1018
1058
|
/**
|
|
1019
1059
|
* Create a one value monom
|
|
1020
1060
|
*/
|
|
1021
|
-
a(this, "one", () => (h(this, T, new u().one()), h(this,
|
|
1061
|
+
a(this, "one", () => (h(this, T, new u().one()), h(this, b, {}), this));
|
|
1022
1062
|
/**
|
|
1023
1063
|
* Get the opposite
|
|
1024
1064
|
* Returns a monom.
|
|
@@ -1030,8 +1070,8 @@ const I = class I {
|
|
|
1030
1070
|
*/
|
|
1031
1071
|
a(this, "pow", (e) => {
|
|
1032
1072
|
s(this, T).pow(e);
|
|
1033
|
-
for (const t in s(this,
|
|
1034
|
-
s(this,
|
|
1073
|
+
for (const t in s(this, b))
|
|
1074
|
+
s(this, b)[t].multiply(e);
|
|
1035
1075
|
return this;
|
|
1036
1076
|
});
|
|
1037
1077
|
a(this, "primitive", (e) => {
|
|
@@ -1042,8 +1082,8 @@ const I = class I {
|
|
|
1042
1082
|
});
|
|
1043
1083
|
a(this, "reduce", () => {
|
|
1044
1084
|
this.coefficient.reduce();
|
|
1045
|
-
for (const e in s(this,
|
|
1046
|
-
s(this,
|
|
1085
|
+
for (const e in s(this, b))
|
|
1086
|
+
s(this, b)[e].isZero() && this.removeVariable(e);
|
|
1047
1087
|
return this;
|
|
1048
1088
|
});
|
|
1049
1089
|
/**
|
|
@@ -1057,15 +1097,15 @@ const I = class I {
|
|
|
1057
1097
|
* @param letter (string) Letter to change
|
|
1058
1098
|
* @param pow (number) Power of the setLetter (must be positive integer.
|
|
1059
1099
|
*/
|
|
1060
|
-
a(this, "setLetter", (e, t) => t instanceof u ? (this.hasVariable(e) && t.isZero() && this.removeVariable(e), s(this,
|
|
1100
|
+
a(this, "setLetter", (e, t) => t instanceof u ? (this.hasVariable(e) && t.isZero() && this.removeVariable(e), s(this, b)[e] = t.clone(), this) : this.setLetter(e, new u(t)));
|
|
1061
1101
|
/**
|
|
1062
1102
|
* Return the square root of a monom
|
|
1063
1103
|
*/
|
|
1064
1104
|
a(this, "sqrt", () => {
|
|
1065
1105
|
if (this.isSquare()) {
|
|
1066
1106
|
s(this, T).sqrt();
|
|
1067
|
-
for (const e in s(this,
|
|
1068
|
-
s(this,
|
|
1107
|
+
for (const e in s(this, b))
|
|
1108
|
+
s(this, b)[e].clone().divide(2);
|
|
1069
1109
|
}
|
|
1070
1110
|
return this;
|
|
1071
1111
|
});
|
|
@@ -1076,57 +1116,57 @@ const I = class I {
|
|
|
1076
1116
|
a(this, "subtract", (...e) => {
|
|
1077
1117
|
for (const t of e) {
|
|
1078
1118
|
const i = t instanceof I ? t : new I(t);
|
|
1079
|
-
this.isSameAs(i) ? (this.isZero() &&
|
|
1119
|
+
this.isSameAs(i) ? (this.isZero() && A(this, Qe, xt).call(this, i), s(this, T).add(i.clone().coefficient.opposite())) : console.log("Subtract: Is not similar: ", i.display);
|
|
1080
1120
|
}
|
|
1081
1121
|
return this;
|
|
1082
1122
|
});
|
|
1083
1123
|
/**
|
|
1084
1124
|
* Create a zero value monom
|
|
1085
1125
|
*/
|
|
1086
|
-
a(this, "zero", () => (h(this, T, new u().zero()), h(this,
|
|
1087
|
-
|
|
1126
|
+
a(this, "zero", () => (h(this, T, new u().zero()), h(this, b, {}), this));
|
|
1127
|
+
m(this, ze, (e) => {
|
|
1088
1128
|
let t = this.coefficient.value;
|
|
1089
1129
|
if (typeof e == "number") {
|
|
1090
1130
|
const i = {}, n = this.variables[0];
|
|
1091
|
-
return i[n] = e, s(this,
|
|
1131
|
+
return i[n] = e, s(this, ze).call(this, i);
|
|
1092
1132
|
}
|
|
1093
1133
|
if (e instanceof u) {
|
|
1094
1134
|
const i = {};
|
|
1095
|
-
return i[this.variables[0]] = new u(e).value, s(this,
|
|
1135
|
+
return i[this.variables[0]] = new u(e).value, s(this, ze).call(this, i);
|
|
1096
1136
|
}
|
|
1097
1137
|
if (e instanceof vt)
|
|
1098
1138
|
return NaN;
|
|
1099
1139
|
if (typeof e == "object") {
|
|
1100
1140
|
if (this.variables.length === 0)
|
|
1101
1141
|
return this.coefficient.value;
|
|
1102
|
-
for (const i in s(this,
|
|
1142
|
+
for (const i in s(this, b)) {
|
|
1103
1143
|
const n = e[i];
|
|
1104
|
-
n instanceof u ? t *= n.value ** s(this,
|
|
1144
|
+
n instanceof u ? t *= n.value ** s(this, b)[i].value : t *= n ** s(this, b)[i].value;
|
|
1105
1145
|
}
|
|
1106
1146
|
}
|
|
1107
1147
|
return t;
|
|
1108
1148
|
});
|
|
1109
|
-
|
|
1110
|
-
const i = new
|
|
1149
|
+
m(this, Mt, (e) => {
|
|
1150
|
+
const i = new Kt().parse(e).rpn, n = [];
|
|
1111
1151
|
if (i.length === 0)
|
|
1112
1152
|
return this.zero(), this;
|
|
1113
1153
|
if (i.length === 1) {
|
|
1114
1154
|
const r = i[0];
|
|
1115
|
-
return this.one(), r.tokenType ===
|
|
1155
|
+
return this.one(), r.tokenType === g.COEFFICIENT ? this.coefficient = new u(r.token) : r.tokenType === g.VARIABLE && this.setLetter(r.token, 1), this;
|
|
1116
1156
|
} else
|
|
1117
1157
|
for (const r of i)
|
|
1118
1158
|
s(this, kt).call(this, n, r);
|
|
1119
1159
|
return this.one(), this.multiply(n[0]), this;
|
|
1120
1160
|
});
|
|
1121
|
-
|
|
1122
|
-
var
|
|
1161
|
+
m(this, kt, (e, t) => {
|
|
1162
|
+
var f;
|
|
1123
1163
|
let i, n, r, l, c;
|
|
1124
|
-
if (t.tokenType ===
|
|
1164
|
+
if (t.tokenType === g.COEFFICIENT)
|
|
1125
1165
|
e.push(new I(new u(t.token)));
|
|
1126
|
-
else if (t.tokenType ===
|
|
1127
|
-
const
|
|
1128
|
-
|
|
1129
|
-
} else if (t.tokenType ===
|
|
1166
|
+
else if (t.tokenType === g.VARIABLE) {
|
|
1167
|
+
const d = new I().one();
|
|
1168
|
+
d.setLetter(t.token, 1), e.push(d.clone());
|
|
1169
|
+
} else if (t.tokenType === g.OPERATION)
|
|
1130
1170
|
switch (t.token) {
|
|
1131
1171
|
case "-":
|
|
1132
1172
|
n = e.pop() ?? new I().zero(), i = e.pop() ?? new I().zero(), e.push(i.subtract(n));
|
|
@@ -1138,12 +1178,12 @@ const I = class I {
|
|
|
1138
1178
|
n = e.pop() ?? new I().one(), i = e.pop() ?? new I().one(), e.push(i.divide(n));
|
|
1139
1179
|
break;
|
|
1140
1180
|
case "^": {
|
|
1141
|
-
c = ((
|
|
1181
|
+
c = ((f = e.pop()) == null ? void 0 : f.coefficient) ?? new u().one(), r = e.pop() ?? new I().one(), l = r.variables[0], l && r.setLetter(l, c), e.push(r);
|
|
1142
1182
|
break;
|
|
1143
1183
|
}
|
|
1144
1184
|
}
|
|
1145
1185
|
});
|
|
1146
|
-
return h(this, T, new u().zero()), h(this,
|
|
1186
|
+
return h(this, T, new u().zero()), h(this, b, {}), e !== void 0 && this.parse(e), this;
|
|
1147
1187
|
}
|
|
1148
1188
|
// -----------------------------------------
|
|
1149
1189
|
/**
|
|
@@ -1151,7 +1191,7 @@ const I = class I {
|
|
|
1151
1191
|
* @param inputStr
|
|
1152
1192
|
*/
|
|
1153
1193
|
parse(e) {
|
|
1154
|
-
return h(this, T, new u()), h(this,
|
|
1194
|
+
return h(this, T, new u()), h(this, b, {}), typeof e == "string" ? s(this, Mt).call(this, e) : typeof e == "number" ? h(this, T, new u(e)) : e instanceof u ? h(this, T, e.clone()) : e instanceof I && (h(this, T, s(e, T).clone()), A(this, Qe, xt).call(this, e)), this;
|
|
1155
1195
|
}
|
|
1156
1196
|
/**
|
|
1157
1197
|
* Get the coefficient \\(k\\) of the Monom \\(k\\cdot x^{n}\\)
|
|
@@ -1173,9 +1213,9 @@ const I = class I {
|
|
|
1173
1213
|
*/
|
|
1174
1214
|
get display() {
|
|
1175
1215
|
let e = "";
|
|
1176
|
-
const t = Object.keys(s(this,
|
|
1216
|
+
const t = Object.keys(s(this, b)).sort();
|
|
1177
1217
|
for (const i of t)
|
|
1178
|
-
s(this,
|
|
1218
|
+
s(this, b)[i].isNotZero() && (e += i, s(this, b)[i].isNotEqual(1) && (e += `^(${s(this, b)[i].display})`));
|
|
1179
1219
|
return e === "" ? s(this, T).value != 0 ? s(this, T).display : "" : s(this, T).value === 1 ? e : s(this, T).value === -1 ? `-${e}` : s(this, T).value === 0 ? "0" : `${s(this, T).display}${e}`;
|
|
1180
1220
|
}
|
|
1181
1221
|
get dividers() {
|
|
@@ -1185,7 +1225,7 @@ const I = class I {
|
|
|
1185
1225
|
return [this.clone()];
|
|
1186
1226
|
if (this.coefficient.numerator > 1e6)
|
|
1187
1227
|
return [this.clone()];
|
|
1188
|
-
const e =
|
|
1228
|
+
const e = U.dividers(Math.abs(this.coefficient.numerator));
|
|
1189
1229
|
let t = [];
|
|
1190
1230
|
for (const n in this.literal)
|
|
1191
1231
|
t = this._getLiteralDividers(t, n);
|
|
@@ -1217,28 +1257,27 @@ const I = class I {
|
|
|
1217
1257
|
* @returns {literalType}
|
|
1218
1258
|
*/
|
|
1219
1259
|
get literal() {
|
|
1220
|
-
return s(this,
|
|
1260
|
+
return s(this, b);
|
|
1221
1261
|
}
|
|
1222
1262
|
/**
|
|
1223
1263
|
* Set the literal part of the monom. Must be a dictionary {x: Fraction, y: Fraction, ...}
|
|
1224
1264
|
* @param {literalType<Fraction>} L
|
|
1225
1265
|
*/
|
|
1226
1266
|
set literal(e) {
|
|
1227
|
-
h(this,
|
|
1267
|
+
h(this, b, e);
|
|
1228
1268
|
}
|
|
1229
1269
|
/**
|
|
1230
1270
|
* Get the literal square roots of the Monom.
|
|
1231
|
-
* TODO: remove this getter ? Is it used and is it correct ?
|
|
1232
1271
|
* @returns {literalType<Fraction>}
|
|
1233
1272
|
*/
|
|
1234
1273
|
get literalSqrt() {
|
|
1235
1274
|
if (this.isLiteralSquare()) {
|
|
1236
1275
|
const e = {};
|
|
1237
|
-
for (const t in s(this,
|
|
1238
|
-
e[t] = s(this,
|
|
1276
|
+
for (const t in s(this, b))
|
|
1277
|
+
e[t] = s(this, b)[t].clone().sqrt();
|
|
1239
1278
|
return e;
|
|
1240
1279
|
} else
|
|
1241
|
-
return s(this,
|
|
1280
|
+
return s(this, b);
|
|
1242
1281
|
}
|
|
1243
1282
|
/**
|
|
1244
1283
|
* Set the literal part of the monom from a string
|
|
@@ -1246,28 +1285,28 @@ const I = class I {
|
|
|
1246
1285
|
*/
|
|
1247
1286
|
set literalStr(e) {
|
|
1248
1287
|
for (const t of [...e.matchAll(/([a-z])\^([+-]?[0-9]+)/g)])
|
|
1249
|
-
t[1] in s(this,
|
|
1288
|
+
t[1] in s(this, b) || (s(this, b)[t[1]] = new u().zero()), s(this, b)[t[1]].add(+t[2]);
|
|
1250
1289
|
for (const t of [...e.matchAll(/([a-z](?!\^))/g)])
|
|
1251
|
-
t[1] in s(this,
|
|
1290
|
+
t[1] in s(this, b) || (s(this, b)[t[1]] = new u().zero()), s(this, b)[t[1]].add(1);
|
|
1252
1291
|
}
|
|
1253
1292
|
get plotFunction() {
|
|
1254
1293
|
let e = "";
|
|
1255
|
-
const t = Object.keys(s(this,
|
|
1294
|
+
const t = Object.keys(s(this, b)).sort();
|
|
1256
1295
|
for (const i of t)
|
|
1257
|
-
s(this,
|
|
1296
|
+
s(this, b)[i].isNotZero() && (e += (e === "" ? "" : "*") + i, s(this, b)[i].isNotEqual(1) && (e += `^(${s(this, b)[i].display})`));
|
|
1258
1297
|
return e === "" ? s(this, T).value != 0 ? s(this, T).display : "" : s(this, T).value === 1 ? e : s(this, T).value === -1 ? `-${e}` : s(this, T).value === 0 ? "0" : `${s(this, T).display}*${e}`;
|
|
1259
1298
|
}
|
|
1260
1299
|
removeVariable(e) {
|
|
1261
|
-
delete s(this,
|
|
1300
|
+
delete s(this, b)[e];
|
|
1262
1301
|
}
|
|
1263
1302
|
/**
|
|
1264
1303
|
* Get the tex output of the monom
|
|
1265
1304
|
*/
|
|
1266
1305
|
get tex() {
|
|
1267
1306
|
let e = "";
|
|
1268
|
-
const t = Object.keys(s(this,
|
|
1307
|
+
const t = Object.keys(s(this, b)).sort();
|
|
1269
1308
|
for (const i of t)
|
|
1270
|
-
s(this,
|
|
1309
|
+
s(this, b)[i].isNotZero() && (e += i, s(this, b)[i].isNotEqual(1) && (e += `^{ ${s(this, b)[i].tfrac.tex} }`));
|
|
1271
1310
|
return e === "" ? s(this, T).value != 0 ? s(this, T).frac.tex : "0" : s(this, T).value === 1 ? e : s(this, T).value === -1 ? `-${e}` : s(this, T).value === 0 ? "0" : `${s(this, T).frac.tex}${e}`;
|
|
1272
1311
|
}
|
|
1273
1312
|
// Getter helpers.
|
|
@@ -1298,14 +1337,14 @@ const I = class I {
|
|
|
1298
1337
|
return i;
|
|
1299
1338
|
}
|
|
1300
1339
|
};
|
|
1301
|
-
T = new WeakMap(),
|
|
1340
|
+
T = new WeakMap(), b = new WeakMap(), Qe = new WeakSet(), xt = function(e) {
|
|
1302
1341
|
for (const t in e.literal)
|
|
1303
|
-
s(this,
|
|
1304
|
-
},
|
|
1342
|
+
s(this, b)[t] = e.literal[t].clone();
|
|
1343
|
+
}, ze = new WeakMap(), Mt = new WeakMap(), kt = new WeakMap(), a(I, "gcd", (...e) => {
|
|
1305
1344
|
for (const r of e)
|
|
1306
1345
|
if (r.containsRationalPower())
|
|
1307
1346
|
return new I().zero();
|
|
1308
|
-
const t = new I(), i =
|
|
1347
|
+
const t = new I(), i = U.gcd(...e.map((r) => r.coefficient.numerator)), n = U.lcm(...e.map((r) => r.coefficient.denominator));
|
|
1309
1348
|
t.coefficient = new u(i, n).reduce();
|
|
1310
1349
|
for (const r of e) {
|
|
1311
1350
|
for (const l in t.literal)
|
|
@@ -1324,36 +1363,36 @@ a(I, "xMultiply", (...e) => {
|
|
|
1324
1363
|
t.multiply(i);
|
|
1325
1364
|
return t;
|
|
1326
1365
|
});
|
|
1327
|
-
let
|
|
1328
|
-
function
|
|
1366
|
+
let k = I;
|
|
1367
|
+
function yi(o, e = !0) {
|
|
1329
1368
|
return e ? `\\left( ${o} \\right)` : `(${o})`;
|
|
1330
1369
|
}
|
|
1331
|
-
function
|
|
1332
|
-
return o.map((r, l) =>
|
|
1370
|
+
function Et(o, e, t, i, n) {
|
|
1371
|
+
return o.map((r, l) => r === e ? t : r);
|
|
1333
1372
|
}
|
|
1334
|
-
var
|
|
1335
|
-
const
|
|
1373
|
+
var je, y, Ke, ft, Je, dt, Ct, $t, Pt, _e, It, pt, Bt, St, Rt, zt, Mi, Lt, Vt;
|
|
1374
|
+
const $ = class $ {
|
|
1336
1375
|
constructor(e, ...t) {
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1376
|
+
m(this, zt);
|
|
1377
|
+
m(this, je);
|
|
1378
|
+
m(this, y);
|
|
1379
|
+
m(this, Ke);
|
|
1380
|
+
m(this, ft, !1);
|
|
1342
1381
|
/**
|
|
1343
1382
|
* Parse a string to a polynom.
|
|
1344
1383
|
* @param inputStr
|
|
1345
1384
|
* @param values
|
|
1346
1385
|
*/
|
|
1347
1386
|
a(this, "parse", (e, ...t) => {
|
|
1348
|
-
if (h(this, y, []), h(this,
|
|
1349
|
-
return
|
|
1350
|
-
if ((typeof e == "number" || e instanceof u || e instanceof
|
|
1351
|
-
s(this, y).push(new
|
|
1352
|
-
else if (e instanceof
|
|
1353
|
-
s(this, y).push(new
|
|
1354
|
-
s(this, y).push(new
|
|
1387
|
+
if (h(this, y, []), h(this, je, []), typeof e == "string")
|
|
1388
|
+
return A(this, zt, Mi).call(this, e, ...t);
|
|
1389
|
+
if ((typeof e == "number" || e instanceof u || e instanceof k) && t.length === 0)
|
|
1390
|
+
s(this, y).push(new k(e));
|
|
1391
|
+
else if (e instanceof k && t.length > 0)
|
|
1392
|
+
s(this, y).push(new k(e)), t.forEach((i) => {
|
|
1393
|
+
s(this, y).push(new k(i));
|
|
1355
1394
|
});
|
|
1356
|
-
else if (e instanceof
|
|
1395
|
+
else if (e instanceof $)
|
|
1357
1396
|
for (const i of e.monoms)
|
|
1358
1397
|
s(this, y).push(i.clone());
|
|
1359
1398
|
return this;
|
|
@@ -1362,18 +1401,18 @@ const C = class C {
|
|
|
1362
1401
|
* Clone the polynom
|
|
1363
1402
|
*/
|
|
1364
1403
|
a(this, "clone", () => {
|
|
1365
|
-
const e = new
|
|
1404
|
+
const e = new $(), t = [];
|
|
1366
1405
|
for (const i of s(this, y))
|
|
1367
1406
|
t.push(i.clone());
|
|
1368
1407
|
return e.monoms = t, e;
|
|
1369
1408
|
});
|
|
1370
1409
|
a(this, "add", (...e) => {
|
|
1371
1410
|
for (const t of e)
|
|
1372
|
-
t instanceof
|
|
1411
|
+
t instanceof $ ? h(this, y, s(this, y).concat(t.monoms)) : t instanceof k ? s(this, y).push(t.clone()) : typeof t == "number" && Number.isSafeInteger(t) ? s(this, y).push(new k(t.toString())) : s(this, y).push(new k(t));
|
|
1373
1412
|
return this.reduce();
|
|
1374
1413
|
});
|
|
1375
1414
|
a(this, "commonMonom", () => {
|
|
1376
|
-
const e = new
|
|
1415
|
+
const e = new k().one(), t = this.gcdNumerator(), i = this.gcdDenominator(), n = this.degree();
|
|
1377
1416
|
e.coefficient = new u(t, i);
|
|
1378
1417
|
for (const r of this.variables) {
|
|
1379
1418
|
e.setLetter(r, n);
|
|
@@ -1390,28 +1429,28 @@ const C = class C {
|
|
|
1390
1429
|
return t;
|
|
1391
1430
|
});
|
|
1392
1431
|
a(this, "derivative", (e) => {
|
|
1393
|
-
const t = new
|
|
1432
|
+
const t = new $();
|
|
1394
1433
|
for (const i of s(this, y))
|
|
1395
1434
|
t.add(i.derivative(e));
|
|
1396
|
-
return t;
|
|
1435
|
+
return t.reduce();
|
|
1397
1436
|
});
|
|
1398
1437
|
a(this, "divide", (e) => {
|
|
1399
1438
|
if (e instanceof u)
|
|
1400
|
-
return s(this,
|
|
1439
|
+
return s(this, dt).call(this, e);
|
|
1401
1440
|
if (typeof e == "number" && Number.isSafeInteger(e))
|
|
1402
|
-
return s(this,
|
|
1403
|
-
if (e instanceof
|
|
1404
|
-
return this.divide(new
|
|
1405
|
-
if (e instanceof
|
|
1441
|
+
return s(this, Ct).call(this, e);
|
|
1442
|
+
if (e instanceof k)
|
|
1443
|
+
return this.divide(new $(e));
|
|
1444
|
+
if (e instanceof $) {
|
|
1406
1445
|
if (e.monoms.length === 1 && e.variables.length === 0)
|
|
1407
|
-
return s(this,
|
|
1446
|
+
return s(this, dt).call(this, e.monoms[0].coefficient);
|
|
1408
1447
|
{
|
|
1409
1448
|
const { quotient: t, reminder: i } = this.euclidean(e);
|
|
1410
1449
|
if (i.isZero())
|
|
1411
1450
|
return h(this, y, t.monoms), this;
|
|
1412
1451
|
}
|
|
1413
1452
|
} else if (typeof e == "string")
|
|
1414
|
-
return this.divide(new
|
|
1453
|
+
return this.divide(new $(e));
|
|
1415
1454
|
throw new Error(`Cannot divide by ${e}`);
|
|
1416
1455
|
});
|
|
1417
1456
|
a(this, "empty", () => (h(this, y, []), this));
|
|
@@ -1421,21 +1460,21 @@ const C = class C {
|
|
|
1421
1460
|
* returns {quotient: Polynom, reminder: Polynom}
|
|
1422
1461
|
*/
|
|
1423
1462
|
a(this, "euclidean", (e) => {
|
|
1424
|
-
const t = e.variables[0], i = new
|
|
1463
|
+
const t = e.variables[0], i = new $().zero(), n = this.clone().reorder(t);
|
|
1425
1464
|
if (e.variables.length === 0)
|
|
1426
1465
|
return {
|
|
1427
1466
|
quotient: this.clone().divide(e).reduce(),
|
|
1428
|
-
reminder: new
|
|
1467
|
+
reminder: new $().zero()
|
|
1429
1468
|
};
|
|
1430
1469
|
const r = e.monomByDegree(void 0, t), l = e.degree(t);
|
|
1431
|
-
let c,
|
|
1432
|
-
for (; n.degree(t).isGeq(l) &&
|
|
1470
|
+
let c, f = this.degree(t).value * 2;
|
|
1471
|
+
for (; n.degree(t).isGeq(l) && f > 0 && (f--, c = n.monomByDegree(void 0, t).clone().divide(r), !(!c.isZero() && (i.add(c), n.subtract(e.clone().multiply(c)).reduce(), c.degree(t).isZero()))); )
|
|
1433
1472
|
;
|
|
1434
1473
|
return i.reduce(), n.reduce(), { quotient: i, reminder: n };
|
|
1435
1474
|
});
|
|
1436
1475
|
a(this, "evaluate", (e, t) => {
|
|
1437
1476
|
if (t)
|
|
1438
|
-
return s(this,
|
|
1477
|
+
return s(this, $t).call(this, e);
|
|
1439
1478
|
const i = new u().zero();
|
|
1440
1479
|
return s(this, y).forEach((n) => {
|
|
1441
1480
|
i.add(n.evaluate(e, t));
|
|
@@ -1450,7 +1489,7 @@ const C = class C {
|
|
|
1450
1489
|
let t = [], i = this.clone().reorder();
|
|
1451
1490
|
const n = i.commonMonom();
|
|
1452
1491
|
if (i.monomByDegree().coefficient.isStrictlyNegative() && n.coefficient.isStrictlyPositive() && !n.isOne() && n.opposite(), !n.isOne()) {
|
|
1453
|
-
const c = new
|
|
1492
|
+
const c = new $(n);
|
|
1454
1493
|
t = [c.clone()], i = i.euclidean(c).quotient;
|
|
1455
1494
|
}
|
|
1456
1495
|
let r = i.degree().clone().multiply(2).value, l = 1;
|
|
@@ -1464,22 +1503,22 @@ const C = class C {
|
|
|
1464
1503
|
} else {
|
|
1465
1504
|
let c = s(this, It).call(this, i, l, e ?? "x");
|
|
1466
1505
|
for (l = i.degree(e).value; c.length > 0; ) {
|
|
1467
|
-
const
|
|
1468
|
-
if (!i.isDividableBy(
|
|
1506
|
+
const f = c[0];
|
|
1507
|
+
if (!i.isDividableBy(f))
|
|
1469
1508
|
c.shift();
|
|
1470
1509
|
else {
|
|
1471
|
-
const
|
|
1472
|
-
t.push(
|
|
1473
|
-
const
|
|
1474
|
-
return V.isDivisible(
|
|
1510
|
+
const d = i.euclidean(f);
|
|
1511
|
+
t.push(f), i = d.quotient.clone(), c = c.filter((p) => {
|
|
1512
|
+
const w = i.monoms[0], V = i.monoms[i.monoms.length - 1], ce = p.monoms[0], ue = p.monoms[p.monoms.length - 1];
|
|
1513
|
+
return V.isDivisible(ue) ? w.isDivisible(ce) : !1;
|
|
1475
1514
|
});
|
|
1476
1515
|
}
|
|
1477
1516
|
}
|
|
1478
1517
|
}
|
|
1479
|
-
return i.isOne() || t.push(i.clone()), h(this,
|
|
1518
|
+
return i.isOne() || t.push(i.clone()), h(this, je, t), s(this, je);
|
|
1480
1519
|
});
|
|
1481
|
-
a(this, "gcdDenominator", () =>
|
|
1482
|
-
a(this, "gcdNumerator", () =>
|
|
1520
|
+
a(this, "gcdDenominator", () => U.gcd(...this.getDenominators()));
|
|
1521
|
+
a(this, "gcdNumerator", () => U.gcd(...this.getNumerators()));
|
|
1483
1522
|
// Next functions are used for for commonMonom, which is used in the factorize method.
|
|
1484
1523
|
a(this, "getDenominators", () => {
|
|
1485
1524
|
const e = [];
|
|
@@ -1493,7 +1532,7 @@ const C = class C {
|
|
|
1493
1532
|
e.push(t.coefficient.numerator);
|
|
1494
1533
|
return e;
|
|
1495
1534
|
});
|
|
1496
|
-
a(this, "getZeroes", () => this.degree().isZero() ? [] : (this.roots = new
|
|
1535
|
+
a(this, "getZeroes", () => this.degree().isZero() ? [] : (this.roots = new At(this.clone()).solve(), this.roots));
|
|
1497
1536
|
a(this, "integrate", (e, t, i = "x") => {
|
|
1498
1537
|
const n = this.primitive(i), r = {}, l = {};
|
|
1499
1538
|
return r[i] = new u(e), l[i] = new u(t), n.evaluate(l).subtract(n.evaluate(r));
|
|
@@ -1504,7 +1543,7 @@ const C = class C {
|
|
|
1504
1543
|
if (i.includes("(") || i.includes(")"))
|
|
1505
1544
|
return !1;
|
|
1506
1545
|
try {
|
|
1507
|
-
t = new
|
|
1546
|
+
t = new $(e);
|
|
1508
1547
|
} catch {
|
|
1509
1548
|
return !1;
|
|
1510
1549
|
}
|
|
@@ -1519,12 +1558,12 @@ const C = class C {
|
|
|
1519
1558
|
return t.isZero();
|
|
1520
1559
|
}
|
|
1521
1560
|
});
|
|
1522
|
-
a(this, "isEqual", (e) => s(this,
|
|
1523
|
-
a(this, "isOppositeAt", (e) => s(this,
|
|
1561
|
+
a(this, "isEqual", (e) => s(this, Je).call(this, e, "="));
|
|
1562
|
+
a(this, "isOppositeAt", (e) => s(this, Je).call(this, e.clone().opposite(), "="));
|
|
1524
1563
|
a(this, "isReduced", (e) => {
|
|
1525
1564
|
if (!this.isDeveloped(e))
|
|
1526
1565
|
return !1;
|
|
1527
|
-
const t = new
|
|
1566
|
+
const t = new $(e);
|
|
1528
1567
|
if (t.monoms.length > this.monoms.length)
|
|
1529
1568
|
return !1;
|
|
1530
1569
|
for (const i of t.monoms)
|
|
@@ -1532,9 +1571,9 @@ const C = class C {
|
|
|
1532
1571
|
return !1;
|
|
1533
1572
|
return !1;
|
|
1534
1573
|
});
|
|
1535
|
-
a(this, "isSameAs", (e) => s(this,
|
|
1536
|
-
a(this, "lcmDenominator", () =>
|
|
1537
|
-
a(this, "lcmNumerator", () =>
|
|
1574
|
+
a(this, "isSameAs", (e) => s(this, Je).call(this, e, "same"));
|
|
1575
|
+
a(this, "lcmDenominator", () => U.lcm(...this.getDenominators()));
|
|
1576
|
+
a(this, "lcmNumerator", () => U.lcm(...this.getNumerators()));
|
|
1538
1577
|
a(this, "letters", () => {
|
|
1539
1578
|
let e = /* @__PURE__ */ new Set();
|
|
1540
1579
|
for (const t of s(this, y))
|
|
@@ -1556,7 +1595,7 @@ const C = class C {
|
|
|
1556
1595
|
for (const n of s(i, y))
|
|
1557
1596
|
if (n.degree(t).isEqual(e))
|
|
1558
1597
|
return n.clone();
|
|
1559
|
-
return new
|
|
1598
|
+
return new k().zero();
|
|
1560
1599
|
});
|
|
1561
1600
|
// Used in LinearSystem.tex
|
|
1562
1601
|
a(this, "monomByLetter", (e) => {
|
|
@@ -1564,7 +1603,7 @@ const C = class C {
|
|
|
1564
1603
|
for (const i of s(t, y))
|
|
1565
1604
|
if (i.hasVariable(e))
|
|
1566
1605
|
return i.clone();
|
|
1567
|
-
return new
|
|
1606
|
+
return new k().zero();
|
|
1568
1607
|
});
|
|
1569
1608
|
a(this, "monomsByDegree", (e, t) => {
|
|
1570
1609
|
if (e === void 0)
|
|
@@ -1574,8 +1613,8 @@ const C = class C {
|
|
|
1574
1613
|
r.degree(t).isEqual(e) && i.push(r.clone());
|
|
1575
1614
|
return i;
|
|
1576
1615
|
});
|
|
1577
|
-
a(this, "multiply", (e) => e instanceof
|
|
1578
|
-
a(this, "one", () => (h(this, y, []), s(this, y).push(new
|
|
1616
|
+
a(this, "multiply", (e) => e instanceof $ ? s(this, Rt).call(this, e) : e instanceof u ? s(this, pt).call(this, e) : e instanceof k ? s(this, St).call(this, e) : Number.isSafeInteger(e) && typeof e == "number" ? s(this, Bt).call(this, e) : this);
|
|
1617
|
+
a(this, "one", () => (h(this, y, []), s(this, y).push(new k().one()), this));
|
|
1579
1618
|
// ------------------------------------------
|
|
1580
1619
|
a(this, "opposite", () => (h(this, y, s(this, y).map((e) => e.opposite())), this));
|
|
1581
1620
|
a(this, "pow", (e) => {
|
|
@@ -1584,14 +1623,14 @@ const C = class C {
|
|
|
1584
1623
|
if (e < 0)
|
|
1585
1624
|
return this.zero();
|
|
1586
1625
|
if (e === 0)
|
|
1587
|
-
return new
|
|
1626
|
+
return new $();
|
|
1588
1627
|
const t = this.clone();
|
|
1589
1628
|
for (let i = 1; i < e; i++)
|
|
1590
1629
|
this.multiply(t);
|
|
1591
1630
|
return this.reduce();
|
|
1592
1631
|
});
|
|
1593
1632
|
a(this, "primitive", (e) => {
|
|
1594
|
-
const t = new
|
|
1633
|
+
const t = new $();
|
|
1595
1634
|
for (const i of s(this, y))
|
|
1596
1635
|
t.add(i.primitive(e));
|
|
1597
1636
|
return t;
|
|
@@ -1600,14 +1639,15 @@ const C = class C {
|
|
|
1600
1639
|
let e = 0;
|
|
1601
1640
|
for (; e < s(this, y).length; ) {
|
|
1602
1641
|
for (let t = e + 1; t < s(this, y).length; t++)
|
|
1603
|
-
s(this, y)[e].isSameAs(s(this, y)[t]) && (s(this, y)[e].add(s(this, y)[t]), s(this, y).splice(t, 1), s(this, y)[e].isZero() && (s(this, y)[e] = new
|
|
1642
|
+
s(this, y)[e].isSameAs(s(this, y)[t]) && (s(this, y)[e].add(s(this, y)[t]), s(this, y).splice(t, 1), s(this, y)[e].isZero() && (s(this, y)[e] = new k().zero()), t--);
|
|
1604
1643
|
e++;
|
|
1605
1644
|
}
|
|
1606
1645
|
h(this, y, s(this, y).filter((t) => !t.coefficient.isZero()));
|
|
1607
1646
|
for (const t of s(this, y))
|
|
1608
1647
|
t.coefficient.reduce();
|
|
1609
|
-
return this.length === 0 ? new
|
|
1648
|
+
return this.length === 0 ? new $().zero() : this.reorder();
|
|
1610
1649
|
});
|
|
1650
|
+
// ------------------------------------------
|
|
1611
1651
|
a(this, "reorder", (e = "x", t) => {
|
|
1612
1652
|
t === void 0 && (t = !1);
|
|
1613
1653
|
const i = this.variables.filter((n) => n !== e);
|
|
@@ -1616,15 +1656,14 @@ const C = class C {
|
|
|
1616
1656
|
if (l !== c)
|
|
1617
1657
|
return t ? l - c : c - l;
|
|
1618
1658
|
if (i.length > 0)
|
|
1619
|
-
for (const
|
|
1620
|
-
const
|
|
1621
|
-
if (
|
|
1622
|
-
return t ?
|
|
1659
|
+
for (const f of i) {
|
|
1660
|
+
const d = n.degree(f).value, p = r.degree(f).value;
|
|
1661
|
+
if (d !== p)
|
|
1662
|
+
return t ? d - p : p - d;
|
|
1623
1663
|
}
|
|
1624
1664
|
return 0;
|
|
1625
1665
|
}), this;
|
|
1626
1666
|
});
|
|
1627
|
-
// ------------------------------------------
|
|
1628
1667
|
/**
|
|
1629
1668
|
* Replace a variable (letter) by a polynom.
|
|
1630
1669
|
* @param letter
|
|
@@ -1632,22 +1671,22 @@ const C = class C {
|
|
|
1632
1671
|
*/
|
|
1633
1672
|
a(this, "replaceBy", (e, t) => {
|
|
1634
1673
|
let i;
|
|
1635
|
-
const n = new
|
|
1674
|
+
const n = new $().zero();
|
|
1636
1675
|
for (const r of this.monoms)
|
|
1637
1676
|
!r.hasVariable(e) || r.literal[e].isZero() ? n.add(r.clone()) : (i = r.literal[e].clone(), r.removeVariable(e), n.add(t.clone().pow(Math.abs(i.numerator)).multiply(r)));
|
|
1638
1677
|
return h(this, y, n.reduce().monoms), this;
|
|
1639
1678
|
});
|
|
1640
1679
|
a(this, "subtract", (...e) => {
|
|
1641
1680
|
for (const t of e)
|
|
1642
|
-
t instanceof
|
|
1681
|
+
t instanceof $ ? this.add(t.clone().opposite()) : t instanceof k ? s(this, y).push(t.clone().opposite()) : s(this, y).push(new k(t).opposite());
|
|
1643
1682
|
return this.reduce();
|
|
1644
1683
|
});
|
|
1645
1684
|
/**
|
|
1646
1685
|
* Set the polynom to zero.
|
|
1647
1686
|
* @returns {this}
|
|
1648
1687
|
*/
|
|
1649
|
-
a(this, "zero", () => (h(this, y, []), s(this, y).push(new
|
|
1650
|
-
|
|
1688
|
+
a(this, "zero", () => (h(this, y, []), s(this, y).push(new k().zero()), this));
|
|
1689
|
+
m(this, Je, (e, t) => {
|
|
1651
1690
|
t === void 0 && (t = "=");
|
|
1652
1691
|
const i = this.clone().reduce().reorder(), n = e.clone().reduce().reorder();
|
|
1653
1692
|
switch (t) {
|
|
@@ -1659,47 +1698,47 @@ const C = class C {
|
|
|
1659
1698
|
return !1;
|
|
1660
1699
|
}
|
|
1661
1700
|
});
|
|
1662
|
-
|
|
1701
|
+
m(this, dt, (e) => {
|
|
1663
1702
|
for (const t of s(this, y))
|
|
1664
1703
|
t.coefficient.divide(e);
|
|
1665
1704
|
return this;
|
|
1666
1705
|
});
|
|
1667
|
-
|
|
1706
|
+
m(this, Ct, (e) => {
|
|
1668
1707
|
const t = new u(e);
|
|
1669
1708
|
for (const i of s(this, y))
|
|
1670
1709
|
i.coefficient.divide(t);
|
|
1671
1710
|
return this;
|
|
1672
1711
|
});
|
|
1673
|
-
|
|
1712
|
+
m(this, $t, (e) => {
|
|
1674
1713
|
let t = 0;
|
|
1675
1714
|
return s(this, y).forEach((i) => {
|
|
1676
1715
|
t += i.evaluate(e, !0);
|
|
1677
1716
|
}), t;
|
|
1678
1717
|
});
|
|
1679
|
-
|
|
1680
|
-
var
|
|
1681
|
-
let t, i, n, r, l, c,
|
|
1718
|
+
m(this, Pt, (e) => {
|
|
1719
|
+
var w;
|
|
1720
|
+
let t, i, n, r, l, c, f, d, p;
|
|
1682
1721
|
if (this.numberOfVars === 1)
|
|
1683
|
-
return n = this.monomByDegree(2, e).coefficient, r = this.monomByDegree(1, e).coefficient, l = this.monomByDegree(0, e).coefficient, c = r.clone().pow(2).subtract(n.clone().multiply(l).multiply(4)), c.isZero() ? (
|
|
1684
|
-
new
|
|
1685
|
-
new
|
|
1722
|
+
return n = this.monomByDegree(2, e).coefficient, r = this.monomByDegree(1, e).coefficient, l = this.monomByDegree(0, e).coefficient, c = r.clone().pow(2).subtract(n.clone().multiply(l).multiply(4)), c.isZero() ? (f = r.clone().opposite().divide(n.clone().multiply(2)), t = new $(e).subtract(f.display).multiply(f.denominator), i = new $(e).subtract(f.display).multiply(f.denominator), p = n.divide(f.denominator).divide(f.denominator), p.isOne() ? [t, i] : [new $(p.display), t, i]) : c.isPositive() && c.isSquare() ? (f = r.clone().opposite().add(c.clone().sqrt()).divide(n.clone().multiply(2)), d = r.clone().opposite().subtract(c.clone().sqrt()).divide(n.clone().multiply(2)), p = n.divide(f.denominator).divide(d.denominator), p.isOne() ? [
|
|
1723
|
+
new $(e).subtract(f.display).multiply(f.denominator),
|
|
1724
|
+
new $(e).subtract(d.display).multiply(d.denominator)
|
|
1686
1725
|
] : [
|
|
1687
|
-
new
|
|
1688
|
-
new
|
|
1689
|
-
new
|
|
1726
|
+
new $(p.display),
|
|
1727
|
+
new $(e).subtract(f.display).multiply(f.denominator),
|
|
1728
|
+
new $(e).subtract(d.display).multiply(d.denominator)
|
|
1690
1729
|
]) : [this.clone()];
|
|
1691
1730
|
if (n = this.monomByDegree(2, e), r = this.monomByDegree(1, e), l = this.monomByDegree(0, e), n.isLiteralSquare() && l.isLiteralSquare() && r.clone().pow(2).isSameAs(n.clone().multiply(l))) {
|
|
1692
|
-
const V = new
|
|
1693
|
-
let
|
|
1694
|
-
if (
|
|
1695
|
-
for (const
|
|
1696
|
-
|
|
1697
|
-
return
|
|
1731
|
+
const V = new $("x", n.coefficient, r.coefficient, l.coefficient), ce = s(w = V, Pt).call(w, "x"), ue = [];
|
|
1732
|
+
let fe;
|
|
1733
|
+
if (ce.length >= 2) {
|
|
1734
|
+
for (const ye of ce)
|
|
1735
|
+
ye.degree().isZero() ? ue.push(ye.clone()) : (fe = ye.clone(), fe.monoms[0].literal = n.literalSqrt, fe.monoms[1].literal = l.literalSqrt, ue.push(fe.clone()));
|
|
1736
|
+
return ue;
|
|
1698
1737
|
}
|
|
1699
1738
|
}
|
|
1700
1739
|
return [this.clone()];
|
|
1701
1740
|
});
|
|
1702
|
-
|
|
1741
|
+
m(this, _e, (e, t, i, n) => {
|
|
1703
1742
|
let r = "";
|
|
1704
1743
|
for (const l of s(this, y)) {
|
|
1705
1744
|
if (l.coefficient.value === 0)
|
|
@@ -1709,56 +1748,56 @@ const C = class C {
|
|
|
1709
1748
|
}
|
|
1710
1749
|
return i === !0 && this.length > 1 && (e === "tex" ? r = `\\left( ${r} \\right)` : r = `(${r})`), r === "" && (r = "0"), r;
|
|
1711
1750
|
});
|
|
1712
|
-
|
|
1751
|
+
m(this, It, (e, t, i) => {
|
|
1713
1752
|
const n = e.monoms[0].dividers, r = e.monoms[e.monoms.length - 1].dividers, l = [];
|
|
1714
1753
|
return n.forEach((c) => {
|
|
1715
|
-
c.degree(i).isLeq(t) && r.forEach((
|
|
1716
|
-
c.degree(i).isNotEqual(
|
|
1754
|
+
c.degree(i).isLeq(t) && r.forEach((f) => {
|
|
1755
|
+
c.degree(i).isNotEqual(f.degree(i)) && (l.push(new $(c, f)), l.push(new $(c, f.clone().opposite())));
|
|
1717
1756
|
});
|
|
1718
1757
|
}), l;
|
|
1719
1758
|
});
|
|
1720
|
-
|
|
1759
|
+
m(this, pt, (e) => {
|
|
1721
1760
|
for (const t of s(this, y))
|
|
1722
1761
|
t.coefficient.multiply(e);
|
|
1723
1762
|
return this.reduce();
|
|
1724
1763
|
});
|
|
1725
|
-
|
|
1726
|
-
|
|
1764
|
+
m(this, Bt, (e) => s(this, pt).call(this, new u(e)));
|
|
1765
|
+
m(this, St, (e) => {
|
|
1727
1766
|
for (const t of s(this, y))
|
|
1728
1767
|
t.multiply(e);
|
|
1729
1768
|
return this.reduce();
|
|
1730
1769
|
});
|
|
1731
|
-
|
|
1770
|
+
m(this, Rt, (e) => {
|
|
1732
1771
|
const t = [];
|
|
1733
1772
|
for (const i of s(this, y))
|
|
1734
1773
|
for (const n of e.monoms)
|
|
1735
|
-
t.push(
|
|
1774
|
+
t.push(k.xMultiply(i, n));
|
|
1736
1775
|
return h(this, y, t), this.reduce();
|
|
1737
1776
|
});
|
|
1738
1777
|
/**
|
|
1739
1778
|
* Main parse using a shutting yard class
|
|
1740
1779
|
* @param inputStr
|
|
1741
1780
|
*/
|
|
1742
|
-
|
|
1743
|
-
const i = new
|
|
1781
|
+
m(this, Lt, (e) => {
|
|
1782
|
+
const i = new Kt().parse(e).rpn;
|
|
1744
1783
|
this.zero();
|
|
1745
1784
|
const n = [];
|
|
1746
1785
|
for (const r of i)
|
|
1747
|
-
s(this,
|
|
1786
|
+
s(this, Vt).call(this, n, r);
|
|
1748
1787
|
return n.length === 1 && this.add(n[0]), this.reorder();
|
|
1749
1788
|
});
|
|
1750
|
-
|
|
1789
|
+
m(this, Vt, (e, t) => {
|
|
1751
1790
|
switch (t.tokenType) {
|
|
1752
|
-
case
|
|
1753
|
-
e.push(new
|
|
1791
|
+
case g.COEFFICIENT:
|
|
1792
|
+
e.push(new $(t.token));
|
|
1754
1793
|
break;
|
|
1755
|
-
case
|
|
1756
|
-
e.push(new
|
|
1794
|
+
case g.VARIABLE:
|
|
1795
|
+
e.push(new $().add(new k(t.token)));
|
|
1757
1796
|
break;
|
|
1758
|
-
case
|
|
1797
|
+
case g.CONSTANT:
|
|
1759
1798
|
console.log("Actually, not supported - will be added later !");
|
|
1760
1799
|
break;
|
|
1761
|
-
case
|
|
1800
|
+
case g.OPERATION:
|
|
1762
1801
|
if (e.length >= 2) {
|
|
1763
1802
|
const i = e.pop(), n = e.pop();
|
|
1764
1803
|
if (n === void 0 || i === void 0)
|
|
@@ -1789,18 +1828,36 @@ const C = class C {
|
|
|
1789
1828
|
} else
|
|
1790
1829
|
throw new Error("Error parsing the polynom");
|
|
1791
1830
|
break;
|
|
1792
|
-
case
|
|
1831
|
+
case g.MONOM:
|
|
1793
1832
|
console.error("The monom token should not appear here");
|
|
1794
1833
|
break;
|
|
1795
|
-
case
|
|
1834
|
+
case g.FUNCTION:
|
|
1796
1835
|
console.error("The function token should not appear here - might be introduced later.");
|
|
1797
1836
|
break;
|
|
1798
1837
|
}
|
|
1799
1838
|
});
|
|
1800
|
-
return h(this, y, []), h(this,
|
|
1839
|
+
return h(this, y, []), h(this, je, []), h(this, Ke, []), e !== void 0 && this.parse(e, ...t), this;
|
|
1840
|
+
}
|
|
1841
|
+
get tex() {
|
|
1842
|
+
return s(this, _e).call(this, "tex");
|
|
1801
1843
|
}
|
|
1802
1844
|
get display() {
|
|
1803
|
-
return s(this,
|
|
1845
|
+
return s(this, _e).call(this);
|
|
1846
|
+
}
|
|
1847
|
+
fromCoefficients(...e) {
|
|
1848
|
+
h(this, y, []);
|
|
1849
|
+
const t = "x";
|
|
1850
|
+
return e.reverse().forEach((i, n) => {
|
|
1851
|
+
const r = new k();
|
|
1852
|
+
r.coefficient = new u(i), r.setLetter(t, n), s(this, y).push(r);
|
|
1853
|
+
}), this;
|
|
1854
|
+
}
|
|
1855
|
+
getCoefficients() {
|
|
1856
|
+
const e = this.clone().reorder(), t = this.degree().value + 1, i = new Array(t).fill(new u(0));
|
|
1857
|
+
return e.monoms.forEach((n) => {
|
|
1858
|
+
const r = t - n.degree().value - 1;
|
|
1859
|
+
i[r] = n.coefficient.clone();
|
|
1860
|
+
}), i;
|
|
1804
1861
|
}
|
|
1805
1862
|
hasVariable(e) {
|
|
1806
1863
|
return this.variables.includes(e);
|
|
@@ -1830,49 +1887,38 @@ const C = class C {
|
|
|
1830
1887
|
return this.variables.length;
|
|
1831
1888
|
}
|
|
1832
1889
|
get plotFunction() {
|
|
1833
|
-
return s(this,
|
|
1890
|
+
return s(this, _e).call(this, "tex", !1, !1, !0);
|
|
1834
1891
|
}
|
|
1835
1892
|
root() {
|
|
1836
1893
|
throw new Error("Cannot take the root from a polynom");
|
|
1837
1894
|
}
|
|
1838
1895
|
get roots() {
|
|
1839
|
-
return s(this,
|
|
1896
|
+
return s(this, ft) ? s(this, Ke) : this.getZeroes();
|
|
1840
1897
|
}
|
|
1841
1898
|
set roots(e) {
|
|
1842
|
-
h(this,
|
|
1899
|
+
h(this, ft, !0), h(this, Ke, e);
|
|
1843
1900
|
}
|
|
1844
1901
|
sqrt() {
|
|
1845
1902
|
throw new Error("Cannot take the square root from a polynom");
|
|
1846
1903
|
}
|
|
1847
|
-
tableOfSigns(
|
|
1848
|
-
const
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
"",
|
|
1864
|
-
this.evaluate(d.value - 1, !0) < 0 ? "-" : "+",
|
|
1865
|
-
0,
|
|
1866
|
-
l
|
|
1867
|
-
)), r = g * 2 + 1, l = f === i.length - 1 ? n.length : t.findIndex((V) => V.value === i[f + 1].value) * 2 + 1;
|
|
1868
|
-
const N = f === i.length - 1 ? d.value + 1 : (d.value + i[f + 1].value) / 2;
|
|
1869
|
-
c = this.evaluate(N, !0) < 0 ? "-" : "+", n[r] = "z", n = Re(n, "", c, r, l), r = +l, l = n.length;
|
|
1904
|
+
tableOfSigns() {
|
|
1905
|
+
const e = this.roots;
|
|
1906
|
+
let t = new Array(2 * e.length + 1).fill("").map((i, n) => n % 2 === 0 ? "" : "z");
|
|
1907
|
+
if (t.length === 1) {
|
|
1908
|
+
const [i] = this.getCoefficients().map((n) => n.value);
|
|
1909
|
+
t = Et(t, "", i > 0 ? "+" : "-");
|
|
1910
|
+
} else if (this.degree().isOne()) {
|
|
1911
|
+
const [i] = this.getCoefficients().map((n) => n.value);
|
|
1912
|
+
t[0] = i > 0 ? "-" : "+", t[1] = "z", t[2] = i > 0 ? "+" : "-";
|
|
1913
|
+
} else
|
|
1914
|
+
[
|
|
1915
|
+
e[0].value - 1,
|
|
1916
|
+
...e.map((n, r) => r === e.length - 1 ? e[r].value + 1 : (e[r].value + e[r + 1].value) / 2)
|
|
1917
|
+
].forEach((n, r) => {
|
|
1918
|
+
const l = this.evaluate({ x: n }, !0);
|
|
1919
|
+
t[r * 2] = l > 0 ? "+" : "-";
|
|
1870
1920
|
});
|
|
1871
|
-
}
|
|
1872
|
-
return { roots: t, signs: n };
|
|
1873
|
-
}
|
|
1874
|
-
get tex() {
|
|
1875
|
-
return s(this, Je).call(this, "tex");
|
|
1921
|
+
return { roots: e, signs: t };
|
|
1876
1922
|
}
|
|
1877
1923
|
get variables() {
|
|
1878
1924
|
let e = [];
|
|
@@ -1884,60 +1930,62 @@ const C = class C {
|
|
|
1884
1930
|
return this.getZeroes();
|
|
1885
1931
|
}
|
|
1886
1932
|
};
|
|
1887
|
-
|
|
1933
|
+
je = new WeakMap(), y = new WeakMap(), Ke = new WeakMap(), ft = new WeakMap(), Je = new WeakMap(), dt = new WeakMap(), Ct = new WeakMap(), $t = new WeakMap(), Pt = new WeakMap(), _e = new WeakMap(), It = new WeakMap(), pt = new WeakMap(), Bt = new WeakMap(), St = new WeakMap(), Rt = new WeakMap(), zt = new WeakSet(), Mi = function(e, ...t) {
|
|
1888
1934
|
if (t.length === 0) {
|
|
1889
1935
|
if (e = "" + e, e !== "" && !isNaN(Number(e))) {
|
|
1890
1936
|
this.empty();
|
|
1891
|
-
const i = new
|
|
1937
|
+
const i = new k(e);
|
|
1892
1938
|
return this.add(i), this;
|
|
1893
1939
|
}
|
|
1894
|
-
return s(this,
|
|
1940
|
+
return s(this, Lt).call(this, e);
|
|
1895
1941
|
} else if (/^[a-z]+/.test(e)) {
|
|
1896
1942
|
this.empty();
|
|
1897
1943
|
const i = t.map((n) => new u(n));
|
|
1898
1944
|
if (e.length > 1) {
|
|
1899
1945
|
const n = e.split("");
|
|
1946
|
+
if (n.length < t.length - 2)
|
|
1947
|
+
throw new Error("Too many factors for too few variables !");
|
|
1900
1948
|
let r = 0;
|
|
1901
1949
|
for (const l of i) {
|
|
1902
|
-
const c = new
|
|
1950
|
+
const c = new k();
|
|
1903
1951
|
c.coefficient = l.clone(), c.literalStr = n[r] || "", this.add(c), r++;
|
|
1904
1952
|
}
|
|
1905
1953
|
} else {
|
|
1906
1954
|
let n = i.length - 1;
|
|
1907
1955
|
for (const r of i) {
|
|
1908
|
-
const l = new
|
|
1956
|
+
const l = new k();
|
|
1909
1957
|
l.coefficient = r.clone(), l.literalStr = `${e}^${n}`, this.add(l), n--;
|
|
1910
1958
|
}
|
|
1911
1959
|
}
|
|
1912
1960
|
return this;
|
|
1913
1961
|
} else
|
|
1914
1962
|
return this.zero();
|
|
1915
|
-
},
|
|
1916
|
-
let O =
|
|
1917
|
-
var
|
|
1918
|
-
const
|
|
1963
|
+
}, Lt = new WeakMap(), Vt = new WeakMap();
|
|
1964
|
+
let O = $;
|
|
1965
|
+
var q, M, re, Dt, et, Zt;
|
|
1966
|
+
const Ne = class Ne {
|
|
1919
1967
|
constructor(e, t, i) {
|
|
1920
1968
|
// Left part of the equation
|
|
1921
|
-
|
|
1969
|
+
m(this, q);
|
|
1922
1970
|
// Right part of the equation
|
|
1923
|
-
|
|
1971
|
+
m(this, M);
|
|
1924
1972
|
// Signe of the equation
|
|
1925
|
-
|
|
1973
|
+
m(this, re);
|
|
1926
1974
|
// ------------------------------------------
|
|
1927
1975
|
a(this, "parse", (e) => {
|
|
1928
1976
|
const t = s(this, Dt).call(this, e);
|
|
1929
1977
|
if (t === !1)
|
|
1930
1978
|
throw new Error("The equation is not valid (no sign found)");
|
|
1931
1979
|
const i = e.split(t);
|
|
1932
|
-
return this.create(new O(i[0]), new O(i[1]), s(this,
|
|
1980
|
+
return this.create(new O(i[0]), new O(i[1]), s(this, et).call(this, t));
|
|
1933
1981
|
});
|
|
1934
|
-
a(this, "create", (e, t, i) => (h(this,
|
|
1935
|
-
a(this, "clone", () => new
|
|
1982
|
+
a(this, "create", (e, t, i) => (h(this, q, e), h(this, M, t), h(this, re, s(this, et).call(this, i ?? "=")), this));
|
|
1983
|
+
a(this, "clone", () => new Ne(s(this, q).clone(), s(this, M).clone(), s(this, re)));
|
|
1936
1984
|
/**
|
|
1937
1985
|
* Get the degree of the equation
|
|
1938
1986
|
* @param letter
|
|
1939
1987
|
*/
|
|
1940
|
-
a(this, "degree", (e) => u.max(s(this,
|
|
1988
|
+
a(this, "degree", (e) => u.max(s(this, q).degree(e), s(this, M).degree(e)));
|
|
1941
1989
|
/**
|
|
1942
1990
|
* divide an equation by a given value (transformed as a fraction)
|
|
1943
1991
|
*
|
|
@@ -1968,7 +2016,7 @@ const Ee = class Ee {
|
|
|
1968
2016
|
/**
|
|
1969
2017
|
* Determine if the equation contains more than one letter/variable.
|
|
1970
2018
|
*/
|
|
1971
|
-
a(this, "isMultiVariable", () => s(this,
|
|
2019
|
+
a(this, "isMultiVariable", () => s(this, q).isMultiVariable || s(this, M).isMultiVariable);
|
|
1972
2020
|
// -----------------------------------------------
|
|
1973
2021
|
// Equations helpers
|
|
1974
2022
|
a(this, "isEqualTo", (e) => {
|
|
@@ -1983,47 +2031,47 @@ const Ee = class Ee {
|
|
|
1983
2031
|
if (!this.degree(e).isOne() || this.isMultiVariable())
|
|
1984
2032
|
return !1;
|
|
1985
2033
|
let t;
|
|
1986
|
-
s(this,
|
|
1987
|
-
const i = [...s(this,
|
|
2034
|
+
s(this, q).subtract(s(this, M)), s(this, M).zero();
|
|
2035
|
+
const i = [...s(this, q).monoms];
|
|
1988
2036
|
for (const r of i)
|
|
1989
|
-
r.hasVariable(e) || (t = r.clone(), s(this,
|
|
1990
|
-
if (s(this,
|
|
2037
|
+
r.hasVariable(e) || (t = r.clone(), s(this, q).subtract(t), s(this, M).subtract(t));
|
|
2038
|
+
if (s(this, q).length !== 1)
|
|
1991
2039
|
return !1;
|
|
1992
|
-
const n = s(this,
|
|
1993
|
-
return s(this,
|
|
2040
|
+
const n = s(this, q).monoms[0].coefficient.clone();
|
|
2041
|
+
return s(this, q).divide(n), s(this, M).divide(n), this;
|
|
1994
2042
|
});
|
|
1995
2043
|
// -----------------------------------------------
|
|
1996
2044
|
// Equations operations
|
|
1997
2045
|
// -----------------------------------------------
|
|
1998
|
-
a(this, "letters", () => [.../* @__PURE__ */ new Set([...s(this,
|
|
2046
|
+
a(this, "letters", () => [.../* @__PURE__ */ new Set([...s(this, q).letters(), ...s(this, M).letters()])]);
|
|
1999
2047
|
// -----------------------------------------------
|
|
2000
2048
|
/**
|
|
2001
2049
|
* Reorder will move all monoms containing a letter on the left, all the other on the right.
|
|
2002
2050
|
*/
|
|
2003
|
-
a(this, "moveLeft", () => (s(this,
|
|
2051
|
+
a(this, "moveLeft", () => (s(this, q).subtract(s(this, M)), s(this, M).zero(), this));
|
|
2004
2052
|
/**
|
|
2005
2053
|
* Multiple an equation by a fraction value.
|
|
2006
2054
|
* @param value
|
|
2007
2055
|
*/
|
|
2008
2056
|
a(this, "multiply", (e) => {
|
|
2009
2057
|
const t = new u(e);
|
|
2010
|
-
return s(this,
|
|
2058
|
+
return s(this, q).multiply(t), s(this, M).multiply(t), s(this, re) !== "=" && t.sign() === -1 && s(this, Zt).call(this), this;
|
|
2011
2059
|
});
|
|
2012
|
-
a(this, "opposite", () => (h(this,
|
|
2013
|
-
a(this, "reorder", (e) => (s(this,
|
|
2060
|
+
a(this, "opposite", () => (h(this, q, s(this, q).opposite()), h(this, M, s(this, M).opposite()), this));
|
|
2061
|
+
a(this, "reorder", (e) => (s(this, q).subtract(s(this, M)), s(this, M).zero(), s(this, q).reorder(), e ? this : (s(this, q).monoms.filter((t) => t.degree().isZero()).forEach((t) => {
|
|
2014
2062
|
const i = t.clone();
|
|
2015
|
-
s(this,
|
|
2016
|
-
}), s(this,
|
|
2063
|
+
s(this, q).subtract(i), s(this, M).subtract(i);
|
|
2064
|
+
}), s(this, q).reorder(), s(this, M).reorder(), this)));
|
|
2017
2065
|
// ------------------------------------------
|
|
2018
|
-
a(this, "replaceBy", (e, t) => (s(this,
|
|
2066
|
+
a(this, "replaceBy", (e, t) => (s(this, q).replaceBy(e, t), s(this, M).replaceBy(e, t), this));
|
|
2019
2067
|
/**
|
|
2020
2068
|
* Multiply by the lcm denominator and divide by the gcm numerators.
|
|
2021
2069
|
*/
|
|
2022
|
-
a(this, "simplify", () => (this.multiply(
|
|
2070
|
+
a(this, "simplify", () => (this.multiply(U.lcm(...s(this, q).getDenominators(), ...s(this, M).getDenominators())), this.divide(U.gcd(...s(this, q).getNumerators(), ...s(this, M).getNumerators())), this));
|
|
2023
2071
|
// -----------------------------------------------
|
|
2024
|
-
a(this, "solve", () => new
|
|
2072
|
+
a(this, "solve", () => new At(this.clone()).solve());
|
|
2025
2073
|
a(this, "test", (e) => this.left.evaluate(e).isEqual(this.right.evaluate(e)));
|
|
2026
|
-
|
|
2074
|
+
m(this, Dt, (e) => {
|
|
2027
2075
|
if (e.includes("geq"))
|
|
2028
2076
|
return e.includes("\\geq") ? "\\geq" : "geq";
|
|
2029
2077
|
if (e.includes("leq"))
|
|
@@ -2046,10 +2094,10 @@ const Ee = class Ee {
|
|
|
2046
2094
|
});
|
|
2047
2095
|
// -----------------------------------------------
|
|
2048
2096
|
// Equations solving algorithms
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
if (h(this,
|
|
2052
|
-
if (e instanceof
|
|
2097
|
+
m(this, et, (e) => e === void 0 ? "=" : e.includes("geq") || e.includes(">=") || e.includes("=>") ? ">=" : e.includes(">") ? ">" : e.includes("leq") || e.includes("<=") || e.includes("=<") ? "<=" : e.includes("<") ? "<" : "=");
|
|
2098
|
+
m(this, Zt, () => s(this, re) === "=" ? this : s(this, re).includes("<") ? (s(this, re).replace("<", ">"), this) : s(this, re).includes(">") ? (s(this, re).replace(">", "<"), this) : this);
|
|
2099
|
+
if (h(this, q, new O().zero()), h(this, M, new O().zero()), h(this, re, "="), e !== void 0 && t === void 0) {
|
|
2100
|
+
if (e instanceof Ne)
|
|
2053
2101
|
return e.clone();
|
|
2054
2102
|
typeof e == "string" && this.parse(e);
|
|
2055
2103
|
} else e !== void 0 && t !== void 0 && (this.left = new O(e), this.right = new O(t));
|
|
@@ -2064,12 +2112,12 @@ const Ee = class Ee {
|
|
|
2064
2112
|
* @param value | Polynom | Monom | Fraction | string | monom
|
|
2065
2113
|
*/
|
|
2066
2114
|
add(e) {
|
|
2067
|
-
if (e instanceof
|
|
2068
|
-
return s(this,
|
|
2069
|
-
if (typeof e == "string" && !
|
|
2070
|
-
return this.add(new
|
|
2115
|
+
if (e instanceof Ne)
|
|
2116
|
+
return s(this, q).add(e.left), s(this, M).add(e.right), this;
|
|
2117
|
+
if (typeof e == "string" && !Ne.isEquationString(e))
|
|
2118
|
+
return this.add(new Ne(e));
|
|
2071
2119
|
const t = new O(e);
|
|
2072
|
-
return s(this,
|
|
2120
|
+
return s(this, q).add(t), s(this, M).add(t), this;
|
|
2073
2121
|
}
|
|
2074
2122
|
/**
|
|
2075
2123
|
* Create an Equation using two polynoms.
|
|
@@ -2078,29 +2126,29 @@ const Ee = class Ee {
|
|
|
2078
2126
|
* @param asNumeric
|
|
2079
2127
|
*/
|
|
2080
2128
|
evaluate(e, t) {
|
|
2081
|
-
const i = s(this,
|
|
2129
|
+
const i = s(this, q).evaluate(e, t), n = s(this, M).evaluate(e, t);
|
|
2082
2130
|
return t ? i === n : i.isEqual(n);
|
|
2083
2131
|
}
|
|
2084
2132
|
isEqual(e) {
|
|
2085
|
-
const t = new
|
|
2086
|
-
return t.left.isEqual(s(this,
|
|
2133
|
+
const t = new Ne(e);
|
|
2134
|
+
return t.left.isEqual(s(this, q)) && t.right.isEqual(s(this, M));
|
|
2087
2135
|
}
|
|
2088
2136
|
pow(e) {
|
|
2089
|
-
return s(this,
|
|
2137
|
+
return s(this, q).pow(e), s(this, M).pow(e), this;
|
|
2090
2138
|
}
|
|
2091
2139
|
reduce() {
|
|
2092
|
-
return this.moveLeft(), s(this,
|
|
2140
|
+
return this.moveLeft(), s(this, q).reduce(), this.simplify(), s(this, q).monoms[0].coefficient.isNegative() && this.multiply(-1), this;
|
|
2093
2141
|
}
|
|
2094
2142
|
split() {
|
|
2095
|
-
return [s(this,
|
|
2143
|
+
return [s(this, q).clone(), s(this, M).clone()];
|
|
2096
2144
|
}
|
|
2097
2145
|
subtract(e) {
|
|
2098
|
-
if (e instanceof
|
|
2099
|
-
return s(this,
|
|
2100
|
-
if (typeof e == "string" && !
|
|
2101
|
-
return this.subtract(new
|
|
2146
|
+
if (e instanceof Ne)
|
|
2147
|
+
return s(this, q).subtract(e.left), s(this, M).subtract(e.right), this;
|
|
2148
|
+
if (typeof e == "string" && !Ne.isEquationString(e))
|
|
2149
|
+
return this.subtract(new Ne(e));
|
|
2102
2150
|
const t = new O(e);
|
|
2103
|
-
return s(this,
|
|
2151
|
+
return s(this, q).subtract(t), s(this, M).subtract(t), this;
|
|
2104
2152
|
}
|
|
2105
2153
|
static isEquationString(e) {
|
|
2106
2154
|
return e.includes("=") || e.includes("<") || e.includes(">") || e.includes("<=") || e.includes(">=");
|
|
@@ -2110,58 +2158,51 @@ const Ee = class Ee {
|
|
|
2110
2158
|
return t === !0 && n.sort((r, l) => r.value - l.value), n;
|
|
2111
2159
|
}
|
|
2112
2160
|
get display() {
|
|
2113
|
-
return `${s(this,
|
|
2161
|
+
return `${s(this, q).display}${this.signAsTex}${s(this, M).display}`;
|
|
2114
2162
|
}
|
|
2115
2163
|
// Getter and setter
|
|
2116
2164
|
get left() {
|
|
2117
|
-
return s(this,
|
|
2165
|
+
return s(this, q);
|
|
2118
2166
|
}
|
|
2119
2167
|
set left(e) {
|
|
2120
|
-
h(this,
|
|
2168
|
+
h(this, q, e);
|
|
2121
2169
|
}
|
|
2122
2170
|
get numberOfVars() {
|
|
2123
2171
|
return this.variables.length;
|
|
2124
2172
|
}
|
|
2125
2173
|
get right() {
|
|
2126
|
-
return s(this,
|
|
2174
|
+
return s(this, M);
|
|
2127
2175
|
}
|
|
2128
2176
|
set right(e) {
|
|
2129
|
-
h(this,
|
|
2177
|
+
h(this, M, e);
|
|
2130
2178
|
}
|
|
2131
2179
|
// ------------------------------------------
|
|
2132
2180
|
get sign() {
|
|
2133
|
-
return s(this,
|
|
2181
|
+
return s(this, re);
|
|
2134
2182
|
}
|
|
2135
2183
|
set sign(e) {
|
|
2136
|
-
h(this,
|
|
2184
|
+
h(this, re, s(this, et).call(this, e));
|
|
2137
2185
|
}
|
|
2138
2186
|
get signAsTex() {
|
|
2139
|
-
return s(this,
|
|
2187
|
+
return s(this, re) === ">=" ? "\\geq" : s(this, re) === "<=" ? "\\leq" : s(this, re);
|
|
2140
2188
|
}
|
|
2141
2189
|
get tex() {
|
|
2142
|
-
return `${s(this,
|
|
2190
|
+
return `${s(this, q).tex}${this.signAsTex}${s(this, M).tex}`;
|
|
2143
2191
|
}
|
|
2144
2192
|
get variables() {
|
|
2145
|
-
return [...new Set(s(this,
|
|
2193
|
+
return [...new Set(s(this, M).variables.concat(s(this, q).variables))];
|
|
2146
2194
|
}
|
|
2147
2195
|
};
|
|
2148
|
-
|
|
2149
|
-
let H =
|
|
2150
|
-
var
|
|
2196
|
+
q = new WeakMap(), M = new WeakMap(), re = new WeakMap(), Dt = new WeakMap(), et = new WeakMap(), Zt = new WeakMap();
|
|
2197
|
+
let H = Ne;
|
|
2198
|
+
var Te, Ae, be, tt;
|
|
2151
2199
|
const ve = class ve {
|
|
2152
2200
|
constructor(e, t) {
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
h(this, Te, e.polynom.clone()), h(this, Ae, e.power.clone());
|
|
2159
|
-
else if (typeof e == "string" && t === void 0) {
|
|
2160
|
-
const [i, n = "1"] = e.split("^");
|
|
2161
|
-
h(this, Te, new O(i)), h(this, Ae, new u(n.replace("(", "").replace(")", "")));
|
|
2162
|
-
} else
|
|
2163
|
-
h(this, Te, new O(e)), h(this, Ae, new u(t ?? 1));
|
|
2164
|
-
return h(this, Ne, 1), this;
|
|
2201
|
+
m(this, Te);
|
|
2202
|
+
m(this, Ae);
|
|
2203
|
+
m(this, be);
|
|
2204
|
+
m(this, tt, !1);
|
|
2205
|
+
return e instanceof ve ? (h(this, Ae, e.polynom.clone()), h(this, be, e.power.clone()), t !== void 0 && s(this, be).multiply(new u(t))) : e !== void 0 ? (h(this, Ae, new O(e)), h(this, be, new u(t ?? 1))) : (h(this, Ae, new O()), h(this, be, new u(1))), h(this, Te, 1), this;
|
|
2165
2206
|
}
|
|
2166
2207
|
parse() {
|
|
2167
2208
|
throw new Error("Method not implemented.");
|
|
@@ -2169,27 +2210,30 @@ const ve = class ve {
|
|
|
2169
2210
|
clone() {
|
|
2170
2211
|
return new ve(this);
|
|
2171
2212
|
}
|
|
2213
|
+
fromPolynom(e) {
|
|
2214
|
+
return h(this, Ae, new O(e)), h(this, be, new u(1)), this;
|
|
2215
|
+
}
|
|
2172
2216
|
get tex() {
|
|
2173
2217
|
const e = this.power.numerator, t = this.power.denominator;
|
|
2174
2218
|
let i, n;
|
|
2175
|
-
return s(this,
|
|
2219
|
+
return s(this, Te) === 0 && t > 1 ? (i = `\\sqrt${t === 2 ? "" : `[ ${t} ]`}{ ${this.polynom.tex} }`, n = e === 1 ? "" : `^{ ${e} }`) : (i = s(this, tt) && this.power.isOne() ? this.polynom.tex : yi(this.polynom.tex), n = t === 1 && e === 1 ? "" : `^{ ${this.power.tex} }`), i = `${i}${n}`, s(this, Te) === 0 && e < 0 && (i = `\\frac{ 1 }{ ${i} }`), i;
|
|
2176
2220
|
}
|
|
2177
2221
|
get display() {
|
|
2178
2222
|
const e = this.power.numerator, t = this.power.denominator;
|
|
2179
2223
|
let i, n;
|
|
2180
|
-
return s(this,
|
|
2224
|
+
return s(this, Te) === 0 && t > 1 ? (i = `${t === 2 ? "sqrt" : `root(${t})`}(${this.polynom.display})`, n = e === 1 ? "" : `^(${e})`) : (i = s(this, tt) && this.power.isOne() ? this.polynom.display : yi(this.polynom.display, !1), n = t === 1 && e === 1 ? "" : `^(${this.power.display})`), i = `${i}${n}`, s(this, Te) === 0 && e < 0 && (i = `1/(${i})`), i;
|
|
2181
2225
|
}
|
|
2182
2226
|
add() {
|
|
2183
2227
|
throw new Error("Adding two factors is not possible");
|
|
2184
2228
|
}
|
|
2185
2229
|
get asSingle() {
|
|
2186
|
-
return h(this,
|
|
2230
|
+
return h(this, tt, !0), this;
|
|
2187
2231
|
}
|
|
2188
2232
|
degree(e) {
|
|
2189
2233
|
return this.polynom.degree(e).multiply(this.power);
|
|
2190
2234
|
}
|
|
2191
2235
|
derivative() {
|
|
2192
|
-
return this.power.isZero() ? [new ve("0"
|
|
2236
|
+
return this.power.isZero() ? [new ve("0")] : this.power.isOne() ? [new ve(this.polynom.clone().derivative())] : [
|
|
2193
2237
|
new ve(this.power.clone()),
|
|
2194
2238
|
new ve(this.polynom.clone().derivative()),
|
|
2195
2239
|
new ve(this.polynom.clone(), this.power.clone().subtract(1))
|
|
@@ -2239,25 +2283,25 @@ const ve = class ve {
|
|
|
2239
2283
|
throw new Error("The two factors must be the same");
|
|
2240
2284
|
}
|
|
2241
2285
|
one() {
|
|
2242
|
-
return s(this,
|
|
2286
|
+
return s(this, Ae).one(), s(this, be).one(), this;
|
|
2243
2287
|
}
|
|
2244
2288
|
opposite() {
|
|
2245
2289
|
throw new Error("Method not implemented.");
|
|
2246
2290
|
}
|
|
2247
2291
|
get polynom() {
|
|
2248
|
-
return s(this,
|
|
2292
|
+
return s(this, Ae);
|
|
2249
2293
|
}
|
|
2250
2294
|
set polynom(e) {
|
|
2251
|
-
h(this,
|
|
2295
|
+
h(this, Ae, e);
|
|
2252
2296
|
}
|
|
2253
2297
|
pow(e) {
|
|
2254
2298
|
return this.power.multiply(e), this;
|
|
2255
2299
|
}
|
|
2256
2300
|
get power() {
|
|
2257
|
-
return s(this,
|
|
2301
|
+
return s(this, be);
|
|
2258
2302
|
}
|
|
2259
2303
|
set power(e) {
|
|
2260
|
-
h(this,
|
|
2304
|
+
h(this, be, new u(e));
|
|
2261
2305
|
}
|
|
2262
2306
|
primitive() {
|
|
2263
2307
|
throw new Error("Method not implemented.");
|
|
@@ -2274,48 +2318,48 @@ const ve = class ve {
|
|
|
2274
2318
|
subtract() {
|
|
2275
2319
|
throw new Error("Subtracting two factors is not possible");
|
|
2276
2320
|
}
|
|
2277
|
-
tableOfSigns(
|
|
2278
|
-
const
|
|
2279
|
-
return
|
|
2321
|
+
tableOfSigns() {
|
|
2322
|
+
const e = this.power.clone().reduce(), t = this.polynom.tableOfSigns();
|
|
2323
|
+
return e.isStrictlyNegative() && (t.signs = Et(t.signs, "z", "d")), e.denominator % 2 === 0 ? t.signs = Et(t.signs, "-", "h") : e.numerator % 2 === 0 && (t.signs = Et(t.signs, "-", "+")), { roots: t.roots, signs: t.signs };
|
|
2280
2324
|
}
|
|
2281
2325
|
get variables() {
|
|
2282
2326
|
return this.polynom.variables;
|
|
2283
2327
|
}
|
|
2284
2328
|
get withPower() {
|
|
2285
|
-
return h(this,
|
|
2329
|
+
return h(this, Te, 1), this;
|
|
2286
2330
|
}
|
|
2287
2331
|
get withRoot() {
|
|
2288
|
-
return h(this,
|
|
2332
|
+
return h(this, Te, 0), this;
|
|
2289
2333
|
}
|
|
2290
2334
|
zero() {
|
|
2291
|
-
return s(this,
|
|
2335
|
+
return s(this, Ae).zero(), s(this, be).one(), this;
|
|
2292
2336
|
}
|
|
2293
2337
|
};
|
|
2294
|
-
|
|
2295
|
-
let
|
|
2296
|
-
var
|
|
2297
|
-
const
|
|
2338
|
+
Te = new WeakMap(), Ae = new WeakMap(), be = new WeakMap(), tt = new WeakMap();
|
|
2339
|
+
let ae = ve;
|
|
2340
|
+
var lt = /* @__PURE__ */ ((o) => (o[o.ROOT = 0] = "ROOT", o[o.POWER = 1] = "POWER", o))(lt || {}), D, $e, Ft, jt;
|
|
2341
|
+
const Xe = class Xe {
|
|
2298
2342
|
constructor(...e) {
|
|
2299
|
-
|
|
2343
|
+
m(this, D);
|
|
2300
2344
|
// Determine the letters in the linear system, usually ['x', 'y']
|
|
2301
|
-
|
|
2302
|
-
a(this, "parse", (...e) => (h(this, D, e.map((t) => new H(t))), s(this,
|
|
2303
|
-
a(this, "clone", () => new
|
|
2345
|
+
m(this, $e);
|
|
2346
|
+
a(this, "parse", (...e) => (h(this, D, e.map((t) => new H(t))), s(this, Ft).call(this), this));
|
|
2347
|
+
a(this, "clone", () => new Xe().parse(...s(this, D).map((e) => e.clone())));
|
|
2304
2348
|
a(this, "buildTex", (e, t) => {
|
|
2305
2349
|
let i, n, r = [];
|
|
2306
2350
|
const l = [];
|
|
2307
|
-
for (const
|
|
2308
|
-
r = r.concat(
|
|
2351
|
+
for (const f of e)
|
|
2352
|
+
r = r.concat(f.letters());
|
|
2309
2353
|
r = [...new Set(r)], r.sort();
|
|
2310
|
-
for (let
|
|
2311
|
-
const
|
|
2354
|
+
for (let f = 0; f < e.length; f++) {
|
|
2355
|
+
const d = e[f];
|
|
2312
2356
|
i = [];
|
|
2313
|
-
for (const
|
|
2314
|
-
n =
|
|
2315
|
-
if (i.push("="), i.push(
|
|
2357
|
+
for (const p of r)
|
|
2358
|
+
n = d.left.monomByLetter(p), i.length === 0 ? i.push(n.isZero() ? "" : n.tex) : i.push(n.isZero() ? "" : (n.coefficient.sign() === 1 ? "+" : "") + n.tex);
|
|
2359
|
+
if (i.push("="), i.push(d.right.tex), (t == null ? void 0 : t[f]) !== void 0) {
|
|
2316
2360
|
i[i.length - 1] = i[i.length - 1] + " \\phantom{\\quad}";
|
|
2317
|
-
for (const
|
|
2318
|
-
i.push(`\\ \\cdot\\ ${
|
|
2361
|
+
for (const p of t[f])
|
|
2362
|
+
i.push(`\\ \\cdot\\ ${p.startsWith("-") ? "\\left(" + p + "\\right)" : p}`);
|
|
2319
2363
|
}
|
|
2320
2364
|
l.push(i.join("&"));
|
|
2321
2365
|
}
|
|
@@ -2341,16 +2385,16 @@ const He = class He {
|
|
|
2341
2385
|
if (l === n)
|
|
2342
2386
|
continue;
|
|
2343
2387
|
const c = i[l][n].clone().opposite();
|
|
2344
|
-
for (let
|
|
2345
|
-
i[l][
|
|
2346
|
-
if (i[l].slice(0, i[l].length - 1).every((
|
|
2388
|
+
for (let f = 0; f < i[l].length; f++)
|
|
2389
|
+
i[l][f].add(i[n][f].clone().multiply(c));
|
|
2390
|
+
if (i[l].slice(0, i[l].length - 1).every((f) => f.isZero()))
|
|
2347
2391
|
return i[l][i[l].length - 1].isZero() ? [new u().infinite()] : [];
|
|
2348
2392
|
}
|
|
2349
2393
|
}
|
|
2350
2394
|
return i.map((n) => n[n.length - 1]);
|
|
2351
2395
|
});
|
|
2352
|
-
|
|
2353
|
-
|
|
2396
|
+
m(this, Ft, () => (h(this, $e, s(this, D).reduce((e, t) => [.../* @__PURE__ */ new Set([...e, ...t.variables])], [])), s(this, $e).sort(), this));
|
|
2397
|
+
m(this, jt, () => {
|
|
2354
2398
|
const e = [], t = [];
|
|
2355
2399
|
for (const i of s(this, D)) {
|
|
2356
2400
|
const n = [], r = i.clone().reorder();
|
|
@@ -2369,7 +2413,7 @@ const He = class He {
|
|
|
2369
2413
|
if (e.some((r) => r.length !== i))
|
|
2370
2414
|
throw new Error("All rows must have the same number of columns");
|
|
2371
2415
|
const n = t.split("").splice(0, i - 1);
|
|
2372
|
-
return new
|
|
2416
|
+
return new Xe(
|
|
2373
2417
|
...e.map((r) => {
|
|
2374
2418
|
const l = new O(n.join(""), ...r);
|
|
2375
2419
|
return new H(l, 0);
|
|
@@ -2377,7 +2421,7 @@ const He = class He {
|
|
|
2377
2421
|
);
|
|
2378
2422
|
}
|
|
2379
2423
|
add(e, t) {
|
|
2380
|
-
if (e instanceof
|
|
2424
|
+
if (e instanceof Xe) {
|
|
2381
2425
|
const i = e.equations.length;
|
|
2382
2426
|
if (i !== s(this, D).length)
|
|
2383
2427
|
throw new Error("The number of equations must be the same");
|
|
@@ -2417,7 +2461,7 @@ const He = class He {
|
|
|
2417
2461
|
return this.variables.length === s(this, D).length;
|
|
2418
2462
|
}
|
|
2419
2463
|
get matrix() {
|
|
2420
|
-
return s(this,
|
|
2464
|
+
return s(this, jt).call(this);
|
|
2421
2465
|
}
|
|
2422
2466
|
multiply(e, t) {
|
|
2423
2467
|
if (Array.isArray(e)) {
|
|
@@ -2438,7 +2482,7 @@ const He = class He {
|
|
|
2438
2482
|
return [];
|
|
2439
2483
|
}
|
|
2440
2484
|
subtract(e, t) {
|
|
2441
|
-
if (e instanceof
|
|
2485
|
+
if (e instanceof Xe) {
|
|
2442
2486
|
const i = e.equations.length;
|
|
2443
2487
|
if (i !== s(this, D).length)
|
|
2444
2488
|
throw new Error("The number of equations must be the same");
|
|
@@ -2464,18 +2508,18 @@ const He = class He {
|
|
|
2464
2508
|
t.sort(), h(this, $e, t);
|
|
2465
2509
|
}
|
|
2466
2510
|
};
|
|
2467
|
-
D = new WeakMap(), $e = new WeakMap(),
|
|
2468
|
-
let
|
|
2469
|
-
var Oe,
|
|
2470
|
-
class
|
|
2511
|
+
D = new WeakMap(), $e = new WeakMap(), Ft = new WeakMap(), jt = new WeakMap();
|
|
2512
|
+
let ti = Xe;
|
|
2513
|
+
var Oe, mt, ii;
|
|
2514
|
+
class ss {
|
|
2471
2515
|
/**
|
|
2472
2516
|
*
|
|
2473
2517
|
* @param {string} value (optional) Default polynom to parse on class creation
|
|
2474
2518
|
*/
|
|
2475
2519
|
constructor(e) {
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
a(this, "parse", (e) => (h(this, Oe, new
|
|
2520
|
+
m(this, mt);
|
|
2521
|
+
m(this, Oe);
|
|
2522
|
+
a(this, "parse", (e) => (h(this, Oe, new Kt(Ze.SET).parse(e).rpn), this));
|
|
2479
2523
|
return h(this, Oe, []), e !== void 0 && this.parse(e), this;
|
|
2480
2524
|
}
|
|
2481
2525
|
evaluate(e) {
|
|
@@ -2552,20 +2596,20 @@ class es {
|
|
|
2552
2596
|
return s(this, Oe).filter((e) => e.tokenType === "variable").map((e) => e.token);
|
|
2553
2597
|
}
|
|
2554
2598
|
vennAB() {
|
|
2555
|
-
return
|
|
2599
|
+
return A(this, mt, ii).call(this, {
|
|
2556
2600
|
A: ["A", "AB"],
|
|
2557
2601
|
B: ["B", "AB"]
|
|
2558
2602
|
}, ["A", "B", "AB", "E"]);
|
|
2559
2603
|
}
|
|
2560
2604
|
vennABC() {
|
|
2561
|
-
return
|
|
2605
|
+
return A(this, mt, ii).call(this, {
|
|
2562
2606
|
A: ["A", "AB", "AC", "ABC"],
|
|
2563
2607
|
B: ["B", "AB", "BC", "ABC"],
|
|
2564
2608
|
C: ["C", "AC", "BC", "ABC"]
|
|
2565
2609
|
}, ["A", "B", "C", "AB", "AC", "BC", "ABC", "E"]);
|
|
2566
2610
|
}
|
|
2567
2611
|
}
|
|
2568
|
-
Oe = new WeakMap(),
|
|
2612
|
+
Oe = new WeakMap(), mt = new WeakSet(), ii = function(e, t) {
|
|
2569
2613
|
const i = [];
|
|
2570
2614
|
let n;
|
|
2571
2615
|
if (t === void 0) {
|
|
@@ -2585,7 +2629,7 @@ Oe = new WeakMap(), pt = new WeakSet(), si = function(e, t) {
|
|
|
2585
2629
|
case "&":
|
|
2586
2630
|
if (i.length >= 2) {
|
|
2587
2631
|
const l = i.pop(), c = i.pop();
|
|
2588
|
-
c && l && i.push(new Set([...c].filter((
|
|
2632
|
+
c && l && i.push(new Set([...c].filter((f) => l.has(f))));
|
|
2589
2633
|
}
|
|
2590
2634
|
break;
|
|
2591
2635
|
case "|":
|
|
@@ -2597,7 +2641,7 @@ Oe = new WeakMap(), pt = new WeakSet(), si = function(e, t) {
|
|
|
2597
2641
|
case "-":
|
|
2598
2642
|
if (i.length >= 2) {
|
|
2599
2643
|
const l = i.pop(), c = i.pop();
|
|
2600
|
-
c && l && i.push(new Set([...c].filter((
|
|
2644
|
+
c && l && i.push(new Set([...c].filter((f) => !l.has(f))));
|
|
2601
2645
|
}
|
|
2602
2646
|
break;
|
|
2603
2647
|
case "!":
|
|
@@ -2609,111 +2653,152 @@ Oe = new WeakMap(), pt = new WeakSet(), si = function(e, t) {
|
|
|
2609
2653
|
}
|
|
2610
2654
|
return [...i[0]].sort();
|
|
2611
2655
|
};
|
|
2612
|
-
var
|
|
2613
|
-
const
|
|
2656
|
+
var it, N, We, ni, ki, gt, ri;
|
|
2657
|
+
const X = class X {
|
|
2614
2658
|
constructor(...e) {
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2659
|
+
m(this, gt);
|
|
2660
|
+
m(this, it, lt.POWER);
|
|
2661
|
+
m(this, N, []);
|
|
2618
2662
|
return this.parse(...e), this;
|
|
2619
2663
|
}
|
|
2620
2664
|
parse(...e) {
|
|
2621
|
-
return e.length === 0 ? this : (
|
|
2622
|
-
|
|
2623
|
-
const i = t.split(")(").join(")*(").split("*");
|
|
2624
|
-
s(this, E).push(...i.map((n) => new le(n)));
|
|
2625
|
-
} else t instanceof ue ? s(this, E).push(...t.factors.map((i) => i.clone())) : s(this, E).push(new le(t));
|
|
2665
|
+
return h(this, N, []), e.length === 0 ? this : (e.forEach((t) => {
|
|
2666
|
+
t instanceof X ? s(this, N).push(...t.factors.map((i) => i.clone())) : s(this, N).push(new ae(t));
|
|
2626
2667
|
}), this);
|
|
2627
2668
|
}
|
|
2628
2669
|
clone() {
|
|
2629
|
-
return new
|
|
2670
|
+
return new X(...s(this, N).map((e) => e.clone()));
|
|
2630
2671
|
}
|
|
2631
2672
|
get tex() {
|
|
2632
|
-
const { num: e, den: t } =
|
|
2673
|
+
const { num: e, den: t } = A(this, gt, ri).call(this);
|
|
2633
2674
|
if (t.length === 0)
|
|
2634
2675
|
return e.length === 1 ? e[0].asSingle.tex : e.map((r) => r.tex).join("");
|
|
2635
2676
|
const i = e.length === 1 ? e[0].asSingle.tex : e.map((r) => r.tex).join(""), n = t.length === 1 ? t[0].asSingle.tex : t.map((r) => r.tex).join("");
|
|
2636
2677
|
return `\\frac{ ${i} }{ ${n} }`;
|
|
2637
2678
|
}
|
|
2638
2679
|
get display() {
|
|
2639
|
-
const { num: e, den: t } =
|
|
2680
|
+
const { num: e, den: t } = A(this, gt, ri).call(this);
|
|
2640
2681
|
if (t.length === 0)
|
|
2641
|
-
return e.length === 1 ? e[0].asSingle.display : e.map(
|
|
2682
|
+
return e.length === 1 ? e[0].asSingle.display : e.map(
|
|
2683
|
+
(r, l) => l === 0 && r.polynom.monoms.length === 1 ? r.asSingle.display : r.display
|
|
2684
|
+
).join("");
|
|
2642
2685
|
const i = e.length === 1 ? e[0].asSingle.display : e.map((r) => r.display).join(""), n = t.length === 1 ? t[0].asSingle.display : t.map((r) => r.display).join("");
|
|
2643
2686
|
return `(${i})/(${n})`;
|
|
2644
2687
|
}
|
|
2645
2688
|
static gcd(...e) {
|
|
2646
2689
|
var i;
|
|
2647
2690
|
if (e.length === 0)
|
|
2648
|
-
return new
|
|
2691
|
+
return new X().one();
|
|
2649
2692
|
if (e.length === 1)
|
|
2650
2693
|
return e[0];
|
|
2651
2694
|
if (e.length === 2)
|
|
2652
|
-
return
|
|
2695
|
+
return A(i = X, We, ni).call(i, e[0], e[1]);
|
|
2653
2696
|
let t = e[0];
|
|
2654
2697
|
return e.shift(), e.forEach((n) => {
|
|
2655
2698
|
var r;
|
|
2656
|
-
return t =
|
|
2699
|
+
return t = A(r = X, We, ni).call(r, t, n);
|
|
2700
|
+
}), t;
|
|
2701
|
+
}
|
|
2702
|
+
static lcm(...e) {
|
|
2703
|
+
if (e.length === 0)
|
|
2704
|
+
return new X().one();
|
|
2705
|
+
if (e.length === 1)
|
|
2706
|
+
return e[0];
|
|
2707
|
+
let t = e[0];
|
|
2708
|
+
return e.shift(), e.forEach((i) => {
|
|
2709
|
+
var n;
|
|
2710
|
+
return t = A(n = X, We, ki).call(n, t, i);
|
|
2657
2711
|
}), t;
|
|
2658
2712
|
}
|
|
2659
2713
|
add(...e) {
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2714
|
+
const t = [this.numerator, ...e.map((c) => c.numerator)], i = [this.denominator, ...e.map((c) => c.denominator)];
|
|
2715
|
+
let n;
|
|
2716
|
+
if (i.some((c) => c.factors.length > 0)) {
|
|
2717
|
+
const c = X.lcm(...i);
|
|
2718
|
+
t.forEach((f, d) => {
|
|
2719
|
+
f.multiply(c.clone().divide(i[d]));
|
|
2720
|
+
}), n = c;
|
|
2721
|
+
}
|
|
2722
|
+
const r = X.gcd(...t), l = new O(0).add(
|
|
2723
|
+
...t.map((c) => c.divide(r).reduce().develop().factors[0].polynom)
|
|
2724
|
+
).reduce();
|
|
2725
|
+
return h(this, N, [
|
|
2726
|
+
...r.factors,
|
|
2727
|
+
new ae(l)
|
|
2728
|
+
]), n && this.divide(n), h(this, N, s(this, N).filter((c) => !c.power.isZero())), this;
|
|
2668
2729
|
}
|
|
2669
2730
|
get asPower() {
|
|
2670
|
-
return h(this,
|
|
2731
|
+
return h(this, it, lt.POWER), this;
|
|
2671
2732
|
}
|
|
2672
2733
|
get asRoot() {
|
|
2673
|
-
return h(this,
|
|
2734
|
+
return h(this, it, lt.ROOT), this;
|
|
2674
2735
|
}
|
|
2675
2736
|
degree(e) {
|
|
2676
|
-
return s(this,
|
|
2737
|
+
return s(this, N).reduce((t, i) => t.add(i.degree(e)), new u("0"));
|
|
2677
2738
|
}
|
|
2678
2739
|
get denominator() {
|
|
2679
|
-
return new
|
|
2740
|
+
return new X(
|
|
2741
|
+
...s(this, N).filter((e) => e.power.isNegative()).map((e) => e.clone().inverse())
|
|
2742
|
+
);
|
|
2680
2743
|
}
|
|
2681
2744
|
derivative() {
|
|
2682
|
-
const e = [], t = s(this,
|
|
2745
|
+
const e = [], t = s(this, N).length;
|
|
2683
2746
|
for (let n = 0; n < t; n++) {
|
|
2684
|
-
const r = s(this,
|
|
2685
|
-
e.push(
|
|
2747
|
+
const r = s(this, N).slice(), l = r.splice(n, 1)[0].derivative();
|
|
2748
|
+
e.push(
|
|
2749
|
+
new X(...r, ...l)
|
|
2750
|
+
);
|
|
2686
2751
|
}
|
|
2687
2752
|
e.forEach((n) => n.reduce());
|
|
2688
2753
|
const i = e.shift();
|
|
2689
|
-
return i !== void 0 && h(this,
|
|
2754
|
+
return i !== void 0 && h(this, N, i.factors), this.add(...e);
|
|
2690
2755
|
}
|
|
2691
2756
|
develop() {
|
|
2692
|
-
const e = new O("1");
|
|
2693
|
-
return
|
|
2694
|
-
e.multiply(
|
|
2695
|
-
}),
|
|
2757
|
+
const e = new O("1"), t = new O("1");
|
|
2758
|
+
return this.numerator.factors.forEach((i) => {
|
|
2759
|
+
e.multiply(i.develop());
|
|
2760
|
+
}), this.denominator.factors.forEach((i) => {
|
|
2761
|
+
t.multiply(i.develop());
|
|
2762
|
+
}), new X().fromPolynom(e, t);
|
|
2696
2763
|
}
|
|
2697
2764
|
divide(e) {
|
|
2698
|
-
return h(this,
|
|
2765
|
+
return h(this, N, s(this, N).concat(e.clone().factors.map((t) => t.inverse()))), this;
|
|
2699
2766
|
}
|
|
2700
2767
|
evaluate(e, t) {
|
|
2701
|
-
return t ? s(this,
|
|
2768
|
+
return t ? s(this, N).reduce((i, n) => i * n.evaluate(e, t), 1) : s(this, N).reduce((i, n) => i.multiply(n.evaluate(e)), new u("1"));
|
|
2769
|
+
}
|
|
2770
|
+
factorize(e) {
|
|
2771
|
+
const t = [];
|
|
2772
|
+
s(this, N).forEach((l) => {
|
|
2773
|
+
const c = l.polynom.factorize(e);
|
|
2774
|
+
if (c.length > 1) {
|
|
2775
|
+
const f = l.power.clone();
|
|
2776
|
+
t.push(...c.map((d) => new ae(d, f)));
|
|
2777
|
+
} else
|
|
2778
|
+
t.push(l.clone());
|
|
2779
|
+
});
|
|
2780
|
+
const i = new X(...t), n = i.numerator.reduce(), r = i.denominator.reduce();
|
|
2781
|
+
return n.divide(r);
|
|
2702
2782
|
}
|
|
2703
2783
|
get factors() {
|
|
2704
|
-
return s(this,
|
|
2784
|
+
return s(this, N);
|
|
2705
2785
|
}
|
|
2706
2786
|
set factors(e) {
|
|
2707
|
-
h(this,
|
|
2787
|
+
h(this, N, e);
|
|
2708
2788
|
}
|
|
2709
|
-
fromPolynom(e, t
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2789
|
+
fromPolynom(e, t) {
|
|
2790
|
+
if (h(this, N, [new ae(new O(e))]), t) {
|
|
2791
|
+
const i = new O(t);
|
|
2792
|
+
if (i.isOne())
|
|
2793
|
+
return this;
|
|
2794
|
+
if (i.isZero())
|
|
2795
|
+
throw new Error("Cannot divide by zero");
|
|
2796
|
+
s(this, N).push(new ae(i, -1));
|
|
2797
|
+
}
|
|
2798
|
+
return this;
|
|
2714
2799
|
}
|
|
2715
2800
|
getZeroes() {
|
|
2716
|
-
const e = [].concat(...s(this,
|
|
2801
|
+
const e = [].concat(...s(this, N).map((t) => t.polynom.getZeroes()));
|
|
2717
2802
|
return e.sort((t, i) => t.value - i.value), e.filter(
|
|
2718
2803
|
(t, i, n) => i === n.findIndex(
|
|
2719
2804
|
(r) => r.value === t.value
|
|
@@ -2721,113 +2806,146 @@ const ue = class ue {
|
|
|
2721
2806
|
);
|
|
2722
2807
|
}
|
|
2723
2808
|
hasVariable(e) {
|
|
2724
|
-
return s(this,
|
|
2809
|
+
return s(this, N).some((t) => t.hasVariable(e));
|
|
2725
2810
|
}
|
|
2726
2811
|
inverse() {
|
|
2727
|
-
return h(this,
|
|
2812
|
+
return h(this, N, s(this, N).map((e) => e.inverse())), this;
|
|
2728
2813
|
}
|
|
2729
2814
|
isEqual(e) {
|
|
2730
|
-
const t =
|
|
2815
|
+
const t = X.gcd(this, e), i = this.clone().divide(t).reduce(), n = e.clone().divide(t).reduce();
|
|
2731
2816
|
return i.isOne() && n.isOne();
|
|
2732
2817
|
}
|
|
2733
2818
|
isOne() {
|
|
2734
|
-
return s(this,
|
|
2819
|
+
return s(this, N).every((e) => e.isOne());
|
|
2735
2820
|
}
|
|
2736
2821
|
isZero() {
|
|
2737
|
-
return s(this,
|
|
2822
|
+
return s(this, N).every((e) => e.isZero());
|
|
2738
2823
|
}
|
|
2739
2824
|
multiply(...e) {
|
|
2740
2825
|
return e.forEach((t) => {
|
|
2741
|
-
h(this,
|
|
2826
|
+
h(this, N, s(this, N).concat(t.clone().factors));
|
|
2742
2827
|
}), this;
|
|
2743
2828
|
}
|
|
2744
2829
|
get numerator() {
|
|
2745
|
-
return new
|
|
2830
|
+
return new X(...s(this, N).filter((e) => e.power.isPositive()));
|
|
2746
2831
|
}
|
|
2747
2832
|
one() {
|
|
2748
|
-
return h(this,
|
|
2833
|
+
return h(this, N, [new ae("1", "1")]), this;
|
|
2749
2834
|
}
|
|
2750
2835
|
opposite() {
|
|
2751
|
-
const e = s(this,
|
|
2752
|
-
return e >= 0 ? s(this,
|
|
2836
|
+
const e = s(this, N).findIndex((t) => t.display === "(-1)");
|
|
2837
|
+
return e >= 0 ? s(this, N).splice(e, 1) : s(this, N).push(new ae("-1", "1")), this;
|
|
2753
2838
|
}
|
|
2754
2839
|
pow(e) {
|
|
2755
|
-
return h(this,
|
|
2840
|
+
return h(this, N, s(this, N).map((t) => t.pow(e))), this;
|
|
2756
2841
|
}
|
|
2757
2842
|
primitive() {
|
|
2758
2843
|
throw new Error("Method not implemented.");
|
|
2759
2844
|
}
|
|
2760
2845
|
reduce() {
|
|
2761
|
-
const e =
|
|
2762
|
-
return h(this,
|
|
2846
|
+
const e = ht(this);
|
|
2847
|
+
return h(this, N, Object.values(e).map((t) => {
|
|
2763
2848
|
const i = t[0].polynom, n = t.reduce((r, l) => r.add(l.power), new u("0"));
|
|
2764
|
-
return new
|
|
2849
|
+
return new ae(i, n.reduce());
|
|
2765
2850
|
}).filter((t) => !t.power.isZero())), this;
|
|
2766
2851
|
}
|
|
2767
2852
|
root(e) {
|
|
2768
|
-
return h(this,
|
|
2853
|
+
return h(this, N, s(this, N).map((t) => t.root(e))), this;
|
|
2769
2854
|
}
|
|
2770
|
-
|
|
2771
|
-
|
|
2855
|
+
/**
|
|
2856
|
+
* Reoarder the factors using :
|
|
2857
|
+
* 1. number of monoms
|
|
2858
|
+
* 2. degree of polynom
|
|
2859
|
+
* 3. power of polyfactor
|
|
2860
|
+
*/
|
|
2861
|
+
sort(e) {
|
|
2862
|
+
return s(this, N).sort((t, i) => {
|
|
2863
|
+
const n = t.power.value, r = i.power.value;
|
|
2864
|
+
if (n * r < 0)
|
|
2865
|
+
return -n;
|
|
2866
|
+
const l = t.polynom.monoms.length, c = i.polynom.monoms.length;
|
|
2867
|
+
if (l !== c)
|
|
2868
|
+
return l - c;
|
|
2869
|
+
const f = t.polynom.degree(e).value, d = i.polynom.degree(e).value;
|
|
2870
|
+
return f !== d ? f - d : n !== r ? n - r : t.degree().isLeq(i.degree()) ? -1 : 1;
|
|
2871
|
+
}), this;
|
|
2772
2872
|
}
|
|
2773
2873
|
sqrt() {
|
|
2774
|
-
return h(this,
|
|
2874
|
+
return h(this, N, s(this, N).map((e) => e.sqrt())), this;
|
|
2775
2875
|
}
|
|
2776
2876
|
subtract(...e) {
|
|
2777
2877
|
return this.add(...e.map((t) => t.opposite()));
|
|
2778
2878
|
}
|
|
2779
2879
|
tableOfSigns() {
|
|
2780
|
-
const e = this.getZeroes(), t = this.factors.map((
|
|
2781
|
-
return
|
|
2782
|
-
|
|
2880
|
+
const e = this.getZeroes(), t = e.map((r) => r.value), i = this.factors.map((r) => ({ factor: new ae(r), ...r.tableOfSigns() }));
|
|
2881
|
+
return i.forEach((r) => {
|
|
2882
|
+
const l = new Array(2 * e.length + 1).fill("");
|
|
2883
|
+
let c = r.signs.shift(), f = r.roots.shift();
|
|
2884
|
+
const d = l.map((p, w) => {
|
|
2885
|
+
if (w % 2 === 0)
|
|
2886
|
+
return c;
|
|
2887
|
+
if (f === void 0 || f.value !== t[(w - 1) / 2])
|
|
2888
|
+
return "t";
|
|
2889
|
+
const V = r.signs.shift();
|
|
2890
|
+
return c = r.signs.shift(), f = r.roots.shift(), V;
|
|
2891
|
+
});
|
|
2892
|
+
r.roots = e, r.signs = d;
|
|
2893
|
+
}), { signs: i.map((r) => r.signs).reduce((r, l) => r.length === 0 ? l : (l.forEach((c, f) => {
|
|
2894
|
+
switch (c) {
|
|
2783
2895
|
case "d":
|
|
2784
|
-
|
|
2896
|
+
r[f] = "d";
|
|
2785
2897
|
break;
|
|
2786
2898
|
case "z":
|
|
2787
|
-
|
|
2899
|
+
r[f] = r[f] === "d" ? "d" : "z";
|
|
2788
2900
|
break;
|
|
2789
2901
|
case "h":
|
|
2790
|
-
|
|
2902
|
+
r[f] = "h";
|
|
2791
2903
|
break;
|
|
2792
2904
|
case "-":
|
|
2793
|
-
|
|
2905
|
+
r[f] = r[f] === "h" ? "h" : r[f] === "-" ? "+" : "-";
|
|
2794
2906
|
break;
|
|
2795
2907
|
}
|
|
2796
|
-
}),
|
|
2908
|
+
}), r), []), roots: e, factors: i };
|
|
2797
2909
|
}
|
|
2798
2910
|
get variables() {
|
|
2799
|
-
return s(this,
|
|
2911
|
+
return s(this, N).reduce((e, t) => e.concat(t.variables), []);
|
|
2800
2912
|
}
|
|
2801
2913
|
zero() {
|
|
2802
|
-
return h(this,
|
|
2914
|
+
return h(this, N, [new ae("0", "1")]), this;
|
|
2803
2915
|
}
|
|
2804
2916
|
};
|
|
2805
|
-
|
|
2806
|
-
const i =
|
|
2807
|
-
const
|
|
2808
|
-
return new
|
|
2917
|
+
it = new WeakMap(), N = new WeakMap(), We = new WeakSet(), ni = function(e, t) {
|
|
2918
|
+
const i = ht(e), n = ht(t), l = Object.keys(i).filter((c) => Object.hasOwn(n, c)).map((c) => {
|
|
2919
|
+
const f = i[c].reduce((p, w) => p.add(w.power), new u("0")), d = n[c].reduce((p, w) => p.add(w.power), new u("0"));
|
|
2920
|
+
return new ae(c, u.min(f, d));
|
|
2809
2921
|
});
|
|
2810
|
-
return new
|
|
2811
|
-
},
|
|
2922
|
+
return new X(...l);
|
|
2923
|
+
}, ki = function(e, t) {
|
|
2924
|
+
const i = ht(e), n = ht(t), l = [.../* @__PURE__ */ new Set([...Object.keys(i), ...Object.keys(n)])].map((c) => {
|
|
2925
|
+
const f = Object.hasOwn(i, c) ? i[c].reduce((p, w) => p.add(w.power), new u("0")) : new u(0), d = Object.hasOwn(n, c) ? n[c].reduce((p, w) => p.add(w.power), new u("0")) : new u(0);
|
|
2926
|
+
return new ae(c, u.max(f, d));
|
|
2927
|
+
});
|
|
2928
|
+
return new X(...l);
|
|
2929
|
+
}, gt = new WeakSet(), ri = function() {
|
|
2812
2930
|
let e, t = [];
|
|
2813
|
-
return s(this,
|
|
2814
|
-
},
|
|
2815
|
-
let
|
|
2816
|
-
function
|
|
2931
|
+
return s(this, it) === lt.ROOT ? (e = this.numerator.factors, t = this.denominator.factors) : e = s(this, N), e.length === 0 && (e = [new ae("1")]), { num: e, den: t };
|
|
2932
|
+
}, m(X, We);
|
|
2933
|
+
let si = X;
|
|
2934
|
+
function ht(o) {
|
|
2817
2935
|
const e = new u().one(), t = o.factors.reduce((i, n) => {
|
|
2818
2936
|
if (n.polynom.degree().isZero())
|
|
2819
2937
|
return n.polynom.monoms.length > 0 && e.multiply(n.polynom.monoms[0].coefficient), i;
|
|
2820
2938
|
const r = n.polynom.display;
|
|
2821
2939
|
return Object.hasOwn(i, r) ? i[r].push(n) : i[r] = [n], i;
|
|
2822
2940
|
}, {});
|
|
2823
|
-
return e.isOne() || (t[e.display] = [new
|
|
2941
|
+
return e.isOne() || (t[e.display] = [new ae(e.display, 1)]), t;
|
|
2824
2942
|
}
|
|
2825
|
-
function
|
|
2943
|
+
function ns(o, e) {
|
|
2826
2944
|
return o.dimension === e.dimension && o.array.every(
|
|
2827
2945
|
(t, i) => e.array[i].isEqual(t)
|
|
2828
2946
|
);
|
|
2829
2947
|
}
|
|
2830
|
-
function
|
|
2948
|
+
function rs(o, e) {
|
|
2831
2949
|
if (o.dimension !== e.dimension)
|
|
2832
2950
|
return !1;
|
|
2833
2951
|
const t = e.array[0].value / o.array[0].value;
|
|
@@ -2835,14 +2953,18 @@ function is(o, e) {
|
|
|
2835
2953
|
(i, n) => e.array[n].value === i.value * t
|
|
2836
2954
|
);
|
|
2837
2955
|
}
|
|
2838
|
-
function
|
|
2956
|
+
function os(o, e) {
|
|
2839
2957
|
return o.dimension !== e.dimension ? new u().invalid() : o.array.reduce(
|
|
2840
2958
|
(t, i, n) => t.add(i.clone().multiply(e.array[n])),
|
|
2841
2959
|
new u(0)
|
|
2842
2960
|
);
|
|
2843
2961
|
}
|
|
2844
|
-
function
|
|
2845
|
-
|
|
2962
|
+
function hs(...o) {
|
|
2963
|
+
if (o.some((e) => e.dimension !== o[0].dimension))
|
|
2964
|
+
throw new Error("All vectors must have the same dimension");
|
|
2965
|
+
if (o[0].dimension !== o.length)
|
|
2966
|
+
throw new Error(`The determinant of dimension ${o[0].dimension} must have the same number of vectors (${o.length} given)`);
|
|
2967
|
+
return o[0].dimension === 2 ? o[0].array[0].clone().multiply(o[1].array[1]).subtract(o[0].array[1].clone().multiply(o[1].array[0])) : o[0].array[0].clone().multiply(
|
|
2846
2968
|
o[1].array[1].clone().multiply(o[2].array[2]).subtract(o[1].array[2].clone().multiply(o[2].array[1]))
|
|
2847
2969
|
).subtract(
|
|
2848
2970
|
o[0].array[1].clone().multiply(
|
|
@@ -2850,11 +2972,11 @@ function ns(...o) {
|
|
|
2850
2972
|
)
|
|
2851
2973
|
).add(o[0].array[2].clone().multiply(o[1].array[0].clone().multiply(o[2].array[1]).subtract(o[1].array[1].clone().multiply(o[2].array[0]))));
|
|
2852
2974
|
}
|
|
2853
|
-
var F,
|
|
2975
|
+
var F, Le;
|
|
2854
2976
|
const Se = class Se {
|
|
2855
2977
|
constructor(...e) {
|
|
2856
|
-
|
|
2857
|
-
|
|
2978
|
+
m(this, F, []);
|
|
2979
|
+
m(this, Le, !1);
|
|
2858
2980
|
a(this, "zero", () => (s(this, F).forEach((e) => e.zero()), this));
|
|
2859
2981
|
a(this, "one", () => (this.zero(), this.x.one(), this));
|
|
2860
2982
|
a(this, "opposite", () => (s(this, F).forEach((e) => e.opposite()), this));
|
|
@@ -2864,15 +2986,15 @@ const Se = class Se {
|
|
|
2864
2986
|
const e = this.norm;
|
|
2865
2987
|
return e === 0 ? this : this.divideByScalar(e);
|
|
2866
2988
|
});
|
|
2867
|
-
a(this, "dot", (e) =>
|
|
2989
|
+
a(this, "dot", (e) => os(this, e));
|
|
2868
2990
|
a(this, "normal", () => {
|
|
2869
2991
|
if (this.dimension >= 3)
|
|
2870
2992
|
throw new Error("Normal vector can only be determined in 2D");
|
|
2871
2993
|
const e = this.x.clone().opposite(), t = this.y.clone();
|
|
2872
2994
|
return s(this, F)[0] = t, s(this, F)[1] = e, this;
|
|
2873
2995
|
});
|
|
2874
|
-
a(this, "isEqual", (e) =>
|
|
2875
|
-
a(this, "isColinearTo", (e) =>
|
|
2996
|
+
a(this, "isEqual", (e) => ns(this, e));
|
|
2997
|
+
a(this, "isColinearTo", (e) => rs(this, e));
|
|
2876
2998
|
a(this, "isNormalTo", (e) => this.dot(e).isZero());
|
|
2877
2999
|
a(this, "multiplyByScalar", (e) => {
|
|
2878
3000
|
const t = new u(e);
|
|
@@ -2880,9 +3002,9 @@ const Se = class Se {
|
|
|
2880
3002
|
});
|
|
2881
3003
|
a(this, "divideByScalar", (e) => this.multiplyByScalar(new u(e).inverse()));
|
|
2882
3004
|
a(this, "simplify", () => this.multiplyByScalar(
|
|
2883
|
-
|
|
3005
|
+
U.lcm(...this.array.map((e) => e.denominator))
|
|
2884
3006
|
).divideByScalar(
|
|
2885
|
-
|
|
3007
|
+
U.gcd(...this.array.map((e) => e.numerator))
|
|
2886
3008
|
).multiplyByScalar(
|
|
2887
3009
|
this.x.isNegative() ? -1 : 1
|
|
2888
3010
|
));
|
|
@@ -2929,10 +3051,10 @@ const Se = class Se {
|
|
|
2929
3051
|
s(this, F)[2] = new u(e);
|
|
2930
3052
|
}
|
|
2931
3053
|
get asPoint() {
|
|
2932
|
-
return s(this,
|
|
3054
|
+
return s(this, Le);
|
|
2933
3055
|
}
|
|
2934
3056
|
set asPoint(e) {
|
|
2935
|
-
h(this,
|
|
3057
|
+
h(this, Le, e);
|
|
2936
3058
|
}
|
|
2937
3059
|
get normSquare() {
|
|
2938
3060
|
return this.array.reduce((e, t) => e.add(t.clone().pow(2)), new u(0));
|
|
@@ -2941,10 +3063,10 @@ const Se = class Se {
|
|
|
2941
3063
|
return Math.sqrt(this.normSquare.value);
|
|
2942
3064
|
}
|
|
2943
3065
|
get tex() {
|
|
2944
|
-
return s(this,
|
|
3066
|
+
return s(this, Le) ? `\\left(${this.array.map((e) => e.tex).join(";")}\\right)` : `\\begin{pmatrix} ${this.array.map((e) => e.tex).join(" \\\\ ")} \\end{pmatrix}`;
|
|
2945
3067
|
}
|
|
2946
3068
|
get display() {
|
|
2947
|
-
return s(this,
|
|
3069
|
+
return s(this, Le) ? `(${this.array.map((e) => e.display).join(";")})` : `((${this.array.map((e) => e.display).join(",")}))`;
|
|
2948
3070
|
}
|
|
2949
3071
|
setDimension(e = 2) {
|
|
2950
3072
|
if (e < 2)
|
|
@@ -2972,7 +3094,7 @@ const Se = class Se {
|
|
|
2972
3094
|
return `((${e.join(",")}))`;
|
|
2973
3095
|
}
|
|
2974
3096
|
defineAsPoint(e) {
|
|
2975
|
-
return h(this,
|
|
3097
|
+
return h(this, Le, e !== !1), this;
|
|
2976
3098
|
}
|
|
2977
3099
|
parse(...e) {
|
|
2978
3100
|
if (e.length === 0)
|
|
@@ -3035,40 +3157,40 @@ const Se = class Se {
|
|
|
3035
3157
|
};
|
|
3036
3158
|
}
|
|
3037
3159
|
};
|
|
3038
|
-
F = new WeakMap(),
|
|
3039
|
-
let
|
|
3040
|
-
var we = /* @__PURE__ */ ((o) => (o.None = "none", o.Parallel = "parallel", o.Perpendicular = "perpendicular", o.Tangent = "tangent", o))(we || {}),
|
|
3041
|
-
function
|
|
3160
|
+
F = new WeakMap(), Le = new WeakMap();
|
|
3161
|
+
let E = Se;
|
|
3162
|
+
var we = /* @__PURE__ */ ((o) => (o.None = "none", o.Parallel = "parallel", o.Perpendicular = "perpendicular", o.Tangent = "tangent", o))(we || {}), oi = /* @__PURE__ */ ((o) => (o.None = "none", o.Parallel = "parallel", o.Perpendicular = "perpendicular", o.Tangent = "tangent", o))(oi || {});
|
|
3163
|
+
function Ci(o = 0.5) {
|
|
3042
3164
|
return Math.random() < o;
|
|
3043
3165
|
}
|
|
3044
|
-
function
|
|
3166
|
+
function pe(o, e, t) {
|
|
3045
3167
|
if (e === void 0)
|
|
3046
|
-
return o >= 0 ?
|
|
3168
|
+
return o >= 0 ? pe(0, o) : pe(o, 0);
|
|
3047
3169
|
if (o === e)
|
|
3048
3170
|
return o;
|
|
3049
3171
|
if (t === void 0)
|
|
3050
3172
|
return Math.floor(Math.random() * (e - o + 1) + o);
|
|
3051
3173
|
if (Math.abs(e - o) <= t.length)
|
|
3052
3174
|
throw new Error("The number of excluded values is too high.");
|
|
3053
|
-
let i =
|
|
3175
|
+
let i = pe(o, e);
|
|
3054
3176
|
for (; t.includes(i); )
|
|
3055
|
-
i =
|
|
3177
|
+
i = pe(o, e);
|
|
3056
3178
|
return i;
|
|
3057
3179
|
}
|
|
3058
|
-
function
|
|
3059
|
-
return e === !1 ?
|
|
3180
|
+
function Q(o, e) {
|
|
3181
|
+
return e === !1 ? Ci() ? pe(1, o) : -pe(1, o) : pe(-o, o);
|
|
3060
3182
|
}
|
|
3061
|
-
function
|
|
3062
|
-
let e =
|
|
3063
|
-
return o !== void 0 && (e = e.filter((t) => t < o)),
|
|
3183
|
+
function as(o) {
|
|
3184
|
+
let e = U.primes();
|
|
3185
|
+
return o !== void 0 && (e = e.filter((t) => t < o)), di(e);
|
|
3064
3186
|
}
|
|
3065
|
-
function
|
|
3066
|
-
return e === void 0 && (e = 1), o.length <= 0 ? Object.values(o) :
|
|
3187
|
+
function ls(o, e) {
|
|
3188
|
+
return e === void 0 && (e = 1), o.length <= 0 ? Object.values(o) : $i(o).slice(0, e);
|
|
3067
3189
|
}
|
|
3068
|
-
function
|
|
3069
|
-
return o.length === 0 ? null : o[
|
|
3190
|
+
function di(o) {
|
|
3191
|
+
return o.length === 0 ? null : o[pe(0, o.length - 1)];
|
|
3070
3192
|
}
|
|
3071
|
-
function
|
|
3193
|
+
function $i(o) {
|
|
3072
3194
|
const e = Object.values(o);
|
|
3073
3195
|
for (let t = e.length - 1; t > 0; t--) {
|
|
3074
3196
|
const i = Math.floor(Math.random() * (t + 1)), n = e[t];
|
|
@@ -3076,19 +3198,19 @@ function ki(o) {
|
|
|
3076
3198
|
}
|
|
3077
3199
|
return e;
|
|
3078
3200
|
}
|
|
3079
|
-
class B extends
|
|
3201
|
+
class B extends E {
|
|
3080
3202
|
constructor(...e) {
|
|
3081
3203
|
super(), e.length > 0 && this.parse(...e);
|
|
3082
3204
|
}
|
|
3083
3205
|
parse(...e) {
|
|
3084
3206
|
if (this.asPoint = !0, e.length === 1) {
|
|
3085
|
-
if (e[0] instanceof
|
|
3207
|
+
if (e[0] instanceof E)
|
|
3086
3208
|
return this.array = e[0].copy(), this;
|
|
3087
3209
|
if (typeof e[0] == "string")
|
|
3088
3210
|
return this.fromString(e[0]), this;
|
|
3089
3211
|
}
|
|
3090
3212
|
if (e.length > 1) {
|
|
3091
|
-
if (e.some((i) => i instanceof
|
|
3213
|
+
if (e.some((i) => i instanceof E))
|
|
3092
3214
|
throw new Error("Creating a point with multiple argument requires an input fraction");
|
|
3093
3215
|
const t = e.map((i) => new u(i));
|
|
3094
3216
|
if (t.some((i) => i.isNaN()))
|
|
@@ -3102,32 +3224,32 @@ class B extends x {
|
|
|
3102
3224
|
return e.array = this.copy(), e.asPoint = !0, e;
|
|
3103
3225
|
}
|
|
3104
3226
|
}
|
|
3105
|
-
var
|
|
3106
|
-
const
|
|
3227
|
+
var Pe, S, z, W, oe, J, Ie, xe;
|
|
3228
|
+
const De = class De {
|
|
3107
3229
|
/**
|
|
3108
3230
|
* Value can be a mix of:
|
|
3109
3231
|
*
|
|
3110
3232
|
* @param values
|
|
3111
3233
|
*/
|
|
3112
3234
|
constructor(...e) {
|
|
3113
|
-
|
|
3235
|
+
m(this, Pe);
|
|
3114
3236
|
// ax + by + c = 0
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3237
|
+
m(this, S);
|
|
3238
|
+
m(this, z);
|
|
3239
|
+
m(this, W);
|
|
3240
|
+
m(this, oe);
|
|
3241
|
+
m(this, J);
|
|
3242
|
+
m(this, Ie);
|
|
3243
|
+
m(this, xe, "canonical");
|
|
3122
3244
|
a(this, "randomPoint", (e) => {
|
|
3123
|
-
const t = s(this,
|
|
3245
|
+
const t = s(this, J).clone().multiplyByScalar(Q(e === void 0 || e <= 1 ? 3 : e, !1)).add(s(this, oe));
|
|
3124
3246
|
return t.asPoint = !0, t;
|
|
3125
3247
|
});
|
|
3126
3248
|
a(this, "randomNearPoint", (e) => {
|
|
3127
3249
|
const t = this.randomPoint(e);
|
|
3128
3250
|
let i = 10;
|
|
3129
3251
|
for (; this.isOnLine(t) && i > 0; )
|
|
3130
|
-
t.x.add(
|
|
3252
|
+
t.x.add(Q(1, !1)), t.y.add(Q(1, !1)), i--;
|
|
3131
3253
|
return t;
|
|
3132
3254
|
});
|
|
3133
3255
|
// ------------------------------------------
|
|
@@ -3142,7 +3264,7 @@ const Ze = class Ze {
|
|
|
3142
3264
|
if (e.length === 0)
|
|
3143
3265
|
return this;
|
|
3144
3266
|
if (e.length === 1) {
|
|
3145
|
-
if (e[0] instanceof
|
|
3267
|
+
if (e[0] instanceof De)
|
|
3146
3268
|
return this.fromCoefficient(e[0].a, e[0].b, e[0].c);
|
|
3147
3269
|
if (e[0] instanceof H)
|
|
3148
3270
|
return this.fromEquation(e[0]);
|
|
@@ -3154,21 +3276,21 @@ const Ze = class Ze {
|
|
|
3154
3276
|
return this;
|
|
3155
3277
|
}
|
|
3156
3278
|
}
|
|
3157
|
-
if (e.length === 2 && e.every((t) => t instanceof
|
|
3279
|
+
if (e.length === 2 && e.every((t) => t instanceof E)) {
|
|
3158
3280
|
const t = e;
|
|
3159
3281
|
if (t[0].asPoint && t[1].asPoint)
|
|
3160
|
-
return this.fromPointAndDirection(t[0], new
|
|
3282
|
+
return this.fromPointAndDirection(t[0], new E(t[0], t[1]));
|
|
3161
3283
|
if (t[0].asPoint && !t[1].asPoint)
|
|
3162
3284
|
return this.fromPointAndDirection(t[0], t[1]);
|
|
3163
3285
|
}
|
|
3164
3286
|
if (e.length === 3) {
|
|
3165
|
-
if (e[0] instanceof
|
|
3287
|
+
if (e[0] instanceof E && e[1] instanceof E) {
|
|
3166
3288
|
if (e[2] === we.Perpendicular)
|
|
3167
3289
|
return this.fromPointAndNormal(e[0], e[1]);
|
|
3168
3290
|
if (e[2] === we.Parallel)
|
|
3169
3291
|
return this.fromPointAndDirection(e[0], e[1]);
|
|
3170
3292
|
}
|
|
3171
|
-
return e[0] instanceof
|
|
3293
|
+
return e[0] instanceof E && e[1] instanceof De ? e[2] === we.Parallel || e[2] === null ? this.fromPointAndLine(e[0], e[1], we.Parallel) : this.fromPointAndLine(e[0], e[1], we.Perpendicular) : this.fromCoefficient(
|
|
3172
3294
|
e[0],
|
|
3173
3295
|
e[1],
|
|
3174
3296
|
e[2]
|
|
@@ -3189,42 +3311,42 @@ const Ze = class Ze {
|
|
|
3189
3311
|
e.left.monomByDegree(0).coefficient
|
|
3190
3312
|
);
|
|
3191
3313
|
});
|
|
3192
|
-
a(this, "fromCoefficient", (e, t, i) => (h(this, S, new u(e)), h(this, z, new u(t)), h(this,
|
|
3314
|
+
a(this, "fromCoefficient", (e, t, i) => (h(this, S, new u(e)), h(this, z, new u(t)), h(this, W, new u(i)), h(this, J, new E(s(this, z).clone(), s(this, S).clone().opposite())), h(this, oe, new E(new u().zero(), s(this, W).clone())), h(this, Ie, s(this, J).clone().normal()), this));
|
|
3193
3315
|
a(this, "fromPointAndDirection", (e, t) => (this.fromCoefficient(
|
|
3194
3316
|
t.y,
|
|
3195
3317
|
t.x.clone().opposite(),
|
|
3196
3318
|
e.x.clone().multiply(t.y).subtract(e.y.clone().multiply(t.x)).opposite()
|
|
3197
|
-
), h(this,
|
|
3319
|
+
), h(this, oe, e.clone()), h(this, J, t.clone()), h(this, Ie, s(this, J).clone().normal()), this));
|
|
3198
3320
|
a(this, "fromPointAndNormal", (e, t) => this.fromCoefficient(
|
|
3199
3321
|
t.x,
|
|
3200
3322
|
t.y,
|
|
3201
3323
|
e.x.clone().multiply(t.x).add(e.y.clone().multiply(t.y)).opposite()
|
|
3202
3324
|
));
|
|
3203
3325
|
a(this, "fromPointAndLine", (e, t, i) => (i === void 0 && (i = we.Parallel), i === we.Parallel ? this.fromPointAndNormal(e, t.normal) : i === we.Perpendicular ? this.fromPointAndNormal(e, t.director) : this));
|
|
3204
|
-
a(this, "clone", () => (h(this, S, s(this, S).clone()), h(this, z, s(this, z).clone()), h(this,
|
|
3326
|
+
a(this, "clone", () => (h(this, S, s(this, S).clone()), h(this, z, s(this, z).clone()), h(this, W, s(this, W).clone()), h(this, J, s(this, J).clone()), h(this, oe, s(this, oe).clone()), h(this, Ie, s(this, Ie).clone()), this));
|
|
3205
3327
|
// ------------------------------------------
|
|
3206
3328
|
// Mathematical operations
|
|
3207
3329
|
// ------------------------------------------
|
|
3208
3330
|
a(this, "isOnLine", (e) => s(this, S).clone().multiply(e.x).add(
|
|
3209
3331
|
s(this, z).clone().multiply(e.y)
|
|
3210
|
-
).add(s(this,
|
|
3332
|
+
).add(s(this, W)).isZero());
|
|
3211
3333
|
a(this, "isParallelTo", (e) => this.slope.isEqual(e.slope) && this.height.isNotEqual(e.height));
|
|
3212
3334
|
a(this, "isSameAs", (e) => this.slope.isEqual(e.slope) && this.height.isEqual(e.height));
|
|
3213
3335
|
a(this, "isPerpendicularTo", (e) => this.d.isNormalTo(e.d));
|
|
3214
3336
|
a(this, "isVertical", () => this.slope.isInfinity());
|
|
3215
3337
|
a(this, "simplify", () => {
|
|
3216
|
-
const e =
|
|
3338
|
+
const e = U.lcm(s(this, S).denominator, s(this, z).denominator, s(this, W).denominator), t = U.gcd(s(this, S).numerator, s(this, z).numerator, s(this, W).numerator);
|
|
3217
3339
|
return this.fromCoefficient(
|
|
3218
3340
|
s(this, S).clone().multiply(e).divide(t),
|
|
3219
3341
|
s(this, z).clone().multiply(e).divide(t),
|
|
3220
|
-
s(this,
|
|
3342
|
+
s(this, W).clone().multiply(e).divide(t)
|
|
3221
3343
|
), this;
|
|
3222
3344
|
});
|
|
3223
|
-
a(this, "simplifyDirection", () => (s(this,
|
|
3345
|
+
a(this, "simplifyDirection", () => (s(this, J).simplify(), this));
|
|
3224
3346
|
a(this, "intersection", (e) => {
|
|
3225
3347
|
const t = new B();
|
|
3226
3348
|
let i = !1, n = !1;
|
|
3227
|
-
return s(this, z).isZero() || e.b.isZero(), this.isParallelTo(e) ? (t.x = new u().invalid(), t.y = new u().invalid(), i = !0) : this.isSameAs(e) ? (t.x = new u().invalid(), t.y = new u().invalid(), n = !0) : (t.x = s(this, z).clone().multiply(e.c).subtract(s(this,
|
|
3349
|
+
return s(this, z).isZero() || e.b.isZero(), this.isParallelTo(e) ? (t.x = new u().invalid(), t.y = new u().invalid(), i = !0) : this.isSameAs(e) ? (t.x = new u().invalid(), t.y = new u().invalid(), n = !0) : (t.x = s(this, z).clone().multiply(e.c).subtract(s(this, W).clone().multiply(e.b)).divide(s(this, S).clone().multiply(e.b).subtract(s(this, z).clone().multiply(e.a))), t.y = s(this, S).clone().multiply(e.c).subtract(s(this, W).clone().multiply(e.a)).divide(s(this, z).clone().multiply(e.a).subtract(s(this, S).clone().multiply(e.b)))), {
|
|
3228
3350
|
point: t,
|
|
3229
3351
|
hasIntersection: !(i || n),
|
|
3230
3352
|
isParallel: i,
|
|
@@ -3239,7 +3361,7 @@ const Ze = class Ze {
|
|
|
3239
3361
|
const t = this.getEquation().isolate("x"), i = new u(e);
|
|
3240
3362
|
return t instanceof H ? t.right.evaluate({ y: i }) : new u().invalid();
|
|
3241
3363
|
});
|
|
3242
|
-
return h(this, S, new u().zero()), h(this, z, new u().zero()), h(this,
|
|
3364
|
+
return h(this, S, new u().zero()), h(this, z, new u().zero()), h(this, W, new u().zero()), h(this, oe, new E()), h(this, J, new E()), h(this, Ie, new E()), h(this, Pe, !0), e.length > 0 && this.parse(...e), this;
|
|
3243
3365
|
}
|
|
3244
3366
|
get a() {
|
|
3245
3367
|
return s(this, S);
|
|
@@ -3256,30 +3378,30 @@ const Ze = class Ze {
|
|
|
3256
3378
|
h(this, z, e);
|
|
3257
3379
|
}
|
|
3258
3380
|
get c() {
|
|
3259
|
-
return s(this,
|
|
3381
|
+
return s(this, W);
|
|
3260
3382
|
}
|
|
3261
3383
|
set c(e) {
|
|
3262
|
-
h(this,
|
|
3384
|
+
h(this, W, e);
|
|
3263
3385
|
}
|
|
3264
3386
|
get OA() {
|
|
3265
|
-
return s(this,
|
|
3387
|
+
return s(this, oe);
|
|
3266
3388
|
}
|
|
3267
3389
|
set OA(e) {
|
|
3268
|
-
h(this,
|
|
3390
|
+
h(this, oe, e);
|
|
3269
3391
|
}
|
|
3270
3392
|
get d() {
|
|
3271
|
-
return s(this,
|
|
3393
|
+
return s(this, J);
|
|
3272
3394
|
}
|
|
3273
3395
|
set d(e) {
|
|
3274
|
-
h(this,
|
|
3396
|
+
h(this, J, e);
|
|
3275
3397
|
}
|
|
3276
3398
|
get n() {
|
|
3277
|
-
return s(this,
|
|
3399
|
+
return s(this, Ie);
|
|
3278
3400
|
}
|
|
3279
3401
|
// ------------------------------------------
|
|
3280
3402
|
getEquation() {
|
|
3281
|
-
const e = new H(new O().parse("xy", s(this, S), s(this, z), s(this,
|
|
3282
|
-
return s(this,
|
|
3403
|
+
const e = new H(new O().parse("xy", s(this, S), s(this, z), s(this, W)), new O("0"));
|
|
3404
|
+
return s(this, Pe) ? e.simplify() : e;
|
|
3283
3405
|
}
|
|
3284
3406
|
// get system(): { x: Equation, y: Equation } {
|
|
3285
3407
|
// const e1 = new Equation(
|
|
@@ -3295,33 +3417,33 @@ const Ze = class Ze {
|
|
|
3295
3417
|
// return { x: e1, y: e2 }
|
|
3296
3418
|
// }
|
|
3297
3419
|
get canonical() {
|
|
3298
|
-
return h(this,
|
|
3420
|
+
return h(this, xe, "canonical"), this;
|
|
3299
3421
|
}
|
|
3300
3422
|
get equation() {
|
|
3301
|
-
return h(this,
|
|
3423
|
+
return h(this, xe, "equation"), this;
|
|
3302
3424
|
}
|
|
3303
3425
|
get mxh() {
|
|
3304
|
-
return h(this,
|
|
3426
|
+
return h(this, xe, "mxh"), this;
|
|
3305
3427
|
}
|
|
3306
3428
|
get parametric() {
|
|
3307
|
-
return h(this,
|
|
3429
|
+
return h(this, xe, "parametric"), this;
|
|
3308
3430
|
}
|
|
3309
3431
|
get system() {
|
|
3310
|
-
return h(this,
|
|
3432
|
+
return h(this, xe, "system"), this;
|
|
3311
3433
|
}
|
|
3312
3434
|
get tex() {
|
|
3313
|
-
const e = s(this,
|
|
3314
|
-
switch (h(this,
|
|
3435
|
+
const e = s(this, xe);
|
|
3436
|
+
switch (h(this, xe, "canonical"), e) {
|
|
3315
3437
|
case "equation":
|
|
3316
3438
|
return this.getEquation().reorder().tex;
|
|
3317
3439
|
case "mxh":
|
|
3318
3440
|
return this.slope.isInfinity() ? "x=" + this.OA.x.tex : "y=" + new O().parse("x", this.slope, this.height).tex;
|
|
3319
3441
|
case "parametric":
|
|
3320
3442
|
case "system": {
|
|
3321
|
-
const t = s(this,
|
|
3322
|
-
return s(this,
|
|
3323
|
-
x &= ${new O(s(this,
|
|
3324
|
-
y &= ${new O(s(this,
|
|
3443
|
+
const t = s(this, J).clone();
|
|
3444
|
+
return s(this, Pe) && t.simplify(), e === "parametric" ? `${E.asTex("x", "y")} = ${E.asTex(s(this, oe).x.tex, s(this, oe).y.tex)} + k\\cdot ${E.asTex(t.x.tex, t.y.tex)}` : `\\left\\{\\begin{aligned}
|
|
3445
|
+
x &= ${new O(s(this, oe).x).add(new k(s(this, J).x).multiply(new k("k"))).reorder("k", !0).tex}\\\\
|
|
3446
|
+
y &= ${new O(s(this, oe).y).add(new k(s(this, J).y).multiply(new k("k"))).reorder("k", !0).tex}
|
|
3325
3447
|
\\end{aligned}\\right.`;
|
|
3326
3448
|
}
|
|
3327
3449
|
default: {
|
|
@@ -3331,21 +3453,21 @@ const Ze = class Ze {
|
|
|
3331
3453
|
}
|
|
3332
3454
|
}
|
|
3333
3455
|
get reduceBeforeDisplay() {
|
|
3334
|
-
return s(this,
|
|
3456
|
+
return s(this, Pe);
|
|
3335
3457
|
}
|
|
3336
3458
|
set reduceBeforeDisplay(e) {
|
|
3337
|
-
h(this,
|
|
3459
|
+
h(this, Pe, e);
|
|
3338
3460
|
}
|
|
3339
3461
|
get display() {
|
|
3340
|
-
const e = s(this,
|
|
3341
|
-
switch (h(this,
|
|
3462
|
+
const e = s(this, xe);
|
|
3463
|
+
switch (h(this, xe, "canonical"), e) {
|
|
3342
3464
|
case "equation":
|
|
3343
3465
|
return this.getEquation().reorder().display;
|
|
3344
3466
|
case "mxh":
|
|
3345
3467
|
return this.slope.isInfinity() ? "x=" + this.OA.x.display : "y=" + new O().parse("x", this.slope, this.height).display;
|
|
3346
3468
|
case "parametric": {
|
|
3347
|
-
const t = s(this,
|
|
3348
|
-
return s(this,
|
|
3469
|
+
const t = s(this, J).clone();
|
|
3470
|
+
return s(this, Pe) && t.simplify(), `((x,y))=((${s(this, oe).x.display},${s(this, oe).y.display}))+k((${t.x.display},${t.y.display}))`;
|
|
3349
3471
|
}
|
|
3350
3472
|
default: {
|
|
3351
3473
|
const t = this.getEquation();
|
|
@@ -3354,22 +3476,22 @@ const Ze = class Ze {
|
|
|
3354
3476
|
}
|
|
3355
3477
|
}
|
|
3356
3478
|
get normal() {
|
|
3357
|
-
return new
|
|
3479
|
+
return new E(s(this, S), s(this, z));
|
|
3358
3480
|
}
|
|
3359
3481
|
get director() {
|
|
3360
|
-
return s(this,
|
|
3482
|
+
return s(this, J).clone();
|
|
3361
3483
|
}
|
|
3362
3484
|
get slope() {
|
|
3363
3485
|
return s(this, S).clone().opposite().divide(s(this, z));
|
|
3364
3486
|
}
|
|
3365
3487
|
get height() {
|
|
3366
|
-
return s(this,
|
|
3488
|
+
return s(this, W).clone().opposite().divide(s(this, z));
|
|
3367
3489
|
}
|
|
3368
3490
|
fromPoints(e, t) {
|
|
3369
|
-
return this.fromPointAndDirection(e, new
|
|
3491
|
+
return this.fromPointAndDirection(e, new E(e, t));
|
|
3370
3492
|
}
|
|
3371
3493
|
distanceTo(e) {
|
|
3372
|
-
const t = e.x.clone().multiply(s(this, S)).add(e.y.clone().multiply(s(this, z))).add(s(this,
|
|
3494
|
+
const t = e.x.clone().multiply(s(this, S)).add(e.y.clone().multiply(s(this, z))).add(s(this, W)).abs(), i = this.normal.normSquare;
|
|
3373
3495
|
if (i.isZero())
|
|
3374
3496
|
return {
|
|
3375
3497
|
value: NaN,
|
|
@@ -3389,7 +3511,7 @@ const Ze = class Ze {
|
|
|
3389
3511
|
}
|
|
3390
3512
|
hitSegment(e, t) {
|
|
3391
3513
|
const i = this.intersection(
|
|
3392
|
-
new
|
|
3514
|
+
new De().fromPoints(e, t)
|
|
3393
3515
|
);
|
|
3394
3516
|
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) : !1;
|
|
3395
3517
|
}
|
|
@@ -3399,28 +3521,28 @@ const Ze = class Ze {
|
|
|
3399
3521
|
canonicalAsFloatCoefficient(e) {
|
|
3400
3522
|
e === void 0 && (e = 2);
|
|
3401
3523
|
let t = "";
|
|
3402
|
-
return s(this, S).isZero() || (s(this, S).isOne() ? t = "x" : s(this, S).clone().opposite().isOne() ? t = "-x" : t = s(this, S).value.toFixed(e) + "x"), s(this, z).isZero() || (s(this, z).isPositive() && (t += "+"), t += s(this, z).value.toFixed(e) + "y"), s(this,
|
|
3524
|
+
return s(this, S).isZero() || (s(this, S).isOne() ? t = "x" : s(this, S).clone().opposite().isOne() ? t = "-x" : t = s(this, S).value.toFixed(e) + "x"), s(this, z).isZero() || (s(this, z).isPositive() && (t += "+"), t += s(this, z).value.toFixed(e) + "y"), s(this, W).isZero() || (s(this, W).isPositive() && (t += "+"), t += s(this, W).value.toFixed(e)), t + "=0";
|
|
3403
3525
|
}
|
|
3404
3526
|
};
|
|
3405
|
-
|
|
3406
|
-
a(
|
|
3407
|
-
let R =
|
|
3408
|
-
var
|
|
3409
|
-
const
|
|
3527
|
+
Pe = new WeakMap(), S = new WeakMap(), z = new WeakMap(), W = new WeakMap(), oe = new WeakMap(), J = new WeakMap(), Ie = new WeakMap(), xe = new WeakMap(), // A line is defined as the canonical form
|
|
3528
|
+
a(De, "PERPENDICULAR", we.Perpendicular), a(De, "PARALLEL", we.Parallel);
|
|
3529
|
+
let R = De;
|
|
3530
|
+
var he, j, qe, Ut, Wt, Gt, le, Pi, Nt, Ii, Bi, Si, hi;
|
|
3531
|
+
const Ht = class Ht {
|
|
3410
3532
|
constructor(...e) {
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3533
|
+
m(this, le);
|
|
3534
|
+
m(this, he);
|
|
3535
|
+
m(this, j);
|
|
3536
|
+
m(this, qe);
|
|
3415
3537
|
/**
|
|
3416
3538
|
* Get the relative position between circle and line. It corresponds to the number of intersection.
|
|
3417
3539
|
* @param {Line} L
|
|
3418
3540
|
* @returns {number}
|
|
3419
3541
|
*/
|
|
3420
3542
|
a(this, "relativePosition", (e) => {
|
|
3421
|
-
if (s(this,
|
|
3543
|
+
if (s(this, he) === void 0 || s(this, j) === void 0)
|
|
3422
3544
|
throw new Error("Circle not defined");
|
|
3423
|
-
const t = e.distanceTo(s(this,
|
|
3545
|
+
const t = e.distanceTo(s(this, he)), i = Math.sqrt(s(this, j).value);
|
|
3424
3546
|
return t.value - i > 1e-10 ? 0 : Math.abs(t.value - i) < 1e-10 ? 1 : 2;
|
|
3425
3547
|
});
|
|
3426
3548
|
a(this, "lineIntersection", (e) => {
|
|
@@ -3430,13 +3552,13 @@ const Wt = class Wt {
|
|
|
3430
3552
|
const i = s(this, qe).clone(), n = e.getEquation().clone().isolate("x"), r = e.getEquation().clone().isolate("y");
|
|
3431
3553
|
return n instanceof H && r instanceof H && (i.replaceBy("y", r.right).simplify(), i.solve()), t;
|
|
3432
3554
|
});
|
|
3433
|
-
a(this, "tangents", (e) => e instanceof u ? s(this, Gt).call(this, e) : this.isPointOnCircle(e) ? s(this,
|
|
3555
|
+
a(this, "tangents", (e) => e instanceof u ? s(this, Gt).call(this, e) : this.isPointOnCircle(e) ? s(this, Ut).call(this, e) : s(this, he) !== void 0 && s(this, he).distanceTo(e).value > this.radius.value ? s(this, Wt).call(this, e) : (console.log("No tangents as the point is inside !"), []));
|
|
3434
3556
|
a(this, "isPointOnCircle", (e) => {
|
|
3435
3557
|
var t;
|
|
3436
3558
|
return ((t = s(this, qe)) == null ? void 0 : t.test({ x: e.x, y: e.y })) ?? !1;
|
|
3437
3559
|
});
|
|
3438
3560
|
a(this, "getPointsOnCircle", (e) => {
|
|
3439
|
-
const t =
|
|
3561
|
+
const t = U.pythagoreanTripletsWithTarget(this.squareRadius.value, !0), i = [];
|
|
3440
3562
|
return t.forEach((n) => {
|
|
3441
3563
|
for (const r of [[1, 1], [-1, 1], [-1, -1], [1, -1]])
|
|
3442
3564
|
i.push(
|
|
@@ -3447,26 +3569,26 @@ const Wt = class Wt {
|
|
|
3447
3569
|
);
|
|
3448
3570
|
}), i;
|
|
3449
3571
|
});
|
|
3450
|
-
|
|
3451
|
-
const t = new
|
|
3572
|
+
m(this, Ut, (e) => {
|
|
3573
|
+
const t = new E(this.center, e);
|
|
3452
3574
|
return [new R(e, t, we.Perpendicular)];
|
|
3453
3575
|
});
|
|
3454
|
-
|
|
3576
|
+
m(this, Wt, (e) => {
|
|
3455
3577
|
const t = this.center.x.clone().subtract(e.x), i = this.center.y.clone().subtract(e.y), n = new O("x"), r = new O("x^2+1");
|
|
3456
|
-
return n.multiply(t).subtract(i).pow(2), r.multiply(this.squareRadius), new H(n, r).solve().map((
|
|
3457
|
-
let
|
|
3458
|
-
const
|
|
3459
|
-
return
|
|
3578
|
+
return n.multiply(t).subtract(i).pow(2), r.multiply(this.squareRadius), new H(n, r).solve().map((f) => {
|
|
3579
|
+
let d;
|
|
3580
|
+
const p = new H("y", "x");
|
|
3581
|
+
return f.exact instanceof u ? (d = e.x.clone().opposite().multiply(f.exact).add(e.y), p.right.multiply(f.exact).add(d)) : (d = e.x.clone().opposite().multiply(f.value).add(e.y), p.right.multiply(f.value).add(d)), new R(p);
|
|
3460
3582
|
});
|
|
3461
3583
|
});
|
|
3462
|
-
|
|
3463
|
-
const t = e.numerator, i = -e.denominator, n = this.center.x.clone(), r = this.center.y.clone(), l = this.squareRadius.clone().multiply(e.numerator ** 2 + e.denominator ** 2), c = n.clone().multiply(t).opposite().subtract(r.clone().multiply(i)).add(l.clone().sqrt()),
|
|
3464
|
-
return [new R(t, i, c), new R(t, i,
|
|
3584
|
+
m(this, Gt, (e) => {
|
|
3585
|
+
const t = e.numerator, i = -e.denominator, n = this.center.x.clone(), r = this.center.y.clone(), l = this.squareRadius.clone().multiply(e.numerator ** 2 + e.denominator ** 2), c = n.clone().multiply(t).opposite().subtract(r.clone().multiply(i)).add(l.clone().sqrt()), f = n.clone().multiply(t).opposite().subtract(r.clone().multiply(i)).subtract(l.clone().sqrt());
|
|
3586
|
+
return [new R(t, i, c), new R(t, i, f)];
|
|
3465
3587
|
});
|
|
3466
3588
|
e.length > 0 && this.parse(...e);
|
|
3467
3589
|
}
|
|
3468
3590
|
get center() {
|
|
3469
|
-
return s(this,
|
|
3591
|
+
return s(this, he) ?? new B();
|
|
3470
3592
|
}
|
|
3471
3593
|
get squareRadius() {
|
|
3472
3594
|
return s(this, j) ?? new u(0);
|
|
@@ -3499,17 +3621,17 @@ const Wt = class Wt {
|
|
|
3499
3621
|
return this.center.x.isZero() ? e = "x^2" : e = `(x${this.center.x.isNegative() ? "+" : "-"}${this.center.x.clone().abs().tex})^2`, this.center.y.isZero() ? t = "y^2" : t = `(y${this.center.y.isNegative() ? "+" : "-"}${this.center.y.clone().abs().tex})^2`, `${e}+${t}=${this.squareRadius.display}`;
|
|
3500
3622
|
}
|
|
3501
3623
|
clone() {
|
|
3502
|
-
return new
|
|
3624
|
+
return new Ht(
|
|
3503
3625
|
this.center.clone(),
|
|
3504
3626
|
this.squareRadius.clone(),
|
|
3505
3627
|
!0
|
|
3506
3628
|
);
|
|
3507
3629
|
}
|
|
3508
3630
|
setRadius(e, t) {
|
|
3509
|
-
return t ? h(this, j, new u(e)) : h(this, j, new u(e).pow(2)),
|
|
3631
|
+
return t ? h(this, j, new u(e)) : h(this, j, new u(e).pow(2)), A(this, le, Nt).call(this), this;
|
|
3510
3632
|
}
|
|
3511
3633
|
parse(...e) {
|
|
3512
|
-
return
|
|
3634
|
+
return A(this, le, Pi).call(this), typeof e[0] == "string" ? A(this, le, hi).call(this, new H(e[0])) : e[0] instanceof H ? A(this, le, hi).call(this, e[0]) : e[0] instanceof Ht ? A(this, le, Ii).call(this, e[0]) : e[0] instanceof B && e.length > 1 && (e[1] instanceof B ? e[2] instanceof B || A(this, le, Si).call(this, e[0], e[1]) : (e[1] instanceof u || typeof e[1] == "number") && A(this, le, Bi).call(this, e[0], e[1], typeof e[2] == "boolean" ? e[2] : !1)), A(this, le, Nt).call(this), this;
|
|
3513
3635
|
}
|
|
3514
3636
|
// private _parseThroughtThreePoints(A: Point, B: Point, C: Point): this {
|
|
3515
3637
|
// const T = new Triangle(A, B, C), mAB = T.remarquables.mediators.AB.clone(),
|
|
@@ -3518,35 +3640,35 @@ const Wt = class Wt {
|
|
|
3518
3640
|
// return this
|
|
3519
3641
|
// }
|
|
3520
3642
|
};
|
|
3521
|
-
|
|
3522
|
-
return h(this,
|
|
3523
|
-
},
|
|
3643
|
+
he = new WeakMap(), j = new WeakMap(), qe = new WeakMap(), Ut = new WeakMap(), Wt = new WeakMap(), Gt = new WeakMap(), le = new WeakSet(), Pi = function() {
|
|
3644
|
+
return h(this, he, void 0), h(this, j, void 0), h(this, qe, void 0), this;
|
|
3645
|
+
}, Nt = function() {
|
|
3524
3646
|
h(this, qe, new H(
|
|
3525
3647
|
new O(`(x-(${this.center.x.display}))^2+(y-(${this.center.y.display}))^2`),
|
|
3526
3648
|
new O(this.squareRadius.display)
|
|
3527
3649
|
).moveLeft());
|
|
3528
|
-
},
|
|
3529
|
-
return h(this,
|
|
3530
|
-
},
|
|
3531
|
-
return h(this,
|
|
3532
|
-
},
|
|
3533
|
-
return h(this,
|
|
3534
|
-
},
|
|
3650
|
+
}, Ii = function(e) {
|
|
3651
|
+
return h(this, he, e.center.clone()), h(this, j, e.squareRadius.clone()), A(this, le, Nt).call(this), this;
|
|
3652
|
+
}, Bi = function(e, t, i) {
|
|
3653
|
+
return h(this, he, e.clone()), i ? h(this, j, new u(t)) : h(this, j, new u(t).pow(2)), this;
|
|
3654
|
+
}, Si = function(e, t) {
|
|
3655
|
+
return h(this, he, e.clone()), h(this, j, new E(s(this, he), t).normSquare), this;
|
|
3656
|
+
}, hi = function(e) {
|
|
3535
3657
|
if (e.moveLeft(), e.degree("x").value === 2 && e.degree("y").value === 2) {
|
|
3536
3658
|
const t = e.left.monomByDegree(2, "x"), i = e.left.monomByDegree(2, "y");
|
|
3537
3659
|
let n, r, l;
|
|
3538
|
-
t.coefficient.isEqual(i.coefficient) ? (e.divide(t.coefficient), n = e.left.monomByDegree(1, "x"), r = e.left.monomByDegree(1, "y"), l = e.left.monomByDegree(0), h(this,
|
|
3660
|
+
t.coefficient.isEqual(i.coefficient) ? (e.divide(t.coefficient), n = e.left.monomByDegree(1, "x"), r = e.left.monomByDegree(1, "y"), l = e.left.monomByDegree(0), h(this, he, new B(n.coefficient.clone().divide(2).opposite(), r.coefficient.clone().divide(2).opposite())), h(this, j, l.coefficient.clone().opposite().add(s(this, he).x.clone().pow(2)).add(s(this, he).y.clone().pow(2)))) : (h(this, he, void 0), h(this, j, void 0));
|
|
3539
3661
|
}
|
|
3540
3662
|
return this;
|
|
3541
3663
|
};
|
|
3542
|
-
let Tt =
|
|
3543
|
-
var L,
|
|
3544
|
-
const
|
|
3664
|
+
let Tt = Ht;
|
|
3665
|
+
var L, G;
|
|
3666
|
+
const ct = class ct {
|
|
3545
3667
|
constructor(e, t) {
|
|
3546
3668
|
// ax + by + c = 0
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
a(this, "clone", () => (h(this,
|
|
3669
|
+
m(this, L, new B());
|
|
3670
|
+
m(this, G, new E());
|
|
3671
|
+
a(this, "clone", () => (h(this, G, s(this, G).clone()), h(this, L, s(this, L).clone()), this));
|
|
3550
3672
|
// ------------------------------------------
|
|
3551
3673
|
// Mathematical operations
|
|
3552
3674
|
// ------------------------------------------
|
|
@@ -3586,14 +3708,14 @@ const lt = class lt {
|
|
|
3586
3708
|
// return new Fraction().invalid()
|
|
3587
3709
|
// }
|
|
3588
3710
|
a(this, "randomPoint", (e = 5) => {
|
|
3589
|
-
const t = s(this, L).clone(), i = new u(
|
|
3711
|
+
const t = s(this, L).clone(), i = new u(Q(e, !1));
|
|
3590
3712
|
return new B(
|
|
3591
|
-
t.x.clone().add(s(this,
|
|
3592
|
-
t.y.clone().add(s(this,
|
|
3593
|
-
t.z.clone().add(s(this,
|
|
3713
|
+
t.x.clone().add(s(this, G).x.clone().multiply(i)),
|
|
3714
|
+
t.y.clone().add(s(this, G).y.clone().multiply(i)),
|
|
3715
|
+
t.z.clone().add(s(this, G).z.clone().multiply(i))
|
|
3594
3716
|
);
|
|
3595
3717
|
});
|
|
3596
|
-
return h(this, L, e.clone()), h(this,
|
|
3718
|
+
return h(this, L, e.clone()), h(this, G, t.asPoint ? new E(e, t) : t.clone()), this;
|
|
3597
3719
|
}
|
|
3598
3720
|
get OA() {
|
|
3599
3721
|
return s(this, L);
|
|
@@ -3605,18 +3727,18 @@ const lt = class lt {
|
|
|
3605
3727
|
return s(this, L).clone();
|
|
3606
3728
|
}
|
|
3607
3729
|
get d() {
|
|
3608
|
-
return s(this,
|
|
3730
|
+
return s(this, G);
|
|
3609
3731
|
}
|
|
3610
3732
|
set d(e) {
|
|
3611
|
-
h(this,
|
|
3733
|
+
h(this, G, e);
|
|
3612
3734
|
}
|
|
3613
3735
|
get tex() {
|
|
3614
3736
|
return {
|
|
3615
|
-
parametric: `${
|
|
3737
|
+
parametric: `${E.asTex("x", "y", "z")} = ${E.asTex(s(this, L).x.tex, s(this, L).y.tex, s(this, L).z.tex)} + k\\cdot ${E.asTex(s(this, G).x.tex, s(this, G).y.tex, s(this, G).z.tex)}`,
|
|
3616
3738
|
system: `\\left\\{\\begin{aligned}
|
|
3617
|
-
x &= ${new O(s(this, L).x).add(new
|
|
3618
|
-
y &= ${new O(s(this, L).y).add(new
|
|
3619
|
-
z &= ${new O(s(this, L).z).add(new
|
|
3739
|
+
x &= ${new O(s(this, L).x).add(new k(s(this, G).x).multiply(new k("k"))).reorder("k", !0).tex}\\\\
|
|
3740
|
+
y &= ${new O(s(this, L).y).add(new k(s(this, G).y).multiply(new k("k"))).reorder("k", !0).tex}\\\\
|
|
3741
|
+
z &= ${new O(s(this, L).z).add(new k(s(this, G).z).multiply(new k("k"))).reorder("k", !0).tex}
|
|
3620
3742
|
\\end{aligned}\\right.`,
|
|
3621
3743
|
cartesian: `\\frac{ ${new O("x", 1, s(this, L).x.clone().opposite()).tex} }{ ${this.direction.x.tex} } = \\frac{ ${new O("y", 1, s(this, L).y.clone().opposite()).tex} }{ ${this.direction.y.tex} } = \\frac{ ${new O("z", 1, s(this, L).z.clone().opposite()).tex} }{ ${this.direction.z.tex} }`
|
|
3622
3744
|
};
|
|
@@ -3624,16 +3746,16 @@ const lt = class lt {
|
|
|
3624
3746
|
get display() {
|
|
3625
3747
|
const e = s(this, L).x.display, t = s(this, L).y.display, i = s(this, L).z.display, n = this.direction.simplify(), r = n.x.display, l = n.y.display, c = n.z.display;
|
|
3626
3748
|
return {
|
|
3627
|
-
parametric: `${
|
|
3749
|
+
parametric: `${E.asDisplay("x", "y", "z")} = ${E.asDisplay(s(this, L).x.display, s(this, L).y.display, s(this, L).z.display)} + k\\cdot ${E.asDisplay(s(this, G).x.display, s(this, G).y.display, s(this, G).z.display)}`,
|
|
3628
3750
|
system: "",
|
|
3629
3751
|
cartesian: `(x-${e})/${r} = (y-${t})/${l} = (z-${i})/${c}`
|
|
3630
3752
|
};
|
|
3631
3753
|
}
|
|
3632
3754
|
get direction() {
|
|
3633
|
-
return s(this,
|
|
3755
|
+
return s(this, G).clone();
|
|
3634
3756
|
}
|
|
3635
3757
|
distanceTo(e) {
|
|
3636
|
-
const t = new
|
|
3758
|
+
const t = new E(s(this, L), e), i = this.direction, n = this.direction.normSquare, r = t.cross(i).normSquare, l = r.clone().divide(n), c = l.clone().sqrt();
|
|
3637
3759
|
return console.log("CROSS", t.cross(i).display), {
|
|
3638
3760
|
value: Math.sqrt(l.value),
|
|
3639
3761
|
fraction: l.clone().sqrt(),
|
|
@@ -3642,69 +3764,69 @@ const lt = class lt {
|
|
|
3642
3764
|
}
|
|
3643
3765
|
hitSegment(e, t) {
|
|
3644
3766
|
const i = this.intersection(
|
|
3645
|
-
new
|
|
3767
|
+
new ct(e, t)
|
|
3646
3768
|
);
|
|
3647
3769
|
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;
|
|
3648
3770
|
}
|
|
3649
3771
|
};
|
|
3650
|
-
L = new WeakMap(),
|
|
3651
|
-
a(
|
|
3652
|
-
let
|
|
3653
|
-
var
|
|
3654
|
-
class
|
|
3772
|
+
L = new WeakMap(), G = new WeakMap(), // A line is defined as the canonical form
|
|
3773
|
+
a(ct, "PERPENDICULAR", oi.Perpendicular), a(ct, "PARALLEL", oi.Parallel);
|
|
3774
|
+
let Ot = ct;
|
|
3775
|
+
var Me;
|
|
3776
|
+
class cs {
|
|
3655
3777
|
constructor(...e) {
|
|
3656
|
-
|
|
3657
|
-
return h(this,
|
|
3778
|
+
m(this, Me, []);
|
|
3779
|
+
return h(this, Me, e), this;
|
|
3658
3780
|
}
|
|
3659
3781
|
get values() {
|
|
3660
|
-
return s(this,
|
|
3782
|
+
return s(this, Me);
|
|
3661
3783
|
}
|
|
3662
3784
|
get array() {
|
|
3663
|
-
return s(this,
|
|
3785
|
+
return s(this, Me).map((e) => e.array);
|
|
3664
3786
|
}
|
|
3665
3787
|
get dimension() {
|
|
3666
|
-
return [s(this,
|
|
3788
|
+
return [s(this, Me).length, s(this, Me)[0].dimension];
|
|
3667
3789
|
}
|
|
3668
3790
|
isSquare() {
|
|
3669
|
-
return s(this,
|
|
3791
|
+
return s(this, Me).length === s(this, Me)[0].dimension;
|
|
3670
3792
|
}
|
|
3671
3793
|
determinant() {
|
|
3672
3794
|
if (!this.isSquare())
|
|
3673
3795
|
throw new Error("Matrix is not square");
|
|
3674
|
-
return
|
|
3796
|
+
return hs(...this.values);
|
|
3675
3797
|
}
|
|
3676
3798
|
}
|
|
3677
|
-
|
|
3678
|
-
var
|
|
3679
|
-
const
|
|
3799
|
+
Me = new WeakMap();
|
|
3800
|
+
var ke, Ue;
|
|
3801
|
+
const mi = class mi {
|
|
3680
3802
|
constructor(e) {
|
|
3681
|
-
|
|
3682
|
-
|
|
3803
|
+
m(this, ke, new E(0, 0, 1));
|
|
3804
|
+
m(this, Ue, new B(0, 0, 0));
|
|
3683
3805
|
return e && this.parse(e), this;
|
|
3684
3806
|
}
|
|
3685
3807
|
get normal() {
|
|
3686
|
-
return s(this,
|
|
3808
|
+
return s(this, ke);
|
|
3687
3809
|
}
|
|
3688
3810
|
set normal(e) {
|
|
3689
|
-
h(this,
|
|
3811
|
+
h(this, ke, e), s(this, ke).asPoint = !1;
|
|
3690
3812
|
}
|
|
3691
3813
|
get point() {
|
|
3692
|
-
return s(this,
|
|
3814
|
+
return s(this, Ue);
|
|
3693
3815
|
}
|
|
3694
3816
|
set point(e) {
|
|
3695
|
-
h(this,
|
|
3817
|
+
h(this, Ue, e), s(this, Ue).asPoint = !0;
|
|
3696
3818
|
}
|
|
3697
3819
|
get a() {
|
|
3698
|
-
return s(this,
|
|
3820
|
+
return s(this, ke).x;
|
|
3699
3821
|
}
|
|
3700
3822
|
get b() {
|
|
3701
|
-
return s(this,
|
|
3823
|
+
return s(this, ke).y;
|
|
3702
3824
|
}
|
|
3703
3825
|
get c() {
|
|
3704
|
-
return s(this,
|
|
3826
|
+
return s(this, ke).z;
|
|
3705
3827
|
}
|
|
3706
3828
|
get d() {
|
|
3707
|
-
return s(this,
|
|
3829
|
+
return s(this, ke).dot(s(this, Ue)).opposite();
|
|
3708
3830
|
}
|
|
3709
3831
|
get tex() {
|
|
3710
3832
|
return new H(
|
|
@@ -3725,26 +3847,26 @@ const gi = class gi {
|
|
|
3725
3847
|
return;
|
|
3726
3848
|
}
|
|
3727
3849
|
if (e.equation) {
|
|
3728
|
-
const r = e.equation.moveLeft().reduce().left, l = r.monomByLetter("x").coefficient, c = r.monomByLetter("y").coefficient,
|
|
3729
|
-
this.normal = new
|
|
3850
|
+
const r = e.equation.moveLeft().reduce().left, l = r.monomByLetter("x").coefficient, c = r.monomByLetter("y").coefficient, f = r.monomByLetter("z").coefficient, d = r.monomByDegree(0).coefficient;
|
|
3851
|
+
this.normal = new E(l, c, f), l.isNotZero() ? this.point = new B(d.clone().divide(l).opposite(), 0, 0) : c.isNotZero() ? this.point = new B(0, d.clone().divide(c).opposite(), 0) : this.point = new B(0, 0, d.clone().divide(f).opposite());
|
|
3730
3852
|
return;
|
|
3731
3853
|
}
|
|
3732
|
-
if (((i = e.points) == null ? void 0 : i.length) === 3 && e.points.every((r) => r instanceof
|
|
3733
|
-
const r = e.points[0], l = e.points[1], c = e.points[2],
|
|
3734
|
-
this.normal =
|
|
3854
|
+
if (((i = e.points) == null ? void 0 : i.length) === 3 && e.points.every((r) => r instanceof E)) {
|
|
3855
|
+
const r = e.points[0], l = e.points[1], c = e.points[2], f = new E(r, l), d = new E(r, c);
|
|
3856
|
+
this.normal = f.cross(d), this.point = r;
|
|
3735
3857
|
return;
|
|
3736
3858
|
}
|
|
3737
3859
|
if (((n = e.coefficients) == null ? void 0 : n.length) === 4) {
|
|
3738
|
-
const [r, l, c,
|
|
3739
|
-
this.normal = new
|
|
3860
|
+
const [r, l, c, f] = e.coefficients;
|
|
3861
|
+
this.normal = new E(r, l, c), this.point = new B(0, 0, -f);
|
|
3740
3862
|
return;
|
|
3741
3863
|
}
|
|
3742
3864
|
}
|
|
3743
3865
|
angle(e, t, i) {
|
|
3744
|
-
if (e instanceof
|
|
3866
|
+
if (e instanceof mi)
|
|
3745
3867
|
return this.normal.angle(e.normal, t, i);
|
|
3746
3868
|
let n;
|
|
3747
|
-
if (e instanceof
|
|
3869
|
+
if (e instanceof E) {
|
|
3748
3870
|
if (e.dimension !== 3)
|
|
3749
3871
|
throw new Error("Vector is not 3D");
|
|
3750
3872
|
n = e;
|
|
@@ -3766,25 +3888,25 @@ const gi = class gi {
|
|
|
3766
3888
|
return this.normal.dot(e).add(this.d).isZero();
|
|
3767
3889
|
}
|
|
3768
3890
|
};
|
|
3769
|
-
|
|
3770
|
-
let
|
|
3771
|
-
var
|
|
3772
|
-
const
|
|
3891
|
+
ke = new WeakMap(), Ue = new WeakMap();
|
|
3892
|
+
let ai = mi;
|
|
3893
|
+
var Y, _, ee, st, Ce, yt, Xt, wt, Be, Yt, nt;
|
|
3894
|
+
const Qt = class Qt {
|
|
3773
3895
|
constructor(...e) {
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3896
|
+
m(this, Y, new B());
|
|
3897
|
+
m(this, _, new B());
|
|
3898
|
+
m(this, ee, new B());
|
|
3899
|
+
m(this, st, {
|
|
3778
3900
|
AB: new R(),
|
|
3779
3901
|
AC: new R(),
|
|
3780
3902
|
BC: new R()
|
|
3781
3903
|
});
|
|
3782
|
-
|
|
3904
|
+
m(this, Ce, {
|
|
3783
3905
|
AB: new B(),
|
|
3784
3906
|
AC: new B(),
|
|
3785
3907
|
BC: new B()
|
|
3786
3908
|
});
|
|
3787
|
-
|
|
3909
|
+
m(this, yt, null);
|
|
3788
3910
|
// ------------------------------------------
|
|
3789
3911
|
// Creation / parsing functions
|
|
3790
3912
|
// ------------------------------------------
|
|
@@ -3792,7 +3914,6 @@ const Yt = class Yt {
|
|
|
3792
3914
|
* Parse values to a triangle. Supported formats:
|
|
3793
3915
|
* Vector2D, Vector2D, Vector2D
|
|
3794
3916
|
* x1, y1, x2, y2, x3, y3
|
|
3795
|
-
* TODO: Something else ?
|
|
3796
3917
|
* @param values
|
|
3797
3918
|
*/
|
|
3798
3919
|
a(this, "parse", (...e) => {
|
|
@@ -3801,9 +3922,9 @@ const Yt = class Yt {
|
|
|
3801
3922
|
if (t.some((i) => i.isNaN()))
|
|
3802
3923
|
throw new Error("One of the values is not a valid number");
|
|
3803
3924
|
return this.parse(
|
|
3804
|
-
new
|
|
3805
|
-
new
|
|
3806
|
-
new
|
|
3925
|
+
new E(t[0], t[1]),
|
|
3926
|
+
new E(t[2], t[3]),
|
|
3927
|
+
new E(t[4], t[5])
|
|
3807
3928
|
);
|
|
3808
3929
|
} else if (e.length === 3) {
|
|
3809
3930
|
if (e.every((t) => typeof t == "string"))
|
|
@@ -3812,36 +3933,36 @@ const Yt = class Yt {
|
|
|
3812
3933
|
);
|
|
3813
3934
|
if (e.every((t) => t instanceof R)) {
|
|
3814
3935
|
const t = e[0].clone(), i = e[1].clone(), n = e[2].clone();
|
|
3815
|
-
h(this,
|
|
3936
|
+
h(this, st, { AB: t, BC: i, AC: n });
|
|
3816
3937
|
let r = t.intersection(i);
|
|
3817
3938
|
if (r.hasIntersection)
|
|
3818
|
-
h(this,
|
|
3939
|
+
h(this, _, r.point.clone());
|
|
3819
3940
|
else
|
|
3820
3941
|
throw new Error("Lines do not intersect !");
|
|
3821
3942
|
if (r = i.intersection(n), r.hasIntersection)
|
|
3822
|
-
h(this,
|
|
3943
|
+
h(this, ee, r.point.clone());
|
|
3823
3944
|
else
|
|
3824
3945
|
throw new Error("Lines do not intersect !");
|
|
3825
3946
|
if (r = n.intersection(t), r.hasIntersection)
|
|
3826
|
-
h(this,
|
|
3947
|
+
h(this, Y, r.point.clone());
|
|
3827
3948
|
else
|
|
3828
3949
|
throw new Error("Lines do not intersect !");
|
|
3829
|
-
} else e.every((t) => t instanceof B) && (h(this,
|
|
3830
|
-
AB: new R(s(this,
|
|
3831
|
-
BC: new R(s(this,
|
|
3832
|
-
AC: new R(s(this,
|
|
3950
|
+
} else e.every((t) => t instanceof B) && (h(this, Y, e[0].clone()), h(this, _, e[1].clone()), h(this, ee, e[2].clone()), h(this, st, {
|
|
3951
|
+
AB: new R(s(this, Y), s(this, _)),
|
|
3952
|
+
BC: new R(s(this, _), s(this, ee)),
|
|
3953
|
+
AC: new R(s(this, Y), s(this, ee))
|
|
3833
3954
|
}));
|
|
3834
|
-
} else if (e.length === 1 && e[0] instanceof
|
|
3955
|
+
} else if (e.length === 1 && e[0] instanceof Qt)
|
|
3835
3956
|
return e[0].clone();
|
|
3836
|
-
return s(this,
|
|
3957
|
+
return s(this, Xt).call(this), this;
|
|
3837
3958
|
});
|
|
3838
3959
|
/**
|
|
3839
3960
|
* Clone the Triangle class
|
|
3840
3961
|
*/
|
|
3841
|
-
a(this, "clone", () => new
|
|
3842
|
-
s(this,
|
|
3843
|
-
s(this,
|
|
3844
|
-
s(this,
|
|
3962
|
+
a(this, "clone", () => new Qt(
|
|
3963
|
+
s(this, Y).clone(),
|
|
3964
|
+
s(this, _).clone(),
|
|
3965
|
+
s(this, ee).clone()
|
|
3845
3966
|
));
|
|
3846
3967
|
// ------------------------------------------
|
|
3847
3968
|
// Triangle operations and properties
|
|
@@ -3849,79 +3970,79 @@ const Yt = class Yt {
|
|
|
3849
3970
|
/**
|
|
3850
3971
|
* Generate the Line object for the three segments of the triangle
|
|
3851
3972
|
*/
|
|
3852
|
-
|
|
3853
|
-
s(this,
|
|
3854
|
-
AB: new B().middleOf(s(this,
|
|
3855
|
-
AC: new B().middleOf(s(this,
|
|
3856
|
-
BC: new B().middleOf(s(this,
|
|
3857
|
-
}), h(this, yt, s(this,
|
|
3973
|
+
m(this, Xt, () => {
|
|
3974
|
+
s(this, Y).asPoint = !0, s(this, _).asPoint = !0, s(this, ee).asPoint = !0, h(this, Ce, {
|
|
3975
|
+
AB: new B().middleOf(s(this, Y), s(this, _)),
|
|
3976
|
+
AC: new B().middleOf(s(this, Y), s(this, ee)),
|
|
3977
|
+
BC: new B().middleOf(s(this, _), s(this, ee))
|
|
3978
|
+
}), h(this, yt, s(this, Yt).call(this));
|
|
3858
3979
|
});
|
|
3859
3980
|
/**
|
|
3860
3981
|
* Get the Vector2D class for the given name
|
|
3861
3982
|
* @param ptName
|
|
3862
3983
|
*/
|
|
3863
|
-
|
|
3984
|
+
m(this, wt, (e) => {
|
|
3864
3985
|
switch (e.toUpperCase()) {
|
|
3865
3986
|
case "A":
|
|
3866
|
-
return s(this,
|
|
3987
|
+
return s(this, Y);
|
|
3867
3988
|
case "B":
|
|
3868
|
-
return s(this,
|
|
3989
|
+
return s(this, _);
|
|
3869
3990
|
case "C":
|
|
3870
|
-
return s(this,
|
|
3991
|
+
return s(this, ee);
|
|
3871
3992
|
}
|
|
3872
|
-
return s(this,
|
|
3993
|
+
return s(this, Y);
|
|
3873
3994
|
});
|
|
3874
3995
|
/**
|
|
3875
3996
|
* Get the vector for the segment given by name.
|
|
3876
3997
|
* @param ptName1
|
|
3877
3998
|
* @param ptName2
|
|
3878
3999
|
*/
|
|
3879
|
-
|
|
4000
|
+
m(this, Be, (e, t) => new E(
|
|
3880
4001
|
s(this, wt).call(this, e),
|
|
3881
4002
|
s(this, wt).call(this, t)
|
|
3882
4003
|
));
|
|
3883
|
-
|
|
4004
|
+
m(this, Yt, () => {
|
|
3884
4005
|
const e = {
|
|
3885
|
-
A: new R().fromPoints(s(this,
|
|
3886
|
-
B: new R().fromPoints(s(this,
|
|
3887
|
-
C: new R().fromPoints(s(this,
|
|
4006
|
+
A: new R().fromPoints(s(this, Y), s(this, Ce).BC),
|
|
4007
|
+
B: new R().fromPoints(s(this, _), s(this, Ce).AC),
|
|
4008
|
+
C: new R().fromPoints(s(this, ee), s(this, Ce).AB),
|
|
3888
4009
|
intersection: null
|
|
3889
4010
|
}, t = {
|
|
3890
|
-
AB: new R().fromPointAndNormal(s(this, Ce).AB, new
|
|
3891
|
-
AC: new R().fromPointAndNormal(s(this, Ce).AC, new
|
|
3892
|
-
BC: new R().fromPointAndNormal(s(this, Ce).BC, new
|
|
4011
|
+
AB: new R().fromPointAndNormal(s(this, Ce).AB, new E(s(this, Y), s(this, _)).normal()),
|
|
4012
|
+
AC: new R().fromPointAndNormal(s(this, Ce).AC, new E(s(this, Y), s(this, ee)).normal()),
|
|
4013
|
+
BC: new R().fromPointAndNormal(s(this, Ce).BC, new E(s(this, _), s(this, ee)).normal()),
|
|
3893
4014
|
intersection: null
|
|
3894
4015
|
}, i = {
|
|
3895
|
-
A: new R().fromPointAndNormal(s(this,
|
|
3896
|
-
B: new R().fromPointAndNormal(s(this,
|
|
3897
|
-
C: new R().fromPointAndNormal(s(this,
|
|
4016
|
+
A: new R().fromPointAndNormal(s(this, Y), new E(s(this, _), s(this, ee)).normal()),
|
|
4017
|
+
B: new R().fromPointAndNormal(s(this, _), new E(s(this, Y), s(this, ee)).normal()),
|
|
4018
|
+
C: new R().fromPointAndNormal(s(this, ee), new E(s(this, Y), s(this, _)).normal()),
|
|
3898
4019
|
intersection: null
|
|
3899
|
-
}, n = s(this,
|
|
4020
|
+
}, n = s(this, nt).call(this, "A"), r = s(this, nt).call(this, "B"), l = s(this, nt).call(this, "C"), c = {
|
|
3900
4021
|
A: n.internal,
|
|
3901
4022
|
B: r.internal,
|
|
3902
4023
|
C: r.internal,
|
|
3903
4024
|
intersection: null
|
|
3904
|
-
},
|
|
4025
|
+
}, f = {
|
|
3905
4026
|
A: n.external,
|
|
3906
4027
|
B: r.external,
|
|
3907
4028
|
C: l.external,
|
|
3908
4029
|
intersection: null
|
|
3909
|
-
},
|
|
4030
|
+
}, d = {
|
|
3910
4031
|
medians: e,
|
|
3911
4032
|
mediators: t,
|
|
3912
4033
|
heights: i,
|
|
3913
4034
|
bisectors: c,
|
|
3914
|
-
externalBisectors:
|
|
4035
|
+
externalBisectors: f
|
|
3915
4036
|
};
|
|
3916
|
-
return
|
|
4037
|
+
return d.medians.intersection = d.medians.A.intersection(d.medians.B).point, d.mediators.intersection = d.mediators.AB.intersection(d.mediators.BC).point, d.heights.intersection = d.heights.A.intersection(d.heights.B).point, d.bisectors.intersection = d.bisectors.A.intersection(d.bisectors.B).point, d;
|
|
3917
4038
|
});
|
|
3918
|
-
|
|
4039
|
+
m(this, nt, (e) => {
|
|
3919
4040
|
const t = this.lines;
|
|
3920
4041
|
let i, n;
|
|
3921
4042
|
if (e === "A" ? (i = t.AB, n = t.AC) : e === "B" ? (i = t.AB, n = t.BC) : e === "C" && (i = t.BC, n = t.AC), i === void 0 || n === void 0)
|
|
3922
4043
|
throw new Error(`The point ${e} does not exist`);
|
|
3923
|
-
const r = i.n.simplify().norm, l = n.n.simplify().norm, c = i.getEquation().multiply(l),
|
|
3924
|
-
return e === "A" ?
|
|
4044
|
+
const r = i.n.simplify().norm, l = n.n.simplify().norm, c = i.getEquation().multiply(l), f = n.getEquation().multiply(r), d = new R(c.clone().subtract(f).simplify()), p = new R(f.clone().subtract(c).simplify());
|
|
4045
|
+
return e === "A" ? d.hitSegment(this.B, this.C) ? { internal: d, external: p } : { internal: p, external: d } : e === "B" ? d.hitSegment(this.A, this.C) ? { internal: d, external: p } : { internal: p, external: d } : e === "C" ? d.hitSegment(this.B, this.A) ? { internal: d, external: p } : { internal: p, external: d } : { internal: d, external: p };
|
|
3925
4046
|
});
|
|
3926
4047
|
return e.length > 0 && this.parse(...e), this;
|
|
3927
4048
|
}
|
|
@@ -3929,13 +4050,13 @@ const Yt = class Yt {
|
|
|
3929
4050
|
// Getter and setters
|
|
3930
4051
|
// ------------------------------------------
|
|
3931
4052
|
get A() {
|
|
3932
|
-
return s(this,
|
|
4053
|
+
return s(this, Y);
|
|
3933
4054
|
}
|
|
3934
4055
|
get B() {
|
|
3935
|
-
return s(this,
|
|
4056
|
+
return s(this, _);
|
|
3936
4057
|
}
|
|
3937
4058
|
get C() {
|
|
3938
|
-
return s(this,
|
|
4059
|
+
return s(this, ee);
|
|
3939
4060
|
}
|
|
3940
4061
|
get AB() {
|
|
3941
4062
|
return s(this, Be).call(this, "A", "B");
|
|
@@ -3965,15 +4086,15 @@ const Yt = class Yt {
|
|
|
3965
4086
|
return this.AB.normSquare.isEqual(this.BC.normSquare) || this.AB.normSquare.isEqual(this.AC.normSquare) || this.BC.normSquare.isEqual(this.AC.normSquare);
|
|
3966
4087
|
}
|
|
3967
4088
|
get lines() {
|
|
3968
|
-
return s(this,
|
|
4089
|
+
return s(this, st);
|
|
3969
4090
|
}
|
|
3970
4091
|
get remarquables() {
|
|
3971
4092
|
return s(this, yt);
|
|
3972
4093
|
}
|
|
3973
4094
|
};
|
|
3974
|
-
|
|
3975
|
-
let
|
|
3976
|
-
function
|
|
4095
|
+
Y = new WeakMap(), _ = new WeakMap(), ee = new WeakMap(), st = new WeakMap(), Ce = new WeakMap(), yt = new WeakMap(), Xt = new WeakMap(), wt = new WeakMap(), Be = new WeakMap(), Yt = new WeakMap(), nt = new WeakMap();
|
|
4096
|
+
let li = Qt;
|
|
4097
|
+
function qt(o) {
|
|
3977
4098
|
const e = Object.assign(
|
|
3978
4099
|
{
|
|
3979
4100
|
negative: !0,
|
|
@@ -3984,16 +4105,16 @@ function Ot(o) {
|
|
|
3984
4105
|
},
|
|
3985
4106
|
o
|
|
3986
4107
|
), t = new u();
|
|
3987
|
-
if (e.negative ? t.numerator =
|
|
4108
|
+
if (e.negative ? t.numerator = Q(e.max, e.zero) : t.numerator = pe(e.zero ? 0 : 1, e.max), e.natural)
|
|
3988
4109
|
t.denominator = 1;
|
|
3989
4110
|
else {
|
|
3990
4111
|
let i = 0;
|
|
3991
4112
|
for (; t.isRelative() && i < 10; )
|
|
3992
|
-
t.denominator =
|
|
4113
|
+
t.denominator = pe(1, e.max), i++;
|
|
3993
4114
|
}
|
|
3994
4115
|
return e.reduced ? t.reduce() : t;
|
|
3995
4116
|
}
|
|
3996
|
-
function
|
|
4117
|
+
function Ri(o) {
|
|
3997
4118
|
const e = Object.assign(
|
|
3998
4119
|
{
|
|
3999
4120
|
letters: "x",
|
|
@@ -4002,8 +4123,8 @@ function Pi(o) {
|
|
|
4002
4123
|
zero: !1
|
|
4003
4124
|
},
|
|
4004
4125
|
o
|
|
4005
|
-
), t = new
|
|
4006
|
-
if (t.coefficient =
|
|
4126
|
+
), t = new k();
|
|
4127
|
+
if (t.coefficient = qt({
|
|
4007
4128
|
zero: e.zero,
|
|
4008
4129
|
reduced: !0,
|
|
4009
4130
|
natural: !e.fraction
|
|
@@ -4011,14 +4132,14 @@ function Pi(o) {
|
|
|
4011
4132
|
for (const i of e.letters.split(""))
|
|
4012
4133
|
t.setLetter(i, 0);
|
|
4013
4134
|
for (let i = 0; i < e.degree; i++) {
|
|
4014
|
-
const n =
|
|
4135
|
+
const n = di(e.letters.split(""));
|
|
4015
4136
|
t.setLetter(n, t.degree(n).clone().add(1));
|
|
4016
4137
|
}
|
|
4017
4138
|
} else
|
|
4018
4139
|
t.setLetter(e.letters, e.degree);
|
|
4019
4140
|
return t;
|
|
4020
4141
|
}
|
|
4021
|
-
const
|
|
4142
|
+
const us = {
|
|
4022
4143
|
letters: "x",
|
|
4023
4144
|
degree: 2,
|
|
4024
4145
|
fraction: !1,
|
|
@@ -4029,14 +4150,14 @@ const as = {
|
|
|
4029
4150
|
numberOfMonoms: 0,
|
|
4030
4151
|
positive: !0
|
|
4031
4152
|
};
|
|
4032
|
-
function
|
|
4153
|
+
function zi(o) {
|
|
4033
4154
|
const e = Object.assign(
|
|
4034
|
-
|
|
4155
|
+
us,
|
|
4035
4156
|
o
|
|
4036
4157
|
), t = new O().empty();
|
|
4037
4158
|
let i;
|
|
4038
4159
|
for (let n = e.degree; n >= 0; n--)
|
|
4039
|
-
i =
|
|
4160
|
+
i = Ri({
|
|
4040
4161
|
letters: e.letters,
|
|
4041
4162
|
degree: n,
|
|
4042
4163
|
fraction: e.fraction,
|
|
@@ -4044,12 +4165,12 @@ function Bi(o) {
|
|
|
4044
4165
|
}), e.unit && e.degree === n && i.coefficient.one(), t.add(i);
|
|
4045
4166
|
if (e.positive && t.monomByDegree().coefficient.isNegative() && t.monomByDegree().coefficient.opposite(), e.numberOfMonoms && e.numberOfMonoms > 0 && e.numberOfMonoms < t.length)
|
|
4046
4167
|
for (; t.length > e.numberOfMonoms; ) {
|
|
4047
|
-
const n =
|
|
4168
|
+
const n = pe(1, t.length - 1);
|
|
4048
4169
|
t.monoms.splice(n, 1);
|
|
4049
4170
|
}
|
|
4050
4171
|
return t.reduce();
|
|
4051
4172
|
}
|
|
4052
|
-
function
|
|
4173
|
+
function fs(o) {
|
|
4053
4174
|
const e = Object.assign(
|
|
4054
4175
|
{
|
|
4055
4176
|
letters: "x",
|
|
@@ -4071,7 +4192,7 @@ function ls(o) {
|
|
|
4071
4192
|
o
|
|
4072
4193
|
), t = new O().one();
|
|
4073
4194
|
for (let i = 0; i < e.degree; i++) {
|
|
4074
|
-
const n =
|
|
4195
|
+
const n = zi({
|
|
4075
4196
|
degree: 1,
|
|
4076
4197
|
unit: e.unit,
|
|
4077
4198
|
fraction: e.fraction,
|
|
@@ -4082,7 +4203,7 @@ function ls(o) {
|
|
|
4082
4203
|
}
|
|
4083
4204
|
return new H(t, 0);
|
|
4084
4205
|
}
|
|
4085
|
-
function
|
|
4206
|
+
function ci(o) {
|
|
4086
4207
|
const e = Object.assign(
|
|
4087
4208
|
{
|
|
4088
4209
|
axis: !0,
|
|
@@ -4091,10 +4212,10 @@ function ui(o) {
|
|
|
4091
4212
|
quadrant: null
|
|
4092
4213
|
},
|
|
4093
4214
|
o
|
|
4094
|
-
), t = e.axis === "x", i = e.axis === "y", n = e.fraction ?
|
|
4215
|
+
), t = e.axis === "x", i = e.axis === "y", n = e.fraction ? qt({ max: e.max, zero: t }) : new u(Q(e.max, t)), r = e.fraction ? qt({ max: e.max, zero: i }) : new u(Q(e.max, i));
|
|
4095
4216
|
return Number(e.quadrant) === 1 && (n.abs(), r.abs()), Number(e.quadrant) === 2 && (n.isPositive() && n.opposite(), r.isNegative() && r.opposite()), Number(e.quadrant) === 3 && (n.isPositive() && n.opposite(), r.isPositive() && r.opposite()), Number(e.quadrant) === 4 && (n.isNegative() && n.opposite(), r.isPositive() && r.opposite()), new B(n, r);
|
|
4096
4217
|
}
|
|
4097
|
-
function
|
|
4218
|
+
function ds(o) {
|
|
4098
4219
|
const e = Object.assign(
|
|
4099
4220
|
{
|
|
4100
4221
|
center: {
|
|
@@ -4104,116 +4225,116 @@ function cs(o) {
|
|
|
4104
4225
|
pointsOnCircle: 8
|
|
4105
4226
|
},
|
|
4106
4227
|
o
|
|
4107
|
-
), t =
|
|
4228
|
+
), t = ci(e.center);
|
|
4108
4229
|
let i, n;
|
|
4109
|
-
return e.pointsOnCircle === 8 ? (i =
|
|
4230
|
+
return e.pointsOnCircle === 8 ? (i = pe(1, 3), n = i ** 2 + (i + 1) ** 2) : n = pe(1, 20), new Tt(t, n, !0);
|
|
4110
4231
|
}
|
|
4111
|
-
function
|
|
4232
|
+
function ps(o) {
|
|
4112
4233
|
const e = Object.assign(
|
|
4113
4234
|
{
|
|
4114
4235
|
A: {
|
|
4115
|
-
x:
|
|
4116
|
-
y:
|
|
4236
|
+
x: Q(10),
|
|
4237
|
+
y: Q(10)
|
|
4117
4238
|
}
|
|
4118
4239
|
},
|
|
4119
4240
|
o
|
|
4120
|
-
), t = new
|
|
4121
|
-
|
|
4122
|
-
|
|
4241
|
+
), t = new E(
|
|
4242
|
+
Q(10),
|
|
4243
|
+
Q(10)
|
|
4123
4244
|
);
|
|
4124
4245
|
for (; t.isNull; )
|
|
4125
|
-
t.x =
|
|
4126
|
-
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 R(new
|
|
4246
|
+
t.x = Q(10), t.y = Q(10);
|
|
4247
|
+
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 R(new E(e.A.x, e.A.y), t);
|
|
4127
4248
|
}
|
|
4128
|
-
function
|
|
4249
|
+
function ms(o) {
|
|
4129
4250
|
const e = Object.assign(
|
|
4130
4251
|
{
|
|
4131
4252
|
A: {
|
|
4132
|
-
x:
|
|
4133
|
-
y:
|
|
4134
|
-
z:
|
|
4253
|
+
x: Q(10),
|
|
4254
|
+
y: Q(10),
|
|
4255
|
+
z: Q(10)
|
|
4135
4256
|
},
|
|
4136
4257
|
direction: {
|
|
4137
|
-
x:
|
|
4138
|
-
y:
|
|
4139
|
-
z:
|
|
4258
|
+
x: Q(10),
|
|
4259
|
+
y: Q(10),
|
|
4260
|
+
z: Q(10)
|
|
4140
4261
|
}
|
|
4141
4262
|
},
|
|
4142
4263
|
o
|
|
4143
|
-
), t = new B(e.A.x, e.A.y, e.A.z), i = new
|
|
4144
|
-
return new
|
|
4264
|
+
), t = new B(e.A.x, e.A.y, e.A.z), i = new E(e.direction.x, e.direction.y, e.direction.z);
|
|
4265
|
+
return new Ot(t, i);
|
|
4145
4266
|
}
|
|
4146
|
-
const
|
|
4147
|
-
equation: (o) =>
|
|
4148
|
-
polynom: (o) =>
|
|
4149
|
-
monom: (o) =>
|
|
4150
|
-
fraction: (o) =>
|
|
4151
|
-
number: (o, e, t) =>
|
|
4152
|
-
numberSym: (o, e) =>
|
|
4153
|
-
prime: (o) =>
|
|
4154
|
-
bool: (o) =>
|
|
4155
|
-
array: (o, e) =>
|
|
4156
|
-
item: (o) =>
|
|
4157
|
-
shuffle: (o) =>
|
|
4158
|
-
line: (o) =>
|
|
4159
|
-
line3: (o) =>
|
|
4160
|
-
vector: (o) =>
|
|
4267
|
+
const gs = {
|
|
4268
|
+
equation: (o) => fs(o),
|
|
4269
|
+
polynom: (o) => zi(o),
|
|
4270
|
+
monom: (o) => Ri(o),
|
|
4271
|
+
fraction: (o) => qt(o),
|
|
4272
|
+
number: (o, e, t) => pe(o, e, t),
|
|
4273
|
+
numberSym: (o, e) => Q(o, e),
|
|
4274
|
+
prime: (o) => as(o),
|
|
4275
|
+
bool: (o) => Ci(o),
|
|
4276
|
+
array: (o, e) => ls(o, e),
|
|
4277
|
+
item: (o) => di(o),
|
|
4278
|
+
shuffle: (o) => $i(o),
|
|
4279
|
+
line: (o) => ps(o),
|
|
4280
|
+
line3: (o) => ms(o),
|
|
4281
|
+
vector: (o) => ci(o),
|
|
4161
4282
|
point: (o) => {
|
|
4162
|
-
const e =
|
|
4283
|
+
const e = ci(o);
|
|
4163
4284
|
return e.asPoint = !0, e;
|
|
4164
4285
|
},
|
|
4165
|
-
circle: (o) =>
|
|
4166
|
-
},
|
|
4167
|
-
Numeric:
|
|
4286
|
+
circle: (o) => ds(o)
|
|
4287
|
+
}, ws = {
|
|
4288
|
+
Numeric: U,
|
|
4168
4289
|
Fraction: u,
|
|
4169
4290
|
Root: vt,
|
|
4170
|
-
Monom:
|
|
4291
|
+
Monom: k,
|
|
4171
4292
|
Polynom: O,
|
|
4172
4293
|
Equation: H,
|
|
4173
|
-
Matrix:
|
|
4174
|
-
LinearSystem:
|
|
4175
|
-
Factor:
|
|
4176
|
-
PolyFactor:
|
|
4177
|
-
LogicalSet:
|
|
4178
|
-
Random:
|
|
4294
|
+
Matrix: cs,
|
|
4295
|
+
LinearSystem: ti,
|
|
4296
|
+
Factor: ae,
|
|
4297
|
+
PolyFactor: si,
|
|
4298
|
+
LogicalSet: ss,
|
|
4299
|
+
Random: gs,
|
|
4179
4300
|
Geometry: {
|
|
4180
|
-
Vector:
|
|
4301
|
+
Vector: E,
|
|
4181
4302
|
Point: B,
|
|
4182
4303
|
Line: R,
|
|
4183
|
-
Triangle:
|
|
4304
|
+
Triangle: li,
|
|
4184
4305
|
Circle: Tt,
|
|
4185
|
-
Line3:
|
|
4186
|
-
Plane3:
|
|
4306
|
+
Line3: Ot,
|
|
4307
|
+
Plane3: ai
|
|
4187
4308
|
},
|
|
4188
|
-
NumExp:
|
|
4309
|
+
NumExp: is
|
|
4189
4310
|
};
|
|
4190
4311
|
export {
|
|
4191
4312
|
Tt as Circle,
|
|
4192
4313
|
H as Equation,
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4314
|
+
At as EquationSolver,
|
|
4315
|
+
lt as FACTOR_DISPLAY,
|
|
4316
|
+
ae as Factor,
|
|
4196
4317
|
u as Fraction,
|
|
4197
4318
|
R as Line,
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4319
|
+
Ot as Line3,
|
|
4320
|
+
ti as LinearSystem,
|
|
4321
|
+
ss as LogicalSet,
|
|
4322
|
+
cs as Matrix,
|
|
4323
|
+
k as Monom,
|
|
4203
4324
|
vt as NthRoot,
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4325
|
+
is as NumExp,
|
|
4326
|
+
U as Numeric,
|
|
4327
|
+
ai as Plane3,
|
|
4207
4328
|
B as Point,
|
|
4208
|
-
|
|
4329
|
+
si as PolyFactor,
|
|
4209
4330
|
O as Polynom,
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4331
|
+
gs as Random,
|
|
4332
|
+
li as Triangle,
|
|
4333
|
+
E as Vector,
|
|
4334
|
+
rs as areVectorsColinears,
|
|
4335
|
+
ns as areVectorsEquals,
|
|
4336
|
+
ws as default,
|
|
4337
|
+
hs as determinant,
|
|
4338
|
+
os as dotProduct
|
|
4218
4339
|
};
|
|
4219
4340
|
//# sourceMappingURL=pimath.js.map
|