pimath 0.0.76 → 0.0.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/pi.js CHANGED
@@ -2542,6 +2542,23 @@ class Polynom {
2542
2542
  };
2543
2543
  // ------------------------------------------
2544
2544
  // Compare functions
2545
+ this.isReduced = (polynomString) => {
2546
+ // The polynom must be developed to be reduced.
2547
+ if (!this.isDeveloped(polynomString)) {
2548
+ return false;
2549
+ }
2550
+ let P = new Polynom(polynomString);
2551
+ if (P.monoms.length > this.monoms.length) {
2552
+ return false;
2553
+ }
2554
+ // TODO: Not ur the reduced systme checking is working properly !
2555
+ for (let m of P.monoms) {
2556
+ if (!m.coefficient.isReduced()) {
2557
+ return false;
2558
+ }
2559
+ }
2560
+ return false;
2561
+ };
2545
2562
  this.isDeveloped = (polynomString) => {
2546
2563
  let P;
2547
2564
  // There is at least one parenthese - it is not developed.
@@ -3174,6 +3191,38 @@ class Polynom {
3174
3191
  }
3175
3192
  return tex;
3176
3193
  }
3194
+ get texDisplay() {
3195
+ this.factorize();
3196
+ if (this.factors.length <= 1) {
3197
+ return this.display;
3198
+ }
3199
+ // Build an array of texFactors with the number of similar items.
3200
+ let factorsCount = {};
3201
+ for (let f of this.factors) {
3202
+ if (factorsCount[f.display] !== undefined) {
3203
+ factorsCount[f.display].degree++;
3204
+ }
3205
+ else {
3206
+ factorsCount[f.display] = {
3207
+ degree: 1,
3208
+ factor: f
3209
+ };
3210
+ }
3211
+ }
3212
+ // First round to put the 'monom' first
3213
+ let simpleFactor = new Polynom().one();
3214
+ for (let item of Object.values(factorsCount).filter(item => item.factor.monoms.length === 1)) {
3215
+ simpleFactor.multiply(item.factor);
3216
+ }
3217
+ let display = simpleFactor.isOne() ? '' : simpleFactor.display;
3218
+ // Loop through all factors that contains at least 2 monoms.
3219
+ for (let item of Object.values(factorsCount).filter(item => item.factor.monoms.length > 1)) {
3220
+ if (item.factor.length > 1) {
3221
+ display += `\\left( ${item.factor.display} \\right)${item.degree > 1 ? '^{ ' + item.degree + ' }' : ''}`;
3222
+ }
3223
+ }
3224
+ return display;
3225
+ }
3177
3226
  get length() {
3178
3227
  // TODO: Must reduce the monoms list to remove the zero coefficient.
3179
3228
  return this._monoms.length;
@@ -4063,7 +4112,9 @@ class Fraction {
4063
4112
  else {
4064
4113
  // The given value is a float number
4065
4114
  // Get the number of decimals after the float sign
4066
- let p = (value.toString()).split('.')[1].length;
4115
+ let [unit, decimal] = (value.toString()).split('.');
4116
+ let p = decimal.length;
4117
+ // Detect if the decimal part is periodic or not...
4067
4118
  // Transform the float number in two integer
4068
4119
  if (denominatorOrPeriodic === undefined) {
4069
4120
  this._numerator = value * Math.pow(10, p);
@@ -6523,6 +6574,58 @@ class Numeric {
6523
6574
  }
6524
6575
  return triplets;
6525
6576
  }
6577
+ static numberCorrection(value) {
6578
+ // Must modify the number if it's like:
6579
+ // a: 3.0000000000000003
6580
+ // b: 3.9999999999999994
6581
+ // remove the last character
6582
+ // check if around n last characters are either 0 or 9
6583
+ // if it is, 'round' the number.
6584
+ function extractDecimalPart(valueToExtract) {
6585
+ let decimal = valueToExtract.toString();
6586
+ if (!decimal.includes('.')) {
6587
+ return '';
6588
+ }
6589
+ decimal = decimal.split('.')[1];
6590
+ return decimal.substring(0, decimal.length - 2);
6591
+ }
6592
+ const epsilon = 0.00000000000001, number_of_digits = 6;
6593
+ const decimal = extractDecimalPart(value);
6594
+ if (decimal === '') {
6595
+ return value;
6596
+ }
6597
+ const n9 = decimal.match(/9+$/g);
6598
+ const n0 = decimal.match(/0+$/g);
6599
+ if (n9 && n9[0].length >= number_of_digits) {
6600
+ // New tested values.
6601
+ const mod = extractDecimalPart(value + epsilon), mod0 = mod.match(/0+$/g);
6602
+ if (mod0 && mod0[0].length >= number_of_digits) {
6603
+ // The value can be changed. Remove all zeros!
6604
+ return +((value + epsilon).toString().split(mod0[0])[0]);
6605
+ }
6606
+ }
6607
+ if (n0 && n0[0].length >= number_of_digits) {
6608
+ // New tested values.
6609
+ const mod = extractDecimalPart(value - epsilon), mod9 = mod.match(/9+$/g);
6610
+ if (mod9 && mod9[0].length >= number_of_digits) {
6611
+ // The value can be changed. Remove all nines!
6612
+ return +(value.toString().split(n0[0])[0]);
6613
+ }
6614
+ }
6615
+ return value;
6616
+ }
6617
+ static periodic(value) {
6618
+ if (Number.isSafeInteger(value)) {
6619
+ return 0;
6620
+ }
6621
+ // Assume it's with decimal.
6622
+ let decimal = (value.toString()).split('.')[0];
6623
+ // The decimal part is limited
6624
+ if (decimal.length < 10) {
6625
+ return 0;
6626
+ }
6627
+ // Find the periodic if it exists.
6628
+ }
6526
6629
  }
6527
6630
  exports.Numeric = Numeric;
6528
6631
 
@@ -6589,7 +6692,7 @@ var Random;
6589
6692
  }
6590
6693
  Random.item = item;
6591
6694
  function shuffle(arr) {
6592
- rndHelpers_1.rndHelpers.shuffleArray(arr);
6695
+ return rndHelpers_1.rndHelpers.shuffleArray(arr);
6593
6696
  }
6594
6697
  Random.shuffle = shuffle;
6595
6698
  })(Random = exports.Random || (exports.Random = {}));