pimath 0.1.0 → 0.1.2
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 +1 -1
- package/dist/pimath.js +1683 -1380
- package/package.json +1 -1
- package/types/algebra/monom.d.ts.map +1 -1
- package/types/algebra/polynom.d.ts.map +1 -1
- package/types/geometry/triangle.d.ts.map +1 -1
- package/types/index.d.ts +15 -6
- package/types/index.d.ts.map +1 -1
- package/types/numeric.d.ts.map +1 -0
- package/types/randomization/random.d.ts +8 -8
package/dist/pimath.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var Ti = Object.defineProperty;
|
|
2
|
+
var ri = (o) => {
|
|
3
3
|
throw TypeError(o);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var a = (o, e, t) =>
|
|
7
|
-
var i = (o, e, t) => (
|
|
8
|
-
function
|
|
9
|
-
const e =
|
|
5
|
+
var Ai = (o, e, t) => e in o ? Ti(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
6
|
+
var a = (o, e, t) => Ai(o, typeof e != "symbol" ? e + "" : e, t), Gt = (o, e, t) => e.has(o) || ri("Cannot " + t);
|
|
7
|
+
var i = (o, e, t) => (Gt(o, e, "read from private field"), t ? t.call(o) : e.get(o)), f = (o, e, t) => e.has(o) ? ri("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(o) : e.set(o, t), h = (o, e, t, s) => (Gt(o, e, "write to private field"), s ? s.call(o, t) : e.set(o, t), t), M = (o, e, t) => (Gt(o, e, "access private method"), t);
|
|
8
|
+
function Mi(o) {
|
|
9
|
+
const e = oi(o), t = [];
|
|
10
10
|
let s, r;
|
|
11
11
|
for (; e.length > 0; )
|
|
12
12
|
s = e.shift() ?? 1, r = (e.length > 0 ? e.pop() : +s) ?? 1, t.push([s, r]);
|
|
13
13
|
return t;
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
const e =
|
|
15
|
+
function Ii(...o) {
|
|
16
|
+
const e = ei(...o);
|
|
17
17
|
return o.map((t) => t / e);
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function oi(o) {
|
|
20
20
|
const e = Math.abs(o), t = Math.sqrt(e), s = [];
|
|
21
21
|
for (let r = 1; r <= t; r++)
|
|
22
22
|
o % r === 0 && (s.push(r), s.push(e / r));
|
|
@@ -24,7 +24,7 @@ function Yt(o) {
|
|
|
24
24
|
return r - n;
|
|
25
25
|
}), [...new Set(s)];
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function ei(...o) {
|
|
28
28
|
const e = function(r, n) {
|
|
29
29
|
return n === 0 ? r : e(n, r % n);
|
|
30
30
|
};
|
|
@@ -39,53 +39,53 @@ function Ut(...o) {
|
|
|
39
39
|
;
|
|
40
40
|
return Math.abs(t);
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function Ci(...o) {
|
|
43
43
|
return o.reduce(function(e, t) {
|
|
44
|
-
return Math.abs(e * t /
|
|
44
|
+
return Math.abs(e * t / ei(e, t));
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
|
-
function
|
|
47
|
+
function $i(o, e = 3) {
|
|
48
48
|
return +o.toFixed(e);
|
|
49
49
|
}
|
|
50
|
-
function
|
|
50
|
+
function Bi(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 Pi(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 Si(o, e) {
|
|
60
60
|
const t = [], s = e === !0 ? +o : o ** 2;
|
|
61
61
|
for (let r = 0; r <= o; r++)
|
|
62
62
|
for (let n = 0; n <= o; n++)
|
|
63
63
|
r ** 2 + n ** 2 === s && t.push([r, n, o]);
|
|
64
64
|
return t;
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function Ri(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 G = {
|
|
70
|
+
decompose: Mi,
|
|
71
|
+
dividers: oi,
|
|
72
|
+
divideNumbersByGCD: Ii,
|
|
73
|
+
gcd: ei,
|
|
74
|
+
lcm: Ci,
|
|
75
|
+
numberCorrection: $i,
|
|
76
|
+
periodic: Bi,
|
|
77
|
+
primes: Pi,
|
|
78
|
+
pythagoreanTripletsWithTarget: Si,
|
|
79
|
+
round: Ri
|
|
80
80
|
};
|
|
81
|
-
var
|
|
81
|
+
var w, b, ot, Se;
|
|
82
82
|
const $ = class $ {
|
|
83
83
|
constructor(e, t) {
|
|
84
84
|
// #region Class fields (2)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
f(this, w, 1);
|
|
86
|
+
f(this, b, 1);
|
|
87
|
+
f(this, ot, !1);
|
|
88
|
+
f(this, Se, "frac");
|
|
89
89
|
// ------------------------------------------
|
|
90
90
|
/**
|
|
91
91
|
* Parse the value to get the numerator and denominator
|
|
@@ -95,7 +95,7 @@ const $ = class $ {
|
|
|
95
95
|
a(this, "parse", (e, t) => {
|
|
96
96
|
let s;
|
|
97
97
|
if (e === "")
|
|
98
|
-
return h(this,
|
|
98
|
+
return h(this, w, 0), h(this, b, 1), this;
|
|
99
99
|
switch (typeof e) {
|
|
100
100
|
case "string":
|
|
101
101
|
if (s = e.split("/"), s.length > 2)
|
|
@@ -104,36 +104,36 @@ const $ = class $ {
|
|
|
104
104
|
throw new Error(`The given value is not a valid fraction (${e})`);
|
|
105
105
|
if (s.length === 1)
|
|
106
106
|
return this.parse(+s[0]);
|
|
107
|
-
s.length === 2 ? s[1] === "0" ? (h(this,
|
|
107
|
+
s.length === 2 ? s[1] === "0" ? (h(this, w, NaN), h(this, b, 1)) : (h(this, w, +s[0]), h(this, b, +s[1])) : (h(this, w, NaN), h(this, b, 1));
|
|
108
108
|
break;
|
|
109
109
|
case "number":
|
|
110
110
|
if (Number.isSafeInteger(e))
|
|
111
|
-
h(this,
|
|
111
|
+
h(this, w, +e), t === void 0 || !Number.isSafeInteger(t) ? h(this, b, 1) : h(this, b, +t);
|
|
112
112
|
else {
|
|
113
113
|
const [, r] = e.toString().split("."), n = r ? r.length : 0;
|
|
114
|
-
t === void 0 ? (h(this,
|
|
114
|
+
t === void 0 ? (h(this, w, e * Math.pow(10, n)), h(this, b, Math.pow(10, n))) : Number.isSafeInteger(t) && (h(this, w, e * Math.pow(10, n) - Math.floor(e * Math.pow(10, n - t))), this.denominator = Math.pow(10, n) - Math.pow(10, n - t)), this.reduce();
|
|
115
115
|
}
|
|
116
116
|
break;
|
|
117
117
|
case "object":
|
|
118
|
-
e instanceof $ && (h(this,
|
|
118
|
+
e instanceof $ && (h(this, w, +e.numerator), h(this, b, +e.denominator));
|
|
119
119
|
break;
|
|
120
120
|
}
|
|
121
121
|
return this;
|
|
122
122
|
});
|
|
123
123
|
a(this, "clone", () => {
|
|
124
124
|
const e = new $();
|
|
125
|
-
return e.numerator = +i(this,
|
|
125
|
+
return e.numerator = +i(this, w), e.denominator = +i(this, b), e;
|
|
126
126
|
});
|
|
127
|
-
a(this, "abs", () => (h(this,
|
|
127
|
+
a(this, "abs", () => (h(this, w, Math.abs(i(this, w))), h(this, b, Math.abs(i(this, b))), this));
|
|
128
128
|
a(this, "add", (e) => {
|
|
129
129
|
if (e instanceof $) {
|
|
130
|
-
const t = i(this,
|
|
131
|
-
h(this,
|
|
130
|
+
const t = i(this, w), s = i(this, b);
|
|
131
|
+
h(this, w, t * e.denominator + e.numerator * s), h(this, b, s * e.denominator);
|
|
132
132
|
} else
|
|
133
133
|
return this.add(new $(e));
|
|
134
134
|
return this.reduce();
|
|
135
135
|
});
|
|
136
|
-
a(this, "amplify", (e) => (Number.isSafeInteger(e) && (h(this,
|
|
136
|
+
a(this, "amplify", (e) => (Number.isSafeInteger(e) && (h(this, w, i(this, w) * e), h(this, b, i(this, b) * e)), this));
|
|
137
137
|
// TODO: The rest of the functions are not used or unnecessary ?
|
|
138
138
|
/**
|
|
139
139
|
* Simple function to determine if it's a fraction
|
|
@@ -175,63 +175,63 @@ const $ = class $ {
|
|
|
175
175
|
const t = new $(e);
|
|
176
176
|
if (t.numerator === 0)
|
|
177
177
|
return new $().infinite();
|
|
178
|
-
const s = +i(this,
|
|
179
|
-
return h(this,
|
|
178
|
+
const s = +i(this, w), r = +i(this, b);
|
|
179
|
+
return h(this, w, s * t.denominator), h(this, b, r * t.numerator), this.reduce();
|
|
180
180
|
});
|
|
181
|
-
a(this, "infinite", () => (h(this,
|
|
182
|
-
a(this, "invalid", () => (h(this,
|
|
181
|
+
a(this, "infinite", () => (h(this, w, 1 / 0), h(this, b, 1), this));
|
|
182
|
+
a(this, "invalid", () => (h(this, w, NaN), h(this, b, 1), this));
|
|
183
183
|
a(this, "inverse", () => {
|
|
184
|
-
const e = +i(this,
|
|
185
|
-
return h(this,
|
|
184
|
+
const e = +i(this, w);
|
|
185
|
+
return h(this, w, +i(this, b)), h(this, b, e), this;
|
|
186
186
|
});
|
|
187
|
-
a(this, "isApproximative", () => i(this,
|
|
187
|
+
a(this, "isApproximative", () => i(this, ot) || i(this, w).toString().length >= 15 && i(this, b).toString().length >= 15);
|
|
188
188
|
a(this, "isEqual", (e) => this.compare(e, "="));
|
|
189
189
|
a(this, "isEven", () => this.isRelative() && this.value % 2 === 0);
|
|
190
190
|
a(this, "isExact", () => !this.isApproximative());
|
|
191
191
|
a(this, "isFinite", () => !this.isInfinity() && !this.isNaN());
|
|
192
192
|
a(this, "isGeq", (e) => this.compare(e, ">="));
|
|
193
193
|
a(this, "isGreater", (e) => this.compare(e, ">"));
|
|
194
|
-
a(this, "isInfinity", () => Math.abs(i(this,
|
|
194
|
+
a(this, "isInfinity", () => Math.abs(i(this, w)) === 1 / 0);
|
|
195
195
|
a(this, "isInverted", (e) => this.isEqual(new $().one().divide(e.clone())));
|
|
196
196
|
a(this, "isLeq", (e) => this.compare(e, "<="));
|
|
197
197
|
/* Compare shortcuts */
|
|
198
198
|
a(this, "isLesser", (e) => this.compare(e, "<"));
|
|
199
|
-
a(this, "isNaN", () => isNaN(i(this,
|
|
199
|
+
a(this, "isNaN", () => isNaN(i(this, w)));
|
|
200
200
|
a(this, "isNatural", () => this.isRelative() && this.isPositive());
|
|
201
201
|
a(this, "isNegative", () => this.sign() === -1);
|
|
202
|
-
a(this, "isNegativeOne", () => i(this,
|
|
202
|
+
a(this, "isNegativeOne", () => i(this, w) === -1 && i(this, b) === 1);
|
|
203
203
|
a(this, "isNotEqual", (e) => this.compare(e, "<>"));
|
|
204
|
-
a(this, "isNotZero", () => i(this,
|
|
204
|
+
a(this, "isNotZero", () => i(this, w) !== 0);
|
|
205
205
|
a(this, "isOdd", () => this.isRelative() && this.value % 2 === 1);
|
|
206
|
-
a(this, "isOne", () => i(this,
|
|
206
|
+
a(this, "isOne", () => i(this, w) === 1 && i(this, b) === 1);
|
|
207
207
|
a(this, "isOpposite", (e) => this.isEqual(e.clone().opposite()));
|
|
208
208
|
a(this, "isPositive", () => this.sign() === 1);
|
|
209
209
|
a(this, "isRational", () => !this.isRelative());
|
|
210
|
-
a(this, "isReduced", () => Math.abs(
|
|
210
|
+
a(this, "isReduced", () => Math.abs(G.gcd(i(this, w), i(this, b))) === 1);
|
|
211
211
|
a(this, "isRelative", () => this.clone().reduce().denominator === 1);
|
|
212
|
-
a(this, "isSquare", () => Math.sqrt(i(this,
|
|
212
|
+
a(this, "isSquare", () => Math.sqrt(i(this, w)) % 1 === 0 && Math.sqrt(i(this, b)) % 1 === 0);
|
|
213
213
|
a(this, "isStrictlyNegative", () => this.value < 0);
|
|
214
214
|
a(this, "isStrictlyPositive", () => this.value > 0);
|
|
215
215
|
// ------------------------------------------
|
|
216
216
|
// Mathematical operations specific to fractions
|
|
217
|
-
a(this, "isZero", () => i(this,
|
|
217
|
+
a(this, "isZero", () => i(this, w) === 0);
|
|
218
218
|
a(this, "multiply", (e) => {
|
|
219
219
|
const t = new $(e);
|
|
220
|
-
return h(this,
|
|
220
|
+
return h(this, w, i(this, w) * t.numerator), h(this, b, i(this, b) * t.denominator), this.reduce();
|
|
221
221
|
});
|
|
222
|
-
a(this, "one", () => (h(this,
|
|
223
|
-
a(this, "opposite", () => (h(this,
|
|
222
|
+
a(this, "one", () => (h(this, w, 1), h(this, b, 1), this));
|
|
223
|
+
a(this, "opposite", () => (h(this, w, -i(this, w)), this));
|
|
224
224
|
a(this, "pow", (e) => {
|
|
225
225
|
if (e instanceof $)
|
|
226
226
|
return this.pow(e.value);
|
|
227
227
|
this.reduce(), e < 0 && this.inverse();
|
|
228
|
-
const t = Math.floor(Math.pow(i(this,
|
|
229
|
-
return t ** Math.abs(e) === i(this,
|
|
228
|
+
const t = Math.floor(Math.pow(i(this, w), Math.abs(e))), s = Math.floor(Math.pow(i(this, b), Math.abs(e)));
|
|
229
|
+
return t ** Math.abs(e) === i(this, w) && s ** Math.abs(e) === i(this, b) ? (h(this, w, i(this, w) ** Math.abs(e)), h(this, b, i(this, b) ** Math.abs(e))) : (h(this, w, i(this, w) ** Math.abs(e)), h(this, b, i(this, b) ** Math.abs(e))), this;
|
|
230
230
|
});
|
|
231
231
|
// ------------------------------------------
|
|
232
232
|
a(this, "reduce", () => {
|
|
233
|
-
const e =
|
|
234
|
-
return h(this,
|
|
233
|
+
const e = G.gcd(i(this, w), i(this, b));
|
|
234
|
+
return h(this, w, i(this, w) / e), h(this, b, i(this, b) / e), i(this, b) < 0 && (h(this, b, -i(this, b)), h(this, w, -i(this, w))), this;
|
|
235
235
|
});
|
|
236
236
|
a(this, "root", (e) => {
|
|
237
237
|
if (e === 0)
|
|
@@ -242,57 +242,57 @@ const $ = class $ {
|
|
|
242
242
|
throw new Error("The root of a negative number must be odd.");
|
|
243
243
|
const t = this.sign();
|
|
244
244
|
this.abs(), this.reduce();
|
|
245
|
-
const s = Math.floor(Math.pow(i(this,
|
|
246
|
-
return h(this,
|
|
245
|
+
const s = Math.floor(Math.pow(i(this, w), Math.abs(1 / e))), r = Math.floor(Math.pow(i(this, b), Math.abs(1 / e)));
|
|
246
|
+
return h(this, w, Math.pow(i(this, w), Math.abs(1 / e))), h(this, b, Math.pow(i(this, b), Math.abs(1 / e))), (s !== i(this, w) || r !== i(this, b)) && (h(this, w, i(this, w) / i(this, b)), h(this, b, 1), h(this, ot, !0)), this.multiply(t), this;
|
|
247
247
|
});
|
|
248
|
-
a(this, "sign", () => i(this,
|
|
248
|
+
a(this, "sign", () => i(this, w) * i(this, b) >= 0 ? 1 : -1);
|
|
249
249
|
a(this, "sqrt", () => this.root(2));
|
|
250
250
|
a(this, "subtract", (e) => e instanceof $ ? this.add(e.clone().opposite()) : this.add(-e));
|
|
251
|
-
a(this, "zero", () => (h(this,
|
|
251
|
+
a(this, "zero", () => (h(this, w, 0), h(this, b, 1), this));
|
|
252
252
|
return e !== void 0 && this.parse(e, t), this;
|
|
253
253
|
}
|
|
254
254
|
// #endregion Properties and methods (55)
|
|
255
255
|
// #region Getters And Setters (11)
|
|
256
256
|
get denominator() {
|
|
257
|
-
return i(this,
|
|
257
|
+
return i(this, b);
|
|
258
258
|
}
|
|
259
259
|
set denominator(e) {
|
|
260
|
-
h(this,
|
|
260
|
+
h(this, b, e);
|
|
261
261
|
}
|
|
262
262
|
get display() {
|
|
263
|
-
return this.isExact() ? i(this,
|
|
263
|
+
return this.isExact() ? i(this, b) === 1 ? `${i(this, w)}` : `${i(this, w)}/${i(this, b)}` : this.value.toFixed(3);
|
|
264
264
|
}
|
|
265
265
|
// ------------------------------------------
|
|
266
266
|
// Getter and setter
|
|
267
267
|
// ------------------------------------------
|
|
268
268
|
get numerator() {
|
|
269
|
-
return i(this,
|
|
269
|
+
return i(this, w);
|
|
270
270
|
}
|
|
271
271
|
set numerator(e) {
|
|
272
|
-
h(this,
|
|
272
|
+
h(this, w, e);
|
|
273
273
|
}
|
|
274
274
|
get tfrac() {
|
|
275
|
-
return h(this,
|
|
275
|
+
return h(this, Se, "tfrac"), this;
|
|
276
276
|
}
|
|
277
277
|
get dfrac() {
|
|
278
|
-
return h(this,
|
|
278
|
+
return h(this, Se, "dfrac"), this;
|
|
279
279
|
}
|
|
280
280
|
get frac() {
|
|
281
|
-
return h(this,
|
|
281
|
+
return h(this, Se, "frac"), this;
|
|
282
282
|
}
|
|
283
283
|
// Display getter
|
|
284
284
|
get tex() {
|
|
285
|
-
return this.isInfinity() ? `${this.sign() === 1 ? "+" : "-"}\\infty` : this.isExact() ? i(this,
|
|
285
|
+
return this.isInfinity() ? `${this.sign() === 1 ? "+" : "-"}\\infty` : this.isExact() ? i(this, b) === 1 ? `${i(this, w)}` : i(this, w) < 0 ? `-\\${i(this, Se)}{ ${-i(this, w)} }{ ${i(this, b)} }` : `\\${i(this, Se)}{ ${i(this, w)} }{ ${i(this, b)} }` : this.value.toFixed(3);
|
|
286
286
|
}
|
|
287
287
|
get texWithSign() {
|
|
288
288
|
return this.isPositive() ? `+${this.tex}` : this.tex;
|
|
289
289
|
}
|
|
290
290
|
get value() {
|
|
291
|
-
return i(this,
|
|
291
|
+
return i(this, w) / i(this, b);
|
|
292
292
|
}
|
|
293
293
|
// #endregion Getters And Setters (11)
|
|
294
294
|
};
|
|
295
|
-
|
|
295
|
+
w = new WeakMap(), b = new WeakMap(), ot = new WeakMap(), Se = new WeakMap(), a($, "average", (...e) => {
|
|
296
296
|
const t = new $().zero();
|
|
297
297
|
for (const s of e)
|
|
298
298
|
t.add(s);
|
|
@@ -328,318 +328,182 @@ g = new WeakMap(), v = new WeakMap(), et = new WeakMap(), Ce = new WeakMap(), a(
|
|
|
328
328
|
return t;
|
|
329
329
|
});
|
|
330
330
|
let c = $;
|
|
331
|
-
var
|
|
332
|
-
|
|
333
|
-
constructor(e, t, s = "x") {
|
|
334
|
-
d(this, P);
|
|
335
|
-
d(this, le);
|
|
336
|
-
d(this, Se);
|
|
337
|
-
if (h(this, Se, s), Object.hasOwn(e, "moveLeft")) {
|
|
338
|
-
const r = e;
|
|
339
|
-
h(this, le, r.left.clone().subtract(r.right));
|
|
340
|
-
} else
|
|
341
|
-
h(this, le, e.clone().subtract(t ?? 0));
|
|
342
|
-
}
|
|
343
|
-
solve() {
|
|
344
|
-
if (i(this, le).degree().isOne())
|
|
345
|
-
return q(this, P, Qt).call(this);
|
|
346
|
-
if (i(this, le).degree().value === 2)
|
|
347
|
-
return q(this, P, Kt).call(this);
|
|
348
|
-
const e = q(this, P, _t).call(this);
|
|
349
|
-
if (e.length > 0)
|
|
350
|
-
return e;
|
|
351
|
-
if (i(this, le).degree().value === 3)
|
|
352
|
-
return q(this, P, Lt).call(this);
|
|
353
|
-
throw new Error("The equation degree is too high.");
|
|
354
|
-
}
|
|
355
|
-
solveAsCardan() {
|
|
356
|
-
if (i(this, le).degree().value !== 3)
|
|
357
|
-
throw new Error("The equation is not cubic.");
|
|
358
|
-
return q(this, P, Lt).call(this);
|
|
359
|
-
}
|
|
360
|
-
};
|
|
361
|
-
le = new WeakMap(), Se = new WeakMap(), P = new WeakSet(), ye = function(e) {
|
|
362
|
-
if (e instanceof c && e.isApproximative())
|
|
363
|
-
return q(this, P, Qe).call(this, e.value);
|
|
364
|
-
const t = new c(e);
|
|
365
|
-
return {
|
|
366
|
-
variable: i(this, Se),
|
|
367
|
-
exact: t,
|
|
368
|
-
value: t.value,
|
|
369
|
-
tex: t.tex,
|
|
370
|
-
display: t.display
|
|
371
|
-
};
|
|
372
|
-
}, Qe = function(e, t) {
|
|
373
|
-
return {
|
|
374
|
-
variable: i(this, Se),
|
|
375
|
-
exact: !1,
|
|
376
|
-
value: +e.toFixed(10),
|
|
377
|
-
tex: (t == null ? void 0 : t.tex) ?? "",
|
|
378
|
-
display: (t == null ? void 0 : t.display) ?? ""
|
|
379
|
-
};
|
|
380
|
-
}, Qt = function() {
|
|
381
|
-
const e = i(this, le).monomByDegree(0).coefficient.clone().opposite().divide(i(this, le).monomByDegree(1).coefficient);
|
|
382
|
-
return [
|
|
383
|
-
q(this, P, ye).call(this, e)
|
|
384
|
-
];
|
|
385
|
-
}, Kt = function() {
|
|
386
|
-
const e = i(this, le), t = e.monomByDegree(2).coefficient, s = e.monomByDegree(1).coefficient, r = e.monomByDegree(0).coefficient, n = s.clone().pow(2).subtract(t.clone().multiply(r).multiply(4));
|
|
387
|
-
if (n.isNegative())
|
|
388
|
-
return [];
|
|
389
|
-
if (n.isSquare()) {
|
|
390
|
-
const l = n.sqrt(), u = s.clone().opposite().add(l).divide(t.clone().multiply(2)), b = s.clone().opposite().subtract(l).divide(t.clone().multiply(2));
|
|
391
|
-
return l.isZero() ? [q(this, P, ye).call(this, u)] : [
|
|
392
|
-
q(this, P, ye).call(this, u),
|
|
393
|
-
q(this, P, ye).call(this, b)
|
|
394
|
-
].sort((p, m) => p.value - m.value);
|
|
395
|
-
}
|
|
396
|
-
return q(this, P, Jt).call(this, t, s, n);
|
|
397
|
-
}, Jt = function(e, t, s) {
|
|
398
|
-
const r = j.dividers(s.value).filter((de) => Math.sqrt(de) % 1 === 0).map((de) => Math.sqrt(de)).pop() ?? 1, n = j.gcd(2 * e.value, t.value, r) * (e.isNegative() ? -1 : 1), l = t.clone().divide(n).opposite(), u = e.clone().divide(n).multiply(2), b = s.clone().divide(r ** 2), p = Math.abs(r / n), m = r === 1 ? "-" : `-${p} `, x = r === 1 ? "+" : `+${p} `;
|
|
399
|
-
function k(de, ae, Xe, St) {
|
|
400
|
-
return `\\frac{ ${ae} ${Xe}\\sqrt{ ${St} } }{ ${de} }`;
|
|
401
|
-
}
|
|
402
|
-
function _(de, ae, Xe, St) {
|
|
403
|
-
return `(${ae}${Xe}sqrt(${St}))/${de}`;
|
|
404
|
-
}
|
|
405
|
-
const oe = s.value ** 0.5, he = (-t.value - oe) / (2 * e.value), me = (-t.value + oe) / (2 * e.value);
|
|
406
|
-
return [
|
|
407
|
-
q(this, P, Qe).call(this, he, {
|
|
408
|
-
tex: k(u.tex, l.tex, m.toString(), b.tex),
|
|
409
|
-
display: _(u.display, l.display, m.toString(), b.display)
|
|
410
|
-
}),
|
|
411
|
-
q(this, P, Qe).call(this, me, {
|
|
412
|
-
tex: k(u.tex, l.tex, x.toString(), b.tex),
|
|
413
|
-
display: _(u.display, l.display, x.toString(), b.display)
|
|
414
|
-
})
|
|
415
|
-
].sort((de, ae) => de.value - ae.value);
|
|
416
|
-
}, Lt = function() {
|
|
417
|
-
const e = i(this, le), t = e.monomByDegree(3).coefficient, s = e.monomByDegree(2).coefficient, r = e.monomByDegree(1).coefficient, n = e.monomByDegree(0).coefficient, l = s.clone().divide(t), u = r.clone().divide(t), b = n.clone().divide(t), p = u.clone().subtract(l.clone().pow(2).divide(3)), m = b.clone().subtract(l.clone().multiply(u).divide(3)).add(l.clone().pow(3).multiply(2).divide(27)), x = m.clone().opposite(), k = p.clone().opposite().pow(3).divide(27), _ = x.clone().pow(2).subtract(k.clone().multiply(4)).opposite();
|
|
418
|
-
if (_.isNegative()) {
|
|
419
|
-
const oe = m.clone().opposite().add(_.clone().opposite().sqrt()).divide(2).root(3), he = m.clone().opposite().subtract(_.clone().opposite().sqrt()).divide(2).root(3), me = oe.clone().add(he).subtract(l.clone().divide(3));
|
|
420
|
-
return [q(this, P, ye).call(this, me)];
|
|
421
|
-
}
|
|
422
|
-
if (_.isZero()) {
|
|
423
|
-
const oe = m.clone().opposite().divide(2).root(3), he = oe.clone().opposite().subtract(l.clone().divide(3)), me = oe.clone().multiply(2).subtract(l.clone().divide(3));
|
|
424
|
-
return he.isEqual(me) ? [q(this, P, ye).call(this, he)] : [
|
|
425
|
-
q(this, P, ye).call(this, me),
|
|
426
|
-
q(this, P, ye).call(this, he)
|
|
427
|
-
].sort((de, ae) => de.value - ae.value);
|
|
428
|
-
}
|
|
429
|
-
if (_.isPositive()) {
|
|
430
|
-
const oe = [], he = p.value, me = m.value, de = l.value;
|
|
431
|
-
for (let ae = 0; ae < 3; ae++)
|
|
432
|
-
oe.push(2 * Math.sqrt(-he / 3) * Math.cos(Math.acos(3 * me / (2 * he) * Math.sqrt(-3 / he)) / 3 + 2 * Math.PI * ae / 3) - de / 3);
|
|
433
|
-
return oe.map((ae) => q(this, P, Qe).call(this, ae)).sort((ae, Xe) => ae.value - Xe.value);
|
|
434
|
-
}
|
|
435
|
-
return [];
|
|
436
|
-
}, _t = function() {
|
|
437
|
-
let e = i(this, le).clone(), t = [];
|
|
438
|
-
const s = e.lcmDenominator();
|
|
439
|
-
s !== 1 && e.multiply(s);
|
|
440
|
-
const r = e.monomByDegree().coefficient;
|
|
441
|
-
let n = e.monomByDegree(0).coefficient;
|
|
442
|
-
for (; n.isZero(); )
|
|
443
|
-
t.length === 0 && t.push(q(this, P, ye).call(this, 0)), e = e.divide("x"), n = e.monomByDegree(0).coefficient;
|
|
444
|
-
const l = j.dividers(r.value), u = j.dividers(n.value);
|
|
445
|
-
for (const m of l)
|
|
446
|
-
for (const x of u) {
|
|
447
|
-
const k = new c(x, m);
|
|
448
|
-
e.evaluate(k).isZero() && !t.find((_) => _.value === k.value) && t.push(q(this, P, ye).call(this, k)), k.opposite(), e.evaluate(k).isZero() && !t.find((_) => _.value === k.value) && t.push(q(this, P, ye).call(this, k));
|
|
449
|
-
}
|
|
450
|
-
for (const m of t) {
|
|
451
|
-
if (m.exact !== !1 && m.exact.isZero())
|
|
452
|
-
continue;
|
|
453
|
-
const x = i(this, le).clone().parse("x", m.exact.denominator, -m.exact.numerator);
|
|
454
|
-
for (; e.isDividableBy(x); )
|
|
455
|
-
console.log(e.display, x.display), e = e.divide(x);
|
|
456
|
-
}
|
|
457
|
-
if (e.degree().isZero())
|
|
458
|
-
return t.sort((m, x) => m.value - x.value);
|
|
459
|
-
if (e.degree().value > 3)
|
|
460
|
-
return [];
|
|
461
|
-
const b = e.clone().parse("0");
|
|
462
|
-
console.log(e.display), console.log(b.display);
|
|
463
|
-
const p = new Wt(e, e.clone().parse("0"), i(this, Se));
|
|
464
|
-
return t = t.concat(p.solve()), t.sort((m, x) => m.value - x.value);
|
|
465
|
-
};
|
|
466
|
-
let ct = Wt;
|
|
467
|
-
var L, Q, te, Ze;
|
|
468
|
-
class ot {
|
|
331
|
+
var Z, J, se, We;
|
|
332
|
+
class ft {
|
|
469
333
|
constructor(...e) {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
334
|
+
f(this, Z);
|
|
335
|
+
f(this, J);
|
|
336
|
+
f(this, se);
|
|
337
|
+
f(this, We);
|
|
474
338
|
// ------------------------------------------
|
|
475
339
|
// Creation / parsing functions
|
|
476
340
|
// ------------------------------------------
|
|
477
|
-
a(this, "parse", (e, t, s) => (h(this,
|
|
341
|
+
a(this, "parse", (e, t, s) => (h(this, se, s ?? 1), h(this, J, t ?? 2), h(this, Z, e), i(this, J) % 2 === 0 && i(this, Z) < 0 && h(this, We, !1), this));
|
|
478
342
|
// ------------------------------------------
|
|
479
343
|
// Mathematical operations
|
|
480
344
|
// ------------------------------------------
|
|
481
345
|
a(this, "reduce", () => {
|
|
482
|
-
let e = Math.floor(Math.pow(i(this,
|
|
346
|
+
let e = Math.floor(Math.pow(i(this, Z), 1 / i(this, J)));
|
|
483
347
|
for (; e > 1; ) {
|
|
484
|
-
if (i(this,
|
|
485
|
-
h(this,
|
|
348
|
+
if (i(this, Z) % Math.pow(e, i(this, J)) === 0) {
|
|
349
|
+
h(this, se, i(this, se) * e), h(this, Z, i(this, Z) / Math.pow(e, i(this, J))), e = Math.floor(Math.pow(i(this, Z), 1 / i(this, J)));
|
|
486
350
|
continue;
|
|
487
351
|
}
|
|
488
352
|
e--;
|
|
489
353
|
}
|
|
490
354
|
return this;
|
|
491
355
|
});
|
|
492
|
-
a(this, "multiply", (e) => (h(this,
|
|
356
|
+
a(this, "multiply", (e) => (h(this, Z, i(this, Z) * e.radical), this.reduce()));
|
|
493
357
|
// ------------------------------------------
|
|
494
358
|
// Help functions
|
|
495
359
|
// ------------------------------------------
|
|
496
|
-
a(this, "hasRadical", () => !(i(this,
|
|
497
|
-
h(this,
|
|
360
|
+
a(this, "hasRadical", () => !(i(this, Z) === 1 || i(this, Z) === 0 || !i(this, We)));
|
|
361
|
+
h(this, Z, 1), h(this, se, 1), h(this, J, 2), h(this, We, !0), e.length > 0 && this.parse(e[0], e[1], e[2]);
|
|
498
362
|
}
|
|
499
363
|
// ------------------------------------------
|
|
500
364
|
// Getter and setter
|
|
501
365
|
// ------------------------------------------
|
|
502
366
|
get radical() {
|
|
503
|
-
return i(this,
|
|
367
|
+
return i(this, Z);
|
|
504
368
|
}
|
|
505
369
|
set radical(e) {
|
|
506
|
-
h(this,
|
|
370
|
+
h(this, Z, e);
|
|
507
371
|
}
|
|
508
372
|
get nth() {
|
|
509
|
-
return i(this,
|
|
373
|
+
return i(this, J);
|
|
510
374
|
}
|
|
511
375
|
set nth(e) {
|
|
512
|
-
Number.isSafeInteger(e) && e >= 2 ? h(this,
|
|
376
|
+
Number.isSafeInteger(e) && e >= 2 ? h(this, J, e) : (console.log("Error setting the nth root"), h(this, J, 2));
|
|
513
377
|
}
|
|
514
378
|
get coefficient() {
|
|
515
|
-
return i(this,
|
|
379
|
+
return i(this, se);
|
|
516
380
|
}
|
|
517
381
|
set coefficient(e) {
|
|
518
|
-
h(this,
|
|
382
|
+
h(this, se, e);
|
|
519
383
|
}
|
|
520
384
|
get tex() {
|
|
521
385
|
let e;
|
|
522
|
-
return i(this,
|
|
386
|
+
return i(this, se) === 1 ? e = "" : i(this, se) === -1 ? e = "-" : e = i(this, se).toString(), i(this, Z) === 1 ? `${i(this, se)}` : i(this, J) === 2 ? `${e}\\sqrt{${i(this, Z)}}` : `${e}\\sqrt[${i(this, J)}]{${i(this, Z)}}`;
|
|
523
387
|
}
|
|
524
388
|
get display() {
|
|
525
389
|
let e;
|
|
526
|
-
return i(this,
|
|
390
|
+
return i(this, se) === 1 ? e = "" : i(this, se) === -1 ? e = "-" : e = i(this, se).toString(), i(this, Z) === 1 ? `${i(this, se)}` : i(this, J) === 2 ? `${e}sqrt{${i(this, Z)}}` : `${e}root(${i(this, J)}){${i(this, Z)}}`;
|
|
527
391
|
}
|
|
528
392
|
get value() {
|
|
529
|
-
return i(this,
|
|
393
|
+
return i(this, se) * Math.pow(i(this, Z), 1 / i(this, J));
|
|
530
394
|
}
|
|
531
395
|
}
|
|
532
|
-
|
|
533
|
-
var
|
|
396
|
+
Z = new WeakMap(), J = new WeakMap(), se = new WeakMap(), We = new WeakMap();
|
|
397
|
+
var hi = (o) => {
|
|
534
398
|
throw TypeError(o);
|
|
535
|
-
},
|
|
536
|
-
const
|
|
399
|
+
}, ai = (o, e, t) => e.has(o) || hi("Cannot " + t), K = (o, e, t) => (ai(o, e, "read from private field"), t ? t.call(o) : e.get(o)), tt = (o, e, t) => e.has(o) ? hi("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(o) : e.set(o, t), be = (o, e, t, s) => (ai(o, e, "write to private field"), e.set(o, t), t);
|
|
400
|
+
const li = {
|
|
537
401
|
pi: Math.PI,
|
|
538
402
|
e: Math.exp(1)
|
|
539
403
|
};
|
|
540
|
-
var
|
|
541
|
-
function
|
|
404
|
+
var d = /* @__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))(d || {}), it = /* @__PURE__ */ ((o) => (o.EXPRESSION = "expression", o.POLYNOM = "polynom", o.SET = "set", o.NUMERIC = "numeric", o))(it || {});
|
|
405
|
+
function zi(o, e) {
|
|
542
406
|
if (o.length <= 1)
|
|
543
407
|
return o;
|
|
544
|
-
const t = Object.keys(e).filter((
|
|
545
|
-
t.sort((
|
|
546
|
-
const s = new RegExp(`^(${t.join("|")})\\(`), r = Object.keys(
|
|
547
|
-
r.sort((
|
|
408
|
+
const t = Object.keys(e).filter((E) => e[E].type === d.FUNCTION).map((E) => E);
|
|
409
|
+
t.sort((E, D) => D.length - E.length);
|
|
410
|
+
const s = new RegExp(`^(${t.join("|")})\\(`), r = Object.keys(li);
|
|
411
|
+
r.sort((E, D) => D.length - E.length);
|
|
548
412
|
const n = new RegExp(`^(${r.join("|")})`), l = /^(\d+(\.\d+)?)/;
|
|
549
|
-
let u = "",
|
|
413
|
+
let u = "", p, m, y;
|
|
550
414
|
for (; o.length > 0; ) {
|
|
551
|
-
if (
|
|
552
|
-
const
|
|
553
|
-
|
|
415
|
+
if (p = m, y = void 0, t.length > 0 && s.exec(o)) {
|
|
416
|
+
const E = t.find((D) => o.startsWith(D));
|
|
417
|
+
E && (y = E + "(", o = o.slice(E.length + 1), m = d.FUNCTION);
|
|
554
418
|
} else if (r.length > 0 && n.exec(o)) {
|
|
555
|
-
const
|
|
556
|
-
|
|
419
|
+
const E = r.find((D) => o.startsWith(D));
|
|
420
|
+
E && (y = E, o = o.slice(E.length), m = d.CONSTANT);
|
|
557
421
|
} else if (l.exec(o)) {
|
|
558
|
-
const
|
|
559
|
-
|
|
422
|
+
const E = l.exec(o);
|
|
423
|
+
E && (y = E[0], o = o.slice(E[0].length), m = d.COEFFICIENT);
|
|
560
424
|
} else
|
|
561
|
-
switch (
|
|
425
|
+
switch (y = o[0], o = o.slice(1), y) {
|
|
562
426
|
case "(":
|
|
563
|
-
|
|
427
|
+
m = d.LEFT_PARENTHESIS;
|
|
564
428
|
break;
|
|
565
429
|
case ")":
|
|
566
|
-
|
|
430
|
+
m = d.RIGHT_PARENTHESIS;
|
|
567
431
|
break;
|
|
568
432
|
case ",":
|
|
569
|
-
|
|
433
|
+
m = d.FUNCTION_ARGUMENT;
|
|
570
434
|
break;
|
|
571
435
|
case "+":
|
|
572
436
|
case "-":
|
|
573
437
|
case "*":
|
|
574
438
|
case "/":
|
|
575
439
|
case "^":
|
|
576
|
-
|
|
440
|
+
m = d.OPERATION;
|
|
577
441
|
break;
|
|
578
442
|
default:
|
|
579
|
-
|
|
443
|
+
m = d.VARIABLE;
|
|
580
444
|
}
|
|
581
|
-
if (
|
|
445
|
+
if (y === void 0 || m === void 0)
|
|
582
446
|
throw new Error("The token is undefined");
|
|
583
|
-
u +=
|
|
447
|
+
u += ki(p, m), u += y;
|
|
584
448
|
}
|
|
585
449
|
return u;
|
|
586
450
|
}
|
|
587
|
-
function
|
|
588
|
-
return o === void 0 || o ===
|
|
451
|
+
function ki(o, e) {
|
|
452
|
+
return o === void 0 || o === d.OPERATION || e === d.OPERATION || o === d.LEFT_PARENTHESIS || o === d.FUNCTION || o === d.FUNCTION_ARGUMENT || e === d.RIGHT_PARENTHESIS || e === d.FUNCTION_ARGUMENT ? "" : "*";
|
|
589
453
|
}
|
|
590
|
-
const
|
|
591
|
-
"^": { precedence: 4, associative: "right", type:
|
|
592
|
-
"*": { precedence: 3, associative: "left", type:
|
|
593
|
-
"/": { precedence: 3, associative: "left", type:
|
|
594
|
-
"+": { precedence: 2, associative: "left", type:
|
|
595
|
-
"-": { precedence: 2, associative: "left", type:
|
|
596
|
-
},
|
|
597
|
-
"^": { precedence: 4, associative: "right", type:
|
|
598
|
-
"*": { precedence: 3, associative: "left", type:
|
|
599
|
-
"/": { precedence: 3, associative: "left", type:
|
|
600
|
-
"+": { precedence: 2, associative: "left", type:
|
|
601
|
-
"-": { precedence: 2, associative: "left", type:
|
|
602
|
-
"%": { precedence: 3, associative: "right", type:
|
|
603
|
-
sin: { precedence: 4, associative: "right", type:
|
|
604
|
-
cos: { precedence: 4, associative: "right", type:
|
|
605
|
-
tan: { precedence: 4, associative: "right", type:
|
|
606
|
-
sqrt: { precedence: 4, associative: "right", type:
|
|
607
|
-
nthrt: { precedence: 4, associative: "right", type:
|
|
608
|
-
",": { precedence: 2, associative: "left", type:
|
|
609
|
-
},
|
|
610
|
-
"^": { precedence: 4, associative: "right", type:
|
|
611
|
-
"*": { precedence: 3, associative: "left", type:
|
|
612
|
-
"/": { precedence: 3, associative: "left", type:
|
|
613
|
-
"+": { precedence: 2, associative: "left", type:
|
|
614
|
-
"-": { precedence: 2, associative: "left", type:
|
|
615
|
-
"%": { precedence: 3, associative: "right", type:
|
|
616
|
-
sin: { precedence: 4, associative: "right", type:
|
|
617
|
-
cos: { precedence: 4, associative: "right", type:
|
|
618
|
-
tan: { precedence: 4, associative: "right", type:
|
|
619
|
-
sqrt: { precedence: 4, associative: "right", type:
|
|
620
|
-
nthrt: { precedence: 4, associative: "right", type:
|
|
621
|
-
ln: { precedence: 4, associative: "right", type:
|
|
622
|
-
log: { precedence: 4, associative: "right", type:
|
|
623
|
-
},
|
|
624
|
-
"&": { precedence: 3, associative: "left", type:
|
|
625
|
-
"|": { precedence: 3, associative: "left", type:
|
|
626
|
-
"!": { precedence: 4, associative: "right", type:
|
|
627
|
-
"-": { precedence: 2, associative: "left", type:
|
|
454
|
+
const Li = {
|
|
455
|
+
"^": { precedence: 4, associative: "right", type: d.OPERATION },
|
|
456
|
+
"*": { precedence: 3, associative: "left", type: d.OPERATION },
|
|
457
|
+
"/": { precedence: 3, associative: "left", type: d.OPERATION },
|
|
458
|
+
"+": { precedence: 2, associative: "left", type: d.OPERATION },
|
|
459
|
+
"-": { precedence: 2, associative: "left", type: d.OPERATION }
|
|
460
|
+
}, Di = {
|
|
461
|
+
"^": { precedence: 4, associative: "right", type: d.OPERATION },
|
|
462
|
+
"*": { precedence: 3, associative: "left", type: d.OPERATION },
|
|
463
|
+
"/": { precedence: 3, associative: "left", type: d.OPERATION },
|
|
464
|
+
"+": { precedence: 2, associative: "left", type: d.OPERATION },
|
|
465
|
+
"-": { precedence: 2, associative: "left", type: d.OPERATION },
|
|
466
|
+
"%": { precedence: 3, associative: "right", type: d.OPERATION },
|
|
467
|
+
sin: { precedence: 4, associative: "right", type: d.FUNCTION },
|
|
468
|
+
cos: { precedence: 4, associative: "right", type: d.FUNCTION },
|
|
469
|
+
tan: { precedence: 4, associative: "right", type: d.FUNCTION },
|
|
470
|
+
sqrt: { precedence: 4, associative: "right", type: d.FUNCTION },
|
|
471
|
+
nthrt: { precedence: 4, associative: "right", type: d.FUNCTION },
|
|
472
|
+
",": { precedence: 2, associative: "left", type: d.FUNCTION_ARGUMENT }
|
|
473
|
+
}, Zi = {
|
|
474
|
+
"^": { precedence: 4, associative: "right", type: d.OPERATION },
|
|
475
|
+
"*": { precedence: 3, associative: "left", type: d.OPERATION },
|
|
476
|
+
"/": { precedence: 3, associative: "left", type: d.OPERATION },
|
|
477
|
+
"+": { precedence: 2, associative: "left", type: d.OPERATION },
|
|
478
|
+
"-": { precedence: 2, associative: "left", type: d.OPERATION },
|
|
479
|
+
"%": { precedence: 3, associative: "right", type: d.OPERATION },
|
|
480
|
+
sin: { precedence: 4, associative: "right", type: d.FUNCTION },
|
|
481
|
+
cos: { precedence: 4, associative: "right", type: d.FUNCTION },
|
|
482
|
+
tan: { precedence: 4, associative: "right", type: d.FUNCTION },
|
|
483
|
+
sqrt: { precedence: 4, associative: "right", type: d.FUNCTION },
|
|
484
|
+
nthrt: { precedence: 4, associative: "right", type: d.FUNCTION },
|
|
485
|
+
ln: { precedence: 4, associative: "right", type: d.FUNCTION },
|
|
486
|
+
log: { precedence: 4, associative: "right", type: d.FUNCTION }
|
|
487
|
+
}, Vi = {
|
|
488
|
+
"&": { precedence: 3, associative: "left", type: d.OPERATION },
|
|
489
|
+
"|": { precedence: 3, associative: "left", type: d.OPERATION },
|
|
490
|
+
"!": { precedence: 4, associative: "right", type: d.OPERATION },
|
|
491
|
+
"-": { precedence: 2, associative: "left", type: d.OPERATION }
|
|
628
492
|
};
|
|
629
|
-
var
|
|
630
|
-
class
|
|
493
|
+
var je, st, ie, dt, ke;
|
|
494
|
+
class ci {
|
|
631
495
|
constructor(e) {
|
|
632
|
-
|
|
496
|
+
tt(this, je), tt(this, st, []), tt(this, ie, {}), tt(this, dt, []), tt(this, ke), be(this, je, typeof e > "u" ? it.POLYNOM : e), this.tokenConfigInitialization();
|
|
633
497
|
}
|
|
634
498
|
// Getter
|
|
635
499
|
get rpn() {
|
|
636
|
-
return
|
|
500
|
+
return K(this, st);
|
|
637
501
|
}
|
|
638
502
|
get rpnToken() {
|
|
639
|
-
return
|
|
503
|
+
return K(this, st).map((e) => e.token);
|
|
640
504
|
}
|
|
641
505
|
tokenConfigInitialization() {
|
|
642
|
-
return
|
|
506
|
+
return K(this, je) === it.SET ? (be(this, ie, Vi), be(this, ke, !1)) : K(this, je) === it.NUMERIC ? (be(this, ie, Zi), be(this, ke, !0)) : K(this, je) === it.EXPRESSION ? (be(this, ie, Di), be(this, ke, !0)) : (be(this, ie, Li), be(this, ke, !0)), be(this, dt, Object.keys(K(this, ie)).sort((e, t) => t.length - e.length)), K(this, ie);
|
|
643
507
|
}
|
|
644
508
|
/**
|
|
645
509
|
* Get the next token to analyse.
|
|
@@ -649,31 +513,31 @@ class si {
|
|
|
649
513
|
NextToken(e, t) {
|
|
650
514
|
let s, r;
|
|
651
515
|
if (s = "", r = void 0, e[t] === "(")
|
|
652
|
-
s = "(", r =
|
|
516
|
+
s = "(", r = d.LEFT_PARENTHESIS;
|
|
653
517
|
else if (e[t] === ")")
|
|
654
|
-
s = ")", r =
|
|
518
|
+
s = ")", r = d.RIGHT_PARENTHESIS;
|
|
655
519
|
else if (e[t] === ",")
|
|
656
|
-
s = ",", r =
|
|
520
|
+
s = ",", r = d.FUNCTION_ARGUMENT;
|
|
657
521
|
else {
|
|
658
|
-
for (const n of
|
|
522
|
+
for (const n of K(this, dt))
|
|
659
523
|
if (e.substring(t, t + n.length) === n) {
|
|
660
|
-
s += n, r =
|
|
524
|
+
s += n, r = K(this, ie)[n].type;
|
|
661
525
|
break;
|
|
662
526
|
}
|
|
663
|
-
for (const n in
|
|
527
|
+
for (const n in li)
|
|
664
528
|
if (e.substring(t, t + n.length) === n) {
|
|
665
|
-
s += n, r =
|
|
529
|
+
s += n, r = d.CONSTANT;
|
|
666
530
|
break;
|
|
667
531
|
}
|
|
668
532
|
if (s === "")
|
|
669
533
|
if (/[0-9.]/.exec(e[t])) {
|
|
670
534
|
const n = /^([0-9.]+)/.exec(e.substring(t));
|
|
671
|
-
s = n ? n[0] : "", r =
|
|
535
|
+
s = n ? n[0] : "", r = d.COEFFICIENT;
|
|
672
536
|
} else if (/[a-zA-Z]/.exec(e[t])) {
|
|
673
537
|
const n = /^([a-zA-Z])/.exec(e.substring(t));
|
|
674
|
-
s = n ? n[0] : "", r =
|
|
538
|
+
s = n ? n[0] : "", r = d.VARIABLE;
|
|
675
539
|
} else
|
|
676
|
-
console.log("Unidentified token", e[t], e, t), s = e[t], r =
|
|
540
|
+
console.log("Unidentified token", e[t], e, t), s = e[t], r = d.MONOM;
|
|
677
541
|
}
|
|
678
542
|
if (r === void 0)
|
|
679
543
|
throw new Error(`Token type is undefined for token ${s}`);
|
|
@@ -688,56 +552,56 @@ class si {
|
|
|
688
552
|
parse(e, t) {
|
|
689
553
|
const s = [], r = [];
|
|
690
554
|
let n = "", l = 0, u;
|
|
691
|
-
(t ??
|
|
692
|
-
const
|
|
693
|
-
let
|
|
555
|
+
(t ?? K(this, ke)) && (e = zi(e, K(this, ie)));
|
|
556
|
+
const p = 50;
|
|
557
|
+
let m = 50, y;
|
|
694
558
|
for (; l < e.length; ) {
|
|
695
|
-
if (
|
|
559
|
+
if (m--, m === 0) {
|
|
696
560
|
console.log("SECURITY LEVEL 1 EXIT");
|
|
697
561
|
break;
|
|
698
562
|
}
|
|
699
563
|
switch ([n, l, u] = this.NextToken(e, l), u) {
|
|
700
|
-
case
|
|
701
|
-
case
|
|
702
|
-
case
|
|
703
|
-
case
|
|
564
|
+
case d.MONOM:
|
|
565
|
+
case d.COEFFICIENT:
|
|
566
|
+
case d.VARIABLE:
|
|
567
|
+
case d.CONSTANT:
|
|
704
568
|
s.push({
|
|
705
569
|
token: n,
|
|
706
570
|
tokenType: u
|
|
707
571
|
});
|
|
708
572
|
break;
|
|
709
|
-
case
|
|
573
|
+
case d.OPERATION:
|
|
710
574
|
if (r.length > 0) {
|
|
711
|
-
let
|
|
712
|
-
for (
|
|
713
|
-
(
|
|
714
|
-
|
|
715
|
-
if (
|
|
575
|
+
let E = r[r.length - 1];
|
|
576
|
+
for (y = +p; E.token in K(this, ie) && //either o1 is left-associative and its precedence is less than or equal to that of o2,
|
|
577
|
+
(K(this, ie)[n].associative === "left" && K(this, ie)[n].precedence <= K(this, ie)[E.token].precedence || //or o1 is right associative, and has precedence less than that of o2,
|
|
578
|
+
K(this, ie)[n].associative === "right" && K(this, ie)[n].precedence < K(this, ie)[E.token].precedence); ) {
|
|
579
|
+
if (y--, y === 0) {
|
|
716
580
|
console.log("SECURITY LEVEL 2 OPERATION EXIT");
|
|
717
581
|
break;
|
|
718
582
|
}
|
|
719
|
-
if (s.push(r.pop() ?? { token: "", tokenType:
|
|
583
|
+
if (s.push(r.pop() ?? { token: "", tokenType: d.OPERATION }), r.length === 0)
|
|
720
584
|
break;
|
|
721
|
-
|
|
585
|
+
E = r[r.length - 1];
|
|
722
586
|
}
|
|
723
587
|
}
|
|
724
588
|
r.push({ token: n, tokenType: u });
|
|
725
589
|
break;
|
|
726
|
-
case
|
|
727
|
-
for (
|
|
728
|
-
if (
|
|
590
|
+
case d.FUNCTION_ARGUMENT:
|
|
591
|
+
for (y = +p; r[r.length - 1].token !== "(" && r.length > 0; ) {
|
|
592
|
+
if (y--, y === 0) {
|
|
729
593
|
console.log("SECURITY LEVEL 2 FUNCTION ARGUMENT EXIT");
|
|
730
594
|
break;
|
|
731
595
|
}
|
|
732
596
|
s.push(r.pop() ?? { token: n, tokenType: u });
|
|
733
597
|
}
|
|
734
598
|
break;
|
|
735
|
-
case
|
|
736
|
-
r.push({ token: n, tokenType: u }), e[l] === "-" && s.push({ token: "0", tokenType:
|
|
599
|
+
case d.LEFT_PARENTHESIS:
|
|
600
|
+
r.push({ token: n, tokenType: u }), e[l] === "-" && s.push({ token: "0", tokenType: d.COEFFICIENT });
|
|
737
601
|
break;
|
|
738
|
-
case
|
|
739
|
-
for (
|
|
740
|
-
if (
|
|
602
|
+
case d.RIGHT_PARENTHESIS:
|
|
603
|
+
for (y = +p; r[r.length - 1].token !== "(" && r.length > 1; ) {
|
|
604
|
+
if (y--, y === 0) {
|
|
741
605
|
console.log("SECURITY LEVEL 2 CLOSING PARENTHESIS EXIT");
|
|
742
606
|
break;
|
|
743
607
|
}
|
|
@@ -745,31 +609,31 @@ class si {
|
|
|
745
609
|
}
|
|
746
610
|
r.pop();
|
|
747
611
|
break;
|
|
748
|
-
case
|
|
612
|
+
case d.FUNCTION:
|
|
749
613
|
r.push({ token: n, tokenType: u });
|
|
750
614
|
break;
|
|
751
615
|
default:
|
|
752
616
|
throw new Error(`Token type ${n} is not handled`);
|
|
753
617
|
}
|
|
754
618
|
}
|
|
755
|
-
return
|
|
619
|
+
return be(this, st, s.concat(r.reverse())), this;
|
|
756
620
|
}
|
|
757
621
|
}
|
|
758
|
-
|
|
759
|
-
var
|
|
622
|
+
je = /* @__PURE__ */ new WeakMap(), st = /* @__PURE__ */ new WeakMap(), ie = /* @__PURE__ */ new WeakMap(), dt = /* @__PURE__ */ new WeakMap(), ke = /* @__PURE__ */ new WeakMap();
|
|
623
|
+
var O, v, He, pt, Re, bt, xt;
|
|
760
624
|
const B = class B {
|
|
761
625
|
constructor(e) {
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
626
|
+
f(this, He);
|
|
627
|
+
f(this, O);
|
|
628
|
+
f(this, v);
|
|
765
629
|
/**
|
|
766
630
|
* Clone the current Monom.
|
|
767
631
|
*/
|
|
768
632
|
a(this, "clone", () => {
|
|
769
633
|
const e = new B();
|
|
770
|
-
e.coefficient = i(this,
|
|
771
|
-
for (const t in i(this,
|
|
772
|
-
e.setLetter(t, i(this,
|
|
634
|
+
e.coefficient = i(this, O).clone();
|
|
635
|
+
for (const t in i(this, v))
|
|
636
|
+
e.setLetter(t, i(this, v)[t].clone());
|
|
773
637
|
return e;
|
|
774
638
|
});
|
|
775
639
|
/**
|
|
@@ -779,24 +643,24 @@ const B = class B {
|
|
|
779
643
|
a(this, "add", (...e) => {
|
|
780
644
|
for (const t of e) {
|
|
781
645
|
const s = t instanceof B ? t : new B(t);
|
|
782
|
-
this.isSameAs(s) ? (this.isZero() &&
|
|
646
|
+
this.isSameAs(s) ? (this.isZero() && M(this, He, pt).call(this, s), i(this, O).add(s.coefficient)) : console.log("Add monom: " + this.display + " is not similar with ", s.display);
|
|
783
647
|
}
|
|
784
648
|
return this;
|
|
785
649
|
});
|
|
786
|
-
a(this, "containsRationalPower", () => Object.values(i(this,
|
|
650
|
+
a(this, "containsRationalPower", () => Object.values(i(this, v)).some((e) => e.isRational()));
|
|
787
651
|
/**
|
|
788
652
|
* Get the degree of a monom. If no setLetter is given, the result will be the global degree.
|
|
789
653
|
* @param letter (string) Letter to get to degree (power)
|
|
790
654
|
*/
|
|
791
|
-
a(this, "degree", (e) => this.variables.length === 0 ? new c().zero() : e === void 0 ? Object.values(i(this,
|
|
655
|
+
a(this, "degree", (e) => this.variables.length === 0 ? new c().zero() : e === void 0 ? Object.values(i(this, v)).reduce((t, s) => t.clone().add(s)) : this.hasVariable(e) ? i(this, v)[e].clone() : new c().zero());
|
|
792
656
|
/**
|
|
793
657
|
* Derivative the monom
|
|
794
658
|
* @param letter
|
|
795
659
|
*/
|
|
796
660
|
a(this, "derivative", (e) => {
|
|
797
661
|
if (e === void 0 && (e = "x"), this.hasVariable(e)) {
|
|
798
|
-
const t = i(this,
|
|
799
|
-
return i(s,
|
|
662
|
+
const t = i(this, v)[e].clone(), s = this.clone();
|
|
663
|
+
return i(s, v)[e].subtract(1), i(s, O).multiply(new c(t.clone())), s;
|
|
800
664
|
} else
|
|
801
665
|
return new B().zero();
|
|
802
666
|
});
|
|
@@ -807,9 +671,9 @@ const B = class B {
|
|
|
807
671
|
a(this, "divide", (...e) => {
|
|
808
672
|
for (const t of e) {
|
|
809
673
|
const s = t instanceof B ? t : new B(t);
|
|
810
|
-
i(this,
|
|
674
|
+
i(this, O).divide(s.coefficient);
|
|
811
675
|
for (const r in s.literal)
|
|
812
|
-
i(this,
|
|
676
|
+
i(this, v)[r] = this.hasVariable(r) ? i(this, v)[r].subtract(s.literal[r]) : s.literal[r].clone().opposite(), i(this, v)[r].isZero() && this.removeVariable(r);
|
|
813
677
|
}
|
|
814
678
|
return this;
|
|
815
679
|
});
|
|
@@ -821,16 +685,16 @@ const B = class B {
|
|
|
821
685
|
a(this, "evaluate", (e, t) => {
|
|
822
686
|
if (t === !0) {
|
|
823
687
|
if (e instanceof c)
|
|
824
|
-
return i(this,
|
|
825
|
-
if (e instanceof
|
|
688
|
+
return i(this, Re).call(this, e.value);
|
|
689
|
+
if (e instanceof ft)
|
|
826
690
|
return new c().invalid();
|
|
827
691
|
if (typeof e == "number")
|
|
828
|
-
return i(this,
|
|
692
|
+
return i(this, Re).call(this, e);
|
|
829
693
|
if (typeof e == "object") {
|
|
830
694
|
const r = {};
|
|
831
695
|
for (const n in e)
|
|
832
696
|
r[n] = new c(e[n]).value;
|
|
833
|
-
return i(this,
|
|
697
|
+
return i(this, Re).call(this, r);
|
|
834
698
|
}
|
|
835
699
|
}
|
|
836
700
|
const s = this.coefficient.clone();
|
|
@@ -838,14 +702,14 @@ const B = class B {
|
|
|
838
702
|
const r = {};
|
|
839
703
|
return r[this.variables[0]] = new c(e), this.evaluate(r);
|
|
840
704
|
}
|
|
841
|
-
if (e instanceof
|
|
705
|
+
if (e instanceof ft)
|
|
842
706
|
return new c().invalid();
|
|
843
707
|
if (typeof e == "object") {
|
|
844
708
|
if (this.variables.length === 0)
|
|
845
709
|
return this.coefficient;
|
|
846
|
-
for (const r in i(this,
|
|
710
|
+
for (const r in i(this, v)) {
|
|
847
711
|
const n = new c(e[r]);
|
|
848
|
-
s.multiply(n.pow(i(this,
|
|
712
|
+
s.multiply(n.pow(i(this, v)[r]));
|
|
849
713
|
}
|
|
850
714
|
}
|
|
851
715
|
return s;
|
|
@@ -855,11 +719,11 @@ const B = class B {
|
|
|
855
719
|
* Determine if a monom contains a setLetter in it's literal part
|
|
856
720
|
* @param letter
|
|
857
721
|
*/
|
|
858
|
-
a(this, "hasVariable", (e) => Object.hasOwn(i(this,
|
|
722
|
+
a(this, "hasVariable", (e) => Object.hasOwn(i(this, v), e ?? "x"));
|
|
859
723
|
a(this, "inverse", () => {
|
|
860
|
-
i(this,
|
|
861
|
-
for (const e in i(this,
|
|
862
|
-
i(this,
|
|
724
|
+
i(this, O).opposite();
|
|
725
|
+
for (const e in i(this, v))
|
|
726
|
+
i(this, v)[e].opposite();
|
|
863
727
|
return this;
|
|
864
728
|
});
|
|
865
729
|
a(this, "isDivisible", (e) => {
|
|
@@ -874,7 +738,7 @@ const B = class B {
|
|
|
874
738
|
* Determine if two monoms are equals
|
|
875
739
|
* @param M
|
|
876
740
|
*/
|
|
877
|
-
a(this, "isEqual", (e) => this.isSameAs(e) && i(this,
|
|
741
|
+
a(this, "isEqual", (e) => this.isSameAs(e) && i(this, O).isEqual(e.coefficient));
|
|
878
742
|
a(this, "isLiteralSquare", () => {
|
|
879
743
|
for (const e in this.literal)
|
|
880
744
|
if (this.literal[e].isRational() || this.literal[e].isEven())
|
|
@@ -884,7 +748,7 @@ const B = class B {
|
|
|
884
748
|
/**
|
|
885
749
|
* Determine if the monom is one
|
|
886
750
|
*/
|
|
887
|
-
a(this, "isOne", () => i(this,
|
|
751
|
+
a(this, "isOne", () => i(this, O).value === 1 && this.variables.length === 0);
|
|
888
752
|
/**
|
|
889
753
|
* Determine if two monoms are similar
|
|
890
754
|
* @param M
|
|
@@ -897,7 +761,7 @@ const B = class B {
|
|
|
897
761
|
return !1;
|
|
898
762
|
if (!this.isZero() && !e.isZero()) {
|
|
899
763
|
for (const n of r)
|
|
900
|
-
if (!this.hasVariable(n) || !e.hasVariable(n) || !i(this,
|
|
764
|
+
if (!this.hasVariable(n) || !e.hasVariable(n) || !i(this, v)[n].isEqual(e.literal[n]))
|
|
901
765
|
return !1;
|
|
902
766
|
}
|
|
903
767
|
return !0;
|
|
@@ -906,7 +770,7 @@ const B = class B {
|
|
|
906
770
|
/**
|
|
907
771
|
* Determine if the monom is null
|
|
908
772
|
*/
|
|
909
|
-
a(this, "isZero", () => i(this,
|
|
773
|
+
a(this, "isZero", () => i(this, O).value === 0);
|
|
910
774
|
/**
|
|
911
775
|
* Multiple multiple monoms to the current monom
|
|
912
776
|
* @param M (Monom[]) The monoms to multiply to.
|
|
@@ -914,29 +778,29 @@ const B = class B {
|
|
|
914
778
|
a(this, "multiply", (...e) => {
|
|
915
779
|
for (const t of e) {
|
|
916
780
|
const s = t instanceof B ? t : new B(t);
|
|
917
|
-
i(this,
|
|
781
|
+
i(this, O).multiply(s.coefficient);
|
|
918
782
|
for (const r in s.literal)
|
|
919
|
-
this.hasVariable(r) ? i(this,
|
|
783
|
+
this.hasVariable(r) ? i(this, v)[r].add(s.literal[r]) : i(this, v)[r] = s.literal[r].clone();
|
|
920
784
|
}
|
|
921
785
|
return this;
|
|
922
786
|
});
|
|
923
787
|
/**
|
|
924
788
|
* Create a one value monom
|
|
925
789
|
*/
|
|
926
|
-
a(this, "one", () => (h(this,
|
|
790
|
+
a(this, "one", () => (h(this, O, new c().one()), h(this, v, {}), this));
|
|
927
791
|
/**
|
|
928
792
|
* Get the opposite
|
|
929
793
|
* Returns a monom.
|
|
930
794
|
*/
|
|
931
|
-
a(this, "opposite", () => (i(this,
|
|
795
|
+
a(this, "opposite", () => (i(this, O).opposite(), this));
|
|
932
796
|
/**
|
|
933
797
|
* Get the pow of a monom.
|
|
934
798
|
* @param nb (number) : Mathematical pow
|
|
935
799
|
*/
|
|
936
800
|
a(this, "pow", (e) => {
|
|
937
|
-
i(this,
|
|
938
|
-
for (const t in i(this,
|
|
939
|
-
i(this,
|
|
801
|
+
i(this, O).pow(e);
|
|
802
|
+
for (const t in i(this, v))
|
|
803
|
+
i(this, v)[t].multiply(e);
|
|
940
804
|
return this;
|
|
941
805
|
});
|
|
942
806
|
// #endregion Properties and methods (31)
|
|
@@ -949,8 +813,8 @@ const B = class B {
|
|
|
949
813
|
});
|
|
950
814
|
a(this, "reduce", () => {
|
|
951
815
|
this.coefficient.reduce();
|
|
952
|
-
for (const e in i(this,
|
|
953
|
-
i(this,
|
|
816
|
+
for (const e in i(this, v))
|
|
817
|
+
i(this, v)[e].isZero() && this.removeVariable(e);
|
|
954
818
|
return this;
|
|
955
819
|
});
|
|
956
820
|
/**
|
|
@@ -964,15 +828,15 @@ const B = class B {
|
|
|
964
828
|
* @param letter (string) Letter to change
|
|
965
829
|
* @param pow (number) Power of the setLetter (must be positive integer.
|
|
966
830
|
*/
|
|
967
|
-
a(this, "setLetter", (e, t) => t instanceof c ? (this.hasVariable(e) && t.isZero() && this.removeVariable(e), i(this,
|
|
831
|
+
a(this, "setLetter", (e, t) => t instanceof c ? (this.hasVariable(e) && t.isZero() && this.removeVariable(e), i(this, v)[e] = t.clone(), this) : this.setLetter(e, new c(t)));
|
|
968
832
|
/**
|
|
969
833
|
* Return the square root of a monom
|
|
970
834
|
*/
|
|
971
835
|
a(this, "sqrt", () => {
|
|
972
836
|
if (this.isSquare()) {
|
|
973
|
-
i(this,
|
|
974
|
-
for (const e in i(this,
|
|
975
|
-
i(this,
|
|
837
|
+
i(this, O).sqrt();
|
|
838
|
+
for (const e in i(this, v))
|
|
839
|
+
i(this, v)[e].clone().divide(2);
|
|
976
840
|
}
|
|
977
841
|
return this;
|
|
978
842
|
});
|
|
@@ -983,57 +847,57 @@ const B = class B {
|
|
|
983
847
|
a(this, "subtract", (...e) => {
|
|
984
848
|
for (const t of e) {
|
|
985
849
|
const s = t instanceof B ? t : new B(t);
|
|
986
|
-
this.isSameAs(s) ? (this.isZero() &&
|
|
850
|
+
this.isSameAs(s) ? (this.isZero() && M(this, He, pt).call(this, s), i(this, O).add(s.clone().coefficient.opposite())) : console.log("Subtract: Is not similar: ", s.display);
|
|
987
851
|
}
|
|
988
852
|
return this;
|
|
989
853
|
});
|
|
990
854
|
/**
|
|
991
855
|
* Create a zero value monom
|
|
992
856
|
*/
|
|
993
|
-
a(this, "zero", () => (h(this,
|
|
994
|
-
|
|
857
|
+
a(this, "zero", () => (h(this, O, new c().zero()), h(this, v, {}), this));
|
|
858
|
+
f(this, Re, (e) => {
|
|
995
859
|
let t = this.coefficient.value;
|
|
996
860
|
if (typeof e == "number") {
|
|
997
861
|
const s = {}, r = this.variables[0];
|
|
998
|
-
return s[r] = e, i(this,
|
|
862
|
+
return s[r] = e, i(this, Re).call(this, s);
|
|
999
863
|
}
|
|
1000
864
|
if (e instanceof c) {
|
|
1001
865
|
const s = {};
|
|
1002
|
-
return s[this.variables[0]] = new c(e).value, i(this,
|
|
866
|
+
return s[this.variables[0]] = new c(e).value, i(this, Re).call(this, s);
|
|
1003
867
|
}
|
|
1004
|
-
if (e instanceof
|
|
868
|
+
if (e instanceof ft)
|
|
1005
869
|
return NaN;
|
|
1006
870
|
if (typeof e == "object") {
|
|
1007
871
|
if (this.variables.length === 0)
|
|
1008
872
|
return this.coefficient.value;
|
|
1009
|
-
for (const s in i(this,
|
|
873
|
+
for (const s in i(this, v)) {
|
|
1010
874
|
const r = e[s];
|
|
1011
|
-
r instanceof c ? t *= r.value ** i(this,
|
|
875
|
+
r instanceof c ? t *= r.value ** i(this, v)[s].value : t *= r ** i(this, v)[s].value;
|
|
1012
876
|
}
|
|
1013
877
|
}
|
|
1014
878
|
return t;
|
|
1015
879
|
});
|
|
1016
|
-
|
|
1017
|
-
const s = new
|
|
880
|
+
f(this, bt, (e) => {
|
|
881
|
+
const s = new ci().parse(e).rpn, r = [];
|
|
1018
882
|
if (s.length === 0)
|
|
1019
883
|
return this.zero(), this;
|
|
1020
884
|
if (s.length === 1) {
|
|
1021
885
|
const n = s[0];
|
|
1022
|
-
return this.one(), n.tokenType ===
|
|
886
|
+
return this.one(), n.tokenType === d.COEFFICIENT ? this.coefficient = new c(n.token) : n.tokenType === d.VARIABLE && this.setLetter(n.token, 1), this;
|
|
1023
887
|
} else
|
|
1024
888
|
for (const n of s)
|
|
1025
|
-
i(this,
|
|
889
|
+
i(this, xt).call(this, r, n);
|
|
1026
890
|
return this.one(), this.multiply(r[0]), this;
|
|
1027
891
|
});
|
|
1028
|
-
|
|
1029
|
-
var
|
|
892
|
+
f(this, xt, (e, t) => {
|
|
893
|
+
var p;
|
|
1030
894
|
let s, r, n, l, u;
|
|
1031
|
-
if (t.tokenType ===
|
|
895
|
+
if (t.tokenType === d.COEFFICIENT)
|
|
1032
896
|
e.push(new B(new c(t.token)));
|
|
1033
|
-
else if (t.tokenType ===
|
|
1034
|
-
const
|
|
1035
|
-
|
|
1036
|
-
} else if (t.tokenType ===
|
|
897
|
+
else if (t.tokenType === d.VARIABLE) {
|
|
898
|
+
const m = new B().one();
|
|
899
|
+
m.setLetter(t.token, 1), e.push(m.clone());
|
|
900
|
+
} else if (t.tokenType === d.OPERATION)
|
|
1037
901
|
switch (t.token) {
|
|
1038
902
|
case "-":
|
|
1039
903
|
r = e.pop() ?? new B().zero(), s = e.pop() ?? new B().zero(), e.push(s.subtract(r));
|
|
@@ -1045,12 +909,12 @@ const B = class B {
|
|
|
1045
909
|
r = e.pop() ?? new B().one(), s = e.pop() ?? new B().one(), e.push(s.divide(r));
|
|
1046
910
|
break;
|
|
1047
911
|
case "^": {
|
|
1048
|
-
u = ((
|
|
912
|
+
u = ((p = e.pop()) == null ? void 0 : p.coefficient) ?? new c().one(), n = e.pop() ?? new B().one(), l = n.variables[0], l && n.setLetter(l, u), e.push(n);
|
|
1049
913
|
break;
|
|
1050
914
|
}
|
|
1051
915
|
}
|
|
1052
916
|
});
|
|
1053
|
-
return h(this,
|
|
917
|
+
return h(this, O, new c().zero()), h(this, v, {}), e !== void 0 && this.parse(e), this;
|
|
1054
918
|
}
|
|
1055
919
|
// -----------------------------------------
|
|
1056
920
|
/**
|
|
@@ -1058,21 +922,21 @@ const B = class B {
|
|
|
1058
922
|
* @param inputStr
|
|
1059
923
|
*/
|
|
1060
924
|
parse(e) {
|
|
1061
|
-
return h(this,
|
|
925
|
+
return h(this, O, new c()), h(this, v, {}), typeof e == "string" ? i(this, bt).call(this, e) : typeof e == "number" ? h(this, O, new c(e)) : e instanceof c ? h(this, O, e.clone()) : e instanceof B && (h(this, O, i(e, O).clone()), M(this, He, pt).call(this, e)), this;
|
|
1062
926
|
}
|
|
1063
927
|
/**
|
|
1064
928
|
* Get the coefficient \\(k\\) of the Monom \\(k\\cdot x^{n}\\)
|
|
1065
929
|
* @returns {Fraction}
|
|
1066
930
|
*/
|
|
1067
931
|
get coefficient() {
|
|
1068
|
-
return i(this,
|
|
932
|
+
return i(this, O);
|
|
1069
933
|
}
|
|
1070
934
|
/**
|
|
1071
935
|
* Set the coefficient \\(k\\) value of the monom
|
|
1072
936
|
* @param {Fraction | number | string} F
|
|
1073
937
|
*/
|
|
1074
938
|
set coefficient(e) {
|
|
1075
|
-
h(this,
|
|
939
|
+
h(this, O, new c(e));
|
|
1076
940
|
}
|
|
1077
941
|
// Display getter
|
|
1078
942
|
/**
|
|
@@ -1080,10 +944,10 @@ const B = class B {
|
|
|
1080
944
|
*/
|
|
1081
945
|
get display() {
|
|
1082
946
|
let e = "";
|
|
1083
|
-
const t = Object.keys(i(this,
|
|
947
|
+
const t = Object.keys(i(this, v)).sort();
|
|
1084
948
|
for (const s of t)
|
|
1085
|
-
i(this,
|
|
1086
|
-
return e === "" ? i(this,
|
|
949
|
+
i(this, v)[s].isNotZero() && (e += s, i(this, v)[s].isNotEqual(1) && (e += `^(${i(this, v)[s].display})`));
|
|
950
|
+
return e === "" ? i(this, O).value != 0 ? i(this, O).display : "" : i(this, O).value === 1 ? e : i(this, O).value === -1 ? `-${e}` : i(this, O).value === 0 ? "0" : `${i(this, O).display}${e}`;
|
|
1087
951
|
}
|
|
1088
952
|
get dividers() {
|
|
1089
953
|
if (!this.coefficient.isRelative())
|
|
@@ -1092,7 +956,7 @@ const B = class B {
|
|
|
1092
956
|
return [this.clone()];
|
|
1093
957
|
if (this.coefficient.numerator > 1e6)
|
|
1094
958
|
return [this.clone()];
|
|
1095
|
-
const e =
|
|
959
|
+
const e = G.dividers(Math.abs(this.coefficient.numerator));
|
|
1096
960
|
let t = [];
|
|
1097
961
|
for (const r in this.literal)
|
|
1098
962
|
t = this._getLiteralDividers(t, r);
|
|
@@ -1124,14 +988,14 @@ const B = class B {
|
|
|
1124
988
|
* @returns {literalType}
|
|
1125
989
|
*/
|
|
1126
990
|
get literal() {
|
|
1127
|
-
return i(this,
|
|
991
|
+
return i(this, v);
|
|
1128
992
|
}
|
|
1129
993
|
/**
|
|
1130
994
|
* Set the literal part of the monom. Must be a dictionary {x: Fraction, y: Fraction, ...}
|
|
1131
995
|
* @param {literalType<Fraction>} L
|
|
1132
996
|
*/
|
|
1133
997
|
set literal(e) {
|
|
1134
|
-
h(this,
|
|
998
|
+
h(this, v, e);
|
|
1135
999
|
}
|
|
1136
1000
|
/**
|
|
1137
1001
|
* Get the literal square roots of the Monom.
|
|
@@ -1141,11 +1005,11 @@ const B = class B {
|
|
|
1141
1005
|
get literalSqrt() {
|
|
1142
1006
|
if (this.isLiteralSquare()) {
|
|
1143
1007
|
const e = {};
|
|
1144
|
-
for (const t in i(this,
|
|
1145
|
-
e[t] = i(this,
|
|
1008
|
+
for (const t in i(this, v))
|
|
1009
|
+
e[t] = i(this, v)[t].clone().sqrt();
|
|
1146
1010
|
return e;
|
|
1147
1011
|
} else
|
|
1148
|
-
return i(this,
|
|
1012
|
+
return i(this, v);
|
|
1149
1013
|
}
|
|
1150
1014
|
/**
|
|
1151
1015
|
* Set the literal part of the monom from a string
|
|
@@ -1153,29 +1017,29 @@ const B = class B {
|
|
|
1153
1017
|
*/
|
|
1154
1018
|
set literalStr(e) {
|
|
1155
1019
|
for (const t of [...e.matchAll(/([a-z])\^([+-]?[0-9]+)/g)])
|
|
1156
|
-
t[1] in i(this,
|
|
1020
|
+
t[1] in i(this, v) || (i(this, v)[t[1]] = new c().zero()), i(this, v)[t[1]].add(+t[2]);
|
|
1157
1021
|
for (const t of [...e.matchAll(/([a-z](?!\^))/g)])
|
|
1158
|
-
t[1] in i(this,
|
|
1022
|
+
t[1] in i(this, v) || (i(this, v)[t[1]] = new c().zero()), i(this, v)[t[1]].add(1);
|
|
1159
1023
|
}
|
|
1160
1024
|
get plotFunction() {
|
|
1161
1025
|
let e = "";
|
|
1162
|
-
const t = Object.keys(i(this,
|
|
1026
|
+
const t = Object.keys(i(this, v)).sort();
|
|
1163
1027
|
for (const s of t)
|
|
1164
|
-
i(this,
|
|
1165
|
-
return e === "" ? i(this,
|
|
1028
|
+
i(this, v)[s].isNotZero() && (e += (e === "" ? "" : "*") + s, i(this, v)[s].isNotEqual(1) && (e += `^(${i(this, v)[s].display})`));
|
|
1029
|
+
return e === "" ? i(this, O).value != 0 ? i(this, O).display : "" : i(this, O).value === 1 ? e : i(this, O).value === -1 ? `-${e}` : i(this, O).value === 0 ? "0" : `${i(this, O).display}*${e}`;
|
|
1166
1030
|
}
|
|
1167
1031
|
removeVariable(e) {
|
|
1168
|
-
delete i(this,
|
|
1032
|
+
delete i(this, v)[e];
|
|
1169
1033
|
}
|
|
1170
1034
|
/**
|
|
1171
1035
|
* Get the tex output of the monom
|
|
1172
1036
|
*/
|
|
1173
1037
|
get tex() {
|
|
1174
1038
|
let e = "";
|
|
1175
|
-
const t = Object.keys(i(this,
|
|
1039
|
+
const t = Object.keys(i(this, v)).sort();
|
|
1176
1040
|
for (const s of t)
|
|
1177
|
-
i(this,
|
|
1178
|
-
return e === "" ? i(this,
|
|
1041
|
+
i(this, v)[s].isNotZero() && (e += s, i(this, v)[s].isNotEqual(1) && (e += `^{ ${i(this, v)[s].tfrac.tex} }`));
|
|
1042
|
+
return e === "" ? i(this, O).value != 0 ? i(this, O).frac.tex : "0" : i(this, O).value === 1 ? e : i(this, O).value === -1 ? `-${e}` : i(this, O).value === 0 ? "0" : `${i(this, O).frac.tex}${e}`;
|
|
1179
1043
|
}
|
|
1180
1044
|
// Getter helpers.
|
|
1181
1045
|
/**
|
|
@@ -1206,14 +1070,14 @@ const B = class B {
|
|
|
1206
1070
|
}
|
|
1207
1071
|
// #endregion Private methods (5)
|
|
1208
1072
|
};
|
|
1209
|
-
|
|
1073
|
+
O = new WeakMap(), v = new WeakMap(), He = new WeakSet(), pt = function(e) {
|
|
1210
1074
|
for (const t in e.literal)
|
|
1211
|
-
i(this,
|
|
1212
|
-
},
|
|
1075
|
+
i(this, v)[t] = e.literal[t].clone();
|
|
1076
|
+
}, Re = new WeakMap(), bt = new WeakMap(), xt = new WeakMap(), a(B, "gcd", (...e) => {
|
|
1213
1077
|
for (const n of e)
|
|
1214
1078
|
if (n.containsRationalPower())
|
|
1215
1079
|
return new B().zero();
|
|
1216
|
-
const t = new B(), s =
|
|
1080
|
+
const t = new B(), s = G.gcd(...e.map((n) => n.coefficient.numerator)), r = G.lcm(...e.map((n) => n.coefficient.denominator));
|
|
1217
1081
|
t.coefficient = new c(s, r).reduce();
|
|
1218
1082
|
for (const n of e) {
|
|
1219
1083
|
for (const l in t.literal)
|
|
@@ -1232,14 +1096,150 @@ a(B, "xMultiply", (...e) => {
|
|
|
1232
1096
|
t.multiply(s);
|
|
1233
1097
|
return t;
|
|
1234
1098
|
});
|
|
1235
|
-
let
|
|
1236
|
-
var
|
|
1099
|
+
let I = B;
|
|
1100
|
+
var ue, De, P, ge, rt, ui, fi, di, Ht, pi;
|
|
1101
|
+
const ii = class ii {
|
|
1102
|
+
constructor(e, t, s = "x") {
|
|
1103
|
+
f(this, P);
|
|
1104
|
+
f(this, ue);
|
|
1105
|
+
f(this, De);
|
|
1106
|
+
if (h(this, De, s), Object.hasOwn(e, "moveLeft")) {
|
|
1107
|
+
const r = e;
|
|
1108
|
+
h(this, ue, r.left.clone().subtract(r.right));
|
|
1109
|
+
} else
|
|
1110
|
+
h(this, ue, e.clone().subtract(t ?? 0));
|
|
1111
|
+
}
|
|
1112
|
+
solve() {
|
|
1113
|
+
if (i(this, ue).degree().isOne())
|
|
1114
|
+
return M(this, P, ui).call(this);
|
|
1115
|
+
if (i(this, ue).degree().value === 2)
|
|
1116
|
+
return M(this, P, fi).call(this);
|
|
1117
|
+
const e = M(this, P, pi).call(this);
|
|
1118
|
+
if (e.length > 0)
|
|
1119
|
+
return e;
|
|
1120
|
+
if (i(this, ue).degree().value === 3)
|
|
1121
|
+
return M(this, P, Ht).call(this);
|
|
1122
|
+
throw new Error("The equation degree is too high.");
|
|
1123
|
+
}
|
|
1124
|
+
solveAsCardan() {
|
|
1125
|
+
if (i(this, ue).degree().value !== 3)
|
|
1126
|
+
throw new Error("The equation is not cubic.");
|
|
1127
|
+
return M(this, P, Ht).call(this);
|
|
1128
|
+
}
|
|
1129
|
+
};
|
|
1130
|
+
ue = new WeakMap(), De = new WeakMap(), P = new WeakSet(), ge = function(e) {
|
|
1131
|
+
if (e instanceof c && e.isApproximative())
|
|
1132
|
+
return M(this, P, rt).call(this, e.value);
|
|
1133
|
+
const t = new c(e);
|
|
1134
|
+
return {
|
|
1135
|
+
variable: i(this, De),
|
|
1136
|
+
exact: t,
|
|
1137
|
+
value: t.value,
|
|
1138
|
+
tex: t.tex,
|
|
1139
|
+
display: t.display
|
|
1140
|
+
};
|
|
1141
|
+
}, rt = function(e, t) {
|
|
1142
|
+
return {
|
|
1143
|
+
variable: i(this, De),
|
|
1144
|
+
exact: !1,
|
|
1145
|
+
value: +e.toFixed(10),
|
|
1146
|
+
tex: (t == null ? void 0 : t.tex) ?? "",
|
|
1147
|
+
display: (t == null ? void 0 : t.display) ?? ""
|
|
1148
|
+
};
|
|
1149
|
+
}, ui = function() {
|
|
1150
|
+
const e = i(this, ue).monomByDegree(0).coefficient.clone().opposite().divide(i(this, ue).monomByDegree(1).coefficient);
|
|
1151
|
+
return [
|
|
1152
|
+
M(this, P, ge).call(this, e)
|
|
1153
|
+
];
|
|
1154
|
+
}, fi = function() {
|
|
1155
|
+
const e = i(this, ue), t = e.monomByDegree(2).coefficient, s = e.monomByDegree(1).coefficient, r = e.monomByDegree(0).coefficient, n = s.clone().pow(2).subtract(t.clone().multiply(r).multiply(4));
|
|
1156
|
+
if (n.isNegative())
|
|
1157
|
+
return [];
|
|
1158
|
+
if (n.isSquare()) {
|
|
1159
|
+
const l = n.sqrt(), u = s.clone().opposite().add(l).divide(t.clone().multiply(2)), p = s.clone().opposite().subtract(l).divide(t.clone().multiply(2));
|
|
1160
|
+
return l.isZero() ? [M(this, P, ge).call(this, u)] : [
|
|
1161
|
+
M(this, P, ge).call(this, u),
|
|
1162
|
+
M(this, P, ge).call(this, p)
|
|
1163
|
+
].sort((m, y) => m.value - y.value);
|
|
1164
|
+
}
|
|
1165
|
+
return M(this, P, di).call(this, t, s, n);
|
|
1166
|
+
}, di = function(e, t, s) {
|
|
1167
|
+
const r = G.dividers(s.value).filter((pe) => Math.sqrt(pe) % 1 === 0).map((pe) => Math.sqrt(pe)).pop() ?? 1, n = G.gcd(2 * e.value, t.value, r) * (e.isNegative() ? -1 : 1), l = t.clone().divide(n).opposite(), u = e.clone().divide(n).multiply(2), p = s.clone().divide(r ** 2), m = Math.abs(r / n), y = r === 1 ? "-" : `-${m} `, E = r === 1 ? "+" : `+${m} `;
|
|
1168
|
+
function D(pe, ce, et, Ut) {
|
|
1169
|
+
return `\\frac{ ${ce} ${et}\\sqrt{ ${Ut} } }{ ${pe} }`;
|
|
1170
|
+
}
|
|
1171
|
+
function te(pe, ce, et, Ut) {
|
|
1172
|
+
return `(${ce}${et}sqrt(${Ut}))/${pe}`;
|
|
1173
|
+
}
|
|
1174
|
+
const ae = s.value ** 0.5, le = (-t.value - ae) / (2 * e.value), ye = (-t.value + ae) / (2 * e.value);
|
|
1175
|
+
return [
|
|
1176
|
+
M(this, P, rt).call(this, le, {
|
|
1177
|
+
tex: D(u.tex, l.tex, y.toString(), p.tex),
|
|
1178
|
+
display: te(u.display, l.display, y.toString(), p.display)
|
|
1179
|
+
}),
|
|
1180
|
+
M(this, P, rt).call(this, ye, {
|
|
1181
|
+
tex: D(u.tex, l.tex, E.toString(), p.tex),
|
|
1182
|
+
display: te(u.display, l.display, E.toString(), p.display)
|
|
1183
|
+
})
|
|
1184
|
+
].sort((pe, ce) => pe.value - ce.value);
|
|
1185
|
+
}, Ht = function() {
|
|
1186
|
+
const e = i(this, ue), t = e.monomByDegree(3).coefficient, s = e.monomByDegree(2).coefficient, r = e.monomByDegree(1).coefficient, n = e.monomByDegree(0).coefficient, l = s.clone().divide(t), u = r.clone().divide(t), p = n.clone().divide(t), m = u.clone().subtract(l.clone().pow(2).divide(3)), y = p.clone().subtract(l.clone().multiply(u).divide(3)).add(l.clone().pow(3).multiply(2).divide(27)), E = y.clone().opposite(), D = m.clone().opposite().pow(3).divide(27), te = E.clone().pow(2).subtract(D.clone().multiply(4)).opposite();
|
|
1187
|
+
if (te.isNegative()) {
|
|
1188
|
+
const ae = y.clone().opposite().add(te.clone().opposite().sqrt()).divide(2).root(3), le = y.clone().opposite().subtract(te.clone().opposite().sqrt()).divide(2).root(3), ye = ae.clone().add(le).subtract(l.clone().divide(3));
|
|
1189
|
+
return [M(this, P, ge).call(this, ye)];
|
|
1190
|
+
}
|
|
1191
|
+
if (te.isZero()) {
|
|
1192
|
+
const ae = y.clone().opposite().divide(2).root(3), le = ae.clone().opposite().subtract(l.clone().divide(3)), ye = ae.clone().multiply(2).subtract(l.clone().divide(3));
|
|
1193
|
+
return le.isEqual(ye) ? [M(this, P, ge).call(this, le)] : [
|
|
1194
|
+
M(this, P, ge).call(this, ye),
|
|
1195
|
+
M(this, P, ge).call(this, le)
|
|
1196
|
+
].sort((pe, ce) => pe.value - ce.value);
|
|
1197
|
+
}
|
|
1198
|
+
if (te.isPositive()) {
|
|
1199
|
+
const ae = [], le = m.value, ye = y.value, pe = l.value;
|
|
1200
|
+
for (let ce = 0; ce < 3; ce++)
|
|
1201
|
+
ae.push(2 * Math.sqrt(-le / 3) * Math.cos(Math.acos(3 * ye / (2 * le) * Math.sqrt(-3 / le)) / 3 + 2 * Math.PI * ce / 3) - pe / 3);
|
|
1202
|
+
return ae.map((ce) => M(this, P, rt).call(this, ce)).sort((ce, et) => ce.value - et.value);
|
|
1203
|
+
}
|
|
1204
|
+
return [];
|
|
1205
|
+
}, pi = function() {
|
|
1206
|
+
let e = i(this, ue).clone(), t = [];
|
|
1207
|
+
const s = e.lcmDenominator();
|
|
1208
|
+
s !== 1 && e.multiply(s);
|
|
1209
|
+
const r = e.monomByDegree().coefficient;
|
|
1210
|
+
let n = e.monomByDegree(0).coefficient;
|
|
1211
|
+
for (; n.isZero(); )
|
|
1212
|
+
t.length === 0 && t.push(M(this, P, ge).call(this, 0)), e = e.divide("x"), n = e.monomByDegree(0).coefficient;
|
|
1213
|
+
const l = G.dividers(r.value), u = G.dividers(n.value);
|
|
1214
|
+
for (const y of l)
|
|
1215
|
+
for (const E of u) {
|
|
1216
|
+
const D = new c(E, y);
|
|
1217
|
+
e.evaluate(D).isZero() && !t.find((te) => te.value === D.value) && t.push(M(this, P, ge).call(this, D)), D.opposite(), e.evaluate(D).isZero() && !t.find((te) => te.value === D.value) && t.push(M(this, P, ge).call(this, D));
|
|
1218
|
+
}
|
|
1219
|
+
for (const y of t) {
|
|
1220
|
+
if (y.exact !== !1 && y.exact.isZero())
|
|
1221
|
+
continue;
|
|
1222
|
+
const E = i(this, ue).clone().parse("x", y.exact.denominator, -y.exact.numerator);
|
|
1223
|
+
for (; e.isDividableBy(E); )
|
|
1224
|
+
console.log(e.display, E.display), e = e.divide(E);
|
|
1225
|
+
}
|
|
1226
|
+
if (e.degree().isZero())
|
|
1227
|
+
return t.sort((y, E) => y.value - E.value);
|
|
1228
|
+
if (e.degree().value > 3)
|
|
1229
|
+
return [];
|
|
1230
|
+
const p = e.clone().parse("0");
|
|
1231
|
+
console.log(e.display), console.log(p.display);
|
|
1232
|
+
const m = new ii(e, e.clone().parse("0"), i(this, De));
|
|
1233
|
+
return t = t.concat(m.solve()), t.sort((y, E) => y.value - E.value);
|
|
1234
|
+
};
|
|
1235
|
+
let yt = ii;
|
|
1236
|
+
var Ze, g, Xe, ht, Et, Nt, Ot, qt, at, Tt, At, Mt, It, mi, Ct, Ye, $t;
|
|
1237
1237
|
const C = class C {
|
|
1238
1238
|
constructor(e, ...t) {
|
|
1239
|
-
|
|
1239
|
+
f(this, It);
|
|
1240
1240
|
// #region Class fields (8)
|
|
1241
|
-
|
|
1242
|
-
|
|
1241
|
+
f(this, Ze);
|
|
1242
|
+
f(this, g);
|
|
1243
1243
|
// #endregion Constructors (7)
|
|
1244
1244
|
// #region Properties and methods (49)
|
|
1245
1245
|
/**
|
|
@@ -1248,17 +1248,17 @@ const C = class C {
|
|
|
1248
1248
|
* @param values
|
|
1249
1249
|
*/
|
|
1250
1250
|
a(this, "parse", (e, ...t) => {
|
|
1251
|
-
if (h(this,
|
|
1252
|
-
return
|
|
1253
|
-
if ((typeof e == "number" || e instanceof c || e instanceof
|
|
1254
|
-
i(this,
|
|
1255
|
-
else if (e instanceof
|
|
1256
|
-
i(this,
|
|
1257
|
-
i(this,
|
|
1251
|
+
if (h(this, g, []), h(this, Ze, []), typeof e == "string")
|
|
1252
|
+
return M(this, It, mi).call(this, e, ...t);
|
|
1253
|
+
if ((typeof e == "number" || e instanceof c || e instanceof I) && t.length === 0)
|
|
1254
|
+
i(this, g).push(new I(e));
|
|
1255
|
+
else if (e instanceof I && t.length > 0)
|
|
1256
|
+
i(this, g).push(new I(e)), t.forEach((s) => {
|
|
1257
|
+
i(this, g).push(new I(s));
|
|
1258
1258
|
});
|
|
1259
1259
|
else if (e instanceof C)
|
|
1260
1260
|
for (const s of e.monoms)
|
|
1261
|
-
i(this,
|
|
1261
|
+
i(this, g).push(s.clone());
|
|
1262
1262
|
return this;
|
|
1263
1263
|
});
|
|
1264
1264
|
/**
|
|
@@ -1266,21 +1266,21 @@ const C = class C {
|
|
|
1266
1266
|
*/
|
|
1267
1267
|
a(this, "clone", () => {
|
|
1268
1268
|
const e = new C(), t = [];
|
|
1269
|
-
for (const s of i(this,
|
|
1269
|
+
for (const s of i(this, g))
|
|
1270
1270
|
t.push(s.clone());
|
|
1271
1271
|
return e.monoms = t, e;
|
|
1272
1272
|
});
|
|
1273
1273
|
a(this, "add", (...e) => {
|
|
1274
1274
|
for (const t of e)
|
|
1275
|
-
t instanceof C ? h(this,
|
|
1275
|
+
t instanceof C ? h(this, g, i(this, g).concat(t.monoms)) : t instanceof I ? i(this, g).push(t.clone()) : typeof t == "number" && Number.isSafeInteger(t) ? i(this, g).push(new I(t.toString())) : i(this, g).push(new I(t));
|
|
1276
1276
|
return this.reduce();
|
|
1277
1277
|
});
|
|
1278
1278
|
a(this, "commonMonom", () => {
|
|
1279
|
-
const e = new
|
|
1279
|
+
const e = new I().one(), t = this.gcdNumerator(), s = this.gcdDenominator(), r = this.degree();
|
|
1280
1280
|
e.coefficient = new c(t, s);
|
|
1281
1281
|
for (const n of this.variables) {
|
|
1282
1282
|
e.setLetter(n, r);
|
|
1283
|
-
for (const l of i(this,
|
|
1283
|
+
for (const l of i(this, g))
|
|
1284
1284
|
if (e.setLetter(n, c.min(l.degree(n), e.degree(n))), e.degree(n).isZero())
|
|
1285
1285
|
break;
|
|
1286
1286
|
}
|
|
@@ -1288,26 +1288,26 @@ const C = class C {
|
|
|
1288
1288
|
});
|
|
1289
1289
|
a(this, "degree", (e) => {
|
|
1290
1290
|
let t = new c().zero();
|
|
1291
|
-
for (const s of i(this,
|
|
1291
|
+
for (const s of i(this, g))
|
|
1292
1292
|
t = c.max(s.degree(e).value, t);
|
|
1293
1293
|
return t;
|
|
1294
1294
|
});
|
|
1295
1295
|
a(this, "derivative", (e) => {
|
|
1296
1296
|
const t = new C();
|
|
1297
|
-
for (const s of i(this,
|
|
1297
|
+
for (const s of i(this, g))
|
|
1298
1298
|
t.add(s.derivative(e));
|
|
1299
1299
|
return t;
|
|
1300
1300
|
});
|
|
1301
1301
|
a(this, "divide", (e) => {
|
|
1302
1302
|
if (e instanceof c)
|
|
1303
|
-
return i(this,
|
|
1303
|
+
return i(this, ht).call(this, e);
|
|
1304
1304
|
if (typeof e == "number" && Number.isSafeInteger(e))
|
|
1305
|
-
return i(this,
|
|
1306
|
-
if (e instanceof
|
|
1305
|
+
return i(this, Et).call(this, e);
|
|
1306
|
+
if (e instanceof I)
|
|
1307
1307
|
return this.divide(new C(e));
|
|
1308
1308
|
if (e instanceof C) {
|
|
1309
1309
|
if (e.monoms.length === 1 && e.variables.length === 0)
|
|
1310
|
-
return i(this,
|
|
1310
|
+
return i(this, ht).call(this, e.monoms[0].coefficient);
|
|
1311
1311
|
{
|
|
1312
1312
|
const { quotient: t, reminder: s } = this.euclidean(e);
|
|
1313
1313
|
if (s.isZero())
|
|
@@ -1317,7 +1317,7 @@ const C = class C {
|
|
|
1317
1317
|
return this.divide(new C(e));
|
|
1318
1318
|
throw new Error(`Cannot divide by ${e}`);
|
|
1319
1319
|
});
|
|
1320
|
-
a(this, "empty", () => (h(this,
|
|
1320
|
+
a(this, "empty", () => (h(this, g, []), this));
|
|
1321
1321
|
/**
|
|
1322
1322
|
* Divide the current polynom by another polynom.
|
|
1323
1323
|
* @param P
|
|
@@ -1331,16 +1331,16 @@ const C = class C {
|
|
|
1331
1331
|
reminder: new C().zero()
|
|
1332
1332
|
};
|
|
1333
1333
|
const n = e.monomByDegree(void 0, t), l = e.degree(t);
|
|
1334
|
-
let u,
|
|
1335
|
-
for (; r.degree(t).isGeq(l) &&
|
|
1334
|
+
let u, p = this.degree(t).value * 2;
|
|
1335
|
+
for (; r.degree(t).isGeq(l) && p > 0 && (p--, u = r.monomByDegree(void 0, t).clone().divide(n), !(!u.isZero() && (s.add(u), r.subtract(e.clone().multiply(u)).reduce(), u.degree(t).isZero()))); )
|
|
1336
1336
|
;
|
|
1337
1337
|
return s.reduce(), r.reduce(), { quotient: s, reminder: r };
|
|
1338
1338
|
});
|
|
1339
1339
|
a(this, "evaluate", (e, t) => {
|
|
1340
1340
|
if (t)
|
|
1341
|
-
return i(this,
|
|
1341
|
+
return i(this, Nt).call(this, e);
|
|
1342
1342
|
const s = new c().zero();
|
|
1343
|
-
return i(this,
|
|
1343
|
+
return i(this, g).forEach((r) => {
|
|
1344
1344
|
s.add(r.evaluate(e, t));
|
|
1345
1345
|
}), s;
|
|
1346
1346
|
});
|
|
@@ -1365,38 +1365,38 @@ const C = class C {
|
|
|
1365
1365
|
t.push(s.clone()), s.one();
|
|
1366
1366
|
break;
|
|
1367
1367
|
} else {
|
|
1368
|
-
let u = i(this,
|
|
1368
|
+
let u = i(this, qt).call(this, s, l, e ?? "x");
|
|
1369
1369
|
for (l = s.degree(e).value; u.length > 0; ) {
|
|
1370
|
-
const
|
|
1371
|
-
if (!s.isDividableBy(
|
|
1370
|
+
const p = u[0];
|
|
1371
|
+
if (!s.isDividableBy(p))
|
|
1372
1372
|
u.shift();
|
|
1373
1373
|
else {
|
|
1374
|
-
const
|
|
1375
|
-
t.push(
|
|
1376
|
-
const
|
|
1377
|
-
return
|
|
1374
|
+
const m = s.euclidean(p);
|
|
1375
|
+
t.push(p), s = m.quotient.clone(), u = u.filter((y) => {
|
|
1376
|
+
const E = s.monoms[0], D = s.monoms[s.monoms.length - 1], te = y.monoms[0], ae = y.monoms[y.monoms.length - 1];
|
|
1377
|
+
return D.isDivisible(ae) ? E.isDivisible(te) : !1;
|
|
1378
1378
|
});
|
|
1379
1379
|
}
|
|
1380
1380
|
}
|
|
1381
1381
|
}
|
|
1382
|
-
return s.isOne() || t.push(s.clone()), h(this,
|
|
1382
|
+
return s.isOne() || t.push(s.clone()), h(this, Ze, t), i(this, Ze);
|
|
1383
1383
|
});
|
|
1384
|
-
a(this, "gcdDenominator", () =>
|
|
1385
|
-
a(this, "gcdNumerator", () =>
|
|
1384
|
+
a(this, "gcdDenominator", () => G.gcd(...this.getDenominators()));
|
|
1385
|
+
a(this, "gcdNumerator", () => G.gcd(...this.getNumerators()));
|
|
1386
1386
|
// Next functions are used for for commonMonom, which is used in the factorize method.
|
|
1387
1387
|
a(this, "getDenominators", () => {
|
|
1388
1388
|
const e = [];
|
|
1389
|
-
for (const t of i(this,
|
|
1389
|
+
for (const t of i(this, g))
|
|
1390
1390
|
e.push(t.coefficient.denominator);
|
|
1391
1391
|
return e;
|
|
1392
1392
|
});
|
|
1393
1393
|
a(this, "getNumerators", () => {
|
|
1394
1394
|
const e = [];
|
|
1395
|
-
for (const t of i(this,
|
|
1395
|
+
for (const t of i(this, g))
|
|
1396
1396
|
e.push(t.coefficient.numerator);
|
|
1397
1397
|
return e;
|
|
1398
1398
|
});
|
|
1399
|
-
a(this, "getZeroes", () => new
|
|
1399
|
+
a(this, "getZeroes", () => new yt(this.clone()).solve());
|
|
1400
1400
|
a(this, "integrate", (e, t, s = "x") => {
|
|
1401
1401
|
const r = this.primitive(s), n = {}, l = {};
|
|
1402
1402
|
return n[s] = new c(e), l[s] = new c(t), r.evaluate(l).subtract(r.evaluate(n));
|
|
@@ -1422,8 +1422,8 @@ const C = class C {
|
|
|
1422
1422
|
return t.isZero();
|
|
1423
1423
|
}
|
|
1424
1424
|
});
|
|
1425
|
-
a(this, "isEqual", (e) => i(this,
|
|
1426
|
-
a(this, "isOppositeAt", (e) => i(this,
|
|
1425
|
+
a(this, "isEqual", (e) => i(this, Xe).call(this, e, "="));
|
|
1426
|
+
a(this, "isOppositeAt", (e) => i(this, Xe).call(this, e.clone().opposite(), "="));
|
|
1427
1427
|
a(this, "isReduced", (e) => {
|
|
1428
1428
|
if (!this.isDeveloped(e))
|
|
1429
1429
|
return !1;
|
|
@@ -1435,12 +1435,12 @@ const C = class C {
|
|
|
1435
1435
|
return !1;
|
|
1436
1436
|
return !1;
|
|
1437
1437
|
});
|
|
1438
|
-
a(this, "isSameAs", (e) => i(this,
|
|
1439
|
-
a(this, "lcmDenominator", () =>
|
|
1440
|
-
a(this, "lcmNumerator", () =>
|
|
1438
|
+
a(this, "isSameAs", (e) => i(this, Xe).call(this, e, "same"));
|
|
1439
|
+
a(this, "lcmDenominator", () => G.lcm(...this.getDenominators()));
|
|
1440
|
+
a(this, "lcmNumerator", () => G.lcm(...this.getNumerators()));
|
|
1441
1441
|
a(this, "letters", () => {
|
|
1442
1442
|
let e = /* @__PURE__ */ new Set();
|
|
1443
|
-
for (const t of i(this,
|
|
1443
|
+
for (const t of i(this, g))
|
|
1444
1444
|
e = /* @__PURE__ */ new Set([...e, ...t.variables]);
|
|
1445
1445
|
return [...e];
|
|
1446
1446
|
});
|
|
@@ -1456,31 +1456,31 @@ const C = class C {
|
|
|
1456
1456
|
if (e === void 0)
|
|
1457
1457
|
return this.monomByDegree(this.degree(t), t);
|
|
1458
1458
|
const s = this.clone().reduce();
|
|
1459
|
-
for (const r of i(s,
|
|
1459
|
+
for (const r of i(s, g))
|
|
1460
1460
|
if (r.degree(t).isEqual(e))
|
|
1461
1461
|
return r.clone();
|
|
1462
|
-
return new
|
|
1462
|
+
return new I().zero();
|
|
1463
1463
|
});
|
|
1464
1464
|
// Used in LinearSystem.tex
|
|
1465
1465
|
a(this, "monomByLetter", (e) => {
|
|
1466
1466
|
const t = this.clone().reduce();
|
|
1467
|
-
for (const s of i(t,
|
|
1467
|
+
for (const s of i(t, g))
|
|
1468
1468
|
if (s.hasVariable(e))
|
|
1469
1469
|
return s.clone();
|
|
1470
|
-
return new
|
|
1470
|
+
return new I().zero();
|
|
1471
1471
|
});
|
|
1472
1472
|
a(this, "monomsByDegree", (e, t) => {
|
|
1473
1473
|
if (e === void 0)
|
|
1474
1474
|
return this.monomsByDegree(this.degree(t));
|
|
1475
1475
|
const s = [], r = this.clone().reduce();
|
|
1476
|
-
for (const n of i(r,
|
|
1476
|
+
for (const n of i(r, g))
|
|
1477
1477
|
n.degree(t) === e && s.push(n.clone());
|
|
1478
1478
|
return s;
|
|
1479
1479
|
});
|
|
1480
|
-
a(this, "multiply", (e) => e instanceof C ? i(this,
|
|
1481
|
-
a(this, "one", () => (h(this,
|
|
1480
|
+
a(this, "multiply", (e) => e instanceof C ? i(this, Mt).call(this, e) : e instanceof c ? i(this, at).call(this, e) : e instanceof I ? i(this, At).call(this, e) : Number.isSafeInteger(e) && typeof e == "number" ? i(this, Tt).call(this, e) : this);
|
|
1481
|
+
a(this, "one", () => (h(this, g, []), i(this, g).push(new I().one()), this));
|
|
1482
1482
|
// ------------------------------------------
|
|
1483
|
-
a(this, "opposite", () => (h(this,
|
|
1483
|
+
a(this, "opposite", () => (h(this, g, i(this, g).map((e) => e.opposite())), this));
|
|
1484
1484
|
a(this, "pow", (e) => {
|
|
1485
1485
|
if (!Number.isSafeInteger(e))
|
|
1486
1486
|
return this.zero();
|
|
@@ -1495,34 +1495,34 @@ const C = class C {
|
|
|
1495
1495
|
});
|
|
1496
1496
|
a(this, "primitive", (e) => {
|
|
1497
1497
|
const t = new C();
|
|
1498
|
-
for (const s of i(this,
|
|
1498
|
+
for (const s of i(this, g))
|
|
1499
1499
|
t.add(s.primitive(e));
|
|
1500
1500
|
return t;
|
|
1501
1501
|
});
|
|
1502
1502
|
a(this, "reduce", () => {
|
|
1503
1503
|
let e = 0;
|
|
1504
|
-
for (; e < i(this,
|
|
1505
|
-
for (let t = e + 1; t < i(this,
|
|
1506
|
-
i(this,
|
|
1504
|
+
for (; e < i(this, g).length; ) {
|
|
1505
|
+
for (let t = e + 1; t < i(this, g).length; t++)
|
|
1506
|
+
i(this, g)[e].isSameAs(i(this, g)[t]) && (i(this, g)[e].add(i(this, g)[t]), i(this, g).splice(t, 1), i(this, g)[e].isZero() && (i(this, g)[e] = new I().zero()), t--);
|
|
1507
1507
|
e++;
|
|
1508
1508
|
}
|
|
1509
|
-
h(this,
|
|
1510
|
-
for (const t of i(this,
|
|
1509
|
+
h(this, g, i(this, g).filter((t) => !t.coefficient.isZero()));
|
|
1510
|
+
for (const t of i(this, g))
|
|
1511
1511
|
t.coefficient.reduce();
|
|
1512
1512
|
return this.length === 0 ? new C().zero() : this.reorder();
|
|
1513
1513
|
});
|
|
1514
1514
|
a(this, "reorder", (e = "x", t) => {
|
|
1515
1515
|
t === void 0 && (t = !1);
|
|
1516
1516
|
const s = this.variables.filter((r) => r !== e);
|
|
1517
|
-
return i(this,
|
|
1517
|
+
return i(this, g).sort(function(r, n) {
|
|
1518
1518
|
const l = r.degree(e).value, u = n.degree(e).value;
|
|
1519
1519
|
if (l !== u)
|
|
1520
1520
|
return t ? l - u : u - l;
|
|
1521
1521
|
if (s.length > 0)
|
|
1522
|
-
for (const
|
|
1523
|
-
const
|
|
1524
|
-
if (
|
|
1525
|
-
return t ?
|
|
1522
|
+
for (const p of s) {
|
|
1523
|
+
const m = r.degree(p).value, y = n.degree(p).value;
|
|
1524
|
+
if (m !== y)
|
|
1525
|
+
return t ? m - y : y - m;
|
|
1526
1526
|
}
|
|
1527
1527
|
return 0;
|
|
1528
1528
|
}), this;
|
|
@@ -1537,21 +1537,21 @@ const C = class C {
|
|
|
1537
1537
|
const r = new C().zero();
|
|
1538
1538
|
for (const n of this.monoms)
|
|
1539
1539
|
!n.hasVariable(e) || n.literal[e].isZero() ? r.add(n.clone()) : (s = n.literal[e].clone(), n.removeVariable(e), r.add(t.clone().pow(Math.abs(s.numerator)).multiply(n)));
|
|
1540
|
-
return h(this,
|
|
1540
|
+
return h(this, g, r.reduce().monoms), this;
|
|
1541
1541
|
});
|
|
1542
1542
|
a(this, "subtract", (...e) => {
|
|
1543
1543
|
for (const t of e)
|
|
1544
|
-
t instanceof C ? this.add(t.clone().opposite()) : t instanceof
|
|
1544
|
+
t instanceof C ? this.add(t.clone().opposite()) : t instanceof I ? i(this, g).push(t.clone().opposite()) : i(this, g).push(new I(t).opposite());
|
|
1545
1545
|
return this.reduce();
|
|
1546
1546
|
});
|
|
1547
1547
|
/**
|
|
1548
1548
|
* Set the polynom to zero.
|
|
1549
1549
|
* @returns {this}
|
|
1550
1550
|
*/
|
|
1551
|
-
a(this, "zero", () => (h(this,
|
|
1551
|
+
a(this, "zero", () => (h(this, g, []), i(this, g).push(new I().zero()), this));
|
|
1552
1552
|
// #endregion Getters And Setters (22)
|
|
1553
1553
|
// #region Private methods (15)
|
|
1554
|
-
|
|
1554
|
+
f(this, Xe, (e, t) => {
|
|
1555
1555
|
t === void 0 && (t = "=");
|
|
1556
1556
|
const s = this.clone().reduce(), r = e.clone().reduce();
|
|
1557
1557
|
switch (t) {
|
|
@@ -1563,84 +1563,84 @@ const C = class C {
|
|
|
1563
1563
|
return !1;
|
|
1564
1564
|
}
|
|
1565
1565
|
});
|
|
1566
|
-
|
|
1567
|
-
for (const t of i(this,
|
|
1566
|
+
f(this, ht, (e) => {
|
|
1567
|
+
for (const t of i(this, g))
|
|
1568
1568
|
t.coefficient.divide(e);
|
|
1569
1569
|
return this;
|
|
1570
1570
|
});
|
|
1571
|
-
|
|
1571
|
+
f(this, Et, (e) => {
|
|
1572
1572
|
const t = new c(e);
|
|
1573
|
-
for (const s of i(this,
|
|
1573
|
+
for (const s of i(this, g))
|
|
1574
1574
|
s.coefficient.divide(t);
|
|
1575
1575
|
return this;
|
|
1576
1576
|
});
|
|
1577
|
-
|
|
1577
|
+
f(this, Nt, (e) => {
|
|
1578
1578
|
let t = 0;
|
|
1579
|
-
return i(this,
|
|
1579
|
+
return i(this, g).forEach((s) => {
|
|
1580
1580
|
t += s.evaluate(e, !0);
|
|
1581
1581
|
}), t;
|
|
1582
1582
|
});
|
|
1583
|
-
|
|
1584
|
-
var
|
|
1585
|
-
let t, s, r, n, l, u,
|
|
1583
|
+
f(this, Ot, (e) => {
|
|
1584
|
+
var E;
|
|
1585
|
+
let t, s, r, n, l, u, p, m, y;
|
|
1586
1586
|
if (this.numberOfVars === 1)
|
|
1587
|
-
return r = this.monomByDegree(2, e).coefficient, n = this.monomByDegree(1, e).coefficient, l = this.monomByDegree(0, e).coefficient, u = n.clone().pow(2).subtract(r.clone().multiply(l).multiply(4)), u.isZero() ? (
|
|
1588
|
-
new C(e).subtract(
|
|
1589
|
-
new C(e).subtract(
|
|
1587
|
+
return r = this.monomByDegree(2, e).coefficient, n = this.monomByDegree(1, e).coefficient, l = this.monomByDegree(0, e).coefficient, u = n.clone().pow(2).subtract(r.clone().multiply(l).multiply(4)), u.isZero() ? (p = n.clone().opposite().divide(r.clone().multiply(2)), t = new C(e).subtract(p.display).multiply(p.denominator), s = new C(e).subtract(p.display).multiply(p.denominator), y = r.divide(p.denominator).divide(p.denominator), y.isOne() ? [t, s] : [new C(y.display), t, s]) : u.isPositive() && u.isSquare() ? (p = n.clone().opposite().add(u.clone().sqrt()).divide(r.clone().multiply(2)), m = n.clone().opposite().subtract(u.clone().sqrt()).divide(r.clone().multiply(2)), y = r.divide(p.denominator).divide(m.denominator), y.isOne() ? [
|
|
1588
|
+
new C(e).subtract(p.display).multiply(p.denominator),
|
|
1589
|
+
new C(e).subtract(m.display).multiply(m.denominator)
|
|
1590
1590
|
] : [
|
|
1591
|
-
new C(
|
|
1592
|
-
new C(e).subtract(
|
|
1593
|
-
new C(e).subtract(
|
|
1591
|
+
new C(y.display),
|
|
1592
|
+
new C(e).subtract(p.display).multiply(p.denominator),
|
|
1593
|
+
new C(e).subtract(m.display).multiply(m.denominator)
|
|
1594
1594
|
]) : [this.clone()];
|
|
1595
1595
|
if (r = this.monomByDegree(2, e), n = this.monomByDegree(1, e), l = this.monomByDegree(0, e), r.isLiteralSquare() && l.isLiteralSquare() && n.clone().pow(2).isSameAs(r.clone().multiply(l))) {
|
|
1596
|
-
const
|
|
1597
|
-
let
|
|
1598
|
-
if (
|
|
1599
|
-
for (const
|
|
1600
|
-
|
|
1601
|
-
return
|
|
1596
|
+
const D = new C("x", r.coefficient, n.coefficient, l.coefficient), te = i(E = D, Ot).call(E, "x"), ae = [];
|
|
1597
|
+
let le;
|
|
1598
|
+
if (te.length >= 2) {
|
|
1599
|
+
for (const ye of te)
|
|
1600
|
+
ye.degree().isZero() ? ae.push(ye.clone()) : (le = ye.clone(), le.monoms[0].literal = r.literalSqrt, le.monoms[1].literal = l.literalSqrt, ae.push(le.clone()));
|
|
1601
|
+
return ae;
|
|
1602
1602
|
}
|
|
1603
1603
|
}
|
|
1604
1604
|
return [this.clone()];
|
|
1605
1605
|
});
|
|
1606
|
-
|
|
1606
|
+
f(this, qt, (e, t, s) => {
|
|
1607
1607
|
const r = e.monoms[0].dividers, n = e.monoms[e.monoms.length - 1].dividers, l = [];
|
|
1608
1608
|
return r.forEach((u) => {
|
|
1609
|
-
u.degree(s).isLeq(t) && n.forEach((
|
|
1610
|
-
u.degree(s).isNotEqual(
|
|
1609
|
+
u.degree(s).isLeq(t) && n.forEach((p) => {
|
|
1610
|
+
u.degree(s).isNotEqual(p.degree(s)) && (l.push(new C(u, p)), l.push(new C(u, p.clone().opposite())));
|
|
1611
1611
|
});
|
|
1612
1612
|
}), l;
|
|
1613
1613
|
});
|
|
1614
|
-
|
|
1615
|
-
for (const t of i(this,
|
|
1614
|
+
f(this, at, (e) => {
|
|
1615
|
+
for (const t of i(this, g))
|
|
1616
1616
|
t.coefficient.multiply(e);
|
|
1617
1617
|
return this.reduce();
|
|
1618
1618
|
});
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
for (const t of i(this,
|
|
1619
|
+
f(this, Tt, (e) => i(this, at).call(this, new c(e)));
|
|
1620
|
+
f(this, At, (e) => {
|
|
1621
|
+
for (const t of i(this, g))
|
|
1622
1622
|
t.multiply(e);
|
|
1623
1623
|
return this.reduce();
|
|
1624
1624
|
});
|
|
1625
|
-
|
|
1625
|
+
f(this, Mt, (e) => {
|
|
1626
1626
|
const t = [];
|
|
1627
|
-
for (const s of i(this,
|
|
1627
|
+
for (const s of i(this, g))
|
|
1628
1628
|
for (const r of e.monoms)
|
|
1629
|
-
t.push(
|
|
1630
|
-
return h(this,
|
|
1629
|
+
t.push(I.xMultiply(s, r));
|
|
1630
|
+
return h(this, g, t), this.reduce();
|
|
1631
1631
|
});
|
|
1632
|
-
|
|
1632
|
+
f(this, Ct, (e, t) => {
|
|
1633
1633
|
switch (t.tokenType) {
|
|
1634
|
-
case
|
|
1634
|
+
case d.COEFFICIENT:
|
|
1635
1635
|
e.push(new C(t.token));
|
|
1636
1636
|
break;
|
|
1637
|
-
case
|
|
1638
|
-
e.push(new C().add(new
|
|
1637
|
+
case d.VARIABLE:
|
|
1638
|
+
e.push(new C().add(new I(t.token)));
|
|
1639
1639
|
break;
|
|
1640
|
-
case
|
|
1640
|
+
case d.CONSTANT:
|
|
1641
1641
|
console.log("Actually, not supported - will be added later !");
|
|
1642
1642
|
break;
|
|
1643
|
-
case
|
|
1643
|
+
case d.OPERATION:
|
|
1644
1644
|
if (e.length >= 2) {
|
|
1645
1645
|
const s = e.pop(), r = e.pop();
|
|
1646
1646
|
if (r === void 0 || s === void 0)
|
|
@@ -1670,17 +1670,17 @@ const C = class C {
|
|
|
1670
1670
|
} else
|
|
1671
1671
|
throw new Error("Error parsing the polynom");
|
|
1672
1672
|
break;
|
|
1673
|
-
case
|
|
1673
|
+
case d.MONOM:
|
|
1674
1674
|
console.error("The monom token should not appear here");
|
|
1675
1675
|
break;
|
|
1676
|
-
case
|
|
1676
|
+
case d.FUNCTION:
|
|
1677
1677
|
console.error("The function token should not appear here - might be introduced later.");
|
|
1678
1678
|
break;
|
|
1679
1679
|
}
|
|
1680
1680
|
});
|
|
1681
|
-
|
|
1681
|
+
f(this, Ye, (e, t, s, r) => {
|
|
1682
1682
|
let n = "";
|
|
1683
|
-
for (const l of i(this,
|
|
1683
|
+
for (const l of i(this, g)) {
|
|
1684
1684
|
if (l.coefficient.value === 0)
|
|
1685
1685
|
continue;
|
|
1686
1686
|
let u;
|
|
@@ -1692,15 +1692,15 @@ const C = class C {
|
|
|
1692
1692
|
* Main parse using a shutting yard class
|
|
1693
1693
|
* @param inputStr
|
|
1694
1694
|
*/
|
|
1695
|
-
|
|
1696
|
-
const s = new
|
|
1695
|
+
f(this, $t, (e) => {
|
|
1696
|
+
const s = new ci().parse(e).rpn;
|
|
1697
1697
|
this.zero();
|
|
1698
1698
|
const r = [];
|
|
1699
1699
|
for (const n of s)
|
|
1700
|
-
i(this,
|
|
1700
|
+
i(this, Ct).call(this, r, n);
|
|
1701
1701
|
return r.length === 1 && this.add(r[0]), this.reorder();
|
|
1702
1702
|
});
|
|
1703
|
-
return h(this,
|
|
1703
|
+
return h(this, g, []), h(this, Ze, []), e !== void 0 && this.parse(e, ...t), this;
|
|
1704
1704
|
}
|
|
1705
1705
|
hasVariable(e) {
|
|
1706
1706
|
return this.variables.includes(e);
|
|
@@ -1708,10 +1708,10 @@ const C = class C {
|
|
|
1708
1708
|
inverse() {
|
|
1709
1709
|
}
|
|
1710
1710
|
isOne() {
|
|
1711
|
-
return i(this,
|
|
1711
|
+
return i(this, g).length === 1 && i(this, g)[0].coefficient.isOne();
|
|
1712
1712
|
}
|
|
1713
1713
|
isZero() {
|
|
1714
|
-
return i(this,
|
|
1714
|
+
return i(this, g).length === 1 && i(this, g)[0].coefficient.isZero() || i(this, g).length === 0;
|
|
1715
1715
|
}
|
|
1716
1716
|
root() {
|
|
1717
1717
|
throw new Error("Cannot take the root from a polynom");
|
|
@@ -1723,33 +1723,33 @@ const C = class C {
|
|
|
1723
1723
|
// #region Getters And Setters (22)
|
|
1724
1724
|
// ------------------------------------------
|
|
1725
1725
|
get display() {
|
|
1726
|
-
return i(this,
|
|
1726
|
+
return i(this, Ye).call(this);
|
|
1727
1727
|
}
|
|
1728
1728
|
get isMultiVariable() {
|
|
1729
|
-
return i(this,
|
|
1729
|
+
return i(this, g).some((e) => e.variables.length > 1);
|
|
1730
1730
|
}
|
|
1731
1731
|
get length() {
|
|
1732
|
-
return i(this,
|
|
1732
|
+
return i(this, g).length;
|
|
1733
1733
|
}
|
|
1734
1734
|
// ------------------------------------------
|
|
1735
1735
|
get monoms() {
|
|
1736
|
-
return i(this,
|
|
1736
|
+
return i(this, g);
|
|
1737
1737
|
}
|
|
1738
1738
|
set monoms(e) {
|
|
1739
|
-
h(this,
|
|
1739
|
+
h(this, g, e);
|
|
1740
1740
|
}
|
|
1741
1741
|
get numberOfVars() {
|
|
1742
1742
|
return this.variables.length;
|
|
1743
1743
|
}
|
|
1744
1744
|
get plotFunction() {
|
|
1745
|
-
return i(this,
|
|
1745
|
+
return i(this, Ye).call(this, "tex", !1, !1, !0);
|
|
1746
1746
|
}
|
|
1747
1747
|
get tex() {
|
|
1748
|
-
return i(this,
|
|
1748
|
+
return i(this, Ye).call(this, "tex");
|
|
1749
1749
|
}
|
|
1750
1750
|
get variables() {
|
|
1751
1751
|
let e = [];
|
|
1752
|
-
for (const t of i(this,
|
|
1752
|
+
for (const t of i(this, g))
|
|
1753
1753
|
e = e.concat(t.variables);
|
|
1754
1754
|
return e = [...new Set(e)], e.sort(), e;
|
|
1755
1755
|
}
|
|
@@ -1758,14 +1758,14 @@ const C = class C {
|
|
|
1758
1758
|
}
|
|
1759
1759
|
// #endregion Private methods (15)
|
|
1760
1760
|
};
|
|
1761
|
-
|
|
1761
|
+
Ze = new WeakMap(), g = new WeakMap(), Xe = new WeakMap(), ht = new WeakMap(), Et = new WeakMap(), Nt = new WeakMap(), Ot = new WeakMap(), qt = new WeakMap(), at = new WeakMap(), Tt = new WeakMap(), At = new WeakMap(), Mt = new WeakMap(), It = new WeakSet(), mi = function(e, ...t) {
|
|
1762
1762
|
if (t.length === 0) {
|
|
1763
1763
|
if (e = "" + e, e !== "" && !isNaN(Number(e))) {
|
|
1764
1764
|
this.empty();
|
|
1765
|
-
const s = new
|
|
1765
|
+
const s = new I(e);
|
|
1766
1766
|
return this.add(s), this;
|
|
1767
1767
|
}
|
|
1768
|
-
return i(this,
|
|
1768
|
+
return i(this, $t).call(this, e);
|
|
1769
1769
|
} else if (/^[a-z]+/.test(e)) {
|
|
1770
1770
|
this.empty();
|
|
1771
1771
|
const s = t.map((r) => new c(r));
|
|
@@ -1773,306 +1773,66 @@ ze = new WeakMap(), y = new WeakMap(), Fe = new WeakMap(), tt = new WeakMap(), m
|
|
|
1773
1773
|
const r = e.split("");
|
|
1774
1774
|
let n = 0;
|
|
1775
1775
|
for (const l of s) {
|
|
1776
|
-
const u = new
|
|
1776
|
+
const u = new I();
|
|
1777
1777
|
u.coefficient = l.clone(), u.literalStr = r[n] || "", this.add(u), n++;
|
|
1778
1778
|
}
|
|
1779
1779
|
} else {
|
|
1780
1780
|
let r = s.length - 1;
|
|
1781
1781
|
for (const n of s) {
|
|
1782
|
-
const l = new
|
|
1782
|
+
const l = new I();
|
|
1783
1783
|
l.coefficient = n.clone(), l.literalStr = `${e}^${r}`, this.add(l), r--;
|
|
1784
1784
|
}
|
|
1785
1785
|
}
|
|
1786
1786
|
return this;
|
|
1787
1787
|
} else
|
|
1788
1788
|
return this.zero();
|
|
1789
|
-
},
|
|
1790
|
-
let
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
const
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
});
|
|
1810
|
-
a(this, "create", (e, t, s) => (h(this, T, e), h(this, A, t), h(this, ie, i(this, Ue).call(this, s ?? "=")), this));
|
|
1811
|
-
a(this, "clone", () => new be(i(this, T).clone(), i(this, A).clone(), i(this, ie)));
|
|
1812
|
-
/**
|
|
1813
|
-
* Get the degree of the equation
|
|
1814
|
-
* @param letter
|
|
1815
|
-
*/
|
|
1816
|
-
a(this, "degree", (e) => c.max(i(this, T).degree(e), i(this, A).degree(e)));
|
|
1817
|
-
/**
|
|
1818
|
-
* divide an equation by a given value (transformed as a fraction)
|
|
1819
|
-
*
|
|
1820
|
-
* ```
|
|
1821
|
-
* 8x+10=6x \vert 2
|
|
1822
|
-
* 4x+5=3x
|
|
1823
|
-
* ```
|
|
1824
|
-
*
|
|
1825
|
-
* |>Alternatively with $3x-4$ maybe it's working ?
|
|
1826
|
-
* $$\frac{3x}{5}$$
|
|
1827
|
-
*
|
|
1828
|
-
* @param value
|
|
1829
|
-
* @returns {Equation}
|
|
1830
|
-
*/
|
|
1831
|
-
a(this, "divide", (e) => {
|
|
1832
|
-
const t = new c(e);
|
|
1833
|
-
return t.isZero() ? this : this.multiply(t.inverse());
|
|
1834
|
-
});
|
|
1835
|
-
/**
|
|
1836
|
-
* Determine if the equation contains a variable.
|
|
1837
|
-
* @param letter
|
|
1838
|
-
*/
|
|
1839
|
-
a(this, "hasVariable", (e) => this.variables.includes(e));
|
|
1840
|
-
a(this, "isLinearTo", (e) => {
|
|
1841
|
-
const t = e.clone().moveLeft().simplify().left, s = this.clone().moveLeft().simplify().left;
|
|
1842
|
-
return t.isEqual(s) || t.isOppositeAt(s);
|
|
1843
|
-
});
|
|
1844
|
-
/**
|
|
1845
|
-
* Determine if the equation contains more than one letter/variable.
|
|
1846
|
-
*/
|
|
1847
|
-
a(this, "isMultiVariable", () => i(this, T).isMultiVariable || i(this, A).isMultiVariable);
|
|
1848
|
-
// -----------------------------------------------
|
|
1849
|
-
// Equations helpers
|
|
1850
|
-
a(this, "isEqualTo", (e) => {
|
|
1851
|
-
const t = e.clone().moveLeft().left, s = this.clone().moveLeft().left;
|
|
1852
|
-
return t.isEqual(s) || t.isOppositeAt(s);
|
|
1853
|
-
});
|
|
1854
|
-
/**
|
|
1855
|
-
* Reorder the polynom to have only one letter on the left, the rest on the right.
|
|
1856
|
-
* @param letter
|
|
1857
|
-
*/
|
|
1858
|
-
a(this, "isolate", (e) => {
|
|
1859
|
-
if (!this.degree(e).isOne() || this.isMultiVariable())
|
|
1860
|
-
return !1;
|
|
1861
|
-
let t;
|
|
1862
|
-
i(this, T).subtract(i(this, A)), i(this, A).zero();
|
|
1863
|
-
const s = [...i(this, T).monoms];
|
|
1864
|
-
for (const n of s)
|
|
1865
|
-
n.hasVariable(e) || (t = n.clone(), i(this, T).subtract(t), i(this, A).subtract(t));
|
|
1866
|
-
if (i(this, T).length !== 1)
|
|
1867
|
-
return !1;
|
|
1868
|
-
const r = i(this, T).monoms[0].coefficient.clone();
|
|
1869
|
-
return i(this, T).divide(r), i(this, A).divide(r), this;
|
|
1870
|
-
});
|
|
1871
|
-
// -----------------------------------------------
|
|
1872
|
-
// Equations operations
|
|
1873
|
-
// -----------------------------------------------
|
|
1874
|
-
a(this, "letters", () => [.../* @__PURE__ */ new Set([...i(this, T).letters(), ...i(this, A).letters()])]);
|
|
1875
|
-
// -----------------------------------------------
|
|
1876
|
-
/**
|
|
1877
|
-
* Reorder will move all monoms containing a letter on the left, all the other on the right.
|
|
1878
|
-
*/
|
|
1879
|
-
a(this, "moveLeft", () => (i(this, T).subtract(i(this, A)), i(this, A).zero(), this));
|
|
1880
|
-
/**
|
|
1881
|
-
* Multiple an equation by a fraction value.
|
|
1882
|
-
* @param value
|
|
1883
|
-
*/
|
|
1884
|
-
a(this, "multiply", (e) => {
|
|
1885
|
-
const t = new c(e);
|
|
1886
|
-
return i(this, T).multiply(t), i(this, A).multiply(t), i(this, ie) !== "=" && t.sign() === -1 && i(this, At).call(this), this;
|
|
1887
|
-
});
|
|
1888
|
-
a(this, "opposite", () => (h(this, T, i(this, T).opposite()), h(this, A, i(this, A).opposite()), this));
|
|
1889
|
-
a(this, "reorder", (e) => (i(this, T).subtract(i(this, A)), i(this, A).zero(), i(this, T).reorder(), e ? this : (i(this, T).monoms.filter((t) => t.degree().isZero()).forEach((t) => {
|
|
1890
|
-
const s = t.clone();
|
|
1891
|
-
i(this, T).subtract(s), i(this, A).subtract(s);
|
|
1892
|
-
}), i(this, T).reorder(), i(this, A).reorder(), this)));
|
|
1893
|
-
// ------------------------------------------
|
|
1894
|
-
a(this, "replaceBy", (e, t) => (i(this, T).replaceBy(e, t), i(this, A).replaceBy(e, t), this));
|
|
1895
|
-
/**
|
|
1896
|
-
* Multiply by the lcm denominator and divide by the gcm numerators.
|
|
1897
|
-
*/
|
|
1898
|
-
a(this, "simplify", () => (this.multiply(j.lcm(...i(this, T).getDenominators(), ...i(this, A).getDenominators())), this.divide(j.gcd(...i(this, T).getNumerators(), ...i(this, A).getNumerators())), this));
|
|
1899
|
-
// -----------------------------------------------
|
|
1900
|
-
a(this, "solve", () => new ct(this.clone()).solve());
|
|
1901
|
-
a(this, "test", (e) => this.left.evaluate(e).isEqual(this.right.evaluate(e)));
|
|
1902
|
-
// #endregion Getters And Setters (13)
|
|
1903
|
-
// #region Private methods (6)
|
|
1904
|
-
d(this, Tt, (e) => {
|
|
1905
|
-
if (e.includes("geq"))
|
|
1906
|
-
return e.includes("\\geq") ? "\\geq" : "geq";
|
|
1907
|
-
if (e.includes("leq"))
|
|
1908
|
-
return e.includes("\\leq") ? "\\leq" : "leq";
|
|
1909
|
-
if (e.includes(">="))
|
|
1910
|
-
return ">=";
|
|
1911
|
-
if (e.includes("=>"))
|
|
1912
|
-
return "=>";
|
|
1913
|
-
if (e.includes(">"))
|
|
1914
|
-
return ">";
|
|
1915
|
-
if (e.includes("<="))
|
|
1916
|
-
return "<=";
|
|
1917
|
-
if (e.includes("=<"))
|
|
1918
|
-
return "=<";
|
|
1919
|
-
if (e.includes("<"))
|
|
1920
|
-
return "<";
|
|
1921
|
-
if (e.includes("="))
|
|
1922
|
-
return "=";
|
|
1923
|
-
throw new Error("The equation is not valid (no sign found)");
|
|
1924
|
-
});
|
|
1925
|
-
// -----------------------------------------------
|
|
1926
|
-
// Equations solving algorithms
|
|
1927
|
-
d(this, Ue, (e) => e === void 0 ? "=" : e.includes("geq") || e.includes(">=") || e.includes("=>") ? ">=" : e.includes(">") ? ">" : e.includes("leq") || e.includes("<=") || e.includes("=<") ? "<=" : e.includes("<") ? "<" : "=");
|
|
1928
|
-
d(this, At, () => i(this, ie) === "=" ? this : i(this, ie).includes("<") ? (i(this, ie).replace("<", ">"), this) : i(this, ie).includes(">") ? (i(this, ie).replace(">", "<"), this) : this);
|
|
1929
|
-
if (h(this, T, new I().zero()), h(this, A, new I().zero()), h(this, ie, "="), e !== void 0 && t === void 0) {
|
|
1930
|
-
if (e instanceof be)
|
|
1931
|
-
return e.clone();
|
|
1932
|
-
typeof e == "string" && this.parse(e);
|
|
1933
|
-
} else e !== void 0 && t !== void 0 && (this.left = new I(e), this.right = new I(t));
|
|
1934
|
-
return s !== void 0 && (this.sign = s), this;
|
|
1789
|
+
}, Ct = new WeakMap(), Ye = new WeakMap(), $t = new WeakMap();
|
|
1790
|
+
let T = C;
|
|
1791
|
+
function ni(o, e = !0) {
|
|
1792
|
+
return e ? `\\left( ${o} \\right)` : `(${o})`;
|
|
1793
|
+
}
|
|
1794
|
+
var Ee, Qe, Ne, Oe;
|
|
1795
|
+
const we = class we {
|
|
1796
|
+
constructor(e, t) {
|
|
1797
|
+
f(this, Ee);
|
|
1798
|
+
f(this, Qe, !1);
|
|
1799
|
+
f(this, Ne);
|
|
1800
|
+
f(this, Oe);
|
|
1801
|
+
if (e instanceof we)
|
|
1802
|
+
h(this, Ne, e.polynom.clone()), h(this, Oe, e.power.clone());
|
|
1803
|
+
else if (typeof e == "string" && t === void 0) {
|
|
1804
|
+
const [s, r = "1"] = e.split("^");
|
|
1805
|
+
h(this, Ne, new T(s)), h(this, Oe, new c(r.replace("(", "").replace(")", "")));
|
|
1806
|
+
} else
|
|
1807
|
+
h(this, Ne, new T(e)), h(this, Oe, new c(t ?? 1));
|
|
1808
|
+
return h(this, Ee, 1), this;
|
|
1935
1809
|
}
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
* if value is an equation, add the left part to the left part of the equation
|
|
1939
|
-
* and the right part to the right part of the equation
|
|
1940
|
-
* if value is a string, try to create an equation
|
|
1941
|
-
* if it fails, create a polynom and add it to the left and right part of the equation
|
|
1942
|
-
* @param value | Polynom | Monom | Fraction | string | monom
|
|
1943
|
-
*/
|
|
1944
|
-
add(e) {
|
|
1945
|
-
if (e instanceof be)
|
|
1946
|
-
return i(this, T).add(e.left), i(this, A).add(e.right), this;
|
|
1947
|
-
if (typeof e == "string" && !be.isEquationString(e))
|
|
1948
|
-
return this.add(new be(e));
|
|
1949
|
-
const t = new I(e);
|
|
1950
|
-
return i(this, T).add(t), i(this, A).add(t), this;
|
|
1951
|
-
}
|
|
1952
|
-
/**
|
|
1953
|
-
* Create an Equation using two polynoms.
|
|
1954
|
-
* Markdown *support* is cool
|
|
1955
|
-
* @param values
|
|
1956
|
-
* @param asNumeric
|
|
1957
|
-
*/
|
|
1958
|
-
evaluate(e, t) {
|
|
1959
|
-
const s = i(this, T).evaluate(e, t), r = i(this, A).evaluate(e, t);
|
|
1960
|
-
return t ? s === r : s.isEqual(r);
|
|
1961
|
-
}
|
|
1962
|
-
isEqual(e) {
|
|
1963
|
-
const t = new be(e);
|
|
1964
|
-
return t.left.isEqual(i(this, T)) && t.right.isEqual(i(this, A));
|
|
1965
|
-
}
|
|
1966
|
-
pow(e) {
|
|
1967
|
-
return i(this, T).pow(e), i(this, A).pow(e), this;
|
|
1968
|
-
}
|
|
1969
|
-
reduce() {
|
|
1970
|
-
return this.moveLeft(), i(this, T).reduce(), this.simplify(), i(this, T).monoms[0].coefficient.isNegative() && this.multiply(-1), this;
|
|
1971
|
-
}
|
|
1972
|
-
split() {
|
|
1973
|
-
return [i(this, T).clone(), i(this, A).clone()];
|
|
1974
|
-
}
|
|
1975
|
-
subtract(e) {
|
|
1976
|
-
if (e instanceof be)
|
|
1977
|
-
return i(this, T).subtract(e.left), i(this, A).subtract(e.right), this;
|
|
1978
|
-
if (typeof e == "string" && !be.isEquationString(e))
|
|
1979
|
-
return this.subtract(new be(e));
|
|
1980
|
-
const t = new I(e);
|
|
1981
|
-
return i(this, T).subtract(t), i(this, A).subtract(t), this;
|
|
1982
|
-
}
|
|
1983
|
-
static isEquationString(e) {
|
|
1984
|
-
return e.includes("=") || e.includes("<") || e.includes(">") || e.includes("<=") || e.includes(">=");
|
|
1985
|
-
}
|
|
1986
|
-
static makeSolutionsUnique(e, t) {
|
|
1987
|
-
const s = [], r = e.filter((n) => s.includes(n.tex) ? !1 : (s.push(n.tex), !0));
|
|
1988
|
-
return t === !0 && r.sort((n, l) => n.value - l.value), r;
|
|
1989
|
-
}
|
|
1990
|
-
// #endregion Properties and methods (26)
|
|
1991
|
-
// #region Getters And Setters (13)
|
|
1992
|
-
get display() {
|
|
1993
|
-
return `${i(this, T).display}${this.signAsTex}${i(this, A).display}`;
|
|
1994
|
-
}
|
|
1995
|
-
// Getter and setter
|
|
1996
|
-
get left() {
|
|
1997
|
-
return i(this, T);
|
|
1998
|
-
}
|
|
1999
|
-
set left(e) {
|
|
2000
|
-
h(this, T, e);
|
|
2001
|
-
}
|
|
2002
|
-
get numberOfVars() {
|
|
2003
|
-
return this.variables.length;
|
|
2004
|
-
}
|
|
2005
|
-
get right() {
|
|
2006
|
-
return i(this, A);
|
|
2007
|
-
}
|
|
2008
|
-
set right(e) {
|
|
2009
|
-
h(this, A, e);
|
|
2010
|
-
}
|
|
2011
|
-
// ------------------------------------------
|
|
2012
|
-
get sign() {
|
|
2013
|
-
return i(this, ie);
|
|
2014
|
-
}
|
|
2015
|
-
set sign(e) {
|
|
2016
|
-
h(this, ie, i(this, Ue).call(this, e));
|
|
2017
|
-
}
|
|
2018
|
-
get signAsTex() {
|
|
2019
|
-
return i(this, ie) === ">=" ? "\\geq" : i(this, ie) === "<=" ? "\\leq" : i(this, ie);
|
|
2020
|
-
}
|
|
2021
|
-
get tex() {
|
|
2022
|
-
return `${i(this, T).tex}${this.signAsTex}${i(this, A).tex}`;
|
|
2023
|
-
}
|
|
2024
|
-
get variables() {
|
|
2025
|
-
return [...new Set(i(this, A).variables.concat(i(this, T).variables))];
|
|
2026
|
-
}
|
|
2027
|
-
// #endregion Private methods (6)
|
|
2028
|
-
};
|
|
2029
|
-
T = new WeakMap(), A = new WeakMap(), ie = new WeakMap(), Tt = new WeakMap(), Ue = new WeakMap(), At = new WeakMap();
|
|
2030
|
-
let ce = be;
|
|
2031
|
-
function Xt(o, e = !0) {
|
|
2032
|
-
return e ? `\\left( ${o} \\right)` : `(${o})`;
|
|
2033
|
-
}
|
|
2034
|
-
var xe, Ge, Ee, Ne;
|
|
2035
|
-
const ge = class ge {
|
|
2036
|
-
constructor(e, t) {
|
|
2037
|
-
d(this, xe);
|
|
2038
|
-
d(this, Ge, !1);
|
|
2039
|
-
d(this, Ee);
|
|
2040
|
-
d(this, Ne);
|
|
2041
|
-
if (e instanceof ge)
|
|
2042
|
-
h(this, Ee, e.polynom.clone()), h(this, Ne, e.power.clone());
|
|
2043
|
-
else if (typeof e == "string" && t === void 0) {
|
|
2044
|
-
const [s, r = "1"] = e.split("^");
|
|
2045
|
-
h(this, Ee, new I(s)), h(this, Ne, new c(r.replace("(", "").replace(")", "")));
|
|
2046
|
-
} else
|
|
2047
|
-
h(this, Ee, new I(e)), h(this, Ne, new c(t ?? 1));
|
|
2048
|
-
return h(this, xe, 1), this;
|
|
2049
|
-
}
|
|
2050
|
-
parse() {
|
|
2051
|
-
throw new Error("Method not implemented.");
|
|
1810
|
+
parse() {
|
|
1811
|
+
throw new Error("Method not implemented.");
|
|
2052
1812
|
}
|
|
2053
1813
|
clone() {
|
|
2054
|
-
return new
|
|
1814
|
+
return new we(this);
|
|
2055
1815
|
}
|
|
2056
1816
|
add() {
|
|
2057
1817
|
throw new Error("Adding two factors is not possible");
|
|
2058
1818
|
}
|
|
2059
1819
|
get withPower() {
|
|
2060
|
-
return h(this,
|
|
1820
|
+
return h(this, Ee, 1), this;
|
|
2061
1821
|
}
|
|
2062
1822
|
get withRoot() {
|
|
2063
|
-
return h(this,
|
|
1823
|
+
return h(this, Ee, 0), this;
|
|
2064
1824
|
}
|
|
2065
1825
|
get asSingle() {
|
|
2066
|
-
return h(this,
|
|
1826
|
+
return h(this, Qe, !0), this;
|
|
2067
1827
|
}
|
|
2068
1828
|
degree(e) {
|
|
2069
1829
|
return this.polynom.degree(e).multiply(this.power);
|
|
2070
1830
|
}
|
|
2071
1831
|
derivative() {
|
|
2072
|
-
return this.power.isZero() ? [new
|
|
2073
|
-
new
|
|
2074
|
-
new
|
|
2075
|
-
new
|
|
1832
|
+
return this.power.isZero() ? [new we("0", "1")] : this.power.isOne() ? [new we(this.polynom.clone().derivative())] : [
|
|
1833
|
+
new we(this.power.clone()),
|
|
1834
|
+
new we(this.polynom.clone().derivative()),
|
|
1835
|
+
new we(this.polynom.clone(), this.power.clone().subtract(1))
|
|
2076
1836
|
];
|
|
2077
1837
|
}
|
|
2078
1838
|
develop() {
|
|
@@ -2083,12 +1843,12 @@ const ge = class ge {
|
|
|
2083
1843
|
get display() {
|
|
2084
1844
|
const e = this.power.numerator, t = this.power.denominator;
|
|
2085
1845
|
let s, r;
|
|
2086
|
-
return i(this,
|
|
1846
|
+
return i(this, Ee) === 0 && t > 1 ? (s = `${t === 2 ? "sqrt" : `root(${t})`}(${this.polynom.display})`, r = Math.abs(e) === 1 ? "" : `^(${Math.abs(e)})`) : (s = i(this, Qe) && this.power.isOne() ? this.polynom.display : ni(this.polynom.display, !1), r = t === 1 && Math.abs(e) === 1 ? "" : `^(${this.power.display})`), s = `${s}${r}`, i(this, Ee) === 0 && e < 0 && (s = `1/(${s})`), s;
|
|
2087
1847
|
}
|
|
2088
1848
|
divide(e) {
|
|
2089
|
-
if (e instanceof
|
|
1849
|
+
if (e instanceof we && this.isSameAs(e))
|
|
2090
1850
|
return this.power.subtract(e.power), this;
|
|
2091
|
-
const t = new
|
|
1851
|
+
const t = new T(e);
|
|
2092
1852
|
if (this.isSameAs(t))
|
|
2093
1853
|
return this.power.subtract(1), this;
|
|
2094
1854
|
throw new Error("The two factors must be the same");
|
|
@@ -2110,39 +1870,39 @@ const ge = class ge {
|
|
|
2110
1870
|
}
|
|
2111
1871
|
isSameAs(e) {
|
|
2112
1872
|
let t;
|
|
2113
|
-
return e instanceof
|
|
1873
|
+
return e instanceof we ? t = e.polynom : e instanceof T ? t = e : t = new T(e), this.polynom.isEqual(t);
|
|
2114
1874
|
}
|
|
2115
1875
|
isZero() {
|
|
2116
1876
|
return this.polynom.isZero();
|
|
2117
1877
|
}
|
|
2118
1878
|
multiply(e) {
|
|
2119
|
-
if (e instanceof
|
|
1879
|
+
if (e instanceof we && this.isSameAs(e))
|
|
2120
1880
|
return this.power.add(e.power), this;
|
|
2121
|
-
const t = new
|
|
1881
|
+
const t = new T(e);
|
|
2122
1882
|
if (this.isSameAs(t))
|
|
2123
1883
|
return this.power.add(1), this;
|
|
2124
1884
|
throw new Error("The two factors must be the same");
|
|
2125
1885
|
}
|
|
2126
1886
|
one() {
|
|
2127
|
-
return i(this,
|
|
1887
|
+
return i(this, Ne).one(), i(this, Oe).one(), this;
|
|
2128
1888
|
}
|
|
2129
1889
|
opposite() {
|
|
2130
1890
|
throw new Error("Method not implemented.");
|
|
2131
1891
|
}
|
|
2132
1892
|
get polynom() {
|
|
2133
|
-
return i(this,
|
|
1893
|
+
return i(this, Ne);
|
|
2134
1894
|
}
|
|
2135
1895
|
set polynom(e) {
|
|
2136
|
-
h(this,
|
|
1896
|
+
h(this, Ne, e);
|
|
2137
1897
|
}
|
|
2138
1898
|
pow(e) {
|
|
2139
1899
|
return this.power.multiply(e), this;
|
|
2140
1900
|
}
|
|
2141
1901
|
get power() {
|
|
2142
|
-
return i(this,
|
|
1902
|
+
return i(this, Oe);
|
|
2143
1903
|
}
|
|
2144
1904
|
set power(e) {
|
|
2145
|
-
h(this,
|
|
1905
|
+
h(this, Oe, new c(e));
|
|
2146
1906
|
}
|
|
2147
1907
|
primitive() {
|
|
2148
1908
|
throw new Error("Method not implemented.");
|
|
@@ -2162,207 +1922,620 @@ const ge = class ge {
|
|
|
2162
1922
|
get tex() {
|
|
2163
1923
|
const e = this.power.numerator, t = this.power.denominator;
|
|
2164
1924
|
let s, r;
|
|
2165
|
-
return i(this,
|
|
1925
|
+
return i(this, Ee) === 0 && t > 1 ? (s = `\\sqrt${t === 2 ? "" : `[ ${t} ]`}{ ${this.polynom.tex} }`, r = Math.abs(e) === 1 ? "" : `^{ ${Math.abs(e)} }`) : (s = i(this, Qe) && this.power.isOne() ? this.polynom.tex : ni(this.polynom.tex), r = t === 1 && Math.abs(e) === 1 ? "" : `^{ ${this.power.tex} }`), s = `${s}${r}`, i(this, Ee) === 0 && e < 0 && (s = `\\frac{ 1 }{ ${s} }`), s;
|
|
2166
1926
|
}
|
|
2167
1927
|
get variables() {
|
|
2168
1928
|
return this.polynom.variables;
|
|
2169
1929
|
}
|
|
2170
1930
|
zero() {
|
|
2171
|
-
return i(this,
|
|
1931
|
+
return i(this, Ne).zero(), i(this, Oe).one(), this;
|
|
2172
1932
|
}
|
|
2173
1933
|
};
|
|
2174
|
-
|
|
2175
|
-
let
|
|
2176
|
-
var
|
|
2177
|
-
const
|
|
1934
|
+
Ee = new WeakMap(), Qe = new WeakMap(), Ne = new WeakMap(), Oe = new WeakMap();
|
|
1935
|
+
let fe = we;
|
|
1936
|
+
var Ue = /* @__PURE__ */ ((o) => (o[o.ROOT = 0] = "ROOT", o[o.POWER = 1] = "POWER", o))(Ue || {}), N, Ve, lt, Yt;
|
|
1937
|
+
const me = class me {
|
|
2178
1938
|
// #endregion Class fields (1)
|
|
2179
1939
|
// #region Constructors (1)
|
|
2180
1940
|
constructor(...e) {
|
|
2181
1941
|
// #region Class fields (1)
|
|
2182
|
-
|
|
2183
|
-
|
|
1942
|
+
f(this, N, []);
|
|
1943
|
+
f(this, Ve, Ue.POWER);
|
|
2184
1944
|
return this.parse(...e), this;
|
|
2185
1945
|
}
|
|
2186
1946
|
// #endregion Constructors (1)
|
|
2187
1947
|
// #region Properties and methods (25)
|
|
2188
1948
|
parse(...e) {
|
|
2189
|
-
return e.length === 0 ? this : (h(this,
|
|
1949
|
+
return e.length === 0 ? this : (h(this, N, []), e.forEach((t) => {
|
|
2190
1950
|
if (typeof t == "string") {
|
|
2191
1951
|
const s = t.split(")(").join(")*(").split("*");
|
|
2192
|
-
i(this,
|
|
2193
|
-
} else t instanceof
|
|
1952
|
+
i(this, N).push(...s.map((r) => new fe(r)));
|
|
1953
|
+
} else t instanceof me ? i(this, N).push(...t.factors.map((s) => s.clone())) : i(this, N).push(new fe(t));
|
|
2194
1954
|
}), this);
|
|
2195
1955
|
}
|
|
2196
1956
|
clone() {
|
|
2197
|
-
return new
|
|
1957
|
+
return new me(...i(this, N).map((e) => e.clone()));
|
|
2198
1958
|
}
|
|
2199
1959
|
add(...e) {
|
|
2200
1960
|
let t = [this, ...e];
|
|
2201
|
-
const s =
|
|
1961
|
+
const s = me.gcd(...t);
|
|
2202
1962
|
t = t.map((n) => n.divide(s).reduce());
|
|
2203
|
-
const r = new
|
|
2204
|
-
return t.forEach((n) => r.add(n.develop())), h(this,
|
|
1963
|
+
const r = new T("0");
|
|
1964
|
+
return t.forEach((n) => r.add(n.develop())), h(this, N, [
|
|
2205
1965
|
...s.factors,
|
|
2206
|
-
new
|
|
1966
|
+
new fe(r)
|
|
2207
1967
|
]), this;
|
|
2208
1968
|
}
|
|
2209
1969
|
degree(e) {
|
|
2210
|
-
return i(this,
|
|
1970
|
+
return i(this, N).reduce((t, s) => t.add(s.degree(e)), new c("0"));
|
|
2211
1971
|
}
|
|
2212
1972
|
derivative() {
|
|
2213
|
-
const e = [], t = i(this,
|
|
1973
|
+
const e = [], t = i(this, N).length;
|
|
2214
1974
|
for (let r = 0; r < t; r++) {
|
|
2215
|
-
const n = i(this,
|
|
2216
|
-
e.push(new
|
|
1975
|
+
const n = i(this, N).slice(), l = n.splice(r, 1)[0];
|
|
1976
|
+
e.push(new me(...n).multiply(new me(...l.derivative())));
|
|
2217
1977
|
}
|
|
2218
1978
|
e.forEach((r) => r.reduce());
|
|
2219
1979
|
const s = e.shift();
|
|
2220
|
-
return s !== void 0 && h(this,
|
|
1980
|
+
return s !== void 0 && h(this, N, s.factors), this.add(...e);
|
|
2221
1981
|
}
|
|
2222
1982
|
develop() {
|
|
2223
|
-
const e = new
|
|
2224
|
-
return i(this,
|
|
1983
|
+
const e = new T("1");
|
|
1984
|
+
return i(this, N).forEach((t) => {
|
|
2225
1985
|
e.multiply(t.develop());
|
|
2226
1986
|
}), e;
|
|
2227
1987
|
}
|
|
2228
1988
|
divide(e) {
|
|
2229
|
-
return h(this,
|
|
1989
|
+
return h(this, N, i(this, N).concat(e.clone().factors.map((t) => t.inverse()))), this;
|
|
2230
1990
|
}
|
|
2231
1991
|
evaluate(e, t) {
|
|
2232
|
-
return t ? i(this,
|
|
1992
|
+
return t ? i(this, N).reduce((s, r) => s * r.evaluate(e, t), 1) : i(this, N).reduce((s, r) => s.multiply(r.evaluate(e)), new c("1"));
|
|
2233
1993
|
}
|
|
2234
1994
|
hasVariable(e) {
|
|
2235
|
-
return i(this,
|
|
1995
|
+
return i(this, N).some((t) => t.hasVariable(e));
|
|
2236
1996
|
}
|
|
2237
1997
|
inverse() {
|
|
2238
|
-
return h(this,
|
|
1998
|
+
return h(this, N, i(this, N).map((e) => e.inverse())), this;
|
|
2239
1999
|
}
|
|
2240
2000
|
isEqual(e) {
|
|
2241
|
-
const t =
|
|
2001
|
+
const t = me.gcd(this, e), s = this.clone().divide(t).reduce(), r = e.clone().divide(t).reduce();
|
|
2242
2002
|
return s.isOne() && r.isOne();
|
|
2243
2003
|
}
|
|
2244
2004
|
isOne() {
|
|
2245
|
-
return i(this,
|
|
2005
|
+
return i(this, N).every((e) => e.isOne());
|
|
2246
2006
|
}
|
|
2247
2007
|
isZero() {
|
|
2248
|
-
return i(this,
|
|
2008
|
+
return i(this, N).every((e) => e.isZero());
|
|
2249
2009
|
}
|
|
2250
2010
|
multiply(...e) {
|
|
2251
2011
|
return e.forEach((t) => {
|
|
2252
|
-
h(this,
|
|
2012
|
+
h(this, N, i(this, N).concat(t.clone().factors));
|
|
2253
2013
|
}), this;
|
|
2254
2014
|
}
|
|
2255
2015
|
one() {
|
|
2256
|
-
return h(this,
|
|
2016
|
+
return h(this, N, [new fe("1", "1")]), this;
|
|
2257
2017
|
}
|
|
2258
2018
|
opposite() {
|
|
2259
|
-
const e = i(this,
|
|
2260
|
-
return e >= 0 ? i(this,
|
|
2019
|
+
const e = i(this, N).findIndex((t) => t.display === "(-1)");
|
|
2020
|
+
return e >= 0 ? i(this, N).splice(e, 1) : i(this, N).push(new fe("-1", "1")), this;
|
|
2261
2021
|
}
|
|
2262
2022
|
pow(e) {
|
|
2263
|
-
return h(this,
|
|
2023
|
+
return h(this, N, i(this, N).map((t) => t.pow(e))), this;
|
|
2264
2024
|
}
|
|
2265
2025
|
primitive() {
|
|
2266
2026
|
throw new Error("Method not implemented.");
|
|
2267
2027
|
}
|
|
2268
2028
|
reduce() {
|
|
2269
|
-
const e =
|
|
2270
|
-
return h(this,
|
|
2029
|
+
const e = Wt(this);
|
|
2030
|
+
return h(this, N, Object.values(e).map((t) => {
|
|
2271
2031
|
const s = t[0].polynom, r = t.reduce((n, l) => n.add(l.power), new c("0"));
|
|
2272
|
-
return new
|
|
2032
|
+
return new fe(s, r.reduce());
|
|
2273
2033
|
}).filter((t) => !t.power.isZero())), this;
|
|
2274
2034
|
}
|
|
2275
2035
|
root(e) {
|
|
2276
|
-
return h(this,
|
|
2036
|
+
return h(this, N, i(this, N).map((t) => t.root(e))), this;
|
|
2277
2037
|
}
|
|
2278
2038
|
sort() {
|
|
2279
|
-
return h(this,
|
|
2039
|
+
return h(this, N, i(this, N).sort((e, t) => e.degree().isLeq(t.degree()) ? -1 : 1)), this;
|
|
2280
2040
|
}
|
|
2281
2041
|
sqrt() {
|
|
2282
|
-
return h(this,
|
|
2042
|
+
return h(this, N, i(this, N).map((e) => e.sqrt())), this;
|
|
2283
2043
|
}
|
|
2284
2044
|
subtract(...e) {
|
|
2285
2045
|
return this.add(...e.map((t) => t.opposite()));
|
|
2286
2046
|
}
|
|
2287
2047
|
zero() {
|
|
2288
|
-
return h(this,
|
|
2048
|
+
return h(this, N, [new fe("0", "1")]), this;
|
|
2289
2049
|
}
|
|
2290
2050
|
static gcd(...e) {
|
|
2291
2051
|
var s;
|
|
2292
2052
|
if (e.length === 0)
|
|
2293
|
-
return new
|
|
2053
|
+
return new me().one();
|
|
2294
2054
|
if (e.length === 1)
|
|
2295
2055
|
return e[0];
|
|
2296
2056
|
if (e.length === 2)
|
|
2297
|
-
return
|
|
2057
|
+
return M(s = me, lt, Yt).call(s, e[0], e[1]);
|
|
2298
2058
|
let t = e[0];
|
|
2299
2059
|
return e.shift(), e.forEach((r) => {
|
|
2300
2060
|
var n;
|
|
2301
|
-
return t =
|
|
2061
|
+
return t = M(n = me, lt, Yt).call(n, t, r);
|
|
2302
2062
|
}), t;
|
|
2303
2063
|
}
|
|
2304
2064
|
// #endregion Properties and methods (25)
|
|
2305
2065
|
// #region Getters And Setters (5)
|
|
2306
2066
|
get factors() {
|
|
2307
|
-
return i(this,
|
|
2067
|
+
return i(this, N);
|
|
2308
2068
|
}
|
|
2309
2069
|
set factors(e) {
|
|
2310
|
-
h(this,
|
|
2070
|
+
h(this, N, e);
|
|
2311
2071
|
}
|
|
2312
2072
|
get variables() {
|
|
2313
|
-
return i(this,
|
|
2073
|
+
return i(this, N).reduce((e, t) => e.concat(t.variables), []);
|
|
2314
2074
|
}
|
|
2315
2075
|
get asRoot() {
|
|
2316
|
-
return h(this,
|
|
2076
|
+
return h(this, Ve, Ue.ROOT), this;
|
|
2317
2077
|
}
|
|
2318
2078
|
get asPower() {
|
|
2319
|
-
return h(this,
|
|
2079
|
+
return h(this, Ve, Ue.POWER), this;
|
|
2320
2080
|
}
|
|
2321
2081
|
get numerator() {
|
|
2322
|
-
return i(this,
|
|
2082
|
+
return i(this, N).filter((e) => e.power.isPositive());
|
|
2323
2083
|
}
|
|
2324
2084
|
get denominator() {
|
|
2325
|
-
return i(this,
|
|
2085
|
+
return i(this, N).filter((e) => e.power.isNegative());
|
|
2086
|
+
}
|
|
2087
|
+
get display() {
|
|
2088
|
+
let e = [], t = [];
|
|
2089
|
+
if (i(this, Ve) === Ue.ROOT ? (e = this.numerator, t = this.denominator.map((n) => n.clone().inverse())) : e = i(this, N), e.length === 0 && (e = [new fe("1")]), t.length === 0)
|
|
2090
|
+
return e.length === 1 ? e[0].asSingle.display : e.map((n) => n.display).join("");
|
|
2091
|
+
const s = e.length === 1 ? e[0].asSingle.display : e.map((n) => n.display).join(""), r = t.length === 1 ? t[0].asSingle.display : t.map((n) => n.display).join("");
|
|
2092
|
+
return `(${s})/(${r})`;
|
|
2093
|
+
}
|
|
2094
|
+
get tex() {
|
|
2095
|
+
let e = [], t = [];
|
|
2096
|
+
if (i(this, Ve) === Ue.ROOT ? (e = this.numerator, t = this.denominator.map((n) => n.clone().inverse())) : e = i(this, N), e.length === 0 && (e = [new fe("1")]), t.length === 0)
|
|
2097
|
+
return e.length === 1 ? e[0].asSingle.tex : e.map((n) => n.tex).join("");
|
|
2098
|
+
const s = e.length === 1 ? e[0].asSingle.tex : e.map((n) => n.tex).join(""), r = t.length === 1 ? t[0].asSingle.tex : t.map((n) => n.tex).join("");
|
|
2099
|
+
return `\\frac{ ${s} }{ ${r} }`;
|
|
2100
|
+
}
|
|
2101
|
+
// #endregion Private methods (1)
|
|
2102
|
+
};
|
|
2103
|
+
N = new WeakMap(), Ve = new WeakMap(), lt = new WeakSet(), Yt = function(e, t) {
|
|
2104
|
+
const s = Wt(e), r = Wt(t), l = Object.keys(s).filter((u) => Object.hasOwn(r, u)).map((u) => {
|
|
2105
|
+
const p = s[u].reduce((y, E) => y.add(E.power), new c("0")), m = r[u].reduce((y, E) => y.add(E.power), new c("0"));
|
|
2106
|
+
return new fe(u, c.min(p, m));
|
|
2107
|
+
});
|
|
2108
|
+
return new me(...l);
|
|
2109
|
+
}, f(me, lt);
|
|
2110
|
+
let Xt = me;
|
|
2111
|
+
function Wt(o) {
|
|
2112
|
+
const e = new c().one(), t = o.factors.reduce((s, r) => {
|
|
2113
|
+
if (r.polynom.degree().isZero())
|
|
2114
|
+
return r.polynom.monoms.length > 0 && e.multiply(r.polynom.monoms[0].coefficient), s;
|
|
2115
|
+
const n = r.polynom.display;
|
|
2116
|
+
return Object.hasOwn(s, n) ? s[n].push(r) : s[n] = [r], s;
|
|
2117
|
+
}, {});
|
|
2118
|
+
return e.isOne() || (t[e.display] = [new fe(e.display, 1)]), t;
|
|
2119
|
+
}
|
|
2120
|
+
var q, A, re, Bt, Ke, Pt;
|
|
2121
|
+
const xe = class xe {
|
|
2122
|
+
constructor(e, t, s) {
|
|
2123
|
+
// Left part of the equation
|
|
2124
|
+
f(this, q);
|
|
2125
|
+
// Right part of the equation
|
|
2126
|
+
f(this, A);
|
|
2127
|
+
// Signe of the equation
|
|
2128
|
+
f(this, re);
|
|
2129
|
+
// #endregion Constructors (3)
|
|
2130
|
+
// #region Properties and methods (26)
|
|
2131
|
+
// ------------------------------------------
|
|
2132
|
+
a(this, "parse", (e) => {
|
|
2133
|
+
const t = i(this, Bt).call(this, e);
|
|
2134
|
+
if (t === !1)
|
|
2135
|
+
throw new Error("The equation is not valid (no sign found)");
|
|
2136
|
+
const s = e.split(t);
|
|
2137
|
+
return this.create(new T(s[0]), new T(s[1]), i(this, Ke).call(this, t));
|
|
2138
|
+
});
|
|
2139
|
+
a(this, "create", (e, t, s) => (h(this, q, e), h(this, A, t), h(this, re, i(this, Ke).call(this, s ?? "=")), this));
|
|
2140
|
+
a(this, "clone", () => new xe(i(this, q).clone(), i(this, A).clone(), i(this, re)));
|
|
2141
|
+
/**
|
|
2142
|
+
* Get the degree of the equation
|
|
2143
|
+
* @param letter
|
|
2144
|
+
*/
|
|
2145
|
+
a(this, "degree", (e) => c.max(i(this, q).degree(e), i(this, A).degree(e)));
|
|
2146
|
+
/**
|
|
2147
|
+
* divide an equation by a given value (transformed as a fraction)
|
|
2148
|
+
*
|
|
2149
|
+
* ```
|
|
2150
|
+
* 8x+10=6x \vert 2
|
|
2151
|
+
* 4x+5=3x
|
|
2152
|
+
* ```
|
|
2153
|
+
*
|
|
2154
|
+
* |>Alternatively with $3x-4$ maybe it's working ?
|
|
2155
|
+
* $$\frac{3x}{5}$$
|
|
2156
|
+
*
|
|
2157
|
+
* @param value
|
|
2158
|
+
* @returns {Equation}
|
|
2159
|
+
*/
|
|
2160
|
+
a(this, "divide", (e) => {
|
|
2161
|
+
const t = new c(e);
|
|
2162
|
+
return t.isZero() ? this : this.multiply(t.inverse());
|
|
2163
|
+
});
|
|
2164
|
+
/**
|
|
2165
|
+
* Determine if the equation contains a variable.
|
|
2166
|
+
* @param letter
|
|
2167
|
+
*/
|
|
2168
|
+
a(this, "hasVariable", (e) => this.variables.includes(e));
|
|
2169
|
+
a(this, "isLinearTo", (e) => {
|
|
2170
|
+
const t = e.clone().moveLeft().simplify().left, s = this.clone().moveLeft().simplify().left;
|
|
2171
|
+
return t.isEqual(s) || t.isOppositeAt(s);
|
|
2172
|
+
});
|
|
2173
|
+
/**
|
|
2174
|
+
* Determine if the equation contains more than one letter/variable.
|
|
2175
|
+
*/
|
|
2176
|
+
a(this, "isMultiVariable", () => i(this, q).isMultiVariable || i(this, A).isMultiVariable);
|
|
2177
|
+
// -----------------------------------------------
|
|
2178
|
+
// Equations helpers
|
|
2179
|
+
a(this, "isEqualTo", (e) => {
|
|
2180
|
+
const t = e.clone().moveLeft().left, s = this.clone().moveLeft().left;
|
|
2181
|
+
return t.isEqual(s) || t.isOppositeAt(s);
|
|
2182
|
+
});
|
|
2183
|
+
/**
|
|
2184
|
+
* Reorder the polynom to have only one letter on the left, the rest on the right.
|
|
2185
|
+
* @param letter
|
|
2186
|
+
*/
|
|
2187
|
+
a(this, "isolate", (e) => {
|
|
2188
|
+
if (!this.degree(e).isOne() || this.isMultiVariable())
|
|
2189
|
+
return !1;
|
|
2190
|
+
let t;
|
|
2191
|
+
i(this, q).subtract(i(this, A)), i(this, A).zero();
|
|
2192
|
+
const s = [...i(this, q).monoms];
|
|
2193
|
+
for (const n of s)
|
|
2194
|
+
n.hasVariable(e) || (t = n.clone(), i(this, q).subtract(t), i(this, A).subtract(t));
|
|
2195
|
+
if (i(this, q).length !== 1)
|
|
2196
|
+
return !1;
|
|
2197
|
+
const r = i(this, q).monoms[0].coefficient.clone();
|
|
2198
|
+
return i(this, q).divide(r), i(this, A).divide(r), this;
|
|
2199
|
+
});
|
|
2200
|
+
// -----------------------------------------------
|
|
2201
|
+
// Equations operations
|
|
2202
|
+
// -----------------------------------------------
|
|
2203
|
+
a(this, "letters", () => [.../* @__PURE__ */ new Set([...i(this, q).letters(), ...i(this, A).letters()])]);
|
|
2204
|
+
// -----------------------------------------------
|
|
2205
|
+
/**
|
|
2206
|
+
* Reorder will move all monoms containing a letter on the left, all the other on the right.
|
|
2207
|
+
*/
|
|
2208
|
+
a(this, "moveLeft", () => (i(this, q).subtract(i(this, A)), i(this, A).zero(), this));
|
|
2209
|
+
/**
|
|
2210
|
+
* Multiple an equation by a fraction value.
|
|
2211
|
+
* @param value
|
|
2212
|
+
*/
|
|
2213
|
+
a(this, "multiply", (e) => {
|
|
2214
|
+
const t = new c(e);
|
|
2215
|
+
return i(this, q).multiply(t), i(this, A).multiply(t), i(this, re) !== "=" && t.sign() === -1 && i(this, Pt).call(this), this;
|
|
2216
|
+
});
|
|
2217
|
+
a(this, "opposite", () => (h(this, q, i(this, q).opposite()), h(this, A, i(this, A).opposite()), this));
|
|
2218
|
+
a(this, "reorder", (e) => (i(this, q).subtract(i(this, A)), i(this, A).zero(), i(this, q).reorder(), e ? this : (i(this, q).monoms.filter((t) => t.degree().isZero()).forEach((t) => {
|
|
2219
|
+
const s = t.clone();
|
|
2220
|
+
i(this, q).subtract(s), i(this, A).subtract(s);
|
|
2221
|
+
}), i(this, q).reorder(), i(this, A).reorder(), this)));
|
|
2222
|
+
// ------------------------------------------
|
|
2223
|
+
a(this, "replaceBy", (e, t) => (i(this, q).replaceBy(e, t), i(this, A).replaceBy(e, t), this));
|
|
2224
|
+
/**
|
|
2225
|
+
* Multiply by the lcm denominator and divide by the gcm numerators.
|
|
2226
|
+
*/
|
|
2227
|
+
a(this, "simplify", () => (this.multiply(G.lcm(...i(this, q).getDenominators(), ...i(this, A).getDenominators())), this.divide(G.gcd(...i(this, q).getNumerators(), ...i(this, A).getNumerators())), this));
|
|
2228
|
+
// -----------------------------------------------
|
|
2229
|
+
a(this, "solve", () => new yt(this.clone()).solve());
|
|
2230
|
+
a(this, "test", (e) => this.left.evaluate(e).isEqual(this.right.evaluate(e)));
|
|
2231
|
+
// #endregion Getters And Setters (13)
|
|
2232
|
+
// #region Private methods (6)
|
|
2233
|
+
f(this, Bt, (e) => {
|
|
2234
|
+
if (e.includes("geq"))
|
|
2235
|
+
return e.includes("\\geq") ? "\\geq" : "geq";
|
|
2236
|
+
if (e.includes("leq"))
|
|
2237
|
+
return e.includes("\\leq") ? "\\leq" : "leq";
|
|
2238
|
+
if (e.includes(">="))
|
|
2239
|
+
return ">=";
|
|
2240
|
+
if (e.includes("=>"))
|
|
2241
|
+
return "=>";
|
|
2242
|
+
if (e.includes(">"))
|
|
2243
|
+
return ">";
|
|
2244
|
+
if (e.includes("<="))
|
|
2245
|
+
return "<=";
|
|
2246
|
+
if (e.includes("=<"))
|
|
2247
|
+
return "=<";
|
|
2248
|
+
if (e.includes("<"))
|
|
2249
|
+
return "<";
|
|
2250
|
+
if (e.includes("="))
|
|
2251
|
+
return "=";
|
|
2252
|
+
throw new Error("The equation is not valid (no sign found)");
|
|
2253
|
+
});
|
|
2254
|
+
// -----------------------------------------------
|
|
2255
|
+
// Equations solving algorithms
|
|
2256
|
+
f(this, Ke, (e) => e === void 0 ? "=" : e.includes("geq") || e.includes(">=") || e.includes("=>") ? ">=" : e.includes(">") ? ">" : e.includes("leq") || e.includes("<=") || e.includes("=<") ? "<=" : e.includes("<") ? "<" : "=");
|
|
2257
|
+
f(this, Pt, () => i(this, re) === "=" ? this : i(this, re).includes("<") ? (i(this, re).replace("<", ">"), this) : i(this, re).includes(">") ? (i(this, re).replace(">", "<"), this) : this);
|
|
2258
|
+
if (h(this, q, new T().zero()), h(this, A, new T().zero()), h(this, re, "="), e !== void 0 && t === void 0) {
|
|
2259
|
+
if (e instanceof xe)
|
|
2260
|
+
return e.clone();
|
|
2261
|
+
typeof e == "string" && this.parse(e);
|
|
2262
|
+
} else e !== void 0 && t !== void 0 && (this.left = new T(e), this.right = new T(t));
|
|
2263
|
+
return s !== void 0 && (this.sign = s), this;
|
|
2264
|
+
}
|
|
2265
|
+
/**
|
|
2266
|
+
* Add a value to the equation
|
|
2267
|
+
* if value is an equation, add the left part to the left part of the equation
|
|
2268
|
+
* and the right part to the right part of the equation
|
|
2269
|
+
* if value is a string, try to create an equation
|
|
2270
|
+
* if it fails, create a polynom and add it to the left and right part of the equation
|
|
2271
|
+
* @param value | Polynom | Monom | Fraction | string | monom
|
|
2272
|
+
*/
|
|
2273
|
+
add(e) {
|
|
2274
|
+
if (e instanceof xe)
|
|
2275
|
+
return i(this, q).add(e.left), i(this, A).add(e.right), this;
|
|
2276
|
+
if (typeof e == "string" && !xe.isEquationString(e))
|
|
2277
|
+
return this.add(new xe(e));
|
|
2278
|
+
const t = new T(e);
|
|
2279
|
+
return i(this, q).add(t), i(this, A).add(t), this;
|
|
2280
|
+
}
|
|
2281
|
+
/**
|
|
2282
|
+
* Create an Equation using two polynoms.
|
|
2283
|
+
* Markdown *support* is cool
|
|
2284
|
+
* @param values
|
|
2285
|
+
* @param asNumeric
|
|
2286
|
+
*/
|
|
2287
|
+
evaluate(e, t) {
|
|
2288
|
+
const s = i(this, q).evaluate(e, t), r = i(this, A).evaluate(e, t);
|
|
2289
|
+
return t ? s === r : s.isEqual(r);
|
|
2290
|
+
}
|
|
2291
|
+
isEqual(e) {
|
|
2292
|
+
const t = new xe(e);
|
|
2293
|
+
return t.left.isEqual(i(this, q)) && t.right.isEqual(i(this, A));
|
|
2294
|
+
}
|
|
2295
|
+
pow(e) {
|
|
2296
|
+
return i(this, q).pow(e), i(this, A).pow(e), this;
|
|
2297
|
+
}
|
|
2298
|
+
reduce() {
|
|
2299
|
+
return this.moveLeft(), i(this, q).reduce(), this.simplify(), i(this, q).monoms[0].coefficient.isNegative() && this.multiply(-1), this;
|
|
2300
|
+
}
|
|
2301
|
+
split() {
|
|
2302
|
+
return [i(this, q).clone(), i(this, A).clone()];
|
|
2303
|
+
}
|
|
2304
|
+
subtract(e) {
|
|
2305
|
+
if (e instanceof xe)
|
|
2306
|
+
return i(this, q).subtract(e.left), i(this, A).subtract(e.right), this;
|
|
2307
|
+
if (typeof e == "string" && !xe.isEquationString(e))
|
|
2308
|
+
return this.subtract(new xe(e));
|
|
2309
|
+
const t = new T(e);
|
|
2310
|
+
return i(this, q).subtract(t), i(this, A).subtract(t), this;
|
|
2311
|
+
}
|
|
2312
|
+
static isEquationString(e) {
|
|
2313
|
+
return e.includes("=") || e.includes("<") || e.includes(">") || e.includes("<=") || e.includes(">=");
|
|
2314
|
+
}
|
|
2315
|
+
static makeSolutionsUnique(e, t) {
|
|
2316
|
+
const s = [], r = e.filter((n) => s.includes(n.tex) ? !1 : (s.push(n.tex), !0));
|
|
2317
|
+
return t === !0 && r.sort((n, l) => n.value - l.value), r;
|
|
2318
|
+
}
|
|
2319
|
+
// #endregion Properties and methods (26)
|
|
2320
|
+
// #region Getters And Setters (13)
|
|
2321
|
+
get display() {
|
|
2322
|
+
return `${i(this, q).display}${this.signAsTex}${i(this, A).display}`;
|
|
2323
|
+
}
|
|
2324
|
+
// Getter and setter
|
|
2325
|
+
get left() {
|
|
2326
|
+
return i(this, q);
|
|
2327
|
+
}
|
|
2328
|
+
set left(e) {
|
|
2329
|
+
h(this, q, e);
|
|
2330
|
+
}
|
|
2331
|
+
get numberOfVars() {
|
|
2332
|
+
return this.variables.length;
|
|
2333
|
+
}
|
|
2334
|
+
get right() {
|
|
2335
|
+
return i(this, A);
|
|
2336
|
+
}
|
|
2337
|
+
set right(e) {
|
|
2338
|
+
h(this, A, e);
|
|
2339
|
+
}
|
|
2340
|
+
// ------------------------------------------
|
|
2341
|
+
get sign() {
|
|
2342
|
+
return i(this, re);
|
|
2343
|
+
}
|
|
2344
|
+
set sign(e) {
|
|
2345
|
+
h(this, re, i(this, Ke).call(this, e));
|
|
2346
|
+
}
|
|
2347
|
+
get signAsTex() {
|
|
2348
|
+
return i(this, re) === ">=" ? "\\geq" : i(this, re) === "<=" ? "\\leq" : i(this, re);
|
|
2349
|
+
}
|
|
2350
|
+
get tex() {
|
|
2351
|
+
return `${i(this, q).tex}${this.signAsTex}${i(this, A).tex}`;
|
|
2352
|
+
}
|
|
2353
|
+
get variables() {
|
|
2354
|
+
return [...new Set(i(this, A).variables.concat(i(this, q).variables))];
|
|
2355
|
+
}
|
|
2356
|
+
// #endregion Private methods (6)
|
|
2357
|
+
};
|
|
2358
|
+
q = new WeakMap(), A = new WeakMap(), re = new WeakMap(), Bt = new WeakMap(), Ke = new WeakMap(), Pt = new WeakMap();
|
|
2359
|
+
let H = xe;
|
|
2360
|
+
var L, Ie, St, Rt;
|
|
2361
|
+
const Ge = class Ge {
|
|
2362
|
+
constructor(...e) {
|
|
2363
|
+
f(this, L);
|
|
2364
|
+
// Determine the letters in the linear system, usually ['x', 'y']
|
|
2365
|
+
f(this, Ie);
|
|
2366
|
+
a(this, "parse", (...e) => (h(this, L, e.map((t) => new H(t))), i(this, St).call(this), this));
|
|
2367
|
+
a(this, "clone", () => new Ge().parse(...i(this, L).map((e) => e.clone())));
|
|
2368
|
+
a(this, "buildTex", (e, t) => {
|
|
2369
|
+
let s, r, n = [];
|
|
2370
|
+
const l = [];
|
|
2371
|
+
for (const p of e)
|
|
2372
|
+
n = n.concat(p.letters());
|
|
2373
|
+
n = [...new Set(n)], n.sort();
|
|
2374
|
+
for (let p = 0; p < e.length; p++) {
|
|
2375
|
+
const m = e[p];
|
|
2376
|
+
s = [];
|
|
2377
|
+
for (const y of n)
|
|
2378
|
+
r = m.left.monomByLetter(y), s.length === 0 ? s.push(r.isZero() ? "" : r.tex) : s.push(r.isZero() ? "" : (r.coefficient.sign() === 1 ? "+" : "") + r.tex);
|
|
2379
|
+
if (s.push("="), s.push(m.right.tex), (t == null ? void 0 : t[p]) !== void 0) {
|
|
2380
|
+
s[s.length - 1] = s[s.length - 1] + " \\phantom{\\quad}";
|
|
2381
|
+
for (const y of t[p])
|
|
2382
|
+
s.push(`\\ \\cdot\\ ${y.startsWith("-") ? "\\left(" + y + "\\right)" : y}`);
|
|
2383
|
+
}
|
|
2384
|
+
l.push(s.join("&"));
|
|
2385
|
+
}
|
|
2386
|
+
let u = 0;
|
|
2387
|
+
return t !== void 0 && t.length > 0 && (u = t[0].length), `\\left\\{\\begin{array}{${"r".repeat(n.length)}cl ${"|l".repeat(u)}}${l.join("\\\\ ")}\\end{array}\\right.`;
|
|
2388
|
+
});
|
|
2389
|
+
a(this, "mergeEquations", (e, t, s, r) => {
|
|
2390
|
+
const n = e.clone().multiply(new c(s)), l = t.clone().multiply(new c(r));
|
|
2391
|
+
return n.left.add(l.left), n.right.add(l.right), n;
|
|
2392
|
+
});
|
|
2393
|
+
// ------------------------------------------
|
|
2394
|
+
a(this, "reorder", () => {
|
|
2395
|
+
for (const e of i(this, L))
|
|
2396
|
+
e.reorder();
|
|
2397
|
+
return this;
|
|
2398
|
+
});
|
|
2399
|
+
a(this, "solveMatrix", () => {
|
|
2400
|
+
const [e, t] = this.matrix, s = e.map((r, n) => [...r, t[n]]);
|
|
2401
|
+
for (let r = 0; r < e.length; r++) {
|
|
2402
|
+
const n = s[r][r].clone();
|
|
2403
|
+
s[r] = s[r].map((l) => l.divide(n));
|
|
2404
|
+
for (let l = 0; l < e.length; l++) {
|
|
2405
|
+
if (l === r)
|
|
2406
|
+
continue;
|
|
2407
|
+
const u = s[l][r].clone().opposite();
|
|
2408
|
+
for (let p = 0; p < s[l].length; p++)
|
|
2409
|
+
s[l][p].add(s[r][p].clone().multiply(u));
|
|
2410
|
+
if (s[l].slice(0, s[l].length - 1).every((p) => p.isZero()))
|
|
2411
|
+
return s[l][s[l].length - 1].isZero() ? [new c().infinite()] : [];
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
return s.map((r) => r[r.length - 1]);
|
|
2415
|
+
});
|
|
2416
|
+
f(this, St, () => (h(this, Ie, i(this, L).reduce((e, t) => [.../* @__PURE__ */ new Set([...e, ...t.variables])], [])), i(this, Ie).sort(), this));
|
|
2417
|
+
f(this, Rt, () => {
|
|
2418
|
+
const e = [], t = [];
|
|
2419
|
+
for (const s of i(this, L)) {
|
|
2420
|
+
const r = [], n = s.clone().reorder();
|
|
2421
|
+
for (const l of this.variables) {
|
|
2422
|
+
const u = n.left.monomByLetter(l);
|
|
2423
|
+
r.push(u.coefficient);
|
|
2424
|
+
}
|
|
2425
|
+
t.push(n.right.monoms[0].coefficient), e.push(r);
|
|
2426
|
+
}
|
|
2427
|
+
return [e, t];
|
|
2428
|
+
});
|
|
2429
|
+
return h(this, L, []), h(this, Ie, []), e.length > 0 && this.parse(...e), this;
|
|
2430
|
+
}
|
|
2431
|
+
static fromMatrix(e, t = "xyz") {
|
|
2432
|
+
const s = e[0].length;
|
|
2433
|
+
if (e.some((n) => n.length !== s))
|
|
2434
|
+
throw new Error("All rows must have the same number of columns");
|
|
2435
|
+
const r = t.split("").splice(0, s - 1);
|
|
2436
|
+
return new Ge(
|
|
2437
|
+
...e.map((n) => {
|
|
2438
|
+
const l = new T(r.join(""), ...n);
|
|
2439
|
+
return new H(l, 0);
|
|
2440
|
+
})
|
|
2441
|
+
);
|
|
2442
|
+
}
|
|
2443
|
+
add(e, t) {
|
|
2444
|
+
if (e instanceof Ge) {
|
|
2445
|
+
const s = e.equations.length;
|
|
2446
|
+
if (s !== i(this, L).length)
|
|
2447
|
+
throw new Error("The number of equations must be the same");
|
|
2448
|
+
for (let r = 0; r < s; r++)
|
|
2449
|
+
i(this, L)[r].add(e.equations[r]);
|
|
2450
|
+
} else {
|
|
2451
|
+
if (t === void 0 || t < 0 || t >= i(this, L).length)
|
|
2452
|
+
throw new Error("Index out of range");
|
|
2453
|
+
const s = new H(e);
|
|
2454
|
+
i(this, L)[t].add(s);
|
|
2455
|
+
}
|
|
2456
|
+
return this;
|
|
2457
|
+
}
|
|
2458
|
+
degree(e) {
|
|
2459
|
+
return c.max(...i(this, L).map((t) => t.degree(e)));
|
|
2460
|
+
}
|
|
2461
|
+
get display() {
|
|
2462
|
+
return this.tex + "as display";
|
|
2463
|
+
}
|
|
2464
|
+
// ------------------------------------------
|
|
2465
|
+
get equations() {
|
|
2466
|
+
return i(this, L);
|
|
2467
|
+
}
|
|
2468
|
+
set equations(e) {
|
|
2469
|
+
h(this, L, e);
|
|
2470
|
+
}
|
|
2471
|
+
evaluate(e, t) {
|
|
2472
|
+
throw new Error("Method not implemented.");
|
|
2473
|
+
}
|
|
2474
|
+
hasVariable(e) {
|
|
2475
|
+
return i(this, Ie).includes(e);
|
|
2476
|
+
}
|
|
2477
|
+
isEqual(e) {
|
|
2478
|
+
return this.equations.every((t, s) => t.isEqual(e.equations[s]));
|
|
2479
|
+
}
|
|
2480
|
+
get isSolvable() {
|
|
2481
|
+
return this.variables.length === i(this, L).length;
|
|
2482
|
+
}
|
|
2483
|
+
get matrix() {
|
|
2484
|
+
return i(this, Rt).call(this);
|
|
2485
|
+
}
|
|
2486
|
+
multiply(e, t) {
|
|
2487
|
+
if (Array.isArray(e)) {
|
|
2488
|
+
if (e.length !== i(this, L).length)
|
|
2489
|
+
throw new Error("The number of values must be the same as the number of equations");
|
|
2490
|
+
for (let s = 0; s < e.length; s++)
|
|
2491
|
+
i(this, L)[s].multiply(e[s]);
|
|
2492
|
+
return this;
|
|
2493
|
+
}
|
|
2494
|
+
if (t === void 0 || t < 0 || t >= i(this, L).length)
|
|
2495
|
+
throw new Error("Index out of range");
|
|
2496
|
+
return i(this, L)[t].multiply(e), this;
|
|
2497
|
+
}
|
|
2498
|
+
reduce() {
|
|
2499
|
+
throw new Error("Method not implemented.");
|
|
2500
|
+
}
|
|
2501
|
+
solve() {
|
|
2502
|
+
return [];
|
|
2326
2503
|
}
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2504
|
+
subtract(e, t) {
|
|
2505
|
+
if (e instanceof Ge) {
|
|
2506
|
+
const s = e.equations.length;
|
|
2507
|
+
if (s !== i(this, L).length)
|
|
2508
|
+
throw new Error("The number of equations must be the same");
|
|
2509
|
+
for (let r = 0; r < s; r++)
|
|
2510
|
+
i(this, L)[r].subtract(e.equations[r]);
|
|
2511
|
+
} else {
|
|
2512
|
+
if (t === void 0 || t < 0 || t >= i(this, L).length)
|
|
2513
|
+
throw new Error("Index out of range");
|
|
2514
|
+
const s = new H(e);
|
|
2515
|
+
i(this, L)[t].subtract(s);
|
|
2516
|
+
}
|
|
2517
|
+
return this;
|
|
2333
2518
|
}
|
|
2334
2519
|
get tex() {
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
return
|
|
2520
|
+
const e = this.clone().reorder();
|
|
2521
|
+
return this.buildTex(e.equations);
|
|
2522
|
+
}
|
|
2523
|
+
get variables() {
|
|
2524
|
+
return i(this, Ie);
|
|
2525
|
+
}
|
|
2526
|
+
set variables(e) {
|
|
2527
|
+
const t = typeof e == "string" ? e.split("") : [...e];
|
|
2528
|
+
t.sort(), h(this, Ie, t);
|
|
2340
2529
|
}
|
|
2341
|
-
// #endregion Private methods (1)
|
|
2342
2530
|
};
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
return new ue(u, c.min(b, p));
|
|
2347
|
-
});
|
|
2348
|
-
return new pe(...l);
|
|
2349
|
-
}, d(pe, st);
|
|
2350
|
-
let Dt = pe;
|
|
2351
|
-
function kt(o) {
|
|
2352
|
-
const e = new c().one(), t = o.factors.reduce((s, r) => {
|
|
2353
|
-
if (r.polynom.degree().isZero())
|
|
2354
|
-
return r.polynom.monoms.length > 0 && e.multiply(r.polynom.monoms[0].coefficient), s;
|
|
2355
|
-
const n = r.polynom.display;
|
|
2356
|
-
return Object.hasOwn(s, n) ? s[n].push(r) : s[n] = [r], s;
|
|
2357
|
-
}, {});
|
|
2358
|
-
return e.isOne() || (t[e.display] = [new ue(e.display, 1)]), t;
|
|
2359
|
-
}
|
|
2360
|
-
function $i(o, e) {
|
|
2531
|
+
L = new WeakMap(), Ie = new WeakMap(), St = new WeakMap(), Rt = new WeakMap();
|
|
2532
|
+
let Qt = Ge;
|
|
2533
|
+
function Fi(o, e) {
|
|
2361
2534
|
return o.dimension === e.dimension && o.array.every(
|
|
2362
2535
|
(t, s) => e.array[s].isEqual(t)
|
|
2363
2536
|
);
|
|
2364
2537
|
}
|
|
2365
|
-
function
|
|
2538
|
+
function ji(o, e) {
|
|
2366
2539
|
if (o.dimension !== e.dimension)
|
|
2367
2540
|
return !1;
|
|
2368
2541
|
const t = e.array[0].value / o.array[0].value;
|
|
@@ -2370,35 +2543,44 @@ function Bi(o, e) {
|
|
|
2370
2543
|
(s, r) => e.array[r].value === s.value * t
|
|
2371
2544
|
);
|
|
2372
2545
|
}
|
|
2373
|
-
function
|
|
2546
|
+
function Ui(o, e) {
|
|
2374
2547
|
return o.dimension !== e.dimension ? new c().invalid() : o.array.reduce(
|
|
2375
2548
|
(t, s, r) => t.add(s.clone().multiply(e.array[r])),
|
|
2376
2549
|
new c(0)
|
|
2377
2550
|
);
|
|
2378
2551
|
}
|
|
2379
|
-
|
|
2380
|
-
|
|
2552
|
+
function Gi(...o) {
|
|
2553
|
+
return o.some((e) => e.dimension !== o[0].dimension) ? new c().invalid() : o[0].dimension === 2 && o.length !== 2 ? new c().invalid() : o[0].dimension === 3 && o.length !== 3 ? new c().invalid() : 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(
|
|
2554
|
+
o[1].array[1].clone().multiply(o[2].array[2]).subtract(o[1].array[2].clone().multiply(o[2].array[1]))
|
|
2555
|
+
).subtract(
|
|
2556
|
+
o[0].array[1].clone().multiply(
|
|
2557
|
+
o[1].array[0].clone().multiply(o[2].array[2]).subtract(o[1].array[2].clone().multiply(o[2].array[0]))
|
|
2558
|
+
)
|
|
2559
|
+
).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]))));
|
|
2560
|
+
}
|
|
2561
|
+
var V, ze, zt;
|
|
2562
|
+
const Pe = class Pe {
|
|
2381
2563
|
constructor(...e) {
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
a(this, "zero", () => (i(this,
|
|
2564
|
+
f(this, V, []);
|
|
2565
|
+
f(this, ze, !1);
|
|
2566
|
+
a(this, "zero", () => (i(this, V).forEach((e) => e.zero()), this));
|
|
2385
2567
|
a(this, "one", () => (this.zero(), this.x.one(), this));
|
|
2386
|
-
a(this, "opposite", () => (i(this,
|
|
2387
|
-
a(this, "add", (e) => (i(this,
|
|
2568
|
+
a(this, "opposite", () => (i(this, V).forEach((e) => e.opposite()), this));
|
|
2569
|
+
a(this, "add", (e) => (i(this, V).forEach((t, s) => t.add(e.array[s])), this));
|
|
2388
2570
|
a(this, "subtract", (e) => this.add(e.clone().opposite()));
|
|
2389
2571
|
a(this, "unit", () => {
|
|
2390
2572
|
const e = this.norm;
|
|
2391
2573
|
return e === 0 ? this : this.divideByScalar(e);
|
|
2392
2574
|
});
|
|
2393
|
-
a(this, "dot", (e) =>
|
|
2575
|
+
a(this, "dot", (e) => Ui(this, e));
|
|
2394
2576
|
a(this, "normal", () => {
|
|
2395
2577
|
if (this.dimension >= 3)
|
|
2396
2578
|
throw new Error("Normal vector can only be determined in 2D");
|
|
2397
2579
|
const e = this.x.clone().opposite(), t = this.y.clone();
|
|
2398
|
-
return i(this,
|
|
2580
|
+
return i(this, V)[0] = t, i(this, V)[1] = e, this;
|
|
2399
2581
|
});
|
|
2400
|
-
a(this, "isEqual", (e) =>
|
|
2401
|
-
a(this, "isColinearTo", (e) =>
|
|
2582
|
+
a(this, "isEqual", (e) => Fi(this, e));
|
|
2583
|
+
a(this, "isColinearTo", (e) => ji(this, e));
|
|
2402
2584
|
a(this, "isNormalTo", (e) => this.dot(e).isZero());
|
|
2403
2585
|
a(this, "multiplyByScalar", (e) => {
|
|
2404
2586
|
const t = new c(e);
|
|
@@ -2406,9 +2588,9 @@ const Ie = class Ie {
|
|
|
2406
2588
|
});
|
|
2407
2589
|
a(this, "divideByScalar", (e) => this.multiplyByScalar(new c(e).inverse()));
|
|
2408
2590
|
a(this, "simplify", () => this.multiplyByScalar(
|
|
2409
|
-
|
|
2591
|
+
G.lcm(...this.array.map((e) => e.denominator))
|
|
2410
2592
|
).divideByScalar(
|
|
2411
|
-
|
|
2593
|
+
G.gcd(...this.array.map((e) => e.numerator))
|
|
2412
2594
|
).multiplyByScalar(
|
|
2413
2595
|
this.x.isNegative() ? -1 : 1
|
|
2414
2596
|
));
|
|
@@ -2416,10 +2598,10 @@ const Ie = class Ie {
|
|
|
2416
2598
|
let r = this.dot(e).value;
|
|
2417
2599
|
return t && (r = Math.abs(r)), (s ? 1 : 180 / Math.PI) * Math.acos(r / (this.norm * e.norm));
|
|
2418
2600
|
});
|
|
2419
|
-
|
|
2601
|
+
f(this, zt, (e) => {
|
|
2420
2602
|
e.startsWith("(") && (e = e.substring(1)), e.endsWith(")") && (e = e.substring(0, e.length - 1));
|
|
2421
2603
|
const t = e.split(/[,;\s]/g).filter((s) => s.trim() !== "");
|
|
2422
|
-
return t.length < 2 ? this : (h(this,
|
|
2604
|
+
return t.length < 2 ? this : (h(this, V, t.map((s) => new c(s))), this);
|
|
2423
2605
|
});
|
|
2424
2606
|
e.length > 0 && this.parse(...e);
|
|
2425
2607
|
}
|
|
@@ -2427,38 +2609,38 @@ const Ie = class Ie {
|
|
|
2427
2609
|
// Getter and setter
|
|
2428
2610
|
// ------------------------------------------
|
|
2429
2611
|
get array() {
|
|
2430
|
-
return i(this,
|
|
2612
|
+
return i(this, V);
|
|
2431
2613
|
}
|
|
2432
2614
|
set array(e) {
|
|
2433
|
-
h(this,
|
|
2615
|
+
h(this, V, e);
|
|
2434
2616
|
}
|
|
2435
2617
|
get x() {
|
|
2436
|
-
return i(this,
|
|
2618
|
+
return i(this, V)[0];
|
|
2437
2619
|
}
|
|
2438
2620
|
set x(e) {
|
|
2439
|
-
i(this,
|
|
2621
|
+
i(this, V)[0] = new c(e);
|
|
2440
2622
|
}
|
|
2441
2623
|
get y() {
|
|
2442
|
-
return i(this,
|
|
2624
|
+
return i(this, V)[1];
|
|
2443
2625
|
}
|
|
2444
2626
|
set y(e) {
|
|
2445
|
-
i(this,
|
|
2627
|
+
i(this, V)[1] = new c(e);
|
|
2446
2628
|
}
|
|
2447
2629
|
get z() {
|
|
2448
2630
|
if (this.dimension < 3)
|
|
2449
2631
|
throw new Error("Vector is not 3D");
|
|
2450
|
-
return i(this,
|
|
2632
|
+
return i(this, V)[2];
|
|
2451
2633
|
}
|
|
2452
2634
|
set z(e) {
|
|
2453
2635
|
if (this.dimension < 3)
|
|
2454
2636
|
throw new Error("Vector is not 3D");
|
|
2455
|
-
i(this,
|
|
2637
|
+
i(this, V)[2] = new c(e);
|
|
2456
2638
|
}
|
|
2457
2639
|
get asPoint() {
|
|
2458
|
-
return i(this,
|
|
2640
|
+
return i(this, ze);
|
|
2459
2641
|
}
|
|
2460
2642
|
set asPoint(e) {
|
|
2461
|
-
h(this,
|
|
2643
|
+
h(this, ze, e);
|
|
2462
2644
|
}
|
|
2463
2645
|
get normSquare() {
|
|
2464
2646
|
return this.array.reduce((e, t) => e.add(t.clone().pow(2)), new c(0));
|
|
@@ -2467,19 +2649,19 @@ const Ie = class Ie {
|
|
|
2467
2649
|
return Math.sqrt(this.normSquare.value);
|
|
2468
2650
|
}
|
|
2469
2651
|
get tex() {
|
|
2470
|
-
return i(this,
|
|
2652
|
+
return i(this, ze) ? `\\left(${this.array.map((e) => e.tex).join(";")}\\right)` : `\\begin{pmatrix} ${this.array.map((e) => e.tex).join(" \\\\ ")} \\end{pmatrix}`;
|
|
2471
2653
|
}
|
|
2472
2654
|
get display() {
|
|
2473
|
-
return i(this,
|
|
2655
|
+
return i(this, ze) ? `(${this.array.map((e) => e.display).join(";")})` : `((${this.array.map((e) => e.display).join(",")}))`;
|
|
2474
2656
|
}
|
|
2475
2657
|
setDimension(e = 2) {
|
|
2476
2658
|
if (e < 2)
|
|
2477
2659
|
throw new Error("Dimension must be at least 2");
|
|
2478
2660
|
if (e < this.dimension)
|
|
2479
|
-
h(this,
|
|
2661
|
+
h(this, V, i(this, V).slice(0, e));
|
|
2480
2662
|
else if (e > this.dimension)
|
|
2481
2663
|
for (let t = this.dimension; t < e; t++)
|
|
2482
|
-
i(this,
|
|
2664
|
+
i(this, V).push(new c(0));
|
|
2483
2665
|
return this;
|
|
2484
2666
|
}
|
|
2485
2667
|
get dimension() {
|
|
@@ -2498,34 +2680,34 @@ const Ie = class Ie {
|
|
|
2498
2680
|
return `((${e.join(",")}))`;
|
|
2499
2681
|
}
|
|
2500
2682
|
defineAsPoint(e) {
|
|
2501
|
-
return h(this,
|
|
2683
|
+
return h(this, ze, e !== !1), this;
|
|
2502
2684
|
}
|
|
2503
2685
|
parse(...e) {
|
|
2504
2686
|
if (e.length === 0)
|
|
2505
2687
|
throw new Error("Invalid value");
|
|
2506
2688
|
if (e.length === 1) {
|
|
2507
|
-
if (e[0] instanceof
|
|
2689
|
+
if (e[0] instanceof Pe)
|
|
2508
2690
|
return e[0].clone();
|
|
2509
2691
|
if (typeof e[0] == "string")
|
|
2510
|
-
return i(this,
|
|
2692
|
+
return i(this, zt).call(this, e[0]);
|
|
2511
2693
|
throw new Error("Invalid value");
|
|
2512
2694
|
}
|
|
2513
2695
|
if (e.length === 2) {
|
|
2514
2696
|
const [t, s] = e;
|
|
2515
|
-
if (t instanceof
|
|
2697
|
+
if (t instanceof Pe && s instanceof Pe) {
|
|
2516
2698
|
if (t.dimension !== s.dimension)
|
|
2517
2699
|
throw new Error("Vectors must have the same dimension");
|
|
2518
|
-
return h(this,
|
|
2700
|
+
return h(this, V, s.array.map((r, n) => r.clone().subtract(t.array[n]))), this;
|
|
2519
2701
|
}
|
|
2520
2702
|
}
|
|
2521
|
-
return h(this,
|
|
2703
|
+
return h(this, V, e.map((t) => new c(t))), this;
|
|
2522
2704
|
}
|
|
2523
2705
|
clone() {
|
|
2524
|
-
const e = new
|
|
2706
|
+
const e = new Pe();
|
|
2525
2707
|
return e.array = this.copy(), e.asPoint = this.asPoint, e;
|
|
2526
2708
|
}
|
|
2527
2709
|
copy() {
|
|
2528
|
-
return i(this,
|
|
2710
|
+
return i(this, V).map((e) => e.clone());
|
|
2529
2711
|
}
|
|
2530
2712
|
middleOf(e, t) {
|
|
2531
2713
|
if (e.dimension !== t.dimension)
|
|
@@ -2540,7 +2722,7 @@ const Ie = class Ie {
|
|
|
2540
2722
|
cross(e) {
|
|
2541
2723
|
if (this.dimension !== 3 || e.dimension !== 3)
|
|
2542
2724
|
throw new Error("Cross product can only be determined in 3D");
|
|
2543
|
-
return new
|
|
2725
|
+
return new Pe(
|
|
2544
2726
|
this.y.clone().multiply(e.z).subtract(this.z.clone().multiply(e.y)),
|
|
2545
2727
|
this.z.clone().multiply(e.x).subtract(this.x.clone().multiply(e.z)),
|
|
2546
2728
|
this.x.clone().multiply(e.y).subtract(this.y.clone().multiply(e.x))
|
|
@@ -2553,7 +2735,7 @@ const Ie = class Ie {
|
|
|
2553
2735
|
return this.array.every((e, t) => t === 0 ? e.isOne() : e.isZero());
|
|
2554
2736
|
}
|
|
2555
2737
|
distanceTo(e) {
|
|
2556
|
-
const t = new
|
|
2738
|
+
const t = new Pe(this, e);
|
|
2557
2739
|
return {
|
|
2558
2740
|
value: t.norm,
|
|
2559
2741
|
fraction: t.normSquare,
|
|
@@ -2561,39 +2743,39 @@ const Ie = class Ie {
|
|
|
2561
2743
|
};
|
|
2562
2744
|
}
|
|
2563
2745
|
};
|
|
2564
|
-
|
|
2565
|
-
let
|
|
2566
|
-
function
|
|
2746
|
+
V = new WeakMap(), ze = new WeakMap(), zt = new WeakMap();
|
|
2747
|
+
let x = Pe;
|
|
2748
|
+
function yi(o = 0.5) {
|
|
2567
2749
|
return Math.random() < o;
|
|
2568
2750
|
}
|
|
2569
|
-
function
|
|
2751
|
+
function de(o, e, t) {
|
|
2570
2752
|
if (e === void 0)
|
|
2571
|
-
return o >= 0 ?
|
|
2753
|
+
return o >= 0 ? de(0, o) : de(o, 0);
|
|
2572
2754
|
if (o === e)
|
|
2573
2755
|
return o;
|
|
2574
2756
|
if (t === void 0)
|
|
2575
2757
|
return Math.floor(Math.random() * (e - o + 1) + o);
|
|
2576
2758
|
if (Math.abs(e - o) <= t.length)
|
|
2577
2759
|
throw new Error("The number of excluded values is too high.");
|
|
2578
|
-
let s =
|
|
2760
|
+
let s = de(o, e);
|
|
2579
2761
|
for (; t.includes(s); )
|
|
2580
|
-
s =
|
|
2762
|
+
s = de(o, e);
|
|
2581
2763
|
return s;
|
|
2582
2764
|
}
|
|
2583
|
-
function
|
|
2584
|
-
return e === !1 ?
|
|
2765
|
+
function X(o, e) {
|
|
2766
|
+
return e === !1 ? yi() ? de(1, o) : -de(1, o) : de(-o, o);
|
|
2585
2767
|
}
|
|
2586
|
-
function
|
|
2587
|
-
let e =
|
|
2588
|
-
return o !== void 0 && (e = e.filter((t) => t < o)),
|
|
2768
|
+
function Wi(o) {
|
|
2769
|
+
let e = G.primes();
|
|
2770
|
+
return o !== void 0 && (e = e.filter((t) => t < o)), ti(e);
|
|
2589
2771
|
}
|
|
2590
|
-
function
|
|
2591
|
-
return e === void 0 && (e = 1), o.length <= 0 ? Object.values(o) :
|
|
2772
|
+
function Hi(o, e) {
|
|
2773
|
+
return e === void 0 && (e = 1), o.length <= 0 ? Object.values(o) : gi(o).slice(0, e);
|
|
2592
2774
|
}
|
|
2593
|
-
function
|
|
2594
|
-
return o.length === 0 ? null : o[
|
|
2775
|
+
function ti(o) {
|
|
2776
|
+
return o.length === 0 ? null : o[de(0, o.length - 1)];
|
|
2595
2777
|
}
|
|
2596
|
-
function
|
|
2778
|
+
function gi(o) {
|
|
2597
2779
|
const e = Object.values(o);
|
|
2598
2780
|
for (let t = e.length - 1; t > 0; t--) {
|
|
2599
2781
|
const s = Math.floor(Math.random() * (t + 1)), r = e[t];
|
|
@@ -2601,13 +2783,13 @@ function oi(o) {
|
|
|
2601
2783
|
}
|
|
2602
2784
|
return e;
|
|
2603
2785
|
}
|
|
2604
|
-
class
|
|
2786
|
+
class R extends x {
|
|
2605
2787
|
constructor(...e) {
|
|
2606
2788
|
super(), e.length > 0 && this.parse(...e);
|
|
2607
2789
|
}
|
|
2608
2790
|
parse(...e) {
|
|
2609
2791
|
if (this.asPoint = !0, e.length === 0) {
|
|
2610
|
-
if (e[0] instanceof
|
|
2792
|
+
if (e[0] instanceof x)
|
|
2611
2793
|
return this.array = e[0].copy(), this;
|
|
2612
2794
|
if (typeof e[0] == "string") {
|
|
2613
2795
|
const t = e[0].replaceAll("(", "").replaceAll(")", "").split(",").map((s) => new c(s));
|
|
@@ -2617,7 +2799,7 @@ class G extends O {
|
|
|
2617
2799
|
}
|
|
2618
2800
|
}
|
|
2619
2801
|
if (e.length > 1) {
|
|
2620
|
-
if (e.some((s) => s instanceof
|
|
2802
|
+
if (e.some((s) => s instanceof x))
|
|
2621
2803
|
throw new Error("Creating a point with multiple argument requires an input fraction");
|
|
2622
2804
|
const t = e.map((s) => new c(s));
|
|
2623
2805
|
if (t.some((s) => s.isNaN()))
|
|
@@ -2627,33 +2809,33 @@ class G extends O {
|
|
|
2627
2809
|
return this;
|
|
2628
2810
|
}
|
|
2629
2811
|
clone() {
|
|
2630
|
-
const e = new
|
|
2812
|
+
const e = new R();
|
|
2631
2813
|
return e.array = this.copy(), e.asPoint = !0, e;
|
|
2632
2814
|
}
|
|
2633
2815
|
}
|
|
2634
|
-
var
|
|
2635
|
-
const
|
|
2816
|
+
var wi = /* @__PURE__ */ ((o) => (o.None = "none", o.Parallel = "parallel", o.Perpendicular = "perpendicular", o.Tangent = "tangent", o))(wi || {}), Ce, S, z, U, ne, Y, $e, ve;
|
|
2817
|
+
const Le = class Le {
|
|
2636
2818
|
/**
|
|
2637
2819
|
* Value can be a mix of:
|
|
2638
2820
|
*
|
|
2639
2821
|
* @param values
|
|
2640
2822
|
*/
|
|
2641
2823
|
constructor(...e) {
|
|
2642
|
-
|
|
2824
|
+
f(this, Ce);
|
|
2643
2825
|
// ax + by + c = 0
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
a(this, "randomPoint", (e) => i(this,
|
|
2826
|
+
f(this, S);
|
|
2827
|
+
f(this, z);
|
|
2828
|
+
f(this, U);
|
|
2829
|
+
f(this, ne);
|
|
2830
|
+
f(this, Y);
|
|
2831
|
+
f(this, $e);
|
|
2832
|
+
f(this, ve, "canonical");
|
|
2833
|
+
a(this, "randomPoint", (e) => i(this, Y).clone().multiplyByScalar(X(e === void 0 || e <= 1 ? 3 : e, !1)).add(i(this, ne)));
|
|
2652
2834
|
a(this, "randomNearPoint", (e) => {
|
|
2653
2835
|
const t = this.randomPoint(e);
|
|
2654
2836
|
let s = 10;
|
|
2655
2837
|
for (; this.isOnLine(t) && s > 0; )
|
|
2656
|
-
t.x.add(
|
|
2838
|
+
t.x.add(X(1, !1)), t.y.add(X(1, !1)), s--;
|
|
2657
2839
|
return t;
|
|
2658
2840
|
});
|
|
2659
2841
|
// ------------------------------------------
|
|
@@ -2668,32 +2850,32 @@ const Re = class Re {
|
|
|
2668
2850
|
if (e.length === 0)
|
|
2669
2851
|
return this;
|
|
2670
2852
|
if (e.length === 1) {
|
|
2671
|
-
if (e[0] instanceof
|
|
2853
|
+
if (e[0] instanceof Le)
|
|
2672
2854
|
return e[0].clone();
|
|
2673
|
-
if (e[0] instanceof
|
|
2855
|
+
if (e[0] instanceof H)
|
|
2674
2856
|
return this.parseEquation(e[0]);
|
|
2675
2857
|
if (typeof e[0] == "string")
|
|
2676
2858
|
try {
|
|
2677
|
-
const t = new
|
|
2859
|
+
const t = new H(e[0]);
|
|
2678
2860
|
return this.parse(t);
|
|
2679
2861
|
} catch {
|
|
2680
2862
|
return this;
|
|
2681
2863
|
}
|
|
2682
2864
|
}
|
|
2683
2865
|
if (e.length === 2) {
|
|
2684
|
-
if (e[0] instanceof
|
|
2866
|
+
if (e[0] instanceof R && e[1] instanceof x)
|
|
2685
2867
|
return this.parseByPointAndVector(e[0], e[1]);
|
|
2686
|
-
if (e[0] instanceof
|
|
2687
|
-
return this.parseByPointAndVector(e[0], new
|
|
2868
|
+
if (e[0] instanceof R && e[1] instanceof R)
|
|
2869
|
+
return this.parseByPointAndVector(e[0], new x(e[0], e[1]));
|
|
2688
2870
|
}
|
|
2689
2871
|
if (e.length === 3) {
|
|
2690
|
-
if (e[0] instanceof
|
|
2872
|
+
if (e[0] instanceof x && e[1] instanceof x) {
|
|
2691
2873
|
if (e[2] === "perpendicular")
|
|
2692
2874
|
return this.parseByPointAndNormal(e[0], e[1]);
|
|
2693
2875
|
if (e[2] === "parallel")
|
|
2694
2876
|
return this.parseByPointAndVector(e[0], e[1]);
|
|
2695
2877
|
}
|
|
2696
|
-
return e[0] instanceof
|
|
2878
|
+
return e[0] instanceof x && e[1] instanceof Le ? e[2] === "parallel" || e[2] === null ? this.parseByPointAndLine(
|
|
2697
2879
|
e[0],
|
|
2698
2880
|
e[1],
|
|
2699
2881
|
"parallel"
|
|
@@ -2720,42 +2902,42 @@ const Re = class Re {
|
|
|
2720
2902
|
t.has(s) && t.delete(s);
|
|
2721
2903
|
return t.size > 0 ? this : this.parseByCoefficient(e.left.monomByLetter("x").coefficient, e.left.monomByLetter("y").coefficient, e.left.monomByDegree(0).coefficient);
|
|
2722
2904
|
});
|
|
2723
|
-
a(this, "parseByCoefficient", (e, t, s) => (h(this,
|
|
2905
|
+
a(this, "parseByCoefficient", (e, t, s) => (h(this, S, new c(e)), h(this, z, new c(t)), h(this, U, new c(s)), h(this, Y, new x(i(this, z).clone(), i(this, S).clone().opposite())), h(this, ne, new x(new c().zero(), i(this, U).clone())), h(this, $e, i(this, Y).clone().normal()), this));
|
|
2724
2906
|
a(this, "parseByPointAndVector", (e, t) => (this.parseByCoefficient(
|
|
2725
2907
|
t.y,
|
|
2726
2908
|
t.x.clone().opposite(),
|
|
2727
2909
|
e.x.clone().multiply(t.y).subtract(e.y.clone().multiply(t.x)).opposite()
|
|
2728
|
-
), h(this,
|
|
2910
|
+
), h(this, ne, e.clone()), h(this, Y, t.clone()), h(this, $e, i(this, Y).clone().normal()), this));
|
|
2729
2911
|
a(this, "parseByPointAndNormal", (e, t) => this.parseByCoefficient(
|
|
2730
2912
|
t.x,
|
|
2731
2913
|
t.y,
|
|
2732
2914
|
e.x.clone().multiply(t.x).add(e.y.clone().multiply(t.y)).opposite()
|
|
2733
2915
|
));
|
|
2734
2916
|
a(this, "parseByPointAndLine", (e, t, s) => (s === void 0 && (s = "parallel"), s === "parallel" ? this.parseByPointAndNormal(e, t.normal) : s === "perpendicular" ? this.parseByPointAndNormal(e, t.director) : this));
|
|
2735
|
-
a(this, "clone", () => (h(this,
|
|
2917
|
+
a(this, "clone", () => (h(this, S, i(this, S).clone()), h(this, z, i(this, z).clone()), h(this, U, i(this, U).clone()), h(this, Y, i(this, Y).clone()), h(this, ne, i(this, ne).clone()), h(this, $e, i(this, $e).clone()), this));
|
|
2736
2918
|
// ------------------------------------------
|
|
2737
2919
|
// Mathematical operations
|
|
2738
2920
|
// ------------------------------------------
|
|
2739
|
-
a(this, "isOnLine", (e) => i(this,
|
|
2740
|
-
i(this,
|
|
2741
|
-
).add(i(this,
|
|
2921
|
+
a(this, "isOnLine", (e) => i(this, S).clone().multiply(e.x).add(
|
|
2922
|
+
i(this, z).clone().multiply(e.y)
|
|
2923
|
+
).add(i(this, U)).isZero());
|
|
2742
2924
|
a(this, "isParallelTo", (e) => this.slope.isEqual(e.slope) && this.height.isNotEqual(e.height));
|
|
2743
2925
|
a(this, "isSameAs", (e) => this.slope.isEqual(e.slope) && this.height.isEqual(e.height));
|
|
2744
2926
|
a(this, "isPerpendicularTo", (e) => this.d.isNormalTo(e.d));
|
|
2745
2927
|
a(this, "isVertical", () => this.slope.isInfinity());
|
|
2746
2928
|
a(this, "simplify", () => {
|
|
2747
|
-
const e =
|
|
2929
|
+
const e = G.lcm(i(this, S).denominator, i(this, z).denominator, i(this, U).denominator), t = G.gcd(i(this, S).numerator, i(this, z).numerator, i(this, U).numerator);
|
|
2748
2930
|
return this.parseByCoefficient(
|
|
2749
|
-
i(this, R).clone().multiply(e).divide(t),
|
|
2750
2931
|
i(this, S).clone().multiply(e).divide(t),
|
|
2751
|
-
i(this,
|
|
2932
|
+
i(this, z).clone().multiply(e).divide(t),
|
|
2933
|
+
i(this, U).clone().multiply(e).divide(t)
|
|
2752
2934
|
), this;
|
|
2753
2935
|
});
|
|
2754
|
-
a(this, "simplifyDirection", () => (i(this,
|
|
2936
|
+
a(this, "simplifyDirection", () => (i(this, Y).simplify(), this));
|
|
2755
2937
|
a(this, "intersection", (e) => {
|
|
2756
|
-
const t = new
|
|
2938
|
+
const t = new x();
|
|
2757
2939
|
let s = !1, r = !1;
|
|
2758
|
-
return i(this,
|
|
2940
|
+
return i(this, z).isZero() || e.b.isZero(), this.isParallelTo(e) ? (t.x = new c().invalid(), t.y = new c().invalid(), s = !0) : this.isSameAs(e) ? (t.x = new c().invalid(), t.y = new c().invalid(), r = !0) : (t.x = i(this, z).clone().multiply(e.c).subtract(i(this, U).clone().multiply(e.b)).divide(i(this, S).clone().multiply(e.b).subtract(i(this, z).clone().multiply(e.a))), t.y = i(this, S).clone().multiply(e.c).subtract(i(this, U).clone().multiply(e.a)).divide(i(this, z).clone().multiply(e.a).subtract(i(this, S).clone().multiply(e.b)))), {
|
|
2759
2941
|
point: t,
|
|
2760
2942
|
hasIntersection: !(s || r),
|
|
2761
2943
|
isParallel: s,
|
|
@@ -2764,53 +2946,53 @@ const Re = class Re {
|
|
|
2764
2946
|
});
|
|
2765
2947
|
a(this, "getValueAtX", (e) => {
|
|
2766
2948
|
const t = this.getEquation().isolate("y"), s = new c(e);
|
|
2767
|
-
return t instanceof
|
|
2949
|
+
return t instanceof H ? t.right.evaluate({ x: s }) : new c().invalid();
|
|
2768
2950
|
});
|
|
2769
2951
|
a(this, "getValueAtY", (e) => {
|
|
2770
2952
|
const t = this.getEquation().isolate("x"), s = new c(e);
|
|
2771
|
-
return t instanceof
|
|
2953
|
+
return t instanceof H ? t.right.evaluate({ y: s }) : new c().invalid();
|
|
2772
2954
|
});
|
|
2773
|
-
return h(this,
|
|
2955
|
+
return h(this, S, new c().zero()), h(this, z, new c().zero()), h(this, U, new c().zero()), h(this, ne, new x()), h(this, Y, new x()), h(this, $e, new x()), h(this, Ce, !0), e.length > 0 && this.parse(...e), this;
|
|
2774
2956
|
}
|
|
2775
2957
|
get a() {
|
|
2776
|
-
return i(this,
|
|
2958
|
+
return i(this, S);
|
|
2777
2959
|
}
|
|
2778
2960
|
// ------------------------------------------
|
|
2779
2961
|
// Getter and setter
|
|
2780
2962
|
set a(e) {
|
|
2781
|
-
h(this,
|
|
2963
|
+
h(this, S, e);
|
|
2782
2964
|
}
|
|
2783
2965
|
get b() {
|
|
2784
|
-
return i(this,
|
|
2966
|
+
return i(this, z);
|
|
2785
2967
|
}
|
|
2786
2968
|
set b(e) {
|
|
2787
|
-
h(this,
|
|
2969
|
+
h(this, z, e);
|
|
2788
2970
|
}
|
|
2789
2971
|
get c() {
|
|
2790
|
-
return i(this,
|
|
2972
|
+
return i(this, U);
|
|
2791
2973
|
}
|
|
2792
2974
|
set c(e) {
|
|
2793
|
-
h(this,
|
|
2975
|
+
h(this, U, e);
|
|
2794
2976
|
}
|
|
2795
2977
|
get OA() {
|
|
2796
|
-
return i(this,
|
|
2978
|
+
return i(this, ne);
|
|
2797
2979
|
}
|
|
2798
2980
|
set OA(e) {
|
|
2799
|
-
h(this,
|
|
2981
|
+
h(this, ne, e);
|
|
2800
2982
|
}
|
|
2801
2983
|
get d() {
|
|
2802
|
-
return i(this,
|
|
2984
|
+
return i(this, Y);
|
|
2803
2985
|
}
|
|
2804
2986
|
set d(e) {
|
|
2805
|
-
h(this,
|
|
2987
|
+
h(this, Y, e);
|
|
2806
2988
|
}
|
|
2807
2989
|
get n() {
|
|
2808
|
-
return i(this,
|
|
2990
|
+
return i(this, $e);
|
|
2809
2991
|
}
|
|
2810
2992
|
// ------------------------------------------
|
|
2811
2993
|
getEquation() {
|
|
2812
|
-
const e = new
|
|
2813
|
-
return i(this,
|
|
2994
|
+
const e = new H(new T().parse("xy", i(this, S), i(this, z), i(this, U)), new T("0"));
|
|
2995
|
+
return i(this, Ce) ? e.simplify() : e;
|
|
2814
2996
|
}
|
|
2815
2997
|
// get system(): { x: Equation, y: Equation } {
|
|
2816
2998
|
// const e1 = new Equation(
|
|
@@ -2826,78 +3008,78 @@ const Re = class Re {
|
|
|
2826
3008
|
// return { x: e1, y: e2 }
|
|
2827
3009
|
// }
|
|
2828
3010
|
get canonical() {
|
|
2829
|
-
return h(this,
|
|
3011
|
+
return h(this, ve, "canonical"), this;
|
|
2830
3012
|
}
|
|
2831
3013
|
get equation() {
|
|
2832
|
-
return h(this,
|
|
3014
|
+
return h(this, ve, "equation"), this;
|
|
2833
3015
|
}
|
|
2834
3016
|
get mxh() {
|
|
2835
|
-
return h(this,
|
|
3017
|
+
return h(this, ve, "mxh"), this;
|
|
2836
3018
|
}
|
|
2837
3019
|
get parametric() {
|
|
2838
|
-
return h(this,
|
|
3020
|
+
return h(this, ve, "parametric"), this;
|
|
2839
3021
|
}
|
|
2840
3022
|
get system() {
|
|
2841
|
-
return h(this,
|
|
3023
|
+
return h(this, ve, "system"), this;
|
|
2842
3024
|
}
|
|
2843
3025
|
get tex() {
|
|
2844
|
-
const e = i(this,
|
|
2845
|
-
switch (h(this,
|
|
3026
|
+
const e = i(this, ve);
|
|
3027
|
+
switch (h(this, ve, "canonical"), e) {
|
|
2846
3028
|
case "equation":
|
|
2847
3029
|
return this.getEquation().reorder().tex;
|
|
2848
3030
|
case "mxh":
|
|
2849
|
-
return this.slope.isInfinity() ? "x=" + this.OA.x.tex : "y=" + new
|
|
3031
|
+
return this.slope.isInfinity() ? "x=" + this.OA.x.tex : "y=" + new T().parse("x", this.slope, this.height).tex;
|
|
2850
3032
|
case "parametric":
|
|
2851
3033
|
case "system": {
|
|
2852
|
-
const t = i(this,
|
|
2853
|
-
return i(this,
|
|
2854
|
-
x &= ${new
|
|
2855
|
-
y &= ${new
|
|
3034
|
+
const t = i(this, Y).clone();
|
|
3035
|
+
return i(this, Ce) && t.simplify(), e === "parametric" ? `${x.asTex("x", "y")} = ${x.asTex(i(this, ne).x.tex, i(this, ne).y.tex)} + k\\cdot ${x.asTex(t.x.tex, t.y.tex)}` : `\\left\\{\\begin{aligned}
|
|
3036
|
+
x &= ${new T(i(this, ne).x).add(new I(i(this, Y).x).multiply(new I("k"))).reorder("k", !0).tex}\\\\
|
|
3037
|
+
y &= ${new T(i(this, ne).y).add(new I(i(this, Y).y).multiply(new I("k"))).reorder("k", !0).tex}
|
|
2856
3038
|
\\end{aligned}\\right.`;
|
|
2857
3039
|
}
|
|
2858
3040
|
default: {
|
|
2859
3041
|
const t = this.getEquation();
|
|
2860
|
-
return i(this,
|
|
3042
|
+
return i(this, S).isNegative() && t.multiply(-1), t.tex;
|
|
2861
3043
|
}
|
|
2862
3044
|
}
|
|
2863
3045
|
}
|
|
2864
3046
|
get reduceBeforeDisplay() {
|
|
2865
|
-
return i(this,
|
|
3047
|
+
return i(this, Ce);
|
|
2866
3048
|
}
|
|
2867
3049
|
set reduceBeforeDisplay(e) {
|
|
2868
|
-
h(this,
|
|
3050
|
+
h(this, Ce, e);
|
|
2869
3051
|
}
|
|
2870
3052
|
get display() {
|
|
2871
|
-
const e = i(this,
|
|
2872
|
-
switch (h(this,
|
|
3053
|
+
const e = i(this, ve);
|
|
3054
|
+
switch (h(this, ve, "canonical"), e) {
|
|
2873
3055
|
case "equation":
|
|
2874
3056
|
return this.getEquation().reorder().display;
|
|
2875
3057
|
case "mxh":
|
|
2876
|
-
return this.slope.isInfinity() ? "x=" + this.OA.x.display : "y=" + new
|
|
3058
|
+
return this.slope.isInfinity() ? "x=" + this.OA.x.display : "y=" + new T().parse("x", this.slope, this.height).display;
|
|
2877
3059
|
case "parametric": {
|
|
2878
|
-
const t = i(this,
|
|
2879
|
-
return i(this,
|
|
3060
|
+
const t = i(this, Y).clone();
|
|
3061
|
+
return i(this, Ce) && t.simplify(), `((x,y))=((${i(this, ne).x.display},${i(this, ne).y.display}))+k((${t.x.display},${t.y.display}))`;
|
|
2880
3062
|
}
|
|
2881
3063
|
default: {
|
|
2882
3064
|
const t = this.getEquation();
|
|
2883
|
-
return i(this,
|
|
3065
|
+
return i(this, S).isNegative() && t.multiply(-1), t.display;
|
|
2884
3066
|
}
|
|
2885
3067
|
}
|
|
2886
3068
|
}
|
|
2887
3069
|
get normal() {
|
|
2888
|
-
return new
|
|
3070
|
+
return new x(i(this, S), i(this, z));
|
|
2889
3071
|
}
|
|
2890
3072
|
get director() {
|
|
2891
|
-
return i(this,
|
|
3073
|
+
return i(this, Y).clone();
|
|
2892
3074
|
}
|
|
2893
3075
|
get slope() {
|
|
2894
|
-
return i(this,
|
|
3076
|
+
return i(this, S).clone().opposite().divide(i(this, z));
|
|
2895
3077
|
}
|
|
2896
3078
|
get height() {
|
|
2897
|
-
return i(this,
|
|
3079
|
+
return i(this, U).clone().opposite().divide(i(this, z));
|
|
2898
3080
|
}
|
|
2899
3081
|
distanceTo(e) {
|
|
2900
|
-
const t = e.x.clone().multiply(i(this,
|
|
3082
|
+
const t = e.x.clone().multiply(i(this, S)).add(e.y.clone().multiply(i(this, z))).add(i(this, U)).abs(), s = this.normal.normSquare;
|
|
2901
3083
|
if (s.isZero())
|
|
2902
3084
|
return {
|
|
2903
3085
|
value: NaN,
|
|
@@ -2917,7 +3099,7 @@ const Re = class Re {
|
|
|
2917
3099
|
}
|
|
2918
3100
|
hitSegment(e, t) {
|
|
2919
3101
|
const s = this.intersection(
|
|
2920
|
-
new
|
|
3102
|
+
new Le(e, t)
|
|
2921
3103
|
);
|
|
2922
3104
|
return s.hasIntersection ? s.point.x.value >= Math.min(e.x.value, t.x.value) && s.point.x.value <= Math.max(e.x.value, t.x.value) && s.point.y.value >= Math.min(e.y.value, t.y.value) && s.point.y.value <= Math.max(e.y.value, t.y.value) : !1;
|
|
2923
3105
|
}
|
|
@@ -2927,88 +3109,88 @@ const Re = class Re {
|
|
|
2927
3109
|
canonicalAsFloatCoefficient(e) {
|
|
2928
3110
|
e === void 0 && (e = 2);
|
|
2929
3111
|
let t = "";
|
|
2930
|
-
return i(this,
|
|
3112
|
+
return i(this, S).isZero() || (i(this, S).isOne() ? t = "x" : i(this, S).clone().opposite().isOne() ? t = "-x" : t = i(this, S).value.toFixed(e) + "x"), i(this, z).isZero() || (i(this, z).isPositive() && (t += "+"), t += i(this, z).value.toFixed(e) + "y"), i(this, U).isZero() || (i(this, U).isPositive() && (t += "+"), t += i(this, U).value.toFixed(e)), t + "=0";
|
|
2931
3113
|
}
|
|
2932
3114
|
};
|
|
2933
|
-
|
|
2934
|
-
a(
|
|
2935
|
-
let
|
|
2936
|
-
var
|
|
2937
|
-
const
|
|
3115
|
+
Ce = new WeakMap(), S = new WeakMap(), z = new WeakMap(), U = new WeakMap(), ne = new WeakMap(), Y = new WeakMap(), $e = new WeakMap(), ve = new WeakMap(), // A line is defined as the canonical form
|
|
3116
|
+
a(Le, "PERPENDICULAR", "perpendicular"), a(Le, "PARALLEL", "parallel");
|
|
3117
|
+
let j = Le;
|
|
3118
|
+
var oe, F, qe, kt, Lt, Dt, he, vi, mt, bi, xi, Ei, Kt;
|
|
3119
|
+
const Zt = class Zt {
|
|
2938
3120
|
constructor(...e) {
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
3121
|
+
f(this, he);
|
|
3122
|
+
f(this, oe);
|
|
3123
|
+
f(this, F);
|
|
3124
|
+
f(this, qe);
|
|
2943
3125
|
/**
|
|
2944
3126
|
* Get the relative position between circle and line. It corresponds to the number of intersection.
|
|
2945
3127
|
* @param {Line} L
|
|
2946
3128
|
* @returns {number}
|
|
2947
3129
|
*/
|
|
2948
3130
|
a(this, "relativePosition", (e) => {
|
|
2949
|
-
if (i(this,
|
|
3131
|
+
if (i(this, oe) === void 0 || i(this, F) === void 0)
|
|
2950
3132
|
throw new Error("Circle not defined");
|
|
2951
|
-
const t = e.distanceTo(i(this,
|
|
3133
|
+
const t = e.distanceTo(i(this, oe)), s = Math.sqrt(i(this, F).value);
|
|
2952
3134
|
return t.value - s > 1e-10 ? 0 : Math.abs(t.value - s) < 1e-10 ? 1 : 2;
|
|
2953
3135
|
});
|
|
2954
3136
|
a(this, "lineIntersection", (e) => {
|
|
2955
3137
|
const t = [];
|
|
2956
|
-
if (i(this,
|
|
3138
|
+
if (i(this, qe) === void 0)
|
|
2957
3139
|
return [];
|
|
2958
|
-
const s = i(this,
|
|
2959
|
-
return r instanceof
|
|
3140
|
+
const s = i(this, qe).clone(), r = e.getEquation().clone().isolate("x"), n = e.getEquation().clone().isolate("y");
|
|
3141
|
+
return r instanceof H && n instanceof H && (s.replaceBy("y", n.right).simplify(), s.solve()), t;
|
|
2960
3142
|
});
|
|
2961
|
-
a(this, "tangents", (e) => e instanceof c ? i(this,
|
|
3143
|
+
a(this, "tangents", (e) => e instanceof c ? i(this, Dt).call(this, e) : this.isPointOnCircle(e) ? i(this, kt).call(this, e) : i(this, oe) !== void 0 && i(this, oe).distanceTo(e).value > this.radius.value ? (i(this, Lt).call(this, e), []) : (console.log("No tangents as the point is inside !"), []));
|
|
2962
3144
|
a(this, "isPointOnCircle", (e) => {
|
|
2963
3145
|
var t;
|
|
2964
|
-
return ((t = i(this,
|
|
3146
|
+
return ((t = i(this, qe)) == null ? void 0 : t.test({ x: e.x, y: e.y })) ?? !1;
|
|
2965
3147
|
});
|
|
2966
3148
|
a(this, "getPointsOnCircle", (e) => {
|
|
2967
|
-
const t =
|
|
3149
|
+
const t = G.pythagoreanTripletsWithTarget(this.squareRadius.value, !0), s = [];
|
|
2968
3150
|
return t.forEach((r) => {
|
|
2969
3151
|
for (const n of [[1, 1], [-1, 1], [-1, -1], [1, -1]])
|
|
2970
3152
|
s.push(
|
|
2971
|
-
new
|
|
3153
|
+
new R(
|
|
2972
3154
|
this.center.x.clone().add(n[0] * r[0]),
|
|
2973
3155
|
this.center.y.clone().add(n[1] * r[1])
|
|
2974
3156
|
)
|
|
2975
3157
|
);
|
|
2976
3158
|
}), s;
|
|
2977
3159
|
});
|
|
2978
|
-
|
|
2979
|
-
const t = new
|
|
2980
|
-
return [new
|
|
3160
|
+
f(this, kt, (e) => {
|
|
3161
|
+
const t = new R(this.center, e);
|
|
3162
|
+
return [new j(e, t, wi.Perpendicular)];
|
|
2981
3163
|
});
|
|
2982
|
-
|
|
2983
|
-
const t = this.center.x.clone().subtract(e.x), s = this.center.y.clone().subtract(e.y), r = new
|
|
2984
|
-
r.multiply(t).subtract(s).pow(2), n.multiply(this.squareRadius), new
|
|
3164
|
+
f(this, Lt, (e) => {
|
|
3165
|
+
const t = this.center.x.clone().subtract(e.x), s = this.center.y.clone().subtract(e.y), r = new T("x"), n = new T("x^2+1");
|
|
3166
|
+
r.multiply(t).subtract(s).pow(2), n.multiply(this.squareRadius), new H(r, n).moveLeft().simplify().solve();
|
|
2985
3167
|
});
|
|
2986
|
-
|
|
2987
|
-
const t = e.numerator, s = -e.denominator, r = this.center.x.clone(), n = this.center.y.clone(), l = this.squareRadius.clone().multiply(e.numerator ** 2 + e.denominator ** 2), u = r.clone().multiply(t).opposite().subtract(n.clone().multiply(s)).add(l.clone().sqrt()),
|
|
2988
|
-
return [new
|
|
3168
|
+
f(this, Dt, (e) => {
|
|
3169
|
+
const t = e.numerator, s = -e.denominator, r = this.center.x.clone(), n = this.center.y.clone(), l = this.squareRadius.clone().multiply(e.numerator ** 2 + e.denominator ** 2), u = r.clone().multiply(t).opposite().subtract(n.clone().multiply(s)).add(l.clone().sqrt()), p = r.clone().multiply(t).opposite().subtract(n.clone().multiply(s)).subtract(l.clone().sqrt());
|
|
3170
|
+
return [new j(t, s, u), new j(t, s, p)];
|
|
2989
3171
|
});
|
|
2990
3172
|
e.length > 0 && this.parse(...e);
|
|
2991
3173
|
}
|
|
2992
3174
|
get center() {
|
|
2993
|
-
return i(this,
|
|
3175
|
+
return i(this, oe) ?? new R();
|
|
2994
3176
|
}
|
|
2995
3177
|
get squareRadius() {
|
|
2996
|
-
return i(this,
|
|
3178
|
+
return i(this, F) ?? new c(0);
|
|
2997
3179
|
}
|
|
2998
3180
|
get cartesian() {
|
|
2999
|
-
if (i(this,
|
|
3181
|
+
if (i(this, qe) === void 0)
|
|
3000
3182
|
throw new Error("Cartesian equation not defined");
|
|
3001
|
-
return i(this,
|
|
3183
|
+
return i(this, qe);
|
|
3002
3184
|
}
|
|
3003
3185
|
get radius() {
|
|
3004
|
-
return i(this,
|
|
3005
|
-
tex: i(this,
|
|
3006
|
-
display: i(this,
|
|
3007
|
-
value: i(this,
|
|
3186
|
+
return i(this, F) === void 0 ? { tex: "", display: "", value: 0 } : i(this, F).isSquare() ? {
|
|
3187
|
+
tex: i(this, F).clone().sqrt().tex,
|
|
3188
|
+
display: i(this, F).clone().sqrt().display,
|
|
3189
|
+
value: i(this, F).clone().sqrt().value
|
|
3008
3190
|
} : {
|
|
3009
|
-
tex: `\\sqrt{${i(this,
|
|
3010
|
-
display: `sqrt(${i(this,
|
|
3011
|
-
value: i(this,
|
|
3191
|
+
tex: `\\sqrt{${i(this, F).tex}}`,
|
|
3192
|
+
display: `sqrt(${i(this, F).display})`,
|
|
3193
|
+
value: i(this, F).clone().sqrt().value
|
|
3012
3194
|
};
|
|
3013
3195
|
}
|
|
3014
3196
|
get tex() {
|
|
@@ -3023,17 +3205,17 @@ const $t = class $t {
|
|
|
3023
3205
|
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}`;
|
|
3024
3206
|
}
|
|
3025
3207
|
clone() {
|
|
3026
|
-
return new
|
|
3208
|
+
return new Zt(
|
|
3027
3209
|
this.center.clone(),
|
|
3028
3210
|
this.squareRadius.clone(),
|
|
3029
3211
|
!0
|
|
3030
3212
|
);
|
|
3031
3213
|
}
|
|
3032
3214
|
setRadius(e, t) {
|
|
3033
|
-
return t ? h(this,
|
|
3215
|
+
return t ? h(this, F, new c(e)) : h(this, F, new c(e).pow(2)), M(this, he, mt).call(this), this;
|
|
3034
3216
|
}
|
|
3035
3217
|
parse(...e) {
|
|
3036
|
-
return
|
|
3218
|
+
return M(this, he, vi).call(this), typeof e[0] == "string" ? M(this, he, Kt).call(this, new H(e[0])) : e[0] instanceof H ? M(this, he, Kt).call(this, e[0]) : e[0] instanceof Zt ? M(this, he, bi).call(this, e[0]) : e[0] instanceof R && e.length > 1 && (e[1] instanceof R ? e[2] instanceof R || M(this, he, Ei).call(this, e[0], e[1]) : (e[1] instanceof c || typeof e[1] == "number") && M(this, he, xi).call(this, e[0], e[1], typeof e[2] == "boolean" ? e[2] : !1)), M(this, he, mt).call(this), this;
|
|
3037
3219
|
}
|
|
3038
3220
|
// private _parseThroughtThreePoints(A: Point, B: Point, C: Point): this {
|
|
3039
3221
|
// const T = new Triangle(A, B, C), mAB = T.remarquables.mediators.AB.clone(),
|
|
@@ -3042,37 +3224,37 @@ const $t = class $t {
|
|
|
3042
3224
|
// return this
|
|
3043
3225
|
// }
|
|
3044
3226
|
};
|
|
3045
|
-
|
|
3046
|
-
return h(this,
|
|
3047
|
-
},
|
|
3048
|
-
h(this,
|
|
3049
|
-
new
|
|
3050
|
-
new
|
|
3227
|
+
oe = new WeakMap(), F = new WeakMap(), qe = new WeakMap(), kt = new WeakMap(), Lt = new WeakMap(), Dt = new WeakMap(), he = new WeakSet(), vi = function() {
|
|
3228
|
+
return h(this, oe, void 0), h(this, F, void 0), h(this, qe, void 0), this;
|
|
3229
|
+
}, mt = function() {
|
|
3230
|
+
h(this, qe, new H(
|
|
3231
|
+
new T(`(x-(${this.center.x.display}))^2+(y-(${this.center.y.display}))^2`),
|
|
3232
|
+
new T(this.squareRadius.display)
|
|
3051
3233
|
).moveLeft());
|
|
3052
|
-
},
|
|
3053
|
-
return h(this,
|
|
3054
|
-
},
|
|
3055
|
-
return h(this,
|
|
3056
|
-
},
|
|
3057
|
-
return h(this,
|
|
3058
|
-
},
|
|
3234
|
+
}, bi = function(e) {
|
|
3235
|
+
return h(this, oe, e.center.clone()), h(this, F, e.squareRadius.clone()), M(this, he, mt).call(this), this;
|
|
3236
|
+
}, xi = function(e, t, s) {
|
|
3237
|
+
return h(this, oe, e.clone()), s ? h(this, F, new c(t)) : h(this, F, new c(t).pow(2)), this;
|
|
3238
|
+
}, Ei = function(e, t) {
|
|
3239
|
+
return h(this, oe, e.clone()), h(this, F, new x(i(this, oe), t).normSquare), this;
|
|
3240
|
+
}, Kt = function(e) {
|
|
3059
3241
|
if (e.moveLeft(), e.degree("x").value === 2 && e.degree("y").value === 2) {
|
|
3060
3242
|
const t = e.left.monomByDegree(2, "x"), s = e.left.monomByDegree(2, "y");
|
|
3061
3243
|
let r, n, l;
|
|
3062
|
-
t.coefficient.isEqual(s.coefficient) ? (e.divide(t.coefficient), r = e.left.monomByDegree(1, "x"), n = e.left.monomByDegree(1, "y"), l = e.left.monomByDegree(0), h(this,
|
|
3244
|
+
t.coefficient.isEqual(s.coefficient) ? (e.divide(t.coefficient), r = e.left.monomByDegree(1, "x"), n = e.left.monomByDegree(1, "y"), l = e.left.monomByDegree(0), h(this, oe, new R(r.coefficient.clone().divide(2).opposite(), n.coefficient.clone().divide(2).opposite())), h(this, F, l.coefficient.clone().opposite().add(i(this, oe).x.clone().pow(2)).add(i(this, oe).y.clone().pow(2)))) : (h(this, oe, void 0), h(this, F, void 0));
|
|
3063
3245
|
}
|
|
3064
3246
|
return this;
|
|
3065
3247
|
};
|
|
3066
|
-
let
|
|
3067
|
-
var
|
|
3068
|
-
const
|
|
3248
|
+
let gt = Zt;
|
|
3249
|
+
var Q, _, ee, Je, Te, ct, Vt, ut, Be, Ft, _e;
|
|
3250
|
+
const jt = class jt {
|
|
3069
3251
|
constructor(...e) {
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3252
|
+
f(this, Q);
|
|
3253
|
+
f(this, _);
|
|
3254
|
+
f(this, ee);
|
|
3255
|
+
f(this, Je);
|
|
3256
|
+
f(this, Te);
|
|
3257
|
+
f(this, ct);
|
|
3076
3258
|
// ------------------------------------------
|
|
3077
3259
|
// Creation / parsing functions
|
|
3078
3260
|
// ------------------------------------------
|
|
@@ -3089,45 +3271,45 @@ const Rt = class Rt {
|
|
|
3089
3271
|
if (t.some((s) => s.isNaN()))
|
|
3090
3272
|
throw new Error("One of the values is not a valid number");
|
|
3091
3273
|
return this.parse(
|
|
3092
|
-
new
|
|
3093
|
-
new
|
|
3094
|
-
new
|
|
3274
|
+
new x(t[0], t[1]),
|
|
3275
|
+
new x(t[2], t[3]),
|
|
3276
|
+
new x(t[4], t[5])
|
|
3095
3277
|
);
|
|
3096
3278
|
} else if (e.length === 3) {
|
|
3097
3279
|
if (e.every((t) => typeof t == "string"))
|
|
3098
|
-
return this.parse(...e.map((t) => new
|
|
3099
|
-
if (e.every((t) => t instanceof
|
|
3280
|
+
return this.parse(...e.map((t) => new j(t)));
|
|
3281
|
+
if (e.every((t) => t instanceof j)) {
|
|
3100
3282
|
const t = e[0].clone(), s = e[1].clone(), r = e[2].clone();
|
|
3101
|
-
h(this,
|
|
3283
|
+
h(this, Je, { AB: t, BC: s, AC: r });
|
|
3102
3284
|
let n = t.intersection(s);
|
|
3103
3285
|
if (n.hasIntersection)
|
|
3104
|
-
h(this,
|
|
3286
|
+
h(this, _, n.point.clone());
|
|
3105
3287
|
else
|
|
3106
3288
|
throw new Error("Lines do not intersect !");
|
|
3107
3289
|
if (n = s.intersection(r), n.hasIntersection)
|
|
3108
|
-
h(this,
|
|
3290
|
+
h(this, ee, n.point.clone());
|
|
3109
3291
|
else
|
|
3110
3292
|
throw new Error("Lines do not intersect !");
|
|
3111
3293
|
if (n = r.intersection(t), n.hasIntersection)
|
|
3112
|
-
h(this,
|
|
3294
|
+
h(this, Q, n.point.clone());
|
|
3113
3295
|
else
|
|
3114
3296
|
throw new Error("Lines do not intersect !");
|
|
3115
|
-
} else e.every((t) => t instanceof
|
|
3116
|
-
AB: new
|
|
3117
|
-
BC: new
|
|
3118
|
-
AC: new
|
|
3297
|
+
} else e.every((t) => t instanceof R) && (h(this, Q, e[0].clone()), h(this, _, e[1].clone()), h(this, ee, e[2].clone()), h(this, Je, {
|
|
3298
|
+
AB: new j(i(this, Q), i(this, _)),
|
|
3299
|
+
BC: new j(i(this, _), i(this, ee)),
|
|
3300
|
+
AC: new j(i(this, Q), i(this, ee))
|
|
3119
3301
|
}));
|
|
3120
|
-
} else if (e.length === 1 && e[0] instanceof
|
|
3302
|
+
} else if (e.length === 1 && e[0] instanceof jt)
|
|
3121
3303
|
return e[0].clone();
|
|
3122
|
-
return i(this,
|
|
3304
|
+
return i(this, Vt).call(this), this;
|
|
3123
3305
|
});
|
|
3124
3306
|
/**
|
|
3125
3307
|
* Clone the Triangle class
|
|
3126
3308
|
*/
|
|
3127
|
-
a(this, "clone", () => new
|
|
3128
|
-
i(this,
|
|
3129
|
-
i(this,
|
|
3130
|
-
i(this,
|
|
3309
|
+
a(this, "clone", () => new jt(
|
|
3310
|
+
i(this, Q).clone(),
|
|
3311
|
+
i(this, _).clone(),
|
|
3312
|
+
i(this, ee).clone()
|
|
3131
3313
|
));
|
|
3132
3314
|
// ------------------------------------------
|
|
3133
3315
|
// Triangle operations and properties
|
|
@@ -3135,79 +3317,79 @@ const Rt = class Rt {
|
|
|
3135
3317
|
/**
|
|
3136
3318
|
* Generate the Line object for the three segments of the triangle
|
|
3137
3319
|
*/
|
|
3138
|
-
|
|
3320
|
+
f(this, Vt, () => {
|
|
3139
3321
|
h(this, Te, {
|
|
3140
|
-
AB: new
|
|
3141
|
-
AC: new
|
|
3142
|
-
BC: new
|
|
3143
|
-
}), h(this,
|
|
3322
|
+
AB: new R().middleOf(i(this, Q), i(this, _)),
|
|
3323
|
+
AC: new R().middleOf(i(this, Q), i(this, ee)),
|
|
3324
|
+
BC: new R().middleOf(i(this, _), i(this, ee))
|
|
3325
|
+
}), h(this, ct, i(this, Ft).call(this));
|
|
3144
3326
|
});
|
|
3145
3327
|
/**
|
|
3146
3328
|
* Get the Vector2D class for the given name
|
|
3147
3329
|
* @param ptName
|
|
3148
3330
|
*/
|
|
3149
|
-
|
|
3331
|
+
f(this, ut, (e) => {
|
|
3150
3332
|
switch (e.toUpperCase()) {
|
|
3151
3333
|
case "A":
|
|
3152
|
-
return i(this,
|
|
3334
|
+
return i(this, Q);
|
|
3153
3335
|
case "B":
|
|
3154
|
-
return i(this,
|
|
3336
|
+
return i(this, _);
|
|
3155
3337
|
case "C":
|
|
3156
|
-
return i(this,
|
|
3338
|
+
return i(this, ee);
|
|
3157
3339
|
}
|
|
3158
|
-
return i(this,
|
|
3340
|
+
return i(this, Q);
|
|
3159
3341
|
});
|
|
3160
3342
|
/**
|
|
3161
3343
|
* Get the vector for the segment given by name.
|
|
3162
3344
|
* @param ptName1
|
|
3163
3345
|
* @param ptName2
|
|
3164
3346
|
*/
|
|
3165
|
-
|
|
3166
|
-
i(this,
|
|
3167
|
-
i(this,
|
|
3347
|
+
f(this, Be, (e, t) => new x(
|
|
3348
|
+
i(this, ut).call(this, e),
|
|
3349
|
+
i(this, ut).call(this, t)
|
|
3168
3350
|
));
|
|
3169
|
-
|
|
3351
|
+
f(this, Ft, () => {
|
|
3170
3352
|
const e = {
|
|
3171
|
-
A: new
|
|
3172
|
-
B: new
|
|
3173
|
-
C: new
|
|
3353
|
+
A: new j(i(this, Q), i(this, Te).BC),
|
|
3354
|
+
B: new j(i(this, _), i(this, Te).AC),
|
|
3355
|
+
C: new j(i(this, ee), i(this, Te).AB),
|
|
3174
3356
|
intersection: null
|
|
3175
3357
|
}, t = {
|
|
3176
|
-
AB: new
|
|
3177
|
-
AC: new
|
|
3178
|
-
BC: new
|
|
3358
|
+
AB: new j(i(this, Te).AB, new x(i(this, Q), i(this, _)).normal()),
|
|
3359
|
+
AC: new j(i(this, Te).AC, new x(i(this, Q), i(this, ee)).normal()),
|
|
3360
|
+
BC: new j(i(this, Te).BC, new x(i(this, _), i(this, ee)).normal()),
|
|
3179
3361
|
intersection: null
|
|
3180
3362
|
}, s = {
|
|
3181
|
-
A: new
|
|
3182
|
-
B: new
|
|
3183
|
-
C: new
|
|
3363
|
+
A: new j(i(this, Q), new x(i(this, _), i(this, ee)).normal()),
|
|
3364
|
+
B: new j(i(this, _), new x(i(this, Q), i(this, ee)).normal()),
|
|
3365
|
+
C: new j(i(this, ee), new x(i(this, Q), i(this, _)).normal()),
|
|
3184
3366
|
intersection: null
|
|
3185
|
-
}, r = i(this,
|
|
3367
|
+
}, r = i(this, _e).call(this, "A"), n = i(this, _e).call(this, "B"), l = i(this, _e).call(this, "C"), u = {
|
|
3186
3368
|
A: r.internal,
|
|
3187
3369
|
B: n.internal,
|
|
3188
3370
|
C: n.internal,
|
|
3189
3371
|
intersection: null
|
|
3190
|
-
},
|
|
3372
|
+
}, p = {
|
|
3191
3373
|
A: r.external,
|
|
3192
3374
|
B: n.external,
|
|
3193
3375
|
C: l.external,
|
|
3194
3376
|
intersection: null
|
|
3195
|
-
},
|
|
3377
|
+
}, m = {
|
|
3196
3378
|
medians: e,
|
|
3197
3379
|
mediators: t,
|
|
3198
3380
|
heights: s,
|
|
3199
3381
|
bisectors: u,
|
|
3200
|
-
externalBisectors:
|
|
3382
|
+
externalBisectors: p
|
|
3201
3383
|
};
|
|
3202
|
-
return
|
|
3384
|
+
return m.medians.intersection = m.medians.A.intersection(m.medians.B).point, m.mediators.intersection = m.mediators.AB.intersection(m.mediators.BC).point, m.heights.intersection = m.heights.A.intersection(m.heights.B).point, m.bisectors.intersection = m.bisectors.A.intersection(m.bisectors.B).point, m;
|
|
3203
3385
|
});
|
|
3204
|
-
|
|
3386
|
+
f(this, _e, (e) => {
|
|
3205
3387
|
const t = this.lines;
|
|
3206
3388
|
let s, r;
|
|
3207
3389
|
if (e === "A" ? (s = t.AB, r = t.AC) : e === "B" ? (s = t.AB, r = t.BC) : e === "C" && (s = t.BC, r = t.AC), s === void 0 || r === void 0)
|
|
3208
3390
|
throw new Error(`The point ${e} does not exist`);
|
|
3209
|
-
const n = s.n.simplify().norm, l = r.n.simplify().norm, u = s.getEquation().multiply(l),
|
|
3210
|
-
return e === "A" ?
|
|
3391
|
+
const n = s.n.simplify().norm, l = r.n.simplify().norm, u = s.getEquation().multiply(l), p = r.getEquation().multiply(n), m = new j(u.clone().subtract(p).simplify()), y = new j(p.clone().subtract(u).simplify());
|
|
3392
|
+
return e === "A" ? m.hitSegment(this.B, this.C) ? { internal: m, external: y } : { internal: y, external: m } : e === "B" ? m.hitSegment(this.A, this.C) ? { internal: m, external: y } : { internal: y, external: m } : e === "C" ? m.hitSegment(this.B, this.A) ? { internal: m, external: y } : { internal: y, external: m } : { internal: m, external: y };
|
|
3211
3393
|
});
|
|
3212
3394
|
return e.length > 0 && this.parse(...e), this;
|
|
3213
3395
|
}
|
|
@@ -3215,31 +3397,31 @@ const Rt = class Rt {
|
|
|
3215
3397
|
// Getter and setters
|
|
3216
3398
|
// ------------------------------------------
|
|
3217
3399
|
get A() {
|
|
3218
|
-
return i(this,
|
|
3400
|
+
return i(this, Q);
|
|
3219
3401
|
}
|
|
3220
3402
|
get B() {
|
|
3221
|
-
return i(this,
|
|
3403
|
+
return i(this, _);
|
|
3222
3404
|
}
|
|
3223
3405
|
get C() {
|
|
3224
|
-
return i(this,
|
|
3406
|
+
return i(this, ee);
|
|
3225
3407
|
}
|
|
3226
3408
|
get AB() {
|
|
3227
|
-
return i(this,
|
|
3409
|
+
return i(this, Be).call(this, "A", "B");
|
|
3228
3410
|
}
|
|
3229
3411
|
get BA() {
|
|
3230
|
-
return i(this,
|
|
3412
|
+
return i(this, Be).call(this, "B", "A");
|
|
3231
3413
|
}
|
|
3232
3414
|
get BC() {
|
|
3233
|
-
return i(this,
|
|
3415
|
+
return i(this, Be).call(this, "B", "C");
|
|
3234
3416
|
}
|
|
3235
3417
|
get CB() {
|
|
3236
|
-
return i(this,
|
|
3418
|
+
return i(this, Be).call(this, "C", "B");
|
|
3237
3419
|
}
|
|
3238
3420
|
get AC() {
|
|
3239
|
-
return i(this,
|
|
3421
|
+
return i(this, Be).call(this, "A", "C");
|
|
3240
3422
|
}
|
|
3241
3423
|
get CA() {
|
|
3242
|
-
return i(this,
|
|
3424
|
+
return i(this, Be).call(this, "C", "A");
|
|
3243
3425
|
}
|
|
3244
3426
|
get isRectangle() {
|
|
3245
3427
|
return !!(this.AB.isNormalTo(this.BC) || this.AB.isNormalTo(this.AC) || this.BC.isNormalTo(this.AC));
|
|
@@ -3251,15 +3433,243 @@ const Rt = class Rt {
|
|
|
3251
3433
|
return this.AB.normSquare.isEqual(this.BC.normSquare) || this.AB.normSquare.isEqual(this.AC.normSquare) || this.BC.normSquare.isEqual(this.AC.normSquare);
|
|
3252
3434
|
}
|
|
3253
3435
|
get lines() {
|
|
3254
|
-
return i(this,
|
|
3436
|
+
return i(this, Je);
|
|
3255
3437
|
}
|
|
3256
3438
|
get remarquables() {
|
|
3257
|
-
return i(this,
|
|
3439
|
+
return i(this, ct);
|
|
3440
|
+
}
|
|
3441
|
+
};
|
|
3442
|
+
Q = new WeakMap(), _ = new WeakMap(), ee = new WeakMap(), Je = new WeakMap(), Te = new WeakMap(), ct = new WeakMap(), Vt = new WeakMap(), ut = new WeakMap(), Be = new WeakMap(), Ft = new WeakMap(), _e = new WeakMap();
|
|
3443
|
+
let Jt = jt;
|
|
3444
|
+
var k, W;
|
|
3445
|
+
const nt = class nt {
|
|
3446
|
+
constructor(e, t) {
|
|
3447
|
+
// ax + by + c = 0
|
|
3448
|
+
f(this, k, new R());
|
|
3449
|
+
f(this, W, new x());
|
|
3450
|
+
a(this, "clone", () => (h(this, W, i(this, W).clone()), h(this, k, i(this, k).clone()), this));
|
|
3451
|
+
// ------------------------------------------
|
|
3452
|
+
// Mathematical operations
|
|
3453
|
+
// ------------------------------------------
|
|
3454
|
+
a(this, "isOnLine", (e) => !1);
|
|
3455
|
+
a(this, "isParallelTo", (e) => {
|
|
3456
|
+
throw new Error("Method not implemented.");
|
|
3457
|
+
});
|
|
3458
|
+
a(this, "isSameAs", (e) => {
|
|
3459
|
+
throw new Error("Method not implemented.");
|
|
3460
|
+
});
|
|
3461
|
+
a(this, "isPerpendicularTo", (e) => {
|
|
3462
|
+
throw new Error("Method not implemented.");
|
|
3463
|
+
});
|
|
3464
|
+
a(this, "isVertical", () => {
|
|
3465
|
+
throw new Error("Method not implemented.");
|
|
3466
|
+
});
|
|
3467
|
+
a(this, "simplify", () => {
|
|
3468
|
+
throw new Error("Method not implemented.");
|
|
3469
|
+
});
|
|
3470
|
+
a(this, "intersection", (e) => {
|
|
3471
|
+
throw new Error("Method not implemented.");
|
|
3472
|
+
});
|
|
3473
|
+
// getValueAtX = (value: Fraction | number): Fraction => {
|
|
3474
|
+
// const equ = this.equation.clone().isolate('y'),
|
|
3475
|
+
// F = new Fraction(value)
|
|
3476
|
+
// if (equ instanceof Equation) {
|
|
3477
|
+
// return equ.right.evaluate({ x: F }) as Fraction
|
|
3478
|
+
// }
|
|
3479
|
+
// return new Fraction().invalid()
|
|
3480
|
+
// }
|
|
3481
|
+
// getValueAtY = (value: Fraction | number): Fraction => {
|
|
3482
|
+
// const equ = this.equation.clone().isolate('x'),
|
|
3483
|
+
// F = new Fraction(value)
|
|
3484
|
+
// if (equ instanceof Equation) {
|
|
3485
|
+
// return equ.right.evaluate({ y: F }) as Fraction
|
|
3486
|
+
// }
|
|
3487
|
+
// return new Fraction().invalid()
|
|
3488
|
+
// }
|
|
3489
|
+
a(this, "randomPoint", (e = 5) => {
|
|
3490
|
+
const t = i(this, k).clone(), s = new c(X(e, !1));
|
|
3491
|
+
return new R(
|
|
3492
|
+
t.x.clone().add(i(this, W).x.clone().multiply(s)),
|
|
3493
|
+
t.y.clone().add(i(this, W).y.clone().multiply(s)),
|
|
3494
|
+
t.z.clone().add(i(this, W).z.clone().multiply(s))
|
|
3495
|
+
);
|
|
3496
|
+
});
|
|
3497
|
+
return h(this, k, e.clone()), h(this, W, t.asPoint ? new x(e, t) : t.clone()), this;
|
|
3498
|
+
}
|
|
3499
|
+
get OA() {
|
|
3500
|
+
return i(this, k);
|
|
3501
|
+
}
|
|
3502
|
+
set OA(e) {
|
|
3503
|
+
h(this, k, e);
|
|
3504
|
+
}
|
|
3505
|
+
get point() {
|
|
3506
|
+
return i(this, k).clone();
|
|
3507
|
+
}
|
|
3508
|
+
get d() {
|
|
3509
|
+
return i(this, W);
|
|
3510
|
+
}
|
|
3511
|
+
set d(e) {
|
|
3512
|
+
h(this, W, e);
|
|
3513
|
+
}
|
|
3514
|
+
get tex() {
|
|
3515
|
+
return {
|
|
3516
|
+
parametric: `${x.asTex("x", "y", "z")} = ${x.asTex(i(this, k).x.tex, i(this, k).y.tex, i(this, k).z.tex)} + k\\cdot ${x.asTex(i(this, W).x.tex, i(this, W).y.tex, i(this, W).z.tex)}`,
|
|
3517
|
+
system: `\\left\\{\\begin{aligned}
|
|
3518
|
+
x &= ${new T(i(this, k).x).add(new I(i(this, W).x).multiply(new I("k"))).reorder("k", !0).tex}\\\\
|
|
3519
|
+
y &= ${new T(i(this, k).y).add(new I(i(this, W).y).multiply(new I("k"))).reorder("k", !0).tex}\\\\
|
|
3520
|
+
z &= ${new T(i(this, k).z).add(new I(i(this, W).z).multiply(new I("k"))).reorder("k", !0).tex}
|
|
3521
|
+
\\end{aligned}\\right.`,
|
|
3522
|
+
cartesian: `\\frac{ ${new T("x", 1, i(this, k).x.clone().opposite()).tex} }{ ${this.direction.x.tex} } = \\frac{ ${new T("y", 1, i(this, k).y.clone().opposite()).tex} }{ ${this.direction.y.tex} } = \\frac{ ${new T("z", 1, i(this, k).z.clone().opposite()).tex} }{ ${this.direction.z.tex} }`
|
|
3523
|
+
};
|
|
3524
|
+
}
|
|
3525
|
+
get display() {
|
|
3526
|
+
const e = i(this, k).x.display, t = i(this, k).y.display, s = i(this, k).z.display, r = this.direction.simplify(), n = r.x.display, l = r.y.display, u = r.z.display;
|
|
3527
|
+
return {
|
|
3528
|
+
parametric: `${x.asDisplay("x", "y", "z")} = ${x.asDisplay(i(this, k).x.display, i(this, k).y.display, i(this, k).z.display)} + k\\cdot ${x.asDisplay(i(this, W).x.display, i(this, W).y.display, i(this, W).z.display)}`,
|
|
3529
|
+
system: "",
|
|
3530
|
+
cartesian: `(x-${e})/${n} = (y-${t})/${l} = (z-${s})/${u}`
|
|
3531
|
+
};
|
|
3532
|
+
}
|
|
3533
|
+
get direction() {
|
|
3534
|
+
return i(this, W).clone();
|
|
3535
|
+
}
|
|
3536
|
+
distanceTo(e) {
|
|
3537
|
+
const t = new x(i(this, k), e), s = this.direction, r = this.direction.normSquare, n = t.cross(s).normSquare, l = n.clone().divide(r), u = l.clone().sqrt();
|
|
3538
|
+
return console.log("CROSS", t.cross(s).display), {
|
|
3539
|
+
value: Math.sqrt(l.value),
|
|
3540
|
+
fraction: l.clone().sqrt(),
|
|
3541
|
+
tex: u.isExact() ? u.tex : `\\sqrt{${l.tex}}`
|
|
3542
|
+
};
|
|
3543
|
+
}
|
|
3544
|
+
hitSegment(e, t) {
|
|
3545
|
+
const s = this.intersection(
|
|
3546
|
+
new nt(e, t)
|
|
3547
|
+
);
|
|
3548
|
+
return s.hasIntersection ? s.point.x.value >= Math.min(e.x.value, t.x.value) && s.point.x.value <= Math.max(e.x.value, t.x.value) && s.point.y.value >= Math.min(e.y.value, t.y.value) && s.point.y.value <= Math.max(e.y.value, t.y.value) && s.point.z.value >= Math.min(e.z.value, t.z.value) && s.point.z.value <= Math.max(e.z.value, t.z.value) : !1;
|
|
3549
|
+
}
|
|
3550
|
+
};
|
|
3551
|
+
k = new WeakMap(), W = new WeakMap(), // A line is defined as the canonical form
|
|
3552
|
+
a(nt, "PERPENDICULAR", "perpendicular"), a(nt, "PARALLEL", "parallel");
|
|
3553
|
+
let wt = nt;
|
|
3554
|
+
var Ae, Fe;
|
|
3555
|
+
const si = class si {
|
|
3556
|
+
constructor(e) {
|
|
3557
|
+
f(this, Ae, new x(0, 0, 1));
|
|
3558
|
+
f(this, Fe, new R(0, 0, 0));
|
|
3559
|
+
return e && this.parse(e), this;
|
|
3560
|
+
}
|
|
3561
|
+
get normal() {
|
|
3562
|
+
return i(this, Ae);
|
|
3563
|
+
}
|
|
3564
|
+
set normal(e) {
|
|
3565
|
+
h(this, Ae, e), i(this, Ae).asPoint = !1;
|
|
3566
|
+
}
|
|
3567
|
+
get point() {
|
|
3568
|
+
return i(this, Fe);
|
|
3569
|
+
}
|
|
3570
|
+
set point(e) {
|
|
3571
|
+
h(this, Fe, e), i(this, Fe).asPoint = !0;
|
|
3572
|
+
}
|
|
3573
|
+
get a() {
|
|
3574
|
+
return i(this, Ae).x;
|
|
3575
|
+
}
|
|
3576
|
+
get b() {
|
|
3577
|
+
return i(this, Ae).y;
|
|
3578
|
+
}
|
|
3579
|
+
get c() {
|
|
3580
|
+
return i(this, Ae).z;
|
|
3581
|
+
}
|
|
3582
|
+
get d() {
|
|
3583
|
+
return i(this, Ae).dot(i(this, Fe)).opposite();
|
|
3584
|
+
}
|
|
3585
|
+
get tex() {
|
|
3586
|
+
return new H(
|
|
3587
|
+
new T("xyz", this.a, this.b, this.c, this.d),
|
|
3588
|
+
new T(0)
|
|
3589
|
+
).reduce().tex;
|
|
3590
|
+
}
|
|
3591
|
+
parse(e) {
|
|
3592
|
+
var t, s, r;
|
|
3593
|
+
if (e.point && e.normal) {
|
|
3594
|
+
this.point = e.point, this.normal = e.normal;
|
|
3595
|
+
return;
|
|
3596
|
+
}
|
|
3597
|
+
if (e.point && ((t = e.directions) == null ? void 0 : t.length) === 2) {
|
|
3598
|
+
this.point = e.point;
|
|
3599
|
+
const [n, l] = e.directions;
|
|
3600
|
+
this.normal = n.cross(l);
|
|
3601
|
+
return;
|
|
3602
|
+
}
|
|
3603
|
+
if (e.equation) {
|
|
3604
|
+
const n = e.equation.moveLeft().reduce().left, l = n.monomByLetter("x").coefficient, u = n.monomByLetter("y").coefficient, p = n.monomByLetter("z").coefficient, m = n.monomByDegree(0).coefficient;
|
|
3605
|
+
this.normal = new x(l, u, p), l.isNotZero() ? this.point = new R(m.clone().divide(l).opposite(), 0, 0) : u.isNotZero() ? this.point = new R(0, m.clone().divide(u).opposite(), 0) : this.point = new R(0, 0, m.clone().divide(p).opposite());
|
|
3606
|
+
return;
|
|
3607
|
+
}
|
|
3608
|
+
if (((s = e.points) == null ? void 0 : s.length) === 3 && e.points.every((n) => n instanceof x)) {
|
|
3609
|
+
const n = e.points[0], l = e.points[1], u = e.points[2], p = new x(n, l), m = new x(n, u);
|
|
3610
|
+
this.normal = p.cross(m), this.point = n;
|
|
3611
|
+
return;
|
|
3612
|
+
}
|
|
3613
|
+
if (((r = e.coefficients) == null ? void 0 : r.length) === 4) {
|
|
3614
|
+
const [n, l, u, p] = e.coefficients;
|
|
3615
|
+
this.normal = new x(n, l, u), this.point = new R(0, 0, -p);
|
|
3616
|
+
return;
|
|
3617
|
+
}
|
|
3618
|
+
}
|
|
3619
|
+
angle(e, t, s) {
|
|
3620
|
+
if (e instanceof si)
|
|
3621
|
+
return this.normal.angle(e.normal, t, s);
|
|
3622
|
+
let r;
|
|
3623
|
+
if (e instanceof x) {
|
|
3624
|
+
if (e.dimension !== 3)
|
|
3625
|
+
throw new Error("Vector is not 3D");
|
|
3626
|
+
r = e;
|
|
3627
|
+
} else
|
|
3628
|
+
r = e.direction;
|
|
3629
|
+
return (s ? Math.PI / 2 : 90) - this.normal.angle(r, !0, s);
|
|
3630
|
+
}
|
|
3631
|
+
distanceTo(e) {
|
|
3632
|
+
return this.normal.dot(e).add(this.d).abs().value / this.normal.norm;
|
|
3633
|
+
}
|
|
3634
|
+
intersectWithLine(e) {
|
|
3635
|
+
const { point: t, direction: s } = e, r = this.normal.dot(t).add(this.d).divide(this.normal.dot(s).opposite());
|
|
3636
|
+
return t.clone().add(s.clone().multiplyByScalar(r));
|
|
3637
|
+
}
|
|
3638
|
+
intersectWithPlane(e) {
|
|
3639
|
+
throw this.normal.cross(e.normal), new R(0, 0, 0), new Error("Intersection with plane not yet implemented !");
|
|
3640
|
+
}
|
|
3641
|
+
isPointOnPlane(e) {
|
|
3642
|
+
return this.normal.dot(e).add(this.d).isZero();
|
|
3258
3643
|
}
|
|
3259
3644
|
};
|
|
3260
|
-
|
|
3261
|
-
let
|
|
3262
|
-
|
|
3645
|
+
Ae = new WeakMap(), Fe = new WeakMap();
|
|
3646
|
+
let _t = si;
|
|
3647
|
+
var Me;
|
|
3648
|
+
class Xi {
|
|
3649
|
+
constructor(...e) {
|
|
3650
|
+
f(this, Me, []);
|
|
3651
|
+
return h(this, Me, e), this;
|
|
3652
|
+
}
|
|
3653
|
+
get values() {
|
|
3654
|
+
return i(this, Me);
|
|
3655
|
+
}
|
|
3656
|
+
get array() {
|
|
3657
|
+
return i(this, Me).map((e) => e.array);
|
|
3658
|
+
}
|
|
3659
|
+
get dimension() {
|
|
3660
|
+
return [i(this, Me).length, i(this, Me)[0].dimension];
|
|
3661
|
+
}
|
|
3662
|
+
isSquare() {
|
|
3663
|
+
return i(this, Me).length === i(this, Me)[0].dimension;
|
|
3664
|
+
}
|
|
3665
|
+
determinant() {
|
|
3666
|
+
if (!this.isSquare())
|
|
3667
|
+
throw new Error("Matrix is not square");
|
|
3668
|
+
return Gi(...this.values);
|
|
3669
|
+
}
|
|
3670
|
+
}
|
|
3671
|
+
Me = new WeakMap();
|
|
3672
|
+
function vt(o) {
|
|
3263
3673
|
const e = Object.assign(
|
|
3264
3674
|
{
|
|
3265
3675
|
negative: !0,
|
|
@@ -3270,16 +3680,16 @@ function ft(o) {
|
|
|
3270
3680
|
},
|
|
3271
3681
|
o
|
|
3272
3682
|
), t = new c();
|
|
3273
|
-
if (e.negative ? t.numerator =
|
|
3683
|
+
if (e.negative ? t.numerator = X(e.max, e.zero) : t.numerator = de(e.zero ? 0 : 1, e.max), e.natural)
|
|
3274
3684
|
t.denominator = 1;
|
|
3275
3685
|
else {
|
|
3276
3686
|
let s = 0;
|
|
3277
3687
|
for (; t.isRelative() && s < 10; )
|
|
3278
|
-
t.denominator =
|
|
3688
|
+
t.denominator = de(1, e.max), s++;
|
|
3279
3689
|
}
|
|
3280
3690
|
return e.reduced ? t.reduce() : t;
|
|
3281
3691
|
}
|
|
3282
|
-
function
|
|
3692
|
+
function Ni(o) {
|
|
3283
3693
|
const e = Object.assign(
|
|
3284
3694
|
{
|
|
3285
3695
|
letters: "x",
|
|
@@ -3288,8 +3698,8 @@ function fi(o) {
|
|
|
3288
3698
|
zero: !1
|
|
3289
3699
|
},
|
|
3290
3700
|
o
|
|
3291
|
-
), t = new
|
|
3292
|
-
if (t.coefficient =
|
|
3701
|
+
), t = new I();
|
|
3702
|
+
if (t.coefficient = vt({
|
|
3293
3703
|
zero: e.zero,
|
|
3294
3704
|
reduced: !0,
|
|
3295
3705
|
natural: !e.fraction
|
|
@@ -3297,14 +3707,14 @@ function fi(o) {
|
|
|
3297
3707
|
for (const s of e.letters.split(""))
|
|
3298
3708
|
t.setLetter(s, 0);
|
|
3299
3709
|
for (let s = 0; s < e.degree; s++) {
|
|
3300
|
-
const r =
|
|
3710
|
+
const r = ti(e.letters.split(""));
|
|
3301
3711
|
t.setLetter(r, t.degree(r).clone().add(1));
|
|
3302
3712
|
}
|
|
3303
3713
|
} else
|
|
3304
3714
|
t.setLetter(e.letters, e.degree);
|
|
3305
3715
|
return t;
|
|
3306
3716
|
}
|
|
3307
|
-
const
|
|
3717
|
+
const Yi = {
|
|
3308
3718
|
letters: "x",
|
|
3309
3719
|
degree: 2,
|
|
3310
3720
|
fraction: !1,
|
|
@@ -3315,14 +3725,14 @@ const zi = {
|
|
|
3315
3725
|
numberOfMonoms: 0,
|
|
3316
3726
|
positive: !0
|
|
3317
3727
|
};
|
|
3318
|
-
function
|
|
3728
|
+
function Oi(o) {
|
|
3319
3729
|
const e = Object.assign(
|
|
3320
|
-
|
|
3730
|
+
Yi,
|
|
3321
3731
|
o
|
|
3322
|
-
), t = new
|
|
3732
|
+
), t = new T().empty();
|
|
3323
3733
|
let s;
|
|
3324
3734
|
for (let r = e.degree; r >= 0; r--)
|
|
3325
|
-
s =
|
|
3735
|
+
s = Ni({
|
|
3326
3736
|
letters: e.letters,
|
|
3327
3737
|
degree: r,
|
|
3328
3738
|
fraction: e.fraction,
|
|
@@ -3330,12 +3740,12 @@ function di(o) {
|
|
|
3330
3740
|
}), e.unit && e.degree === r && s.coefficient.one(), t.add(s);
|
|
3331
3741
|
if (e.positive && t.monomByDegree().coefficient.isNegative() && t.monomByDegree().coefficient.opposite(), e.numberOfMonoms && e.numberOfMonoms > 0 && e.numberOfMonoms < t.length)
|
|
3332
3742
|
for (; t.length > e.numberOfMonoms; ) {
|
|
3333
|
-
const r =
|
|
3743
|
+
const r = de(1, t.length - 1);
|
|
3334
3744
|
t.monoms.splice(r, 1);
|
|
3335
3745
|
}
|
|
3336
3746
|
return t;
|
|
3337
3747
|
}
|
|
3338
|
-
function
|
|
3748
|
+
function Qi(o) {
|
|
3339
3749
|
const e = Object.assign(
|
|
3340
3750
|
{
|
|
3341
3751
|
letters: "x",
|
|
@@ -3355,9 +3765,9 @@ function ki(o) {
|
|
|
3355
3765
|
}
|
|
3356
3766
|
},
|
|
3357
3767
|
o
|
|
3358
|
-
), t = new
|
|
3768
|
+
), t = new T().one();
|
|
3359
3769
|
for (let s = 0; s < e.degree; s++) {
|
|
3360
|
-
const r =
|
|
3770
|
+
const r = Oi({
|
|
3361
3771
|
degree: 1,
|
|
3362
3772
|
unit: e.unit,
|
|
3363
3773
|
fraction: e.fraction,
|
|
@@ -3366,9 +3776,9 @@ function ki(o) {
|
|
|
3366
3776
|
});
|
|
3367
3777
|
t.multiply(r);
|
|
3368
3778
|
}
|
|
3369
|
-
return new
|
|
3779
|
+
return new H(t, 0);
|
|
3370
3780
|
}
|
|
3371
|
-
function
|
|
3781
|
+
function qi(o) {
|
|
3372
3782
|
const e = Object.assign(
|
|
3373
3783
|
{
|
|
3374
3784
|
axis: !0,
|
|
@@ -3377,10 +3787,10 @@ function pi(o) {
|
|
|
3377
3787
|
quadrant: null
|
|
3378
3788
|
},
|
|
3379
3789
|
o
|
|
3380
|
-
), t = e.axis === "x", s = e.axis === "y", r = e.fraction ?
|
|
3381
|
-
return Number(e.quadrant) === 1 && (r.abs(), n.abs()), Number(e.quadrant) === 2 && (r.isPositive() && r.opposite(), n.isNegative() && n.opposite()), Number(e.quadrant) === 3 && (r.isPositive() && r.opposite(), n.isPositive() && n.opposite()), Number(e.quadrant) === 4 && (r.isNegative() && r.opposite(), n.isPositive() && n.opposite()), new
|
|
3790
|
+
), t = e.axis === "x", s = e.axis === "y", r = e.fraction ? vt({ max: e.max, zero: t }) : new c(X(e.max, t)), n = e.fraction ? vt({ max: e.max, zero: s }) : new c(X(e.max, s));
|
|
3791
|
+
return Number(e.quadrant) === 1 && (r.abs(), n.abs()), Number(e.quadrant) === 2 && (r.isPositive() && r.opposite(), n.isNegative() && n.opposite()), Number(e.quadrant) === 3 && (r.isPositive() && r.opposite(), n.isPositive() && n.opposite()), Number(e.quadrant) === 4 && (r.isNegative() && r.opposite(), n.isPositive() && n.opposite()), new R(r, n);
|
|
3382
3792
|
}
|
|
3383
|
-
function
|
|
3793
|
+
function Ki(o) {
|
|
3384
3794
|
const e = Object.assign(
|
|
3385
3795
|
{
|
|
3386
3796
|
center: {
|
|
@@ -3390,191 +3800,84 @@ function Li(o) {
|
|
|
3390
3800
|
pointsOnCircle: 8
|
|
3391
3801
|
},
|
|
3392
3802
|
o
|
|
3393
|
-
), t =
|
|
3803
|
+
), t = qi(e.center);
|
|
3394
3804
|
let s, r;
|
|
3395
|
-
return e.pointsOnCircle === 8 ? (s =
|
|
3805
|
+
return e.pointsOnCircle === 8 ? (s = de(1, 3), r = s ** 2 + (s + 1) ** 2) : r = de(1, 20), new gt(t, r, !0);
|
|
3396
3806
|
}
|
|
3397
|
-
function
|
|
3807
|
+
function Ji(o) {
|
|
3398
3808
|
const e = Object.assign(
|
|
3399
3809
|
{
|
|
3400
3810
|
A: {
|
|
3401
|
-
x:
|
|
3402
|
-
y:
|
|
3811
|
+
x: X(10),
|
|
3812
|
+
y: X(10)
|
|
3403
3813
|
}
|
|
3404
3814
|
},
|
|
3405
3815
|
o
|
|
3406
|
-
), t = new
|
|
3407
|
-
|
|
3408
|
-
|
|
3816
|
+
), t = new x(
|
|
3817
|
+
X(10),
|
|
3818
|
+
X(10)
|
|
3409
3819
|
);
|
|
3410
3820
|
for (; t.isNull; )
|
|
3411
|
-
t.x =
|
|
3412
|
-
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
|
|
3821
|
+
t.x = X(10), t.y = X(10);
|
|
3822
|
+
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 j(new x(e.A.x, e.A.y), t);
|
|
3413
3823
|
}
|
|
3414
|
-
|
|
3415
|
-
const _e = class _e {
|
|
3416
|
-
constructor(e, t) {
|
|
3417
|
-
// ax + by + c = 0
|
|
3418
|
-
d(this, z, new G());
|
|
3419
|
-
d(this, U, new O());
|
|
3420
|
-
a(this, "clone", () => (h(this, U, i(this, U).clone()), h(this, z, i(this, z).clone()), this));
|
|
3421
|
-
// ------------------------------------------
|
|
3422
|
-
// Mathematical operations
|
|
3423
|
-
// ------------------------------------------
|
|
3424
|
-
a(this, "isOnLine", (e) => !1);
|
|
3425
|
-
a(this, "isParallelTo", (e) => {
|
|
3426
|
-
throw new Error("Method not implemented.");
|
|
3427
|
-
});
|
|
3428
|
-
a(this, "isSameAs", (e) => {
|
|
3429
|
-
throw new Error("Method not implemented.");
|
|
3430
|
-
});
|
|
3431
|
-
a(this, "isPerpendicularTo", (e) => {
|
|
3432
|
-
throw new Error("Method not implemented.");
|
|
3433
|
-
});
|
|
3434
|
-
a(this, "isVertical", () => {
|
|
3435
|
-
throw new Error("Method not implemented.");
|
|
3436
|
-
});
|
|
3437
|
-
a(this, "simplify", () => {
|
|
3438
|
-
throw new Error("Method not implemented.");
|
|
3439
|
-
});
|
|
3440
|
-
a(this, "intersection", (e) => {
|
|
3441
|
-
throw new Error("Method not implemented.");
|
|
3442
|
-
});
|
|
3443
|
-
// getValueAtX = (value: Fraction | number): Fraction => {
|
|
3444
|
-
// const equ = this.equation.clone().isolate('y'),
|
|
3445
|
-
// F = new Fraction(value)
|
|
3446
|
-
// if (equ instanceof Equation) {
|
|
3447
|
-
// return equ.right.evaluate({ x: F }) as Fraction
|
|
3448
|
-
// }
|
|
3449
|
-
// return new Fraction().invalid()
|
|
3450
|
-
// }
|
|
3451
|
-
// getValueAtY = (value: Fraction | number): Fraction => {
|
|
3452
|
-
// const equ = this.equation.clone().isolate('x'),
|
|
3453
|
-
// F = new Fraction(value)
|
|
3454
|
-
// if (equ instanceof Equation) {
|
|
3455
|
-
// return equ.right.evaluate({ y: F }) as Fraction
|
|
3456
|
-
// }
|
|
3457
|
-
// return new Fraction().invalid()
|
|
3458
|
-
// }
|
|
3459
|
-
a(this, "randomPoint", (e = 5) => {
|
|
3460
|
-
const t = i(this, z).clone(), s = new c(W(e, !1));
|
|
3461
|
-
return new G(
|
|
3462
|
-
t.x.clone().add(i(this, U).x.clone().multiply(s)),
|
|
3463
|
-
t.y.clone().add(i(this, U).y.clone().multiply(s)),
|
|
3464
|
-
t.z.clone().add(i(this, U).z.clone().multiply(s))
|
|
3465
|
-
);
|
|
3466
|
-
});
|
|
3467
|
-
return h(this, z, e.clone()), h(this, U, t.asPoint ? new O(e, t) : t.clone()), this;
|
|
3468
|
-
}
|
|
3469
|
-
get OA() {
|
|
3470
|
-
return i(this, z);
|
|
3471
|
-
}
|
|
3472
|
-
set OA(e) {
|
|
3473
|
-
h(this, z, e);
|
|
3474
|
-
}
|
|
3475
|
-
get point() {
|
|
3476
|
-
return i(this, z).clone();
|
|
3477
|
-
}
|
|
3478
|
-
get d() {
|
|
3479
|
-
return i(this, U);
|
|
3480
|
-
}
|
|
3481
|
-
set d(e) {
|
|
3482
|
-
h(this, U, e);
|
|
3483
|
-
}
|
|
3484
|
-
get tex() {
|
|
3485
|
-
return {
|
|
3486
|
-
parametric: `${O.asTex("x", "y", "z")} = ${O.asTex(i(this, z).x.tex, i(this, z).y.tex, i(this, z).z.tex)} + k\\cdot ${O.asTex(i(this, U).x.tex, i(this, U).y.tex, i(this, U).z.tex)}`,
|
|
3487
|
-
system: `\\left\\{\\begin{aligned}
|
|
3488
|
-
x &= ${new I(i(this, z).x).add(new M(i(this, U).x).multiply(new M("k"))).reorder("k", !0).tex}\\\\
|
|
3489
|
-
y &= ${new I(i(this, z).y).add(new M(i(this, U).y).multiply(new M("k"))).reorder("k", !0).tex}\\\\
|
|
3490
|
-
z &= ${new I(i(this, z).z).add(new M(i(this, U).z).multiply(new M("k"))).reorder("k", !0).tex}
|
|
3491
|
-
\\end{aligned}\\right.`,
|
|
3492
|
-
cartesian: `\\frac{ ${new I("x", 1, i(this, z).x.clone().opposite()).tex} }{ ${this.direction.x.tex} } = \\frac{ ${new I("y", 1, i(this, z).y.clone().opposite()).tex} }{ ${this.direction.y.tex} } = \\frac{ ${new I("z", 1, i(this, z).z.clone().opposite()).tex} }{ ${this.direction.z.tex} }`
|
|
3493
|
-
};
|
|
3494
|
-
}
|
|
3495
|
-
get display() {
|
|
3496
|
-
const e = i(this, z).x.display, t = i(this, z).y.display, s = i(this, z).z.display, r = this.direction.simplify(), n = r.x.display, l = r.y.display, u = r.z.display;
|
|
3497
|
-
return {
|
|
3498
|
-
parametric: `${O.asDisplay("x", "y", "z")} = ${O.asDisplay(i(this, z).x.display, i(this, z).y.display, i(this, z).z.display)} + k\\cdot ${O.asDisplay(i(this, U).x.display, i(this, U).y.display, i(this, U).z.display)}`,
|
|
3499
|
-
system: "",
|
|
3500
|
-
cartesian: `(x-${e})/${n} = (y-${t})/${l} = (z-${s})/${u}`
|
|
3501
|
-
};
|
|
3502
|
-
}
|
|
3503
|
-
get direction() {
|
|
3504
|
-
return i(this, U).clone();
|
|
3505
|
-
}
|
|
3506
|
-
distanceTo(e) {
|
|
3507
|
-
const t = new O(i(this, z), e), s = this.direction, r = this.direction.normSquare, n = t.cross(s).normSquare, l = n.clone().divide(r), u = l.clone().sqrt();
|
|
3508
|
-
return console.log("CROSS", t.cross(s).display), {
|
|
3509
|
-
value: Math.sqrt(l.value),
|
|
3510
|
-
fraction: l.clone().sqrt(),
|
|
3511
|
-
tex: u.isExact() ? u.tex : `\\sqrt{${l.tex}}`
|
|
3512
|
-
};
|
|
3513
|
-
}
|
|
3514
|
-
hitSegment(e, t) {
|
|
3515
|
-
const s = this.intersection(
|
|
3516
|
-
new _e(e, t)
|
|
3517
|
-
);
|
|
3518
|
-
return s.hasIntersection ? s.point.x.value >= Math.min(e.x.value, t.x.value) && s.point.x.value <= Math.max(e.x.value, t.x.value) && s.point.y.value >= Math.min(e.y.value, t.y.value) && s.point.y.value <= Math.max(e.y.value, t.y.value) && s.point.z.value >= Math.min(e.z.value, t.z.value) && s.point.z.value <= Math.max(e.z.value, t.z.value) : !1;
|
|
3519
|
-
}
|
|
3520
|
-
};
|
|
3521
|
-
z = new WeakMap(), U = new WeakMap(), // A line is defined as the canonical form
|
|
3522
|
-
a(_e, "PERPENDICULAR", "perpendicular"), a(_e, "PARALLEL", "parallel");
|
|
3523
|
-
let jt = _e;
|
|
3524
|
-
function Zi(o) {
|
|
3824
|
+
function _i(o) {
|
|
3525
3825
|
const e = Object.assign(
|
|
3526
3826
|
{
|
|
3527
3827
|
A: {
|
|
3528
|
-
x:
|
|
3529
|
-
y:
|
|
3530
|
-
z:
|
|
3828
|
+
x: X(10),
|
|
3829
|
+
y: X(10),
|
|
3830
|
+
z: X(10)
|
|
3531
3831
|
},
|
|
3532
3832
|
direction: {
|
|
3533
|
-
x:
|
|
3534
|
-
y:
|
|
3535
|
-
z:
|
|
3833
|
+
x: X(10),
|
|
3834
|
+
y: X(10),
|
|
3835
|
+
z: X(10)
|
|
3536
3836
|
}
|
|
3537
3837
|
},
|
|
3538
3838
|
o
|
|
3539
|
-
), t = new
|
|
3540
|
-
return new
|
|
3839
|
+
), t = new R(e.A.x, e.A.y, e.A.z), s = new x(e.direction.x, e.direction.y, e.direction.z);
|
|
3840
|
+
return new wt(t, s);
|
|
3541
3841
|
}
|
|
3542
|
-
const
|
|
3543
|
-
equation: (o) =>
|
|
3544
|
-
polynom: (o) =>
|
|
3545
|
-
monom: (o) =>
|
|
3546
|
-
fraction: (o) =>
|
|
3547
|
-
number: (o, e, t) =>
|
|
3548
|
-
numberSym: (o, e) =>
|
|
3549
|
-
prime: (o) =>
|
|
3550
|
-
bool: (o) =>
|
|
3551
|
-
array: (o, e) =>
|
|
3552
|
-
item: (o) =>
|
|
3553
|
-
shuffle: (o) =>
|
|
3554
|
-
line: (o) =>
|
|
3555
|
-
line3: (o) =>
|
|
3556
|
-
point: (o) =>
|
|
3557
|
-
circle: (o) =>
|
|
3558
|
-
},
|
|
3559
|
-
Vector:
|
|
3560
|
-
Point:
|
|
3561
|
-
Line:
|
|
3562
|
-
Triangle:
|
|
3563
|
-
Circle:
|
|
3564
|
-
|
|
3565
|
-
|
|
3842
|
+
const es = {
|
|
3843
|
+
equation: (o) => Qi(o),
|
|
3844
|
+
polynom: (o) => Oi(o),
|
|
3845
|
+
monom: (o) => Ni(o),
|
|
3846
|
+
fraction: (o) => vt(o),
|
|
3847
|
+
number: (o, e, t) => de(o, e, t),
|
|
3848
|
+
numberSym: (o, e) => X(o, e),
|
|
3849
|
+
prime: (o) => Wi(o),
|
|
3850
|
+
bool: (o) => yi(o),
|
|
3851
|
+
array: (o, e) => Hi(o, e),
|
|
3852
|
+
item: (o) => ti(o),
|
|
3853
|
+
shuffle: (o) => gi(o),
|
|
3854
|
+
line: (o) => Ji(o),
|
|
3855
|
+
line3: (o) => _i(o),
|
|
3856
|
+
point: (o) => qi(o),
|
|
3857
|
+
circle: (o) => Ki(o)
|
|
3858
|
+
}, ts = {
|
|
3859
|
+
Vector: x,
|
|
3860
|
+
Point: R,
|
|
3861
|
+
Line: j,
|
|
3862
|
+
Triangle: Jt,
|
|
3863
|
+
Circle: gt,
|
|
3864
|
+
Line3: wt,
|
|
3865
|
+
Plane3: _t
|
|
3866
|
+
}, ss = {
|
|
3867
|
+
Numeric: G,
|
|
3566
3868
|
Fraction: c,
|
|
3567
|
-
Root:
|
|
3568
|
-
Monom:
|
|
3569
|
-
Polynom:
|
|
3570
|
-
Equation:
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3869
|
+
Root: ft,
|
|
3870
|
+
Monom: I,
|
|
3871
|
+
Polynom: T,
|
|
3872
|
+
Equation: H,
|
|
3873
|
+
Matrix: Xi,
|
|
3874
|
+
LinearSystem: Qt,
|
|
3875
|
+
Factor: fe,
|
|
3876
|
+
PolyFactor: Xt,
|
|
3574
3877
|
// LogicalSet,
|
|
3575
|
-
Random:
|
|
3576
|
-
Geometry:
|
|
3878
|
+
Random: es,
|
|
3879
|
+
Geometry: ts
|
|
3577
3880
|
};
|
|
3578
3881
|
export {
|
|
3579
|
-
|
|
3882
|
+
ss as default
|
|
3580
3883
|
};
|