pimath 0.0.55 → 0.0.58

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 (59) hide show
  1. package/.eslintrc.js +23 -23
  2. package/dist/pi.js +117 -46
  3. package/dist/pi.js.map +1 -1
  4. package/dist/pi.min.js +1 -1
  5. package/dist/pi.min.js.map +1 -1
  6. package/docs/assets/highlight.css +78 -78
  7. package/docs/assets/main.js +52 -52
  8. package/docs/assets/style.css +1413 -1413
  9. package/docs/classes/Logicalset.Logicalset-1.html +4 -4
  10. package/docs/classes/Polynom.Rational.html +3 -3
  11. package/docs/classes/algebra_equation.Equation.html +25 -25
  12. package/docs/classes/algebra_monom.Monom.html +113 -113
  13. package/docs/classes/algebra_polynom.Polynom.html +29 -29
  14. package/docs/classes/coefficients_fraction.Fraction.html +18 -18
  15. package/docs/classes/coefficients_nthroot.NthRoot.html +2 -2
  16. package/docs/classes/geometry_circle.Circle.html +2 -2
  17. package/docs/classes/geometry_line.Line.html +2 -2
  18. package/docs/classes/geometry_triangle.Triangle.html +16 -16
  19. package/docs/classes/numeric.Numeric.html +13 -13
  20. package/docs/classes/shutingyard.Shutingyard.html +17 -17
  21. package/docs/index.html +10 -10
  22. package/docs/interfaces/algebra_equation.ISolution.html +2 -2
  23. package/docs/modules/Logicalset.html +2 -2
  24. package/docs/modules/Polynom.html +2 -2
  25. package/docs/modules/Vector.html +2 -2
  26. package/esm/maths/algebra/equation.js +4 -4
  27. package/esm/maths/algebra/equation.js.map +1 -10
  28. package/esm/maths/algebra/linearSystem.js.map +1 -10
  29. package/esm/maths/algebra/monom.d.ts +3 -3
  30. package/esm/maths/algebra/monom.js +49 -8
  31. package/esm/maths/algebra/monom.js.map +1 -10
  32. package/esm/maths/algebra/polynom.d.ts +6 -6
  33. package/esm/maths/algebra/polynom.js +73 -50
  34. package/esm/maths/algebra/polynom.js.map +1 -10
  35. package/esm/maths/algebra/rational.d.ts +2 -1
  36. package/esm/maths/algebra/rational.js +28 -4
  37. package/esm/maths/algebra/rational.js.map +1 -10
  38. package/esm/maths/expressions/numexp.d.ts +1 -1
  39. package/esm/maths/expressions/numexp.js +1 -1
  40. package/esm/maths/expressions/numexp.js.map +1 -1
  41. package/esm/maths/expressions/polynomexp.bkp.js +1 -1
  42. package/esm/maths/expressions/polynomexp.bkp.js.map +1 -10
  43. package/esm/maths/expressions/polynomexp.js +2 -2
  44. package/esm/maths/expressions/polynomexp.js.map +1 -10
  45. package/esm/maths/geometry/point.js.map +1 -10
  46. package/esm/maths/randomization/random.js +1 -5
  47. package/esm/maths/randomization/random.js.map +1 -10
  48. package/esm/maths/shutingyard.js.map +1 -1
  49. package/package.json +1 -1
  50. package/public/index.html +1 -1
  51. package/public/matrices.html +100 -0
  52. package/src/maths/algebra/monom.ts +37 -3
  53. package/src/maths/algebra/polynom.ts +65 -52
  54. package/src/maths/algebra/rational.ts +30 -7
  55. package/src/maths/expressions/numexp.ts +1 -1
  56. package/src/maths/shutingyard.ts +1 -0
  57. package/tests/algebra/polynom.test.ts +8 -0
  58. package/tests/algebra/rationnal.test.ts +6 -0
  59. package/tests/numexp.test.ts +8 -0
