pimath 0.2.2 → 0.2.4
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 +733 -699
- package/dist/pimath.js.map +1 -1
- package/package.json +1 -1
- package/src/algebra/equation.ts +1 -1
- package/src/algebra/monom.ts +89 -144
- package/src/algebra/polynom.ts +165 -189
- package/src/coefficients/fraction.ts +71 -42
- package/src/coefficients/root.ts +5 -4
- package/src/geometry/triangle.ts +11 -6
- package/src/index.ts +1 -0
- package/src/numeric.ts +6 -0
- package/src/randomization/algebra/rndPolynom.ts +7 -4
- package/types/algebra/monom.d.ts +1 -1
- package/types/algebra/monom.d.ts.map +1 -1
- package/types/algebra/polynom.d.ts +39 -41
- package/types/algebra/polynom.d.ts.map +1 -1
- package/types/coefficients/fraction.d.ts +5 -6
- package/types/coefficients/fraction.d.ts.map +1 -1
- package/types/coefficients/root.d.ts.map +1 -1
- package/types/geometry/triangle.d.ts.map +1 -1
- package/types/index.d.ts +10 -9
- package/types/index.d.ts.map +1 -1
- package/types/numeric.d.ts.map +1 -1
- package/types/randomization/algebra/rndPolynom.d.ts.map +1 -1
package/dist/pimath.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
function ut(n) {
|
|
2
|
-
const t =
|
|
2
|
+
const t = st(n), e = [];
|
|
3
3
|
let i, s;
|
|
4
4
|
for (; t.length > 0; )
|
|
5
5
|
i = t.shift() ?? 1, s = (t.length > 0 ? t.pop() : +i) ?? 1, e.push([i, s]);
|
|
6
6
|
return e;
|
|
7
7
|
}
|
|
8
8
|
function ft(...n) {
|
|
9
|
-
const t =
|
|
9
|
+
const t = J(...n);
|
|
10
10
|
return n.map((e) => e / t);
|
|
11
11
|
}
|
|
12
|
-
function
|
|
12
|
+
function st(n) {
|
|
13
13
|
const t = Math.abs(n), e = Math.sqrt(t), i = [];
|
|
14
14
|
for (let s = 1; s <= e; s++)
|
|
15
15
|
n % s === 0 && (i.push(s), i.push(t / s));
|
|
@@ -17,9 +17,9 @@ function rt(n) {
|
|
|
17
17
|
return s - r;
|
|
18
18
|
}), [...new Set(i)];
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function J(...n) {
|
|
21
21
|
const t = function(s, r) {
|
|
22
|
-
return r === 0 ? s : t(r, s % r);
|
|
22
|
+
return isNaN(s) || isNaN(r) ? NaN : r === 0 ? s : s === 0 ? r : t(r, s % r);
|
|
23
23
|
};
|
|
24
24
|
let e = 1, i = 2;
|
|
25
25
|
if (n.length === 0)
|
|
@@ -34,7 +34,7 @@ function _(...n) {
|
|
|
34
34
|
}
|
|
35
35
|
function dt(...n) {
|
|
36
36
|
return n.reduce(function(t, e) {
|
|
37
|
-
return Math.abs(t * e /
|
|
37
|
+
return Math.abs(t * e / J(t, e));
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
function pt(n, t = 3) {
|
|
@@ -72,9 +72,9 @@ function vt(n, t) {
|
|
|
72
72
|
}
|
|
73
73
|
const x = {
|
|
74
74
|
decompose: ut,
|
|
75
|
-
dividers:
|
|
75
|
+
dividers: st,
|
|
76
76
|
divideNumbersByGCD: ft,
|
|
77
|
-
gcd:
|
|
77
|
+
gcd: J,
|
|
78
78
|
lcm: dt,
|
|
79
79
|
numberCorrection: pt,
|
|
80
80
|
periodic: mt,
|
|
@@ -84,7 +84,7 @@ const x = {
|
|
|
84
84
|
greatestPower: vt
|
|
85
85
|
};
|
|
86
86
|
var xt = /* @__PURE__ */ ((n) => (n.frac = "frac", n.dfrac = "dfrac", n.tfrac = "tfrac", n))(xt || {});
|
|
87
|
-
class
|
|
87
|
+
class h {
|
|
88
88
|
#t = 1;
|
|
89
89
|
#e = 3;
|
|
90
90
|
#i = !0;
|
|
@@ -99,10 +99,10 @@ class a {
|
|
|
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 == "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 h ? this.copy(t) : this;
|
|
103
103
|
clone = () => {
|
|
104
|
-
const t = new
|
|
105
|
-
return t.numerator = this.#s, t.denominator = this.#t, t.exact = this.exact, t;
|
|
104
|
+
const t = new h();
|
|
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) {
|
|
108
108
|
return this.#s = t.numerator, this.#t = t.denominator, this.#i = t.exact, this;
|
|
@@ -119,66 +119,70 @@ class a {
|
|
|
119
119
|
const t = this.#n && this.isPositive() ? "+" : "";
|
|
120
120
|
return this.exact ? this.#t === 1 ? `${t}${this.#s}` : `${t}${this.#s}/${this.#t}` : t + this.value.toFixed(this.#e);
|
|
121
121
|
}
|
|
122
|
+
static areEquals = (...t) => t.every((e) => e.isEqual(t[0]));
|
|
122
123
|
static average = (...t) => {
|
|
123
|
-
const e = new
|
|
124
|
+
const e = new h().zero();
|
|
124
125
|
for (const i of t)
|
|
125
126
|
e.add(i);
|
|
126
127
|
return e.divide(t.length), e;
|
|
127
128
|
};
|
|
128
129
|
static isFraction(t) {
|
|
129
|
-
if (t instanceof
|
|
130
|
+
if (t instanceof h || typeof t == "number" && !isNaN(t))
|
|
130
131
|
return !0;
|
|
131
132
|
if (typeof t == "string") {
|
|
132
|
-
const
|
|
133
|
-
return
|
|
133
|
+
const e = t.split("/");
|
|
134
|
+
return e.length <= 2 && e.every((i) => !isNaN(+i));
|
|
134
135
|
}
|
|
135
136
|
return !1;
|
|
136
137
|
}
|
|
137
138
|
static max = (...t) => {
|
|
138
|
-
let e = new
|
|
139
|
+
let e = new h(t[0]);
|
|
139
140
|
for (const i of t) {
|
|
140
|
-
const s = new
|
|
141
|
+
const s = new h(i);
|
|
141
142
|
s.isGreater(e) && (e = s.clone());
|
|
142
143
|
}
|
|
143
144
|
return e;
|
|
144
145
|
};
|
|
145
146
|
static min = (...t) => {
|
|
146
|
-
let e = new
|
|
147
|
+
let e = new h(t[0]);
|
|
147
148
|
for (const i of t) {
|
|
148
|
-
const s = new
|
|
149
|
+
const s = new h(i);
|
|
149
150
|
s.isLesser(e) && (e = s.clone());
|
|
150
151
|
}
|
|
151
152
|
return e;
|
|
152
153
|
};
|
|
153
154
|
static sort = (t, e) => {
|
|
154
|
-
const s = t.map((r) => r instanceof
|
|
155
|
+
const s = t.map((r) => r instanceof h ? r : new h(r)).sort((r, o) => r.value - o.value);
|
|
155
156
|
return e && s.reverse(), s;
|
|
156
157
|
};
|
|
157
158
|
static toSameDenominateur(...t) {
|
|
158
|
-
const e = t.map((s) => new
|
|
159
|
+
const e = t.map((s) => new h(s)), i = x.lcm(...e.map((s) => s.denominator));
|
|
159
160
|
return e.forEach((s) => s.amplify(i / s.denominator)), e;
|
|
160
161
|
}
|
|
161
162
|
static unique = (t) => {
|
|
162
163
|
const e = {}, i = [];
|
|
163
164
|
return t.forEach((s) => {
|
|
164
|
-
s instanceof
|
|
165
|
+
s instanceof h || (s = new h(s)), e[s.clone().reduce().tex] || (i.push(s.clone()), e[s.clone().reduce().tex] = !0);
|
|
165
166
|
}), i;
|
|
166
167
|
};
|
|
167
168
|
static xMultiply = (...t) => {
|
|
168
|
-
const e = new
|
|
169
|
+
const e = new h();
|
|
169
170
|
return t.forEach((i) => e.multiply(i, !1)), e;
|
|
170
171
|
};
|
|
171
172
|
abs = () => (this.#s = Math.abs(this.#s), this.#t = Math.abs(this.#t), this);
|
|
172
173
|
add = (t) => {
|
|
173
|
-
if (t instanceof
|
|
174
|
+
if (t instanceof h) {
|
|
174
175
|
const e = this.#s, i = this.#t;
|
|
175
176
|
this.#s = e * t.denominator + t.numerator * i, this.#t = i * t.denominator, this.exact = this.exact && t.exact;
|
|
176
177
|
} else
|
|
177
|
-
return this.add(new
|
|
178
|
+
return this.add(new h(t));
|
|
178
179
|
return this.reduce();
|
|
179
180
|
};
|
|
180
|
-
amplify = (t) =>
|
|
181
|
-
|
|
181
|
+
amplify = (t) => {
|
|
182
|
+
if (!Number.isSafeInteger(t))
|
|
183
|
+
throw new Error("The amplification factor must be a safe integer.");
|
|
184
|
+
return this.#s *= t, this.#t *= t, this;
|
|
185
|
+
};
|
|
182
186
|
/**
|
|
183
187
|
* Compare the current coefficient with another coefficient
|
|
184
188
|
* @param F (Coefficient) The coefficient to _compare
|
|
@@ -187,7 +191,7 @@ class a {
|
|
|
187
191
|
compare = (t, e) => {
|
|
188
192
|
e ??= "=";
|
|
189
193
|
let i;
|
|
190
|
-
switch (t instanceof
|
|
194
|
+
switch (t instanceof h ? i = t.clone() : i = new h(t), e) {
|
|
191
195
|
case ">":
|
|
192
196
|
return this.value > i.value;
|
|
193
197
|
case ">=":
|
|
@@ -201,9 +205,9 @@ class a {
|
|
|
201
205
|
case "leq":
|
|
202
206
|
return this.value <= i.value;
|
|
203
207
|
case "=":
|
|
204
|
-
return this.
|
|
208
|
+
return this.#s * i.denominator === i.numerator * this.#t;
|
|
205
209
|
case "<>":
|
|
206
|
-
return this.
|
|
210
|
+
return this.#s * i.denominator !== i.numerator * this.#t;
|
|
207
211
|
default:
|
|
208
212
|
return !1;
|
|
209
213
|
}
|
|
@@ -221,9 +225,9 @@ class a {
|
|
|
221
225
|
return this.#e = t, this;
|
|
222
226
|
}
|
|
223
227
|
divide = (t) => {
|
|
224
|
-
const e = new
|
|
228
|
+
const e = new h(t);
|
|
225
229
|
if (e.numerator === 0)
|
|
226
|
-
return
|
|
230
|
+
return this.infinite();
|
|
227
231
|
const i = this.#s, s = this.#t;
|
|
228
232
|
return this.#s = i * e.denominator, this.#t = s * e.numerator, this.exact = this.exact && e.exact, this.reduce();
|
|
229
233
|
};
|
|
@@ -246,12 +250,17 @@ class a {
|
|
|
246
250
|
return Number.isSafeInteger(t) && Number.isSafeInteger(e) ? (this.#s = t, this.#t = e, this.#i = !0, this) : this.fromNumber(t / e);
|
|
247
251
|
}
|
|
248
252
|
fromPeriodic(t, e) {
|
|
249
|
-
const [, i] = t.toString().split(/[.,]/), s = i ? i.length : 0
|
|
253
|
+
const [, i] = t.toString().split(/[.,]/), s = i ? i.length : 0;
|
|
254
|
+
if (!Number.isSafeInteger(e) || e <= 0)
|
|
255
|
+
throw new Error("The periodic length must be a positive integer.");
|
|
256
|
+
if (e > s)
|
|
257
|
+
throw new Error(`The periodic length (${e}) cannot exceed the number of decimal digits (${s}).`);
|
|
258
|
+
const r = Math.pow(10, s);
|
|
250
259
|
return this.#s = +t * r - Math.floor(+t * Math.pow(10, s - e)), this.#t = r - Math.pow(10, s - e), this.#i = !0, this;
|
|
251
260
|
}
|
|
252
261
|
fromString(t) {
|
|
253
262
|
const e = t.split("/").map(Number);
|
|
254
|
-
return this.#i = !0, e.length > 2 ? (this.#s = NaN, this) : e.some((i) => isNaN(i)) ? (this.#s = NaN, this) : e.length === 1 ? this.fromNumber(+t) : e[1] === 0 ? (
|
|
263
|
+
return this.#i = !0, e.length > 2 ? (this.#s = NaN, this) : e.some((i) => isNaN(i)) ? (this.#s = NaN, this) : e.length === 1 ? this.fromNumber(+t) : e[1] === 0 ? this.infinite() : (this.#s = e[0], this.#t = e[1], this);
|
|
255
264
|
}
|
|
256
265
|
infinite = () => (this.#s = 1 / 0, this.#t = 1, this.exact = !0, this);
|
|
257
266
|
invalid = () => (this.#s = NaN, this.#t = 1, this.exact = !0, this);
|
|
@@ -272,7 +281,7 @@ class a {
|
|
|
272
281
|
isNegative = () => this.sign() === -1;
|
|
273
282
|
isNotEqual = (t) => this.compare(t, "<>");
|
|
274
283
|
isNotZero = () => this.#s !== 0;
|
|
275
|
-
isOdd = () => this.isRelative() && this.value % 2 === 1;
|
|
284
|
+
isOdd = () => this.isRelative() && Math.abs(this.value % 2) === 1;
|
|
276
285
|
isOne = () => this.#s === 1 && this.#t === 1;
|
|
277
286
|
isPositive = () => this.sign() === 1;
|
|
278
287
|
isRational = () => this.exact && !this.isRelative();
|
|
@@ -287,7 +296,7 @@ class a {
|
|
|
287
296
|
// Mathematical operations specific to fractions
|
|
288
297
|
isZero = () => this.#s === 0;
|
|
289
298
|
multiply = (t, e = !0) => {
|
|
290
|
-
const i = new
|
|
299
|
+
const i = new h(t);
|
|
291
300
|
return this.#s = this.#s * i.numerator, this.#t = this.#t * i.denominator, this.exact = this.exact && i.exact, e ? this.reduce() : this;
|
|
292
301
|
};
|
|
293
302
|
// ------------------------------------------
|
|
@@ -300,11 +309,11 @@ class a {
|
|
|
300
309
|
one = () => this.fromNumber(1);
|
|
301
310
|
opposite = () => (this.#s = -this.#s, this);
|
|
302
311
|
pow = (t) => {
|
|
303
|
-
if (t instanceof
|
|
312
|
+
if (t instanceof h)
|
|
304
313
|
return this.pow(t.value);
|
|
305
314
|
this.reduce(), t < 0 && this.inverse();
|
|
306
|
-
const e = Math.
|
|
307
|
-
return
|
|
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);
|
|
316
|
+
return r === i && o === s ? (this.#s = r, this.#t = o) : (this.#s = i / s, this.#t = 1, this.exact = !1), this;
|
|
308
317
|
};
|
|
309
318
|
reduce = () => {
|
|
310
319
|
const t = x.gcd(this.#s, this.#t);
|
|
@@ -313,9 +322,9 @@ class a {
|
|
|
313
322
|
root = (t) => {
|
|
314
323
|
if (t === 0)
|
|
315
324
|
return this;
|
|
316
|
-
if (
|
|
325
|
+
if (!Number.isSafeInteger(t))
|
|
317
326
|
throw new Error("The root must be an integer.");
|
|
318
|
-
if (this.isNegative() && t % 2 === 0)
|
|
327
|
+
if (t < 0 && this.inverse(), this.isNegative() && t % 2 === 0)
|
|
319
328
|
throw new Error("The root of a negative number must be odd.");
|
|
320
329
|
const e = this.sign();
|
|
321
330
|
this.abs(), this.reduce();
|
|
@@ -324,10 +333,7 @@ class a {
|
|
|
324
333
|
};
|
|
325
334
|
sign = () => this.#s * this.#t >= 0 ? 1 : -1;
|
|
326
335
|
sqrt = () => this.root(2);
|
|
327
|
-
subtract = (t) => t instanceof
|
|
328
|
-
get texWithSign() {
|
|
329
|
-
return this.isPositive() ? `+${this.tex}` : this.tex;
|
|
330
|
-
}
|
|
336
|
+
subtract = (t) => t instanceof h ? this.add(t.clone().opposite()) : this.add(-t);
|
|
331
337
|
get tfrac() {
|
|
332
338
|
return this.#r = "tfrac", this;
|
|
333
339
|
}
|
|
@@ -343,13 +349,13 @@ class a {
|
|
|
343
349
|
}
|
|
344
350
|
zero = () => this.fromNumber(0);
|
|
345
351
|
}
|
|
346
|
-
function
|
|
352
|
+
function it(n, t = !0) {
|
|
347
353
|
return t ? `\\left( ${n} \\right)` : `(${n})`;
|
|
348
354
|
}
|
|
349
355
|
function Q(n) {
|
|
350
356
|
return n.startsWith("(") && (n = n.substring(1)), n.endsWith(")") && (n = n.substring(0, n.length - 1)), n;
|
|
351
357
|
}
|
|
352
|
-
function
|
|
358
|
+
function j(n, t, e, i, s) {
|
|
353
359
|
return n.map((r, o) => r === t ? e : r);
|
|
354
360
|
}
|
|
355
361
|
class T {
|
|
@@ -358,29 +364,29 @@ class T {
|
|
|
358
364
|
#i;
|
|
359
365
|
#s = !1;
|
|
360
366
|
constructor(t) {
|
|
361
|
-
return this.#e = 2, this.#t = new
|
|
367
|
+
return this.#e = 2, this.#t = new h().zero(), this.#i = new h().zero(), t && this.parse(t), this;
|
|
362
368
|
}
|
|
363
369
|
parse(t) {
|
|
364
370
|
if (t instanceof T)
|
|
365
371
|
return this.index = t.index, this.radical = t.radical.clone(), this.factor = t.factor.clone(), this;
|
|
366
|
-
if (t instanceof
|
|
372
|
+
if (t instanceof h)
|
|
367
373
|
return this.index = 2, this.factor = t.clone(), this.radical.one(), this;
|
|
368
374
|
if (typeof t == "string") {
|
|
369
375
|
if (t.includes("sqrt"))
|
|
370
|
-
return this.#
|
|
376
|
+
return this.#a(t);
|
|
371
377
|
if (t.includes("root"))
|
|
372
378
|
return this.#o(t);
|
|
373
379
|
}
|
|
374
|
-
return this.index = 2, this.factor = new
|
|
380
|
+
return this.index = 2, this.factor = new h(t), this.radical.one(), this;
|
|
375
381
|
}
|
|
376
382
|
clone() {
|
|
377
383
|
return new T().from(this.index, this.radical, this.factor);
|
|
378
384
|
}
|
|
379
385
|
get tex() {
|
|
380
|
-
const t = this.#s && this.factor.isPositive() ? "+" : "";
|
|
386
|
+
const t = this.#s && this.factor.isPositive() ? "+" : "", e = t && this.#t.numerator === 1 ? " " : "";
|
|
381
387
|
if (this.value === 0) return `${t}0`;
|
|
382
|
-
const
|
|
383
|
-
return
|
|
388
|
+
const i = this.#n(this.#t.denominator, this.#i.denominator), s = this.#n(this.#t.numerator, this.#i.numerator) ?? "1";
|
|
389
|
+
return i === null ? `${t}${e}${s}` : `${t}${e}\\frac{ ${s} }{ ${i} }`;
|
|
384
390
|
}
|
|
385
391
|
get display() {
|
|
386
392
|
const t = this.#s && this.factor.isPositive() ? "+" : "";
|
|
@@ -405,7 +411,7 @@ class T {
|
|
|
405
411
|
this.#t = t;
|
|
406
412
|
}
|
|
407
413
|
from(t, e, i) {
|
|
408
|
-
return this.index = t, this.radical = new
|
|
414
|
+
return this.index = t, this.radical = new h(e), this.factor = i ? new h(i) : new h().one(), this;
|
|
409
415
|
}
|
|
410
416
|
/**
|
|
411
417
|
* convert to root(index)(radical), without factor
|
|
@@ -422,7 +428,7 @@ class T {
|
|
|
422
428
|
this.#e = t;
|
|
423
429
|
}
|
|
424
430
|
get indexAsPow() {
|
|
425
|
-
return new
|
|
431
|
+
return new h(this.index).inverse();
|
|
426
432
|
}
|
|
427
433
|
inverse() {
|
|
428
434
|
return this.factor.inverse(), this.radical.inverse(), this;
|
|
@@ -499,25 +505,25 @@ class T {
|
|
|
499
505
|
}
|
|
500
506
|
#r(t, e, i) {
|
|
501
507
|
const s = this.#e === 2 ? "sqrt" : `root(${this.#e})`, r = [
|
|
502
|
-
t
|
|
508
|
+
t === 1 || t === 0 ? null : t === -1 ? "-" : t.toString(),
|
|
503
509
|
e !== 1 && e !== 0 ? `${s}(${e})` : null
|
|
504
510
|
].filter((o) => o !== null);
|
|
505
511
|
return r.length === 0 ? null : i && r.length === 2 ? `(${r.join("")})` : r.join("");
|
|
506
512
|
}
|
|
507
513
|
#n(t, e) {
|
|
508
514
|
const i = this.#e === 2 ? "\\sqrt" : `\\sqrt[ ${this.#e} ]`, s = [
|
|
509
|
-
t
|
|
515
|
+
t === 1 || t === 0 ? null : t === -1 ? "-" : t.toString(),
|
|
510
516
|
e !== 1 && e !== 0 ? `${i}{ ${e} }` : null
|
|
511
517
|
].filter((r) => r !== null);
|
|
512
518
|
return s.length === 0 ? null : s.join(" ");
|
|
513
519
|
}
|
|
514
520
|
#o(t) {
|
|
515
521
|
const [e, i] = t.split("root"), [s, r] = i.split(")");
|
|
516
|
-
return this.index = +Q(s), this.radical = new
|
|
522
|
+
return this.index = +Q(s), this.radical = new h(Q(r)), this.factor = e === "" ? new h().one() : new h(e), this;
|
|
517
523
|
}
|
|
518
|
-
#
|
|
524
|
+
#a(t) {
|
|
519
525
|
const [e, i] = t.split("sqrt");
|
|
520
|
-
return this.index = 2, this.radical = new
|
|
526
|
+
return this.index = 2, this.radical = new h(Q(i)), this.factor = e === "" ? new h().one() : new h(e), this;
|
|
521
527
|
}
|
|
522
528
|
}
|
|
523
529
|
class C {
|
|
@@ -529,13 +535,13 @@ class C {
|
|
|
529
535
|
#n;
|
|
530
536
|
#o;
|
|
531
537
|
constructor() {
|
|
532
|
-
this.#o = "x", this.#i = !1, this.#e = null, this.#n = null, this.#s = new
|
|
538
|
+
this.#o = "x", this.#i = !1, this.#e = null, this.#n = null, this.#s = new h().zero(), this.#r = new T(), this.#t = 1;
|
|
533
539
|
}
|
|
534
540
|
get tex() {
|
|
535
541
|
if (this.#n) return this.#n;
|
|
536
542
|
if (this.#r.isZero()) return this.#s.tex;
|
|
537
543
|
if (this.#s.isZero()) return this.#r.tex;
|
|
538
|
-
const [t] =
|
|
544
|
+
const [t] = h.toSameDenominateur(this.#s, this.#r.factor), e = this.#r.clone().multiply(t.denominator).reduce(), i = `${t.numerator} ${e.withSign.tex}`;
|
|
539
545
|
return t.denominator === 1 ? i : `\\frac{ ${i} }{ ${t.denominator} }`;
|
|
540
546
|
}
|
|
541
547
|
set tex(t) {
|
|
@@ -545,7 +551,7 @@ class C {
|
|
|
545
551
|
if (this.#e) return this.#e;
|
|
546
552
|
if (this.#r.isZero()) return this.#s.display;
|
|
547
553
|
if (this.#s.isZero()) return this.#r.display;
|
|
548
|
-
const [t] =
|
|
554
|
+
const [t] = h.toSameDenominateur(this.#s, this.#r.factor), e = this.#r.clone().multiply(t.denominator).reduce(), i = `${t.numerator}${e.withSign.display}`;
|
|
549
555
|
return t.denominator === 1 ? i : `(${i})/${t.denominator}`;
|
|
550
556
|
}
|
|
551
557
|
set display(t) {
|
|
@@ -554,21 +560,21 @@ class C {
|
|
|
554
560
|
static fromFraction(t) {
|
|
555
561
|
const e = new C();
|
|
556
562
|
e.setExact();
|
|
557
|
-
const i = new
|
|
563
|
+
const i = new h(t);
|
|
558
564
|
return e.display = i.display, e.tex = i.tex, e.fraction = i, e.root = new T(), e;
|
|
559
565
|
}
|
|
560
566
|
static fromQuadratic(t, e, i) {
|
|
561
|
-
const [s, r, o] = [t, e, i].map((m) => new
|
|
562
|
-
if (
|
|
567
|
+
const [s, r, o] = [t, e, i].map((m) => new h(m)), a = r.clone().pow(2).subtract(s.clone().multiply(o).multiply(4));
|
|
568
|
+
if (a.isNegative())
|
|
563
569
|
return [];
|
|
564
|
-
if (
|
|
565
|
-
const m =
|
|
570
|
+
if (a.isSquare()) {
|
|
571
|
+
const m = a.sqrt(), d = r.clone().opposite().subtract(m).divide(s.clone().multiply(2)), y = r.clone().opposite().add(m).divide(s.clone().multiply(2));
|
|
566
572
|
return m.isZero() ? [C.fromFraction(d)] : [C.fromFraction(d), C.fromFraction(y)];
|
|
567
573
|
}
|
|
568
574
|
const c = new C();
|
|
569
|
-
c.fraction = r.clone().opposite().divide(s).divide(2), c.root = new T().from(2,
|
|
575
|
+
c.fraction = r.clone().opposite().divide(s).divide(2), c.root = new T().from(2, a, s.clone().multiply(2).inverse().opposite()), c.setExact(!1);
|
|
570
576
|
const f = new C();
|
|
571
|
-
return f.fraction = r.clone().opposite().divide(s).divide(2), f.root = new T().from(2,
|
|
577
|
+
return f.fraction = r.clone().opposite().divide(s).divide(2), f.root = new T().from(2, a, s.clone().multiply(2).inverse()), f.setExact(!1), [c, f];
|
|
572
578
|
}
|
|
573
579
|
get count() {
|
|
574
580
|
return this.#t;
|
|
@@ -613,7 +619,7 @@ class C {
|
|
|
613
619
|
t !== void 0 && (this.#o = t);
|
|
614
620
|
}
|
|
615
621
|
}
|
|
616
|
-
class
|
|
622
|
+
class Ut {
|
|
617
623
|
#t;
|
|
618
624
|
#e;
|
|
619
625
|
constructor(t) {
|
|
@@ -666,19 +672,19 @@ class R {
|
|
|
666
672
|
solveAsCardan() {
|
|
667
673
|
if (this.#e.degree().value !== 3)
|
|
668
674
|
throw new Error("The equation is not cubic.");
|
|
669
|
-
return this.#
|
|
675
|
+
return this.#h();
|
|
670
676
|
}
|
|
671
677
|
#s(t, e) {
|
|
672
678
|
const i = new C();
|
|
673
|
-
return i.exact = !1, i.tex = e?.tex ?? null, i.display = e?.display ?? null, i.fraction = new
|
|
679
|
+
return i.exact = !1, i.tex = e?.tex ?? null, i.display = e?.display ?? null, i.fraction = new h(t), i.fraction.exact = !1, i.variable = this.#i, i;
|
|
674
680
|
}
|
|
675
681
|
#r(t) {
|
|
676
|
-
return t instanceof
|
|
682
|
+
return t instanceof h && !t.exact ? this.#s(t.value) : C.fromFraction(t);
|
|
677
683
|
}
|
|
678
684
|
// Solve using bissection algorithm (approximative solution)
|
|
679
685
|
#n(t) {
|
|
680
|
-
const e = [], i = t.degree().value, [s, ...r] = t.getCoefficients(), o = 2 + Math.max(...r.map((f) => f.value / s.value)),
|
|
681
|
-
return this.#a
|
|
686
|
+
const e = [], i = t.degree().value, [s, ...r] = t.getCoefficients(), o = 2 + Math.max(...r.map((f) => f.value / s.value)), a = this.#a(t, o, 100);
|
|
687
|
+
return this.#c(a, i).forEach((f) => {
|
|
682
688
|
const [m, d] = f;
|
|
683
689
|
if (m === d)
|
|
684
690
|
e.push(this.#r(m));
|
|
@@ -695,27 +701,27 @@ class R {
|
|
|
695
701
|
let o;
|
|
696
702
|
for (; (i - e) / 2 > this.#t; ) {
|
|
697
703
|
this._++, o = (e + i) / 2;
|
|
698
|
-
const
|
|
699
|
-
if (
|
|
704
|
+
const a = t.evaluate(o, !0);
|
|
705
|
+
if (a === 0)
|
|
700
706
|
return o;
|
|
701
|
-
s *
|
|
707
|
+
s * a < 0 ? (i = o, r = a) : (e = o, s = a);
|
|
702
708
|
}
|
|
703
709
|
return (e + i) / 2;
|
|
704
710
|
}
|
|
705
|
-
#
|
|
711
|
+
#a(t, e, i) {
|
|
706
712
|
const s = [], r = 2 * e / i;
|
|
707
713
|
for (let o = -e; o <= e; o += r) {
|
|
708
|
-
const
|
|
714
|
+
const a = x.numberCorrection(o);
|
|
709
715
|
s.push(
|
|
710
716
|
{
|
|
711
|
-
x:
|
|
712
|
-
fx: t.evaluate(
|
|
717
|
+
x: a,
|
|
718
|
+
fx: t.evaluate(a, !0)
|
|
713
719
|
}
|
|
714
720
|
);
|
|
715
721
|
}
|
|
716
722
|
return s;
|
|
717
723
|
}
|
|
718
|
-
#
|
|
724
|
+
#c(t, e) {
|
|
719
725
|
const i = [];
|
|
720
726
|
for (let s = 1; s < t.length; s++) {
|
|
721
727
|
const r = t[s], o = t[s - 1];
|
|
@@ -733,10 +739,10 @@ class R {
|
|
|
733
739
|
const d = t.monoms.reduce((q, $) => $.degree().value < q.degree().value ? $ : q), y = d.coefficient;
|
|
734
740
|
d.clone().divide(y), t.divide(d);
|
|
735
741
|
}
|
|
736
|
-
const o = x.dividers(s.value),
|
|
742
|
+
const o = x.dividers(s.value), a = x.dividers(r.value), c = [];
|
|
737
743
|
for (const d of o)
|
|
738
|
-
for (const y of
|
|
739
|
-
const q = new
|
|
744
|
+
for (const y of a) {
|
|
745
|
+
const q = new h(y, d);
|
|
740
746
|
c.find(($) => $.value === q.value) || (c.push(q.clone()), c.push(q.opposite().clone()));
|
|
741
747
|
}
|
|
742
748
|
c.forEach((d) => {
|
|
@@ -757,8 +763,8 @@ class R {
|
|
|
757
763
|
reminder: f
|
|
758
764
|
};
|
|
759
765
|
}
|
|
760
|
-
#
|
|
761
|
-
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),
|
|
766
|
+
#h() {
|
|
767
|
+
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), a = s.clone().divide(e), c = r.clone().divide(e), f = a.clone().subtract(o.clone().pow(2).divide(3)), m = c.clone().subtract(o.clone().multiply(a).divide(3)).add(o.clone().pow(3).multiply(2).divide(27)), d = m.clone().opposite(), y = f.clone().opposite().pow(3).divide(27), q = d.clone().pow(2).subtract(y.clone().multiply(4)).opposite();
|
|
762
768
|
if (q.isNegative()) {
|
|
763
769
|
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));
|
|
764
770
|
return [this.#r(I)];
|
|
@@ -791,13 +797,13 @@ class R {
|
|
|
791
797
|
if (r.isNegative())
|
|
792
798
|
return [];
|
|
793
799
|
if (r.isSquare()) {
|
|
794
|
-
const o = r.sqrt(),
|
|
800
|
+
const o = r.sqrt(), a = i.clone().opposite().subtract(o).divide(e.clone().multiply(2)), c = i.clone().opposite().add(o).divide(e.clone().multiply(2));
|
|
795
801
|
if (o.isZero()) {
|
|
796
|
-
const f = this.#r(
|
|
802
|
+
const f = this.#r(a);
|
|
797
803
|
return f.count = 2, [f];
|
|
798
804
|
}
|
|
799
805
|
return [
|
|
800
|
-
this.#r(
|
|
806
|
+
this.#r(a),
|
|
801
807
|
this.#r(c)
|
|
802
808
|
].sort((f, m) => f.value - m.value);
|
|
803
809
|
}
|
|
@@ -805,25 +811,25 @@ class R {
|
|
|
805
811
|
}
|
|
806
812
|
#d(t, e, i) {
|
|
807
813
|
const s = t.clone().multiply(2), r = new C();
|
|
808
|
-
r.fraction = e.clone().opposite().divide(s.clone()), r.root.radical = i.clone(), r.root.factor = new
|
|
814
|
+
r.fraction = e.clone().opposite().divide(s.clone()), r.root.radical = i.clone(), r.root.factor = new h().one().divide(s.clone()), r.exact = !0;
|
|
809
815
|
const o = new C();
|
|
810
|
-
return o.fraction = e.clone().opposite().divide(s.clone()), o.root.radical = i.clone(), o.root.factor = new
|
|
816
|
+
return o.fraction = e.clone().opposite().divide(s.clone()), o.root.radical = i.clone(), o.root.factor = new h().one().divide(s.clone()).opposite(), o.exact = !0, [r, o].sort((a, c) => a.value - c.value);
|
|
811
817
|
}
|
|
812
818
|
}
|
|
813
|
-
const
|
|
819
|
+
const _ = {
|
|
814
820
|
pi: Math.PI,
|
|
815
821
|
e: Math.exp(1)
|
|
816
822
|
};
|
|
817
|
-
var
|
|
823
|
+
var l = /* @__PURE__ */ ((n) => (n.VARIABLE = "variable", n.COEFFICIENT = "coefficient", n.OPERATION = "operation", n.CONSTANT = "constant", n.FUNCTION = "function", n.FUNCTION_ARGUMENT = "function-argument", n.MONOM = "monom", n.LEFT_PARENTHESIS = "(", n.RIGHT_PARENTHESIS = ")", n))(l || {}), S = /* @__PURE__ */ ((n) => (n.EXPRESSION = "expression", n.POLYNOM = "polynom", n.SET = "set", n.NUMERIC = "numeric", n))(S || {});
|
|
818
824
|
function bt(n, t) {
|
|
819
825
|
if (n.length <= 1)
|
|
820
826
|
return n;
|
|
821
|
-
const e = Object.keys(t).filter((d) => t[d].type ===
|
|
827
|
+
const e = Object.keys(t).filter((d) => t[d].type === l.FUNCTION).map((d) => d);
|
|
822
828
|
e.sort((d, y) => y.length - d.length);
|
|
823
|
-
const i = new RegExp(`^(${e.join("|")})\\(`), s = Object.keys(
|
|
829
|
+
const i = new RegExp(`^(${e.join("|")})\\(`), s = Object.keys(_);
|
|
824
830
|
s.sort((d, y) => y.length - d.length);
|
|
825
831
|
const r = new RegExp(`^(${s.join("|")})`), o = /^(\d+(\.\d+)?)/;
|
|
826
|
-
let
|
|
832
|
+
let a = "", c, f, m;
|
|
827
833
|
for (e.forEach((d) => {
|
|
828
834
|
if (n.includes(d)) {
|
|
829
835
|
const y = new RegExp(`${d}([0-9.]+)`, "g");
|
|
@@ -832,81 +838,81 @@ function bt(n, t) {
|
|
|
832
838
|
}); n.length > 0; ) {
|
|
833
839
|
if (c = f, m = void 0, e.length > 0 && i.exec(n)) {
|
|
834
840
|
const d = e.find((y) => n.startsWith(y));
|
|
835
|
-
d && (m = d + "(", n = n.slice(d.length + 1), f =
|
|
841
|
+
d && (m = d + "(", n = n.slice(d.length + 1), f = l.FUNCTION);
|
|
836
842
|
} else if (s.length > 0 && r.exec(n)) {
|
|
837
843
|
const d = s.find((y) => n.startsWith(y));
|
|
838
|
-
d && (m = d, n = n.slice(d.length), f =
|
|
844
|
+
d && (m = d, n = n.slice(d.length), f = l.CONSTANT);
|
|
839
845
|
} else if (o.exec(n)) {
|
|
840
846
|
const d = o.exec(n);
|
|
841
|
-
d && (m = d[0], n = n.slice(d[0].length), f =
|
|
847
|
+
d && (m = d[0], n = n.slice(d[0].length), f = l.COEFFICIENT);
|
|
842
848
|
} else
|
|
843
849
|
switch (m = n[0], n = n.slice(1), m) {
|
|
844
850
|
case "(":
|
|
845
|
-
f =
|
|
851
|
+
f = l.LEFT_PARENTHESIS;
|
|
846
852
|
break;
|
|
847
853
|
case ")":
|
|
848
|
-
f =
|
|
854
|
+
f = l.RIGHT_PARENTHESIS;
|
|
849
855
|
break;
|
|
850
856
|
case ",":
|
|
851
|
-
f =
|
|
857
|
+
f = l.FUNCTION_ARGUMENT;
|
|
852
858
|
break;
|
|
853
859
|
case "+":
|
|
854
860
|
case "-":
|
|
855
861
|
case "*":
|
|
856
862
|
case "/":
|
|
857
863
|
case "^":
|
|
858
|
-
f =
|
|
864
|
+
f = l.OPERATION;
|
|
859
865
|
break;
|
|
860
866
|
default:
|
|
861
|
-
f =
|
|
867
|
+
f = l.VARIABLE;
|
|
862
868
|
}
|
|
863
869
|
if (m === void 0 || f === void 0)
|
|
864
870
|
throw new Error("The token is undefined");
|
|
865
|
-
|
|
871
|
+
a += Et(c, f), a += m;
|
|
866
872
|
}
|
|
867
|
-
return
|
|
873
|
+
return a;
|
|
868
874
|
}
|
|
869
875
|
function Et(n, t) {
|
|
870
|
-
return n === void 0 || n ===
|
|
876
|
+
return n === void 0 || n === l.OPERATION || t === l.OPERATION || n === l.LEFT_PARENTHESIS || n === l.FUNCTION || n === l.FUNCTION_ARGUMENT || t === l.RIGHT_PARENTHESIS || t === l.FUNCTION_ARGUMENT ? "" : "*";
|
|
871
877
|
}
|
|
872
878
|
const Nt = {
|
|
873
|
-
"^": { precedence: 4, associative: "right", type:
|
|
874
|
-
"*": { precedence: 3, associative: "left", type:
|
|
875
|
-
"/": { precedence: 3, associative: "left", type:
|
|
876
|
-
"+": { precedence: 2, associative: "left", type:
|
|
877
|
-
"-": { precedence: 2, associative: "left", type:
|
|
879
|
+
"^": { precedence: 4, associative: "right", type: l.OPERATION },
|
|
880
|
+
"*": { precedence: 3, associative: "left", type: l.OPERATION },
|
|
881
|
+
"/": { precedence: 3, associative: "left", type: l.OPERATION },
|
|
882
|
+
"+": { precedence: 2, associative: "left", type: l.OPERATION },
|
|
883
|
+
"-": { precedence: 2, associative: "left", type: l.OPERATION }
|
|
878
884
|
}, At = {
|
|
879
|
-
"^": { precedence: 4, associative: "right", type:
|
|
880
|
-
"*": { precedence: 3, associative: "left", type:
|
|
881
|
-
"/": { precedence: 3, associative: "left", type:
|
|
882
|
-
"+": { precedence: 2, associative: "left", type:
|
|
883
|
-
"-": { precedence: 2, associative: "left", type:
|
|
884
|
-
"%": { precedence: 3, associative: "right", type:
|
|
885
|
-
sin: { precedence: 4, associative: "right", type:
|
|
886
|
-
cos: { precedence: 4, associative: "right", type:
|
|
887
|
-
tan: { precedence: 4, associative: "right", type:
|
|
888
|
-
sqrt: { precedence: 4, associative: "right", type:
|
|
889
|
-
nthrt: { precedence: 4, associative: "right", type:
|
|
890
|
-
",": { precedence: 2, associative: "left", type:
|
|
885
|
+
"^": { precedence: 4, associative: "right", type: l.OPERATION },
|
|
886
|
+
"*": { precedence: 3, associative: "left", type: l.OPERATION },
|
|
887
|
+
"/": { precedence: 3, associative: "left", type: l.OPERATION },
|
|
888
|
+
"+": { precedence: 2, associative: "left", type: l.OPERATION },
|
|
889
|
+
"-": { precedence: 2, associative: "left", type: l.OPERATION },
|
|
890
|
+
"%": { precedence: 3, associative: "right", type: l.OPERATION },
|
|
891
|
+
sin: { precedence: 4, associative: "right", type: l.FUNCTION },
|
|
892
|
+
cos: { precedence: 4, associative: "right", type: l.FUNCTION },
|
|
893
|
+
tan: { precedence: 4, associative: "right", type: l.FUNCTION },
|
|
894
|
+
sqrt: { precedence: 4, associative: "right", type: l.FUNCTION },
|
|
895
|
+
nthrt: { precedence: 4, associative: "right", type: l.FUNCTION },
|
|
896
|
+
",": { precedence: 2, associative: "left", type: l.FUNCTION_ARGUMENT }
|
|
891
897
|
}, Tt = {
|
|
892
|
-
"^": { precedence: 4, associative: "right", type:
|
|
893
|
-
"*": { precedence: 3, associative: "left", type:
|
|
894
|
-
"/": { precedence: 3, associative: "left", type:
|
|
895
|
-
"+": { precedence: 2, associative: "left", type:
|
|
896
|
-
"-": { precedence: 2, associative: "left", type:
|
|
897
|
-
"%": { precedence: 3, associative: "right", type:
|
|
898
|
-
sin: { precedence: 4, associative: "right", type:
|
|
899
|
-
cos: { precedence: 4, associative: "right", type:
|
|
900
|
-
tan: { precedence: 4, associative: "right", type:
|
|
901
|
-
sqrt: { precedence: 4, associative: "right", type:
|
|
902
|
-
nthrt: { precedence: 4, associative: "right", type:
|
|
903
|
-
ln: { precedence: 4, associative: "right", type:
|
|
904
|
-
log: { precedence: 4, associative: "right", type:
|
|
898
|
+
"^": { precedence: 4, associative: "right", type: l.OPERATION },
|
|
899
|
+
"*": { precedence: 3, associative: "left", type: l.OPERATION },
|
|
900
|
+
"/": { precedence: 3, associative: "left", type: l.OPERATION },
|
|
901
|
+
"+": { precedence: 2, associative: "left", type: l.OPERATION },
|
|
902
|
+
"-": { precedence: 2, associative: "left", type: l.OPERATION },
|
|
903
|
+
"%": { precedence: 3, associative: "right", type: l.OPERATION },
|
|
904
|
+
sin: { precedence: 4, associative: "right", type: l.FUNCTION },
|
|
905
|
+
cos: { precedence: 4, associative: "right", type: l.FUNCTION },
|
|
906
|
+
tan: { precedence: 4, associative: "right", type: l.FUNCTION },
|
|
907
|
+
sqrt: { precedence: 4, associative: "right", type: l.FUNCTION },
|
|
908
|
+
nthrt: { precedence: 4, associative: "right", type: l.FUNCTION },
|
|
909
|
+
ln: { precedence: 4, associative: "right", type: l.FUNCTION },
|
|
910
|
+
log: { precedence: 4, associative: "right", type: l.FUNCTION }
|
|
905
911
|
}, Ot = {
|
|
906
|
-
"&": { precedence: 3, associative: "left", type:
|
|
907
|
-
"|": { precedence: 3, associative: "left", type:
|
|
908
|
-
"!": { precedence: 4, associative: "right", type:
|
|
909
|
-
"-": { precedence: 2, associative: "left", type:
|
|
912
|
+
"&": { precedence: 3, associative: "left", type: l.OPERATION },
|
|
913
|
+
"|": { precedence: 3, associative: "left", type: l.OPERATION },
|
|
914
|
+
"!": { precedence: 4, associative: "right", type: l.OPERATION },
|
|
915
|
+
"-": { precedence: 2, associative: "left", type: l.OPERATION }
|
|
910
916
|
};
|
|
911
917
|
class G {
|
|
912
918
|
#t;
|
|
@@ -935,31 +941,31 @@ class G {
|
|
|
935
941
|
NextToken(t, e) {
|
|
936
942
|
let i, s;
|
|
937
943
|
if (i = "", s = void 0, t[e] === "(")
|
|
938
|
-
i = "(", s =
|
|
944
|
+
i = "(", s = l.LEFT_PARENTHESIS;
|
|
939
945
|
else if (t[e] === ")")
|
|
940
|
-
i = ")", s =
|
|
946
|
+
i = ")", s = l.RIGHT_PARENTHESIS;
|
|
941
947
|
else if (t[e] === ",")
|
|
942
|
-
i = ",", s =
|
|
948
|
+
i = ",", s = l.FUNCTION_ARGUMENT;
|
|
943
949
|
else {
|
|
944
950
|
for (const r of this.#s)
|
|
945
951
|
if (t.substring(e, e + r.length) === r) {
|
|
946
952
|
i += r, s = this.#i[r].type;
|
|
947
953
|
break;
|
|
948
954
|
}
|
|
949
|
-
for (const r in
|
|
955
|
+
for (const r in _)
|
|
950
956
|
if (t.substring(e, e + r.length) === r) {
|
|
951
|
-
i += r, s =
|
|
957
|
+
i += r, s = l.CONSTANT;
|
|
952
958
|
break;
|
|
953
959
|
}
|
|
954
960
|
if (i === "")
|
|
955
961
|
if (/[0-9.]/.exec(t[e])) {
|
|
956
962
|
const r = /^([0-9.]+)/.exec(t.substring(e));
|
|
957
|
-
i = r ? r[0] : "", s =
|
|
963
|
+
i = r ? r[0] : "", s = l.COEFFICIENT;
|
|
958
964
|
} else if (/[a-zA-Z]/.exec(t[e])) {
|
|
959
965
|
const r = /^([a-zA-Z])/.exec(t.substring(e));
|
|
960
|
-
i = r ? r[0] : "", s =
|
|
966
|
+
i = r ? r[0] : "", s = l.VARIABLE;
|
|
961
967
|
} else
|
|
962
|
-
console.log("Unidentified token", t[e], t, e), i = t[e], s =
|
|
968
|
+
console.log("Unidentified token", t[e], t, e), i = t[e], s = l.MONOM;
|
|
963
969
|
}
|
|
964
970
|
if (s === void 0)
|
|
965
971
|
throw new Error(`Token type is undefined for token ${i}`);
|
|
@@ -973,7 +979,7 @@ class G {
|
|
|
973
979
|
*/
|
|
974
980
|
parse(t, e) {
|
|
975
981
|
const i = [], s = [];
|
|
976
|
-
let r = "", o = 0,
|
|
982
|
+
let r = "", o = 0, a;
|
|
977
983
|
(e ?? this.#r) && (t = bt(t, this.#i));
|
|
978
984
|
let c = 50, f;
|
|
979
985
|
for (; o < t.length; ) {
|
|
@@ -981,17 +987,17 @@ class G {
|
|
|
981
987
|
console.log("SECURITY LEVEL 1 EXIT");
|
|
982
988
|
break;
|
|
983
989
|
}
|
|
984
|
-
switch ([r, o,
|
|
985
|
-
case
|
|
986
|
-
case
|
|
987
|
-
case
|
|
988
|
-
case
|
|
990
|
+
switch ([r, o, a] = this.NextToken(t, o), a) {
|
|
991
|
+
case l.MONOM:
|
|
992
|
+
case l.COEFFICIENT:
|
|
993
|
+
case l.VARIABLE:
|
|
994
|
+
case l.CONSTANT:
|
|
989
995
|
i.push({
|
|
990
996
|
token: r,
|
|
991
|
-
tokenType:
|
|
997
|
+
tokenType: a
|
|
992
998
|
});
|
|
993
999
|
break;
|
|
994
|
-
case
|
|
1000
|
+
case l.OPERATION:
|
|
995
1001
|
if (s.length > 0) {
|
|
996
1002
|
let m = s[s.length - 1];
|
|
997
1003
|
for (f = 50; m.token in this.#i && //either o1 is left-associative and its precedence is less than or equal to that of o2,
|
|
@@ -1001,37 +1007,37 @@ class G {
|
|
|
1001
1007
|
console.log("SECURITY LEVEL 2 OPERATION EXIT");
|
|
1002
1008
|
break;
|
|
1003
1009
|
}
|
|
1004
|
-
if (i.push(s.pop() ?? { token: "", tokenType:
|
|
1010
|
+
if (i.push(s.pop() ?? { token: "", tokenType: l.OPERATION }), s.length === 0)
|
|
1005
1011
|
break;
|
|
1006
1012
|
m = s[s.length - 1];
|
|
1007
1013
|
}
|
|
1008
1014
|
}
|
|
1009
|
-
s.push({ token: r, tokenType:
|
|
1015
|
+
s.push({ token: r, tokenType: a });
|
|
1010
1016
|
break;
|
|
1011
|
-
case
|
|
1017
|
+
case l.FUNCTION_ARGUMENT:
|
|
1012
1018
|
for (f = 50; s[s.length - 1].token !== "(" && s.length > 0; ) {
|
|
1013
1019
|
if (f--, f === 0) {
|
|
1014
1020
|
console.log("SECURITY LEVEL 2 FUNCTION ARGUMENT EXIT");
|
|
1015
1021
|
break;
|
|
1016
1022
|
}
|
|
1017
|
-
i.push(s.pop() ?? { token: r, tokenType:
|
|
1023
|
+
i.push(s.pop() ?? { token: r, tokenType: a });
|
|
1018
1024
|
}
|
|
1019
1025
|
break;
|
|
1020
|
-
case
|
|
1021
|
-
s.push({ token: r, tokenType:
|
|
1026
|
+
case l.LEFT_PARENTHESIS:
|
|
1027
|
+
s.push({ token: r, tokenType: a }), t[o] === "-" && i.push({ token: "0", tokenType: l.COEFFICIENT });
|
|
1022
1028
|
break;
|
|
1023
|
-
case
|
|
1029
|
+
case l.RIGHT_PARENTHESIS:
|
|
1024
1030
|
for (f = 50; s[s.length - 1].token !== "(" && s.length > 1; ) {
|
|
1025
1031
|
if (f--, f === 0) {
|
|
1026
1032
|
console.log("SECURITY LEVEL 2 CLOSING PARENTHESIS EXIT");
|
|
1027
1033
|
break;
|
|
1028
1034
|
}
|
|
1029
|
-
i.push(s.pop() ?? { token: r, tokenType:
|
|
1035
|
+
i.push(s.pop() ?? { token: r, tokenType: a });
|
|
1030
1036
|
}
|
|
1031
1037
|
s.pop();
|
|
1032
1038
|
break;
|
|
1033
|
-
case
|
|
1034
|
-
s.push({ token: r, tokenType:
|
|
1039
|
+
case l.FUNCTION:
|
|
1040
|
+
s.push({ token: r, tokenType: a });
|
|
1035
1041
|
break;
|
|
1036
1042
|
default:
|
|
1037
1043
|
throw new Error(`Token type ${r} is not handled`);
|
|
@@ -1076,7 +1082,7 @@ class Ct {
|
|
|
1076
1082
|
return this._isValid = !1, 0;
|
|
1077
1083
|
this._isValid = !0;
|
|
1078
1084
|
for (const i of this._rpn)
|
|
1079
|
-
if (i.tokenType ===
|
|
1085
|
+
if (i.tokenType === l.COEFFICIENT)
|
|
1080
1086
|
if (!isNaN(+i.token))
|
|
1081
1087
|
e.push(+i.token);
|
|
1082
1088
|
else {
|
|
@@ -1085,11 +1091,11 @@ class Ct {
|
|
|
1085
1091
|
throw this._isValid = !1, new Error("This coefficient is not a fraction");
|
|
1086
1092
|
e.push(+s[0] / +s[1]);
|
|
1087
1093
|
}
|
|
1088
|
-
else if (i.tokenType ===
|
|
1094
|
+
else if (i.tokenType === l.VARIABLE && t !== void 0)
|
|
1089
1095
|
Object.hasOwn(t, i.token) && e.push(+t[i.token]);
|
|
1090
|
-
else if (i.tokenType ===
|
|
1091
|
-
e.push(
|
|
1092
|
-
else if (i.tokenType ===
|
|
1096
|
+
else if (i.tokenType === l.CONSTANT)
|
|
1097
|
+
e.push(_[i.token]);
|
|
1098
|
+
else if (i.tokenType === l.OPERATION) {
|
|
1093
1099
|
if (i.token === "*") {
|
|
1094
1100
|
const s = e.pop(), r = e.pop();
|
|
1095
1101
|
if (r === void 0 || s === void 0)
|
|
@@ -1116,7 +1122,7 @@ class Ct {
|
|
|
1116
1122
|
throw this._isValid = !1, new Error(`The base value ${r ?? "a"} or exponent ${s ?? "b"} are not defined`);
|
|
1117
1123
|
e.push(Math.pow(r, s));
|
|
1118
1124
|
}
|
|
1119
|
-
} else if (i.tokenType ===
|
|
1125
|
+
} else if (i.tokenType === l.FUNCTION) {
|
|
1120
1126
|
const s = e.pop();
|
|
1121
1127
|
if (s === void 0)
|
|
1122
1128
|
throw this._isValid = !1, new Error(`The parameters for ${i.token} is not defined`);
|
|
@@ -1147,7 +1153,7 @@ class p {
|
|
|
1147
1153
|
#t;
|
|
1148
1154
|
#e;
|
|
1149
1155
|
constructor(t) {
|
|
1150
|
-
return this.#t = new
|
|
1156
|
+
return this.#t = new h().zero(), this.#e = {}, t !== void 0 && this.parse(t), this;
|
|
1151
1157
|
}
|
|
1152
1158
|
// -----------------------------------------
|
|
1153
1159
|
/**
|
|
@@ -1155,7 +1161,7 @@ class p {
|
|
|
1155
1161
|
* @param inputStr
|
|
1156
1162
|
*/
|
|
1157
1163
|
parse(t) {
|
|
1158
|
-
return this.#t = new
|
|
1164
|
+
return this.#t = new h(), this.#e = {}, t instanceof p ? (this.#t = t.#t.clone(), this.#i(t), this) : t instanceof h ? (this.#t = t.clone(), this) : typeof t == "number" ? (this.#t = new h(t), this) : (isNaN(Number(t)) ? this.#a(t) : this.#t = new h(Number(t)), this);
|
|
1159
1165
|
}
|
|
1160
1166
|
/**
|
|
1161
1167
|
* Clone the current Monom.
|
|
@@ -1171,34 +1177,26 @@ class p {
|
|
|
1171
1177
|
* Get the tex output of the monom
|
|
1172
1178
|
*/
|
|
1173
1179
|
get tex() {
|
|
1174
|
-
|
|
1175
|
-
const e = Object.keys(this.#e).sort();
|
|
1176
|
-
for (const i of e)
|
|
1177
|
-
this.#e[i].isNotZero() && (t += i, this.#e[i].isNotEqual(1) && (t += `^{ ${this.#e[i].tfrac.tex} }`));
|
|
1178
|
-
return t === "" ? this.#t.value != 0 ? this.#t.frac.tex : "0" : this.#t.value === 1 ? t : this.#t.value === -1 ? `-${t}` : this.#t.value === 0 ? "0" : `${this.#t.frac.tex}${t}`;
|
|
1180
|
+
return this.#r("tex");
|
|
1179
1181
|
}
|
|
1180
1182
|
// Display getter
|
|
1181
1183
|
/**
|
|
1182
1184
|
* This display getter is to be used in the polynom display getter
|
|
1183
1185
|
*/
|
|
1184
1186
|
get display() {
|
|
1185
|
-
|
|
1186
|
-
const e = Object.keys(this.#e).sort();
|
|
1187
|
-
for (const i of e)
|
|
1188
|
-
this.#e[i].isNotZero() && (t += i, this.#e[i].isNotEqual(1) && (t += `^(${this.#e[i].display})`));
|
|
1189
|
-
return t === "" ? this.#t.value != 0 ? this.#t.display : "" : this.#t.value === 1 ? t : this.#t.value === -1 ? `-${t}` : this.#t.value === 0 ? "0" : `${this.#t.display}${t}`;
|
|
1187
|
+
return this.#r("display");
|
|
1190
1188
|
}
|
|
1191
1189
|
static gcd = (...t) => {
|
|
1192
1190
|
for (const r of t)
|
|
1193
1191
|
if (r.containsRationalPower())
|
|
1194
1192
|
return new p().zero();
|
|
1195
1193
|
const e = new p(), i = x.gcd(...t.map((r) => r.coefficient.numerator)), s = x.lcm(...t.map((r) => r.coefficient.denominator));
|
|
1196
|
-
e.coefficient = new
|
|
1194
|
+
e.coefficient = new h(i, s).reduce();
|
|
1197
1195
|
for (const r of t) {
|
|
1198
1196
|
for (const o in e.literal)
|
|
1199
|
-
o in r.literal || e.
|
|
1197
|
+
o in r.literal || e.removeVariable(o);
|
|
1200
1198
|
for (const o in r.literal)
|
|
1201
|
-
!e.hasVariable(o) && r.literal[o].isStrictlyPositive() ? e.literal[o] = r.literal[o].clone() : e.literal[o] = new
|
|
1199
|
+
!e.hasVariable(o) && r.literal[o].isStrictlyPositive() ? e.literal[o] = r.literal[o].clone() : e.literal[o] = new h(Math.min(r.literal[o].value, e.literal[o].value));
|
|
1202
1200
|
}
|
|
1203
1201
|
return e;
|
|
1204
1202
|
};
|
|
@@ -1219,7 +1217,10 @@ class p {
|
|
|
1219
1217
|
add = (...t) => {
|
|
1220
1218
|
for (const e of t) {
|
|
1221
1219
|
const i = e instanceof p ? e : new p(e);
|
|
1222
|
-
|
|
1220
|
+
if (this.isSameAs(i))
|
|
1221
|
+
this.isZero() && this.#i(i), this.#t.add(i.coefficient);
|
|
1222
|
+
else
|
|
1223
|
+
throw new Error("Add monom: " + this.display + " is not similar with " + i.display);
|
|
1223
1224
|
}
|
|
1224
1225
|
return this;
|
|
1225
1226
|
};
|
|
@@ -1235,14 +1236,14 @@ class p {
|
|
|
1235
1236
|
* @param {Fraction | number | string} F
|
|
1236
1237
|
*/
|
|
1237
1238
|
set coefficient(t) {
|
|
1238
|
-
this.#t = new
|
|
1239
|
+
this.#t = new h(t);
|
|
1239
1240
|
}
|
|
1240
1241
|
containsRationalPower = () => Object.values(this.#e).some((t) => t.isRational());
|
|
1241
1242
|
/**
|
|
1242
1243
|
* Get the degree of a monom. If no setLetter is given, the result will be the global degree.
|
|
1243
1244
|
* @param letter (string) Letter to get to degree (power)
|
|
1244
1245
|
*/
|
|
1245
|
-
degree = (t) => this.variables.length === 0 ? new
|
|
1246
|
+
degree = (t) => this.variables.length === 0 ? new h().zero() : t === void 0 ? Object.values(this.#e).reduce((e, i) => e.clone().add(i)) : this.hasVariable(t) ? this.#e[t].clone() : new h().zero();
|
|
1246
1247
|
/**
|
|
1247
1248
|
* Derivative the monom
|
|
1248
1249
|
* @param letter
|
|
@@ -1250,7 +1251,7 @@ class p {
|
|
|
1250
1251
|
derivative = (t = "x") => {
|
|
1251
1252
|
if (this.hasVariable(t)) {
|
|
1252
1253
|
const e = this.#e[t].clone(), i = this.clone();
|
|
1253
|
-
return i.#e[t].subtract(1), i.#t.multiply(new
|
|
1254
|
+
return i.#e[t].subtract(1), i.#t.multiply(new h(e.clone())), i;
|
|
1254
1255
|
} else
|
|
1255
1256
|
return new p().zero();
|
|
1256
1257
|
};
|
|
@@ -1277,23 +1278,23 @@ class p {
|
|
|
1277
1278
|
const t = x.dividers(Math.abs(this.coefficient.numerator));
|
|
1278
1279
|
let e = [];
|
|
1279
1280
|
for (const s in this.literal)
|
|
1280
|
-
e = this
|
|
1281
|
+
e = this.#n(e, s);
|
|
1281
1282
|
const i = [];
|
|
1282
1283
|
if (e.length > 0 && t.length > 0)
|
|
1283
1284
|
for (const s of t)
|
|
1284
1285
|
for (const r of e) {
|
|
1285
1286
|
const o = new p();
|
|
1286
|
-
o.coefficient = new
|
|
1287
|
+
o.coefficient = new h(s), o.literal = r, i.push(o);
|
|
1287
1288
|
}
|
|
1288
1289
|
else if (t.length === 0)
|
|
1289
1290
|
for (const s of e) {
|
|
1290
1291
|
const r = new p();
|
|
1291
|
-
r.coefficient = new
|
|
1292
|
+
r.coefficient = new h().one(), r.literal = s, i.push(r);
|
|
1292
1293
|
}
|
|
1293
1294
|
else
|
|
1294
1295
|
for (const s of t) {
|
|
1295
1296
|
const r = new p();
|
|
1296
|
-
r.coefficient = new
|
|
1297
|
+
r.coefficient = new h(s), i.push(r);
|
|
1297
1298
|
}
|
|
1298
1299
|
return i.length === 0 ? [new p().one()] : i;
|
|
1299
1300
|
}
|
|
@@ -1304,27 +1305,27 @@ class p {
|
|
|
1304
1305
|
*/
|
|
1305
1306
|
evaluate = (t, e) => {
|
|
1306
1307
|
if (e === !0) {
|
|
1307
|
-
if (t instanceof
|
|
1308
|
+
if (t instanceof h)
|
|
1308
1309
|
return this.#s(t.value);
|
|
1309
1310
|
if (typeof t == "number")
|
|
1310
1311
|
return this.#s(t);
|
|
1311
1312
|
if (typeof t == "object") {
|
|
1312
1313
|
const s = {};
|
|
1313
1314
|
for (const r in t)
|
|
1314
|
-
s[r] = new
|
|
1315
|
+
s[r] = new h(t[r]).value;
|
|
1315
1316
|
return this.#s(s);
|
|
1316
1317
|
}
|
|
1317
1318
|
}
|
|
1318
1319
|
const i = this.coefficient.clone();
|
|
1319
|
-
if (typeof t == "number" || t instanceof
|
|
1320
|
+
if (typeof t == "number" || t instanceof h) {
|
|
1320
1321
|
const s = {};
|
|
1321
|
-
return s[this.variables[0]] = new
|
|
1322
|
+
return s[this.variables[0]] = new h(t), this.evaluate(s);
|
|
1322
1323
|
}
|
|
1323
1324
|
if (typeof t == "object") {
|
|
1324
1325
|
if (this.variables.length === 0)
|
|
1325
1326
|
return this.coefficient;
|
|
1326
1327
|
for (const s in this.#e) {
|
|
1327
|
-
const r = new
|
|
1328
|
+
const r = new h(t[s]);
|
|
1328
1329
|
i.multiply(r.pow(this.#e[s]));
|
|
1329
1330
|
}
|
|
1330
1331
|
}
|
|
@@ -1338,10 +1339,10 @@ class p {
|
|
|
1338
1339
|
hasVariable = (t) => Object.hasOwn(this.#e, t ?? "x");
|
|
1339
1340
|
integrate(t, e, i) {
|
|
1340
1341
|
const s = this.primitive(i);
|
|
1341
|
-
return s.evaluate(e).subtract(s.evaluate(t));
|
|
1342
|
+
return s.evaluate(e, !1).subtract(s.evaluate(t, !1));
|
|
1342
1343
|
}
|
|
1343
1344
|
inverse = () => {
|
|
1344
|
-
this.#t.
|
|
1345
|
+
this.#t.inverse();
|
|
1345
1346
|
for (const t in this.#e)
|
|
1346
1347
|
this.#e[t].opposite();
|
|
1347
1348
|
return this;
|
|
@@ -1361,7 +1362,7 @@ class p {
|
|
|
1361
1362
|
isEqual = (t) => this.isSameAs(t) && this.#t.isEqual(t.coefficient);
|
|
1362
1363
|
isLiteralSquare = () => {
|
|
1363
1364
|
for (const t in this.literal)
|
|
1364
|
-
if (this.literal[t].isRational() || this.literal[t].
|
|
1365
|
+
if (this.literal[t].isRational() || this.literal[t].isOdd())
|
|
1365
1366
|
return !1;
|
|
1366
1367
|
return !0;
|
|
1367
1368
|
};
|
|
@@ -1411,9 +1412,9 @@ class p {
|
|
|
1411
1412
|
*/
|
|
1412
1413
|
set literalStr(t) {
|
|
1413
1414
|
for (const e of [...t.matchAll(/([a-z])\^([+-]?[0-9]+)/g)])
|
|
1414
|
-
e[1] in this.#e || (this.#e[e[1]] = new
|
|
1415
|
+
e[1] in this.#e || (this.#e[e[1]] = new h().zero()), this.#e[e[1]].add(+e[2]);
|
|
1415
1416
|
for (const e of [...t.matchAll(/([a-z](?!\^))/g)])
|
|
1416
|
-
e[1] in this.#e || (this.#e[e[1]] = new
|
|
1417
|
+
e[1] in this.#e || (this.#e[e[1]] = new h().zero()), this.#e[e[1]].add(1);
|
|
1417
1418
|
}
|
|
1418
1419
|
/**
|
|
1419
1420
|
* Multiple multiple monoms to the current monom
|
|
@@ -1431,18 +1432,14 @@ class p {
|
|
|
1431
1432
|
/**
|
|
1432
1433
|
* Create a one value monom
|
|
1433
1434
|
*/
|
|
1434
|
-
one = () => (this.#t = new
|
|
1435
|
+
one = () => (this.#t = new h().one(), this.#e = {}, this);
|
|
1435
1436
|
/**
|
|
1436
1437
|
* Get the opposite
|
|
1437
1438
|
* Returns a monom.
|
|
1438
1439
|
*/
|
|
1439
1440
|
opposite = () => (this.#t.opposite(), this);
|
|
1440
1441
|
get plotFunction() {
|
|
1441
|
-
|
|
1442
|
-
const e = Object.keys(this.#e).sort();
|
|
1443
|
-
for (const i of e)
|
|
1444
|
-
this.#e[i].isNotZero() && (t += (t === "" ? "" : "*") + i, this.#e[i].isNotEqual(1) && (t += `^(${this.#e[i].display})`));
|
|
1445
|
-
return t === "" ? this.#t.value != 0 ? this.#t.display : "" : this.#t.value === 1 ? t : this.#t.value === -1 ? `-${t}` : this.#t.value === 0 ? "0" : `${this.#t.display}*${t}`;
|
|
1442
|
+
return this.#r("plot");
|
|
1446
1443
|
}
|
|
1447
1444
|
/**
|
|
1448
1445
|
* Get the pow of a monom.
|
|
@@ -1457,7 +1454,7 @@ class p {
|
|
|
1457
1454
|
primitive = (t = "x") => {
|
|
1458
1455
|
const e = this.clone();
|
|
1459
1456
|
let i;
|
|
1460
|
-
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
|
|
1457
|
+
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 h().one()), e.setLetter(t, 1)), e;
|
|
1461
1458
|
};
|
|
1462
1459
|
reduce = () => {
|
|
1463
1460
|
this.coefficient.reduce();
|
|
@@ -1470,6 +1467,7 @@ class p {
|
|
|
1470
1467
|
}
|
|
1471
1468
|
/**
|
|
1472
1469
|
* Get the nth-root of the monom
|
|
1470
|
+
* @todo Not yet implemented
|
|
1473
1471
|
*/
|
|
1474
1472
|
root = () => {
|
|
1475
1473
|
throw new Error("Method not implemented.");
|
|
@@ -1479,7 +1477,7 @@ class p {
|
|
|
1479
1477
|
* @param letter (string) Letter to change
|
|
1480
1478
|
* @param pow (number) Power of the setLetter (must be positive integer.
|
|
1481
1479
|
*/
|
|
1482
|
-
setLetter = (t, e) => e instanceof
|
|
1480
|
+
setLetter = (t, e) => e instanceof h ? this.hasVariable(t) && e.isZero() ? (this.removeVariable(t), this) : (this.#e[t] = e.clone(), this) : this.setLetter(t, new h(e));
|
|
1483
1481
|
/**
|
|
1484
1482
|
* Return the square root of a monom
|
|
1485
1483
|
*/
|
|
@@ -1487,7 +1485,7 @@ class p {
|
|
|
1487
1485
|
if (this.isSquare()) {
|
|
1488
1486
|
this.#t.sqrt();
|
|
1489
1487
|
for (const t in this.#e)
|
|
1490
|
-
this.#e[t].
|
|
1488
|
+
this.#e[t].divide(2);
|
|
1491
1489
|
}
|
|
1492
1490
|
return this;
|
|
1493
1491
|
};
|
|
@@ -1498,7 +1496,10 @@ class p {
|
|
|
1498
1496
|
subtract = (...t) => {
|
|
1499
1497
|
for (const e of t) {
|
|
1500
1498
|
const i = e instanceof p ? e : new p(e);
|
|
1501
|
-
|
|
1499
|
+
if (this.isSameAs(i))
|
|
1500
|
+
this.isZero() && this.#i(i), this.#t.add(i.clone().coefficient.opposite());
|
|
1501
|
+
else
|
|
1502
|
+
throw new Error("Subtract: Is not similar: " + i.display);
|
|
1502
1503
|
}
|
|
1503
1504
|
return this;
|
|
1504
1505
|
};
|
|
@@ -1517,7 +1518,7 @@ class p {
|
|
|
1517
1518
|
/**
|
|
1518
1519
|
* Create a zero value monom
|
|
1519
1520
|
*/
|
|
1520
|
-
zero = () => (this.#t = new
|
|
1521
|
+
zero = () => (this.#t = new h().zero(), this.#e = {}, this);
|
|
1521
1522
|
#i(t) {
|
|
1522
1523
|
for (const e in t.literal)
|
|
1523
1524
|
this.#e[e] = t.literal[e].clone();
|
|
@@ -1528,40 +1529,51 @@ class p {
|
|
|
1528
1529
|
const i = {}, s = this.variables[0];
|
|
1529
1530
|
return i[s] = t, this.#s(i);
|
|
1530
1531
|
}
|
|
1531
|
-
if (t instanceof
|
|
1532
|
+
if (t instanceof h) {
|
|
1532
1533
|
const i = {};
|
|
1533
|
-
return i[this.variables[0]] = new
|
|
1534
|
+
return i[this.variables[0]] = new h(t).value, this.#s(i);
|
|
1534
1535
|
}
|
|
1535
1536
|
if (typeof t == "object") {
|
|
1536
1537
|
if (this.variables.length === 0)
|
|
1537
1538
|
return this.coefficient.value;
|
|
1538
1539
|
for (const i in this.#e) {
|
|
1539
1540
|
const s = t[i];
|
|
1540
|
-
s instanceof
|
|
1541
|
+
s instanceof h ? e *= s.value ** this.#e[i].value : e *= s ** this.#e[i].value;
|
|
1541
1542
|
}
|
|
1542
1543
|
}
|
|
1543
1544
|
return e;
|
|
1544
1545
|
};
|
|
1545
1546
|
#r = (t) => {
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
} else
|
|
1553
|
-
for (const r of i)
|
|
1554
|
-
this.#n(s, r);
|
|
1555
|
-
return this.one(), this.multiply(s[0]), this;
|
|
1547
|
+
let e = "";
|
|
1548
|
+
const i = Object.keys(this.#e).sort();
|
|
1549
|
+
for (const r of i)
|
|
1550
|
+
this.#e[r].isNotZero() && (t === "plot" && e !== "" && (e += "*"), e += r, this.#e[r].isNotEqual(1) && (e += t === "tex" ? `^{ ${this.#e[r].tfrac.tex} }` : `^(${this.#e[r].display})`));
|
|
1551
|
+
const s = t === "tex" ? this.#t.frac.tex : this.#t.display;
|
|
1552
|
+
return e === "" ? this.#t.value !== 0 ? s : "0" : this.#t.value === 1 ? e : this.#t.value === -1 ? `-${e}` : this.#t.value === 0 ? "0" : t === "plot" ? `${s}*${e}` : `${s}${e}`;
|
|
1556
1553
|
};
|
|
1557
|
-
#n
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
t.
|
|
1561
|
-
|
|
1554
|
+
#n(t, e) {
|
|
1555
|
+
const i = [];
|
|
1556
|
+
for (let s = 0; s <= this.literal[e].value; s++)
|
|
1557
|
+
if (t.length === 0) {
|
|
1558
|
+
const r = {};
|
|
1559
|
+
r[e] = new h(s), i.push(r);
|
|
1560
|
+
} else
|
|
1561
|
+
for (const r of t) {
|
|
1562
|
+
const o = {};
|
|
1563
|
+
for (const a in r)
|
|
1564
|
+
o[a] = r[a];
|
|
1565
|
+
o[e] = new h(s), i.push(o);
|
|
1566
|
+
}
|
|
1567
|
+
return i;
|
|
1568
|
+
}
|
|
1569
|
+
#o = (t, e) => {
|
|
1570
|
+
let i, s, r, o, a;
|
|
1571
|
+
if (e.tokenType === l.COEFFICIENT)
|
|
1572
|
+
t.push(new p(new h(e.token)));
|
|
1573
|
+
else if (e.tokenType === l.VARIABLE) {
|
|
1562
1574
|
const c = new p().one();
|
|
1563
1575
|
c.setLetter(e.token, 1), t.push(c.clone());
|
|
1564
|
-
} else if (e.tokenType ===
|
|
1576
|
+
} else if (e.tokenType === l.OPERATION)
|
|
1565
1577
|
switch (e.token) {
|
|
1566
1578
|
case "-":
|
|
1567
1579
|
s = t.pop() ?? new p().zero(), i = t.pop() ?? new p().zero(), t.push(i.subtract(s));
|
|
@@ -1573,28 +1585,25 @@ class p {
|
|
|
1573
1585
|
s = t.pop() ?? new p().one(), i = t.pop() ?? new p().one(), t.push(i.divide(s));
|
|
1574
1586
|
break;
|
|
1575
1587
|
case "^": {
|
|
1576
|
-
|
|
1588
|
+
a = t.pop()?.coefficient ?? new h().one(), r = t.pop() ?? new p().one(), o = r.variables[0], o && r.setLetter(o, a), t.push(r);
|
|
1577
1589
|
break;
|
|
1578
1590
|
}
|
|
1579
1591
|
}
|
|
1580
1592
|
};
|
|
1581
|
-
|
|
1582
|
-
const i = [];
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
}
|
|
1594
|
-
return i;
|
|
1595
|
-
}
|
|
1593
|
+
#a = (t) => {
|
|
1594
|
+
const i = new G().parse(t).rpn, s = [];
|
|
1595
|
+
if (i.length === 0)
|
|
1596
|
+
return this.zero(), this;
|
|
1597
|
+
if (i.length === 1) {
|
|
1598
|
+
const r = i[0];
|
|
1599
|
+
return this.one(), r.tokenType === l.COEFFICIENT ? this.coefficient = new h(r.token) : r.tokenType === l.VARIABLE && this.setLetter(r.token, 1), this;
|
|
1600
|
+
} else
|
|
1601
|
+
for (const r of i)
|
|
1602
|
+
this.#o(s, r);
|
|
1603
|
+
return this.one(), this.multiply(s[0]), this;
|
|
1604
|
+
};
|
|
1596
1605
|
}
|
|
1597
|
-
function
|
|
1606
|
+
function rt(n, t) {
|
|
1598
1607
|
if (!Number.isSafeInteger(t))
|
|
1599
1608
|
throw new Error("Can only raise item by an integer");
|
|
1600
1609
|
if (t < 0)
|
|
@@ -1606,7 +1615,7 @@ function nt(n, t) {
|
|
|
1606
1615
|
n.multiply(e);
|
|
1607
1616
|
return n;
|
|
1608
1617
|
}
|
|
1609
|
-
class
|
|
1618
|
+
class u {
|
|
1610
1619
|
#t = "x";
|
|
1611
1620
|
#e;
|
|
1612
1621
|
#i;
|
|
@@ -1620,29 +1629,30 @@ class l {
|
|
|
1620
1629
|
* @param inputStr
|
|
1621
1630
|
* @param values
|
|
1622
1631
|
*/
|
|
1623
|
-
parse
|
|
1624
|
-
if (this.#i = [], this.#e = [], typeof t == "string")
|
|
1632
|
+
parse(t, ...e) {
|
|
1633
|
+
if (this.#i = [], this.#e = [], this.#h(), typeof t == "string")
|
|
1625
1634
|
return this.#m(t, ...e);
|
|
1626
|
-
if ((typeof t == "number" || t instanceof
|
|
1635
|
+
if ((typeof t == "number" || t instanceof h || t instanceof p) && e.length === 0)
|
|
1627
1636
|
this.#i.push(new p(t));
|
|
1628
1637
|
else if (t instanceof p && e.length > 0)
|
|
1629
1638
|
this.#i.push(new p(t)), e.forEach((i) => {
|
|
1630
1639
|
this.#i.push(new p(i));
|
|
1631
1640
|
});
|
|
1632
|
-
else if (t instanceof
|
|
1641
|
+
else if (t instanceof u)
|
|
1633
1642
|
for (const i of t.monoms)
|
|
1634
1643
|
this.#i.push(i.clone());
|
|
1635
1644
|
return this;
|
|
1636
|
-
}
|
|
1645
|
+
}
|
|
1637
1646
|
/**
|
|
1638
1647
|
* Clone the polynom
|
|
1639
1648
|
*/
|
|
1640
|
-
clone
|
|
1641
|
-
const t = new
|
|
1649
|
+
clone() {
|
|
1650
|
+
const t = new u(), e = [];
|
|
1651
|
+
t.#t = this.#t;
|
|
1642
1652
|
for (const i of this.#i)
|
|
1643
1653
|
e.push(i.clone());
|
|
1644
1654
|
return t.monoms = e, t;
|
|
1645
|
-
}
|
|
1655
|
+
}
|
|
1646
1656
|
get tex() {
|
|
1647
1657
|
return this.#l("tex");
|
|
1648
1658
|
}
|
|
@@ -1650,105 +1660,109 @@ class l {
|
|
|
1650
1660
|
return this.#l();
|
|
1651
1661
|
}
|
|
1652
1662
|
static xMultiply(...t) {
|
|
1653
|
-
const e = new
|
|
1663
|
+
const e = new u().one();
|
|
1654
1664
|
return t.forEach((i) => {
|
|
1655
1665
|
e.multiply(i);
|
|
1656
1666
|
}), e;
|
|
1657
1667
|
}
|
|
1658
|
-
add
|
|
1668
|
+
add(...t) {
|
|
1659
1669
|
for (const e of t)
|
|
1660
|
-
e instanceof
|
|
1670
|
+
e instanceof u ? this.#i = this.#i.concat(e.monoms.map((i) => i.clone())) : e instanceof p ? this.#i.push(e.clone()) : typeof e == "number" && Number.isSafeInteger(e) ? this.#i.push(new p(e.toString())) : this.#i.push(new p(e));
|
|
1661
1671
|
return this.reduce();
|
|
1662
|
-
}
|
|
1663
|
-
commonMonom
|
|
1664
|
-
const t = new p().one(), e = this.gcdNumerator(), i = this.gcdDenominator()
|
|
1665
|
-
t.coefficient = new
|
|
1666
|
-
for (const
|
|
1667
|
-
t.setLetter(
|
|
1668
|
-
for (const
|
|
1669
|
-
if (t.setLetter(
|
|
1672
|
+
}
|
|
1673
|
+
commonMonom() {
|
|
1674
|
+
const t = new p().one(), e = this.gcdNumerator(), i = this.gcdDenominator();
|
|
1675
|
+
t.coefficient = new h(e, i);
|
|
1676
|
+
for (const s of this.variables) {
|
|
1677
|
+
t.setLetter(s, this.degree(s));
|
|
1678
|
+
for (const r of this.#i)
|
|
1679
|
+
if (t.setLetter(s, h.min(r.degree(s), t.degree(s))), t.degree(s).isZero())
|
|
1670
1680
|
break;
|
|
1671
1681
|
}
|
|
1672
1682
|
return t;
|
|
1673
|
-
}
|
|
1674
|
-
degree
|
|
1675
|
-
let e = new
|
|
1683
|
+
}
|
|
1684
|
+
degree(t) {
|
|
1685
|
+
let e = new h().zero();
|
|
1676
1686
|
for (const i of this.#i)
|
|
1677
|
-
e =
|
|
1687
|
+
e = h.max(i.degree(t).value, e);
|
|
1678
1688
|
return e;
|
|
1679
|
-
}
|
|
1680
|
-
derivative
|
|
1681
|
-
const e = new
|
|
1689
|
+
}
|
|
1690
|
+
derivative(t) {
|
|
1691
|
+
const e = new u();
|
|
1682
1692
|
for (const i of this.#i)
|
|
1683
1693
|
e.add(i.derivative(t));
|
|
1684
1694
|
return e.reduce();
|
|
1685
|
-
}
|
|
1686
|
-
divide
|
|
1687
|
-
if (t instanceof
|
|
1695
|
+
}
|
|
1696
|
+
divide(t) {
|
|
1697
|
+
if (t instanceof h)
|
|
1688
1698
|
return this.#o(t);
|
|
1689
1699
|
if (typeof t == "number" && Number.isSafeInteger(t))
|
|
1690
|
-
return this.#
|
|
1700
|
+
return this.#a(t);
|
|
1691
1701
|
if (t instanceof p)
|
|
1692
|
-
return this.divide(new
|
|
1693
|
-
if (t instanceof
|
|
1702
|
+
return this.divide(new u(t));
|
|
1703
|
+
if (t instanceof u) {
|
|
1694
1704
|
if (t.monoms.length === 1 && t.variables.length === 0)
|
|
1695
1705
|
return this.#o(t.monoms[0].coefficient);
|
|
1696
1706
|
{
|
|
1697
1707
|
const { quotient: e, reminder: i } = this.euclidean(t);
|
|
1698
1708
|
if (i.isZero())
|
|
1699
|
-
return this.#i = e.monoms, this;
|
|
1709
|
+
return this.#i = e.monoms, this.#h(), this;
|
|
1700
1710
|
}
|
|
1701
1711
|
} else if (typeof t == "string")
|
|
1702
|
-
return this.divide(new
|
|
1712
|
+
return this.divide(new u(t));
|
|
1703
1713
|
throw new Error(`Cannot divide by ${t}`);
|
|
1704
|
-
}
|
|
1705
|
-
empty
|
|
1714
|
+
}
|
|
1715
|
+
empty() {
|
|
1716
|
+
return this.#i = [], this.#h(), this;
|
|
1717
|
+
}
|
|
1706
1718
|
/**
|
|
1707
1719
|
* Divide the current polynom by another polynom.
|
|
1708
1720
|
* @param P
|
|
1709
1721
|
* returns {quotient: Polynom, reminder: Polynom}
|
|
1710
1722
|
*/
|
|
1711
|
-
euclidean
|
|
1712
|
-
const e = t.variables[0], i = new
|
|
1723
|
+
euclidean(t) {
|
|
1724
|
+
const e = t.variables[0], i = new u().zero(), s = this.clone().reorder(e);
|
|
1713
1725
|
if (t.variables.length === 0)
|
|
1714
1726
|
return {
|
|
1715
1727
|
quotient: this.clone().divide(t).reduce(),
|
|
1716
|
-
reminder: new
|
|
1728
|
+
reminder: new u().zero()
|
|
1717
1729
|
};
|
|
1730
|
+
if (!this.degree(e).isNatural() || !t.degree(e).isNatural())
|
|
1731
|
+
throw new Error("Euclidean division requires integer degrees");
|
|
1718
1732
|
const r = t.monomByDegree(void 0, e), o = t.degree(e);
|
|
1719
|
-
let
|
|
1720
|
-
for (; s.degree(e).isGeq(o) && c > 0 && (c--,
|
|
1733
|
+
let a, c = this.degree(e).value - o.value + 1;
|
|
1734
|
+
for (; s.degree(e).isGeq(o) && c > 0 && (c--, a = s.monomByDegree(void 0, e).clone().divide(r), !(!a.isZero() && (i.add(a), s.subtract(t.clone().multiply(a)).reduce(), a.degree(e).isZero()))); )
|
|
1721
1735
|
;
|
|
1722
1736
|
return i.reduce(), s.reduce(), { quotient: i, reminder: s };
|
|
1723
|
-
}
|
|
1724
|
-
evaluate
|
|
1737
|
+
}
|
|
1738
|
+
evaluate(t, e) {
|
|
1725
1739
|
if (e)
|
|
1726
|
-
return this.#
|
|
1727
|
-
const i = new
|
|
1740
|
+
return this.#c(t);
|
|
1741
|
+
const i = new h().zero();
|
|
1728
1742
|
return this.#i.forEach((s) => {
|
|
1729
1743
|
i.add(s.evaluate(t, e));
|
|
1730
1744
|
}), i;
|
|
1731
|
-
}
|
|
1745
|
+
}
|
|
1732
1746
|
// -------------------------------------
|
|
1733
1747
|
/**
|
|
1734
1748
|
* Factorize a polynom and store the best results in factors.
|
|
1735
|
-
* @param
|
|
1749
|
+
* @param _letter
|
|
1736
1750
|
* TODO: Handle other letter than 'x'.
|
|
1737
1751
|
*/
|
|
1738
1752
|
factorize(t) {
|
|
1739
1753
|
this.#e = [];
|
|
1740
1754
|
let e = this.clone().reorder();
|
|
1741
1755
|
const i = e.commonMonom();
|
|
1742
|
-
e.monomByDegree().coefficient.isStrictlyNegative() && i.opposite(), i.isOne() || (this.#e.push(new
|
|
1756
|
+
e.monomByDegree().coefficient.isStrictlyNegative() && i.opposite(), i.isOne() || (this.#e.push(new u(i)), e = e.euclidean(this.#e[0]).quotient);
|
|
1743
1757
|
const s = new R(e).solve();
|
|
1744
1758
|
if (s.length === 0)
|
|
1745
|
-
return this.#e = [this.clone()], this.#e;
|
|
1759
|
+
return this.#e.length === 0 ? this.#e = [this.clone()] : this.#e.push(e), this.#e;
|
|
1746
1760
|
if (s.forEach((o) => {
|
|
1747
1761
|
if (o.exact && o.root.isZero())
|
|
1748
|
-
for (let
|
|
1749
|
-
o.fraction.isRational() ? this.#e.push(new
|
|
1750
|
-
}), this.#e.map((o) => o.degree().value).reduce((o,
|
|
1751
|
-
const o =
|
|
1762
|
+
for (let a = 0; a < o.count; a++)
|
|
1763
|
+
o.fraction.isRational() ? this.#e.push(new u().fromCoefficients(o.fraction.denominator, -o.fraction.numerator)) : this.#e.push(new u().fromCoefficients(1, o.fraction.clone().opposite()));
|
|
1764
|
+
}), this.#e.map((o) => o.degree().value).reduce((o, a) => o + a, 0) < this.degree().value) {
|
|
1765
|
+
const o = u.xMultiply(...this.#e);
|
|
1752
1766
|
this.#e.push(this.clone().divide(o));
|
|
1753
1767
|
}
|
|
1754
1768
|
return this.#e;
|
|
@@ -1761,54 +1775,62 @@ class l {
|
|
|
1761
1775
|
const e = this.#t ?? "x";
|
|
1762
1776
|
return t.reverse().forEach((i, s) => {
|
|
1763
1777
|
const r = new p();
|
|
1764
|
-
r.coefficient = new
|
|
1765
|
-
}), this.reorder();
|
|
1778
|
+
r.coefficient = new h(i), r.setLetter(e, s), this.#i.push(r);
|
|
1779
|
+
}), this.#h(), this.reorder();
|
|
1780
|
+
}
|
|
1781
|
+
gcdDenominator() {
|
|
1782
|
+
return x.gcd(...this.getDenominators());
|
|
1783
|
+
}
|
|
1784
|
+
gcdNumerator() {
|
|
1785
|
+
return x.gcd(...this.getNumerators());
|
|
1766
1786
|
}
|
|
1767
|
-
gcdDenominator = () => x.gcd(...this.getDenominators());
|
|
1768
|
-
gcdNumerator = () => x.gcd(...this.getNumerators());
|
|
1769
1787
|
getCoefficients() {
|
|
1770
|
-
|
|
1788
|
+
if (!this.degree().isNatural())
|
|
1789
|
+
throw new Error("getCoefficients() requires a polynomial with integer degrees");
|
|
1790
|
+
const t = this.clone().reorder(), e = this.degree().value + 1, i = Array.from({ length: e }, () => new h(0));
|
|
1771
1791
|
return t.monoms.forEach((s) => {
|
|
1772
1792
|
const r = e - s.degree().value - 1;
|
|
1773
1793
|
i[r] = s.coefficient.clone();
|
|
1774
1794
|
}), i;
|
|
1775
1795
|
}
|
|
1776
1796
|
// Next functions are used for for commonMonom, which is used in the factorize method.
|
|
1777
|
-
getDenominators
|
|
1797
|
+
getDenominators() {
|
|
1778
1798
|
const t = [];
|
|
1779
1799
|
for (const e of this.#i)
|
|
1780
1800
|
t.push(e.coefficient.denominator);
|
|
1781
1801
|
return t;
|
|
1782
|
-
}
|
|
1783
|
-
getNumerators
|
|
1802
|
+
}
|
|
1803
|
+
getNumerators() {
|
|
1784
1804
|
const t = [];
|
|
1785
1805
|
for (const e of this.#i)
|
|
1786
1806
|
t.push(e.coefficient.numerator);
|
|
1787
1807
|
return t;
|
|
1788
|
-
}
|
|
1789
|
-
getZeroes
|
|
1808
|
+
}
|
|
1809
|
+
getZeroes() {
|
|
1810
|
+
return this.degree().isZero() ? [] : (this.roots = new R(this.clone()).solve(), this.roots);
|
|
1811
|
+
}
|
|
1790
1812
|
hasVariable(t) {
|
|
1791
1813
|
return this.variables.includes(t);
|
|
1792
1814
|
}
|
|
1793
|
-
integrate
|
|
1815
|
+
integrate(t, e, i = "x") {
|
|
1794
1816
|
const s = this.primitive(i), r = {}, o = {};
|
|
1795
|
-
return r[i] = new
|
|
1796
|
-
}
|
|
1817
|
+
return r[i] = new h(t), o[i] = new h(e), s.evaluate(o).subtract(s.evaluate(r));
|
|
1818
|
+
}
|
|
1797
1819
|
inverse() {
|
|
1798
1820
|
}
|
|
1799
|
-
isDeveloped
|
|
1821
|
+
isDeveloped(t) {
|
|
1800
1822
|
let e;
|
|
1801
1823
|
const i = t.replaceAll(/\^\(([-0-9/]+)\)/g, "$1");
|
|
1802
1824
|
if (i.includes("(") || i.includes(")"))
|
|
1803
1825
|
return !1;
|
|
1804
1826
|
try {
|
|
1805
|
-
e = new
|
|
1827
|
+
e = new u(t);
|
|
1806
1828
|
} catch {
|
|
1807
1829
|
return !1;
|
|
1808
1830
|
}
|
|
1809
1831
|
return !!this.isEqual(e);
|
|
1810
|
-
}
|
|
1811
|
-
isDividableBy
|
|
1832
|
+
}
|
|
1833
|
+
isDividableBy(t) {
|
|
1812
1834
|
if (t.degree().isOne()) {
|
|
1813
1835
|
const e = t.getZeroes()[0];
|
|
1814
1836
|
return e.exact ? this.evaluate(e.fraction).isZero() : !1;
|
|
@@ -1816,39 +1838,44 @@ class l {
|
|
|
1816
1838
|
const { reminder: e } = this.euclidean(t);
|
|
1817
1839
|
return e.isZero();
|
|
1818
1840
|
}
|
|
1819
|
-
}
|
|
1820
|
-
isEqual
|
|
1841
|
+
}
|
|
1842
|
+
isEqual(t) {
|
|
1843
|
+
return this.#n(t, "=");
|
|
1844
|
+
}
|
|
1821
1845
|
get isMultiVariable() {
|
|
1822
1846
|
return this.#i.some((t) => t.variables.length > 1);
|
|
1823
1847
|
}
|
|
1824
1848
|
isOne() {
|
|
1825
1849
|
return this.#i.length === 1 && this.#i[0].coefficient.isOne() && this.degree().isZero();
|
|
1826
1850
|
}
|
|
1827
|
-
isOppositeAt
|
|
1828
|
-
|
|
1851
|
+
isOppositeAt(t) {
|
|
1852
|
+
return this.#n(t.clone().opposite(), "=");
|
|
1853
|
+
}
|
|
1854
|
+
isSameAs(t) {
|
|
1855
|
+
return this.#n(t, "same");
|
|
1856
|
+
}
|
|
1829
1857
|
isZero() {
|
|
1830
1858
|
return this.#i.length === 1 && this.#i[0].coefficient.isZero() || this.#i.length === 0;
|
|
1831
1859
|
}
|
|
1832
|
-
lcmDenominator
|
|
1833
|
-
|
|
1860
|
+
lcmDenominator() {
|
|
1861
|
+
return x.lcm(...this.getDenominators());
|
|
1862
|
+
}
|
|
1863
|
+
lcmNumerator() {
|
|
1864
|
+
return x.lcm(...this.getNumerators());
|
|
1865
|
+
}
|
|
1834
1866
|
get length() {
|
|
1835
1867
|
return this.#i.length;
|
|
1836
1868
|
}
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
limitToNegativeInfinity = (t) => {
|
|
1848
|
-
const e = this.monomByDegree(void 0, t), i = e.coefficient.sign(), s = e.degree(t);
|
|
1849
|
-
return s.isStrictlyPositive() ? i === -1 ? new a().infinite() : new a().infinite().opposite() : s.isZero() ? e.coefficient : new a().zero();
|
|
1850
|
-
};
|
|
1851
|
-
monomByDegree = (t, e) => {
|
|
1869
|
+
limitTo(t, e) {
|
|
1870
|
+
const i = new h(t);
|
|
1871
|
+
if (i.isFinite()) {
|
|
1872
|
+
const f = e ?? this.variables[0] ?? "x";
|
|
1873
|
+
return this.evaluate({ [f]: i });
|
|
1874
|
+
}
|
|
1875
|
+
const s = this.monomByDegree(void 0, e), r = s.coefficient.sign(), o = s.degree(e);
|
|
1876
|
+
return o.isZero() ? s.coefficient.clone() : o.isStrictlyPositive() ? i.isPositive() ? r === 1 ? new h().infinite() : new h().infinite().opposite() : (o.value % 2 === 0 ? r : -r) === 1 ? new h().infinite() : new h().infinite().opposite() : new h().zero();
|
|
1877
|
+
}
|
|
1878
|
+
monomByDegree(t, e) {
|
|
1852
1879
|
if (t === void 0)
|
|
1853
1880
|
return this.monomByDegree(this.degree(e), e);
|
|
1854
1881
|
const i = this.clone().reduce();
|
|
@@ -1856,34 +1883,34 @@ class l {
|
|
|
1856
1883
|
if (s.degree(e).isEqual(t))
|
|
1857
1884
|
return s.clone();
|
|
1858
1885
|
return new p().zero();
|
|
1859
|
-
}
|
|
1886
|
+
}
|
|
1860
1887
|
// Used in LinearSystem.tex
|
|
1861
|
-
monomByLetter
|
|
1888
|
+
monomByLetter(t) {
|
|
1862
1889
|
const e = this.clone().reduce();
|
|
1863
1890
|
for (const i of e.#i)
|
|
1864
1891
|
if (i.hasVariable(t))
|
|
1865
1892
|
return i.clone();
|
|
1866
1893
|
return new p().zero();
|
|
1867
|
-
}
|
|
1894
|
+
}
|
|
1868
1895
|
// ------------------------------------------
|
|
1869
1896
|
get monoms() {
|
|
1870
1897
|
return this.#i;
|
|
1871
1898
|
}
|
|
1872
1899
|
set monoms(t) {
|
|
1873
|
-
this.#i = t;
|
|
1900
|
+
this.#i = t, this.#h();
|
|
1874
1901
|
}
|
|
1875
|
-
monomsByDegree
|
|
1902
|
+
monomsByDegree(t, e) {
|
|
1876
1903
|
if (t === void 0)
|
|
1877
|
-
return this.monomsByDegree(this.degree(e));
|
|
1904
|
+
return this.monomsByDegree(this.degree(e), e);
|
|
1878
1905
|
const i = [], s = this.clone().reduce();
|
|
1879
1906
|
for (const r of s.#i)
|
|
1880
1907
|
r.degree(e).isEqual(t) && i.push(r.clone());
|
|
1881
1908
|
return i;
|
|
1882
|
-
}
|
|
1883
|
-
multiply
|
|
1884
|
-
if (t instanceof
|
|
1909
|
+
}
|
|
1910
|
+
multiply(t) {
|
|
1911
|
+
if (t instanceof u)
|
|
1885
1912
|
return this.#p(t);
|
|
1886
|
-
if (t instanceof
|
|
1913
|
+
if (t instanceof h)
|
|
1887
1914
|
return this.#u(t);
|
|
1888
1915
|
if (t instanceof p)
|
|
1889
1916
|
return this.#d(t);
|
|
@@ -1891,30 +1918,36 @@ class l {
|
|
|
1891
1918
|
return this.#f(t);
|
|
1892
1919
|
if (typeof t == "string")
|
|
1893
1920
|
try {
|
|
1894
|
-
const e = new
|
|
1921
|
+
const e = new h(t);
|
|
1895
1922
|
return this.#u(e);
|
|
1896
1923
|
} catch {
|
|
1897
1924
|
throw new Error("Cannot multiply by this value.");
|
|
1898
1925
|
}
|
|
1899
1926
|
throw new Error(`Cannot multiply by this value: ${t}`);
|
|
1900
|
-
}
|
|
1927
|
+
}
|
|
1901
1928
|
get numberOfVars() {
|
|
1902
1929
|
return this.variables.length;
|
|
1903
1930
|
}
|
|
1904
|
-
one
|
|
1931
|
+
one() {
|
|
1932
|
+
return this.#i = [], this.#i.push(new p().one()), this.#h(), this;
|
|
1933
|
+
}
|
|
1905
1934
|
// ------------------------------------------
|
|
1906
|
-
opposite
|
|
1935
|
+
opposite() {
|
|
1936
|
+
return this.#i = this.#i.map((t) => t.opposite()), this.#h(), this;
|
|
1937
|
+
}
|
|
1907
1938
|
get plotFunction() {
|
|
1908
1939
|
return this.#l("tex", !1, !1, !0);
|
|
1909
1940
|
}
|
|
1910
|
-
pow
|
|
1911
|
-
|
|
1912
|
-
|
|
1941
|
+
pow(t) {
|
|
1942
|
+
return rt(this, t).reduce();
|
|
1943
|
+
}
|
|
1944
|
+
primitive(t) {
|
|
1945
|
+
const e = new u();
|
|
1913
1946
|
for (const i of this.#i)
|
|
1914
1947
|
e.add(i.primitive(t));
|
|
1915
1948
|
return e;
|
|
1916
|
-
}
|
|
1917
|
-
reduce
|
|
1949
|
+
}
|
|
1950
|
+
reduce() {
|
|
1918
1951
|
let t = 0;
|
|
1919
1952
|
for (; t < this.#i.length; ) {
|
|
1920
1953
|
for (let e = t + 1; e < this.#i.length; e++)
|
|
@@ -1924,14 +1957,14 @@ class l {
|
|
|
1924
1957
|
this.#i = this.#i.filter((e) => !e.coefficient.isZero());
|
|
1925
1958
|
for (const e of this.#i)
|
|
1926
1959
|
e.coefficient.reduce();
|
|
1927
|
-
return this.length === 0 ?
|
|
1928
|
-
}
|
|
1929
|
-
reorder
|
|
1960
|
+
return this.length === 0 ? this.zero() : (this.#h(), this.reorder());
|
|
1961
|
+
}
|
|
1962
|
+
reorder(t = "x", e = !1) {
|
|
1930
1963
|
const i = this.variables.filter((s) => s !== t);
|
|
1931
1964
|
return this.#i.sort(function(s, r) {
|
|
1932
|
-
const o = s.degree(t).value,
|
|
1933
|
-
if (o !==
|
|
1934
|
-
return e ? o -
|
|
1965
|
+
const o = s.degree(t).value, a = r.degree(t).value;
|
|
1966
|
+
if (o !== a)
|
|
1967
|
+
return e ? o - a : a - o;
|
|
1935
1968
|
if (i.length > 0)
|
|
1936
1969
|
for (const c of i) {
|
|
1937
1970
|
const f = s.degree(c).value, m = r.degree(c).value;
|
|
@@ -1940,19 +1973,25 @@ class l {
|
|
|
1940
1973
|
}
|
|
1941
1974
|
return 0;
|
|
1942
1975
|
}), this;
|
|
1943
|
-
}
|
|
1976
|
+
}
|
|
1944
1977
|
/**
|
|
1945
1978
|
* Replace a variable (letter) by a polynom.
|
|
1946
1979
|
* @param letter
|
|
1947
1980
|
* @param P
|
|
1948
1981
|
*/
|
|
1949
|
-
replaceBy
|
|
1982
|
+
replaceBy(t, e) {
|
|
1950
1983
|
let i;
|
|
1951
|
-
const s = new
|
|
1984
|
+
const s = new u().zero();
|
|
1952
1985
|
for (const r of this.monoms)
|
|
1953
|
-
!r.hasVariable(t) || r.literal[t].isZero()
|
|
1954
|
-
|
|
1955
|
-
|
|
1986
|
+
if (!r.hasVariable(t) || r.literal[t].isZero())
|
|
1987
|
+
s.add(r.clone());
|
|
1988
|
+
else {
|
|
1989
|
+
if (i = r.literal[t].clone(), r.removeVariable(t), i.isStrictlyNegative())
|
|
1990
|
+
throw new Error(`Cannot replace variable "${t}" with negative power in a Polynom`);
|
|
1991
|
+
s.add(e.clone().pow(i.numerator).multiply(r));
|
|
1992
|
+
}
|
|
1993
|
+
return this.#i = s.reduce().monoms, this.#h(), this;
|
|
1994
|
+
}
|
|
1956
1995
|
// ------------------------------------------
|
|
1957
1996
|
root() {
|
|
1958
1997
|
throw new Error("Cannot take the root from a polynom");
|
|
@@ -1969,17 +2008,17 @@ class l {
|
|
|
1969
2008
|
sqrt() {
|
|
1970
2009
|
throw new Error("Cannot take the square root from a polynom");
|
|
1971
2010
|
}
|
|
1972
|
-
subtract
|
|
2011
|
+
subtract(...t) {
|
|
1973
2012
|
for (const e of t)
|
|
1974
|
-
e instanceof
|
|
2013
|
+
e instanceof u ? this.add(e.clone().opposite()) : e instanceof p ? this.#i.push(e.clone().opposite()) : this.#i.push(new p(e).opposite());
|
|
1975
2014
|
return this.reduce();
|
|
1976
|
-
}
|
|
2015
|
+
}
|
|
1977
2016
|
tableOfSigns() {
|
|
1978
2017
|
const t = this.roots;
|
|
1979
2018
|
let e = new Array(2 * t.length + 1).fill("").map((i, s) => s % 2 === 0 ? "" : "z");
|
|
1980
2019
|
if (e.length === 1) {
|
|
1981
2020
|
const [i] = this.getCoefficients().map((s) => s.value);
|
|
1982
|
-
e =
|
|
2021
|
+
e = j(e, "", i > 0 ? "+" : "-");
|
|
1983
2022
|
} else if (this.degree().isOne()) {
|
|
1984
2023
|
const [i] = this.getCoefficients().map((s) => s.value);
|
|
1985
2024
|
e[0] = i > 0 ? "-" : "+", e[1] = "z", e[2] = i > 0 ? "+" : "-";
|
|
@@ -1988,7 +2027,7 @@ class l {
|
|
|
1988
2027
|
t[0].value - 1,
|
|
1989
2028
|
...t.map((s, r) => r === t.length - 1 ? t[r].value + 1 : (t[r].value + t[r + 1].value) / 2)
|
|
1990
2029
|
].forEach((s, r) => {
|
|
1991
|
-
const o = this.evaluate({ x: s }, !0);
|
|
2030
|
+
const o = this.evaluate({ [this.variables[0] ?? "x"]: s }, !0);
|
|
1992
2031
|
e[r * 2] = o > 0 ? "+" : "-";
|
|
1993
2032
|
});
|
|
1994
2033
|
return { roots: t, signs: e };
|
|
@@ -1998,20 +2037,19 @@ class l {
|
|
|
1998
2037
|
return this.monoms[0]?.coefficient.value ?? 0;
|
|
1999
2038
|
}
|
|
2000
2039
|
get variables() {
|
|
2001
|
-
|
|
2002
|
-
for (const e of this.#i)
|
|
2003
|
-
t = t.concat(e.variables);
|
|
2004
|
-
return t = [...new Set(t)], t.sort(), t;
|
|
2040
|
+
return [...new Set(this.#i.flatMap((t) => t.variables))].sort();
|
|
2005
2041
|
}
|
|
2006
2042
|
/**
|
|
2007
2043
|
* Set the polynom to zero.
|
|
2008
2044
|
* @returns {this}
|
|
2009
2045
|
*/
|
|
2010
|
-
zero
|
|
2046
|
+
zero() {
|
|
2047
|
+
return this.#i = [], this.#i.push(new p().zero()), this.#h(), this;
|
|
2048
|
+
}
|
|
2011
2049
|
get zeroes() {
|
|
2012
2050
|
return this.getZeroes();
|
|
2013
2051
|
}
|
|
2014
|
-
#n
|
|
2052
|
+
#n(t, e) {
|
|
2015
2053
|
e ??= "=";
|
|
2016
2054
|
const i = this.clone().reduce().reorder(), s = t.clone().reduce().reorder();
|
|
2017
2055
|
switch (e) {
|
|
@@ -2022,60 +2060,57 @@ class l {
|
|
|
2022
2060
|
default:
|
|
2023
2061
|
return !1;
|
|
2024
2062
|
}
|
|
2025
|
-
}
|
|
2026
|
-
#o
|
|
2063
|
+
}
|
|
2064
|
+
#o(t) {
|
|
2027
2065
|
for (const e of this.#i)
|
|
2028
2066
|
e.coefficient.divide(t);
|
|
2029
|
-
return this;
|
|
2030
|
-
}
|
|
2031
|
-
#
|
|
2032
|
-
const e = new
|
|
2067
|
+
return this.#h(), this;
|
|
2068
|
+
}
|
|
2069
|
+
#a(t) {
|
|
2070
|
+
const e = new h(t);
|
|
2033
2071
|
for (const i of this.#i)
|
|
2034
2072
|
i.coefficient.divide(e);
|
|
2035
|
-
return this;
|
|
2036
|
-
}
|
|
2037
|
-
#
|
|
2073
|
+
return this.#h(), this;
|
|
2074
|
+
}
|
|
2075
|
+
#c(t) {
|
|
2038
2076
|
let e = 0;
|
|
2039
2077
|
return this.#i.forEach((i) => {
|
|
2040
2078
|
e += i.evaluate(t, !0);
|
|
2041
2079
|
}), e;
|
|
2042
|
-
}
|
|
2043
|
-
#l
|
|
2080
|
+
}
|
|
2081
|
+
#l(t, e, i, s) {
|
|
2044
2082
|
let r = "";
|
|
2045
2083
|
for (const o of this.#i) {
|
|
2046
2084
|
if (o.coefficient.value === 0)
|
|
2047
2085
|
continue;
|
|
2048
|
-
let
|
|
2049
|
-
s ?
|
|
2086
|
+
let a;
|
|
2087
|
+
s ? a = o.plotFunction : a = t === "tex" ? o.tex : o.display, r += `${o.coefficient.sign() === 1 && (r !== "" || e === !0) ? "+" : ""}${a}`;
|
|
2050
2088
|
}
|
|
2051
2089
|
return i === !0 && this.length > 1 && (t === "tex" ? r = `\\left( ${r} \\right)` : r = `(${r})`), r === "" && (r = "0"), r;
|
|
2052
|
-
}
|
|
2053
|
-
#
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
h.degree(i).isNotEqual(c.degree(i)) && (o.push(new l(h, c)), o.push(new l(h, c.clone().opposite())));
|
|
2058
|
-
});
|
|
2059
|
-
}), o;
|
|
2060
|
-
};
|
|
2061
|
-
#u = (t) => {
|
|
2090
|
+
}
|
|
2091
|
+
#h() {
|
|
2092
|
+
this.#r = !1, this.#e = [];
|
|
2093
|
+
}
|
|
2094
|
+
#u(t) {
|
|
2062
2095
|
for (const e of this.#i)
|
|
2063
2096
|
e.coefficient.multiply(t);
|
|
2064
2097
|
return this.reduce();
|
|
2065
|
-
}
|
|
2066
|
-
#f
|
|
2067
|
-
|
|
2098
|
+
}
|
|
2099
|
+
#f(t) {
|
|
2100
|
+
return this.#u(new h(t));
|
|
2101
|
+
}
|
|
2102
|
+
#d(t) {
|
|
2068
2103
|
for (const e of this.#i)
|
|
2069
2104
|
e.multiply(t);
|
|
2070
2105
|
return this.reduce();
|
|
2071
|
-
}
|
|
2072
|
-
#p
|
|
2106
|
+
}
|
|
2107
|
+
#p(t) {
|
|
2073
2108
|
const e = [];
|
|
2074
2109
|
for (const i of this.#i)
|
|
2075
2110
|
for (const s of t.monoms)
|
|
2076
2111
|
e.push(p.xMultiply(i, s));
|
|
2077
2112
|
return this.#i = e, this.reduce();
|
|
2078
|
-
}
|
|
2113
|
+
}
|
|
2079
2114
|
#m(t, ...e) {
|
|
2080
2115
|
if (e.length === 0) {
|
|
2081
2116
|
if (t !== "" && !isNaN(Number(t))) {
|
|
@@ -2083,18 +2118,18 @@ class l {
|
|
|
2083
2118
|
const i = new p(Number(t));
|
|
2084
2119
|
return this.add(i), this;
|
|
2085
2120
|
}
|
|
2086
|
-
return this.#
|
|
2087
|
-
} else if (/^[a-z]
|
|
2121
|
+
return this.#w(t);
|
|
2122
|
+
} else if (/^[a-z]+$/.test(t)) {
|
|
2088
2123
|
this.empty();
|
|
2089
|
-
const i = e.map((s) => new
|
|
2124
|
+
const i = e.map((s) => new h(s));
|
|
2090
2125
|
if (t.length > 1) {
|
|
2091
2126
|
const s = t.split("");
|
|
2092
|
-
if (
|
|
2093
|
-
throw new Error(
|
|
2127
|
+
if (i.length > s.length + 1)
|
|
2128
|
+
throw new Error(`Too many values: ${s.length} letters but ${i.length} values provided`);
|
|
2094
2129
|
let r = 0;
|
|
2095
2130
|
for (const o of i) {
|
|
2096
|
-
const
|
|
2097
|
-
|
|
2131
|
+
const a = new p();
|
|
2132
|
+
a.coefficient = o.clone(), a.literalStr = s[r] ?? "", this.add(a), r++;
|
|
2098
2133
|
}
|
|
2099
2134
|
} else {
|
|
2100
2135
|
let s = i.length - 1;
|
|
@@ -2107,43 +2142,32 @@ class l {
|
|
|
2107
2142
|
} else
|
|
2108
2143
|
return this.zero();
|
|
2109
2144
|
}
|
|
2110
|
-
|
|
2111
|
-
* Main parse using a shutting yard class
|
|
2112
|
-
* @param inputStr
|
|
2113
|
-
*/
|
|
2114
|
-
#g = (t) => {
|
|
2115
|
-
const i = new G().parse(t).rpn;
|
|
2116
|
-
this.zero();
|
|
2117
|
-
const s = [];
|
|
2118
|
-
for (const r of i)
|
|
2119
|
-
this.#w(s, r);
|
|
2120
|
-
return s.length === 1 && this.add(s[0]), this.reorder();
|
|
2121
|
-
};
|
|
2122
|
-
#w = (t, e) => {
|
|
2145
|
+
#g(t, e) {
|
|
2123
2146
|
switch (e.tokenType) {
|
|
2124
|
-
case
|
|
2125
|
-
t.push(new
|
|
2147
|
+
case l.COEFFICIENT:
|
|
2148
|
+
t.push(new u(e.token));
|
|
2126
2149
|
break;
|
|
2127
|
-
case
|
|
2128
|
-
t.push(new
|
|
2150
|
+
case l.VARIABLE:
|
|
2151
|
+
t.push(new u().add(new p(e.token)));
|
|
2129
2152
|
break;
|
|
2130
|
-
case
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
case u.OPERATION:
|
|
2153
|
+
case l.CONSTANT:
|
|
2154
|
+
throw new Error("Unsupported CONSTANT token in Polynom parser");
|
|
2155
|
+
case l.OPERATION:
|
|
2134
2156
|
if (t.length >= 2) {
|
|
2135
2157
|
const i = t.pop(), s = t.pop();
|
|
2136
2158
|
if (s === void 0 || i === void 0)
|
|
2137
|
-
|
|
2159
|
+
throw new Error("Unexpected undefined operand in Polynom parser stack");
|
|
2138
2160
|
if (e.token === "+")
|
|
2139
2161
|
t.push(s.add(i));
|
|
2140
2162
|
else if (e.token === "-")
|
|
2141
2163
|
t.push(s.subtract(i));
|
|
2142
2164
|
else if (e.token === "*")
|
|
2143
2165
|
t.push(s.multiply(i));
|
|
2144
|
-
else if (e.token === "/")
|
|
2145
|
-
i.degree().isStrictlyPositive()
|
|
2146
|
-
|
|
2166
|
+
else if (e.token === "/") {
|
|
2167
|
+
if (i.degree().isStrictlyPositive())
|
|
2168
|
+
throw new Error("Cannot divide a Polynom by another Polynom of degree > 0");
|
|
2169
|
+
t.push(s.divide(i.monoms[0].coefficient));
|
|
2170
|
+
} else if (e.token === "^") {
|
|
2147
2171
|
if (i.degree().isStrictlyPositive())
|
|
2148
2172
|
throw new Error("Cannot elevate a polynom with another polynom !");
|
|
2149
2173
|
if (i.monoms[0].coefficient.isRelative())
|
|
@@ -2153,7 +2177,7 @@ class l {
|
|
|
2153
2177
|
s.monoms[0].literal[r].multiply(i.monoms[0].coefficient);
|
|
2154
2178
|
t.push(s);
|
|
2155
2179
|
} else
|
|
2156
|
-
|
|
2180
|
+
throw new Error("Cannot raise a multi-monom Polynom to a fractional power");
|
|
2157
2181
|
}
|
|
2158
2182
|
} else if (e.token === "-") {
|
|
2159
2183
|
const i = t.pop();
|
|
@@ -2161,14 +2185,24 @@ class l {
|
|
|
2161
2185
|
} else
|
|
2162
2186
|
throw new Error("Error parsing the polynom");
|
|
2163
2187
|
break;
|
|
2164
|
-
case
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
console.error("The function token should not appear here - might be introduced later.");
|
|
2169
|
-
break;
|
|
2188
|
+
case l.MONOM:
|
|
2189
|
+
throw new Error("Unexpected MONOM token in polynom parser");
|
|
2190
|
+
case l.FUNCTION:
|
|
2191
|
+
throw new Error(`Unsupported function token "${e.token}" in polynom parser`);
|
|
2170
2192
|
}
|
|
2171
|
-
}
|
|
2193
|
+
}
|
|
2194
|
+
/**
|
|
2195
|
+
* Main parse using a shutting yard class
|
|
2196
|
+
* @param inputStr
|
|
2197
|
+
*/
|
|
2198
|
+
#w(t) {
|
|
2199
|
+
const i = new G().parse(t).rpn;
|
|
2200
|
+
this.zero();
|
|
2201
|
+
const s = [];
|
|
2202
|
+
for (const r of i)
|
|
2203
|
+
this.#g(s, r);
|
|
2204
|
+
return s.length === 1 && this.add(s[0]), this.reorder();
|
|
2205
|
+
}
|
|
2172
2206
|
}
|
|
2173
2207
|
class v {
|
|
2174
2208
|
// Left part of the equation
|
|
@@ -2178,11 +2212,11 @@ class v {
|
|
|
2178
2212
|
// Signe of the equation
|
|
2179
2213
|
#i;
|
|
2180
2214
|
constructor(t, e, i) {
|
|
2181
|
-
if (this.#t = new
|
|
2215
|
+
if (this.#t = new u().zero(), this.#e = new u().zero(), this.#i = "=", t !== void 0 && e === void 0) {
|
|
2182
2216
|
if (t instanceof v)
|
|
2183
2217
|
return t.clone();
|
|
2184
2218
|
typeof t == "string" && this.parse(t);
|
|
2185
|
-
} else t !== void 0 && e !== void 0 && (this.left = new
|
|
2219
|
+
} else t !== void 0 && e !== void 0 && (this.left = new u(t), this.right = new u(e));
|
|
2186
2220
|
return i !== void 0 && (this.sign = i), this;
|
|
2187
2221
|
}
|
|
2188
2222
|
// ------------------------------------------
|
|
@@ -2191,7 +2225,7 @@ class v {
|
|
|
2191
2225
|
if (e === !1)
|
|
2192
2226
|
throw new Error("The equation is not valid (no sign found)");
|
|
2193
2227
|
const i = t.split(e);
|
|
2194
|
-
return this.create(new
|
|
2228
|
+
return this.create(new u(i[0]), new u(i[1]), this.#r(e));
|
|
2195
2229
|
};
|
|
2196
2230
|
clone = () => new v(this.#t.clone(), this.#e.clone(), this.#i);
|
|
2197
2231
|
get tex() {
|
|
@@ -2220,7 +2254,7 @@ class v {
|
|
|
2220
2254
|
return this.#t.add(t.left), this.#e.add(t.right), this;
|
|
2221
2255
|
if (typeof t == "string" && !v.isEquationString(t))
|
|
2222
2256
|
return this.add(new v(t));
|
|
2223
|
-
const e = new
|
|
2257
|
+
const e = new u(t);
|
|
2224
2258
|
return this.#t.add(e), this.#e.add(e), this;
|
|
2225
2259
|
}
|
|
2226
2260
|
create = (t, e, i) => (this.#t = t, this.#e = e, this.#i = this.#r(i ?? "="), this);
|
|
@@ -2228,7 +2262,7 @@ class v {
|
|
|
2228
2262
|
* Get the degree of the equation
|
|
2229
2263
|
* @param letter
|
|
2230
2264
|
*/
|
|
2231
|
-
degree = (t) =>
|
|
2265
|
+
degree = (t) => h.max(this.#t.degree(t), this.#e.degree(t));
|
|
2232
2266
|
/**
|
|
2233
2267
|
* divide an equation by a given value (transformed as a fraction)
|
|
2234
2268
|
*
|
|
@@ -2244,7 +2278,7 @@ class v {
|
|
|
2244
2278
|
* @returns {Equation}
|
|
2245
2279
|
*/
|
|
2246
2280
|
divide = (t) => {
|
|
2247
|
-
const e = new
|
|
2281
|
+
const e = new h(t);
|
|
2248
2282
|
return e.isZero() ? this : this.multiply(e.inverse());
|
|
2249
2283
|
};
|
|
2250
2284
|
/**
|
|
@@ -2307,7 +2341,7 @@ class v {
|
|
|
2307
2341
|
this.#t = t;
|
|
2308
2342
|
}
|
|
2309
2343
|
// -----------------------------------------------
|
|
2310
|
-
letters = () => [.../* @__PURE__ */ new Set([...this.#t.
|
|
2344
|
+
letters = () => [.../* @__PURE__ */ new Set([...this.#t.variables, ...this.#e.variables])];
|
|
2311
2345
|
// -----------------------------------------------
|
|
2312
2346
|
/**
|
|
2313
2347
|
* Reorder will move all monoms containing a letter on the left, all the other on the right.
|
|
@@ -2318,7 +2352,7 @@ class v {
|
|
|
2318
2352
|
* @param value
|
|
2319
2353
|
*/
|
|
2320
2354
|
multiply = (t) => {
|
|
2321
|
-
const e = new
|
|
2355
|
+
const e = new h(t);
|
|
2322
2356
|
return this.#t.multiply(e), this.#e.multiply(e), this.#i !== "=" && e.sign() === -1 && this.#n(), this;
|
|
2323
2357
|
};
|
|
2324
2358
|
get numberOfVars() {
|
|
@@ -2367,7 +2401,7 @@ class v {
|
|
|
2367
2401
|
return this.#t.subtract(t.left), this.#e.subtract(t.right), this;
|
|
2368
2402
|
if (typeof t == "string" && !v.isEquationString(t))
|
|
2369
2403
|
return this.subtract(new v(t));
|
|
2370
|
-
const e = new
|
|
2404
|
+
const e = new u(t);
|
|
2371
2405
|
return this.#t.subtract(e), this.#e.subtract(e), this;
|
|
2372
2406
|
}
|
|
2373
2407
|
test = (t) => this.left.evaluate(t).isEqual(this.right.evaluate(t));
|
|
@@ -2406,7 +2440,7 @@ class b {
|
|
|
2406
2440
|
#i;
|
|
2407
2441
|
#s = !1;
|
|
2408
2442
|
constructor(t, e) {
|
|
2409
|
-
return t instanceof b ? (this.#e = t.polynom.clone(), this.#i = t.power.clone(), e !== void 0 && this.#i.multiply(new
|
|
2443
|
+
return t instanceof b ? (this.#e = t.polynom.clone(), this.#i = t.power.clone(), e !== void 0 && this.#i.multiply(new h(e))) : t !== void 0 ? (this.#e = new u(t), this.#i = new h(e ?? 1)) : (this.#e = new u(), this.#i = new h(1)), this.#t = 1, this;
|
|
2410
2444
|
}
|
|
2411
2445
|
parse() {
|
|
2412
2446
|
throw new Error("Method not implemented.");
|
|
@@ -2417,12 +2451,12 @@ class b {
|
|
|
2417
2451
|
get tex() {
|
|
2418
2452
|
const t = this.power.numerator, e = this.power.denominator;
|
|
2419
2453
|
let i, s;
|
|
2420
|
-
return this.#t === 0 && e > 1 ? (i = `\\sqrt${e === 2 ? "" : `[ ${e} ]`}{ ${this.polynom.tex} }`, s = t === 1 ? "" : `^{ ${t} }`) : (i = this.#s && this.power.isOne() ? this.polynom.tex :
|
|
2454
|
+
return this.#t === 0 && e > 1 ? (i = `\\sqrt${e === 2 ? "" : `[ ${e} ]`}{ ${this.polynom.tex} }`, s = t === 1 ? "" : `^{ ${t} }`) : (i = this.#s && this.power.isOne() ? this.polynom.tex : it(this.polynom.tex), s = e === 1 && t === 1 ? "" : `^{ ${this.power.tex} }`), i = `${i}${s}`, this.#t === 0 && t < 0 && (i = `\\frac{ 1 }{ ${i} }`), i;
|
|
2421
2455
|
}
|
|
2422
2456
|
get display() {
|
|
2423
2457
|
const t = this.power.numerator, e = this.power.denominator;
|
|
2424
2458
|
let i, s;
|
|
2425
|
-
return this.#t === 0 && e > 1 ? (i = `${e === 2 ? "sqrt" : `root(${e})`}(${this.polynom.display})`, s = t === 1 ? "" : `^(${t})`) : (i = this.#s && this.power.isOne() ? this.polynom.display :
|
|
2459
|
+
return this.#t === 0 && e > 1 ? (i = `${e === 2 ? "sqrt" : `root(${e})`}(${this.polynom.display})`, s = t === 1 ? "" : `^(${t})`) : (i = this.#s && this.power.isOne() ? this.polynom.display : it(this.polynom.display, !1), s = e === 1 && t === 1 ? "" : `^(${this.power.display})`), i = `${i}${s}`, this.#t === 0 && t < 0 && (i = `1/(${i})`), i;
|
|
2426
2460
|
}
|
|
2427
2461
|
add() {
|
|
2428
2462
|
throw new Error("Adding two factors is not possible");
|
|
@@ -2448,7 +2482,7 @@ class b {
|
|
|
2448
2482
|
divide(t) {
|
|
2449
2483
|
if (t instanceof b && this.isSameAs(t))
|
|
2450
2484
|
return this.power.subtract(t.power), this;
|
|
2451
|
-
const e = new
|
|
2485
|
+
const e = new u(t);
|
|
2452
2486
|
if (this.isSameAs(e))
|
|
2453
2487
|
return this.power.subtract(1), this;
|
|
2454
2488
|
throw new Error("The two factors must be the same");
|
|
@@ -2457,7 +2491,7 @@ class b {
|
|
|
2457
2491
|
return e ? this.polynom.evaluate(t, !0) ** this.power.value : this.polynom.evaluate(t).pow(this.power);
|
|
2458
2492
|
}
|
|
2459
2493
|
fromPolynom(t) {
|
|
2460
|
-
return this.#e = new
|
|
2494
|
+
return this.#e = new u(t), this.#i = new h(1), this;
|
|
2461
2495
|
}
|
|
2462
2496
|
hasVariable(t) {
|
|
2463
2497
|
return this.polynom.hasVariable(t);
|
|
@@ -2473,7 +2507,7 @@ class b {
|
|
|
2473
2507
|
}
|
|
2474
2508
|
isSameAs(t) {
|
|
2475
2509
|
let e;
|
|
2476
|
-
return t instanceof b ? e = t.polynom : t instanceof
|
|
2510
|
+
return t instanceof b ? e = t.polynom : t instanceof u ? e = t : e = new u(t), this.polynom.isEqual(e);
|
|
2477
2511
|
}
|
|
2478
2512
|
isZero() {
|
|
2479
2513
|
return this.polynom.isZero();
|
|
@@ -2481,7 +2515,7 @@ class b {
|
|
|
2481
2515
|
multiply(t) {
|
|
2482
2516
|
if (t instanceof b && this.isSameAs(t))
|
|
2483
2517
|
return this.power.add(t.power), this;
|
|
2484
|
-
const e = new
|
|
2518
|
+
const e = new u(t);
|
|
2485
2519
|
if (this.isSameAs(e))
|
|
2486
2520
|
return this.power.add(1), this;
|
|
2487
2521
|
throw new Error("The two factors must be the same");
|
|
@@ -2505,7 +2539,7 @@ class b {
|
|
|
2505
2539
|
return this.#i;
|
|
2506
2540
|
}
|
|
2507
2541
|
set power(t) {
|
|
2508
|
-
this.#i = new
|
|
2542
|
+
this.#i = new h(t);
|
|
2509
2543
|
}
|
|
2510
2544
|
primitive() {
|
|
2511
2545
|
throw new Error("Method not implemented.");
|
|
@@ -2524,7 +2558,7 @@ class b {
|
|
|
2524
2558
|
}
|
|
2525
2559
|
tableOfSigns() {
|
|
2526
2560
|
const t = this.power.clone().reduce(), e = this.polynom.tableOfSigns();
|
|
2527
|
-
return t.isStrictlyNegative() && (e.signs =
|
|
2561
|
+
return t.isStrictlyNegative() && (e.signs = j(e.signs, "z", "d")), t.denominator % 2 === 0 ? e.signs = j(e.signs, "-", "h") : t.numerator % 2 === 0 && (e.signs = j(e.signs, "-", "+")), { roots: e.roots, signs: e.signs };
|
|
2528
2562
|
}
|
|
2529
2563
|
get variables() {
|
|
2530
2564
|
return this.polynom.variables;
|
|
@@ -2563,7 +2597,7 @@ class z {
|
|
|
2563
2597
|
const s = e.split("").splice(0, i - 1);
|
|
2564
2598
|
return new z(
|
|
2565
2599
|
...t.map((r) => {
|
|
2566
|
-
const o = new
|
|
2600
|
+
const o = new u(s.join(""), ...r);
|
|
2567
2601
|
return new v(o, 0);
|
|
2568
2602
|
})
|
|
2569
2603
|
);
|
|
@@ -2607,11 +2641,11 @@ class z {
|
|
|
2607
2641
|
}
|
|
2608
2642
|
o.push(i.join("&"));
|
|
2609
2643
|
}
|
|
2610
|
-
let
|
|
2611
|
-
return e !== void 0 && e.length > 0 && (
|
|
2644
|
+
let a = 0;
|
|
2645
|
+
return e !== void 0 && e.length > 0 && (a = e[0].length), `\\left\\{\\begin{array}{${"r".repeat(r.length)}cl ${"|l".repeat(a)}}${o.join("\\\\ ")}\\end{array}\\right.`;
|
|
2612
2646
|
};
|
|
2613
2647
|
degree(t) {
|
|
2614
|
-
return
|
|
2648
|
+
return h.max(...this.#t.map((e) => e.degree(t)));
|
|
2615
2649
|
}
|
|
2616
2650
|
// ------------------------------------------
|
|
2617
2651
|
get equations() {
|
|
@@ -2665,9 +2699,9 @@ class z {
|
|
|
2665
2699
|
for (let s = 0; s < t.length; s++) {
|
|
2666
2700
|
let r = i[s][s].clone();
|
|
2667
2701
|
if (r.isZero()) {
|
|
2668
|
-
const o = i.find((
|
|
2702
|
+
const o = i.find((a, c) => c > s && !a[s].isZero());
|
|
2669
2703
|
if (o)
|
|
2670
|
-
i[s].forEach((
|
|
2704
|
+
i[s].forEach((a, c) => a.add(o[c])), r = i[s][s].clone();
|
|
2671
2705
|
else
|
|
2672
2706
|
throw new Error("Unsolvable...");
|
|
2673
2707
|
}
|
|
@@ -2675,9 +2709,9 @@ class z {
|
|
|
2675
2709
|
for (let o = 0; o < t.length; o++) {
|
|
2676
2710
|
if (o === s)
|
|
2677
2711
|
continue;
|
|
2678
|
-
const
|
|
2712
|
+
const a = i[o][s].clone().opposite();
|
|
2679
2713
|
for (let c = 0; c < i[o].length; c++)
|
|
2680
|
-
i[o][c].add(i[s][c].clone().multiply(
|
|
2714
|
+
i[o][c].add(i[s][c].clone().multiply(a));
|
|
2681
2715
|
if (i[o].slice(0, i[o].length - 1).every((c) => c.isZero()))
|
|
2682
2716
|
return i[o][i[o].length - 1].isZero() ? this.#r() : [];
|
|
2683
2717
|
}
|
|
@@ -2688,15 +2722,15 @@ class z {
|
|
|
2688
2722
|
const e = [], i = this.equations.map((s) => s.left.monomByLetter(t).coefficient.value);
|
|
2689
2723
|
return i.forEach((s, r) => {
|
|
2690
2724
|
for (let o = r + 1; o < i.length; o++) {
|
|
2691
|
-
const
|
|
2725
|
+
const a = x.lcm(s, i[o]), c = s < 0 ? -1 : 1;
|
|
2692
2726
|
e.push([
|
|
2693
2727
|
{
|
|
2694
2728
|
id: r,
|
|
2695
|
-
factor: c *
|
|
2729
|
+
factor: c * a / s
|
|
2696
2730
|
},
|
|
2697
2731
|
{
|
|
2698
2732
|
id: o,
|
|
2699
|
-
factor: -c *
|
|
2733
|
+
factor: -c * a / i[o]
|
|
2700
2734
|
}
|
|
2701
2735
|
]);
|
|
2702
2736
|
}
|
|
@@ -2730,8 +2764,8 @@ class z {
|
|
|
2730
2764
|
for (const i of this.#t) {
|
|
2731
2765
|
const s = [], r = i.clone().reorder();
|
|
2732
2766
|
for (const o of this.variables) {
|
|
2733
|
-
const
|
|
2734
|
-
s.push(
|
|
2767
|
+
const a = r.left.monomByLetter(o);
|
|
2768
|
+
s.push(a.coefficient);
|
|
2735
2769
|
}
|
|
2736
2770
|
e.push(r.right.monoms[0].coefficient), t.push(s);
|
|
2737
2771
|
}
|
|
@@ -2869,26 +2903,26 @@ class qt {
|
|
|
2869
2903
|
switch (r.token) {
|
|
2870
2904
|
case "&":
|
|
2871
2905
|
if (i.length >= 2) {
|
|
2872
|
-
const o = i.pop(),
|
|
2873
|
-
|
|
2906
|
+
const o = i.pop(), a = i.pop();
|
|
2907
|
+
a && o && i.push(new Set([...a].filter((c) => o.has(c))));
|
|
2874
2908
|
}
|
|
2875
2909
|
break;
|
|
2876
2910
|
case "|":
|
|
2877
2911
|
if (i.length >= 2) {
|
|
2878
|
-
const o = i.pop(),
|
|
2879
|
-
|
|
2912
|
+
const o = i.pop(), a = i.pop();
|
|
2913
|
+
a && o && i.push(/* @__PURE__ */ new Set([...a, ...o]));
|
|
2880
2914
|
}
|
|
2881
2915
|
break;
|
|
2882
2916
|
case "-":
|
|
2883
2917
|
if (i.length >= 2) {
|
|
2884
|
-
const o = i.pop(),
|
|
2885
|
-
|
|
2918
|
+
const o = i.pop(), a = i.pop();
|
|
2919
|
+
a && o && i.push(new Set([...a].filter((c) => !o.has(c))));
|
|
2886
2920
|
}
|
|
2887
2921
|
break;
|
|
2888
2922
|
case "!":
|
|
2889
2923
|
if (i.length >= 1) {
|
|
2890
2924
|
const o = i.pop();
|
|
2891
|
-
o && i.push(new Set([...s].filter((
|
|
2925
|
+
o && i.push(new Set([...s].filter((a) => !o.has(a))));
|
|
2892
2926
|
}
|
|
2893
2927
|
break;
|
|
2894
2928
|
}
|
|
@@ -2926,16 +2960,16 @@ class N {
|
|
|
2926
2960
|
return `(${i})/(${s})`;
|
|
2927
2961
|
}
|
|
2928
2962
|
static #i(t, e) {
|
|
2929
|
-
const i = Z(t), s = Z(e), o = Object.keys(i).filter((
|
|
2930
|
-
const c = i[
|
|
2931
|
-
return new b(
|
|
2963
|
+
const i = Z(t), s = Z(e), o = Object.keys(i).filter((a) => Object.hasOwn(s, a)).map((a) => {
|
|
2964
|
+
const c = i[a].reduce((m, d) => m.add(d.power), new h("0")), f = s[a].reduce((m, d) => m.add(d.power), new h("0"));
|
|
2965
|
+
return new b(a, h.min(c, f));
|
|
2932
2966
|
});
|
|
2933
2967
|
return new N(...o);
|
|
2934
2968
|
}
|
|
2935
2969
|
static #s(t, e) {
|
|
2936
|
-
const i = Z(t), s = Z(e), o = [.../* @__PURE__ */ new Set([...Object.keys(i), ...Object.keys(s)])].map((
|
|
2937
|
-
const c = Object.hasOwn(i,
|
|
2938
|
-
return new b(
|
|
2970
|
+
const i = Z(t), s = Z(e), o = [.../* @__PURE__ */ new Set([...Object.keys(i), ...Object.keys(s)])].map((a) => {
|
|
2971
|
+
const c = Object.hasOwn(i, a) ? i[a].reduce((m, d) => m.add(d.power), new h("0")) : new h(0), f = Object.hasOwn(s, a) ? s[a].reduce((m, d) => m.add(d.power), new h("0")) : new h(0);
|
|
2972
|
+
return new b(a, h.max(c, f));
|
|
2939
2973
|
});
|
|
2940
2974
|
return new N(...o);
|
|
2941
2975
|
}
|
|
@@ -2958,21 +2992,21 @@ class N {
|
|
|
2958
2992
|
return t.shift(), t.forEach((i) => e = N.#s(e, i)), e;
|
|
2959
2993
|
}
|
|
2960
2994
|
add(...t) {
|
|
2961
|
-
const e = [this.numerator, ...t.map((
|
|
2995
|
+
const e = [this.numerator, ...t.map((a) => a.numerator)], i = [this.denominator, ...t.map((a) => a.denominator)];
|
|
2962
2996
|
let s;
|
|
2963
|
-
if (i.some((
|
|
2964
|
-
const
|
|
2997
|
+
if (i.some((a) => a.factors.length > 0)) {
|
|
2998
|
+
const a = N.lcm(...i);
|
|
2965
2999
|
e.forEach((c, f) => {
|
|
2966
|
-
c.multiply(
|
|
2967
|
-
}), s =
|
|
3000
|
+
c.multiply(a.clone().divide(i[f]));
|
|
3001
|
+
}), s = a;
|
|
2968
3002
|
}
|
|
2969
|
-
const r = N.gcd(...e), o = new
|
|
2970
|
-
...e.map((
|
|
3003
|
+
const r = N.gcd(...e), o = new u(0).add(
|
|
3004
|
+
...e.map((a) => a.divide(r).reduce().develop().factors[0].polynom)
|
|
2971
3005
|
).reduce();
|
|
2972
3006
|
return this.#e = [
|
|
2973
3007
|
...r.factors,
|
|
2974
3008
|
new b(o)
|
|
2975
|
-
], s && this.divide(s), this.#e = this.#e.filter((
|
|
3009
|
+
], s && this.divide(s), this.#e = this.#e.filter((a) => !a.power.isZero()), this;
|
|
2976
3010
|
}
|
|
2977
3011
|
get asPower() {
|
|
2978
3012
|
return this.#t = D.POWER, this;
|
|
@@ -2981,7 +3015,7 @@ class N {
|
|
|
2981
3015
|
return this.#t = D.ROOT, this;
|
|
2982
3016
|
}
|
|
2983
3017
|
degree(t) {
|
|
2984
|
-
return this.#e.reduce((e, i) => e.add(i.degree(t)), new
|
|
3018
|
+
return this.#e.reduce((e, i) => e.add(i.degree(t)), new h("0"));
|
|
2985
3019
|
}
|
|
2986
3020
|
get denominator() {
|
|
2987
3021
|
return new N(
|
|
@@ -3001,7 +3035,7 @@ class N {
|
|
|
3001
3035
|
return i !== void 0 && (this.#e = i.factors), this.add(...t);
|
|
3002
3036
|
}
|
|
3003
3037
|
develop() {
|
|
3004
|
-
const t = new
|
|
3038
|
+
const t = new u("1"), e = new u("1");
|
|
3005
3039
|
return this.numerator.factors.forEach((i) => {
|
|
3006
3040
|
t.multiply(i.develop());
|
|
3007
3041
|
}), this.denominator.factors.forEach((i) => {
|
|
@@ -3012,15 +3046,15 @@ class N {
|
|
|
3012
3046
|
return this.#e = this.#e.concat(t.clone().factors.map((e) => e.inverse())), this;
|
|
3013
3047
|
}
|
|
3014
3048
|
evaluate(t, e) {
|
|
3015
|
-
return e ? this.#e.reduce((i, s) => i * s.evaluate(t, e), 1) : this.#e.reduce((i, s) => i.multiply(s.evaluate(t)), new
|
|
3049
|
+
return e ? this.#e.reduce((i, s) => i * s.evaluate(t, e), 1) : this.#e.reduce((i, s) => i.multiply(s.evaluate(t)), new h("1"));
|
|
3016
3050
|
}
|
|
3017
3051
|
factorize(t) {
|
|
3018
3052
|
const e = [];
|
|
3019
3053
|
this.#e.forEach((o) => {
|
|
3020
|
-
const
|
|
3021
|
-
if (
|
|
3054
|
+
const a = o.polynom.factorize(t);
|
|
3055
|
+
if (a.length > 1) {
|
|
3022
3056
|
const c = o.power.clone();
|
|
3023
|
-
e.push(...
|
|
3057
|
+
e.push(...a.map((f) => new b(f, c)));
|
|
3024
3058
|
} else
|
|
3025
3059
|
e.push(o.clone());
|
|
3026
3060
|
});
|
|
@@ -3034,8 +3068,8 @@ class N {
|
|
|
3034
3068
|
this.#e = t;
|
|
3035
3069
|
}
|
|
3036
3070
|
fromPolynom(t, e) {
|
|
3037
|
-
if (this.#e = [new b(new
|
|
3038
|
-
const i = new
|
|
3071
|
+
if (this.#e = [new b(new u(t))], e) {
|
|
3072
|
+
const i = new u(e);
|
|
3039
3073
|
if (i.isOne())
|
|
3040
3074
|
return this;
|
|
3041
3075
|
if (i.isZero())
|
|
@@ -3098,7 +3132,7 @@ class N {
|
|
|
3098
3132
|
reduce() {
|
|
3099
3133
|
const t = Z(this);
|
|
3100
3134
|
return this.#e = Object.values(t).map((e) => {
|
|
3101
|
-
const i = e[0].polynom, s = e.reduce((r, o) => r.add(o.power), new
|
|
3135
|
+
const i = e[0].polynom, s = e.reduce((r, o) => r.add(o.power), new h("0"));
|
|
3102
3136
|
return new b(i, s.reduce());
|
|
3103
3137
|
}).filter((e) => !e.power.isZero()), this;
|
|
3104
3138
|
}
|
|
@@ -3116,9 +3150,9 @@ class N {
|
|
|
3116
3150
|
const s = e.power.value, r = i.power.value;
|
|
3117
3151
|
if (s * r < 0)
|
|
3118
3152
|
return -s;
|
|
3119
|
-
const o = e.polynom.monoms.length,
|
|
3120
|
-
if (o !==
|
|
3121
|
-
return o -
|
|
3153
|
+
const o = e.polynom.monoms.length, a = i.polynom.monoms.length;
|
|
3154
|
+
if (o !== a)
|
|
3155
|
+
return o - a;
|
|
3122
3156
|
const c = e.polynom.degree(t).value, f = i.polynom.degree(t).value;
|
|
3123
3157
|
return c !== f ? c - f : s !== r ? s - r : e.degree().isLeq(i.degree()) ? -1 : 1;
|
|
3124
3158
|
}), this;
|
|
@@ -3133,18 +3167,18 @@ class N {
|
|
|
3133
3167
|
const t = this.getZeroes(), e = t.map((r) => r.value), i = this.factorize().factors.map((r) => ({ factor: new b(r), ...r.tableOfSigns() }));
|
|
3134
3168
|
return i.forEach((r) => {
|
|
3135
3169
|
const o = new Array(2 * t.length + 1).fill("");
|
|
3136
|
-
let
|
|
3170
|
+
let a = r.signs.shift(), c = r.roots.shift();
|
|
3137
3171
|
const f = o.map((m, d) => {
|
|
3138
3172
|
if (d % 2 === 0)
|
|
3139
|
-
return
|
|
3173
|
+
return a;
|
|
3140
3174
|
if (c === void 0 || c.value !== e[(d - 1) / 2])
|
|
3141
3175
|
return "t";
|
|
3142
3176
|
const y = r.signs.shift();
|
|
3143
|
-
return
|
|
3177
|
+
return a = r.signs.shift(), c = r.roots.shift(), y;
|
|
3144
3178
|
});
|
|
3145
3179
|
r.roots = t, r.signs = f;
|
|
3146
|
-
}), { signs: i.map((r) => [...r.signs]).reduce((r, o) => r.length === 0 ? o : (o.forEach((
|
|
3147
|
-
switch (
|
|
3180
|
+
}), { signs: i.map((r) => [...r.signs]).reduce((r, o) => r.length === 0 ? o : (o.forEach((a, c) => {
|
|
3181
|
+
switch (a) {
|
|
3148
3182
|
case "d":
|
|
3149
3183
|
r[c] = "d";
|
|
3150
3184
|
break;
|
|
@@ -3172,11 +3206,11 @@ class N {
|
|
|
3172
3206
|
}
|
|
3173
3207
|
}
|
|
3174
3208
|
function Z(n) {
|
|
3175
|
-
const t = new
|
|
3176
|
-
if (
|
|
3177
|
-
return
|
|
3178
|
-
const c =
|
|
3179
|
-
return Object.hasOwn(o, c) ? o[c].push(
|
|
3209
|
+
const t = new h().one(), e = new h().one(), i = n.factors.reduce((o, a) => {
|
|
3210
|
+
if (a.polynom.degree().isZero())
|
|
3211
|
+
return a.power.isPositive() ? t.multiply(a.polynom.monoms[0].coefficient) : e.multiply(a.polynom.monoms[0].coefficient), o;
|
|
3212
|
+
const c = a.polynom.display;
|
|
3213
|
+
return Object.hasOwn(o, c) ? o[c].push(a) : o[c] = [a], o;
|
|
3180
3214
|
}, {}), { numerator: s, denominator: r } = t.divide(e).reduce();
|
|
3181
3215
|
return s !== 1 && (i[s.toString()] = [new b(s, 1)]), r !== 1 && (i[r.toString()] = [new b(r, -1)]), i;
|
|
3182
3216
|
}
|
|
@@ -3243,7 +3277,7 @@ class B {
|
|
|
3243
3277
|
}
|
|
3244
3278
|
characteristic_polynom(t) {
|
|
3245
3279
|
return t ??= "k", this.clone().subtract(
|
|
3246
|
-
new B(this.dimension.rows).one().multiply(new
|
|
3280
|
+
new B(this.dimension.rows).one().multiply(new u(t))
|
|
3247
3281
|
).determinant();
|
|
3248
3282
|
}
|
|
3249
3283
|
cofactor(t, e) {
|
|
@@ -3253,7 +3287,7 @@ class B {
|
|
|
3253
3287
|
}), i.determinant().multiply((-1) ** (t + e));
|
|
3254
3288
|
}
|
|
3255
3289
|
get cols() {
|
|
3256
|
-
const t = Array.from({ length: this.dimension.cols }, () => Array.from({ length: this.dimension.rows }, () => new
|
|
3290
|
+
const t = Array.from({ length: this.dimension.cols }, () => Array.from({ length: this.dimension.rows }, () => new u()));
|
|
3257
3291
|
return this.forEach((e, i, s) => {
|
|
3258
3292
|
t[s][i] = e;
|
|
3259
3293
|
}), t;
|
|
@@ -3261,7 +3295,7 @@ class B {
|
|
|
3261
3295
|
determinant() {
|
|
3262
3296
|
if (!this.isSquare())
|
|
3263
3297
|
throw new Error("Matrix is not square");
|
|
3264
|
-
const t = new
|
|
3298
|
+
const t = new u();
|
|
3265
3299
|
return this.#i.length === 1 ? this.#i[0][0].clone() : (this.values[0].forEach((e, i) => {
|
|
3266
3300
|
const s = this.cofactor(0, i);
|
|
3267
3301
|
t.add(e.clone().multiply(s));
|
|
@@ -3284,14 +3318,14 @@ class B {
|
|
|
3284
3318
|
});
|
|
3285
3319
|
}
|
|
3286
3320
|
fromDimensions(t, e) {
|
|
3287
|
-
return this.#i = Array.from({ length: t }, () => Array.from({ length: e }, () => new
|
|
3321
|
+
return this.#i = Array.from({ length: t }, () => Array.from({ length: e }, () => new u())), this;
|
|
3288
3322
|
}
|
|
3289
3323
|
fromString(t) {
|
|
3290
3324
|
if (t.startsWith("((") && t.endsWith("))"))
|
|
3291
3325
|
return this.fromString(t.substring(1, t.length - 1));
|
|
3292
3326
|
const e = t.split("),(");
|
|
3293
3327
|
return this.#i = e.map((i, s) => s === 0 ? i.substring(1).split(",") : s === e.length - 1 ? i.substring(0, i.length - 1).split(",") : i.split(",")).map(
|
|
3294
|
-
(i) => i.map((s) => new
|
|
3328
|
+
(i) => i.map((s) => new u(s))
|
|
3295
3329
|
), this;
|
|
3296
3330
|
}
|
|
3297
3331
|
fromValues(t) {
|
|
@@ -3302,7 +3336,7 @@ class B {
|
|
|
3302
3336
|
return t.forEach((i) => {
|
|
3303
3337
|
const s = [];
|
|
3304
3338
|
i.forEach((r) => {
|
|
3305
|
-
s.push(new
|
|
3339
|
+
s.push(new u(r));
|
|
3306
3340
|
}), this.#i.push(s);
|
|
3307
3341
|
}), this;
|
|
3308
3342
|
}
|
|
@@ -3313,7 +3347,7 @@ class B {
|
|
|
3313
3347
|
throw new Error("Each vectors must be the same dimension");
|
|
3314
3348
|
return this.fromDimensions(t[0].dimension, t.length), t.forEach((i, s) => {
|
|
3315
3349
|
i.array.forEach((r, o) => {
|
|
3316
|
-
this.#i[o][s] = new
|
|
3350
|
+
this.#i[o][s] = new u(r);
|
|
3317
3351
|
});
|
|
3318
3352
|
}), this;
|
|
3319
3353
|
}
|
|
@@ -3352,8 +3386,8 @@ class B {
|
|
|
3352
3386
|
const { rows: e, cols: i } = this.dimension, s = Array.from({ length: e }, () => Array.from({ length: i }, () => {
|
|
3353
3387
|
}));
|
|
3354
3388
|
return this.#i.forEach((r, o) => {
|
|
3355
|
-
r.forEach((
|
|
3356
|
-
s[o][c] = t(
|
|
3389
|
+
r.forEach((a, c) => {
|
|
3390
|
+
s[o][c] = t(a, o, c);
|
|
3357
3391
|
});
|
|
3358
3392
|
}), s;
|
|
3359
3393
|
}
|
|
@@ -3363,9 +3397,9 @@ class B {
|
|
|
3363
3397
|
throw new Error("Cannot multiply a matrix with incompatibles dimensions");
|
|
3364
3398
|
const e = new B(this.dimension.rows, t.dimension.cols);
|
|
3365
3399
|
return e.forEach((i, s, r) => {
|
|
3366
|
-
const o = this.rows[s],
|
|
3400
|
+
const o = this.rows[s], a = t.cols[r], c = new u();
|
|
3367
3401
|
o.forEach((f, m) => {
|
|
3368
|
-
c.add(f.clone().multiply(
|
|
3402
|
+
c.add(f.clone().multiply(a[m]));
|
|
3369
3403
|
}), e.setValue(s, r, c);
|
|
3370
3404
|
}), this.#i = e.values, this;
|
|
3371
3405
|
}
|
|
@@ -3387,7 +3421,7 @@ class B {
|
|
|
3387
3421
|
return this.#e = !0, this;
|
|
3388
3422
|
}
|
|
3389
3423
|
pow(t) {
|
|
3390
|
-
return
|
|
3424
|
+
return rt(this, t);
|
|
3391
3425
|
}
|
|
3392
3426
|
reduce() {
|
|
3393
3427
|
throw new Error("Not yet implemented");
|
|
@@ -3399,7 +3433,7 @@ class B {
|
|
|
3399
3433
|
const { rows: s, cols: r } = this.dimension;
|
|
3400
3434
|
if (t < 0 || t >= s || e < 0 || e >= r)
|
|
3401
3435
|
throw new Error(`${t}x${e} is out of range (${s}x${r})`);
|
|
3402
|
-
return this.#i[t][e] = new
|
|
3436
|
+
return this.#i[t][e] = new u(i), this;
|
|
3403
3437
|
}
|
|
3404
3438
|
subtract(t) {
|
|
3405
3439
|
if (!this.canBeAdded(t))
|
|
@@ -3437,12 +3471,12 @@ function kt(n, t) {
|
|
|
3437
3471
|
);
|
|
3438
3472
|
}
|
|
3439
3473
|
function Mt(n, t) {
|
|
3440
|
-
return n.dimension !== t.dimension ? new
|
|
3474
|
+
return n.dimension !== t.dimension ? new h().invalid() : n.array.reduce(
|
|
3441
3475
|
(e, i, s) => e.add(i.clone().multiply(t.array[s])),
|
|
3442
|
-
new
|
|
3476
|
+
new h(0)
|
|
3443
3477
|
);
|
|
3444
3478
|
}
|
|
3445
|
-
function
|
|
3479
|
+
function jt(...n) {
|
|
3446
3480
|
if (n.some((t) => t.dimension !== n[0].dimension))
|
|
3447
3481
|
throw new Error("All vectors must have the same dimension");
|
|
3448
3482
|
if (n[0].dimension !== n.length)
|
|
@@ -3459,7 +3493,7 @@ class P {
|
|
|
3459
3493
|
#t = [];
|
|
3460
3494
|
#e;
|
|
3461
3495
|
constructor(...t) {
|
|
3462
|
-
this.#t = t.map((e) => new
|
|
3496
|
+
this.#t = t.map((e) => new h(e));
|
|
3463
3497
|
}
|
|
3464
3498
|
copy() {
|
|
3465
3499
|
return this.#t.map((t) => t.clone());
|
|
@@ -3476,7 +3510,7 @@ class P {
|
|
|
3476
3510
|
fromString(t) {
|
|
3477
3511
|
t.startsWith("(") && (t = t.substring(1)), t.endsWith(")") && (t = t.substring(0, t.length - 1));
|
|
3478
3512
|
const e = t.split(/[,;\s]/g).filter((i) => i.trim() !== "");
|
|
3479
|
-
return e.length < 2 ? this : (this.#t = e.map((i) => new
|
|
3513
|
+
return e.length < 2 ? this : (this.#t = e.map((i) => new h(i)), this);
|
|
3480
3514
|
}
|
|
3481
3515
|
get onChange() {
|
|
3482
3516
|
return this.#e;
|
|
@@ -3491,20 +3525,20 @@ class P {
|
|
|
3491
3525
|
this.#t = this.#t.slice(0, t);
|
|
3492
3526
|
else if (t > this.dimension)
|
|
3493
3527
|
for (let e = this.dimension; e < t; e++)
|
|
3494
|
-
this.#t.push(new
|
|
3528
|
+
this.#t.push(new h(0));
|
|
3495
3529
|
return this;
|
|
3496
3530
|
}
|
|
3497
3531
|
get x() {
|
|
3498
3532
|
return this.#t[0];
|
|
3499
3533
|
}
|
|
3500
3534
|
set x(t) {
|
|
3501
|
-
this.#t[0] = new
|
|
3535
|
+
this.#t[0] = new h(t), this.#e?.();
|
|
3502
3536
|
}
|
|
3503
3537
|
get y() {
|
|
3504
3538
|
return this.#t[1];
|
|
3505
3539
|
}
|
|
3506
3540
|
set y(t) {
|
|
3507
|
-
this.#t[1] = new
|
|
3541
|
+
this.#t[1] = new h(t), this.#e?.();
|
|
3508
3542
|
}
|
|
3509
3543
|
get z() {
|
|
3510
3544
|
if (this.dimension < 3)
|
|
@@ -3514,7 +3548,7 @@ class P {
|
|
|
3514
3548
|
set z(t) {
|
|
3515
3549
|
if (this.dimension < 3)
|
|
3516
3550
|
throw new Error("Vector is not 3D");
|
|
3517
|
-
this.#t[2] = new
|
|
3551
|
+
this.#t[2] = new h(t), this.#e?.();
|
|
3518
3552
|
}
|
|
3519
3553
|
zero = () => (this.#t.forEach((t) => t.zero()), this.#e?.(), this);
|
|
3520
3554
|
}
|
|
@@ -3532,7 +3566,7 @@ class w extends P {
|
|
|
3532
3566
|
if (t.length > 1) {
|
|
3533
3567
|
if (t.some((i) => i instanceof w))
|
|
3534
3568
|
throw new Error("Creating a point with multiple argument requires an input fraction");
|
|
3535
|
-
const e = t.map((i) => new
|
|
3569
|
+
const e = t.map((i) => new h(i));
|
|
3536
3570
|
if (e.some((i) => i.isNaN()))
|
|
3537
3571
|
throw new Error("The given values are not a valid point string (a,b): ");
|
|
3538
3572
|
this.array = e;
|
|
@@ -3553,7 +3587,7 @@ class w extends P {
|
|
|
3553
3587
|
throw new Error("The two points must have the same dimensions.");
|
|
3554
3588
|
const i = this.array.map((s, r) => t.array[r].clone().subtract(s)).reduce(
|
|
3555
3589
|
(s, r) => s.add(r.clone().pow(2)),
|
|
3556
|
-
new
|
|
3590
|
+
new h(0)
|
|
3557
3591
|
);
|
|
3558
3592
|
return new T().from(2, i).reduce();
|
|
3559
3593
|
}
|
|
@@ -3595,7 +3629,7 @@ class g extends P {
|
|
|
3595
3629
|
return this.array = i.array.map((s, r) => s.clone().subtract(e.array[r])), this;
|
|
3596
3630
|
}
|
|
3597
3631
|
}
|
|
3598
|
-
return this.array = t.map((e) => new
|
|
3632
|
+
return this.array = t.map((e) => new h(e)), this;
|
|
3599
3633
|
}
|
|
3600
3634
|
clone() {
|
|
3601
3635
|
return new g(...this.copy());
|
|
@@ -3628,7 +3662,7 @@ class g extends P {
|
|
|
3628
3662
|
}
|
|
3629
3663
|
// ------------------------------------------
|
|
3630
3664
|
// Creation / parsing functions
|
|
3631
|
-
divideByScalar = (t) => this.multiplyByScalar(new
|
|
3665
|
+
divideByScalar = (t) => this.multiplyByScalar(new h(t).inverse());
|
|
3632
3666
|
dot = (t) => Mt(this, t);
|
|
3633
3667
|
fromString(t) {
|
|
3634
3668
|
return t.startsWith("((") && t.endsWith("))") ? super.fromString(t.slice(1, -1)) : super.fromString(t);
|
|
@@ -3647,14 +3681,14 @@ class g extends P {
|
|
|
3647
3681
|
return this.array.every((t) => t.isZero());
|
|
3648
3682
|
}
|
|
3649
3683
|
multiplyByScalar = (t) => {
|
|
3650
|
-
const e = new
|
|
3684
|
+
const e = new h(t);
|
|
3651
3685
|
return this.array.forEach((i) => i.multiply(e)), this;
|
|
3652
3686
|
};
|
|
3653
3687
|
get norm() {
|
|
3654
3688
|
return Math.sqrt(this.normSquare.value);
|
|
3655
3689
|
}
|
|
3656
3690
|
get normSquare() {
|
|
3657
|
-
return this.array.reduce((t, e) => t.add(e.clone().pow(2)), new
|
|
3691
|
+
return this.array.reduce((t, e) => t.add(e.clone().pow(2)), new h(0));
|
|
3658
3692
|
}
|
|
3659
3693
|
normal = () => {
|
|
3660
3694
|
if (this.dimension >= 3)
|
|
@@ -3666,7 +3700,7 @@ class g extends P {
|
|
|
3666
3700
|
opposite = () => (this.array.forEach((t) => t.opposite()), this);
|
|
3667
3701
|
simplify = () => {
|
|
3668
3702
|
const t = x.lcm(...this.array.map((i) => i.denominator)), e = x.gcd(...this.array.map((i) => i.numerator));
|
|
3669
|
-
return this.multiplyByScalar(new
|
|
3703
|
+
return this.multiplyByScalar(new h(t, e)), this.x.isNegative() && this.opposite(), this;
|
|
3670
3704
|
};
|
|
3671
3705
|
subtract = (t) => this.add(t.clone().opposite());
|
|
3672
3706
|
translate(...t) {
|
|
@@ -3677,8 +3711,8 @@ class g extends P {
|
|
|
3677
3711
|
return t === 0 ? this : this.divideByScalar(t);
|
|
3678
3712
|
};
|
|
3679
3713
|
}
|
|
3680
|
-
var
|
|
3681
|
-
function
|
|
3714
|
+
var V = /* @__PURE__ */ ((n) => (n.None = "none", n.Parallel = "parallel", n.Perpendicular = "perpendicular", n.Tangent = "tangent", n))(V || {}), H = /* @__PURE__ */ ((n) => (n.None = "none", n.Parallel = "parallel", n.Perpendicular = "perpendicular", n.Tangent = "tangent", n))(H || {});
|
|
3715
|
+
function nt(n = 0.5) {
|
|
3682
3716
|
return Math.random() < n;
|
|
3683
3717
|
}
|
|
3684
3718
|
function O(n, t, e) {
|
|
@@ -3696,7 +3730,7 @@ function O(n, t, e) {
|
|
|
3696
3730
|
return i;
|
|
3697
3731
|
}
|
|
3698
3732
|
function A(n, t) {
|
|
3699
|
-
return t === !1 ?
|
|
3733
|
+
return t === !1 ? nt() ? O(1, n) : -O(1, n) : O(-n, n);
|
|
3700
3734
|
}
|
|
3701
3735
|
function Bt(n, t) {
|
|
3702
3736
|
const e = x.pythagoreanTripletsWithTarget(n).filter((i) => t === !0 || !i.includes(0));
|
|
@@ -3707,12 +3741,12 @@ function St(n) {
|
|
|
3707
3741
|
return n !== void 0 && (t = t.filter((e) => e < n)), W(t);
|
|
3708
3742
|
}
|
|
3709
3743
|
function It(n, t) {
|
|
3710
|
-
return t === void 0 && (t = 1), n.length <= 0 ? Object.values(n) :
|
|
3744
|
+
return t === void 0 && (t = 1), n.length <= 0 ? Object.values(n) : ot(n).slice(0, t);
|
|
3711
3745
|
}
|
|
3712
3746
|
function W(n) {
|
|
3713
3747
|
return n.length === 0 ? null : n[O(0, n.length - 1)];
|
|
3714
3748
|
}
|
|
3715
|
-
function
|
|
3749
|
+
function ot(n) {
|
|
3716
3750
|
const t = Object.values(n);
|
|
3717
3751
|
for (let e = t.length - 1; e > 0; e--) {
|
|
3718
3752
|
const i = Math.floor(Math.random() * (e + 1)), s = t[e];
|
|
@@ -3721,8 +3755,8 @@ function ht(n) {
|
|
|
3721
3755
|
return t;
|
|
3722
3756
|
}
|
|
3723
3757
|
class E {
|
|
3724
|
-
static PARALLEL =
|
|
3725
|
-
static PERPENDICULAR =
|
|
3758
|
+
static PARALLEL = V.Parallel;
|
|
3759
|
+
static PERPENDICULAR = V.Perpendicular;
|
|
3726
3760
|
#t;
|
|
3727
3761
|
// ax + by + c = 0
|
|
3728
3762
|
#e;
|
|
@@ -3738,7 +3772,7 @@ class E {
|
|
|
3738
3772
|
* @param values
|
|
3739
3773
|
*/
|
|
3740
3774
|
constructor(...t) {
|
|
3741
|
-
return this.#e = new
|
|
3775
|
+
return this.#e = new h().zero(), this.#i = new h().zero(), this.#s = new h().zero(), this.#t = new g(), this.#r = "lr", t.length > 0 && this.parse(...t), this;
|
|
3742
3776
|
}
|
|
3743
3777
|
// ------------------------------------------
|
|
3744
3778
|
/**
|
|
@@ -3768,7 +3802,7 @@ class E {
|
|
|
3768
3802
|
if (t[0] instanceof w && t[1] instanceof g)
|
|
3769
3803
|
return this.fromPointAndDirection(t[0], t[1]);
|
|
3770
3804
|
}
|
|
3771
|
-
return t.length === 3 && t.every((e) =>
|
|
3805
|
+
return t.length === 3 && t.every((e) => h.isFraction(e)) ? this.fromCoefficient(
|
|
3772
3806
|
t[0],
|
|
3773
3807
|
t[1],
|
|
3774
3808
|
t[2]
|
|
@@ -3783,13 +3817,13 @@ class E {
|
|
|
3783
3817
|
case 0:
|
|
3784
3818
|
return this.getEquation().reorder().tex;
|
|
3785
3819
|
case 2:
|
|
3786
|
-
return this.slope.isInfinity() ? "x=" + this.OA.x.tex : "y=" + new
|
|
3820
|
+
return this.slope.isInfinity() ? "x=" + this.OA.x.tex : "y=" + new u().parse("x", this.slope, this.height).tex;
|
|
3787
3821
|
case 3:
|
|
3788
3822
|
case 4: {
|
|
3789
3823
|
const e = this.d.clone().simplify();
|
|
3790
3824
|
return t === 3 ? `${g.asTex("x", "y")} = ${g.asTex(this.#t.x.tex, this.#t.y.tex)} + k\\cdot ${g.asTex(e.x.tex, e.y.tex)}` : `\\left\\{\\begin{aligned}
|
|
3791
|
-
x &= ${new
|
|
3792
|
-
y &= ${new
|
|
3825
|
+
x &= ${new u(this.#t.x).add(new p(e.x).multiply(new p("k"))).reorder("k", !0).tex}\\\\
|
|
3826
|
+
y &= ${new u(this.#t.y).add(new p(e.y).multiply(new p("k"))).reorder("k", !0).tex}
|
|
3793
3827
|
\\end{aligned}\\right.`;
|
|
3794
3828
|
}
|
|
3795
3829
|
default: {
|
|
@@ -3804,13 +3838,13 @@ class E {
|
|
|
3804
3838
|
case 0:
|
|
3805
3839
|
return this.getEquation().reorder().display;
|
|
3806
3840
|
case 2:
|
|
3807
|
-
return this.slope.isInfinity() ? "x=" + this.OA.x.display : "y=" + new
|
|
3841
|
+
return this.slope.isInfinity() ? "x=" + this.OA.x.display : "y=" + new u().parse("x", this.slope, this.height).display;
|
|
3808
3842
|
case 3: {
|
|
3809
3843
|
const e = this.d.clone().simplify();
|
|
3810
3844
|
return `((x,y))=((${this.#t.x.display},${this.#t.y.display}))+k((${e.x.display},${e.y.display}))`;
|
|
3811
3845
|
}
|
|
3812
3846
|
case 4: {
|
|
3813
|
-
const e = this.d.clone().simplify(), i = new
|
|
3847
|
+
const e = this.d.clone().simplify(), i = new u(this.#t.x).add(new p(e.x).multiply(new p("k"))).reorder("k", !0), s = new u(this.#t.y).add(new p(e.y).multiply(new p("k"))).reorder("k", !0);
|
|
3814
3848
|
return `{(x,=,${i.display}),(y,=,${s.display}):}`;
|
|
3815
3849
|
}
|
|
3816
3850
|
default: {
|
|
@@ -3878,13 +3912,13 @@ class E {
|
|
|
3878
3912
|
return i.isZero() ? new T(0) : new T().from(2, i.inverse(), e).reduce();
|
|
3879
3913
|
}
|
|
3880
3914
|
fromCoefficient(t, e, i) {
|
|
3881
|
-
this.#e = new
|
|
3915
|
+
this.#e = new h(t), this.#i = new h(e), this.#s = new h(i);
|
|
3882
3916
|
const s = [this.#e, this.#i, this.#s].every((o) => o.exact) ? x.lcm(this.#e.denominator, this.#i.denominator, this.#s.denominator) : 1;
|
|
3883
3917
|
if (s > 1 && (this.#e.multiply(s).reduce(), this.#i.multiply(s).reduce(), this.#s.multiply(s).reduce()), this.#i.isZero())
|
|
3884
3918
|
return this.#t = new g(this.#s.clone().divide(this.#e).opposite(), 0), this;
|
|
3885
3919
|
for (let o = 0; o < this.#i.value; o++) {
|
|
3886
|
-
const
|
|
3887
|
-
if (this.#t = new g(o,
|
|
3920
|
+
const a = this.#e.clone().divide(this.#i).multiply(o).subtract(this.#s.clone().divide(this.#i)).reduce();
|
|
3921
|
+
if (this.#t = new g(o, a), a.isRelative())
|
|
3888
3922
|
return this;
|
|
3889
3923
|
}
|
|
3890
3924
|
const r = this.#s.clone().divide(this.#i).opposite().reduce();
|
|
@@ -3912,8 +3946,8 @@ class E {
|
|
|
3912
3946
|
fromPointAndDirection(t, e) {
|
|
3913
3947
|
return this.#r = e.x.isPositive() ? "lr" : "rl", this.fromPointAndNormal(t, e.clone().normal());
|
|
3914
3948
|
}
|
|
3915
|
-
fromPointAndLine(t, e, i =
|
|
3916
|
-
return i ===
|
|
3949
|
+
fromPointAndLine(t, e, i = V.Parallel) {
|
|
3950
|
+
return i === V.Perpendicular ? this.fromPointAndNormal(t, e.director) : this.fromPointAndNormal(t, e.normal);
|
|
3917
3951
|
}
|
|
3918
3952
|
fromPointAndNormal = (t, e) => e.isZero() ? (console.warn("Normal vector is null."), this) : (this.fromCoefficient(
|
|
3919
3953
|
e.x,
|
|
@@ -3927,15 +3961,15 @@ class E {
|
|
|
3927
3961
|
}
|
|
3928
3962
|
// ------------------------------------------
|
|
3929
3963
|
getEquation() {
|
|
3930
|
-
return new v(new
|
|
3964
|
+
return new v(new u().parse("xy", this.#e, this.#i, this.#s), new u("0")).simplify();
|
|
3931
3965
|
}
|
|
3932
3966
|
getValueAtX = (t) => {
|
|
3933
|
-
const e = this.getEquation().isolate("y"), i = new
|
|
3934
|
-
return e instanceof v ? e.right.evaluate({ x: i }) : new
|
|
3967
|
+
const e = this.getEquation().isolate("y"), i = new h(t);
|
|
3968
|
+
return e instanceof v ? e.right.evaluate({ x: i }) : new h().invalid();
|
|
3935
3969
|
};
|
|
3936
3970
|
getValueAtY = (t) => {
|
|
3937
|
-
const e = this.getEquation().isolate("x"), i = new
|
|
3938
|
-
return e instanceof v ? e.right.evaluate({ y: i }) : new
|
|
3971
|
+
const e = this.getEquation().isolate("x"), i = new h(t);
|
|
3972
|
+
return e instanceof v ? e.right.evaluate({ y: i }) : new h().invalid();
|
|
3939
3973
|
};
|
|
3940
3974
|
get height() {
|
|
3941
3975
|
return this.#s.clone().opposite().divide(this.#i);
|
|
@@ -3949,7 +3983,7 @@ class E {
|
|
|
3949
3983
|
intersection = (t) => {
|
|
3950
3984
|
const e = new w();
|
|
3951
3985
|
let i = !1, s = !1;
|
|
3952
|
-
return this.#i.isZero() || t.b.isZero(), this.isParallelTo(t) ? (e.x = new
|
|
3986
|
+
return this.#i.isZero() || t.b.isZero(), this.isParallelTo(t) ? (e.x = new h().invalid(), e.y = new h().invalid(), i = !0) : this.isSameAs(t) ? (e.x = new h().invalid(), e.y = new h().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)))), {
|
|
3953
3987
|
point: e,
|
|
3954
3988
|
hasIntersection: !(i || s),
|
|
3955
3989
|
isParallel: i,
|
|
@@ -3998,7 +4032,7 @@ class E {
|
|
|
3998
4032
|
return this.#e.clone().opposite().divide(this.#i);
|
|
3999
4033
|
}
|
|
4000
4034
|
}
|
|
4001
|
-
class
|
|
4035
|
+
class L {
|
|
4002
4036
|
// This defines the triangle
|
|
4003
4037
|
#t = new w();
|
|
4004
4038
|
#e = new w();
|
|
@@ -4018,7 +4052,7 @@ class V {
|
|
|
4018
4052
|
return t.length > 0 && this.parse(...t), this;
|
|
4019
4053
|
}
|
|
4020
4054
|
parse = (...t) => {
|
|
4021
|
-
if (t.length === 1 && t[0] instanceof
|
|
4055
|
+
if (t.length === 1 && t[0] instanceof L)
|
|
4022
4056
|
return this.copy(t[0]);
|
|
4023
4057
|
if (t.length === 3) {
|
|
4024
4058
|
if (t.every((e) => typeof e == "string")) {
|
|
@@ -4031,7 +4065,7 @@ class V {
|
|
|
4031
4065
|
return this.fromPoints(t[0], t[1], t[2]);
|
|
4032
4066
|
}
|
|
4033
4067
|
if (t.length === 6) {
|
|
4034
|
-
const e = t.map((i) => new
|
|
4068
|
+
const e = t.map((i) => new h(i));
|
|
4035
4069
|
if (e.some((i) => i.isNaN()))
|
|
4036
4070
|
throw new Error("One of the values is not a valid number");
|
|
4037
4071
|
return this.fromCoordinates(e[0], e[1], e[2], e[3], e[4], e[5]);
|
|
@@ -4041,7 +4075,7 @@ class V {
|
|
|
4041
4075
|
/**
|
|
4042
4076
|
* Clone the Triangle class
|
|
4043
4077
|
*/
|
|
4044
|
-
clone = () => new
|
|
4078
|
+
clone = () => new L(
|
|
4045
4079
|
this.#t.clone(),
|
|
4046
4080
|
this.#e.clone(),
|
|
4047
4081
|
this.#i.clone()
|
|
@@ -4060,10 +4094,10 @@ class V {
|
|
|
4060
4094
|
this.#t = t, this.#t.onChange = () => this.reset(), this.reset();
|
|
4061
4095
|
}
|
|
4062
4096
|
get AB() {
|
|
4063
|
-
return this.#
|
|
4097
|
+
return this.#h("A", "B");
|
|
4064
4098
|
}
|
|
4065
4099
|
get AC() {
|
|
4066
|
-
return this.#
|
|
4100
|
+
return this.#h("A", "C");
|
|
4067
4101
|
}
|
|
4068
4102
|
get B() {
|
|
4069
4103
|
return this.#e;
|
|
@@ -4072,10 +4106,10 @@ class V {
|
|
|
4072
4106
|
this.#e = t, this.#e.onChange = () => this.reset(), this.reset();
|
|
4073
4107
|
}
|
|
4074
4108
|
get BA() {
|
|
4075
|
-
return this.#
|
|
4109
|
+
return this.#h("B", "A");
|
|
4076
4110
|
}
|
|
4077
4111
|
get BC() {
|
|
4078
|
-
return this.#
|
|
4112
|
+
return this.#h("B", "C");
|
|
4079
4113
|
}
|
|
4080
4114
|
get C() {
|
|
4081
4115
|
return this.#i;
|
|
@@ -4084,10 +4118,10 @@ class V {
|
|
|
4084
4118
|
this.#i = t, this.#i.onChange = () => this.reset(), this.reset();
|
|
4085
4119
|
}
|
|
4086
4120
|
get CA() {
|
|
4087
|
-
return this.#
|
|
4121
|
+
return this.#h("C", "A");
|
|
4088
4122
|
}
|
|
4089
4123
|
get CB() {
|
|
4090
|
-
return this.#
|
|
4124
|
+
return this.#h("C", "B");
|
|
4091
4125
|
}
|
|
4092
4126
|
get asDegree() {
|
|
4093
4127
|
return this.#n = !1, this;
|
|
@@ -4104,17 +4138,17 @@ class V {
|
|
|
4104
4138
|
}
|
|
4105
4139
|
fromLines(t, e, i) {
|
|
4106
4140
|
const s = new E(t).clone(), r = new E(e).clone(), o = new E(i).clone();
|
|
4107
|
-
let
|
|
4108
|
-
if (
|
|
4109
|
-
this.#e =
|
|
4141
|
+
let a = s.intersection(r);
|
|
4142
|
+
if (a.hasIntersection)
|
|
4143
|
+
this.#e = a.point;
|
|
4110
4144
|
else
|
|
4111
4145
|
return this.#s = !1, this;
|
|
4112
|
-
if (
|
|
4113
|
-
this.#i =
|
|
4146
|
+
if (a = r.intersection(o), a.hasIntersection)
|
|
4147
|
+
this.#i = a.point;
|
|
4114
4148
|
else
|
|
4115
4149
|
return this.#s = !1, this;
|
|
4116
|
-
if (
|
|
4117
|
-
this.#t =
|
|
4150
|
+
if (a = o.intersection(s), a.hasIntersection)
|
|
4151
|
+
this.#t = a.point;
|
|
4118
4152
|
else
|
|
4119
4153
|
return this.#s = !1, this;
|
|
4120
4154
|
return this.reset(), this.#r = { AB: s, AC: o, BC: r }, this;
|
|
@@ -4124,14 +4158,13 @@ class V {
|
|
|
4124
4158
|
}
|
|
4125
4159
|
getAngle(t) {
|
|
4126
4160
|
const e = this.BC.norm, i = this.AC.norm, s = this.AB.norm;
|
|
4127
|
-
return t === "A" ? this.#
|
|
4161
|
+
return t === "A" ? this.#c(e, i, s) : t === "C" ? this.#c(s, i, e) : this.#c(i, e, s);
|
|
4128
4162
|
}
|
|
4129
4163
|
getBisectors(t = !0) {
|
|
4130
|
-
if (
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
}
|
|
4134
|
-
return this.#o.bisectors;
|
|
4164
|
+
if (t && this.#o.bisectors) return this.#o.bisectors;
|
|
4165
|
+
if (!t && this.#o.externalBisectors) return this.#o.externalBisectors;
|
|
4166
|
+
const e = this.#a("A", t), i = this.#a("B", t), s = this.#a("C", t), r = e.intersection(i).point;
|
|
4167
|
+
return t ? this.#o.bisectors = { A: e, B: i, C: s, intersection: r } : this.#o.externalBisectors = { A: e, B: i, C: s, intersection: r }, { A: e, B: i, C: s, intersection: r };
|
|
4135
4168
|
}
|
|
4136
4169
|
getHeights() {
|
|
4137
4170
|
if (!this.#o.heights) {
|
|
@@ -4221,15 +4254,15 @@ class V {
|
|
|
4221
4254
|
bisectors: null
|
|
4222
4255
|
}, this;
|
|
4223
4256
|
}
|
|
4224
|
-
#
|
|
4257
|
+
#a(t, e = !0) {
|
|
4225
4258
|
const i = this.lines;
|
|
4226
4259
|
let s = new g(), r = new g(), o = new w();
|
|
4227
4260
|
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)
|
|
4228
4261
|
throw new Error(`The point ${t} does not exist`);
|
|
4229
|
-
const
|
|
4230
|
-
return new E().fromPointAndDirection(o,
|
|
4262
|
+
const a = e ? s.unit().add(r.unit()) : s.unit().subtract(r.unit());
|
|
4263
|
+
return new E().fromPointAndDirection(o, a);
|
|
4231
4264
|
}
|
|
4232
|
-
#
|
|
4265
|
+
#c(t, e, i) {
|
|
4233
4266
|
const s = (e ** 2 + i ** 2 - t ** 2) / (2 * e * i);
|
|
4234
4267
|
return this.#n ? Math.acos(s) : x.numberCorrection(Math.acos(s) * 180 / Math.PI);
|
|
4235
4268
|
}
|
|
@@ -4253,12 +4286,12 @@ class V {
|
|
|
4253
4286
|
* @param ptName1
|
|
4254
4287
|
* @param ptName2
|
|
4255
4288
|
*/
|
|
4256
|
-
#
|
|
4289
|
+
#h = (t, e) => new g(
|
|
4257
4290
|
this.#l(t),
|
|
4258
4291
|
this.#l(e)
|
|
4259
4292
|
);
|
|
4260
4293
|
}
|
|
4261
|
-
class
|
|
4294
|
+
class U {
|
|
4262
4295
|
#t = null;
|
|
4263
4296
|
#e = null;
|
|
4264
4297
|
#i = 1;
|
|
@@ -4267,14 +4300,14 @@ class j {
|
|
|
4267
4300
|
t.length > 0 && this.parse(...t);
|
|
4268
4301
|
}
|
|
4269
4302
|
parse(...t) {
|
|
4270
|
-
return typeof t[0] == "string" ? this.fromString(t[0]) : t[0] instanceof v ? this.fromEquation(t[0]) : t[0] instanceof
|
|
4303
|
+
return typeof t[0] == "string" ? this.fromString(t[0]) : t[0] instanceof v ? 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 h || typeof t[1] == "number") ? this.fromCenterRadius(
|
|
4271
4304
|
t[0],
|
|
4272
4305
|
t[1],
|
|
4273
4306
|
typeof t[2] == "boolean" ? t[2] : !1
|
|
4274
4307
|
) : this;
|
|
4275
4308
|
}
|
|
4276
4309
|
clone() {
|
|
4277
|
-
return new
|
|
4310
|
+
return new U().fromCenterRadius(
|
|
4278
4311
|
this.center.clone(),
|
|
4279
4312
|
this.squareRadius.clone(),
|
|
4280
4313
|
!0
|
|
@@ -4311,7 +4344,7 @@ class j {
|
|
|
4311
4344
|
return this.#t = t.clone(), this.#s = new g(this.#t, e).normSquare, this.#r(), this;
|
|
4312
4345
|
}
|
|
4313
4346
|
fromCenterRadius(t, e, i) {
|
|
4314
|
-
return this.#t = t.clone(), i ? this.#s = new
|
|
4347
|
+
return this.#t = t.clone(), i ? this.#s = new h(e) : this.#s = new h(e).pow(2), this.#r(), this;
|
|
4315
4348
|
}
|
|
4316
4349
|
fromEquation(t) {
|
|
4317
4350
|
if (t.moveLeft(), t.degree("x").value === 2 && t.degree("y").value === 2) {
|
|
@@ -4324,7 +4357,7 @@ class j {
|
|
|
4324
4357
|
return this;
|
|
4325
4358
|
}
|
|
4326
4359
|
fromPoints(t, e, i) {
|
|
4327
|
-
const s = new
|
|
4360
|
+
const s = new L(t, e, i);
|
|
4328
4361
|
if (!s.isValid || !s.remarquables)
|
|
4329
4362
|
return this.#n(), this;
|
|
4330
4363
|
const r = s.getMediators().c.clone(), o = s.getMediators().b.clone();
|
|
@@ -4341,7 +4374,7 @@ class j {
|
|
|
4341
4374
|
return t.forEach((i) => {
|
|
4342
4375
|
for (const s of [[1, 1], [-1, 1], [-1, -1], [1, -1]]) {
|
|
4343
4376
|
const r = this.center.x.clone().add(s[0] * i[0]), o = this.center.y.clone().add(s[1] * i[1]);
|
|
4344
|
-
e.every((
|
|
4377
|
+
e.every((a) => !a.isEqualXY(r, o)) && e.push(new w(r, o));
|
|
4345
4378
|
}
|
|
4346
4379
|
}), e;
|
|
4347
4380
|
}
|
|
@@ -4356,7 +4389,7 @@ class j {
|
|
|
4356
4389
|
*/
|
|
4357
4390
|
lineIntersection(t) {
|
|
4358
4391
|
if (this.#e === null) return [];
|
|
4359
|
-
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),
|
|
4392
|
+
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), a = 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, a);
|
|
4360
4393
|
if (c.length === 0) return [];
|
|
4361
4394
|
if (c.length === 1) {
|
|
4362
4395
|
const d = s.add(i.clone().multiplyByScalar(c[0].fraction));
|
|
@@ -4385,16 +4418,16 @@ class j {
|
|
|
4385
4418
|
return e - i > 1e-10 ? 0 : Math.abs(e - i) < 1e-10 ? 1 : 2;
|
|
4386
4419
|
}
|
|
4387
4420
|
setRadius(t, e) {
|
|
4388
|
-
return e ? this.#s = new
|
|
4421
|
+
return e ? this.#s = new h(t) : this.#s = new h(t).pow(2), this.#r(), this;
|
|
4389
4422
|
}
|
|
4390
4423
|
get squareRadius() {
|
|
4391
|
-
return this.#s?.clone() ?? new
|
|
4424
|
+
return this.#s?.clone() ?? new h(-1);
|
|
4392
4425
|
}
|
|
4393
|
-
tangents = (t) => t instanceof
|
|
4426
|
+
tangents = (t) => t instanceof h ? this.#c(t) : this.isPointOnCircle(t) ? this.#o(t) : this.#t !== null && this.#t.distanceTo(t).value > this.radius.value ? this.#a(t) : [];
|
|
4394
4427
|
#r() {
|
|
4395
4428
|
this.#e = new v(
|
|
4396
|
-
new
|
|
4397
|
-
new
|
|
4429
|
+
new u(`(x-(${this.center.x.display}))^2+(y-(${this.center.y.display}))^2`),
|
|
4430
|
+
new u(this.squareRadius.display)
|
|
4398
4431
|
).moveLeft();
|
|
4399
4432
|
}
|
|
4400
4433
|
#n() {
|
|
@@ -4404,17 +4437,17 @@ class j {
|
|
|
4404
4437
|
const e = new g(this.center, t);
|
|
4405
4438
|
return [new E().fromPointAndNormal(t, e)];
|
|
4406
4439
|
};
|
|
4407
|
-
#
|
|
4408
|
-
const e = this.center.x.clone().subtract(t.x), i = this.center.y.clone().subtract(t.y), s = new
|
|
4440
|
+
#a = (t) => {
|
|
4441
|
+
const e = this.center.x.clone().subtract(t.x), i = this.center.y.clone().subtract(t.y), s = new u("x"), r = new u("x^2+1");
|
|
4409
4442
|
return s.multiply(e).subtract(i).pow(2), r.multiply(this.squareRadius), new v(s, r).solve().map((c) => {
|
|
4410
4443
|
let f;
|
|
4411
4444
|
const m = new v("y", "x");
|
|
4412
4445
|
return c.exact ? (f = t.x.clone().opposite().multiply(c.fraction).add(t.y), m.right.multiply(c.fraction).add(f)) : (f = t.x.clone().opposite().multiply(c.value).add(t.y), m.right.multiply(c.value).add(f)), new E(m);
|
|
4413
4446
|
});
|
|
4414
4447
|
};
|
|
4415
|
-
#
|
|
4416
|
-
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),
|
|
4417
|
-
return [new E(e, i,
|
|
4448
|
+
#c = (t) => {
|
|
4449
|
+
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), a = 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());
|
|
4450
|
+
return [new E(e, i, a), new E(e, i, c)];
|
|
4418
4451
|
};
|
|
4419
4452
|
}
|
|
4420
4453
|
class X {
|
|
@@ -4432,19 +4465,19 @@ class X {
|
|
|
4432
4465
|
return {
|
|
4433
4466
|
parametric: `${g.asTex("x", "y", "z")} = ${g.asTex(this.#t.x.tex, this.#t.y.tex, this.#t.z.tex)} + k\\cdot ${g.asTex(this.#e.x.tex, this.#e.y.tex, this.#e.z.tex)}`,
|
|
4434
4467
|
system: `\\left\\{\\begin{aligned}
|
|
4435
|
-
x &= ${new
|
|
4436
|
-
y &= ${new
|
|
4437
|
-
z &= ${new
|
|
4468
|
+
x &= ${new u(this.#t.x).add(new p(this.#e.x).multiply(new p("k"))).reorder("k", !0).tex}\\\\
|
|
4469
|
+
y &= ${new u(this.#t.y).add(new p(this.#e.y).multiply(new p("k"))).reorder("k", !0).tex}\\\\
|
|
4470
|
+
z &= ${new u(this.#t.z).add(new p(this.#e.z).multiply(new p("k"))).reorder("k", !0).tex}
|
|
4438
4471
|
\\end{aligned}\\right.`,
|
|
4439
|
-
cartesian: `\\frac{ ${new
|
|
4472
|
+
cartesian: `\\frac{ ${new u("x", 1, this.#t.x.clone().opposite()).tex} }{ ${this.direction.x.tex} } = \\frac{ ${new u("y", 1, this.#t.y.clone().opposite()).tex} }{ ${this.direction.y.tex} } = \\frac{ ${new u("z", 1, this.#t.z.clone().opposite()).tex} }{ ${this.direction.z.tex} }`
|
|
4440
4473
|
};
|
|
4441
4474
|
}
|
|
4442
4475
|
get display() {
|
|
4443
|
-
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,
|
|
4476
|
+
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, a = s.z.display;
|
|
4444
4477
|
return {
|
|
4445
4478
|
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)}`,
|
|
4446
4479
|
system: "",
|
|
4447
|
-
cartesian: `(x-${t})/${r} = (y-${e})/${o} = (z-${i})/${
|
|
4480
|
+
cartesian: `(x-${t})/${r} = (y-${e})/${o} = (z-${i})/${a}`
|
|
4448
4481
|
};
|
|
4449
4482
|
}
|
|
4450
4483
|
get OA() {
|
|
@@ -4463,11 +4496,11 @@ class X {
|
|
|
4463
4496
|
return this.#e.clone();
|
|
4464
4497
|
}
|
|
4465
4498
|
distanceTo(t) {
|
|
4466
|
-
const e = new g(this.#t, t), i = this.direction, s = this.direction.normSquare, r = e.cross(i).normSquare, o = r.clone().divide(s),
|
|
4499
|
+
const e = new g(this.#t, t), i = this.direction, s = this.direction.normSquare, r = e.cross(i).normSquare, o = r.clone().divide(s), a = o.clone().sqrt();
|
|
4467
4500
|
return {
|
|
4468
4501
|
value: Math.sqrt(o.value),
|
|
4469
4502
|
fraction: o.clone().sqrt(),
|
|
4470
|
-
tex:
|
|
4503
|
+
tex: a.exact ? a.tex : `\\sqrt{${o.tex}}`
|
|
4471
4504
|
};
|
|
4472
4505
|
}
|
|
4473
4506
|
// ------------------------------------------
|
|
@@ -4499,7 +4532,7 @@ class X {
|
|
|
4499
4532
|
return this.#t.clone();
|
|
4500
4533
|
}
|
|
4501
4534
|
randomPoint = (t = 5) => {
|
|
4502
|
-
const e = this.#t.clone(), i = new
|
|
4535
|
+
const e = this.#t.clone(), i = new h(A(t, !1));
|
|
4503
4536
|
return new w(
|
|
4504
4537
|
e.x.clone().add(this.#e.x.clone().multiply(i)),
|
|
4505
4538
|
e.y.clone().add(this.#e.y.clone().multiply(i)),
|
|
@@ -4526,7 +4559,7 @@ class X {
|
|
|
4526
4559
|
throw new Error("Method not implemented.");
|
|
4527
4560
|
};
|
|
4528
4561
|
}
|
|
4529
|
-
class
|
|
4562
|
+
class tt {
|
|
4530
4563
|
#t = new g(0, 0, 1);
|
|
4531
4564
|
#e = new w(0, 0, 0);
|
|
4532
4565
|
constructor(t) {
|
|
@@ -4561,21 +4594,21 @@ class et {
|
|
|
4561
4594
|
}
|
|
4562
4595
|
get tex() {
|
|
4563
4596
|
return new v(
|
|
4564
|
-
new
|
|
4565
|
-
new
|
|
4597
|
+
new u("xyz", this.a, this.b, this.c, this.d),
|
|
4598
|
+
new u(0)
|
|
4566
4599
|
).reduce().tex;
|
|
4567
4600
|
}
|
|
4568
4601
|
get display() {
|
|
4569
4602
|
return new v(
|
|
4570
|
-
new
|
|
4571
|
-
new
|
|
4603
|
+
new u("xyz", this.a, this.b, this.c, this.d),
|
|
4604
|
+
new u(0)
|
|
4572
4605
|
).reduce().display;
|
|
4573
4606
|
}
|
|
4574
4607
|
get a() {
|
|
4575
4608
|
return this.#t.x;
|
|
4576
4609
|
}
|
|
4577
4610
|
angle(t, e, i) {
|
|
4578
|
-
if (t instanceof
|
|
4611
|
+
if (t instanceof tt)
|
|
4579
4612
|
return this.normal.angle(t.normal, e, i);
|
|
4580
4613
|
let s;
|
|
4581
4614
|
if (t instanceof g) {
|
|
@@ -4623,14 +4656,14 @@ class et {
|
|
|
4623
4656
|
this.#e = new w(t);
|
|
4624
4657
|
}
|
|
4625
4658
|
}
|
|
4626
|
-
var
|
|
4659
|
+
var ht = /* @__PURE__ */ ((n) => (n[n.INTERIOR = 0] = "INTERIOR", n[n.EXTERIOR = 1] = "EXTERIOR", n[n.SECANT = 2] = "SECANT", n[n.TANGENT_INSIDE = 3] = "TANGENT_INSIDE", n[n.TANGENT_OUTSIDE = 4] = "TANGENT_OUTSIDE", n[n.SUPERPOSED = 5] = "SUPERPOSED", n[n.CONCENTRIC = 6] = "CONCENTRIC", n))(ht || {});
|
|
4627
4660
|
class zt {
|
|
4628
4661
|
#t = void 0;
|
|
4629
4662
|
#e = void 0;
|
|
4630
4663
|
#i = void 0;
|
|
4631
4664
|
#s = 1;
|
|
4632
4665
|
constructor(t, e) {
|
|
4633
|
-
return t && e && (this.#t = t, this.#e = new
|
|
4666
|
+
return t && e && (this.#t = t, this.#e = new h(e).clone().pow(2), this.#n()), this;
|
|
4634
4667
|
}
|
|
4635
4668
|
fromEquation(t) {
|
|
4636
4669
|
const e = new v(t).moveLeft().reduce(), i = ["x", "y", "z"];
|
|
@@ -4696,7 +4729,7 @@ class zt {
|
|
|
4696
4729
|
if (this.center[s].isZero())
|
|
4697
4730
|
e.push(`${s}^2`);
|
|
4698
4731
|
else {
|
|
4699
|
-
const r = new
|
|
4732
|
+
const r = new u(s).subtract(this.center[s]);
|
|
4700
4733
|
e.push(
|
|
4701
4734
|
t ? `\\(${r.tex}\\)^2` : `(${r.display})^2`
|
|
4702
4735
|
);
|
|
@@ -4705,15 +4738,15 @@ class zt {
|
|
|
4705
4738
|
};
|
|
4706
4739
|
#n() {
|
|
4707
4740
|
this.#i = new v(
|
|
4708
|
-
new
|
|
4709
|
-
new
|
|
4741
|
+
new u("x").subtract(this.center.x).pow(2).add(
|
|
4742
|
+
new u("y").subtract(this.center.y).pow(2)
|
|
4710
4743
|
).add(
|
|
4711
|
-
new
|
|
4744
|
+
new u("z").subtract(this.center.z).pow(2)
|
|
4712
4745
|
),
|
|
4713
|
-
new
|
|
4746
|
+
new u(this.squareRadius)
|
|
4714
4747
|
).reduce();
|
|
4715
4748
|
}
|
|
4716
|
-
static RELATIVE_POSITION =
|
|
4749
|
+
static RELATIVE_POSITION = ht;
|
|
4717
4750
|
relativePosition = (t) => {
|
|
4718
4751
|
const e = this.center.distanceTo(t.center).value, i = this.radius.value, s = t.radius.value;
|
|
4719
4752
|
return e > i + s ? 1 : e === i + s ? 4 : e === 0 ? i === s ? 5 : 6 : e === Math.abs(i - s) ? 3 : e < Math.abs(i - s) ? 0 : 2;
|
|
@@ -4734,7 +4767,7 @@ function F(n) {
|
|
|
4734
4767
|
natural: !1
|
|
4735
4768
|
},
|
|
4736
4769
|
n
|
|
4737
|
-
), e = new
|
|
4770
|
+
), e = new h();
|
|
4738
4771
|
if (t.negative ? e.numerator = A(t.max, t.zero) : e.numerator = O(t.zero ? 0 : 1, t.max), t.natural)
|
|
4739
4772
|
e.denominator = 1;
|
|
4740
4773
|
else {
|
|
@@ -4744,7 +4777,7 @@ function F(n) {
|
|
|
4744
4777
|
}
|
|
4745
4778
|
return t.reduced ? e.reduce() : e;
|
|
4746
4779
|
}
|
|
4747
|
-
function
|
|
4780
|
+
function at(n) {
|
|
4748
4781
|
const t = Object.assign(
|
|
4749
4782
|
{
|
|
4750
4783
|
letters: "x",
|
|
@@ -4769,7 +4802,7 @@ function ct(n) {
|
|
|
4769
4802
|
e.setLetter(t.letters, t.degree);
|
|
4770
4803
|
return e;
|
|
4771
4804
|
}
|
|
4772
|
-
const
|
|
4805
|
+
const ct = {
|
|
4773
4806
|
letters: "x",
|
|
4774
4807
|
degree: 2,
|
|
4775
4808
|
fraction: !1,
|
|
@@ -4781,17 +4814,18 @@ const K = {
|
|
|
4781
4814
|
commonConstant: !1,
|
|
4782
4815
|
positive: !0
|
|
4783
4816
|
};
|
|
4784
|
-
function
|
|
4817
|
+
function et(n) {
|
|
4818
|
+
console.log(n);
|
|
4785
4819
|
const t = Object.assign(
|
|
4786
|
-
|
|
4820
|
+
ct,
|
|
4787
4821
|
n
|
|
4788
4822
|
);
|
|
4789
|
-
if (t.factorable) return Pt(
|
|
4790
|
-
const e = new
|
|
4823
|
+
if (console.log(">>>>"), console.log(t), t.factorable) return Pt(t);
|
|
4824
|
+
const e = new u().empty();
|
|
4791
4825
|
let i;
|
|
4792
4826
|
const s = t.degree ?? 2;
|
|
4793
4827
|
for (let r = s; r >= 0; r--)
|
|
4794
|
-
i =
|
|
4828
|
+
i = at({
|
|
4795
4829
|
letters: t.letters,
|
|
4796
4830
|
degree: r,
|
|
4797
4831
|
fraction: t.fraction,
|
|
@@ -4806,18 +4840,18 @@ function it(n) {
|
|
|
4806
4840
|
}
|
|
4807
4841
|
function Pt(n) {
|
|
4808
4842
|
const t = Object.assign(
|
|
4809
|
-
|
|
4843
|
+
ct,
|
|
4810
4844
|
n
|
|
4811
4845
|
), e = { ...t };
|
|
4812
4846
|
e.degree = 1, e.factorable = !1;
|
|
4813
4847
|
const i = [], s = t.degree ?? 2;
|
|
4814
4848
|
for (; i.length < s; )
|
|
4815
|
-
i.push(
|
|
4849
|
+
i.push(et(e));
|
|
4816
4850
|
if (n?.commonConstant !== !1) {
|
|
4817
4851
|
let r = A(10, !1);
|
|
4818
|
-
n?.commonConstant === !0 && (r === 1 || r === -1) && (r *= O(2, 5)), r !== 1 && r !== -1 && i.unshift(new
|
|
4852
|
+
n?.commonConstant === !0 && (r === 1 || r === -1) && (r *= O(2, 5)), r !== 1 && r !== -1 && i.unshift(new u(r));
|
|
4819
4853
|
}
|
|
4820
|
-
return
|
|
4854
|
+
return u.xMultiply(...i);
|
|
4821
4855
|
}
|
|
4822
4856
|
function Rt(n) {
|
|
4823
4857
|
const t = Object.assign(
|
|
@@ -4839,9 +4873,9 @@ function Rt(n) {
|
|
|
4839
4873
|
}
|
|
4840
4874
|
},
|
|
4841
4875
|
n
|
|
4842
|
-
), e = new
|
|
4876
|
+
), e = new u().one();
|
|
4843
4877
|
for (let i = 0; i < t.degree; i++) {
|
|
4844
|
-
const s =
|
|
4878
|
+
const s = et({
|
|
4845
4879
|
degree: 1,
|
|
4846
4880
|
unit: t.unit,
|
|
4847
4881
|
fraction: t.fraction,
|
|
@@ -4852,7 +4886,7 @@ function Rt(n) {
|
|
|
4852
4886
|
}
|
|
4853
4887
|
return new v(e, 0);
|
|
4854
4888
|
}
|
|
4855
|
-
function
|
|
4889
|
+
function K(n) {
|
|
4856
4890
|
const t = Object.assign(
|
|
4857
4891
|
{
|
|
4858
4892
|
axis: !0,
|
|
@@ -4861,7 +4895,7 @@ function J(n) {
|
|
|
4861
4895
|
quadrant: null
|
|
4862
4896
|
},
|
|
4863
4897
|
n
|
|
4864
|
-
), e = t.axis === "x", i = t.axis === "y", s = t.fraction ? F({ max: t.max, zero: e }) : new
|
|
4898
|
+
), e = t.axis === "x", i = t.axis === "y", s = t.fraction ? F({ max: t.max, zero: e }) : new h(A(t.max, e)), r = t.fraction ? F({ max: t.max, zero: i }) : new h(A(t.max, i));
|
|
4865
4899
|
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);
|
|
4866
4900
|
}
|
|
4867
4901
|
function Zt(n) {
|
|
@@ -4874,9 +4908,9 @@ function Zt(n) {
|
|
|
4874
4908
|
pointsOnCircle: 8
|
|
4875
4909
|
},
|
|
4876
4910
|
n
|
|
4877
|
-
), e =
|
|
4911
|
+
), e = K(t.center);
|
|
4878
4912
|
let i, s;
|
|
4879
|
-
return t.pointsOnCircle === 8 ? (i = O(1, 3), s = i ** 2 + (i + 1) ** 2) : s = O(1, 20), new
|
|
4913
|
+
return t.pointsOnCircle === 8 ? (i = O(1, 3), s = i ** 2 + (i + 1) ** 2) : s = O(1, 20), new U(e, s, !0);
|
|
4880
4914
|
}
|
|
4881
4915
|
function Dt(n) {
|
|
4882
4916
|
const t = Object.assign(
|
|
@@ -4892,7 +4926,7 @@ function Dt(n) {
|
|
|
4892
4926
|
e.x = A(10, t.allow?.vertical ?? !0), e.y = A(10, t.allow?.horizontal ?? !0);
|
|
4893
4927
|
return t.slope === 1 ? e.x.sign() !== e.y.sign() && e.y.opposite() : t.slope === -1 && e.x.sign() !== e.y.sign() && e.y.opposite(), new E().fromPointAndDirection(new g(t.A.x, t.A.y), e);
|
|
4894
4928
|
}
|
|
4895
|
-
function
|
|
4929
|
+
function Vt(n) {
|
|
4896
4930
|
const t = Object.assign(
|
|
4897
4931
|
{
|
|
4898
4932
|
A: {
|
|
@@ -4910,57 +4944,57 @@ function Lt(n) {
|
|
|
4910
4944
|
), e = new w(t.A.x, t.A.y, t.A.z), i = new g(t.direction.x, t.direction.y, t.direction.z);
|
|
4911
4945
|
return new X(e, i);
|
|
4912
4946
|
}
|
|
4913
|
-
const
|
|
4947
|
+
const Lt = {
|
|
4914
4948
|
equation: (n) => Rt(n),
|
|
4915
|
-
polynom: (n) =>
|
|
4916
|
-
monom: (n) =>
|
|
4949
|
+
polynom: (n) => et(n),
|
|
4950
|
+
monom: (n) => at(n),
|
|
4917
4951
|
fraction: (n) => F(n),
|
|
4918
4952
|
number: (n, t, e) => O(n, t, e),
|
|
4919
4953
|
numberSym: (n, t) => A(n, t),
|
|
4920
4954
|
prime: (n) => St(n),
|
|
4921
4955
|
triplet: (n, t) => Bt(n, t),
|
|
4922
|
-
bool: (n) =>
|
|
4956
|
+
bool: (n) => nt(n),
|
|
4923
4957
|
array: (n, t) => It(n, t),
|
|
4924
4958
|
item: (n) => W(n),
|
|
4925
|
-
shuffle: (n) =>
|
|
4959
|
+
shuffle: (n) => ot(n),
|
|
4926
4960
|
line: (n) => Dt(n),
|
|
4927
|
-
line3: (n) =>
|
|
4928
|
-
vector: (n) =>
|
|
4929
|
-
point: (n) => new w(
|
|
4961
|
+
line3: (n) => Vt(n),
|
|
4962
|
+
vector: (n) => K(n),
|
|
4963
|
+
point: (n) => new w(K(n)),
|
|
4930
4964
|
circle: (n) => Zt(n)
|
|
4931
4965
|
}, Ft = {
|
|
4932
4966
|
Numeric: x,
|
|
4933
|
-
Fraction:
|
|
4967
|
+
Fraction: h,
|
|
4934
4968
|
Root: T,
|
|
4935
4969
|
Monom: p,
|
|
4936
|
-
Polynom:
|
|
4970
|
+
Polynom: u,
|
|
4937
4971
|
Equation: v,
|
|
4938
4972
|
Matrix: B,
|
|
4939
4973
|
LinearSystem: z,
|
|
4940
4974
|
Factor: b,
|
|
4941
4975
|
PolyFactor: N,
|
|
4942
4976
|
LogicalSet: qt,
|
|
4943
|
-
Random:
|
|
4977
|
+
Random: Lt,
|
|
4944
4978
|
Geometry: {
|
|
4945
4979
|
Vector: g,
|
|
4946
4980
|
Point: w,
|
|
4947
4981
|
Line: E,
|
|
4948
|
-
Triangle:
|
|
4949
|
-
Circle:
|
|
4982
|
+
Triangle: L,
|
|
4983
|
+
Circle: U,
|
|
4950
4984
|
Line3: X,
|
|
4951
|
-
Plane3:
|
|
4985
|
+
Plane3: tt,
|
|
4952
4986
|
Sphere3: zt
|
|
4953
4987
|
},
|
|
4954
4988
|
NumExp: Ct
|
|
4955
4989
|
};
|
|
4956
4990
|
export {
|
|
4957
|
-
|
|
4991
|
+
U as Circle,
|
|
4958
4992
|
v as Equation,
|
|
4959
4993
|
R as EquationSolver,
|
|
4960
4994
|
D as FACTOR_DISPLAY,
|
|
4961
4995
|
xt as FRAC_TYPE,
|
|
4962
4996
|
b as Factor,
|
|
4963
|
-
|
|
4997
|
+
h as Fraction,
|
|
4964
4998
|
E as Line,
|
|
4965
4999
|
X as Line3,
|
|
4966
5000
|
z as LinearSystem,
|
|
@@ -4969,22 +5003,22 @@ export {
|
|
|
4969
5003
|
p as Monom,
|
|
4970
5004
|
Ct as NumExp,
|
|
4971
5005
|
x as Numeric,
|
|
4972
|
-
|
|
5006
|
+
tt as Plane3,
|
|
4973
5007
|
w as Point,
|
|
4974
5008
|
N as PolyFactor,
|
|
4975
|
-
|
|
4976
|
-
|
|
5009
|
+
u as Polynom,
|
|
5010
|
+
Lt as Random,
|
|
4977
5011
|
T as Root,
|
|
4978
|
-
|
|
5012
|
+
ht as SPHERE3_RELATIVE_POSITION,
|
|
4979
5013
|
C as Solution,
|
|
4980
5014
|
zt as Sphere3,
|
|
4981
|
-
|
|
4982
|
-
|
|
5015
|
+
Ut as TableOfSigns,
|
|
5016
|
+
L as Triangle,
|
|
4983
5017
|
g as Vector,
|
|
4984
5018
|
kt as areVectorsColinears,
|
|
4985
5019
|
$t as areVectorsEquals,
|
|
4986
5020
|
Ft as default,
|
|
4987
|
-
|
|
5021
|
+
jt as determinantFromVectors,
|
|
4988
5022
|
Mt as dotProduct
|
|
4989
5023
|
};
|
|
4990
5024
|
//# sourceMappingURL=pimath.js.map
|