pimath 0.0.28 → 0.0.32

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 (96) hide show
  1. package/dev/pi.js +864 -487
  2. package/dev/pi.js.map +1 -1
  3. package/dist/pi.js +1 -1
  4. package/dist/pi.js.map +1 -1
  5. package/docs/assets/search.js +1 -1
  6. package/docs/classes/algebra.Equation.html +9 -9
  7. package/docs/classes/algebra.LinearSystem.html +1 -1
  8. package/docs/classes/algebra.Logicalset.html +2 -2
  9. package/docs/classes/algebra.Monom.html +42 -40
  10. package/docs/classes/algebra.Polynom.html +10 -10
  11. package/docs/classes/algebra.PolynomExpFactor.html +1 -0
  12. package/docs/classes/algebra.PolynomExpProduct.html +1 -0
  13. package/docs/classes/algebra.Rational.html +2 -2
  14. package/docs/classes/coefficients.Fraction.html +4 -4
  15. package/docs/classes/coefficients.Nthroot.html +1 -1
  16. package/docs/classes/geometry.Circle.html +2 -2
  17. package/docs/classes/geometry.Line.html +2 -2
  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 +7 -8
  23. package/docs/enums/shutingyard.ShutingyardMode.html +1 -0
  24. package/docs/enums/shutingyard.ShutingyardType.html +1 -0
  25. package/docs/index.html +1 -1
  26. package/docs/interfaces/geometry.remarquableLines.html +1 -1
  27. package/docs/modules/algebra.html +1 -1
  28. package/docs/modules/coefficients.html +1 -1
  29. package/docs/modules/geometry.html +1 -1
  30. package/docs/modules/numeric.html +1 -1
  31. package/docs/modules/random.Random.html +1 -1
  32. package/docs/modules/random.html +1 -1
  33. package/docs/modules/shutingyard.html +1 -1
  34. package/docs/modules.html +1 -1
  35. package/esm/main.js +3 -1
  36. package/esm/main.js.map +1 -1
  37. package/esm/maths/algebra/equation.js +1 -1
  38. package/esm/maths/algebra/equation.js.map +1 -1
  39. package/esm/maths/algebra/index.d.ts +1 -0
  40. package/esm/maths/algebra/index.js +1 -0
  41. package/esm/maths/algebra/index.js.map +1 -1
  42. package/esm/maths/algebra/monom.d.ts +4 -1
  43. package/esm/maths/algebra/monom.js +52 -37
  44. package/esm/maths/algebra/monom.js.map +1 -1
  45. package/esm/maths/algebra/polynom.d.ts +19 -15
  46. package/esm/maths/algebra/polynom.js +242 -174
  47. package/esm/maths/algebra/polynom.js.map +1 -1
  48. package/esm/maths/coefficients/fraction.d.ts +3 -0
  49. package/esm/maths/coefficients/fraction.js +21 -8
  50. package/esm/maths/coefficients/fraction.js.map +1 -1
  51. package/esm/maths/{numexp.d.ts → expressions/numexp.d.ts} +3 -0
  52. package/esm/maths/{numexp.js → expressions/numexp.js} +46 -15
  53. package/esm/maths/expressions/numexp.js.map +1 -0
  54. package/esm/maths/expressions/polynomexp.bkp.d.ts +33 -0
  55. package/esm/maths/expressions/polynomexp.bkp.js +186 -0
  56. package/esm/maths/expressions/polynomexp.bkp.js.map +1 -0
  57. package/esm/maths/expressions/polynomexp.d.ts +52 -0
  58. package/esm/maths/expressions/polynomexp.js +233 -0
  59. package/esm/maths/expressions/polynomexp.js.map +1 -0
  60. package/esm/maths/geometry/line.d.ts +4 -2
  61. package/esm/maths/geometry/line.js +6 -2
  62. package/esm/maths/geometry/line.js.map +1 -1
  63. package/esm/maths/geometry/vector.js +7 -2
  64. package/esm/maths/geometry/vector.js.map +1 -1
  65. package/esm/maths/shutingyard.d.ts +7 -7
  66. package/esm/maths/shutingyard.js +5 -7
  67. package/esm/maths/shutingyard.js.map +1 -1
  68. package/package.json +1 -1
  69. package/{dev → public}/demo.css +0 -0
  70. package/{dev → public}/index.html +48 -14
  71. package/{dev → public}/playground.html +1 -1
  72. package/src/main.ts +13 -2
  73. package/src/maths/algebra/equation.ts +1 -1
  74. package/src/maths/algebra/index.ts +2 -1
  75. package/src/maths/algebra/monom.ts +71 -49
  76. package/src/maths/algebra/polynom.ts +432 -309
  77. package/src/maths/coefficients/fraction.ts +28 -11
  78. package/src/maths/{numexp.ts → expressions/numexp.ts} +42 -20
  79. package/src/maths/expressions/polynomexp.bkp.ts +223 -0
  80. package/src/maths/expressions/polynomexp.ts +309 -0
  81. package/src/maths/geometry/line.ts +7 -2
  82. package/src/maths/geometry/vector.ts +10 -2
  83. package/src/maths/shutingyard.ts +15 -64
  84. package/tests/algebra/monom.test.ts +12 -8
  85. package/tests/algebra/polynom.test.ts +28 -2
  86. package/tests/numexp.test.ts +34 -0
  87. package/tests/polynomexp.test.ts +15 -0
  88. package/tests/shutingyard.test.ts +4 -4
  89. package/tsconfig.json +0 -1
  90. package/esm/docs.d.ts +0 -6
  91. package/esm/docs.js +0 -7
  92. package/esm/docs.js.map +0 -1
  93. package/esm/maths/numexp.js.map +0 -1
  94. package/esm/maths/random/random.d.ts +0 -13
  95. package/esm/maths/random/random.js +0 -27
  96. package/esm/maths/random/random.js.map +0 -1
