pimath 0.0.78 → 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;