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