pimath 0.2.6 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pimath.js +334 -311
- package/dist/pimath.js.map +1 -1
- package/package.json +1 -1
- package/src/algebra/factor.ts +11 -0
- package/src/algebra/polyFactor.ts +41 -9
- package/src/algebra/polynom.ts +3 -0
- package/src/coefficients/root.ts +8 -9
- package/src/helpers.ts +7 -6
- package/types/algebra/factor.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/root.d.ts.map +1 -1
- package/types/helpers.d.ts.map +1 -1
package/dist/pimath.js
CHANGED
|
@@ -84,7 +84,7 @@ const b = {
|
|
|
84
84
|
greatestPower: xt
|
|
85
85
|
};
|
|
86
86
|
var bt = /* @__PURE__ */ ((n) => (n.frac = "frac", n.dfrac = "dfrac", n.tfrac = "tfrac", n))(bt || {});
|
|
87
|
-
class
|
|
87
|
+
class a {
|
|
88
88
|
#t = 1;
|
|
89
89
|
#e = 3;
|
|
90
90
|
#i = !0;
|
|
@@ -99,9 +99,9 @@ class h {
|
|
|
99
99
|
* Parse the value to get the numerator and denominator
|
|
100
100
|
* @param value : number or string to parse to get the fraction
|
|
101
101
|
*/
|
|
102
|
-
parse = (t, e) => t === "" ? (this.#s = 0, this.#t = 1, this) : typeof t == "number" && isNaN(t) ? this.invalid() : typeof t == "number" && !isFinite(t) ? (this.infinite(), t < 0 && this.opposite(), this) : typeof t == "string" ? this.fromString(t) : typeof t == "number" && e === void 0 ? this.fromNumber(t) : typeof t == "number" && typeof e == "number" ? this.fromNumbers(t, e) : t instanceof
|
|
102
|
+
parse = (t, e) => t === "" ? (this.#s = 0, this.#t = 1, this) : typeof t == "number" && isNaN(t) ? this.invalid() : typeof t == "number" && !isFinite(t) ? (this.infinite(), t < 0 && this.opposite(), this) : typeof t == "string" ? this.fromString(t) : typeof t == "number" && e === void 0 ? this.fromNumber(t) : typeof t == "number" && typeof e == "number" ? this.fromNumbers(t, e) : t instanceof a ? this.copy(t) : this;
|
|
103
103
|
clone = () => {
|
|
104
|
-
const t = new
|
|
104
|
+
const t = new a();
|
|
105
105
|
return t.numerator = this.#s, t.denominator = this.#t, t.exact = this.exact, t.#r = this.#r, t.#e = this.#e, t.#n = this.#n, t;
|
|
106
106
|
};
|
|
107
107
|
copy(t) {
|
|
@@ -121,13 +121,13 @@ class h {
|
|
|
121
121
|
}
|
|
122
122
|
static areEquals = (...t) => t.every((e) => e.isEqual(t[0]));
|
|
123
123
|
static average = (...t) => {
|
|
124
|
-
const e = new
|
|
124
|
+
const e = new a().zero();
|
|
125
125
|
for (const i of t)
|
|
126
126
|
e.add(i);
|
|
127
127
|
return e.divide(t.length), e;
|
|
128
128
|
};
|
|
129
129
|
static isFraction(t) {
|
|
130
|
-
if (t instanceof
|
|
130
|
+
if (t instanceof a || typeof t == "number" && !isNaN(t))
|
|
131
131
|
return !0;
|
|
132
132
|
if (typeof t == "string") {
|
|
133
133
|
const e = t.split("/");
|
|
@@ -136,46 +136,46 @@ class h {
|
|
|
136
136
|
return !1;
|
|
137
137
|
}
|
|
138
138
|
static max = (...t) => {
|
|
139
|
-
let e = new
|
|
139
|
+
let e = new a(t[0]);
|
|
140
140
|
for (const i of t) {
|
|
141
|
-
const s = new
|
|
141
|
+
const s = new a(i);
|
|
142
142
|
s.isGreater(e) && (e = s.clone());
|
|
143
143
|
}
|
|
144
144
|
return e;
|
|
145
145
|
};
|
|
146
146
|
static min = (...t) => {
|
|
147
|
-
let e = new
|
|
147
|
+
let e = new a(t[0]);
|
|
148
148
|
for (const i of t) {
|
|
149
|
-
const s = new
|
|
149
|
+
const s = new a(i);
|
|
150
150
|
s.isLesser(e) && (e = s.clone());
|
|
151
151
|
}
|
|
152
152
|
return e;
|
|
153
153
|
};
|
|
154
154
|
static sort = (t, e) => {
|
|
155
|
-
const s = t.map((r) => r instanceof
|
|
155
|
+
const s = t.map((r) => r instanceof a ? r : new a(r)).sort((r, o) => r.value - o.value);
|
|
156
156
|
return e && s.reverse(), s;
|
|
157
157
|
};
|
|
158
158
|
static toSameDenominateur(...t) {
|
|
159
|
-
const e = t.map((s) => new
|
|
159
|
+
const e = t.map((s) => new a(s)), i = b.lcm(...e.map((s) => s.denominator));
|
|
160
160
|
return e.forEach((s) => s.amplify(i / s.denominator)), e;
|
|
161
161
|
}
|
|
162
162
|
static unique = (t) => {
|
|
163
163
|
const e = {}, i = [];
|
|
164
164
|
return t.forEach((s) => {
|
|
165
|
-
s instanceof
|
|
165
|
+
s instanceof a || (s = new a(s)), e[s.clone().reduce().tex] || (i.push(s.clone()), e[s.clone().reduce().tex] = !0);
|
|
166
166
|
}), i;
|
|
167
167
|
};
|
|
168
168
|
static xMultiply = (...t) => {
|
|
169
|
-
const e = new
|
|
169
|
+
const e = new a();
|
|
170
170
|
return t.forEach((i) => e.multiply(i, !1)), e;
|
|
171
171
|
};
|
|
172
172
|
abs = () => (this.#s = Math.abs(this.#s), this.#t = Math.abs(this.#t), this);
|
|
173
173
|
add = (t) => {
|
|
174
|
-
if (t instanceof
|
|
174
|
+
if (t instanceof a) {
|
|
175
175
|
const e = this.#s, i = this.#t;
|
|
176
176
|
this.#s = e * t.denominator + t.numerator * i, this.#t = i * t.denominator, this.exact = this.exact && t.exact;
|
|
177
177
|
} else
|
|
178
|
-
return this.add(new
|
|
178
|
+
return this.add(new a(t));
|
|
179
179
|
return this.reduce();
|
|
180
180
|
};
|
|
181
181
|
amplify = (t) => {
|
|
@@ -191,7 +191,7 @@ class h {
|
|
|
191
191
|
compare = (t, e) => {
|
|
192
192
|
e ??= "=";
|
|
193
193
|
let i;
|
|
194
|
-
switch (t instanceof
|
|
194
|
+
switch (t instanceof a ? i = t.clone() : i = new a(t), e) {
|
|
195
195
|
case ">":
|
|
196
196
|
return this.value > i.value;
|
|
197
197
|
case ">=":
|
|
@@ -225,7 +225,7 @@ class h {
|
|
|
225
225
|
return this.#e = t, this;
|
|
226
226
|
}
|
|
227
227
|
divide = (t) => {
|
|
228
|
-
const e = new
|
|
228
|
+
const e = new a(t);
|
|
229
229
|
if (e.numerator === 0)
|
|
230
230
|
return this.infinite();
|
|
231
231
|
const i = this.#s, s = this.#t;
|
|
@@ -296,7 +296,7 @@ class h {
|
|
|
296
296
|
// Mathematical operations specific to fractions
|
|
297
297
|
isZero = () => this.#s === 0;
|
|
298
298
|
multiply = (t, e = !0) => {
|
|
299
|
-
const i = new
|
|
299
|
+
const i = new a(t);
|
|
300
300
|
return this.#s = this.#s * i.numerator, this.#t = this.#t * i.denominator, this.exact = this.exact && i.exact, e ? this.reduce() : this;
|
|
301
301
|
};
|
|
302
302
|
// ------------------------------------------
|
|
@@ -309,7 +309,7 @@ class h {
|
|
|
309
309
|
one = () => this.fromNumber(1);
|
|
310
310
|
opposite = () => (this.#s = -this.#s, this);
|
|
311
311
|
pow = (t) => {
|
|
312
|
-
if (t instanceof
|
|
312
|
+
if (t instanceof a)
|
|
313
313
|
return this.pow(t.value);
|
|
314
314
|
this.reduce(), t < 0 && this.inverse();
|
|
315
315
|
const e = Math.abs(t), i = Math.pow(this.#s, e), s = Math.pow(this.#t, e), r = Math.floor(i), o = Math.floor(s);
|
|
@@ -333,7 +333,7 @@ class h {
|
|
|
333
333
|
};
|
|
334
334
|
sign = () => this.#s * this.#t >= 0 ? 1 : -1;
|
|
335
335
|
sqrt = () => this.root(2);
|
|
336
|
-
subtract = (t) => t instanceof
|
|
336
|
+
subtract = (t) => t instanceof a ? this.add(t.clone().opposite()) : this.add(-t);
|
|
337
337
|
get tfrac() {
|
|
338
338
|
return this.#r = "tfrac", this;
|
|
339
339
|
}
|
|
@@ -352,10 +352,14 @@ class h {
|
|
|
352
352
|
function st(n, t = !0) {
|
|
353
353
|
return t ? `\\left( ${n} \\right)` : `(${n})`;
|
|
354
354
|
}
|
|
355
|
-
function
|
|
356
|
-
|
|
355
|
+
function j(n) {
|
|
356
|
+
if (!n.startsWith("(") || !n.endsWith(")")) return n;
|
|
357
|
+
let t = 0;
|
|
358
|
+
for (let e = 0; e < n.length - 1; e++)
|
|
359
|
+
if (n[e] === "(" ? t++ : n[e] === ")" && t--, t === 0) return n;
|
|
360
|
+
return n.slice(1, -1);
|
|
357
361
|
}
|
|
358
|
-
function
|
|
362
|
+
function F(n, t, e, i, s) {
|
|
359
363
|
return n.map((r, o) => r === t ? e : r);
|
|
360
364
|
}
|
|
361
365
|
function H(n, t) {
|
|
@@ -369,18 +373,18 @@ function H(n, t) {
|
|
|
369
373
|
}
|
|
370
374
|
return s.push(n.substring(i)), s;
|
|
371
375
|
}
|
|
372
|
-
class
|
|
376
|
+
class O {
|
|
373
377
|
#t;
|
|
374
378
|
#e;
|
|
375
379
|
#i;
|
|
376
380
|
#s = !1;
|
|
377
381
|
constructor(t) {
|
|
378
|
-
return this.#e = 2, this.#t = new
|
|
382
|
+
return this.#e = 2, this.#t = new a().zero(), this.#i = new a().zero(), t && this.parse(t), this;
|
|
379
383
|
}
|
|
380
384
|
parse(t) {
|
|
381
|
-
if (t instanceof
|
|
385
|
+
if (t instanceof O)
|
|
382
386
|
return this.index = t.index, this.radical = t.radical.clone(), this.factor = t.factor.clone(), this;
|
|
383
|
-
if (t instanceof
|
|
387
|
+
if (t instanceof a)
|
|
384
388
|
return this.index = 2, this.factor = t.clone(), this.radical.one(), this;
|
|
385
389
|
if (typeof t == "string") {
|
|
386
390
|
if (t.includes("sqrt"))
|
|
@@ -388,10 +392,10 @@ class T {
|
|
|
388
392
|
if (t.includes("root"))
|
|
389
393
|
return this.#o(t);
|
|
390
394
|
}
|
|
391
|
-
return this.index = 2, this.factor = new
|
|
395
|
+
return this.index = 2, this.factor = new a(t), this.radical.one(), this;
|
|
392
396
|
}
|
|
393
397
|
clone() {
|
|
394
|
-
return new
|
|
398
|
+
return new O().from(this.index, this.radical, this.factor);
|
|
395
399
|
}
|
|
396
400
|
get tex() {
|
|
397
401
|
const t = this.#s && this.factor.isPositive() ? "+" : "", e = t && this.#t.numerator === 1 ? " " : "";
|
|
@@ -407,13 +411,13 @@ class T {
|
|
|
407
411
|
}
|
|
408
412
|
add(t) {
|
|
409
413
|
this.reduce();
|
|
410
|
-
const e = new
|
|
414
|
+
const e = new O(t).reduce();
|
|
411
415
|
if (this.index !== e.index || !this.radical.isEqual(e.radical))
|
|
412
416
|
throw new Error("Add can only be done with two same index and radical");
|
|
413
417
|
return this.factor.add(e.factor), this;
|
|
414
418
|
}
|
|
415
419
|
divide(t) {
|
|
416
|
-
return this.multiply(new
|
|
420
|
+
return this.multiply(new O(t).inverse());
|
|
417
421
|
}
|
|
418
422
|
get factor() {
|
|
419
423
|
return this.#t;
|
|
@@ -422,7 +426,7 @@ class T {
|
|
|
422
426
|
this.#t = t;
|
|
423
427
|
}
|
|
424
428
|
from(t, e, i) {
|
|
425
|
-
return this.index = t, this.radical = new
|
|
429
|
+
return this.index = t, this.radical = new a(e), this.factor = i ? new a(i) : new a().one(), this;
|
|
426
430
|
}
|
|
427
431
|
/**
|
|
428
432
|
* convert to root(index)(radical), without factor
|
|
@@ -439,7 +443,7 @@ class T {
|
|
|
439
443
|
this.#e = t;
|
|
440
444
|
}
|
|
441
445
|
get indexAsPow() {
|
|
442
|
-
return new
|
|
446
|
+
return new a(this.index).inverse();
|
|
443
447
|
}
|
|
444
448
|
inverse() {
|
|
445
449
|
return this.factor.inverse(), this.radical.inverse(), this;
|
|
@@ -458,7 +462,7 @@ class T {
|
|
|
458
462
|
return this.factor.isZero() || this.radical.isZero();
|
|
459
463
|
}
|
|
460
464
|
multiply(t) {
|
|
461
|
-
const e = new
|
|
465
|
+
const e = new O(t);
|
|
462
466
|
if (this.factor.multiply(e.factor), this.index === e.index)
|
|
463
467
|
return this.radical.multiply(e.radical), this;
|
|
464
468
|
if (this.radical.isEqual(e.radical)) {
|
|
@@ -499,7 +503,7 @@ class T {
|
|
|
499
503
|
return this.root(2);
|
|
500
504
|
}
|
|
501
505
|
subtract(t) {
|
|
502
|
-
const e = new
|
|
506
|
+
const e = new O(t);
|
|
503
507
|
return this.add(e.opposite());
|
|
504
508
|
}
|
|
505
509
|
get value() {
|
|
@@ -529,12 +533,14 @@ class T {
|
|
|
529
533
|
return s.length === 0 ? null : s.join(" ");
|
|
530
534
|
}
|
|
531
535
|
#o(t) {
|
|
532
|
-
const
|
|
533
|
-
|
|
536
|
+
const e = /^(.*?)root\((\d+)\)\(?([^)]+)/.exec(t);
|
|
537
|
+
if (!e) throw new Error(`Invalid root format: "${t}"`);
|
|
538
|
+
const [, i, s, r] = e;
|
|
539
|
+
return this.index = +s, this.radical = new a(r), this.factor = i === "" ? new a().one() : new a(i.trim()), this;
|
|
534
540
|
}
|
|
535
541
|
#a(t) {
|
|
536
542
|
const [e, i] = t.split("sqrt");
|
|
537
|
-
return this.index = 2, this.radical = new
|
|
543
|
+
return this.index = 2, this.radical = new a(j(i)), this.factor = e === "" ? new a().one() : new a(e), this;
|
|
538
544
|
}
|
|
539
545
|
}
|
|
540
546
|
class C {
|
|
@@ -546,13 +552,13 @@ class C {
|
|
|
546
552
|
#n;
|
|
547
553
|
#o;
|
|
548
554
|
constructor() {
|
|
549
|
-
this.#o = "x", this.#i = !1, this.#e = null, this.#n = null, this.#s = new
|
|
555
|
+
this.#o = "x", this.#i = !1, this.#e = null, this.#n = null, this.#s = new a().zero(), this.#r = new O(), this.#t = 1;
|
|
550
556
|
}
|
|
551
557
|
get tex() {
|
|
552
558
|
if (this.#n) return this.#n;
|
|
553
559
|
if (this.#r.isZero()) return this.#s.tex;
|
|
554
560
|
if (this.#s.isZero()) return this.#r.tex;
|
|
555
|
-
const [t] =
|
|
561
|
+
const [t] = a.toSameDenominateur(this.#s, this.#r.factor), e = this.#r.clone().multiply(t.denominator).reduce(), i = `${t.numerator} ${e.withSign.tex}`;
|
|
556
562
|
return t.denominator === 1 ? i : `\\frac{ ${i} }{ ${t.denominator} }`;
|
|
557
563
|
}
|
|
558
564
|
set tex(t) {
|
|
@@ -562,7 +568,7 @@ class C {
|
|
|
562
568
|
if (this.#e) return this.#e;
|
|
563
569
|
if (this.#r.isZero()) return this.#s.display;
|
|
564
570
|
if (this.#s.isZero()) return this.#r.display;
|
|
565
|
-
const [t] =
|
|
571
|
+
const [t] = a.toSameDenominateur(this.#s, this.#r.factor), e = this.#r.clone().multiply(t.denominator).reduce(), i = `${t.numerator}${e.withSign.display}`;
|
|
566
572
|
return t.denominator === 1 ? i : `(${i})/${t.denominator}`;
|
|
567
573
|
}
|
|
568
574
|
set display(t) {
|
|
@@ -571,21 +577,21 @@ class C {
|
|
|
571
577
|
static fromFraction(t) {
|
|
572
578
|
const e = new C();
|
|
573
579
|
e.setExact();
|
|
574
|
-
const i = new
|
|
575
|
-
return e.display = i.display, e.tex = i.tex, e.fraction = i, e.root = new
|
|
580
|
+
const i = new a(t);
|
|
581
|
+
return e.display = i.display, e.tex = i.tex, e.fraction = i, e.root = new O(), e;
|
|
576
582
|
}
|
|
577
583
|
static fromQuadratic(t, e, i) {
|
|
578
|
-
const [s, r, o] = [t, e, i].map((m) => new
|
|
579
|
-
if (
|
|
584
|
+
const [s, r, o] = [t, e, i].map((m) => new a(m)), h = r.clone().pow(2).subtract(s.clone().multiply(o).multiply(4));
|
|
585
|
+
if (h.isNegative())
|
|
580
586
|
return [];
|
|
581
|
-
if (
|
|
582
|
-
const m =
|
|
587
|
+
if (h.isSquare()) {
|
|
588
|
+
const m = h.sqrt(), d = r.clone().opposite().subtract(m).divide(s.clone().multiply(2)), v = r.clone().opposite().add(m).divide(s.clone().multiply(2));
|
|
583
589
|
return m.isZero() ? [C.fromFraction(d)] : [C.fromFraction(d), C.fromFraction(v)];
|
|
584
590
|
}
|
|
585
591
|
const c = new C();
|
|
586
|
-
c.fraction = r.clone().opposite().divide(s).divide(2), c.root = new
|
|
592
|
+
c.fraction = r.clone().opposite().divide(s).divide(2), c.root = new O().from(2, h, s.clone().multiply(2).inverse().opposite()), c.setExact(!1);
|
|
587
593
|
const f = new C();
|
|
588
|
-
return f.fraction = r.clone().opposite().divide(s).divide(2), f.root = new
|
|
594
|
+
return f.fraction = r.clone().opposite().divide(s).divide(2), f.root = new O().from(2, h, s.clone().multiply(2).inverse()), f.setExact(!1), [c, f];
|
|
589
595
|
}
|
|
590
596
|
get count() {
|
|
591
597
|
return this.#t;
|
|
@@ -687,15 +693,15 @@ class R {
|
|
|
687
693
|
}
|
|
688
694
|
#s(t, e) {
|
|
689
695
|
const i = new C();
|
|
690
|
-
return i.exact = !1, i.tex = e?.tex ?? null, i.display = e?.display ?? null, i.fraction = new
|
|
696
|
+
return i.exact = !1, i.tex = e?.tex ?? null, i.display = e?.display ?? null, i.fraction = new a(t), i.fraction.exact = !1, i.variable = this.#i, i;
|
|
691
697
|
}
|
|
692
698
|
#r(t) {
|
|
693
|
-
return t instanceof
|
|
699
|
+
return t instanceof a && !t.exact ? this.#s(t.value) : C.fromFraction(t);
|
|
694
700
|
}
|
|
695
701
|
// Solve using bissection algorithm (approximative solution)
|
|
696
702
|
#n(t) {
|
|
697
|
-
const e = [], i = t.degree().value, [s, ...r] = t.getCoefficients(), o = 2 + Math.max(...r.map((f) => f.value / s.value)),
|
|
698
|
-
return this.#c(
|
|
703
|
+
const e = [], i = t.degree().value, [s, ...r] = t.getCoefficients(), o = 2 + Math.max(...r.map((f) => f.value / s.value)), h = this.#a(t, o, 100);
|
|
704
|
+
return this.#c(h, i).forEach((f) => {
|
|
699
705
|
const [m, d] = f;
|
|
700
706
|
if (m === d)
|
|
701
707
|
e.push(this.#r(m));
|
|
@@ -712,21 +718,21 @@ class R {
|
|
|
712
718
|
let o;
|
|
713
719
|
for (; (i - e) / 2 > this.#t; ) {
|
|
714
720
|
this._++, o = (e + i) / 2;
|
|
715
|
-
const
|
|
716
|
-
if (
|
|
721
|
+
const h = t.evaluate(o, !0);
|
|
722
|
+
if (h === 0)
|
|
717
723
|
return o;
|
|
718
|
-
s *
|
|
724
|
+
s * h < 0 ? (i = o, r = h) : (e = o, s = h);
|
|
719
725
|
}
|
|
720
726
|
return (e + i) / 2;
|
|
721
727
|
}
|
|
722
728
|
#a(t, e, i) {
|
|
723
729
|
const s = [], r = 2 * e / i;
|
|
724
730
|
for (let o = -e; o <= e; o += r) {
|
|
725
|
-
const
|
|
731
|
+
const h = b.numberCorrection(o);
|
|
726
732
|
s.push(
|
|
727
733
|
{
|
|
728
|
-
x:
|
|
729
|
-
fx: t.evaluate(
|
|
734
|
+
x: h,
|
|
735
|
+
fx: t.evaluate(h, !0)
|
|
730
736
|
}
|
|
731
737
|
);
|
|
732
738
|
}
|
|
@@ -750,10 +756,10 @@ class R {
|
|
|
750
756
|
const d = t.monoms.reduce((q, $) => $.degree().value < q.degree().value ? $ : q), v = d.coefficient;
|
|
751
757
|
d.clone().divide(v), t.divide(d);
|
|
752
758
|
}
|
|
753
|
-
const o = b.dividers(s.value),
|
|
759
|
+
const o = b.dividers(s.value), h = b.dividers(r.value), c = [];
|
|
754
760
|
for (const d of o)
|
|
755
|
-
for (const v of
|
|
756
|
-
const q = new
|
|
761
|
+
for (const v of h) {
|
|
762
|
+
const q = new a(v, d);
|
|
757
763
|
c.find(($) => $.value === q.value) || (c.push(q.clone()), c.push(q.opposite().clone()));
|
|
758
764
|
}
|
|
759
765
|
c.forEach((d) => {
|
|
@@ -775,7 +781,7 @@ class R {
|
|
|
775
781
|
};
|
|
776
782
|
}
|
|
777
783
|
#h() {
|
|
778
|
-
const t = this.#e, e = t.monomByDegree(3).coefficient, i = t.monomByDegree(2).coefficient, s = t.monomByDegree(1).coefficient, r = t.monomByDegree(0).coefficient, o = i.clone().divide(e),
|
|
784
|
+
const t = this.#e, e = t.monomByDegree(3).coefficient, i = t.monomByDegree(2).coefficient, s = t.monomByDegree(1).coefficient, r = t.monomByDegree(0).coefficient, o = i.clone().divide(e), h = s.clone().divide(e), c = r.clone().divide(e), f = h.clone().subtract(o.clone().pow(2).divide(3)), m = c.clone().subtract(o.clone().multiply(h).divide(3)).add(o.clone().pow(3).multiply(2).divide(27)), d = m.clone().opposite(), v = f.clone().opposite().pow(3).divide(27), q = d.clone().pow(2).subtract(v.clone().multiply(4)).opposite();
|
|
779
785
|
if (q.isNegative()) {
|
|
780
786
|
const $ = m.clone().opposite().add(q.clone().opposite().sqrt()).divide(2).root(3), k = m.clone().opposite().subtract(q.clone().opposite().sqrt()).divide(2).root(3), I = $.clone().add(k).subtract(o.clone().divide(3));
|
|
781
787
|
return [this.#r(I)];
|
|
@@ -785,12 +791,12 @@ class R {
|
|
|
785
791
|
return k.isEqual(I) ? [this.#r(k)] : [
|
|
786
792
|
this.#r(I),
|
|
787
793
|
this.#r(k)
|
|
788
|
-
].sort((
|
|
794
|
+
].sort((Q, M) => Q.value - M.value);
|
|
789
795
|
}
|
|
790
796
|
if (q.isPositive()) {
|
|
791
|
-
const $ = [], k = f.value, I = m.value,
|
|
797
|
+
const $ = [], k = f.value, I = m.value, Q = o.value;
|
|
792
798
|
for (let M = 0; M < 3; M++)
|
|
793
|
-
$.push(2 * Math.sqrt(-k / 3) * Math.cos(Math.acos(3 * I / (2 * k) * Math.sqrt(-3 / k)) / 3 + 2 * Math.PI * M / 3) -
|
|
799
|
+
$.push(2 * Math.sqrt(-k / 3) * Math.cos(Math.acos(3 * I / (2 * k) * Math.sqrt(-3 / k)) / 3 + 2 * Math.PI * M / 3) - Q / 3);
|
|
794
800
|
return $.map((M) => this.#s(M)).sort((M, ut) => M.value - ut.value);
|
|
795
801
|
}
|
|
796
802
|
return [];
|
|
@@ -808,13 +814,13 @@ class R {
|
|
|
808
814
|
if (r.isNegative())
|
|
809
815
|
return [];
|
|
810
816
|
if (r.isSquare()) {
|
|
811
|
-
const o = r.sqrt(),
|
|
817
|
+
const o = r.sqrt(), h = i.clone().opposite().subtract(o).divide(e.clone().multiply(2)), c = i.clone().opposite().add(o).divide(e.clone().multiply(2));
|
|
812
818
|
if (o.isZero()) {
|
|
813
|
-
const f = this.#r(
|
|
819
|
+
const f = this.#r(h);
|
|
814
820
|
return f.count = 2, [f];
|
|
815
821
|
}
|
|
816
822
|
return [
|
|
817
|
-
this.#r(
|
|
823
|
+
this.#r(h),
|
|
818
824
|
this.#r(c)
|
|
819
825
|
].sort((f, m) => f.value - m.value);
|
|
820
826
|
}
|
|
@@ -822,9 +828,9 @@ class R {
|
|
|
822
828
|
}
|
|
823
829
|
#d(t, e, i) {
|
|
824
830
|
const s = t.clone().multiply(2), r = new C();
|
|
825
|
-
r.fraction = e.clone().opposite().divide(s.clone()), r.root.radical = i.clone(), r.root.factor = new
|
|
831
|
+
r.fraction = e.clone().opposite().divide(s.clone()), r.root.radical = i.clone(), r.root.factor = new a().one().divide(s.clone()), r.exact = !0;
|
|
826
832
|
const o = new C();
|
|
827
|
-
return o.fraction = e.clone().opposite().divide(s.clone()), o.root.radical = i.clone(), o.root.factor = new
|
|
833
|
+
return o.fraction = e.clone().opposite().divide(s.clone()), o.root.radical = i.clone(), o.root.factor = new a().one().divide(s.clone()).opposite(), o.exact = !0, [r, o].sort((h, c) => h.value - c.value);
|
|
828
834
|
}
|
|
829
835
|
}
|
|
830
836
|
const tt = {
|
|
@@ -840,7 +846,7 @@ function Et(n, t) {
|
|
|
840
846
|
const i = new RegExp(`^(${e.join("|")})\\(`), s = Object.keys(tt);
|
|
841
847
|
s.sort((d, v) => v.length - d.length);
|
|
842
848
|
const r = new RegExp(`^(${s.join("|")})`), o = /^(\d+(\.\d+)?)/;
|
|
843
|
-
let
|
|
849
|
+
let h = "", c, f, m;
|
|
844
850
|
for (e.forEach((d) => {
|
|
845
851
|
if (n.includes(d)) {
|
|
846
852
|
const v = new RegExp(`${d}([0-9.]+)`, "g");
|
|
@@ -879,9 +885,9 @@ function Et(n, t) {
|
|
|
879
885
|
}
|
|
880
886
|
if (m === void 0 || f === void 0)
|
|
881
887
|
throw new Error("The token is undefined");
|
|
882
|
-
|
|
888
|
+
h += Nt(c, f), h += m;
|
|
883
889
|
}
|
|
884
|
-
return
|
|
890
|
+
return h;
|
|
885
891
|
}
|
|
886
892
|
function Nt(n, t) {
|
|
887
893
|
return n === void 0 || n === u.OPERATION || t === u.OPERATION || n === u.LEFT_PARENTHESIS || n === u.FUNCTION || n === u.FUNCTION_ARGUMENT || t === u.RIGHT_PARENTHESIS || t === u.FUNCTION_ARGUMENT ? "" : "*";
|
|
@@ -892,7 +898,7 @@ const At = {
|
|
|
892
898
|
"/": { precedence: 3, associative: "left", type: u.OPERATION },
|
|
893
899
|
"+": { precedence: 2, associative: "left", type: u.OPERATION },
|
|
894
900
|
"-": { precedence: 2, associative: "left", type: u.OPERATION }
|
|
895
|
-
},
|
|
901
|
+
}, Ot = {
|
|
896
902
|
"^": { precedence: 4, associative: "right", type: u.OPERATION },
|
|
897
903
|
"*": { precedence: 3, associative: "left", type: u.OPERATION },
|
|
898
904
|
"/": { precedence: 3, associative: "left", type: u.OPERATION },
|
|
@@ -905,7 +911,7 @@ const At = {
|
|
|
905
911
|
sqrt: { precedence: 4, associative: "right", type: u.FUNCTION },
|
|
906
912
|
nthrt: { precedence: 4, associative: "right", type: u.FUNCTION },
|
|
907
913
|
",": { precedence: 2, associative: "left", type: u.FUNCTION_ARGUMENT }
|
|
908
|
-
},
|
|
914
|
+
}, Tt = {
|
|
909
915
|
"^": { precedence: 4, associative: "right", type: u.OPERATION },
|
|
910
916
|
"*": { precedence: 3, associative: "left", type: u.OPERATION },
|
|
911
917
|
"/": { precedence: 3, associative: "left", type: u.OPERATION },
|
|
@@ -925,7 +931,7 @@ const At = {
|
|
|
925
931
|
"!": { precedence: 4, associative: "right", type: u.OPERATION },
|
|
926
932
|
"-": { precedence: 2, associative: "left", type: u.OPERATION }
|
|
927
933
|
};
|
|
928
|
-
class
|
|
934
|
+
class W {
|
|
929
935
|
#t;
|
|
930
936
|
#e = [];
|
|
931
937
|
#i = {};
|
|
@@ -942,7 +948,7 @@ class G {
|
|
|
942
948
|
return this.#e.map((t) => t.token);
|
|
943
949
|
}
|
|
944
950
|
tokenConfigInitialization() {
|
|
945
|
-
return this.#t === S.SET ? (this.#i = Ct, this.#r = !1) : this.#t === S.NUMERIC ? (this.#i =
|
|
951
|
+
return this.#t === S.SET ? (this.#i = Ct, this.#r = !1) : this.#t === S.NUMERIC ? (this.#i = Tt, this.#r = !0) : this.#t === S.EXPRESSION ? (this.#i = Ot, this.#r = !0) : (this.#i = At, this.#r = !0), this.#s = Object.keys(this.#i).sort((t, e) => e.length - t.length), this.#i;
|
|
946
952
|
}
|
|
947
953
|
/**
|
|
948
954
|
* Get the next token to analyse.
|
|
@@ -990,7 +996,7 @@ class G {
|
|
|
990
996
|
*/
|
|
991
997
|
parse(t, e) {
|
|
992
998
|
const i = [], s = [];
|
|
993
|
-
let r = "", o = 0,
|
|
999
|
+
let r = "", o = 0, h;
|
|
994
1000
|
(e ?? this.#r) && (t = Et(t, this.#i));
|
|
995
1001
|
let c = 50, f;
|
|
996
1002
|
for (; o < t.length; ) {
|
|
@@ -998,14 +1004,14 @@ class G {
|
|
|
998
1004
|
console.log("SECURITY LEVEL 1 EXIT");
|
|
999
1005
|
break;
|
|
1000
1006
|
}
|
|
1001
|
-
switch ([r, o,
|
|
1007
|
+
switch ([r, o, h] = this.NextToken(t, o), h) {
|
|
1002
1008
|
case u.MONOM:
|
|
1003
1009
|
case u.COEFFICIENT:
|
|
1004
1010
|
case u.VARIABLE:
|
|
1005
1011
|
case u.CONSTANT:
|
|
1006
1012
|
i.push({
|
|
1007
1013
|
token: r,
|
|
1008
|
-
tokenType:
|
|
1014
|
+
tokenType: h
|
|
1009
1015
|
});
|
|
1010
1016
|
break;
|
|
1011
1017
|
case u.OPERATION:
|
|
@@ -1023,7 +1029,7 @@ class G {
|
|
|
1023
1029
|
m = s[s.length - 1];
|
|
1024
1030
|
}
|
|
1025
1031
|
}
|
|
1026
|
-
s.push({ token: r, tokenType:
|
|
1032
|
+
s.push({ token: r, tokenType: h });
|
|
1027
1033
|
break;
|
|
1028
1034
|
case u.FUNCTION_ARGUMENT:
|
|
1029
1035
|
for (f = 50; s[s.length - 1].token !== "(" && s.length > 0; ) {
|
|
@@ -1031,11 +1037,11 @@ class G {
|
|
|
1031
1037
|
console.log("SECURITY LEVEL 2 FUNCTION ARGUMENT EXIT");
|
|
1032
1038
|
break;
|
|
1033
1039
|
}
|
|
1034
|
-
i.push(s.pop() ?? { token: r, tokenType:
|
|
1040
|
+
i.push(s.pop() ?? { token: r, tokenType: h });
|
|
1035
1041
|
}
|
|
1036
1042
|
break;
|
|
1037
1043
|
case u.LEFT_PARENTHESIS:
|
|
1038
|
-
s.push({ token: r, tokenType:
|
|
1044
|
+
s.push({ token: r, tokenType: h }), t[o] === "-" && i.push({ token: "0", tokenType: u.COEFFICIENT });
|
|
1039
1045
|
break;
|
|
1040
1046
|
case u.RIGHT_PARENTHESIS:
|
|
1041
1047
|
for (f = 50; s[s.length - 1].token !== "(" && s.length > 1; ) {
|
|
@@ -1043,12 +1049,12 @@ class G {
|
|
|
1043
1049
|
console.log("SECURITY LEVEL 2 CLOSING PARENTHESIS EXIT");
|
|
1044
1050
|
break;
|
|
1045
1051
|
}
|
|
1046
|
-
i.push(s.pop() ?? { token: r, tokenType:
|
|
1052
|
+
i.push(s.pop() ?? { token: r, tokenType: h });
|
|
1047
1053
|
}
|
|
1048
1054
|
s.pop();
|
|
1049
1055
|
break;
|
|
1050
1056
|
case u.FUNCTION:
|
|
1051
|
-
s.push({ token: r, tokenType:
|
|
1057
|
+
s.push({ token: r, tokenType: h });
|
|
1052
1058
|
break;
|
|
1053
1059
|
default:
|
|
1054
1060
|
throw new Error(`Token type ${r} is not handled`);
|
|
@@ -1064,7 +1070,7 @@ class qt {
|
|
|
1064
1070
|
constructor(t, e) {
|
|
1065
1071
|
this._expression = t;
|
|
1066
1072
|
try {
|
|
1067
|
-
this._rpn = new
|
|
1073
|
+
this._rpn = new W(S.NUMERIC).parse(t, e).rpn;
|
|
1068
1074
|
} catch (i) {
|
|
1069
1075
|
throw this._rpn = null, this._isValid = !1, console.warn(i), new Error(`There was a problem parsing: ${t}`);
|
|
1070
1076
|
}
|
|
@@ -1164,7 +1170,7 @@ class p {
|
|
|
1164
1170
|
#t;
|
|
1165
1171
|
#e;
|
|
1166
1172
|
constructor(t) {
|
|
1167
|
-
return this.#t = new
|
|
1173
|
+
return this.#t = new a().zero(), this.#e = {}, t !== void 0 && this.parse(t), this;
|
|
1168
1174
|
}
|
|
1169
1175
|
// -----------------------------------------
|
|
1170
1176
|
/**
|
|
@@ -1172,7 +1178,7 @@ class p {
|
|
|
1172
1178
|
* @param inputStr
|
|
1173
1179
|
*/
|
|
1174
1180
|
parse(t) {
|
|
1175
|
-
return this.#t = new
|
|
1181
|
+
return this.#t = new a(), this.#e = {}, t instanceof p ? (this.#t = t.#t.clone(), this.#i(t), this) : t instanceof a ? (this.#t = t.clone(), this) : typeof t == "number" ? (this.#t = new a(t), this) : (isNaN(Number(t)) ? this.#a(t) : this.#t = new a(Number(t)), this);
|
|
1176
1182
|
}
|
|
1177
1183
|
/**
|
|
1178
1184
|
* Clone the current Monom.
|
|
@@ -1202,12 +1208,12 @@ class p {
|
|
|
1202
1208
|
if (r.containsRationalPower())
|
|
1203
1209
|
return new p().zero();
|
|
1204
1210
|
const e = new p(), i = b.gcd(...t.map((r) => r.coefficient.numerator)), s = b.lcm(...t.map((r) => r.coefficient.denominator));
|
|
1205
|
-
e.coefficient = new
|
|
1211
|
+
e.coefficient = new a(i, s).reduce();
|
|
1206
1212
|
for (const r of t) {
|
|
1207
1213
|
for (const o in e.literal)
|
|
1208
1214
|
o in r.literal || e.removeVariable(o);
|
|
1209
1215
|
for (const o in r.literal)
|
|
1210
|
-
!e.hasVariable(o) && r.literal[o].isStrictlyPositive() ? e.literal[o] = r.literal[o].clone() : e.literal[o] = new
|
|
1216
|
+
!e.hasVariable(o) && r.literal[o].isStrictlyPositive() ? e.literal[o] = r.literal[o].clone() : e.literal[o] = new a(Math.min(r.literal[o].value, e.literal[o].value));
|
|
1211
1217
|
}
|
|
1212
1218
|
return e;
|
|
1213
1219
|
};
|
|
@@ -1247,14 +1253,14 @@ class p {
|
|
|
1247
1253
|
* @param {Fraction | number | string} F
|
|
1248
1254
|
*/
|
|
1249
1255
|
set coefficient(t) {
|
|
1250
|
-
this.#t = new
|
|
1256
|
+
this.#t = new a(t);
|
|
1251
1257
|
}
|
|
1252
1258
|
containsRationalPower = () => Object.values(this.#e).some((t) => t.isRational());
|
|
1253
1259
|
/**
|
|
1254
1260
|
* Get the degree of a monom. If no setLetter is given, the result will be the global degree.
|
|
1255
1261
|
* @param letter (string) Letter to get to degree (power)
|
|
1256
1262
|
*/
|
|
1257
|
-
degree = (t) => this.variables.length === 0 ? new
|
|
1263
|
+
degree = (t) => this.variables.length === 0 ? new a().zero() : t === void 0 ? Object.values(this.#e).reduce((e, i) => e.clone().add(i)) : this.hasVariable(t) ? this.#e[t].clone() : new a().zero();
|
|
1258
1264
|
/**
|
|
1259
1265
|
* Derivative the monom
|
|
1260
1266
|
* @param letter
|
|
@@ -1262,7 +1268,7 @@ class p {
|
|
|
1262
1268
|
derivative = (t = "x") => {
|
|
1263
1269
|
if (this.hasVariable(t)) {
|
|
1264
1270
|
const e = this.#e[t].clone(), i = this.clone();
|
|
1265
|
-
return i.#e[t].subtract(1), i.#t.multiply(new
|
|
1271
|
+
return i.#e[t].subtract(1), i.#t.multiply(new a(e.clone())), i;
|
|
1266
1272
|
} else
|
|
1267
1273
|
return new p().zero();
|
|
1268
1274
|
};
|
|
@@ -1295,17 +1301,17 @@ class p {
|
|
|
1295
1301
|
for (const s of t)
|
|
1296
1302
|
for (const r of e) {
|
|
1297
1303
|
const o = new p();
|
|
1298
|
-
o.coefficient = new
|
|
1304
|
+
o.coefficient = new a(s), o.literal = r, i.push(o);
|
|
1299
1305
|
}
|
|
1300
1306
|
else if (t.length === 0)
|
|
1301
1307
|
for (const s of e) {
|
|
1302
1308
|
const r = new p();
|
|
1303
|
-
r.coefficient = new
|
|
1309
|
+
r.coefficient = new a().one(), r.literal = s, i.push(r);
|
|
1304
1310
|
}
|
|
1305
1311
|
else
|
|
1306
1312
|
for (const s of t) {
|
|
1307
1313
|
const r = new p();
|
|
1308
|
-
r.coefficient = new
|
|
1314
|
+
r.coefficient = new a(s), i.push(r);
|
|
1309
1315
|
}
|
|
1310
1316
|
return i.length === 0 ? [new p().one()] : i;
|
|
1311
1317
|
}
|
|
@@ -1316,27 +1322,27 @@ class p {
|
|
|
1316
1322
|
*/
|
|
1317
1323
|
evaluate = (t, e) => {
|
|
1318
1324
|
if (e === !0) {
|
|
1319
|
-
if (t instanceof
|
|
1325
|
+
if (t instanceof a)
|
|
1320
1326
|
return this.#s(t.value);
|
|
1321
1327
|
if (typeof t == "number")
|
|
1322
1328
|
return this.#s(t);
|
|
1323
1329
|
if (typeof t == "object") {
|
|
1324
1330
|
const s = {};
|
|
1325
1331
|
for (const r in t)
|
|
1326
|
-
s[r] = new
|
|
1332
|
+
s[r] = new a(t[r]).value;
|
|
1327
1333
|
return this.#s(s);
|
|
1328
1334
|
}
|
|
1329
1335
|
}
|
|
1330
1336
|
const i = this.coefficient.clone();
|
|
1331
|
-
if (typeof t == "number" || t instanceof
|
|
1337
|
+
if (typeof t == "number" || t instanceof a) {
|
|
1332
1338
|
const s = {};
|
|
1333
|
-
return s[this.variables[0]] = new
|
|
1339
|
+
return s[this.variables[0]] = new a(t), this.evaluate(s);
|
|
1334
1340
|
}
|
|
1335
1341
|
if (typeof t == "object") {
|
|
1336
1342
|
if (this.variables.length === 0)
|
|
1337
1343
|
return this.coefficient;
|
|
1338
1344
|
for (const s in this.#e) {
|
|
1339
|
-
const r = new
|
|
1345
|
+
const r = new a(t[s]);
|
|
1340
1346
|
i.multiply(r.pow(this.#e[s]));
|
|
1341
1347
|
}
|
|
1342
1348
|
}
|
|
@@ -1423,9 +1429,9 @@ class p {
|
|
|
1423
1429
|
*/
|
|
1424
1430
|
set literalStr(t) {
|
|
1425
1431
|
for (const e of [...t.matchAll(/([a-z])\^([+-]?[0-9]+)/g)])
|
|
1426
|
-
e[1] in this.#e || (this.#e[e[1]] = new
|
|
1432
|
+
e[1] in this.#e || (this.#e[e[1]] = new a().zero()), this.#e[e[1]].add(+e[2]);
|
|
1427
1433
|
for (const e of [...t.matchAll(/([a-z](?!\^))/g)])
|
|
1428
|
-
e[1] in this.#e || (this.#e[e[1]] = new
|
|
1434
|
+
e[1] in this.#e || (this.#e[e[1]] = new a().zero()), this.#e[e[1]].add(1);
|
|
1429
1435
|
}
|
|
1430
1436
|
/**
|
|
1431
1437
|
* Multiple multiple monoms to the current monom
|
|
@@ -1443,7 +1449,7 @@ class p {
|
|
|
1443
1449
|
/**
|
|
1444
1450
|
* Create a one value monom
|
|
1445
1451
|
*/
|
|
1446
|
-
one = () => (this.#t = new
|
|
1452
|
+
one = () => (this.#t = new a().one(), this.#e = {}, this);
|
|
1447
1453
|
/**
|
|
1448
1454
|
* Get the opposite
|
|
1449
1455
|
* Returns a monom.
|
|
@@ -1465,7 +1471,7 @@ class p {
|
|
|
1465
1471
|
primitive = (t = "x") => {
|
|
1466
1472
|
const e = this.clone();
|
|
1467
1473
|
let i;
|
|
1468
|
-
return e.hasVariable(t) ? (i = e.degree(t).clone().add(1), e.coefficient = e.coefficient.clone().divide(i), e.setLetter(t, i)) : (e.coefficient.isZero() && (e.coefficient = new
|
|
1474
|
+
return e.hasVariable(t) ? (i = e.degree(t).clone().add(1), e.coefficient = e.coefficient.clone().divide(i), e.setLetter(t, i)) : (e.coefficient.isZero() && (e.coefficient = new a().one()), e.setLetter(t, 1)), e;
|
|
1469
1475
|
};
|
|
1470
1476
|
reduce = () => {
|
|
1471
1477
|
this.coefficient.reduce();
|
|
@@ -1488,7 +1494,7 @@ class p {
|
|
|
1488
1494
|
* @param letter (string) Letter to change
|
|
1489
1495
|
* @param pow (number) Power of the setLetter (must be positive integer.
|
|
1490
1496
|
*/
|
|
1491
|
-
setLetter = (t, e) => e instanceof
|
|
1497
|
+
setLetter = (t, e) => e instanceof a ? this.hasVariable(t) && e.isZero() ? (this.removeVariable(t), this) : (this.#e[t] = e.clone(), this) : this.setLetter(t, new a(e));
|
|
1492
1498
|
/**
|
|
1493
1499
|
* Return the square root of a monom
|
|
1494
1500
|
*/
|
|
@@ -1529,7 +1535,7 @@ class p {
|
|
|
1529
1535
|
/**
|
|
1530
1536
|
* Create a zero value monom
|
|
1531
1537
|
*/
|
|
1532
|
-
zero = () => (this.#t = new
|
|
1538
|
+
zero = () => (this.#t = new a().zero(), this.#e = {}, this);
|
|
1533
1539
|
#i(t) {
|
|
1534
1540
|
for (const e in t.literal)
|
|
1535
1541
|
this.#e[e] = t.literal[e].clone();
|
|
@@ -1540,16 +1546,16 @@ class p {
|
|
|
1540
1546
|
const i = {}, s = this.variables[0];
|
|
1541
1547
|
return i[s] = t, this.#s(i);
|
|
1542
1548
|
}
|
|
1543
|
-
if (t instanceof
|
|
1549
|
+
if (t instanceof a) {
|
|
1544
1550
|
const i = {};
|
|
1545
|
-
return i[this.variables[0]] = new
|
|
1551
|
+
return i[this.variables[0]] = new a(t).value, this.#s(i);
|
|
1546
1552
|
}
|
|
1547
1553
|
if (typeof t == "object") {
|
|
1548
1554
|
if (this.variables.length === 0)
|
|
1549
1555
|
return this.coefficient.value;
|
|
1550
1556
|
for (const i in this.#e) {
|
|
1551
1557
|
const s = t[i];
|
|
1552
|
-
s instanceof
|
|
1558
|
+
s instanceof a ? e *= s.value ** this.#e[i].value : e *= s ** this.#e[i].value;
|
|
1553
1559
|
}
|
|
1554
1560
|
}
|
|
1555
1561
|
return e;
|
|
@@ -1567,20 +1573,20 @@ class p {
|
|
|
1567
1573
|
for (let s = 0; s <= this.literal[e].value; s++)
|
|
1568
1574
|
if (t.length === 0) {
|
|
1569
1575
|
const r = {};
|
|
1570
|
-
r[e] = new
|
|
1576
|
+
r[e] = new a(s), i.push(r);
|
|
1571
1577
|
} else
|
|
1572
1578
|
for (const r of t) {
|
|
1573
1579
|
const o = {};
|
|
1574
|
-
for (const
|
|
1575
|
-
o[
|
|
1576
|
-
o[e] = new
|
|
1580
|
+
for (const h in r)
|
|
1581
|
+
o[h] = r[h];
|
|
1582
|
+
o[e] = new a(s), i.push(o);
|
|
1577
1583
|
}
|
|
1578
1584
|
return i;
|
|
1579
1585
|
}
|
|
1580
1586
|
#o = (t, e) => {
|
|
1581
|
-
let i, s, r, o,
|
|
1587
|
+
let i, s, r, o, h;
|
|
1582
1588
|
if (e.tokenType === u.COEFFICIENT)
|
|
1583
|
-
t.push(new p(new
|
|
1589
|
+
t.push(new p(new a(e.token)));
|
|
1584
1590
|
else if (e.tokenType === u.VARIABLE) {
|
|
1585
1591
|
const c = new p().one();
|
|
1586
1592
|
c.setLetter(e.token, 1), t.push(c.clone());
|
|
@@ -1596,18 +1602,18 @@ class p {
|
|
|
1596
1602
|
s = t.pop() ?? new p().one(), i = t.pop() ?? new p().one(), t.push(i.divide(s));
|
|
1597
1603
|
break;
|
|
1598
1604
|
case "^": {
|
|
1599
|
-
|
|
1605
|
+
h = t.pop()?.coefficient ?? new a().one(), r = t.pop() ?? new p().one(), o = r.variables[0], o && r.setLetter(o, h), t.push(r);
|
|
1600
1606
|
break;
|
|
1601
1607
|
}
|
|
1602
1608
|
}
|
|
1603
1609
|
};
|
|
1604
1610
|
#a = (t) => {
|
|
1605
|
-
const i = new
|
|
1611
|
+
const i = new W().parse(t).rpn, s = [];
|
|
1606
1612
|
if (i.length === 0)
|
|
1607
1613
|
return this.zero(), this;
|
|
1608
1614
|
if (i.length === 1) {
|
|
1609
1615
|
const r = i[0];
|
|
1610
|
-
return this.one(), r.tokenType === u.COEFFICIENT ? this.coefficient = new
|
|
1616
|
+
return this.one(), r.tokenType === u.COEFFICIENT ? this.coefficient = new a(r.token) : r.tokenType === u.VARIABLE && this.setLetter(r.token, 1), this;
|
|
1611
1617
|
} else
|
|
1612
1618
|
for (const r of i)
|
|
1613
1619
|
this.#o(s, r);
|
|
@@ -1643,7 +1649,7 @@ class l {
|
|
|
1643
1649
|
parse(t, ...e) {
|
|
1644
1650
|
if (this.#i = [], this.#e = [], this.#h(), typeof t == "string")
|
|
1645
1651
|
return this.#m(t, ...e);
|
|
1646
|
-
if ((typeof t == "number" || t instanceof
|
|
1652
|
+
if ((typeof t == "number" || t instanceof a || t instanceof p) && e.length === 0)
|
|
1647
1653
|
this.#i.push(new p(t));
|
|
1648
1654
|
else if (t instanceof p && e.length > 0)
|
|
1649
1655
|
this.#i.push(new p(t)), e.forEach((i) => {
|
|
@@ -1683,19 +1689,19 @@ class l {
|
|
|
1683
1689
|
}
|
|
1684
1690
|
commonMonom() {
|
|
1685
1691
|
const t = new p().one(), e = this.gcdNumerator(), i = this.gcdDenominator();
|
|
1686
|
-
t.coefficient = new
|
|
1692
|
+
t.coefficient = new a(e, i);
|
|
1687
1693
|
for (const s of this.variables) {
|
|
1688
1694
|
t.setLetter(s, this.degree(s));
|
|
1689
1695
|
for (const r of this.#i)
|
|
1690
|
-
if (t.setLetter(s,
|
|
1696
|
+
if (t.setLetter(s, a.min(r.degree(s), t.degree(s))), t.degree(s).isZero())
|
|
1691
1697
|
break;
|
|
1692
1698
|
}
|
|
1693
1699
|
return t;
|
|
1694
1700
|
}
|
|
1695
1701
|
degree(t) {
|
|
1696
|
-
let e = new
|
|
1702
|
+
let e = new a().zero();
|
|
1697
1703
|
for (const i of this.#i)
|
|
1698
|
-
e =
|
|
1704
|
+
e = a.max(i.degree(t).value, e);
|
|
1699
1705
|
return e;
|
|
1700
1706
|
}
|
|
1701
1707
|
derivative(t) {
|
|
@@ -1705,7 +1711,7 @@ class l {
|
|
|
1705
1711
|
return e.reduce();
|
|
1706
1712
|
}
|
|
1707
1713
|
divide(t) {
|
|
1708
|
-
if (t instanceof
|
|
1714
|
+
if (t instanceof a)
|
|
1709
1715
|
return this.#o(t);
|
|
1710
1716
|
if (typeof t == "number" && Number.isSafeInteger(t))
|
|
1711
1717
|
return this.#a(t);
|
|
@@ -1741,15 +1747,15 @@ class l {
|
|
|
1741
1747
|
if (!this.degree(e).isNatural() || !t.degree(e).isNatural())
|
|
1742
1748
|
throw new Error("Euclidean division requires integer degrees");
|
|
1743
1749
|
const r = t.monomByDegree(void 0, e), o = t.degree(e);
|
|
1744
|
-
let
|
|
1745
|
-
for (; s.degree(e).isGeq(o) && c > 0 && (c--,
|
|
1750
|
+
let h, c = this.degree(e).value - o.value + 1;
|
|
1751
|
+
for (; s.degree(e).isGeq(o) && c > 0 && (c--, h = s.monomByDegree(void 0, e).clone().divide(r), !(!h.isZero() && (i.add(h), s.subtract(t.clone().multiply(h)).reduce(), h.degree(e).isZero()))); )
|
|
1746
1752
|
;
|
|
1747
1753
|
return i.reduce(), s.reduce(), { quotient: i, reminder: s };
|
|
1748
1754
|
}
|
|
1749
1755
|
evaluate(t, e) {
|
|
1750
1756
|
if (e)
|
|
1751
1757
|
return this.#c(t);
|
|
1752
|
-
const i = new
|
|
1758
|
+
const i = new a().zero();
|
|
1753
1759
|
return this.#i.forEach((s) => {
|
|
1754
1760
|
i.add(s.evaluate(t, e));
|
|
1755
1761
|
}), i;
|
|
@@ -1761,7 +1767,7 @@ class l {
|
|
|
1761
1767
|
* TODO: Handle other letter than 'x'.
|
|
1762
1768
|
*/
|
|
1763
1769
|
factorize(t) {
|
|
1764
|
-
this.#e = [];
|
|
1770
|
+
if (this.#e = [], this.monoms.length === 1) return [this.clone()];
|
|
1765
1771
|
let e = this.clone().reorder();
|
|
1766
1772
|
const i = e.commonMonom();
|
|
1767
1773
|
e.monomByDegree().coefficient.isStrictlyNegative() && i.opposite(), i.isOne() || (this.#e.push(new l(i)), e = e.euclidean(this.#e[0]).quotient);
|
|
@@ -1770,9 +1776,9 @@ class l {
|
|
|
1770
1776
|
return this.#e.length === 0 ? this.#e = [this.clone()] : this.#e.push(e), this.#e;
|
|
1771
1777
|
if (s.forEach((o) => {
|
|
1772
1778
|
if (o.exact && o.root.isZero())
|
|
1773
|
-
for (let
|
|
1779
|
+
for (let h = 0; h < o.count; h++)
|
|
1774
1780
|
o.fraction.isRational() ? this.#e.push(new l().fromCoefficients(o.fraction.denominator, -o.fraction.numerator)) : this.#e.push(new l().fromCoefficients(1, o.fraction.clone().opposite()));
|
|
1775
|
-
}), this.#e.map((o) => o.degree().value).reduce((o,
|
|
1781
|
+
}), this.#e.map((o) => o.degree().value).reduce((o, h) => o + h, 0) < this.degree().value) {
|
|
1776
1782
|
const o = l.xMultiply(...this.#e);
|
|
1777
1783
|
this.#e.push(this.clone().divide(o));
|
|
1778
1784
|
}
|
|
@@ -1786,7 +1792,7 @@ class l {
|
|
|
1786
1792
|
const e = this.#t ?? "x";
|
|
1787
1793
|
return t.reverse().forEach((i, s) => {
|
|
1788
1794
|
const r = new p();
|
|
1789
|
-
r.coefficient = new
|
|
1795
|
+
r.coefficient = new a(i), r.setLetter(e, s), this.#i.push(r);
|
|
1790
1796
|
}), this.#h(), this.reorder();
|
|
1791
1797
|
}
|
|
1792
1798
|
gcdDenominator() {
|
|
@@ -1798,7 +1804,7 @@ class l {
|
|
|
1798
1804
|
getCoefficients() {
|
|
1799
1805
|
if (!this.degree().isNatural())
|
|
1800
1806
|
throw new Error("getCoefficients() requires a polynomial with integer degrees");
|
|
1801
|
-
const t = this.clone().reorder(), e = this.degree().value + 1, i = Array.from({ length: e }, () => new
|
|
1807
|
+
const t = this.clone().reorder(), e = this.degree().value + 1, i = Array.from({ length: e }, () => new a(0));
|
|
1802
1808
|
return t.monoms.forEach((s) => {
|
|
1803
1809
|
const r = e - s.degree().value - 1;
|
|
1804
1810
|
i[r] = s.coefficient.clone();
|
|
@@ -1825,7 +1831,7 @@ class l {
|
|
|
1825
1831
|
}
|
|
1826
1832
|
integrate(t, e, i = "x") {
|
|
1827
1833
|
const s = this.primitive(i), r = {}, o = {};
|
|
1828
|
-
return r[i] = new
|
|
1834
|
+
return r[i] = new a(t), o[i] = new a(e), s.evaluate(o).subtract(s.evaluate(r));
|
|
1829
1835
|
}
|
|
1830
1836
|
inverse() {
|
|
1831
1837
|
}
|
|
@@ -1878,13 +1884,13 @@ class l {
|
|
|
1878
1884
|
return this.#i.length;
|
|
1879
1885
|
}
|
|
1880
1886
|
limitTo(t, e) {
|
|
1881
|
-
const i = new
|
|
1887
|
+
const i = new a(t);
|
|
1882
1888
|
if (i.isFinite()) {
|
|
1883
1889
|
const f = e ?? this.variables[0] ?? "x";
|
|
1884
1890
|
return this.evaluate({ [f]: i });
|
|
1885
1891
|
}
|
|
1886
1892
|
const s = this.monomByDegree(void 0, e), r = s.coefficient.sign(), o = s.degree(e);
|
|
1887
|
-
return o.isZero() ? s.coefficient.clone() : o.isStrictlyPositive() ? i.isPositive() ? r === 1 ? new
|
|
1893
|
+
return o.isZero() ? s.coefficient.clone() : o.isStrictlyPositive() ? i.isPositive() ? r === 1 ? new a().infinite() : new a().infinite().opposite() : (o.value % 2 === 0 ? r : -r) === 1 ? new a().infinite() : new a().infinite().opposite() : new a().zero();
|
|
1888
1894
|
}
|
|
1889
1895
|
monomByDegree(t, e) {
|
|
1890
1896
|
if (t === void 0)
|
|
@@ -1921,7 +1927,7 @@ class l {
|
|
|
1921
1927
|
multiply(t) {
|
|
1922
1928
|
if (t instanceof l)
|
|
1923
1929
|
return this.#p(t);
|
|
1924
|
-
if (t instanceof
|
|
1930
|
+
if (t instanceof a)
|
|
1925
1931
|
return this.#u(t);
|
|
1926
1932
|
if (t instanceof p)
|
|
1927
1933
|
return this.#d(t);
|
|
@@ -1929,7 +1935,7 @@ class l {
|
|
|
1929
1935
|
return this.#f(t);
|
|
1930
1936
|
if (typeof t == "string")
|
|
1931
1937
|
try {
|
|
1932
|
-
const e = new
|
|
1938
|
+
const e = new a(t);
|
|
1933
1939
|
return this.#u(e);
|
|
1934
1940
|
} catch {
|
|
1935
1941
|
throw new Error("Cannot multiply by this value.");
|
|
@@ -1973,9 +1979,9 @@ class l {
|
|
|
1973
1979
|
reorder(t = "x", e = !1) {
|
|
1974
1980
|
const i = this.variables.filter((s) => s !== t);
|
|
1975
1981
|
return this.#i.sort(function(s, r) {
|
|
1976
|
-
const o = s.degree(t).value,
|
|
1977
|
-
if (o !==
|
|
1978
|
-
return e ? o -
|
|
1982
|
+
const o = s.degree(t).value, h = r.degree(t).value;
|
|
1983
|
+
if (o !== h)
|
|
1984
|
+
return e ? o - h : h - o;
|
|
1979
1985
|
if (i.length > 0)
|
|
1980
1986
|
for (const c of i) {
|
|
1981
1987
|
const f = s.degree(c).value, m = r.degree(c).value;
|
|
@@ -2029,7 +2035,7 @@ class l {
|
|
|
2029
2035
|
let e = new Array(2 * t.length + 1).fill("").map((i, s) => s % 2 === 0 ? "" : "z");
|
|
2030
2036
|
if (e.length === 1) {
|
|
2031
2037
|
const [i] = this.getCoefficients().map((s) => s.value);
|
|
2032
|
-
e =
|
|
2038
|
+
e = F(e, "", i > 0 ? "+" : "-");
|
|
2033
2039
|
} else if (this.degree().isOne()) {
|
|
2034
2040
|
const [i] = this.getCoefficients().map((s) => s.value);
|
|
2035
2041
|
e[0] = i > 0 ? "-" : "+", e[1] = "z", e[2] = i > 0 ? "+" : "-";
|
|
@@ -2078,7 +2084,7 @@ class l {
|
|
|
2078
2084
|
return this.#h(), this;
|
|
2079
2085
|
}
|
|
2080
2086
|
#a(t) {
|
|
2081
|
-
const e = new
|
|
2087
|
+
const e = new a(t);
|
|
2082
2088
|
for (const i of this.#i)
|
|
2083
2089
|
i.coefficient.divide(e);
|
|
2084
2090
|
return this.#h(), this;
|
|
@@ -2094,8 +2100,8 @@ class l {
|
|
|
2094
2100
|
for (const o of this.#i) {
|
|
2095
2101
|
if (o.coefficient.value === 0)
|
|
2096
2102
|
continue;
|
|
2097
|
-
let
|
|
2098
|
-
s ?
|
|
2103
|
+
let h;
|
|
2104
|
+
s ? h = o.plotFunction : h = t === "tex" ? o.tex : o.display, r += `${o.coefficient.sign() === 1 && (r !== "" || e === !0) ? "+" : ""}${h}`;
|
|
2099
2105
|
}
|
|
2100
2106
|
return i === !0 && this.length > 1 && (t === "tex" ? r = `\\left( ${r} \\right)` : r = `(${r})`), r === "" && (r = "0"), r;
|
|
2101
2107
|
}
|
|
@@ -2108,7 +2114,7 @@ class l {
|
|
|
2108
2114
|
return this.reduce();
|
|
2109
2115
|
}
|
|
2110
2116
|
#f(t) {
|
|
2111
|
-
return this.#u(new
|
|
2117
|
+
return this.#u(new a(t));
|
|
2112
2118
|
}
|
|
2113
2119
|
#d(t) {
|
|
2114
2120
|
for (const e of this.#i)
|
|
@@ -2132,15 +2138,15 @@ class l {
|
|
|
2132
2138
|
return this.#w(t);
|
|
2133
2139
|
} else if (/^[a-z]+$/.test(t)) {
|
|
2134
2140
|
this.empty();
|
|
2135
|
-
const i = e.map((s) => new
|
|
2141
|
+
const i = e.map((s) => new a(s));
|
|
2136
2142
|
if (t.length > 1) {
|
|
2137
2143
|
const s = t.split("");
|
|
2138
2144
|
if (i.length > s.length + 1)
|
|
2139
2145
|
throw new Error(`Too many values: ${s.length} letters but ${i.length} values provided`);
|
|
2140
2146
|
let r = 0;
|
|
2141
2147
|
for (const o of i) {
|
|
2142
|
-
const
|
|
2143
|
-
|
|
2148
|
+
const h = new p();
|
|
2149
|
+
h.coefficient = o.clone(), h.literalStr = s[r] ?? "", this.add(h), r++;
|
|
2144
2150
|
}
|
|
2145
2151
|
} else {
|
|
2146
2152
|
let s = i.length - 1;
|
|
@@ -2207,7 +2213,7 @@ class l {
|
|
|
2207
2213
|
* @param inputStr
|
|
2208
2214
|
*/
|
|
2209
2215
|
#w(t) {
|
|
2210
|
-
const i = new
|
|
2216
|
+
const i = new W().parse(t).rpn;
|
|
2211
2217
|
this.zero();
|
|
2212
2218
|
const s = [];
|
|
2213
2219
|
for (const r of i)
|
|
@@ -2273,7 +2279,7 @@ class x {
|
|
|
2273
2279
|
* Get the degree of the equation
|
|
2274
2280
|
* @param letter
|
|
2275
2281
|
*/
|
|
2276
|
-
degree = (t) =>
|
|
2282
|
+
degree = (t) => a.max(this.#t.degree(t), this.#e.degree(t));
|
|
2277
2283
|
/**
|
|
2278
2284
|
* divide an equation by a given value (transformed as a fraction)
|
|
2279
2285
|
*
|
|
@@ -2289,7 +2295,7 @@ class x {
|
|
|
2289
2295
|
* @returns {Equation}
|
|
2290
2296
|
*/
|
|
2291
2297
|
divide = (t) => {
|
|
2292
|
-
const e = new
|
|
2298
|
+
const e = new a(t);
|
|
2293
2299
|
return e.isZero() ? this : this.multiply(e.inverse());
|
|
2294
2300
|
};
|
|
2295
2301
|
/**
|
|
@@ -2363,7 +2369,7 @@ class x {
|
|
|
2363
2369
|
* @param value
|
|
2364
2370
|
*/
|
|
2365
2371
|
multiply = (t) => {
|
|
2366
|
-
const e = new
|
|
2372
|
+
const e = new a(t);
|
|
2367
2373
|
return this.#t.multiply(e), this.#e.multiply(e), this.#i !== "=" && e.sign() === -1 && this.#n(), this;
|
|
2368
2374
|
};
|
|
2369
2375
|
get numberOfVars() {
|
|
@@ -2451,7 +2457,7 @@ class y {
|
|
|
2451
2457
|
#i;
|
|
2452
2458
|
#s = !1;
|
|
2453
2459
|
constructor(t, e) {
|
|
2454
|
-
return t instanceof y ? (this.#e = t.polynom.clone(), this.#i = t.power.clone(), e !== void 0 && this.#i.multiply(new
|
|
2460
|
+
return t instanceof y ? (this.#e = t.polynom.clone(), this.#i = t.power.clone(), e !== void 0 && this.#i.multiply(new a(e))) : t !== void 0 ? (this.#e = new l(t), this.#i = new a(e ?? 1)) : (this.#e = new l(), this.#i = new a(1)), this.#t = 1, this;
|
|
2455
2461
|
}
|
|
2456
2462
|
parse() {
|
|
2457
2463
|
throw new Error("Method not implemented.");
|
|
@@ -2502,7 +2508,7 @@ class y {
|
|
|
2502
2508
|
return e ? this.polynom.evaluate(t, !0) ** this.power.value : this.polynom.evaluate(t).pow(this.power);
|
|
2503
2509
|
}
|
|
2504
2510
|
fromPolynom(t) {
|
|
2505
|
-
return this.#e = new l(t), this.#i = new
|
|
2511
|
+
return this.#e = new l(t), this.#i = new a(1), this;
|
|
2506
2512
|
}
|
|
2507
2513
|
hasVariable(t) {
|
|
2508
2514
|
return this.polynom.hasVariable(t);
|
|
@@ -2524,10 +2530,13 @@ class y {
|
|
|
2524
2530
|
return this.polynom.isZero();
|
|
2525
2531
|
}
|
|
2526
2532
|
multiply(t) {
|
|
2533
|
+
const e = new y(t);
|
|
2534
|
+
if (this.polynom.monoms.length === 1 && this.power.isOne() && e.polynom.monoms.length === 1 && this.power.isOne())
|
|
2535
|
+
return this.polynom.multiply(e.polynom), this;
|
|
2527
2536
|
if (t instanceof y && this.isSameAs(t))
|
|
2528
2537
|
return this.power.add(t.power), this;
|
|
2529
|
-
const
|
|
2530
|
-
if (this.isSameAs(
|
|
2538
|
+
const i = new l(t);
|
|
2539
|
+
if (this.isSameAs(i))
|
|
2531
2540
|
return this.power.add(1), this;
|
|
2532
2541
|
throw new Error("The two factors must be the same");
|
|
2533
2542
|
}
|
|
@@ -2550,7 +2559,7 @@ class y {
|
|
|
2550
2559
|
return this.#i;
|
|
2551
2560
|
}
|
|
2552
2561
|
set power(t) {
|
|
2553
|
-
this.#i = new
|
|
2562
|
+
this.#i = new a(t);
|
|
2554
2563
|
}
|
|
2555
2564
|
primitive() {
|
|
2556
2565
|
throw new Error("Method not implemented.");
|
|
@@ -2569,7 +2578,7 @@ class y {
|
|
|
2569
2578
|
}
|
|
2570
2579
|
tableOfSigns() {
|
|
2571
2580
|
const t = this.power.clone().reduce(), e = this.polynom.tableOfSigns();
|
|
2572
|
-
return t.isStrictlyNegative() && (e.signs =
|
|
2581
|
+
return t.isStrictlyNegative() && (e.signs = F(e.signs, "z", "d")), t.denominator % 2 === 0 ? e.signs = F(e.signs, "-", "h") : t.numerator % 2 === 0 && (e.signs = F(e.signs, "-", "+")), { roots: e.roots, signs: e.signs };
|
|
2573
2582
|
}
|
|
2574
2583
|
get variables() {
|
|
2575
2584
|
return this.polynom.variables;
|
|
@@ -2595,14 +2604,14 @@ class y {
|
|
|
2595
2604
|
const i = e ? 1 : -1, s = [], r = /\(([^)]+)\)(?:\^(-?[0-9]+(?:\/[0-9]+)?|\(-?[0-9]+(?:\/[0-9]+)?\)))?|([^(]+)/g;
|
|
2596
2605
|
for (const o of t.matchAll(r))
|
|
2597
2606
|
if (o[1] !== void 0) {
|
|
2598
|
-
const
|
|
2607
|
+
const h = (o[2] ?? "1").replace(/[()]/g, "");
|
|
2599
2608
|
s.push(
|
|
2600
2609
|
new y(
|
|
2601
2610
|
new l(o[1]),
|
|
2602
|
-
new h
|
|
2611
|
+
new a(h).multiply(i)
|
|
2603
2612
|
)
|
|
2604
2613
|
);
|
|
2605
|
-
} else o[3]?.trim() && s.push(new y(new l(o[3].trim()), new
|
|
2614
|
+
} else o[3]?.trim() && s.push(new y(new l(o[3].trim()), new a(i)));
|
|
2606
2615
|
return s;
|
|
2607
2616
|
}
|
|
2608
2617
|
}
|
|
@@ -2674,11 +2683,11 @@ class P {
|
|
|
2674
2683
|
}
|
|
2675
2684
|
o.push(i.join("&"));
|
|
2676
2685
|
}
|
|
2677
|
-
let
|
|
2678
|
-
return e !== void 0 && e.length > 0 && (
|
|
2686
|
+
let h = 0;
|
|
2687
|
+
return e !== void 0 && e.length > 0 && (h = e[0].length), `\\left\\{\\begin{array}{${"r".repeat(r.length)}cl ${"|l".repeat(h)}}${o.join("\\\\ ")}\\end{array}\\right.`;
|
|
2679
2688
|
};
|
|
2680
2689
|
degree(t) {
|
|
2681
|
-
return
|
|
2690
|
+
return a.max(...this.#t.map((e) => e.degree(t)));
|
|
2682
2691
|
}
|
|
2683
2692
|
// ------------------------------------------
|
|
2684
2693
|
get equations() {
|
|
@@ -2732,9 +2741,9 @@ class P {
|
|
|
2732
2741
|
for (let s = 0; s < t.length; s++) {
|
|
2733
2742
|
let r = i[s][s].clone();
|
|
2734
2743
|
if (r.isZero()) {
|
|
2735
|
-
const o = i.find((
|
|
2744
|
+
const o = i.find((h, c) => c > s && !h[s].isZero());
|
|
2736
2745
|
if (o)
|
|
2737
|
-
i[s].forEach((
|
|
2746
|
+
i[s].forEach((h, c) => h.add(o[c])), r = i[s][s].clone();
|
|
2738
2747
|
else
|
|
2739
2748
|
throw new Error("Unsolvable...");
|
|
2740
2749
|
}
|
|
@@ -2742,9 +2751,9 @@ class P {
|
|
|
2742
2751
|
for (let o = 0; o < t.length; o++) {
|
|
2743
2752
|
if (o === s)
|
|
2744
2753
|
continue;
|
|
2745
|
-
const
|
|
2754
|
+
const h = i[o][s].clone().opposite();
|
|
2746
2755
|
for (let c = 0; c < i[o].length; c++)
|
|
2747
|
-
i[o][c].add(i[s][c].clone().multiply(
|
|
2756
|
+
i[o][c].add(i[s][c].clone().multiply(h));
|
|
2748
2757
|
if (i[o].slice(0, i[o].length - 1).every((c) => c.isZero()))
|
|
2749
2758
|
return i[o][i[o].length - 1].isZero() ? this.#r() : [];
|
|
2750
2759
|
}
|
|
@@ -2755,15 +2764,15 @@ class P {
|
|
|
2755
2764
|
const e = [], i = this.equations.map((s) => s.left.monomByLetter(t).coefficient.value);
|
|
2756
2765
|
return i.forEach((s, r) => {
|
|
2757
2766
|
for (let o = r + 1; o < i.length; o++) {
|
|
2758
|
-
const
|
|
2767
|
+
const h = b.lcm(s, i[o]), c = s < 0 ? -1 : 1;
|
|
2759
2768
|
e.push([
|
|
2760
2769
|
{
|
|
2761
2770
|
id: r,
|
|
2762
|
-
factor: c *
|
|
2771
|
+
factor: c * h / s
|
|
2763
2772
|
},
|
|
2764
2773
|
{
|
|
2765
2774
|
id: o,
|
|
2766
|
-
factor: -c *
|
|
2775
|
+
factor: -c * h / i[o]
|
|
2767
2776
|
}
|
|
2768
2777
|
]);
|
|
2769
2778
|
}
|
|
@@ -2797,8 +2806,8 @@ class P {
|
|
|
2797
2806
|
for (const i of this.#t) {
|
|
2798
2807
|
const s = [], r = i.clone().reorder();
|
|
2799
2808
|
for (const o of this.variables) {
|
|
2800
|
-
const
|
|
2801
|
-
s.push(
|
|
2809
|
+
const h = r.left.monomByLetter(o);
|
|
2810
|
+
s.push(h.coefficient);
|
|
2802
2811
|
}
|
|
2803
2812
|
e.push(r.right.monoms[0].coefficient), t.push(s);
|
|
2804
2813
|
}
|
|
@@ -2824,7 +2833,7 @@ class $t {
|
|
|
2824
2833
|
constructor(t) {
|
|
2825
2834
|
return this.#t = [], t !== void 0 && this.parse(t), this;
|
|
2826
2835
|
}
|
|
2827
|
-
parse = (t) => (this.#t = new
|
|
2836
|
+
parse = (t) => (this.#t = new W(S.SET).parse(t).rpn, this);
|
|
2828
2837
|
get tex() {
|
|
2829
2838
|
const t = [];
|
|
2830
2839
|
for (const e of this.#t)
|
|
@@ -2936,26 +2945,26 @@ class $t {
|
|
|
2936
2945
|
switch (r.token) {
|
|
2937
2946
|
case "&":
|
|
2938
2947
|
if (i.length >= 2) {
|
|
2939
|
-
const o = i.pop(),
|
|
2940
|
-
|
|
2948
|
+
const o = i.pop(), h = i.pop();
|
|
2949
|
+
h && o && i.push(new Set([...h].filter((c) => o.has(c))));
|
|
2941
2950
|
}
|
|
2942
2951
|
break;
|
|
2943
2952
|
case "|":
|
|
2944
2953
|
if (i.length >= 2) {
|
|
2945
|
-
const o = i.pop(),
|
|
2946
|
-
|
|
2954
|
+
const o = i.pop(), h = i.pop();
|
|
2955
|
+
h && o && i.push(/* @__PURE__ */ new Set([...h, ...o]));
|
|
2947
2956
|
}
|
|
2948
2957
|
break;
|
|
2949
2958
|
case "-":
|
|
2950
2959
|
if (i.length >= 2) {
|
|
2951
|
-
const o = i.pop(),
|
|
2952
|
-
|
|
2960
|
+
const o = i.pop(), h = i.pop();
|
|
2961
|
+
h && o && i.push(new Set([...h].filter((c) => !o.has(c))));
|
|
2953
2962
|
}
|
|
2954
2963
|
break;
|
|
2955
2964
|
case "!":
|
|
2956
2965
|
if (i.length >= 1) {
|
|
2957
2966
|
const o = i.pop();
|
|
2958
|
-
o && i.push(new Set([...s].filter((
|
|
2967
|
+
o && i.push(new Set([...s].filter((h) => !o.has(h))));
|
|
2959
2968
|
}
|
|
2960
2969
|
break;
|
|
2961
2970
|
}
|
|
@@ -2993,16 +3002,16 @@ class N {
|
|
|
2993
3002
|
return `(${i})/(${s})`;
|
|
2994
3003
|
}
|
|
2995
3004
|
static #i(t, e) {
|
|
2996
|
-
const i = Z(t), s = Z(e), o = Object.keys(i).filter((
|
|
2997
|
-
const c = i[
|
|
2998
|
-
return new y(
|
|
3005
|
+
const i = Z(t), s = Z(e), o = Object.keys(i).filter((h) => Object.hasOwn(s, h)).map((h) => {
|
|
3006
|
+
const c = i[h].reduce((m, d) => m.add(d.power), new a("0")), f = s[h].reduce((m, d) => m.add(d.power), new a("0"));
|
|
3007
|
+
return new y(h, a.min(c, f));
|
|
2999
3008
|
});
|
|
3000
3009
|
return new N(...o);
|
|
3001
3010
|
}
|
|
3002
3011
|
static #s(t, e) {
|
|
3003
|
-
const i = Z(t), s = Z(e), o = [.../* @__PURE__ */ new Set([...Object.keys(i), ...Object.keys(s)])].map((
|
|
3004
|
-
const c = Object.hasOwn(i,
|
|
3005
|
-
return new y(
|
|
3012
|
+
const i = Z(t), s = Z(e), o = [.../* @__PURE__ */ new Set([...Object.keys(i), ...Object.keys(s)])].map((h) => {
|
|
3013
|
+
const c = Object.hasOwn(i, h) ? i[h].reduce((m, d) => m.add(d.power), new a("0")) : new a(0), f = Object.hasOwn(s, h) ? s[h].reduce((m, d) => m.add(d.power), new a("0")) : new a(0);
|
|
3014
|
+
return new y(h, a.max(c, f));
|
|
3006
3015
|
});
|
|
3007
3016
|
return new N(...o);
|
|
3008
3017
|
}
|
|
@@ -3025,21 +3034,21 @@ class N {
|
|
|
3025
3034
|
return t.shift(), t.forEach((i) => e = N.#s(e, i)), e;
|
|
3026
3035
|
}
|
|
3027
3036
|
add(...t) {
|
|
3028
|
-
const e = [this.numerator, ...t.map((
|
|
3037
|
+
const e = [this.numerator, ...t.map((h) => h.numerator)], i = [this.denominator, ...t.map((h) => h.denominator)];
|
|
3029
3038
|
let s;
|
|
3030
|
-
if (i.some((
|
|
3031
|
-
const
|
|
3039
|
+
if (i.some((h) => h.factors.length > 0)) {
|
|
3040
|
+
const h = N.lcm(...i);
|
|
3032
3041
|
e.forEach((c, f) => {
|
|
3033
|
-
c.multiply(
|
|
3034
|
-
}), s =
|
|
3042
|
+
c.multiply(h.clone().divide(i[f]));
|
|
3043
|
+
}), s = h;
|
|
3035
3044
|
}
|
|
3036
3045
|
const r = N.gcd(...e), o = new l(0).add(
|
|
3037
|
-
...e.map((
|
|
3046
|
+
...e.map((h) => h.divide(r).reduce().develop().factors[0].polynom)
|
|
3038
3047
|
).reduce();
|
|
3039
3048
|
return this.#e = [
|
|
3040
3049
|
...r.factors,
|
|
3041
3050
|
new y(o)
|
|
3042
|
-
], s && this.divide(s), this.#e = this.#e.filter((
|
|
3051
|
+
], s && this.divide(s), this.#e = this.#e.filter((h) => !h.power.isZero()), this;
|
|
3043
3052
|
}
|
|
3044
3053
|
get asPower() {
|
|
3045
3054
|
return this.#t = D.POWER, this;
|
|
@@ -3048,7 +3057,7 @@ class N {
|
|
|
3048
3057
|
return this.#t = D.ROOT, this;
|
|
3049
3058
|
}
|
|
3050
3059
|
degree(t) {
|
|
3051
|
-
return this.#e.reduce((e, i) => e.add(i.degree(t)), new
|
|
3060
|
+
return this.#e.reduce((e, i) => e.add(i.degree(t)), new a("0"));
|
|
3052
3061
|
}
|
|
3053
3062
|
get denominator() {
|
|
3054
3063
|
return new N(
|
|
@@ -3079,15 +3088,15 @@ class N {
|
|
|
3079
3088
|
return this.#e = this.#e.concat(t.clone().factors.map((e) => e.inverse())), this;
|
|
3080
3089
|
}
|
|
3081
3090
|
evaluate(t, e) {
|
|
3082
|
-
return e ? this.#e.reduce((i, s) => i * s.evaluate(t, e), 1) : this.#e.reduce((i, s) => i.multiply(s.evaluate(t)), new
|
|
3091
|
+
return e ? this.#e.reduce((i, s) => i * s.evaluate(t, e), 1) : this.#e.reduce((i, s) => i.multiply(s.evaluate(t)), new a("1"));
|
|
3083
3092
|
}
|
|
3084
3093
|
factorize(t) {
|
|
3085
3094
|
const e = [];
|
|
3086
3095
|
this.#e.forEach((o) => {
|
|
3087
|
-
const
|
|
3088
|
-
if (
|
|
3096
|
+
const h = o.polynom.factorize(t);
|
|
3097
|
+
if (h.length > 1) {
|
|
3089
3098
|
const c = o.power.clone();
|
|
3090
|
-
e.push(...
|
|
3099
|
+
e.push(...h.map((f) => new y(f, c)));
|
|
3091
3100
|
} else
|
|
3092
3101
|
e.push(o.clone());
|
|
3093
3102
|
});
|
|
@@ -3114,9 +3123,9 @@ class N {
|
|
|
3114
3123
|
const [e, ...i] = H(t, "/");
|
|
3115
3124
|
if (e === "") throw new Error("Parsing a PolyFactor from a string requires a numerator");
|
|
3116
3125
|
if (i.length > 1) throw new Error('Parsing a PolyFactor from a string only allows max one signe "/"');
|
|
3117
|
-
return i.length === 0 ? this.#e = y.factorsFromString(e, !0) : this.#e = [
|
|
3118
|
-
...y.factorsFromString(e, !0),
|
|
3119
|
-
...y.factorsFromString(i[0], !1)
|
|
3126
|
+
return i.length === 0 ? this.#e = y.factorsFromString(j(e), !0) : this.#e = [
|
|
3127
|
+
...y.factorsFromString(j(e), !0),
|
|
3128
|
+
...y.factorsFromString(j(i[0]), !1)
|
|
3120
3129
|
], this;
|
|
3121
3130
|
}
|
|
3122
3131
|
/**
|
|
@@ -3172,10 +3181,14 @@ class N {
|
|
|
3172
3181
|
}
|
|
3173
3182
|
reduce() {
|
|
3174
3183
|
const t = Z(this);
|
|
3175
|
-
|
|
3176
|
-
const
|
|
3177
|
-
return new y(
|
|
3178
|
-
}).filter((
|
|
3184
|
+
this.#e = Object.values(t).map((r) => {
|
|
3185
|
+
const o = r[0].polynom, h = r.reduce((c, f) => c.add(f.power), new a("0"));
|
|
3186
|
+
return new y(o, h.reduce());
|
|
3187
|
+
}).filter((r) => !r.power.isZero());
|
|
3188
|
+
const e = new y(1), i = new y(1), s = this.#e.filter((r) => r.polynom.monoms.length === 1 && r.power.isRelative());
|
|
3189
|
+
return s.length > 0 && (s.forEach((r) => {
|
|
3190
|
+
r.power.isPositive() ? e.multiply(new y(r.polynom.clone().pow(r.power.value))) : i.multiply(new y(r.polynom.clone().pow(-r.power.value)));
|
|
3191
|
+
}), this.#e = this.#e.filter((r) => !(r.polynom.monoms.length === 1 && r.power.isRelative())), i.polynom.isOne() || this.#e.push(i.inverse()), e.polynom.isOne() || this.#e.push(e)), this;
|
|
3179
3192
|
}
|
|
3180
3193
|
root(t) {
|
|
3181
3194
|
return this.#e = this.#e.map((e) => e.root(t)), this;
|
|
@@ -3187,15 +3200,23 @@ class N {
|
|
|
3187
3200
|
* 3. power of polyfactor
|
|
3188
3201
|
*/
|
|
3189
3202
|
sort(t) {
|
|
3190
|
-
return this.#e.sort((e, i) => {
|
|
3203
|
+
return this.#e.forEach((e) => e.polynom.reorder(t)), this.#e.sort((e, i) => {
|
|
3191
3204
|
const s = e.power.value, r = i.power.value;
|
|
3192
3205
|
if (s * r < 0)
|
|
3193
3206
|
return -s;
|
|
3194
|
-
const o = e.polynom.monoms.length,
|
|
3195
|
-
if (o !==
|
|
3196
|
-
return o -
|
|
3207
|
+
const o = e.polynom.monoms.length, h = i.polynom.monoms.length;
|
|
3208
|
+
if (o !== h)
|
|
3209
|
+
return o - h;
|
|
3197
3210
|
const c = e.polynom.degree(t).value, f = i.polynom.degree(t).value;
|
|
3198
|
-
|
|
3211
|
+
if (c !== f)
|
|
3212
|
+
return c - f;
|
|
3213
|
+
if (s !== r)
|
|
3214
|
+
return s - r;
|
|
3215
|
+
if (e.polynom.degree(t).isOne() && i.polynom.degree(t).isOne()) {
|
|
3216
|
+
const m = e.polynom.monoms[1].coefficient.clone().opposite().divide(e.polynom.monoms[0].coefficient).value, d = i.polynom.monoms[1].coefficient.clone().opposite().divide(i.polynom.monoms[0].coefficient).value;
|
|
3217
|
+
return m - d;
|
|
3218
|
+
}
|
|
3219
|
+
return e.degree().isLeq(i.degree()) ? -1 : 1;
|
|
3199
3220
|
}), this;
|
|
3200
3221
|
}
|
|
3201
3222
|
sqrt() {
|
|
@@ -3208,18 +3229,18 @@ class N {
|
|
|
3208
3229
|
const t = this.getZeroes(), e = t.map((r) => r.value), i = this.factorize().factors.map((r) => ({ factor: new y(r), ...r.tableOfSigns() }));
|
|
3209
3230
|
return i.forEach((r) => {
|
|
3210
3231
|
const o = new Array(2 * t.length + 1).fill("");
|
|
3211
|
-
let
|
|
3232
|
+
let h = r.signs.shift(), c = r.roots.shift();
|
|
3212
3233
|
const f = o.map((m, d) => {
|
|
3213
3234
|
if (d % 2 === 0)
|
|
3214
|
-
return
|
|
3235
|
+
return h;
|
|
3215
3236
|
if (c?.value !== e[(d - 1) / 2])
|
|
3216
3237
|
return "t";
|
|
3217
3238
|
const v = r.signs.shift();
|
|
3218
|
-
return
|
|
3239
|
+
return h = r.signs.shift(), c = r.roots.shift(), v;
|
|
3219
3240
|
});
|
|
3220
3241
|
r.roots = t, r.signs = f;
|
|
3221
|
-
}), { signs: i.map((r) => [...r.signs]).reduce((r, o) => r.length === 0 ? o : (o.forEach((
|
|
3222
|
-
switch (
|
|
3242
|
+
}), { signs: i.map((r) => [...r.signs]).reduce((r, o) => r.length === 0 ? o : (o.forEach((h, c) => {
|
|
3243
|
+
switch (h) {
|
|
3223
3244
|
case "d":
|
|
3224
3245
|
r[c] = "d";
|
|
3225
3246
|
break;
|
|
@@ -3247,11 +3268,13 @@ class N {
|
|
|
3247
3268
|
}
|
|
3248
3269
|
}
|
|
3249
3270
|
function Z(n) {
|
|
3250
|
-
const t = new
|
|
3251
|
-
if (
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3271
|
+
const t = new a().one(), e = new a().one(), i = n.factors.reduce((o, h) => {
|
|
3272
|
+
if (h.polynom.degree().isZero() && h.power.isRelative()) {
|
|
3273
|
+
const f = h.polynom.monoms[0].coefficient.pow(h.power.clone().abs());
|
|
3274
|
+
return h.power.isPositive() ? t.multiply(f) : e.multiply(f), o;
|
|
3275
|
+
}
|
|
3276
|
+
const c = h.polynom.display;
|
|
3277
|
+
return Object.hasOwn(o, c) ? o[c].push(h) : o[c] = [h], o;
|
|
3255
3278
|
}, {}), { numerator: s, denominator: r } = t.divide(e).reduce();
|
|
3256
3279
|
return s !== 1 && (i[s.toString()] = [new y(s, 1)]), r !== 1 && (i[r.toString()] = [new y(r, -1)]), i;
|
|
3257
3280
|
}
|
|
@@ -3427,8 +3450,8 @@ class B {
|
|
|
3427
3450
|
const { rows: e, cols: i } = this.dimension, s = Array.from({ length: e }, () => Array.from({ length: i }, () => {
|
|
3428
3451
|
}));
|
|
3429
3452
|
return this.#i.forEach((r, o) => {
|
|
3430
|
-
r.forEach((
|
|
3431
|
-
s[o][c] = t(
|
|
3453
|
+
r.forEach((h, c) => {
|
|
3454
|
+
s[o][c] = t(h, o, c);
|
|
3432
3455
|
});
|
|
3433
3456
|
}), s;
|
|
3434
3457
|
}
|
|
@@ -3438,9 +3461,9 @@ class B {
|
|
|
3438
3461
|
throw new Error("Cannot multiply a matrix with incompatibles dimensions");
|
|
3439
3462
|
const e = new B(this.dimension.rows, t.dimension.cols);
|
|
3440
3463
|
return e.forEach((i, s, r) => {
|
|
3441
|
-
const o = this.rows[s],
|
|
3464
|
+
const o = this.rows[s], h = t.cols[r], c = new l();
|
|
3442
3465
|
o.forEach((f, m) => {
|
|
3443
|
-
c.add(f.clone().multiply(
|
|
3466
|
+
c.add(f.clone().multiply(h[m]));
|
|
3444
3467
|
}), e.setValue(s, r, c);
|
|
3445
3468
|
}), this.#i = e.values, this;
|
|
3446
3469
|
}
|
|
@@ -3512,9 +3535,9 @@ function Mt(n, t) {
|
|
|
3512
3535
|
);
|
|
3513
3536
|
}
|
|
3514
3537
|
function Bt(n, t) {
|
|
3515
|
-
return n.dimension !== t.dimension ? new
|
|
3538
|
+
return n.dimension !== t.dimension ? new a().invalid() : n.array.reduce(
|
|
3516
3539
|
(e, i, s) => e.add(i.clone().multiply(t.array[s])),
|
|
3517
|
-
new
|
|
3540
|
+
new a(0)
|
|
3518
3541
|
);
|
|
3519
3542
|
}
|
|
3520
3543
|
function Ft(...n) {
|
|
@@ -3534,7 +3557,7 @@ class z {
|
|
|
3534
3557
|
#t = [];
|
|
3535
3558
|
#e;
|
|
3536
3559
|
constructor(...t) {
|
|
3537
|
-
this.#t = t.map((e) => new
|
|
3560
|
+
this.#t = t.map((e) => new a(e));
|
|
3538
3561
|
}
|
|
3539
3562
|
copy() {
|
|
3540
3563
|
return this.#t.map((t) => t.clone());
|
|
@@ -3551,7 +3574,7 @@ class z {
|
|
|
3551
3574
|
fromString(t) {
|
|
3552
3575
|
t.startsWith("(") && (t = t.substring(1)), t.endsWith(")") && (t = t.substring(0, t.length - 1));
|
|
3553
3576
|
const e = t.split(/[,;\s]/g).filter((i) => i.trim() !== "");
|
|
3554
|
-
return e.length < 2 ? this : (this.#t = e.map((i) => new
|
|
3577
|
+
return e.length < 2 ? this : (this.#t = e.map((i) => new a(i)), this);
|
|
3555
3578
|
}
|
|
3556
3579
|
get onChange() {
|
|
3557
3580
|
return this.#e;
|
|
@@ -3566,20 +3589,20 @@ class z {
|
|
|
3566
3589
|
this.#t = this.#t.slice(0, t);
|
|
3567
3590
|
else if (t > this.dimension)
|
|
3568
3591
|
for (let e = this.dimension; e < t; e++)
|
|
3569
|
-
this.#t.push(new
|
|
3592
|
+
this.#t.push(new a(0));
|
|
3570
3593
|
return this;
|
|
3571
3594
|
}
|
|
3572
3595
|
get x() {
|
|
3573
3596
|
return this.#t[0];
|
|
3574
3597
|
}
|
|
3575
3598
|
set x(t) {
|
|
3576
|
-
this.#t[0] = new
|
|
3599
|
+
this.#t[0] = new a(t), this.#e?.();
|
|
3577
3600
|
}
|
|
3578
3601
|
get y() {
|
|
3579
3602
|
return this.#t[1];
|
|
3580
3603
|
}
|
|
3581
3604
|
set y(t) {
|
|
3582
|
-
this.#t[1] = new
|
|
3605
|
+
this.#t[1] = new a(t), this.#e?.();
|
|
3583
3606
|
}
|
|
3584
3607
|
get z() {
|
|
3585
3608
|
if (this.dimension < 3)
|
|
@@ -3589,7 +3612,7 @@ class z {
|
|
|
3589
3612
|
set z(t) {
|
|
3590
3613
|
if (this.dimension < 3)
|
|
3591
3614
|
throw new Error("Vector is not 3D");
|
|
3592
|
-
this.#t[2] = new
|
|
3615
|
+
this.#t[2] = new a(t), this.#e?.();
|
|
3593
3616
|
}
|
|
3594
3617
|
zero = () => (this.#t.forEach((t) => t.zero()), this.#e?.(), this);
|
|
3595
3618
|
}
|
|
@@ -3607,7 +3630,7 @@ class w extends z {
|
|
|
3607
3630
|
if (t.length > 1) {
|
|
3608
3631
|
if (t.some((i) => i instanceof w))
|
|
3609
3632
|
throw new Error("Creating a point with multiple argument requires an input fraction");
|
|
3610
|
-
const e = t.map((i) => new
|
|
3633
|
+
const e = t.map((i) => new a(i));
|
|
3611
3634
|
if (e.some((i) => i.isNaN()))
|
|
3612
3635
|
throw new Error("The given values are not a valid point string (a,b): ");
|
|
3613
3636
|
this.array = e;
|
|
@@ -3628,9 +3651,9 @@ class w extends z {
|
|
|
3628
3651
|
throw new Error("The two points must have the same dimensions.");
|
|
3629
3652
|
const i = this.array.map((s, r) => t.array[r].clone().subtract(s)).reduce(
|
|
3630
3653
|
(s, r) => s.add(r.clone().pow(2)),
|
|
3631
|
-
new
|
|
3654
|
+
new a(0)
|
|
3632
3655
|
);
|
|
3633
|
-
return new
|
|
3656
|
+
return new O().from(2, i).reduce();
|
|
3634
3657
|
}
|
|
3635
3658
|
isEqual(t) {
|
|
3636
3659
|
return this.x.value === t.x.value && this.y.value === t.y.value;
|
|
@@ -3670,7 +3693,7 @@ class g extends z {
|
|
|
3670
3693
|
return this.array = i.array.map((s, r) => s.clone().subtract(e.array[r])), this;
|
|
3671
3694
|
}
|
|
3672
3695
|
}
|
|
3673
|
-
return this.array = t.map((e) => new
|
|
3696
|
+
return this.array = t.map((e) => new a(e)), this;
|
|
3674
3697
|
}
|
|
3675
3698
|
clone() {
|
|
3676
3699
|
return new g(...this.copy());
|
|
@@ -3703,7 +3726,7 @@ class g extends z {
|
|
|
3703
3726
|
}
|
|
3704
3727
|
// ------------------------------------------
|
|
3705
3728
|
// Creation / parsing functions
|
|
3706
|
-
divideByScalar = (t) => this.multiplyByScalar(new
|
|
3729
|
+
divideByScalar = (t) => this.multiplyByScalar(new a(t).inverse());
|
|
3707
3730
|
dot = (t) => Bt(this, t);
|
|
3708
3731
|
fromString(t) {
|
|
3709
3732
|
return t.startsWith("((") && t.endsWith("))") ? super.fromString(t.slice(1, -1)) : super.fromString(t);
|
|
@@ -3722,14 +3745,14 @@ class g extends z {
|
|
|
3722
3745
|
return this.array.every((t) => t.isZero());
|
|
3723
3746
|
}
|
|
3724
3747
|
multiplyByScalar = (t) => {
|
|
3725
|
-
const e = new
|
|
3748
|
+
const e = new a(t);
|
|
3726
3749
|
return this.array.forEach((i) => i.multiply(e)), this;
|
|
3727
3750
|
};
|
|
3728
3751
|
get norm() {
|
|
3729
3752
|
return Math.sqrt(this.normSquare.value);
|
|
3730
3753
|
}
|
|
3731
3754
|
get normSquare() {
|
|
3732
|
-
return this.array.reduce((t, e) => t.add(e.clone().pow(2)), new
|
|
3755
|
+
return this.array.reduce((t, e) => t.add(e.clone().pow(2)), new a(0));
|
|
3733
3756
|
}
|
|
3734
3757
|
normal = () => {
|
|
3735
3758
|
if (this.dimension >= 3)
|
|
@@ -3741,7 +3764,7 @@ class g extends z {
|
|
|
3741
3764
|
opposite = () => (this.array.forEach((t) => t.opposite()), this);
|
|
3742
3765
|
simplify = () => {
|
|
3743
3766
|
const t = b.lcm(...this.array.map((i) => i.denominator)), e = b.gcd(...this.array.map((i) => i.numerator));
|
|
3744
|
-
return this.multiplyByScalar(new
|
|
3767
|
+
return this.multiplyByScalar(new a(t, e)), this.x.isNegative() && this.opposite(), this;
|
|
3745
3768
|
};
|
|
3746
3769
|
subtract = (t) => this.add(t.clone().opposite());
|
|
3747
3770
|
translate(...t) {
|
|
@@ -3756,36 +3779,36 @@ var V = /* @__PURE__ */ ((n) => (n.None = "none", n.Parallel = "parallel", n.Per
|
|
|
3756
3779
|
function ot(n = 0.5) {
|
|
3757
3780
|
return Math.random() < n;
|
|
3758
3781
|
}
|
|
3759
|
-
function
|
|
3782
|
+
function T(n, t, e) {
|
|
3760
3783
|
if (t === void 0)
|
|
3761
|
-
return n >= 0 ?
|
|
3784
|
+
return n >= 0 ? T(0, n) : T(n, 0);
|
|
3762
3785
|
if (n === t)
|
|
3763
3786
|
return n;
|
|
3764
3787
|
if (e === void 0)
|
|
3765
3788
|
return Math.floor(Math.random() * (t - n + 1) + n);
|
|
3766
3789
|
if (Math.abs(t - n) <= e.length)
|
|
3767
3790
|
throw new Error("The number of excluded values is too high.");
|
|
3768
|
-
let i =
|
|
3791
|
+
let i = T(n, t);
|
|
3769
3792
|
for (; e.includes(i); )
|
|
3770
|
-
i =
|
|
3793
|
+
i = T(n, t);
|
|
3771
3794
|
return i;
|
|
3772
3795
|
}
|
|
3773
3796
|
function A(n, t) {
|
|
3774
|
-
return t === !1 ? ot() ?
|
|
3797
|
+
return t === !1 ? ot() ? T(1, n) : -T(1, n) : T(-n, n);
|
|
3775
3798
|
}
|
|
3776
3799
|
function St(n, t) {
|
|
3777
3800
|
const e = b.pythagoreanTripletsWithTarget(n).filter((i) => t === !0 || !i.includes(0));
|
|
3778
|
-
return e.length === 0 ? null :
|
|
3801
|
+
return e.length === 0 ? null : X(e);
|
|
3779
3802
|
}
|
|
3780
3803
|
function It(n) {
|
|
3781
3804
|
let t = b.primes();
|
|
3782
|
-
return n !== void 0 && (t = t.filter((e) => e < n)),
|
|
3805
|
+
return n !== void 0 && (t = t.filter((e) => e < n)), X(t);
|
|
3783
3806
|
}
|
|
3784
3807
|
function Pt(n, t) {
|
|
3785
3808
|
return t === void 0 && (t = 1), n.length <= 0 ? Object.values(n) : ht(n).slice(0, t);
|
|
3786
3809
|
}
|
|
3787
|
-
function
|
|
3788
|
-
return n.length === 0 ? null : n[
|
|
3810
|
+
function X(n) {
|
|
3811
|
+
return n.length === 0 ? null : n[T(0, n.length - 1)];
|
|
3789
3812
|
}
|
|
3790
3813
|
function ht(n) {
|
|
3791
3814
|
const t = Object.values(n);
|
|
@@ -3813,7 +3836,7 @@ class E {
|
|
|
3813
3836
|
* @param values
|
|
3814
3837
|
*/
|
|
3815
3838
|
constructor(...t) {
|
|
3816
|
-
return this.#e = new
|
|
3839
|
+
return this.#e = new a().zero(), this.#i = new a().zero(), this.#s = new a().zero(), this.#t = new g(), this.#r = "lr", t.length > 0 && this.parse(...t), this;
|
|
3817
3840
|
}
|
|
3818
3841
|
// ------------------------------------------
|
|
3819
3842
|
/**
|
|
@@ -3843,7 +3866,7 @@ class E {
|
|
|
3843
3866
|
if (t[0] instanceof w && t[1] instanceof g)
|
|
3844
3867
|
return this.fromPointAndDirection(t[0], t[1]);
|
|
3845
3868
|
}
|
|
3846
|
-
return t.length === 3 && t.every((e) =>
|
|
3869
|
+
return t.length === 3 && t.every((e) => a.isFraction(e)) ? this.fromCoefficient(
|
|
3847
3870
|
t[0],
|
|
3848
3871
|
t[1],
|
|
3849
3872
|
t[2]
|
|
@@ -3950,16 +3973,16 @@ class E {
|
|
|
3950
3973
|
}
|
|
3951
3974
|
distanceTo(t) {
|
|
3952
3975
|
const e = t.x.clone().multiply(this.#e).add(t.y.clone().multiply(this.#i)).add(this.#s).abs(), i = this.normal.normSquare;
|
|
3953
|
-
return i.isZero() ? new
|
|
3976
|
+
return i.isZero() ? new O(0) : new O().from(2, i.inverse(), e).reduce();
|
|
3954
3977
|
}
|
|
3955
3978
|
fromCoefficient(t, e, i) {
|
|
3956
|
-
this.#e = new
|
|
3979
|
+
this.#e = new a(t), this.#i = new a(e), this.#s = new a(i);
|
|
3957
3980
|
const s = [this.#e, this.#i, this.#s].every((o) => o.exact) ? b.lcm(this.#e.denominator, this.#i.denominator, this.#s.denominator) : 1;
|
|
3958
3981
|
if (s > 1 && (this.#e.multiply(s).reduce(), this.#i.multiply(s).reduce(), this.#s.multiply(s).reduce()), this.#i.isZero())
|
|
3959
3982
|
return this.#t = new g(this.#s.clone().divide(this.#e).opposite(), 0), this;
|
|
3960
3983
|
for (let o = 0; o < this.#i.value; o++) {
|
|
3961
|
-
const
|
|
3962
|
-
if (this.#t = new g(o,
|
|
3984
|
+
const h = this.#e.clone().divide(this.#i).multiply(o).subtract(this.#s.clone().divide(this.#i)).reduce();
|
|
3985
|
+
if (this.#t = new g(o, h), h.isRelative())
|
|
3963
3986
|
return this;
|
|
3964
3987
|
}
|
|
3965
3988
|
const r = this.#s.clone().divide(this.#i).opposite().reduce();
|
|
@@ -4005,12 +4028,12 @@ class E {
|
|
|
4005
4028
|
return new x(new l().parse("xy", this.#e, this.#i, this.#s), new l("0")).simplify();
|
|
4006
4029
|
}
|
|
4007
4030
|
getValueAtX = (t) => {
|
|
4008
|
-
const e = this.getEquation().isolate("y"), i = new
|
|
4009
|
-
return e instanceof x ? e.right.evaluate({ x: i }) : new
|
|
4031
|
+
const e = this.getEquation().isolate("y"), i = new a(t);
|
|
4032
|
+
return e instanceof x ? e.right.evaluate({ x: i }) : new a().invalid();
|
|
4010
4033
|
};
|
|
4011
4034
|
getValueAtY = (t) => {
|
|
4012
|
-
const e = this.getEquation().isolate("x"), i = new
|
|
4013
|
-
return e instanceof x ? e.right.evaluate({ y: i }) : new
|
|
4035
|
+
const e = this.getEquation().isolate("x"), i = new a(t);
|
|
4036
|
+
return e instanceof x ? e.right.evaluate({ y: i }) : new a().invalid();
|
|
4014
4037
|
};
|
|
4015
4038
|
get height() {
|
|
4016
4039
|
return this.#s.clone().opposite().divide(this.#i);
|
|
@@ -4024,7 +4047,7 @@ class E {
|
|
|
4024
4047
|
intersection = (t) => {
|
|
4025
4048
|
const e = new w();
|
|
4026
4049
|
let i = !1, s = !1;
|
|
4027
|
-
return this.#i.isZero() || t.b.isZero(), this.isParallelTo(t) ? (e.x = new
|
|
4050
|
+
return this.#i.isZero() || t.b.isZero(), this.isParallelTo(t) ? (e.x = new a().invalid(), e.y = new a().invalid(), i = !0) : this.isSameAs(t) ? (e.x = new a().invalid(), e.y = new a().invalid(), s = !0) : (e.x = this.#i.clone().multiply(t.c).subtract(this.#s.clone().multiply(t.b)).divide(this.#e.clone().multiply(t.b).subtract(this.#i.clone().multiply(t.a))), e.y = this.#e.clone().multiply(t.c).subtract(this.#s.clone().multiply(t.a)).divide(this.#i.clone().multiply(t.a).subtract(this.#e.clone().multiply(t.b)))), {
|
|
4028
4051
|
point: e,
|
|
4029
4052
|
hasIntersection: !(i || s),
|
|
4030
4053
|
isParallel: i,
|
|
@@ -4106,7 +4129,7 @@ class L {
|
|
|
4106
4129
|
return this.fromPoints(t[0], t[1], t[2]);
|
|
4107
4130
|
}
|
|
4108
4131
|
if (t.length === 6) {
|
|
4109
|
-
const e = t.map((i) => new
|
|
4132
|
+
const e = t.map((i) => new a(i));
|
|
4110
4133
|
if (e.some((i) => i.isNaN()))
|
|
4111
4134
|
throw new Error("One of the values is not a valid number");
|
|
4112
4135
|
return this.fromCoordinates(e[0], e[1], e[2], e[3], e[4], e[5]);
|
|
@@ -4179,17 +4202,17 @@ class L {
|
|
|
4179
4202
|
}
|
|
4180
4203
|
fromLines(t, e, i) {
|
|
4181
4204
|
const s = new E(t).clone(), r = new E(e).clone(), o = new E(i).clone();
|
|
4182
|
-
let
|
|
4183
|
-
if (
|
|
4184
|
-
this.#e =
|
|
4205
|
+
let h = s.intersection(r);
|
|
4206
|
+
if (h.hasIntersection)
|
|
4207
|
+
this.#e = h.point;
|
|
4185
4208
|
else
|
|
4186
4209
|
return this.#s = !1, this;
|
|
4187
|
-
if (
|
|
4188
|
-
this.#i =
|
|
4210
|
+
if (h = r.intersection(o), h.hasIntersection)
|
|
4211
|
+
this.#i = h.point;
|
|
4189
4212
|
else
|
|
4190
4213
|
return this.#s = !1, this;
|
|
4191
|
-
if (
|
|
4192
|
-
this.#t =
|
|
4214
|
+
if (h = o.intersection(s), h.hasIntersection)
|
|
4215
|
+
this.#t = h.point;
|
|
4193
4216
|
else
|
|
4194
4217
|
return this.#s = !1, this;
|
|
4195
4218
|
return this.reset(), this.#r = { AB: s, AC: o, BC: r }, this;
|
|
@@ -4300,8 +4323,8 @@ class L {
|
|
|
4300
4323
|
let s = new g(), r = new g(), o = new w();
|
|
4301
4324
|
if (t === "A" ? (o = this.A.clone(), s = i.AB.clone().d, r = i.AC.clone().d) : t === "B" ? (o = this.B.clone(), s = i.AB.clone().d.opposite(), r = i.BC.clone().d) : t === "C" && (o = this.C.clone(), s = i.BC.clone().d.opposite(), r = i.AC.clone().d.opposite()), s === void 0 || r === void 0)
|
|
4302
4325
|
throw new Error(`The point ${t} does not exist`);
|
|
4303
|
-
const
|
|
4304
|
-
return new E().fromPointAndDirection(o,
|
|
4326
|
+
const h = e ? s.unit().add(r.unit()) : s.unit().subtract(r.unit());
|
|
4327
|
+
return new E().fromPointAndDirection(o, h);
|
|
4305
4328
|
}
|
|
4306
4329
|
#c(t, e, i) {
|
|
4307
4330
|
const s = (e ** 2 + i ** 2 - t ** 2) / (2 * e * i);
|
|
@@ -4341,7 +4364,7 @@ class U {
|
|
|
4341
4364
|
t.length > 0 && this.parse(...t);
|
|
4342
4365
|
}
|
|
4343
4366
|
parse(...t) {
|
|
4344
|
-
return typeof t[0] == "string" ? this.fromString(t[0]) : t[0] instanceof x ? this.fromEquation(t[0]) : t[0] instanceof U ? this.copy(t[0]) : t.length === 2 && t[0] instanceof w && t[1] instanceof w ? this.fromCenterPoint(t[0], t[1]) : t.length >= 2 && t[0] instanceof w && (t[1] instanceof
|
|
4367
|
+
return typeof t[0] == "string" ? this.fromString(t[0]) : t[0] instanceof x ? this.fromEquation(t[0]) : t[0] instanceof U ? this.copy(t[0]) : t.length === 2 && t[0] instanceof w && t[1] instanceof w ? this.fromCenterPoint(t[0], t[1]) : t.length >= 2 && t[0] instanceof w && (t[1] instanceof a || typeof t[1] == "number") ? this.fromCenterRadius(
|
|
4345
4368
|
t[0],
|
|
4346
4369
|
t[1],
|
|
4347
4370
|
typeof t[2] == "boolean" ? t[2] : !1
|
|
@@ -4385,7 +4408,7 @@ class U {
|
|
|
4385
4408
|
return this.#t = t.clone(), this.#s = new g(this.#t, e).normSquare, this.#r(), this;
|
|
4386
4409
|
}
|
|
4387
4410
|
fromCenterRadius(t, e, i) {
|
|
4388
|
-
return this.#t = t.clone(), i ? this.#s = new
|
|
4411
|
+
return this.#t = t.clone(), i ? this.#s = new a(e) : this.#s = new a(e).pow(2), this.#r(), this;
|
|
4389
4412
|
}
|
|
4390
4413
|
fromEquation(t) {
|
|
4391
4414
|
if (t.moveLeft(), t.degree("x").value === 2 && t.degree("y").value === 2) {
|
|
@@ -4415,7 +4438,7 @@ class U {
|
|
|
4415
4438
|
return t.forEach((i) => {
|
|
4416
4439
|
for (const s of [[1, 1], [-1, 1], [-1, -1], [1, -1]]) {
|
|
4417
4440
|
const r = this.center.x.clone().add(s[0] * i[0]), o = this.center.y.clone().add(s[1] * i[1]);
|
|
4418
|
-
e.every((
|
|
4441
|
+
e.every((h) => !h.isEqualXY(r, o)) && e.push(new w(r, o));
|
|
4419
4442
|
}
|
|
4420
4443
|
}), e;
|
|
4421
4444
|
}
|
|
@@ -4430,7 +4453,7 @@ class U {
|
|
|
4430
4453
|
*/
|
|
4431
4454
|
lineIntersection(t) {
|
|
4432
4455
|
if (this.#e === null) return [];
|
|
4433
|
-
const e = this.center, i = t.d, s = t.OA, r = i.normSquare, o = s.x.clone().subtract(e.x).multiply(i.x).add(s.y.clone().subtract(e.y).multiply(i.y)).multiply(2),
|
|
4456
|
+
const e = this.center, i = t.d, s = t.OA, r = i.normSquare, o = s.x.clone().subtract(e.x).multiply(i.x).add(s.y.clone().subtract(e.y).multiply(i.y)).multiply(2), h = s.x.clone().subtract(e.x).pow(2).add(s.y.clone().subtract(e.y).pow(2)).subtract(this.squareRadius), c = C.fromQuadratic(r, o, h);
|
|
4434
4457
|
if (c.length === 0) return [];
|
|
4435
4458
|
if (c.length === 1) {
|
|
4436
4459
|
const d = s.add(i.clone().multiplyByScalar(c[0].fraction));
|
|
@@ -4445,7 +4468,7 @@ class U {
|
|
|
4445
4468
|
].sort((d, v) => i.x.isZero() ? i.y.isPositive() ? d.y.value - v.y.value : v.y.value - d.y.value : i.x.isPositive() ? d.x.value - v.x.value : v.x.value - d.x.value);
|
|
4446
4469
|
}
|
|
4447
4470
|
get radius() {
|
|
4448
|
-
return new
|
|
4471
|
+
return new O().from(2, this.#s ?? 0);
|
|
4449
4472
|
}
|
|
4450
4473
|
/**
|
|
4451
4474
|
* Get the relative position between circle and line. It corresponds to the number of intersection.
|
|
@@ -4459,12 +4482,12 @@ class U {
|
|
|
4459
4482
|
return e - i > 1e-10 ? 0 : Math.abs(e - i) < 1e-10 ? 1 : 2;
|
|
4460
4483
|
}
|
|
4461
4484
|
setRadius(t, e) {
|
|
4462
|
-
return e ? this.#s = new
|
|
4485
|
+
return e ? this.#s = new a(t) : this.#s = new a(t).pow(2), this.#r(), this;
|
|
4463
4486
|
}
|
|
4464
4487
|
get squareRadius() {
|
|
4465
|
-
return this.#s?.clone() ?? new
|
|
4488
|
+
return this.#s?.clone() ?? new a(-1);
|
|
4466
4489
|
}
|
|
4467
|
-
tangents = (t) => t instanceof
|
|
4490
|
+
tangents = (t) => t instanceof a ? this.#c(t) : this.isPointOnCircle(t) ? this.#o(t) : this.#t !== null && this.#t.distanceTo(t).value > this.radius.value ? this.#a(t) : [];
|
|
4468
4491
|
#r() {
|
|
4469
4492
|
this.#e = new x(
|
|
4470
4493
|
new l(`(x-(${this.center.x.display}))^2+(y-(${this.center.y.display}))^2`),
|
|
@@ -4487,11 +4510,11 @@ class U {
|
|
|
4487
4510
|
});
|
|
4488
4511
|
};
|
|
4489
4512
|
#c = (t) => {
|
|
4490
|
-
const e = t.numerator, i = -t.denominator, s = this.center.x.clone(), r = this.center.y.clone(), o = this.squareRadius.clone().multiply(t.numerator ** 2 + t.denominator ** 2),
|
|
4491
|
-
return [new E(e, i,
|
|
4513
|
+
const e = t.numerator, i = -t.denominator, s = this.center.x.clone(), r = this.center.y.clone(), o = this.squareRadius.clone().multiply(t.numerator ** 2 + t.denominator ** 2), h = s.clone().multiply(e).opposite().subtract(r.clone().multiply(i)).add(o.clone().sqrt()), c = s.clone().multiply(e).opposite().subtract(r.clone().multiply(i)).subtract(o.clone().sqrt());
|
|
4514
|
+
return [new E(e, i, h), new E(e, i, c)];
|
|
4492
4515
|
};
|
|
4493
4516
|
}
|
|
4494
|
-
class
|
|
4517
|
+
class Y {
|
|
4495
4518
|
static PARALLEL = K.Parallel;
|
|
4496
4519
|
// A line is defined as the canonical form
|
|
4497
4520
|
static PERPENDICULAR = K.Perpendicular;
|
|
@@ -4514,11 +4537,11 @@ class X {
|
|
|
4514
4537
|
};
|
|
4515
4538
|
}
|
|
4516
4539
|
get display() {
|
|
4517
|
-
const t = this.#t.x.display, e = this.#t.y.display, i = this.#t.z.display, s = this.direction.simplify(), r = s.x.display, o = s.y.display,
|
|
4540
|
+
const t = this.#t.x.display, e = this.#t.y.display, i = this.#t.z.display, s = this.direction.simplify(), r = s.x.display, o = s.y.display, h = s.z.display;
|
|
4518
4541
|
return {
|
|
4519
4542
|
parametric: `${g.asDisplay("x", "y", "z")} = ${g.asDisplay(this.#t.x.display, this.#t.y.display, this.#t.z.display)} + k\\cdot ${g.asDisplay(this.#e.x.display, this.#e.y.display, this.#e.z.display)}`,
|
|
4520
4543
|
system: "",
|
|
4521
|
-
cartesian: `(x-${t})/${r} = (y-${e})/${o} = (z-${i})/${
|
|
4544
|
+
cartesian: `(x-${t})/${r} = (y-${e})/${o} = (z-${i})/${h}`
|
|
4522
4545
|
};
|
|
4523
4546
|
}
|
|
4524
4547
|
get OA() {
|
|
@@ -4537,18 +4560,18 @@ class X {
|
|
|
4537
4560
|
return this.#e.clone();
|
|
4538
4561
|
}
|
|
4539
4562
|
distanceTo(t) {
|
|
4540
|
-
const e = new g(this.#t, t), i = this.direction, s = this.direction.normSquare, r = e.cross(i).normSquare, o = r.clone().divide(s),
|
|
4563
|
+
const e = new g(this.#t, t), i = this.direction, s = this.direction.normSquare, r = e.cross(i).normSquare, o = r.clone().divide(s), h = o.clone().sqrt();
|
|
4541
4564
|
return {
|
|
4542
4565
|
value: Math.sqrt(o.value),
|
|
4543
4566
|
fraction: o.clone().sqrt(),
|
|
4544
|
-
tex:
|
|
4567
|
+
tex: h.exact ? h.tex : `\\sqrt{${o.tex}}`
|
|
4545
4568
|
};
|
|
4546
4569
|
}
|
|
4547
4570
|
// ------------------------------------------
|
|
4548
4571
|
// Mathematical operations
|
|
4549
4572
|
hitSegment(t, e) {
|
|
4550
4573
|
const i = this.intersection(
|
|
4551
|
-
new
|
|
4574
|
+
new Y(t, e)
|
|
4552
4575
|
);
|
|
4553
4576
|
return i.hasIntersection ? i.point.x.value >= Math.min(t.x.value, e.x.value) && i.point.x.value <= Math.max(t.x.value, e.x.value) && i.point.y.value >= Math.min(t.y.value, e.y.value) && i.point.y.value <= Math.max(t.y.value, e.y.value) && i.point.z.value >= Math.min(t.z.value, e.z.value) && i.point.z.value <= Math.max(t.z.value, e.z.value) : !1;
|
|
4554
4577
|
}
|
|
@@ -4573,7 +4596,7 @@ class X {
|
|
|
4573
4596
|
return this.#t.clone();
|
|
4574
4597
|
}
|
|
4575
4598
|
randomPoint = (t = 5) => {
|
|
4576
|
-
const e = this.#t.clone(), i = new
|
|
4599
|
+
const e = this.#t.clone(), i = new a(A(t, !1));
|
|
4577
4600
|
return new w(
|
|
4578
4601
|
e.x.clone().add(this.#e.x.clone().multiply(i)),
|
|
4579
4602
|
e.y.clone().add(this.#e.y.clone().multiply(i)),
|
|
@@ -4704,7 +4727,7 @@ class zt {
|
|
|
4704
4727
|
#i = void 0;
|
|
4705
4728
|
#s = 1;
|
|
4706
4729
|
constructor(t, e) {
|
|
4707
|
-
return t && e && (this.#t = t, this.#e = new
|
|
4730
|
+
return t && e && (this.#t = t, this.#e = new a(e).clone().pow(2), this.#n()), this;
|
|
4708
4731
|
}
|
|
4709
4732
|
fromEquation(t) {
|
|
4710
4733
|
const e = new x(t).moveLeft().reduce(), i = ["x", "y", "z"];
|
|
@@ -4798,7 +4821,7 @@ class zt {
|
|
|
4798
4821
|
z: t.z
|
|
4799
4822
|
}) ?? !1;
|
|
4800
4823
|
}
|
|
4801
|
-
function
|
|
4824
|
+
function G(n) {
|
|
4802
4825
|
const t = Object.assign(
|
|
4803
4826
|
{
|
|
4804
4827
|
negative: !0,
|
|
@@ -4808,13 +4831,13 @@ function F(n) {
|
|
|
4808
4831
|
natural: !1
|
|
4809
4832
|
},
|
|
4810
4833
|
n
|
|
4811
|
-
), e = new
|
|
4812
|
-
if (t.negative ? e.numerator = A(t.max, t.zero) : e.numerator =
|
|
4834
|
+
), e = new a();
|
|
4835
|
+
if (t.negative ? e.numerator = A(t.max, t.zero) : e.numerator = T(t.zero ? 0 : 1, t.max), t.natural)
|
|
4813
4836
|
e.denominator = 1;
|
|
4814
4837
|
else {
|
|
4815
4838
|
let i = 0;
|
|
4816
4839
|
for (; e.isRelative() && i < 10; )
|
|
4817
|
-
e.denominator =
|
|
4840
|
+
e.denominator = T(1, t.max), i++;
|
|
4818
4841
|
}
|
|
4819
4842
|
return t.reduced ? e.reduce() : e;
|
|
4820
4843
|
}
|
|
@@ -4828,7 +4851,7 @@ function ct(n) {
|
|
|
4828
4851
|
},
|
|
4829
4852
|
n
|
|
4830
4853
|
), e = new p();
|
|
4831
|
-
if (e.coefficient =
|
|
4854
|
+
if (e.coefficient = G({
|
|
4832
4855
|
zero: t.zero,
|
|
4833
4856
|
reduced: !0,
|
|
4834
4857
|
natural: !t.fraction
|
|
@@ -4836,7 +4859,7 @@ function ct(n) {
|
|
|
4836
4859
|
for (const i of t.letters.split(""))
|
|
4837
4860
|
e.setLetter(i, 0);
|
|
4838
4861
|
for (let i = 0; i < t.degree; i++) {
|
|
4839
|
-
const s =
|
|
4862
|
+
const s = X(t.letters.split(""));
|
|
4840
4863
|
e.setLetter(s, e.degree(s).clone().add(1));
|
|
4841
4864
|
}
|
|
4842
4865
|
} else
|
|
@@ -4874,7 +4897,7 @@ function it(n) {
|
|
|
4874
4897
|
}), t.unit && s === r && i.coefficient.one(), e.add(i);
|
|
4875
4898
|
if (t.positive && e.monomByDegree().coefficient.isNegative() && e.opposite(), t.numberOfMonoms && t.numberOfMonoms > 0 && t.numberOfMonoms < e.length)
|
|
4876
4899
|
for (; e.length > t.numberOfMonoms; ) {
|
|
4877
|
-
const r =
|
|
4900
|
+
const r = T(1, e.length - 1);
|
|
4878
4901
|
e.monoms.splice(r, 1);
|
|
4879
4902
|
}
|
|
4880
4903
|
return e.reduce();
|
|
@@ -4890,7 +4913,7 @@ function Rt(n) {
|
|
|
4890
4913
|
i.push(it(e));
|
|
4891
4914
|
if (n?.commonConstant !== !1) {
|
|
4892
4915
|
let r = A(10, !1);
|
|
4893
|
-
n?.commonConstant === !0 && (r === 1 || r === -1) && (r *=
|
|
4916
|
+
n?.commonConstant === !0 && (r === 1 || r === -1) && (r *= T(2, 5)), r !== 1 && r !== -1 && i.unshift(new l(r));
|
|
4894
4917
|
}
|
|
4895
4918
|
return l.xMultiply(...i);
|
|
4896
4919
|
}
|
|
@@ -4936,7 +4959,7 @@ function J(n) {
|
|
|
4936
4959
|
quadrant: null
|
|
4937
4960
|
},
|
|
4938
4961
|
n
|
|
4939
|
-
), e = t.axis === "x", i = t.axis === "y", s = t.fraction ?
|
|
4962
|
+
), e = t.axis === "x", i = t.axis === "y", s = t.fraction ? G({ max: t.max, zero: e }) : new a(A(t.max, e)), r = t.fraction ? G({ max: t.max, zero: i }) : new a(A(t.max, i));
|
|
4940
4963
|
return Number(t.quadrant) === 1 && (s.abs(), r.abs()), Number(t.quadrant) === 2 && (s.isPositive() && s.opposite(), r.isNegative() && r.opposite()), Number(t.quadrant) === 3 && (s.isPositive() && s.opposite(), r.isPositive() && r.opposite()), Number(t.quadrant) === 4 && (s.isNegative() && s.opposite(), r.isPositive() && r.opposite()), new w(s, r);
|
|
4941
4964
|
}
|
|
4942
4965
|
function Dt(n) {
|
|
@@ -4951,7 +4974,7 @@ function Dt(n) {
|
|
|
4951
4974
|
n
|
|
4952
4975
|
), e = J(t.center);
|
|
4953
4976
|
let i, s;
|
|
4954
|
-
return t.pointsOnCircle === 8 ? (i =
|
|
4977
|
+
return t.pointsOnCircle === 8 ? (i = T(1, 3), s = i ** 2 + (i + 1) ** 2) : s = T(1, 20), new U(e, s, !0);
|
|
4955
4978
|
}
|
|
4956
4979
|
function Vt(n) {
|
|
4957
4980
|
const t = Object.assign(
|
|
@@ -4983,20 +5006,20 @@ function Lt(n) {
|
|
|
4983
5006
|
},
|
|
4984
5007
|
n
|
|
4985
5008
|
), e = new w(t.A.x, t.A.y, t.A.z), i = new g(t.direction.x, t.direction.y, t.direction.z);
|
|
4986
|
-
return new
|
|
5009
|
+
return new Y(e, i);
|
|
4987
5010
|
}
|
|
4988
5011
|
const Ut = {
|
|
4989
5012
|
equation: (n) => Zt(n),
|
|
4990
5013
|
polynom: (n) => it(n),
|
|
4991
5014
|
monom: (n) => ct(n),
|
|
4992
|
-
fraction: (n) =>
|
|
4993
|
-
number: (n, t, e) =>
|
|
5015
|
+
fraction: (n) => G(n),
|
|
5016
|
+
number: (n, t, e) => T(n, t, e),
|
|
4994
5017
|
numberSym: (n, t) => A(n, t),
|
|
4995
5018
|
prime: (n) => It(n),
|
|
4996
5019
|
triplet: (n, t) => St(n, t),
|
|
4997
5020
|
bool: (n) => ot(n),
|
|
4998
5021
|
array: (n, t) => Pt(n, t),
|
|
4999
|
-
item: (n) =>
|
|
5022
|
+
item: (n) => X(n),
|
|
5000
5023
|
shuffle: (n) => ht(n),
|
|
5001
5024
|
line: (n) => Vt(n),
|
|
5002
5025
|
line3: (n) => Lt(n),
|
|
@@ -5005,8 +5028,8 @@ const Ut = {
|
|
|
5005
5028
|
circle: (n) => Dt(n)
|
|
5006
5029
|
}, Gt = {
|
|
5007
5030
|
Numeric: b,
|
|
5008
|
-
Fraction:
|
|
5009
|
-
Root:
|
|
5031
|
+
Fraction: a,
|
|
5032
|
+
Root: O,
|
|
5010
5033
|
Monom: p,
|
|
5011
5034
|
Polynom: l,
|
|
5012
5035
|
Equation: x,
|
|
@@ -5022,7 +5045,7 @@ const Ut = {
|
|
|
5022
5045
|
Line: E,
|
|
5023
5046
|
Triangle: L,
|
|
5024
5047
|
Circle: U,
|
|
5025
|
-
Line3:
|
|
5048
|
+
Line3: Y,
|
|
5026
5049
|
Plane3: et,
|
|
5027
5050
|
Sphere3: zt
|
|
5028
5051
|
},
|
|
@@ -5035,9 +5058,9 @@ export {
|
|
|
5035
5058
|
D as FACTOR_DISPLAY,
|
|
5036
5059
|
bt as FRAC_TYPE,
|
|
5037
5060
|
y as Factor,
|
|
5038
|
-
|
|
5061
|
+
a as Fraction,
|
|
5039
5062
|
E as Line,
|
|
5040
|
-
|
|
5063
|
+
Y as Line3,
|
|
5041
5064
|
P as LinearSystem,
|
|
5042
5065
|
$t as LogicalSet,
|
|
5043
5066
|
B as Matrix,
|
|
@@ -5049,7 +5072,7 @@ export {
|
|
|
5049
5072
|
N as PolyFactor,
|
|
5050
5073
|
l as Polynom,
|
|
5051
5074
|
Ut as Random,
|
|
5052
|
-
|
|
5075
|
+
O as Root,
|
|
5053
5076
|
at as SPHERE3_RELATIVE_POSITION,
|
|
5054
5077
|
C as Solution,
|
|
5055
5078
|
zt as Sphere3,
|