pimath 0.0.24 → 0.0.28
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/dev/demo.css +3 -0
- package/dev/index.html +220 -54
- package/dev/pi.js +573 -216
- package/dev/pi.js.map +1 -1
- package/dist/pi.js +1 -1
- package/dist/pi.js.map +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/algebra.Equation.html +11 -13
- package/docs/classes/algebra.LinearSystem.html +1 -1
- package/docs/classes/algebra.Logicalset.html +3 -3
- package/docs/classes/algebra.Monom.html +50 -49
- package/docs/classes/algebra.Polynom.html +12 -25
- package/docs/classes/algebra.Rational.html +3 -3
- package/docs/classes/coefficients.Fraction.html +10 -6
- package/docs/classes/coefficients.Nthroot.html +3 -1
- package/docs/classes/geometry.Circle.html +3 -1
- package/docs/classes/geometry.Line.html +3 -1
- package/docs/classes/geometry.Point.html +1 -1
- package/docs/classes/geometry.Triangle.html +6 -6
- package/docs/classes/geometry.Vector.html +1 -1
- package/docs/classes/numeric.Numeric.html +5 -5
- package/docs/classes/shutingyard.Shutingyard.html +5 -5
- package/docs/index.html +1 -1
- package/docs/interfaces/geometry.remarquableLines.html +1 -1
- package/docs/modules/algebra.html +1 -1
- package/docs/modules/coefficients.html +1 -1
- package/docs/modules/geometry.html +1 -1
- package/docs/modules/numeric.html +1 -1
- package/docs/modules/random.Random.html +1 -1
- package/docs/modules/random.html +1 -1
- package/docs/modules/shutingyard.html +1 -1
- package/docs/modules.html +1 -1
- package/esm/main.js +2 -0
- package/esm/main.js.map +1 -1
- package/esm/maths/algebra/equation.d.ts +11 -5
- package/esm/maths/algebra/equation.js +159 -52
- package/esm/maths/algebra/equation.js.map +1 -1
- package/esm/maths/algebra/linearSystem.d.ts +3 -4
- package/esm/maths/algebra/linearSystem.js +2 -5
- package/esm/maths/algebra/linearSystem.js.map +1 -1
- package/esm/maths/algebra/logicalset.d.ts +2 -2
- package/esm/maths/algebra/logicalset.js +1 -1
- package/esm/maths/algebra/logicalset.js.map +1 -1
- package/esm/maths/algebra/monom.d.ts +5 -3
- package/esm/maths/algebra/monom.js +29 -2
- package/esm/maths/algebra/monom.js.map +1 -1
- package/esm/maths/algebra/polynom.d.ts +6 -6
- package/esm/maths/algebra/polynom.js +4 -4
- package/esm/maths/algebra/polynom.js.map +1 -1
- package/esm/maths/algebra/rational.d.ts +1 -1
- package/esm/maths/algebra/rational.js +2 -2
- package/esm/maths/algebra/rational.js.map +1 -1
- package/esm/maths/coefficients/fraction.d.ts +2 -2
- package/esm/maths/coefficients/fraction.js +1 -1
- package/esm/maths/coefficients/fraction.js.map +1 -1
- package/esm/maths/coefficients/nthroot.d.ts +1 -1
- package/esm/maths/coefficients/nthroot.js +4 -1
- package/esm/maths/coefficients/nthroot.js.map +1 -1
- package/esm/maths/geometry/circle.d.ts +12 -3
- package/esm/maths/geometry/circle.js +125 -39
- package/esm/maths/geometry/circle.js.map +1 -1
- package/esm/maths/geometry/line.d.ts +1 -2
- package/esm/maths/geometry/line.js +0 -3
- package/esm/maths/geometry/line.js.map +1 -1
- package/esm/maths/geometry/point.d.ts +3 -4
- package/esm/maths/geometry/point.js +18 -15
- package/esm/maths/geometry/point.js.map +1 -1
- package/esm/maths/geometry/triangle.d.ts +0 -1
- package/esm/maths/geometry/triangle.js +3 -4
- package/esm/maths/geometry/triangle.js.map +1 -1
- package/esm/maths/geometry/vector.js +2 -1
- package/esm/maths/geometry/vector.js.map +1 -1
- package/esm/maths/numexp.d.ts +16 -0
- package/esm/maths/numexp.js +116 -0
- package/esm/maths/numexp.js.map +1 -0
- package/esm/maths/random/rndFraction.js +4 -3
- package/esm/maths/random/rndFraction.js.map +1 -1
- package/esm/maths/random/rndMonom.d.ts +1 -1
- package/esm/maths/random/rndMonom.js +12 -7
- package/esm/maths/random/rndMonom.js.map +1 -1
- package/esm/maths/random/rndPolynom.js +8 -2
- package/esm/maths/random/rndPolynom.js.map +1 -1
- package/esm/maths/random/rndTypes.d.ts +3 -1
- package/esm/maths/shutingyard.d.ts +21 -4
- package/esm/maths/shutingyard.js +72 -74
- package/esm/maths/shutingyard.js.map +1 -1
- package/package.json +3 -5
- package/src/main.ts +2 -0
- package/src/maths/algebra/equation.ts +183 -73
- package/src/maths/algebra/linearSystem.ts +262 -265
- package/src/maths/algebra/logicalset.ts +3 -3
- package/src/maths/algebra/monom.ts +54 -35
- package/src/maths/algebra/polynom.ts +10 -10
- package/src/maths/algebra/rational.ts +1 -1
- package/src/maths/coefficients/fraction.ts +11 -7
- package/src/maths/coefficients/nthroot.ts +8 -1
- package/src/maths/geometry/circle.ts +160 -45
- package/src/maths/geometry/line.ts +1 -5
- package/src/maths/geometry/point.ts +25 -18
- package/src/maths/geometry/triangle.ts +3 -5
- package/src/maths/geometry/vector.ts +4 -3
- package/src/maths/numexp.ts +136 -0
- package/src/maths/random/rndFraction.ts +4 -3
- package/src/maths/random/rndMonom.ts +39 -35
- package/src/maths/random/rndPolynom.ts +13 -3
- package/src/maths/random/rndTypes.ts +4 -2
- package/src/maths/shutingyard.ts +144 -94
- package/tests/algebra/monom.test.ts +18 -4
- package/tests/algebra/polynom.test.ts +19 -4
- package/tests/geometry/circle.test.ts +28 -0
- package/tests/shutingyard.test.ts +3 -3
- package/tsconfig.json +4 -1
- package/typedoc.katex.js +11 -0
- package/docs/classes/algebra.Algebra.Equation.html +0 -26
- package/docs/classes/algebra.Algebra.LinearSystem.html +0 -1
- package/docs/classes/algebra.Algebra.LogicalSet.html +0 -3
- package/docs/classes/algebra.Algebra.Monom.html +0 -111
- package/docs/classes/algebra.Algebra.Polynom.html +0 -36
- package/docs/classes/algebra.Algebra.Rational.html +0 -2
- package/docs/classes/geometry.Geometry.Circle.html +0 -1
- package/docs/classes/geometry.Geometry.Line.html +0 -1
- package/docs/classes/geometry.Geometry.Point.html +0 -1
- package/docs/classes/geometry.Geometry.Triangle.html +0 -9
- package/docs/classes/geometry.Geometry.Vector.html +0 -1
- package/docs/modules/algebra.Algebra.html +0 -1
- package/docs/modules/geometry.Geometry.html +0 -1
- package/src/maths/algebra/monom_bck.backup +0 -746
package/dev/pi.js
CHANGED
|
@@ -14,7 +14,6 @@ exports.Equation = void 0;
|
|
|
14
14
|
const polynom_1 = __webpack_require__(/*! ./polynom */ "./src/maths/algebra/polynom.ts");
|
|
15
15
|
const numeric_1 = __webpack_require__(/*! ../numeric */ "./src/maths/numeric.ts");
|
|
16
16
|
const coefficients_1 = __webpack_require__(/*! ../coefficients */ "./src/maths/coefficients/index.ts");
|
|
17
|
-
const coefficients_2 = __webpack_require__(/*! ../coefficients */ "./src/maths/coefficients/index.ts");
|
|
18
17
|
class Equation {
|
|
19
18
|
_left;
|
|
20
19
|
_right;
|
|
@@ -28,16 +27,26 @@ class Equation {
|
|
|
28
27
|
this._right = new polynom_1.Polynom().zero();
|
|
29
28
|
this._sign = '=';
|
|
30
29
|
if (equations.length === 1) {
|
|
31
|
-
if (equations[0]
|
|
30
|
+
if (equations[0] instanceof Equation) {
|
|
32
31
|
return equations[0].clone();
|
|
33
32
|
}
|
|
34
|
-
else {
|
|
33
|
+
else if (typeof equations[0] === 'string') {
|
|
35
34
|
this.parse(equations[0]);
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
37
|
else if (equations.length === 2) {
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
if (equations[0] instanceof polynom_1.Polynom) {
|
|
39
|
+
this.left = equations[0].clone();
|
|
40
|
+
}
|
|
41
|
+
else if (typeof equations[0] === 'string') {
|
|
42
|
+
this.left = new polynom_1.Polynom(equations[0]);
|
|
43
|
+
}
|
|
44
|
+
if (equations[1] instanceof polynom_1.Polynom) {
|
|
45
|
+
this.right = equations[1].clone();
|
|
46
|
+
}
|
|
47
|
+
else if (typeof equations[1] === 'string') {
|
|
48
|
+
this.right = new polynom_1.Polynom(equations[1]);
|
|
49
|
+
}
|
|
41
50
|
}
|
|
42
51
|
else {
|
|
43
52
|
return this;
|
|
@@ -53,24 +62,24 @@ class Equation {
|
|
|
53
62
|
get solution() {
|
|
54
63
|
if (this._solutions.length === 1
|
|
55
64
|
&&
|
|
56
|
-
(this._solutions[0] === this._real
|
|
57
|
-
|| this._solutions[0] === this._varnothing
|
|
58
|
-
|| this._solutions[0].includes('\\left'))) {
|
|
65
|
+
(this._solutions[0].tex === this._real
|
|
66
|
+
|| this._solutions[0].tex === this._varnothing
|
|
67
|
+
|| this._solutions[0].tex.includes('\\left'))) {
|
|
59
68
|
return `S = ${this._solutions[0]}`;
|
|
60
69
|
}
|
|
61
|
-
return `S = \\left{ ${this._solutions.join(';')} \\right}`;
|
|
70
|
+
return `S = \\left{ ${this._solutions.map(x => x.tex).join(';')} \\right}`;
|
|
62
71
|
}
|
|
63
72
|
get isReal() {
|
|
64
73
|
if (this._solutions === undefined) {
|
|
65
74
|
this.solve();
|
|
66
75
|
}
|
|
67
|
-
return this._solutions[0] === this._real;
|
|
76
|
+
return this._solutions[0].tex === this._real;
|
|
68
77
|
}
|
|
69
78
|
get isVarnothing() {
|
|
70
79
|
if (this._solutions === undefined) {
|
|
71
80
|
this.solve();
|
|
72
81
|
}
|
|
73
|
-
return this._solutions[0] === this._varnothing;
|
|
82
|
+
return this._solutions[0].tex === this._varnothing;
|
|
74
83
|
}
|
|
75
84
|
get signAsTex() {
|
|
76
85
|
if (this._sign === '>=' || this._sign === '=>' || this._sign === 'geq') {
|
|
@@ -310,19 +319,19 @@ class Equation {
|
|
|
310
319
|
letters = () => {
|
|
311
320
|
return [...new Set([...this._left.letters(), ...this._right.letters()])];
|
|
312
321
|
};
|
|
313
|
-
solve = (
|
|
322
|
+
solve = () => {
|
|
314
323
|
this._solutions = [];
|
|
315
324
|
this._polynom = this._left.clone().subtract(this._right);
|
|
316
|
-
switch (this._polynom.degree(
|
|
325
|
+
switch (this._polynom.degree().value) {
|
|
317
326
|
case 0:
|
|
318
327
|
case 1:
|
|
319
|
-
this._solveDegree1(
|
|
328
|
+
this._solveDegree1();
|
|
320
329
|
break;
|
|
321
330
|
case 2:
|
|
322
|
-
this._solveDegree2(
|
|
331
|
+
this._solveDegree2();
|
|
323
332
|
break;
|
|
324
333
|
default:
|
|
325
|
-
this._solveDegree3plus(
|
|
334
|
+
this._solveDegree3plus();
|
|
326
335
|
}
|
|
327
336
|
return this;
|
|
328
337
|
};
|
|
@@ -347,19 +356,31 @@ class Equation {
|
|
|
347
356
|
}
|
|
348
357
|
};
|
|
349
358
|
_solveDegree1 = (letter) => {
|
|
350
|
-
const m1 = this._polynom.monomByDegree(1, letter).coefficient, m0 = this._polynom.monomByDegree(0, letter).coefficient, v = m0.clone().opposed().divide(m1)
|
|
359
|
+
const m1 = this._polynom.monomByDegree(1, letter).coefficient, m0 = this._polynom.monomByDegree(0, letter).coefficient, v = m0.clone().opposed().divide(m1);
|
|
351
360
|
let s;
|
|
352
361
|
if (this.isStrictEqual()) {
|
|
353
362
|
if (m1.value === 0) {
|
|
354
363
|
if (m0.value === 0) {
|
|
355
|
-
this._solutions = [
|
|
364
|
+
this._solutions = [{
|
|
365
|
+
tex: this._real,
|
|
366
|
+
value: NaN,
|
|
367
|
+
exact: false
|
|
368
|
+
}];
|
|
356
369
|
}
|
|
357
370
|
else {
|
|
358
|
-
this._solutions = [
|
|
371
|
+
this._solutions = [{
|
|
372
|
+
tex: this._varnothing,
|
|
373
|
+
value: NaN,
|
|
374
|
+
exact: false
|
|
375
|
+
}];
|
|
359
376
|
}
|
|
360
377
|
}
|
|
361
378
|
else {
|
|
362
|
-
this._solutions = [
|
|
379
|
+
this._solutions = [{
|
|
380
|
+
tex: v.display,
|
|
381
|
+
value: v.value,
|
|
382
|
+
exact: v
|
|
383
|
+
}];
|
|
363
384
|
}
|
|
364
385
|
}
|
|
365
386
|
else {
|
|
@@ -384,7 +405,11 @@ class Equation {
|
|
|
384
405
|
s = `\\left\\]-\\infty;${v} \\right\\${this.isAlsoEqual() ? '\\]' : '\\['}`;
|
|
385
406
|
}
|
|
386
407
|
}
|
|
387
|
-
this._solutions = [
|
|
408
|
+
this._solutions = [{
|
|
409
|
+
tex: s,
|
|
410
|
+
value: NaN,
|
|
411
|
+
exact: false
|
|
412
|
+
}];
|
|
388
413
|
}
|
|
389
414
|
return this._solutions;
|
|
390
415
|
};
|
|
@@ -396,87 +421,161 @@ class Equation {
|
|
|
396
421
|
realX2 = (-b + Math.sqrt(delta)) / (2 * a);
|
|
397
422
|
if (delta > 1.0e5) {
|
|
398
423
|
this._solutions = [
|
|
399
|
-
|
|
400
|
-
|
|
424
|
+
{
|
|
425
|
+
tex: ((-b - Math.sqrt(delta)) / (2 * a)).toFixed(5),
|
|
426
|
+
value: realX1,
|
|
427
|
+
exact: false
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
tex: ((-b + Math.sqrt(delta)) / (2 * a)).toFixed(5),
|
|
431
|
+
value: realX2,
|
|
432
|
+
exact: false
|
|
433
|
+
}
|
|
401
434
|
];
|
|
402
435
|
}
|
|
403
436
|
else {
|
|
404
|
-
nthDelta = new
|
|
437
|
+
nthDelta = new coefficients_1.Nthroot(delta).reduce();
|
|
405
438
|
if (nthDelta.hasRadical()) {
|
|
406
439
|
let gcd = numeric_1.Numeric.gcd(b, 2 * a, nthDelta.coefficient);
|
|
407
440
|
nthDelta.coefficient = nthDelta.coefficient / gcd;
|
|
408
441
|
if (b !== 0) {
|
|
409
442
|
if (2 * a / gcd === 1) {
|
|
410
443
|
this._solutions = [
|
|
411
|
-
|
|
412
|
-
|
|
444
|
+
{
|
|
445
|
+
tex: `${-b / gcd} - ${nthDelta.tex}`,
|
|
446
|
+
value: realX1,
|
|
447
|
+
exact: false
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
tex: `${-b / gcd} + ${nthDelta.tex}`,
|
|
451
|
+
value: realX2,
|
|
452
|
+
exact: false
|
|
453
|
+
},
|
|
413
454
|
];
|
|
414
455
|
}
|
|
415
456
|
else {
|
|
416
457
|
this._solutions = [
|
|
417
|
-
|
|
418
|
-
|
|
458
|
+
{
|
|
459
|
+
tex: `\\dfrac{${-b / gcd} - ${nthDelta.tex} }{ ${2 * a / gcd} }`,
|
|
460
|
+
value: realX1,
|
|
461
|
+
exact: false
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
tex: `\\dfrac{${-b / gcd} + ${nthDelta.tex} }{ ${2 * a / gcd} }`,
|
|
465
|
+
value: realX2,
|
|
466
|
+
exact: false
|
|
467
|
+
},
|
|
419
468
|
];
|
|
420
469
|
}
|
|
421
470
|
}
|
|
422
471
|
else {
|
|
423
472
|
if (2 * a / gcd === 1) {
|
|
424
473
|
this._solutions = [
|
|
425
|
-
|
|
426
|
-
|
|
474
|
+
{
|
|
475
|
+
tex: `- ${nthDelta.tex}`,
|
|
476
|
+
value: realX1,
|
|
477
|
+
exact: false
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
tex: `${nthDelta.tex}`,
|
|
481
|
+
value: realX2,
|
|
482
|
+
exact: false
|
|
483
|
+
},
|
|
427
484
|
];
|
|
428
485
|
}
|
|
429
486
|
else {
|
|
430
487
|
this._solutions = [
|
|
431
|
-
|
|
432
|
-
|
|
488
|
+
{
|
|
489
|
+
tex: `\\dfrac{- ${nthDelta.tex} }{ ${2 * a / gcd} }`,
|
|
490
|
+
value: realX1,
|
|
491
|
+
exact: false
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
tex: `\\dfrac{${nthDelta.tex} }{ ${2 * a / gcd} }`,
|
|
495
|
+
value: realX2,
|
|
496
|
+
exact: false
|
|
497
|
+
},
|
|
433
498
|
];
|
|
434
499
|
}
|
|
435
500
|
}
|
|
436
501
|
}
|
|
437
502
|
else {
|
|
503
|
+
const S1 = new coefficients_1.Fraction(-b - nthDelta.coefficient, 2 * a).reduce(), S2 = new coefficients_1.Fraction(-b + nthDelta.coefficient, 2 * a).reduce();
|
|
438
504
|
this._solutions = [
|
|
439
|
-
|
|
440
|
-
|
|
505
|
+
{
|
|
506
|
+
tex: S1.dfrac,
|
|
507
|
+
value: realX1,
|
|
508
|
+
exact: S1
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
tex: S2.dfrac,
|
|
512
|
+
value: realX2,
|
|
513
|
+
exact: S2
|
|
514
|
+
}
|
|
441
515
|
];
|
|
442
516
|
}
|
|
443
517
|
}
|
|
444
518
|
}
|
|
445
519
|
else if (delta === 0) {
|
|
446
|
-
|
|
520
|
+
const sol = new coefficients_1.Fraction(-b, 2 * a).reduce();
|
|
521
|
+
this._solutions = [{
|
|
522
|
+
tex: sol.dfrac,
|
|
523
|
+
value: sol.value,
|
|
524
|
+
exact: sol
|
|
525
|
+
}];
|
|
447
526
|
}
|
|
448
527
|
else {
|
|
449
|
-
this._solutions = [
|
|
528
|
+
this._solutions = [{
|
|
529
|
+
tex: this._varnothing,
|
|
530
|
+
value: NaN,
|
|
531
|
+
exact: false
|
|
532
|
+
}];
|
|
450
533
|
}
|
|
451
534
|
if (!this.isStrictEqual()) {
|
|
452
535
|
if (this._solutions.length === 2) {
|
|
453
|
-
sX1 = (realX1 < realX2) ? this._solutions[0] : this._solutions[1];
|
|
454
|
-
sX2 = (realX1 < realX2) ? this._solutions[1] : this._solutions[0];
|
|
536
|
+
sX1 = (realX1 < realX2) ? this._solutions[0].tex : this._solutions[1].tex;
|
|
537
|
+
sX2 = (realX1 < realX2) ? this._solutions[1].tex : this._solutions[0].tex;
|
|
455
538
|
if ((this.isGreater() && aF.sign() === 1) || (!this.isGreater() && aF.sign() === -1)) {
|
|
456
|
-
this._solutions = [
|
|
457
|
-
|
|
539
|
+
this._solutions = [{
|
|
540
|
+
tex: `\\left]-\\infty ; ${sX1}\\right${this.isAlsoEqual() ? ']' : '['} \\cup \\left${this.isAlsoEqual() ? '[' : ']'}${sX2};+\\infty\\right[`,
|
|
541
|
+
value: NaN,
|
|
542
|
+
exact: false
|
|
543
|
+
}
|
|
458
544
|
];
|
|
459
545
|
}
|
|
460
546
|
else {
|
|
461
|
-
this._solutions = [
|
|
462
|
-
|
|
463
|
-
|
|
547
|
+
this._solutions = [{
|
|
548
|
+
tex: `\\left${this.isAlsoEqual() ? '[' : ']'}${sX1} ; ${sX2}\\right${this.isAlsoEqual() ? ']' : '['}`,
|
|
549
|
+
value: NaN,
|
|
550
|
+
exact: false
|
|
551
|
+
}];
|
|
464
552
|
}
|
|
465
553
|
}
|
|
466
|
-
else if (this._solutions.length === 1 && this._solutions[0] !== this._varnothing) {
|
|
554
|
+
else if (this._solutions.length === 1 && this._solutions[0].tex !== this._varnothing) {
|
|
467
555
|
if (!this.isAlsoEqual()) {
|
|
468
556
|
if ((this.isGreater() && aF.sign() === 1) || (!this.isGreater() && aF.sign() === -1)) {
|
|
469
|
-
this._solutions = [
|
|
470
|
-
|
|
557
|
+
this._solutions = [{
|
|
558
|
+
tex: `\\left]-\\infty ; ${this._solutions[0].tex}\\right[ \\cup \\left]${this._solutions[0].tex};+\\infty\\right[`,
|
|
559
|
+
value: NaN,
|
|
560
|
+
exact: false
|
|
561
|
+
}
|
|
471
562
|
];
|
|
472
563
|
}
|
|
473
564
|
else {
|
|
474
|
-
this._solutions = [
|
|
565
|
+
this._solutions = [{
|
|
566
|
+
tex: this._varnothing,
|
|
567
|
+
value: NaN,
|
|
568
|
+
exact: false
|
|
569
|
+
}];
|
|
475
570
|
}
|
|
476
571
|
}
|
|
477
572
|
else {
|
|
478
573
|
if ((this.isGreater() && aF.sign() === 1) || (!this.isGreater() && aF.sign() === -1)) {
|
|
479
|
-
this._solutions = [
|
|
574
|
+
this._solutions = [{
|
|
575
|
+
tex: this._real,
|
|
576
|
+
value: NaN,
|
|
577
|
+
exact: false
|
|
578
|
+
}];
|
|
480
579
|
}
|
|
481
580
|
else {
|
|
482
581
|
}
|
|
@@ -484,17 +583,25 @@ class Equation {
|
|
|
484
583
|
}
|
|
485
584
|
else {
|
|
486
585
|
if (this.isGreater()) {
|
|
487
|
-
this._solutions = [
|
|
586
|
+
this._solutions = [{
|
|
587
|
+
tex: aF.sign() === 1 ? this._real : this._varnothing,
|
|
588
|
+
value: NaN,
|
|
589
|
+
exact: false
|
|
590
|
+
}];
|
|
488
591
|
}
|
|
489
592
|
else {
|
|
490
|
-
this._solutions = [
|
|
593
|
+
this._solutions = [{
|
|
594
|
+
tex: aF.sign() === -1 ? this._real : this._varnothing,
|
|
595
|
+
value: NaN,
|
|
596
|
+
exact: false
|
|
597
|
+
}];
|
|
491
598
|
}
|
|
492
599
|
}
|
|
493
600
|
}
|
|
494
601
|
return this._solutions;
|
|
495
602
|
};
|
|
496
|
-
_solveDegree3plus = (
|
|
497
|
-
this._solutions = [
|
|
603
|
+
_solveDegree3plus = () => {
|
|
604
|
+
this._solutions = [{ tex: 'solve x - not yet handled', value: NaN, exact: false }];
|
|
498
605
|
return this._solutions;
|
|
499
606
|
};
|
|
500
607
|
}
|
|
@@ -557,9 +664,6 @@ class LinearSystem {
|
|
|
557
664
|
}
|
|
558
665
|
return this;
|
|
559
666
|
}
|
|
560
|
-
get isLinearSystem() {
|
|
561
|
-
return true;
|
|
562
|
-
}
|
|
563
667
|
get equations() {
|
|
564
668
|
return this._equations;
|
|
565
669
|
}
|
|
@@ -605,7 +709,7 @@ class LinearSystem {
|
|
|
605
709
|
}
|
|
606
710
|
return `\\left\\{\\begin{array}{${"r".repeat(letters.length)}cl}${equArray.join('\\\\\ ')}\\end{array}\\right.`;
|
|
607
711
|
}
|
|
608
|
-
get
|
|
712
|
+
get solution() {
|
|
609
713
|
let tex = [];
|
|
610
714
|
if (this._solutions === undefined) {
|
|
611
715
|
this.solve();
|
|
@@ -732,7 +836,7 @@ class LinearSystem {
|
|
|
732
836
|
let E = this._resolutionSteps[this._resolutionSteps.length - 1].equations[0];
|
|
733
837
|
E.solve();
|
|
734
838
|
return {
|
|
735
|
-
value: new coefficients_1.Fraction(E.solutions[0]),
|
|
839
|
+
value: new coefficients_1.Fraction(E.solutions[0].value),
|
|
736
840
|
isReal: E.isReal,
|
|
737
841
|
isVarnothing: E.isVarnothing
|
|
738
842
|
};
|
|
@@ -774,7 +878,7 @@ class Logicalset {
|
|
|
774
878
|
}
|
|
775
879
|
;
|
|
776
880
|
parse = (value) => {
|
|
777
|
-
this._rpn = new shutingyard_1.Shutingyard(
|
|
881
|
+
this._rpn = new shutingyard_1.Shutingyard(shutingyard_1.ShutingyardMode.SET).parse(value).rpn;
|
|
778
882
|
return this;
|
|
779
883
|
};
|
|
780
884
|
evaluate(tokenSets, reference) {
|
|
@@ -932,7 +1036,7 @@ class Monom {
|
|
|
932
1036
|
return this._coefficient;
|
|
933
1037
|
}
|
|
934
1038
|
set coefficient(F) {
|
|
935
|
-
this._coefficient = F;
|
|
1039
|
+
this._coefficient = new coefficients_1.Fraction(F);
|
|
936
1040
|
}
|
|
937
1041
|
get literal() {
|
|
938
1042
|
return this._literal;
|
|
@@ -1071,6 +1175,12 @@ class Monom {
|
|
|
1071
1175
|
let d = this.display;
|
|
1072
1176
|
return (d[0] !== '-' ? '+' : '') + d;
|
|
1073
1177
|
}
|
|
1178
|
+
get texWithSign() {
|
|
1179
|
+
if (this.coefficient.isStrictlyPositive()) {
|
|
1180
|
+
return '+' + this.tex;
|
|
1181
|
+
}
|
|
1182
|
+
return this.tex;
|
|
1183
|
+
}
|
|
1074
1184
|
get tex() {
|
|
1075
1185
|
let L = '', letters = Object.keys(this._literal).sort();
|
|
1076
1186
|
for (let letter of letters) {
|
|
@@ -1105,7 +1215,21 @@ class Monom {
|
|
|
1105
1215
|
}
|
|
1106
1216
|
}
|
|
1107
1217
|
parse = (inputStr) => {
|
|
1108
|
-
|
|
1218
|
+
if (typeof inputStr === 'string') {
|
|
1219
|
+
this._shutingYardToReducedMonom(inputStr);
|
|
1220
|
+
}
|
|
1221
|
+
else if (typeof inputStr === 'number') {
|
|
1222
|
+
this._coefficient = new coefficients_1.Fraction(inputStr);
|
|
1223
|
+
this._literal = {};
|
|
1224
|
+
}
|
|
1225
|
+
else if (inputStr instanceof coefficients_1.Fraction) {
|
|
1226
|
+
this._coefficient = inputStr.clone();
|
|
1227
|
+
this._literal = {};
|
|
1228
|
+
}
|
|
1229
|
+
else if (inputStr instanceof Monom) {
|
|
1230
|
+
this._coefficient = inputStr._coefficient.clone();
|
|
1231
|
+
this._literal = this.copyLiterals(inputStr.literal);
|
|
1232
|
+
}
|
|
1109
1233
|
return this;
|
|
1110
1234
|
};
|
|
1111
1235
|
_shutingYardToReducedMonom = (inputStr) => {
|
|
@@ -1176,6 +1300,13 @@ class Monom {
|
|
|
1176
1300
|
}
|
|
1177
1301
|
return F;
|
|
1178
1302
|
};
|
|
1303
|
+
copyLiterals = (literal) => {
|
|
1304
|
+
let L = {};
|
|
1305
|
+
for (let k in literal) {
|
|
1306
|
+
L[k] = literal[k].clone();
|
|
1307
|
+
}
|
|
1308
|
+
return L;
|
|
1309
|
+
};
|
|
1179
1310
|
makeSame = (M) => {
|
|
1180
1311
|
for (let k in M._literal) {
|
|
1181
1312
|
this.setLetter(k, M._literal[k].clone());
|
|
@@ -1737,7 +1868,7 @@ class Polynom {
|
|
|
1737
1868
|
else if (value instanceof monom_1.Monom) {
|
|
1738
1869
|
return this.multiplyByMonom(value);
|
|
1739
1870
|
}
|
|
1740
|
-
else if (Number.isSafeInteger(value)) {
|
|
1871
|
+
else if (Number.isSafeInteger(value) && typeof value === 'number') {
|
|
1741
1872
|
return this.multiplyByInteger(value);
|
|
1742
1873
|
}
|
|
1743
1874
|
return this;
|
|
@@ -1778,7 +1909,7 @@ class Polynom {
|
|
|
1778
1909
|
const degreeP = P.degree(letter);
|
|
1779
1910
|
let newM;
|
|
1780
1911
|
let MaxIteration = this.degree(letter).clone().multiply(2);
|
|
1781
|
-
while (reminder.degree(letter)
|
|
1912
|
+
while (reminder.degree(letter).geq(degreeP) && MaxIteration.isPositive()) {
|
|
1782
1913
|
MaxIteration.subtract(1);
|
|
1783
1914
|
newM = reminder.monomByDegree(undefined, letter).clone().divide(maxMP);
|
|
1784
1915
|
if (newM.isZero()) {
|
|
@@ -1790,10 +1921,10 @@ class Polynom {
|
|
|
1790
1921
|
return { quotient, reminder };
|
|
1791
1922
|
};
|
|
1792
1923
|
divide = (value) => {
|
|
1793
|
-
if (value.
|
|
1924
|
+
if (value instanceof coefficients_1.Fraction) {
|
|
1794
1925
|
this.divideByFraction(value);
|
|
1795
1926
|
}
|
|
1796
|
-
else if (Number.isSafeInteger(value)) {
|
|
1927
|
+
else if (typeof value === 'number' && Number.isSafeInteger(value)) {
|
|
1797
1928
|
return this.divideByInteger(value);
|
|
1798
1929
|
}
|
|
1799
1930
|
};
|
|
@@ -2289,7 +2420,7 @@ exports.Polynom = Polynom;
|
|
|
2289
2420
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
2290
2421
|
exports.Rational = void 0;
|
|
2291
2422
|
const polynom_1 = __webpack_require__(/*! ./polynom */ "./src/maths/algebra/polynom.ts");
|
|
2292
|
-
const
|
|
2423
|
+
const coefficients_1 = __webpack_require__(/*! ../coefficients */ "./src/maths/coefficients/index.ts");
|
|
2293
2424
|
class Rational {
|
|
2294
2425
|
_rawString;
|
|
2295
2426
|
_numerator;
|
|
@@ -2388,7 +2519,7 @@ class Rational {
|
|
|
2388
2519
|
}
|
|
2389
2520
|
}
|
|
2390
2521
|
else {
|
|
2391
|
-
return this._numerator.evaluate({ letter: new
|
|
2522
|
+
return this._numerator.evaluate({ letter: new coefficients_1.Fraction(value) }).divide(this._denominator.evaluate({ letter: new coefficients_1.Fraction(value) }));
|
|
2392
2523
|
}
|
|
2393
2524
|
};
|
|
2394
2525
|
}
|
|
@@ -2516,7 +2647,7 @@ class Fraction {
|
|
|
2516
2647
|
}
|
|
2517
2648
|
break;
|
|
2518
2649
|
case "object":
|
|
2519
|
-
if (value
|
|
2650
|
+
if (value instanceof Fraction) {
|
|
2520
2651
|
this._numerator = +value.numerator;
|
|
2521
2652
|
this._denominator = +value.denominator;
|
|
2522
2653
|
}
|
|
@@ -2825,11 +2956,14 @@ class Nthroot {
|
|
|
2825
2956
|
_nth;
|
|
2826
2957
|
_coefficient;
|
|
2827
2958
|
_isValid;
|
|
2828
|
-
constructor() {
|
|
2959
|
+
constructor(...values) {
|
|
2829
2960
|
this._radical = 1;
|
|
2830
2961
|
this._coefficient = 1;
|
|
2831
2962
|
this._nth = 2;
|
|
2832
2963
|
this._isValid = true;
|
|
2964
|
+
if (values !== undefined) {
|
|
2965
|
+
this.parse(values[0], values[1], values[2]);
|
|
2966
|
+
}
|
|
2833
2967
|
}
|
|
2834
2968
|
get radical() {
|
|
2835
2969
|
return this._radical;
|
|
@@ -2929,9 +3063,9 @@ const point_1 = __webpack_require__(/*! ./point */ "./src/maths/geometry/point.t
|
|
|
2929
3063
|
const coefficients_1 = __webpack_require__(/*! ../coefficients */ "./src/maths/coefficients/index.ts");
|
|
2930
3064
|
const algebra_1 = __webpack_require__(/*! ../algebra */ "./src/maths/algebra/index.ts");
|
|
2931
3065
|
const vector_1 = __webpack_require__(/*! ./vector */ "./src/maths/geometry/vector.ts");
|
|
3066
|
+
const triangle_1 = __webpack_require__(/*! ./triangle */ "./src/maths/geometry/triangle.ts");
|
|
2932
3067
|
class Circle {
|
|
2933
3068
|
_center;
|
|
2934
|
-
_radius;
|
|
2935
3069
|
_squareRadius;
|
|
2936
3070
|
_cartesian;
|
|
2937
3071
|
_exists;
|
|
@@ -2944,6 +3078,12 @@ class Circle {
|
|
|
2944
3078
|
get center() {
|
|
2945
3079
|
return this._center;
|
|
2946
3080
|
}
|
|
3081
|
+
get exists() {
|
|
3082
|
+
return this._exists;
|
|
3083
|
+
}
|
|
3084
|
+
get squareRadius() {
|
|
3085
|
+
return this._squareRadius;
|
|
3086
|
+
}
|
|
2947
3087
|
get radius() {
|
|
2948
3088
|
if (this._squareRadius.isSquare()) {
|
|
2949
3089
|
return {
|
|
@@ -2960,20 +3100,25 @@ class Circle {
|
|
|
2960
3100
|
return this._squareRadius;
|
|
2961
3101
|
}
|
|
2962
3102
|
get tex() {
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
3103
|
+
if (this._exists) {
|
|
3104
|
+
let cx, cy;
|
|
3105
|
+
if (this._center.x.isZero()) {
|
|
3106
|
+
cx = 'x^2';
|
|
3107
|
+
}
|
|
3108
|
+
else {
|
|
3109
|
+
cx = `\\left(x${this._center.x.isNegative() ? '+' : '-'}${this._center.x.clone().abs().tex}\\right)^2`;
|
|
3110
|
+
}
|
|
3111
|
+
if (this._center.y.isZero()) {
|
|
3112
|
+
cy = 'y^2';
|
|
3113
|
+
}
|
|
3114
|
+
else {
|
|
3115
|
+
cy = `\\left(y${this._center.y.isNegative() ? '+' : '-'}${this._center.y.clone().abs().tex}\\right)^2`;
|
|
3116
|
+
}
|
|
3117
|
+
return `${cx}+${cy}=${this._squareRadius.tex}`;
|
|
2972
3118
|
}
|
|
2973
3119
|
else {
|
|
2974
|
-
|
|
3120
|
+
return `\\text{le cercle n'existe pas.}`;
|
|
2975
3121
|
}
|
|
2976
|
-
return `${cx}+${cy}=${this._squareRadius.tex}`;
|
|
2977
3122
|
}
|
|
2978
3123
|
get developed() {
|
|
2979
3124
|
return this._cartesian.tex;
|
|
@@ -2984,43 +3129,108 @@ class Circle {
|
|
|
2984
3129
|
get cartesian() {
|
|
2985
3130
|
return this._cartesian;
|
|
2986
3131
|
}
|
|
3132
|
+
clone() {
|
|
3133
|
+
this._center = this._center.clone();
|
|
3134
|
+
this._squareRadius = this._squareRadius.clone();
|
|
3135
|
+
this._calculateCartesian();
|
|
3136
|
+
return this;
|
|
3137
|
+
}
|
|
3138
|
+
_reset() {
|
|
3139
|
+
this._center = null;
|
|
3140
|
+
this._squareRadius = null;
|
|
3141
|
+
this._cartesian = null;
|
|
3142
|
+
this._exists = false;
|
|
3143
|
+
return this;
|
|
3144
|
+
}
|
|
2987
3145
|
parse(...values) {
|
|
2988
|
-
|
|
2989
|
-
|
|
3146
|
+
this._reset();
|
|
3147
|
+
if (typeof values[0] === 'string') {
|
|
3148
|
+
this._parseEquation(new algebra_1.Equation(values[0]));
|
|
3149
|
+
}
|
|
3150
|
+
else if (values[0] instanceof algebra_1.Equation) {
|
|
3151
|
+
this._parseEquation(values[0]);
|
|
2990
3152
|
}
|
|
2991
|
-
else if (values
|
|
2992
|
-
this.
|
|
3153
|
+
else if (values[0] instanceof Circle) {
|
|
3154
|
+
this._parseCopyCircle(values[0]);
|
|
3155
|
+
}
|
|
3156
|
+
else if (values[0] instanceof point_1.Point && values.length > 1) {
|
|
2993
3157
|
if (values[1] instanceof point_1.Point) {
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
else {
|
|
2997
|
-
if (values[2] === true) {
|
|
2998
|
-
this._squareRadius = new coefficients_1.Fraction(values[1]);
|
|
3158
|
+
if (values[2] instanceof point_1.Point) {
|
|
3159
|
+
this._parseThroughtThreePoints(values[0], values[1], values[2]);
|
|
2999
3160
|
}
|
|
3000
3161
|
else {
|
|
3001
|
-
this.
|
|
3002
|
-
this._squareRadius = this._radius.clone().pow(2);
|
|
3162
|
+
this._parseCenterAndPointThrough(values[0], values[1]);
|
|
3003
3163
|
}
|
|
3004
3164
|
}
|
|
3005
|
-
|
|
3165
|
+
else if (values[1] instanceof coefficients_1.Fraction || typeof values[1] === 'number') {
|
|
3166
|
+
this._parseCenterAndRadius(values[0], values[1], (typeof values[2] === "boolean") ? values[2] : false);
|
|
3167
|
+
}
|
|
3168
|
+
}
|
|
3169
|
+
if (this._exists) {
|
|
3170
|
+
this._calculateCartesian();
|
|
3171
|
+
if (this._squareRadius !== undefined && this._squareRadius.isNegative()) {
|
|
3172
|
+
this._exists = false;
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
return this;
|
|
3176
|
+
}
|
|
3177
|
+
_calculateCartesian() {
|
|
3178
|
+
this._cartesian = (new algebra_1.Equation(new algebra_1.Polynom(`(x-(${this._center.x.display}))^2+(y-(${this._center.y.display}))^2`), new algebra_1.Polynom(`${this._squareRadius.display}`))).moveLeft();
|
|
3179
|
+
}
|
|
3180
|
+
_parseCopyCircle(circle) {
|
|
3181
|
+
this._center = circle.center.clone();
|
|
3182
|
+
this._squareRadius = circle.squareRadius.clone();
|
|
3183
|
+
this._calculateCartesian();
|
|
3184
|
+
this._exists = circle.exists;
|
|
3185
|
+
return this;
|
|
3186
|
+
}
|
|
3187
|
+
_parseCenterAndRadius(center, radius, square) {
|
|
3188
|
+
this._center = center.clone();
|
|
3189
|
+
if (square) {
|
|
3190
|
+
this._squareRadius = (new coefficients_1.Fraction(radius));
|
|
3006
3191
|
}
|
|
3192
|
+
else {
|
|
3193
|
+
this._squareRadius = new coefficients_1.Fraction(radius).pow(2);
|
|
3194
|
+
}
|
|
3195
|
+
this._exists = true;
|
|
3196
|
+
return this;
|
|
3197
|
+
}
|
|
3198
|
+
_parseCenterAndPointThrough(center, pointThrough) {
|
|
3199
|
+
this._center = center.clone();
|
|
3200
|
+
this._squareRadius = new vector_1.Vector(this._center, pointThrough).normSquare;
|
|
3201
|
+
this._exists = true;
|
|
3202
|
+
return this;
|
|
3007
3203
|
}
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3204
|
+
_parseEquation(equ) {
|
|
3205
|
+
this._exists = false;
|
|
3206
|
+
equ.moveLeft();
|
|
3207
|
+
if (equ.degree('x').value === 2 && equ.degree('y').value === 2) {
|
|
3208
|
+
let x2 = equ.left.monomByDegree(2, 'x'), y2 = equ.left.monomByDegree(2, 'y'), x1, y1, c;
|
|
3011
3209
|
if (x2.coefficient.isEqual(y2.coefficient)) {
|
|
3012
|
-
|
|
3013
|
-
x1 =
|
|
3014
|
-
y1 =
|
|
3015
|
-
c =
|
|
3210
|
+
equ.divide(x2.coefficient);
|
|
3211
|
+
x1 = equ.left.monomByDegree(1, 'x');
|
|
3212
|
+
y1 = equ.left.monomByDegree(1, 'y');
|
|
3213
|
+
c = equ.left.monomByDegree(0);
|
|
3016
3214
|
this._center = new point_1.Point(x1.coefficient.clone().divide(2).opposed(), y1.coefficient.clone().divide(2).opposed());
|
|
3017
3215
|
this._squareRadius = c.coefficient.clone().opposed()
|
|
3018
3216
|
.add(this._center.x.clone().pow(2))
|
|
3019
3217
|
.add(this._center.y.clone().pow(2));
|
|
3218
|
+
this._calculateCartesian();
|
|
3219
|
+
this._exists = true;
|
|
3220
|
+
}
|
|
3221
|
+
else {
|
|
3222
|
+
this._center = null;
|
|
3223
|
+
this._squareRadius = null;
|
|
3224
|
+
this._exists = false;
|
|
3020
3225
|
}
|
|
3021
3226
|
}
|
|
3022
|
-
return
|
|
3023
|
-
}
|
|
3227
|
+
return this;
|
|
3228
|
+
}
|
|
3229
|
+
_parseThroughtThreePoints(A, B, C) {
|
|
3230
|
+
let T = new triangle_1.Triangle(A, B, C), mAB = T.remarquables.mediators.AB.clone(), mAC = T.remarquables.mediators.AC.clone();
|
|
3231
|
+
this.parse(mAB.intersection(mAC).point, A);
|
|
3232
|
+
return this;
|
|
3233
|
+
}
|
|
3024
3234
|
relativePosition = (L) => {
|
|
3025
3235
|
let distance = L.distanceTo(this.center), radius = Math.sqrt(this._squareRadius.value);
|
|
3026
3236
|
if (distance.value - radius > 0.0000000001) {
|
|
@@ -3034,13 +3244,23 @@ class Circle {
|
|
|
3034
3244
|
}
|
|
3035
3245
|
};
|
|
3036
3246
|
lineIntersection = (L) => {
|
|
3037
|
-
let
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3247
|
+
let intersectionPoints = [], solX;
|
|
3248
|
+
if (this._cartesian === null) {
|
|
3249
|
+
return [];
|
|
3250
|
+
}
|
|
3251
|
+
const equX = this._cartesian.clone(), lineX = L.equation.clone().isolate('x'), lineY = L.equation.clone().isolate('y');
|
|
3252
|
+
if (lineX instanceof algebra_1.Equation && lineY instanceof algebra_1.Equation) {
|
|
3253
|
+
equX.replaceBy('y', lineY.right).simplify();
|
|
3254
|
+
equX.solve();
|
|
3255
|
+
for (let x of equX.solutions) {
|
|
3256
|
+
if (x.exact === false && isNaN(x.value)) {
|
|
3257
|
+
continue;
|
|
3258
|
+
}
|
|
3259
|
+
solX = new coefficients_1.Fraction(x.exact === false ? x.value : x.exact);
|
|
3260
|
+
intersectionPoints.push(new point_1.Point(solX.clone(), lineY.right.evaluate(solX)));
|
|
3261
|
+
}
|
|
3042
3262
|
}
|
|
3043
|
-
return
|
|
3263
|
+
return intersectionPoints;
|
|
3044
3264
|
};
|
|
3045
3265
|
}
|
|
3046
3266
|
exports.Circle = Circle;
|
|
@@ -3114,9 +3334,6 @@ class Line {
|
|
|
3114
3334
|
}
|
|
3115
3335
|
return this;
|
|
3116
3336
|
}
|
|
3117
|
-
get isLine() {
|
|
3118
|
-
return true;
|
|
3119
|
-
}
|
|
3120
3337
|
get exists() {
|
|
3121
3338
|
return this._exists;
|
|
3122
3339
|
}
|
|
@@ -3431,23 +3648,24 @@ exports.Line = Line;
|
|
|
3431
3648
|
|
|
3432
3649
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
3433
3650
|
exports.Point = void 0;
|
|
3434
|
-
const
|
|
3651
|
+
const coefficients_1 = __webpack_require__(/*! ../coefficients */ "./src/maths/coefficients/index.ts");
|
|
3652
|
+
class PointXY {
|
|
3653
|
+
x;
|
|
3654
|
+
y;
|
|
3655
|
+
}
|
|
3435
3656
|
class Point {
|
|
3436
3657
|
_x;
|
|
3437
3658
|
_y;
|
|
3438
3659
|
_exist;
|
|
3439
3660
|
constructor(...values) {
|
|
3440
|
-
this._x = new
|
|
3441
|
-
this._y = new
|
|
3661
|
+
this._x = new coefficients_1.Fraction().zero();
|
|
3662
|
+
this._y = new coefficients_1.Fraction().zero();
|
|
3442
3663
|
if (values !== undefined) {
|
|
3443
3664
|
this.parse(...values);
|
|
3444
3665
|
}
|
|
3445
3666
|
return this;
|
|
3446
3667
|
}
|
|
3447
3668
|
;
|
|
3448
|
-
get isPoint() {
|
|
3449
|
-
return true;
|
|
3450
|
-
}
|
|
3451
3669
|
get x() {
|
|
3452
3670
|
return this._x;
|
|
3453
3671
|
}
|
|
@@ -3486,22 +3704,24 @@ class Point {
|
|
|
3486
3704
|
if (typeof values[0] === 'string') {
|
|
3487
3705
|
let xy = values[0].split(',');
|
|
3488
3706
|
if (xy.length === 2) {
|
|
3489
|
-
this._x = new
|
|
3490
|
-
this._y = new
|
|
3707
|
+
this._x = new coefficients_1.Fraction(xy[0]).reduce();
|
|
3708
|
+
this._y = new coefficients_1.Fraction(xy[1]).reduce();
|
|
3491
3709
|
return this;
|
|
3492
3710
|
}
|
|
3493
3711
|
}
|
|
3494
|
-
if (values[0]
|
|
3495
|
-
this._x = new
|
|
3496
|
-
this._y = new
|
|
3712
|
+
if (values[0] instanceof PointXY) {
|
|
3713
|
+
this._x = new coefficients_1.Fraction(values[0].x).reduce();
|
|
3714
|
+
this._y = new coefficients_1.Fraction(values[0].y).reduce();
|
|
3715
|
+
return this;
|
|
3497
3716
|
}
|
|
3498
3717
|
else {
|
|
3499
3718
|
return this.zero();
|
|
3500
3719
|
}
|
|
3501
3720
|
}
|
|
3502
3721
|
if (values.length === 2) {
|
|
3503
|
-
this._x = new
|
|
3504
|
-
this._y = new
|
|
3722
|
+
this._x = new coefficients_1.Fraction(values[0]).reduce();
|
|
3723
|
+
this._y = new coefficients_1.Fraction(values[1]).reduce();
|
|
3724
|
+
return this;
|
|
3505
3725
|
}
|
|
3506
3726
|
return this;
|
|
3507
3727
|
};
|
|
@@ -3511,8 +3731,8 @@ class Point {
|
|
|
3511
3731
|
return this;
|
|
3512
3732
|
};
|
|
3513
3733
|
zero = () => {
|
|
3514
|
-
this._x = new
|
|
3515
|
-
this._y = new
|
|
3734
|
+
this._x = new coefficients_1.Fraction(null);
|
|
3735
|
+
this._y = new coefficients_1.Fraction(null);
|
|
3516
3736
|
return this;
|
|
3517
3737
|
};
|
|
3518
3738
|
origin = () => {
|
|
@@ -3571,7 +3791,6 @@ class Triangle {
|
|
|
3571
3791
|
}
|
|
3572
3792
|
return this;
|
|
3573
3793
|
}
|
|
3574
|
-
get isTriangle() { return true; }
|
|
3575
3794
|
get A() {
|
|
3576
3795
|
return this._A;
|
|
3577
3796
|
}
|
|
@@ -3635,7 +3854,7 @@ class Triangle {
|
|
|
3635
3854
|
if (values.filter((x) => typeof x === 'string').length === 3) {
|
|
3636
3855
|
return this.parse(...values.map((x) => new line_1.Line(x)));
|
|
3637
3856
|
}
|
|
3638
|
-
else if (values.filter((x) => x
|
|
3857
|
+
else if (values.filter((x) => x instanceof line_1.Line).length === 3) {
|
|
3639
3858
|
this._lines = {
|
|
3640
3859
|
'AB': values[0],
|
|
3641
3860
|
'BC': values[1],
|
|
@@ -3664,7 +3883,7 @@ class Triangle {
|
|
|
3664
3883
|
}
|
|
3665
3884
|
}
|
|
3666
3885
|
else {
|
|
3667
|
-
if (values.filter((x) => x
|
|
3886
|
+
if (values.filter((x) => (x instanceof point_1.Point)).length < 3) {
|
|
3668
3887
|
return this.parse(new point_1.Point(values[0]), new point_1.Point(values[1]), new point_1.Point(values[2]));
|
|
3669
3888
|
}
|
|
3670
3889
|
this._A = values[0].clone();
|
|
@@ -3678,7 +3897,7 @@ class Triangle {
|
|
|
3678
3897
|
}
|
|
3679
3898
|
}
|
|
3680
3899
|
else if (values.length === 1) {
|
|
3681
|
-
if (values[0]
|
|
3900
|
+
if (values[0] instanceof Triangle) {
|
|
3682
3901
|
return values[0].clone();
|
|
3683
3902
|
}
|
|
3684
3903
|
}
|
|
@@ -3795,6 +4014,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
3795
4014
|
exports.Vector = void 0;
|
|
3796
4015
|
const fraction_1 = __webpack_require__(/*! ../coefficients/fraction */ "./src/maths/coefficients/fraction.ts");
|
|
3797
4016
|
const numeric_1 = __webpack_require__(/*! ../numeric */ "./src/maths/numeric.ts");
|
|
4017
|
+
const point_1 = __webpack_require__(/*! ./point */ "./src/maths/geometry/point.ts");
|
|
3798
4018
|
class Vector {
|
|
3799
4019
|
_x;
|
|
3800
4020
|
_y;
|
|
@@ -3841,7 +4061,7 @@ class Vector {
|
|
|
3841
4061
|
}
|
|
3842
4062
|
}
|
|
3843
4063
|
if (values.length >= 2) {
|
|
3844
|
-
if (values[0].
|
|
4064
|
+
if (values[0] instanceof point_1.Point && values[1] instanceof point_1.Point) {
|
|
3845
4065
|
this._x = values[1].x.clone().subtract(values[0].x);
|
|
3846
4066
|
this._y = values[1].y.clone().subtract(values[0].y);
|
|
3847
4067
|
return this;
|
|
@@ -4014,6 +4234,131 @@ class Numeric {
|
|
|
4014
4234
|
exports.Numeric = Numeric;
|
|
4015
4235
|
|
|
4016
4236
|
|
|
4237
|
+
/***/ }),
|
|
4238
|
+
|
|
4239
|
+
/***/ "./src/maths/numexp.ts":
|
|
4240
|
+
/*!*****************************!*\
|
|
4241
|
+
!*** ./src/maths/numexp.ts ***!
|
|
4242
|
+
\*****************************/
|
|
4243
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
4244
|
+
|
|
4245
|
+
|
|
4246
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
4247
|
+
exports.NumExp = void 0;
|
|
4248
|
+
const shutingyard_1 = __webpack_require__(/*! ./shutingyard */ "./src/maths/shutingyard.ts");
|
|
4249
|
+
const coefficients_1 = __webpack_require__(/*! ./coefficients */ "./src/maths/coefficients/index.ts");
|
|
4250
|
+
class NumExp {
|
|
4251
|
+
_rpn;
|
|
4252
|
+
_expression;
|
|
4253
|
+
constructor(value) {
|
|
4254
|
+
this._expression = value;
|
|
4255
|
+
this._rpn = new shutingyard_1.Shutingyard(shutingyard_1.ShutingyardMode.NUMERIC).parse(value).rpn;
|
|
4256
|
+
}
|
|
4257
|
+
get rpn() {
|
|
4258
|
+
return this._rpn;
|
|
4259
|
+
}
|
|
4260
|
+
get expression() {
|
|
4261
|
+
return this._expression;
|
|
4262
|
+
}
|
|
4263
|
+
_extractDecimalPart(value) {
|
|
4264
|
+
let decimal = value.toString();
|
|
4265
|
+
if (!decimal.includes('.')) {
|
|
4266
|
+
return '';
|
|
4267
|
+
}
|
|
4268
|
+
decimal = decimal.split('.')[1];
|
|
4269
|
+
return decimal.substring(0, decimal.length - 2);
|
|
4270
|
+
}
|
|
4271
|
+
_numberCorrection(value) {
|
|
4272
|
+
const epsilon = 0.00000000000001, number_of_digits = 6;
|
|
4273
|
+
let decimal = this._extractDecimalPart(value);
|
|
4274
|
+
if (decimal === '') {
|
|
4275
|
+
return value;
|
|
4276
|
+
}
|
|
4277
|
+
const n9 = decimal.match(/9+$/g);
|
|
4278
|
+
const n0 = decimal.match(/0+$/g);
|
|
4279
|
+
if (n9 && n9[0].length >= number_of_digits) {
|
|
4280
|
+
let mod = this._extractDecimalPart(value + epsilon), mod0 = mod.match(/0+$/g);
|
|
4281
|
+
if (mod0 && mod0[0].length >= number_of_digits) {
|
|
4282
|
+
return +((value + epsilon).toString().split(mod0[0])[0]);
|
|
4283
|
+
}
|
|
4284
|
+
}
|
|
4285
|
+
if (n0 && n0[0].length >= number_of_digits) {
|
|
4286
|
+
let mod = this._extractDecimalPart(value - epsilon), mod9 = mod.match(/9+$/g);
|
|
4287
|
+
if (mod9 && mod9[0].length >= number_of_digits) {
|
|
4288
|
+
return +(value.toString().split(n0[0])[0]);
|
|
4289
|
+
}
|
|
4290
|
+
}
|
|
4291
|
+
return value;
|
|
4292
|
+
}
|
|
4293
|
+
_addToStack(stack, value) {
|
|
4294
|
+
stack.push(this._numberCorrection(value));
|
|
4295
|
+
}
|
|
4296
|
+
evaluate(values) {
|
|
4297
|
+
let stack = [];
|
|
4298
|
+
for (const element of this._rpn) {
|
|
4299
|
+
if (element.tokenType === shutingyard_1.ShutingyardType.COEFFICIENT) {
|
|
4300
|
+
if (!isNaN(+element.token)) {
|
|
4301
|
+
this._addToStack(stack, +element.token);
|
|
4302
|
+
}
|
|
4303
|
+
else {
|
|
4304
|
+
this._addToStack(stack, new coefficients_1.Fraction(element.token).value);
|
|
4305
|
+
}
|
|
4306
|
+
}
|
|
4307
|
+
else if (element.tokenType === shutingyard_1.ShutingyardType.VARIABLE) {
|
|
4308
|
+
if (values[element.token] !== undefined) {
|
|
4309
|
+
this._addToStack(stack, +values[element.token]);
|
|
4310
|
+
}
|
|
4311
|
+
}
|
|
4312
|
+
else if (element.tokenType === shutingyard_1.ShutingyardType.CONSTANT) {
|
|
4313
|
+
this._addToStack(stack, shutingyard_1.tokenConstant[element.token]);
|
|
4314
|
+
}
|
|
4315
|
+
else if (element.tokenType === shutingyard_1.ShutingyardType.OPERATION) {
|
|
4316
|
+
if (element.token === '*') {
|
|
4317
|
+
const b = +stack.pop(), a = +stack.pop();
|
|
4318
|
+
this._addToStack(stack, a * b);
|
|
4319
|
+
}
|
|
4320
|
+
else if (element.token === '/') {
|
|
4321
|
+
const b = +stack.pop(), a = +stack.pop();
|
|
4322
|
+
this._addToStack(stack, a / b);
|
|
4323
|
+
}
|
|
4324
|
+
else if (element.token === '+') {
|
|
4325
|
+
const b = +stack.pop(), a = +stack.pop();
|
|
4326
|
+
this._addToStack(stack, a + b);
|
|
4327
|
+
}
|
|
4328
|
+
else if (element.token === '-') {
|
|
4329
|
+
const b = +stack.pop(), a = +stack.pop();
|
|
4330
|
+
this._addToStack(stack, a - b);
|
|
4331
|
+
}
|
|
4332
|
+
else if (element.token === '^') {
|
|
4333
|
+
const b = +stack.pop(), a = +stack.pop();
|
|
4334
|
+
this._addToStack(stack, Math.pow(a, b));
|
|
4335
|
+
}
|
|
4336
|
+
}
|
|
4337
|
+
else if (element.tokenType === shutingyard_1.ShutingyardType.FUNCTION) {
|
|
4338
|
+
const a = +stack.pop();
|
|
4339
|
+
if (element.token === 'sin') {
|
|
4340
|
+
this._addToStack(stack, Math.sin(a));
|
|
4341
|
+
}
|
|
4342
|
+
else if (element.token === 'cos') {
|
|
4343
|
+
this._addToStack(stack, Math.cos(a));
|
|
4344
|
+
}
|
|
4345
|
+
else if (element.token === 'tan') {
|
|
4346
|
+
this._addToStack(stack, Math.tan(a));
|
|
4347
|
+
}
|
|
4348
|
+
}
|
|
4349
|
+
}
|
|
4350
|
+
if (stack.length === 1) {
|
|
4351
|
+
return stack[0];
|
|
4352
|
+
}
|
|
4353
|
+
else {
|
|
4354
|
+
console.error('There was a problem parsing', this._expression, '. The RPN array is', this._rpn);
|
|
4355
|
+
return 0;
|
|
4356
|
+
}
|
|
4357
|
+
}
|
|
4358
|
+
}
|
|
4359
|
+
exports.NumExp = NumExp;
|
|
4360
|
+
|
|
4361
|
+
|
|
4017
4362
|
/***/ }),
|
|
4018
4363
|
|
|
4019
4364
|
/***/ "./src/maths/random/index.ts":
|
|
@@ -4131,6 +4476,7 @@ class rndFraction extends randomCore_1.randomCore {
|
|
|
4131
4476
|
super();
|
|
4132
4477
|
this._defaultConfig = {
|
|
4133
4478
|
negative: true,
|
|
4479
|
+
max: 10,
|
|
4134
4480
|
reduced: true,
|
|
4135
4481
|
zero: true,
|
|
4136
4482
|
natural: false
|
|
@@ -4140,16 +4486,16 @@ class rndFraction extends randomCore_1.randomCore {
|
|
|
4140
4486
|
generate = () => {
|
|
4141
4487
|
let Q = new coefficients_1.Fraction();
|
|
4142
4488
|
if (this._config.negative) {
|
|
4143
|
-
Q.numerator = index_1.Random.numberSym(
|
|
4489
|
+
Q.numerator = index_1.Random.numberSym(this._config.max, this._config.zero);
|
|
4144
4490
|
}
|
|
4145
4491
|
else {
|
|
4146
|
-
Q.numerator = index_1.Random.number(this._config.zero ? 0 : 1,
|
|
4492
|
+
Q.numerator = index_1.Random.number(this._config.zero ? 0 : 1, this._config.max);
|
|
4147
4493
|
}
|
|
4148
4494
|
if (this._config.natural) {
|
|
4149
4495
|
Q.denominator = 1;
|
|
4150
4496
|
}
|
|
4151
4497
|
else {
|
|
4152
|
-
Q.denominator = index_1.Random.number(1,
|
|
4498
|
+
Q.denominator = index_1.Random.number(1, this._config.max);
|
|
4153
4499
|
}
|
|
4154
4500
|
return this._config.reduced ? Q.reduce() : Q;
|
|
4155
4501
|
};
|
|
@@ -4228,7 +4574,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
4228
4574
|
exports.rndMonom = void 0;
|
|
4229
4575
|
const randomCore_1 = __webpack_require__(/*! ./randomCore */ "./src/maths/random/randomCore.ts");
|
|
4230
4576
|
const index_1 = __webpack_require__(/*! ./index */ "./src/maths/random/index.ts");
|
|
4231
|
-
const
|
|
4577
|
+
const algebra_1 = __webpack_require__(/*! ../algebra */ "./src/maths/algebra/index.ts");
|
|
4232
4578
|
class rndMonom extends randomCore_1.randomCore {
|
|
4233
4579
|
constructor(userConfig) {
|
|
4234
4580
|
super();
|
|
@@ -4241,12 +4587,17 @@ class rndMonom extends randomCore_1.randomCore {
|
|
|
4241
4587
|
this._config = this.mergeConfig(userConfig, this._defaultConfig);
|
|
4242
4588
|
}
|
|
4243
4589
|
generate = () => {
|
|
4244
|
-
let M = new
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4590
|
+
let M = new algebra_1.Monom();
|
|
4591
|
+
if (typeof this._config.fraction === "boolean") {
|
|
4592
|
+
M.coefficient = index_1.Random.fraction({
|
|
4593
|
+
zero: this._config.zero,
|
|
4594
|
+
reduced: true,
|
|
4595
|
+
natural: !this._config.fraction
|
|
4596
|
+
});
|
|
4597
|
+
}
|
|
4598
|
+
else {
|
|
4599
|
+
M.coefficient = index_1.Random.fraction(this._config.fraction);
|
|
4600
|
+
}
|
|
4250
4601
|
if (this._config.letters.length > 1) {
|
|
4251
4602
|
for (let L of this._config.letters.split('')) {
|
|
4252
4603
|
M.setLetter(L, 0);
|
|
@@ -4291,7 +4642,8 @@ class rndPolynom extends randomCore_1.randomCore {
|
|
|
4291
4642
|
unit: false,
|
|
4292
4643
|
factorable: false,
|
|
4293
4644
|
allowNullMonom: true,
|
|
4294
|
-
numberOfMonoms: 0
|
|
4645
|
+
numberOfMonoms: 0,
|
|
4646
|
+
positive: true
|
|
4295
4647
|
};
|
|
4296
4648
|
this._config = this.mergeConfig(userConfig, this._defaultConfig);
|
|
4297
4649
|
}
|
|
@@ -4312,8 +4664,13 @@ class rndPolynom extends randomCore_1.randomCore {
|
|
|
4312
4664
|
}
|
|
4313
4665
|
P.add(M);
|
|
4314
4666
|
}
|
|
4667
|
+
if (this._config.positive && P.monomByDegree().coefficient.isNegative()) {
|
|
4668
|
+
P.monomByDegree().coefficient.opposed();
|
|
4669
|
+
}
|
|
4315
4670
|
if (this._config.numberOfMonoms > 0 && this._config.numberOfMonoms < P.length) {
|
|
4316
|
-
|
|
4671
|
+
let M = P.monomByDegree().clone();
|
|
4672
|
+
P.monoms = index_1.Random.array(P.monoms.slice(1), this._config.numberOfMonoms - 1);
|
|
4673
|
+
P.add(M).reorder().reduce();
|
|
4317
4674
|
}
|
|
4318
4675
|
return P;
|
|
4319
4676
|
};
|
|
@@ -4353,46 +4710,75 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
4353
4710
|
|
|
4354
4711
|
|
|
4355
4712
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
4356
|
-
exports.Shutingyard = void 0;
|
|
4713
|
+
exports.Shutingyard = exports.ShutingyardMode = exports.ShutingyardType = exports.tokenConstant = void 0;
|
|
4714
|
+
exports.tokenConstant = {
|
|
4715
|
+
pi: Math.PI,
|
|
4716
|
+
e: Math.exp(1)
|
|
4717
|
+
};
|
|
4718
|
+
var ShutingyardType;
|
|
4719
|
+
(function (ShutingyardType) {
|
|
4720
|
+
ShutingyardType["VARIABLE"] = "variable";
|
|
4721
|
+
ShutingyardType["COEFFICIENT"] = "coefficient";
|
|
4722
|
+
ShutingyardType["OPERATION"] = "operation";
|
|
4723
|
+
ShutingyardType["CONSTANT"] = "constant";
|
|
4724
|
+
ShutingyardType["FUNCTION"] = "function";
|
|
4725
|
+
ShutingyardType["MONOM"] = "monom";
|
|
4726
|
+
})(ShutingyardType = exports.ShutingyardType || (exports.ShutingyardType = {}));
|
|
4727
|
+
var ShutingyardMode;
|
|
4728
|
+
(function (ShutingyardMode) {
|
|
4729
|
+
ShutingyardMode["POLYNOM"] = "polynom";
|
|
4730
|
+
ShutingyardMode["SET"] = "set";
|
|
4731
|
+
ShutingyardMode["NUMERIC"] = "numeric";
|
|
4732
|
+
})(ShutingyardMode = exports.ShutingyardMode || (exports.ShutingyardMode = {}));
|
|
4357
4733
|
class Shutingyard {
|
|
4358
4734
|
_rpn = [];
|
|
4359
4735
|
_mode;
|
|
4360
4736
|
_tokenConfig;
|
|
4737
|
+
_tokenConstant;
|
|
4361
4738
|
_uniformize;
|
|
4739
|
+
_tokenKeys;
|
|
4362
4740
|
constructor(mode) {
|
|
4363
|
-
this._mode = typeof mode === 'undefined' ?
|
|
4741
|
+
this._mode = typeof mode === 'undefined' ? ShutingyardMode.POLYNOM : mode;
|
|
4364
4742
|
this.tokenConfigInitialization();
|
|
4365
4743
|
}
|
|
4366
|
-
isOperation(token) {
|
|
4367
|
-
if (token[0].match(/[+\-*/^]/g)) {
|
|
4368
|
-
return true;
|
|
4369
|
-
}
|
|
4370
|
-
return false;
|
|
4371
|
-
}
|
|
4372
4744
|
tokenConfigInitialization() {
|
|
4373
|
-
if (this._mode ===
|
|
4745
|
+
if (this._mode === ShutingyardMode.SET) {
|
|
4374
4746
|
this._tokenConfig = {
|
|
4375
|
-
'&': { precedence: 3, associative: 'left' },
|
|
4376
|
-
'|': { precedence: 3, associative: 'left' },
|
|
4377
|
-
'!': { precedence: 4, associative: 'right' },
|
|
4378
|
-
'-': { precedence: 2, associative: 'left' }
|
|
4747
|
+
'&': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
|
|
4748
|
+
'|': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
|
|
4749
|
+
'!': { precedence: 4, associative: 'right', type: ShutingyardType.OPERATION },
|
|
4750
|
+
'-': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION }
|
|
4379
4751
|
};
|
|
4380
4752
|
this._uniformize = false;
|
|
4381
4753
|
}
|
|
4754
|
+
else if (this._mode === ShutingyardMode.NUMERIC) {
|
|
4755
|
+
this._tokenConfig = {
|
|
4756
|
+
'^': { precedence: 4, associative: 'right', type: ShutingyardType.OPERATION },
|
|
4757
|
+
'*': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
|
|
4758
|
+
'/': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
|
|
4759
|
+
'+': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
|
|
4760
|
+
'-': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
|
|
4761
|
+
'%': { precedence: 3, associative: 'right', type: ShutingyardType.OPERATION },
|
|
4762
|
+
'sin': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
4763
|
+
'cos': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
4764
|
+
'tan': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
4765
|
+
};
|
|
4766
|
+
}
|
|
4382
4767
|
else {
|
|
4383
4768
|
this._tokenConfig = {
|
|
4384
|
-
'^': { precedence: 4, associative: 'right' },
|
|
4385
|
-
'*': { precedence: 3, associative: 'left' },
|
|
4386
|
-
'/': { precedence: 3, associative: 'left' },
|
|
4387
|
-
'+': { precedence: 2, associative: 'left' },
|
|
4388
|
-
'-': { precedence: 2, associative: 'left' },
|
|
4389
|
-
'%': { precedence: 3, associative: 'right' },
|
|
4390
|
-
'sin': { precedence: 4, associative: 'right' },
|
|
4391
|
-
'cos': { precedence: 4, associative: 'right' },
|
|
4392
|
-
'
|
|
4769
|
+
'^': { precedence: 4, associative: 'right', type: ShutingyardType.OPERATION },
|
|
4770
|
+
'*': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
|
|
4771
|
+
'/': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
|
|
4772
|
+
'+': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
|
|
4773
|
+
'-': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
|
|
4774
|
+
'%': { precedence: 3, associative: 'right', type: ShutingyardType.OPERATION },
|
|
4775
|
+
'sin': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
4776
|
+
'cos': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
4777
|
+
'tan': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
4393
4778
|
};
|
|
4394
4779
|
this._uniformize = true;
|
|
4395
4780
|
}
|
|
4781
|
+
this._tokenKeys = Object.keys(this._tokenConfig).sort((a, b) => b.length - a.length);
|
|
4396
4782
|
return this._tokenConfig;
|
|
4397
4783
|
}
|
|
4398
4784
|
NextToken2(expr, start) {
|
|
@@ -4412,75 +4798,43 @@ class Shutingyard {
|
|
|
4412
4798
|
tokenType = 'function-argument';
|
|
4413
4799
|
}
|
|
4414
4800
|
else {
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
if (expr.substr(start, key.length) === key) {
|
|
4801
|
+
for (let key of this._tokenKeys) {
|
|
4802
|
+
if (expr.substring(start, start + key.length) === key) {
|
|
4418
4803
|
token += key;
|
|
4419
|
-
tokenType =
|
|
4804
|
+
tokenType = this._tokenConfig[key].type;
|
|
4805
|
+
break;
|
|
4806
|
+
}
|
|
4807
|
+
}
|
|
4808
|
+
for (let key in exports.tokenConstant) {
|
|
4809
|
+
if (expr.substring(start, start + key.length) === key) {
|
|
4810
|
+
token += key;
|
|
4811
|
+
tokenType = ShutingyardType.CONSTANT;
|
|
4420
4812
|
break;
|
|
4421
4813
|
}
|
|
4422
4814
|
}
|
|
4423
4815
|
if (token === '') {
|
|
4424
4816
|
if (expr[start].match(/[0-9]/)) {
|
|
4425
|
-
|
|
4426
|
-
|
|
4817
|
+
if (this._mode === ShutingyardMode.POLYNOM) {
|
|
4818
|
+
token = expr.substring(start).match(/^([0-9.,/]+)/)[0];
|
|
4819
|
+
}
|
|
4820
|
+
else {
|
|
4821
|
+
token = expr.substring(start).match(/^([0-9.,]+)/)[0];
|
|
4822
|
+
}
|
|
4823
|
+
tokenType = ShutingyardType.COEFFICIENT;
|
|
4427
4824
|
}
|
|
4428
4825
|
else if (expr[start].match(/[a-zA-Z]/)) {
|
|
4429
|
-
token = expr.
|
|
4430
|
-
tokenType =
|
|
4826
|
+
token = expr.substring(start).match(/^([a-zA-Z])/)[0];
|
|
4827
|
+
tokenType = ShutingyardType.VARIABLE;
|
|
4431
4828
|
}
|
|
4432
4829
|
else {
|
|
4433
4830
|
console.log('Unidentified token', expr[start], expr, start);
|
|
4434
4831
|
token = expr[start];
|
|
4435
|
-
tokenType =
|
|
4832
|
+
tokenType = ShutingyardType.MONOM;
|
|
4436
4833
|
}
|
|
4437
4834
|
}
|
|
4438
4835
|
}
|
|
4439
4836
|
return [token, start + token.length, tokenType];
|
|
4440
4837
|
}
|
|
4441
|
-
NextToken(expr, start) {
|
|
4442
|
-
let tokenMatch, token, tokenType;
|
|
4443
|
-
this.NextToken2(expr, start);
|
|
4444
|
-
tokenMatch = (expr.substr(start).match(/^[0-9/a-zA-Z^]+/g)) || [];
|
|
4445
|
-
if (expr.substr(start, start + 3).match(/^(sin|cos|tan)/g)) {
|
|
4446
|
-
token = expr.substr(start, 3);
|
|
4447
|
-
tokenType = 'function';
|
|
4448
|
-
}
|
|
4449
|
-
else if (tokenMatch.length > 0) {
|
|
4450
|
-
token = tokenMatch[0];
|
|
4451
|
-
tokenType = 'monom';
|
|
4452
|
-
}
|
|
4453
|
-
else if (expr[start].match(/[+\-*/^]/g)) {
|
|
4454
|
-
token = expr[start];
|
|
4455
|
-
tokenType = 'operation';
|
|
4456
|
-
}
|
|
4457
|
-
else if (expr[start].match(/[&|!]/g)) {
|
|
4458
|
-
token = expr[start];
|
|
4459
|
-
tokenType = 'operation';
|
|
4460
|
-
}
|
|
4461
|
-
else if (expr[start] === '(') {
|
|
4462
|
-
token = '(';
|
|
4463
|
-
tokenType = '(';
|
|
4464
|
-
}
|
|
4465
|
-
else if (expr[start] === ')') {
|
|
4466
|
-
token = ')';
|
|
4467
|
-
tokenType = ')';
|
|
4468
|
-
}
|
|
4469
|
-
else if (expr[start] === ',') {
|
|
4470
|
-
token = ',';
|
|
4471
|
-
tokenType = 'function-argument';
|
|
4472
|
-
}
|
|
4473
|
-
else {
|
|
4474
|
-
token = tokenMatch[0];
|
|
4475
|
-
tokenType = 'monom';
|
|
4476
|
-
if (token === '') {
|
|
4477
|
-
token = expr[start];
|
|
4478
|
-
tokenType = 'monom';
|
|
4479
|
-
console.log('SHUTING YARD - NEXT TOKEN: error at ', start);
|
|
4480
|
-
}
|
|
4481
|
-
}
|
|
4482
|
-
return [token, start + token.length, tokenType];
|
|
4483
|
-
}
|
|
4484
4838
|
Uniformizer(expr) {
|
|
4485
4839
|
if (!this._uniformize) {
|
|
4486
4840
|
return expr;
|
|
@@ -4513,6 +4867,7 @@ class Shutingyard {
|
|
|
4513
4867
|
case 'monom':
|
|
4514
4868
|
case 'coefficient':
|
|
4515
4869
|
case 'variable':
|
|
4870
|
+
case 'constant':
|
|
4516
4871
|
outQueue.push({
|
|
4517
4872
|
token,
|
|
4518
4873
|
tokenType
|
|
@@ -4625,6 +4980,7 @@ var exports = __webpack_exports__;
|
|
|
4625
4980
|
|
|
4626
4981
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
4627
4982
|
const numeric_1 = __webpack_require__(/*! ./maths/numeric */ "./src/maths/numeric.ts");
|
|
4983
|
+
const numexp_1 = __webpack_require__(/*! ./maths/numexp */ "./src/maths/numexp.ts");
|
|
4628
4984
|
const shutingyard_1 = __webpack_require__(/*! ./maths/shutingyard */ "./src/maths/shutingyard.ts");
|
|
4629
4985
|
const random_1 = __webpack_require__(/*! ./maths/random */ "./src/maths/random/index.ts");
|
|
4630
4986
|
const coefficients_1 = __webpack_require__(/*! ./maths/coefficients */ "./src/maths/coefficients/index.ts");
|
|
@@ -4633,6 +4989,7 @@ const geometry_1 = __webpack_require__(/*! ./maths/geometry */ "./src/maths/geom
|
|
|
4633
4989
|
window.Pi = {
|
|
4634
4990
|
ShutingYard: shutingyard_1.Shutingyard,
|
|
4635
4991
|
Numeric: numeric_1.Numeric,
|
|
4992
|
+
NumExp: numexp_1.NumExp,
|
|
4636
4993
|
Fraction: coefficients_1.Fraction,
|
|
4637
4994
|
Root: coefficients_1.Nthroot,
|
|
4638
4995
|
Monom: algebra_1.Monom,
|