package/.eslintrc.js CHANGED
@@ -1,24 +1,24 @@
1
- module.exports = {
2
- "env": {
3
- "browser": true,
4
- "es6": true
5
- },
6
- "extends": [
7
- "eslint:recommended",
8
- "plugin:@typescript-eslint/eslint-recommended"
9
- ],
10
- "globals": {
11
- "Atomics": "readonly",
12
- "SharedArrayBuffer": "readonly"
13
- },
14
- "parser": "@typescript-eslint/parser",
15
- "parserOptions": {
16
- "ecmaVersion": 2018,
17
- "sourceType": "module"
18
- },
19
- "plugins": [
20
- "@typescript-eslint"
21
- ],
22
- "rules": {
23
- }
1
+ module.exports = {
2
+ "env": {
3
+ "browser": true,
4
+ "es6": true
5
+ },
6
+ "extends": [
7
+ "eslint:recommended",
8
+ "plugin:@typescript-eslint/eslint-recommended"
9
+ ],
10
+ "globals": {
11
+ "Atomics": "readonly",
12
+ "SharedArrayBuffer": "readonly"
13
+ },
14
+ "parser": "@typescript-eslint/parser",
15
+ "parserOptions": {
16
+ "ecmaVersion": 2018,
17
+ "sourceType": "module"
18
+ },
19
+ "plugins": [
20
+ "@typescript-eslint"
21
+ ],
22
+ "rules": {
23
+ }
24
24
  };
package/dist/pi.js CHANGED
@@ -1859,7 +1859,7 @@ class Monom {
1859
1859
  if (this._literal[letter].isNotZero()) {
1860
1860
  L += `${letter}`;
1861
1861
  if (this._literal[letter].isNotEqual(1)) {
1862
- L += `^${this._literal[letter].display}`;
1862
+ L += `^(${this._literal[letter].display})`;
1863
1863
  }
1864
1864
  }
1865
1865
  }
@@ -1897,7 +1897,7 @@ class Monom {
1897
1897
  return [this.clone()];
1898
1898
  }
1899
1899
  // Security : do not do this if greater than 10000
1900
- if (this.coefficient.numerator > 10000) {
1900
+ if (this.coefficient.numerator > 1000000) {
1901
1901
  return [this.clone()];
1902
1902
  }
1903
1903
  const dividers = numeric_1.Numeric.dividers(Math.abs(this.coefficient.numerator));
@@ -1970,6 +1970,41 @@ class Monom {
1970
1970
  }
1971
1971
  return this.tex;
1972
1972
  }
1973
+ get plotFunction() {
1974
+ let L = '', letters = Object.keys(this._literal).sort();
1975
+ for (let letter of letters) {
1976
+ if (this._literal[letter].isNotZero()) {
1977
+ L += (L === '' ? "" : "*") + `${letter}`;
1978
+ if (this._literal[letter].isNotEqual(1)) {
1979
+ L += `^(${this._literal[letter].display})`;
1980
+ }
1981
+ }
1982
+ }
1983
+ // No literal part
1984
+ if (L === '') {
1985
+ // No setLetter - means it's only a number !
1986
+ if (this._coefficient.value != 0) {
1987
+ return `${this._coefficient.display}`;
1988
+ }
1989
+ else {
1990
+ return '';
1991
+ }
1992
+ }
1993
+ else {
1994
+ if (this._coefficient.value === 1) {
1995
+ return L;
1996
+ }
1997
+ else if (this._coefficient.value === -1) {
1998
+ return `-${L}`;
1999
+ }
2000
+ else if (this._coefficient.value === 0) {
2001
+ return '0';
2002
+ }
2003
+ else {
2004
+ return `${this._coefficient.display}*${L}`;
2005
+ }
2006
+ }
2007
+ }
1973
2008
  /**
1974
2009
  * Get the tex output of the monom
1975
2010
  */
@@ -2176,6 +2211,8 @@ class Polynom {
2176
2211
  }
2177
2212
  };
2178
2213
  // ------------------------------------------