@@ -2,7 +2,7 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Getting Started</title>
5
- <script src="pi.js"></script>
5
+ <script src="../dev/pi.js"></script>
6
6
 
7
7
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css" integrity="sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFgW6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X" crossorigin="anonymous">
8
8
 
package/src/main.ts CHANGED
@@ -1,9 +1,18 @@
1
1
  import {Numeric} from "./maths/numeric";
2
- import {NumExp} from "./maths/numexp";
2
+ import {NumExp} from "./maths/expressions/numexp";
3
3
  import {Shutingyard} from "./maths/shutingyard";
4
4
  import {Random} from "./maths/random";
5
5
  import {Fraction, Nthroot} from "./maths/coefficients";
6
- import {Monom, Polynom, Equation, LinearSystem, Rational, Logicalset} from "./maths/algebra";
6
+ import {
7
+ Monom,
8
+ Polynom,
9
+ Equation,
10
+ LinearSystem,
11
+ Rational,
12
+ Logicalset,
13
+ PolynomExpFactor,
14
+ PolynomExpProduct
15
+ } from "./maths/algebra";
7
16
  import {Line, Circle, Triangle, Point, Vector} from "./maths/geometry";
8
17
 
9
18
  // Expose as global
@@ -21,6 +30,8 @@ import {Line, Circle, Triangle, Point, Vector} from "./maths/geometry";
21
30
  Rational: Rational,
22
31
  Logicalset: Logicalset,
23
32
  Random: Random,
