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