2214
+ // Creation / parsing functions
2215
+ // ------------------------------------------
2179
2216
  /**
2180
2217
  * Parse a string to a polynom.
2181
2218
  * @param inputStr
@@ -2205,8 +2242,6 @@ class Polynom {
2205
2242
  }
2206
2243
  return this;
2207
2244
  };
2208
- // ------------------------------------------
2209
- // Creation / parsing functions
2210
2245
  /**
2211
2246
  * Clone the polynom
2212
2247
  */
@@ -2245,23 +2280,6 @@ class Polynom {
2245
2280
  this._monoms = this._monoms.map(m => m.opposed());
2246
2281
  return this;
2247
2282
  };
2248
- this.add = (...values) => {
2249
- for (let value of values) {
2250
- if (value instanceof Polynom) {
2251
- this._monoms = this._monoms.concat(value.monoms);
2252
- }
2253
- else if (value instanceof monom_1.Monom) {
2254
- this._monoms.push(value.clone());
2255
- }
2256
- else if (Number.isSafeInteger(value)) {
2257
- this._monoms.push(new monom_1.Monom(value.toString()));
2258
- }
2259
- else {
2260
- this._monoms.push(new monom_1.Monom(value));
2261
- }
2262
- }
2263
- return this.reduce();
2264
- };
2265
2283
  // // -----------------------------------------------
2266
2284
  // // Polynom generators and randomizers
2267
2285
  // // -----------------------------------------------