33
+ PolynomExpFactor: PolynomExpFactor,
34
+ PolynomExpProduct: PolynomExpProduct,
24
35
  Geometry: {
25
36
  Vector: Vector,
26
37
  Point: Point,
@@ -165,7 +165,7 @@ export class Equation {
165
165
  strSign = this._findSign(equationString);
166
166
 
167
167
  if (strSign === false) {
168
- console.log('The equation is not valid (no sign found)');
168
+ console.error('The equation is not valid (no sign found)');
169
169
  return;
170
170
  }
171
171
 
@@ -3,4 +3,5 @@ export * from "./linearSystem"
3
3
  export * from "./logicalset"
4
4
  export * from "./monom"
5
5
  export * from "./polynom"
6
- export * from "./rational"
6
+ export * from "./rational"
7
+ export * from "./../expressions/polynomexp"
@@ -3,7 +3,8 @@
3
3
  */
4
4
  import {Fraction} from "../coefficients";
5
5
  import {Numeric} from "../numeric";
6
- import {Shutingyard} from "../shutingyard";
6
+ import {Shutingyard, ShutingyardType, Token, tokenType} from "../shutingyard";
7
+ import {log} from "util";
7
8
 
8
9
  export type literalType = {
9
10
  [Key: string]: Fraction
@@ -118,8 +119,8 @@ export class Monom {
118
119
  * Get the variables letters
119
120
  */
120
121
  get variables(): string[] {
121
- this.clone().clean();
122
- return Object.keys(this._literal)
122
+ let M = this.clone().clean();
123
+ return Object.keys(M.literal)
123
124
  }
124
125
 
125
126
  // Display getter
@@ -260,7 +261,7 @@ export class Monom {
260
261
  if (this._literal[letter].isNotZero()) {
261
262
  L += `${letter}`;
262
263
  if (this._literal[letter].isNotEqual(1)) {
263
- L += `^{${this._literal[letter].display}}`;
264
+ L += `^{${this._literal[letter].tfrac}}`;
264
265
  }
265
266
  }
266
267
  }
@@ -310,6 +311,59 @@ export class Monom {
310
311
  return this;
311
312
  };
312
313
 
314
+ static addToken = (stack: Monom[], element: Token): void => {
315
+
316
+ let q1: Monom, q2: Monom, m: Monom, letter: string, pow: Fraction
317
+
318
+ if (element.tokenType === ShutingyardType.COEFFICIENT) {
319
+ stack.push(new Monom(new Fraction(element.token)))
320
+
321
+ } else if (element.tokenType === ShutingyardType.VARIABLE) {
322
+ let M = new Monom().one()
323
+ M.setLetter(element.token, 1)
324
+ stack.push(M.clone())
325
+
326
+ } else if (element.tokenType === ShutingyardType.OPERATION) {
327
+ switch (element.token) {
328
+ case '-':
329
+ // this should only happen for negative powers or for negative coefficient.
330
+ q2 = (stack.pop()) || new Monom().zero()
331
+ q1 = (stack.pop()) || new Monom().zero()
332
+
333
+ stack.push(q1.subtract(q2))
334
+
335
+ break;
336
+ case '*':
337
+ // Get the last element in the stack
338
+ q2 = (stack.pop()) || new Monom().one()
339
+ q1 = (stack.pop()) || new Monom().one()
340
+
341
+ stack.push(q1.multiply(q2))
342
+ break
343
+ case '/':
344
+ // Get the last element in the stack
345
+ q2 = (stack.pop()) || new Monom().one()
346
+ q1 = (stack.pop()) || new Monom().one()
347
+
348
+ stack.push(q1.divide(q2))
349
+ break
350
+ case '^':
351
+ // get the two last elements in the stack
352
+ pow = (stack.pop().coefficient) || new Fraction().one()
353
+ m = (stack.pop()) || new Monom().one()
354
+
355
+ letter = m.variables[0]
356
+
357
+ if (letter !== undefined) {
358
+ m.setLetter(letter, pow)
359
+ }
360
+
361
+ stack.push(m)
362
+ // this.multiply(m.clone())
363
+ break
364
+ }
365
+ }
366
+ }
313
367
  private _shutingYardToReducedMonom = (inputStr: string): Monom => {
314
368
  // Get the RPN array of the current expression
315
369
  const SY: Shutingyard = new Shutingyard().parse(inputStr);
@@ -333,47 +387,7 @@ export class Monom {
333
387
  } else {
334
388
  // Reset the monom
335
389
  for (const element of rpn) {
336
- if (element.tokenType === 'coefficient') {
337
- let M = new Monom().one()
338
- M.coefficient = new Fraction(element.token)
339
- stack.push(M.clone())
340
- } else if (element.tokenType === 'variable') {
341
- let M = new Monom().one()
342
- M.setLetter(element.token, 1)
343
- stack.push(M.clone())
344
- } else if (element.tokenType === 'operation') {
345
- switch (element.token) {
346
- case '-':
347
- // this should only happen for negative powers or for negative coefficient.
348
- q2 = (stack.pop()) || new Monom().zero()
349
- q1 = (stack.pop()) || new Monom().zero()
350
-
351
- stack.push(q1.subtract(q2))
352
-
353
- break;
354
- case '*':
355
- // Get the last element in the stack
356
- q2 = (stack.pop()) || new Monom().one()
357
- q1 = (stack.pop()) || new Monom().one()
358
-
359
- stack.push(q1.multiply(q2))
360
- break
361
- case '^':
362
- // get the two last elements in the stack
363
- pow = (stack.pop().coefficient) || new Fraction().one()
364
- m = (stack.pop()) || new Monom().one()
365
-
366
- letter = m.variables[0]
367
-
368
- if (letter !== undefined) {
369
- m.setLetter(letter, pow)
370
- }
371
-
372
- stack.push(m)
373
- // this.multiply(m.clone())
374
- break
375
- }
376
- }
390
+ Monom.addToken(stack, element)
377
391
  }
378
392
  }
379
393
 
@@ -440,10 +454,15 @@ export class Monom {
440
454
  delete this._literal[letter];
441
455
  }
442
456
  }
443
-
444
457
  return this;
445
458
  };
446
459
 
460
+ reduce = (): Monom => {
461
+ this.clean()
462
+ this.coefficient.reduce()
463
+ return this
464
+ }
465
+
447
466
  // ------------------------------------------
448
467
  // Mathematical operations
449
468
  // ------------------------------------------
@@ -547,10 +566,10 @@ export class Monom {
547
566
  * Get the pow of a monom.
548
567
  * @param nb (number) : Mathematical pow
549
568
  */
550
- pow = (nb: number): Monom => {
569
+ pow = (nb: number|Fraction): Monom => {
551
570
  this._coefficient.pow(nb);
552
571
  for (let letter in this._literal) {
553
- this._literal[letter].pow(nb)
572
+ this._literal[letter].multiply(nb)
554
573
  }
555
574
  return this;
556
575
  };
@@ -602,6 +621,7 @@ export class Monom {
602
621
  M2: string[] = M.variables,
603
622
  K: string[] = M1.concat(M2.filter((item) => M1.indexOf(item) < 0));
604
623
 
624
+ if(M1.length===0 && M2.length===0){return true}
605
625
  // To compare, both must be different than zero.
606
626
  if (!this.isZero() && !M.isZero()) {
607
627
  for (let key of K) {
@@ -746,7 +766,6 @@ export class Monom {
746
766
 
747
767
  if (typeof values === 'number' || values instanceof Fraction) {
748
768
  let tmpValues: literalType = {}
749
-
750
769
  tmpValues[this.variables[0]] = new Fraction(values)
751
770
  return this.evaluate(tmpValues);
752
771
  }
@@ -758,9 +777,11 @@ export class Monom {
758
777
  }
759
778
 
760
779
  let value = new Fraction(values[L])
780
+
761
781
  r.multiply(value.pow(this._literal[L]))
762
782
  }
763
783
  }
784
+
764
785
  return r;
765
786
  };
766
787
 
@@ -811,6 +832,7 @@ export class Monom {
811
832
  }
812
833
  M.setLetter(letter, 1)
813
834
  }
835
+
814
836
  return M
815
837
  }
816
838
  // ----------------------------------------