pimath 0.0.23 → 0.0.27

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.
Files changed (127) hide show
  1. package/dev/demo.css +3 -0
  2. package/dev/index.html +217 -53
  3. package/dev/pi.js +581 -220
  4. package/dev/pi.js.map +1 -1
  5. package/dist/pi.js +1 -1
  6. package/dist/pi.js.map +1 -1
  7. package/docs/assets/search.js +1 -1
  8. package/docs/classes/algebra.Equation.html +11 -13
  9. package/docs/classes/algebra.LinearSystem.html +1 -1
  10. package/docs/classes/algebra.Logicalset.html +3 -3
  11. package/docs/classes/algebra.Monom.html +50 -49
  12. package/docs/classes/algebra.Polynom.html +12 -25
  13. package/docs/classes/algebra.Rational.html +3 -3
  14. package/docs/classes/coefficients.Fraction.html +10 -6
  15. package/docs/classes/coefficients.Nthroot.html +3 -1
  16. package/docs/classes/geometry.Circle.html +3 -1
  17. package/docs/classes/geometry.Line.html +3 -1
  18. package/docs/classes/geometry.Point.html +1 -1
  19. package/docs/classes/geometry.Triangle.html +6 -6
  20. package/docs/classes/geometry.Vector.html +1 -1
  21. package/docs/classes/numeric.Numeric.html +5 -5
  22. package/docs/classes/shutingyard.Shutingyard.html +5 -5
  23. package/docs/index.html +1 -1
  24. package/docs/interfaces/geometry.remarquableLines.html +1 -1
  25. package/docs/modules/algebra.html +1 -1
  26. package/docs/modules/coefficients.html +1 -1
  27. package/docs/modules/geometry.html +1 -1
  28. package/docs/modules/numeric.html +1 -1
  29. package/docs/modules/random.Random.html +1 -1
  30. package/docs/modules/random.html +1 -1
  31. package/docs/modules/shutingyard.html +1 -1
  32. package/docs/modules.html +1 -1
  33. package/esm/main.js +2 -0
  34. package/esm/main.js.map +1 -1
  35. package/esm/maths/algebra/equation.d.ts +11 -5
  36. package/esm/maths/algebra/equation.js +159 -52
  37. package/esm/maths/algebra/equation.js.map +1 -1
  38. package/esm/maths/algebra/linearSystem.d.ts +3 -4
  39. package/esm/maths/algebra/linearSystem.js +2 -5
  40. package/esm/maths/algebra/linearSystem.js.map +1 -1
  41. package/esm/maths/algebra/logicalset.d.ts +2 -2
  42. package/esm/maths/algebra/logicalset.js +1 -1
  43. package/esm/maths/algebra/logicalset.js.map +1 -1
  44. package/esm/maths/algebra/monom.d.ts +5 -3
  45. package/esm/maths/algebra/monom.js +29 -2
  46. package/esm/maths/algebra/monom.js.map +1 -1
  47. package/esm/maths/algebra/polynom.d.ts +6 -6
  48. package/esm/maths/algebra/polynom.js +4 -4
  49. package/esm/maths/algebra/polynom.js.map +1 -1
  50. package/esm/maths/algebra/rational.d.ts +1 -1
  51. package/esm/maths/algebra/rational.js +2 -2
  52. package/esm/maths/algebra/rational.js.map +1 -1
  53. package/esm/maths/coefficients/fraction.d.ts +2 -2
  54. package/esm/maths/coefficients/fraction.js +1 -1
  55. package/esm/maths/coefficients/fraction.js.map +1 -1
  56. package/esm/maths/coefficients/nthroot.d.ts +1 -1
  57. package/esm/maths/coefficients/nthroot.js +4 -1
  58. package/esm/maths/coefficients/nthroot.js.map +1 -1
  59. package/esm/maths/geometry/circle.d.ts +12 -3
  60. package/esm/maths/geometry/circle.js +125 -39
  61. package/esm/maths/geometry/circle.js.map +1 -1
  62. package/esm/maths/geometry/line.d.ts +1 -2
  63. package/esm/maths/geometry/line.js +1 -4
  64. package/esm/maths/geometry/line.js.map +1 -1
  65. package/esm/maths/geometry/point.d.ts +3 -4
  66. package/esm/maths/geometry/point.js +18 -15
  67. package/esm/maths/geometry/point.js.map +1 -1
  68. package/esm/maths/geometry/triangle.d.ts +0 -1
  69. package/esm/maths/geometry/triangle.js +3 -4
  70. package/esm/maths/geometry/triangle.js.map +1 -1
  71. package/esm/maths/geometry/vector.js +2 -1
  72. package/esm/maths/geometry/vector.js.map +1 -1
  73. package/esm/maths/numexp.d.ts +11 -0
  74. package/esm/maths/numexp.js +107 -0
  75. package/esm/maths/numexp.js.map +1 -0
  76. package/esm/maths/random/rndFraction.js +4 -3
  77. package/esm/maths/random/rndFraction.js.map +1 -1
  78. package/esm/maths/random/rndMonom.d.ts +1 -1
  79. package/esm/maths/random/rndMonom.js +12 -7
  80. package/esm/maths/random/rndMonom.js.map +1 -1
  81. package/esm/maths/random/rndPolynom.js +8 -2
  82. package/esm/maths/random/rndPolynom.js.map +1 -1
  83. package/esm/maths/random/rndTypes.d.ts +3 -1
  84. package/esm/maths/shutingyard.d.ts +21 -4
  85. package/esm/maths/shutingyard.js +72 -74
  86. package/esm/maths/shutingyard.js.map +1 -1
  87. package/package.json +3 -5
  88. package/src/main.ts +2 -0
  89. package/src/maths/algebra/equation.ts +183 -73
  90. package/src/maths/algebra/linearSystem.ts +262 -265
  91. package/src/maths/algebra/logicalset.ts +3 -3
  92. package/src/maths/algebra/monom.ts +54 -35
  93. package/src/maths/algebra/polynom.ts +10 -10
  94. package/src/maths/algebra/rational.ts +1 -1
  95. package/src/maths/coefficients/fraction.ts +11 -7
  96. package/src/maths/coefficients/nthroot.ts +8 -1
  97. package/src/maths/geometry/circle.ts +160 -45
  98. package/src/maths/geometry/line.ts +4 -8
  99. package/src/maths/geometry/point.ts +25 -18
  100. package/src/maths/geometry/triangle.ts +3 -5
  101. package/src/maths/geometry/vector.ts +4 -3
  102. package/src/maths/numexp.ts +127 -0
  103. package/src/maths/random/rndFraction.ts +4 -3
  104. package/src/maths/random/rndMonom.ts +39 -35
  105. package/src/maths/random/rndPolynom.ts +13 -3
  106. package/src/maths/random/rndTypes.ts +4 -2
  107. package/src/maths/shutingyard.ts +144 -94
  108. package/tests/algebra/monom.test.ts +18 -4
  109. package/tests/algebra/polynom.test.ts +19 -4
  110. package/tests/geometry/circle.test.ts +28 -0
  111. package/tests/shutingyard.test.ts +3 -3
  112. package/tsconfig.json +4 -1
  113. package/typedoc.katex.js +11 -0
  114. package/docs/classes/algebra.Algebra.Equation.html +0 -26
  115. package/docs/classes/algebra.Algebra.LinearSystem.html +0 -1
  116. package/docs/classes/algebra.Algebra.LogicalSet.html +0 -3
  117. package/docs/classes/algebra.Algebra.Monom.html +0 -111
  118. package/docs/classes/algebra.Algebra.Polynom.html +0 -36
  119. package/docs/classes/algebra.Algebra.Rational.html +0 -2
  120. package/docs/classes/geometry.Geometry.Circle.html +0 -1
  121. package/docs/classes/geometry.Geometry.Line.html +0 -1
  122. package/docs/classes/geometry.Geometry.Point.html +0 -1
  123. package/docs/classes/geometry.Geometry.Triangle.html +0 -9
  124. package/docs/classes/geometry.Geometry.Vector.html +0 -1
  125. package/docs/modules/algebra.Algebra.html +0 -1
  126. package/docs/modules/geometry.Geometry.html +0 -1
  127. 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].isEquation === true) {
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
- this.left = (equations[0] instanceof polynom_1.Polynom) ? equations[0].clone() : new polynom_1.Polynom(equations[0]);
40
- this.right = (equations[1] instanceof polynom_1.Polynom) ? equations[1].clone() : new polynom_1.Polynom(equations[1]);
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 = (letter) => {
322
+ solve = () => {
314
323
  this._solutions = [];
315
324
  this._polynom = this._left.clone().subtract(this._right);
316
- switch (this._polynom.degree(letter).value) {
325
+ switch (this._polynom.degree().value) {
317
326
  case 0:
318
327
  case 1:
319
- this._solveDegree1(letter);
328
+ this._solveDegree1();
320
329
  break;
321
330
  case 2:
322
- this._solveDegree2(letter);
331
+ this._solveDegree2();
323
332
  break;
324
333
  default:
325
- this._solveDegree3plus(letter);
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).display;
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 = [this._real];
364
+ this._solutions = [{
365
+ tex: this._real,
366
+ value: NaN,
367
+ exact: false
368
+ }];
356
369
  }
357
370
  else {
358
- this._solutions = [this._varnothing];
371
+ this._solutions = [{
372
+ tex: this._varnothing,
373
+ value: NaN,
374
+ exact: false
375
+ }];
359
376
  }
360
377
  }
361
378
  else {
362
- this._solutions = [v];
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 = [s];
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
- ((-b - Math.sqrt(delta)) / (2 * a)).toFixed(5),
400
- ((-b + Math.sqrt(delta)) / (2 * a)).toFixed(5)
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 coefficients_2.Nthroot().parse(delta).reduce();
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
- `${-b / gcd} - ${nthDelta.tex}`,
412
- `${-b / gcd} + ${nthDelta.tex}`,
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
- `\\dfrac{${-b / gcd} - ${nthDelta.tex} }{ ${2 * a / gcd} }`,
418
- `\\dfrac{${-b / gcd} + ${nthDelta.tex} }{ ${2 * a / gcd} }`,
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
- `- ${nthDelta.tex}`,
426
- `${nthDelta.tex}`,
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
- `\\dfrac{- ${nthDelta.tex} }{ ${2 * a / gcd} }`,
432
- `\\dfrac{${nthDelta.tex} }{ ${2 * a / gcd} }`,
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
- new coefficients_1.Fraction(-b - nthDelta.coefficient, 2 * a).reduce().dfrac,
440
- new coefficients_1.Fraction(-b + nthDelta.coefficient, 2 * a).reduce().dfrac
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
- this._solutions = [new coefficients_1.Fraction(-b, 2 * a).reduce().dfrac];
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 = [this._varnothing];
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
- `\\left]-\\infty ; ${sX1}\\right${this.isAlsoEqual() ? ']' : '['} \\cup \\left${this.isAlsoEqual() ? '[' : ']'}${sX2};+\\infty\\right[`
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
- `\\left${this.isAlsoEqual() ? '[' : ']'}${sX1} ; ${sX2}\\right${this.isAlsoEqual() ? ']' : '['}`
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
- `\\left]-\\infty ; ${this._solutions[0]}\\right[ \\cup \\left]${this._solutions[0]};+\\infty\\right[`
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 = [this._varnothing];
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 = [this._real];
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 = [aF.sign() === 1 ? this._real : this._varnothing];
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 = [aF.sign() === -1 ? this._real : this._varnothing];
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 = (letter) => {
497
- this._solutions = [letter];
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 texSolution() {
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('set').parse(value).rpn;
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
- this._shutingYardToReducedMonom(inputStr);
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) >= degreeP && MaxIteration.isPositive()) {
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.isFraction) {
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 fraction_1 = __webpack_require__(/*! ../coefficients/fraction */ "./src/maths/coefficients/fraction.ts");
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 fraction_1.Fraction(value) }).divide(this._denominator.evaluate({ letter: new fraction_1.Fraction(value) }));
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.isFraction) {
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
- let cx, cy;
2964
- if (this._center.x.isZero()) {
2965
- cx = 'x^2';
2966
- }
2967
- else {
2968
- cx = `\\left(x${this._center.x.isNegative() ? '+' : '-'}${this._center.x.clone().abs().tex}\\right)^2`;
2969
- }
2970
- if (this._center.y.isZero()) {
2971
- cy = 'y^2';
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
- cy = `\\left(y${this._center.y.isNegative() ? '+' : '-'}${this._center.y.clone().abs().tex}\\right)^2`;
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
- if (values.length === 1 && typeof values[0] === 'string') {
2989
- this.checkCircle(new algebra_1.Equation(values[0]));
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.length >= 2) {
2992
- this._center = new point_1.Point(values[0]);
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
- this._squareRadius = new vector_1.Vector(this._center, values[1]).normSquare;
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._radius = new coefficients_1.Fraction(values[1]);
3002
- this._squareRadius = this._radius.clone().pow(2);
3162
+ this._parseCenterAndPointThrough(values[0], values[1]);
3003
3163
  }
3004
3164
  }
3005
- 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();
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
- checkCircle = (P) => {
3009
- if (P.degree('x').value === 2 && P.degree('y').value === 2) {
3010
- let x2 = P.left.monomByDegree(2, 'x'), y2 = P.left.monomByDegree(2, 'y'), x1, y1, c;
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
- P.divide(x2.coefficient);
3013
- x1 = P.left.monomByDegree(1, 'x');
3014
- y1 = P.left.monomByDegree(1, 'y');
3015
- c = P.left.monomByDegree(0);
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 false;
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 P1, P2;
3038
- const equ = this._cartesian.clone(), yLine = L.equation.clone().isolate('y');
3039
- if (yLine instanceof algebra_1.Equation) {
3040
- equ.replaceBy('y', yLine.right);
3041
- equ.solve();
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
  }
@@ -3220,6 +3437,14 @@ class Line {
3220
3437
  (values[2] instanceof coefficients_1.Fraction || typeof values[2] === 'number')) {
3221
3438
  return this.parseByCoefficient(values[0], values[1], values[2]);
3222
3439
  }
3440
+ else if (values[0] instanceof point_1.Point && values[1] instanceof vector_1.Vector) {
3441
+ if (values[2] === LinePropriety.Perpendicular) {
3442
+ return this.parseByPointAndNormal(values[0], values[1]);
3443
+ }
3444
+ else if (values[2] === LinePropriety.Parallel) {
3445
+ return this.parseByPointAndVector(values[0], values[1]);
3446
+ }
3447
+ }
3223
3448
  }
3224
3449
  console.log('Someting wrong happend while creating the line');
3225
3450
  return this;
@@ -3291,6 +3516,11 @@ class Line {
3291
3516
  isSameAs = (line) => {
3292
3517
  return this.slope.isEqual(line.slope) && this.height.isEqual(line.height);
3293
3518
  };
3519
+ simplify = () => {
3520
+ let lcm = numeric_1.Numeric.lcm(this._a.denominator, this._b.denominator, this._c.denominator), gcd = numeric_1.Numeric.gcd(this._a.numerator, this._b.numerator, this._c.numerator);
3521
+ this.parseByCoefficient(this._a.clone().multiply(lcm).divide(gcd), this._b.clone().multiply(lcm).divide(gcd), this._c.clone().multiply(lcm).divide(gcd));
3522
+ return this;
3523
+ };
3294
3524
  simplifyDirection = () => {
3295
3525
  let lcm = numeric_1.Numeric.lcm(this._d.x.denominator, this._d.y.denominator), gcd = numeric_1.Numeric.gcd(this._d.x.numerator, this._d.y.numerator);
3296
3526
  this._d.x.multiply(lcm).divide(gcd);
@@ -3360,16 +3590,16 @@ class Line {
3360
3590
  return false;
3361
3591
  }
3362
3592
  getValueAtX = (value) => {
3363
- const equ = this.equation.clone().isolate('y');
3593
+ const equ = this.equation.clone().isolate('y'), F = new coefficients_1.Fraction(value);
3364
3594
  if (equ instanceof algebra_1.Equation) {
3365
- return equ.right.evaluate({ x: value });
3595
+ return equ.right.evaluate({ x: F });
3366
3596
  }
3367
3597
  return;
3368
3598
  };
3369
3599
  getValueAtY = (value) => {
3370
- const equ = this.equation.clone().isolate('x');
3600
+ const equ = this.equation.clone().isolate('x'), F = new coefficients_1.Fraction(value);
3371
3601
  if (equ instanceof algebra_1.Equation) {
3372
- return equ.right.evaluate({ y: value });
3602
+ return equ.right.evaluate({ y: F });
3373
3603
  }
3374
3604
  return;
3375
3605
  };
@@ -3418,23 +3648,24 @@ exports.Line = Line;
3418
3648
 
3419
3649
  Object.defineProperty(exports, "__esModule", ({ value: true }));
3420
3650
  exports.Point = void 0;
3421
- const fraction_1 = __webpack_require__(/*! ../coefficients/fraction */ "./src/maths/coefficients/fraction.ts");
3651
+ const coefficients_1 = __webpack_require__(/*! ../coefficients */ "./src/maths/coefficients/index.ts");
3652
+ class PointXY {
3653
+ x;
3654
+ y;
3655
+ }
3422
3656
  class Point {
3423
3657
  _x;
3424
3658
  _y;
3425
3659
  _exist;
3426
3660
  constructor(...values) {
3427
- this._x = new fraction_1.Fraction().zero();
3428
- this._y = new fraction_1.Fraction().zero();
3661
+ this._x = new coefficients_1.Fraction().zero();
3662
+ this._y = new coefficients_1.Fraction().zero();
3429
3663
  if (values !== undefined) {
3430
3664
  this.parse(...values);
3431
3665
  }
3432
3666
  return this;
3433
3667
  }
3434
3668
  ;
3435
- get isPoint() {
3436
- return true;
3437
- }
3438
3669
  get x() {
3439
3670
  return this._x;
3440
3671
  }
@@ -3473,22 +3704,24 @@ class Point {
3473
3704
  if (typeof values[0] === 'string') {
3474
3705
  let xy = values[0].split(',');
3475
3706
  if (xy.length === 2) {
3476
- this._x = new fraction_1.Fraction(xy[0]).reduce();
3477
- this._y = new fraction_1.Fraction(xy[1]).reduce();
3707
+ this._x = new coefficients_1.Fraction(xy[0]).reduce();
3708
+ this._y = new coefficients_1.Fraction(xy[1]).reduce();
3478
3709
  return this;
3479
3710
  }
3480
3711
  }
3481
- if (values[0].x !== undefined && values[0].y !== undefined) {
3482
- this._x = new fraction_1.Fraction(values[0].x).reduce();
3483
- this._y = new fraction_1.Fraction(values[0].y).reduce();
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;
3484
3716
  }
3485
3717
  else {
3486
3718
  return this.zero();
3487
3719
  }
3488
3720
  }
3489
3721
  if (values.length === 2) {
3490
- this._x = new fraction_1.Fraction(values[0]).reduce();
3491
- this._y = new fraction_1.Fraction(values[1]).reduce();
3722
+ this._x = new coefficients_1.Fraction(values[0]).reduce();
3723
+ this._y = new coefficients_1.Fraction(values[1]).reduce();
3724
+ return this;
3492
3725
  }
3493
3726
  return this;
3494
3727
  };
@@ -3498,8 +3731,8 @@ class Point {
3498
3731
  return this;
3499
3732
  };
3500
3733
  zero = () => {
3501
- this._x = new fraction_1.Fraction(null);
3502
- this._y = new fraction_1.Fraction(null);
3734
+ this._x = new coefficients_1.Fraction(null);
3735
+ this._y = new coefficients_1.Fraction(null);
3503
3736
  return this;
3504
3737
  };
3505
3738
  origin = () => {
@@ -3558,7 +3791,6 @@ class Triangle {
3558
3791
  }
3559
3792
  return this;
3560
3793
  }
3561
- get isTriangle() { return true; }
3562
3794
  get A() {
3563
3795
  return this._A;
3564
3796
  }
@@ -3622,7 +3854,7 @@ class Triangle {
3622
3854
  if (values.filter((x) => typeof x === 'string').length === 3) {
3623
3855
  return this.parse(...values.map((x) => new line_1.Line(x)));
3624
3856
  }
3625
- else if (values.filter((x) => x.isLine === true).length === 3) {
3857
+ else if (values.filter((x) => x instanceof line_1.Line).length === 3) {
3626
3858
  this._lines = {
3627
3859
  'AB': values[0],
3628
3860
  'BC': values[1],
@@ -3651,7 +3883,7 @@ class Triangle {
3651
3883
  }
3652
3884
  }
3653
3885
  else {
3654
- if (values.filter((x) => x.isPoint === true).length < 3) {
3886
+ if (values.filter((x) => (x instanceof point_1.Point)).length < 3) {
3655
3887
  return this.parse(new point_1.Point(values[0]), new point_1.Point(values[1]), new point_1.Point(values[2]));
3656
3888
  }
3657
3889
  this._A = values[0].clone();
@@ -3665,7 +3897,7 @@ class Triangle {
3665
3897
  }
3666
3898
  }
3667
3899
  else if (values.length === 1) {
3668
- if (values[0].isTriangle === true) {
3900
+ if (values[0] instanceof Triangle) {
3669
3901
  return values[0].clone();
3670
3902
  }
3671
3903
  }
@@ -3782,6 +4014,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
3782
4014
  exports.Vector = void 0;
3783
4015
  const fraction_1 = __webpack_require__(/*! ../coefficients/fraction */ "./src/maths/coefficients/fraction.ts");
3784
4016
  const numeric_1 = __webpack_require__(/*! ../numeric */ "./src/maths/numeric.ts");
4017
+ const point_1 = __webpack_require__(/*! ./point */ "./src/maths/geometry/point.ts");
3785
4018
  class Vector {
3786
4019
  _x;
3787
4020
  _y;
@@ -3828,7 +4061,7 @@ class Vector {
3828
4061
  }
3829
4062
  }
3830
4063
  if (values.length >= 2) {
3831
- if (values[0].isPoint && values[1].isPoint) {
4064
+ if (values[0] instanceof point_1.Point && values[1] instanceof point_1.Point) {
3832
4065
  this._x = values[1].x.clone().subtract(values[0].x);
3833
4066
  this._y = values[1].y.clone().subtract(values[0].y);
3834
4067
  return this;
@@ -4001,6 +4234,122 @@ class Numeric {
4001
4234
  exports.Numeric = Numeric;
4002
4235
 
4003
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
+ _extractDecimalPart(value) {
4258
+ let decimal = value.toString();
4259
+ if (!decimal.includes('.')) {
4260
+ return '';
4261
+ }
4262
+ decimal = decimal.split('.')[1];
4263
+ return decimal.substring(0, decimal.length - 2);
4264
+ }
4265
+ _numberCorrection(value) {
4266
+ const omega = 0.00000000000001, number_of_digits = 6;
4267
+ let decimal = this._extractDecimalPart(value);
4268
+ const n9 = decimal.match(/9+$/g);
4269
+ const n0 = decimal.match(/0+$/g);
4270
+ if (n9 && n9[0].length >= number_of_digits) {
4271
+ let mod = this._extractDecimalPart(value + omega), mod0 = mod.match(/0+$/g);
4272
+ if (mod0 && mod0[0].length >= number_of_digits) {
4273
+ return +((value + omega).toString().split(mod0[0])[0]);
4274
+ }
4275
+ }
4276
+ if (n0 && n0[0].length >= number_of_digits) {
4277
+ let mod = this._extractDecimalPart(value - omega), mod9 = mod.match(/9+$/g);
4278
+ if (mod9 && mod9[0].length >= number_of_digits) {
4279
+ return +((value - omega).toString().split(mod9[0])[0]);
4280
+ }
4281
+ }
4282
+ return value;
4283
+ }
4284
+ _addToStack(stack, value) {
4285
+ stack.push(this._numberCorrection(value));
4286
+ }
4287
+ evaluate(values) {
4288
+ let stack = [];
4289
+ for (const element of this._rpn) {
4290
+ if (element.tokenType === shutingyard_1.ShutingyardType.COEFFICIENT) {
4291
+ if (!isNaN(+element.token)) {
4292
+ this._addToStack(stack, +element.token);
4293
+ }
4294
+ else {
4295
+ this._addToStack(stack, new coefficients_1.Fraction(element.token).value);
4296
+ }
4297
+ }
4298
+ else if (element.tokenType === shutingyard_1.ShutingyardType.VARIABLE) {
4299
+ if (values[element.token] !== undefined) {
4300
+ this._addToStack(stack, +values[element.token]);
4301
+ }
4302
+ }
4303
+ else if (element.tokenType === shutingyard_1.ShutingyardType.CONSTANT) {
4304
+ this._addToStack(stack, shutingyard_1.tokenConstant[element.token]);
4305
+ }
4306
+ else if (element.tokenType === shutingyard_1.ShutingyardType.OPERATION) {
4307
+ if (element.token === '*') {
4308
+ const b = +stack.pop(), a = +stack.pop();
4309
+ this._addToStack(stack, a * b);
4310
+ }
4311
+ else if (element.token === '/') {
4312
+ const b = +stack.pop(), a = +stack.pop();
4313
+ this._addToStack(stack, a / b);
4314
+ }
4315
+ else if (element.token === '+') {
4316
+ const b = +stack.pop(), a = +stack.pop();
4317
+ this._addToStack(stack, a + b);
4318
+ }
4319
+ else if (element.token === '-') {
4320
+ const b = +stack.pop(), a = +stack.pop();
4321
+ this._addToStack(stack, a - b);
4322
+ }
4323
+ else if (element.token === '^') {
4324
+ const b = +stack.pop(), a = +stack.pop();
4325
+ this._addToStack(stack, Math.pow(a, b));
4326
+ }
4327
+ }
4328
+ else if (element.tokenType === shutingyard_1.ShutingyardType.FUNCTION) {
4329
+ const a = +stack.pop();
4330
+ if (element.token === 'sin') {
4331
+ this._addToStack(stack, Math.sin(a));
4332
+ }
4333
+ else if (element.token === 'cos') {
4334
+ this._addToStack(stack, Math.cos(a));
4335
+ }
4336
+ else if (element.token === 'tan') {
4337
+ this._addToStack(stack, Math.tan(a));
4338
+ }
4339
+ }
4340
+ }
4341
+ if (stack.length === 1) {
4342
+ return stack[0];
4343
+ }
4344
+ else {
4345
+ console.error('There was a problem parsing', this._expression, '. The RPN array is', this._rpn);
4346
+ return 0;
4347
+ }
4348
+ }
4349
+ }
4350
+ exports.NumExp = NumExp;
4351
+
4352
+
4004
4353
  /***/ }),
4005
4354
 
4006
4355
  /***/ "./src/maths/random/index.ts":
@@ -4118,6 +4467,7 @@ class rndFraction extends randomCore_1.randomCore {
4118
4467
  super();
4119
4468
  this._defaultConfig = {
4120
4469
  negative: true,
4470
+ max: 10,
4121
4471
  reduced: true,
4122
4472
  zero: true,
4123
4473
  natural: false
@@ -4127,16 +4477,16 @@ class rndFraction extends randomCore_1.randomCore {
4127
4477
  generate = () => {
4128
4478
  let Q = new coefficients_1.Fraction();
4129
4479
  if (this._config.negative) {
4130
- Q.numerator = index_1.Random.numberSym(10, this._config.zero);
4480
+ Q.numerator = index_1.Random.numberSym(this._config.max, this._config.zero);
4131
4481
  }
4132
4482
  else {
4133
- Q.numerator = index_1.Random.number(this._config.zero ? 0 : 1, 10);
4483
+ Q.numerator = index_1.Random.number(this._config.zero ? 0 : 1, this._config.max);
4134
4484
  }
4135
4485
  if (this._config.natural) {
4136
4486
  Q.denominator = 1;
4137
4487
  }
4138
4488
  else {
4139
- Q.denominator = index_1.Random.number(1, 10);
4489
+ Q.denominator = index_1.Random.number(1, this._config.max);
4140
4490
  }
4141
4491
  return this._config.reduced ? Q.reduce() : Q;
4142
4492
  };
@@ -4215,7 +4565,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
4215
4565
  exports.rndMonom = void 0;
4216
4566
  const randomCore_1 = __webpack_require__(/*! ./randomCore */ "./src/maths/random/randomCore.ts");
4217
4567
  const index_1 = __webpack_require__(/*! ./index */ "./src/maths/random/index.ts");
4218
- const monom_1 = __webpack_require__(/*! ../algebra/monom */ "./src/maths/algebra/monom.ts");
4568
+ const algebra_1 = __webpack_require__(/*! ../algebra */ "./src/maths/algebra/index.ts");
4219
4569
  class rndMonom extends randomCore_1.randomCore {
4220
4570
  constructor(userConfig) {
4221
4571
  super();
@@ -4228,12 +4578,17 @@ class rndMonom extends randomCore_1.randomCore {
4228
4578
  this._config = this.mergeConfig(userConfig, this._defaultConfig);
4229
4579
  }
4230
4580
  generate = () => {
4231
- let M = new monom_1.Monom();
4232
- M.coefficient = index_1.Random.fraction({
4233
- zero: this._config.zero,
4234
- reduced: true,
4235
- natural: !this._config.fraction
4236
- });
4581
+ let M = new algebra_1.Monom();
4582
+ if (typeof this._config.fraction === "boolean") {
4583
+ M.coefficient = index_1.Random.fraction({
4584
+ zero: this._config.zero,
4585
+ reduced: true,
4586
+ natural: !this._config.fraction
4587
+ });
4588
+ }
4589
+ else {
4590
+ M.coefficient = index_1.Random.fraction(this._config.fraction);
4591
+ }
4237
4592
  if (this._config.letters.length > 1) {
4238
4593
  for (let L of this._config.letters.split('')) {
4239
4594
  M.setLetter(L, 0);
@@ -4278,7 +4633,8 @@ class rndPolynom extends randomCore_1.randomCore {
4278
4633
  unit: false,
4279
4634
  factorable: false,
4280
4635
  allowNullMonom: true,
4281
- numberOfMonoms: 0
4636
+ numberOfMonoms: 0,
4637
+ positive: true
4282
4638
  };
4283
4639
  this._config = this.mergeConfig(userConfig, this._defaultConfig);
4284
4640
  }
@@ -4299,8 +4655,13 @@ class rndPolynom extends randomCore_1.randomCore {
4299
4655
  }
4300
4656
  P.add(M);
4301
4657
  }
4658
+ if (this._config.positive && P.monomByDegree().coefficient.isNegative()) {
4659
+ P.monomByDegree().coefficient.opposed();
4660
+ }
4302
4661
  if (this._config.numberOfMonoms > 0 && this._config.numberOfMonoms < P.length) {
4303
- P.monoms = index_1.Random.array(P.monoms, this._config.numberOfMonoms);
4662
+ let M = P.monomByDegree().clone();
4663
+ P.monoms = index_1.Random.array(P.monoms.slice(1), this._config.numberOfMonoms - 1);
4664
+ P.add(M).reorder().reduce();
4304
4665
  }
4305
4666
  return P;
4306
4667
  };
@@ -4340,46 +4701,75 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
4340
4701
 
4341
4702
 
4342
4703
  Object.defineProperty(exports, "__esModule", ({ value: true }));
4343
- exports.Shutingyard = void 0;
4704
+ exports.Shutingyard = exports.ShutingyardMode = exports.ShutingyardType = exports.tokenConstant = void 0;
4705
+ exports.tokenConstant = {
4706
+ pi: Math.PI,
4707
+ e: Math.exp(1)
4708
+ };
4709
+ var ShutingyardType;
4710
+ (function (ShutingyardType) {
4711
+ ShutingyardType["VARIABLE"] = "variable";
4712
+ ShutingyardType["COEFFICIENT"] = "coefficient";
4713
+ ShutingyardType["OPERATION"] = "operation";
4714
+ ShutingyardType["CONSTANT"] = "constant";
4715
+ ShutingyardType["FUNCTION"] = "function";
4716
+ ShutingyardType["MONOM"] = "monom";
4717
+ })(ShutingyardType = exports.ShutingyardType || (exports.ShutingyardType = {}));
4718
+ var ShutingyardMode;
4719
+ (function (ShutingyardMode) {
4720
+ ShutingyardMode["POLYNOM"] = "polynom";
4721
+ ShutingyardMode["SET"] = "set";
4722
+ ShutingyardMode["NUMERIC"] = "numeric";
4723
+ })(ShutingyardMode = exports.ShutingyardMode || (exports.ShutingyardMode = {}));
4344
4724
  class Shutingyard {
4345
4725
  _rpn = [];
4346
4726
  _mode;
4347
4727
  _tokenConfig;
4728
+ _tokenConstant;
4348
4729
  _uniformize;
4730
+ _tokenKeys;
4349
4731
  constructor(mode) {
4350
- this._mode = typeof mode === 'undefined' ? 'polynom' : mode;
4732
+ this._mode = typeof mode === 'undefined' ? ShutingyardMode.POLYNOM : mode;
4351
4733
  this.tokenConfigInitialization();
4352
4734
  }
4353
- isOperation(token) {
4354
- if (token[0].match(/[+\-*/^]/g)) {
4355
- return true;
4356
- }
4357
- return false;
4358
- }
4359
4735
  tokenConfigInitialization() {
4360
- if (this._mode === 'set') {
4736
+ if (this._mode === ShutingyardMode.SET) {
4361
4737
  this._tokenConfig = {
4362
- '&': { precedence: 3, associative: 'left' },
4363
- '|': { precedence: 3, associative: 'left' },
4364
- '!': { precedence: 4, associative: 'right' },
4365
- '-': { precedence: 2, associative: 'left' }
4738
+ '&': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
4739
+ '|': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
4740
+ '!': { precedence: 4, associative: 'right', type: ShutingyardType.OPERATION },
4741
+ '-': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION }
4366
4742
  };
4367
4743
  this._uniformize = false;
4368
4744
  }
4745
+ else if (this._mode === ShutingyardMode.NUMERIC) {
4746
+ this._tokenConfig = {
4747
+ '^': { precedence: 4, associative: 'right', type: ShutingyardType.OPERATION },
4748
+ '*': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
4749
+ '/': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
4750
+ '+': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
4751
+ '-': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
4752
+ '%': { precedence: 3, associative: 'right', type: ShutingyardType.OPERATION },
4753
+ 'sin': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
4754
+ 'cos': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
4755
+ 'tan': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
4756
+ };
4757
+ }
4369
4758
  else {
4370
4759
  this._tokenConfig = {
4371
- '^': { precedence: 4, associative: 'right' },
4372
- '*': { precedence: 3, associative: 'left' },
4373
- '/': { precedence: 3, associative: 'left' },
4374
- '+': { precedence: 2, associative: 'left' },
4375
- '-': { precedence: 2, associative: 'left' },
4376
- '%': { precedence: 3, associative: 'right' },
4377
- 'sin': { precedence: 4, associative: 'right' },
4378
- 'cos': { precedence: 4, associative: 'right' },
4379
- 'tab': { precedence: 4, associative: 'right' },
4760
+ '^': { precedence: 4, associative: 'right', type: ShutingyardType.OPERATION },
4761
+ '*': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
4762
+ '/': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
4763
+ '+': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
4764
+ '-': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
4765
+ '%': { precedence: 3, associative: 'right', type: ShutingyardType.OPERATION },
4766
+ 'sin': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
4767
+ 'cos': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
4768
+ 'tan': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
4380
4769
  };
4381
4770
  this._uniformize = true;
4382
4771
  }
4772
+ this._tokenKeys = Object.keys(this._tokenConfig).sort((a, b) => b.length - a.length);
4383
4773
  return this._tokenConfig;
4384
4774
  }
4385
4775
  NextToken2(expr, start) {
@@ -4399,75 +4789,43 @@ class Shutingyard {
4399
4789
  tokenType = 'function-argument';
4400
4790
  }
4401
4791
  else {
4402
- const keys = Object.keys(this._tokenConfig).sort((a, b) => b.length - a.length);
4403
- for (let key of keys) {
4404
- if (expr.substr(start, key.length) === key) {
4792
+ for (let key of this._tokenKeys) {
4793
+ if (expr.substring(start, start + key.length) === key) {
4794
+ token += key;
4795
+ tokenType = this._tokenConfig[key].type;
4796
+ break;
4797
+ }
4798
+ }
4799
+ for (let key in exports.tokenConstant) {
4800
+ if (expr.substring(start, start + key.length) === key) {
4405
4801
  token += key;
4406
- tokenType = 'operation';
4802
+ tokenType = ShutingyardType.CONSTANT;
4407
4803
  break;
4408
4804
  }
4409
4805
  }
4410
4806
  if (token === '') {
4411
4807
  if (expr[start].match(/[0-9]/)) {
4412
- token = expr.substr(start).match(/^([0-9.,/]+)/)[0];
4413
- tokenType = 'coefficient';
4808
+ if (this._mode === ShutingyardMode.POLYNOM) {
4809
+ token = expr.substring(start).match(/^([0-9.,/]+)/)[0];
4810
+ }
4811
+ else {
4812
+ token = expr.substring(start).match(/^([0-9.,]+)/)[0];
4813
+ }
4814
+ tokenType = ShutingyardType.COEFFICIENT;
4414
4815
  }
4415
4816
  else if (expr[start].match(/[a-zA-Z]/)) {
4416
- token = expr.substr(start).match(/^([a-zA-Z])/)[0];
4417
- tokenType = 'variable';
4817
+ token = expr.substring(start).match(/^([a-zA-Z])/)[0];
4818
+ tokenType = ShutingyardType.VARIABLE;
4418
4819
  }
4419
4820
  else {
4420
4821
  console.log('Unidentified token', expr[start], expr, start);
4421
4822
  token = expr[start];
4422
- tokenType = 'monom';
4823
+ tokenType = ShutingyardType.MONOM;
4423
4824
  }
4424
4825
  }
4425
4826
  }
4426
4827
  return [token, start + token.length, tokenType];
4427
4828
  }
4428
- NextToken(expr, start) {
4429
- let tokenMatch, token, tokenType;
4430
- this.NextToken2(expr, start);
4431
- tokenMatch = (expr.substr(start).match(/^[0-9/a-zA-Z^]+/g)) || [];
4432
- if (expr.substr(start, start + 3).match(/^(sin|cos|tan)/g)) {
4433
- token = expr.substr(start, 3);
4434
- tokenType = 'function';
4435
- }
4436
- else if (tokenMatch.length > 0) {
4437
- token = tokenMatch[0];
4438
- tokenType = 'monom';
4439
- }
4440
- else if (expr[start].match(/[+\-*/^]/g)) {
4441
- token = expr[start];
4442
- tokenType = 'operation';
4443
- }
4444
- else if (expr[start].match(/[&|!]/g)) {
4445
- token = expr[start];
4446
- tokenType = 'operation';
4447
- }
4448
- else if (expr[start] === '(') {
4449
- token = '(';
4450
- tokenType = '(';
4451
- }
4452
- else if (expr[start] === ')') {
4453
- token = ')';
4454
- tokenType = ')';
4455
- }
4456
- else if (expr[start] === ',') {
4457
- token = ',';
4458
- tokenType = 'function-argument';
4459
- }
4460
- else {
4461
- token = tokenMatch[0];
4462
- tokenType = 'monom';
4463
- if (token === '') {
4464
- token = expr[start];
4465
- tokenType = 'monom';
4466
- console.log('SHUTING YARD - NEXT TOKEN: error at ', start);
4467
- }
4468
- }
4469
- return [token, start + token.length, tokenType];
4470
- }
4471
4829
  Uniformizer(expr) {
4472
4830
  if (!this._uniformize) {
4473
4831
  return expr;
@@ -4500,6 +4858,7 @@ class Shutingyard {
4500
4858
  case 'monom':
4501
4859
  case 'coefficient':
4502
4860
  case 'variable':
4861
+ case 'constant':
4503
4862
  outQueue.push({
4504
4863
  token,
4505
4864
  tokenType
@@ -4612,6 +4971,7 @@ var exports = __webpack_exports__;
4612
4971
 
4613
4972
  Object.defineProperty(exports, "__esModule", ({ value: true }));
4614
4973
  const numeric_1 = __webpack_require__(/*! ./maths/numeric */ "./src/maths/numeric.ts");
4974
+ const numexp_1 = __webpack_require__(/*! ./maths/numexp */ "./src/maths/numexp.ts");
4615
4975
  const shutingyard_1 = __webpack_require__(/*! ./maths/shutingyard */ "./src/maths/shutingyard.ts");
4616
4976
  const random_1 = __webpack_require__(/*! ./maths/random */ "./src/maths/random/index.ts");
4617
4977
  const coefficients_1 = __webpack_require__(/*! ./maths/coefficients */ "./src/maths/coefficients/index.ts");
@@ -4620,6 +4980,7 @@ const geometry_1 = __webpack_require__(/*! ./maths/geometry */ "./src/maths/geom
4620
4980
  window.Pi = {
4621
4981
  ShutingYard: shutingyard_1.Shutingyard,
4622
4982
  Numeric: numeric_1.Numeric,
4983
+ NumExp: numexp_1.NumExp,
4623
4984
  Fraction: coefficients_1.Fraction,
4624
4985
  Root: coefficients_1.Nthroot,
4625
4986
  Monom: algebra_1.Monom,