pimath 0.2.11 → 0.2.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 +882 -907
- package/dist/pimath.js.map +1 -1
- package/package.json +3 -2
- package/src/algebra/equation.ts +3 -2
- package/src/algebra/equationSolver.ts +2 -1
- package/src/algebra/factor.ts +10 -9
- package/src/algebra/linearSystem.ts +10 -9
- package/src/algebra/logicalset.ts +8 -3
- package/src/algebra/matrix.ts +10 -9
- package/src/algebra/monom.ts +10 -4
- package/src/algebra/operations.ts +3 -2
- package/src/algebra/polyFactor.ts +5 -4
- package/src/algebra/polynom.ts +30 -30
- package/src/coefficients/fraction.ts +6 -5
- package/src/coefficients/root.ts +5 -4
- package/src/errors.ts +45 -0
- package/src/geometry/TupleN.ts +4 -3
- package/src/geometry/geomMath.ts +3 -2
- package/src/geometry/line.ts +4 -2
- package/src/geometry/line3.ts +7 -6
- package/src/geometry/plane3.ts +3 -2
- package/src/geometry/point.ts +5 -4
- package/src/geometry/sphere3.ts +6 -5
- package/src/geometry/triangle.ts +3 -2
- package/src/geometry/vector.ts +6 -5
- package/src/helpers.ts +3 -1
- package/src/index.ts +23 -0
- package/src/numeric.ts +2 -1
- package/src/randomization/rndHelpers.ts +2 -1
- package/types/algebra/equation.d.ts.map +1 -1
- package/types/algebra/equationSolver.d.ts.map +1 -1
- package/types/algebra/factor.d.ts.map +1 -1
- package/types/algebra/linearSystem.d.ts.map +1 -1
- package/types/algebra/logicalset.d.ts.map +1 -1
- package/types/algebra/matrix.d.ts.map +1 -1
- package/types/algebra/monom.d.ts.map +1 -1
- package/types/algebra/operations.d.ts.map +1 -1
- package/types/algebra/polyFactor.d.ts.map +1 -1
- package/types/algebra/polynom.d.ts.map +1 -1
- package/types/coefficients/fraction.d.ts.map +1 -1
- package/types/coefficients/root.d.ts.map +1 -1
- package/types/errors.d.ts +20 -0
- package/types/errors.d.ts.map +1 -0
- package/types/geometry/TupleN.d.ts.map +1 -1
- package/types/geometry/geomMath.d.ts.map +1 -1
- package/types/geometry/line.d.ts.map +1 -1
- package/types/geometry/line3.d.ts.map +1 -1
- package/types/geometry/plane3.d.ts.map +1 -1
- package/types/geometry/point.d.ts.map +1 -1
- package/types/geometry/sphere3.d.ts.map +1 -1
- package/types/geometry/triangle.d.ts.map +1 -1
- package/types/geometry/vector.d.ts.map +1 -1
- package/types/helpers.d.ts.map +1 -1
- package/types/index.d.ts +12 -0
- package/types/index.d.ts.map +1 -1
- package/types/numeric.d.ts.map +1 -1
- package/types/randomization/rndHelpers.d.ts.map +1 -1
package/dist/pimath.js
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
|
+
//#region src/errors.ts
|
|
2
|
+
var e = class extends Error {
|
|
3
|
+
constructor(e, t) {
|
|
4
|
+
super(e, t), this.name = new.target.name;
|
|
5
|
+
}
|
|
6
|
+
}, t = class extends e {}, n = class extends e {}, r = class extends e {}, i = class extends e {}, a = class extends e {}, o = class extends e {}, s = class extends e {};
|
|
7
|
+
//#endregion
|
|
1
8
|
//#region src/numeric.ts
|
|
2
|
-
function
|
|
3
|
-
let t =
|
|
4
|
-
for (; t.length > 0;)
|
|
5
|
-
return
|
|
9
|
+
function c(e) {
|
|
10
|
+
let t = u(e), n = [], r, i;
|
|
11
|
+
for (; t.length > 0;) r = t.shift() ?? 1, i = (t.length > 0 ? t.pop() : +r) ?? 1, n.push([r, i]);
|
|
12
|
+
return n;
|
|
6
13
|
}
|
|
7
|
-
function
|
|
8
|
-
let t =
|
|
14
|
+
function l(...e) {
|
|
15
|
+
let t = d(...e);
|
|
9
16
|
return e.map((e) => e / t);
|
|
10
17
|
}
|
|
11
|
-
function
|
|
18
|
+
function u(e) {
|
|
12
19
|
let t = Math.abs(e), n = Math.sqrt(t), r = [];
|
|
13
20
|
for (let i = 1; i <= n; i++) e % i === 0 && (r.push(i), r.push(t / i));
|
|
14
21
|
return r.sort(function(e, t) {
|
|
15
22
|
return e - t;
|
|
16
23
|
}), [...new Set(r)];
|
|
17
24
|
}
|
|
18
|
-
function
|
|
25
|
+
function d(...e) {
|
|
19
26
|
let t = function(e, n) {
|
|
20
27
|
return isNaN(e) || isNaN(n) ? NaN : n === 0 ? e : e === 0 ? n : t(n, e % n);
|
|
21
28
|
}, n = 1, r = 2;
|
|
@@ -25,19 +32,19 @@ function r(...e) {
|
|
|
25
32
|
for (r = 2; r < e.length && (n = t(n, e[r]), n !== 1); r++);
|
|
26
33
|
return Math.abs(n);
|
|
27
34
|
}
|
|
28
|
-
function
|
|
35
|
+
function f(...e) {
|
|
29
36
|
return e.reduce(function(e, t) {
|
|
30
|
-
return Math.abs(e * t /
|
|
37
|
+
return Math.abs(e * t / d(e, t));
|
|
31
38
|
});
|
|
32
39
|
}
|
|
33
|
-
function
|
|
40
|
+
function ee(e, t = 3) {
|
|
34
41
|
return +e.toFixed(t);
|
|
35
42
|
}
|
|
36
|
-
function
|
|
43
|
+
function te(e) {
|
|
37
44
|
if (Number.isSafeInteger(e) || e.toString().split(".")[0].length < 10) return 0;
|
|
38
|
-
throw
|
|
45
|
+
throw new a("Periodic value: Not implemented yet");
|
|
39
46
|
}
|
|
40
|
-
function
|
|
47
|
+
function ne(e) {
|
|
41
48
|
let t = [
|
|
42
49
|
2,
|
|
43
50
|
3,
|
|
@@ -1271,7 +1278,7 @@ function s(e) {
|
|
|
1271
1278
|
];
|
|
1272
1279
|
return e === void 0 ? t : t.slice(0, Math.min(t.length, e));
|
|
1273
1280
|
}
|
|
1274
|
-
function
|
|
1281
|
+
function re(e, t) {
|
|
1275
1282
|
let n = [], r = t === !0 ? +e : e ** 2;
|
|
1276
1283
|
for (let t = 0; t <= e; t++) for (let i = 0; i <= e; i++) t ** 2 + i ** 2 === r && n.push([
|
|
1277
1284
|
t,
|
|
@@ -1280,11 +1287,11 @@ function c(e, t) {
|
|
|
1280
1287
|
]);
|
|
1281
1288
|
return n;
|
|
1282
1289
|
}
|
|
1283
|
-
function
|
|
1290
|
+
function ie(e, t = 2) {
|
|
1284
1291
|
let n = Math.round(Number(`${e}e${t}`));
|
|
1285
1292
|
return Number(`${n}e-${t}`);
|
|
1286
1293
|
}
|
|
1287
|
-
function
|
|
1294
|
+
function ae(e, t) {
|
|
1288
1295
|
let n = Math.floor(e ** (1 / t)), r = e;
|
|
1289
1296
|
for (; n > 1;) {
|
|
1290
1297
|
let e = n ** +t;
|
|
@@ -1293,21 +1300,21 @@ function u(e, t) {
|
|
|
1293
1300
|
}
|
|
1294
1301
|
return 1;
|
|
1295
1302
|
}
|
|
1296
|
-
var
|
|
1297
|
-
decompose:
|
|
1298
|
-
dividers:
|
|
1299
|
-
divideNumbersByGCD:
|
|
1300
|
-
gcd:
|
|
1301
|
-
lcm:
|
|
1302
|
-
numberCorrection:
|
|
1303
|
-
periodic:
|
|
1304
|
-
primes:
|
|
1305
|
-
pythagoreanTripletsWithTarget:
|
|
1306
|
-
round:
|
|
1307
|
-
greatestPower:
|
|
1308
|
-
},
|
|
1303
|
+
var p = {
|
|
1304
|
+
decompose: c,
|
|
1305
|
+
dividers: u,
|
|
1306
|
+
divideNumbersByGCD: l,
|
|
1307
|
+
gcd: d,
|
|
1308
|
+
lcm: f,
|
|
1309
|
+
numberCorrection: ee,
|
|
1310
|
+
periodic: te,
|
|
1311
|
+
primes: ne,
|
|
1312
|
+
pythagoreanTripletsWithTarget: re,
|
|
1313
|
+
round: ie,
|
|
1314
|
+
greatestPower: ae
|
|
1315
|
+
}, oe = /* @__PURE__ */ function(e) {
|
|
1309
1316
|
return e.frac = "frac", e.dfrac = "dfrac", e.tfrac = "tfrac", e;
|
|
1310
|
-
}({}),
|
|
1317
|
+
}({}), m = class e {
|
|
1311
1318
|
#e = 1;
|
|
1312
1319
|
#t = 3;
|
|
1313
1320
|
#n = !0;
|
|
@@ -1370,7 +1377,7 @@ var d = {
|
|
|
1370
1377
|
return n && r.reverse(), r;
|
|
1371
1378
|
};
|
|
1372
1379
|
static toSameDenominateur(...t) {
|
|
1373
|
-
let n = t.map((t) => new e(t)), r =
|
|
1380
|
+
let n = t.map((t) => new e(t)), r = p.lcm(...n.map((e) => e.denominator));
|
|
1374
1381
|
return n.forEach((e) => e.amplify(r / e.denominator)), n;
|
|
1375
1382
|
}
|
|
1376
1383
|
static unique = (t) => {
|
|
@@ -1392,7 +1399,7 @@ var d = {
|
|
|
1392
1399
|
return this.reduce();
|
|
1393
1400
|
};
|
|
1394
1401
|
amplify = (e) => {
|
|
1395
|
-
if (!Number.isSafeInteger(e)) throw
|
|
1402
|
+
if (!Number.isSafeInteger(e)) throw new i("The amplification factor must be a safe integer.");
|
|
1396
1403
|
return this.#r *= e, this.#e *= e, this;
|
|
1397
1404
|
};
|
|
1398
1405
|
compare = (t, n) => {
|
|
@@ -1442,17 +1449,17 @@ var d = {
|
|
|
1442
1449
|
fromNumber(e) {
|
|
1443
1450
|
if (Number.isSafeInteger(e)) return this.#r = e, this.#e = 1, this.#n = !0, this;
|
|
1444
1451
|
let [, t] = e.toString().split("."), n = t ? t.length : 0, r = 10 ** n;
|
|
1445
|
-
return this.#r = e * r, this.#e = r, this.#r =
|
|
1452
|
+
return this.#r = e * r, this.#e = r, this.#r = p.numberCorrection(this.#r), this.#e = p.numberCorrection(this.#e), this.reduce(), this.#n = n < 10, this;
|
|
1446
1453
|
}
|
|
1447
1454
|
fromNumbers(e, t) {
|
|
1448
1455
|
return Number.isSafeInteger(e) && Number.isSafeInteger(t) ? (this.#r = e, this.#e = t, this.#n = !0, this) : this.fromNumber(e / t);
|
|
1449
1456
|
}
|
|
1450
1457
|
fromPeriodic(e, t) {
|
|
1451
1458
|
let [, n] = e.toString().split(/[.,]/), r = n ? n.length : 0;
|
|
1452
|
-
if (!Number.isSafeInteger(t) || t <= 0) throw
|
|
1453
|
-
if (t > r) throw
|
|
1454
|
-
let
|
|
1455
|
-
return this.#r = +e *
|
|
1459
|
+
if (!Number.isSafeInteger(t) || t <= 0) throw new i("The periodic length must be a positive integer.");
|
|
1460
|
+
if (t > r) throw new i(`The periodic length (${t}) cannot exceed the number of decimal digits (${r}).`);
|
|
1461
|
+
let a = 10 ** r;
|
|
1462
|
+
return this.#r = +e * a - Math.floor(e * 10 ** (r - t)), this.#e = a - 10 ** (r - t), this.#n = !0, this;
|
|
1456
1463
|
}
|
|
1457
1464
|
fromString(e) {
|
|
1458
1465
|
let t = e.split("/").map(Number);
|
|
@@ -1481,7 +1488,7 @@ var d = {
|
|
|
1481
1488
|
isOne = () => this.#r === 1 && this.#e === 1;
|
|
1482
1489
|
isPositive = () => this.sign() === 1;
|
|
1483
1490
|
isRational = () => this.exact && !this.isRelative();
|
|
1484
|
-
isReduced = () => Math.abs(
|
|
1491
|
+
isReduced = () => Math.abs(p.gcd(this.#r, this.#e)) === 1;
|
|
1485
1492
|
isRelative = () => this.exact && this.clone().reduce().denominator === 1;
|
|
1486
1493
|
isSquare = () => Math.sqrt(this.#r) % 1 == 0 && Math.sqrt(this.#e) % 1 == 0;
|
|
1487
1494
|
isStrictlyNegative = () => this.value < 0;
|
|
@@ -1509,17 +1516,17 @@ var d = {
|
|
|
1509
1516
|
return a === r && o === i ? (this.#r = a, this.#e = o) : (this.#r = r / i, this.#e = 1, this.exact = !1), this;
|
|
1510
1517
|
};
|
|
1511
1518
|
reduce = () => {
|
|
1512
|
-
let e =
|
|
1519
|
+
let e = p.gcd(this.#r, this.#e);
|
|
1513
1520
|
return this.#r /= e, this.#e /= e, this.#e < 0 && (this.#e = -this.#e, this.#r = -this.#r), this;
|
|
1514
1521
|
};
|
|
1515
1522
|
root = (e) => {
|
|
1516
1523
|
if (e === 0) return this;
|
|
1517
|
-
if (!Number.isSafeInteger(e)) throw
|
|
1518
|
-
if (e < 0 && this.inverse(), this.isNegative() && e % 2 == 0) throw
|
|
1524
|
+
if (!Number.isSafeInteger(e)) throw new i("The root must be an integer.");
|
|
1525
|
+
if (e < 0 && this.inverse(), this.isNegative() && e % 2 == 0) throw new r("The root of a negative number must be odd.");
|
|
1519
1526
|
let t = this.sign();
|
|
1520
1527
|
this.abs(), this.reduce();
|
|
1521
|
-
let n = Math.floor(this.#r ** +Math.abs(1 / e)),
|
|
1522
|
-
return this.#r **= +Math.abs(1 / e), this.#e **= +Math.abs(1 / e), (n !== this.#r ||
|
|
1528
|
+
let n = Math.floor(this.#r ** +Math.abs(1 / e)), a = Math.floor(this.#e ** +Math.abs(1 / e));
|
|
1529
|
+
return this.#r **= +Math.abs(1 / e), this.#e **= +Math.abs(1 / e), (n !== this.#r || a !== this.#e) && (this.#r /= this.#e, this.#e = 1, this.exact = !1), this.multiply(t), this;
|
|
1523
1530
|
};
|
|
1524
1531
|
sign = () => this.#r * this.#e >= 0 ? 1 : -1;
|
|
1525
1532
|
sqrt = () => this.root(2);
|
|
@@ -1541,7 +1548,7 @@ var d = {
|
|
|
1541
1548
|
};
|
|
1542
1549
|
//#endregion
|
|
1543
1550
|
//#region src/helpers.ts
|
|
1544
|
-
function
|
|
1551
|
+
function se(e, t = !0) {
|
|
1545
1552
|
return t ? `\\left( ${e} \\right)` : `(${e})`;
|
|
1546
1553
|
}
|
|
1547
1554
|
function h(e) {
|
|
@@ -1554,13 +1561,13 @@ function g(e, t, n, r, i) {
|
|
|
1554
1561
|
return e.map((e, a) => r !== void 0 && a < r || i !== void 0 && a > i ? e : e === t ? n : e);
|
|
1555
1562
|
}
|
|
1556
1563
|
function _(e, t) {
|
|
1557
|
-
if (t.length !== 1) throw
|
|
1558
|
-
let n = 0, r = 0,
|
|
1559
|
-
for (let
|
|
1560
|
-
let o = e[
|
|
1561
|
-
o === "(" ? n++ : o === ")" ? n-- : o === t && n === 0 && (
|
|
1564
|
+
if (t.length !== 1) throw new i(`splitChar must be a single character, got: "${t}"`);
|
|
1565
|
+
let n = 0, r = 0, a = [];
|
|
1566
|
+
for (let i = 0; i < e.length; i++) {
|
|
1567
|
+
let o = e[i];
|
|
1568
|
+
o === "(" ? n++ : o === ")" ? n-- : o === t && n === 0 && (a.push(e.substring(r, i)), r = i + 1);
|
|
1562
1569
|
}
|
|
1563
|
-
return
|
|
1570
|
+
return a.push(e.substring(r)), a;
|
|
1564
1571
|
}
|
|
1565
1572
|
//#endregion
|
|
1566
1573
|
//#region src/coefficients/root.ts
|
|
@@ -1570,16 +1577,16 @@ var v = class e {
|
|
|
1570
1577
|
#n;
|
|
1571
1578
|
#r = !1;
|
|
1572
1579
|
constructor(e) {
|
|
1573
|
-
return this.#t = 2, this.#e = new
|
|
1580
|
+
return this.#t = 2, this.#e = new m().zero(), this.#n = new m().zero(), e && this.parse(e), this;
|
|
1574
1581
|
}
|
|
1575
1582
|
parse(t) {
|
|
1576
1583
|
if (t instanceof e) return this.index = t.index, this.radical = t.radical.clone(), this.factor = t.factor.clone(), this;
|
|
1577
|
-
if (t instanceof
|
|
1584
|
+
if (t instanceof m) return this.index = 2, this.factor = t.clone(), this.radical.one(), this;
|
|
1578
1585
|
if (typeof t == "string") {
|
|
1579
1586
|
if (t.includes("sqrt")) return this.#s(t);
|
|
1580
1587
|
if (t.includes("root")) return this.#o(t);
|
|
1581
1588
|
}
|
|
1582
|
-
return this.index = 2, this.factor = new
|
|
1589
|
+
return this.index = 2, this.factor = new m(t), this.radical.one(), this;
|
|
1583
1590
|
}
|
|
1584
1591
|
clone() {
|
|
1585
1592
|
return new e().from(this.index, this.radical, this.factor);
|
|
@@ -1599,7 +1606,7 @@ var v = class e {
|
|
|
1599
1606
|
add(t) {
|
|
1600
1607
|
this.reduce();
|
|
1601
1608
|
let n = new e(t).reduce();
|
|
1602
|
-
if (this.index !== n.index || !this.radical.isEqual(n.radical)) throw
|
|
1609
|
+
if (this.index !== n.index || !this.radical.isEqual(n.radical)) throw new r("Add can only be done with two same index and radical");
|
|
1603
1610
|
return this.factor.add(n.factor), this;
|
|
1604
1611
|
}
|
|
1605
1612
|
divide(t) {
|
|
@@ -1612,7 +1619,7 @@ var v = class e {
|
|
|
1612
1619
|
this.#e = e;
|
|
1613
1620
|
}
|
|
1614
1621
|
from(e, t, n) {
|
|
1615
|
-
return this.index = e, this.radical = new
|
|
1622
|
+
return this.index = e, this.radical = new m(t), this.factor = n ? new m(n) : new m().one(), this;
|
|
1616
1623
|
}
|
|
1617
1624
|
group() {
|
|
1618
1625
|
return this.radical.multiply(this.factor.pow(this.index)), this.factor.one(), this;
|
|
@@ -1621,11 +1628,11 @@ var v = class e {
|
|
|
1621
1628
|
return this.#t;
|
|
1622
1629
|
}
|
|
1623
1630
|
set index(e) {
|
|
1624
|
-
if (!Number.isSafeInteger(e) || e <= 0) throw
|
|
1631
|
+
if (!Number.isSafeInteger(e) || e <= 0) throw new i("Index must be a strictly positive integer.");
|
|
1625
1632
|
this.#t = e;
|
|
1626
1633
|
}
|
|
1627
1634
|
get indexAsPow() {
|
|
1628
|
-
return new
|
|
1635
|
+
return new m(this.index).inverse();
|
|
1629
1636
|
}
|
|
1630
1637
|
inverse() {
|
|
1631
1638
|
return this.factor.inverse(), this.radical.inverse(), this;
|
|
@@ -1650,7 +1657,7 @@ var v = class e {
|
|
|
1650
1657
|
let e = this.indexAsPow.add(n.indexAsPow).reduce();
|
|
1651
1658
|
return this.index = e.denominator, this.radical = this.radical.pow(e.numerator), this;
|
|
1652
1659
|
}
|
|
1653
|
-
throw
|
|
1660
|
+
throw new r("Multiply can only be done if radical or index as equals.");
|
|
1654
1661
|
}
|
|
1655
1662
|
one() {
|
|
1656
1663
|
return this.radical.one(), this.factor.one(), this;
|
|
@@ -1660,7 +1667,7 @@ var v = class e {
|
|
|
1660
1667
|
}
|
|
1661
1668
|
pow(e) {
|
|
1662
1669
|
this.factor.pow(e);
|
|
1663
|
-
let t =
|
|
1670
|
+
let t = p.gcd(this.index, e);
|
|
1664
1671
|
return this.index /= t, this.radical.pow(e / t), this;
|
|
1665
1672
|
}
|
|
1666
1673
|
get radical() {
|
|
@@ -1674,7 +1681,7 @@ var v = class e {
|
|
|
1674
1681
|
let e = this.radical.denominator;
|
|
1675
1682
|
this.radical.denominator = 1, this.radical.numerator *= e, this.factor.divide(e);
|
|
1676
1683
|
}
|
|
1677
|
-
let e =
|
|
1684
|
+
let e = p.greatestPower(this.radical.value, this.index);
|
|
1678
1685
|
return this.factor.multiply(e ** (1 / this.index)), this.radical.divide(e), this;
|
|
1679
1686
|
}
|
|
1680
1687
|
root(e) {
|
|
@@ -1688,7 +1695,7 @@ var v = class e {
|
|
|
1688
1695
|
return this.add(n.opposite());
|
|
1689
1696
|
}
|
|
1690
1697
|
get value() {
|
|
1691
|
-
return
|
|
1698
|
+
return p.numberCorrection(this.factor.value * this.radical.value ** (1 / this.index));
|
|
1692
1699
|
}
|
|
1693
1700
|
get withSign() {
|
|
1694
1701
|
return this.#r = !0, this;
|
|
@@ -1708,14 +1715,14 @@ var v = class e {
|
|
|
1708
1715
|
return r.length === 0 ? null : r.join(" ");
|
|
1709
1716
|
}
|
|
1710
1717
|
#o(e) {
|
|
1711
|
-
let
|
|
1712
|
-
if (!
|
|
1713
|
-
let [,
|
|
1714
|
-
return this.index = +
|
|
1718
|
+
let n = /^(.*?)root\((\d+)\)\(?([^)]+)/.exec(e);
|
|
1719
|
+
if (!n) throw new t(`Invalid root format: "${e}"`);
|
|
1720
|
+
let [, r, i, a] = n;
|
|
1721
|
+
return this.index = +i, this.radical = new m(a), this.factor = r === "" ? new m().one() : new m(r.trim()), this;
|
|
1715
1722
|
}
|
|
1716
1723
|
#s(e) {
|
|
1717
1724
|
let [t, n] = e.split("sqrt");
|
|
1718
|
-
return this.index = 2, this.radical = new
|
|
1725
|
+
return this.index = 2, this.radical = new m(h(n)), this.factor = t === "" ? new m().one() : new m(t), this;
|
|
1719
1726
|
}
|
|
1720
1727
|
}, y = class e {
|
|
1721
1728
|
#e;
|
|
@@ -1726,13 +1733,13 @@ var v = class e {
|
|
|
1726
1733
|
#a;
|
|
1727
1734
|
#o;
|
|
1728
1735
|
constructor() {
|
|
1729
|
-
this.#o = "x", this.#n = !1, this.#t = null, this.#a = null, this.#r = new
|
|
1736
|
+
this.#o = "x", this.#n = !1, this.#t = null, this.#a = null, this.#r = new m().zero(), this.#i = new v(), this.#e = 1;
|
|
1730
1737
|
}
|
|
1731
1738
|
get tex() {
|
|
1732
1739
|
if (this.#a) return this.#a;
|
|
1733
1740
|
if (this.#i.isZero()) return this.#r.tex;
|
|
1734
1741
|
if (this.#r.isZero()) return this.#i.tex;
|
|
1735
|
-
let [e] =
|
|
1742
|
+
let [e] = m.toSameDenominateur(this.#r, this.#i.factor), t = this.#i.clone().multiply(e.denominator).reduce(), n = `${e.numerator} ${t.withSign.tex}`;
|
|
1736
1743
|
return e.denominator === 1 ? n : `\\frac{ ${n} }{ ${e.denominator} }`;
|
|
1737
1744
|
}
|
|
1738
1745
|
set tex(e) {
|
|
@@ -1742,7 +1749,7 @@ var v = class e {
|
|
|
1742
1749
|
if (this.#t) return this.#t;
|
|
1743
1750
|
if (this.#i.isZero()) return this.#r.display;
|
|
1744
1751
|
if (this.#r.isZero()) return this.#i.display;
|
|
1745
|
-
let [e] =
|
|
1752
|
+
let [e] = m.toSameDenominateur(this.#r, this.#i.factor), t = this.#i.clone().multiply(e.denominator).reduce(), n = `${e.numerator}${t.withSign.display}`;
|
|
1746
1753
|
return e.denominator === 1 ? n : `(${n})/${e.denominator}`;
|
|
1747
1754
|
}
|
|
1748
1755
|
set display(e) {
|
|
@@ -1751,7 +1758,7 @@ var v = class e {
|
|
|
1751
1758
|
static fromFraction(t) {
|
|
1752
1759
|
let n = new e();
|
|
1753
1760
|
n.setExact();
|
|
1754
|
-
let r = new
|
|
1761
|
+
let r = new m(t);
|
|
1755
1762
|
return n.display = r.display, n.tex = r.tex, n.fraction = r, n.root = new v(), n;
|
|
1756
1763
|
}
|
|
1757
1764
|
static fromQuadratic(t, n, r) {
|
|
@@ -1759,7 +1766,7 @@ var v = class e {
|
|
|
1759
1766
|
t,
|
|
1760
1767
|
n,
|
|
1761
1768
|
r
|
|
1762
|
-
].map((e) => new
|
|
1769
|
+
].map((e) => new m(e)), s = a.clone().pow(2).subtract(i.clone().multiply(o).multiply(4));
|
|
1763
1770
|
if (s.isNegative()) return [];
|
|
1764
1771
|
if (s.isSquare()) {
|
|
1765
1772
|
let t = s.sqrt(), n = a.clone().opposite().subtract(t).divide(i.clone().multiply(2)), r = a.clone().opposite().add(t).divide(i.clone().multiply(2));
|
|
@@ -1812,11 +1819,11 @@ var v = class e {
|
|
|
1812
1819
|
set variable(e) {
|
|
1813
1820
|
e !== void 0 && (this.#o = e);
|
|
1814
1821
|
}
|
|
1815
|
-
},
|
|
1822
|
+
}, ce = class {
|
|
1816
1823
|
#e;
|
|
1817
1824
|
#t;
|
|
1818
1825
|
constructor(e) {
|
|
1819
|
-
this.#e = e instanceof
|
|
1826
|
+
this.#e = e instanceof R || e instanceof P ? new R(e) : new R().fromPolynom(e), this.#t = this.#e.getRoots();
|
|
1820
1827
|
}
|
|
1821
1828
|
get fx() {
|
|
1822
1829
|
return this.#e;
|
|
@@ -1854,15 +1861,15 @@ var v = class e {
|
|
|
1854
1861
|
return r.degree().isZero() ? n : r.degree().value <= 2 ? n.concat(new e(r.clone()).solve()) : (this._ = 0, n.concat(this.#a(r)).sort((e, t) => e.value - t.value));
|
|
1855
1862
|
}
|
|
1856
1863
|
solveAsCardan() {
|
|
1857
|
-
if (this.#t.degree().value !== 3) throw
|
|
1864
|
+
if (this.#t.degree().value !== 3) throw new r("The equation is not cubic.");
|
|
1858
1865
|
return this.#u();
|
|
1859
1866
|
}
|
|
1860
1867
|
#r(e, t) {
|
|
1861
1868
|
let n = new y();
|
|
1862
|
-
return n.exact = !1, n.tex = t?.tex ?? null, n.display = t?.display ?? null, n.fraction = new
|
|
1869
|
+
return n.exact = !1, n.tex = t?.tex ?? null, n.display = t?.display ?? null, n.fraction = new m(e), n.fraction.exact = !1, n.variable = this.#n, n;
|
|
1863
1870
|
}
|
|
1864
1871
|
#i(e) {
|
|
1865
|
-
return e instanceof
|
|
1872
|
+
return e instanceof m && !e.exact ? this.#r(e.value) : y.fromFraction(e);
|
|
1866
1873
|
}
|
|
1867
1874
|
#a(e) {
|
|
1868
1875
|
let t = [], n = e.degree().value, [r, ...i] = e.getCoefficients(), a = 2 + Math.max(...i.map((e) => e.value / r.value)), o = this.#s(e, a, 100);
|
|
@@ -1890,7 +1897,7 @@ var v = class e {
|
|
|
1890
1897
|
#s(e, t, n) {
|
|
1891
1898
|
let r = [], i = 2 * t / n;
|
|
1892
1899
|
for (let n = -t; n <= t; n += i) {
|
|
1893
|
-
let t =
|
|
1900
|
+
let t = p.numberCorrection(n);
|
|
1894
1901
|
r.push({
|
|
1895
1902
|
x: t,
|
|
1896
1903
|
fx: e.evaluate(t, !0)
|
|
@@ -1915,9 +1922,9 @@ var v = class e {
|
|
|
1915
1922
|
let e = t.monoms.reduce((e, t) => t.degree().value < e.degree().value ? t : e), r = e.coefficient;
|
|
1916
1923
|
e.clone().divide(r), t.divide(e);
|
|
1917
1924
|
}
|
|
1918
|
-
let o =
|
|
1925
|
+
let o = p.dividers(i.value), s = p.dividers(a.value), c = [];
|
|
1919
1926
|
for (let e of o) for (let t of s) {
|
|
1920
|
-
let n = new
|
|
1927
|
+
let n = new m(t, e);
|
|
1921
1928
|
c.find((e) => e.value === n.value) || (c.push(n.clone()), c.push(n.opposite().clone()));
|
|
1922
1929
|
}
|
|
1923
1930
|
c.forEach((e) => {
|
|
@@ -1976,23 +1983,27 @@ var v = class e {
|
|
|
1976
1983
|
}
|
|
1977
1984
|
#p(e, t, n) {
|
|
1978
1985
|
let r = e.clone().multiply(2), i = new y();
|
|
1979
|
-
i.fraction = t.clone().opposite().divide(r.clone()), i.root.radical = n.clone(), i.root.factor = new
|
|
1986
|
+
i.fraction = t.clone().opposite().divide(r.clone()), i.root.radical = n.clone(), i.root.factor = new m().one().divide(r.clone()), i.exact = !0;
|
|
1980
1987
|
let a = new y();
|
|
1981
|
-
return a.fraction = t.clone().opposite().divide(r.clone()), a.root.radical = n.clone(), a.root.factor = new
|
|
1988
|
+
return a.fraction = t.clone().opposite().divide(r.clone()), a.root.radical = n.clone(), a.root.factor = new m().one().divide(r.clone()).opposite(), a.exact = !0, [i, a].sort((e, t) => e.value - t.value);
|
|
1989
|
+
}
|
|
1990
|
+
}, le = class extends Error {
|
|
1991
|
+
constructor(e, t) {
|
|
1992
|
+
super(e, t), this.name = new.target.name;
|
|
1982
1993
|
}
|
|
1983
|
-
}, x = {
|
|
1994
|
+
}, x = class extends le {}, S = class extends le {}, ue = class extends S {}, C = {
|
|
1984
1995
|
pi: Math.PI,
|
|
1985
1996
|
e: Math.exp(1)
|
|
1986
|
-
},
|
|
1997
|
+
}, w = /* @__PURE__ */ function(e) {
|
|
1987
1998
|
return e.VARIABLE = "variable", e.COEFFICIENT = "coefficient", e.OPERATION = "operation", e.CONSTANT = "constant", e.FUNCTION = "function", e.FUNCTION_ARGUMENT = "function-argument", e.MONOM = "monom", e.LEFT_PARENTHESIS = "(", e.RIGHT_PARENTHESIS = ")", e;
|
|
1988
|
-
}({}),
|
|
1999
|
+
}({}), T = /* @__PURE__ */ function(e) {
|
|
1989
2000
|
return e.EXPRESSION = "expression", e.POLYNOM = "polynom", e.SET = "set", e.NUMERIC = "numeric", e;
|
|
1990
2001
|
}({});
|
|
1991
|
-
function
|
|
1992
|
-
if (e.length <= 1) return e;
|
|
1993
|
-
let n = Object.keys(t).filter((e) => t[e].type ===
|
|
2002
|
+
function de(e, t) {
|
|
2003
|
+
if (e = e.replace(/\s+/g, ""), e.length <= 1) return e;
|
|
2004
|
+
let n = Object.keys(t).filter((e) => t[e].type === w.FUNCTION).map((e) => e);
|
|
1994
2005
|
n.sort((e, t) => t.length - e.length);
|
|
1995
|
-
let r = RegExp(`^(${n.join("|")})\\(`), i = Object.keys(
|
|
2006
|
+
let r = RegExp(`^(${n.join("|")})\\(`), i = Object.keys(C);
|
|
1996
2007
|
i.sort((e, t) => t.length - e.length);
|
|
1997
2008
|
let a = RegExp(`^(${i.join("|")})`), o = /^(\d+(\.\d+)?)/, s = "", c, l, u;
|
|
1998
2009
|
for (n.forEach((t) => {
|
|
@@ -2001,234 +2012,174 @@ function te(e, t) {
|
|
|
2001
2012
|
e = e.replaceAll(n, `${t}($1)`);
|
|
2002
2013
|
}
|
|
2003
2014
|
}); e.length > 0;) {
|
|
2004
|
-
|
|
2015
|
+
c = l, u = void 0;
|
|
2016
|
+
let t = n.find((t) => e.startsWith(t));
|
|
2017
|
+
if (t !== void 0 && e[t.length] !== "(") throw new x(`Function "${t}" must be followed by parentheses`);
|
|
2018
|
+
if (n.length > 0 && r.exec(e)) {
|
|
2005
2019
|
let t = n.find((t) => e.startsWith(t));
|
|
2006
|
-
t && (u = t + "(", e = e.slice(t.length + 1), l =
|
|
2020
|
+
t && (u = t + "(", e = e.slice(t.length + 1), l = w.FUNCTION);
|
|
2007
2021
|
} else if (i.length > 0 && a.exec(e)) {
|
|
2008
2022
|
let t = i.find((t) => e.startsWith(t));
|
|
2009
|
-
t && (u = t, e = e.slice(t.length), l =
|
|
2023
|
+
t && (u = t, e = e.slice(t.length), l = w.CONSTANT);
|
|
2010
2024
|
} else if (o.exec(e)) {
|
|
2011
2025
|
let t = o.exec(e);
|
|
2012
|
-
t && (u = t[0], e = e.slice(t[0].length), l =
|
|
2026
|
+
t && (u = t[0], e = e.slice(t[0].length), l = w.COEFFICIENT);
|
|
2013
2027
|
} else switch (u = e[0], e = e.slice(1), u) {
|
|
2014
2028
|
case "(":
|
|
2015
|
-
l =
|
|
2029
|
+
l = w.LEFT_PARENTHESIS;
|
|
2016
2030
|
break;
|
|
2017
2031
|
case ")":
|
|
2018
|
-
l =
|
|
2032
|
+
l = w.RIGHT_PARENTHESIS;
|
|
2019
2033
|
break;
|
|
2020
2034
|
case ",":
|
|
2021
|
-
l =
|
|
2035
|
+
l = w.FUNCTION_ARGUMENT;
|
|
2022
2036
|
break;
|
|
2023
2037
|
case "+":
|
|
2024
2038
|
case "-":
|
|
2025
2039
|
case "*":
|
|
2026
2040
|
case "/":
|
|
2027
2041
|
case "^":
|
|
2028
|
-
|
|
2042
|
+
case "%":
|
|
2043
|
+
l = w.OPERATION;
|
|
2029
2044
|
break;
|
|
2030
|
-
default: l =
|
|
2045
|
+
default: l = w.VARIABLE;
|
|
2031
2046
|
}
|
|
2032
2047
|
if (u === void 0 || l === void 0) throw Error("The token is undefined");
|
|
2033
|
-
s +=
|
|
2048
|
+
s += fe(c, l), s += u;
|
|
2034
2049
|
}
|
|
2035
2050
|
return s;
|
|
2036
2051
|
}
|
|
2037
|
-
function
|
|
2038
|
-
return e === void 0 || e ===
|
|
2052
|
+
function fe(e, t) {
|
|
2053
|
+
return e === void 0 || e === w.OPERATION || t === w.OPERATION || e === w.LEFT_PARENTHESIS || e === w.FUNCTION || e === w.FUNCTION_ARGUMENT || t === w.RIGHT_PARENTHESIS || t === w.FUNCTION_ARGUMENT ? "" : "*";
|
|
2039
2054
|
}
|
|
2040
|
-
var
|
|
2055
|
+
var pe = {
|
|
2041
2056
|
"^": {
|
|
2042
2057
|
precedence: 4,
|
|
2043
2058
|
associative: "right",
|
|
2044
|
-
type:
|
|
2059
|
+
type: w.OPERATION
|
|
2045
2060
|
},
|
|
2046
2061
|
"*": {
|
|
2047
2062
|
precedence: 3,
|
|
2048
2063
|
associative: "left",
|
|
2049
|
-
type:
|
|
2064
|
+
type: w.OPERATION
|
|
2050
2065
|
},
|
|
2051
2066
|
"/": {
|
|
2052
2067
|
precedence: 3,
|
|
2053
2068
|
associative: "left",
|
|
2054
|
-
type:
|
|
2069
|
+
type: w.OPERATION
|
|
2055
2070
|
},
|
|
2056
2071
|
"+": {
|
|
2057
2072
|
precedence: 2,
|
|
2058
2073
|
associative: "left",
|
|
2059
|
-
type:
|
|
2074
|
+
type: w.OPERATION
|
|
2060
2075
|
},
|
|
2061
2076
|
"-": {
|
|
2062
2077
|
precedence: 2,
|
|
2063
2078
|
associative: "left",
|
|
2064
|
-
type:
|
|
2065
|
-
}
|
|
2066
|
-
}, ie = {
|
|
2067
|
-
"^": {
|
|
2068
|
-
precedence: 4,
|
|
2069
|
-
associative: "right",
|
|
2070
|
-
type: S.OPERATION
|
|
2079
|
+
type: w.OPERATION
|
|
2071
2080
|
},
|
|
2072
|
-
"
|
|
2081
|
+
"%": {
|
|
2073
2082
|
precedence: 3,
|
|
2074
2083
|
associative: "left",
|
|
2075
|
-
type:
|
|
2084
|
+
type: w.OPERATION
|
|
2076
2085
|
},
|
|
2077
|
-
"
|
|
2086
|
+
"&": {
|
|
2078
2087
|
precedence: 3,
|
|
2079
2088
|
associative: "left",
|
|
2080
|
-
type:
|
|
2081
|
-
},
|
|
2082
|
-
"+": {
|
|
2083
|
-
precedence: 2,
|
|
2084
|
-
associative: "left",
|
|
2085
|
-
type: S.OPERATION
|
|
2089
|
+
type: w.OPERATION
|
|
2086
2090
|
},
|
|
2087
|
-
"
|
|
2088
|
-
precedence:
|
|
2091
|
+
"|": {
|
|
2092
|
+
precedence: 3,
|
|
2089
2093
|
associative: "left",
|
|
2090
|
-
type:
|
|
2094
|
+
type: w.OPERATION
|
|
2091
2095
|
},
|
|
2092
|
-
"
|
|
2093
|
-
precedence:
|
|
2096
|
+
"!": {
|
|
2097
|
+
precedence: 4,
|
|
2094
2098
|
associative: "right",
|
|
2095
|
-
type:
|
|
2099
|
+
type: w.OPERATION
|
|
2096
2100
|
},
|
|
2097
2101
|
sin: {
|
|
2098
2102
|
precedence: 4,
|
|
2099
2103
|
associative: "right",
|
|
2100
|
-
type:
|
|
2104
|
+
type: w.FUNCTION,
|
|
2105
|
+
arity: 1
|
|
2101
2106
|
},
|
|
2102
2107
|
cos: {
|
|
2103
2108
|
precedence: 4,
|
|
2104
2109
|
associative: "right",
|
|
2105
|
-
type:
|
|
2110
|
+
type: w.FUNCTION,
|
|
2111
|
+
arity: 1
|
|
2106
2112
|
},
|
|
2107
2113
|
tan: {
|
|
2108
2114
|
precedence: 4,
|
|
2109
2115
|
associative: "right",
|
|
2110
|
-
type:
|
|
2111
|
-
|
|
2112
|
-
sqrt: {
|
|
2113
|
-
precedence: 4,
|
|
2114
|
-
associative: "right",
|
|
2115
|
-
type: S.FUNCTION
|
|
2116
|
-
},
|
|
2117
|
-
nthrt: {
|
|
2118
|
-
precedence: 4,
|
|
2119
|
-
associative: "right",
|
|
2120
|
-
type: S.FUNCTION
|
|
2121
|
-
},
|
|
2122
|
-
logn: {
|
|
2123
|
-
precedence: 4,
|
|
2124
|
-
associative: "right",
|
|
2125
|
-
type: S.FUNCTION
|
|
2126
|
-
},
|
|
2127
|
-
",": {
|
|
2128
|
-
precedence: 2,
|
|
2129
|
-
associative: "left",
|
|
2130
|
-
type: S.FUNCTION_ARGUMENT
|
|
2131
|
-
}
|
|
2132
|
-
}, ae = {
|
|
2133
|
-
"^": {
|
|
2134
|
-
precedence: 4,
|
|
2135
|
-
associative: "right",
|
|
2136
|
-
type: S.OPERATION
|
|
2137
|
-
},
|
|
2138
|
-
"*": {
|
|
2139
|
-
precedence: 3,
|
|
2140
|
-
associative: "left",
|
|
2141
|
-
type: S.OPERATION
|
|
2142
|
-
},
|
|
2143
|
-
"/": {
|
|
2144
|
-
precedence: 3,
|
|
2145
|
-
associative: "left",
|
|
2146
|
-
type: S.OPERATION
|
|
2147
|
-
},
|
|
2148
|
-
"+": {
|
|
2149
|
-
precedence: 2,
|
|
2150
|
-
associative: "left",
|
|
2151
|
-
type: S.OPERATION
|
|
2152
|
-
},
|
|
2153
|
-
"-": {
|
|
2154
|
-
precedence: 2,
|
|
2155
|
-
associative: "left",
|
|
2156
|
-
type: S.OPERATION
|
|
2157
|
-
},
|
|
2158
|
-
"%": {
|
|
2159
|
-
precedence: 3,
|
|
2160
|
-
associative: "right",
|
|
2161
|
-
type: S.OPERATION
|
|
2116
|
+
type: w.FUNCTION,
|
|
2117
|
+
arity: 1
|
|
2162
2118
|
},
|
|
2163
|
-
|
|
2119
|
+
asin: {
|
|
2164
2120
|
precedence: 4,
|
|
2165
2121
|
associative: "right",
|
|
2166
|
-
type:
|
|
2122
|
+
type: w.FUNCTION,
|
|
2123
|
+
arity: 1
|
|
2167
2124
|
},
|
|
2168
|
-
|
|
2125
|
+
acos: {
|
|
2169
2126
|
precedence: 4,
|
|
2170
2127
|
associative: "right",
|
|
2171
|
-
type:
|
|
2128
|
+
type: w.FUNCTION,
|
|
2129
|
+
arity: 1
|
|
2172
2130
|
},
|
|
2173
|
-
|
|
2131
|
+
atan: {
|
|
2174
2132
|
precedence: 4,
|
|
2175
2133
|
associative: "right",
|
|
2176
|
-
type:
|
|
2134
|
+
type: w.FUNCTION,
|
|
2135
|
+
arity: 1
|
|
2177
2136
|
},
|
|
2178
2137
|
sqrt: {
|
|
2179
2138
|
precedence: 4,
|
|
2180
2139
|
associative: "right",
|
|
2181
|
-
type:
|
|
2140
|
+
type: w.FUNCTION,
|
|
2141
|
+
arity: 1
|
|
2182
2142
|
},
|
|
2183
2143
|
nthrt: {
|
|
2184
2144
|
precedence: 4,
|
|
2185
2145
|
associative: "right",
|
|
2186
|
-
type:
|
|
2146
|
+
type: w.FUNCTION,
|
|
2147
|
+
arity: 2
|
|
2187
2148
|
},
|
|
2188
2149
|
ln: {
|
|
2189
2150
|
precedence: 4,
|
|
2190
2151
|
associative: "right",
|
|
2191
|
-
type:
|
|
2192
|
-
|
|
2193
|
-
logn: {
|
|
2194
|
-
precedence: 4,
|
|
2195
|
-
associative: "right",
|
|
2196
|
-
type: S.FUNCTION
|
|
2152
|
+
type: w.FUNCTION,
|
|
2153
|
+
arity: 1
|
|
2197
2154
|
},
|
|
2198
2155
|
log: {
|
|
2199
2156
|
precedence: 4,
|
|
2200
2157
|
associative: "right",
|
|
2201
|
-
type:
|
|
2202
|
-
|
|
2203
|
-
}, oe = {
|
|
2204
|
-
"&": {
|
|
2205
|
-
precedence: 3,
|
|
2206
|
-
associative: "left",
|
|
2207
|
-
type: S.OPERATION
|
|
2158
|
+
type: w.FUNCTION,
|
|
2159
|
+
arity: 1
|
|
2208
2160
|
},
|
|
2209
|
-
|
|
2210
|
-
precedence: 3,
|
|
2211
|
-
associative: "left",
|
|
2212
|
-
type: S.OPERATION
|
|
2213
|
-
},
|
|
2214
|
-
"!": {
|
|
2161
|
+
logn: {
|
|
2215
2162
|
precedence: 4,
|
|
2216
2163
|
associative: "right",
|
|
2217
|
-
type:
|
|
2218
|
-
|
|
2219
|
-
"-": {
|
|
2220
|
-
precedence: 2,
|
|
2221
|
-
associative: "left",
|
|
2222
|
-
type: S.OPERATION
|
|
2164
|
+
type: w.FUNCTION,
|
|
2165
|
+
arity: 2
|
|
2223
2166
|
}
|
|
2224
|
-
}
|
|
2167
|
+
};
|
|
2168
|
+
function E(...e) {
|
|
2169
|
+
let t = {};
|
|
2170
|
+
for (let n of e) t[n] = pe[n];
|
|
2171
|
+
return t;
|
|
2172
|
+
}
|
|
2173
|
+
var me = {};
|
|
2174
|
+
for (let [e, t] of Object.entries(pe)) t.type === w.FUNCTION && (me[e] = t.arity ?? 1);
|
|
2175
|
+
var he = E("^", "*", "/", "+", "-"), D = E("^", "*", "/", "+", "-", "%", "sin", "cos", "tan", "asin", "acos", "atan", "sqrt", "nthrt", "ln", "log", "logn"), ge = D, _e = E("&", "|", "!", "-"), O = class {
|
|
2225
2176
|
#e;
|
|
2226
2177
|
#t = [];
|
|
2227
2178
|
#n = {};
|
|
2228
2179
|
#r = [];
|
|
2229
2180
|
#i;
|
|
2230
2181
|
constructor(e) {
|
|
2231
|
-
this.#e = e === void 0 ?
|
|
2182
|
+
this.#e = e === void 0 ? T.POLYNOM : e, this.tokenConfigInitialization();
|
|
2232
2183
|
}
|
|
2233
2184
|
get rpn() {
|
|
2234
2185
|
return this.#t;
|
|
@@ -2237,217 +2188,216 @@ var re = {
|
|
|
2237
2188
|
return this.#t.map((e) => e.token);
|
|
2238
2189
|
}
|
|
2239
2190
|
tokenConfigInitialization() {
|
|
2240
|
-
return this.#e ===
|
|
2191
|
+
return this.#e === T.SET ? (this.#n = _e, this.#i = !1) : this.#e === T.NUMERIC ? (this.#n = D, this.#i = !0) : this.#e === T.EXPRESSION ? (this.#n = ge, this.#i = !0) : (this.#n = he, this.#i = !0), this.#r = Object.keys(this.#n).sort((e, t) => t.length - e.length), this.#n;
|
|
2241
2192
|
}
|
|
2242
2193
|
NextToken(e, t) {
|
|
2243
2194
|
let n, r;
|
|
2244
|
-
if (n = "", r = void 0, e[t] === "(") n = "(", r =
|
|
2245
|
-
else if (e[t] === ")") n = ")", r =
|
|
2246
|
-
else if (e[t] === ",") n = ",", r =
|
|
2195
|
+
if (n = "", r = void 0, e[t] === "(") n = "(", r = w.LEFT_PARENTHESIS;
|
|
2196
|
+
else if (e[t] === ")") n = ")", r = w.RIGHT_PARENTHESIS;
|
|
2197
|
+
else if (e[t] === ",") n = ",", r = w.FUNCTION_ARGUMENT;
|
|
2247
2198
|
else {
|
|
2248
2199
|
for (let i of this.#r) if (e.substring(t, t + i.length) === i) {
|
|
2249
2200
|
n += i, r = this.#n[i].type;
|
|
2250
2201
|
break;
|
|
2251
2202
|
}
|
|
2252
|
-
for (let i in
|
|
2253
|
-
n += i, r =
|
|
2203
|
+
for (let i in C) if (e.substring(t, t + i.length) === i) {
|
|
2204
|
+
n += i, r = w.CONSTANT;
|
|
2254
2205
|
break;
|
|
2255
2206
|
}
|
|
2256
2207
|
if (n === "") if (/[0-9.]/.exec(e[t])) {
|
|
2257
2208
|
let i = /^([0-9.]+)/.exec(e.substring(t));
|
|
2258
|
-
n = i ? i[0] : "", r =
|
|
2209
|
+
n = i ? i[0] : "", r = w.COEFFICIENT;
|
|
2259
2210
|
} else if (/[a-zA-Z]/.exec(e[t])) {
|
|
2260
2211
|
let i = /^([a-zA-Z])/.exec(e.substring(t));
|
|
2261
|
-
n = i ? i[0] : "", r =
|
|
2262
|
-
} else
|
|
2212
|
+
n = i ? i[0] : "", r = w.VARIABLE;
|
|
2213
|
+
} else throw new x(`Unknown token "${e[t]}" at position ${t} in "${e}"`);
|
|
2263
2214
|
}
|
|
2264
|
-
if (r === void 0) throw
|
|
2265
|
-
return
|
|
2266
|
-
n,
|
|
2267
|
-
t + n.length,
|
|
2268
|
-
r
|
|
2269
|
-
|
|
2215
|
+
if (r === void 0) throw new x(`Token type is undefined for token ${n}`);
|
|
2216
|
+
return {
|
|
2217
|
+
token: n,
|
|
2218
|
+
nextPos: t + n.length,
|
|
2219
|
+
type: r
|
|
2220
|
+
};
|
|
2270
2221
|
}
|
|
2271
2222
|
parse(e, t) {
|
|
2272
|
-
let n = [], r = [], i =
|
|
2273
|
-
(t ?? this.#i) && (e =
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
switch ([i, a, o] = this.NextToken(e, a), o) {
|
|
2281
|
-
case S.MONOM:
|
|
2282
|
-
case S.COEFFICIENT:
|
|
2283
|
-
case S.VARIABLE:
|
|
2284
|
-
case S.CONSTANT:
|
|
2223
|
+
let n = [], r = [], i = 0;
|
|
2224
|
+
for ((t ?? this.#i) && (e = de(e, this.#n)); i < e.length;) {
|
|
2225
|
+
let t = i, { token: a, nextPos: o, type: s } = this.NextToken(e, i);
|
|
2226
|
+
if (i = o, i <= t) throw new x(`Parser stalled at position ${t} in "${e}"`);
|
|
2227
|
+
switch (s) {
|
|
2228
|
+
case w.COEFFICIENT:
|
|
2229
|
+
case w.VARIABLE:
|
|
2230
|
+
case w.CONSTANT:
|
|
2285
2231
|
n.push({
|
|
2286
|
-
token:
|
|
2287
|
-
tokenType:
|
|
2232
|
+
token: a,
|
|
2233
|
+
tokenType: s
|
|
2288
2234
|
});
|
|
2289
2235
|
break;
|
|
2290
|
-
case
|
|
2236
|
+
case w.OPERATION:
|
|
2291
2237
|
if (r.length > 0) {
|
|
2292
2238
|
let e = r[r.length - 1];
|
|
2293
|
-
for (
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
}
|
|
2298
|
-
if (n.push(r.pop() ?? {
|
|
2299
|
-
token: "",
|
|
2300
|
-
tokenType: S.OPERATION
|
|
2301
|
-
}), r.length === 0) break;
|
|
2302
|
-
e = r[r.length - 1];
|
|
2303
|
-
}
|
|
2239
|
+
for (; e.token in this.#n && (this.#n[a].associative === "left" && this.#n[a].precedence <= this.#n[e.token].precedence || this.#n[a].associative === "right" && this.#n[a].precedence < this.#n[e.token].precedence) && (n.push(r.pop() ?? {
|
|
2240
|
+
token: "",
|
|
2241
|
+
tokenType: w.OPERATION
|
|
2242
|
+
}), r.length !== 0);) e = r[r.length - 1];
|
|
2304
2243
|
}
|
|
2305
2244
|
r.push({
|
|
2306
|
-
token:
|
|
2307
|
-
tokenType:
|
|
2245
|
+
token: a,
|
|
2246
|
+
tokenType: s
|
|
2308
2247
|
});
|
|
2309
2248
|
break;
|
|
2310
|
-
case
|
|
2311
|
-
for (
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
n.push(r.pop() ?? {
|
|
2317
|
-
token: i,
|
|
2318
|
-
tokenType: o
|
|
2319
|
-
});
|
|
2320
|
-
}
|
|
2249
|
+
case w.FUNCTION_ARGUMENT:
|
|
2250
|
+
for (; r.length > 0 && r[r.length - 1].token !== "(";) n.push(r.pop() ?? {
|
|
2251
|
+
token: a,
|
|
2252
|
+
tokenType: s
|
|
2253
|
+
});
|
|
2254
|
+
if (r.length === 0) throw new x(`Misplaced argument separator ',' in "${e}"`);
|
|
2321
2255
|
break;
|
|
2322
|
-
case
|
|
2256
|
+
case w.LEFT_PARENTHESIS:
|
|
2323
2257
|
r.push({
|
|
2324
|
-
token:
|
|
2325
|
-
tokenType:
|
|
2326
|
-
}), e[
|
|
2258
|
+
token: a,
|
|
2259
|
+
tokenType: s
|
|
2260
|
+
}), e[i] === "-" && n.push({
|
|
2327
2261
|
token: "0",
|
|
2328
|
-
tokenType:
|
|
2262
|
+
tokenType: w.COEFFICIENT
|
|
2329
2263
|
});
|
|
2330
2264
|
break;
|
|
2331
|
-
case
|
|
2332
|
-
for (
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
n.push(r.pop() ?? {
|
|
2338
|
-
token: i,
|
|
2339
|
-
tokenType: o
|
|
2340
|
-
});
|
|
2341
|
-
}
|
|
2265
|
+
case w.RIGHT_PARENTHESIS:
|
|
2266
|
+
for (; r.length > 0 && r[r.length - 1].token !== "(";) n.push(r.pop() ?? {
|
|
2267
|
+
token: a,
|
|
2268
|
+
tokenType: s
|
|
2269
|
+
});
|
|
2270
|
+
if (r.length === 0) throw new x(`Mismatched parentheses (unexpected ')') in "${e}"`);
|
|
2342
2271
|
r.pop();
|
|
2343
2272
|
break;
|
|
2344
|
-
case
|
|
2273
|
+
case w.FUNCTION:
|
|
2345
2274
|
r.push({
|
|
2346
|
-
token:
|
|
2347
|
-
tokenType:
|
|
2275
|
+
token: a,
|
|
2276
|
+
tokenType: s
|
|
2348
2277
|
});
|
|
2349
2278
|
break;
|
|
2350
|
-
default: throw
|
|
2279
|
+
default: throw new x(`Token type ${a} is not handled`);
|
|
2351
2280
|
}
|
|
2352
2281
|
}
|
|
2282
|
+
if (r.some((e) => e.token === "(")) throw new x(`Mismatched parentheses (unclosed '(') in "${e}"`);
|
|
2353
2283
|
return this.#t = n.concat(r.reverse()), this;
|
|
2354
2284
|
}
|
|
2355
|
-
},
|
|
2285
|
+
}, k = class {
|
|
2356
2286
|
_rpn;
|
|
2357
2287
|
_expression;
|
|
2358
|
-
_isValid;
|
|
2359
2288
|
constructor(e, t) {
|
|
2360
2289
|
this._expression = e;
|
|
2361
2290
|
try {
|
|
2362
|
-
this._rpn = new
|
|
2291
|
+
this._rpn = new O(T.NUMERIC).parse(e, t).rpn;
|
|
2363
2292
|
} catch (t) {
|
|
2364
|
-
throw
|
|
2293
|
+
throw new x(`There was a problem parsing: ${e}`, { cause: t });
|
|
2365
2294
|
}
|
|
2366
2295
|
}
|
|
2367
2296
|
get rpn() {
|
|
2368
|
-
return this._rpn
|
|
2369
|
-
}
|
|
2370
|
-
get isValid() {
|
|
2371
|
-
if (this._isValid === void 0) try {
|
|
2372
|
-
this.evaluate({ x: 2 });
|
|
2373
|
-
} catch (e) {
|
|
2374
|
-
e instanceof Error, this._isValid = !1;
|
|
2375
|
-
}
|
|
2376
|
-
return this._isValid ?? !1;
|
|
2377
|
-
}
|
|
2378
|
-
set isValid(e) {
|
|
2379
|
-
this._isValid = e;
|
|
2297
|
+
return this._rpn;
|
|
2380
2298
|
}
|
|
2381
2299
|
get expression() {
|
|
2382
2300
|
return this._expression;
|
|
2383
2301
|
}
|
|
2302
|
+
get variables() {
|
|
2303
|
+
let e = /* @__PURE__ */ new Set();
|
|
2304
|
+
for (let t of this._rpn) t.tokenType === w.VARIABLE && e.add(t.token);
|
|
2305
|
+
return [...e];
|
|
2306
|
+
}
|
|
2307
|
+
isValid(e) {
|
|
2308
|
+
return this._isStructurallyValid() ? this.variables.every((t) => e !== void 0 && Object.hasOwn(e, t)) : !1;
|
|
2309
|
+
}
|
|
2310
|
+
_isStructurallyValid() {
|
|
2311
|
+
let e = 0;
|
|
2312
|
+
for (let t of this._rpn) switch (t.tokenType) {
|
|
2313
|
+
case w.COEFFICIENT:
|
|
2314
|
+
case w.VARIABLE:
|
|
2315
|
+
case w.CONSTANT:
|
|
2316
|
+
e += 1;
|
|
2317
|
+
break;
|
|
2318
|
+
case w.OPERATION:
|
|
2319
|
+
if (e < 2) return !1;
|
|
2320
|
+
--e;
|
|
2321
|
+
break;
|
|
2322
|
+
case w.FUNCTION: {
|
|
2323
|
+
let n = me[t.token] ?? 1;
|
|
2324
|
+
if (e < n) return !1;
|
|
2325
|
+
e += 1 - n;
|
|
2326
|
+
break;
|
|
2327
|
+
}
|
|
2328
|
+
default: return !1;
|
|
2329
|
+
}
|
|
2330
|
+
return e === 1;
|
|
2331
|
+
}
|
|
2384
2332
|
evaluate(e) {
|
|
2385
2333
|
let t = [];
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
t.push(e[0] / +e[1]);
|
|
2393
|
-
}
|
|
2394
|
-
else if (n.tokenType === S.VARIABLE && e !== void 0) Object.hasOwn(e, n.token) && t.push(+e[n.token]);
|
|
2395
|
-
else if (n.tokenType === S.CONSTANT) t.push(x[n.token]);
|
|
2396
|
-
else if (n.tokenType === S.OPERATION) {
|
|
2334
|
+
for (let n of this._rpn) if (n.tokenType === w.COEFFICIENT) t.push(+n.token);
|
|
2335
|
+
else if (n.tokenType === w.VARIABLE) {
|
|
2336
|
+
if (e === void 0 || !Object.hasOwn(e, n.token)) throw new ue(`Missing value for variable "${n.token}"`);
|
|
2337
|
+
t.push(e[n.token]);
|
|
2338
|
+
} else if (n.tokenType === w.CONSTANT) t.push(C[n.token]);
|
|
2339
|
+
else if (n.tokenType === w.OPERATION) {
|
|
2397
2340
|
if (n.token === "*") {
|
|
2398
2341
|
let e = t.pop(), n = t.pop();
|
|
2399
|
-
if (n === void 0 || e === void 0) throw
|
|
2342
|
+
if (n === void 0 || e === void 0) throw new S(`The multiplication factors ${n ?? "a"} or ${e ?? "b"} are not defined`);
|
|
2400
2343
|
t.push(n * e);
|
|
2401
2344
|
} else if (n.token === "/") {
|
|
2402
2345
|
let e = t.pop(), n = t.pop();
|
|
2403
|
-
if (n === void 0 || e === void 0) throw
|
|
2346
|
+
if (n === void 0 || e === void 0) throw new S(`The division values ${n ?? "a"} or ${e ?? "b"} are not defined`);
|
|
2404
2347
|
t.push(n / e);
|
|
2405
2348
|
} else if (n.token === "+") {
|
|
2406
2349
|
let e = t.pop(), n = t.pop();
|
|
2407
|
-
if (n === void 0 || e === void 0) throw
|
|
2408
|
-
t.push(
|
|
2350
|
+
if (n === void 0 || e === void 0) throw new S(`The addition values ${n ?? "a"} or ${e ?? "b"} are not defined`);
|
|
2351
|
+
t.push(n + e);
|
|
2409
2352
|
} else if (n.token === "-") {
|
|
2410
2353
|
let e = t.pop(), n = t.pop() ?? 0;
|
|
2411
|
-
if (e === void 0) throw
|
|
2354
|
+
if (e === void 0) throw new S("The subtraction value b is not defined");
|
|
2412
2355
|
t.push(n - e);
|
|
2356
|
+
} else if (n.token === "%") {
|
|
2357
|
+
let e = t.pop(), n = t.pop();
|
|
2358
|
+
if (n === void 0 || e === void 0) throw new S(`The modulo values ${n ?? "a"} or ${e ?? "b"} are not defined`);
|
|
2359
|
+
t.push(n % e);
|
|
2413
2360
|
} else if (n.token === "^") {
|
|
2414
2361
|
let e = t.pop(), n = t.pop();
|
|
2415
|
-
if (n === void 0 || e === void 0) throw
|
|
2362
|
+
if (n === void 0 || e === void 0) throw new S(`The base value ${n ?? "a"} or exponent ${e ?? "b"} are not defined`);
|
|
2416
2363
|
t.push(n ** +e);
|
|
2417
2364
|
}
|
|
2418
|
-
} else if (n.tokenType ===
|
|
2365
|
+
} else if (n.tokenType === w.FUNCTION) {
|
|
2419
2366
|
let e = t.pop();
|
|
2420
|
-
if (e === void 0) throw
|
|
2367
|
+
if (e === void 0) throw new S(`The parameters for ${n.token} is not defined`);
|
|
2421
2368
|
if (n.token === "sin") t.push(Math.sin(e));
|
|
2422
2369
|
else if (n.token === "cos") t.push(Math.cos(e));
|
|
2423
2370
|
else if (n.token === "tan") t.push(Math.tan(e));
|
|
2371
|
+
else if (n.token === "asin") t.push(Math.asin(e));
|
|
2372
|
+
else if (n.token === "acos") t.push(Math.acos(e));
|
|
2373
|
+
else if (n.token === "atan") t.push(Math.atan(e));
|
|
2424
2374
|
else if (n.token === "sqrt") t.push(Math.sqrt(e));
|
|
2425
2375
|
else if (n.token === "nthrt") {
|
|
2426
2376
|
let n = t.pop();
|
|
2427
|
-
if (n === void 0) throw
|
|
2377
|
+
if (n === void 0) throw new S("The nthrt function requires two parameters");
|
|
2428
2378
|
e % 2 == 0 && n < 0 ? t.push(NaN) : t.push((n < 0 ? -1 : 1) * Math.abs(n) ** (1 / e));
|
|
2429
2379
|
} else if (n.token === "ln") t.push(Math.log(e));
|
|
2430
2380
|
else if (n.token === "log") t.push(Math.log10(e));
|
|
2431
2381
|
else if (n.token === "logn") {
|
|
2432
2382
|
let n = t.pop();
|
|
2433
|
-
if (n === void 0) throw
|
|
2383
|
+
if (n === void 0) throw new S("The logn function requires two parameters");
|
|
2434
2384
|
e <= 0 || e === 1 || n <= 0 ? t.push(NaN) : t.push(Math.log(n) / Math.log(e));
|
|
2435
2385
|
}
|
|
2436
2386
|
}
|
|
2437
2387
|
if (t.length === 1) return this._numberCorrection(t[0]);
|
|
2438
|
-
throw
|
|
2388
|
+
throw new S(`There was a problem parsing: ${this._expression}`);
|
|
2439
2389
|
}
|
|
2440
2390
|
_numberCorrection(e, t = 8) {
|
|
2441
2391
|
return +e.toFixed(t);
|
|
2442
2392
|
}
|
|
2443
|
-
},
|
|
2393
|
+
}, A = class e {
|
|
2444
2394
|
#e;
|
|
2445
2395
|
#t;
|
|
2446
2396
|
constructor(e) {
|
|
2447
|
-
return this.#e = new
|
|
2397
|
+
return this.#e = new m().zero(), this.#t = {}, e !== void 0 && this.parse(e), this;
|
|
2448
2398
|
}
|
|
2449
2399
|
parse(t) {
|
|
2450
|
-
return this.#e = new
|
|
2400
|
+
return this.#e = new m(), this.#t = {}, t instanceof e ? (this.#e = t.#e.clone(), this.#n(t), this) : t instanceof m ? (this.#e = t.clone(), this) : typeof t == "number" ? (this.#e = new m(t), this) : (isNaN(Number(t)) ? this.#s(t) : this.#e = new m(Number(t)), this);
|
|
2451
2401
|
}
|
|
2452
2402
|
clone = () => {
|
|
2453
2403
|
let t = new e();
|
|
@@ -2464,10 +2414,10 @@ var re = {
|
|
|
2464
2414
|
static gcd = (...t) => {
|
|
2465
2415
|
for (let n of t) if (n.containsRationalPower()) return new e().zero();
|
|
2466
2416
|
let n = new e();
|
|
2467
|
-
n.coefficient = new p
|
|
2417
|
+
n.coefficient = new m(p.gcd(...t.map((e) => e.coefficient.numerator)), p.lcm(...t.map((e) => e.coefficient.denominator))).reduce();
|
|
2468
2418
|
for (let e of t) {
|
|
2469
2419
|
for (let t in n.literal) t in e.literal || n.removeVariable(t);
|
|
2470
|
-
for (let t in e.literal) !n.hasVariable(t) && e.literal[t].isStrictlyPositive() ? n.literal[t] = e.literal[t].clone() : n.literal[t] = new
|
|
2420
|
+
for (let t in e.literal) !n.hasVariable(t) && e.literal[t].isStrictlyPositive() ? n.literal[t] = e.literal[t].clone() : n.literal[t] = new m(Math.min(e.literal[t].value, n.literal[t].value));
|
|
2471
2421
|
}
|
|
2472
2422
|
return n;
|
|
2473
2423
|
};
|
|
@@ -2480,7 +2430,7 @@ var re = {
|
|
|
2480
2430
|
for (let n of t) {
|
|
2481
2431
|
let t = n instanceof e ? n : new e(n);
|
|
2482
2432
|
if (this.isSameAs(t)) this.isZero() && this.#n(t), this.#e.add(t.coefficient);
|
|
2483
|
-
else throw
|
|
2433
|
+
else throw new r("Add monom: " + this.display + " is not similar with " + t.display);
|
|
2484
2434
|
}
|
|
2485
2435
|
return this;
|
|
2486
2436
|
};
|
|
@@ -2488,14 +2438,14 @@ var re = {
|
|
|
2488
2438
|
return this.#e;
|
|
2489
2439
|
}
|
|
2490
2440
|
set coefficient(e) {
|
|
2491
|
-
this.#e = new
|
|
2441
|
+
this.#e = new m(e);
|
|
2492
2442
|
}
|
|
2493
2443
|
containsRationalPower = () => Object.values(this.#t).some((e) => e.isRational());
|
|
2494
|
-
degree = (e) => this.variables.length === 0 ? new
|
|
2444
|
+
degree = (e) => this.variables.length === 0 ? new m().zero() : e === void 0 ? Object.values(this.#t).reduce((e, t) => e.clone().add(t)) : this.hasVariable(e) ? this.#t[e].clone() : new m().zero();
|
|
2495
2445
|
derivative = (t = "x") => {
|
|
2496
2446
|
if (this.hasVariable(t)) {
|
|
2497
2447
|
let e = this.#t[t].clone(), n = this.clone();
|
|
2498
|
-
return n.#t[t].subtract(1), n.#e.multiply(new
|
|
2448
|
+
return n.#t[t].subtract(1), n.#e.multiply(new m(e.clone())), n;
|
|
2499
2449
|
}
|
|
2500
2450
|
return new e().zero();
|
|
2501
2451
|
};
|
|
@@ -2509,42 +2459,42 @@ var re = {
|
|
|
2509
2459
|
};
|
|
2510
2460
|
get dividers() {
|
|
2511
2461
|
if (!this.coefficient.isRelative() || this.containsRationalPower() || this.coefficient.numerator > 1e6) return [this.clone()];
|
|
2512
|
-
let t =
|
|
2462
|
+
let t = p.dividers(Math.abs(this.coefficient.numerator)), n = [];
|
|
2513
2463
|
for (let e in this.literal) n = this.#a(n, e);
|
|
2514
2464
|
let r = [];
|
|
2515
2465
|
if (n.length > 0 && t.length > 0) for (let i of t) for (let t of n) {
|
|
2516
2466
|
let n = new e();
|
|
2517
|
-
n.coefficient = new
|
|
2467
|
+
n.coefficient = new m(i), n.literal = t, r.push(n);
|
|
2518
2468
|
}
|
|
2519
2469
|
else if (t.length === 0) for (let t of n) {
|
|
2520
2470
|
let n = new e();
|
|
2521
|
-
n.coefficient = new
|
|
2471
|
+
n.coefficient = new m().one(), n.literal = t, r.push(n);
|
|
2522
2472
|
}
|
|
2523
2473
|
else for (let n of t) {
|
|
2524
2474
|
let t = new e();
|
|
2525
|
-
t.coefficient = new
|
|
2475
|
+
t.coefficient = new m(n), r.push(t);
|
|
2526
2476
|
}
|
|
2527
2477
|
return r.length === 0 ? [new e().one()] : r;
|
|
2528
2478
|
}
|
|
2529
2479
|
evaluate = (e, t) => {
|
|
2530
2480
|
if (t === !0) {
|
|
2531
|
-
if (e instanceof
|
|
2481
|
+
if (e instanceof m) return this.#r(e.value);
|
|
2532
2482
|
if (typeof e == "number") return this.#r(e);
|
|
2533
2483
|
if (typeof e == "object") {
|
|
2534
2484
|
let t = {};
|
|
2535
|
-
for (let n in e) t[n] = new
|
|
2485
|
+
for (let n in e) t[n] = new m(e[n]).value;
|
|
2536
2486
|
return this.#r(t);
|
|
2537
2487
|
}
|
|
2538
2488
|
}
|
|
2539
2489
|
let n = this.coefficient.clone();
|
|
2540
|
-
if (typeof e == "number" || e instanceof
|
|
2490
|
+
if (typeof e == "number" || e instanceof m) {
|
|
2541
2491
|
let t = {};
|
|
2542
|
-
return t[this.variables[0]] = new
|
|
2492
|
+
return t[this.variables[0]] = new m(e), this.evaluate(t);
|
|
2543
2493
|
}
|
|
2544
2494
|
if (typeof e == "object") {
|
|
2545
2495
|
if (this.variables.length === 0) return this.coefficient;
|
|
2546
2496
|
for (let t in this.#t) {
|
|
2547
|
-
let r = new
|
|
2497
|
+
let r = new m(e[t]);
|
|
2548
2498
|
n.multiply(r.pow(this.#t[t]));
|
|
2549
2499
|
}
|
|
2550
2500
|
}
|
|
@@ -2590,8 +2540,8 @@ var re = {
|
|
|
2590
2540
|
this.#t = e;
|
|
2591
2541
|
}
|
|
2592
2542
|
set literalStr(e) {
|
|
2593
|
-
for (let t of [...e.matchAll(/([a-z])\^([+-]?[0-9]+)/g)]) t[1] in this.#t || (this.#t[t[1]] = new
|
|
2594
|
-
for (let t of [...e.matchAll(/([a-z](?!\^))/g)]) t[1] in this.#t || (this.#t[t[1]] = new
|
|
2543
|
+
for (let t of [...e.matchAll(/([a-z])\^([+-]?[0-9]+)/g)]) t[1] in this.#t || (this.#t[t[1]] = new m().zero()), this.#t[t[1]].add(+t[2]);
|
|
2544
|
+
for (let t of [...e.matchAll(/([a-z](?!\^))/g)]) t[1] in this.#t || (this.#t[t[1]] = new m().zero()), this.#t[t[1]].add(1);
|
|
2595
2545
|
}
|
|
2596
2546
|
multiply = (...t) => {
|
|
2597
2547
|
for (let n of t) {
|
|
@@ -2601,7 +2551,7 @@ var re = {
|
|
|
2601
2551
|
}
|
|
2602
2552
|
return this;
|
|
2603
2553
|
};
|
|
2604
|
-
one = () => (this.#e = new
|
|
2554
|
+
one = () => (this.#e = new m().one(), this.#t = {}, this);
|
|
2605
2555
|
opposite = () => (this.#e.opposite(), this);
|
|
2606
2556
|
get plotFunction() {
|
|
2607
2557
|
return this.#i("plot");
|
|
@@ -2613,7 +2563,7 @@ var re = {
|
|
|
2613
2563
|
};
|
|
2614
2564
|
primitive = (e = "x") => {
|
|
2615
2565
|
let t = this.clone(), n;
|
|
2616
|
-
return t.hasVariable(e) ? (n = t.degree(e).clone().add(1), t.coefficient = t.coefficient.clone().divide(n), t.setLetter(e, n)) : (t.coefficient.isZero() && (t.coefficient = new
|
|
2566
|
+
return t.hasVariable(e) ? (n = t.degree(e).clone().add(1), t.coefficient = t.coefficient.clone().divide(n), t.setLetter(e, n)) : (t.coefficient.isZero() && (t.coefficient = new m().one()), t.setLetter(e, 1)), t;
|
|
2617
2567
|
};
|
|
2618
2568
|
reduce = () => {
|
|
2619
2569
|
this.coefficient.reduce();
|
|
@@ -2624,9 +2574,9 @@ var re = {
|
|
|
2624
2574
|
delete this.#t[e];
|
|
2625
2575
|
}
|
|
2626
2576
|
root = () => {
|
|
2627
|
-
throw
|
|
2577
|
+
throw new a("Method not implemented.");
|
|
2628
2578
|
};
|
|
2629
|
-
setLetter = (e, t) => t instanceof
|
|
2579
|
+
setLetter = (e, t) => t instanceof m ? this.hasVariable(e) && t.isZero() ? (this.removeVariable(e), this) : (this.#t[e] = t.clone(), this) : this.setLetter(e, new m(t));
|
|
2630
2580
|
sqrt = () => {
|
|
2631
2581
|
if (this.isSquare()) {
|
|
2632
2582
|
this.#e.sqrt();
|
|
@@ -2638,7 +2588,7 @@ var re = {
|
|
|
2638
2588
|
for (let n of t) {
|
|
2639
2589
|
let t = n instanceof e ? n : new e(n);
|
|
2640
2590
|
if (this.isSameAs(t)) this.isZero() && this.#n(t), this.#e.add(t.clone().coefficient.opposite());
|
|
2641
|
-
else throw
|
|
2591
|
+
else throw new r("Subtract: Is not similar: " + t.display);
|
|
2642
2592
|
}
|
|
2643
2593
|
return this;
|
|
2644
2594
|
};
|
|
@@ -2648,7 +2598,7 @@ var re = {
|
|
|
2648
2598
|
n.isZero() || e.push(t);
|
|
2649
2599
|
}), e.sort(), e;
|
|
2650
2600
|
}
|
|
2651
|
-
zero = () => (this.#e = new
|
|
2601
|
+
zero = () => (this.#e = new m().zero(), this.#t = {}, this);
|
|
2652
2602
|
#n(e) {
|
|
2653
2603
|
for (let t in e.literal) this.#t[t] = e.literal[t].clone();
|
|
2654
2604
|
}
|
|
@@ -2658,15 +2608,15 @@ var re = {
|
|
|
2658
2608
|
let t = {}, n = this.variables[0];
|
|
2659
2609
|
return t[n] = e, this.#r(t);
|
|
2660
2610
|
}
|
|
2661
|
-
if (e instanceof
|
|
2611
|
+
if (e instanceof m) {
|
|
2662
2612
|
let t = {};
|
|
2663
|
-
return t[this.variables[0]] = new
|
|
2613
|
+
return t[this.variables[0]] = new m(e).value, this.#r(t);
|
|
2664
2614
|
}
|
|
2665
2615
|
if (typeof e == "object") {
|
|
2666
2616
|
if (this.variables.length === 0) return this.coefficient.value;
|
|
2667
2617
|
for (let n in this.#t) {
|
|
2668
2618
|
let r = e[n];
|
|
2669
|
-
r instanceof
|
|
2619
|
+
r instanceof m ? t *= r.value ** this.#t[n].value : t *= r ** this.#t[n].value;
|
|
2670
2620
|
}
|
|
2671
2621
|
}
|
|
2672
2622
|
return t;
|
|
@@ -2681,21 +2631,21 @@ var re = {
|
|
|
2681
2631
|
let n = [];
|
|
2682
2632
|
for (let r = 0; r <= this.literal[t].value; r++) if (e.length === 0) {
|
|
2683
2633
|
let e = {};
|
|
2684
|
-
e[t] = new
|
|
2634
|
+
e[t] = new m(r), n.push(e);
|
|
2685
2635
|
} else for (let i of e) {
|
|
2686
2636
|
let e = {};
|
|
2687
2637
|
for (let t in i) e[t] = i[t];
|
|
2688
|
-
e[t] = new
|
|
2638
|
+
e[t] = new m(r), n.push(e);
|
|
2689
2639
|
}
|
|
2690
2640
|
return n;
|
|
2691
2641
|
}
|
|
2692
2642
|
#o = (t, n) => {
|
|
2693
2643
|
let r, i, a, o, s;
|
|
2694
|
-
if (n.tokenType ===
|
|
2695
|
-
else if (n.tokenType ===
|
|
2644
|
+
if (n.tokenType === w.COEFFICIENT) t.push(new e(new m(n.token)));
|
|
2645
|
+
else if (n.tokenType === w.VARIABLE) {
|
|
2696
2646
|
let r = new e().one();
|
|
2697
2647
|
r.setLetter(n.token, 1), t.push(r.clone());
|
|
2698
|
-
} else if (n.tokenType ===
|
|
2648
|
+
} else if (n.tokenType === w.OPERATION) switch (n.token) {
|
|
2699
2649
|
case "-":
|
|
2700
2650
|
i = t.pop() ?? new e().zero(), r = t.pop() ?? new e().zero(), t.push(r.subtract(i));
|
|
2701
2651
|
break;
|
|
@@ -2705,25 +2655,31 @@ var re = {
|
|
|
2705
2655
|
case "/":
|
|
2706
2656
|
i = t.pop() ?? new e().one(), r = t.pop() ?? new e().one(), t.push(r.divide(i));
|
|
2707
2657
|
break;
|
|
2708
|
-
case "^": s = t.pop()?.coefficient ?? new
|
|
2658
|
+
case "^": s = t.pop()?.coefficient ?? new m().one(), a = t.pop() ?? new e().one(), o = a.variables[0], o && a.setLetter(o, s), t.push(a);
|
|
2709
2659
|
}
|
|
2710
2660
|
};
|
|
2711
2661
|
#s = (e) => {
|
|
2712
|
-
let
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2662
|
+
let n;
|
|
2663
|
+
try {
|
|
2664
|
+
n = new O().parse(e);
|
|
2665
|
+
} catch (n) {
|
|
2666
|
+
throw new t(`Cannot parse "${e}" as a Monom`, { cause: n });
|
|
2717
2667
|
}
|
|
2718
|
-
|
|
2719
|
-
|
|
2668
|
+
let r = n.rpn, i = [];
|
|
2669
|
+
if (r.length === 0) return this.zero(), this;
|
|
2670
|
+
if (r.length === 1) {
|
|
2671
|
+
let e = r[0];
|
|
2672
|
+
return this.one(), e.tokenType === w.COEFFICIENT ? this.coefficient = new m(e.token) : e.tokenType === w.VARIABLE && this.setLetter(e.token, 1), this;
|
|
2673
|
+
}
|
|
2674
|
+
for (let e of r) this.#o(i, e);
|
|
2675
|
+
return this.one(), this.multiply(i[0]), this;
|
|
2720
2676
|
};
|
|
2721
2677
|
};
|
|
2722
2678
|
//#endregion
|
|
2723
2679
|
//#region src/algebra/operations.ts
|
|
2724
|
-
function
|
|
2725
|
-
if (!Number.isSafeInteger(t)) throw
|
|
2726
|
-
if (t < 0) throw
|
|
2680
|
+
function j(e, t) {
|
|
2681
|
+
if (!Number.isSafeInteger(t)) throw new i("Can only raise item by an integer");
|
|
2682
|
+
if (t < 0) throw new i("Can only raise item by a positive integer");
|
|
2727
2683
|
if (t === 0) return e.one();
|
|
2728
2684
|
let n = e.clone();
|
|
2729
2685
|
for (let r = 1; r < t; r++) e.multiply(n);
|
|
@@ -2731,7 +2687,7 @@ function D(e, t) {
|
|
|
2731
2687
|
}
|
|
2732
2688
|
//#endregion
|
|
2733
2689
|
//#region src/algebra/polynom.ts
|
|
2734
|
-
var
|
|
2690
|
+
var M = class e {
|
|
2735
2691
|
#e = "x";
|
|
2736
2692
|
#t;
|
|
2737
2693
|
#n;
|
|
@@ -2742,9 +2698,9 @@ var O = class e {
|
|
|
2742
2698
|
}
|
|
2743
2699
|
parse(t, ...n) {
|
|
2744
2700
|
if (this.#n = [], this.#t = [], this.#u(), typeof t == "string") return this.#h(t, ...n);
|
|
2745
|
-
if ((typeof t == "number" || t instanceof
|
|
2746
|
-
else if (t instanceof
|
|
2747
|
-
this.#n.push(new
|
|
2701
|
+
if ((typeof t == "number" || t instanceof m || t instanceof A) && n.length === 0) this.#n.push(new A(t));
|
|
2702
|
+
else if (t instanceof A && n.length > 0) this.#n.push(new A(t)), n.forEach((e) => {
|
|
2703
|
+
this.#n.push(new A(e));
|
|
2748
2704
|
});
|
|
2749
2705
|
else if (t instanceof e) for (let e of t.monoms) this.#n.push(e.clone());
|
|
2750
2706
|
return this;
|
|
@@ -2768,21 +2724,21 @@ var O = class e {
|
|
|
2768
2724
|
}), n;
|
|
2769
2725
|
}
|
|
2770
2726
|
add(...t) {
|
|
2771
|
-
for (let n of t) n instanceof e ? this.#n = this.#n.concat(n.monoms.map((e) => e.clone())) : n instanceof
|
|
2727
|
+
for (let n of t) n instanceof e ? this.#n = this.#n.concat(n.monoms.map((e) => e.clone())) : n instanceof A ? this.#n.push(n.clone()) : typeof n == "number" && Number.isSafeInteger(n) ? this.#n.push(new A(n.toString())) : this.#n.push(new A(n));
|
|
2772
2728
|
return this.reduce();
|
|
2773
2729
|
}
|
|
2774
2730
|
commonMonom() {
|
|
2775
|
-
let e = new
|
|
2776
|
-
e.coefficient = new
|
|
2731
|
+
let e = new A().one();
|
|
2732
|
+
e.coefficient = new m(this.gcdNumerator(), this.gcdDenominator());
|
|
2777
2733
|
for (let t of this.variables) {
|
|
2778
2734
|
e.setLetter(t, this.degree(t));
|
|
2779
|
-
for (let n of this.#n) if (e.setLetter(t,
|
|
2735
|
+
for (let n of this.#n) if (e.setLetter(t, m.min(n.degree(t), e.degree(t))), e.degree(t).isZero()) break;
|
|
2780
2736
|
}
|
|
2781
2737
|
return e;
|
|
2782
2738
|
}
|
|
2783
2739
|
degree(e) {
|
|
2784
|
-
let t = new
|
|
2785
|
-
for (let n of this.#n) t =
|
|
2740
|
+
let t = new m().zero();
|
|
2741
|
+
for (let n of this.#n) t = m.max(n.degree(e).value, t);
|
|
2786
2742
|
return t;
|
|
2787
2743
|
}
|
|
2788
2744
|
derivative(t) {
|
|
@@ -2791,9 +2747,9 @@ var O = class e {
|
|
|
2791
2747
|
return n.reduce();
|
|
2792
2748
|
}
|
|
2793
2749
|
divide(t) {
|
|
2794
|
-
if (t instanceof
|
|
2750
|
+
if (t instanceof m) return this.#o(t);
|
|
2795
2751
|
if (typeof t == "number" && Number.isSafeInteger(t)) return this.#s(t);
|
|
2796
|
-
if (t instanceof
|
|
2752
|
+
if (t instanceof A) return this.divide(new e(t));
|
|
2797
2753
|
if (t instanceof e) {
|
|
2798
2754
|
if (t.monoms.length === 1 && t.variables.length === 0) return this.#o(t.monoms[0].coefficient);
|
|
2799
2755
|
{
|
|
@@ -2801,28 +2757,28 @@ var O = class e {
|
|
|
2801
2757
|
if (n.isZero()) return this.#n = e.monoms, this.#u(), this;
|
|
2802
2758
|
}
|
|
2803
2759
|
} else if (typeof t == "string") return this.divide(new e(t));
|
|
2804
|
-
throw
|
|
2760
|
+
throw new r(`Cannot divide by ${t}`);
|
|
2805
2761
|
}
|
|
2806
2762
|
empty() {
|
|
2807
2763
|
return this.#n = [], this.#u(), this;
|
|
2808
2764
|
}
|
|
2809
2765
|
euclidean(t) {
|
|
2810
|
-
let n = t.variables[0],
|
|
2766
|
+
let n = t.variables[0], i = new e().zero(), a = this.clone().reorder(n);
|
|
2811
2767
|
if (t.variables.length === 0) return {
|
|
2812
2768
|
quotient: this.clone().divide(t).reduce(),
|
|
2813
2769
|
reminder: new e().zero()
|
|
2814
2770
|
};
|
|
2815
|
-
if (!this.degree(n).isNatural() || !t.degree(n).isNatural()) throw
|
|
2816
|
-
let
|
|
2817
|
-
for (;
|
|
2818
|
-
return
|
|
2819
|
-
quotient:
|
|
2820
|
-
reminder:
|
|
2771
|
+
if (!this.degree(n).isNatural() || !t.degree(n).isNatural()) throw new r("Euclidean division requires integer degrees");
|
|
2772
|
+
let o = t.monomByDegree(void 0, n), s = t.degree(n), c, l = this.degree(n).value - s.value + 1;
|
|
2773
|
+
for (; a.degree(n).isGeq(s) && l > 0 && (l--, c = a.monomByDegree(void 0, n).clone().divide(o), !(!c.isZero() && (i.add(c), a.subtract(t.clone().multiply(c)).reduce(), c.degree(n).isZero()))););
|
|
2774
|
+
return i.reduce(), a.reduce(), {
|
|
2775
|
+
quotient: i,
|
|
2776
|
+
reminder: a
|
|
2821
2777
|
};
|
|
2822
2778
|
}
|
|
2823
2779
|
evaluate(e, t) {
|
|
2824
2780
|
if (t) return this.#c(e);
|
|
2825
|
-
let n = new
|
|
2781
|
+
let n = new m().zero();
|
|
2826
2782
|
return this.#n.forEach((r) => {
|
|
2827
2783
|
n.add(r.evaluate(e, t));
|
|
2828
2784
|
}), n;
|
|
@@ -2848,19 +2804,19 @@ var O = class e {
|
|
|
2848
2804
|
this.#n = [];
|
|
2849
2805
|
let t = this.#e ?? "x";
|
|
2850
2806
|
return e.reverse().forEach((e, n) => {
|
|
2851
|
-
let r = new
|
|
2852
|
-
r.coefficient = new
|
|
2807
|
+
let r = new A();
|
|
2808
|
+
r.coefficient = new m(e), r.setLetter(t, n), this.#n.push(r);
|
|
2853
2809
|
}), this.#u(), this.reorder();
|
|
2854
2810
|
}
|
|
2855
2811
|
gcdDenominator() {
|
|
2856
|
-
return
|
|
2812
|
+
return p.gcd(...this.getDenominators());
|
|
2857
2813
|
}
|
|
2858
2814
|
gcdNumerator() {
|
|
2859
|
-
return
|
|
2815
|
+
return p.gcd(...this.getNumerators());
|
|
2860
2816
|
}
|
|
2861
2817
|
getCoefficients() {
|
|
2862
|
-
if (!this.degree().isNatural()) throw
|
|
2863
|
-
let e = this.clone().reorder(), t = this.degree().value + 1, n = Array.from({ length: t }, () => new
|
|
2818
|
+
if (!this.degree().isNatural()) throw new r("getCoefficients() requires a polynomial with integer degrees");
|
|
2819
|
+
let e = this.clone().reorder(), t = this.degree().value + 1, n = Array.from({ length: t }, () => new m(0));
|
|
2864
2820
|
return e.monoms.forEach((e) => {
|
|
2865
2821
|
let r = t - e.degree().value - 1;
|
|
2866
2822
|
n[r] = e.coefficient.clone();
|
|
@@ -2884,18 +2840,14 @@ var O = class e {
|
|
|
2884
2840
|
}
|
|
2885
2841
|
integrate(e, t, n = "x") {
|
|
2886
2842
|
let r = this.primitive(n), i = {}, a = {};
|
|
2887
|
-
return i[n] = new
|
|
2843
|
+
return i[n] = new m(e), a[n] = new m(t), r.evaluate(a).subtract(r.evaluate(i));
|
|
2888
2844
|
}
|
|
2889
2845
|
inverse() {}
|
|
2890
2846
|
isDeveloped(t) {
|
|
2891
|
-
let n
|
|
2892
|
-
if (
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
} catch {
|
|
2896
|
-
return !1;
|
|
2897
|
-
}
|
|
2898
|
-
return !!this.isEqual(n);
|
|
2847
|
+
let n = t.replaceAll(/\^\(([-0-9/]+)\)/g, "$1");
|
|
2848
|
+
if (n.includes("(") || n.includes(")")) return !1;
|
|
2849
|
+
let r = new e(t);
|
|
2850
|
+
return !!this.isEqual(r);
|
|
2899
2851
|
}
|
|
2900
2852
|
isDividableBy(e) {
|
|
2901
2853
|
if (e.degree().isOne()) {
|
|
@@ -2926,33 +2878,33 @@ var O = class e {
|
|
|
2926
2878
|
return this.#n.length === 1 && this.#n[0].coefficient.isZero() || this.#n.length === 0;
|
|
2927
2879
|
}
|
|
2928
2880
|
lcmDenominator() {
|
|
2929
|
-
return
|
|
2881
|
+
return p.lcm(...this.getDenominators());
|
|
2930
2882
|
}
|
|
2931
2883
|
lcmNumerator() {
|
|
2932
|
-
return
|
|
2884
|
+
return p.lcm(...this.getNumerators());
|
|
2933
2885
|
}
|
|
2934
2886
|
get length() {
|
|
2935
2887
|
return this.#n.length;
|
|
2936
2888
|
}
|
|
2937
2889
|
limitTo(e, t) {
|
|
2938
|
-
let n = new
|
|
2890
|
+
let n = new m(e);
|
|
2939
2891
|
if (n.isFinite()) {
|
|
2940
2892
|
let e = t ?? this.variables[0] ?? "x";
|
|
2941
2893
|
return this.evaluate({ [e]: n });
|
|
2942
2894
|
}
|
|
2943
2895
|
let r = this.monomByDegree(void 0, t), i = r.coefficient.sign(), a = r.degree(t);
|
|
2944
|
-
return a.isZero() ? r.coefficient.clone() : a.isStrictlyPositive() ? n.isPositive() ? i === 1 ? new
|
|
2896
|
+
return a.isZero() ? r.coefficient.clone() : a.isStrictlyPositive() ? n.isPositive() ? i === 1 ? new m().infinite() : new m().infinite().opposite() : (a.value % 2 == 0 ? i : -i) === 1 ? new m().infinite() : new m().infinite().opposite() : new m().zero();
|
|
2945
2897
|
}
|
|
2946
2898
|
monomByDegree(e, t) {
|
|
2947
2899
|
if (e === void 0) return this.monomByDegree(this.degree(t), t);
|
|
2948
2900
|
let n = this.clone().reduce();
|
|
2949
2901
|
for (let r of n.#n) if (r.degree(t).isEqual(e)) return r.clone();
|
|
2950
|
-
return new
|
|
2902
|
+
return new A().zero();
|
|
2951
2903
|
}
|
|
2952
2904
|
monomByLetter(e) {
|
|
2953
2905
|
let t = this.clone().reduce();
|
|
2954
2906
|
for (let n of t.#n) if (n.hasVariable(e)) return n.clone();
|
|
2955
|
-
return new
|
|
2907
|
+
return new A().zero();
|
|
2956
2908
|
}
|
|
2957
2909
|
get monoms() {
|
|
2958
2910
|
return this.#n;
|
|
@@ -2968,22 +2920,22 @@ var O = class e {
|
|
|
2968
2920
|
}
|
|
2969
2921
|
multiply(t) {
|
|
2970
2922
|
if (t instanceof e) return this.#m(t);
|
|
2971
|
-
if (t instanceof
|
|
2972
|
-
if (t instanceof
|
|
2923
|
+
if (t instanceof m) return this.#d(t);
|
|
2924
|
+
if (t instanceof A) return this.#p(t);
|
|
2973
2925
|
if (Number.isSafeInteger(t) && typeof t == "number") return this.#f(t);
|
|
2974
2926
|
if (typeof t == "string") try {
|
|
2975
|
-
let e = new
|
|
2927
|
+
let e = new m(t);
|
|
2976
2928
|
return this.#d(e);
|
|
2977
|
-
} catch {
|
|
2978
|
-
throw
|
|
2929
|
+
} catch (e) {
|
|
2930
|
+
throw new r("Cannot multiply by this value.", { cause: e });
|
|
2979
2931
|
}
|
|
2980
|
-
throw
|
|
2932
|
+
throw new r(`Cannot multiply by this value: ${t}`);
|
|
2981
2933
|
}
|
|
2982
2934
|
get numberOfVars() {
|
|
2983
2935
|
return this.variables.length;
|
|
2984
2936
|
}
|
|
2985
2937
|
one() {
|
|
2986
|
-
return this.#n = [], this.#n.push(new
|
|
2938
|
+
return this.#n = [], this.#n.push(new A().one()), this.#u(), this;
|
|
2987
2939
|
}
|
|
2988
2940
|
opposite() {
|
|
2989
2941
|
return this.#n = this.#n.map((e) => e.opposite()), this.#u(), this;
|
|
@@ -2992,7 +2944,7 @@ var O = class e {
|
|
|
2992
2944
|
return this.#l("tex", !1, !1, !0);
|
|
2993
2945
|
}
|
|
2994
2946
|
pow(e) {
|
|
2995
|
-
return
|
|
2947
|
+
return j(this, e).reduce();
|
|
2996
2948
|
}
|
|
2997
2949
|
primitive(t) {
|
|
2998
2950
|
let n = new e();
|
|
@@ -3002,7 +2954,7 @@ var O = class e {
|
|
|
3002
2954
|
reduce() {
|
|
3003
2955
|
let e = 0;
|
|
3004
2956
|
for (; e < this.#n.length;) {
|
|
3005
|
-
for (let t = e + 1; t < this.#n.length; t++) this.#n[e].isSameAs(this.#n[t]) && (this.#n[e].add(this.#n[t]), this.#n.splice(t, 1), this.#n[e].isZero() && (this.#n[e] = new
|
|
2957
|
+
for (let t = e + 1; t < this.#n.length; t++) this.#n[e].isSameAs(this.#n[t]) && (this.#n[e].add(this.#n[t]), this.#n.splice(t, 1), this.#n[e].isZero() && (this.#n[e] = new A().zero()), t--);
|
|
3006
2958
|
e++;
|
|
3007
2959
|
}
|
|
3008
2960
|
this.#n = this.#n.filter((e) => !e.coefficient.isZero());
|
|
@@ -3022,16 +2974,16 @@ var O = class e {
|
|
|
3022
2974
|
}), this;
|
|
3023
2975
|
}
|
|
3024
2976
|
replaceBy(t, n) {
|
|
3025
|
-
let
|
|
3026
|
-
for (let e of this.monoms) if (!e.hasVariable(t) || e.literal[t].isZero())
|
|
2977
|
+
let i, a = new e().zero();
|
|
2978
|
+
for (let e of this.monoms) if (!e.hasVariable(t) || e.literal[t].isZero()) a.add(e.clone());
|
|
3027
2979
|
else {
|
|
3028
|
-
if (
|
|
3029
|
-
|
|
2980
|
+
if (i = e.literal[t].clone(), e.removeVariable(t), i.isStrictlyNegative()) throw new r(`Cannot replace variable "${t}" with negative power in a Polynom`);
|
|
2981
|
+
a.add(n.clone().pow(i.numerator).multiply(e));
|
|
3030
2982
|
}
|
|
3031
|
-
return this.#n =
|
|
2983
|
+
return this.#n = a.reduce().monoms, this.#u(), this;
|
|
3032
2984
|
}
|
|
3033
2985
|
root() {
|
|
3034
|
-
throw
|
|
2986
|
+
throw new r("Cannot take the root from a polynom");
|
|
3035
2987
|
}
|
|
3036
2988
|
get roots() {
|
|
3037
2989
|
return this.#i ? this.#r : this.getZeroes();
|
|
@@ -3043,10 +2995,10 @@ var O = class e {
|
|
|
3043
2995
|
return this.#e = e, this;
|
|
3044
2996
|
}
|
|
3045
2997
|
sqrt() {
|
|
3046
|
-
throw
|
|
2998
|
+
throw new r("Cannot take the square root from a polynom");
|
|
3047
2999
|
}
|
|
3048
3000
|
subtract(...t) {
|
|
3049
|
-
for (let n of t) n instanceof e ? this.add(n.clone().opposite()) : n instanceof
|
|
3001
|
+
for (let n of t) n instanceof e ? this.add(n.clone().opposite()) : n instanceof A ? this.#n.push(n.clone().opposite()) : this.#n.push(new A(n).opposite());
|
|
3050
3002
|
return this.reduce();
|
|
3051
3003
|
}
|
|
3052
3004
|
tableOfSigns() {
|
|
@@ -3073,7 +3025,7 @@ var O = class e {
|
|
|
3073
3025
|
return [...new Set(this.#n.flatMap((e) => e.variables))].sort();
|
|
3074
3026
|
}
|
|
3075
3027
|
zero() {
|
|
3076
|
-
return this.#n = [], this.#n.push(new
|
|
3028
|
+
return this.#n = [], this.#n.push(new A().zero()), this.#u(), this;
|
|
3077
3029
|
}
|
|
3078
3030
|
get zeroes() {
|
|
3079
3031
|
return this.getZeroes();
|
|
@@ -3092,7 +3044,7 @@ var O = class e {
|
|
|
3092
3044
|
return this.#u(), this;
|
|
3093
3045
|
}
|
|
3094
3046
|
#s(e) {
|
|
3095
|
-
let t = new
|
|
3047
|
+
let t = new m(e);
|
|
3096
3048
|
for (let e of this.#n) e.coefficient.divide(t);
|
|
3097
3049
|
return this.#u(), this;
|
|
3098
3050
|
}
|
|
@@ -3119,7 +3071,7 @@ var O = class e {
|
|
|
3119
3071
|
return this.reduce();
|
|
3120
3072
|
}
|
|
3121
3073
|
#f(e) {
|
|
3122
|
-
return this.#d(new
|
|
3074
|
+
return this.#d(new m(e));
|
|
3123
3075
|
}
|
|
3124
3076
|
#p(e) {
|
|
3125
3077
|
for (let t of this.#n) t.multiply(e);
|
|
@@ -3127,33 +3079,33 @@ var O = class e {
|
|
|
3127
3079
|
}
|
|
3128
3080
|
#m(e) {
|
|
3129
3081
|
let t = [];
|
|
3130
|
-
for (let n of this.#n) for (let r of e.monoms) t.push(
|
|
3082
|
+
for (let n of this.#n) for (let r of e.monoms) t.push(A.xMultiply(n, r));
|
|
3131
3083
|
return this.#n = t, this.reduce();
|
|
3132
3084
|
}
|
|
3133
3085
|
#h(e, ...t) {
|
|
3134
3086
|
if (t.length === 0) {
|
|
3135
3087
|
if (e !== "" && !isNaN(Number(e))) {
|
|
3136
3088
|
this.empty();
|
|
3137
|
-
let t = new
|
|
3089
|
+
let t = new A(Number(e));
|
|
3138
3090
|
return this.add(t), this;
|
|
3139
3091
|
}
|
|
3140
3092
|
return this.#_(e);
|
|
3141
3093
|
}
|
|
3142
3094
|
if (/^[a-z]+$/.test(e)) {
|
|
3143
3095
|
this.empty();
|
|
3144
|
-
let n = t.map((e) => new
|
|
3096
|
+
let n = t.map((e) => new m(e));
|
|
3145
3097
|
if (e.length > 1) {
|
|
3146
3098
|
let t = e.split("");
|
|
3147
|
-
if (n.length > t.length + 1) throw
|
|
3099
|
+
if (n.length > t.length + 1) throw new i(`Too many values: ${t.length} letters but ${n.length} values provided`);
|
|
3148
3100
|
let r = 0;
|
|
3149
3101
|
for (let e of n) {
|
|
3150
|
-
let n = new
|
|
3102
|
+
let n = new A();
|
|
3151
3103
|
n.coefficient = e.clone(), n.literalStr = t[r] ?? "", this.add(n), r++;
|
|
3152
3104
|
}
|
|
3153
3105
|
} else {
|
|
3154
3106
|
let t = n.length - 1;
|
|
3155
3107
|
for (let r of n) {
|
|
3156
|
-
let n = new
|
|
3108
|
+
let n = new A();
|
|
3157
3109
|
n.coefficient = r.clone(), n.literalStr = `${e}^${t}`, this.add(n), t--;
|
|
3158
3110
|
}
|
|
3159
3111
|
}
|
|
@@ -3161,65 +3113,71 @@ var O = class e {
|
|
|
3161
3113
|
}
|
|
3162
3114
|
return this.zero();
|
|
3163
3115
|
}
|
|
3164
|
-
#g(
|
|
3165
|
-
switch (
|
|
3166
|
-
case
|
|
3167
|
-
|
|
3116
|
+
#g(n, i) {
|
|
3117
|
+
switch (i.tokenType) {
|
|
3118
|
+
case w.COEFFICIENT:
|
|
3119
|
+
n.push(new e(i.token));
|
|
3168
3120
|
break;
|
|
3169
|
-
case
|
|
3170
|
-
|
|
3121
|
+
case w.VARIABLE:
|
|
3122
|
+
n.push(new e().add(new A(i.token)));
|
|
3171
3123
|
break;
|
|
3172
|
-
case
|
|
3173
|
-
case
|
|
3174
|
-
if (
|
|
3175
|
-
let e =
|
|
3176
|
-
if (
|
|
3177
|
-
if (
|
|
3178
|
-
else if (
|
|
3179
|
-
else if (
|
|
3180
|
-
else if (
|
|
3181
|
-
if (e.degree().isStrictlyPositive()) throw
|
|
3182
|
-
|
|
3183
|
-
} else if (
|
|
3184
|
-
if (e.degree().isStrictlyPositive()) throw
|
|
3185
|
-
if (e.monoms[0].coefficient.isRelative())
|
|
3186
|
-
else if (
|
|
3187
|
-
for (let t in
|
|
3188
|
-
|
|
3189
|
-
} else throw
|
|
3124
|
+
case w.CONSTANT: throw new t("Unsupported CONSTANT token in Polynom parser");
|
|
3125
|
+
case w.OPERATION:
|
|
3126
|
+
if (n.length >= 2) {
|
|
3127
|
+
let e = n.pop(), a = n.pop();
|
|
3128
|
+
if (a === void 0 || e === void 0) throw new t("Unexpected undefined operand in Polynom parser stack");
|
|
3129
|
+
if (i.token === "+") n.push(a.add(e));
|
|
3130
|
+
else if (i.token === "-") n.push(a.subtract(e));
|
|
3131
|
+
else if (i.token === "*") n.push(a.multiply(e));
|
|
3132
|
+
else if (i.token === "/") {
|
|
3133
|
+
if (e.degree().isStrictlyPositive()) throw new r("Cannot divide a Polynom by another Polynom of degree > 0");
|
|
3134
|
+
n.push(a.divide(e.monoms[0].coefficient));
|
|
3135
|
+
} else if (i.token === "^") {
|
|
3136
|
+
if (e.degree().isStrictlyPositive()) throw new r("Cannot elevate a polynom with another polynom !");
|
|
3137
|
+
if (e.monoms[0].coefficient.isRelative()) n.push(a.pow(e.monoms[0].coefficient.value));
|
|
3138
|
+
else if (a.monoms.length === 1 && a.monoms[0].coefficient.isOne()) {
|
|
3139
|
+
for (let t in a.monoms[0].literal) a.monoms[0].literal[t].multiply(e.monoms[0].coefficient);
|
|
3140
|
+
n.push(a);
|
|
3141
|
+
} else throw new r("Cannot raise a multi-monom Polynom to a fractional power");
|
|
3190
3142
|
}
|
|
3191
|
-
} else if (
|
|
3192
|
-
let e =
|
|
3193
|
-
e &&
|
|
3194
|
-
} else throw
|
|
3143
|
+
} else if (i.token === "-") {
|
|
3144
|
+
let e = n.pop();
|
|
3145
|
+
e && n.push(e.opposite());
|
|
3146
|
+
} else throw new t("Error parsing the polynom");
|
|
3195
3147
|
break;
|
|
3196
|
-
case
|
|
3197
|
-
case
|
|
3148
|
+
case w.MONOM: throw new t("Unexpected MONOM token in polynom parser");
|
|
3149
|
+
case w.FUNCTION: throw new t(`Unsupported function token "${i.token}" in polynom parser`);
|
|
3198
3150
|
}
|
|
3199
3151
|
}
|
|
3200
3152
|
#_(e) {
|
|
3201
|
-
let
|
|
3153
|
+
let n;
|
|
3154
|
+
try {
|
|
3155
|
+
n = new O().parse(e);
|
|
3156
|
+
} catch (n) {
|
|
3157
|
+
throw new t(`Cannot parse "${e}" as a Polynom`, { cause: n });
|
|
3158
|
+
}
|
|
3159
|
+
let r = n.rpn;
|
|
3202
3160
|
this.zero();
|
|
3203
|
-
let
|
|
3204
|
-
for (let e of
|
|
3205
|
-
return
|
|
3161
|
+
let i = [];
|
|
3162
|
+
for (let e of r) this.#g(i, e);
|
|
3163
|
+
return i.length === 1 && this.add(i[0]), this.reorder();
|
|
3206
3164
|
}
|
|
3207
|
-
},
|
|
3165
|
+
}, N = class e {
|
|
3208
3166
|
#e;
|
|
3209
3167
|
#t;
|
|
3210
3168
|
#n;
|
|
3211
3169
|
constructor(t, n, r) {
|
|
3212
|
-
if (this.#e = new
|
|
3170
|
+
if (this.#e = new M().zero(), this.#t = new M().zero(), this.#n = "=", t !== void 0 && n === void 0) {
|
|
3213
3171
|
if (t instanceof e) return t.clone();
|
|
3214
3172
|
typeof t == "string" && this.parse(t);
|
|
3215
|
-
} else t !== void 0 && n !== void 0 && (this.left = new
|
|
3173
|
+
} else t !== void 0 && n !== void 0 && (this.left = new M(t), this.right = new M(n));
|
|
3216
3174
|
return r !== void 0 && (this.sign = r), this;
|
|
3217
3175
|
}
|
|
3218
3176
|
parse = (e) => {
|
|
3219
|
-
let
|
|
3220
|
-
if (
|
|
3221
|
-
let
|
|
3222
|
-
return this.create(new
|
|
3177
|
+
let n = this.#r(e);
|
|
3178
|
+
if (n === !1) throw new t("The equation is not valid (no sign found)");
|
|
3179
|
+
let r = e.split(n);
|
|
3180
|
+
return this.create(new M(r[0]), new M(r[1]), this.#i(n));
|
|
3223
3181
|
};
|
|
3224
3182
|
clone = () => new e(this.#e.clone(), this.#t.clone(), this.#n);
|
|
3225
3183
|
get tex() {
|
|
@@ -3238,13 +3196,13 @@ var O = class e {
|
|
|
3238
3196
|
add(t) {
|
|
3239
3197
|
if (t instanceof e) return this.#e.add(t.left), this.#t.add(t.right), this;
|
|
3240
3198
|
if (typeof t == "string" && !e.isEquationString(t)) return this.add(new e(t));
|
|
3241
|
-
let n = new
|
|
3199
|
+
let n = new M(t);
|
|
3242
3200
|
return this.#e.add(n), this.#t.add(n), this;
|
|
3243
3201
|
}
|
|
3244
3202
|
create = (e, t, n) => (this.#e = e, this.#t = t, this.#n = this.#i(n ?? "="), this);
|
|
3245
|
-
degree = (e) =>
|
|
3203
|
+
degree = (e) => m.max(this.#e.degree(e), this.#t.degree(e));
|
|
3246
3204
|
divide = (e) => {
|
|
3247
|
-
let t = new
|
|
3205
|
+
let t = new m(e);
|
|
3248
3206
|
return t.isZero() ? this : this.multiply(t.inverse());
|
|
3249
3207
|
};
|
|
3250
3208
|
evaluate(e, t) {
|
|
@@ -3284,7 +3242,7 @@ var O = class e {
|
|
|
3284
3242
|
letters = () => [.../* @__PURE__ */ new Set([...this.#e.variables, ...this.#t.variables])];
|
|
3285
3243
|
moveLeft = () => (this.#e.subtract(this.#t), this.#t.zero(), this);
|
|
3286
3244
|
multiply = (e) => {
|
|
3287
|
-
let t = new
|
|
3245
|
+
let t = new m(e);
|
|
3288
3246
|
return this.#e.multiply(t), this.#t.multiply(t), this.#n !== "=" && t.sign() === -1 && this.#a(), this;
|
|
3289
3247
|
};
|
|
3290
3248
|
get numberOfVars() {
|
|
@@ -3317,7 +3275,7 @@ var O = class e {
|
|
|
3317
3275
|
get signAsTex() {
|
|
3318
3276
|
return this.#n === ">=" ? "\\geq" : this.#n === "<=" ? "\\leq" : this.#n;
|
|
3319
3277
|
}
|
|
3320
|
-
simplify = () => (this.multiply(
|
|
3278
|
+
simplify = () => (this.multiply(p.lcm(...this.#e.getDenominators(), ...this.#t.getDenominators())), this.divide(p.gcd(...this.#e.getNumerators(), ...this.#t.getNumerators())), this);
|
|
3321
3279
|
solve = () => new b(this.clone()).solve();
|
|
3322
3280
|
split() {
|
|
3323
3281
|
return [this.#e.clone(), this.#t.clone()];
|
|
@@ -3325,7 +3283,7 @@ var O = class e {
|
|
|
3325
3283
|
subtract(t) {
|
|
3326
3284
|
if (t instanceof e) return this.#e.subtract(t.left), this.#t.subtract(t.right), this;
|
|
3327
3285
|
if (typeof t == "string" && !e.isEquationString(t)) return this.subtract(new e(t));
|
|
3328
|
-
let n = new
|
|
3286
|
+
let n = new M(t);
|
|
3329
3287
|
return this.#e.subtract(n), this.#t.subtract(n), this;
|
|
3330
3288
|
}
|
|
3331
3289
|
test = (e) => this.left.evaluate(e).isEqual(this.right.evaluate(e));
|
|
@@ -3342,34 +3300,34 @@ var O = class e {
|
|
|
3342
3300
|
if (e.includes("=<")) return "=<";
|
|
3343
3301
|
if (e.includes("<")) return "<";
|
|
3344
3302
|
if (e.includes("=")) return "=";
|
|
3345
|
-
throw
|
|
3303
|
+
throw new t("The equation is not valid (no sign found)");
|
|
3346
3304
|
};
|
|
3347
3305
|
#i = (e) => e === void 0 ? "=" : e.includes("geq") || e.includes(">=") || e.includes("=>") ? ">=" : e.includes(">") ? ">" : e.includes("leq") || e.includes("<=") || e.includes("=<") ? "<=" : e.includes("<") ? "<" : "=";
|
|
3348
3306
|
#a = () => this.#n === "=" ? this : this.#n.includes("<") ? (this.#n.replace("<", ">"), this) : (this.#n.includes(">") && this.#n.replace(">", "<"), this);
|
|
3349
|
-
},
|
|
3307
|
+
}, P = class e {
|
|
3350
3308
|
#e;
|
|
3351
3309
|
#t;
|
|
3352
3310
|
#n;
|
|
3353
3311
|
#r = !1;
|
|
3354
3312
|
constructor(t, n) {
|
|
3355
|
-
return t instanceof e ? (this.#t = t.polynom.clone(), this.#n = t.power.clone(), n !== void 0 && this.#n.multiply(new
|
|
3313
|
+
return t instanceof e ? (this.#t = t.polynom.clone(), this.#n = t.power.clone(), n !== void 0 && this.#n.multiply(new m(n))) : t === void 0 ? (this.#t = new M(), this.#n = new m(1)) : (this.#t = new M(t), this.#n = new m(n ?? 1)), this.#e = 1, this;
|
|
3356
3314
|
}
|
|
3357
3315
|
parse() {
|
|
3358
|
-
throw
|
|
3316
|
+
throw new a("Method not implemented.");
|
|
3359
3317
|
}
|
|
3360
3318
|
clone() {
|
|
3361
3319
|
return new e(this);
|
|
3362
3320
|
}
|
|
3363
3321
|
get tex() {
|
|
3364
3322
|
let e = this.power.numerator, t = this.power.denominator, n, r;
|
|
3365
|
-
return this.#e === 0 && t > 1 ? (n = `\\sqrt${t === 2 ? "" : `[ ${t} ]`}{ ${this.polynom.tex} }`, r = e === 1 ? "" : `^{ ${e} }`) : (n = this.#r && this.power.isOne() ? this.polynom.tex :
|
|
3323
|
+
return this.#e === 0 && t > 1 ? (n = `\\sqrt${t === 2 ? "" : `[ ${t} ]`}{ ${this.polynom.tex} }`, r = e === 1 ? "" : `^{ ${e} }`) : (n = this.#r && this.power.isOne() ? this.polynom.tex : se(this.polynom.tex), r = t === 1 && e === 1 ? "" : `^{ ${this.power.tex} }`), n = `${n}${r}`, this.#e === 0 && e < 0 && (n = `\\frac{ 1 }{ ${n} }`), n;
|
|
3366
3324
|
}
|
|
3367
3325
|
get display() {
|
|
3368
3326
|
let e = this.power.numerator, t = this.power.denominator, n, r;
|
|
3369
|
-
return this.#e === 0 && t > 1 ? (n = `${t === 2 ? "sqrt" : `root(${t})`}(${this.polynom.display})`, r = e === 1 ? "" : `^(${e})`) : (n = this.#r && this.power.isOne() ? this.polynom.display :
|
|
3327
|
+
return this.#e === 0 && t > 1 ? (n = `${t === 2 ? "sqrt" : `root(${t})`}(${this.polynom.display})`, r = e === 1 ? "" : `^(${e})`) : (n = this.#r && this.power.isOne() ? this.polynom.display : se(this.polynom.display, !1), r = t === 1 && e === 1 ? "" : `^(${this.power.display})`), n = `${n}${r}`, this.#e === 0 && e < 0 && (n = `1/(${n})`), n;
|
|
3370
3328
|
}
|
|
3371
3329
|
add() {
|
|
3372
|
-
throw
|
|
3330
|
+
throw new r("Adding two factors is not possible");
|
|
3373
3331
|
}
|
|
3374
3332
|
get asSingle() {
|
|
3375
3333
|
return this.#r = !0, this;
|
|
@@ -3386,19 +3344,19 @@ var O = class e {
|
|
|
3386
3344
|
}
|
|
3387
3345
|
develop() {
|
|
3388
3346
|
if (this.power.isNatural()) return this.polynom.clone().pow(this.power.value);
|
|
3389
|
-
throw
|
|
3347
|
+
throw new r("The power must be a natural number");
|
|
3390
3348
|
}
|
|
3391
3349
|
divide(t) {
|
|
3392
3350
|
if (t instanceof e && this.isSameAs(t)) return this.power.subtract(t.power), this;
|
|
3393
|
-
let n = new
|
|
3351
|
+
let n = new M(t);
|
|
3394
3352
|
if (this.isSameAs(n)) return this.power.subtract(1), this;
|
|
3395
|
-
throw
|
|
3353
|
+
throw new r("The two factors must be the same");
|
|
3396
3354
|
}
|
|
3397
3355
|
evaluate(e, t) {
|
|
3398
3356
|
return t ? this.polynom.evaluate(e, !0) ** this.power.value : this.polynom.evaluate(e).pow(this.power);
|
|
3399
3357
|
}
|
|
3400
3358
|
fromPolynom(e) {
|
|
3401
|
-
return this.#t = new
|
|
3359
|
+
return this.#t = new M(e), this.#n = new m(1), this;
|
|
3402
3360
|
}
|
|
3403
3361
|
hasVariable(e) {
|
|
3404
3362
|
return this.polynom.hasVariable(e);
|
|
@@ -3414,7 +3372,7 @@ var O = class e {
|
|
|
3414
3372
|
}
|
|
3415
3373
|
isSameAs(t) {
|
|
3416
3374
|
let n;
|
|
3417
|
-
return n = t instanceof e ? t.polynom : t instanceof
|
|
3375
|
+
return n = t instanceof e ? t.polynom : t instanceof M ? t : new M(t), this.polynom.isEqual(n);
|
|
3418
3376
|
}
|
|
3419
3377
|
isZero() {
|
|
3420
3378
|
return this.polynom.isZero();
|
|
@@ -3423,15 +3381,15 @@ var O = class e {
|
|
|
3423
3381
|
let n = new e(t);
|
|
3424
3382
|
if (this.polynom.monoms.length === 1 && this.power.isOne() && n.polynom.monoms.length === 1 && this.power.isOne()) return this.polynom.multiply(n.polynom), this;
|
|
3425
3383
|
if (t instanceof e && this.isSameAs(t)) return this.power.add(t.power), this;
|
|
3426
|
-
let
|
|
3427
|
-
if (this.isSameAs(
|
|
3428
|
-
throw
|
|
3384
|
+
let i = new M(t);
|
|
3385
|
+
if (this.isSameAs(i)) return this.power.add(1), this;
|
|
3386
|
+
throw new r("The two factors must be the same");
|
|
3429
3387
|
}
|
|
3430
3388
|
one() {
|
|
3431
3389
|
return this.#t.one(), this.#n.one(), this;
|
|
3432
3390
|
}
|
|
3433
3391
|
opposite() {
|
|
3434
|
-
throw
|
|
3392
|
+
throw new a("Method not implemented.");
|
|
3435
3393
|
}
|
|
3436
3394
|
get polynom() {
|
|
3437
3395
|
return this.#t;
|
|
@@ -3446,13 +3404,13 @@ var O = class e {
|
|
|
3446
3404
|
return this.#n;
|
|
3447
3405
|
}
|
|
3448
3406
|
set power(e) {
|
|
3449
|
-
this.#n = new
|
|
3407
|
+
this.#n = new m(e);
|
|
3450
3408
|
}
|
|
3451
3409
|
primitive() {
|
|
3452
|
-
throw
|
|
3410
|
+
throw new a("Method not implemented.");
|
|
3453
3411
|
}
|
|
3454
3412
|
reduce() {
|
|
3455
|
-
throw
|
|
3413
|
+
throw new a("Method not implemented.");
|
|
3456
3414
|
}
|
|
3457
3415
|
root(e) {
|
|
3458
3416
|
return this.power.divide(e), this;
|
|
@@ -3461,7 +3419,7 @@ var O = class e {
|
|
|
3461
3419
|
return this.root(2);
|
|
3462
3420
|
}
|
|
3463
3421
|
subtract() {
|
|
3464
|
-
throw
|
|
3422
|
+
throw new r("Subtracting two factors is not possible");
|
|
3465
3423
|
}
|
|
3466
3424
|
tableOfSigns() {
|
|
3467
3425
|
let e = this.power.clone().reduce(), t = this.polynom.tableOfSigns();
|
|
@@ -3493,19 +3451,19 @@ var O = class e {
|
|
|
3493
3451
|
let r = n ? 1 : -1, i = [];
|
|
3494
3452
|
for (let n of t.matchAll(/\(([^)]+)\)(?:\^(-?[0-9]+(?:\/[0-9]+)?|\(-?[0-9]+(?:\/[0-9]+)?\)))?|([^(]+)/g)) if (n[1] !== void 0) {
|
|
3495
3453
|
let t = (n[2] ?? "1").replace(/[()]/g, "");
|
|
3496
|
-
i.push(new e(new
|
|
3497
|
-
} else n[3]?.trim() && i.push(new e(new
|
|
3454
|
+
i.push(new e(new M(n[1]), new m(t).multiply(r)));
|
|
3455
|
+
} else n[3]?.trim() && i.push(new e(new M(n[3].trim()), new m(r)));
|
|
3498
3456
|
return i;
|
|
3499
3457
|
}
|
|
3500
|
-
},
|
|
3458
|
+
}, F = /* @__PURE__ */ function(e) {
|
|
3501
3459
|
return e[e.ROOT = 0] = "ROOT", e[e.POWER = 1] = "POWER", e;
|
|
3502
|
-
}({}),
|
|
3460
|
+
}({}), I = class e {
|
|
3503
3461
|
#e;
|
|
3504
3462
|
#t;
|
|
3505
3463
|
constructor(...e) {
|
|
3506
3464
|
return this.#e = [], this.#t = [], e.length > 0 && this.parse(...e), this;
|
|
3507
3465
|
}
|
|
3508
|
-
parse = (...e) => (this.#e = e.map((e) => new
|
|
3466
|
+
parse = (...e) => (this.#e = e.map((e) => new N(e)), this.#n(), this);
|
|
3509
3467
|
clone = () => new e().parse(...this.#e.map((e) => e.clone()));
|
|
3510
3468
|
get tex() {
|
|
3511
3469
|
let e = this.clone().reorder();
|
|
@@ -3514,11 +3472,11 @@ var O = class e {
|
|
|
3514
3472
|
get display() {
|
|
3515
3473
|
return this.tex + "as display";
|
|
3516
3474
|
}
|
|
3517
|
-
static fromMatrix(t,
|
|
3518
|
-
let
|
|
3519
|
-
if (t.some((e) => e.length !==
|
|
3520
|
-
let
|
|
3521
|
-
return new e(...t.map((e) => new
|
|
3475
|
+
static fromMatrix(t, r = "xyz") {
|
|
3476
|
+
let i = t[0].length;
|
|
3477
|
+
if (t.some((e) => e.length !== i)) throw new n("All rows must have the same number of columns");
|
|
3478
|
+
let a = r.split("").splice(0, i - 1);
|
|
3479
|
+
return new e(...t.map((e) => new N(new M(a.join(""), ...e), 0)));
|
|
3522
3480
|
}
|
|
3523
3481
|
static solutionAsDisplay(e) {
|
|
3524
3482
|
return `(${e.map((e) => e.display).join(";")})`;
|
|
@@ -3526,15 +3484,15 @@ var O = class e {
|
|
|
3526
3484
|
static solutionAsTex(e) {
|
|
3527
3485
|
return `\\left( ${e.map((e) => e.tex).join(" ; ")} \\right)`;
|
|
3528
3486
|
}
|
|
3529
|
-
add(t,
|
|
3487
|
+
add(t, r) {
|
|
3530
3488
|
if (t instanceof e) {
|
|
3531
3489
|
let e = t.equations.length;
|
|
3532
|
-
if (e !== this.#e.length) throw
|
|
3490
|
+
if (e !== this.#e.length) throw new n("The number of equations must be the same");
|
|
3533
3491
|
for (let n = 0; n < e; n++) this.#e[n].add(t.equations[n]);
|
|
3534
3492
|
} else {
|
|
3535
|
-
if (
|
|
3536
|
-
let e = new
|
|
3537
|
-
this.#e[
|
|
3493
|
+
if (r === void 0 || r < 0 || r >= this.#e.length) throw new o("Index out of range");
|
|
3494
|
+
let e = new N(t);
|
|
3495
|
+
this.#e[r].add(e);
|
|
3538
3496
|
}
|
|
3539
3497
|
return this;
|
|
3540
3498
|
}
|
|
@@ -3556,7 +3514,7 @@ var O = class e {
|
|
|
3556
3514
|
return t !== void 0 && t.length > 0 && (o = t[0].length), `\\left\\{\\begin{array}{${"r".repeat(i.length)}cl ${"|l".repeat(o)}}${a.join("\\\\ ")}\\end{array}\\right.`;
|
|
3557
3515
|
};
|
|
3558
3516
|
degree(e) {
|
|
3559
|
-
return
|
|
3517
|
+
return m.max(...this.#e.map((t) => t.degree(e)));
|
|
3560
3518
|
}
|
|
3561
3519
|
get equations() {
|
|
3562
3520
|
return this.#e;
|
|
@@ -3565,7 +3523,7 @@ var O = class e {
|
|
|
3565
3523
|
this.#e = e, this.#n();
|
|
3566
3524
|
}
|
|
3567
3525
|
evaluate(e, t) {
|
|
3568
|
-
throw
|
|
3526
|
+
throw new a("Method not implemented.");
|
|
3569
3527
|
}
|
|
3570
3528
|
hasVariable(e) {
|
|
3571
3529
|
return this.#t.includes(e);
|
|
@@ -3585,11 +3543,11 @@ var O = class e {
|
|
|
3585
3543
|
}
|
|
3586
3544
|
multiply(e, t) {
|
|
3587
3545
|
if (Array.isArray(e)) {
|
|
3588
|
-
if (e.length !== this.#e.length) throw
|
|
3546
|
+
if (e.length !== this.#e.length) throw new n("The number of values must be the same as the number of equations");
|
|
3589
3547
|
for (let t = 0; t < e.length; t++) this.#e[t].multiply(e[t]);
|
|
3590
3548
|
return this;
|
|
3591
3549
|
}
|
|
3592
|
-
if (t === void 0 || t < 0 || t >= this.#e.length) throw
|
|
3550
|
+
if (t === void 0 || t < 0 || t >= this.#e.length) throw new o("Index out of range");
|
|
3593
3551
|
return this.#e[t].multiply(e), this;
|
|
3594
3552
|
}
|
|
3595
3553
|
reduce() {
|
|
@@ -3602,13 +3560,13 @@ var O = class e {
|
|
|
3602
3560
|
solve() {
|
|
3603
3561
|
let [e, t] = this.matrix, n = e.map((e, n) => [...e, t[n]]);
|
|
3604
3562
|
for (let t = 0; t < e.length; t++) {
|
|
3605
|
-
let
|
|
3606
|
-
if (
|
|
3563
|
+
let i = n[t][t].clone();
|
|
3564
|
+
if (i.isZero()) {
|
|
3607
3565
|
let e = n.find((e, n) => n > t && !e[t].isZero());
|
|
3608
|
-
if (e) n[t].forEach((t, n) => t.add(e[n])),
|
|
3609
|
-
else throw
|
|
3566
|
+
if (e) n[t].forEach((t, n) => t.add(e[n])), i = n[t][t].clone();
|
|
3567
|
+
else throw new r("Unsolvable...");
|
|
3610
3568
|
}
|
|
3611
|
-
n[t] = n[t].map((e) => e.divide(
|
|
3569
|
+
n[t] = n[t].map((e) => e.divide(i));
|
|
3612
3570
|
for (let r = 0; r < e.length; r++) {
|
|
3613
3571
|
if (r === t) continue;
|
|
3614
3572
|
let e = n[r][t].clone().opposite();
|
|
@@ -3622,7 +3580,7 @@ var O = class e {
|
|
|
3622
3580
|
let t = [], n = this.equations.map((t) => t.left.monomByLetter(e).coefficient.value);
|
|
3623
3581
|
return n.forEach((e, r) => {
|
|
3624
3582
|
for (let i = r + 1; i < n.length; i++) {
|
|
3625
|
-
let a =
|
|
3583
|
+
let a = p.lcm(e, n[i]), o = e < 0 ? -1 : 1;
|
|
3626
3584
|
t.push([{
|
|
3627
3585
|
id: r,
|
|
3628
3586
|
factor: o * a / e
|
|
@@ -3633,15 +3591,15 @@ var O = class e {
|
|
|
3633
3591
|
}
|
|
3634
3592
|
}), t.sort((e, t) => Math.abs(e[0].factor) + Math.abs(e[1].factor) - (Math.abs(t[0].factor) + Math.abs(t[1].factor)));
|
|
3635
3593
|
}
|
|
3636
|
-
subtract(t,
|
|
3594
|
+
subtract(t, r) {
|
|
3637
3595
|
if (t instanceof e) {
|
|
3638
3596
|
let e = t.equations.length;
|
|
3639
|
-
if (e !== this.#e.length) throw
|
|
3597
|
+
if (e !== this.#e.length) throw new n("The number of equations must be the same");
|
|
3640
3598
|
for (let n = 0; n < e; n++) this.#e[n].subtract(t.equations[n]);
|
|
3641
3599
|
} else {
|
|
3642
|
-
if (
|
|
3643
|
-
let e = new
|
|
3644
|
-
this.#e[
|
|
3600
|
+
if (r === void 0 || r < 0 || r >= this.#e.length) throw new o("Index out of range");
|
|
3601
|
+
let e = new N(t);
|
|
3602
|
+
this.#e[r].subtract(e);
|
|
3645
3603
|
}
|
|
3646
3604
|
return this;
|
|
3647
3605
|
}
|
|
@@ -3675,12 +3633,19 @@ var O = class e {
|
|
|
3675
3633
|
n.variable = e, t.push(n);
|
|
3676
3634
|
}), t);
|
|
3677
3635
|
}
|
|
3678
|
-
},
|
|
3636
|
+
}, L = class {
|
|
3679
3637
|
#e;
|
|
3680
3638
|
constructor(e) {
|
|
3681
3639
|
return this.#e = [], e !== void 0 && this.parse(e), this;
|
|
3682
3640
|
}
|
|
3683
|
-
parse = (e) =>
|
|
3641
|
+
parse = (e) => {
|
|
3642
|
+
try {
|
|
3643
|
+
this.#e = new O(T.SET).parse(e).rpn;
|
|
3644
|
+
} catch (n) {
|
|
3645
|
+
throw new t(`Cannot parse "${e}" as a LogicalSet`, { cause: n });
|
|
3646
|
+
}
|
|
3647
|
+
return this;
|
|
3648
|
+
};
|
|
3684
3649
|
get tex() {
|
|
3685
3650
|
let e = [];
|
|
3686
3651
|
for (let t of this.#e) if (t.tokenType === "variable") e.push(t);
|
|
@@ -3828,8 +3793,8 @@ var O = class e {
|
|
|
3828
3793
|
}
|
|
3829
3794
|
return [...n[0]].sort();
|
|
3830
3795
|
}
|
|
3831
|
-
},
|
|
3832
|
-
#e =
|
|
3796
|
+
}, R = class e {
|
|
3797
|
+
#e = F.POWER;
|
|
3833
3798
|
#t = [];
|
|
3834
3799
|
constructor(...e) {
|
|
3835
3800
|
return this.parse(...e), this;
|
|
@@ -3837,7 +3802,7 @@ var O = class e {
|
|
|
3837
3802
|
parse(...t) {
|
|
3838
3803
|
return this.#t = [], t.length === 0 || t.forEach((t) => {
|
|
3839
3804
|
if (typeof t == "string") return this.fromString(t);
|
|
3840
|
-
t instanceof e ? this.#t.push(...t.factors.map((e) => e.clone())) : this.#t.push(new
|
|
3805
|
+
t instanceof e ? this.#t.push(...t.factors.map((e) => e.clone())) : this.#t.push(new P(t));
|
|
3841
3806
|
}), this;
|
|
3842
3807
|
}
|
|
3843
3808
|
clone() {
|
|
@@ -3852,16 +3817,16 @@ var O = class e {
|
|
|
3852
3817
|
return t.length === 0 ? e.length === 1 ? e[0].asSingle.display : e.map((e, t) => t === 0 && e.polynom.monoms.length === 1 ? e.asSingle.display : e.display).join("") : `(${e.length === 1 ? e[0].asSingle.display : e.map((e) => e.display).join("")})/(${t.length === 1 ? t[0].asSingle.display : t.map((e) => e.display).join("")})`;
|
|
3853
3818
|
}
|
|
3854
3819
|
static #n(t, n) {
|
|
3855
|
-
let r =
|
|
3856
|
-
let t = r[e].reduce((e, t) => e.add(t.power), new
|
|
3857
|
-
return new
|
|
3820
|
+
let r = z(t), i = z(n), a = Object.keys(r).filter((e) => Object.hasOwn(i, e)).map((e) => {
|
|
3821
|
+
let t = r[e].reduce((e, t) => e.add(t.power), new m("0")), n = i[e].reduce((e, t) => e.add(t.power), new m("0"));
|
|
3822
|
+
return new P(e, m.min(t, n));
|
|
3858
3823
|
});
|
|
3859
3824
|
return new e(...a);
|
|
3860
3825
|
}
|
|
3861
3826
|
static #r(t, n) {
|
|
3862
|
-
let r =
|
|
3863
|
-
let t = Object.hasOwn(r, e) ? r[e].reduce((e, t) => e.add(t.power), new
|
|
3864
|
-
return new
|
|
3827
|
+
let r = z(t), i = z(n), a = [.../* @__PURE__ */ new Set([...Object.keys(r), ...Object.keys(i)])].map((e) => {
|
|
3828
|
+
let t = Object.hasOwn(r, e) ? r[e].reduce((e, t) => e.add(t.power), new m("0")) : new m(0), n = Object.hasOwn(i, e) ? i[e].reduce((e, t) => e.add(t.power), new m("0")) : new m(0);
|
|
3829
|
+
return new P(e, m.max(t, n));
|
|
3865
3830
|
});
|
|
3866
3831
|
return new e(...a);
|
|
3867
3832
|
}
|
|
@@ -3886,17 +3851,17 @@ var O = class e {
|
|
|
3886
3851
|
e.multiply(t.clone().divide(r[n]));
|
|
3887
3852
|
}), i = t;
|
|
3888
3853
|
}
|
|
3889
|
-
let a = e.gcd(...n), o = new
|
|
3890
|
-
return this.#t = [...a.factors, new
|
|
3854
|
+
let a = e.gcd(...n), o = new M(0).add(...n.map((e) => e.divide(a).reduce().develop().factors[0].polynom)).reduce();
|
|
3855
|
+
return this.#t = [...a.factors, new P(o)], i && this.divide(i), this.#t = this.#t.filter((e) => !e.power.isZero()), this;
|
|
3891
3856
|
}
|
|
3892
3857
|
get asPower() {
|
|
3893
|
-
return this.#e =
|
|
3858
|
+
return this.#e = F.POWER, this;
|
|
3894
3859
|
}
|
|
3895
3860
|
get asRoot() {
|
|
3896
|
-
return this.#e =
|
|
3861
|
+
return this.#e = F.ROOT, this;
|
|
3897
3862
|
}
|
|
3898
3863
|
degree(e) {
|
|
3899
|
-
return this.#t.reduce((t, n) => t.add(n.degree(e)), new
|
|
3864
|
+
return this.#t.reduce((t, n) => t.add(n.degree(e)), new m("0"));
|
|
3900
3865
|
}
|
|
3901
3866
|
get denominator() {
|
|
3902
3867
|
return new e(...this.#t.filter((e) => e.power.isNegative()).map((e) => e.clone().inverse()));
|
|
@@ -3912,7 +3877,7 @@ var O = class e {
|
|
|
3912
3877
|
return r !== void 0 && (this.#t = r.factors), this.add(...t);
|
|
3913
3878
|
}
|
|
3914
3879
|
develop() {
|
|
3915
|
-
let t = new
|
|
3880
|
+
let t = new M("1"), n = new M("1");
|
|
3916
3881
|
return this.numerator.factors.forEach((e) => {
|
|
3917
3882
|
t.multiply(e.develop());
|
|
3918
3883
|
}), this.denominator.factors.forEach((e) => {
|
|
@@ -3923,7 +3888,7 @@ var O = class e {
|
|
|
3923
3888
|
return this.#t = this.#t.concat(e.clone().factors.map((e) => e.inverse())), this;
|
|
3924
3889
|
}
|
|
3925
3890
|
evaluate(e, t) {
|
|
3926
|
-
return t ? this.#t.reduce((n, r) => n * r.evaluate(e, t), 1) : this.#t.reduce((t, n) => t.multiply(n.evaluate(e)), new
|
|
3891
|
+
return t ? this.#t.reduce((n, r) => n * r.evaluate(e, t), 1) : this.#t.reduce((t, n) => t.multiply(n.evaluate(e)), new m("1"));
|
|
3927
3892
|
}
|
|
3928
3893
|
factorize(t) {
|
|
3929
3894
|
let n = [];
|
|
@@ -3931,7 +3896,7 @@ var O = class e {
|
|
|
3931
3896
|
let r = e.polynom.factorize(t);
|
|
3932
3897
|
if (r.length > 1) {
|
|
3933
3898
|
let t = e.power.clone();
|
|
3934
|
-
n.push(...r.map((e) => new
|
|
3899
|
+
n.push(...r.map((e) => new P(e, t)));
|
|
3935
3900
|
} else n.push(e.clone());
|
|
3936
3901
|
});
|
|
3937
3902
|
let r = new e(...n), i = r.numerator.reduce(), a = r.denominator.reduce();
|
|
@@ -3944,20 +3909,20 @@ var O = class e {
|
|
|
3944
3909
|
this.#t = e;
|
|
3945
3910
|
}
|
|
3946
3911
|
fromPolynom(e, t) {
|
|
3947
|
-
if (this.#t = [new
|
|
3948
|
-
let e = new
|
|
3912
|
+
if (this.#t = [new P(new M(e))], t) {
|
|
3913
|
+
let e = new M(t);
|
|
3949
3914
|
if (e.isOne()) return this;
|
|
3950
|
-
if (e.isZero()) throw
|
|
3951
|
-
this.#t.push(new
|
|
3915
|
+
if (e.isZero()) throw new r("Cannot divide by zero");
|
|
3916
|
+
this.#t.push(new P(e, -1));
|
|
3952
3917
|
}
|
|
3953
3918
|
return this;
|
|
3954
3919
|
}
|
|
3955
3920
|
fromString(e) {
|
|
3956
3921
|
this.#t = [];
|
|
3957
|
-
let [
|
|
3958
|
-
if (
|
|
3959
|
-
if (
|
|
3960
|
-
return this.#t =
|
|
3922
|
+
let [n, ...r] = _(e, "/");
|
|
3923
|
+
if (n === "") throw new t("Parsing a PolyFactor from a string requires a numerator");
|
|
3924
|
+
if (r.length > 1) throw new t("Parsing a PolyFactor from a string only allows max one signe \"/\"");
|
|
3925
|
+
return this.#t = r.length === 0 ? P.factorsFromString(h(n), !0) : [...P.factorsFromString(h(n), !0), ...P.factorsFromString(h(r[0]), !1)], this;
|
|
3961
3926
|
}
|
|
3962
3927
|
getRoots() {
|
|
3963
3928
|
return [];
|
|
@@ -3992,27 +3957,27 @@ var O = class e {
|
|
|
3992
3957
|
return new e(...this.#t.filter((e) => e.power.isPositive()));
|
|
3993
3958
|
}
|
|
3994
3959
|
one() {
|
|
3995
|
-
return this.#t = [new
|
|
3960
|
+
return this.#t = [new P("1", "1")], this;
|
|
3996
3961
|
}
|
|
3997
3962
|
opposite() {
|
|
3998
3963
|
let e = this.#t.findIndex((e) => e.display === "(-1)");
|
|
3999
|
-
return e >= 0 ? this.#t.splice(e, 1) : this.#t.push(new
|
|
3964
|
+
return e >= 0 ? this.#t.splice(e, 1) : this.#t.push(new P("-1", "1")), this;
|
|
4000
3965
|
}
|
|
4001
3966
|
pow(e) {
|
|
4002
3967
|
return this.#t = this.#t.map((t) => t.pow(e)), this;
|
|
4003
3968
|
}
|
|
4004
3969
|
primitive() {
|
|
4005
|
-
throw
|
|
3970
|
+
throw new a("Method not implemented.");
|
|
4006
3971
|
}
|
|
4007
3972
|
reduce() {
|
|
4008
|
-
let e =
|
|
3973
|
+
let e = z(this);
|
|
4009
3974
|
this.#t = Object.values(e).map((e) => {
|
|
4010
3975
|
let t = e[0].polynom;
|
|
4011
|
-
return new
|
|
3976
|
+
return new P(t, e.reduce((e, t) => e.add(t.power), new m("0")).reduce());
|
|
4012
3977
|
}).filter((e) => !e.power.isZero());
|
|
4013
|
-
let t = new
|
|
3978
|
+
let t = new P(1), n = new P(1), r = this.#t.filter((e) => e.polynom.monoms.length === 1 && e.power.isRelative());
|
|
4014
3979
|
return r.length > 0 && (r.forEach((e) => {
|
|
4015
|
-
e.power.isPositive() ? t.multiply(new
|
|
3980
|
+
e.power.isPositive() ? t.multiply(new P(e.polynom.clone().pow(e.power.value))) : n.multiply(new P(e.polynom.clone().pow(-e.power.value)));
|
|
4016
3981
|
}), this.#t = this.#t.filter((e) => !(e.polynom.monoms.length === 1 && e.power.isRelative())), n.polynom.isOne() || this.#t.push(n.inverse()), t.polynom.isOne() || this.#t.push(t)), this;
|
|
4017
3982
|
}
|
|
4018
3983
|
root(e) {
|
|
@@ -4036,7 +4001,7 @@ var O = class e {
|
|
|
4036
4001
|
}
|
|
4037
4002
|
tableOfSigns() {
|
|
4038
4003
|
let e = this.getZeroes(), t = e.map((e) => e.value), n = this.factorize().factors.map((e) => ({
|
|
4039
|
-
factor: new
|
|
4004
|
+
factor: new P(e),
|
|
4040
4005
|
...e.tableOfSigns()
|
|
4041
4006
|
}));
|
|
4042
4007
|
return n.forEach((n) => {
|
|
@@ -4070,18 +4035,18 @@ var O = class e {
|
|
|
4070
4035
|
return this.#t.reduce((e, t) => e.concat(t.variables), []);
|
|
4071
4036
|
}
|
|
4072
4037
|
zero() {
|
|
4073
|
-
return this.#t = [new
|
|
4038
|
+
return this.#t = [new P("0", "1")], this;
|
|
4074
4039
|
}
|
|
4075
4040
|
#i() {
|
|
4076
4041
|
let e, t = [];
|
|
4077
|
-
return this.#e ===
|
|
4042
|
+
return this.#e === F.ROOT ? (e = this.numerator.factors, t = this.denominator.factors) : e = this.#t, e.length === 0 && (e = [new P("1")]), {
|
|
4078
4043
|
num: e,
|
|
4079
4044
|
den: t
|
|
4080
4045
|
};
|
|
4081
4046
|
}
|
|
4082
4047
|
};
|
|
4083
|
-
function
|
|
4084
|
-
let t = new
|
|
4048
|
+
function z(e) {
|
|
4049
|
+
let t = new m().one(), n = new m().one(), r = e.factors.reduce((e, r) => {
|
|
4085
4050
|
if (r.polynom.degree().isZero() && r.power.isRelative()) {
|
|
4086
4051
|
let i = r.polynom.monoms[0].coefficient.pow(r.power.clone().abs());
|
|
4087
4052
|
return r.power.isPositive() ? t.multiply(i) : n.multiply(i), e;
|
|
@@ -4089,11 +4054,11 @@ function N(e) {
|
|
|
4089
4054
|
let i = r.polynom.display;
|
|
4090
4055
|
return Object.hasOwn(e, i) ? e[i].push(r) : e[i] = [r], e;
|
|
4091
4056
|
}, {}), { numerator: i, denominator: a } = t.divide(n).reduce();
|
|
4092
|
-
return i !== 1 && (r[i.toString()] = [new
|
|
4057
|
+
return i !== 1 && (r[i.toString()] = [new P(i, 1)]), a !== 1 && (r[a.toString()] = [new P(a, -1)]), r;
|
|
4093
4058
|
}
|
|
4094
4059
|
//#endregion
|
|
4095
4060
|
//#region src/algebra/matrix.ts
|
|
4096
|
-
var
|
|
4061
|
+
var ve = class e {
|
|
4097
4062
|
#e = null;
|
|
4098
4063
|
#t = 0;
|
|
4099
4064
|
#n = [];
|
|
@@ -4133,7 +4098,7 @@ var le = class e {
|
|
|
4133
4098
|
return this.#e = null, t;
|
|
4134
4099
|
}
|
|
4135
4100
|
add(e) {
|
|
4136
|
-
if (!this.canBeAdded(e)) throw
|
|
4101
|
+
if (!this.canBeAdded(e)) throw new n("Cannot add a matrix with different dimensions.");
|
|
4137
4102
|
return this.forEach((t, n, r) => {
|
|
4138
4103
|
t.add(e.values[n][r]);
|
|
4139
4104
|
}), this;
|
|
@@ -4158,7 +4123,7 @@ var le = class e {
|
|
|
4158
4123
|
return this.dimension.cols === e.dimension.rows;
|
|
4159
4124
|
}
|
|
4160
4125
|
characteristic_polynom(t) {
|
|
4161
|
-
return t ??= "k", this.clone().subtract(new e(this.dimension.rows).one().multiply(new
|
|
4126
|
+
return t ??= "k", this.clone().subtract(new e(this.dimension.rows).one().multiply(new M(t))).determinant();
|
|
4162
4127
|
}
|
|
4163
4128
|
cofactor(e, t) {
|
|
4164
4129
|
let n = this.clone();
|
|
@@ -4167,14 +4132,14 @@ var le = class e {
|
|
|
4167
4132
|
}), n.determinant().multiply((-1) ** (e + t));
|
|
4168
4133
|
}
|
|
4169
4134
|
get cols() {
|
|
4170
|
-
let e = Array.from({ length: this.dimension.cols }, () => Array.from({ length: this.dimension.rows }, () => new
|
|
4135
|
+
let e = Array.from({ length: this.dimension.cols }, () => Array.from({ length: this.dimension.rows }, () => new M()));
|
|
4171
4136
|
return this.forEach((t, n, r) => {
|
|
4172
4137
|
e[r][n] = t;
|
|
4173
4138
|
}), e;
|
|
4174
4139
|
}
|
|
4175
4140
|
determinant() {
|
|
4176
|
-
if (!this.isSquare()) throw
|
|
4177
|
-
let e = new
|
|
4141
|
+
if (!this.isSquare()) throw new n("Matrix is not square");
|
|
4142
|
+
let e = new M();
|
|
4178
4143
|
return this.#n.length === 1 ? this.#n[0][0].clone() : (this.values[0].forEach((t, n) => {
|
|
4179
4144
|
let r = this.cofactor(0, n);
|
|
4180
4145
|
e.add(t.clone().multiply(r));
|
|
@@ -4197,36 +4162,36 @@ var le = class e {
|
|
|
4197
4162
|
});
|
|
4198
4163
|
}
|
|
4199
4164
|
fromDimensions(e, t) {
|
|
4200
|
-
return this.#n = Array.from({ length: e }, () => Array.from({ length: t }, () => new
|
|
4165
|
+
return this.#n = Array.from({ length: e }, () => Array.from({ length: t }, () => new M())), this;
|
|
4201
4166
|
}
|
|
4202
4167
|
fromString(e) {
|
|
4203
4168
|
if (e.startsWith("((") && e.endsWith("))")) return this.fromString(e.substring(1, e.length - 1));
|
|
4204
4169
|
let t = e.split("),(");
|
|
4205
|
-
return this.#n = t.map((e, n) => n === 0 ? e.substring(1).split(",") : n === t.length - 1 ? e.substring(0, e.length - 1).split(",") : e.split(",")).map((e) => e.map((e) => new
|
|
4170
|
+
return this.#n = t.map((e, n) => n === 0 ? e.substring(1).split(",") : n === t.length - 1 ? e.substring(0, e.length - 1).split(",") : e.split(",")).map((e) => e.map((e) => new M(e))), this;
|
|
4206
4171
|
}
|
|
4207
4172
|
fromValues(e) {
|
|
4208
4173
|
this.#n = [];
|
|
4209
4174
|
let t = e[0].length;
|
|
4210
|
-
if (e.some((e) => e.length !== t)) throw
|
|
4175
|
+
if (e.some((e) => e.length !== t)) throw new n("Each line must be the same length");
|
|
4211
4176
|
return e.forEach((e) => {
|
|
4212
4177
|
let t = [];
|
|
4213
4178
|
e.forEach((e) => {
|
|
4214
|
-
t.push(new
|
|
4179
|
+
t.push(new M(e));
|
|
4215
4180
|
}), this.#n.push(t);
|
|
4216
4181
|
}), this;
|
|
4217
4182
|
}
|
|
4218
4183
|
fromVectors(...e) {
|
|
4219
4184
|
this.#n = [];
|
|
4220
4185
|
let t = e[0].dimension;
|
|
4221
|
-
if (e.some((e) => e.dimension !== t)) throw
|
|
4186
|
+
if (e.some((e) => e.dimension !== t)) throw new n("Each vectors must be the same dimension");
|
|
4222
4187
|
return this.fromDimensions(e[0].dimension, e.length), e.forEach((e, t) => {
|
|
4223
4188
|
e.array.forEach((e, n) => {
|
|
4224
|
-
this.#n[n][t] = new
|
|
4189
|
+
this.#n[n][t] = new M(e);
|
|
4225
4190
|
});
|
|
4226
4191
|
}), this;
|
|
4227
4192
|
}
|
|
4228
4193
|
inverse() {
|
|
4229
|
-
if (!this.canBeInverted()) throw
|
|
4194
|
+
if (!this.canBeInverted()) throw new r("The matrix cannot be inverted.");
|
|
4230
4195
|
let t = new e().fromDimensions(this.dimension.rows, this.dimension.cols);
|
|
4231
4196
|
t.forEach((e, n, r) => {
|
|
4232
4197
|
t.setValue(n, r, this.cofactor(n, r));
|
|
@@ -4261,14 +4226,14 @@ var le = class e {
|
|
|
4261
4226
|
}
|
|
4262
4227
|
multiply(t) {
|
|
4263
4228
|
if (t instanceof e) {
|
|
4264
|
-
if (!this.canBeMultiplied(t)) throw
|
|
4265
|
-
let
|
|
4266
|
-
return
|
|
4267
|
-
let a = this.rows[
|
|
4229
|
+
if (!this.canBeMultiplied(t)) throw new n("Cannot multiply a matrix with incompatibles dimensions");
|
|
4230
|
+
let r = new e(this.dimension.rows, t.dimension.cols);
|
|
4231
|
+
return r.forEach((e, n, i) => {
|
|
4232
|
+
let a = this.rows[n], o = t.cols[i], s = new M();
|
|
4268
4233
|
a.forEach((e, t) => {
|
|
4269
4234
|
s.add(e.clone().multiply(o[t]));
|
|
4270
|
-
}),
|
|
4271
|
-
}), this.#n =
|
|
4235
|
+
}), r.setValue(n, i, s);
|
|
4236
|
+
}), this.#n = r.values, this;
|
|
4272
4237
|
}
|
|
4273
4238
|
return this.forEach((e, n, r) => {
|
|
4274
4239
|
this.setValue(n, r, e.multiply(t));
|
|
@@ -4294,21 +4259,21 @@ var le = class e {
|
|
|
4294
4259
|
return this.#t = 4, this;
|
|
4295
4260
|
}
|
|
4296
4261
|
pow(e) {
|
|
4297
|
-
return
|
|
4262
|
+
return j(this, e);
|
|
4298
4263
|
}
|
|
4299
4264
|
reduce() {
|
|
4300
|
-
throw
|
|
4265
|
+
throw new a("Not yet implemented");
|
|
4301
4266
|
}
|
|
4302
4267
|
get rows() {
|
|
4303
4268
|
return this.#n;
|
|
4304
4269
|
}
|
|
4305
4270
|
setValue(e, t, n) {
|
|
4306
4271
|
let { rows: r, cols: i } = this.dimension;
|
|
4307
|
-
if (e < 0 || e >= r || t < 0 || t >= i) throw
|
|
4308
|
-
return this.#n[e][t] = new
|
|
4272
|
+
if (e < 0 || e >= r || t < 0 || t >= i) throw new o(`${e}x${t} is out of range (${r}x${i})`);
|
|
4273
|
+
return this.#n[e][t] = new M(n), this;
|
|
4309
4274
|
}
|
|
4310
4275
|
subtract(e) {
|
|
4311
|
-
if (!this.canBeAdded(e)) throw
|
|
4276
|
+
if (!this.canBeAdded(e)) throw new n("Cannot subtract a matrix with different dimensions.");
|
|
4312
4277
|
return this.forEach((t, n, r) => {
|
|
4313
4278
|
t.subtract(e.values[n][r]);
|
|
4314
4279
|
}), this;
|
|
@@ -4330,29 +4295,29 @@ var le = class e {
|
|
|
4330
4295
|
};
|
|
4331
4296
|
//#endregion
|
|
4332
4297
|
//#region src/geometry/geomMath.ts
|
|
4333
|
-
function
|
|
4298
|
+
function ye(e, t) {
|
|
4334
4299
|
return e.dimension === t.dimension && e.array.every((e, n) => t.array[n].isEqual(e));
|
|
4335
4300
|
}
|
|
4336
|
-
function
|
|
4301
|
+
function be(e, t) {
|
|
4337
4302
|
if (e.dimension !== t.dimension) return !1;
|
|
4338
4303
|
let n = t.array[0].value / e.array[0].value;
|
|
4339
4304
|
return e.array.every((e, r) => t.array[r].value === e.value * n);
|
|
4340
4305
|
}
|
|
4341
|
-
function
|
|
4342
|
-
return e.dimension === t.dimension ? e.array.reduce((e, n, r) => e.add(n.clone().multiply(t.array[r])), new
|
|
4306
|
+
function xe(e, t) {
|
|
4307
|
+
return e.dimension === t.dimension ? e.array.reduce((e, n, r) => e.add(n.clone().multiply(t.array[r])), new m(0)) : new m().invalid();
|
|
4343
4308
|
}
|
|
4344
|
-
function
|
|
4345
|
-
if (e.some((t) => t.dimension !== e[0].dimension)) throw
|
|
4346
|
-
if (e[0].dimension !== e.length) throw
|
|
4309
|
+
function Se(...e) {
|
|
4310
|
+
if (e.some((t) => t.dimension !== e[0].dimension)) throw new n("All vectors must have the same dimension");
|
|
4311
|
+
if (e[0].dimension !== e.length) throw new n(`The determinant of dimension ${e[0].dimension} must have the same number of vectors (${e.length} given)`);
|
|
4347
4312
|
return e[0].dimension === 2 ? e[0].array[0].clone().multiply(e[1].array[1]).subtract(e[0].array[1].clone().multiply(e[1].array[0])) : e[0].array[0].clone().multiply(e[1].array[1].clone().multiply(e[2].array[2]).subtract(e[1].array[2].clone().multiply(e[2].array[1]))).subtract(e[0].array[1].clone().multiply(e[1].array[0].clone().multiply(e[2].array[2]).subtract(e[1].array[2].clone().multiply(e[2].array[0])))).add(e[0].array[2].clone().multiply(e[1].array[0].clone().multiply(e[2].array[1]).subtract(e[1].array[1].clone().multiply(e[2].array[0]))));
|
|
4348
4313
|
}
|
|
4349
4314
|
//#endregion
|
|
4350
4315
|
//#region src/geometry/TupleN.ts
|
|
4351
|
-
var
|
|
4316
|
+
var B = class {
|
|
4352
4317
|
#e = [];
|
|
4353
4318
|
#t;
|
|
4354
4319
|
constructor(...e) {
|
|
4355
|
-
this.#e = e.map((e) => new
|
|
4320
|
+
this.#e = e.map((e) => new m(e));
|
|
4356
4321
|
}
|
|
4357
4322
|
copy() {
|
|
4358
4323
|
return this.#e.map((e) => e.clone());
|
|
@@ -4369,7 +4334,7 @@ var F = class {
|
|
|
4369
4334
|
fromString(e) {
|
|
4370
4335
|
e.startsWith("(") && (e = e.substring(1)), e.endsWith(")") && (e = e.substring(0, e.length - 1));
|
|
4371
4336
|
let t = e.split(/[,;\s]/g).filter((e) => e.trim() !== "");
|
|
4372
|
-
return t.length < 2 || (this.#e = t.map((e) => new
|
|
4337
|
+
return t.length < 2 || (this.#e = t.map((e) => new m(e))), this;
|
|
4373
4338
|
}
|
|
4374
4339
|
get onChange() {
|
|
4375
4340
|
return this.#t;
|
|
@@ -4378,46 +4343,46 @@ var F = class {
|
|
|
4378
4343
|
this.#t = e;
|
|
4379
4344
|
}
|
|
4380
4345
|
setDimension(e = 2) {
|
|
4381
|
-
if (e < 2) throw
|
|
4346
|
+
if (e < 2) throw new n("Dimension must be at least 2");
|
|
4382
4347
|
if (e < this.dimension) this.#e = this.#e.slice(0, e);
|
|
4383
|
-
else if (e > this.dimension) for (let t = this.dimension; t < e; t++) this.#e.push(new
|
|
4348
|
+
else if (e > this.dimension) for (let t = this.dimension; t < e; t++) this.#e.push(new m(0));
|
|
4384
4349
|
return this;
|
|
4385
4350
|
}
|
|
4386
4351
|
get x() {
|
|
4387
4352
|
return this.#e[0];
|
|
4388
4353
|
}
|
|
4389
4354
|
set x(e) {
|
|
4390
|
-
this.#e[0] = new
|
|
4355
|
+
this.#e[0] = new m(e), this.#t?.();
|
|
4391
4356
|
}
|
|
4392
4357
|
get y() {
|
|
4393
4358
|
return this.#e[1];
|
|
4394
4359
|
}
|
|
4395
4360
|
set y(e) {
|
|
4396
|
-
this.#e[1] = new
|
|
4361
|
+
this.#e[1] = new m(e), this.#t?.();
|
|
4397
4362
|
}
|
|
4398
4363
|
get z() {
|
|
4399
|
-
if (this.dimension < 3) throw
|
|
4364
|
+
if (this.dimension < 3) throw new n("Vector is not 3D");
|
|
4400
4365
|
return this.#e[2];
|
|
4401
4366
|
}
|
|
4402
4367
|
set z(e) {
|
|
4403
|
-
if (this.dimension < 3) throw
|
|
4404
|
-
this.#e[2] = new
|
|
4368
|
+
if (this.dimension < 3) throw new n("Vector is not 3D");
|
|
4369
|
+
this.#e[2] = new m(e), this.#t?.();
|
|
4405
4370
|
}
|
|
4406
4371
|
zero = () => (this.#e.forEach((e) => e.zero()), this.#t?.(), this);
|
|
4407
|
-
},
|
|
4372
|
+
}, V = class e extends B {
|
|
4408
4373
|
constructor(...e) {
|
|
4409
4374
|
super(), e.length > 0 && this.parse(...e);
|
|
4410
4375
|
}
|
|
4411
|
-
parse(...
|
|
4412
|
-
if (
|
|
4413
|
-
if (
|
|
4414
|
-
if (typeof
|
|
4376
|
+
parse(...n) {
|
|
4377
|
+
if (n.length === 1) {
|
|
4378
|
+
if (n[0] instanceof B) return this.array = n[0].copy(), this;
|
|
4379
|
+
if (typeof n[0] == "string") return this.fromString(n[0]), this;
|
|
4415
4380
|
}
|
|
4416
|
-
if (
|
|
4417
|
-
if (
|
|
4418
|
-
let
|
|
4419
|
-
if (
|
|
4420
|
-
this.array =
|
|
4381
|
+
if (n.length > 1) {
|
|
4382
|
+
if (n.some((t) => t instanceof e)) throw new i("Creating a point with multiple argument requires an input fraction");
|
|
4383
|
+
let r = n.map((e) => new m(e));
|
|
4384
|
+
if (r.some((e) => e.isNaN())) throw new t("The given values are not a valid point string (a,b): ");
|
|
4385
|
+
this.array = r;
|
|
4421
4386
|
}
|
|
4422
4387
|
return this;
|
|
4423
4388
|
}
|
|
@@ -4431,8 +4396,8 @@ var F = class {
|
|
|
4431
4396
|
return `(${this.array.map((e) => e.display).join(";")})`;
|
|
4432
4397
|
}
|
|
4433
4398
|
distanceTo(e) {
|
|
4434
|
-
if (this.dimension !== e.dimension) throw
|
|
4435
|
-
let t = this.array.map((t, n) => e.array[n].clone().subtract(t)).reduce((e, t) => e.add(t.clone().pow(2)), new
|
|
4399
|
+
if (this.dimension !== e.dimension) throw new n("The two points must have the same dimensions.");
|
|
4400
|
+
let t = this.array.map((t, n) => e.array[n].clone().subtract(t)).reduce((e, t) => e.add(t.clone().pow(2)), new m(0));
|
|
4436
4401
|
return new v().from(2, t).reduce();
|
|
4437
4402
|
}
|
|
4438
4403
|
isEqual(e) {
|
|
@@ -4442,30 +4407,30 @@ var F = class {
|
|
|
4442
4407
|
return this.isEqual(new e(t, n));
|
|
4443
4408
|
}
|
|
4444
4409
|
middleOf(e, t) {
|
|
4445
|
-
if (e.dimension !== t.dimension) throw
|
|
4410
|
+
if (e.dimension !== t.dimension) throw new n("Vectors must be the same dimension");
|
|
4446
4411
|
return this.array = [], e.array.forEach((e, n) => {
|
|
4447
4412
|
this.array.push(e.clone().add(t.array[n]).divide(2));
|
|
4448
4413
|
}), this;
|
|
4449
4414
|
}
|
|
4450
|
-
},
|
|
4415
|
+
}, H = class e extends B {
|
|
4451
4416
|
constructor(...e) {
|
|
4452
4417
|
return super(), e.length > 0 && this.parse(...e), this;
|
|
4453
4418
|
}
|
|
4454
4419
|
parse(...e) {
|
|
4455
|
-
if (e.length === 0) throw
|
|
4420
|
+
if (e.length === 0) throw new i("Invalid value");
|
|
4456
4421
|
if (e.length === 1) {
|
|
4457
|
-
if (e[0] instanceof
|
|
4422
|
+
if (e[0] instanceof B) return this.array = e[0].copy(), this;
|
|
4458
4423
|
if (typeof e[0] == "string") return this.fromString(e[0]);
|
|
4459
|
-
throw
|
|
4424
|
+
throw new i("Invalid value");
|
|
4460
4425
|
}
|
|
4461
4426
|
if (e.length === 2) {
|
|
4462
|
-
let [t,
|
|
4463
|
-
if (t instanceof
|
|
4464
|
-
if (t.dimension !==
|
|
4465
|
-
return this.array =
|
|
4427
|
+
let [t, r] = e;
|
|
4428
|
+
if (t instanceof B && r instanceof B) {
|
|
4429
|
+
if (t.dimension !== r.dimension) throw new n("Vectors must have the same dimension");
|
|
4430
|
+
return this.array = r.array.map((e, n) => e.clone().subtract(t.array[n])), this;
|
|
4466
4431
|
}
|
|
4467
4432
|
}
|
|
4468
|
-
return this.array = e.map((e) => new
|
|
4433
|
+
return this.array = e.map((e) => new m(e)), this;
|
|
4469
4434
|
}
|
|
4470
4435
|
clone() {
|
|
4471
4436
|
return new e(...this.copy());
|
|
@@ -4488,16 +4453,16 @@ var F = class {
|
|
|
4488
4453
|
return t && (r = Math.abs(r)), (n ? 1 : 180 / Math.PI) * Math.acos(r / (this.norm * e.norm));
|
|
4489
4454
|
};
|
|
4490
4455
|
cross(t) {
|
|
4491
|
-
if (this.dimension !== 3 || t.dimension !== 3) throw
|
|
4456
|
+
if (this.dimension !== 3 || t.dimension !== 3) throw new n("Cross product can only be determined in 3D");
|
|
4492
4457
|
return new e(this.y.clone().multiply(t.z).subtract(this.z.clone().multiply(t.y)), this.z.clone().multiply(t.x).subtract(this.x.clone().multiply(t.z)), this.x.clone().multiply(t.y).subtract(this.y.clone().multiply(t.x)));
|
|
4493
4458
|
}
|
|
4494
|
-
divideByScalar = (e) => this.multiplyByScalar(new
|
|
4495
|
-
dot = (e) =>
|
|
4459
|
+
divideByScalar = (e) => this.multiplyByScalar(new m(e).inverse());
|
|
4460
|
+
dot = (e) => xe(this, e);
|
|
4496
4461
|
fromString(e) {
|
|
4497
4462
|
return e.startsWith("((") && e.endsWith("))") ? super.fromString(e.slice(1, -1)) : super.fromString(e);
|
|
4498
4463
|
}
|
|
4499
|
-
isColinearTo = (e) =>
|
|
4500
|
-
isEqual = (e) =>
|
|
4464
|
+
isColinearTo = (e) => be(this, e);
|
|
4465
|
+
isEqual = (e) => ye(this, e);
|
|
4501
4466
|
isNormalTo = (e) => this.dot(e).isZero();
|
|
4502
4467
|
get isNull() {
|
|
4503
4468
|
return this.array.every((e) => e.isZero());
|
|
@@ -4509,25 +4474,25 @@ var F = class {
|
|
|
4509
4474
|
return this.array.every((e) => e.isZero());
|
|
4510
4475
|
}
|
|
4511
4476
|
multiplyByScalar = (e) => {
|
|
4512
|
-
let t = new
|
|
4477
|
+
let t = new m(e);
|
|
4513
4478
|
return this.array.forEach((e) => e.multiply(t)), this;
|
|
4514
4479
|
};
|
|
4515
4480
|
get norm() {
|
|
4516
4481
|
return Math.sqrt(this.normSquare.value);
|
|
4517
4482
|
}
|
|
4518
4483
|
get normSquare() {
|
|
4519
|
-
return this.array.reduce((e, t) => e.add(t.clone().pow(2)), new
|
|
4484
|
+
return this.array.reduce((e, t) => e.add(t.clone().pow(2)), new m(0));
|
|
4520
4485
|
}
|
|
4521
4486
|
normal = () => {
|
|
4522
|
-
if (this.dimension >= 3) throw
|
|
4487
|
+
if (this.dimension >= 3) throw new n("Normal vector can only be determined in 2D");
|
|
4523
4488
|
let e = this.x.clone().opposite(), t = this.y.clone();
|
|
4524
4489
|
return this.array[0] = t, this.array[1] = e, this;
|
|
4525
4490
|
};
|
|
4526
4491
|
one = () => (this.zero(), this.x.one(), this);
|
|
4527
4492
|
opposite = () => (this.array.forEach((e) => e.opposite()), this);
|
|
4528
4493
|
simplify = () => {
|
|
4529
|
-
let e =
|
|
4530
|
-
return this.multiplyByScalar(new
|
|
4494
|
+
let e = p.lcm(...this.array.map((e) => e.denominator)), t = p.gcd(...this.array.map((e) => e.numerator));
|
|
4495
|
+
return this.multiplyByScalar(new m(e, t)), this.x.isNegative() && this.opposite(), this;
|
|
4531
4496
|
};
|
|
4532
4497
|
subtract = (e) => this.add(e.clone().opposite());
|
|
4533
4498
|
translate(...e) {
|
|
@@ -4537,43 +4502,43 @@ var F = class {
|
|
|
4537
4502
|
let e = this.norm;
|
|
4538
4503
|
return e === 0 ? this : this.divideByScalar(e);
|
|
4539
4504
|
};
|
|
4540
|
-
},
|
|
4505
|
+
}, U = /* @__PURE__ */ function(e) {
|
|
4541
4506
|
return e.None = "none", e.Parallel = "parallel", e.Perpendicular = "perpendicular", e.Tangent = "tangent", e;
|
|
4542
|
-
}({}),
|
|
4507
|
+
}({}), Ce = /* @__PURE__ */ function(e) {
|
|
4543
4508
|
return e.None = "none", e.Parallel = "parallel", e.Perpendicular = "perpendicular", e.Tangent = "tangent", e;
|
|
4544
4509
|
}({});
|
|
4545
4510
|
//#endregion
|
|
4546
4511
|
//#region src/randomization/rndHelpers.ts
|
|
4547
|
-
function
|
|
4512
|
+
function we(e = .5) {
|
|
4548
4513
|
return Math.random() < e;
|
|
4549
4514
|
}
|
|
4550
|
-
function
|
|
4551
|
-
if (t === void 0) return e >= 0 ?
|
|
4515
|
+
function W(e, t, n) {
|
|
4516
|
+
if (t === void 0) return e >= 0 ? W(0, e) : W(e, 0);
|
|
4552
4517
|
if (e === t) return e;
|
|
4553
4518
|
if (n === void 0) return Math.floor(Math.random() * (t - e + 1) + e);
|
|
4554
|
-
if (Math.abs(t - e) <= n.length) throw
|
|
4555
|
-
let r =
|
|
4556
|
-
for (; n.includes(r);) r =
|
|
4519
|
+
if (Math.abs(t - e) <= n.length) throw new i("The number of excluded values is too high.");
|
|
4520
|
+
let r = W(e, t);
|
|
4521
|
+
for (; n.includes(r);) r = W(e, t);
|
|
4557
4522
|
return r;
|
|
4558
4523
|
}
|
|
4559
|
-
function
|
|
4560
|
-
return t === !1 ?
|
|
4524
|
+
function G(e, t) {
|
|
4525
|
+
return t === !1 ? we() ? W(1, e) : -W(1, e) : W(-e, e);
|
|
4561
4526
|
}
|
|
4562
|
-
function
|
|
4563
|
-
let n =
|
|
4564
|
-
return n.length === 0 ? null :
|
|
4527
|
+
function Te(e, t) {
|
|
4528
|
+
let n = p.pythagoreanTripletsWithTarget(e).filter((e) => t === !0 || !e.includes(0));
|
|
4529
|
+
return n.length === 0 ? null : K(n);
|
|
4565
4530
|
}
|
|
4566
|
-
function
|
|
4567
|
-
let t =
|
|
4568
|
-
return e !== void 0 && (t = t.filter((t) => t < e)),
|
|
4531
|
+
function Ee(e) {
|
|
4532
|
+
let t = p.primes();
|
|
4533
|
+
return e !== void 0 && (t = t.filter((t) => t < e)), K(t);
|
|
4569
4534
|
}
|
|
4570
|
-
function
|
|
4571
|
-
return t === void 0 && (t = 1), e.length <= 0 ? Object.values(e) :
|
|
4535
|
+
function De(e, t) {
|
|
4536
|
+
return t === void 0 && (t = 1), e.length <= 0 ? Object.values(e) : Oe(e).slice(0, t);
|
|
4572
4537
|
}
|
|
4573
|
-
function
|
|
4574
|
-
return e.length === 0 ? null : e[
|
|
4538
|
+
function K(e) {
|
|
4539
|
+
return e.length === 0 ? null : e[W(0, e.length - 1)];
|
|
4575
4540
|
}
|
|
4576
|
-
function
|
|
4541
|
+
function Oe(e) {
|
|
4577
4542
|
let t = Object.values(e);
|
|
4578
4543
|
for (let e = t.length - 1; e > 0; e--) {
|
|
4579
4544
|
let n = Math.floor(Math.random() * (e + 1)), r = t[e];
|
|
@@ -4583,9 +4548,9 @@ function W(e) {
|
|
|
4583
4548
|
}
|
|
4584
4549
|
//#endregion
|
|
4585
4550
|
//#region src/geometry/line.ts
|
|
4586
|
-
var
|
|
4587
|
-
static PARALLEL =
|
|
4588
|
-
static PERPENDICULAR =
|
|
4551
|
+
var q = class e {
|
|
4552
|
+
static PARALLEL = U.Parallel;
|
|
4553
|
+
static PERPENDICULAR = U.Perpendicular;
|
|
4589
4554
|
#e;
|
|
4590
4555
|
#t;
|
|
4591
4556
|
#n;
|
|
@@ -4593,36 +4558,36 @@ var G = class e {
|
|
|
4593
4558
|
#i;
|
|
4594
4559
|
#a = 1;
|
|
4595
4560
|
constructor(...e) {
|
|
4596
|
-
return this.#t = new
|
|
4597
|
-
}
|
|
4598
|
-
parse = (...
|
|
4599
|
-
if (
|
|
4600
|
-
if (
|
|
4601
|
-
if (
|
|
4602
|
-
if (
|
|
4603
|
-
if (typeof
|
|
4604
|
-
let e = new
|
|
4561
|
+
return this.#t = new m().zero(), this.#n = new m().zero(), this.#r = new m().zero(), this.#e = new H(), this.#i = "lr", e.length > 0 && this.parse(...e), this;
|
|
4562
|
+
}
|
|
4563
|
+
parse = (...n) => {
|
|
4564
|
+
if (n.length === 0) return this;
|
|
4565
|
+
if (n.length === 1) {
|
|
4566
|
+
if (n[0] instanceof e) return this.fromCoefficient(n[0].a, n[0].b, n[0].c);
|
|
4567
|
+
if (n[0] instanceof N) return this.fromEquation(n[0]);
|
|
4568
|
+
if (typeof n[0] == "string") try {
|
|
4569
|
+
let e = new N(n[0]);
|
|
4605
4570
|
return this.parse(e);
|
|
4606
4571
|
} catch (e) {
|
|
4607
|
-
|
|
4572
|
+
throw new t(`Cannot parse "${n[0]}" as a Line`, { cause: e });
|
|
4608
4573
|
}
|
|
4609
4574
|
}
|
|
4610
|
-
if (
|
|
4611
|
-
if (
|
|
4612
|
-
if (
|
|
4575
|
+
if (n.length === 2) {
|
|
4576
|
+
if (n[0] instanceof V && n[1] instanceof V) return this.fromPoints(n[0], n[1]);
|
|
4577
|
+
if (n[0] instanceof V && n[1] instanceof H) return this.fromPointAndDirection(n[0], n[1]);
|
|
4613
4578
|
}
|
|
4614
|
-
return
|
|
4579
|
+
return n.length === 3 && n.every((e) => m.isFraction(e)) ? this.fromCoefficient(n[0], n[1], n[2]) : (console.warn("Something wrong happened while creating the line"), console.warn(n), this);
|
|
4615
4580
|
};
|
|
4616
4581
|
clone = () => new e().fromCoefficient(this.#t, this.#n, this.#r);
|
|
4617
4582
|
get tex() {
|
|
4618
4583
|
let e = this.#a;
|
|
4619
4584
|
switch (this.#a = 1, e) {
|
|
4620
4585
|
case 0: return this.getEquation().reorder().tex;
|
|
4621
|
-
case 2: return this.slope.isInfinity() ? "x=" + this.OA.x.tex : "y=" + new
|
|
4586
|
+
case 2: return this.slope.isInfinity() ? "x=" + this.OA.x.tex : "y=" + new M().parse("x", this.slope, this.height).tex;
|
|
4622
4587
|
case 3:
|
|
4623
4588
|
case 4: {
|
|
4624
4589
|
let t = this.d.clone().simplify();
|
|
4625
|
-
return e === 3 ? `${
|
|
4590
|
+
return e === 3 ? `${H.asTex("x", "y")} = ${H.asTex(this.#e.x.tex, this.#e.y.tex)} + k\\cdot ${H.asTex(t.x.tex, t.y.tex)}` : `\\left\\{\\begin{aligned}\n\tx &= ${new M(this.#e.x).add(new A(t.x).multiply(new A("k"))).reorder("k", !0).tex}\\\\\n\ty &= ${new M(this.#e.y).add(new A(t.y).multiply(new A("k"))).reorder("k", !0).tex}\n\\end{aligned}\\right.`;
|
|
4626
4591
|
}
|
|
4627
4592
|
default: {
|
|
4628
4593
|
let e = this.getEquation();
|
|
@@ -4634,13 +4599,13 @@ var G = class e {
|
|
|
4634
4599
|
let e = this.#a;
|
|
4635
4600
|
switch (this.#a = 1, e) {
|
|
4636
4601
|
case 0: return this.getEquation().reorder().display;
|
|
4637
|
-
case 2: return this.slope.isInfinity() ? "x=" + this.OA.x.display : "y=" + new
|
|
4602
|
+
case 2: return this.slope.isInfinity() ? "x=" + this.OA.x.display : "y=" + new M().parse("x", this.slope, this.height).display;
|
|
4638
4603
|
case 3: {
|
|
4639
4604
|
let e = this.d.clone().simplify();
|
|
4640
4605
|
return `((x,y))=((${this.#e.x.display},${this.#e.y.display}))+k((${e.x.display},${e.y.display}))`;
|
|
4641
4606
|
}
|
|
4642
4607
|
case 4: {
|
|
4643
|
-
let e = this.d.clone().simplify(), t = new
|
|
4608
|
+
let e = this.d.clone().simplify(), t = new M(this.#e.x).add(new A(e.x).multiply(new A("k"))).reorder("k", !0), n = new M(this.#e.y).add(new A(e.y).multiply(new A("k"))).reorder("k", !0);
|
|
4644
4609
|
return `{(x,=,${t.display}),(y,=,${n.display}):}`;
|
|
4645
4610
|
}
|
|
4646
4611
|
default: {
|
|
@@ -4693,7 +4658,7 @@ var G = class e {
|
|
|
4693
4658
|
return this.#t.isZero() || (t = this.#t.isOne() ? "x" : this.#t.clone().opposite().isOne() ? "-x" : this.#t.value.toFixed(e) + "x"), this.#n.isZero() || (this.#n.isPositive() && (t += "+"), t += this.#n.value.toFixed(e) + "y"), this.#r.isZero() || (this.#r.isPositive() && (t += "+"), t += this.#r.value.toFixed(e)), t + "=0";
|
|
4694
4659
|
}
|
|
4695
4660
|
get d() {
|
|
4696
|
-
let e = new
|
|
4661
|
+
let e = new H(this.#n.clone(), this.#t.clone().opposite());
|
|
4697
4662
|
return (this.#i === "lr" && e.x.isNegative() || this.#i === "rl" && e.x.isPositive()) && e.opposite(), e;
|
|
4698
4663
|
}
|
|
4699
4664
|
set d(e) {
|
|
@@ -4707,19 +4672,19 @@ var G = class e {
|
|
|
4707
4672
|
return n.isZero() ? new v(0) : new v().from(2, n.inverse(), t).reduce();
|
|
4708
4673
|
}
|
|
4709
4674
|
fromCoefficient(e, t, n) {
|
|
4710
|
-
this.#t = new
|
|
4675
|
+
this.#t = new m(e), this.#n = new m(t), this.#r = new m(n);
|
|
4711
4676
|
let r = [
|
|
4712
4677
|
this.#t,
|
|
4713
4678
|
this.#n,
|
|
4714
4679
|
this.#r
|
|
4715
|
-
].every((e) => e.exact) ?
|
|
4716
|
-
if (r > 1 && (this.#t.multiply(r).reduce(), this.#n.multiply(r).reduce(), this.#r.multiply(r).reduce()), this.#n.isZero()) return this.#e = new
|
|
4680
|
+
].every((e) => e.exact) ? p.lcm(this.#t.denominator, this.#n.denominator, this.#r.denominator) : 1;
|
|
4681
|
+
if (r > 1 && (this.#t.multiply(r).reduce(), this.#n.multiply(r).reduce(), this.#r.multiply(r).reduce()), this.#n.isZero()) return this.#e = new H(this.#r.clone().divide(this.#t).opposite(), 0), this;
|
|
4717
4682
|
for (let e = 0; e < this.#n.value; e++) {
|
|
4718
4683
|
let t = this.#t.clone().divide(this.#n).multiply(e).subtract(this.#r.clone().divide(this.#n)).reduce();
|
|
4719
|
-
if (this.#e = new
|
|
4684
|
+
if (this.#e = new H(e, t), t.isRelative()) return this;
|
|
4720
4685
|
}
|
|
4721
4686
|
let i = this.#r.clone().divide(this.#n).opposite().reduce();
|
|
4722
|
-
return this.#e = new
|
|
4687
|
+
return this.#e = new H(0, i), this;
|
|
4723
4688
|
}
|
|
4724
4689
|
fromEquation(e) {
|
|
4725
4690
|
e.reorder(!0);
|
|
@@ -4737,23 +4702,23 @@ var G = class e {
|
|
|
4737
4702
|
fromPointAndDirection(e, t) {
|
|
4738
4703
|
return this.#i = t.x.isPositive() ? "lr" : "rl", this.fromPointAndNormal(e, t.clone().normal());
|
|
4739
4704
|
}
|
|
4740
|
-
fromPointAndLine(e, t, n =
|
|
4741
|
-
return n ===
|
|
4705
|
+
fromPointAndLine(e, t, n = U.Parallel) {
|
|
4706
|
+
return n === U.Perpendicular ? this.fromPointAndNormal(e, t.director) : this.fromPointAndNormal(e, t.normal);
|
|
4742
4707
|
}
|
|
4743
|
-
fromPointAndNormal = (e, t) => t.isZero() ? (console.warn("Normal vector is null."), this) : (this.fromCoefficient(t.x, t.y, e.x.clone().multiply(t.x).add(e.y.clone().multiply(t.y)).opposite()), this.#e = new
|
|
4708
|
+
fromPointAndNormal = (e, t) => t.isZero() ? (console.warn("Normal vector is null."), this) : (this.fromCoefficient(t.x, t.y, e.x.clone().multiply(t.x).add(e.y.clone().multiply(t.y)).opposite()), this.#e = new H(e.clone()), this);
|
|
4744
4709
|
fromPoints(e, t) {
|
|
4745
|
-
return this.fromPointAndNormal(e, new
|
|
4710
|
+
return this.fromPointAndNormal(e, new H(e, t).normal());
|
|
4746
4711
|
}
|
|
4747
4712
|
getEquation() {
|
|
4748
|
-
return new
|
|
4713
|
+
return new N(new M().parse("xy", this.#t, this.#n, this.#r), new M("0")).simplify();
|
|
4749
4714
|
}
|
|
4750
4715
|
getValueAtX = (e) => {
|
|
4751
|
-
let t = this.getEquation().isolate("y"), n = new
|
|
4752
|
-
return t instanceof
|
|
4716
|
+
let t = this.getEquation().isolate("y"), n = new m(e);
|
|
4717
|
+
return t instanceof N ? t.right.evaluate({ x: n }) : new m().invalid();
|
|
4753
4718
|
};
|
|
4754
4719
|
getValueAtY = (e) => {
|
|
4755
|
-
let t = this.getEquation().isolate("x"), n = new
|
|
4756
|
-
return t instanceof
|
|
4720
|
+
let t = this.getEquation().isolate("x"), n = new m(e);
|
|
4721
|
+
return t instanceof N ? t.right.evaluate({ y: n }) : new m().invalid();
|
|
4757
4722
|
};
|
|
4758
4723
|
get height() {
|
|
4759
4724
|
return this.#r.clone().opposite().divide(this.#n);
|
|
@@ -4763,8 +4728,8 @@ var G = class e {
|
|
|
4763
4728
|
return r.hasIntersection ? r.point.x.value >= Math.min(t.x.value, n.x.value) && r.point.x.value <= Math.max(t.x.value, n.x.value) && r.point.y.value >= Math.min(t.y.value, n.y.value) && r.point.y.value <= Math.max(t.y.value, n.y.value) : !1;
|
|
4764
4729
|
}
|
|
4765
4730
|
intersection = (e) => {
|
|
4766
|
-
let t = new
|
|
4767
|
-
return this.#n.isZero() || e.b.isZero(), this.isParallelTo(e) ? (t.x = new
|
|
4731
|
+
let t = new V(), n = !1, r = !1;
|
|
4732
|
+
return this.#n.isZero() || e.b.isZero(), this.isParallelTo(e) ? (t.x = new m().invalid(), t.y = new m().invalid(), n = !0) : this.isSameAs(e) ? (t.x = new m().invalid(), t.y = new m().invalid(), r = !0) : (t.x = this.#n.clone().multiply(e.c).subtract(this.#r.clone().multiply(e.b)).divide(this.#t.clone().multiply(e.b).subtract(this.#n.clone().multiply(e.a))), t.y = this.#t.clone().multiply(e.c).subtract(this.#r.clone().multiply(e.a)).divide(this.#n.clone().multiply(e.a).subtract(this.#t.clone().multiply(e.b)))), {
|
|
4768
4733
|
point: t,
|
|
4769
4734
|
hasIntersection: !(n || r),
|
|
4770
4735
|
isParallel: n,
|
|
@@ -4785,25 +4750,25 @@ var G = class e {
|
|
|
4785
4750
|
return this.d.normal();
|
|
4786
4751
|
}
|
|
4787
4752
|
get normal() {
|
|
4788
|
-
return new
|
|
4753
|
+
return new H(this.#t, this.#n);
|
|
4789
4754
|
}
|
|
4790
4755
|
randomNearPoint = (e) => {
|
|
4791
4756
|
let t = this.randomPoint(e), n = 10;
|
|
4792
|
-
for (; this.isOnLine(t) && n > 0;) t.x.add(
|
|
4757
|
+
for (; this.isOnLine(t) && n > 0;) t.x.add(G(1, !1)), t.y.add(G(1, !1)), n--;
|
|
4793
4758
|
return t;
|
|
4794
4759
|
};
|
|
4795
|
-
randomPoint = (e) => new
|
|
4760
|
+
randomPoint = (e) => new V(this.d.clone().multiplyByScalar(G(e === void 0 || e <= 1 ? 3 : e, !1)).add(this.#e));
|
|
4796
4761
|
simplify = () => {
|
|
4797
|
-
let e =
|
|
4762
|
+
let e = p.lcm(this.#t.denominator, this.#n.denominator, this.#r.denominator), t = p.gcd(this.#t.numerator, this.#n.numerator, this.#r.numerator);
|
|
4798
4763
|
return this.fromCoefficient(this.#t.clone().multiply(e).divide(t), this.#n.clone().multiply(e).divide(t), this.#r.clone().multiply(e).divide(t)), this;
|
|
4799
4764
|
};
|
|
4800
4765
|
get slope() {
|
|
4801
4766
|
return this.#t.clone().opposite().divide(this.#n);
|
|
4802
4767
|
}
|
|
4803
|
-
},
|
|
4804
|
-
#e = new
|
|
4805
|
-
#t = new
|
|
4806
|
-
#n = new
|
|
4768
|
+
}, J = class e {
|
|
4769
|
+
#e = new V();
|
|
4770
|
+
#t = new V();
|
|
4771
|
+
#n = new V();
|
|
4807
4772
|
#r = !1;
|
|
4808
4773
|
#i = null;
|
|
4809
4774
|
#a = !0;
|
|
@@ -4824,12 +4789,12 @@ var G = class e {
|
|
|
4824
4789
|
let [e, n, r] = t;
|
|
4825
4790
|
return this.fromLines(e, n, r);
|
|
4826
4791
|
}
|
|
4827
|
-
if (t.every((e) => e instanceof
|
|
4828
|
-
if (t.every((e) => e instanceof
|
|
4792
|
+
if (t.every((e) => e instanceof q)) return this.fromLines(t[0], t[1], t[2]);
|
|
4793
|
+
if (t.every((e) => e instanceof V)) return this.fromPoints(t[0], t[1], t[2]);
|
|
4829
4794
|
}
|
|
4830
4795
|
if (t.length === 6) {
|
|
4831
|
-
let e = t.map((e) => new
|
|
4832
|
-
if (e.some((e) => e.isNaN())) throw
|
|
4796
|
+
let e = t.map((e) => new m(e));
|
|
4797
|
+
if (e.some((e) => e.isNaN())) throw new i("One of the values is not a valid number");
|
|
4833
4798
|
return this.fromCoordinates(e[0], e[1], e[2], e[3], e[4], e[5]);
|
|
4834
4799
|
}
|
|
4835
4800
|
return this;
|
|
@@ -4881,10 +4846,10 @@ var G = class e {
|
|
|
4881
4846
|
return this.#a = !0, this;
|
|
4882
4847
|
}
|
|
4883
4848
|
fromCoordinates(e, t, n, r, i, a) {
|
|
4884
|
-
return this.fromPoints(new
|
|
4849
|
+
return this.fromPoints(new V(e, t), new V(n, r), new V(i, a));
|
|
4885
4850
|
}
|
|
4886
4851
|
fromLines(e, t, n) {
|
|
4887
|
-
let r = new
|
|
4852
|
+
let r = new q(e).clone(), i = new q(t).clone(), a = new q(n).clone(), o = r.intersection(i);
|
|
4888
4853
|
if (o.hasIntersection) this.#t = o.point;
|
|
4889
4854
|
else return this.#r = !1, this;
|
|
4890
4855
|
if (o = i.intersection(a), o.hasIntersection) this.#n = o.point;
|
|
@@ -4927,7 +4892,7 @@ var G = class e {
|
|
|
4927
4892
|
}
|
|
4928
4893
|
getHeights() {
|
|
4929
4894
|
if (!this.#o.heights) {
|
|
4930
|
-
let e = new
|
|
4895
|
+
let e = new q().fromPointAndNormal(this.#e, new H(this.#t, this.#n)), t = new q().fromPointAndNormal(this.#t, new H(this.#e, this.#n)), n = new q().fromPointAndNormal(this.#n, new H(this.#e, this.#t)), r = e.intersection(t).point;
|
|
4931
4896
|
this.#o.heights = {
|
|
4932
4897
|
A: e,
|
|
4933
4898
|
B: t,
|
|
@@ -4940,7 +4905,7 @@ var G = class e {
|
|
|
4940
4905
|
getMedians() {
|
|
4941
4906
|
let e = this.getMiddles();
|
|
4942
4907
|
if (!this.#o.medians) {
|
|
4943
|
-
let t = new
|
|
4908
|
+
let t = new q().fromPoints(this.#e, e.BC), n = new q().fromPoints(this.#t, e.AC), r = new q().fromPoints(this.#n, e.AB), i = t.intersection(n).point;
|
|
4944
4909
|
this.#o.medians = {
|
|
4945
4910
|
A: t,
|
|
4946
4911
|
B: n,
|
|
@@ -4953,7 +4918,7 @@ var G = class e {
|
|
|
4953
4918
|
getMediators() {
|
|
4954
4919
|
let e = this.getMiddles();
|
|
4955
4920
|
if (!this.#o.mediators) {
|
|
4956
|
-
let t = new
|
|
4921
|
+
let t = new q().fromPointAndNormal(e.BC, new H(this.#t, this.#n)), n = new q().fromPointAndNormal(e.AC, new H(this.#e, this.#n)), r = new q().fromPointAndNormal(e.AB, new H(this.#e, this.#t)), i = t.intersection(n).point;
|
|
4957
4922
|
this.#o.mediators = {
|
|
4958
4923
|
a: t,
|
|
4959
4924
|
b: n,
|
|
@@ -4965,9 +4930,9 @@ var G = class e {
|
|
|
4965
4930
|
}
|
|
4966
4931
|
getMiddles() {
|
|
4967
4932
|
return {
|
|
4968
|
-
AB: new
|
|
4969
|
-
AC: new
|
|
4970
|
-
BC: new
|
|
4933
|
+
AB: new V().middleOf(this.#e, this.#t),
|
|
4934
|
+
AC: new V().middleOf(this.#e, this.#n),
|
|
4935
|
+
BC: new V().middleOf(this.#t, this.#n)
|
|
4971
4936
|
};
|
|
4972
4937
|
}
|
|
4973
4938
|
getPoints() {
|
|
@@ -5006,9 +4971,9 @@ var G = class e {
|
|
|
5006
4971
|
}
|
|
5007
4972
|
get lines() {
|
|
5008
4973
|
return this.#i === null && (this.#i = {
|
|
5009
|
-
AB: new
|
|
5010
|
-
BC: new
|
|
5011
|
-
AC: new
|
|
4974
|
+
AB: new q(this.#e, this.#t),
|
|
4975
|
+
BC: new q(this.#t, this.#n),
|
|
4976
|
+
AC: new q(this.#e, this.#n)
|
|
5012
4977
|
}), this.#i;
|
|
5013
4978
|
}
|
|
5014
4979
|
medianA() {
|
|
@@ -5033,14 +4998,14 @@ var G = class e {
|
|
|
5033
4998
|
}, this;
|
|
5034
4999
|
}
|
|
5035
5000
|
#s(e, t = !0) {
|
|
5036
|
-
let n = this.lines, r = new
|
|
5037
|
-
if (e === "A" ? (a = this.A.clone(), r = n.AB.clone().d, i = n.AC.clone().d) : e === "B" ? (a = this.B.clone(), r = n.AB.clone().d.opposite(), i = n.BC.clone().d) : e === "C" && (a = this.C.clone(), r = n.BC.clone().d.opposite(), i = n.AC.clone().d.opposite()), r === void 0 || i === void 0) throw
|
|
5038
|
-
let
|
|
5039
|
-
return new
|
|
5001
|
+
let n = this.lines, r = new H(), i = new H(), a = new V();
|
|
5002
|
+
if (e === "A" ? (a = this.A.clone(), r = n.AB.clone().d, i = n.AC.clone().d) : e === "B" ? (a = this.B.clone(), r = n.AB.clone().d.opposite(), i = n.BC.clone().d) : e === "C" && (a = this.C.clone(), r = n.BC.clone().d.opposite(), i = n.AC.clone().d.opposite()), r === void 0 || i === void 0) throw new o(`The point ${e} does not exist`);
|
|
5003
|
+
let s = t ? r.unit().add(i.unit()) : r.unit().subtract(i.unit());
|
|
5004
|
+
return new q().fromPointAndDirection(a, s);
|
|
5040
5005
|
}
|
|
5041
5006
|
#c(e, t, n) {
|
|
5042
5007
|
let r = (t ** 2 + n ** 2 - e ** 2) / (2 * t * n);
|
|
5043
|
-
return this.#a ? Math.acos(r) :
|
|
5008
|
+
return this.#a ? Math.acos(r) : p.numberCorrection(Math.acos(r) * 180 / Math.PI);
|
|
5044
5009
|
}
|
|
5045
5010
|
#l = (e) => {
|
|
5046
5011
|
switch (e.toUpperCase()) {
|
|
@@ -5050,8 +5015,8 @@ var G = class e {
|
|
|
5050
5015
|
}
|
|
5051
5016
|
return this.#e;
|
|
5052
5017
|
};
|
|
5053
|
-
#u = (e, t) => new
|
|
5054
|
-
},
|
|
5018
|
+
#u = (e, t) => new H(this.#l(e), this.#l(t));
|
|
5019
|
+
}, Y = class e {
|
|
5055
5020
|
#e = null;
|
|
5056
5021
|
#t = null;
|
|
5057
5022
|
#n = 1;
|
|
@@ -5060,7 +5025,7 @@ var G = class e {
|
|
|
5060
5025
|
e.length > 0 && this.parse(...e);
|
|
5061
5026
|
}
|
|
5062
5027
|
parse(...t) {
|
|
5063
|
-
return typeof t[0] == "string" ? this.fromString(t[0]) : t[0] instanceof
|
|
5028
|
+
return typeof t[0] == "string" ? this.fromString(t[0]) : t[0] instanceof N ? this.fromEquation(t[0]) : t[0] instanceof e ? this.copy(t[0]) : t.length === 2 && t[0] instanceof V && t[1] instanceof V ? this.fromCenterPoint(t[0], t[1]) : t.length >= 2 && t[0] instanceof V && (t[1] instanceof m || typeof t[1] == "number") ? this.fromCenterRadius(t[0], t[1], typeof t[2] == "boolean" && t[2]) : this;
|
|
5064
5029
|
}
|
|
5065
5030
|
clone() {
|
|
5066
5031
|
return new e().fromCenterRadius(this.center.clone(), this.squareRadius.clone(), !0);
|
|
@@ -5085,36 +5050,36 @@ var G = class e {
|
|
|
5085
5050
|
return this.#n = 1, this;
|
|
5086
5051
|
}
|
|
5087
5052
|
get center() {
|
|
5088
|
-
return this.#e ?? new
|
|
5053
|
+
return this.#e ?? new V();
|
|
5089
5054
|
}
|
|
5090
5055
|
get equation() {
|
|
5091
|
-
return this.#t?.clone() ?? new
|
|
5056
|
+
return this.#t?.clone() ?? new N("0=0");
|
|
5092
5057
|
}
|
|
5093
5058
|
fromCenterPoint(e, t) {
|
|
5094
|
-
return this.#e = e.clone(), this.#r = new
|
|
5059
|
+
return this.#e = e.clone(), this.#r = new H(this.#e, t).normSquare, this.#i(), this;
|
|
5095
5060
|
}
|
|
5096
5061
|
fromCenterRadius(e, t, n) {
|
|
5097
|
-
return this.#e = e.clone(), this.#r = n ? new
|
|
5062
|
+
return this.#e = e.clone(), this.#r = n ? new m(t) : new m(t).pow(2), this.#i(), this;
|
|
5098
5063
|
}
|
|
5099
5064
|
fromEquation(e) {
|
|
5100
5065
|
if (e.moveLeft(), e.degree("x").value === 2 && e.degree("y").value === 2) {
|
|
5101
5066
|
let t = e.left.monomByDegree(2, "x"), n = e.left.monomByDegree(2, "y"), r, i, a;
|
|
5102
|
-
if (t.coefficient.isEqual(n.coefficient)) return e.divide(t.coefficient), r = e.left.monomByDegree(1, "x"), i = e.left.monomByDegree(1, "y"), a = e.left.monomByDegree(0), this.#e = new
|
|
5067
|
+
if (t.coefficient.isEqual(n.coefficient)) return e.divide(t.coefficient), r = e.left.monomByDegree(1, "x"), i = e.left.monomByDegree(1, "y"), a = e.left.monomByDegree(0), this.#e = new V(r.coefficient.clone().divide(2).opposite(), i.coefficient.clone().divide(2).opposite()), this.#r = a.coefficient.clone().opposite().add(this.#e.x.clone().pow(2)).add(this.#e.y.clone().pow(2)), this.#i(), this;
|
|
5103
5068
|
this.#a();
|
|
5104
5069
|
}
|
|
5105
5070
|
return this;
|
|
5106
5071
|
}
|
|
5107
5072
|
fromPoints(e, t, n) {
|
|
5108
|
-
let r = new
|
|
5073
|
+
let r = new J(e, t, n);
|
|
5109
5074
|
if (!r.isValid || !r.remarquables) return this.#a(), this;
|
|
5110
5075
|
let i = r.getMediators().c.clone(), a = r.getMediators().b.clone();
|
|
5111
5076
|
return this.fromCenterPoint(i.intersection(a).point, e);
|
|
5112
5077
|
}
|
|
5113
5078
|
fromString(e) {
|
|
5114
|
-
return this.fromEquation(new
|
|
5079
|
+
return this.fromEquation(new N(e));
|
|
5115
5080
|
}
|
|
5116
5081
|
getPointsOnCircle() {
|
|
5117
|
-
let e =
|
|
5082
|
+
let e = p.pythagoreanTripletsWithTarget(this.squareRadius.value, !0), t = [];
|
|
5118
5083
|
return e.forEach((e) => {
|
|
5119
5084
|
for (let n of [
|
|
5120
5085
|
[1, 1],
|
|
@@ -5123,7 +5088,7 @@ var G = class e {
|
|
|
5123
5088
|
[1, -1]
|
|
5124
5089
|
]) {
|
|
5125
5090
|
let r = this.center.x.clone().add(n[0] * e[0]), i = this.center.y.clone().add(n[1] * e[1]);
|
|
5126
|
-
t.every((e) => !e.isEqualXY(r, i)) && t.push(new
|
|
5091
|
+
t.every((e) => !e.isEqualXY(r, i)) && t.push(new V(r, i));
|
|
5127
5092
|
}
|
|
5128
5093
|
}), t;
|
|
5129
5094
|
}
|
|
@@ -5140,10 +5105,10 @@ var G = class e {
|
|
|
5140
5105
|
if (s.length === 0) return [];
|
|
5141
5106
|
if (s.length === 1) {
|
|
5142
5107
|
let e = r.add(n.clone().multiplyByScalar(s[0].fraction));
|
|
5143
|
-
return [new
|
|
5108
|
+
return [new V(e.x, e.y)];
|
|
5144
5109
|
}
|
|
5145
5110
|
let c = s[0].exact ? r.clone().add(n.clone().multiplyByScalar(s[0].fraction)) : r.clone().add(n.clone().multiplyByScalar(s[0].value)), l = s[1].exact ? r.clone().add(n.clone().multiplyByScalar(s[1].fraction)) : r.clone().add(n.clone().multiplyByScalar(s[1].value));
|
|
5146
|
-
return [new
|
|
5111
|
+
return [new V(c.x, c.y), new V(l.x, l.y)].sort((e, t) => n.x.isZero() ? n.y.isPositive() ? e.y.value - t.y.value : t.y.value - e.y.value : n.x.isPositive() ? e.x.value - t.x.value : t.x.value - e.x.value);
|
|
5147
5112
|
}
|
|
5148
5113
|
get radius() {
|
|
5149
5114
|
return new v().from(2, this.#r ?? 0);
|
|
@@ -5154,57 +5119,57 @@ var G = class e {
|
|
|
5154
5119
|
return t - n > 1e-10 ? 0 : Math.abs(t - n) < 1e-10 ? 1 : 2;
|
|
5155
5120
|
}
|
|
5156
5121
|
setRadius(e, t) {
|
|
5157
|
-
return this.#r = t ? new
|
|
5122
|
+
return this.#r = t ? new m(e) : new m(e).pow(2), this.#i(), this;
|
|
5158
5123
|
}
|
|
5159
5124
|
get squareRadius() {
|
|
5160
|
-
return this.#r?.clone() ?? new
|
|
5125
|
+
return this.#r?.clone() ?? new m(-1);
|
|
5161
5126
|
}
|
|
5162
|
-
tangents = (e) => e instanceof
|
|
5127
|
+
tangents = (e) => e instanceof m ? this.#c(e) : this.isPointOnCircle(e) ? this.#o(e) : this.#e !== null && this.#e.distanceTo(e).value > this.radius.value ? this.#s(e) : [];
|
|
5163
5128
|
#i() {
|
|
5164
|
-
this.#t = new
|
|
5129
|
+
this.#t = new N(new M(`(x-(${this.center.x.display}))^2+(y-(${this.center.y.display}))^2`), new M(this.squareRadius.display)).moveLeft();
|
|
5165
5130
|
}
|
|
5166
5131
|
#a() {
|
|
5167
5132
|
this.#e = null, this.#r = null, this.#t = null;
|
|
5168
5133
|
}
|
|
5169
5134
|
#o = (e) => {
|
|
5170
|
-
let t = new
|
|
5171
|
-
return [new
|
|
5135
|
+
let t = new H(this.center, e);
|
|
5136
|
+
return [new q().fromPointAndNormal(e, t)];
|
|
5172
5137
|
};
|
|
5173
5138
|
#s = (e) => {
|
|
5174
|
-
let t = this.center.x.clone().subtract(e.x), n = this.center.y.clone().subtract(e.y), r = new
|
|
5175
|
-
return r.multiply(t).subtract(n).pow(2), i.multiply(this.squareRadius), new
|
|
5176
|
-
let n, r = new
|
|
5177
|
-
return t.exact ? (n = e.x.clone().opposite().multiply(t.fraction).add(e.y), r.right.multiply(t.fraction).add(n)) : (n = e.x.clone().opposite().multiply(t.value).add(e.y), r.right.multiply(t.value).add(n)), new
|
|
5139
|
+
let t = this.center.x.clone().subtract(e.x), n = this.center.y.clone().subtract(e.y), r = new M("x"), i = new M("x^2+1");
|
|
5140
|
+
return r.multiply(t).subtract(n).pow(2), i.multiply(this.squareRadius), new N(r, i).solve().map((t) => {
|
|
5141
|
+
let n, r = new N("y", "x");
|
|
5142
|
+
return t.exact ? (n = e.x.clone().opposite().multiply(t.fraction).add(e.y), r.right.multiply(t.fraction).add(n)) : (n = e.x.clone().opposite().multiply(t.value).add(e.y), r.right.multiply(t.value).add(n)), new q(r);
|
|
5178
5143
|
});
|
|
5179
5144
|
};
|
|
5180
5145
|
#c = (e) => {
|
|
5181
5146
|
let t = e.numerator, n = -e.denominator, r = this.center.x.clone(), i = this.center.y.clone(), a = this.squareRadius.clone().multiply(e.numerator ** 2 + e.denominator ** 2), o = r.clone().multiply(t).opposite().subtract(i.clone().multiply(n)).add(a.clone().sqrt()), s = r.clone().multiply(t).opposite().subtract(i.clone().multiply(n)).subtract(a.clone().sqrt());
|
|
5182
|
-
return [new
|
|
5147
|
+
return [new q(t, n, o), new q(t, n, s)];
|
|
5183
5148
|
};
|
|
5184
|
-
},
|
|
5185
|
-
static PARALLEL =
|
|
5186
|
-
static PERPENDICULAR =
|
|
5187
|
-
#e = new
|
|
5188
|
-
#t = new
|
|
5149
|
+
}, X = class e {
|
|
5150
|
+
static PARALLEL = Ce.Parallel;
|
|
5151
|
+
static PERPENDICULAR = Ce.Perpendicular;
|
|
5152
|
+
#e = new V();
|
|
5153
|
+
#t = new H();
|
|
5189
5154
|
constructor(e, t) {
|
|
5190
|
-
return this.#e = e.clone(), this.#t = t instanceof
|
|
5155
|
+
return this.#e = e.clone(), this.#t = t instanceof V ? new H(e, t) : t.clone(), this;
|
|
5191
5156
|
}
|
|
5192
5157
|
clone = () => (this.#t = this.#t.clone(), this.#e = this.#e.clone(), this);
|
|
5193
5158
|
get tex() {
|
|
5194
5159
|
return {
|
|
5195
|
-
parametric: `${
|
|
5160
|
+
parametric: `${H.asTex("x", "y", "z")} = ${H.asTex(this.#e.x.tex, this.#e.y.tex, this.#e.z.tex)} + k\\cdot ${H.asTex(this.#t.x.tex, this.#t.y.tex, this.#t.z.tex)}`,
|
|
5196
5161
|
system: `\\left\\{\\begin{aligned}
|
|
5197
|
-
x &= ${new
|
|
5198
|
-
y &= ${new
|
|
5199
|
-
z &= ${new
|
|
5162
|
+
x &= ${new M(this.#e.x).add(new A(this.#t.x).multiply(new A("k"))).reorder("k", !0).tex}\\\\
|
|
5163
|
+
y &= ${new M(this.#e.y).add(new A(this.#t.y).multiply(new A("k"))).reorder("k", !0).tex}\\\\
|
|
5164
|
+
z &= ${new M(this.#e.z).add(new A(this.#t.z).multiply(new A("k"))).reorder("k", !0).tex}
|
|
5200
5165
|
\\end{aligned}\\right.`,
|
|
5201
|
-
cartesian: `\\frac{ ${new
|
|
5166
|
+
cartesian: `\\frac{ ${new M("x", 1, this.#e.x.clone().opposite()).tex} }{ ${this.direction.x.tex} } = \\frac{ ${new M("y", 1, this.#e.y.clone().opposite()).tex} }{ ${this.direction.y.tex} } = \\frac{ ${new M("z", 1, this.#e.z.clone().opposite()).tex} }{ ${this.direction.z.tex} }`
|
|
5202
5167
|
};
|
|
5203
5168
|
}
|
|
5204
5169
|
get display() {
|
|
5205
5170
|
let e = this.#e.x.display, t = this.#e.y.display, n = this.#e.z.display, r = this.direction.simplify(), i = r.x.display, a = r.y.display, o = r.z.display;
|
|
5206
5171
|
return {
|
|
5207
|
-
parametric: `${
|
|
5172
|
+
parametric: `${H.asDisplay("x", "y", "z")} = ${H.asDisplay(this.#e.x.display, this.#e.y.display, this.#e.z.display)} + k\\cdot ${H.asDisplay(this.#t.x.display, this.#t.y.display, this.#t.z.display)}`,
|
|
5208
5173
|
system: "",
|
|
5209
5174
|
cartesian: `(x-${e})/${i} = (y-${t})/${a} = (z-${n})/${o}`
|
|
5210
5175
|
};
|
|
@@ -5225,7 +5190,7 @@ var G = class e {
|
|
|
5225
5190
|
return this.#t.clone();
|
|
5226
5191
|
}
|
|
5227
5192
|
distanceTo(e) {
|
|
5228
|
-
let t = new
|
|
5193
|
+
let t = new H(this.#e, e), n = this.direction, r = this.direction.normSquare, i = t.cross(n).normSquare.clone().divide(r), a = i.clone().sqrt();
|
|
5229
5194
|
return {
|
|
5230
5195
|
value: Math.sqrt(i.value),
|
|
5231
5196
|
fraction: i.clone().sqrt(),
|
|
@@ -5237,34 +5202,34 @@ var G = class e {
|
|
|
5237
5202
|
return r.hasIntersection ? r.point.x.value >= Math.min(t.x.value, n.x.value) && r.point.x.value <= Math.max(t.x.value, n.x.value) && r.point.y.value >= Math.min(t.y.value, n.y.value) && r.point.y.value <= Math.max(t.y.value, n.y.value) && r.point.z.value >= Math.min(t.z.value, n.z.value) && r.point.z.value <= Math.max(t.z.value, n.z.value) : !1;
|
|
5238
5203
|
}
|
|
5239
5204
|
intersection = (e) => {
|
|
5240
|
-
throw
|
|
5205
|
+
throw new a("Method not implemented.");
|
|
5241
5206
|
};
|
|
5242
5207
|
isOnLine = (e) => !1;
|
|
5243
5208
|
isParallelTo = (e) => {
|
|
5244
|
-
throw
|
|
5209
|
+
throw new a("Method not implemented.");
|
|
5245
5210
|
};
|
|
5246
5211
|
isPerpendicularTo = (e) => {
|
|
5247
|
-
throw
|
|
5212
|
+
throw new a("Method not implemented.");
|
|
5248
5213
|
};
|
|
5249
5214
|
isSameAs = (e) => {
|
|
5250
|
-
throw
|
|
5215
|
+
throw new a("Method not implemented.");
|
|
5251
5216
|
};
|
|
5252
5217
|
isVertical = () => {
|
|
5253
|
-
throw
|
|
5218
|
+
throw new a("Method not implemented.");
|
|
5254
5219
|
};
|
|
5255
5220
|
get point() {
|
|
5256
5221
|
return this.#e.clone();
|
|
5257
5222
|
}
|
|
5258
5223
|
randomPoint = (e = 5) => {
|
|
5259
|
-
let t = this.#e.clone(), n = new
|
|
5260
|
-
return new
|
|
5224
|
+
let t = this.#e.clone(), n = new m(G(e, !1));
|
|
5225
|
+
return new V(t.x.clone().add(this.#t.x.clone().multiply(n)), t.y.clone().add(this.#t.y.clone().multiply(n)), t.z.clone().add(this.#t.z.clone().multiply(n)));
|
|
5261
5226
|
};
|
|
5262
5227
|
simplify = () => {
|
|
5263
|
-
throw
|
|
5228
|
+
throw new a("Method not implemented.");
|
|
5264
5229
|
};
|
|
5265
|
-
},
|
|
5266
|
-
#e = new
|
|
5267
|
-
#t = new
|
|
5230
|
+
}, ke = class e {
|
|
5231
|
+
#e = new H(0, 0, 1);
|
|
5232
|
+
#t = new V(0, 0, 0);
|
|
5268
5233
|
constructor(e) {
|
|
5269
5234
|
return e && this.parse(e), this;
|
|
5270
5235
|
}
|
|
@@ -5281,37 +5246,37 @@ var G = class e {
|
|
|
5281
5246
|
}
|
|
5282
5247
|
if (e.equation) {
|
|
5283
5248
|
let t = e.equation.moveLeft().reduce().left, n = t.monomByLetter("x").coefficient, r = t.monomByLetter("y").coefficient, i = t.monomByLetter("z").coefficient, a = t.monomByDegree(0).coefficient;
|
|
5284
|
-
this.normal = new
|
|
5249
|
+
this.normal = new H(n, r, i), this.point = n.isNotZero() ? new V(a.clone().divide(n).opposite(), 0, 0) : r.isNotZero() ? new V(0, a.clone().divide(r).opposite(), 0) : new V(0, 0, a.clone().divide(i).opposite());
|
|
5285
5250
|
return;
|
|
5286
5251
|
}
|
|
5287
|
-
if (e.points?.length === 3 && e.points.every((e) => e instanceof
|
|
5288
|
-
let t = e.points[0], n = e.points[1], r = e.points[2], i = new
|
|
5252
|
+
if (e.points?.length === 3 && e.points.every((e) => e instanceof H)) {
|
|
5253
|
+
let t = e.points[0], n = e.points[1], r = e.points[2], i = new H(t, n), a = new H(t, r);
|
|
5289
5254
|
this.normal = i.cross(a), this.point = t;
|
|
5290
5255
|
return;
|
|
5291
5256
|
}
|
|
5292
5257
|
if (e.coefficients?.length === 4) {
|
|
5293
5258
|
let [t, n, r, i] = e.coefficients;
|
|
5294
|
-
this.normal = new
|
|
5259
|
+
this.normal = new H(t, n, r), this.point = new V(0, 0, -i);
|
|
5295
5260
|
return;
|
|
5296
5261
|
}
|
|
5297
5262
|
}
|
|
5298
5263
|
get tex() {
|
|
5299
|
-
return new
|
|
5264
|
+
return new N(new M("xyz", this.a, this.b, this.c, this.d), new M(0)).reduce().tex;
|
|
5300
5265
|
}
|
|
5301
5266
|
get display() {
|
|
5302
|
-
return new
|
|
5267
|
+
return new N(new M("xyz", this.a, this.b, this.c, this.d), new M(0)).reduce().display;
|
|
5303
5268
|
}
|
|
5304
5269
|
get a() {
|
|
5305
5270
|
return this.#e.x;
|
|
5306
5271
|
}
|
|
5307
|
-
angle(t,
|
|
5308
|
-
if (t instanceof e) return this.normal.angle(t.normal,
|
|
5309
|
-
let
|
|
5310
|
-
if (t instanceof
|
|
5311
|
-
if (t.dimension !== 3) throw
|
|
5312
|
-
|
|
5313
|
-
} else
|
|
5314
|
-
return (
|
|
5272
|
+
angle(t, r, i) {
|
|
5273
|
+
if (t instanceof e) return this.normal.angle(t.normal, r, i);
|
|
5274
|
+
let a;
|
|
5275
|
+
if (t instanceof H) {
|
|
5276
|
+
if (t.dimension !== 3) throw new n("Vector is not 3D");
|
|
5277
|
+
a = t;
|
|
5278
|
+
} else a = t.direction;
|
|
5279
|
+
return (i ? Math.PI / 2 : 90) - this.normal.angle(a, !0, i);
|
|
5315
5280
|
}
|
|
5316
5281
|
get b() {
|
|
5317
5282
|
return this.#e.y;
|
|
@@ -5327,10 +5292,10 @@ var G = class e {
|
|
|
5327
5292
|
}
|
|
5328
5293
|
intersectWithLine(e) {
|
|
5329
5294
|
let { point: t, direction: n } = e, r = this.normal.dot(t).add(this.d).divide(this.normal.dot(n).opposite());
|
|
5330
|
-
return new
|
|
5295
|
+
return new V(new H(t).add(n.clone().multiplyByScalar(r)));
|
|
5331
5296
|
}
|
|
5332
5297
|
intersectWithPlane(e) {
|
|
5333
|
-
throw this.normal.cross(e.normal), new
|
|
5298
|
+
throw this.normal.cross(e.normal), new V(0, 0, 0), new a("Intersection with plane not yet implemented !");
|
|
5334
5299
|
}
|
|
5335
5300
|
isPointOnPlane(e) {
|
|
5336
5301
|
return this.normal.dot(e).add(this.d).isZero();
|
|
@@ -5339,44 +5304,44 @@ var G = class e {
|
|
|
5339
5304
|
return this.#e;
|
|
5340
5305
|
}
|
|
5341
5306
|
set normal(e) {
|
|
5342
|
-
this.#e = new
|
|
5307
|
+
this.#e = new H(e);
|
|
5343
5308
|
}
|
|
5344
5309
|
get point() {
|
|
5345
5310
|
return this.#t;
|
|
5346
5311
|
}
|
|
5347
5312
|
set point(e) {
|
|
5348
|
-
this.#t = new
|
|
5313
|
+
this.#t = new V(e);
|
|
5349
5314
|
}
|
|
5350
|
-
},
|
|
5315
|
+
}, Ae = /* @__PURE__ */ function(e) {
|
|
5351
5316
|
return e[e.INTERIOR = 0] = "INTERIOR", e[e.EXTERIOR = 1] = "EXTERIOR", e[e.SECANT = 2] = "SECANT", e[e.TANGENT_INSIDE = 3] = "TANGENT_INSIDE", e[e.TANGENT_OUTSIDE = 4] = "TANGENT_OUTSIDE", e[e.SUPERPOSED = 5] = "SUPERPOSED", e[e.CONCENTRIC = 6] = "CONCENTRIC", e;
|
|
5352
|
-
}({}),
|
|
5317
|
+
}({}), je = class {
|
|
5353
5318
|
#e = void 0;
|
|
5354
5319
|
#t = void 0;
|
|
5355
5320
|
#n = void 0;
|
|
5356
5321
|
#r = 1;
|
|
5357
5322
|
constructor(e, t) {
|
|
5358
|
-
return e && t && (this.#e = e, this.#t = new
|
|
5323
|
+
return e && t && (this.#e = e, this.#t = new m(t).clone().pow(2), this.#a()), this;
|
|
5359
5324
|
}
|
|
5360
5325
|
fromEquation(e) {
|
|
5361
|
-
let t = new
|
|
5326
|
+
let t = new N(e).moveLeft().reduce(), n = [
|
|
5362
5327
|
"x",
|
|
5363
5328
|
"y",
|
|
5364
5329
|
"z"
|
|
5365
5330
|
];
|
|
5366
5331
|
if (n.some((e) => t.degree(e).value !== 2)) return this.makeUndefined();
|
|
5367
5332
|
let r = t.left.monomByDegree(2, "x").coefficient;
|
|
5368
|
-
return n.some((e) => t.left.monomByDegree(2, e).coefficient.isNotEqual(r)) ? this.makeUndefined() : (this.#e = new
|
|
5333
|
+
return n.some((e) => t.left.monomByDegree(2, e).coefficient.isNotEqual(r)) ? this.makeUndefined() : (this.#e = new V(t.left.monomByDegree(1, "x").coefficient.clone().opposite().divide(2), t.left.monomByDegree(1, "y").coefficient.clone().opposite().divide(2), t.left.monomByDegree(1, "z").coefficient.clone().opposite().divide(2)), this.#t = t.left.monomByDegree(0).coefficient.clone().opposite().add(this.#e.x.clone().pow(2)).add(this.#e.y.clone().pow(2)).add(this.#e.z.clone().pow(2)), this.#a(), this);
|
|
5369
5334
|
}
|
|
5370
5335
|
get center() {
|
|
5371
|
-
if (this.#e === void 0) throw
|
|
5336
|
+
if (this.#e === void 0) throw new s("Sphere3 is undefined");
|
|
5372
5337
|
return this.#e;
|
|
5373
5338
|
}
|
|
5374
5339
|
get squareRadius() {
|
|
5375
|
-
if (this.#t === void 0) throw
|
|
5340
|
+
if (this.#t === void 0) throw new s("Sphere3 is undefined");
|
|
5376
5341
|
return this.#t;
|
|
5377
5342
|
}
|
|
5378
5343
|
get radius() {
|
|
5379
|
-
if (this.#t === void 0) throw
|
|
5344
|
+
if (this.#t === void 0) throw new s("Sphere3 is undefined");
|
|
5380
5345
|
return this.#t.isSquare() ? {
|
|
5381
5346
|
tex: this.#t.clone().sqrt().tex,
|
|
5382
5347
|
display: this.#t.clone().sqrt().display,
|
|
@@ -5388,7 +5353,7 @@ var G = class e {
|
|
|
5388
5353
|
};
|
|
5389
5354
|
}
|
|
5390
5355
|
get equation() {
|
|
5391
|
-
if (this.#n === void 0) throw
|
|
5356
|
+
if (this.#n === void 0) throw new s("Sphere3 is undefined");
|
|
5392
5357
|
return this.#n;
|
|
5393
5358
|
}
|
|
5394
5359
|
makeUndefined() {
|
|
@@ -5407,7 +5372,7 @@ var G = class e {
|
|
|
5407
5372
|
return this.#i(!1);
|
|
5408
5373
|
}
|
|
5409
5374
|
#i = (e) => {
|
|
5410
|
-
if (this.#n === void 0) throw
|
|
5375
|
+
if (this.#n === void 0) throw new s("Sphere3 is undefined");
|
|
5411
5376
|
if (this.#r === 0) return e ? this.#n.tex : this.#n.display;
|
|
5412
5377
|
let t = [];
|
|
5413
5378
|
return [
|
|
@@ -5417,15 +5382,15 @@ var G = class e {
|
|
|
5417
5382
|
].forEach((n) => {
|
|
5418
5383
|
if (this.center[n].isZero()) t.push(`${n}^2`);
|
|
5419
5384
|
else {
|
|
5420
|
-
let r = new
|
|
5385
|
+
let r = new M(n).subtract(this.center[n]);
|
|
5421
5386
|
t.push(e ? `\\(${r.tex}\\)^2` : `(${r.display})^2`);
|
|
5422
5387
|
}
|
|
5423
5388
|
}), t.join("+") + "=" + (e ? this.squareRadius.tex : this.squareRadius.display);
|
|
5424
5389
|
};
|
|
5425
5390
|
#a() {
|
|
5426
|
-
this.#n = new
|
|
5391
|
+
this.#n = new N(new M("x").subtract(this.center.x).pow(2).add(new M("y").subtract(this.center.y).pow(2)).add(new M("z").subtract(this.center.z).pow(2)), new M(this.squareRadius)).reduce();
|
|
5427
5392
|
}
|
|
5428
|
-
static RELATIVE_POSITION =
|
|
5393
|
+
static RELATIVE_POSITION = Ae;
|
|
5429
5394
|
relativePosition = (e) => {
|
|
5430
5395
|
let t = this.center.distanceTo(e.center).value, n = this.radius.value, r = e.radius.value;
|
|
5431
5396
|
return t > n + r ? 1 : t === n + r ? 4 : t === 0 ? n === r ? 5 : 6 : t === Math.abs(n - r) ? 3 : t < Math.abs(n - r) ? 0 : 2;
|
|
@@ -5438,38 +5403,38 @@ var G = class e {
|
|
|
5438
5403
|
};
|
|
5439
5404
|
//#endregion
|
|
5440
5405
|
//#region src/randomization/coefficient/rndFraction.ts
|
|
5441
|
-
function
|
|
5406
|
+
function Z(e) {
|
|
5442
5407
|
let t = Object.assign({
|
|
5443
5408
|
negative: !0,
|
|
5444
5409
|
max: 10,
|
|
5445
5410
|
reduced: !0,
|
|
5446
5411
|
zero: !0,
|
|
5447
5412
|
natural: !1
|
|
5448
|
-
}, e), n = new
|
|
5449
|
-
if (n.numerator = t.negative ?
|
|
5413
|
+
}, e), n = new m();
|
|
5414
|
+
if (n.numerator = t.negative ? G(t.max, t.zero) : W(+!t.zero, t.max), t.natural) n.denominator = 1;
|
|
5450
5415
|
else {
|
|
5451
5416
|
let e = 0;
|
|
5452
|
-
for (; n.isRelative() && e < 10;) n.denominator =
|
|
5417
|
+
for (; n.isRelative() && e < 10;) n.denominator = W(1, t.max), e++;
|
|
5453
5418
|
}
|
|
5454
5419
|
return t.reduced ? n.reduce() : n;
|
|
5455
5420
|
}
|
|
5456
5421
|
//#endregion
|
|
5457
5422
|
//#region src/randomization/algebra/rndMonom.ts
|
|
5458
|
-
function
|
|
5423
|
+
function Me(e) {
|
|
5459
5424
|
let t = Object.assign({
|
|
5460
5425
|
letters: "x",
|
|
5461
5426
|
degree: 2,
|
|
5462
5427
|
fraction: !0,
|
|
5463
5428
|
zero: !1
|
|
5464
|
-
}, e), n = new
|
|
5465
|
-
if (n.coefficient =
|
|
5429
|
+
}, e), n = new A();
|
|
5430
|
+
if (n.coefficient = Z(Object.assign({}, {
|
|
5466
5431
|
zero: t.zero,
|
|
5467
5432
|
reduced: !0,
|
|
5468
5433
|
natural: t.fraction === !1
|
|
5469
5434
|
}, typeof t.fraction == "boolean" ? {} : t.fraction)), t.letters.length > 1) {
|
|
5470
5435
|
for (let e of t.letters.split("")) n.setLetter(e, 0);
|
|
5471
5436
|
for (let e = 0; e < t.degree; e++) {
|
|
5472
|
-
let e =
|
|
5437
|
+
let e = K(t.letters.split(""));
|
|
5473
5438
|
n.setLetter(e, n.degree(e).clone().add(1));
|
|
5474
5439
|
}
|
|
5475
5440
|
} else n.setLetter(t.letters, t.degree);
|
|
@@ -5477,7 +5442,7 @@ function ye(e) {
|
|
|
5477
5442
|
}
|
|
5478
5443
|
//#endregion
|
|
5479
5444
|
//#region src/randomization/algebra/rndPolynom.ts
|
|
5480
|
-
var
|
|
5445
|
+
var Ne = {
|
|
5481
5446
|
letters: "x",
|
|
5482
5447
|
degree: 2,
|
|
5483
5448
|
fraction: !1,
|
|
@@ -5489,36 +5454,36 @@ var X = {
|
|
|
5489
5454
|
commonConstant: !1,
|
|
5490
5455
|
positive: !0
|
|
5491
5456
|
};
|
|
5492
|
-
function
|
|
5493
|
-
let t = Object.assign({},
|
|
5494
|
-
if (t.factorable) return
|
|
5495
|
-
let n = new
|
|
5496
|
-
for (let e = i; e >= 0; e--) r =
|
|
5457
|
+
function Q(e) {
|
|
5458
|
+
let t = Object.assign({}, Ne, e);
|
|
5459
|
+
if (t.factorable) return Pe(t);
|
|
5460
|
+
let n = new M().empty(), r, i = t.degree ?? 2;
|
|
5461
|
+
for (let e = i; e >= 0; e--) r = Me({
|
|
5497
5462
|
letters: t.letters,
|
|
5498
5463
|
degree: e,
|
|
5499
5464
|
fraction: t.fraction,
|
|
5500
5465
|
zero: e !== i && t.allowNullMonom
|
|
5501
5466
|
}), t.unit && i === e && r.coefficient.one(), n.add(r);
|
|
5502
5467
|
if (t.positive && n.monomByDegree().coefficient.isNegative() && n.opposite(), t.numberOfMonoms && t.numberOfMonoms > 0 && t.numberOfMonoms < n.length) for (; n.length > t.numberOfMonoms;) {
|
|
5503
|
-
let e =
|
|
5468
|
+
let e = W(1, n.length - 1);
|
|
5504
5469
|
n.monoms.splice(e, 1);
|
|
5505
5470
|
}
|
|
5506
5471
|
return n.reduce();
|
|
5507
5472
|
}
|
|
5508
|
-
function
|
|
5509
|
-
let t = Object.assign(
|
|
5473
|
+
function Pe(e) {
|
|
5474
|
+
let t = Object.assign(Ne, e), n = { ...t };
|
|
5510
5475
|
n.degree = 1, n.factorable = !1;
|
|
5511
5476
|
let r = [], i = t.degree ?? 2;
|
|
5512
|
-
for (; r.length < i;) r.push(
|
|
5477
|
+
for (; r.length < i;) r.push(Q(n));
|
|
5513
5478
|
if (e?.commonConstant !== !1) {
|
|
5514
|
-
let t =
|
|
5515
|
-
e?.commonConstant === !0 && (t === 1 || t === -1) && (t *=
|
|
5479
|
+
let t = G(10, !1);
|
|
5480
|
+
e?.commonConstant === !0 && (t === 1 || t === -1) && (t *= W(2, 5)), t !== 1 && t !== -1 && r.unshift(new M(t));
|
|
5516
5481
|
}
|
|
5517
|
-
return
|
|
5482
|
+
return M.xMultiply(...r);
|
|
5518
5483
|
}
|
|
5519
5484
|
//#endregion
|
|
5520
5485
|
//#region src/randomization/algebra/rndEquation.ts
|
|
5521
|
-
function
|
|
5486
|
+
function Fe(e) {
|
|
5522
5487
|
let t = Object.assign({
|
|
5523
5488
|
letters: "x",
|
|
5524
5489
|
degree: 1,
|
|
@@ -5535,9 +5500,9 @@ function xe(e) {
|
|
|
5535
5500
|
nothing: !1,
|
|
5536
5501
|
everything: !1
|
|
5537
5502
|
}
|
|
5538
|
-
}, e), n = new
|
|
5503
|
+
}, e), n = new M().one();
|
|
5539
5504
|
for (let e = 0; e < t.degree; e++) {
|
|
5540
|
-
let e =
|
|
5505
|
+
let e = Q({
|
|
5541
5506
|
degree: 1,
|
|
5542
5507
|
unit: t.unit,
|
|
5543
5508
|
fraction: t.fraction,
|
|
@@ -5546,28 +5511,28 @@ function xe(e) {
|
|
|
5546
5511
|
});
|
|
5547
5512
|
n.multiply(e);
|
|
5548
5513
|
}
|
|
5549
|
-
return new
|
|
5514
|
+
return new N(n, 0);
|
|
5550
5515
|
}
|
|
5551
5516
|
//#endregion
|
|
5552
5517
|
//#region src/randomization/geometry/rndPoint.ts
|
|
5553
|
-
function
|
|
5518
|
+
function $(e) {
|
|
5554
5519
|
let t = Object.assign({
|
|
5555
5520
|
axis: !0,
|
|
5556
5521
|
fraction: !1,
|
|
5557
5522
|
max: 10,
|
|
5558
5523
|
quadrant: null
|
|
5559
|
-
}, e), n = t.axis === "x", r = t.axis === "y", i = t.fraction ?
|
|
5524
|
+
}, e), n = t.axis === "x", r = t.axis === "y", i = t.fraction ? Z({
|
|
5560
5525
|
max: t.max,
|
|
5561
5526
|
zero: n
|
|
5562
|
-
}) : new
|
|
5527
|
+
}) : new m(G(t.max, n)), a = t.fraction ? Z({
|
|
5563
5528
|
max: t.max,
|
|
5564
5529
|
zero: r
|
|
5565
|
-
}) : new
|
|
5566
|
-
return Number(t.quadrant) === 1 && (i.abs(), a.abs()), Number(t.quadrant) === 2 && (i.isPositive() && i.opposite(), a.isNegative() && a.opposite()), Number(t.quadrant) === 3 && (i.isPositive() && i.opposite(), a.isPositive() && a.opposite()), Number(t.quadrant) === 4 && (i.isNegative() && i.opposite(), a.isPositive() && a.opposite()), new
|
|
5530
|
+
}) : new m(G(t.max, r));
|
|
5531
|
+
return Number(t.quadrant) === 1 && (i.abs(), a.abs()), Number(t.quadrant) === 2 && (i.isPositive() && i.opposite(), a.isNegative() && a.opposite()), Number(t.quadrant) === 3 && (i.isPositive() && i.opposite(), a.isPositive() && a.opposite()), Number(t.quadrant) === 4 && (i.isNegative() && i.opposite(), a.isPositive() && a.opposite()), new V(i, a);
|
|
5567
5532
|
}
|
|
5568
5533
|
//#endregion
|
|
5569
5534
|
//#region src/randomization/geometry/rndCircle.ts
|
|
5570
|
-
function
|
|
5535
|
+
function Ie(e) {
|
|
5571
5536
|
let t = Object.assign({
|
|
5572
5537
|
center: {
|
|
5573
5538
|
x: {
|
|
@@ -5580,82 +5545,92 @@ function Se(e) {
|
|
|
5580
5545
|
}
|
|
5581
5546
|
},
|
|
5582
5547
|
pointsOnCircle: 8
|
|
5583
|
-
}, e), n =
|
|
5584
|
-
return t.pointsOnCircle === 8 ? (r =
|
|
5548
|
+
}, e), n = $(t.center), r, i;
|
|
5549
|
+
return t.pointsOnCircle === 8 ? (r = W(1, 3), i = r ** 2 + (r + 1) ** 2) : i = W(1, 20), new Y(n, i, !0);
|
|
5585
5550
|
}
|
|
5586
5551
|
//#endregion
|
|
5587
5552
|
//#region src/randomization/geometry/rndLine.ts
|
|
5588
|
-
function
|
|
5553
|
+
function Le(e) {
|
|
5589
5554
|
let t = Object.assign({ A: {
|
|
5590
|
-
x:
|
|
5591
|
-
y:
|
|
5592
|
-
} }, e), n = new
|
|
5593
|
-
for (; n.isNull;) n.x =
|
|
5594
|
-
return t.slope === 1 ? n.x.sign() !== n.y.sign() && n.y.opposite() : t.slope === -1 && n.x.sign() !== n.y.sign() && n.y.opposite(), new
|
|
5555
|
+
x: G(10),
|
|
5556
|
+
y: G(10)
|
|
5557
|
+
} }, e), n = new H(0, 0);
|
|
5558
|
+
for (; n.isNull;) n.x = G(10, t.allow?.vertical ?? !0), n.y = G(10, t.allow?.horizontal ?? !0);
|
|
5559
|
+
return t.slope === 1 ? n.x.sign() !== n.y.sign() && n.y.opposite() : t.slope === -1 && n.x.sign() !== n.y.sign() && n.y.opposite(), new q().fromPointAndDirection(new H(t.A.x, t.A.y), n);
|
|
5595
5560
|
}
|
|
5596
5561
|
//#endregion
|
|
5597
5562
|
//#region src/randomization/geometry/rndLine3.ts
|
|
5598
|
-
function
|
|
5563
|
+
function Re(e) {
|
|
5599
5564
|
let t = Object.assign({
|
|
5600
5565
|
A: {
|
|
5601
|
-
x:
|
|
5602
|
-
y:
|
|
5603
|
-
z:
|
|
5566
|
+
x: G(10),
|
|
5567
|
+
y: G(10),
|
|
5568
|
+
z: G(10)
|
|
5604
5569
|
},
|
|
5605
5570
|
direction: {
|
|
5606
|
-
x:
|
|
5607
|
-
y:
|
|
5608
|
-
z:
|
|
5571
|
+
x: G(10),
|
|
5572
|
+
y: G(10),
|
|
5573
|
+
z: G(10)
|
|
5609
5574
|
}
|
|
5610
5575
|
}, e);
|
|
5611
|
-
return new
|
|
5576
|
+
return new X(new V(t.A.x, t.A.y, t.A.z), new H(t.direction.x, t.direction.y, t.direction.z));
|
|
5612
5577
|
}
|
|
5613
5578
|
//#endregion
|
|
5614
5579
|
//#region src/randomization/random.ts
|
|
5615
|
-
var
|
|
5616
|
-
equation: (e) =>
|
|
5617
|
-
polynom: (e) =>
|
|
5618
|
-
monom: (e) =>
|
|
5619
|
-
fraction: (e) =>
|
|
5620
|
-
number: (e, t, n) =>
|
|
5621
|
-
numberSym: (e, t) =>
|
|
5622
|
-
prime: (e) =>
|
|
5623
|
-
triplet: (e, t) =>
|
|
5624
|
-
bool: (e) =>
|
|
5625
|
-
array: (e, t) =>
|
|
5626
|
-
item: (e) =>
|
|
5627
|
-
shuffle: (e) =>
|
|
5628
|
-
line: (e) =>
|
|
5629
|
-
line3: (e) =>
|
|
5630
|
-
vector: (e) => new
|
|
5631
|
-
point: (e) =>
|
|
5632
|
-
circle: (e) =>
|
|
5633
|
-
},
|
|
5634
|
-
Numeric:
|
|
5635
|
-
Fraction:
|
|
5580
|
+
var ze = {
|
|
5581
|
+
equation: (e) => Fe(e),
|
|
5582
|
+
polynom: (e) => Q(e),
|
|
5583
|
+
monom: (e) => Me(e),
|
|
5584
|
+
fraction: (e) => Z(e),
|
|
5585
|
+
number: (e, t, n) => W(e, t, n),
|
|
5586
|
+
numberSym: (e, t) => G(e, t),
|
|
5587
|
+
prime: (e) => Ee(e),
|
|
5588
|
+
triplet: (e, t) => Te(e, t),
|
|
5589
|
+
bool: (e) => we(e),
|
|
5590
|
+
array: (e, t) => De(e, t),
|
|
5591
|
+
item: (e) => K(e),
|
|
5592
|
+
shuffle: (e) => Oe(e),
|
|
5593
|
+
line: (e) => Le(e),
|
|
5594
|
+
line3: (e) => Re(e),
|
|
5595
|
+
vector: (e) => new H($(e)),
|
|
5596
|
+
point: (e) => $(e),
|
|
5597
|
+
circle: (e) => Ie(e)
|
|
5598
|
+
}, Be = {
|
|
5599
|
+
Numeric: p,
|
|
5600
|
+
Fraction: m,
|
|
5636
5601
|
Root: v,
|
|
5637
|
-
Monom:
|
|
5638
|
-
Polynom:
|
|
5639
|
-
Equation:
|
|
5640
|
-
Matrix:
|
|
5641
|
-
LinearSystem:
|
|
5642
|
-
Factor:
|
|
5643
|
-
PolyFactor:
|
|
5644
|
-
LogicalSet:
|
|
5645
|
-
Random:
|
|
5602
|
+
Monom: A,
|
|
5603
|
+
Polynom: M,
|
|
5604
|
+
Equation: N,
|
|
5605
|
+
Matrix: ve,
|
|
5606
|
+
LinearSystem: I,
|
|
5607
|
+
Factor: P,
|
|
5608
|
+
PolyFactor: R,
|
|
5609
|
+
LogicalSet: L,
|
|
5610
|
+
Random: ze,
|
|
5646
5611
|
Geometry: {
|
|
5647
|
-
Vector:
|
|
5648
|
-
Point:
|
|
5649
|
-
Line:
|
|
5650
|
-
Triangle:
|
|
5651
|
-
Circle:
|
|
5652
|
-
Line3:
|
|
5653
|
-
Plane3:
|
|
5654
|
-
Sphere3:
|
|
5612
|
+
Vector: H,
|
|
5613
|
+
Point: V,
|
|
5614
|
+
Line: q,
|
|
5615
|
+
Triangle: J,
|
|
5616
|
+
Circle: Y,
|
|
5617
|
+
Line3: X,
|
|
5618
|
+
Plane3: ke,
|
|
5619
|
+
Sphere3: je
|
|
5620
|
+
},
|
|
5621
|
+
Errors: {
|
|
5622
|
+
PiMathError: e,
|
|
5623
|
+
ParseError: t,
|
|
5624
|
+
DimensionError: n,
|
|
5625
|
+
MathError: r,
|
|
5626
|
+
InvalidArgumentError: i,
|
|
5627
|
+
NotImplementedError: a,
|
|
5628
|
+
IndexError: o,
|
|
5629
|
+
StateError: s
|
|
5655
5630
|
},
|
|
5656
|
-
NumExp:
|
|
5631
|
+
NumExp: k
|
|
5657
5632
|
};
|
|
5658
5633
|
//#endregion
|
|
5659
|
-
export {
|
|
5634
|
+
export { Y as Circle, n as DimensionError, N as Equation, b as EquationSolver, F as FACTOR_DISPLAY, oe as FRAC_TYPE, P as Factor, m as Fraction, o as IndexError, i as InvalidArgumentError, q as Line, X as Line3, I as LinearSystem, L as LogicalSet, r as MathError, ve as Matrix, A as Monom, a as NotImplementedError, k as NumExp, p as Numeric, t as ParseError, e as PiMathError, ke as Plane3, V as Point, R as PolyFactor, M as Polynom, ze as Random, v as Root, Ae as SPHERE3_RELATIVE_POSITION, y as Solution, je as Sphere3, s as StateError, ce as TableOfSigns, J as Triangle, H as Vector, be as areVectorsColinears, ye as areVectorsEquals, Be as default, Se as determinantFromVectors, xe as dotProduct };
|
|
5660
5635
|
|
|
5661
5636
|
//# sourceMappingURL=pimath.js.map
|