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