@@ -2325,6 +2343,23 @@ class Polynom {
2325
2343
  // };
2326
2344
  // ------------------------------------------
2327
2345
  // Mathematical operations
2346
+ this.add = (...values) => {
2347
+ for (let value of values) {
2348
+ if (value instanceof Polynom) {
2349
+ this._monoms = this._monoms.concat(value.monoms);
2350
+ }
2351
+ else if (value instanceof monom_1.Monom) {
2352
+ this._monoms.push(value.clone());
2353
+ }
2354
+ else if (Number.isSafeInteger(value)) {
2355
+ this._monoms.push(new monom_1.Monom(value.toString()));
2356
+ }
2357
+ else {
2358
+ this._monoms.push(new monom_1.Monom(value));
2359
+ }
2360
+ }
2361
+ return this.reduce();
2362
+ };
2328
2363
  this.subtract = (...values) => {
2329
2364
  for (let value of values) {
2330
2365
  if (value instanceof Polynom) {
@@ -2530,6 +2565,8 @@ class Polynom {
2530
2565
  // The polyfactors must be empty and the cumulative opposite factors must be 1.
2531
2566
  return (polyFactors.length === 0 && sign === 1);
2532
2567
  };
2568
+ // ------------------------------------------
2569
+ // Compare functions
2533
2570
  this.isDeveloped = (polynomString) => {
2534
2571
  let P;
2535
2572
  // There is at least one parenthese - it is not developed.
@@ -2557,8 +2594,6 @@ class Polynom {
2557
2594
  // TODO: Maybe it's enough to just make this test !
2558
2595
  return polynomStringNormalized === P.reduce().reorder().display;
2559
2596
  };
2560
- // ------------------------------------------
2561
- // Compare functions
2562
2597
  // -------------------------------------
2563
2598
  this.reduce = () => {
2564
2599
  for (let i = 0; i < this._monoms.length; i++) {
@@ -2644,6 +2679,8 @@ class Polynom {
2644
2679
  }
2645
2680
  return dP;
2646
2681
  };
2682
+ // ------------------------------------------
2683
+ // Misc polynoms functions
2647
2684
  this.primitive = (letter) => {
2648
2685
  let dP = new Polynom();
2649
2686
  for (let m of this._monoms) {
@@ -2651,8 +2688,6 @@ class Polynom {
2651
2688
  }
2652
2689
  return dP;
2653
2690
  };
2654
- // ------------------------------------------
2655
- // Misc polynoms functions
2656
2691
  this.integrate = (a, b, letter) => {
2657
2692
  const primitive = this.primitive(letter);
2658
2693
  if (letter === undefined) {
@@ -2697,7 +2732,8 @@ class Polynom {
2697
2732
  }
2698
2733
  else {
2699
2734
  // Get the first and last monom and build all their dividers.
2700
- let m1 = P.monoms[0].dividers, m2 = P.monoms[P.monoms.length - 1].dividers;
2735
+ // let m1 = P.monoms[0].dividers,
2736
+ // m2 = P.monoms[P.monoms.length - 1].dividers
2701
2737
  // Create the list of all "potential" polynom dividers.
2702
2738
  let allDividers = this._getAllPotentialFactors(P, letter);
2703
2739
  allDividers.every(div => {
@@ -2717,19 +2753,6 @@ class Polynom {
2717
2753
  this.factors = factors;
2718
2754
  return factors;
2719
2755
  };
2720
- this._getAllPotentialFactors = (P, letter) => {
2721
- let m1 = P.monoms[0].dividers, m2 = P.monoms[P.monoms.length - 1].dividers;
2722
- let allDividers = [];
2723
- m1.forEach(m1d => {
2724
- m2.forEach(m2d => {
2725
- if (m1d.degree(letter).isNotEqual(m2d.degree(letter))) {
2726
- allDividers.push(new Polynom(m1d, m2d));
2727
- allDividers.push(new Polynom(m1d, m2d.clone().opposed()));
2728
- }
2729
- });
2730
- });
2731
- return allDividers;
2732
- };
2733
2756
  // TODO: get zeroes for more than first degree and for more than natural degrees
2734
2757
  this.getZeroes = () => {
2735
2758
  let equ = new equation_1.Equation(this.clone(), 0);
@@ -2935,13 +2958,34 @@ class Polynom {
2935
2958
  // Any other cases
2936
2959
  return (new fraction_1.Fraction()).zero();
2937
2960
  };
2938
- this.genDisplay = (output, forceSign, wrapParentheses) => {
2961
+ this._getAllPotentialFactors = (P, letter) => {
2962
+ let m1 = P.monoms[0].dividers, m2 = P.monoms[P.monoms.length - 1].dividers;
2963
+ let allDividers = [];
2964
+ m1.forEach(m1d => {
2965
+ m2.forEach(m2d => {
2966
+ if (m1d.degree(letter).isNotEqual(m2d.degree(letter))) {
2967
+ allDividers.push(new Polynom(m1d, m2d));
2968
+ allDividers.push(new Polynom(m1d, m2d.clone().opposed()));
2969
+ }
2970
+ });
2971
+ });
2972
+ return allDividers;
2973
+ };
2974
+ this.genDisplay = (output, forceSign, wrapParentheses, withAllMultSign) => {
2939
2975
  let P = '';
2940
2976
  for (const k of this._monoms) {
2941
2977
  if (k.coefficient.value === 0) {
2942
2978
  continue;
2943
2979
  }
2944
- P += `${(k.coefficient.sign() === 1 && (P !== '' || forceSign === true)) ? '+' : ''}${(output === 'tex') ? k.tex : k.display}`;
2980
+ // The monom to be displayed
2981
+ let m;
2982
+ if (withAllMultSign) {
2983
+ m = k.plotFunction;
2984
+ }
2985
+ else {
2986
+ m = (output === 'tex') ? k.tex : k.display;
2987
+ }
2988
+ P += `${(k.coefficient.sign() === 1 && (P !== '' || forceSign === true)) ? '+' : ''}${m}`;
2945
2989
  }
2946
2990
  if (wrapParentheses === true && this.length > 1) {
2947
2991
  if (output === 'tex') {
@@ -3240,6 +3284,9 @@ class Polynom {
3240
3284
  get numberOfVars() {
3241
3285
  return this.variables.length;
3242
3286
  }
3287
+ get plotFunction() {
3288
+ return this.genDisplay('tex', false, false, true);
3289
+ }
3243
3290
  isZero() {
3244
3291
  return (this._monoms.length === 1 && this._monoms[0].coefficient.isZero()) || this._monoms.length === 0;
3245
3292
  }
@@ -3437,7 +3484,7 @@ class Rational {
3437
3484
  // Factorize the numerator and the denominator
3438
3485
  this._numerator.factorize();
3439
3486
  this._denominator.factorize();
3440
- let zeroes = equation_1.Equation.makeSolutionsUnique([...this._numerator.getZeroes(), ...this._denominator.getZeroes()], true), NFactors = this._numerator.factors, DFactors = this._denominator.factors;
3487
+ let zeroes = equation_1.Equation.makeSolutionsUnique([...this._numerator.getZeroes(), ...this._denominator.getZeroes()], true).filter(x => !isNaN(x.value)), NFactors = this._numerator.factors, DFactors = this._denominator.factors;
3441
3488
  let tableOfSigns = [], result = [];
3442
3489
  NFactors.forEach(factor => {
3443
3490
  tableOfSigns.push(this._makeOneLineOfTableOfSigns(factor, zeroes, 'z'));
@@ -3505,7 +3552,12 @@ class Rational {
3505
3552
  let oneLine = [], currentZero = factor.getZeroes().map(x => x.tex);
3506
3553
  // First +/- sign, before the first zero
3507
3554
  oneLine.push('');
3508
- oneLine.push(factor.evaluate(zeroes[0].value - 1).sign() === 1 ? '+' : '-');
3555
+ if (factor.degree().isZero()) {
3556
+ oneLine.push(factor.monoms[0].coefficient.sign() === 1 ? '+' : '-');
3557
+ }
3558
+ else {
3559
+ oneLine.push(factor.evaluate(zeroes[0].value - 1).sign() === 1 ? '+' : '-');
3560
+ }
3509
3561
  for (let i = 0; i < zeroes.length; i++) {
3510
3562
  // Add the zero if it's the current one
3511
3563
  oneLine.push(currentZero.includes(zeroes[i].tex) ? zeroSign : 't');
@@ -3520,8 +3572,24 @@ class Rational {
3520
3572
  oneLine.push('');
3521
3573
  return oneLine;
3522
3574
  };
3523
- this._numerator = numerator ? numerator.clone() : new polynom_1.Polynom();
3524
- this._denominator = denominator ? denominator.clone() : new polynom_1.Polynom();
3575
+ if (numerator instanceof polynom_1.Polynom) {
3576
+ this._numerator = numerator.clone();
3577
+ }
3578
+ else if (typeof numerator === 'string') {
3579
+ this._numerator = new polynom_1.Polynom(numerator);
3580
+ }
3581
+ else {
3582
+ this._numerator = new polynom_1.Polynom();
3583
+ }
3584
+ if (denominator instanceof polynom_1.Polynom) {
3585
+ this._denominator = denominator.clone();
3586
+ }
3587
+ else if (typeof denominator === 'string') {
3588
+ this._denominator = new polynom_1.Polynom(denominator);
3589
+ }
3590
+ else {
3591
+ this._denominator = new polynom_1.Polynom();
3592
+ }
3525
3593
  }
3526
3594
  get numerator() {
3527
3595
  return this._numerator;
@@ -3535,6 +3603,9 @@ class Rational {
3535
3603
  get texFactors() {
3536
3604
  return `\\frac{ ${this._numerator.texFactors} }{ ${this._denominator.texFactors} }`;
3537
3605
  }
3606
+ get plotFunction() {
3607
+ return `(${this._numerator.plotFunction})/(${this._denominator.plotFunction})`;
3608
+ }
3538
3609
  }
3539
3610
  exports.Rational = Rational;
3540
3611
 
@@ -4160,7 +4231,7 @@ exports.NumExp = void 0;
4160
4231
  const shutingyard_1 = __webpack_require__(505);
4161
4232
  const fraction_1 = __webpack_require__(506);
4162
4233
  class NumExp {
4163
- constructor(value) {
4234
+ constructor(value, uniformize) {
4164
4235
  this._expression = value;
4165
4236
  this._rpn = new shutingyard_1.Shutingyard(shutingyard_1.ShutingyardMode.NUMERIC).parse(value).rpn;
4166
4237
  }